aboutsummaryrefslogtreecommitdiffstats
path: root/simulation
diff options
context:
space:
mode:
Diffstat (limited to 'simulation')
-rw-r--r--simulation/config/config.go26
-rw-r--r--simulation/governance.go16
-rw-r--r--simulation/marshaller.go8
-rw-r--r--simulation/network.go8
4 files changed, 46 insertions, 12 deletions
diff --git a/simulation/config/config.go b/simulation/config/config.go
index 8bc4ab7..cc31a5b 100644
--- a/simulation/config/config.go
+++ b/simulation/config/config.go
@@ -36,12 +36,13 @@ const (
// Consensus settings.
type Consensus struct {
- PhiRatio float32
- K int
- ChainNum uint32
- GenesisCRS string `toml:"genesis_crs"`
- LambdaBA int `toml:"lambda_ba"`
- LambdaDKG int `toml:"lambda_dkg"`
+ PhiRatio float32
+ K int
+ ChainNum uint32
+ GenesisCRS string `toml:"genesis_crs"`
+ LambdaBA int `toml:"lambda_ba"`
+ LambdaDKG int `toml:"lambda_dkg"`
+ RoundHeight uint64
}
// Legacy config.
@@ -93,12 +94,13 @@ func GenerateDefault(path string) error {
Title: "DEXON Consensus Simulation Config",
Node: Node{
Consensus: Consensus{
- PhiRatio: float32(2) / 3,
- K: 1,
- ChainNum: 7,
- GenesisCRS: "In DEXON we trust.",
- LambdaBA: 250,
- LambdaDKG: 1000,
+ PhiRatio: float32(2) / 3,
+ K: 1,
+ ChainNum: 7,
+ GenesisCRS: "In DEXON we trust.",
+ LambdaBA: 250,
+ LambdaDKG: 1000,
+ RoundHeight: 60,
},
Legacy: Legacy{
ProposeIntervalMean: 500,
diff --git a/simulation/governance.go b/simulation/governance.go
index 643c181..133276c 100644
--- a/simulation/governance.go
+++ b/simulation/governance.go
@@ -23,6 +23,7 @@ import (
"time"
"github.com/dexon-foundation/dexon-consensus-core/core/types"
+ "github.com/dexon-foundation/dexon-consensus-core/crypto"
"github.com/dexon-foundation/dexon-consensus-core/simulation/config"
)
@@ -37,6 +38,7 @@ type simGovernance struct {
phiRatio float32
chainNum uint32
crs []byte
+ tsig map[uint64]crypto.Signature
dkgComplaint map[uint64][]*types.DKGComplaint
dkgMasterPublicKey map[uint64][]*types.DKGMasterPublicKey
lambdaBA time.Duration
@@ -56,6 +58,7 @@ func newSimGovernance(
phiRatio: consensusConfig.PhiRatio,
chainNum: consensusConfig.ChainNum,
crs: []byte(consensusConfig.GenesisCRS),
+ tsig: make(map[uint64]crypto.Signature),
dkgComplaint: make(map[uint64][]*types.DKGComplaint),
dkgMasterPublicKey: make(map[uint64][]*types.DKGMasterPublicKey),
lambdaBA: time.Duration(consensusConfig.LambdaBA) * time.Millisecond,
@@ -108,6 +111,19 @@ func (g *simGovernance) addNode(nID types.NodeID) {
g.notarySet[nID] = struct{}{}
}
+// ProposeThresholdSignature porposes a ThresholdSignature of round.
+func (g *simGovernance) ProposeThresholdSignature(
+ round uint64, signature crypto.Signature) {
+ g.tsig[round] = signature
+}
+
+// GetThresholdSignature gets a ThresholdSignature of round.
+func (g *simGovernance) GetThresholdSignature(round uint64) (
+ sig crypto.Signature, exist bool) {
+ sig, exist = g.tsig[round]
+ return
+}
+
// AddDKGComplaint adds a DKGComplaint.
func (g *simGovernance) AddDKGComplaint(complaint *types.DKGComplaint) {
// TODO(jimmy-dexon): check if the input is valid.
diff --git a/simulation/marshaller.go b/simulation/marshaller.go
index d1b2793..08d67a9 100644
--- a/simulation/marshaller.go
+++ b/simulation/marshaller.go
@@ -90,6 +90,12 @@ func (m *jsonMarshaller) Unmarshal(
break
}
msg = complaint
+ case "dkg-partial-signature":
+ psig := &types.DKGPartialSignature{}
+ if err = json.Unmarshal(payload, psig); err != nil {
+ break
+ }
+ msg = psig
default:
err = fmt.Errorf("unrecognized message type: %v", msgType)
}
@@ -122,6 +128,8 @@ func (m *jsonMarshaller) Marshal(msg interface{}) (
msgType = "dkg-master-public-key"
case *types.DKGComplaint:
msgType = "dkg-complaint"
+ case *types.DKGPartialSignature:
+ msgType = "dkg-partial-signature"
default:
err = fmt.Errorf("unknwon message type: %v", msg)
}
diff --git a/simulation/network.go b/simulation/network.go
index 938d785..3d3acaa 100644
--- a/simulation/network.go
+++ b/simulation/network.go
@@ -161,6 +161,14 @@ func (n *network) BroadcastDKGPrivateShare(
}
}
+// BroadcastDKGPartialSignature implements core.Network interface.
+func (n *network) BroadcastDKGPartialSignature(
+ psig *types.DKGPartialSignature) {
+ if err := n.trans.Broadcast(psig); err != nil {
+ panic(err)
+ }
+}
+
// ReceiveChan implements core.Network interface.
func (n *network) ReceiveChan() <-chan interface{} {
return n.toConsensus