aboutsummaryrefslogtreecommitdiffstats
path: root/vendor
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2018-12-21 12:03:28 +0800
committerWei-Ning Huang <w@dexon.org>2019-03-12 12:19:09 +0800
commit4002c85e8e073f3a03dbd8c71e98188c0306a942 (patch)
tree1f9a380677a5622ba2cd735cb23e3900a05d3c64 /vendor
parent8b9b63c5c11689a402ee07e4dbf251a8f40870eb (diff)
downloaddexon-4002c85e8e073f3a03dbd8c71e98188c0306a942.tar.gz
dexon-4002c85e8e073f3a03dbd8c71e98188c0306a942.tar.zst
dexon-4002c85e8e073f3a03dbd8c71e98188c0306a942.zip
core: vm: Add `MPKReady` to governance (#97)
* core/vm: Add DKGMPKReady * param: update GenesisHash * vendor: sync to latest core
Diffstat (limited to 'vendor')
-rw-r--r--vendor/github.com/dexon-foundation/dexon-consensus/core/agreement-mgr.go5
-rw-r--r--vendor/github.com/dexon-foundation/dexon-consensus/core/authenticator.go8
-rw-r--r--vendor/github.com/dexon-foundation/dexon-consensus/core/compaction-chain.go12
-rw-r--r--vendor/github.com/dexon-foundation/dexon-consensus/core/configuration-chain.go37
-rw-r--r--vendor/github.com/dexon-foundation/dexon-consensus/core/consensus.go102
-rw-r--r--vendor/github.com/dexon-foundation/dexon-consensus/core/crypto.go24
-rw-r--r--vendor/github.com/dexon-foundation/dexon-consensus/core/db/level-db.go2
-rw-r--r--vendor/github.com/dexon-foundation/dexon-consensus/core/db/memory.go2
-rw-r--r--vendor/github.com/dexon-foundation/dexon-consensus/core/dkg-tsig-protocol.go13
-rw-r--r--vendor/github.com/dexon-foundation/dexon-consensus/core/interfaces.go6
-rw-r--r--vendor/github.com/dexon-foundation/dexon-consensus/core/ticker.go12
-rw-r--r--vendor/github.com/dexon-foundation/dexon-consensus/core/types/dkg/dkg.go21
-rw-r--r--vendor/github.com/dexon-foundation/dexon-consensus/core/utils/utils.go61
-rw-r--r--vendor/vendor.json44
14 files changed, 264 insertions, 85 deletions
diff --git a/vendor/github.com/dexon-foundation/dexon-consensus/core/agreement-mgr.go b/vendor/github.com/dexon-foundation/dexon-consensus/core/agreement-mgr.go
index 4cb47b105..fb6536463 100644
--- a/vendor/github.com/dexon-foundation/dexon-consensus/core/agreement-mgr.go
+++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/agreement-mgr.go
@@ -248,9 +248,10 @@ func (mgr *agreementMgr) processAgreementResult(
"hash", result.BlockHash)
mgr.network.PullBlocks(common.Hashes{result.BlockHash})
mgr.logger.Debug("Calling Governance.CRS", "round", result.Position.Round)
- crs := mgr.gov.CRS(result.Position.Round)
+ crs := utils.GetCRSWithPanic(mgr.gov, result.Position.Round, mgr.logger)
nIDs := nodes.GetSubSet(
- int(mgr.gov.Configuration(result.Position.Round).NotarySetSize),
+ int(utils.GetConfigWithPanic(
+ mgr.gov, result.Position.Round, mgr.logger).NotarySetSize),
types.NewNotarySetTarget(crs, result.Position.ChainID))
for key := range result.Votes {
if err := agreement.processVote(&result.Votes[key]); err != nil {
diff --git a/vendor/github.com/dexon-foundation/dexon-consensus/core/authenticator.go b/vendor/github.com/dexon-foundation/dexon-consensus/core/authenticator.go
index 5d176cfee..8e57f719f 100644
--- a/vendor/github.com/dexon-foundation/dexon-consensus/core/authenticator.go
+++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/authenticator.go
@@ -103,6 +103,14 @@ func (au *Authenticator) SignDKGPartialSignature(
return
}
+// SignDKGMPKReady signs a DKG ready message.
+func (au *Authenticator) SignDKGMPKReady(
+ ready *typesDKG.MPKReady) (err error) {
+ ready.ProposerID = au.proposerID
+ ready.Signature, err = au.prvKey.Sign(hashDKGMPKReady(ready))
+ return
+}
+
// SignDKGFinalize signs a DKG finalize message.
func (au *Authenticator) SignDKGFinalize(
final *typesDKG.Finalize) (err error) {
diff --git a/vendor/github.com/dexon-foundation/dexon-consensus/core/compaction-chain.go b/vendor/github.com/dexon-foundation/dexon-consensus/core/compaction-chain.go
index dcd99f497..14e3b265d 100644
--- a/vendor/github.com/dexon-foundation/dexon-consensus/core/compaction-chain.go
+++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/compaction-chain.go
@@ -25,6 +25,7 @@ import (
"github.com/dexon-foundation/dexon-consensus/common"
"github.com/dexon-foundation/dexon-consensus/core/crypto"
"github.com/dexon-foundation/dexon-consensus/core/types"
+ "github.com/dexon-foundation/dexon-consensus/core/utils"
)
// Errors for compaction chain module.
@@ -80,7 +81,7 @@ func (cc *compactionChain) init(initBlock *types.Block) {
// It's the bootstrap case, compactionChain would only deliver blocks until
// tips of all chains are received.
if initBlock.Finalization.Height == 0 {
- cc.chainUnsynced = cc.gov.Configuration(uint64(0)).NumChains
+ cc.chainUnsynced = utils.GetConfigWithPanic(cc.gov, 0, nil).NumChains
}
}
@@ -124,8 +125,6 @@ func (cc *compactionChain) processBlock(block *types.Block) error {
}
func (cc *compactionChain) extractBlocks() []*types.Block {
- prevBlock := cc.lastDeliveredBlock()
-
// Check if we're synced.
if !func() bool {
cc.lock.RLock()
@@ -134,7 +133,7 @@ func (cc *compactionChain) extractBlocks() []*types.Block {
return false
}
// Finalization.Height == 0 is syncing from bootstrap.
- if prevBlock.Finalization.Height == 0 {
+ if cc.prevBlock.Finalization.Height == 0 {
return cc.chainUnsynced == 0
}
return true
@@ -144,7 +143,10 @@ func (cc *compactionChain) extractBlocks() []*types.Block {
deliveringBlocks := make([]*types.Block, 0)
cc.lock.Lock()
defer cc.lock.Unlock()
- var block *types.Block
+ var (
+ block *types.Block
+ prevBlock = cc.prevBlock
+ )
for len(cc.pendingBlocks) > 0 &&
(len(cc.blockRandomness[cc.pendingBlocks[0].Hash]) != 0 ||
cc.pendingBlocks[0].Position.Round == 0) {
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 2b3a859ed..d341cb524 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
@@ -105,6 +105,13 @@ func (cc *configurationChain) registerDKG(round uint64, threshold int) {
cc.recv,
round,
threshold)
+ go func() {
+ ticker := newTicker(cc.gov, round, TickerDKG)
+ <-ticker.Tick()
+ cc.dkgLock.Lock()
+ defer cc.dkgLock.Unlock()
+ cc.dkg.proposeMPKReady()
+ }()
}
func (cc *configurationChain) runDKG(round uint64) error {
@@ -126,13 +133,34 @@ func (cc *configurationChain) runDKG(round uint64) error {
cc.logger.Warn("DKG already final", "round", round)
return nil
}
+ cc.logger.Debug("Calling Governance.IsDKGMPKReady", "round", round)
+ for !cc.gov.IsDKGMPKReady(round) {
+ cc.logger.Info("DKG MPKs are not ready yet. Try again later...",
+ "nodeID", cc.ID)
+ cc.dkgLock.Unlock()
+ time.Sleep(500 * time.Millisecond)
+ cc.dkgLock.Lock()
+ }
ticker := newTicker(cc.gov, round, TickerDKG)
cc.dkgLock.Unlock()
<-ticker.Tick()
cc.dkgLock.Lock()
- // Phase 2(T = 0): Exchange DKG secret key share.
+ // Check if this node successfully join the protocol.
cc.logger.Debug("Calling Governance.DKGMasterPublicKeys", "round", round)
- cc.dkg.processMasterPublicKeys(cc.gov.DKGMasterPublicKeys(round))
+ mpks := cc.gov.DKGMasterPublicKeys(round)
+ inProtocol := false
+ for _, mpk := range mpks {
+ if mpk.ProposerID == cc.ID {
+ inProtocol = true
+ break
+ }
+ }
+ if !inProtocol {
+ cc.logger.Warn("Failed to join DKG protocol", "round", round)
+ return nil
+ }
+ // Phase 2(T = 0): Exchange DKG secret key share.
+ cc.dkg.processMasterPublicKeys(mpks)
cc.mpkReady = true
for _, prvShare := range cc.pendingPrvShare {
if err := cc.dkg.processPrivateShare(prvShare); err != nil {
@@ -219,7 +247,7 @@ func (cc *configurationChain) runDKG(round uint64) error {
return nil
}
-func (cc *configurationChain) isDKGReady(round uint64) bool {
+func (cc *configurationChain) isDKGFinal(round uint64) bool {
if !cc.gov.IsDKGFinal(round) {
return false
}
@@ -261,7 +289,8 @@ func (cc *configurationChain) recoverDKGInfo(round uint64) error {
return ErrDKGNotReady
}
- threshold := getDKGThreshold(cc.gov.Configuration(round))
+ threshold := getDKGThreshold(
+ utils.GetConfigWithPanic(cc.gov, round, cc.logger))
// Restore group public key.
gpk, err := NewDKGGroupPublicKey(round,
cc.gov.DKGMasterPublicKeys(round),
diff --git a/vendor/github.com/dexon-foundation/dexon-consensus/core/consensus.go b/vendor/github.com/dexon-foundation/dexon-consensus/core/consensus.go
index 5beaf546a..e45e4be5a 100644
--- a/vendor/github.com/dexon-foundation/dexon-consensus/core/consensus.go
+++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/consensus.go
@@ -329,6 +329,16 @@ func (recv *consensusDKGReceiver) ProposeDKGAntiNackComplaint(
recv.network.BroadcastDKGPrivateShare(prv)
}
+// ProposeDKGMPKReady propose a DKGMPKReady message.
+func (recv *consensusDKGReceiver) ProposeDKGMPKReady(ready *typesDKG.MPKReady) {
+ if err := recv.authModule.SignDKGMPKReady(ready); err != nil {
+ recv.logger.Error("Failed to sign DKG ready", "error", err)
+ return
+ }
+ recv.logger.Debug("Calling Governance.AddDKGMPKReady", "ready", ready)
+ recv.gov.AddDKGMPKReady(ready.Round, ready)
+}
+
// ProposeDKGFinalize propose a DKGFinalize message.
func (recv *consensusDKGReceiver) ProposeDKGFinalize(final *typesDKG.Finalize) {
if err := recv.authModule.SignDKGFinalize(final); err != nil {
@@ -400,12 +410,7 @@ func NewConsensus(
}
// Get configuration for genesis round.
var round uint64
- logger.Debug("Calling Governance.Configuration", "round", round)
- config := gov.Configuration(round)
- if config == nil {
- logger.Error("Unable to get configuration", "round", round)
- return nil
- }
+ config := utils.GetConfigWithPanic(gov, round, logger)
// Init lattice.
lattice := NewLattice(
dMoment, round, config, authModule, app, debugApp, db, logger)
@@ -494,12 +499,17 @@ func NewConsensusFromSyncer(
db,
logger)
recv.cfgModule = cfgModule
+ // Check if the application implement Debug interface.
+ var debugApp Debug
+ if a, ok := app.(Debug); ok {
+ debugApp = a
+ }
// Setup Consensus instance.
con := &Consensus{
ID: ID,
ccModule: newCompactionChain(gov),
lattice: latticeModule,
- app: app,
+ app: newNonBlocking(app, debugApp),
gov: gov,
db: db,
network: networkModule,
@@ -545,29 +555,19 @@ func (con *Consensus) prepare(initBlock *types.Block) error {
// full node. We don't have to notify it.
con.roundToNotify = initBlock.Position.Round + 1
initRound := initBlock.Position.Round
- con.logger.Debug("Calling Governance.Configuration", "round", initRound)
- initConfig := con.gov.Configuration(initRound)
+ initConfig := utils.GetConfigWithPanic(con.gov, initRound, con.logger)
// Setup context.
con.ccModule.init(initBlock)
- // Setup agreementMgr module.
- con.logger.Debug("Calling Governance.Configuration", "round", initRound)
- initCfg := con.gov.Configuration(initRound)
- if initCfg == nil {
- return ErrConfigurationNotReady
- }
con.logger.Debug("Calling Governance.CRS", "round", initRound)
initCRS := con.gov.CRS(initRound)
if (initCRS == common.Hash{}) {
return ErrCRSNotReady
}
- if err := con.baMgr.appendConfig(initRound, initCfg, initCRS); err != nil {
+ if err := con.baMgr.appendConfig(initRound, initConfig, initCRS); err != nil {
return err
}
// Setup lattice module.
- initPlusOneCfg := con.gov.Configuration(initRound + 1)
- if initPlusOneCfg == nil {
- return ErrConfigurationNotReady
- }
+ initPlusOneCfg := utils.GetConfigWithPanic(con.gov, initRound+1, con.logger)
if err := con.lattice.AppendConfig(initRound+1, initPlusOneCfg); err != nil {
return err
}
@@ -576,6 +576,7 @@ func (con *Consensus) prepare(initBlock *types.Block) error {
if err != nil {
return err
}
+ // TODO(jimmy): registerDKG should be called after dmoment.
if _, exist := dkgSet[con.ID]; exist {
con.logger.Info("Selected as DKG set", "round", initRound)
con.cfgModule.registerDKG(initRound, getDKGThreshold(initConfig))
@@ -641,7 +642,7 @@ func (con *Consensus) runCRS(round uint64) {
}
con.logger.Debug("Calling Governance.IsDKGFinal to check if ready to run CRS",
"round", round)
- if con.cfgModule.isDKGReady(round) {
+ if con.cfgModule.isDKGFinal(round) {
break
}
con.logger.Debug("DKG is not ready for running CRS. Retry later...",
@@ -650,7 +651,8 @@ func (con *Consensus) runCRS(round uint64) {
}
// Start running next round CRS.
con.logger.Debug("Calling Governance.CRS", "round", round)
- psig, err := con.cfgModule.preparePartialSignature(round, con.gov.CRS(round))
+ psig, err := con.cfgModule.preparePartialSignature(
+ round, utils.GetCRSWithPanic(con.gov, round, con.logger))
if err != nil {
con.logger.Error("Failed to prepare partial signature", "error", err)
} else if err = con.authModule.SignDKGPartialSignature(psig); err != nil {
@@ -664,7 +666,8 @@ func (con *Consensus) runCRS(round uint64) {
"hash", psig.Hash)
con.network.BroadcastDKGPartialSignature(psig)
con.logger.Debug("Calling Governance.CRS", "round", round)
- crs, err := con.cfgModule.runCRSTSig(round, con.gov.CRS(round))
+ crs, err := con.cfgModule.runCRSTSig(
+ round, utils.GetCRSWithPanic(con.gov, round, con.logger))
if err != nil {
con.logger.Error("Failed to run CRS Tsig", "error", err)
} else {
@@ -709,12 +712,11 @@ func (con *Consensus) initialRound(
time.Sleep(500 * time.Millisecond)
}
// Notify BA for new round.
- con.logger.Debug("Calling Governance.Configuration",
- "round", nextRound)
- nextConfig := con.gov.Configuration(nextRound)
+ nextConfig := utils.GetConfigWithPanic(
+ con.gov, nextRound, con.logger)
con.logger.Debug("Calling Governance.CRS",
"round", nextRound)
- nextCRS := con.gov.CRS(nextRound)
+ nextCRS := utils.GetCRSWithPanic(con.gov, nextRound, con.logger)
if err := con.baMgr.appendConfig(
nextRound, nextConfig, nextCRS); err != nil {
panic(err)
@@ -753,9 +755,8 @@ func (con *Consensus) initialRound(
defer con.dkgReady.L.Unlock()
con.dkgRunning = 0
}()
- con.logger.Debug("Calling Governance.Configuration",
- "round", nextRound)
- nextConfig := con.gov.Configuration(nextRound)
+ nextConfig := utils.GetConfigWithPanic(
+ con.gov, nextRound, con.logger)
con.runDKG(nextRound, nextConfig)
})
}(round + 1)
@@ -766,9 +767,7 @@ func (con *Consensus) initialRound(
// Change round.
// Get configuration for next round.
nextRound := round + 1
- con.logger.Debug("Calling Governance.Configuration",
- "round", nextRound)
- nextConfig := con.gov.Configuration(nextRound)
+ nextConfig := utils.GetConfigWithPanic(con.gov, nextRound, con.logger)
con.initialRound(
startTime.Add(config.RoundInterval), nextRound, nextConfig)
})
@@ -990,7 +989,7 @@ func (con *Consensus) ProcessBlockRandomnessResult(
"randomness", hex.EncodeToString(rand.Randomness))
con.network.BroadcastRandomnessResult(rand)
}
- return nil
+ return con.deliverFinalizedBlocks()
}
// preProcessBlock performs Byzantine Agreement on the block.
@@ -1021,9 +1020,7 @@ func (con *Consensus) deliverBlock(b *types.Block) {
// - roundShift
// - notifyGenesisRound
futureRound := con.roundToNotify + 1
- con.logger.Debug("Calling Governance.Configuration",
- "round", con.roundToNotify)
- futureConfig := con.gov.Configuration(futureRound)
+ futureConfig := utils.GetConfigWithPanic(con.gov, futureRound, con.logger)
con.logger.Debug("Append Config", "round", futureRound)
if err := con.lattice.AppendConfig(
futureRound, futureConfig); err != nil {
@@ -1046,6 +1043,28 @@ func (con *Consensus) deliverBlock(b *types.Block) {
}
}
+// deliverFinalizedBlocks extracts and delivers finalized blocks to application
+// layer.
+func (con *Consensus) deliverFinalizedBlocks() error {
+ con.lock.Lock()
+ defer con.lock.Unlock()
+ return con.deliverFinalizedBlocksWithoutLock()
+}
+
+func (con *Consensus) deliverFinalizedBlocksWithoutLock() (err error) {
+ deliveredBlocks := con.ccModule.extractBlocks()
+ con.logger.Debug("Last blocks in compaction chain",
+ "delivered", con.ccModule.lastDeliveredBlock(),
+ "pending", con.ccModule.lastPendingBlock())
+ for _, b := range deliveredBlocks {
+ con.deliverBlock(b)
+ }
+ if err = con.lattice.PurgeBlocks(deliveredBlocks); err != nil {
+ return
+ }
+ return
+}
+
// processBlock is the entry point to submit one block to a Consensus instance.
func (con *Consensus) processBlock(block *types.Block) (err error) {
if err = con.db.PutBlock(*block); err != nil && err != db.ErrBlockExists {
@@ -1079,14 +1098,7 @@ func (con *Consensus) processBlock(block *types.Block) (err error) {
}
go con.event.NotifyTime(b.Finalization.Timestamp)
}
- deliveredBlocks = con.ccModule.extractBlocks()
- con.logger.Debug("Last blocks in compaction chain",
- "delivered", con.ccModule.lastDeliveredBlock(),
- "pending", con.ccModule.lastPendingBlock())
- for _, b := range deliveredBlocks {
- con.deliverBlock(b)
- }
- if err = con.lattice.PurgeBlocks(deliveredBlocks); err != nil {
+ if err = con.deliverFinalizedBlocksWithoutLock(); err != nil {
return
}
return
diff --git a/vendor/github.com/dexon-foundation/dexon-consensus/core/crypto.go b/vendor/github.com/dexon-foundation/dexon-consensus/core/crypto.go
index 914ca0865..d4a7f0ead 100644
--- a/vendor/github.com/dexon-foundation/dexon-consensus/core/crypto.go
+++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/crypto.go
@@ -243,6 +243,30 @@ func verifyDKGPartialSignatureSignature(
return true, nil
}
+func hashDKGMPKReady(ready *typesDKG.MPKReady) common.Hash {
+ binaryRound := make([]byte, 8)
+ binary.LittleEndian.PutUint64(binaryRound, ready.Round)
+
+ return crypto.Keccak256Hash(
+ ready.ProposerID.Hash[:],
+ binaryRound,
+ )
+}
+
+// VerifyDKGMPKReadySignature verifies DKGMPKReady signature.
+func VerifyDKGMPKReadySignature(
+ ready *typesDKG.MPKReady) (bool, error) {
+ hash := hashDKGMPKReady(ready)
+ pubKey, err := crypto.SigToPub(hash, ready.Signature)
+ if err != nil {
+ return false, err
+ }
+ if ready.ProposerID != types.NewNodeID(pubKey) {
+ return false, nil
+ }
+ return true, nil
+}
+
func hashDKGFinalize(final *typesDKG.Finalize) common.Hash {
binaryRound := make([]byte, 8)
binary.LittleEndian.PutUint64(binaryRound, final.Round)
diff --git a/vendor/github.com/dexon-foundation/dexon-consensus/core/db/level-db.go b/vendor/github.com/dexon-foundation/dexon-consensus/core/db/level-db.go
index 3b5994b26..75c30372f 100644
--- a/vendor/github.com/dexon-foundation/dexon-consensus/core/db/level-db.go
+++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/db/level-db.go
@@ -163,7 +163,7 @@ func (lvl *LevelDBBackedDB) PutCompactionChainTipInfo(
if err != nil {
return err
}
- if info.Height >= height {
+ if info.Height+1 != height {
return ErrInvalidCompactionChainTipHeight
}
if err = lvl.db.Put(compactionChainTipInfoKey, marshaled, nil); err != nil {
diff --git a/vendor/github.com/dexon-foundation/dexon-consensus/core/db/memory.go b/vendor/github.com/dexon-foundation/dexon-consensus/core/db/memory.go
index 7393de9db..4bc08e704 100644
--- a/vendor/github.com/dexon-foundation/dexon-consensus/core/db/memory.go
+++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/db/memory.go
@@ -149,7 +149,7 @@ func (m *MemBackedDB) PutCompactionChainTipInfo(
blockHash common.Hash, height uint64) error {
m.compactionChainTipLock.Lock()
defer m.compactionChainTipLock.Unlock()
- if m.compactionChainTipHeight >= height {
+ if m.compactionChainTipHeight+1 != height {
return ErrInvalidCompactionChainTipHeight
}
m.compactionChainTipHeight = height
diff --git a/vendor/github.com/dexon-foundation/dexon-consensus/core/dkg-tsig-protocol.go b/vendor/github.com/dexon-foundation/dexon-consensus/core/dkg-tsig-protocol.go
index 8e03cbbda..ef12cf992 100644
--- a/vendor/github.com/dexon-foundation/dexon-consensus/core/dkg-tsig-protocol.go
+++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/dkg-tsig-protocol.go
@@ -26,6 +26,7 @@ import (
"github.com/dexon-foundation/dexon-consensus/core/crypto/dkg"
"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 dkg module.
@@ -67,6 +68,9 @@ type dkgReceiver interface {
// ProposeDKGAntiNackComplaint propose a DKGPrivateShare as an anti complaint.
ProposeDKGAntiNackComplaint(prv *typesDKG.PrivateShare)
+ // ProposeDKGMPKReady propose a DKGMPKReady message.
+ ProposeDKGMPKReady(ready *typesDKG.MPKReady)
+
// ProposeDKGFinalize propose a DKGFinalize message.
ProposeDKGFinalize(final *typesDKG.Finalize)
}
@@ -338,6 +342,13 @@ func (d *dkgProtocol) processPrivateShare(
return nil
}
+func (d *dkgProtocol) proposeMPKReady() {
+ d.recv.ProposeDKGMPKReady(&typesDKG.MPKReady{
+ ProposerID: d.ID,
+ Round: d.round,
+ })
+}
+
func (d *dkgProtocol) proposeFinalize() {
d.recv.ProposeDKGFinalize(&typesDKG.Finalize{
ProposerID: d.ID,
@@ -491,7 +502,7 @@ func (tc *TSigVerifierCache) Update(round uint64) (bool, error) {
gpk, err := NewDKGGroupPublicKey(round,
tc.intf.DKGMasterPublicKeys(round),
tc.intf.DKGComplaints(round),
- int(tc.intf.Configuration(round).DKGSetSize/3)+1)
+ int(utils.GetConfigWithPanic(tc.intf, round, nil).DKGSetSize/3)+1)
if err != nil {
return false, err
}
diff --git a/vendor/github.com/dexon-foundation/dexon-consensus/core/interfaces.go b/vendor/github.com/dexon-foundation/dexon-consensus/core/interfaces.go
index 2ebfe8621..fc3bf09bc 100644
--- a/vendor/github.com/dexon-foundation/dexon-consensus/core/interfaces.go
+++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/interfaces.go
@@ -130,6 +130,12 @@ type Governance interface {
// DKGMasterPublicKeys gets all the DKGMasterPublicKey of round.
DKGMasterPublicKeys(round uint64) []*typesDKG.MasterPublicKey
+ // AddDKGMPKReady adds a DKG ready message.
+ AddDKGMPKReady(round uint64, ready *typesDKG.MPKReady)
+
+ // IsDKGFinal checks if DKG is ready.
+ IsDKGMPKReady(round uint64) bool
+
// AddDKGFinalize adds a DKG finalize message.
AddDKGFinalize(round uint64, final *typesDKG.Finalize)
diff --git a/vendor/github.com/dexon-foundation/dexon-consensus/core/ticker.go b/vendor/github.com/dexon-foundation/dexon-consensus/core/ticker.go
index 3728a79e6..f8d0c67d9 100644
--- a/vendor/github.com/dexon-foundation/dexon-consensus/core/ticker.go
+++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/ticker.go
@@ -17,7 +17,11 @@
package core
-import "time"
+import (
+ "time"
+
+ "github.com/dexon-foundation/dexon-consensus/core/utils"
+)
// TickerType is the type of ticker.
type TickerType int
@@ -65,11 +69,11 @@ func newTicker(gov Governance, round uint64, tickerType TickerType) (t Ticker) {
var duration time.Duration
switch tickerType {
case TickerBA:
- duration = gov.Configuration(round).LambdaBA
+ duration = utils.GetConfigWithPanic(gov, round, nil).LambdaBA
case TickerDKG:
- duration = gov.Configuration(round).LambdaDKG
+ duration = utils.GetConfigWithPanic(gov, round, nil).LambdaDKG
case TickerCRS:
- duration = gov.Configuration(round).RoundInterval / 2
+ duration = utils.GetConfigWithPanic(gov, round, nil).RoundInterval / 2
}
t = newDefaultTicker(duration)
}
diff --git a/vendor/github.com/dexon-foundation/dexon-consensus/core/types/dkg/dkg.go b/vendor/github.com/dexon-foundation/dexon-consensus/core/types/dkg/dkg.go
index cecc4f16c..f021d1bfb 100644
--- a/vendor/github.com/dexon-foundation/dexon-consensus/core/types/dkg/dkg.go
+++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/types/dkg/dkg.go
@@ -167,6 +167,27 @@ type PartialSignature struct {
Signature crypto.Signature `json:"signature"`
}
+// MPKReady describe a dig ready message in DKG protocol.
+type MPKReady struct {
+ ProposerID types.NodeID `json:"proposer_id"`
+ Round uint64 `json:"round"`
+ Signature crypto.Signature `json:"signature"`
+}
+
+func (ready *MPKReady) String() string {
+ return fmt.Sprintf("DKGMPKReady{RP:%s Round:%d}",
+ ready.ProposerID.String()[:6],
+ ready.Round)
+}
+
+// Equal check equality of two MPKReady instances.
+func (ready *MPKReady) Equal(other *MPKReady) bool {
+ return ready.ProposerID.Equal(other.ProposerID) &&
+ ready.Round == other.Round &&
+ ready.Signature.Type == other.Signature.Type &&
+ bytes.Compare(ready.Signature.Signature, other.Signature.Signature) == 0
+}
+
// Finalize describe a dig finalize message in DKG protocol.
type Finalize struct {
ProposerID types.NodeID `json:"proposer_id"`
diff --git a/vendor/github.com/dexon-foundation/dexon-consensus/core/utils/utils.go b/vendor/github.com/dexon-foundation/dexon-consensus/core/utils/utils.go
new file mode 100644
index 000000000..3e3803d06
--- /dev/null
+++ b/vendor/github.com/dexon-foundation/dexon-consensus/core/utils/utils.go
@@ -0,0 +1,61 @@
+// This file is part of the dexon-consensus library.
+//
+// The dexon-consensus 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 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 library. If not, see
+// <http://www.gnu.org/licenses/>.
+
+package utils
+
+import (
+ "fmt"
+
+ "github.com/dexon-foundation/dexon-consensus/common"
+ "github.com/dexon-foundation/dexon-consensus/core/types"
+)
+
+type configAccessor interface {
+ Configuration(round uint64) *types.Config
+}
+
+// GetConfigWithPanic is a helper to access configs, and panic when config for
+// that round is not ready yet.
+func GetConfigWithPanic(accessor configAccessor, round uint64,
+ logger common.Logger) *types.Config {
+ if logger != nil {
+ logger.Debug("Calling Governance.Configuration", "round", round)
+ }
+ c := accessor.Configuration(round)
+ if c == nil {
+ panic(fmt.Errorf("configuration is not ready %v", round))
+ }
+ return c
+}
+
+type crsAccessor interface {
+ CRS(round uint64) common.Hash
+}
+
+// GetCRSWithPanic is a helper to access CRS, and panic when CRS for that
+// round is not ready yet.
+func GetCRSWithPanic(accessor crsAccessor, round uint64,
+ logger common.Logger) common.Hash {
+ if logger != nil {
+ logger.Debug("Calling Governance.CRS", "round", round)
+ }
+ crs := accessor.CRS(round)
+ if (crs == common.Hash{}) {
+ panic(fmt.Errorf("CRS is not ready %v", round))
+ }
+ return crs
+
+}
diff --git a/vendor/vendor.json b/vendor/vendor.json
index add9ce181..f524bce16 100644
--- a/vendor/vendor.json
+++ b/vendor/vendor.json
@@ -105,14 +105,14 @@
{
"checksumSHA1": "65L1yf+f0OCiLFniljqfRxVdsQA=",
"path": "github.com/dexon-foundation/dexon-consensus/common",
- "revision": "99d72382687196fb15ea6ab0fcf297b9ab10ac46",
- "revisionTime": "2018-12-16T06:44:15Z"
+ "revision": "146ed32cf841151b826eafd7d6ade188c56865bf",
+ "revisionTime": "2018-12-20T09:26:30Z"
},
{
- "checksumSHA1": "jZLh+ZsuMIiMuksK9c/5QpMQ2IM=",
+ "checksumSHA1": "DxtHhW/eYFodiPxgwu7opvIhJu0=",
"path": "github.com/dexon-foundation/dexon-consensus/core",
- "revision": "99d72382687196fb15ea6ab0fcf297b9ab10ac46",
- "revisionTime": "2018-12-16T06:44:15Z"
+ "revision": "146ed32cf841151b826eafd7d6ade188c56865bf",
+ "revisionTime": "2018-12-20T09:26:30Z"
},
{
"checksumSHA1": "v4fKR7uhoyufi6hAVO44cFEb+tY=",
@@ -123,44 +123,44 @@
{
"checksumSHA1": "tQSbYCu5P00lUhKsx3IbBZCuSLY=",
"path": "github.com/dexon-foundation/dexon-consensus/core/crypto",
- "revision": "99d72382687196fb15ea6ab0fcf297b9ab10ac46",
- "revisionTime": "2018-12-16T06:44:15Z"
+ "revision": "146ed32cf841151b826eafd7d6ade188c56865bf",
+ "revisionTime": "2018-12-20T09:26:30Z"
},
{
"checksumSHA1": "W2P7pkuJ+26BpJg03K4Y0nB5obI=",
"path": "github.com/dexon-foundation/dexon-consensus/core/crypto/dkg",
- "revision": "99d72382687196fb15ea6ab0fcf297b9ab10ac46",
- "revisionTime": "2018-12-16T06:44:15Z"
+ "revision": "146ed32cf841151b826eafd7d6ade188c56865bf",
+ "revisionTime": "2018-12-20T09:26:30Z"
},
{
"checksumSHA1": "6Pf6caC8LTNCI7IflFmglKYnxYo=",
"path": "github.com/dexon-foundation/dexon-consensus/core/crypto/ecdsa",
- "revision": "99d72382687196fb15ea6ab0fcf297b9ab10ac46",
- "revisionTime": "2018-12-16T06:44:15Z"
+ "revision": "146ed32cf841151b826eafd7d6ade188c56865bf",
+ "revisionTime": "2018-12-20T09:26:30Z"
},
{
- "checksumSHA1": "trkFVPLd7UFFUzL8bn6KuvFU9gE=",
+ "checksumSHA1": "PJXR1OuWwVVYrdJMK3skPr1/8ls=",
"path": "github.com/dexon-foundation/dexon-consensus/core/db",
- "revision": "99d72382687196fb15ea6ab0fcf297b9ab10ac46",
- "revisionTime": "2018-12-16T06:44:15Z"
+ "revision": "146ed32cf841151b826eafd7d6ade188c56865bf",
+ "revisionTime": "2018-12-20T09:26:30Z"
},
{
"checksumSHA1": "Z079qQV+aQV9A3kSJ0LbFjx5VO4=",
"path": "github.com/dexon-foundation/dexon-consensus/core/types",
- "revision": "99d72382687196fb15ea6ab0fcf297b9ab10ac46",
- "revisionTime": "2018-12-16T06:44:15Z"
+ "revision": "146ed32cf841151b826eafd7d6ade188c56865bf",
+ "revisionTime": "2018-12-20T09:26:30Z"
},
{
- "checksumSHA1": "Sn3PAYsblIXmr7gVKDzxnoBPku4=",
+ "checksumSHA1": "sY+2eiOoWvsNMvuPl9qQ+rlT9sA=",
"path": "github.com/dexon-foundation/dexon-consensus/core/types/dkg",
- "revision": "99d72382687196fb15ea6ab0fcf297b9ab10ac46",
- "revisionTime": "2018-12-16T06:44:15Z"
+ "revision": "146ed32cf841151b826eafd7d6ade188c56865bf",
+ "revisionTime": "2018-12-20T09:26:30Z"
},
{
- "checksumSHA1": "A7UQ+7rv9FuElmFBEn/ZdhBqFKI=",
+ "checksumSHA1": "WEtKiyBYr0oPUSF+smv1A2LPBuI=",
"path": "github.com/dexon-foundation/dexon-consensus/core/utils",
- "revision": "99d72382687196fb15ea6ab0fcf297b9ab10ac46",
- "revisionTime": "2018-12-16T06:44:15Z"
+ "revision": "146ed32cf841151b826eafd7d6ade188c56865bf",
+ "revisionTime": "2018-12-20T09:26:30Z"
},
{
"checksumSHA1": "TAkwduKZqLyimyTPPWIllZWYFuE=",