diff options
author | obscuren <geffobscura@gmail.com> | 2014-10-08 18:29:49 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-10-08 18:29:49 +0800 |
commit | 4de3ad1712ce0fdc62b1acc27a3922b192e943c6 (patch) | |
tree | a7de24c746a0c6d3531f1fab925d4e8b48a76cd2 /block_pool.go | |
parent | 9d86a49a7327199c01977f3372c8adf748252c32 (diff) | |
download | go-tangerine-4de3ad1712ce0fdc62b1acc27a3922b192e943c6.tar go-tangerine-4de3ad1712ce0fdc62b1acc27a3922b192e943c6.tar.gz go-tangerine-4de3ad1712ce0fdc62b1acc27a3922b192e943c6.tar.bz2 go-tangerine-4de3ad1712ce0fdc62b1acc27a3922b192e943c6.tar.lz go-tangerine-4de3ad1712ce0fdc62b1acc27a3922b192e943c6.tar.xz go-tangerine-4de3ad1712ce0fdc62b1acc27a3922b192e943c6.tar.zst go-tangerine-4de3ad1712ce0fdc62b1acc27a3922b192e943c6.zip |
New block message
Diffstat (limited to 'block_pool.go')
-rw-r--r-- | block_pool.go | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/block_pool.go b/block_pool.go index ea1f3633a..6ad2f5269 100644 --- a/block_pool.go +++ b/block_pool.go @@ -124,6 +124,14 @@ func (self *BlockPool) AddHash(hash []byte, peer *Peer) { } func (self *BlockPool) Add(b *ethchain.Block, peer *Peer) { + self.addBlock(b, peer, false) +} + +func (self *BlockPool) AddNew(b *ethchain.Block, peer *Peer) { + self.addBlock(b, peer, true) +} + +func (self *BlockPool) addBlock(b *ethchain.Block, peer *Peer, newBlock bool) { self.mut.Lock() defer self.mut.Unlock() @@ -135,12 +143,15 @@ func (self *BlockPool) Add(b *ethchain.Block, peer *Peer) { self.hashes = append(self.hashes, b.Hash()) self.pool[hash] = &block{peer, peer, b, time.Now(), 0} - fmt.Println("1.", !self.eth.BlockChain().HasBlock(b.PrevHash), ethutil.Bytes2Hex(b.Hash()[0:4]), ethutil.Bytes2Hex(b.PrevHash[0:4])) - fmt.Println("2.", self.pool[string(b.PrevHash)] == nil) - fmt.Println("3.", !self.fetchingHashes) - if !self.eth.BlockChain().HasBlock(b.PrevHash) && self.pool[string(b.PrevHash)] == nil && !self.fetchingHashes { - poollogger.Infof("Unknown chain, requesting (%x...)\n", b.PrevHash[0:4]) - peer.QueueMessage(ethwire.NewMessage(ethwire.MsgGetBlockHashesTy, []interface{}{b.Hash(), uint32(256)})) + // The following is only performed on an unrequested new block + if newBlock { + fmt.Println("1.", !self.eth.BlockChain().HasBlock(b.PrevHash), ethutil.Bytes2Hex(b.Hash()[0:4]), ethutil.Bytes2Hex(b.PrevHash[0:4])) + fmt.Println("2.", self.pool[string(b.PrevHash)] == nil) + fmt.Println("3.", !self.fetchingHashes) + if !self.eth.BlockChain().HasBlock(b.PrevHash) && self.pool[string(b.PrevHash)] == nil && !self.fetchingHashes { + poollogger.Infof("Unknown chain, requesting (%x...)\n", b.PrevHash[0:4]) + peer.QueueMessage(ethwire.NewMessage(ethwire.MsgGetBlockHashesTy, []interface{}{b.Hash(), uint32(256)})) + } } } else if self.pool[hash] != nil { self.pool[hash].block = b |