aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/dexon-foundation/dexon-consensus/core/configuration-chain.go
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2018-11-20 13:51:27 +0800
committerWei-Ning Huang <w@byzantine-lab.io>2019-06-12 17:27:18 +0800
commit194c8fdc922b4173cf433e8f92711459b97c3ab0 (patch)
tree337ebd9c4a22cec51e32d6f03d15988156ad137b /vendor/github.com/dexon-foundation/dexon-consensus/core/configuration-chain.go
parentd035ac7c8c624fc884dbc300a2ec7dcaf8dc1905 (diff)
downloadgo-tangerine-194c8fdc922b4173cf433e8f92711459b97c3ab0.tar
go-tangerine-194c8fdc922b4173cf433e8f92711459b97c3ab0.tar.gz
go-tangerine-194c8fdc922b4173cf433e8f92711459b97c3ab0.tar.bz2
go-tangerine-194c8fdc922b4173cf433e8f92711459b97c3ab0.tar.lz
go-tangerine-194c8fdc922b4173cf433e8f92711459b97c3ab0.tar.xz
go-tangerine-194c8fdc922b4173cf433e8f92711459b97c3ab0.tar.zst
go-tangerine-194c8fdc922b4173cf433e8f92711459b97c3ab0.zip
vendor: sync to latest core (#37)
Diffstat (limited to 'vendor/github.com/dexon-foundation/dexon-consensus/core/configuration-chain.go')
-rw-r--r--vendor/github.com/dexon-foundation/dexon-consensus/core/configuration-chain.go39
1 files changed, 32 insertions, 7 deletions
diff --git a/vendor/github.com/dexon-foundation/dexon-consensus/core/configuration-chain.go b/vendor/github.com/dexon-foundation/dexon-consensus/core/configuration-chain.go
index bda2fdf62..fdfcd13d0 100644
--- a/vendor/github.com/dexon-foundation/dexon-consensus/core/configuration-chain.go
+++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/configuration-chain.go
@@ -26,6 +26,7 @@ import (
"github.com/dexon-foundation/dexon-consensus/core/crypto"
"github.com/dexon-foundation/dexon-consensus/core/types"
typesDKG "github.com/dexon-foundation/dexon-consensus/core/types/dkg"
+ "github.com/dexon-foundation/dexon-consensus/core/utils"
)
// Errors for configuration chain..
@@ -51,7 +52,7 @@ type configurationChain struct {
tsig map[common.Hash]*tsigProtocol
tsigTouched map[common.Hash]struct{}
tsigReady *sync.Cond
- cache *NodeSetCache
+ cache *utils.NodeSetCache
dkgSet map[types.NodeID]struct{}
mpkReady bool
pendingPrvShare map[types.NodeID]*typesDKG.PrivateShare
@@ -64,7 +65,7 @@ func newConfigurationChain(
ID types.NodeID,
recv dkgReceiver,
gov Governance,
- cache *NodeSetCache,
+ cache *utils.NodeSetCache,
logger common.Logger) *configurationChain {
return &configurationChain{
ID: ID,
@@ -106,6 +107,10 @@ func (cc *configurationChain) runDKG(round uint64) error {
cc.dkgLock.Lock()
defer cc.dkgLock.Unlock()
if cc.dkg == nil || cc.dkg.round != round {
+ if cc.dkg != nil && cc.dkg.round > round {
+ cc.logger.Warn("DKG canceled", "round", round)
+ return nil
+ }
return ErrDKGNotRegistered
}
if func() bool {
@@ -116,6 +121,11 @@ func (cc *configurationChain) runDKG(round uint64) error {
}() {
return nil
}
+ cc.logger.Debug("Calling Governance.IsDKGFinal", "round", round)
+ if cc.gov.IsDKGFinal(round) {
+ cc.logger.Warn("DKG already final", "round", round)
+ return nil
+ }
ticker := newTicker(cc.gov, round, TickerDKG)
cc.dkgLock.Unlock()
@@ -182,10 +192,6 @@ func (cc *configurationChain) runDKG(round uint64) error {
if err != nil {
return err
}
- signer, err := cc.dkg.recoverShareSecret(gpk.qualifyIDs)
- if err != nil {
- return err
- }
qualifies := ""
for nID := range gpk.qualifyNodeIDs {
qualifies += fmt.Sprintf("%s ", nID.String()[:6])
@@ -195,6 +201,14 @@ func (cc *configurationChain) runDKG(round uint64) error {
"round", round,
"count", len(gpk.qualifyIDs),
"qualifies", qualifies)
+ if _, exist := gpk.qualifyNodeIDs[cc.ID]; !exist {
+ cc.logger.Warn("Self is not in Qualify Nodes")
+ return nil
+ }
+ signer, err := cc.dkg.recoverShareSecret(gpk.qualifyIDs)
+ if err != nil {
+ return err
+ }
cc.dkgResult.Lock()
defer cc.dkgResult.Unlock()
cc.dkgSigner[round] = signer
@@ -264,13 +278,24 @@ func (cc *configurationChain) runTSig(
}
}
}()
+ timeout := make(chan struct{}, 1)
+ go func() {
+ // TODO(jimmy-dexon): make timeout configurable.
+ time.Sleep(5 * time.Second)
+ timeout <- struct{}{}
+ cc.tsigReady.Broadcast()
+ }()
var signature crypto.Signature
var err error
for func() bool {
signature, err = cc.tsig[hash].signature()
+ select {
+ case <-timeout:
+ return false
+ default:
+ }
return err == ErrNotEnoughtPartialSignatures
}() {
- // TODO(jimmy-dexon): add a timeout here.
cc.tsigReady.Wait()
}
delete(cc.tsig, hash)