diff options
author | Wei-Ning Huang <aitjcize@gmail.com> | 2018-11-13 15:26:21 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@dexon.org> | 2019-04-09 13:49:56 +0800 |
commit | 8760562ef5ced12c468095529ddc8dea71e20344 (patch) | |
tree | 57774cc4d6d046e711a7581639c00c11ef2c586e /dex | |
parent | 4c58c3789e6459340f1c580c07aaf59a5808b80e (diff) | |
download | dexon-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 'dex')
-rw-r--r-- | dex/api_backend.go | 3 | ||||
-rw-r--r-- | dex/app.go | 6 |
2 files changed, 5 insertions, 4 deletions
diff --git a/dex/api_backend.go b/dex/api_backend.go index 4d0cdc9e9..d8d52974d 100644 --- a/dex/api_backend.go +++ b/dex/api_backend.go @@ -80,7 +80,8 @@ func (b *DexAPIBackend) BlockByNumber(ctx context.Context, blockNr rpc.BlockNumb func (b *DexAPIBackend) StateAndHeaderByNumber(ctx context.Context, blockNr rpc.BlockNumber) (*state.StateDB, *types.Header, error) { if blockNr == rpc.PendingBlockNumber { - blockNr = rpc.BlockNumber(b.dex.blockchain.CurrentBlock().Header().Number.Uint64()) + block, state := b.dex.BlockChain().GetPending() + return state, block.Header(), nil } header, err := b.HeaderByNumber(ctx, blockNr) if header == nil || err != nil { diff --git a/dex/app.go b/dex/app.go index d0d911e86..a90dfae37 100644 --- a/dex/app.go +++ b/dex/app.go @@ -275,13 +275,13 @@ addressMap: // PrepareWitness will return the witness data no lower than consensusHeight. func (d *DexconApp) PrepareWitness(consensusHeight uint64) (witness coreTypes.Witness, err error) { var witnessBlock *types.Block - lastPendingHeight := d.blockchain.GetLastPendingHeight() + lastPendingHeight := d.blockchain.GetPendingHeight() if lastPendingHeight == 0 && consensusHeight == 0 { witnessBlock = d.blockchain.CurrentBlock() } else if lastPendingHeight >= consensusHeight { - witnessBlock = d.blockchain.GetLastPendingBlock() + witnessBlock = d.blockchain.GetPendingBlock() } else if h := <-d.addNotify(consensusHeight); h >= consensusHeight { - witnessBlock = d.blockchain.GetLastPendingBlock() + witnessBlock = d.blockchain.GetPendingBlock() } else { log.Error("need pending block") return witness, fmt.Errorf("need pending block") |