aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorJimmy Hu <jimmy.hu@dexon.org>2018-09-17 17:43:56 +0800
committerGitHub <noreply@github.com>2018-09-17 17:43:56 +0800
commitcbf0012603deb6d2b8c257c079de98792f7b84cf (patch)
tree10294191481d4b7516ef0bc089bca1ebf1aa705c /core
parent874c4c599a80b9c6f9c085c216be5fd6492cd2c2 (diff)
downloaddexon-consensus-cbf0012603deb6d2b8c257c079de98792f7b84cf.tar
dexon-consensus-cbf0012603deb6d2b8c257c079de98792f7b84cf.tar.gz
dexon-consensus-cbf0012603deb6d2b8c257c079de98792f7b84cf.tar.bz2
dexon-consensus-cbf0012603deb6d2b8c257c079de98792f7b84cf.tar.lz
dexon-consensus-cbf0012603deb6d2b8c257c079de98792f7b84cf.tar.xz
dexon-consensus-cbf0012603deb6d2b8c257c079de98792f7b84cf.tar.zst
dexon-consensus-cbf0012603deb6d2b8c257c079de98792f7b84cf.zip
core: DKG interface (#108)
Diffstat (limited to 'core')
-rw-r--r--core/consensus_test.go5
-rw-r--r--core/interfaces.go15
-rw-r--r--core/test/governance.go35
-rw-r--r--core/types/dkg.go47
4 files changed, 102 insertions, 0 deletions
diff --git a/core/consensus_test.go b/core/consensus_test.go
index a66a459..313600a 100644
--- a/core/consensus_test.go
+++ b/core/consensus_test.go
@@ -45,6 +45,11 @@ func (n *network) BroadcastBlock(block *types.Block) {
func (n *network) BroadcastNotaryAck(notaryAck *types.NotaryAck) {
}
+// SendDKGPrivateShare sends PrivateShare to a DKG participant.
+func (n *network) SendDKGPrivateShare(
+ recv types.ValidatorID, prvShare *types.DKGPrivateShare) {
+}
+
// ReceiveChan returns a channel to receive messages from DEXON network.
func (n *network) ReceiveChan() <-chan interface{} {
return make(chan interface{})
diff --git a/core/interfaces.go b/core/interfaces.go
index d4ace51..aa4756e 100644
--- a/core/interfaces.go
+++ b/core/interfaces.go
@@ -64,6 +64,9 @@ type Network interface {
// BroadcastNotaryAck broadcasts notaryAck to all nodes in DEXON network.
BroadcastNotaryAck(notaryAck *types.NotaryAck)
+ // SendDKGPrivateShare sends PrivateShare to a DKG participant.
+ SendDKGPrivateShare(recv types.ValidatorID, prvShare *types.DKGPrivateShare)
+
// ReceiveChan returns a channel to receive messages from DEXON network.
ReceiveChan() <-chan interface{}
}
@@ -92,4 +95,16 @@ type Governance interface {
// Get configuration change events after an epoch.
GetConfigurationChangeEvent(epoch int) []types.ConfigurationChangeEvent
+
+ // AddDKGComplaint adds a DKGComplaint.
+ AddDKGComplaint(complaint *types.DKGComplaint)
+
+ // GetDKGComplaints gets all the DKGComplaints of round.
+ DKGComplaints(round uint64) []*types.DKGComplaint
+
+ // AddDKGMasterPublicKey adds a DKGMasterPublicKey.
+ AddDKGMasterPublicKey(masterPublicKey *types.DKGMasterPublicKey)
+
+ // DKGMasterPublicKeys gets all the DKGMasterPublicKey of round.
+ DKGMasterPublicKeys(round uint64) []*types.DKGMasterPublicKey
}
diff --git a/core/test/governance.go b/core/test/governance.go
index 46f8606..0e5c249 100644
--- a/core/test/governance.go
+++ b/core/test/governance.go
@@ -37,6 +37,8 @@ type Governance struct {
BlockProposingInterval int
Validators map[types.ValidatorID]decimal.Decimal
PrivateKeys map[types.ValidatorID]crypto.PrivateKey
+ DKGComplaint map[uint64][]*types.DKGComplaint
+ DKGMasterPublicKey map[uint64][]*types.DKGMasterPublicKey
}
// NewGovernance constructs a Governance instance.
@@ -46,6 +48,8 @@ func NewGovernance(validatorCount, proposingInterval int) (
BlockProposingInterval: proposingInterval,
Validators: make(map[types.ValidatorID]decimal.Decimal),
PrivateKeys: make(map[types.ValidatorID]crypto.PrivateKey),
+ DKGComplaint: make(map[uint64][]*types.DKGComplaint),
+ DKGMasterPublicKey: make(map[uint64][]*types.DKGMasterPublicKey),
}
for i := 0; i < validatorCount; i++ {
prv, err := eth.NewPrivateKey()
@@ -110,3 +114,34 @@ func (g *Governance) GetPrivateKey(
}
return
}
+
+// AddDKGComplaint add a DKGComplaint.
+func (g *Governance) AddDKGComplaint(complaint *types.DKGComplaint) {
+ g.DKGComplaint[complaint.Round] = append(g.DKGComplaint[complaint.Round], complaint)
+}
+
+// DKGComplaints returns the DKGComplaints of round.
+func (g *Governance) DKGComplaints(round uint64) []*types.DKGComplaint {
+ complaints, exist := g.DKGComplaint[round]
+ if !exist {
+ return []*types.DKGComplaint{}
+ }
+ return complaints
+}
+
+// AddDKGMasterPublicKey adds a DKGMasterPublicKey.
+func (g *Governance) AddDKGMasterPublicKey(
+ masterPublicKey *types.DKGMasterPublicKey) {
+ g.DKGMasterPublicKey[masterPublicKey.Round] = append(
+ g.DKGMasterPublicKey[masterPublicKey.Round], masterPublicKey)
+}
+
+// DKGMasterPublicKeys returns the DKGMasterPublicKeys of round.
+func (g *Governance) DKGMasterPublicKeys(
+ round uint64) []*types.DKGMasterPublicKey {
+ masterPublicKeys, exist := g.DKGMasterPublicKey[round]
+ if !exist {
+ return []*types.DKGMasterPublicKey{}
+ }
+ return masterPublicKeys
+}
diff --git a/core/types/dkg.go b/core/types/dkg.go
new file mode 100644
index 0000000..7fee404
--- /dev/null
+++ b/core/types/dkg.go
@@ -0,0 +1,47 @@
+// Copyright 2018 The dexon-consensus-core Authors
+// This file is part of the dexon-consensus-core library.
+//
+// The dexon-consensus-core library is free software: you can redistribute it
+// and/or modify it under the terms of the GNU Lesser General Public License as
+// published by the Free Software Foundation, either version 3 of the License,
+// or (at your option) any later version.
+//
+// The dexon-consensus-core library is distributed in the hope that it will be
+// useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
+// General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public License
+// along with the dexon-consensus-core library. If not, see
+// <http://www.gnu.org/licenses/>.
+
+package types
+
+import (
+ "github.com/dexon-foundation/dexon-consensus-core/crypto"
+ "github.com/dexon-foundation/dexon-consensus-core/crypto/dkg"
+)
+
+// DKGPrivateShare describe a secret share in DKG protocol.
+type DKGPrivateShare struct {
+ ProposerID ValidatorID `json:"proposer_id"`
+ Round uint64 `json:"round"`
+ PrivateKeyShare dkg.PrivateKey `json:"private_key_share"`
+ Signature crypto.Signature `json:"signature"`
+}
+
+// DKGMasterPublicKey decrtibe a master public key in DKG protocol.
+type DKGMasterPublicKey struct {
+ ProposerID ValidatorID `json:"proposer_id"`
+ Round uint64 `json:"round"`
+ PublicKeyShares dkg.PublicKeyShares `json:"private_key_share"`
+ Signature crypto.Signature `json:"signature"`
+}
+
+// DKGComplaint describe a complaint in DKG protocol.
+type DKGComplaint struct {
+ ProposerID ValidatorID `json:"proposer_id"`
+ Round uint64 `json:"round"`
+ PrivateShare DKGPrivateShare `json:"private_share"`
+ Signature crypto.Signature `json:"signature"`
+}