diff options
author | Mission Liao <mission.liao@dexon.org> | 2019-03-22 21:45:22 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-22 21:45:22 +0800 |
commit | fb9bbdf2a34aa45c0f032b996f72cafd7bccfa80 (patch) | |
tree | c19d1204850e46145bebcb22703ebb718a5f1d7b /integration_test | |
parent | 0f2dd4260fd98b2be06b7f9b0197134c89f11d3c (diff) | |
download | dexon-consensus-fb9bbdf2a34aa45c0f032b996f72cafd7bccfa80.tar dexon-consensus-fb9bbdf2a34aa45c0f032b996f72cafd7bccfa80.tar.gz dexon-consensus-fb9bbdf2a34aa45c0f032b996f72cafd7bccfa80.tar.bz2 dexon-consensus-fb9bbdf2a34aa45c0f032b996f72cafd7bccfa80.tar.lz dexon-consensus-fb9bbdf2a34aa45c0f032b996f72cafd7bccfa80.tar.xz dexon-consensus-fb9bbdf2a34aa45c0f032b996f72cafd7bccfa80.tar.zst dexon-consensus-fb9bbdf2a34aa45c0f032b996f72cafd7bccfa80.zip |
core: remove initRoundBeginHeight paramenter
* Implement Governance.GetRoundHeight
in test.Governance.
Diffstat (limited to 'integration_test')
-rw-r--r-- | integration_test/byzantine_test.go | 2 | ||||
-rw-r--r-- | integration_test/consensus_test.go | 105 | ||||
-rw-r--r-- | integration_test/round-event_test.go | 20 |
3 files changed, 67 insertions, 60 deletions
diff --git a/integration_test/byzantine_test.go b/integration_test/byzantine_test.go index e95e58d..3aea057 100644 --- a/integration_test/byzantine_test.go +++ b/integration_test/byzantine_test.go @@ -79,7 +79,7 @@ func (s *ByzantineTestSuite) setupNodes( ) gov := seedGov.Clone() gov.SwitchToRemoteMode(networkModule) - gov.NotifyRound(0) + gov.NotifyRound(0, 0) networkModule.AttachNodeSetCache(utils.NewNodeSetCache(gov)) app := test.NewApp(1, gov, nil) nodes[nID] = &node{ diff --git a/integration_test/consensus_test.go b/integration_test/consensus_test.go index afea6d8..6bdc3dc 100644 --- a/integration_test/consensus_test.go +++ b/integration_test/consensus_test.go @@ -41,6 +41,32 @@ type ConsensusTestSuite struct { suite.Suite } +// A round event handler to purge utils.NodeSetCache in test.Network. +func purgeHandlerGen(n *test.Network) func([]utils.RoundEventParam) { + return func(evts []utils.RoundEventParam) { + for _, e := range evts { + if e.Reset == 0 { + continue + } + n.PurgeNodeSetCache(e.Round + 1) + } + } +} + +func govHandlerGen( + round, reset uint64, + g *test.Governance, + doer func(*test.Governance)) func([]utils.RoundEventParam) { + return func(evts []utils.RoundEventParam) { + for _, e := range evts { + if e.Round == round && e.Reset == reset { + doer(g) + } + } + } + +} + type node struct { ID types.NodeID con *core.Consensus @@ -58,6 +84,11 @@ func prohibitDKG(gov *test.Governance) { gov.Prohibit(test.StateAddDKGComplaint) } +func prohibitDKGExceptFinalize(gov *test.Governance) { + gov.Prohibit(test.StateAddDKGMasterPublicKey) + gov.Prohibit(test.StateAddDKGComplaint) +} + func unprohibitDKG(gov *test.Governance) { gov.Unprohibit(test.StateAddDKGMasterPublicKey) gov.Unprohibit(test.StateAddDKGFinal) @@ -91,11 +122,11 @@ func (s *ConsensusTestSuite) setupNodes( ) gov := seedGov.Clone() gov.SwitchToRemoteMode(networkModule) - gov.NotifyRound(initRound) + gov.NotifyRound(initRound, 0) networkModule.AttachNodeSetCache(utils.NewNodeSetCache(gov)) logger := &common.NullLogger{} rEvt, err := utils.NewRoundEvent(context.Background(), gov, logger, 0, - 0, 0, core.ConfigRoundShift) + 0, core.ConfigRoundShift) s.Require().NoError(err) nID := types.NewNodeID(k.PublicKey()) nodes[nID] = &node{ @@ -251,7 +282,6 @@ func (s *ConsensusTestSuite) TestSimple() { Loop: for { <-time.After(5 * time.Second) - fmt.Println("check latest position delivered by each node") for _, n := range nodes { latestPos := n.app.GetLatestDeliveredPosition() fmt.Println("latestPos", n.ID, &latestPos) @@ -337,7 +367,6 @@ func (s *ConsensusTestSuite) TestSetSizeChange() { Loop: for { <-time.After(5 * time.Second) - fmt.Println("check latest position delivered by each node") for _, n := range nodes { latestPos := n.app.GetLatestDeliveredPosition() fmt.Println("latestPos", n.ID, &latestPos) @@ -355,6 +384,7 @@ func (s *ConsensusTestSuite) TestSync() { // The sync test case: // - No configuration change. // - One node does not run when all others starts until aliveRound exceeded. + // - One DKG reset happened before syncing. var ( req = s.Require() peerCount = 4 @@ -363,7 +393,7 @@ func (s *ConsensusTestSuite) TestSync() { stopRound = uint64(4) // aliveRound should be large enough to test round event handling in // syncer. - aliveRound = uint64(3) + aliveRound = uint64(2) errChan = make(chan error, 100) ) prvKeys, pubKeys, err := test.NewKeys(peerCount) @@ -388,6 +418,13 @@ func (s *ConsensusTestSuite) TestSync() { // Pick a node to stop when synced. stoppedNode := nodes[types.NewNodeID(pubKeys[1])] for _, n := range nodes { + n.rEvt.Register(purgeHandlerGen(n.network)) + // Round Height reference table: + // - Round:1 Reset:0 -- 100 + // - Round:1 Reset:1 -- 200 + // - Round:2 Reset:0 -- 300 + n.rEvt.Register(govHandlerGen(1, 0, n.gov, prohibitDKG)) + n.rEvt.Register(govHandlerGen(1, 1, n.gov, unprohibitDKG)) if n.ID != syncNode.ID { go n.con.Run() if n.ID != stoppedNode.ID { @@ -641,7 +678,6 @@ ReachStop: Loop: for { <-time.After(5 * time.Second) - fmt.Println("check latest position delivered by each node") for _, n := range nodes { latestPos := n.app.GetLatestDeliveredPosition() fmt.Println("latestPos", n.ID, &latestPos) @@ -678,54 +714,19 @@ func (s *ConsensusTestSuite) TestResetDKG() { req.NoError(seedGov.State().RequestChange( test.StateChangeDKGSetSize, uint32(4))) nodes := s.setupNodes(dMoment, prvKeys, seedGov) - // A round event handler to purge utils.NodeSetCache in test.Network. - purgeHandlerGen := func(n *test.Network) func([]utils.RoundEventParam) { - return func(evts []utils.RoundEventParam) { - for _, e := range evts { - if e.Reset == 0 { - continue - } - n.PurgeNodeSetCache(e.Round + 1) - } - } - } - // Round Height reference table: - // - Round:1 Reset:0 -- 100 - // - Round:1 Reset:1 -- 200 - // - Round:1 Reset:2 -- 300 - // - Round:2 Reset:0 -- 400 - // - Round:2 Reset:1 -- 500 - // - Round:3 Reset:0 -- 600 - // Register round event handler to prohibit/unprohibit DKG operation to - // governance. - roundHandlerGen := func(g *test.Governance) func([]utils.RoundEventParam) { - return func(evts []utils.RoundEventParam) { - trigger := func(e utils.RoundEventParam) { - // Make round 2 reseted until resetCount == 2. - if e.Round == 1 && e.Reset == 0 { - prohibitDKG(g) - } - if e.Round == 1 && e.Reset == 2 { - unprohibitDKG(g) - } - // Make round 3 reseted until resetCount == 1. - if e.Round == 2 && e.Reset == 0 { - // Allow DKG final this time. - g.Prohibit(test.StateAddDKGMasterPublicKey) - g.Prohibit(test.StateAddDKGComplaint) - } - if e.Round == 2 && e.Reset == 1 { - unprohibitDKG(g) - } - } - for _, e := range evts { - trigger(e) - } - } - } for _, n := range nodes { n.rEvt.Register(purgeHandlerGen(n.network)) - n.rEvt.Register(roundHandlerGen(n.gov)) + // Round Height reference table: + // - Round:1 Reset:0 -- 100 + // - Round:1 Reset:1 -- 200 + // - Round:1 Reset:2 -- 300 + // - Round:2 Reset:0 -- 400 + // - Round:2 Reset:1 -- 500 + // - Round:3 Reset:0 -- 600 + n.rEvt.Register(govHandlerGen(1, 0, n.gov, prohibitDKG)) + n.rEvt.Register(govHandlerGen(1, 2, n.gov, unprohibitDKG)) + n.rEvt.Register(govHandlerGen(2, 0, n.gov, prohibitDKGExceptFinalize)) + n.rEvt.Register(govHandlerGen(2, 1, n.gov, unprohibitDKG)) go n.con.Run() } Loop: diff --git a/integration_test/round-event_test.go b/integration_test/round-event_test.go index b0206ee..19832e8 100644 --- a/integration_test/round-event_test.go +++ b/integration_test/round-event_test.go @@ -115,7 +115,7 @@ func (s *RoundEventTestSuite) TestFromRound0() { gov.CatchUpWithRound(1) // Prepare utils.RoundEvent, starts from genesis. rEvt, err := utils.NewRoundEvent( - context.Background(), gov, s.logger, 0, 0, 0, core.ConfigRoundShift) + context.Background(), gov, s.logger, 0, 0, core.ConfigRoundShift) s.Require().NoError(err) // Register a handler to collects triggered events. var evts []evtParamToCheck @@ -146,13 +146,19 @@ func (s *RoundEventTestSuite) TestFromRound0() { func (s *RoundEventTestSuite) TestFromRoundN() { // Prepare test.Governance. - gov := s.prepareGov() + var ( + gov = s.prepareGov() + roundLength = uint64(100) + ) s.Require().NoError(gov.State().RequestChange(test.StateChangeRoundLength, - uint64(100))) - gov.CatchUpWithRound(22) + roundLength)) for r := uint64(2); r <= uint64(20); r++ { gov.ProposeCRS(r, getCRS(r, 0)) } + for r := uint64(0); r <= uint64(19); r++ { + gov.NotifyRound(r, r*roundLength) + } + gov.NotifyRound(20, 2200) // Reset round#20 twice, then make it done DKG preparation. gov.ResetDKG(getCRS(20, 1)) gov.ResetDKG(getCRS(20, 2)) @@ -169,7 +175,7 @@ func (s *RoundEventTestSuite) TestFromRoundN() { s.proposeFinalize(gov, 22, 0, 3) // Prepare utils.RoundEvent, starts from round#19, reset(for round#20)#1. rEvt, err := utils.NewRoundEvent(context.Background(), gov, s.logger, 19, - 1900, 2019, core.ConfigRoundShift) + 2019, core.ConfigRoundShift) s.Require().NoError(err) // Register a handler to collects triggered events. var evts []evtParamToCheck @@ -207,7 +213,7 @@ func (s *RoundEventTestSuite) TestLastPeriod() { gov.CatchUpWithRound(1) // Prepare utils.RoundEvent, starts from genesis. rEvt, err := utils.NewRoundEvent( - context.Background(), gov, s.logger, 0, 0, 0, core.ConfigRoundShift) + context.Background(), gov, s.logger, 0, 0, core.ConfigRoundShift) s.Require().NoError(err) begin, length := rEvt.LastPeriod() s.Require().Equal(begin, uint64(0)) @@ -237,7 +243,7 @@ func (s *RoundEventTestSuite) TestTriggerInitEvent() { gov.CatchUpWithRound(1) // Prepare utils.RoundEvent, starts from genesis. rEvt, err := utils.NewRoundEvent( - context.Background(), gov, s.logger, 0, 0, 0, core.ConfigRoundShift) + context.Background(), gov, s.logger, 0, 0, core.ConfigRoundShift) s.Require().NoError(err) // Register a handler to collects triggered events. var evts []evtParamToCheck |