aboutsummaryrefslogtreecommitdiffstats
path: root/simulation
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2018-09-05 10:32:25 +0800
committerGitHub <noreply@github.com>2018-09-05 10:32:25 +0800
commit41641e10286dd7b1fdcced6a51157e061d545ef5 (patch)
tree69129be3df35d7abde7b94ef5ceec828787b3498 /simulation
parent04a63a22a24abaaa91b1d981e6d95260d80dadf4 (diff)
downloaddexon-consensus-41641e10286dd7b1fdcced6a51157e061d545ef5.tar
dexon-consensus-41641e10286dd7b1fdcced6a51157e061d545ef5.tar.gz
dexon-consensus-41641e10286dd7b1fdcced6a51157e061d545ef5.tar.bz2
dexon-consensus-41641e10286dd7b1fdcced6a51157e061d545ef5.tar.lz
dexon-consensus-41641e10286dd7b1fdcced6a51157e061d545ef5.tar.xz
dexon-consensus-41641e10286dd7b1fdcced6a51157e061d545ef5.tar.zst
dexon-consensus-41641e10286dd7b1fdcced6a51157e061d545ef5.zip
misc: Polish BA. (#94)
Diffstat (limited to 'simulation')
-rw-r--r--simulation/config/config.go27
-rw-r--r--simulation/kubernetes/config.toml.in7
-rw-r--r--simulation/simulation.go6
-rw-r--r--simulation/validator.go26
4 files changed, 44 insertions, 22 deletions
diff --git a/simulation/config/config.go b/simulation/config/config.go
index c59b663..2f03f85 100644
--- a/simulation/config/config.go
+++ b/simulation/config/config.go
@@ -41,13 +41,19 @@ type Consensus struct {
GenesisCRS string `toml:"genesis_crs"`
}
-// Validator config for the simulation.
-type Validator struct {
- Consensus Consensus
- Num int
+// Legacy config.
+type Legacy struct {
ProposeIntervalMean float64
ProposeIntervalSigma float64
- MaxBlock uint64
+}
+
+// Validator config for the simulation.
+type Validator struct {
+ Consensus Consensus
+ Legacy Legacy
+ Num int
+ Lambda int
+ MaxBlock uint64
}
// Networking config.
@@ -90,10 +96,13 @@ func GenerateDefault(path string) error {
ChainNum: 7,
GenesisCRS: "In DEXON we trust.",
},
- Num: 7,
- ProposeIntervalMean: 500,
- ProposeIntervalSigma: 30,
- MaxBlock: math.MaxUint64,
+ Legacy: Legacy{
+ ProposeIntervalMean: 500,
+ ProposeIntervalSigma: 50,
+ },
+ Num: 7,
+ Lambda: 250,
+ MaxBlock: math.MaxUint64,
},
Networking: Networking{
Type: NetworkTypeTCPLocal,
diff --git a/simulation/kubernetes/config.toml.in b/simulation/kubernetes/config.toml.in
index 1cc18aa..2f12956 100644
--- a/simulation/kubernetes/config.toml.in
+++ b/simulation/kubernetes/config.toml.in
@@ -2,8 +2,7 @@ title = "DEXON Consensus Simulation Config"
[validator]
num = {{numValidators}}
-propose_interval_mean = 5e+02
-propose_interval_sigma = 3e+01
+lambda = 250
max_block = 1000
[validator.consensus]
@@ -12,6 +11,10 @@ k = 1
chain_num = 7
genesis_crs = "In DEXON we trust."
+[validator.legacy]
+propose_interval_mean = 5e+02
+propose_interval_sigma = 5e+01
+
[networking]
type = "tcp"
peer_server = "peer-server-svc.default.svc.cluster.local"
diff --git a/simulation/simulation.go b/simulation/simulation.go
index 4cfc79c..978107a 100644
--- a/simulation/simulation.go
+++ b/simulation/simulation.go
@@ -26,7 +26,7 @@ import (
)
// Run starts the simulation.
-func Run(configPath string) {
+func Run(configPath string, legacy bool) {
cfg, err := config.Read(configPath)
if err != nil {
panic(err)
@@ -65,7 +65,7 @@ func Run(configPath string) {
for i := 0; i < cfg.Validator.Num; i++ {
fmt.Printf("Validator %d: %s\n", i, vs[i].ID)
- go vs[i].Run()
+ go vs[i].Run(legacy)
}
} else if networkType == config.NetworkTypeTCP {
prv, err := eth.NewPrivateKey()
@@ -75,7 +75,7 @@ func Run(configPath string) {
network := NewTCPNetwork(false, cfg.Networking.PeerServer, networkModel)
network.Start()
v := NewValidator(prv, eth.SigToPub, cfg.Validator, network)
- go v.Run()
+ go v.Run(legacy)
vs = append(vs, v)
}
diff --git a/simulation/validator.go b/simulation/validator.go
index 6d73c50..21b9db6 100644
--- a/simulation/validator.go
+++ b/simulation/validator.go
@@ -83,7 +83,7 @@ func (v *Validator) GetID() types.ValidatorID {
}
// Run starts the validator.
-func (v *Validator) Run() {
+func (v *Validator) Run(legacy bool) {
v.network.Join(v)
v.msgChannel = v.network.ReceiveChan()
@@ -99,13 +99,23 @@ func (v *Validator) Run() {
break
}
}
- v.consensus = core.NewConsensus(
- v.app, v.gov, v.db, v.network,
- time.NewTicker(
- time.Duration(v.config.ProposeIntervalMean)*time.Millisecond),
- v.prvKey, v.sigToPub)
-
- go v.consensus.Run()
+ if legacy {
+ v.consensus = core.NewConsensus(
+ v.app, v.gov, v.db, v.network,
+ 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.network,
+ time.NewTicker(
+ time.Duration(v.config.Lambda)*time.Millisecond),
+ v.prvKey, v.sigToPub)
+
+ go v.consensus.Run()
+ }
isShutdown := make(chan struct{})