aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/consensus.go2
-rw-r--r--core/interfaces.go2
-rw-r--r--core/nodeset-cache_test.go2
-rw-r--r--core/test/governance.go15
-rw-r--r--simulation/governance.go28
5 files changed, 31 insertions, 18 deletions
diff --git a/core/consensus.go b/core/consensus.go
index e0f8ef2..3b8883e 100644
--- a/core/consensus.go
+++ b/core/consensus.go
@@ -445,7 +445,7 @@ func (con *Consensus) runCRS() {
if err != nil {
log.Println(err)
} else {
- con.gov.ProposeCRS(con.round+1, crs)
+ con.gov.ProposeCRS(crs)
}
}
}
diff --git a/core/interfaces.go b/core/interfaces.go
index 710550f..77d7610 100644
--- a/core/interfaces.go
+++ b/core/interfaces.go
@@ -97,7 +97,7 @@ type Governance interface {
CRS(round uint64) common.Hash
// Propose a CRS of round.
- ProposeCRS(round uint64, signedCRS []byte)
+ ProposeCRS(signedCRS []byte)
// NodeSet returns the node set at a given round.
// Return the genesis node set if round == 0.
diff --git a/core/nodeset-cache_test.go b/core/nodeset-cache_test.go
index 993b3ec..f36b59a 100644
--- a/core/nodeset-cache_test.go
+++ b/core/nodeset-cache_test.go
@@ -41,7 +41,7 @@ func (g *testGov) Configuration(round uint64) (cfg *types.Config) {
}
}
func (g *testGov) CRS(round uint64) (b common.Hash) { return g.crs }
-func (g *testGov) ProposeCRS(uint64, []byte) {}
+func (g *testGov) ProposeCRS([]byte) {}
func (g *testGov) NodeSet(round uint64) []crypto.PublicKey {
// Randomly generating keys, and check them for verification.
g.curKeys = []crypto.PublicKey{}
diff --git a/core/test/governance.go b/core/test/governance.go
index 31fe5f4..f013534 100644
--- a/core/test/governance.go
+++ b/core/test/governance.go
@@ -40,7 +40,7 @@ type Governance struct {
lambdaBA time.Duration
lambdaDKG time.Duration
privateKeys map[types.NodeID]crypto.PrivateKey
- crs map[uint64]common.Hash
+ crs []common.Hash
tsig map[uint64]crypto.Signature
DKGComplaint map[uint64][]*types.DKGComplaint
DKGMasterPublicKey map[uint64][]*types.DKGMasterPublicKey
@@ -58,7 +58,7 @@ func NewGovernance(nodeCount int, lambda time.Duration) (
lambdaBA: lambda,
lambdaDKG: lambda * 10,
privateKeys: make(map[types.NodeID]crypto.PrivateKey),
- crs: map[uint64]common.Hash{0: hashCRS},
+ crs: []common.Hash{hashCRS},
tsig: make(map[uint64]crypto.Signature),
DKGComplaint: make(map[uint64][]*types.DKGComplaint),
DKGMasterPublicKey: make(map[uint64][]*types.DKGMasterPublicKey),
@@ -107,14 +107,21 @@ func (g *Governance) Configuration(_ uint64) *types.Config {
func (g *Governance) CRS(round uint64) common.Hash {
g.lock.RLock()
defer g.lock.RUnlock()
+ if round >= uint64(len(g.crs)) {
+ return common.Hash{}
+ }
return g.crs[round]
}
// ProposeCRS propose a CRS.
-func (g *Governance) ProposeCRS(round uint64, signedCRS []byte) {
+func (g *Governance) ProposeCRS(signedCRS []byte) {
g.lock.Lock()
defer g.lock.Unlock()
- g.crs[round] = crypto.Keccak256Hash(signedCRS)
+ crs := crypto.Keccak256Hash(signedCRS)
+ if g.crs[len(g.crs)-1].Equal(crs) {
+ return
+ }
+ g.crs = append(g.crs, crs)
}
// PrivateKeys return the private key for that node, this function
diff --git a/simulation/governance.go b/simulation/governance.go
index 68e9765..f357b26 100644
--- a/simulation/governance.go
+++ b/simulation/governance.go
@@ -38,7 +38,7 @@ type simGovernance struct {
k int
phiRatio float32
chainNum uint32
- crs map[uint64]common.Hash
+ crs []common.Hash
tsig map[uint64]crypto.Signature
dkgComplaint map[uint64][]*types.DKGComplaint
dkgMasterPublicKey map[uint64][]*types.DKGMasterPublicKey
@@ -54,14 +54,13 @@ func newSimGovernance(
numNodes int, consensusConfig config.Consensus) *simGovernance {
hashCRS := crypto.Keccak256Hash([]byte(consensusConfig.GenesisCRS))
return &simGovernance{
- id: id,
- nodeSet: make(map[types.NodeID]crypto.PublicKey),
- expectedNumNodes: numNodes,
- k: consensusConfig.K,
- phiRatio: consensusConfig.PhiRatio,
- chainNum: consensusConfig.ChainNum,
- crs: map[uint64]common.Hash{
- 0: hashCRS},
+ id: id,
+ nodeSet: make(map[types.NodeID]crypto.PublicKey),
+ expectedNumNodes: numNodes,
+ k: consensusConfig.K,
+ phiRatio: consensusConfig.PhiRatio,
+ chainNum: consensusConfig.ChainNum,
+ crs: []common.Hash{hashCRS},
tsig: make(map[uint64]crypto.Signature),
dkgComplaint: make(map[uint64][]*types.DKGComplaint),
dkgMasterPublicKey: make(map[uint64][]*types.DKGMasterPublicKey),
@@ -107,12 +106,19 @@ func (g *simGovernance) Configuration(round uint64) *types.Config {
// CRS returns the CRS for a given round.
func (g *simGovernance) CRS(round uint64) common.Hash {
+ if round >= uint64(len(g.crs)) {
+ return common.Hash{}
+ }
return g.crs[round]
}
// ProposeCRS proposes a CRS of round.
-func (g *simGovernance) ProposeCRS(round uint64, signedCRS []byte) {
- g.crs[round] = crypto.Keccak256Hash(signedCRS)
+func (g *simGovernance) ProposeCRS(signedCRS []byte) {
+ crs := crypto.Keccak256Hash(signedCRS)
+ if g.crs[len(g.crs)-1].Equal(crs) {
+ return
+ }
+ g.crs = append(g.crs, crs)
}
// addNode add a new node into the simulated governance contract.