diff options
author | Wei-Ning Huang <w@dexon.org> | 2018-10-25 11:17:52 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@dexon.org> | 2019-03-12 12:19:09 +0800 |
commit | b3ec3ce42ce5382fc16c532ad961b0ac2a3897dc (patch) | |
tree | 77c2ca24a653c38124ca43d5be0af785bea0a24f /vendor | |
parent | e776662999ddf0ab195fb731975643708fa2e8c3 (diff) | |
download | dexon-b3ec3ce42ce5382fc16c532ad961b0ac2a3897dc.tar.gz dexon-b3ec3ce42ce5382fc16c532ad961b0ac2a3897dc.tar.zst dexon-b3ec3ce42ce5382fc16c532ad961b0ac2a3897dc.zip |
vendor: sync consensus core and fix conflict
Diffstat (limited to 'vendor')
11 files changed, 162 insertions, 180 deletions
diff --git a/vendor/github.com/dexon-foundation/dexon-consensus-core/core/authenticator.go b/vendor/github.com/dexon-foundation/dexon-consensus-core/core/authenticator.go index 5415f967c..f773d5292 100644 --- a/vendor/github.com/dexon-foundation/dexon-consensus-core/core/authenticator.go +++ b/vendor/github.com/dexon-foundation/dexon-consensus-core/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/vendor/github.com/dexon-foundation/dexon-consensus-core/core/compaction-chain.go b/vendor/github.com/dexon-foundation/dexon-consensus-core/core/compaction-chain.go index 5b13f7fe1..451cb1355 100644 --- a/vendor/github.com/dexon-foundation/dexon-consensus-core/core/compaction-chain.go +++ b/vendor/github.com/dexon-foundation/dexon-consensus-core/core/compaction-chain.go @@ -132,6 +132,7 @@ func (cc *compactionChain) extractBlocks() []*types.Block { cc.pendingBlocks = cc.pendingBlocks[1:] block := cc.pendingBlocks[0] + block.Finalization.ParentHash = prevBlock.Hash block.Finalization.Height = prevBlock.Finalization.Height + 1 deliveringBlocks = append(deliveringBlocks, block) prevBlock = block @@ -204,8 +205,7 @@ func (cc *compactionChain) extractFinalizedBlocks() []*types.Block { continue } // Fork resolution: choose block with smaller hash. - if prevBlock.Finalization.Height == - b.Finalization.Height { + if prevBlock.Finalization.Height == b.Finalization.Height { //TODO(jimmy-dexon): remove this panic after test. if true { // workaround to `go vet` error diff --git a/vendor/github.com/dexon-foundation/dexon-consensus-core/core/configuration-chain.go b/vendor/github.com/dexon-foundation/dexon-consensus-core/core/configuration-chain.go index 267635155..559eac0b7 100644 --- a/vendor/github.com/dexon-foundation/dexon-consensus-core/core/configuration-chain.go +++ b/vendor/github.com/dexon-foundation/dexon-consensus-core/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/vendor/github.com/dexon-foundation/dexon-consensus-core/core/consensus.go b/vendor/github.com/dexon-foundation/dexon-consensus-core/core/consensus.go index 03855587c..e20b4e79d 100644 --- a/vendor/github.com/dexon-foundation/dexon-consensus-core/core/consensus.go +++ b/vendor/github.com/dexon-foundation/dexon-consensus-core/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 @@ -545,7 +546,7 @@ func (con *Consensus) runCRS() { } else { con.logger.Debug("Calling Governance.ProposeCRS", "round", con.round+1, - "crs", crs) + "crs", hex.EncodeToString(crs)) con.gov.ProposeCRS(con.round+1, crs) } } @@ -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) @@ -846,7 +847,7 @@ func (con *Consensus) processBlock(block *types.Block) (err error) { deliveredBlocks = con.ccModule.extractBlocks() for _, b := range deliveredBlocks { if err = con.db.Put(*b); err != nil { - return + panic(err) } // TODO(mission): clone types.FinalizationResult con.app.BlockDelivered(b.Hash, b.Finalization) diff --git a/vendor/github.com/dexon-foundation/dexon-consensus-core/core/crypto.go b/vendor/github.com/dexon-foundation/dexon-consensus-core/core/crypto.go index f3870a5f6..8eb57fcd8 100644 --- a/vendor/github.com/dexon-foundation/dexon-consensus-core/core/crypto.go +++ b/vendor/github.com/dexon-foundation/dexon-consensus-core/core/crypto.go @@ -23,18 +23,14 @@ 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) { - binaryTimestamp, err := witness.Timestamp.UTC().MarshalBinary() - if err != nil { - return common.Hash{}, err - } binaryHeight := make([]byte, 8) binary.LittleEndian.PutUint64(binaryHeight, witness.Height) return crypto.Keccak256Hash( binaryHeight, - binaryTimestamp, witness.Data), nil } @@ -135,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) @@ -148,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 { @@ -160,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) @@ -174,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 { @@ -186,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) @@ -201,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 } @@ -219,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) @@ -232,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 { @@ -244,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) @@ -256,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/vendor/github.com/dexon-foundation/dexon-consensus-core/core/dkg-tsig-protocol.go b/vendor/github.com/dexon-foundation/dexon-consensus-core/core/dkg-tsig-protocol.go index bb4193193..f3a596e2b 100644 --- a/vendor/github.com/dexon-foundation/dexon-consensus-core/core/dkg-tsig-protocol.go +++ b/vendor/github.com/dexon-foundation/dexon-consensus-core/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/vendor/github.com/dexon-foundation/dexon-consensus-core/core/interfaces.go b/vendor/github.com/dexon-foundation/dexon-consensus-core/core/interfaces.go index 2ba8e0d3a..01e909667 100644 --- a/vendor/github.com/dexon-foundation/dexon-consensus-core/core/interfaces.go +++ b/vendor/github.com/dexon-foundation/dexon-consensus-core/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/vendor/github.com/dexon-foundation/dexon-consensus-core/core/types/block.go b/vendor/github.com/dexon-foundation/dexon-consensus-core/core/types/block.go index 29b1c841f..e12e0d5c7 100644 --- a/vendor/github.com/dexon-foundation/dexon-consensus-core/core/types/block.go +++ b/vendor/github.com/dexon-foundation/dexon-consensus-core/core/types/block.go @@ -77,12 +77,14 @@ func (t *rlpTimestamp) DecodeRLP(s *rlp.Stream) error { // FinalizationResult represents the result of DEXON consensus algorithm. type FinalizationResult struct { - Randomness []byte `json:"randomness"` - Timestamp time.Time `json:"timestamp"` - Height uint64 `json:"height"` + ParentHash common.Hash `json:"parent_hash"` + Randomness []byte `json:"randomness"` + Timestamp time.Time `json:"timestamp"` + Height uint64 `json:"height"` } type rlpFinalizationResult struct { + ParentHash common.Hash Randomness []byte Timestamp *rlpTimestamp Height uint64 @@ -91,6 +93,7 @@ type rlpFinalizationResult struct { // EncodeRLP implements rlp.Encoder func (f *FinalizationResult) EncodeRLP(w io.Writer) error { return rlp.Encode(w, &rlpFinalizationResult{ + ParentHash: f.ParentHash, Randomness: f.Randomness, Timestamp: &rlpTimestamp{f.Timestamp}, Height: f.Height, @@ -103,6 +106,7 @@ func (f *FinalizationResult) DecodeRLP(s *rlp.Stream) error { err := s.Decode(&dec) if err == nil { *f = FinalizationResult{ + ParentHash: dec.ParentHash, Randomness: dec.Randomness, Timestamp: dec.Timestamp.Time, Height: dec.Height, @@ -113,38 +117,8 @@ func (f *FinalizationResult) DecodeRLP(s *rlp.Stream) error { // Witness represents the consensus information on the compaction chain. type Witness struct { - Timestamp time.Time `json:"timestamp"` - Height uint64 `json:"height"` - Data []byte `json:"data"` -} - -type rlpWitness struct { - Timestamp *rlpTimestamp - Height uint64 - Data []byte -} - -// EncodeRLP implements rlp.Encoder -func (w *Witness) EncodeRLP(writer io.Writer) error { - return rlp.Encode(writer, rlpWitness{ - Timestamp: &rlpTimestamp{w.Timestamp}, - Height: w.Height, - Data: w.Data, - }) -} - -// DecodeRLP implements rlp.Decoder -func (w *Witness) DecodeRLP(s *rlp.Stream) error { - var dec rlpWitness - err := s.Decode(&dec) - if err == nil { - *w = Witness{ - Timestamp: dec.Timestamp.Time, - Height: dec.Height, - Data: dec.Data, - } - } - return err + Height uint64 `json:"height"` + Data []byte `json:"data"` } // RecycleBlock put unused block into cache, which might be reused if @@ -245,9 +219,9 @@ func (b *Block) Clone() (bcopy *Block) { bcopy.Position.Height = b.Position.Height bcopy.Signature = b.Signature.Clone() bcopy.CRSSignature = b.CRSSignature.Clone() + bcopy.Finalization.ParentHash = b.Finalization.ParentHash bcopy.Finalization.Timestamp = b.Finalization.Timestamp bcopy.Finalization.Height = b.Finalization.Height - bcopy.Witness.Timestamp = b.Witness.Timestamp bcopy.Witness.Height = b.Witness.Height bcopy.Witness.Data = make([]byte, len(b.Witness.Data)) copy(bcopy.Witness.Data, b.Witness.Data) diff --git a/vendor/github.com/dexon-foundation/dexon-consensus-core/core/types/dkg.go b/vendor/github.com/dexon-foundation/dexon-consensus-core/core/types/dkg/dkg.go index edd420df9..ee00f140f 100644 --- a/vendor/github.com/dexon-foundation/dexon-consensus-core/core/types/dkg.go +++ b/vendor/github.com/dexon-foundation/dexon-consensus-core/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/vendor/github.com/dexon-foundation/dexon-consensus-core/core/types/position.go b/vendor/github.com/dexon-foundation/dexon-consensus-core/core/types/position.go index 51de405c3..f41be324e 100644 --- a/vendor/github.com/dexon-foundation/dexon-consensus-core/core/types/position.go +++ b/vendor/github.com/dexon-foundation/dexon-consensus-core/core/types/position.go @@ -35,7 +35,7 @@ type Position struct { } func (pos *Position) String() string { - return fmt.Sprintf("pos[%d:%d:%d]", pos.ChainID, pos.Round, pos.Height) + return fmt.Sprintf("pos[%d:%d:%d]", pos.Round, pos.ChainID, pos.Height) } // Equal checks if two positions are equal, it panics when their chainIDs diff --git a/vendor/vendor.json b/vendor/vendor.json index cd7af1a10..37dc8aa51 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -105,44 +105,50 @@ { "checksumSHA1": "IKOLx0ZjJoT9x9zO/bVAXWcNXs8=", "path": "github.com/dexon-foundation/dexon-consensus-core/common", - "revision": "47885b50ad94c3b34118554bed2a142717e6ee72", - "revisionTime": "2018-10-24T04:03:50Z" + "revision": "e9283765abc5dddee2e1f8455509bb188f445818", + "revisionTime": "2018-10-25T01:55:59Z" }, { - "checksumSHA1": "h+9DsEkDRxBqu5/GHdNfRuNSYdY=", + "checksumSHA1": "N0TZFVRpv3PxmAZmJyCO5JOGt78=", "path": "github.com/dexon-foundation/dexon-consensus-core/core", - "revision": "47885b50ad94c3b34118554bed2a142717e6ee72", - "revisionTime": "2018-10-24T04:03:50Z" + "revision": "e9283765abc5dddee2e1f8455509bb188f445818", + "revisionTime": "2018-10-25T01:55:59Z" }, { "checksumSHA1": "69/j3ROwzhdGPWKymJnGjaJ5QzY=", "path": "github.com/dexon-foundation/dexon-consensus-core/core/blockdb", - "revision": "47885b50ad94c3b34118554bed2a142717e6ee72", - "revisionTime": "2018-10-24T04:03:50Z" + "revision": "e9283765abc5dddee2e1f8455509bb188f445818", + "revisionTime": "2018-10-25T01:55:59Z" }, { "checksumSHA1": "GXHmtn3UlUftllBXI+M8RBkilzY=", "path": "github.com/dexon-foundation/dexon-consensus-core/core/crypto", - "revision": "47885b50ad94c3b34118554bed2a142717e6ee72", - "revisionTime": "2018-10-24T04:03:50Z" + "revision": "e9283765abc5dddee2e1f8455509bb188f445818", + "revisionTime": "2018-10-25T01:55:59Z" }, { "checksumSHA1": "sh19Kk6G7esEcBPC2QsaFF3V/Ds=", "path": "github.com/dexon-foundation/dexon-consensus-core/core/crypto/dkg", - "revision": "47885b50ad94c3b34118554bed2a142717e6ee72", - "revisionTime": "2018-10-24T04:03:50Z" + "revision": "e9283765abc5dddee2e1f8455509bb188f445818", + "revisionTime": "2018-10-25T01:55:59Z" }, { "checksumSHA1": "priVCcv7H4LTooiN/1EUu8qFiSs=", "path": "github.com/dexon-foundation/dexon-consensus-core/core/crypto/ecdsa", - "revision": "47885b50ad94c3b34118554bed2a142717e6ee72", - "revisionTime": "2018-10-24T04:03:50Z" + "revision": "e9283765abc5dddee2e1f8455509bb188f445818", + "revisionTime": "2018-10-25T01:55:59Z" }, { - "checksumSHA1": "dKIKJdmVmYKd1ihBAfEoOn6qeCc=", + "checksumSHA1": "9UYwfOHKwJlCEk1EH3eZtdVLuS0=", "path": "github.com/dexon-foundation/dexon-consensus-core/core/types", - "revision": "47885b50ad94c3b34118554bed2a142717e6ee72", - "revisionTime": "2018-10-24T04:03:50Z" + "revision": "e9283765abc5dddee2e1f8455509bb188f445818", + "revisionTime": "2018-10-25T01:55:59Z" + }, + { + "checksumSHA1": "ZOjAnqYE7HayNBTsMIgRQPLxndI=", + "path": "github.com/dexon-foundation/dexon-consensus-core/core/types/dkg", + "revision": "e9283765abc5dddee2e1f8455509bb188f445818", + "revisionTime": "2018-10-25T01:55:59Z" }, { "checksumSHA1": "TAkwduKZqLyimyTPPWIllZWYFuE=", |