diff options
author | Jimmy Hu <jimmy.hu@dexon.org> | 2018-10-25 09:55:59 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-25 09:55:59 +0800 |
commit | 9839a1c6fecbada7d1736680930c3e527f984470 (patch) | |
tree | 400c69e60c132dd5101f125eda7114e4bb098b45 /simulation | |
parent | 14b91441825d6b990527e947c021a5311e951c25 (diff) | |
download | dexon-consensus-9839a1c6fecbada7d1736680930c3e527f984470.tar dexon-consensus-9839a1c6fecbada7d1736680930c3e527f984470.tar.gz dexon-consensus-9839a1c6fecbada7d1736680930c3e527f984470.tar.bz2 dexon-consensus-9839a1c6fecbada7d1736680930c3e527f984470.tar.lz dexon-consensus-9839a1c6fecbada7d1736680930c3e527f984470.tar.xz dexon-consensus-9839a1c6fecbada7d1736680930c3e527f984470.tar.zst dexon-consensus-9839a1c6fecbada7d1736680930c3e527f984470.zip |
core: Move dkg in types to types/dkg. (#253)
Diffstat (limited to 'simulation')
-rw-r--r-- | simulation/governance.go | 23 | ||||
-rw-r--r-- | simulation/marshaller.go | 21 | ||||
-rw-r--r-- | simulation/network.go | 9 | ||||
-rw-r--r-- | simulation/node.go | 7 |
4 files changed, 32 insertions, 28 deletions
diff --git a/simulation/governance.go b/simulation/governance.go index fb6ac5c..e0ddc5a 100644 --- a/simulation/governance.go +++ b/simulation/governance.go @@ -25,6 +25,7 @@ import ( "github.com/dexon-foundation/dexon-consensus-core/common" "github.com/dexon-foundation/dexon-consensus-core/core/crypto" "github.com/dexon-foundation/dexon-consensus-core/core/types" + typesDKG "github.com/dexon-foundation/dexon-consensus-core/core/types/dkg" "github.com/dexon-foundation/dexon-consensus-core/simulation/config" ) @@ -40,8 +41,8 @@ type simGovernance struct { chainNum uint32 crs []common.Hash tsig map[uint64]crypto.Signature - dkgComplaint map[uint64][]*types.DKGComplaint - dkgMasterPublicKey map[uint64][]*types.DKGMasterPublicKey + dkgComplaint map[uint64][]*typesDKG.Complaint + dkgMasterPublicKey map[uint64][]*typesDKG.MasterPublicKey dkgFinal map[uint64]map[types.NodeID]struct{} lambdaBA time.Duration lambdaDKG time.Duration @@ -63,8 +64,8 @@ func newSimGovernance( 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), + dkgComplaint: make(map[uint64][]*typesDKG.Complaint), + dkgMasterPublicKey: make(map[uint64][]*typesDKG.MasterPublicKey), dkgFinal: make(map[uint64]map[types.NodeID]struct{}), lambdaBA: time.Duration(consensusConfig.LambdaBA) * time.Millisecond, @@ -146,7 +147,7 @@ func (g *simGovernance) addNode(pubKey crypto.PublicKey) { // AddDKGComplaint adds a DKGComplaint. func (g *simGovernance) AddDKGComplaint( - round uint64, complaint *types.DKGComplaint) { + round uint64, complaint *typesDKG.Complaint) { if round != complaint.Round { return } @@ -165,17 +166,17 @@ func (g *simGovernance) AddDKGComplaint( } // DKGComplaints returns the DKGComplaints of round. -func (g *simGovernance) DKGComplaints(round uint64) []*types.DKGComplaint { +func (g *simGovernance) DKGComplaints(round uint64) []*typesDKG.Complaint { complaints, exist := g.dkgComplaint[round] if !exist { - return []*types.DKGComplaint{} + return []*typesDKG.Complaint{} } return complaints } // AddDKGMasterPublicKey adds a DKGMasterPublicKey. func (g *simGovernance) AddDKGMasterPublicKey( - round uint64, masterPublicKey *types.DKGMasterPublicKey) { + round uint64, masterPublicKey *typesDKG.MasterPublicKey) { if round != masterPublicKey.Round { return } @@ -189,17 +190,17 @@ func (g *simGovernance) AddDKGMasterPublicKey( // DKGMasterPublicKeys returns the DKGMasterPublicKeys of round. func (g *simGovernance) DKGMasterPublicKeys( - round uint64) []*types.DKGMasterPublicKey { + round uint64) []*typesDKG.MasterPublicKey { masterPublicKeys, exist := g.dkgMasterPublicKey[round] if !exist { - return []*types.DKGMasterPublicKey{} + return []*typesDKG.MasterPublicKey{} } return masterPublicKeys } // AddDKGFinalize adds a DKG finalize message. func (g *simGovernance) AddDKGFinalize( - round uint64, final *types.DKGFinalize) { + round uint64, final *typesDKG.Finalize) { if round != final.Round { return } diff --git a/simulation/marshaller.go b/simulation/marshaller.go index bb60432..a051c16 100644 --- a/simulation/marshaller.go +++ b/simulation/marshaller.go @@ -22,6 +22,7 @@ import ( "fmt" "github.com/dexon-foundation/dexon-consensus-core/core/types" + typesDKG "github.com/dexon-foundation/dexon-consensus-core/core/types/dkg" ) // jsonMarshaller implements test.Marshaller to marshal simulation related @@ -76,31 +77,31 @@ func (m *jsonMarshaller) Unmarshal( } msg = result case "dkg-private-share": - privateShare := &types.DKGPrivateShare{} + privateShare := &typesDKG.PrivateShare{} if err = json.Unmarshal(payload, privateShare); err != nil { break } msg = privateShare case "dkg-master-public-key": - masterPublicKey := types.NewDKGMasterPublicKey() + masterPublicKey := typesDKG.NewMasterPublicKey() if err = json.Unmarshal(payload, masterPublicKey); err != nil { break } msg = masterPublicKey case "dkg-complaint": - complaint := &types.DKGComplaint{} + complaint := &typesDKG.Complaint{} if err = json.Unmarshal(payload, complaint); err != nil { break } msg = complaint case "dkg-partial-signature": - psig := &types.DKGPartialSignature{} + psig := &typesDKG.PartialSignature{} if err = json.Unmarshal(payload, psig); err != nil { break } msg = psig case "dkg-finalize": - final := &types.DKGFinalize{} + final := &typesDKG.Finalize{} if err = json.Unmarshal(payload, final); err != nil { break } @@ -133,15 +134,15 @@ func (m *jsonMarshaller) Marshal(msg interface{}) ( msgType = "block-randomness-request" case *types.BlockRandomnessResult: msgType = "block-randomness-result" - case *types.DKGPrivateShare: + case *typesDKG.PrivateShare: msgType = "dkg-private-share" - case *types.DKGMasterPublicKey: + case *typesDKG.MasterPublicKey: msgType = "dkg-master-public-key" - case *types.DKGComplaint: + case *typesDKG.Complaint: msgType = "dkg-complaint" - case *types.DKGPartialSignature: + case *typesDKG.PartialSignature: msgType = "dkg-partial-signature" - case *types.DKGFinalize: + case *typesDKG.Finalize: msgType = "dkg-finalize" default: err = fmt.Errorf("unknwon message type: %v", msg) diff --git a/simulation/network.go b/simulation/network.go index 985fad7..5cd97b6 100644 --- a/simulation/network.go +++ b/simulation/network.go @@ -29,6 +29,7 @@ import ( "github.com/dexon-foundation/dexon-consensus-core/core/crypto" "github.com/dexon-foundation/dexon-consensus-core/core/test" "github.com/dexon-foundation/dexon-consensus-core/core/types" + typesDKG "github.com/dexon-foundation/dexon-consensus-core/core/types/dkg" "github.com/dexon-foundation/dexon-consensus-core/simulation/config" ) @@ -183,7 +184,7 @@ func (n *network) broadcast(message interface{}) { // SendDKGPrivateShare implements core.Network interface. func (n *network) SendDKGPrivateShare( - recv crypto.PublicKey, prvShare *types.DKGPrivateShare) { + recv crypto.PublicKey, prvShare *typesDKG.PrivateShare) { if err := n.trans.Send(types.NewNodeID(recv), prvShare); err != nil { panic(err) } @@ -191,7 +192,7 @@ func (n *network) SendDKGPrivateShare( // BroadcastDKGPrivateShare implements core.Network interface. func (n *network) BroadcastDKGPrivateShare( - prvShare *types.DKGPrivateShare) { + prvShare *typesDKG.PrivateShare) { if err := n.trans.Broadcast(prvShare); err != nil { panic(err) } @@ -199,7 +200,7 @@ func (n *network) BroadcastDKGPrivateShare( // BroadcastDKGPartialSignature implements core.Network interface. func (n *network) BroadcastDKGPartialSignature( - psig *types.DKGPartialSignature) { + psig *typesDKG.PartialSignature) { if err := n.trans.Broadcast(psig); err != nil { panic(err) } @@ -242,7 +243,7 @@ func (n *network) run() { switch e.Msg.(type) { case *types.Block, *types.Vote, *types.AgreementResult, *types.BlockRandomnessResult, - *types.DKGPrivateShare, *types.DKGPartialSignature: + *typesDKG.PrivateShare, *typesDKG.PartialSignature: n.toConsensus <- e.Msg default: n.toNode <- e.Msg diff --git a/simulation/node.go b/simulation/node.go index 5919b3e..9291fdc 100644 --- a/simulation/node.go +++ b/simulation/node.go @@ -27,6 +27,7 @@ import ( "github.com/dexon-foundation/dexon-consensus-core/core/blockdb" "github.com/dexon-foundation/dexon-consensus-core/core/crypto" "github.com/dexon-foundation/dexon-consensus-core/core/types" + typesDKG "github.com/dexon-foundation/dexon-consensus-core/core/types/dkg" "github.com/dexon-foundation/dexon-consensus-core/simulation/config" ) @@ -118,11 +119,11 @@ MainLoop: if val == statusShutdown { break MainLoop } - case *types.DKGComplaint: + case *typesDKG.Complaint: n.gov.AddDKGComplaint(val.Round, val) - case *types.DKGMasterPublicKey: + case *typesDKG.MasterPublicKey: n.gov.AddDKGMasterPublicKey(val.Round, val) - case *types.DKGFinalize: + case *typesDKG.Finalize: n.gov.AddDKGFinalize(val.Round, val) default: panic(fmt.Errorf("unexpected message from server: %v", val)) |