aboutsummaryrefslogtreecommitdiffstats
path: root/core/test/app.go
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2018-08-22 11:33:39 +0800
committerGitHub <noreply@github.com>2018-08-22 11:33:39 +0800
commit89a65a152ae7956bcf6d241eb15d66e6d955b819 (patch)
treeec157eab266cf3dd76a94cfdbe90d35a08a2e492 /core/test/app.go
parent2c816b5d636b8f7decd234582470a3d4c6b4a93a (diff)
downloadtangerine-consensus-89a65a152ae7956bcf6d241eb15d66e6d955b819.tar.gz
tangerine-consensus-89a65a152ae7956bcf6d241eb15d66e6d955b819.tar.zst
tangerine-consensus-89a65a152ae7956bcf6d241eb15d66e6d955b819.zip
core: Notary ack application. (#70)
Diffstat (limited to 'core/test/app.go')
-rw-r--r--core/test/app.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/core/test/app.go b/core/test/app.go
index ddce31a..e26c20c 100644
--- a/core/test/app.go
+++ b/core/test/app.go
@@ -50,6 +50,10 @@ var (
// and delivered are different.
ErrMismatchTotalOrderingAndDelivered = fmt.Errorf(
"mismatch total ordering and delivered sequence")
+ // ErrNotaryAckUnknownBlock means the notary ack is acking on the unknown
+ // block.
+ ErrNotaryAckUnknownBlock = fmt.Errorf(
+ "notary ack on unknown block")
)
// AppAckedRecord caches information when this application received
@@ -83,6 +87,8 @@ type App struct {
Delivered map[common.Hash]*AppDeliveredRecord
DeliverSequence common.Hashes
deliveredLock sync.RWMutex
+ NotaryAckSequence []*types.NotaryAck
+ notaryAckLock sync.RWMutex
}
// NewApp constructs a TestApp instance.
@@ -137,6 +143,10 @@ func (app *App) DeliverBlock(blockHash common.Hash, timestamp time.Time) {
// NotaryAckDeliver implements Application interface.
func (app *App) NotaryAckDeliver(notaryAck *types.NotaryAck) {
+ app.notaryAckLock.Lock()
+ defer app.notaryAckLock.Unlock()
+
+ app.NotaryAckSequence = append(app.NotaryAckSequence, notaryAck)
}
// Compare performs these checks against another App instance
@@ -224,6 +234,15 @@ Loop:
// by total ordering.
return ErrMismatchTotalOrderingAndDelivered
}
+
+ // Make sure that notaryAck is acking the correct block.
+ app.notaryAckLock.RLock()
+ defer app.notaryAckLock.RUnlock()
+ for _, notaryAck := range app.NotaryAckSequence {
+ if _, exists := app.Delivered[notaryAck.NotaryBlockHash]; !exists {
+ return ErrNotaryAckUnknownBlock
+ }
+ }
return nil
}