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 21:32:53 +0800
commit5f2bcc7fba1d247763892c35d694f61e12676969 (patch)
tree4af712f8303c18a58830756b9b0768eca355fad8 /core
parentf14055593cf6a7479f9aea77d08e5e172e8667e4 (diff)
downloaddexon-5f2bcc7fba1d247763892c35d694f61e12676969.tar
dexon-5f2bcc7fba1d247763892c35d694f61e12676969.tar.gz
dexon-5f2bcc7fba1d247763892c35d694f61e12676969.tar.bz2
dexon-5f2bcc7fba1d247763892c35d694f61e12676969.tar.lz
dexon-5f2bcc7fba1d247763892c35d694f61e12676969.tar.xz
dexon-5f2bcc7fba1d247763892c35d694f61e12676969.tar.zst
dexon-5f2bcc7fba1d247763892c35d694f61e12676969.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.