diff options
author | Mission Liao <mission.liao@dexon.org> | 2019-04-01 12:25:09 +0800 |
---|---|---|
committer | Jimmy Hu <jimmy.hu@dexon.org> | 2019-04-01 12:25:09 +0800 |
commit | ecc5e12b1ac4826e302607769f5b831ab4c27046 (patch) | |
tree | e01fbf5d796c555f1d343e14023c282ad83bcba8 /integration_test | |
parent | 46f00c345dc0993cf888523e482ae0ff385c4391 (diff) | |
download | tangerine-consensus-ecc5e12b1ac4826e302607769f5b831ab4c27046.tar tangerine-consensus-ecc5e12b1ac4826e302607769f5b831ab4c27046.tar.gz tangerine-consensus-ecc5e12b1ac4826e302607769f5b831ab4c27046.tar.bz2 tangerine-consensus-ecc5e12b1ac4826e302607769f5b831ab4c27046.tar.lz tangerine-consensus-ecc5e12b1ac4826e302607769f5b831ab4c27046.tar.xz tangerine-consensus-ecc5e12b1ac4826e302607769f5b831ab4c27046.tar.zst tangerine-consensus-ecc5e12b1ac4826e302607769f5b831ab4c27046.zip |
core: clean TODOs (#539)
* core: fix block timestamp (#529)
* Remove TODO
dMoment is still required when the block timestamp of
the genesis block is still need to be verified.
* Refine timestamp when preparing blocks
* Add timestamp checking in sanity check
* Revert code to patch position when preparing
* Remove TODOs that seems meaningless now
* Remove TODOs related to refactoring
* core: remove finalization (#531)
- Remove types.FinalizationResult, randomness
field would be moved to `types.Block` directly.
- Add a placeholder for types.Block.Randomness
field for blocks proposed from
round < DKGDelayRound. (refer to core.NoRand)
- Make the height of the genesis block starts
from 1. (refer to types.GenesisHeight)
- The fullnode's behavior of
core.Governance.GetRoundHeight is (assume
round-length is 100):
- round: 0 -> 0 (we need to workaround this)
- round: 1 -> 101
- round: 2 -> 201
- test.Governance already simulate this
behavior, and the workaround is wrapped at
utils.GetRoundHeight.
* core: fix issues (#536)
fixing code in these condition:
- assigning position without initializing them
and expected it's for genesis
- compare height with 0
Diffstat (limited to 'integration_test')
-rw-r--r-- | integration_test/byzantine_test.go | 2 | ||||
-rw-r--r-- | integration_test/consensus_test.go | 21 | ||||
-rw-r--r-- | integration_test/round-event_test.go | 44 |
3 files changed, 34 insertions, 33 deletions
diff --git a/integration_test/byzantine_test.go b/integration_test/byzantine_test.go index 2395470..34c59f7 100644 --- a/integration_test/byzantine_test.go +++ b/integration_test/byzantine_test.go @@ -81,7 +81,7 @@ func (s *ByzantineTestSuite) setupNodes( ) gov := seedGov.Clone() gov.SwitchToRemoteMode(networkModule) - gov.NotifyRound(0, 0) + gov.NotifyRound(0, types.GenesisHeight) networkModule.AttachNodeSetCache(utils.NewNodeSetCache(gov)) f, err := os.Create(fmt.Sprintf("log.%d.log", i)) if err != nil { diff --git a/integration_test/consensus_test.go b/integration_test/consensus_test.go index 2c7f762..eab0c22 100644 --- a/integration_test/consensus_test.go +++ b/integration_test/consensus_test.go @@ -124,15 +124,15 @@ func (s *ConsensusTestSuite) setupNodes( ) gov := seedGov.Clone() gov.SwitchToRemoteMode(networkModule) - gov.NotifyRound(initRound, 0) + gov.NotifyRound(initRound, types.GenesisHeight) networkModule.AttachNodeSetCache(utils.NewNodeSetCache(gov)) f, err := os.Create(fmt.Sprintf("log.%d.log", i)) if err != nil { panic(err) } logger := common.NewCustomLogger(log.New(f, "", log.LstdFlags|log.Lmicroseconds)) - rEvt, err := utils.NewRoundEvent(context.Background(), gov, logger, 0, - 0, core.ConfigRoundShift) + rEvt, err := utils.NewRoundEvent(context.Background(), gov, logger, + types.Position{Height: types.GenesisHeight}, core.ConfigRoundShift) s.Require().NoError(err) nID := types.NewNodeID(k.PublicKey()) nodes[nID] = &node{ @@ -187,14 +187,13 @@ func (s *ConsensusTestSuite) syncBlocksWithSomeNode( syncerObj *syncer.Consensus, nextSyncHeight uint64) ( syncedCon *core.Consensus, syncerHeight uint64, err error) { - syncerHeight = nextSyncHeight // Setup revealer. DBAll, err := sourceNode.db.GetAllBlocks() if err != nil { return } - r, err := test.NewCompactionChainBlockRevealer(DBAll, nextSyncHeight) + r, err := test.NewBlockRevealerByPosition(DBAll, nextSyncHeight) if err != nil { return } @@ -212,7 +211,7 @@ func (s *ConsensusTestSuite) syncBlocksWithSomeNode( } // Sync app. syncNode.app.BlockConfirmed(*b) - syncNode.app.BlockDelivered(b.Hash, b.Position, b.Finalization) + syncNode.app.BlockDelivered(b.Hash, b.Position, b.Randomness) // Sync gov. syncNode.gov.CatchUpWithRound( b.Position.Round + core.ConfigRoundShift) @@ -241,7 +240,7 @@ func (s *ConsensusTestSuite) syncBlocksWithSomeNode( } break } - syncerHeight = b.Finalization.Height + 1 + syncerHeight = b.Position.Height + 1 compactionChainBlocks = append(compactionChainBlocks, &b) if len(compactionChainBlocks) >= 20 { if syncBlocks() { @@ -482,7 +481,7 @@ ReachAlive: // another go routine. go func() { var ( - syncedHeight uint64 + syncedHeight uint64 = 1 err error syncedCon *core.Consensus ) @@ -646,8 +645,10 @@ ReachStop: } targetNode := nodes[latestNodeID] for nID, node := range nodes { - syncedHeight := node.app.GetLatestDeliveredPosition().Height + 1 - // FinalizationHeight = Height + 1 + if nID == latestNodeID { + continue + } + syncedHeight := node.app.GetLatestDeliveredPosition().Height syncedHeight++ var err error for { diff --git a/integration_test/round-event_test.go b/integration_test/round-event_test.go index 19832e8..f83a437 100644 --- a/integration_test/round-event_test.go +++ b/integration_test/round-event_test.go @@ -114,8 +114,8 @@ func (s *RoundEventTestSuite) TestFromRound0() { uint64(200))) gov.CatchUpWithRound(1) // Prepare utils.RoundEvent, starts from genesis. - rEvt, err := utils.NewRoundEvent( - context.Background(), gov, s.logger, 0, 0, core.ConfigRoundShift) + rEvt, err := utils.NewRoundEvent(context.Background(), gov, s.logger, + types.Position{Height: types.GenesisHeight}, core.ConfigRoundShift) s.Require().NoError(err) // Register a handler to collects triggered events. var evts []evtParamToCheck @@ -139,9 +139,9 @@ func (s *RoundEventTestSuite) TestFromRound0() { s.Require().Equal(rEvt.ValidateNextRound(80), uint(3)) // Check collected events. s.Require().Len(evts, 3) - s.Require().Equal(evts[0], evtParamToCheck{0, 1, 100, gov.CRS(0)}) - s.Require().Equal(evts[1], evtParamToCheck{0, 2, 200, gov.CRS(0)}) - s.Require().Equal(evts[2], evtParamToCheck{1, 0, 300, gov.CRS(1)}) + s.Require().Equal(evts[0], evtParamToCheck{0, 1, 101, gov.CRS(0)}) + s.Require().Equal(evts[1], evtParamToCheck{0, 2, 201, gov.CRS(0)}) + s.Require().Equal(evts[2], evtParamToCheck{1, 0, 301, gov.CRS(1)}) } func (s *RoundEventTestSuite) TestFromRoundN() { @@ -155,10 +155,10 @@ func (s *RoundEventTestSuite) TestFromRoundN() { 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) + for r := uint64(1); r <= uint64(19); r++ { + gov.NotifyRound(r, utils.GetRoundHeight(gov, r-1)+roundLength) } - gov.NotifyRound(20, 2200) + gov.NotifyRound(20, 2201) // Reset round#20 twice, then make it done DKG preparation. gov.ResetDKG(getCRS(20, 1)) gov.ResetDKG(getCRS(20, 2)) @@ -174,8 +174,8 @@ func (s *RoundEventTestSuite) TestFromRoundN() { s.proposeMPK(gov, 22, 0, 3) 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, - 2019, core.ConfigRoundShift) + rEvt, err := utils.NewRoundEvent(context.Background(), gov, s.logger, + types.Position{Round: 19, Height: 2019}, core.ConfigRoundShift) s.Require().NoError(err) // Register a handler to collects triggered events. var evts []evtParamToCheck @@ -193,14 +193,14 @@ func (s *RoundEventTestSuite) TestFromRoundN() { s.Require().Equal(rEvt.ValidateNextRound(2080), uint(2)) // Check collected events. s.Require().Len(evts, 2) - s.Require().Equal(evts[0], evtParamToCheck{19, 2, 2100, gov.CRS(19)}) - s.Require().Equal(evts[1], evtParamToCheck{20, 0, 2200, gov.CRS(20)}) + s.Require().Equal(evts[0], evtParamToCheck{19, 2, 2101, gov.CRS(19)}) + s.Require().Equal(evts[1], evtParamToCheck{20, 0, 2201, gov.CRS(20)}) // Round might exceed round-shift limitation would not be triggered. s.Require().Equal(rEvt.ValidateNextRound(2280), uint(1)) s.Require().Len(evts, 3) - s.Require().Equal(evts[2], evtParamToCheck{21, 0, 2300, gov.CRS(21)}) + s.Require().Equal(evts[2], evtParamToCheck{21, 0, 2301, gov.CRS(21)}) s.Require().Equal(rEvt.ValidateNextRound(2380), uint(1)) - s.Require().Equal(evts[3], evtParamToCheck{22, 0, 2400, gov.CRS(22)}) + s.Require().Equal(evts[3], evtParamToCheck{22, 0, 2401, gov.CRS(22)}) } func (s *RoundEventTestSuite) TestLastPeriod() { @@ -212,24 +212,24 @@ func (s *RoundEventTestSuite) TestLastPeriod() { uint64(200))) gov.CatchUpWithRound(1) // Prepare utils.RoundEvent, starts from genesis. - rEvt, err := utils.NewRoundEvent( - context.Background(), gov, s.logger, 0, 0, core.ConfigRoundShift) + rEvt, err := utils.NewRoundEvent(context.Background(), gov, s.logger, + types.Position{Height: types.GenesisHeight}, core.ConfigRoundShift) s.Require().NoError(err) begin, length := rEvt.LastPeriod() - s.Require().Equal(begin, uint64(0)) + s.Require().Equal(begin, uint64(1)) s.Require().Equal(length, uint64(100)) // Reset round#1 twice, then make it ready. gov.ResetDKG([]byte("DKG round 1 reset 1")) gov.ResetDKG([]byte("DKG round 1 reset 2")) rEvt.ValidateNextRound(80) begin, length = rEvt.LastPeriod() - s.Require().Equal(begin, uint64(200)) + s.Require().Equal(begin, uint64(201)) s.Require().Equal(length, uint64(100)) s.proposeMPK(gov, 1, 2, 3) s.proposeFinalize(gov, 1, 2, 3) rEvt.ValidateNextRound(80) begin, length = rEvt.LastPeriod() - s.Require().Equal(begin, uint64(300)) + s.Require().Equal(begin, uint64(301)) s.Require().Equal(length, uint64(200)) } @@ -242,8 +242,8 @@ func (s *RoundEventTestSuite) TestTriggerInitEvent() { uint64(200))) gov.CatchUpWithRound(1) // Prepare utils.RoundEvent, starts from genesis. - rEvt, err := utils.NewRoundEvent( - context.Background(), gov, s.logger, 0, 0, core.ConfigRoundShift) + rEvt, err := utils.NewRoundEvent(context.Background(), gov, s.logger, + types.Position{Height: types.GenesisHeight}, core.ConfigRoundShift) s.Require().NoError(err) // Register a handler to collects triggered events. var evts []evtParamToCheck @@ -259,7 +259,7 @@ func (s *RoundEventTestSuite) TestTriggerInitEvent() { }) rEvt.TriggerInitEvent() s.Require().Len(evts, 1) - s.Require().Equal(evts[0], evtParamToCheck{0, 0, 0, gov.CRS(0)}) + s.Require().Equal(evts[0], evtParamToCheck{0, 0, 1, gov.CRS(0)}) } func TestRoundEvent(t *testing.T) { |