aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorWei-Ning Huang <aitjcize@gmail.com>2018-11-13 15:26:21 +0800
committerWei-Ning Huang <w@dexon.org>2019-04-09 13:49:56 +0800
commit8760562ef5ced12c468095529ddc8dea71e20344 (patch)
tree57774cc4d6d046e711a7581639c00c11ef2c586e /core
parent4c58c3789e6459340f1c580c07aaf59a5808b80e (diff)
downloaddexon-8760562ef5ced12c468095529ddc8dea71e20344.tar
dexon-8760562ef5ced12c468095529ddc8dea71e20344.tar.gz
dexon-8760562ef5ced12c468095529ddc8dea71e20344.tar.bz2
dexon-8760562ef5ced12c468095529ddc8dea71e20344.tar.lz
dexon-8760562ef5ced12c468095529ddc8dea71e20344.tar.xz
dexon-8760562ef5ced12c468095529ddc8dea71e20344.tar.zst
dexon-8760562ef5ced12c468095529ddc8dea71e20344.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.go13
1 files changed, 11 insertions, 2 deletions
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.