diff options
Diffstat (limited to 'block_pool.go')
-rw-r--r-- | block_pool.go | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/block_pool.go b/block_pool.go index 090871fd3..38302a4c7 100644 --- a/block_pool.go +++ b/block_pool.go @@ -10,8 +10,10 @@ import ( "time" "github.com/ethereum/go-ethereum/chain" + "github.com/ethereum/go-ethereum/chain/types" "github.com/ethereum/go-ethereum/ethutil" "github.com/ethereum/go-ethereum/logger" + "github.com/ethereum/go-ethereum/state" "github.com/ethereum/go-ethereum/wire" ) @@ -20,7 +22,7 @@ var poollogger = logger.NewLogger("BPOOL") type block struct { from *Peer peer *Peer - block *chain.Block + block *types.Block reqAt time.Time requested int } @@ -73,7 +75,7 @@ func (self *BlockPool) HasCommonHash(hash []byte) bool { return self.eth.ChainManager().GetBlock(hash) != nil } -func (self *BlockPool) Blocks() (blocks chain.Blocks) { +func (self *BlockPool) Blocks() (blocks types.Blocks) { for _, item := range self.pool { if item.block != nil { blocks = append(blocks, item.block) @@ -123,15 +125,15 @@ func (self *BlockPool) AddHash(hash []byte, peer *Peer) { } } -func (self *BlockPool) Add(b *chain.Block, peer *Peer) { +func (self *BlockPool) Add(b *types.Block, peer *Peer) { self.addBlock(b, peer, false) } -func (self *BlockPool) AddNew(b *chain.Block, peer *Peer) { +func (self *BlockPool) AddNew(b *types.Block, peer *Peer) { self.addBlock(b, peer, true) } -func (self *BlockPool) addBlock(b *chain.Block, peer *Peer, newBlock bool) { +func (self *BlockPool) addBlock(b *types.Block, peer *Peer, newBlock bool) { self.mut.Lock() defer self.mut.Unlock() @@ -283,7 +285,7 @@ out: break out case <-procTimer.C: blocks := self.Blocks() - chain.BlockBy(chain.Number).Sort(blocks) + types.BlockBy(types.Number).Sort(blocks) // Find common block for i, block := range blocks { @@ -309,10 +311,6 @@ out: } } - // TODO figure out whether we were catching up - // If caught up and just a new block has been propagated: - // sm.eth.EventMux().Post(NewBlockEvent{block}) - // otherwise process and don't emit anything if len(blocks) > 0 { chainManager := self.eth.ChainManager() // Test and import @@ -333,9 +331,14 @@ out: self.td = ethutil.Big0 self.peer = nil } else { - chainManager.InsertChain(bchain) - for _, block := range blocks { - self.Remove(block.Hash()) + if !chain.IsTDError(err) { + chainManager.InsertChain(bchain, func(block *types.Block, messages state.Messages) { + self.eth.EventMux().Post(chain.NewBlockEvent{block}) + self.eth.EventMux().Post(messages) + + self.Remove(block.Hash()) + }) + } } } |