From 5f2bcc7fba1d247763892c35d694f61e12676969 Mon Sep 17 00:00:00 2001 From: Wei-Ning Huang Date: Tue, 13 Nov 2018 15:26:21 +0800 Subject: dex: return correct pending nonce (#14) We need to return the correct pending nonce (include those in the tx pool). Also, StateAndHeaderByNumber is also fixed to use pending block. --- core/blockchain.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'core/blockchain.go') diff --git a/core/blockchain.go b/core/blockchain.go index dce1c276a..3c9e9701d 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -1779,20 +1779,29 @@ func (bc *BlockChain) addPendingBlock(block *types.Block, receipts types.Receipt bc.lastPendingHeight = block.NumberU64() } -func (bc *BlockChain) GetLastPendingHeight() uint64 { +func (bc *BlockChain) GetPendingHeight() uint64 { bc.pendingBlockMu.RLock() defer bc.pendingBlockMu.RUnlock() return bc.lastPendingHeight } -func (bc *BlockChain) GetLastPendingBlock() *types.Block { +func (bc *BlockChain) GetPendingBlock() *types.Block { bc.pendingBlockMu.RLock() defer bc.pendingBlockMu.RUnlock() return bc.pendingBlocks[bc.lastPendingHeight].block } +func (bc *BlockChain) GetPending() (*types.Block, *state.StateDB) { + block := bc.GetPendingBlock() + s, err := state.New(block.Header().Root, bc.stateCache) + if err != nil { + panic(err) + } + return block, s +} + // reorg takes two blocks, an old chain and a new chain and will reconstruct the // blocks and inserts them to be part of the new canonical chain and accumulates // potential missing transactions and post an event about them. -- cgit