From 2d1ed5288cab621aba39c3a81aae7042ead14fd5 Mon Sep 17 00:00:00 2001 From: Wei-Ning Huang Date: Thu, 25 Oct 2018 11:17:52 +0800 Subject: vendor: sync consensus core and fix conflict --- core/vm/governance.go | 15 +- dex/app.go | 5 +- dex/governance.go | 19 +- dex/handler.go | 9 +- dex/network.go | 7 +- dex/peer.go | 17 +- .../dexon-consensus-core/core/authenticator.go | 11 +- .../dexon-consensus-core/core/compaction-chain.go | 4 +- .../core/configuration-chain.go | 13 +- .../dexon-consensus-core/core/consensus.go | 19 +- .../dexon-consensus-core/core/crypto.go | 26 ++- .../dexon-consensus-core/core/dkg-tsig-protocol.go | 47 ++--- .../dexon-consensus-core/core/interfaces.go | 17 +- .../dexon-consensus-core/core/types/block.go | 46 ++--- .../dexon-consensus-core/core/types/dkg.go | 193 -------------------- .../dexon-consensus-core/core/types/dkg/dkg.go | 194 +++++++++++++++++++++ .../dexon-consensus-core/core/types/position.go | 2 +- vendor/vendor.json | 38 ++-- 18 files changed, 334 insertions(+), 348 deletions(-) delete mode 100644 vendor/github.com/dexon-foundation/dexon-consensus-core/core/types/dkg.go create mode 100644 vendor/github.com/dexon-foundation/dexon-consensus-core/core/types/dkg/dkg.go diff --git a/core/vm/governance.go b/core/vm/governance.go index 5c5822261..3570482dc 100644 --- a/core/vm/governance.go +++ b/core/vm/governance.go @@ -33,6 +33,7 @@ import ( coreCrypto "github.com/dexon-foundation/dexon-consensus-core/core/crypto" "github.com/dexon-foundation/dexon-consensus-core/core/crypto/ecdsa" coreTypes "github.com/dexon-foundation/dexon-consensus-core/core/types" + dkgTypes "github.com/dexon-foundation/dexon-consensus-core/core/types/dkg" ) var GovernanceContractAddress = common.HexToAddress("5765692d4e696e6720536f6e696320426f6a6965") @@ -1394,7 +1395,7 @@ func (g *GovernanceContract) addDKGComplaint(round *big.Int, comp []byte) ([]byt return nil, errExecutionReverted } - var dkgComplaint coreTypes.DKGComplaint + var dkgComplaint dkgTypes.Complaint if err := rlp.DecodeBytes(comp, &dkgComplaint); err != nil { g.penalize() return nil, errExecutionReverted @@ -1434,7 +1435,7 @@ func (g *GovernanceContract) addDKGMasterPublicKey(round *big.Int, mpk []byte) ( return nil, errExecutionReverted } - var dkgMasterPK coreTypes.DKGMasterPublicKey + var dkgMasterPK dkgTypes.MasterPublicKey if err := rlp.DecodeBytes(mpk, &dkgMasterPK); err != nil { g.penalize() return nil, errExecutionReverted @@ -1467,7 +1468,7 @@ func (g *GovernanceContract) addDKGFinalize(round *big.Int, finalize []byte) ([] caller := g.contract.Caller() - var dkgFinalize coreTypes.DKGFinalize + var dkgFinalize dkgTypes.Finalize if err := rlp.DecodeBytes(finalize, &dkgFinalize); err != nil { g.penalize() return nil, errExecutionReverted @@ -1566,9 +1567,9 @@ func (g *GovernanceContract) proposeCRS(nextRound *big.Int, signedCRS []byte) ([ // Prepare DKGMasterPublicKeys. // TODO(w): make sure DKGMasterPKs are unique. - var dkgMasterPKs []*coreTypes.DKGMasterPublicKey + var dkgMasterPKs []*dkgTypes.MasterPublicKey for _, mpk := range g.state.DKGMasterPublicKeys(round) { - x := new(coreTypes.DKGMasterPublicKey) + x := new(dkgTypes.MasterPublicKey) if err := rlp.DecodeBytes(mpk, x); err != nil { panic(err) } @@ -1576,9 +1577,9 @@ func (g *GovernanceContract) proposeCRS(nextRound *big.Int, signedCRS []byte) ([ } // Prepare DKGComplaints. - var dkgComplaints []*coreTypes.DKGComplaint + var dkgComplaints []*dkgTypes.Complaint for _, comp := range g.state.DKGComplaints(round) { - x := new(coreTypes.DKGComplaint) + x := new(dkgTypes.Complaint) if err := rlp.DecodeBytes(comp, x); err != nil { panic(err) } diff --git a/dex/app.go b/dex/app.go index d5b7d3556..b1558b46f 100644 --- a/dex/app.go +++ b/dex/app.go @@ -261,9 +261,8 @@ func (d *DexconApp) PrepareWitness(consensusHeight uint64) (witness coreTypes.Wi } return coreTypes.Witness{ - Timestamp: time.Unix(witnessBlock.Time().Int64(), 0), - Height: witnessBlock.NumberU64(), - Data: witnessData, + Height: witnessBlock.NumberU64(), + Data: witnessData, }, nil } diff --git a/dex/governance.go b/dex/governance.go index c7ea440dd..69c1e217f 100644 --- a/dex/governance.go +++ b/dex/governance.go @@ -12,6 +12,7 @@ import ( coreCrypto "github.com/dexon-foundation/dexon-consensus-core/core/crypto" coreEcdsa "github.com/dexon-foundation/dexon-consensus-core/core/crypto/ecdsa" coreTypes "github.com/dexon-foundation/dexon-consensus-core/core/types" + dkgTypes "github.com/dexon-foundation/dexon-consensus-core/core/types/dkg" "github.com/dexon-foundation/dexon/common" "github.com/dexon-foundation/dexon/core/types" @@ -204,7 +205,7 @@ func (d *DexconGovernance) NotifyRoundHeight(targetRound, consensusHeight uint64 } // AddDKGComplaint adds a DKGComplaint. -func (d *DexconGovernance) AddDKGComplaint(round uint64, complaint *coreTypes.DKGComplaint) { +func (d *DexconGovernance) AddDKGComplaint(round uint64, complaint *dkgTypes.Complaint) { method := vm.GovernanceContractName2Method["addDKGComplaint"] encoded, err := rlp.EncodeToBytes(complaint) @@ -227,11 +228,11 @@ func (d *DexconGovernance) AddDKGComplaint(round uint64, complaint *coreTypes.DK } // DKGComplaints gets all the DKGComplaints of round. -func (d *DexconGovernance) DKGComplaints(round uint64) []*coreTypes.DKGComplaint { +func (d *DexconGovernance) DKGComplaints(round uint64) []*dkgTypes.Complaint { s := d.getGovState() - var dkgComplaints []*coreTypes.DKGComplaint + var dkgComplaints []*dkgTypes.Complaint for _, pk := range s.DKGComplaints(big.NewInt(int64(round))) { - x := new(coreTypes.DKGComplaint) + x := new(dkgTypes.Complaint) if err := rlp.DecodeBytes(pk, x); err != nil { panic(err) } @@ -241,7 +242,7 @@ func (d *DexconGovernance) DKGComplaints(round uint64) []*coreTypes.DKGComplaint } // AddDKGMasterPublicKey adds a DKGMasterPublicKey. -func (d *DexconGovernance) AddDKGMasterPublicKey(round uint64, masterPublicKey *coreTypes.DKGMasterPublicKey) { +func (d *DexconGovernance) AddDKGMasterPublicKey(round uint64, masterPublicKey *dkgTypes.MasterPublicKey) { method := vm.GovernanceContractName2Method["addDKGMasterPublicKey"] encoded, err := rlp.EncodeToBytes(masterPublicKey) @@ -264,11 +265,11 @@ func (d *DexconGovernance) AddDKGMasterPublicKey(round uint64, masterPublicKey * } // DKGMasterPublicKeys gets all the DKGMasterPublicKey of round. -func (d *DexconGovernance) DKGMasterPublicKeys(round uint64) []*coreTypes.DKGMasterPublicKey { +func (d *DexconGovernance) DKGMasterPublicKeys(round uint64) []*dkgTypes.MasterPublicKey { s := d.getGovState() - var dkgMasterPKs []*coreTypes.DKGMasterPublicKey + var dkgMasterPKs []*dkgTypes.MasterPublicKey for _, pk := range s.DKGMasterPublicKeys(big.NewInt(int64(round))) { - x := new(coreTypes.DKGMasterPublicKey) + x := new(dkgTypes.MasterPublicKey) if err := rlp.DecodeBytes(pk, x); err != nil { panic(err) } @@ -278,7 +279,7 @@ func (d *DexconGovernance) DKGMasterPublicKeys(round uint64) []*coreTypes.DKGMas } // AddDKGFinalize adds a DKG finalize message. -func (d *DexconGovernance) AddDKGFinalize(round uint64, final *coreTypes.DKGFinalize) { +func (d *DexconGovernance) AddDKGFinalize(round uint64, final *dkgTypes.Finalize) { method := vm.GovernanceContractName2Method["addDKGFinalize"] encoded, err := rlp.EncodeToBytes(final) diff --git a/dex/handler.go b/dex/handler.go index 2b7e1cee1..be50cb43d 100644 --- a/dex/handler.go +++ b/dex/handler.go @@ -28,6 +28,7 @@ import ( coreCrypto "github.com/dexon-foundation/dexon-consensus-core/core/crypto" coreTypes "github.com/dexon-foundation/dexon-consensus-core/core/types" + dkgTypes "github.com/dexon-foundation/dexon-consensus-core/core/types/dkg" "github.com/dexon-foundation/dexon/common" "github.com/dexon-foundation/dexon/consensus" @@ -736,14 +737,14 @@ func (pm *ProtocolManager) handleMsg(p *peer) error { pm.receiveCh <- &randomness case msg.Code == DKGPrivateShareMsg: // Do not relay this msg - var ps coreTypes.DKGPrivateShare + var ps dkgTypes.PrivateShare if err := msg.Decode(&ps); err != nil { return errResp(ErrDecode, "msg %v: %v", msg, err) } pm.receiveCh <- &ps case msg.Code == DKGPartialSignatureMsg: // broadcast in DKG set - var psig coreTypes.DKGPartialSignature + var psig dkgTypes.PartialSignature if err := msg.Decode(&psig); err != nil { return errResp(ErrDecode, "msg %v: %v", msg, err) } @@ -896,7 +897,7 @@ func (pm *ProtocolManager) SendDKGPrivateShare( } func (pm *ProtocolManager) BroadcastDKGPrivateShare( - privateShare *coreTypes.DKGPrivateShare) { + privateShare *dkgTypes.PrivateShare) { label := peerLabel{set: dkgset, round: privateShare.Round} for _, peer := range pm.peers.PeersWithLabel(label) { if !peer.knownDKGPrivateShares.Contains(rlpHash(privateShare)) { @@ -906,7 +907,7 @@ func (pm *ProtocolManager) BroadcastDKGPrivateShare( } func (pm *ProtocolManager) BroadcastDKGPartialSignature( - psig *coreTypes.DKGPartialSignature) { + psig *dkgTypes.PartialSignature) { label := peerLabel{set: dkgset, round: psig.Round} for _, peer := range pm.peers.PeersWithLabel(label) { if !peer.knownDKGPartialSignatures.Contains(rlpHash(psig)) { diff --git a/dex/network.go b/dex/network.go index e99b4f5b1..0d45973ec 100644 --- a/dex/network.go +++ b/dex/network.go @@ -3,6 +3,7 @@ package dex import ( "github.com/dexon-foundation/dexon-consensus-core/core/crypto" "github.com/dexon-foundation/dexon-consensus-core/core/types" + dkgTypes "github.com/dexon-foundation/dexon-consensus-core/core/types/dkg" ) type DexconNetwork struct { @@ -25,20 +26,20 @@ func (n *DexconNetwork) BroadcastBlock(block *types.Block) { // SendDKGPrivateShare sends PrivateShare to a DKG participant. func (n *DexconNetwork) SendDKGPrivateShare( - pub crypto.PublicKey, prvShare *types.DKGPrivateShare) { + pub crypto.PublicKey, prvShare *dkgTypes.PrivateShare) { n.pm.SendDKGPrivateShare(pub, prvShare) } // BroadcastDKGPrivateShare broadcasts PrivateShare to all DKG participants. func (n *DexconNetwork) BroadcastDKGPrivateShare( - prvShare *types.DKGPrivateShare) { + prvShare *dkgTypes.PrivateShare) { n.pm.BroadcastDKGPrivateShare(prvShare) } // BroadcastDKGPartialSignature broadcasts partialSignature to all // DKG participants. func (n *DexconNetwork) BroadcastDKGPartialSignature( - psig *types.DKGPartialSignature) { + psig *dkgTypes.PartialSignature) { n.pm.BroadcastDKGPartialSignature(psig) } diff --git a/dex/peer.go b/dex/peer.go index a5e0dd21a..195be920e 100644 --- a/dex/peer.go +++ b/dex/peer.go @@ -25,6 +25,7 @@ import ( mapset "github.com/deckarep/golang-set" coreTypes "github.com/dexon-foundation/dexon-consensus-core/core/types" + dkgTypes "github.com/dexon-foundation/dexon-consensus-core/core/types/dkg" "github.com/dexon-foundation/dexon/common" "github.com/dexon-foundation/dexon/core/types" @@ -138,8 +139,8 @@ type peer struct { queuedVotes chan *coreTypes.Vote queuedAgreements chan *coreTypes.AgreementResult queuedRandomnesses chan *coreTypes.BlockRandomnessResult - queuedDKGPrivateShares chan *coreTypes.DKGPrivateShare - queuedDKGPartialSignatures chan *coreTypes.DKGPartialSignature + queuedDKGPrivateShares chan *dkgTypes.PrivateShare + queuedDKGPartialSignatures chan *dkgTypes.PartialSignature term chan struct{} // Termination channel to stop the broadcaster } @@ -166,8 +167,8 @@ func newPeer(version int, p *p2p.Peer, rw p2p.MsgReadWriter) *peer { queuedVotes: make(chan *coreTypes.Vote, maxQueuedVotes), queuedAgreements: make(chan *coreTypes.AgreementResult, maxQueuedAgreements), queuedRandomnesses: make(chan *coreTypes.BlockRandomnessResult, maxQueuedRandomnesses), - queuedDKGPrivateShares: make(chan *coreTypes.DKGPrivateShare, maxQueuedDKGPrivateShare), - queuedDKGPartialSignatures: make(chan *coreTypes.DKGPartialSignature, maxQueuedDKGParitialSignature), + queuedDKGPrivateShares: make(chan *dkgTypes.PrivateShare, maxQueuedDKGPrivateShare), + queuedDKGPartialSignatures: make(chan *dkgTypes.PartialSignature, maxQueuedDKGParitialSignature), term: make(chan struct{}), } } @@ -443,12 +444,12 @@ func (p *peer) AsyncSendRandomness(randomness *coreTypes.BlockRandomnessResult) } } -func (p *peer) SendDKGPrivateShare(privateShare *coreTypes.DKGPrivateShare) error { +func (p *peer) SendDKGPrivateShare(privateShare *dkgTypes.PrivateShare) error { p.knownDKGPrivateShares.Add(rlpHash(privateShare)) return p2p.Send(p.rw, DKGPrivateShareMsg, privateShare) } -func (p *peer) AsyncSendDKGPrivateShare(privateShare *coreTypes.DKGPrivateShare) { +func (p *peer) AsyncSendDKGPrivateShare(privateShare *dkgTypes.PrivateShare) { select { case p.queuedDKGPrivateShares <- privateShare: p.knownDKGPrivateShares.Add(rlpHash(privateShare)) @@ -457,12 +458,12 @@ func (p *peer) AsyncSendDKGPrivateShare(privateShare *coreTypes.DKGPrivateShare) } } -func (p *peer) SendDKGPartialSignature(psig *coreTypes.DKGPartialSignature) error { +func (p *peer) SendDKGPartialSignature(psig *dkgTypes.PartialSignature) error { p.knownDKGPartialSignatures.Add(rlpHash(psig)) return p2p.Send(p.rw, DKGPartialSignatureMsg, psig) } -func (p *peer) AsyncSendDKGPartialSignature(psig *coreTypes.DKGPartialSignature) { +func (p *peer) AsyncSendDKGPartialSignature(psig *dkgTypes.PartialSignature) { select { case p.queuedDKGPartialSignatures <- psig: p.knownDKGPartialSignatures.Add(rlpHash(psig)) 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.go deleted file mode 100644 index edd420df9..000000000 --- a/vendor/github.com/dexon-foundation/dexon-consensus-core/core/types/dkg.go +++ /dev/null @@ -1,193 +0,0 @@ -// Copyright 2018 The dexon-consensus-core Authors -// This file is part of the dexon-consensus-core library. -// -// The dexon-consensus-core library is free software: you can redistribute it -// and/or modify it under the terms of the GNU Lesser General Public License as -// published by the Free Software Foundation, either version 3 of the License, -// or (at your option) any later version. -// -// The dexon-consensus-core library is distributed in the hope that it will be -// useful, but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser -// General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with the dexon-consensus-core library. If not, see -// . - -package types - -import ( - "bytes" - "encoding/json" - "fmt" - "io" - - "github.com/dexon-foundation/dexon/rlp" - - "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" -) - -// 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"` -} - -// Equal checks equality between two DKGPrivateShare instances. -func (p *DKGPrivateShare) Equal(other *DKGPrivateShare) bool { - return p.ProposerID.Equal(other.ProposerID) && - p.ReceiverID.Equal(other.ReceiverID) && - p.Round == other.Round && - p.Signature.Type == other.Signature.Type && - bytes.Compare(p.Signature.Signature, other.Signature.Signature) == 0 && - bytes.Compare( - 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"` -} - -func (d *DKGMasterPublicKey) 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 { - return d.ProposerID.Equal(other.ProposerID) && - d.Round == other.Round && - d.DKGID.GetHexString() == other.DKGID.GetHexString() && - d.PublicKeyShares.Equal(&other.PublicKeyShares) && - d.Signature.Type == other.Signature.Type && - bytes.Compare(d.Signature.Signature, other.Signature.Signature) == 0 -} - -type rlpDKGMasterPublicKey struct { - ProposerID NodeID - Round uint64 - DKGID []byte - PublicKeyShares *dkg.PublicKeyShares - Signature crypto.Signature -} - -// EncodeRLP implements rlp.Encoder -func (d *DKGMasterPublicKey) EncodeRLP(w io.Writer) error { - return rlp.Encode(w, rlpDKGMasterPublicKey{ - ProposerID: d.ProposerID, - Round: d.Round, - DKGID: d.DKGID.GetLittleEndian(), - PublicKeyShares: &d.PublicKeyShares, - Signature: d.Signature, - }) -} - -// DecodeRLP implements rlp.Decoder -func (d *DKGMasterPublicKey) DecodeRLP(s *rlp.Stream) error { - var dec rlpDKGMasterPublicKey - if err := s.Decode(&dec); err != nil { - return err - } - - id, err := dkg.BytesID(dec.DKGID) - if err != nil { - return err - } - - *d = DKGMasterPublicKey{ - ProposerID: dec.ProposerID, - Round: dec.Round, - DKGID: id, - PublicKeyShares: *dec.PublicKeyShares, - Signature: dec.Signature, - } - return err -} - -// NewDKGMasterPublicKey returns a new DKGMasterPublicKey instance. -func NewDKGMasterPublicKey() *DKGMasterPublicKey { - return &DKGMasterPublicKey{ - PublicKeyShares: *dkg.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)) -} - -// DKGComplaint describe a complaint in DKG protocol. -type DKGComplaint struct { - ProposerID NodeID `json:"proposer_id"` - Round uint64 `json:"round"` - PrivateShare DKGPrivateShare `json:"private_share"` - Signature crypto.Signature `json:"signature"` -} - -func (c *DKGComplaint) 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", - c.ProposerID.String()[:6], c.Round, c.PrivateShare) -} - -// Equal checks equality between two DKGComplaint instances. -func (c *DKGComplaint) Equal(other *DKGComplaint) bool { - return c.ProposerID.Equal(other.ProposerID) && - c.Round == other.Round && - c.PrivateShare.Equal(&other.PrivateShare) && - c.Signature.Type == other.Signature.Type && - 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"` -} - -// DKGFinalize describe a dig finalize message in DKG protocol. -type DKGFinalize struct { - ProposerID NodeID `json:"proposer_id"` - Round uint64 `json:"round"` - Signature crypto.Signature `json:"signature"` -} - -func (final *DKGFinalize) 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 { - return final.ProposerID.Equal(other.ProposerID) && - final.Round == other.Round && - final.Signature.Type == other.Signature.Type && - bytes.Compare(final.Signature.Signature, other.Signature.Signature) == 0 -} - -// IsNack returns true if it's a nack complaint in DKG protocol. -func (c *DKGComplaint) IsNack() bool { - return len(c.PrivateShare.Signature.Signature) == 0 -} diff --git a/vendor/github.com/dexon-foundation/dexon-consensus-core/core/types/dkg/dkg.go b/vendor/github.com/dexon-foundation/dexon-consensus-core/core/types/dkg/dkg.go new file mode 100644 index 000000000..ee00f140f --- /dev/null +++ b/vendor/github.com/dexon-foundation/dexon-consensus-core/core/types/dkg/dkg.go @@ -0,0 +1,194 @@ +// Copyright 2018 The dexon-consensus-core Authors +// This file is part of the dexon-consensus-core library. +// +// The dexon-consensus-core library is free software: you can redistribute it +// and/or modify it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation, either version 3 of the License, +// or (at your option) any later version. +// +// The dexon-consensus-core library is distributed in the hope that it will be +// useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser +// General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public License +// along with the dexon-consensus-core library. If not, see +// . + +package dkg + +import ( + "bytes" + "encoding/json" + "fmt" + "io" + + "github.com/dexon-foundation/dexon/rlp" + + "github.com/dexon-foundation/dexon-consensus-core/common" + "github.com/dexon-foundation/dexon-consensus-core/core/crypto" + cryptoDKG "github.com/dexon-foundation/dexon-consensus-core/core/crypto/dkg" + "github.com/dexon-foundation/dexon-consensus-core/core/types" +) + +// 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 PrivateShare instances. +func (p *PrivateShare) Equal(other *PrivateShare) bool { + return p.ProposerID.Equal(other.ProposerID) && + p.ReceiverID.Equal(other.ReceiverID) && + p.Round == other.Round && + p.Signature.Type == other.Signature.Type && + bytes.Compare(p.Signature.Signature, other.Signature.Signature) == 0 && + bytes.Compare( + p.PrivateShare.Bytes(), other.PrivateShare.Bytes()) == 0 +} + +// 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 *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 *MasterPublicKey) Equal(other *MasterPublicKey) bool { + return d.ProposerID.Equal(other.ProposerID) && + d.Round == other.Round && + d.DKGID.GetHexString() == other.DKGID.GetHexString() && + d.PublicKeyShares.Equal(&other.PublicKeyShares) && + d.Signature.Type == other.Signature.Type && + bytes.Compare(d.Signature.Signature, other.Signature.Signature) == 0 +} + +type rlpMasterPublicKey struct { + ProposerID types.NodeID + Round uint64 + DKGID []byte + PublicKeyShares *cryptoDKG.PublicKeyShares + Signature crypto.Signature +} + +// EncodeRLP implements rlp.Encoder +func (d *MasterPublicKey) EncodeRLP(w io.Writer) error { + return rlp.Encode(w, rlpMasterPublicKey{ + ProposerID: d.ProposerID, + Round: d.Round, + DKGID: d.DKGID.GetLittleEndian(), + PublicKeyShares: &d.PublicKeyShares, + Signature: d.Signature, + }) +} + +// DecodeRLP implements rlp.Decoder +func (d *MasterPublicKey) DecodeRLP(s *rlp.Stream) error { + var dec rlpMasterPublicKey + if err := s.Decode(&dec); err != nil { + return err + } + + id, err := cryptoDKG.BytesID(dec.DKGID) + if err != nil { + return err + } + + *d = MasterPublicKey{ + ProposerID: dec.ProposerID, + Round: dec.Round, + DKGID: id, + PublicKeyShares: *dec.PublicKeyShares, + Signature: dec.Signature, + } + return err +} + +// NewMasterPublicKey returns a new MasterPublicKey instance. +func NewMasterPublicKey() *MasterPublicKey { + return &MasterPublicKey{ + PublicKeyShares: *cryptoDKG.NewEmptyPublicKeyShares(), + } +} + +// UnmarshalJSON implements json.Unmarshaller. +func (d *MasterPublicKey) UnmarshalJSON(data []byte) error { + type innertMasterPublicKey MasterPublicKey + d.PublicKeyShares = *cryptoDKG.NewEmptyPublicKeyShares() + return json.Unmarshal(data, (*innertMasterPublicKey)(d)) +} + +// Complaint describe a complaint in DKG protocol. +type Complaint struct { + ProposerID types.NodeID `json:"proposer_id"` + Round uint64 `json:"round"` + PrivateShare PrivateShare `json:"private_share"` + Signature crypto.Signature `json:"signature"` +} + +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("Complaint[%s:%d]%v", + c.ProposerID.String()[:6], c.Round, c.PrivateShare) +} + +// 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) && + c.Signature.Type == other.Signature.Type && + bytes.Compare(c.Signature.Signature, other.Signature.Signature) == 0 +} + +// 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"` +} + +// 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 *Finalize) String() string { + return fmt.Sprintf("DKGFinal[%s:%d]", + final.ProposerID.String()[:6], + final.Round) +} + +// 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 && + bytes.Compare(final.Signature.Signature, other.Signature.Signature) == 0 +} + +// IsNack returns true if it's a nack complaint in DKG protocol. +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=", -- cgit