Skip to content

Commit 66b2989

Browse files
committed
use common.Hash as pool key, no string conversion needed
1 parent d7564a9 commit 66b2989

2 files changed

Lines changed: 8 additions & 8 deletions

File tree

‎blockpool/blockpool.go‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ type BlockPool struct {
157157
tdSub event.Subscription // subscription to core.ChainHeadEvent
158158
td *big.Int // our own total difficulty
159159

160-
pool map[string]*entry // the actual blockpool
161-
peers *peers // peers manager in peers.go
160+
pool map[common.Hash]*entry // the actual blockpool
161+
peers *peers // peers manager in peers.go
162162

163163
status *status // info about blockpool (UI interface) in status.go
164164

@@ -210,7 +210,7 @@ func (self *BlockPool) Start() {
210210
self.hashSlicePool = make(chan []common.Hash, 150)
211211
self.status = newStatus()
212212
self.quit = make(chan bool)
213-
self.pool = make(map[string]*entry)
213+
self.pool = make(map[common.Hash]*entry)
214214
self.running = true
215215

216216
self.peers = &peers{
@@ -789,13 +789,13 @@ func (self *BlockPool) getChild(sec *section) *section {
789789
func (self *BlockPool) get(hash common.Hash) *entry {
790790
self.lock.RLock()
791791
defer self.lock.RUnlock()
792-
return self.pool[hash.Str()]
792+
return self.pool[hash]
793793
}
794794

795795
func (self *BlockPool) set(hash common.Hash, e *entry) {
796796
self.lock.Lock()
797797
defer self.lock.Unlock()
798-
self.pool[hash.Str()] = e
798+
self.pool[hash] = e
799799
}
800800

801801
// accessor and setter for total difficulty
@@ -817,7 +817,7 @@ func (self *BlockPool) remove(sec *section) {
817817
defer self.lock.Unlock()
818818

819819
for _, node := range sec.nodes {
820-
delete(self.pool, node.hash.Str())
820+
delete(self.pool, node.hash)
821821
}
822822
if sec.initialised && sec.poolRootIndex != 0 {
823823
self.status.lock.Lock()

‎blockpool/section.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ func (self *section) addSectionToBlockChain(p *peer) {
106106

107107
var nodes []*node
108108
var n *node
109-
var keys []string
109+
var keys []common.Hash
110110
var blocks []*types.Block
111111
for self.poolRootIndex > 0 {
112112
n = self.nodes[self.poolRootIndex-1]
@@ -117,7 +117,7 @@ func (self *section) addSectionToBlockChain(p *peer) {
117117
break
118118
}
119119
self.poolRootIndex--
120-
keys = append(keys, n.hash.Str())
120+
keys = append(keys, n.hash)
121121
blocks = append(blocks, block)
122122
nodes = append(nodes, n)
123123
}

0 commit comments

Comments
 (0)