diff options
author | Jimmy Hu <jimmy.hu@dexon.org> | 2018-10-15 11:17:59 +0800 |
---|---|---|
committer | Wei-Ning Huang <aitjcize@gmail.com> | 2018-10-15 11:17:59 +0800 |
commit | 52d490fa7e6b108f71ffb8937554141d5c668ff1 (patch) | |
tree | 832567efb84766fafe67c2f83dd24e6c20e8a746 /simulation | |
parent | c59b65f22bcd61b10c654ee784d6b8bef9fd3bca (diff) | |
download | dexon-consensus-52d490fa7e6b108f71ffb8937554141d5c668ff1.tar dexon-consensus-52d490fa7e6b108f71ffb8937554141d5c668ff1.tar.gz dexon-consensus-52d490fa7e6b108f71ffb8937554141d5c668ff1.tar.bz2 dexon-consensus-52d490fa7e6b108f71ffb8937554141d5c668ff1.tar.lz dexon-consensus-52d490fa7e6b108f71ffb8937554141d5c668ff1.tar.xz dexon-consensus-52d490fa7e6b108f71ffb8937554141d5c668ff1.tar.zst dexon-consensus-52d490fa7e6b108f71ffb8937554141d5c668ff1.zip |
core: fix simulation error (#201)
* Sync dMoment for all consensus core
* App check for randomness ignore round 0
Diffstat (limited to 'simulation')
-rw-r--r-- | simulation/app.go | 9 | ||||
-rw-r--r-- | simulation/node.go | 6 | ||||
-rw-r--r-- | simulation/simulation.go | 5 |
3 files changed, 16 insertions, 4 deletions
diff --git a/simulation/app.go b/simulation/app.go index 0ca65c9..16bb63a 100644 --- a/simulation/app.go +++ b/simulation/app.go @@ -132,7 +132,14 @@ func (a *simApp) TotalOrderingDelivered(blockHashes common.Hashes, early bool) { // BlockDelivered is called when a block in compaction chain is delivered. func (a *simApp) BlockDelivered( blockHash common.Hash, result types.FinalizationResult) { - if len(result.Randomness) == 0 { + if len(result.Randomness) == 0 && func() bool { + if block, exist := a.blockByHash[blockHash]; exist { + if block.Position.Round == 0 { + return false + } + } + return true + }() { panic(fmt.Errorf("Block %s randomness is empty", blockHash)) } func() { diff --git a/simulation/node.go b/simulation/node.go index a6d5b89..b908d73 100644 --- a/simulation/node.go +++ b/simulation/node.go @@ -20,6 +20,7 @@ package simulation import ( "fmt" "sort" + "time" "github.com/dexon-foundation/dexon-consensus-core/common" "github.com/dexon-foundation/dexon-consensus-core/core" @@ -75,7 +76,7 @@ func (n *node) GetID() types.NodeID { } // run starts the node. -func (n *node) run(serverEndpoint interface{}) { +func (n *node) run(serverEndpoint interface{}, dMoment time.Time) { // Run network. if err := n.netModule.setup(serverEndpoint); err != nil { panic(err) @@ -98,7 +99,8 @@ func (n *node) run(serverEndpoint interface{}) { break } } - n.consensus = core.NewConsensus(n.app, n.gov, n.db, n.netModule, n.prvKey) + n.consensus = core.NewConsensus( + dMoment, n.app, n.gov, n.db, n.netModule, n.prvKey) go n.consensus.Run() // Blocks forever. diff --git a/simulation/simulation.go b/simulation/simulation.go index ce9f68b..ebc5273 100644 --- a/simulation/simulation.go +++ b/simulation/simulation.go @@ -19,6 +19,7 @@ package simulation import ( "sync" + "time" "github.com/dexon-foundation/dexon-consensus-core/core/crypto/ecdsa" "github.com/dexon-foundation/dexon-consensus-core/simulation/config" @@ -33,6 +34,8 @@ func Run(cfg *config.Config) { err error ) + dMoment := time.Now().UTC().Add(1 * time.Second) + // init is a function to init a node. init := func(serverEndpoint interface{}) { prv, err := ecdsa.NewPrivateKey() @@ -43,7 +46,7 @@ func Run(cfg *config.Config) { wg.Add(1) go func() { defer wg.Done() - v.run(serverEndpoint) + v.run(serverEndpoint, dMoment) }() } |