aboutsummaryrefslogtreecommitdiffstats
path: root/dex/app.go
diff options
context:
space:
mode:
authorbojie <bojie@dexon.org>2018-12-05 16:24:35 +0800
committerWei-Ning Huang <w@byzantine-lab.io>2019-06-12 17:27:19 +0800
commitf85ac9ff86438420e51b75cafc7175f957a22f9a (patch)
treec97b533c5969abe456d94c1dc6609986c7a33310 /dex/app.go
parentd4183037825fe7a86e2a6653adb5e97ee0d6bbf8 (diff)
downloadgo-tangerine-f85ac9ff86438420e51b75cafc7175f957a22f9a.tar
go-tangerine-f85ac9ff86438420e51b75cafc7175f957a22f9a.tar.gz
go-tangerine-f85ac9ff86438420e51b75cafc7175f957a22f9a.tar.bz2
go-tangerine-f85ac9ff86438420e51b75cafc7175f957a22f9a.tar.lz
go-tangerine-f85ac9ff86438420e51b75cafc7175f957a22f9a.tar.xz
go-tangerine-f85ac9ff86438420e51b75cafc7175f957a22f9a.tar.zst
go-tangerine-f85ac9ff86438420e51b75cafc7175f957a22f9a.zip
app: return retry later instead of retry with sleep time (#78)
Diffstat (limited to 'dex/app.go')
-rw-r--r--dex/app.go53
1 files changed, 22 insertions, 31 deletions
diff --git a/dex/app.go b/dex/app.go
index 92e1a6aaa..5ce34668c 100644
--- a/dex/app.go
+++ b/dex/app.go
@@ -36,10 +36,6 @@ import (
"github.com/dexon-foundation/dexon/rlp"
)
-const (
- verifyBlockMaxRetries = 4
-)
-
// DexconApp implements the DEXON consensus core application interface.
type DexconApp struct {
txPool *core.TxPool
@@ -312,40 +308,35 @@ func (d *DexconApp) VerifyBlock(block *coreTypes.Block) coreTypes.BlockVerifySta
return coreTypes.VerifyInvalidBlock
}
- // Wait until the witnessed root is seen on our local chain.
- for i := 0; i < verifyBlockMaxRetries; i++ {
- if d.blockchain.GetPendingHeight() < block.Witness.Height {
- log.Debug("Pending height < witness height")
- time.Sleep(500 * time.Millisecond)
- continue
- }
+ // Validate witness height.
+ if d.blockchain.GetPendingHeight() < block.Witness.Height {
+ log.Debug("Pending height < witness height")
+ return coreTypes.VerifyRetryLater
+ }
- b := d.blockchain.GetPendingBlockByNumber(block.Witness.Height)
+ b := d.blockchain.GetPendingBlockByNumber(block.Witness.Height)
+ if b == nil {
+ b = d.blockchain.GetBlockByNumber(block.Witness.Height)
if b == nil {
- b = d.blockchain.GetBlockByNumber(block.Witness.Height)
- if b == nil {
- log.Error("Can not get block by height %v", block.Witness.Height)
- return coreTypes.VerifyInvalidBlock
- }
- }
-
- if b.Root() != witnessData.Root {
- log.Error("Witness root not correct expect %v but %v", b.Root(), witnessData.Root)
+ log.Error("Can not get block by height %v", block.Witness.Height)
return coreTypes.VerifyInvalidBlock
}
+ }
- if b.ReceiptHash() != witnessData.ReceiptHash {
- log.Error("Witness receipt hash not correct expect %v but %v", b.ReceiptHash(), witnessData.ReceiptHash)
- return coreTypes.VerifyInvalidBlock
- }
+ if b.Root() != witnessData.Root {
+ log.Error("Witness root not correct expect %v but %v", b.Root(), witnessData.Root)
+ return coreTypes.VerifyInvalidBlock
+ }
- _, err = d.blockchain.StateAt(witnessData.Root)
- if err != nil {
- log.Error("Get state by root %v error: %v", witnessData.Root, err)
- return coreTypes.VerifyInvalidBlock
- }
+ if b.ReceiptHash() != witnessData.ReceiptHash {
+ log.Error("Witness receipt hash not correct expect %v but %v", b.ReceiptHash(), witnessData.ReceiptHash)
+ return coreTypes.VerifyInvalidBlock
+ }
- break
+ _, err = d.blockchain.StateAt(witnessData.Root)
+ if err != nil {
+ log.Error("Get state by root %v error: %v", witnessData.Root, err)
+ return coreTypes.VerifyInvalidBlock
}
d.chainRLock(block.Position.ChainID)