diff options
author | Jimmy Hu <jimmy.hu@dexon.org> | 2018-11-06 14:32:48 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-06 14:32:48 +0800 |
commit | e662353293b58637acc788a5c214a8904bb1cfcb (patch) | |
tree | 46d56a0c25dd5b96227ddbbc16892bee023bc360 /simulation | |
parent | c537e964d9031a07c125a7225391e26827d9eb7a (diff) | |
download | dexon-consensus-e662353293b58637acc788a5c214a8904bb1cfcb.tar dexon-consensus-e662353293b58637acc788a5c214a8904bb1cfcb.tar.gz dexon-consensus-e662353293b58637acc788a5c214a8904bb1cfcb.tar.bz2 dexon-consensus-e662353293b58637acc788a5c214a8904bb1cfcb.tar.lz dexon-consensus-e662353293b58637acc788a5c214a8904bb1cfcb.tar.xz dexon-consensus-e662353293b58637acc788a5c214a8904bb1cfcb.tar.zst dexon-consensus-e662353293b58637acc788a5c214a8904bb1cfcb.zip |
core: Run DKG stuffs only if the node is in DKG set (#302)
Diffstat (limited to 'simulation')
-rw-r--r-- | simulation/config/config.go | 6 | ||||
-rw-r--r-- | simulation/governance.go | 17 | ||||
-rw-r--r-- | simulation/kubernetes/config.toml.in | 10 | ||||
-rw-r--r-- | simulation/node.go | 7 | ||||
-rw-r--r-- | simulation/simulation.go | 11 |
5 files changed, 38 insertions, 13 deletions
diff --git a/simulation/config/config.go b/simulation/config/config.go index 5a548f1..023c4df 100644 --- a/simulation/config/config.go +++ b/simulation/config/config.go @@ -34,6 +34,8 @@ type Consensus struct { LambdaBA int `toml:"lambda_ba"` LambdaDKG int `toml:"lambda_dkg"` RoundInterval int + NotarySetSize uint32 + DKGSetSize uint32 `toml:"dkg_set_size"` } // Legacy config. @@ -46,7 +48,7 @@ type Legacy struct { type Node struct { Consensus Consensus Legacy Legacy - Num int + Num uint32 MaxBlock uint64 } @@ -92,6 +94,8 @@ func GenerateDefault(path string) error { LambdaBA: 250, LambdaDKG: 1000, RoundInterval: 30 * 1000, + NotarySetSize: 7, + DKGSetSize: 7, }, Legacy: Legacy{ ProposeIntervalMean: 500, diff --git a/simulation/governance.go b/simulation/governance.go index 3b48248..4fdaadb 100644 --- a/simulation/governance.go +++ b/simulation/governance.go @@ -36,7 +36,9 @@ type simGovernance struct { id types.NodeID lock sync.RWMutex nodeSet map[types.NodeID]crypto.PublicKey - expectedNumNodes int + expectedNumNodes uint32 + notarySetSize uint32 + dkgSetSize uint32 k int phiRatio float32 chainNum uint32 @@ -54,12 +56,17 @@ type simGovernance struct { // newSimGovernance returns a new simGovernance instance. func newSimGovernance( id types.NodeID, - numNodes int, consensusConfig config.Consensus) *simGovernance { + numNodes uint32, + notarySetSize uint32, + dkgSetSize uint32, + consensusConfig config.Consensus) *simGovernance { hashCRS := crypto.Keccak256Hash([]byte(consensusConfig.GenesisCRS)) return &simGovernance{ id: id, nodeSet: make(map[types.NodeID]crypto.PublicKey), expectedNumNodes: numNodes, + notarySetSize: notarySetSize, + dkgSetSize: dkgSetSize, k: consensusConfig.K, phiRatio: consensusConfig.PhiRatio, chainNum: consensusConfig.ChainNum, @@ -100,8 +107,8 @@ func (g *simGovernance) Configuration(round uint64) *types.Config { LambdaDKG: g.lambdaDKG, K: g.k, PhiRatio: g.phiRatio, - NotarySetSize: uint32(len(g.nodeSet)), - DKGSetSize: uint32(len(g.nodeSet)), + NotarySetSize: g.notarySetSize, + DKGSetSize: g.dkgSetSize, MinBlockInterval: g.lambdaBA * 3, RoundInterval: g.roundInterval, } @@ -139,7 +146,7 @@ func (g *simGovernance) addNode(pubKey crypto.PublicKey) { if _, exists := g.nodeSet[nID]; exists { return } - if len(g.nodeSet) == g.expectedNumNodes { + if uint32(len(g.nodeSet)) == g.expectedNumNodes { panic(fmt.Errorf("attempt to add node when ready")) } g.nodeSet[nID] = pubKey diff --git a/simulation/kubernetes/config.toml.in b/simulation/kubernetes/config.toml.in index f34ee76..7f02f74 100644 --- a/simulation/kubernetes/config.toml.in +++ b/simulation/kubernetes/config.toml.in @@ -2,18 +2,18 @@ title = "DEXON Consensus Simulation Config" [node] num = {{numNode}} -lambda_ba = 250 -lambda_dkg = 1000 -max_block = 1000 +max_block = 18446744073709551615 [node.consensus] -phi_ratio = 6.66670024394989e-01 +phi_ratio = 6.666666865348816e-01 k = 1 chain_num = 7 genesis_crs = "In DEXON we trust." lambda_ba = 250 -lambda_dkg = 1000 +lambda_dkg = 4000 round_interval = 31536000000 +notary_set_size = 7 +dkg_set_size = 7 [node.legacy] propose_interval_mean = 5e+02 diff --git a/simulation/node.go b/simulation/node.go index 8907d5a..56c5832 100644 --- a/simulation/node.go +++ b/simulation/node.go @@ -91,7 +91,12 @@ func newNode( if err != nil { panic(err) } - gov := newSimGovernance(id, config.Node.Num, config.Node.Consensus) + gov := newSimGovernance( + id, + config.Node.Num, + config.Node.Consensus.NotarySetSize, + config.Node.Consensus.DKGSetSize, + config.Node.Consensus) return &node{ ID: id, prvKey: prvKey, diff --git a/simulation/simulation.go b/simulation/simulation.go index 801bb7e..4e97900 100644 --- a/simulation/simulation.go +++ b/simulation/simulation.go @@ -18,6 +18,7 @@ package simulation import ( + "fmt" "sync" "time" @@ -35,6 +36,14 @@ func Run(cfg *config.Config) { err error ) + if cfg.Node.Consensus.NotarySetSize > cfg.Node.Num { + panic(fmt.Errorf("NotarySetSize should not be larger the node num")) + } + + if cfg.Node.Consensus.DKGSetSize > cfg.Node.Num { + panic(fmt.Errorf("DKGSetSze should not be larger the node num")) + } + dMoment := time.Now().UTC().Add(1 * time.Second) // init is a function to init a node. @@ -69,7 +78,7 @@ func Run(cfg *config.Config) { server.Run() }() // Initialize all nodes. - for i := 0; i < cfg.Node.Num; i++ { + for i := uint32(0); i < cfg.Node.Num; i++ { init(serverEndpoint) } } |