diff options
author | Jimmy Hu <jimmy.hu@dexon.org> | 2019-03-12 11:39:23 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-03-12 11:39:23 +0800 |
commit | d111602d77a06d16a3206247a15895779720cfcf (patch) | |
tree | 189cd0fd73167f2c9fb20db0821c6eb16b999eb8 /core/configuration-chain.go | |
parent | c3bda77db1c2620c5212d4369792b923227d2570 (diff) | |
download | dexon-consensus-d111602d77a06d16a3206247a15895779720cfcf.tar dexon-consensus-d111602d77a06d16a3206247a15895779720cfcf.tar.gz dexon-consensus-d111602d77a06d16a3206247a15895779720cfcf.tar.bz2 dexon-consensus-d111602d77a06d16a3206247a15895779720cfcf.tar.lz dexon-consensus-d111602d77a06d16a3206247a15895779720cfcf.tar.xz dexon-consensus-d111602d77a06d16a3206247a15895779720cfcf.tar.zst dexon-consensus-d111602d77a06d16a3206247a15895779720cfcf.zip |
core: split GroupPublicKey and NodePublicKeys (#484)
* core: add benchmark
* core: split NPKs and GPK
* Add benchmark
Diffstat (limited to 'core/configuration-chain.go')
-rw-r--r-- | core/configuration-chain.go | 48 |
1 files changed, 24 insertions, 24 deletions
diff --git a/core/configuration-chain.go b/core/configuration-chain.go index ecca43c..9e8df6b 100644 --- a/core/configuration-chain.go +++ b/core/configuration-chain.go @@ -48,7 +48,7 @@ type configurationChain struct { logger common.Logger dkgLock sync.RWMutex dkgSigner map[uint64]*dkgShareSecret - gpk map[uint64]*typesDKG.GroupPublicKey + npks map[uint64]*typesDKG.NodePublicKeys dkgResult sync.RWMutex tsig map[common.Hash]*tsigProtocol tsigTouched map[common.Hash]struct{} @@ -76,7 +76,7 @@ func newConfigurationChain( gov: gov, logger: logger, dkgSigner: make(map[uint64]*dkgShareSecret), - gpk: make(map[uint64]*typesDKG.GroupPublicKey), + npks: make(map[uint64]*typesDKG.NodePublicKeys), tsig: make(map[common.Hash]*tsigProtocol), tsigTouched: make(map[common.Hash]struct{}), tsigReady: sync.NewCond(&sync.Mutex{}), @@ -221,7 +221,7 @@ func (cc *configurationChain) runDKG(round uint64) error { } cc.logger.Debug("Calling Governance.DKGMasterPublicKeys", "round", round) cc.logger.Debug("Calling Governance.DKGComplaints", "round", round) - gpk, err := typesDKG.NewGroupPublicKey(round, + npks, err := typesDKG.NewNodePublicKeys(round, cc.gov.DKGMasterPublicKeys(round), cc.gov.DKGComplaints(round), cc.dkg.threshold) @@ -229,19 +229,19 @@ func (cc *configurationChain) runDKG(round uint64) error { return err } qualifies := "" - for nID := range gpk.QualifyNodeIDs { + for nID := range npks.QualifyNodeIDs { qualifies += fmt.Sprintf("%s ", nID.String()[:6]) } cc.logger.Info("Qualify Nodes", "nodeID", cc.ID, "round", round, - "count", len(gpk.QualifyIDs), + "count", len(npks.QualifyIDs), "qualifies", qualifies) - if _, exist := gpk.QualifyNodeIDs[cc.ID]; !exist { + if _, exist := npks.QualifyNodeIDs[cc.ID]; !exist { cc.logger.Warn("Self is not in Qualify Nodes") return nil } - signer, err := cc.dkg.recoverShareSecret(gpk.QualifyIDs) + signer, err := cc.dkg.recoverShareSecret(npks.QualifyIDs) if err != nil { return err } @@ -252,7 +252,7 @@ func (cc *configurationChain) runDKG(round uint64) error { cc.dkgResult.Lock() defer cc.dkgResult.Unlock() cc.dkgSigner[round] = signer - cc.gpk[round] = gpk + cc.npks[round] = npks return nil } @@ -265,40 +265,40 @@ func (cc *configurationChain) isDKGFinal(round uint64) bool { } func (cc *configurationChain) getDKGInfo( - round uint64) (*typesDKG.GroupPublicKey, *dkgShareSecret, error) { - getFromCache := func() (*typesDKG.GroupPublicKey, *dkgShareSecret) { + round uint64) (*typesDKG.NodePublicKeys, *dkgShareSecret, error) { + getFromCache := func() (*typesDKG.NodePublicKeys, *dkgShareSecret) { cc.dkgResult.RLock() defer cc.dkgResult.RUnlock() - gpk := cc.gpk[round] + npks := cc.npks[round] signer := cc.dkgSigner[round] - return gpk, signer + return npks, signer } - gpk, signer := getFromCache() - if gpk == nil || signer == nil { + npks, signer := getFromCache() + if npks == nil || signer == nil { if err := cc.recoverDKGInfo(round); err != nil { return nil, nil, err } - gpk, signer = getFromCache() + npks, signer = getFromCache() } - if gpk == nil || signer == nil { + if npks == nil || signer == nil { return nil, nil, ErrDKGNotReady } - return gpk, signer, nil + return npks, signer, nil } func (cc *configurationChain) recoverDKGInfo(round uint64) error { cc.dkgResult.Lock() defer cc.dkgResult.Unlock() _, signerExists := cc.dkgSigner[round] - _, gpkExists := cc.gpk[round] - if signerExists && gpkExists { + _, npksExists := cc.npks[round] + if signerExists && npksExists { return nil } if !cc.gov.IsDKGFinal(round) { return ErrDKGNotReady } // Restore group public key. - gpk, err := typesDKG.NewGroupPublicKey(round, + npks, err := typesDKG.NewNodePublicKeys(round, cc.gov.DKGMasterPublicKeys(round), cc.gov.DKGComplaints(round), utils.GetDKGThreshold( @@ -311,7 +311,7 @@ func (cc *configurationChain) recoverDKGInfo(round uint64) error { if err != nil { return err } - cc.gpk[round] = gpk + cc.npks[round] = npks cc.dkgSigner[round] = &dkgShareSecret{ privateKey: &prvKey, } @@ -349,8 +349,8 @@ func (cc *configurationChain) untouchTSigHash(hash common.Hash) { func (cc *configurationChain) runTSig( round uint64, hash common.Hash) ( crypto.Signature, error) { - gpk, _, _ := cc.getDKGInfo(round) - if gpk == nil { + npks, _, _ := cc.getDKGInfo(round) + if npks == nil { return crypto.Signature{}, ErrDKGNotReady } cc.tsigReady.L.Lock() @@ -358,7 +358,7 @@ func (cc *configurationChain) runTSig( if _, exist := cc.tsig[hash]; exist { return crypto.Signature{}, ErrTSigAlreadyRunning } - cc.tsig[hash] = newTSigProtocol(gpk, hash) + cc.tsig[hash] = newTSigProtocol(npks, hash) pendingPsig := cc.pendingPsig[hash] delete(cc.pendingPsig, hash) go func() { |