aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2018-10-09 11:59:19 +0800
committerGitHub <noreply@github.com>2018-10-09 11:59:19 +0800
commitdb07d005e2e5a9208620a8d0e5fcaedeaa6ed644 (patch)
tree860c7a1c2f5d30296f66b07ed4e59117eb265eb7
parent9267d50de25ddf0f280eee797e2030ea989294e4 (diff)
downloaddexon-consensus-db07d005e2e5a9208620a8d0e5fcaedeaa6ed644.tar
dexon-consensus-db07d005e2e5a9208620a8d0e5fcaedeaa6ed644.tar.gz
dexon-consensus-db07d005e2e5a9208620a8d0e5fcaedeaa6ed644.tar.bz2
dexon-consensus-db07d005e2e5a9208620a8d0e5fcaedeaa6ed644.tar.lz
dexon-consensus-db07d005e2e5a9208620a8d0e5fcaedeaa6ed644.tar.xz
dexon-consensus-db07d005e2e5a9208620a8d0e5fcaedeaa6ed644.tar.zst
dexon-consensus-db07d005e2e5a9208620a8d0e5fcaedeaa6ed644.zip
core: Add round to DKG methods in gov. Change network interface name (#185)
-rw-r--r--core/configuration-chain_test.go6
-rw-r--r--core/consensus.go8
-rw-r--r--core/consensus_test.go4
-rw-r--r--core/dkg-tsig-protocol_test.go16
-rw-r--r--core/interfaces.go10
-rw-r--r--core/nodeset-cache_test.go8
-rw-r--r--core/test/governance.go16
-rw-r--r--simulation/governance.go17
-rw-r--r--simulation/network.go4
-rw-r--r--simulation/node.go6
10 files changed, 58 insertions, 37 deletions
diff --git a/core/configuration-chain_test.go b/core/configuration-chain_test.go
index 856d46e..4d104ae 100644
--- a/core/configuration-chain_test.go
+++ b/core/configuration-chain_test.go
@@ -69,7 +69,7 @@ func (r *testCCReceiver) ProposeDKGComplaint(complaint *types.DKGComplaint) {
r.s.Require().NoError(err)
complaintCopy := &types.DKGComplaint{}
r.s.Require().NoError(json.Unmarshal(data, complaintCopy))
- gov.AddDKGComplaint(complaintCopy)
+ gov.AddDKGComplaint(complaintCopy.Round, complaintCopy)
}
}
@@ -86,7 +86,7 @@ func (r *testCCReceiver) ProposeDKGMasterPublicKey(
r.s.Require().NoError(err)
mpkCopy := types.NewDKGMasterPublicKey()
r.s.Require().NoError(json.Unmarshal(data, mpkCopy))
- gov.AddDKGMasterPublicKey(mpkCopy)
+ gov.AddDKGMasterPublicKey(mpkCopy.Round, mpkCopy)
}
}
@@ -137,7 +137,7 @@ func (r *testCCReceiver) ProposeDKGFinalize(final *types.DKGFinalize) {
r.s.Require().NoError(err)
finalCopy := &types.DKGFinalize{}
r.s.Require().NoError(json.Unmarshal(data, finalCopy))
- gov.AddDKGFinalize(finalCopy)
+ gov.AddDKGFinalize(finalCopy.Round, finalCopy)
}
}
diff --git a/core/consensus.go b/core/consensus.go
index 47e075b..4b1b4d3 100644
--- a/core/consensus.go
+++ b/core/consensus.go
@@ -102,7 +102,7 @@ func (recv *consensusBAReceiver) ConfirmBlock(
for _, vote := range votes {
voteList = append(voteList, *vote)
}
- recv.consensus.network.BroadcastRandomnessRequest(&types.AgreementResult{
+ recv.consensus.network.BroadcastAgreementResult(&types.AgreementResult{
BlockHash: hash,
Round: recv.round,
Position: block.Position,
@@ -136,7 +136,7 @@ func (recv *consensusDKGReceiver) ProposeDKGComplaint(
log.Println(err)
return
}
- recv.gov.AddDKGComplaint(complaint)
+ recv.gov.AddDKGComplaint(complaint.Round, complaint)
}
// ProposeDKGMasterPublicKey propose a DKGMasterPublicKey.
@@ -146,7 +146,7 @@ func (recv *consensusDKGReceiver) ProposeDKGMasterPublicKey(
log.Println(err)
return
}
- recv.gov.AddDKGMasterPublicKey(mpk)
+ recv.gov.AddDKGMasterPublicKey(mpk.Round, mpk)
}
// ProposeDKGPrivateShare propose a DKGPrivateShare.
@@ -182,7 +182,7 @@ func (recv *consensusDKGReceiver) ProposeDKGFinalize(final *types.DKGFinalize) {
log.Println(err)
return
}
- recv.gov.AddDKGFinalize(final)
+ recv.gov.AddDKGFinalize(final.Round, final)
}
// Consensus implements DEXON Consensus algorithm.
diff --git a/core/consensus_test.go b/core/consensus_test.go
index 4c0f41c..6163e6a 100644
--- a/core/consensus_test.go
+++ b/core/consensus_test.go
@@ -47,8 +47,8 @@ func (n *network) BroadcastBlock(block *types.Block) {
n.conn.broadcast(n.nID, block)
}
-// BroadcastRandomnessRequest broadcasts rand request to DKG set.
-func (n *network) BroadcastRandomnessRequest(
+// BroadcastAgreementResult broadcasts agreement result to DKG set.
+func (n *network) BroadcastAgreementResult(
randRequest *types.AgreementResult) {
n.conn.broadcast(n.nID, randRequest)
}
diff --git a/core/dkg-tsig-protocol_test.go b/core/dkg-tsig-protocol_test.go
index 9d66222..8822de3 100644
--- a/core/dkg-tsig-protocol_test.go
+++ b/core/dkg-tsig-protocol_test.go
@@ -145,7 +145,7 @@ func (s *DKGTSIGProtocolTestSuite) TestDKGTSIGProtocol() {
receivers, protocols := s.newProtocols(k, n, round)
for _, receiver := range receivers {
- gov.AddDKGMasterPublicKey(receiver.mpk)
+ gov.AddDKGMasterPublicKey(round, receiver.mpk)
}
for _, protocol := range protocols {
@@ -250,7 +250,7 @@ func (s *DKGTSIGProtocolTestSuite) TestNackComplaint() {
byzantineID := s.nIDs[0]
for _, receiver := range receivers {
- gov.AddDKGMasterPublicKey(receiver.mpk)
+ gov.AddDKGMasterPublicKey(round, receiver.mpk)
}
for _, protocol := range protocols {
@@ -297,7 +297,7 @@ func (s *DKGTSIGProtocolTestSuite) TestComplaint() {
protocol := protocols[targetID]
for _, receiver := range receivers {
- gov.AddDKGMasterPublicKey(receiver.mpk)
+ gov.AddDKGMasterPublicKey(round, receiver.mpk)
}
for _, protocol := range protocols {
@@ -359,7 +359,7 @@ func (s *DKGTSIGProtocolTestSuite) TestAntiComplaint() {
thirdPerson := s.nIDs[2]
for _, receiver := range receivers {
- gov.AddDKGMasterPublicKey(receiver.mpk)
+ gov.AddDKGMasterPublicKey(round, receiver.mpk)
}
for _, protocol := range protocols {
@@ -414,7 +414,7 @@ func (s *DKGTSIGProtocolTestSuite) TestEncorceNackComplaint() {
thirdPerson := s.nIDs[2]
for _, receiver := range receivers {
- gov.AddDKGMasterPublicKey(receiver.mpk)
+ gov.AddDKGMasterPublicKey(round, receiver.mpk)
}
for _, protocol := range protocols {
@@ -464,7 +464,7 @@ func (s *DKGTSIGProtocolTestSuite) TestQualifyIDs() {
byzantineID := s.nIDs[0]
for _, receiver := range receivers {
- gov.AddDKGMasterPublicKey(receiver.mpk)
+ gov.AddDKGMasterPublicKey(round, receiver.mpk)
}
// Test for nack complaints.
@@ -527,7 +527,7 @@ func (s *DKGTSIGProtocolTestSuite) TestPartialSignature() {
byzantineID := s.nIDs[0]
for _, receiver := range receivers {
- gov.AddDKGMasterPublicKey(receiver.mpk)
+ gov.AddDKGMasterPublicKey(round, receiver.mpk)
}
for _, protocol := range protocols {
@@ -553,7 +553,7 @@ func (s *DKGTSIGProtocolTestSuite) TestPartialSignature() {
s.Require().Len(recv.complaints, 1)
complaint, exist := recv.complaints[byzantineID]
s.Require().True(exist)
- gov.AddDKGComplaint(complaint)
+ gov.AddDKGComplaint(round, complaint)
}
// DKG is fininished.
diff --git a/core/interfaces.go b/core/interfaces.go
index 9232251..f4a6cd0 100644
--- a/core/interfaces.go
+++ b/core/interfaces.go
@@ -64,8 +64,8 @@ type Network interface {
// BroadcastBlock broadcasts block to all nodes in DEXON network.
BroadcastBlock(block *types.Block)
- // BroadcastRandomnessRequest broadcasts rand request to DKG set.
- BroadcastRandomnessRequest(randRequest *types.AgreementResult)
+ // BroadcastAgreementResult broadcasts agreement result to DKG set.
+ BroadcastAgreementResult(randRequest *types.AgreementResult)
// BroadcastRandomnessResult broadcasts rand request to Notary set.
BroadcastRandomnessResult(randResult *types.BlockRandomnessResult)
@@ -106,19 +106,19 @@ type Governance interface {
//// DKG-related methods.
// AddDKGComplaint adds a DKGComplaint.
- AddDKGComplaint(complaint *types.DKGComplaint)
+ AddDKGComplaint(round uint64, complaint *types.DKGComplaint)
// DKGComplaints gets all the DKGComplaints of round.
DKGComplaints(round uint64) []*types.DKGComplaint
// AddDKGMasterPublicKey adds a DKGMasterPublicKey.
- AddDKGMasterPublicKey(masterPublicKey *types.DKGMasterPublicKey)
+ AddDKGMasterPublicKey(round uint64, masterPublicKey *types.DKGMasterPublicKey)
// DKGMasterPublicKeys gets all the DKGMasterPublicKey of round.
DKGMasterPublicKeys(round uint64) []*types.DKGMasterPublicKey
// AddDKGFinalize adds a DKG finalize message.
- AddDKGFinalize(final *types.DKGFinalize)
+ AddDKGFinalize(round uint64, final *types.DKGFinalize)
// IsDKGFinal checks if DKG is final.
IsDKGFinal(round uint64) bool
diff --git a/core/nodeset-cache_test.go b/core/nodeset-cache_test.go
index a1dded6..6324421 100644
--- a/core/nodeset-cache_test.go
+++ b/core/nodeset-cache_test.go
@@ -52,20 +52,20 @@ func (g *testGov) NodeSet(round uint64) []crypto.PublicKey {
}
return g.curKeys
}
-func (g *testGov) AddDKGComplaint(complaint *types.DKGComplaint) {}
+func (g *testGov) AddDKGComplaint(_ uint64, _ *types.DKGComplaint) {}
func (g *testGov) DKGComplaints(
round uint64) (cs []*types.DKGComplaint) {
return
}
func (g *testGov) AddDKGMasterPublicKey(
- masterPublicKey *types.DKGMasterPublicKey) {
+ _ uint64, _ *types.DKGMasterPublicKey) {
}
func (g *testGov) DKGMasterPublicKeys(
round uint64) (keys []*types.DKGMasterPublicKey) {
return
}
-func (g *testGov) AddDKGFinalize(final *types.DKGFinalize) {}
-func (g *testGov) IsDKGFinal(round uint64) bool { return true }
+func (g *testGov) AddDKGFinalize(_ uint64, _ *types.DKGFinalize) {}
+func (g *testGov) IsDKGFinal(round uint64) bool { return true }
type NodeSetCacheTestSuite struct {
suite.Suite
diff --git a/core/test/governance.go b/core/test/governance.go
index de3f34b..de0ec21 100644
--- a/core/test/governance.go
+++ b/core/test/governance.go
@@ -136,7 +136,11 @@ func (g *Governance) PrivateKeys() (keys []crypto.PrivateKey) {
}
// AddDKGComplaint add a DKGComplaint.
-func (g *Governance) AddDKGComplaint(complaint *types.DKGComplaint) {
+func (g *Governance) AddDKGComplaint(
+ round uint64, complaint *types.DKGComplaint) {
+ if round != complaint.Round {
+ return
+ }
if g.IsDKGFinal(complaint.Round) {
return
}
@@ -167,7 +171,10 @@ func (g *Governance) DKGComplaints(round uint64) []*types.DKGComplaint {
// AddDKGMasterPublicKey adds a DKGMasterPublicKey.
func (g *Governance) AddDKGMasterPublicKey(
- masterPublicKey *types.DKGMasterPublicKey) {
+ round uint64, masterPublicKey *types.DKGMasterPublicKey) {
+ if round != masterPublicKey.Round {
+ return
+ }
g.lock.Lock()
defer g.lock.Unlock()
g.DKGMasterPublicKey[masterPublicKey.Round] = append(
@@ -194,7 +201,10 @@ func (g *Governance) DKGMasterPublicKeys(
}
// AddDKGFinalize adds a DKG finalize message.
-func (g *Governance) AddDKGFinalize(final *types.DKGFinalize) {
+func (g *Governance) AddDKGFinalize(round uint64, final *types.DKGFinalize) {
+ if round != final.Round {
+ return
+ }
g.lock.Lock()
defer g.lock.Unlock()
if _, exist := g.DKGFinal[final.Round]; !exist {
diff --git a/simulation/governance.go b/simulation/governance.go
index f22abce..2b0f56b 100644
--- a/simulation/governance.go
+++ b/simulation/governance.go
@@ -140,7 +140,11 @@ func (g *simGovernance) addNode(pubKey crypto.PublicKey) {
}
// AddDKGComplaint adds a DKGComplaint.
-func (g *simGovernance) AddDKGComplaint(complaint *types.DKGComplaint) {
+func (g *simGovernance) AddDKGComplaint(
+ round uint64, complaint *types.DKGComplaint) {
+ if round != complaint.Round {
+ return
+ }
if g.IsDKGFinal(complaint.Round) {
return
}
@@ -166,7 +170,10 @@ func (g *simGovernance) DKGComplaints(round uint64) []*types.DKGComplaint {
// AddDKGMasterPublicKey adds a DKGMasterPublicKey.
func (g *simGovernance) AddDKGMasterPublicKey(
- masterPublicKey *types.DKGMasterPublicKey) {
+ round uint64, masterPublicKey *types.DKGMasterPublicKey) {
+ if round != masterPublicKey.Round {
+ return
+ }
// TODO(jimmy-dexon): check if the input is valid.
g.dkgMasterPublicKey[masterPublicKey.Round] = append(
g.dkgMasterPublicKey[masterPublicKey.Round], masterPublicKey)
@@ -186,7 +193,11 @@ func (g *simGovernance) DKGMasterPublicKeys(
}
// AddDKGFinalize adds a DKG finalize message.
-func (g *simGovernance) AddDKGFinalize(final *types.DKGFinalize) {
+func (g *simGovernance) AddDKGFinalize(
+ round uint64, final *types.DKGFinalize) {
+ if round != final.Round {
+ return
+ }
// TODO(jimmy-dexon): check if the input is valid.
if _, exist := g.dkgFinal[final.Round]; !exist {
g.dkgFinal[final.Round] = make(map[types.NodeID]struct{})
diff --git a/simulation/network.go b/simulation/network.go
index ab3b4fa..89b81ce 100644
--- a/simulation/network.go
+++ b/simulation/network.go
@@ -132,8 +132,8 @@ func (n *network) BroadcastBlock(block *types.Block) {
}
}
-// BroadcastRandomnessRequest implements core.Network interface.
-func (n *network) BroadcastRandomnessRequest(
+// BroadcastAgreementResult implements core.Network interface.
+func (n *network) BroadcastAgreementResult(
randRequest *types.AgreementResult) {
if err := n.trans.Broadcast(randRequest); err != nil {
panic(err)
diff --git a/simulation/node.go b/simulation/node.go
index b90c1f8..a6d5b89 100644
--- a/simulation/node.go
+++ b/simulation/node.go
@@ -111,11 +111,11 @@ MainLoop:
break MainLoop
}
case *types.DKGComplaint:
- n.gov.AddDKGComplaint(val)
+ n.gov.AddDKGComplaint(val.Round, val)
case *types.DKGMasterPublicKey:
- n.gov.AddDKGMasterPublicKey(val)
+ n.gov.AddDKGMasterPublicKey(val.Round, val)
case *types.DKGFinalize:
- n.gov.AddDKGFinalize(val)
+ n.gov.AddDKGFinalize(val.Round, val)
default:
panic(fmt.Errorf("unexpected message from server: %v", val))
}