aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2019-03-27 10:38:17 +0800
committerJimmy Hu <jimmy.hu@dexon.org>2019-03-27 10:38:17 +0800
commit684f33495175ba119b7d29485c06af9ea46a407b (patch)
treee3bd01f4e2ab6d929aa3028585e08e4984db6237
parent040bf9148ab40197fe31fadc7e2f7170e6132702 (diff)
downloaddexon-consensus-jimmy-check-deliver.tar
dexon-consensus-jimmy-check-deliver.tar.gz
dexon-consensus-jimmy-check-deliver.tar.bz2
dexon-consensus-jimmy-check-deliver.tar.lz
dexon-consensus-jimmy-check-deliver.tar.xz
dexon-consensus-jimmy-check-deliver.tar.zst
dexon-consensus-jimmy-check-deliver.zip
test: check witness data of delivered blockjimmy-check-deliver
-rw-r--r--core/test/app.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/core/test/app.go b/core/test/app.go
index 20fe80f..7452e19 100644
--- a/core/test/app.go
+++ b/core/test/app.go
@@ -18,6 +18,7 @@
package test
import (
+ "bytes"
"fmt"
"sync"
"time"
@@ -65,6 +66,14 @@ var (
// ErrParentBlockNotDelivered raised when the parent block is not seen by
// this app.
ErrParentBlockNotDelivered = fmt.Errorf("parent block not delivered")
+ // ErrWitnessLowerHeight raised when a block's witness height is lower
+ // than parent's.
+ ErrWitnessLowerHeight = fmt.Errorf(
+ "witness height is lower than parent's")
+ // ErrWitnessDataNotMatchForEmptyBlock raied when a empty block's witness
+ // data is not as same as parent's.
+ ErrWitnessDataNotMatchForEmptyBlock = fmt.Errorf(
+ "witness data of empty block does not match with parent's")
)
// AppDeliveredRecord caches information when this application received
@@ -217,6 +226,30 @@ func (app *App) ClearUndeliveredBlocks() {
// BlockDelivered implements Application interface.
func (app *App) BlockDelivered(blockHash common.Hash, pos types.Position,
result types.FinalizationResult) {
+ // Check witness data.
+ func() {
+ app.confirmedLock.RLock()
+ defer app.confirmedLock.RUnlock()
+ block, exist := app.Confirmed[blockHash]
+ if !exist {
+ panic(ErrDeliveredBlockNotConfirmed)
+ }
+ if block.ParentHash == (common.Hash{}) {
+ return
+ }
+ parentBlock, exist := app.Confirmed[blockHash]
+ if !exist {
+ panic(ErrParentBlockNotDelivered)
+ }
+ if block.Witness.Height < parentBlock.Witness.Height {
+ panic(ErrWitnessLowerHeight)
+ }
+ if block.IsEmpty() {
+ if !bytes.Equal(block.Witness.Data, parentBlock.Witness.Data) {
+ panic(ErrWitnessDataNotMatchForEmptyBlock)
+ }
+ }
+ }()
func() {
app.deliveredLock.Lock()
defer app.deliveredLock.Unlock()