aboutsummaryrefslogtreecommitdiffstats
path: root/integration_test
diff options
context:
space:
mode:
authorMission Liao <mission.liao@dexon.org>2018-10-27 17:04:04 +0800
committerJimmy Hu <jimmy.hu@dexon.org>2018-10-27 17:04:04 +0800
commitadcdaa20165ec299d2782f032e112b050a15c45f (patch)
tree8b5ae93ad63798c3bb0ca679caef579886eeff94 /integration_test
parentf4a9edfab58063f42526c08b27311a871f8b7207 (diff)
downloaddexon-consensus-adcdaa20165ec299d2782f032e112b050a15c45f.tar
dexon-consensus-adcdaa20165ec299d2782f032e112b050a15c45f.tar.gz
dexon-consensus-adcdaa20165ec299d2782f032e112b050a15c45f.tar.bz2
dexon-consensus-adcdaa20165ec299d2782f032e112b050a15c45f.tar.lz
dexon-consensus-adcdaa20165ec299d2782f032e112b050a15c45f.tar.xz
dexon-consensus-adcdaa20165ec299d2782f032e112b050a15c45f.tar.zst
dexon-consensus-adcdaa20165ec299d2782f032e112b050a15c45f.zip
test: Handle blocks that should retry sanity check later. (#267)
Diffstat (limited to 'integration_test')
-rw-r--r--integration_test/node.go44
-rw-r--r--integration_test/non-byzantine_test.go6
2 files changed, 36 insertions, 14 deletions
diff --git a/integration_test/node.go b/integration_test/node.go
index 8b2931b..bcb44bb 100644
--- a/integration_test/node.go
+++ b/integration_test/node.go
@@ -74,6 +74,7 @@ type Node struct {
networkLatency test.LatencyModel
proposingLatency test.LatencyModel
prevFinalHeight uint64
+ pendings []*types.Block
}
// NewNode constructs an instance of Node.
@@ -187,27 +188,50 @@ func (n *Node) processBlock(b *types.Block) (err error) {
var (
delivered []*types.Block
)
- if err = n.lattice.SanityCheck(b); err != nil {
- if err == core.ErrRetrySanityCheckLater {
- err = nil
- } else {
- return
+ n.pendings = append([]*types.Block{b}, n.pendings...)
+ for {
+ var (
+ newPendings []*types.Block
+ tmpDelivered []*types.Block
+ tmpErr error
+ )
+ updated := false
+ for _, p := range n.pendings {
+ if tmpErr = n.lattice.SanityCheck(p); tmpErr != nil {
+ if tmpErr == core.ErrRetrySanityCheckLater {
+ newPendings = append(newPendings, p)
+ } else {
+ // Those blocks are prepared by lattice module, they should
+ // not be wrong.
+ panic(tmpErr)
+ }
+ continue
+ }
+ if tmpDelivered, tmpErr =
+ n.lattice.ProcessBlock(p); tmpErr != nil {
+ // It's not allowed that sanity checked block failed to
+ // be added to lattice.
+ panic(tmpErr)
+ }
+ delivered = append(delivered, tmpDelivered...)
+ updated = true
+ }
+ n.pendings = newPendings
+ if !updated {
+ break
}
- }
- if delivered, err = n.lattice.ProcessBlock(b); err != nil {
- return
}
// Deliver blocks.
for _, b = range delivered {
if err = n.db.Put(*b); err != nil {
- return
+ panic(err)
}
b.Finalization.Height = n.prevFinalHeight + 1
n.app.BlockDelivered(b.Hash, b.Finalization)
n.prevFinalHeight++
}
if err = n.lattice.PurgeBlocks(delivered); err != nil {
- return
+ panic(err)
}
return
}
diff --git a/integration_test/non-byzantine_test.go b/integration_test/non-byzantine_test.go
index df08b97..a95b10c 100644
--- a/integration_test/non-byzantine_test.go
+++ b/integration_test/non-byzantine_test.go
@@ -59,11 +59,9 @@ func (s *NonByzantineTestSuite) TestNonByzantine() {
sch.RegisterEventHandler(vID, v)
req.Nil(sch.Seed(NewProposeBlockEvent(vID, now)))
}
- sch.Run(10)
+ sch.Run(4)
// Check results by comparing test.App instances.
- if err = VerifyApps(apps); err != nil {
- panic(err)
- }
+ req.NoError(VerifyApps(apps))
}
func TestNonByzantine(t *testing.T) {