diff options
author | obscuren <geffobscura@gmail.com> | 2014-08-22 16:58:57 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-08-22 16:58:57 +0800 |
commit | a9f9a594160405737657083476535f3e48df1558 (patch) | |
tree | 12a87c858db2cfe1fff91d2f29c6051be1844f51 /block_pool.go | |
parent | 42d43147cac99469eb3f445342fe9e1ebeb5222e (diff) | |
download | dexon-a9f9a594160405737657083476535f3e48df1558.tar dexon-a9f9a594160405737657083476535f3e48df1558.tar.gz dexon-a9f9a594160405737657083476535f3e48df1558.tar.bz2 dexon-a9f9a594160405737657083476535f3e48df1558.tar.lz dexon-a9f9a594160405737657083476535f3e48df1558.tar.xz dexon-a9f9a594160405737657083476535f3e48df1558.tar.zst dexon-a9f9a594160405737657083476535f3e48df1558.zip |
Extra checks
Diffstat (limited to 'block_pool.go')
-rw-r--r-- | block_pool.go | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/block_pool.go b/block_pool.go index 3225bdff2..2be2bc787 100644 --- a/block_pool.go +++ b/block_pool.go @@ -49,11 +49,11 @@ func (self *BlockPool) AddHash(hash []byte) { } } -func (self *BlockPool) SetBlock(b *ethchain.Block) { +func (self *BlockPool) SetBlock(b *ethchain.Block, peer *Peer) { hash := string(b.Hash()) - if self.pool[string(hash)] == nil { - self.pool[hash] = &block{nil, nil} + if self.pool[hash] == nil { + self.pool[hash] = &block{peer, nil} } self.pool[hash].block = b @@ -65,6 +65,10 @@ func (self *BlockPool) CheckLinkAndProcess(f func(block *ethchain.Block)) bool { if self.IsLinked() { for i, hash := range self.hashPool { + if self.pool[string(hash)] == nil { + continue + } + block := self.pool[string(hash)].block if block != nil { f(block) @@ -84,7 +88,7 @@ func (self *BlockPool) CheckLinkAndProcess(f func(block *ethchain.Block)) bool { } func (self *BlockPool) IsLinked() bool { - if len(self.hashPool) == 0 { + if len(self.hashPool) == 0 || self.pool[string(self.hashPool[0])] == nil { return false } @@ -104,7 +108,7 @@ func (self *BlockPool) Take(amount int, peer *Peer) (hashes [][]byte) { j := 0 for i := 0; i < len(self.hashPool) && j < num; i++ { hash := string(self.hashPool[i]) - if self.pool[hash].peer == nil || self.pool[hash].peer == peer { + if self.pool[hash] != nil && (self.pool[hash].peer == nil || self.pool[hash].peer == peer) && self.pool[hash].block == nil { self.pool[hash].peer = peer hashes = append(hashes, self.hashPool[i]) |