aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2019-02-18 18:44:35 +0800
committerJimmy Hu <jimmy.hu@dexon.org>2019-02-19 10:48:50 +0800
commit2cf18fd299ea0fc270b213343314cab652cac271 (patch)
tree4b53df22100f8c263ada1964d6ef55bb4174e372
parent4dbdc22e355cf1f6f0c39af1b2f3737b7527bc0c (diff)
downloadtangerine-consensus-2cf18fd299ea0fc270b213343314cab652cac271.tar
tangerine-consensus-2cf18fd299ea0fc270b213343314cab652cac271.tar.gz
tangerine-consensus-2cf18fd299ea0fc270b213343314cab652cac271.tar.bz2
tangerine-consensus-2cf18fd299ea0fc270b213343314cab652cac271.tar.lz
tangerine-consensus-2cf18fd299ea0fc270b213343314cab652cac271.tar.xz
tangerine-consensus-2cf18fd299ea0fc270b213343314cab652cac271.tar.zst
tangerine-consensus-2cf18fd299ea0fc270b213343314cab652cac271.zip
core: fix stuffs (#448)
* Add log * core: delay first dkg * Fix test * core: only runDKG in prepare at round 0
-rw-r--r--core/blockchain.go4
-rw-r--r--core/consensus.go37
-rw-r--r--core/consensus_test.go1
3 files changed, 26 insertions, 16 deletions
diff --git a/core/blockchain.go b/core/blockchain.go
index bfa8552..d1aa644 100644
--- a/core/blockchain.go
+++ b/core/blockchain.go
@@ -550,9 +550,13 @@ func (bc *blockChain) prepareBlock(position types.Position,
}
b.ParentHash = tip.Hash
if !empty {
+ bc.logger.Debug("Calling Application.PreparePayload",
+ "position", b.Position)
if b.Payload, err = bc.app.PreparePayload(b.Position); err != nil {
return
}
+ bc.logger.Debug("Calling Application.PrepareWitness",
+ "height", tip.Witness.Height)
if b.Witness, err = bc.app.PrepareWitness(
tip.Witness.Height); err != nil {
return
diff --git a/core/consensus.go b/core/consensus.go
index ebbcbd1..f4c0a37 100644
--- a/core/consensus.go
+++ b/core/consensus.go
@@ -590,23 +590,28 @@ func (con *Consensus) prepare(initBlock *types.Block) (err error) {
if err = con.bcModule.appendConfig(initRound+1, initPlusOneCfg); err != nil {
return
}
- // Register events.
- dkgSet, err := con.nodeSetCache.GetDKGSet(initRound)
- if err != nil {
- return
- }
- if _, exist := dkgSet[con.ID]; exist {
- con.logger.Info("Selected as DKG set", "round", initRound)
- go func() {
- // Sleep until dMoment come.
- time.Sleep(con.dMoment.Sub(time.Now().UTC()))
- con.cfgModule.registerDKG(initRound, getDKGThreshold(initConfig))
- con.event.RegisterTime(con.dMoment.Add(initConfig.RoundInterval/4),
- func(time.Time) {
- con.runDKG(initRound, initConfig)
- })
- }()
+ if initRound == 0 {
+ dkgSet, err := con.nodeSetCache.GetDKGSet(initRound)
+ if err != nil {
+ return err
+ }
+ if _, exist := dkgSet[con.ID]; exist {
+ con.logger.Info("Selected as DKG set", "round", initRound)
+ go func() {
+ // Sleep until dMoment come.
+ time.Sleep(con.dMoment.Sub(time.Now().UTC()))
+ // Network is not stable upon starting. Wait some time to ensure first
+ // DKG would success. Three is a magic number.
+ time.Sleep(initConfig.MinBlockInterval * 3)
+ con.cfgModule.registerDKG(initRound, getDKGThreshold(initConfig))
+ con.event.RegisterTime(con.dMoment.Add(initConfig.RoundInterval/4),
+ func(time.Time) {
+ con.runDKG(initRound, initConfig)
+ })
+ }()
+ }
}
+ // Register events.
con.initialRound(con.dMoment, initRound, initConfig)
return
}
diff --git a/core/consensus_test.go b/core/consensus_test.go
index 67070d2..fe28320 100644
--- a/core/consensus_test.go
+++ b/core/consensus_test.go
@@ -237,6 +237,7 @@ func (s *ConsensusTestSuite) TestDKGCRS() {
nID := types.NewNodeID(key.PublicKey())
cons[nID] = con
}
+ time.Sleep(gov.Configuration(0).MinBlockInterval * 4)
for _, con := range cons {
go con.runDKG(0, gov.Configuration(0))
}