future queued block support

- queued       bool // flag for blockpool to skip TD check
- set to true when future block queued
- in checkTD: skip check if queued
- TODO: add test (insertchain sets future block)
This commit is contained in:
zelig 2015-04-08 12:43:55 +01:00
parent cbd0b42060
commit 262714fc6c
3 changed files with 7 additions and 1 deletions

View File

@ -782,7 +782,8 @@ LOOP:
// check if block's actual TD (calculated after successful insertChain) is identical to TD advertised for peer's head block. // check if block's actual TD (calculated after successful insertChain) is identical to TD advertised for peer's head block.
func (self *BlockPool) checkTD(nodes ...*node) { func (self *BlockPool) checkTD(nodes ...*node) {
for _, n := range nodes { for _, n := range nodes {
if n.td != nil { // skip check if queued future block
if n.td != nil && !n.block.Queued() {
plog.DebugDetailf("peer td %v =?= block td %v", n.td, n.block.Td) plog.DebugDetailf("peer td %v =?= block td %v", n.td, n.block.Td)
if n.td.Cmp(n.block.Td) != 0 { if n.td.Cmp(n.block.Td) != 0 {
self.peers.peerError(n.blockBy, ErrIncorrectTD, "on block %x", n.hash) self.peers.peerError(n.blockBy, ErrIncorrectTD, "on block %x", n.hash)

View File

@ -471,6 +471,7 @@ func (self *ChainManager) InsertChain(chain types.Blocks) error {
// Do not penelise on future block. We'll need a block queue eventually that will queue // Do not penelise on future block. We'll need a block queue eventually that will queue
// future block for future use // future block for future use
if err == BlockFutureErr { if err == BlockFutureErr {
block.SetQueued(true)
self.futureBlocks.Push(block) self.futureBlocks.Push(block)
stats.queued++ stats.queued++
continue continue

View File

@ -97,6 +97,7 @@ type Block struct {
uncles []*Header uncles []*Header
transactions Transactions transactions Transactions
Td *big.Int Td *big.Int
queued bool // flag for blockpool to skip TD check
receipts Receipts receipts Receipts
} }
@ -268,6 +269,9 @@ func (self *Block) SetNonce(nonce uint64) {
self.header.SetNonce(nonce) self.header.SetNonce(nonce)
} }
func (self *Block) Queued() bool { return self.queued }
func (self *Block) SetQueued(q bool) { self.queued = q }
func (self *Block) Bloom() Bloom { return self.header.Bloom } func (self *Block) Bloom() Bloom { return self.header.Bloom }
func (self *Block) Coinbase() common.Address { return self.header.Coinbase } func (self *Block) Coinbase() common.Address { return self.header.Coinbase }
func (self *Block) Time() int64 { return int64(self.header.Time) } func (self *Block) Time() int64 { return int64(self.header.Time) }