diff options
author | Jimmy Hu <jimmy.hu@dexon.org> | 2018-10-25 09:55:59 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-25 09:55:59 +0800 |
commit | 9839a1c6fecbada7d1736680930c3e527f984470 (patch) | |
tree | 400c69e60c132dd5101f125eda7114e4bb098b45 /core | |
parent | 14b91441825d6b990527e947c021a5311e951c25 (diff) | |
download | dexon-consensus-9839a1c6fecbada7d1736680930c3e527f984470.tar dexon-consensus-9839a1c6fecbada7d1736680930c3e527f984470.tar.gz dexon-consensus-9839a1c6fecbada7d1736680930c3e527f984470.tar.bz2 dexon-consensus-9839a1c6fecbada7d1736680930c3e527f984470.tar.lz dexon-consensus-9839a1c6fecbada7d1736680930c3e527f984470.tar.xz dexon-consensus-9839a1c6fecbada7d1736680930c3e527f984470.tar.zst dexon-consensus-9839a1c6fecbada7d1736680930c3e527f984470.zip |
core: Move dkg in types to types/dkg. (#253)
Diffstat (limited to 'core')
-rw-r--r-- | core/authenticator.go | 11 | ||||
-rw-r--r-- | core/configuration-chain.go | 13 | ||||
-rw-r--r-- | core/configuration-chain_test.go | 23 | ||||
-rw-r--r-- | core/consensus.go | 15 | ||||
-rw-r--r-- | core/consensus_test.go | 11 | ||||
-rw-r--r-- | core/crypto.go | 21 | ||||
-rw-r--r-- | core/crypto_test.go | 11 | ||||
-rw-r--r-- | core/dkg-tsig-protocol.go | 47 | ||||
-rw-r--r-- | core/dkg-tsig-protocol_test.go | 57 | ||||
-rw-r--r-- | core/interfaces.go | 17 | ||||
-rw-r--r-- | core/test/governance.go | 11 | ||||
-rw-r--r-- | core/test/state.go | 57 | ||||
-rw-r--r-- | core/test/state_test.go | 21 | ||||
-rw-r--r-- | core/types/dkg/dkg.go (renamed from core/types/dkg.go) | 119 | ||||
-rw-r--r-- | core/types/dkg/dkg_test.go (renamed from core/types/dkg_test.go) | 81 |
15 files changed, 265 insertions, 250 deletions
diff --git a/core/authenticator.go b/core/authenticator.go index 5415f96..f773d52 100644 --- a/core/authenticator.go +++ b/core/authenticator.go @@ -21,6 +21,7 @@ import ( "github.com/dexon-foundation/dexon-consensus-core/common" "github.com/dexon-foundation/dexon-consensus-core/core/crypto" "github.com/dexon-foundation/dexon-consensus-core/core/types" + typesDKG "github.com/dexon-foundation/dexon-consensus-core/core/types/dkg" ) // Authenticator verify data owner. @@ -71,7 +72,7 @@ func (au *Authenticator) SignCRS(b *types.Block, crs common.Hash) (err error) { // SignDKGComplaint signs a DKG complaint. func (au *Authenticator) SignDKGComplaint( - complaint *types.DKGComplaint) (err error) { + complaint *typesDKG.Complaint) (err error) { complaint.ProposerID = au.proposerID complaint.Signature, err = au.prvKey.Sign(hashDKGComplaint(complaint)) return @@ -79,7 +80,7 @@ func (au *Authenticator) SignDKGComplaint( // SignDKGMasterPublicKey signs a DKG master public key. func (au *Authenticator) SignDKGMasterPublicKey( - mpk *types.DKGMasterPublicKey) (err error) { + mpk *typesDKG.MasterPublicKey) (err error) { mpk.ProposerID = au.proposerID mpk.Signature, err = au.prvKey.Sign(hashDKGMasterPublicKey(mpk)) return @@ -87,7 +88,7 @@ func (au *Authenticator) SignDKGMasterPublicKey( // SignDKGPrivateShare signs a DKG private share. func (au *Authenticator) SignDKGPrivateShare( - prvShare *types.DKGPrivateShare) (err error) { + prvShare *typesDKG.PrivateShare) (err error) { prvShare.ProposerID = au.proposerID prvShare.Signature, err = au.prvKey.Sign(hashDKGPrivateShare(prvShare)) return @@ -95,7 +96,7 @@ func (au *Authenticator) SignDKGPrivateShare( // SignDKGPartialSignature signs a DKG partial signature. func (au *Authenticator) SignDKGPartialSignature( - pSig *types.DKGPartialSignature) (err error) { + pSig *typesDKG.PartialSignature) (err error) { pSig.ProposerID = au.proposerID pSig.Signature, err = au.prvKey.Sign(hashDKGPartialSignature(pSig)) return @@ -103,7 +104,7 @@ func (au *Authenticator) SignDKGPartialSignature( // SignDKGFinalize signs a DKG finalize message. func (au *Authenticator) SignDKGFinalize( - final *types.DKGFinalize) (err error) { + final *typesDKG.Finalize) (err error) { final.ProposerID = au.proposerID final.Signature, err = au.prvKey.Sign(hashDKGFinalize(final)) return diff --git a/core/configuration-chain.go b/core/configuration-chain.go index 2676351..559eac0 100644 --- a/core/configuration-chain.go +++ b/core/configuration-chain.go @@ -25,6 +25,7 @@ import ( "github.com/dexon-foundation/dexon-consensus-core/common" "github.com/dexon-foundation/dexon-consensus-core/core/crypto" "github.com/dexon-foundation/dexon-consensus-core/core/types" + typesDKG "github.com/dexon-foundation/dexon-consensus-core/core/types/dkg" ) // Errors for configuration chain.. @@ -51,7 +52,7 @@ type configurationChain struct { tsigTouched map[common.Hash]struct{} tsigReady *sync.Cond // TODO(jimmy-dexon): add timeout to pending psig. - pendingPsig map[common.Hash][]*types.DKGPartialSignature + pendingPsig map[common.Hash][]*typesDKG.PartialSignature prevHash common.Hash } @@ -70,7 +71,7 @@ func newConfigurationChain( tsig: make(map[common.Hash]*tsigProtocol), tsigTouched: make(map[common.Hash]struct{}), tsigReady: sync.NewCond(&sync.Mutex{}), - pendingPsig: make(map[common.Hash][]*types.DKGPartialSignature), + pendingPsig: make(map[common.Hash][]*typesDKG.PartialSignature), } } @@ -178,7 +179,7 @@ func (cc *configurationChain) runDKG(round uint64) error { } func (cc *configurationChain) preparePartialSignature( - round uint64, hash common.Hash) (*types.DKGPartialSignature, error) { + round uint64, hash common.Hash) (*typesDKG.PartialSignature, error) { signer, exist := func() (*dkgShareSecret, bool) { cc.dkgResult.RLock() defer cc.dkgResult.RUnlock() @@ -188,7 +189,7 @@ func (cc *configurationChain) preparePartialSignature( if !exist { return nil, ErrDKGNotReady } - return &types.DKGPartialSignature{ + return &typesDKG.PartialSignature{ ProposerID: cc.ID, Round: round, Hash: hash, @@ -273,7 +274,7 @@ func (cc *configurationChain) runCRSTSig( } func (cc *configurationChain) processPrivateShare( - prvShare *types.DKGPrivateShare) error { + prvShare *typesDKG.PrivateShare) error { cc.dkgLock.Lock() defer cc.dkgLock.Unlock() if cc.dkg == nil { @@ -283,7 +284,7 @@ func (cc *configurationChain) processPrivateShare( } func (cc *configurationChain) processPartialSignature( - psig *types.DKGPartialSignature) error { + psig *typesDKG.PartialSignature) error { cc.tsigReady.L.Lock() defer cc.tsigReady.L.Unlock() if _, exist := cc.tsig[psig.Hash]; !exist { diff --git a/core/configuration-chain_test.go b/core/configuration-chain_test.go index ec2d6f2..1f729f4 100644 --- a/core/configuration-chain_test.go +++ b/core/configuration-chain_test.go @@ -31,6 +31,7 @@ import ( "github.com/dexon-foundation/dexon-consensus-core/core/crypto/ecdsa" "github.com/dexon-foundation/dexon-consensus-core/core/test" "github.com/dexon-foundation/dexon-consensus-core/core/types" + typesDKG "github.com/dexon-foundation/dexon-consensus-core/core/types/dkg" ) type ConfigurationChainTestSuite struct { @@ -57,7 +58,7 @@ func newTestCCReceiver( } } -func (r *testCCReceiver) ProposeDKGComplaint(complaint *types.DKGComplaint) { +func (r *testCCReceiver) ProposeDKGComplaint(complaint *typesDKG.Complaint) { prvKey, exist := r.s.prvKeys[complaint.ProposerID] r.s.Require().True(exist) var err error @@ -67,14 +68,14 @@ func (r *testCCReceiver) ProposeDKGComplaint(complaint *types.DKGComplaint) { // Use Marshal/Unmarshal to do deep copy. data, err := json.Marshal(complaint) r.s.Require().NoError(err) - complaintCopy := &types.DKGComplaint{} + complaintCopy := &typesDKG.Complaint{} r.s.Require().NoError(json.Unmarshal(data, complaintCopy)) gov.AddDKGComplaint(complaintCopy.Round, complaintCopy) } } func (r *testCCReceiver) ProposeDKGMasterPublicKey( - mpk *types.DKGMasterPublicKey) { + mpk *typesDKG.MasterPublicKey) { prvKey, exist := r.s.prvKeys[mpk.ProposerID] r.s.Require().True(exist) var err error @@ -84,14 +85,14 @@ func (r *testCCReceiver) ProposeDKGMasterPublicKey( // Use Marshal/Unmarshal to do deep copy. data, err := json.Marshal(mpk) r.s.Require().NoError(err) - mpkCopy := types.NewDKGMasterPublicKey() + mpkCopy := typesDKG.NewMasterPublicKey() r.s.Require().NoError(json.Unmarshal(data, mpkCopy)) gov.AddDKGMasterPublicKey(mpkCopy.Round, mpkCopy) } } func (r *testCCReceiver) ProposeDKGPrivateShare( - prv *types.DKGPrivateShare) { + prv *typesDKG.PrivateShare) { go func() { prvKey, exist := r.s.prvKeys[prv.ProposerID] r.s.Require().True(exist) @@ -106,7 +107,7 @@ func (r *testCCReceiver) ProposeDKGPrivateShare( } func (r *testCCReceiver) ProposeDKGAntiNackComplaint( - prv *types.DKGPrivateShare) { + prv *typesDKG.PrivateShare) { go func() { prvKey, exist := r.s.prvKeys[prv.ProposerID] r.s.Require().True(exist) @@ -117,7 +118,7 @@ func (r *testCCReceiver) ProposeDKGAntiNackComplaint( // Use Marshal/Unmarshal to do deep copy. data, err := json.Marshal(prv) r.s.Require().NoError(err) - prvCopy := &types.DKGPrivateShare{} + prvCopy := &typesDKG.PrivateShare{} r.s.Require().NoError(json.Unmarshal(data, prvCopy)) err = cc.processPrivateShare(prvCopy) r.s.Require().NoError(err) @@ -125,7 +126,7 @@ func (r *testCCReceiver) ProposeDKGAntiNackComplaint( }() } -func (r *testCCReceiver) ProposeDKGFinalize(final *types.DKGFinalize) { +func (r *testCCReceiver) ProposeDKGFinalize(final *typesDKG.Finalize) { prvKey, exist := r.s.prvKeys[final.ProposerID] r.s.Require().True(exist) var err error @@ -135,7 +136,7 @@ func (r *testCCReceiver) ProposeDKGFinalize(final *types.DKGFinalize) { // Use Marshal/Unmarshal to do deep copy. data, err := json.Marshal(final) r.s.Require().NoError(err) - finalCopy := &types.DKGFinalize{} + finalCopy := &typesDKG.Finalize{} r.s.Require().NoError(json.Unmarshal(data, finalCopy)) gov.AddDKGFinalize(finalCopy.Round, finalCopy) } @@ -202,8 +203,8 @@ func (s *ConfigurationChainTestSuite) preparePartialSignature( hash common.Hash, round uint64, cfgChains map[types.NodeID]*configurationChain) ( - psigs []*types.DKGPartialSignature) { - psigs = make([]*types.DKGPartialSignature, 0, len(cfgChains)) + psigs []*typesDKG.PartialSignature) { + psigs = make([]*typesDKG.PartialSignature, 0, len(cfgChains)) for nID, cc := range cfgChains { if _, exist := cc.gpk[round].qualifyNodeIDs[nID]; !exist { continue diff --git a/core/consensus.go b/core/consensus.go index a311851..e20b4e7 100644 --- a/core/consensus.go +++ b/core/consensus.go @@ -28,6 +28,7 @@ import ( "github.com/dexon-foundation/dexon-consensus-core/core/blockdb" "github.com/dexon-foundation/dexon-consensus-core/core/crypto" "github.com/dexon-foundation/dexon-consensus-core/core/types" + typesDKG "github.com/dexon-foundation/dexon-consensus-core/core/types/dkg" ) // Errors for consensus core. @@ -157,7 +158,7 @@ type consensusDKGReceiver struct { // ProposeDKGComplaint proposes a DKGComplaint. func (recv *consensusDKGReceiver) ProposeDKGComplaint( - complaint *types.DKGComplaint) { + complaint *typesDKG.Complaint) { if err := recv.authModule.SignDKGComplaint(complaint); err != nil { recv.logger.Error("Failed to sign DKG complaint", "error", err) return @@ -169,7 +170,7 @@ func (recv *consensusDKGReceiver) ProposeDKGComplaint( // ProposeDKGMasterPublicKey propose a DKGMasterPublicKey. func (recv *consensusDKGReceiver) ProposeDKGMasterPublicKey( - mpk *types.DKGMasterPublicKey) { + mpk *typesDKG.MasterPublicKey) { if err := recv.authModule.SignDKGMasterPublicKey(mpk); err != nil { recv.logger.Error("Failed to sign DKG master public key", "error", err) return @@ -180,7 +181,7 @@ func (recv *consensusDKGReceiver) ProposeDKGMasterPublicKey( // ProposeDKGPrivateShare propose a DKGPrivateShare. func (recv *consensusDKGReceiver) ProposeDKGPrivateShare( - prv *types.DKGPrivateShare) { + prv *typesDKG.PrivateShare) { if err := recv.authModule.SignDKGPrivateShare(prv); err != nil { recv.logger.Error("Failed to sign DKG private share", "error", err) return @@ -206,7 +207,7 @@ func (recv *consensusDKGReceiver) ProposeDKGPrivateShare( // ProposeDKGAntiNackComplaint propose a DKGPrivateShare as an anti complaint. func (recv *consensusDKGReceiver) ProposeDKGAntiNackComplaint( - prv *types.DKGPrivateShare) { + prv *typesDKG.PrivateShare) { if prv.ProposerID == recv.ID { if err := recv.authModule.SignDKGPrivateShare(prv); err != nil { recv.logger.Error("Failed sign DKG private share", "error", err) @@ -218,7 +219,7 @@ func (recv *consensusDKGReceiver) ProposeDKGAntiNackComplaint( } // ProposeDKGFinalize propose a DKGFinalize message. -func (recv *consensusDKGReceiver) ProposeDKGFinalize(final *types.DKGFinalize) { +func (recv *consensusDKGReceiver) ProposeDKGFinalize(final *typesDKG.Finalize) { if err := recv.authModule.SignDKGFinalize(final); err != nil { recv.logger.Error("Faield to sign DKG finalize", "error", err) return @@ -644,13 +645,13 @@ func (con *Consensus) processMsg(msgChan <-chan interface{}) { con.logger.Error("Failed to process block randomness result", "error", err) } - case *types.DKGPrivateShare: + case *typesDKG.PrivateShare: if err := con.cfgModule.processPrivateShare(val); err != nil { con.logger.Error("Failed to process private share", "error", err) } - case *types.DKGPartialSignature: + case *typesDKG.PartialSignature: if err := con.cfgModule.processPartialSignature(val); err != nil { con.logger.Error("Failed to process partial signature", "error", err) diff --git a/core/consensus_test.go b/core/consensus_test.go index 7a2e315..ed98b76 100644 --- a/core/consensus_test.go +++ b/core/consensus_test.go @@ -27,6 +27,7 @@ import ( "github.com/dexon-foundation/dexon-consensus-core/core/crypto" "github.com/dexon-foundation/dexon-consensus-core/core/test" "github.com/dexon-foundation/dexon-consensus-core/core/types" + typesDKG "github.com/dexon-foundation/dexon-consensus-core/core/types/dkg" "github.com/stretchr/testify/suite" ) @@ -60,20 +61,20 @@ func (n *network) BroadcastRandomnessResult( // SendDKGPrivateShare sends PrivateShare to a DKG participant. func (n *network) SendDKGPrivateShare( - recv crypto.PublicKey, prvShare *types.DKGPrivateShare) { + recv crypto.PublicKey, prvShare *typesDKG.PrivateShare) { n.conn.send(types.NewNodeID(recv), prvShare) } // BroadcastDKGPrivateShare broadcasts PrivateShare to all DKG participants. func (n *network) BroadcastDKGPrivateShare( - prvShare *types.DKGPrivateShare) { + prvShare *typesDKG.PrivateShare) { n.conn.broadcast(n.nID, prvShare) } // BroadcastDKGPartialSignature broadcasts partialSignature to all // DKG participants. func (n *network) BroadcastDKGPartialSignature( - psig *types.DKGPartialSignature) { + psig *typesDKG.PartialSignature) { n.conn.broadcast(n.nID, psig) } @@ -109,9 +110,9 @@ func (nc *networkConnection) send(to types.NodeID, msg interface{}) { err = con.ProcessAgreementResult(val) case *types.BlockRandomnessResult: err = con.ProcessBlockRandomnessResult(val) - case *types.DKGPrivateShare: + case *typesDKG.PrivateShare: err = con.cfgModule.processPrivateShare(val) - case *types.DKGPartialSignature: + case *typesDKG.PartialSignature: err = con.cfgModule.processPartialSignature(val) } if err != nil { diff --git a/core/crypto.go b/core/crypto.go index f792c09..8eb57fc 100644 --- a/core/crypto.go +++ b/core/crypto.go @@ -23,6 +23,7 @@ import ( "github.com/dexon-foundation/dexon-consensus-core/common" "github.com/dexon-foundation/dexon-consensus-core/core/crypto" "github.com/dexon-foundation/dexon-consensus-core/core/types" + typesDKG "github.com/dexon-foundation/dexon-consensus-core/core/types/dkg" ) func hashWitness(witness *types.Witness) (common.Hash, error) { @@ -130,7 +131,7 @@ func hashPosition(position types.Position) common.Hash { ) } -func hashDKGPrivateShare(prvShare *types.DKGPrivateShare) common.Hash { +func hashDKGPrivateShare(prvShare *typesDKG.PrivateShare) common.Hash { binaryRound := make([]byte, 8) binary.LittleEndian.PutUint64(binaryRound, prvShare.Round) @@ -143,7 +144,7 @@ func hashDKGPrivateShare(prvShare *types.DKGPrivateShare) common.Hash { } func verifyDKGPrivateShareSignature( - prvShare *types.DKGPrivateShare) (bool, error) { + prvShare *typesDKG.PrivateShare) (bool, error) { hash := hashDKGPrivateShare(prvShare) pubKey, err := crypto.SigToPub(hash, prvShare.Signature) if err != nil { @@ -155,7 +156,7 @@ func verifyDKGPrivateShareSignature( return true, nil } -func hashDKGMasterPublicKey(mpk *types.DKGMasterPublicKey) common.Hash { +func hashDKGMasterPublicKey(mpk *typesDKG.MasterPublicKey) common.Hash { binaryRound := make([]byte, 8) binary.LittleEndian.PutUint64(binaryRound, mpk.Round) @@ -169,7 +170,7 @@ func hashDKGMasterPublicKey(mpk *types.DKGMasterPublicKey) common.Hash { // VerifyDKGMasterPublicKeySignature verifies DKGMasterPublicKey signature. func VerifyDKGMasterPublicKeySignature( - mpk *types.DKGMasterPublicKey) (bool, error) { + mpk *typesDKG.MasterPublicKey) (bool, error) { hash := hashDKGMasterPublicKey(mpk) pubKey, err := crypto.SigToPub(hash, mpk.Signature) if err != nil { @@ -181,7 +182,7 @@ func VerifyDKGMasterPublicKeySignature( return true, nil } -func hashDKGComplaint(complaint *types.DKGComplaint) common.Hash { +func hashDKGComplaint(complaint *typesDKG.Complaint) common.Hash { binaryRound := make([]byte, 8) binary.LittleEndian.PutUint64(binaryRound, complaint.Round) @@ -196,7 +197,7 @@ func hashDKGComplaint(complaint *types.DKGComplaint) common.Hash { // VerifyDKGComplaintSignature verifies DKGCompliant signature. func VerifyDKGComplaintSignature( - complaint *types.DKGComplaint) (bool, error) { + complaint *typesDKG.Complaint) (bool, error) { if complaint.Round != complaint.PrivateShare.Round { return false, nil } @@ -214,7 +215,7 @@ func VerifyDKGComplaintSignature( return true, nil } -func hashDKGPartialSignature(psig *types.DKGPartialSignature) common.Hash { +func hashDKGPartialSignature(psig *typesDKG.PartialSignature) common.Hash { binaryRound := make([]byte, 8) binary.LittleEndian.PutUint64(binaryRound, psig.Round) @@ -227,7 +228,7 @@ func hashDKGPartialSignature(psig *types.DKGPartialSignature) common.Hash { } func verifyDKGPartialSignatureSignature( - psig *types.DKGPartialSignature) (bool, error) { + psig *typesDKG.PartialSignature) (bool, error) { hash := hashDKGPartialSignature(psig) pubKey, err := crypto.SigToPub(hash, psig.Signature) if err != nil { @@ -239,7 +240,7 @@ func verifyDKGPartialSignatureSignature( return true, nil } -func hashDKGFinalize(final *types.DKGFinalize) common.Hash { +func hashDKGFinalize(final *typesDKG.Finalize) common.Hash { binaryRound := make([]byte, 8) binary.LittleEndian.PutUint64(binaryRound, final.Round) @@ -251,7 +252,7 @@ func hashDKGFinalize(final *types.DKGFinalize) common.Hash { // VerifyDKGFinalizeSignature verifies DKGFinalize signature. func VerifyDKGFinalizeSignature( - final *types.DKGFinalize) (bool, error) { + final *typesDKG.Finalize) (bool, error) { hash := hashDKGFinalize(final) pubKey, err := crypto.SigToPub(hash, final.Signature) if err != nil { diff --git a/core/crypto_test.go b/core/crypto_test.go index c68b0c3..a248067 100644 --- a/core/crypto_test.go +++ b/core/crypto_test.go @@ -26,6 +26,7 @@ import ( "github.com/dexon-foundation/dexon-consensus-core/core/crypto/dkg" "github.com/dexon-foundation/dexon-consensus-core/core/crypto/ecdsa" "github.com/dexon-foundation/dexon-consensus-core/core/types" + typesDKG "github.com/dexon-foundation/dexon-consensus-core/core/types/dkg" "github.com/stretchr/testify/suite" ) @@ -171,7 +172,7 @@ func (s *CryptoTestSuite) TestDKGSignature() { prv, err := ecdsa.NewPrivateKey() s.Require().NoError(err) nID := types.NewNodeID(prv.PublicKey()) - prvShare := &types.DKGPrivateShare{ + prvShare := &typesDKG.PrivateShare{ ProposerID: nID, Round: 5, PrivateShare: *dkg.NewPrivateKey(), @@ -188,7 +189,7 @@ func (s *CryptoTestSuite) TestDKGSignature() { id := dkg.NewID([]byte{13}) _, pkShare := dkg.NewPrivateKeyShares(1) - mpk := &types.DKGMasterPublicKey{ + mpk := &typesDKG.MasterPublicKey{ ProposerID: nID, Round: 5, DKGID: id, @@ -207,7 +208,7 @@ func (s *CryptoTestSuite) TestDKGSignature() { prvShare.Round = 5 prvShare.Signature, err = prv.Sign(hashDKGPrivateShare(prvShare)) s.Require().NoError(err) - complaint := &types.DKGComplaint{ + complaint := &typesDKG.Complaint{ ProposerID: nID, Round: 5, PrivateShare: *prvShare, @@ -239,7 +240,7 @@ func (s *CryptoTestSuite) TestDKGSignature() { s.Require().NoError(err) s.False(ok) - sig := &types.DKGPartialSignature{ + sig := &typesDKG.PartialSignature{ ProposerID: nID, Round: 5, PartialSignature: dkg.PartialSignature{}, @@ -254,7 +255,7 @@ func (s *CryptoTestSuite) TestDKGSignature() { s.Require().NoError(err) s.False(ok) - final := &types.DKGFinalize{ + final := &typesDKG.Finalize{ ProposerID: nID, Round: 5, } diff --git a/core/dkg-tsig-protocol.go b/core/dkg-tsig-protocol.go index bb41931..f3a596e 100644 --- a/core/dkg-tsig-protocol.go +++ b/core/dkg-tsig-protocol.go @@ -25,6 +25,7 @@ import ( "github.com/dexon-foundation/dexon-consensus-core/core/crypto" "github.com/dexon-foundation/dexon-consensus-core/core/crypto/dkg" "github.com/dexon-foundation/dexon-consensus-core/core/types" + typesDKG "github.com/dexon-foundation/dexon-consensus-core/core/types/dkg" ) // Errors for dkg module. @@ -55,19 +56,19 @@ var ( type dkgReceiver interface { // ProposeDKGComplaint proposes a DKGComplaint. - ProposeDKGComplaint(complaint *types.DKGComplaint) + ProposeDKGComplaint(complaint *typesDKG.Complaint) // ProposeDKGMasterPublicKey propose a DKGMasterPublicKey. - ProposeDKGMasterPublicKey(mpk *types.DKGMasterPublicKey) + ProposeDKGMasterPublicKey(mpk *typesDKG.MasterPublicKey) // ProposeDKGPrivateShare propose a DKGPrivateShare. - ProposeDKGPrivateShare(prv *types.DKGPrivateShare) + ProposeDKGPrivateShare(prv *typesDKG.PrivateShare) // ProposeDKGAntiNackComplaint propose a DKGPrivateShare as an anti complaint. - ProposeDKGAntiNackComplaint(prv *types.DKGPrivateShare) + ProposeDKGAntiNackComplaint(prv *typesDKG.PrivateShare) // ProposeDKGFinalize propose a DKGFinalize message. - ProposeDKGFinalize(final *types.DKGFinalize) + ProposeDKGFinalize(final *typesDKG.Finalize) } type dkgProtocol struct { @@ -133,7 +134,7 @@ func newDKGProtocol( prvShare, pubShare := dkg.NewPrivateKeyShares(threshold) - recv.ProposeDKGMasterPublicKey(&types.DKGMasterPublicKey{ + recv.ProposeDKGMasterPublicKey(&typesDKG.MasterPublicKey{ ProposerID: ID, Round: round, DKGID: newDKGID(ID), @@ -156,7 +157,7 @@ func newDKGProtocol( } func (d *dkgProtocol) processMasterPublicKeys( - mpks []*types.DKGMasterPublicKey) error { + mpks []*typesDKG.MasterPublicKey) error { d.idMap = make(map[types.NodeID]dkg.ID, len(mpks)) d.mpkMap = make(map[types.NodeID]*dkg.PublicKeyShares, len(mpks)) d.prvSharesReceived = make(map[types.NodeID]struct{}, len(mpks)) @@ -173,7 +174,7 @@ func (d *dkgProtocol) processMasterPublicKeys( if !ok { return ErrIDShareNotFound } - d.recv.ProposeDKGPrivateShare(&types.DKGPrivateShare{ + d.recv.ProposeDKGPrivateShare(&typesDKG.PrivateShare{ ProposerID: d.ID, ReceiverID: mpk.ProposerID, Round: d.round, @@ -188,10 +189,10 @@ func (d *dkgProtocol) proposeNackComplaints() { if _, exist := d.prvSharesReceived[nID]; exist { continue } - d.recv.ProposeDKGComplaint(&types.DKGComplaint{ + d.recv.ProposeDKGComplaint(&typesDKG.Complaint{ ProposerID: d.ID, Round: d.round, - PrivateShare: types.DKGPrivateShare{ + PrivateShare: typesDKG.PrivateShare{ ProposerID: nID, Round: d.round, }, @@ -199,7 +200,7 @@ func (d *dkgProtocol) proposeNackComplaints() { } } -func (d *dkgProtocol) processNackComplaints(complaints []*types.DKGComplaint) ( +func (d *dkgProtocol) processNackComplaints(complaints []*typesDKG.Complaint) ( err error) { for _, complaint := range complaints { if !complaint.IsNack() { @@ -218,7 +219,7 @@ func (d *dkgProtocol) processNackComplaints(complaints []*types.DKGComplaint) ( err = ErrIDShareNotFound continue } - d.recv.ProposeDKGAntiNackComplaint(&types.DKGPrivateShare{ + d.recv.ProposeDKGAntiNackComplaint(&typesDKG.PrivateShare{ ProposerID: d.ID, ReceiverID: complaint.ProposerID, Round: d.round, @@ -228,7 +229,7 @@ func (d *dkgProtocol) processNackComplaints(complaints []*types.DKGComplaint) ( return } -func (d *dkgProtocol) enforceNackComplaints(complaints []*types.DKGComplaint) { +func (d *dkgProtocol) enforceNackComplaints(complaints []*typesDKG.Complaint) { for _, complaint := range complaints { if !complaint.IsNack() { continue @@ -245,10 +246,10 @@ func (d *dkgProtocol) enforceNackComplaints(complaints []*types.DKGComplaint) { } if _, exist := d.antiComplaintReceived[from][to]; !exist { - d.recv.ProposeDKGComplaint(&types.DKGComplaint{ + d.recv.ProposeDKGComplaint(&typesDKG.Complaint{ ProposerID: d.ID, Round: d.round, - PrivateShare: types.DKGPrivateShare{ + PrivateShare: typesDKG.PrivateShare{ ProposerID: to, Round: d.round, }, @@ -257,7 +258,7 @@ func (d *dkgProtocol) enforceNackComplaints(complaints []*types.DKGComplaint) { } } -func (d *dkgProtocol) sanityCheck(prvShare *types.DKGPrivateShare) error { +func (d *dkgProtocol) sanityCheck(prvShare *typesDKG.PrivateShare) error { if _, exist := d.idMap[prvShare.ProposerID]; !exist { return ErrNotDKGParticipant } @@ -272,7 +273,7 @@ func (d *dkgProtocol) sanityCheck(prvShare *types.DKGPrivateShare) error { } func (d *dkgProtocol) processPrivateShare( - prvShare *types.DKGPrivateShare) error { + prvShare *typesDKG.PrivateShare) error { if d.round != prvShare.Round { return nil } @@ -296,7 +297,7 @@ func (d *dkgProtocol) processPrivateShare( if _, exist := d.nodeComplained[prvShare.ProposerID]; exist { return nil } - complaint := &types.DKGComplaint{ + complaint := &typesDKG.Complaint{ ProposerID: d.ID, Round: d.round, PrivateShare: *prvShare, @@ -322,7 +323,7 @@ func (d *dkgProtocol) processPrivateShare( } func (d *dkgProtocol) proposeFinalize() { - d.recv.ProposeDKGFinalize(&types.DKGFinalize{ + d.recv.ProposeDKGFinalize(&typesDKG.Finalize{ ProposerID: d.ID, Round: d.round, }) @@ -351,7 +352,7 @@ func (ss *dkgShareSecret) sign(hash common.Hash) dkg.PartialSignature { // NewDKGGroupPublicKey creats a DKGGroupPublicKey instance. func NewDKGGroupPublicKey( round uint64, - mpks []*types.DKGMasterPublicKey, complaints []*types.DKGComplaint, + mpks []*typesDKG.MasterPublicKey, complaints []*typesDKG.Complaint, threshold int) ( *DKGGroupPublicKey, error) { @@ -376,7 +377,7 @@ func NewDKGGroupPublicKey( } qualifyIDs := make(dkg.IDs, 0, len(mpks)-len(disqualifyIDs)) qualifyNodeIDs := make(map[types.NodeID]struct{}) - mpkMap := make(map[dkg.ID]*types.DKGMasterPublicKey, cap(qualifyIDs)) + mpkMap := make(map[dkg.ID]*typesDKG.MasterPublicKey, cap(qualifyIDs)) idMap := make(map[types.NodeID]dkg.ID) for _, mpk := range mpks { if _, exist := disqualifyIDs[mpk.ProposerID]; exist { @@ -507,7 +508,7 @@ func newTSigProtocol( } } -func (tsig *tsigProtocol) sanityCheck(psig *types.DKGPartialSignature) error { +func (tsig *tsigProtocol) sanityCheck(psig *typesDKG.PartialSignature) error { _, exist := tsig.groupPublicKey.publicKeys[psig.ProposerID] if !exist { return ErrNotQualifyDKGParticipant @@ -526,7 +527,7 @@ func (tsig *tsigProtocol) sanityCheck(psig *types.DKGPartialSignature) error { } func (tsig *tsigProtocol) processPartialSignature( - psig *types.DKGPartialSignature) error { + psig *typesDKG.PartialSignature) error { if psig.Round != tsig.groupPublicKey.round { return nil } diff --git a/core/dkg-tsig-protocol_test.go b/core/dkg-tsig-protocol_test.go index 5c60a2f..35714b4 100644 --- a/core/dkg-tsig-protocol_test.go +++ b/core/dkg-tsig-protocol_test.go @@ -28,6 +28,7 @@ import ( "github.com/dexon-foundation/dexon-consensus-core/core/crypto/ecdsa" "github.com/dexon-foundation/dexon-consensus-core/core/test" "github.com/dexon-foundation/dexon-consensus-core/core/types" + typesDKG "github.com/dexon-foundation/dexon-consensus-core/core/types/dkg" ) type DKGTSIGProtocolTestSuite struct { @@ -42,11 +43,11 @@ type testDKGReceiver struct { s *DKGTSIGProtocolTestSuite prvKey crypto.PrivateKey - complaints map[types.NodeID]*types.DKGComplaint - mpk *types.DKGMasterPublicKey - prvShare map[types.NodeID]*types.DKGPrivateShare - antiComplaints map[types.NodeID]*types.DKGPrivateShare - final []*types.DKGFinalize + complaints map[types.NodeID]*typesDKG.Complaint + mpk *typesDKG.MasterPublicKey + prvShare map[types.NodeID]*typesDKG.PrivateShare + antiComplaints map[types.NodeID]*typesDKG.PrivateShare + final []*typesDKG.Finalize } func newTestDKGReceiver( @@ -54,13 +55,13 @@ func newTestDKGReceiver( return &testDKGReceiver{ s: s, prvKey: prvKey, - complaints: make(map[types.NodeID]*types.DKGComplaint), - prvShare: make(map[types.NodeID]*types.DKGPrivateShare), - antiComplaints: make(map[types.NodeID]*types.DKGPrivateShare), + complaints: make(map[types.NodeID]*typesDKG.Complaint), + prvShare: make(map[types.NodeID]*typesDKG.PrivateShare), + antiComplaints: make(map[types.NodeID]*typesDKG.PrivateShare), } } -func (r *testDKGReceiver) ProposeDKGComplaint(complaint *types.DKGComplaint) { +func (r *testDKGReceiver) ProposeDKGComplaint(complaint *typesDKG.Complaint) { var err error complaint.Signature, err = r.prvKey.Sign(hashDKGComplaint(complaint)) r.s.Require().NoError(err) @@ -68,7 +69,7 @@ func (r *testDKGReceiver) ProposeDKGComplaint(complaint *types.DKGComplaint) { } func (r *testDKGReceiver) ProposeDKGMasterPublicKey( - mpk *types.DKGMasterPublicKey) { + mpk *typesDKG.MasterPublicKey) { var err error mpk.Signature, err = r.prvKey.Sign(hashDKGMasterPublicKey(mpk)) r.s.Require().NoError(err) @@ -76,7 +77,7 @@ func (r *testDKGReceiver) ProposeDKGMasterPublicKey( } func (r *testDKGReceiver) ProposeDKGPrivateShare( - prv *types.DKGPrivateShare) { + prv *typesDKG.PrivateShare) { var err error prv.Signature, err = r.prvKey.Sign(hashDKGPrivateShare(prv)) r.s.Require().NoError(err) @@ -84,14 +85,14 @@ func (r *testDKGReceiver) ProposeDKGPrivateShare( } func (r *testDKGReceiver) ProposeDKGAntiNackComplaint( - prv *types.DKGPrivateShare) { + prv *typesDKG.PrivateShare) { var err error prv.Signature, err = r.prvKey.Sign(hashDKGPrivateShare(prv)) r.s.Require().NoError(err) r.antiComplaints[prv.ReceiverID] = prv } -func (r *testDKGReceiver) ProposeDKGFinalize(final *types.DKGFinalize) { +func (r *testDKGReceiver) ProposeDKGFinalize(final *typesDKG.Finalize) { r.final = append(r.final, final) } @@ -220,7 +221,7 @@ func (s *DKGTSIGProtocolTestSuite) TestDKGTSIGProtocol() { msgHash := crypto.Keccak256Hash([]byte("🏖🍹")) tsig := newTSigProtocol(gpk, msgHash) for nID, shareSecret := range shareSecrets { - psig := &types.DKGPartialSignature{ + psig := &typesDKG.PartialSignature{ ProposerID: nID, Round: round, Hash: msgHash, @@ -312,13 +313,13 @@ func (s *DKGTSIGProtocolTestSuite) TestComplaint() { } // These messages are not valid. - err = protocol.processPrivateShare(&types.DKGPrivateShare{ + err = protocol.processPrivateShare(&typesDKG.PrivateShare{ ProposerID: types.NodeID{Hash: common.NewRandomHash()}, ReceiverID: targetID, Round: round, }) s.Equal(ErrNotDKGParticipant, err) - receivers[byzantineID].ProposeDKGPrivateShare(&types.DKGPrivateShare{ + receivers[byzantineID].ProposeDKGPrivateShare(&typesDKG.PrivateShare{ ProposerID: byzantineID, ReceiverID: targetID, Round: round, @@ -330,7 +331,7 @@ func (s *DKGTSIGProtocolTestSuite) TestComplaint() { delete(receivers[byzantineID].prvShare, targetID) // Byzantine node is sending incorrect private share. - receivers[byzantineID].ProposeDKGPrivateShare(&types.DKGPrivateShare{ + receivers[byzantineID].ProposeDKGPrivateShare(&typesDKG.PrivateShare{ ProposerID: byzantineID, ReceiverID: targetID, Round: round, @@ -390,7 +391,7 @@ func (s *DKGTSIGProtocolTestSuite) TestAntiComplaint() { // Creating an anti-nack complaint. err = protocols[byzantineID].processNackComplaints( - []*types.DKGComplaint{complaint}) + []*typesDKG.Complaint{complaint}) s.Require().NoError(err) s.Require().Len(receivers[byzantineID].antiComplaints, 1) antiComplaint, exist := receivers[byzantineID].antiComplaints[targetID] @@ -398,11 +399,11 @@ func (s *DKGTSIGProtocolTestSuite) TestAntiComplaint() { s.Require().Equal(targetID, antiComplaint.ReceiverID) // The anti-complaint should be successfully verified by all others. - receivers[targetID].complaints = make(map[types.NodeID]*types.DKGComplaint) + receivers[targetID].complaints = make(map[types.NodeID]*typesDKG.Complaint) s.Require().NoError(protocols[targetID].processPrivateShare(antiComplaint)) s.Len(receivers[targetID].complaints, 0) - receivers[thirdPerson].complaints = make(map[types.NodeID]*types.DKGComplaint) + receivers[thirdPerson].complaints = make(map[types.NodeID]*typesDKG.Complaint) s.Require().NoError(protocols[thirdPerson].processPrivateShare(antiComplaint)) s.Len(receivers[thirdPerson].complaints, 0) } @@ -440,7 +441,7 @@ func (s *DKGTSIGProtocolTestSuite) TestEncorceNackComplaint() { s.Require().Equal(byzantineID, complaint.PrivateShare.ProposerID) // Encorce nack complaint. - protocols[thirdPerson].enforceNackComplaints([]*types.DKGComplaint{complaint}) + protocols[thirdPerson].enforceNackComplaints([]*typesDKG.Complaint{complaint}) complaint2, exist := receivers[thirdPerson].complaints[byzantineID] s.Require().True(exist) s.Require().True(complaint2.IsNack()) @@ -449,13 +450,13 @@ func (s *DKGTSIGProtocolTestSuite) TestEncorceNackComplaint() { // Received valid private share, do not enforce nack complaint. delete(receivers[thirdPerson].complaints, byzantineID) err = protocols[byzantineID].processNackComplaints( - []*types.DKGComplaint{complaint}) + []*typesDKG.Complaint{complaint}) s.Require().NoError(err) antiComplaint, exist := receivers[byzantineID].antiComplaints[targetID] s.Require().True(exist) s.Require().Equal(targetID, antiComplaint.ReceiverID) s.Require().NoError(protocols[thirdPerson].processPrivateShare(antiComplaint)) - protocols[thirdPerson].enforceNackComplaints([]*types.DKGComplaint{complaint}) + protocols[thirdPerson].enforceNackComplaints([]*typesDKG.Complaint{complaint}) _, exist = receivers[thirdPerson].complaints[byzantineID] s.Require().False(exist) } @@ -480,13 +481,13 @@ func (s *DKGTSIGProtocolTestSuite) TestQualifyIDs() { } // Test for nack complaints. - complaints := make([]*types.DKGComplaint, k+1) + complaints := make([]*typesDKG.Complaint, k+1) for i := range complaints { nID := s.nIDs[i] - complaints[i] = &types.DKGComplaint{ + complaints[i] = &typesDKG.Complaint{ ProposerID: nID, Round: round, - PrivateShare: types.DKGPrivateShare{ + PrivateShare: typesDKG.PrivateShare{ ProposerID: byzantineID, Round: round, }, @@ -601,7 +602,7 @@ func (s *DKGTSIGProtocolTestSuite) TestPartialSignature() { byzantineID2 := s.nIDs[1] byzantineID3 := s.nIDs[2] for nID, shareSecret := range shareSecrets { - psig := &types.DKGPartialSignature{ + psig := &typesDKG.PartialSignature{ ProposerID: nID, Round: round, Hash: msgHash, @@ -644,7 +645,7 @@ func (s *DKGTSIGProtocolTestSuite) TestProposeFinalize() { protocol.proposeFinalize() s.Require().Len(recv.final, 1) final := recv.final[0] - s.Equal(&types.DKGFinalize{ + s.Equal(&typesDKG.Finalize{ ProposerID: nID, Round: 1, }, final) diff --git a/core/interfaces.go b/core/interfaces.go index 2ba8e0d..01e9096 100644 --- a/core/interfaces.go +++ b/core/interfaces.go @@ -23,6 +23,7 @@ import ( "github.com/dexon-foundation/dexon-consensus-core/common" "github.com/dexon-foundation/dexon-consensus-core/core/crypto" "github.com/dexon-foundation/dexon-consensus-core/core/types" + typesDKG "github.com/dexon-foundation/dexon-consensus-core/core/types/dkg" ) // Application describes the application interface that interacts with DEXON @@ -71,14 +72,14 @@ type Network interface { BroadcastRandomnessResult(randResult *types.BlockRandomnessResult) // SendDKGPrivateShare sends PrivateShare to a DKG participant. - SendDKGPrivateShare(pub crypto.PublicKey, prvShare *types.DKGPrivateShare) + SendDKGPrivateShare(pub crypto.PublicKey, prvShare *typesDKG.PrivateShare) // BroadcastDKGPrivateShare broadcasts PrivateShare to all DKG participants. - BroadcastDKGPrivateShare(prvShare *types.DKGPrivateShare) + BroadcastDKGPrivateShare(prvShare *typesDKG.PrivateShare) // BroadcastDKGPartialSignature broadcasts partialSignature to all // DKG participants. - BroadcastDKGPartialSignature(psig *types.DKGPartialSignature) + BroadcastDKGPartialSignature(psig *typesDKG.PartialSignature) // ReceiveChan returns a channel to receive messages from DEXON network. ReceiveChan() <-chan interface{} @@ -110,19 +111,19 @@ type Governance interface { //// DKG-related methods. // AddDKGComplaint adds a DKGComplaint. - AddDKGComplaint(round uint64, complaint *types.DKGComplaint) + AddDKGComplaint(round uint64, complaint *typesDKG.Complaint) // DKGComplaints gets all the DKGComplaints of round. - DKGComplaints(round uint64) []*types.DKGComplaint + DKGComplaints(round uint64) []*typesDKG.Complaint // AddDKGMasterPublicKey adds a DKGMasterPublicKey. - AddDKGMasterPublicKey(round uint64, masterPublicKey *types.DKGMasterPublicKey) + AddDKGMasterPublicKey(round uint64, masterPublicKey *typesDKG.MasterPublicKey) // DKGMasterPublicKeys gets all the DKGMasterPublicKey of round. - DKGMasterPublicKeys(round uint64) []*types.DKGMasterPublicKey + DKGMasterPublicKeys(round uint64) []*typesDKG.MasterPublicKey // AddDKGFinalize adds a DKG finalize message. - AddDKGFinalize(round uint64, final *types.DKGFinalize) + AddDKGFinalize(round uint64, final *typesDKG.Finalize) // IsDKGFinal checks if DKG is final. IsDKGFinal(round uint64) bool diff --git a/core/test/governance.go b/core/test/governance.go index 94dcb6c..a3b9168 100644 --- a/core/test/governance.go +++ b/core/test/governance.go @@ -25,6 +25,7 @@ import ( "github.com/dexon-foundation/dexon-consensus-core/common" "github.com/dexon-foundation/dexon-consensus-core/core/crypto" "github.com/dexon-foundation/dexon-consensus-core/core/types" + typesDKG "github.com/dexon-foundation/dexon-consensus-core/core/types/dkg" ) var ( @@ -112,7 +113,7 @@ func (g *Governance) ProposeCRS(round uint64, signedCRS []byte) { // AddDKGComplaint add a DKGComplaint. func (g *Governance) AddDKGComplaint( - round uint64, complaint *types.DKGComplaint) { + round uint64, complaint *typesDKG.Complaint) { if round != complaint.Round { return } @@ -123,13 +124,13 @@ func (g *Governance) AddDKGComplaint( } // DKGComplaints returns the DKGComplaints of round. -func (g *Governance) DKGComplaints(round uint64) []*types.DKGComplaint { +func (g *Governance) DKGComplaints(round uint64) []*typesDKG.Complaint { return g.state.DKGComplaints(round) } // AddDKGMasterPublicKey adds a DKGMasterPublicKey. func (g *Governance) AddDKGMasterPublicKey( - round uint64, masterPublicKey *types.DKGMasterPublicKey) { + round uint64, masterPublicKey *typesDKG.MasterPublicKey) { if round != masterPublicKey.Round { return } @@ -138,12 +139,12 @@ func (g *Governance) AddDKGMasterPublicKey( // DKGMasterPublicKeys returns the DKGMasterPublicKeys of round. func (g *Governance) DKGMasterPublicKeys( - round uint64) []*types.DKGMasterPublicKey { + round uint64) []*typesDKG.MasterPublicKey { return g.state.DKGMasterPublicKeys(round) } // AddDKGFinalize adds a DKG finalize message. -func (g *Governance) AddDKGFinalize(round uint64, final *types.DKGFinalize) { +func (g *Governance) AddDKGFinalize(round uint64, final *typesDKG.Finalize) { if round != final.Round { return } diff --git a/core/test/state.go b/core/test/state.go index 59b3dc5..f8f9ebe 100644 --- a/core/test/state.go +++ b/core/test/state.go @@ -27,6 +27,7 @@ import ( "github.com/dexon-foundation/dexon-consensus-core/core/crypto" "github.com/dexon-foundation/dexon-consensus-core/core/crypto/ecdsa" "github.com/dexon-foundation/dexon-consensus-core/core/types" + typesDKG "github.com/dexon-foundation/dexon-consensus-core/core/types/dkg" "github.com/dexon-foundation/dexon/rlp" ) @@ -102,9 +103,9 @@ type State struct { // Nodes nodes map[types.NodeID]crypto.PublicKey // DKG & CRS - dkgComplaints map[uint64]map[types.NodeID][]*types.DKGComplaint - dkgMasterPublicKeys map[uint64]map[types.NodeID]*types.DKGMasterPublicKey - dkgFinals map[uint64]map[types.NodeID]*types.DKGFinalize + dkgComplaints map[uint64]map[types.NodeID][]*typesDKG.Complaint + dkgMasterPublicKeys map[uint64]map[types.NodeID]*typesDKG.MasterPublicKey + dkgFinals map[uint64]map[types.NodeID]*typesDKG.Finalize crs []common.Hash // Other stuffs local bool @@ -114,9 +115,9 @@ type State struct { // applied. pendingChangedConfigs map[StateChangeType]interface{} pendingNodes [][]byte - pendingDKGComplaints []*types.DKGComplaint - pendingDKGFinals []*types.DKGFinalize - pendingDKGMasterPublicKeys []*types.DKGMasterPublicKey + pendingDKGComplaints []*typesDKG.Complaint + pendingDKGFinals []*typesDKG.Finalize + pendingDKGMasterPublicKeys []*typesDKG.MasterPublicKey pendingCRS []*crsAdditionRequest pendingChangesLock sync.Mutex } @@ -147,11 +148,11 @@ func NewState( dkgSetSize: uint32(len(nodes)), pendingChangedConfigs: make(map[StateChangeType]interface{}), dkgFinals: make( - map[uint64]map[types.NodeID]*types.DKGFinalize), + map[uint64]map[types.NodeID]*typesDKG.Finalize), dkgComplaints: make( - map[uint64]map[types.NodeID][]*types.DKGComplaint), + map[uint64]map[types.NodeID][]*typesDKG.Complaint), dkgMasterPublicKeys: make( - map[uint64]map[types.NodeID]*types.DKGMasterPublicKey), + map[uint64]map[types.NodeID]*typesDKG.MasterPublicKey), } } @@ -185,13 +186,13 @@ func (s *State) unpackPayload( v = &crsAdditionRequest{} err = rlp.DecodeBytes(raw.Payload, v) case StateAddDKGComplaint: - v = &types.DKGComplaint{} + v = &typesDKG.Complaint{} err = rlp.DecodeBytes(raw.Payload, v) case StateAddDKGMasterPublicKey: - v = &types.DKGMasterPublicKey{} + v = &typesDKG.MasterPublicKey{} err = rlp.DecodeBytes(raw.Payload, v) case StateAddDKGFinal: - v = &types.DKGFinalize{} + v = &typesDKG.Finalize{} err = rlp.DecodeBytes(raw.Payload, v) case StateChangeNumChains: var tmp uint32 @@ -335,7 +336,7 @@ func (s *State) isValidRequest(req *StateChangeRequest) (err error) { // responsible for acquiring appropriate lock. switch req.Type { case StateAddDKGComplaint: - comp := req.Payload.(*types.DKGComplaint) + comp := req.Payload.(*typesDKG.Complaint) // If we've received DKG final from that proposer, we would ignore // its complaint. if _, exists := s.dkgFinals[comp.Round][comp.ProposerID]; exists { @@ -389,24 +390,24 @@ func (s *State) applyRequest(req *StateChangeRequest) error { } s.crs = append(s.crs, crsRequest.CRS) case StateAddDKGComplaint: - comp := req.Payload.(*types.DKGComplaint) + comp := req.Payload.(*typesDKG.Complaint) if _, exists := s.dkgComplaints[comp.Round]; !exists { s.dkgComplaints[comp.Round] = make( - map[types.NodeID][]*types.DKGComplaint) + map[types.NodeID][]*typesDKG.Complaint) } s.dkgComplaints[comp.Round][comp.ProposerID] = append( s.dkgComplaints[comp.Round][comp.ProposerID], comp) case StateAddDKGMasterPublicKey: - mKey := req.Payload.(*types.DKGMasterPublicKey) + mKey := req.Payload.(*typesDKG.MasterPublicKey) if _, exists := s.dkgMasterPublicKeys[mKey.Round]; !exists { s.dkgMasterPublicKeys[mKey.Round] = make( - map[types.NodeID]*types.DKGMasterPublicKey) + map[types.NodeID]*typesDKG.MasterPublicKey) } s.dkgMasterPublicKeys[mKey.Round][mKey.ProposerID] = mKey case StateAddDKGFinal: - final := req.Payload.(*types.DKGFinalize) + final := req.Payload.(*typesDKG.Finalize) if _, exists := s.dkgFinals[final.Round]; !exists { - s.dkgFinals[final.Round] = make(map[types.NodeID]*types.DKGFinalize) + s.dkgFinals[final.Round] = make(map[types.NodeID]*typesDKG.Finalize) } s.dkgFinals[final.Round][final.ProposerID] = final case StateChangeNumChains: @@ -491,13 +492,13 @@ func (s *State) RequestChange( s.pendingCRS = append(s.pendingCRS, payload.(*crsAdditionRequest)) case StateAddDKGComplaint: s.pendingDKGComplaints = append( - s.pendingDKGComplaints, payload.(*types.DKGComplaint)) + s.pendingDKGComplaints, payload.(*typesDKG.Complaint)) case StateAddDKGMasterPublicKey: s.pendingDKGMasterPublicKeys = append( - s.pendingDKGMasterPublicKeys, payload.(*types.DKGMasterPublicKey)) + s.pendingDKGMasterPublicKeys, payload.(*typesDKG.MasterPublicKey)) case StateAddDKGFinal: s.pendingDKGFinals = append( - s.pendingDKGFinals, payload.(*types.DKGFinalize)) + s.pendingDKGFinals, payload.(*typesDKG.Finalize)) default: s.pendingChangedConfigs[t] = payload } @@ -516,21 +517,21 @@ func (s *State) CRS(round uint64) common.Hash { // DKGComplaints access current received dkg complaints for that round. // This information won't be snapshot, thus can't be cached in test.Governance. -func (s *State) DKGComplaints(round uint64) []*types.DKGComplaint { +func (s *State) DKGComplaints(round uint64) []*typesDKG.Complaint { s.lock.RLock() defer s.lock.RUnlock() comps, exists := s.dkgComplaints[round] if !exists { return nil } - tmpComps := make([]*types.DKGComplaint, 0, len(comps)) + tmpComps := make([]*typesDKG.Complaint, 0, len(comps)) for _, compProp := range comps { for _, comp := range compProp { bytes, err := rlp.EncodeToBytes(comp) if err != nil { panic(err) } - compCopy := &types.DKGComplaint{} + compCopy := &typesDKG.Complaint{} if err = rlp.DecodeBytes(bytes, compCopy); err != nil { panic(err) } @@ -543,21 +544,21 @@ func (s *State) DKGComplaints(round uint64) []*types.DKGComplaint { // DKGMasterPublicKeys access current received dkg master public keys for that // round. This information won't be snapshot, thus can't be cached in // test.Governance. -func (s *State) DKGMasterPublicKeys(round uint64) []*types.DKGMasterPublicKey { +func (s *State) DKGMasterPublicKeys(round uint64) []*typesDKG.MasterPublicKey { s.lock.RLock() defer s.lock.RUnlock() masterPublicKeys, exists := s.dkgMasterPublicKeys[round] if !exists { return nil } - mpks := make([]*types.DKGMasterPublicKey, 0, len(masterPublicKeys)) + mpks := make([]*typesDKG.MasterPublicKey, 0, len(masterPublicKeys)) for _, mpk := range masterPublicKeys { // Return a deep copied master public keys. b, err := rlp.EncodeToBytes(mpk) if err != nil { panic(err) } - mpkCopy := types.NewDKGMasterPublicKey() + mpkCopy := typesDKG.NewMasterPublicKey() if err = rlp.DecodeBytes(b, mpkCopy); err != nil { panic(err) } diff --git a/core/test/state_test.go b/core/test/state_test.go index b5ed383..ebb5a25 100644 --- a/core/test/state_test.go +++ b/core/test/state_test.go @@ -27,6 +27,7 @@ import ( "github.com/dexon-foundation/dexon-consensus-core/core/crypto/dkg" "github.com/dexon-foundation/dexon-consensus-core/core/crypto/ecdsa" "github.com/dexon-foundation/dexon-consensus-core/core/types" + typesDKG "github.com/dexon-foundation/dexon-consensus-core/core/types/dkg" "github.com/stretchr/testify/suite" ) @@ -35,7 +36,7 @@ type StateTestSuite struct { } func (s *StateTestSuite) newDKGMasterPublicKey( - round uint64) *types.DKGMasterPublicKey { + round uint64) *typesDKG.MasterPublicKey { prvKey, err := ecdsa.NewPrivateKey() s.Require().NoError(err) pubKey := prvKey.PublicKey() @@ -43,7 +44,7 @@ func (s *StateTestSuite) newDKGMasterPublicKey( _, pubShare := dkg.NewPrivateKeyShares(3) dID, err := dkg.BytesID(nodeID.Hash[:]) s.Require().NoError(err) - return &types.DKGMasterPublicKey{ + return &typesDKG.MasterPublicKey{ ProposerID: nodeID, Round: round, DKGID: dID, @@ -51,16 +52,16 @@ func (s *StateTestSuite) newDKGMasterPublicKey( } } -func (s *StateTestSuite) newDKGComplaint(round uint64) *types.DKGComplaint { +func (s *StateTestSuite) newDKGComplaint(round uint64) *typesDKG.Complaint { prvKey, err := ecdsa.NewPrivateKey() s.Require().NoError(err) pubKey := prvKey.PublicKey() nodeID := types.NewNodeID(pubKey) // TODO(mission): sign it, and it doesn't make sense to complaint self. - return &types.DKGComplaint{ + return &typesDKG.Complaint{ ProposerID: nodeID, Round: round, - PrivateShare: types.DKGPrivateShare{ + PrivateShare: typesDKG.PrivateShare{ ProposerID: nodeID, ReceiverID: nodeID, Round: round, @@ -69,13 +70,13 @@ func (s *StateTestSuite) newDKGComplaint(round uint64) *types.DKGComplaint { } } -func (s *StateTestSuite) newDKGFinal(round uint64) *types.DKGFinalize { +func (s *StateTestSuite) newDKGFinal(round uint64) *typesDKG.Finalize { prvKey, err := ecdsa.NewPrivateKey() s.Require().NoError(err) pubKey := prvKey.PublicKey() nodeID := types.NewNodeID(pubKey) // TODO(mission): sign it. - return &types.DKGFinalize{ + return &typesDKG.Finalize{ ProposerID: nodeID, Round: round, } @@ -126,9 +127,9 @@ func (s *StateTestSuite) findNode( func (s *StateTestSuite) makeDKGChanges( st *State, - masterPubKey *types.DKGMasterPublicKey, - complaint *types.DKGComplaint, - final *types.DKGFinalize) { + masterPubKey *typesDKG.MasterPublicKey, + complaint *typesDKG.Complaint, + final *typesDKG.Finalize) { st.RequestChange(StateAddDKGMasterPublicKey, masterPubKey) st.RequestChange(StateAddDKGComplaint, complaint) st.RequestChange(StateAddDKGFinal, final) diff --git a/core/types/dkg.go b/core/types/dkg/dkg.go index edd420d..ee00f14 100644 --- a/core/types/dkg.go +++ b/core/types/dkg/dkg.go @@ -15,7 +15,7 @@ // along with the dexon-consensus-core library. If not, see // <http://www.gnu.org/licenses/>. -package types +package dkg import ( "bytes" @@ -27,20 +27,21 @@ import ( "github.com/dexon-foundation/dexon-consensus-core/common" "github.com/dexon-foundation/dexon-consensus-core/core/crypto" - "github.com/dexon-foundation/dexon-consensus-core/core/crypto/dkg" + cryptoDKG "github.com/dexon-foundation/dexon-consensus-core/core/crypto/dkg" + "github.com/dexon-foundation/dexon-consensus-core/core/types" ) -// DKGPrivateShare describe a secret share in DKG protocol. -type DKGPrivateShare struct { - ProposerID NodeID `json:"proposer_id"` - ReceiverID NodeID `json:"receiver_id"` - Round uint64 `json:"round"` - PrivateShare dkg.PrivateKey `json:"private_share"` - Signature crypto.Signature `json:"signature"` +// PrivateShare describe a secret share in DKG protocol. +type PrivateShare struct { + ProposerID types.NodeID `json:"proposer_id"` + ReceiverID types.NodeID `json:"receiver_id"` + Round uint64 `json:"round"` + PrivateShare cryptoDKG.PrivateKey `json:"private_share"` + Signature crypto.Signature `json:"signature"` } -// Equal checks equality between two DKGPrivateShare instances. -func (p *DKGPrivateShare) Equal(other *DKGPrivateShare) bool { +// Equal checks equality between two PrivateShare instances. +func (p *PrivateShare) Equal(other *PrivateShare) bool { return p.ProposerID.Equal(other.ProposerID) && p.ReceiverID.Equal(other.ReceiverID) && p.Round == other.Round && @@ -50,23 +51,23 @@ func (p *DKGPrivateShare) Equal(other *DKGPrivateShare) bool { p.PrivateShare.Bytes(), other.PrivateShare.Bytes()) == 0 } -// DKGMasterPublicKey decrtibe a master public key in DKG protocol. -type DKGMasterPublicKey struct { - ProposerID NodeID `json:"proposer_id"` - Round uint64 `json:"round"` - DKGID dkg.ID `json:"dkg_id"` - PublicKeyShares dkg.PublicKeyShares `json:"public_key_shares"` - Signature crypto.Signature `json:"signature"` +// MasterPublicKey decrtibe a master public key in DKG protocol. +type MasterPublicKey struct { + ProposerID types.NodeID `json:"proposer_id"` + Round uint64 `json:"round"` + DKGID cryptoDKG.ID `json:"dkg_id"` + PublicKeyShares cryptoDKG.PublicKeyShares `json:"public_key_shares"` + Signature crypto.Signature `json:"signature"` } -func (d *DKGMasterPublicKey) String() string { +func (d *MasterPublicKey) String() string { return fmt.Sprintf("MasterPublicKey[%s:%d]", d.ProposerID.String()[:6], d.Round) } // Equal check equality of two DKG master public keys. -func (d *DKGMasterPublicKey) Equal(other *DKGMasterPublicKey) bool { +func (d *MasterPublicKey) Equal(other *MasterPublicKey) bool { return d.ProposerID.Equal(other.ProposerID) && d.Round == other.Round && d.DKGID.GetHexString() == other.DKGID.GetHexString() && @@ -75,17 +76,17 @@ func (d *DKGMasterPublicKey) Equal(other *DKGMasterPublicKey) bool { bytes.Compare(d.Signature.Signature, other.Signature.Signature) == 0 } -type rlpDKGMasterPublicKey struct { - ProposerID NodeID +type rlpMasterPublicKey struct { + ProposerID types.NodeID Round uint64 DKGID []byte - PublicKeyShares *dkg.PublicKeyShares + PublicKeyShares *cryptoDKG.PublicKeyShares Signature crypto.Signature } // EncodeRLP implements rlp.Encoder -func (d *DKGMasterPublicKey) EncodeRLP(w io.Writer) error { - return rlp.Encode(w, rlpDKGMasterPublicKey{ +func (d *MasterPublicKey) EncodeRLP(w io.Writer) error { + return rlp.Encode(w, rlpMasterPublicKey{ ProposerID: d.ProposerID, Round: d.Round, DKGID: d.DKGID.GetLittleEndian(), @@ -95,18 +96,18 @@ func (d *DKGMasterPublicKey) EncodeRLP(w io.Writer) error { } // DecodeRLP implements rlp.Decoder -func (d *DKGMasterPublicKey) DecodeRLP(s *rlp.Stream) error { - var dec rlpDKGMasterPublicKey +func (d *MasterPublicKey) DecodeRLP(s *rlp.Stream) error { + var dec rlpMasterPublicKey if err := s.Decode(&dec); err != nil { return err } - id, err := dkg.BytesID(dec.DKGID) + id, err := cryptoDKG.BytesID(dec.DKGID) if err != nil { return err } - *d = DKGMasterPublicKey{ + *d = MasterPublicKey{ ProposerID: dec.ProposerID, Round: dec.Round, DKGID: id, @@ -116,40 +117,40 @@ func (d *DKGMasterPublicKey) DecodeRLP(s *rlp.Stream) error { return err } -// NewDKGMasterPublicKey returns a new DKGMasterPublicKey instance. -func NewDKGMasterPublicKey() *DKGMasterPublicKey { - return &DKGMasterPublicKey{ - PublicKeyShares: *dkg.NewEmptyPublicKeyShares(), +// NewMasterPublicKey returns a new MasterPublicKey instance. +func NewMasterPublicKey() *MasterPublicKey { + return &MasterPublicKey{ + PublicKeyShares: *cryptoDKG.NewEmptyPublicKeyShares(), } } // UnmarshalJSON implements json.Unmarshaller. -func (d *DKGMasterPublicKey) UnmarshalJSON(data []byte) error { - type innertDKGMasterPublicKey DKGMasterPublicKey - d.PublicKeyShares = *dkg.NewEmptyPublicKeyShares() - return json.Unmarshal(data, (*innertDKGMasterPublicKey)(d)) +func (d *MasterPublicKey) UnmarshalJSON(data []byte) error { + type innertMasterPublicKey MasterPublicKey + d.PublicKeyShares = *cryptoDKG.NewEmptyPublicKeyShares() + return json.Unmarshal(data, (*innertMasterPublicKey)(d)) } -// DKGComplaint describe a complaint in DKG protocol. -type DKGComplaint struct { - ProposerID NodeID `json:"proposer_id"` +// Complaint describe a complaint in DKG protocol. +type Complaint struct { + ProposerID types.NodeID `json:"proposer_id"` Round uint64 `json:"round"` - PrivateShare DKGPrivateShare `json:"private_share"` + PrivateShare PrivateShare `json:"private_share"` Signature crypto.Signature `json:"signature"` } -func (c *DKGComplaint) String() string { +func (c *Complaint) String() string { if c.IsNack() { return fmt.Sprintf("DKGNackComplaint[%s:%d]%s", c.ProposerID.String()[:6], c.Round, c.PrivateShare.ProposerID.String()[:6]) } - return fmt.Sprintf("DKGComplaint[%s:%d]%v", + return fmt.Sprintf("Complaint[%s:%d]%v", c.ProposerID.String()[:6], c.Round, c.PrivateShare) } -// Equal checks equality between two DKGComplaint instances. -func (c *DKGComplaint) Equal(other *DKGComplaint) bool { +// Equal checks equality between two Complaint instances. +func (c *Complaint) Equal(other *Complaint) bool { return c.ProposerID.Equal(other.ProposerID) && c.Round == other.Round && c.PrivateShare.Equal(&other.PrivateShare) && @@ -157,30 +158,30 @@ func (c *DKGComplaint) Equal(other *DKGComplaint) bool { bytes.Compare(c.Signature.Signature, other.Signature.Signature) == 0 } -// DKGPartialSignature describe a partial signature in DKG protocol. -type DKGPartialSignature struct { - ProposerID NodeID `json:"proposer_id"` - Round uint64 `json:"round"` - Hash common.Hash `json:"hash"` - PartialSignature dkg.PartialSignature `json:"partial_signature"` - Signature crypto.Signature `json:"signature"` +// PartialSignature describe a partial signature in DKG protocol. +type PartialSignature struct { + ProposerID types.NodeID `json:"proposer_id"` + Round uint64 `json:"round"` + Hash common.Hash `json:"hash"` + PartialSignature cryptoDKG.PartialSignature `json:"partial_signature"` + Signature crypto.Signature `json:"signature"` } -// DKGFinalize describe a dig finalize message in DKG protocol. -type DKGFinalize struct { - ProposerID NodeID `json:"proposer_id"` +// Finalize describe a dig finalize message in DKG protocol. +type Finalize struct { + ProposerID types.NodeID `json:"proposer_id"` Round uint64 `json:"round"` Signature crypto.Signature `json:"signature"` } -func (final *DKGFinalize) String() string { +func (final *Finalize) String() string { return fmt.Sprintf("DKGFinal[%s:%d]", final.ProposerID.String()[:6], final.Round) } -// Equal check equality of two DKGFinalize instances. -func (final *DKGFinalize) Equal(other *DKGFinalize) bool { +// Equal check equality of two Finalize instances. +func (final *Finalize) Equal(other *Finalize) bool { return final.ProposerID.Equal(other.ProposerID) && final.Round == other.Round && final.Signature.Type == other.Signature.Type && @@ -188,6 +189,6 @@ func (final *DKGFinalize) Equal(other *DKGFinalize) bool { } // IsNack returns true if it's a nack complaint in DKG protocol. -func (c *DKGComplaint) IsNack() bool { +func (c *Complaint) IsNack() bool { return len(c.PrivateShare.Signature.Signature) == 0 } diff --git a/core/types/dkg_test.go b/core/types/dkg/dkg_test.go index 0558101..0186c50 100644 --- a/core/types/dkg_test.go +++ b/core/types/dkg/dkg_test.go @@ -15,7 +15,7 @@ // along with the dexon-consensus-core library. If not, see // <http://www.gnu.org/licenses/>. -package types +package dkg import ( "math/rand" @@ -26,7 +26,8 @@ import ( "github.com/dexon-foundation/dexon-consensus-core/common" "github.com/dexon-foundation/dexon-consensus-core/core/crypto" - "github.com/dexon-foundation/dexon-consensus-core/core/crypto/dkg" + cryptoDKG "github.com/dexon-foundation/dexon-consensus-core/core/crypto/dkg" + "github.com/dexon-foundation/dexon-consensus-core/core/types" "github.com/dexon-foundation/dexon/rlp" ) @@ -41,8 +42,8 @@ func (s *DKGTestSuite) genRandomBytes() []byte { return randomness } -func (s *DKGTestSuite) genID() dkg.ID { - dID, err := dkg.BytesID(s.genRandomBytes()) +func (s *DKGTestSuite) genID() cryptoDKG.ID { + dID, err := cryptoDKG.BytesID(s.genRandomBytes()) s.Require().NoError(err) return dID } @@ -56,8 +57,8 @@ func (s *DKGTestSuite) clone(src, dst interface{}) { func (s *DKGTestSuite) TestRLPEncodeDecode() { dID := s.genID() // Prepare master public key for testing. - d := DKGMasterPublicKey{ - ProposerID: NodeID{common.Hash{1, 2, 3}}, + d := MasterPublicKey{ + ProposerID: types.NodeID{Hash: common.Hash{1, 2, 3}}, Round: 10, DKGID: dID, Signature: crypto.Signature{ @@ -69,7 +70,7 @@ func (s *DKGTestSuite) TestRLPEncodeDecode() { b, err := rlp.EncodeToBytes(&d) s.Require().NoError(err) - var dd DKGMasterPublicKey + var dd MasterPublicKey err = rlp.DecodeBytes(b, &dd) s.Require().NoError(err) @@ -82,24 +83,24 @@ func (s *DKGTestSuite) TestRLPEncodeDecode() { s.Require().Equal(d.DKGID.GetHexString(), dd.DKGID.GetHexString()) } -func (s *DKGTestSuite) TestDKGMasterPublicKeyEquality() { +func (s *DKGTestSuite) TestMasterPublicKeyEquality() { var req = s.Require() // Prepare source master public key. - master1 := &DKGMasterPublicKey{ - ProposerID: NodeID{Hash: common.NewRandomHash()}, + master1 := &MasterPublicKey{ + ProposerID: types.NodeID{Hash: common.NewRandomHash()}, Round: 1234, DKGID: s.genID(), Signature: crypto.Signature{ Signature: s.genRandomBytes(), }, } - prvKey := dkg.NewPrivateKey() - pubKey := prvKey.PublicKey().(dkg.PublicKey) - _, pubShares := dkg.NewPrivateKeyShares(2) + prvKey := cryptoDKG.NewPrivateKey() + pubKey := prvKey.PublicKey().(cryptoDKG.PublicKey) + _, pubShares := cryptoDKG.NewPrivateKeyShares(2) req.NoError(pubShares.AddShare(s.genID(), &pubKey)) master1.PublicKeyShares = *pubShares // Prepare another master public key by copying every field. - master2 := &DKGMasterPublicKey{} + master2 := &MasterPublicKey{} s.clone(master1, master2) // They should be equal. req.True(master1.Equal(master2)) @@ -108,11 +109,11 @@ func (s *DKGTestSuite) TestDKGMasterPublicKeyEquality() { req.False(master1.Equal(master2)) master2.Round = 1234 // Change proposerID. - master2.ProposerID = NodeID{Hash: common.NewRandomHash()} + master2.ProposerID = types.NodeID{Hash: common.NewRandomHash()} req.False(master1.Equal(master2)) master2.ProposerID = master1.ProposerID // Change DKGID. - master2.DKGID = dkg.NewID(s.genRandomBytes()) + master2.DKGID = cryptoDKG.NewID(s.genRandomBytes()) req.False(master1.Equal(master2)) master2.DKGID = master1.DKGID // Change signature. @@ -122,31 +123,31 @@ func (s *DKGTestSuite) TestDKGMasterPublicKeyEquality() { req.False(master1.Equal(master2)) master2.Signature = master1.Signature // Change public key share. - master2.PublicKeyShares = *dkg.NewEmptyPublicKeyShares() + master2.PublicKeyShares = *cryptoDKG.NewEmptyPublicKeyShares() req.False(master1.Equal(master2)) } -func (s *DKGTestSuite) TestDKGPrivateShareEquality() { +func (s *DKGTestSuite) TestPrivateShareEquality() { var req = s.Require() - share1 := &DKGPrivateShare{ - ProposerID: NodeID{Hash: common.NewRandomHash()}, - ReceiverID: NodeID{Hash: common.NewRandomHash()}, + share1 := &PrivateShare{ + ProposerID: types.NodeID{Hash: common.NewRandomHash()}, + ReceiverID: types.NodeID{Hash: common.NewRandomHash()}, Round: 1, - PrivateShare: *dkg.NewPrivateKey(), + PrivateShare: *cryptoDKG.NewPrivateKey(), Signature: crypto.Signature{ Signature: s.genRandomBytes(), }, } // Make a copy. - share2 := &DKGPrivateShare{} + share2 := &PrivateShare{} s.clone(share1, share2) req.True(share1.Equal(share2)) // Change proposer ID. - share2.ProposerID = NodeID{Hash: common.NewRandomHash()} + share2.ProposerID = types.NodeID{Hash: common.NewRandomHash()} req.False(share1.Equal(share2)) share2.ProposerID = share1.ProposerID // Change receiver ID. - share2.ReceiverID = NodeID{Hash: common.NewRandomHash()} + share2.ReceiverID = types.NodeID{Hash: common.NewRandomHash()} req.False(share1.Equal(share2)) share2.ReceiverID = share1.ReceiverID // Change round. @@ -160,23 +161,23 @@ func (s *DKGTestSuite) TestDKGPrivateShareEquality() { req.False(share1.Equal(share2)) share2.Signature = share1.Signature // Change private share. - share2.PrivateShare = *dkg.NewPrivateKey() + share2.PrivateShare = *cryptoDKG.NewPrivateKey() req.False(share1.Equal(share2)) share2.PrivateShare = share1.PrivateShare // They should be equal after chaning fields back. req.True(share1.Equal(share2)) } -func (s *DKGTestSuite) TestDKGComplaintEquality() { +func (s *DKGTestSuite) TestComplaintEquality() { var req = s.Require() - comp1 := &DKGComplaint{ - ProposerID: NodeID{Hash: common.NewRandomHash()}, + comp1 := &Complaint{ + ProposerID: types.NodeID{Hash: common.NewRandomHash()}, Round: 1, - PrivateShare: DKGPrivateShare{ - ProposerID: NodeID{Hash: common.NewRandomHash()}, - ReceiverID: NodeID{Hash: common.NewRandomHash()}, + PrivateShare: PrivateShare{ + ProposerID: types.NodeID{Hash: common.NewRandomHash()}, + ReceiverID: types.NodeID{Hash: common.NewRandomHash()}, Round: 2, - PrivateShare: *dkg.NewPrivateKey(), + PrivateShare: *cryptoDKG.NewPrivateKey(), Signature: crypto.Signature{ Signature: s.genRandomBytes(), }, @@ -186,11 +187,11 @@ func (s *DKGTestSuite) TestDKGComplaintEquality() { }, } // Make a copy. - comp2 := &DKGComplaint{} + comp2 := &Complaint{} s.clone(comp1, comp2) req.True(comp1.Equal(comp2)) // Change proposer ID. - comp2.ProposerID = NodeID{Hash: common.NewRandomHash()} + comp2.ProposerID = types.NodeID{Hash: common.NewRandomHash()} req.False(comp1.Equal(comp2)) comp2.ProposerID = comp1.ProposerID // Change round. @@ -211,21 +212,21 @@ func (s *DKGTestSuite) TestDKGComplaintEquality() { req.True(comp1.Equal(comp2)) } -func (s *DKGTestSuite) TestDKGFinalizeEquality() { +func (s *DKGTestSuite) TestFinalizeEquality() { var req = s.Require() - final1 := &DKGFinalize{ - ProposerID: NodeID{Hash: common.NewRandomHash()}, + final1 := &Finalize{ + ProposerID: types.NodeID{Hash: common.NewRandomHash()}, Round: 1, Signature: crypto.Signature{ Signature: s.genRandomBytes(), }, } // Make a copy - final2 := &DKGFinalize{} + final2 := &Finalize{} s.clone(final1, final2) req.True(final1.Equal(final2)) // Change proposer ID. - final2.ProposerID = NodeID{Hash: common.NewRandomHash()} + final2.ProposerID = types.NodeID{Hash: common.NewRandomHash()} req.False(final1.Equal(final2)) final2.ProposerID = final1.ProposerID // Change round. |