diff options
author | Jimmy Hu <jimmy.hu@dexon.org> | 2019-03-04 18:30:03 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-04 18:30:03 +0800 |
commit | d4b4c8a05e94f66c85e7b4238ae5947b26f13c40 (patch) | |
tree | c2a10260820ac3a152506000aa03c41cd244d84f | |
parent | 603f8d6d999c1bb5b16c2f5dfc88f8bc9da7fc33 (diff) | |
download | dexon-consensus-d4b4c8a05e94f66c85e7b4238ae5947b26f13c40.tar dexon-consensus-d4b4c8a05e94f66c85e7b4238ae5947b26f13c40.tar.gz dexon-consensus-d4b4c8a05e94f66c85e7b4238ae5947b26f13c40.tar.bz2 dexon-consensus-d4b4c8a05e94f66c85e7b4238ae5947b26f13c40.tar.lz dexon-consensus-d4b4c8a05e94f66c85e7b4238ae5947b26f13c40.tar.xz dexon-consensus-d4b4c8a05e94f66c85e7b4238ae5947b26f13c40.tar.zst dexon-consensus-d4b4c8a05e94f66c85e7b4238ae5947b26f13c40.zip |
core: first few round will not have DKG (#455)
* core: Add DKGDelayRound constant
* core: use constant value
* core, utils: set DKGDelayRound for utils.
* test: add dkgDelayRound to state
* core: do not run dkg and crs for round < DKGDelayRound
* fix test
-rw-r--r-- | core/blockchain.go | 4 | ||||
-rw-r--r-- | core/configuration-chain_test.go | 18 | ||||
-rw-r--r-- | core/consensus.go | 55 | ||||
-rw-r--r-- | core/consensus_test.go | 4 | ||||
-rw-r--r-- | core/constant.go | 12 | ||||
-rw-r--r-- | core/dkg-tsig-protocol_test.go | 18 | ||||
-rw-r--r-- | core/syncer/agreement_test.go | 4 | ||||
-rw-r--r-- | core/test/governance_test.go | 6 | ||||
-rw-r--r-- | core/test/network_test.go | 2 | ||||
-rw-r--r-- | core/test/state.go | 8 | ||||
-rw-r--r-- | core/test/state_test.go | 31 | ||||
-rw-r--r-- | core/utils/nodeset-cache.go | 12 | ||||
-rw-r--r-- | core/utils/utils.go | 7 | ||||
-rw-r--r-- | core/utils_test.go | 2 | ||||
-rw-r--r-- | integration_test/byzantine_test.go | 2 | ||||
-rw-r--r-- | integration_test/consensus_test.go | 6 | ||||
-rw-r--r-- | simulation/node.go | 2 |
17 files changed, 100 insertions, 93 deletions
diff --git a/core/blockchain.go b/core/blockchain.go index bc9616c..03c8561 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -188,7 +188,7 @@ func (bc *blockChain) extractBlocks() (ret []*types.Block) { defer bc.lock.Unlock() for len(bc.confirmedBlocks) > 0 { c := bc.confirmedBlocks[0] - if c.Position.Round > 0 && len(c.Finalization.Randomness) == 0 { + if c.Position.Round >= DKGDelayRound && len(c.Finalization.Randomness) == 0 { break } c, bc.confirmedBlocks = bc.confirmedBlocks[0], bc.confirmedBlocks[1:] @@ -502,7 +502,7 @@ func (bc *blockChain) purgeConfig() { func (bc *blockChain) verifyRandomness( blockHash common.Hash, round uint64, randomness []byte) (bool, error) { - if round == 0 { + if round < DKGDelayRound { return len(randomness) == 0, nil } v, ok, err := bc.vGetter.UpdateAndGet(round) diff --git a/core/configuration-chain_test.go b/core/configuration-chain_test.go index 1fe54bc..939cf65 100644 --- a/core/configuration-chain_test.go +++ b/core/configuration-chain_test.go @@ -202,7 +202,7 @@ func (s *ConfigurationChainTestSuite) runDKG( recv := newTestCCGlobalReceiver(s) for _, nID := range s.nIDs { - gov, err := test.NewGovernance(test.NewState( + gov, err := test.NewGovernance(test.NewState(DKGDelayRound, s.pubKeys, 100*time.Millisecond, &common.NullLogger{}, true, ), ConfigRoundShift) s.Require().NoError(err) @@ -271,7 +271,7 @@ func (s *ConfigurationChainTestSuite) preparePartialSignature( func (s *ConfigurationChainTestSuite) TestConfigurationChain() { k := 4 n := 10 - round := uint64(0) + round := DKGDelayRound cfgChains := s.runDKG(k, n, round) hash := crypto.Keccak256Hash([]byte("🌚🌝")) @@ -316,7 +316,7 @@ func (s *ConfigurationChainTestSuite) TestConfigurationChain() { func (s *ConfigurationChainTestSuite) TestDKGMasterPublicKeyDelayAdd() { k := 4 n := 10 - round := uint64(0) + round := DKGDelayRound lambdaDKG := 1000 * time.Millisecond s.setupNodes(n) @@ -325,7 +325,7 @@ func (s *ConfigurationChainTestSuite) TestDKGMasterPublicKeyDelayAdd() { delayNode := s.nIDs[0] for _, nID := range s.nIDs { - state := test.NewState( + state := test.NewState(DKGDelayRound, s.pubKeys, 100*time.Millisecond, &common.NullLogger{}, true) gov, err := test.NewGovernance(state, ConfigRoundShift) s.Require().NoError(err) @@ -382,7 +382,7 @@ func (s *ConfigurationChainTestSuite) TestDKGMasterPublicKeyDelayAdd() { func (s *ConfigurationChainTestSuite) TestDKGComplaintDelayAdd() { k := 4 n := 10 - round := uint64(0) + round := DKGDelayRound lambdaDKG := 1000 * time.Millisecond s.setupNodes(n) @@ -390,7 +390,7 @@ func (s *ConfigurationChainTestSuite) TestDKGComplaintDelayAdd() { recv := newTestCCGlobalReceiver(s) recvs := make(map[types.NodeID]*testCCReceiver) for _, nID := range s.nIDs { - state := test.NewState( + state := test.NewState(DKGDelayRound, s.pubKeys, 100*time.Millisecond, &common.NullLogger{}, true) gov, err := test.NewGovernance(state, ConfigRoundShift) s.Require().NoError(err) @@ -458,7 +458,7 @@ func (s *ConfigurationChainTestSuite) TestDKGComplaintDelayAdd() { func (s *ConfigurationChainTestSuite) TestMultipleTSig() { k := 2 n := 7 - round := uint64(0) + round := DKGDelayRound cfgChains := s.runDKG(k, n, round) hash1 := crypto.Keccak256Hash([]byte("Hash1")) @@ -518,7 +518,7 @@ func (s *ConfigurationChainTestSuite) TestMultipleTSig() { func (s *ConfigurationChainTestSuite) TestTSigTimeout() { k := 2 n := 7 - round := uint64(0) + round := DKGDelayRound cfgChains := s.runDKG(k, n, round) timeout := 6 * time.Second @@ -555,7 +555,7 @@ func (s *ConfigurationChainTestSuite) TestTSigTimeout() { func (s *ConfigurationChainTestSuite) TestDKGSignerRecoverFromDB() { k := 2 n := 7 - round := uint64(0) + round := DKGDelayRound cfgChains := s.runDKG(k, n, round) hash := crypto.Keccak256Hash([]byte("Hash1")) // Make sure we have more than one configurationChain instance. diff --git a/core/consensus.go b/core/consensus.go index 25fc16d..370df72 100644 --- a/core/consensus.go +++ b/core/consensus.go @@ -599,25 +599,8 @@ func (con *Consensus) prepare( return } if initRound == 0 { - dkgSet, err := con.nodeSetCache.GetDKGSet(initRound) - if err != nil { - return err - } - if _, exist := dkgSet[con.ID]; exist { - con.logger.Info("Selected as DKG set", "round", initRound) - go func() { - // Sleep until dMoment come. - time.Sleep(con.dMoment.Sub(time.Now().UTC())) - // Network is not stable upon starting. Wait some time to ensure first - // DKG would success. Three is a magic number. - time.Sleep(initConfig.MinBlockInterval * 3) - con.cfgModule.registerDKG(initRound, getDKGThreshold(initConfig)) - con.event.RegisterHeight( - initConfig.RoundLength/4, - func(uint64) { - con.runDKG(initRound, initConfig) - }) - }() + if DKGDelayRound == 0 { + panic("not implemented yet") } } // Register events. @@ -747,20 +730,22 @@ func (con *Consensus) initialRound( return default: } - curDkgSet, err := con.nodeSetCache.GetDKGSet(round) - if err != nil { - con.logger.Error("Error getting DKG set", "round", round, "error", err) - curDkgSet = make(map[types.NodeID]struct{}) - } - // Initiate CRS routine. - if _, exist := curDkgSet[con.ID]; exist { - con.event.RegisterHeight( - startHeight+config.RoundLength/2, - func(uint64) { - go func() { - con.runCRS(round) - }() - }) + if round >= DKGDelayRound { + curDkgSet, err := con.nodeSetCache.GetDKGSet(round) + if err != nil { + con.logger.Error("Error getting DKG set", "round", round, "error", err) + curDkgSet = make(map[types.NodeID]struct{}) + } + // Initiate CRS routine. + if _, exist := curDkgSet[con.ID]; exist { + con.event.RegisterHeight( + startHeight+config.RoundLength/2, + func(uint64) { + go func() { + con.runCRS(round) + }() + }) + } } // checkCRS is a generator of checker to check if CRS for that round is // ready or not. @@ -800,6 +785,10 @@ func (con *Consensus) initialRound( // Initiate DKG for this round. con.event.RegisterHeight(startHeight+config.RoundLength/2, func(uint64) { go func(nextRound uint64) { + if nextRound < DKGDelayRound { + con.logger.Info("Skip runDKG for round", "round", nextRound) + return + } // Normally, gov.CRS would return non-nil. Use this for in case of // unexpected network fluctuation and ensure the robustness. if !checkWithCancel( diff --git a/core/consensus_test.go b/core/consensus_test.go index 1cad67b..b758c77 100644 --- a/core/consensus_test.go +++ b/core/consensus_test.go @@ -216,7 +216,7 @@ func (s *ConsensusTestSuite) TestDKGCRS() { conn := s.newNetworkConnection() prvKeys, pubKeys, err := test.NewKeys(n) s.Require().NoError(err) - gov, err := test.NewGovernance(test.NewState( + gov, err := test.NewGovernance(test.NewState(DKGDelayRound, pubKeys, lambda, &common.NullLogger{}, true), ConfigRoundShift) s.Require().NoError(err) gov.State().RequestChange(test.StateChangeRoundLength, uint64(200)) @@ -258,7 +258,7 @@ func (s *ConsensusTestSuite) TestSyncBA() { conn := s.newNetworkConnection() prvKeys, pubKeys, err := test.NewKeys(4) s.Require().NoError(err) - gov, err := test.NewGovernance(test.NewState( + gov, err := test.NewGovernance(test.NewState(DKGDelayRound, pubKeys, lambdaBA, &common.NullLogger{}, true), ConfigRoundShift) s.Require().NoError(err) prvKey := prvKeys[0] diff --git a/core/constant.go b/core/constant.go index 563a321..f80e1b9 100644 --- a/core/constant.go +++ b/core/constant.go @@ -17,9 +17,21 @@ package core +import "github.com/dexon-foundation/dexon-consensus/core/utils" + // ConfigRoundShift refers to the difference between block's round and config // round derived from its state. // // For example, when round shift is 2, a block in round 0 should derive config // for round 2. const ConfigRoundShift uint64 = 2 + +// DKGDelayRound refers to the round that first DKG is run. +// +// For example, when delay round is 1, new DKG will run at round 1. Round 0 will +// have neither DKG nor CRS. +const DKGDelayRound uint64 = 1 + +func init() { + utils.SetDKGDelayRound(DKGDelayRound) +} diff --git a/core/dkg-tsig-protocol_test.go b/core/dkg-tsig-protocol_test.go index 4086267..445a51c 100644 --- a/core/dkg-tsig-protocol_test.go +++ b/core/dkg-tsig-protocol_test.go @@ -148,7 +148,7 @@ func (s *DKGTSIGProtocolTestSuite) TestDKGTSIGProtocol() { round := uint64(1) _, pubKeys, err := test.NewKeys(5) s.Require().NoError(err) - gov, err := test.NewGovernance(test.NewState( + gov, err := test.NewGovernance(test.NewState(DKGDelayRound, pubKeys, 100, &common.NullLogger{}, true), ConfigRoundShift) s.Require().NoError(err) @@ -253,7 +253,7 @@ func (s *DKGTSIGProtocolTestSuite) TestNackComplaint() { round := uint64(1) _, pubKeys, err := test.NewKeys(5) s.Require().NoError(err) - gov, err := test.NewGovernance(test.NewState( + gov, err := test.NewGovernance(test.NewState(DKGDelayRound, pubKeys, 100, &common.NullLogger{}, true), ConfigRoundShift) s.Require().NoError(err) @@ -300,7 +300,7 @@ func (s *DKGTSIGProtocolTestSuite) TestComplaint() { round := uint64(1) _, pubKeys, err := test.NewKeys(5) s.Require().NoError(err) - gov, err := test.NewGovernance(test.NewState( + gov, err := test.NewGovernance(test.NewState(DKGDelayRound, pubKeys, 100, &common.NullLogger{}, true), ConfigRoundShift) s.Require().NoError(err) @@ -365,7 +365,7 @@ func (s *DKGTSIGProtocolTestSuite) TestDuplicateComplaint() { round := uint64(1) _, pubKeys, err := test.NewKeys(5) s.Require().NoError(err) - gov, err := test.NewGovernance(test.NewState( + gov, err := test.NewGovernance(test.NewState(DKGDelayRound, pubKeys, 100, &common.NullLogger{}, true), ConfigRoundShift) s.Require().NoError(err) @@ -408,7 +408,7 @@ func (s *DKGTSIGProtocolTestSuite) TestAntiComplaint() { round := uint64(1) _, pubKeys, err := test.NewKeys(5) s.Require().NoError(err) - gov, err := test.NewGovernance(test.NewState( + gov, err := test.NewGovernance(test.NewState(DKGDelayRound, pubKeys, 100, &common.NullLogger{}, true), ConfigRoundShift) s.Require().NoError(err) @@ -466,7 +466,7 @@ func (s *DKGTSIGProtocolTestSuite) TestEncorceNackComplaint() { round := uint64(1) _, pubKeys, err := test.NewKeys(5) s.Require().NoError(err) - gov, err := test.NewGovernance(test.NewState( + gov, err := test.NewGovernance(test.NewState(DKGDelayRound, pubKeys, 100, &common.NullLogger{}, true), ConfigRoundShift) s.Require().NoError(err) @@ -521,7 +521,7 @@ func (s *DKGTSIGProtocolTestSuite) TestQualifyIDs() { round := uint64(1) _, pubKeys, err := test.NewKeys(5) s.Require().NoError(err) - gov, err := test.NewGovernance(test.NewState( + gov, err := test.NewGovernance(test.NewState(DKGDelayRound, pubKeys, 100, &common.NullLogger{}, true), ConfigRoundShift) s.Require().NoError(err) @@ -587,7 +587,7 @@ func (s *DKGTSIGProtocolTestSuite) TestPartialSignature() { round := uint64(1) _, pubKeys, err := test.NewKeys(5) s.Require().NoError(err) - gov, err := test.NewGovernance(test.NewState( + gov, err := test.NewGovernance(test.NewState(DKGDelayRound, pubKeys, 100, &common.NullLogger{}, true), ConfigRoundShift) s.Require().NoError(err) @@ -724,7 +724,7 @@ func (s *DKGTSIGProtocolTestSuite) TestTSigVerifierCache() { n := 10 _, pubKeys, err := test.NewKeys(n) s.Require().NoError(err) - gov, err := test.NewGovernance(test.NewState( + gov, err := test.NewGovernance(test.NewState(DKGDelayRound, pubKeys, 100, &common.NullLogger{}, true), ConfigRoundShift) s.Require().NoError(err) gov.CatchUpWithRound(10) diff --git a/core/syncer/agreement_test.go b/core/syncer/agreement_test.go index 4e66f8b..0a12b3c 100644 --- a/core/syncer/agreement_test.go +++ b/core/syncer/agreement_test.go @@ -78,13 +78,13 @@ func (s *AgreementTestSuite) TestFutureAgreementResult() { pos = types.Position{Round: 7, Height: 1000} ) gov, err := test.NewGovernance( - test.NewState(s.pubKeys, time.Second, &common.NullLogger{}, true), + test.NewState(1, s.pubKeys, time.Second, &common.NullLogger{}, true), core.ConfigRoundShift, ) s.Require().NoError(err) // Make sure goverance is ready for some future round, including CRS. gov.CatchUpWithRound(futureRound) - for i := uint64(1); i <= futureRound; i++ { + for i := uint64(2); i <= futureRound; i++ { gov.ProposeCRS(i, common.NewRandomHash().Bytes()) } s.Require().NoError(err) diff --git a/core/test/governance_test.go b/core/test/governance_test.go index e0a2365..af2b5c5 100644 --- a/core/test/governance_test.go +++ b/core/test/governance_test.go @@ -35,11 +35,11 @@ func (s *GovernanceTestSuite) TestEqual() { _, genesisNodes, err := NewKeys(20) req.NoError(err) g1, err := NewGovernance(NewState( - genesisNodes, 100*time.Millisecond, &common.NullLogger{}, true), 2) + 1, genesisNodes, 100*time.Millisecond, &common.NullLogger{}, true), 2) req.NoError(err) // Create a governance with different lambda. g2, err := NewGovernance(NewState( - genesisNodes, 50*time.Millisecond, &common.NullLogger{}, true), 2) + 1, genesisNodes, 50*time.Millisecond, &common.NullLogger{}, true), 2) req.NoError(err) req.False(g1.Equal(g2, true)) // Create configs for 3 rounds for g1. @@ -72,7 +72,7 @@ func (s *GovernanceTestSuite) TestRegisterChange() { _, genesisNodes, err := NewKeys(20) req.NoError(err) g, err := NewGovernance(NewState( - genesisNodes, 100*time.Millisecond, &common.NullLogger{}, true), 2) + 1, genesisNodes, 100*time.Millisecond, &common.NullLogger{}, true), 2) req.NoError(err) // Unable to register change for genesis round. req.Error(g.RegisterConfigChange(0, StateChangeDKGSetSize, uint32(32))) diff --git a/core/test/network_test.go b/core/test/network_test.go index 22c31a8..3e9b557 100644 --- a/core/test/network_test.go +++ b/core/test/network_test.go @@ -248,7 +248,7 @@ func (s *NetworkTestSuite) TestBroadcastToSet() { _, pubKeys, err := NewKeys(peerCount) req.NoError(err) gov, err := NewGovernance(NewState( - pubKeys, time.Second, &common.NullLogger{}, true), 2) + 1, pubKeys, time.Second, &common.NullLogger{}, true), 2) req.NoError(err) req.NoError(gov.State().RequestChange(StateChangeDKGSetSize, uint32(1))) req.NoError(gov.State().RequestChange(StateChangeNotarySetSize, uint32(1))) diff --git a/core/test/state.go b/core/test/state.go index f1cf365..fbf4505 100644 --- a/core/test/state.go +++ b/core/test/state.go @@ -117,6 +117,7 @@ type State struct { // - node set // - crs func NewState( + dkgDelayRound uint64, nodePubKeys []crypto.PublicKey, lambda time.Duration, logger common.Logger, @@ -126,6 +127,11 @@ func NewState( nodes[types.NewNodeID(key)] = key } genesisCRS := crypto.Keccak256Hash([]byte("__ DEXON")) + crs := make([]common.Hash, dkgDelayRound+1) + for i := range crs { + crs[i] = genesisCRS + genesisCRS = crypto.Keccak256Hash(genesisCRS[:]) + } return &State{ local: local, logger: logger, @@ -133,7 +139,7 @@ func NewState( lambdaDKG: lambda * 10, roundInterval: 1000, minBlockInterval: 4 * lambda, - crs: []common.Hash{genesisCRS}, + crs: crs, nodes: nodes, notarySetSize: uint32(len(nodes)), dkgSetSize: uint32(len(nodes)), diff --git a/core/test/state_test.go b/core/test/state_test.go index ad3a1d6..8d2b2a2 100644 --- a/core/test/state_test.go +++ b/core/test/state_test.go @@ -160,10 +160,10 @@ func (s *StateTestSuite) TestEqual() { ) _, genesisNodes, err := NewKeys(20) req.NoError(err) - st := NewState(genesisNodes, lambda, &common.NullLogger{}, true) + st := NewState(1, genesisNodes, lambda, &common.NullLogger{}, true) req.NoError(st.Equal(st)) // One node is missing. - st1 := NewState(genesisNodes, lambda, &common.NullLogger{}, true) + st1 := NewState(1, genesisNodes, lambda, &common.NullLogger{}, true) for nID := range st1.nodes { delete(st1.nodes, nID) break @@ -174,7 +174,6 @@ func (s *StateTestSuite) TestEqual() { req.NoError(st.Equal(st2)) s.makeConfigChanges(st) req.Equal(st.Equal(st2), ErrStateConfigNotEqual) - req.NoError(st.ProposeCRS(1, common.NewRandomHash())) req.NoError(st.ProposeCRS(2, common.NewRandomHash())) req.NoError(st.RequestChange(StateResetDKG, common.NewRandomHash())) masterPubKey := s.newDKGMasterPublicKey(2) @@ -230,12 +229,12 @@ func (s *StateTestSuite) TestPendingChangesEqual() { // Setup a non-local mode State instance. _, genesisNodes, err := NewKeys(20) req.NoError(err) - st := NewState(genesisNodes, lambda, &common.NullLogger{}, false) + st := NewState(1, genesisNodes, lambda, &common.NullLogger{}, false) req.NoError(st.Equal(st)) // Apply some changes. s.makeConfigChanges(st) crs := common.NewRandomHash() - req.NoError(st.ProposeCRS(1, crs)) + req.NoError(st.ProposeCRS(2, crs)) masterPubKey := s.newDKGMasterPublicKey(2) ready := s.newDKGMPKReady(2) comp := s.newDKGComplaint(2) @@ -251,7 +250,7 @@ func (s *StateTestSuite) TestLocalMode() { ) _, genesisNodes, err := NewKeys(20) req.NoError(err) - st := NewState(genesisNodes, lambda, &common.NullLogger{}, true) + st := NewState(1, genesisNodes, lambda, &common.NullLogger{}, true) config1, nodes1 := st.Snapshot() req.True(s.compareNodes(genesisNodes, nodes1)) // Check settings of config1 affected by genesisNodes and lambda. @@ -274,9 +273,6 @@ func (s *StateTestSuite) TestLocalMode() { req.True(s.findNode(newNodes, pubKey)) // Test adding CRS. crs := common.NewRandomHash() - req.NoError(st.ProposeCRS(1, crs)) - req.Equal(st.CRS(1), crs) - crs = common.NewRandomHash() req.NoError(st.ProposeCRS(2, crs)) req.Equal(st.CRS(2), crs) // Test adding node set, DKG complaints, final, master public key. @@ -335,16 +331,11 @@ func (s *StateTestSuite) TestPacking() { // Make config changes. _, genesisNodes, err := NewKeys(20) req.NoError(err) - st := NewState(genesisNodes, lambda, &common.NullLogger{}, false) + st := NewState(1, genesisNodes, lambda, &common.NullLogger{}, false) s.makeConfigChanges(st) // Add new CRS. crs := common.NewRandomHash() - req.NoError(st.ProposeCRS(1, crs)) - packAndApply(st) - // Check if CRS is added. - req.Equal(st.CRS(1), crs) - crs2 := common.NewRandomHash() - req.NoError(st.ProposeCRS(2, crs2)) + req.NoError(st.ProposeCRS(2, crs)) // Add new node. prvKey, err := ecdsa.NewPrivateKey() req.NoError(err) @@ -366,7 +357,7 @@ func (s *StateTestSuite) TestPacking() { config, nodes := st.Snapshot() s.checkConfigChanges(config) // Check if CRS is added. - req.Equal(st.CRS(2), crs2) + req.Equal(st.CRS(2), crs) // Check if new node is added. req.True(s.findNode(nodes, pubKey)) // Check DKGMasterPublicKeys. @@ -409,14 +400,14 @@ func (s *StateTestSuite) TestRequestBroadcastAndPack() { ) _, genesisNodes, err := NewKeys(20) req.NoError(err) - st := NewState(genesisNodes, lambda, &common.NullLogger{}, false) - st1 := NewState(genesisNodes, lambda, &common.NullLogger{}, false) + st := NewState(1, genesisNodes, lambda, &common.NullLogger{}, false) + st1 := NewState(1, genesisNodes, lambda, &common.NullLogger{}, false) req.NoError(st.Equal(st1)) // Make configuration changes. s.makeConfigChanges(st) // Add new CRS. crs := common.NewRandomHash() - req.NoError(st.ProposeCRS(1, crs)) + req.NoError(st.ProposeCRS(2, crs)) // Add new node. prvKey, err := ecdsa.NewPrivateKey() req.NoError(err) diff --git a/core/utils/nodeset-cache.go b/core/utils/nodeset-cache.go index 0e616e4..6249665 100644 --- a/core/utils/nodeset-cache.go +++ b/core/utils/nodeset-cache.go @@ -223,13 +223,15 @@ func (cache *NodeSetCache) update(round uint64) (nIDs *sets, err error) { return } nIDs = &sets{ - crs: crs, - nodeSet: nodeSet, - notarySet: make(map[types.NodeID]struct{}), - dkgSet: nodeSet.GetSubSet( - int(cfg.DKGSetSize), types.NewDKGSetTarget(crs)), + crs: crs, + nodeSet: nodeSet, + notarySet: make(map[types.NodeID]struct{}), leaderNode: make(map[uint64]types.NodeID, cfg.RoundLength), } + if round >= dkgDelayRound { + nIDs.dkgSet = nodeSet.GetSubSet( + int(cfg.DKGSetSize), types.NewDKGSetTarget(crs)) + } nIDs.notarySet = nodeSet.GetSubSet( int(cfg.NotarySetSize), types.NewNotarySetTarget(crs)) cache.rounds[round] = nIDs diff --git a/core/utils/utils.go b/core/utils/utils.go index 8486d28..203f57f 100644 --- a/core/utils/utils.go +++ b/core/utils/utils.go @@ -26,6 +26,13 @@ import ( typesDKG "github.com/dexon-foundation/dexon-consensus/core/types/dkg" ) +var dkgDelayRound uint64 + +// SetDKGDelayRound sets the variable. +func SetDKGDelayRound(delay uint64) { + dkgDelayRound = delay +} + type configAccessor interface { Configuration(round uint64) *types.Config } diff --git a/core/utils_test.go b/core/utils_test.go index c53a38f..560e923 100644 --- a/core/utils_test.go +++ b/core/utils_test.go @@ -48,7 +48,7 @@ func (s *UtilsTestSuite) TestRemoveFromSortedUint32Slice() { func (s *UtilsTestSuite) TestVerifyAgreementResult() { prvKeys, pubKeys, err := test.NewKeys(4) s.Require().NoError(err) - gov, err := test.NewGovernance(test.NewState( + gov, err := test.NewGovernance(test.NewState(DKGDelayRound, pubKeys, time.Second, &common.NullLogger{}, true), ConfigRoundShift) s.Require().NoError(err) cache := utils.NewNodeSetCache(gov) diff --git a/integration_test/byzantine_test.go b/integration_test/byzantine_test.go index 1e5a2a9..c90c9a1 100644 --- a/integration_test/byzantine_test.go +++ b/integration_test/byzantine_test.go @@ -139,7 +139,7 @@ func (s *ByzantineTestSuite) TestOneSlowNodeOneDeadNode() { // run faster. lambda := 100 * time.Millisecond seedGov, err := test.NewGovernance( - test.NewState( + test.NewState(core.DKGDelayRound, pubKeys, lambda, &common.NullLogger{}, true), core.ConfigRoundShift) req.NoError(err) diff --git a/integration_test/consensus_test.go b/integration_test/consensus_test.go index b469859..4f916c3 100644 --- a/integration_test/consensus_test.go +++ b/integration_test/consensus_test.go @@ -210,7 +210,7 @@ func (s *ConsensusTestSuite) TestSimple() { // Setup seed governance instance. Give a short latency to make this test // run faster. seedGov, err := test.NewGovernance( - test.NewState( + test.NewState(core.DKGDelayRound, pubKeys, 100*time.Millisecond, &common.NullLogger{}, true), core.ConfigRoundShift) req.NoError(err) @@ -255,7 +255,7 @@ func (s *ConsensusTestSuite) TestSetSizeChange() { req.NoError(err) // Setup seed governance instance. seedGov, err := test.NewGovernance( - test.NewState(pubKeys, 100*time.Millisecond, &common.NullLogger{}, true), + test.NewState(core.DKGDelayRound, pubKeys, 100*time.Millisecond, &common.NullLogger{}, true), core.ConfigRoundShift) req.NoError(err) req.NoError(seedGov.State().RequestChange( @@ -350,7 +350,7 @@ func (s *ConsensusTestSuite) TestSync() { // Setup seed governance instance. Give a short latency to make this test // run faster. seedGov, err := test.NewGovernance( - test.NewState( + test.NewState(core.DKGDelayRound, pubKeys, 100*time.Millisecond, &common.NullLogger{}, true), core.ConfigRoundShift) req.NoError(err) diff --git a/simulation/node.go b/simulation/node.go index 758f980..fc5be90 100644 --- a/simulation/node.go +++ b/simulation/node.go @@ -90,7 +90,7 @@ func newNode(prvKey crypto.PrivateKey, logger common.Logger, } // Sync config to state in governance. gov, err := test.NewGovernance( - test.NewState( + test.NewState(core.DKGDelayRound, []crypto.PublicKey{pubKey}, time.Millisecond, logger, true), core.ConfigRoundShift) if err != nil { |