use common.Hash as pool key, no string conversion needed
This commit is contained in:
parent
d7564a9a25
commit
66b29899c4
|
@ -157,7 +157,7 @@ type BlockPool struct {
|
||||||
tdSub event.Subscription // subscription to core.ChainHeadEvent
|
tdSub event.Subscription // subscription to core.ChainHeadEvent
|
||||||
td *big.Int // our own total difficulty
|
td *big.Int // our own total difficulty
|
||||||
|
|
||||||
pool map[string]*entry // the actual blockpool
|
pool map[common.Hash]*entry // the actual blockpool
|
||||||
peers *peers // peers manager in peers.go
|
peers *peers // peers manager in peers.go
|
||||||
|
|
||||||
status *status // info about blockpool (UI interface) in status.go
|
status *status // info about blockpool (UI interface) in status.go
|
||||||
|
@ -210,7 +210,7 @@ func (self *BlockPool) Start() {
|
||||||
self.hashSlicePool = make(chan []common.Hash, 150)
|
self.hashSlicePool = make(chan []common.Hash, 150)
|
||||||
self.status = newStatus()
|
self.status = newStatus()
|
||||||
self.quit = make(chan bool)
|
self.quit = make(chan bool)
|
||||||
self.pool = make(map[string]*entry)
|
self.pool = make(map[common.Hash]*entry)
|
||||||
self.running = true
|
self.running = true
|
||||||
|
|
||||||
self.peers = &peers{
|
self.peers = &peers{
|
||||||
|
@ -789,13 +789,13 @@ func (self *BlockPool) getChild(sec *section) *section {
|
||||||
func (self *BlockPool) get(hash common.Hash) *entry {
|
func (self *BlockPool) get(hash common.Hash) *entry {
|
||||||
self.lock.RLock()
|
self.lock.RLock()
|
||||||
defer self.lock.RUnlock()
|
defer self.lock.RUnlock()
|
||||||
return self.pool[hash.Str()]
|
return self.pool[hash]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *BlockPool) set(hash common.Hash, e *entry) {
|
func (self *BlockPool) set(hash common.Hash, e *entry) {
|
||||||
self.lock.Lock()
|
self.lock.Lock()
|
||||||
defer self.lock.Unlock()
|
defer self.lock.Unlock()
|
||||||
self.pool[hash.Str()] = e
|
self.pool[hash] = e
|
||||||
}
|
}
|
||||||
|
|
||||||
// accessor and setter for total difficulty
|
// accessor and setter for total difficulty
|
||||||
|
@ -817,7 +817,7 @@ func (self *BlockPool) remove(sec *section) {
|
||||||
defer self.lock.Unlock()
|
defer self.lock.Unlock()
|
||||||
|
|
||||||
for _, node := range sec.nodes {
|
for _, node := range sec.nodes {
|
||||||
delete(self.pool, node.hash.Str())
|
delete(self.pool, node.hash)
|
||||||
}
|
}
|
||||||
if sec.initialised && sec.poolRootIndex != 0 {
|
if sec.initialised && sec.poolRootIndex != 0 {
|
||||||
self.status.lock.Lock()
|
self.status.lock.Lock()
|
||||||
|
|
|
@ -106,7 +106,7 @@ func (self *section) addSectionToBlockChain(p *peer) {
|
||||||
|
|
||||||
var nodes []*node
|
var nodes []*node
|
||||||
var n *node
|
var n *node
|
||||||
var keys []string
|
var keys []common.Hash
|
||||||
var blocks []*types.Block
|
var blocks []*types.Block
|
||||||
for self.poolRootIndex > 0 {
|
for self.poolRootIndex > 0 {
|
||||||
n = self.nodes[self.poolRootIndex-1]
|
n = self.nodes[self.poolRootIndex-1]
|
||||||
|
@ -117,7 +117,7 @@ func (self *section) addSectionToBlockChain(p *peer) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
self.poolRootIndex--
|
self.poolRootIndex--
|
||||||
keys = append(keys, n.hash.Str())
|
keys = append(keys, n.hash)
|
||||||
blocks = append(blocks, block)
|
blocks = append(blocks, block)
|
||||||
nodes = append(nodes, n)
|
nodes = append(nodes, n)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue