diff options
author | Wei-Ning Huang <aitjcize@gmail.com> | 2018-11-13 15:26:21 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@dexon.org> | 2018-12-19 20:54:27 +0800 |
commit | 1fbea1eeb71062477d104b4def4c367cc5407de8 (patch) | |
tree | c95c74e5dfbabdcb245c1753229a92b8ce25d4fe /core | |
parent | 2029c52f5a683f8135dba829495981a128412e40 (diff) | |
download | dexon-1fbea1eeb71062477d104b4def4c367cc5407de8.tar dexon-1fbea1eeb71062477d104b4def4c367cc5407de8.tar.gz dexon-1fbea1eeb71062477d104b4def4c367cc5407de8.tar.bz2 dexon-1fbea1eeb71062477d104b4def4c367cc5407de8.tar.lz dexon-1fbea1eeb71062477d104b4def4c367cc5407de8.tar.xz dexon-1fbea1eeb71062477d104b4def4c367cc5407de8.tar.zst dexon-1fbea1eeb71062477d104b4def4c367cc5407de8.zip |
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.
Diffstat (limited to 'core')
-rw-r--r-- | core/blockchain.go | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/core/blockchain.go b/core/blockchain.go index b2a52f931..3613eb4f9 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -1773,20 +1773,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 +} + // reorgs 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 |