From d240e0cdec95681cf595609809dea4224dc479df Mon Sep 17 00:00:00 2001 From: Jimmy Hu Date: Mon, 22 Oct 2018 21:05:28 +0800 Subject: core: Handling self proposed DKG private share (#236) --- core/consensus.go | 33 ++++++++++++++++++++++----------- core/crypto/dkg/dkg.go | 10 +++++----- core/types/dkg.go | 18 +++++++----------- 3 files changed, 34 insertions(+), 27 deletions(-) (limited to 'core') diff --git a/core/consensus.go b/core/consensus.go index 478aedb..7154b1b 100644 --- a/core/consensus.go +++ b/core/consensus.go @@ -130,6 +130,7 @@ type consensusDKGReceiver struct { gov Governance authModule *Authenticator nodeSetCache *NodeSetCache + cfgModule *configurationChain network Network logger common.Logger } @@ -170,9 +171,17 @@ func (recv *consensusDKGReceiver) ProposeDKGPrivateShare( "receiver", prv.ReceiverID.String()[:6]) return } - recv.logger.Debug("Calling Network.SendDKGPrivateShare", - "receiver", hex.EncodeToString(receiverPubKey.Bytes())) - recv.network.SendDKGPrivateShare(receiverPubKey, prv) + if prv.ReceiverID == recv.ID { + go func() { + if err := recv.cfgModule.processPrivateShare(prv); err != nil { + recv.logger.Error("Failed to process self private share", "prvShare", prv) + } + }() + } else { + recv.logger.Debug("Calling Network.SendDKGPrivateShare", + "receiver", hex.EncodeToString(receiverPubKey.Bytes())) + recv.network.SendDKGPrivateShare(receiverPubKey, prv) + } } // ProposeDKGAntiNackComplaint propose a DKGPrivateShare as an anti complaint. @@ -273,18 +282,20 @@ func NewConsensus( dMoment, config, authModule, nbModule, nbModule, db, logger) // Init configuration chain. ID := types.NewNodeID(prv.PublicKey()) + recv := &consensusDKGReceiver{ + ID: ID, + gov: gov, + authModule: authModule, + nodeSetCache: nodeSetCache, + network: network, + logger: logger, + } cfgModule := newConfigurationChain( ID, - &consensusDKGReceiver{ - ID: ID, - gov: gov, - authModule: authModule, - nodeSetCache: nodeSetCache, - network: network, - logger: logger, - }, + recv, gov, logger) + recv.cfgModule = cfgModule // Construct Consensus instance. con := &Consensus{ ID: ID, diff --git a/core/crypto/dkg/dkg.go b/core/crypto/dkg/dkg.go index 8ca511d..066b070 100644 --- a/core/crypto/dkg/dkg.go +++ b/core/crypto/dkg/dkg.go @@ -388,15 +388,15 @@ func (pubs *PublicKeyShares) RecoverPublicKey(qualifyIDs IDs) ( return nil, ErrNoIDToRecover } for i, ID := range qualifyIDs { - idx, exist := pubs.shareIndex[ID] - if !exist { - return nil, ErrShareNotFound + pk, err := pubs.Share(ID) + if err != nil { + return nil, err } if i == 0 { - pub.publicKey = pubs.shares[idx].publicKey + pub.publicKey = pk.publicKey continue } - pub.publicKey.Add(&pubs.shares[idx].publicKey) + pub.publicKey.Add(&pk.publicKey) } return &pub, nil } diff --git a/core/types/dkg.go b/core/types/dkg.go index c0a42ee..3bdb414 100644 --- a/core/types/dkg.go +++ b/core/types/dkg.go @@ -38,15 +38,6 @@ type DKGPrivateShare struct { Signature crypto.Signature `json:"signature"` } -func (p *DKGPrivateShare) String() string { - return fmt.Sprintf("prvShare(%d:%s->%s:%s:%s)", - p.Round, - p.ProposerID.String()[:6], - p.ReceiverID.String()[:6], - p.PrivateShare.String(), - p.Signature.String()[:6]) -} - // DKGMasterPublicKey decrtibe a master public key in DKG protocol. type DKGMasterPublicKey struct { ProposerID NodeID `json:"proposer_id"` @@ -126,8 +117,13 @@ type DKGComplaint struct { } func (c *DKGComplaint) String() string { - return fmt.Sprintf("DKGComplaint[%s:%d]%s", - c.ProposerID.String()[:6], c.Round, &c.PrivateShare) + 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) } // DKGPartialSignature describe a partial signature in DKG protocol. -- cgit v1.2.3