aboutsummaryrefslogtreecommitdiffstats
path: root/dex/app.go
diff options
context:
space:
mode:
authorBojie Wu <bojie@dexon.org>2018-10-09 13:28:45 +0800
committerWei-Ning Huang <w@byzantine-lab.io>2019-06-12 17:27:17 +0800
commit8a247252263a9bcc23830217b0c108b2fdd0b84b (patch)
treec208ee7657da1c61ee485a9e4130ed9c54fdfa58 /dex/app.go
parenta69fb3e4c59fab52b6e10993c67400084879b1a8 (diff)
downloadgo-tangerine-8a247252263a9bcc23830217b0c108b2fdd0b84b.tar
go-tangerine-8a247252263a9bcc23830217b0c108b2fdd0b84b.tar.gz
go-tangerine-8a247252263a9bcc23830217b0c108b2fdd0b84b.tar.bz2
go-tangerine-8a247252263a9bcc23830217b0c108b2fdd0b84b.tar.lz
go-tangerine-8a247252263a9bcc23830217b0c108b2fdd0b84b.tar.xz
go-tangerine-8a247252263a9bcc23830217b0c108b2fdd0b84b.tar.zst
go-tangerine-8a247252263a9bcc23830217b0c108b2fdd0b84b.zip
app: fix nil pointer issue
Diffstat (limited to 'dex/app.go')
-rw-r--r--dex/app.go10
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