aboutsummaryrefslogtreecommitdiffstats
path: root/simulation
diff options
context:
space:
mode:
authorMission Liao <mission.liao@dexon.org>2018-09-18 09:07:52 +0800
committerGitHub <noreply@github.com>2018-09-18 09:07:52 +0800
commit81cf96477127a2da8843d544802027c7061a9c06 (patch)
tree70c06aec5df92df1dd93b605cc7afdbd2b8b0347 /simulation
parent8a908e98279d7e80978cd412057eddd4a6bbf06c (diff)
downloadtangerine-consensus-81cf96477127a2da8843d544802027c7061a9c06.tar.gz
tangerine-consensus-81cf96477127a2da8843d544802027c7061a9c06.tar.zst
tangerine-consensus-81cf96477127a2da8843d544802027c7061a9c06.zip
core: remove ticker parameter from NewConsensus
- remove BlockProposingInterval, it's replaced by lambda. - remove ticker parameter of NewConsensus, ticker would be derived from governance. - leave a backdoor to hook the construction of ticker. - move 'Lambda' config from to consensus.
Diffstat (limited to 'simulation')
-rw-r--r--simulation/config/config.go4
-rw-r--r--simulation/governance.go8
-rw-r--r--simulation/validator.go16
3 files changed, 12 insertions, 16 deletions
diff --git a/simulation/config/config.go b/simulation/config/config.go
index f8f629b..ceb0abd 100644
--- a/simulation/config/config.go
+++ b/simulation/config/config.go
@@ -40,6 +40,7 @@ type Consensus struct {
K int
ChainNum uint32
GenesisCRS string `toml:"genesis_crs"`
+ Lambda int
}
// Legacy config.
@@ -53,7 +54,6 @@ type Validator struct {
Consensus Consensus
Legacy Legacy
Num int
- Lambda int
MaxBlock uint64
}
@@ -96,13 +96,13 @@ func GenerateDefault(path string) error {
K: 1,
ChainNum: 7,
GenesisCRS: "In DEXON we trust.",
+ Lambda: 250,
},
Legacy: Legacy{
ProposeIntervalMean: 500,
ProposeIntervalSigma: 50,
},
Num: 7,
- Lambda: 250,
MaxBlock: math.MaxUint64,
},
Networking: Networking{
diff --git a/simulation/governance.go b/simulation/governance.go
index 44f679d..79c9119 100644
--- a/simulation/governance.go
+++ b/simulation/governance.go
@@ -20,6 +20,7 @@ package simulation
import (
"fmt"
"sync"
+ "time"
"github.com/dexon-foundation/dexon-consensus-core/core/types"
"github.com/dexon-foundation/dexon-consensus-core/simulation/config"
@@ -38,6 +39,7 @@ type simGovernance struct {
crs string
dkgComplaint map[uint64][]*types.DKGComplaint
dkgMasterPublicKey map[uint64][]*types.DKGMasterPublicKey
+ lambda time.Duration
}
// newSimGovernance returns a new simGovernance instance.
@@ -52,6 +54,7 @@ func newSimGovernance(
crs: consensusConfig.GenesisCRS,
dkgComplaint: make(map[uint64][]*types.DKGComplaint),
dkgMasterPublicKey: make(map[uint64][]*types.DKGMasterPublicKey),
+ lambda: time.Duration(consensusConfig.Lambda) * time.Millisecond,
}
}
@@ -107,6 +110,11 @@ func (g *simGovernance) GetGenesisCRS() string {
return g.crs
}
+// GetLambda return lambda for BA.
+func (g *simGovernance) GetLambda() time.Duration {
+ return g.lambda
+}
+
// addValidator add a new validator into the simulated governance contract.
func (g *simGovernance) addValidator(vID types.ValidatorID) {
g.lock.Lock()
diff --git a/simulation/validator.go b/simulation/validator.go
index 137c2c0..12ff308 100644
--- a/simulation/validator.go
+++ b/simulation/validator.go
@@ -20,7 +20,6 @@ package simulation
import (
"fmt"
"sort"
- "time"
"github.com/dexon-foundation/dexon-consensus-core/common"
"github.com/dexon-foundation/dexon-consensus-core/core"
@@ -99,22 +98,11 @@ func (v *validator) run(serverEndpoint interface{}, legacy bool) {
break
}
}
+ v.consensus = core.NewConsensus(
+ v.app, v.gov, v.db, v.netModule, v.prvKey, v.sigToPub)
if legacy {
- v.consensus = core.NewConsensus(
- v.app, v.gov, v.db, v.netModule,
- time.NewTicker(
- time.Duration(
- v.config.Legacy.ProposeIntervalMean)*time.Millisecond),
- v.prvKey, v.sigToPub)
-
go v.consensus.RunLegacy()
} else {
- v.consensus = core.NewConsensus(
- v.app, v.gov, v.db, v.netModule,
- time.NewTicker(
- time.Duration(v.config.Lambda)*time.Millisecond),
- v.prvKey, v.sigToPub)
-
go v.consensus.Run()
}