diff options
author | Bojie Wu <bojie@dexon.org> | 2018-10-09 13:28:45 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@dexon.org> | 2018-12-19 20:54:27 +0800 |
commit | 26153cdebdc3c49f6f71537e94297a4f3a0ce07c (patch) | |
tree | 4124a88ec01363e69263648606d9593f70967af3 /dex/app.go | |
parent | b88f16666309f617028c79d8aaed6e39b4ebda34 (diff) | |
download | dexon-26153cdebdc3c49f6f71537e94297a4f3a0ce07c.tar.gz dexon-26153cdebdc3c49f6f71537e94297a4f3a0ce07c.tar.zst dexon-26153cdebdc3c49f6f71537e94297a4f3a0ce07c.zip |
app: fix nil pointer issue
Diffstat (limited to 'dex/app.go')
-rw-r--r-- | dex/app.go | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/dex/app.go b/dex/app.go index 7730ba22f..b924ab620 100644 --- a/dex/app.go +++ b/dex/app.go @@ -129,14 +129,15 @@ func (d *DexconApp) PreparePayload(position coreTypes.Position) (payload []byte, // set state to the pending height var latestState *state.StateDB - if d.lastPendingHeight == 0 { + lastPendingBlock := d.blockchain.GetPendingBlockByHeight(d.lastPendingHeight) + if d.lastPendingHeight == 0 || lastPendingBlock == nil { latestState, err = d.blockchain.State() if err != nil { log.Error("Get current state", "error", err) return nil, fmt.Errorf("get current state error %v", err) } } else { - latestState, err = d.blockchain.StateAt(d.blockchain.GetPendingBlockByHeight(d.lastPendingHeight).Root()) + latestState, err = d.blockchain.StateAt(lastPendingBlock.Root()) if err != nil { log.Error("Get pending state", "error", err) return nil, fmt.Errorf("get pending state error: %v", err) @@ -286,14 +287,15 @@ func (d *DexconApp) VerifyBlock(block *coreTypes.Block) coreTypes.BlockVerifySta // set state to the pending height var latestState *state.StateDB - if d.lastPendingHeight == 0 { + lastPendingBlock := d.blockchain.GetPendingBlockByHeight(d.lastPendingHeight) + if d.lastPendingHeight == 0 || lastPendingBlock == nil { latestState, err = d.blockchain.State() if err != nil { log.Error("Get current state", "error", err) return coreTypes.VerifyInvalidBlock } } else { - latestState, err = d.blockchain.StateAt(d.blockchain.GetPendingBlockByHeight(d.lastPendingHeight).Root()) + latestState, err = d.blockchain.StateAt(lastPendingBlock.Root()) if err != nil { log.Error("Get pending state", "error", err) return coreTypes.VerifyInvalidBlock |