diff options
author | Mission Liao <mission.liao@dexon.org> | 2018-12-26 10:15:51 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-26 10:15:51 +0800 |
commit | d333dc1a24df26ae8e8e3ffa2d700c1116a93ba2 (patch) | |
tree | f615cfa34cca680dd3e4a5930e06a6ff03ac1664 /core/test/state-change-request.go | |
parent | dce509a13ef5873b9cae3c1cabdb97e219b6fb7d (diff) | |
download | tangerine-consensus-d333dc1a24df26ae8e8e3ffa2d700c1116a93ba2.tar tangerine-consensus-d333dc1a24df26ae8e8e3ffa2d700c1116a93ba2.tar.gz tangerine-consensus-d333dc1a24df26ae8e8e3ffa2d700c1116a93ba2.tar.bz2 tangerine-consensus-d333dc1a24df26ae8e8e3ffa2d700c1116a93ba2.tar.lz tangerine-consensus-d333dc1a24df26ae8e8e3ffa2d700c1116a93ba2.tar.xz tangerine-consensus-d333dc1a24df26ae8e8e3ffa2d700c1116a93ba2.tar.zst tangerine-consensus-d333dc1a24df26ae8e8e3ffa2d700c1116a93ba2.zip |
simulation: support config change (#381)
Diffstat (limited to 'core/test/state-change-request.go')
-rw-r--r-- | core/test/state-change-request.go | 86 |
1 files changed, 55 insertions, 31 deletions
diff --git a/core/test/state-change-request.go b/core/test/state-change-request.go index 687eef7..21e623b 100644 --- a/core/test/state-change-request.go +++ b/core/test/state-change-request.go @@ -55,6 +55,44 @@ const ( StateAddNode ) +func (t StateChangeType) String() string { + switch t { + case StateChangeNothing: + return "Nothing" + case StateAddCRS: + return "AddCRS" + case StateAddDKGComplaint: + return "AddDKGComplaint" + case StateAddDKGMasterPublicKey: + return "AddDKGMasterPublicKey" + case StateAddDKGMPKReady: + return "AddDKGMPKReady" + case StateAddDKGFinal: + return "AddDKGFinal" + case StateChangeNumChains: + return "ChangeNumChains" + case StateChangeLambdaBA: + return "ChangeLambdaBA" + case StateChangeLambdaDKG: + return "ChangeLambdaDKG" + case StateChangeRoundInterval: + return "ChangeRoundInterval" + case StateChangeMinBlockInterval: + return "ChangeMinBlockInterval" + case StateChangeK: + return "ChangeK" + case StateChangePhiRatio: + return "ChangePhiRatio" + case StateChangeNotarySetSize: + return "ChangeNotarySetSize" + case StateChangeDKGSetSize: + return "ChangeDKGSetSize" + case StateAddNode: + return "AddNode" + } + panic(fmt.Errorf("attempting to dump unknown type of state change: %d", t)) +} + // StateChangeRequest carries information of state change request. type StateChangeRequest struct { Type StateChangeType `json:"type"` @@ -141,56 +179,42 @@ func (req *StateChangeRequest) Equal(other *StateChangeRequest) error { // String dump the state change request into string form. func (req *StateChangeRequest) String() (ret string) { - ret = "stateChangeRequest" + ret = fmt.Sprintf("stateChangeRequest{Type:%s", req.Type) switch req.Type { case StateChangeNothing: - ret += "{Type:Nothing}" case StateAddCRS: crsReq := req.Payload.(*crsAdditionRequest) - ret += fmt.Sprintf("{Type:AddCRS Round:%v CRS:%s", - crsReq.Round, - crsReq.CRS.String()[:6]) - case StateAddDKGComplaint: ret += fmt.Sprintf( - "{Type:AddDKGComplaint %s", req.Payload.(*typesDKG.Complaint)) + "Round:%v CRS:%s", crsReq.Round, crsReq.CRS.String()[:6]) + case StateAddDKGComplaint: + ret += fmt.Sprintf("%s", req.Payload.(*typesDKG.Complaint)) case StateAddDKGMasterPublicKey: - ret += fmt.Sprintf( - "{Type:AddDKGMasterPublicKey %s", - req.Payload.(*typesDKG.MasterPublicKey)) + ret += fmt.Sprintf("%s", req.Payload.(*typesDKG.MasterPublicKey)) case StateAddDKGMPKReady: - ret += fmt.Sprintf( - "{Type:AddDKGMPKReady %s", req.Payload.(*typesDKG.MPKReady)) + ret += fmt.Sprintf("%s", req.Payload.(*typesDKG.MPKReady)) case StateAddDKGFinal: - ret += fmt.Sprintf( - "{Type:AddDKGFinal %s", req.Payload.(*typesDKG.Finalize)) + ret += fmt.Sprintf("%s", req.Payload.(*typesDKG.Finalize)) case StateChangeNumChains: - ret += fmt.Sprintf("{Type:ChangeNumChains %v", req.Payload.(uint32)) + ret += fmt.Sprintf("%v", req.Payload.(uint32)) case StateChangeLambdaBA: - ret += fmt.Sprintf( - "{Type:ChangeLambdaBA %v", time.Duration(req.Payload.(uint64))) + ret += fmt.Sprintf("%v", time.Duration(req.Payload.(uint64))) case StateChangeLambdaDKG: - ret += fmt.Sprintf( - "{Type:ChangeLambdaDKG %v", time.Duration(req.Payload.(uint64))) + ret += fmt.Sprintf("%v", time.Duration(req.Payload.(uint64))) case StateChangeRoundInterval: - ret += fmt.Sprintf( - "{Type:ChangeRoundInterval %v", time.Duration(req.Payload.(uint64))) + ret += fmt.Sprintf("%v", time.Duration(req.Payload.(uint64))) case StateChangeMinBlockInterval: - ret += fmt.Sprintf( - "{Type:ChangeMinBlockInterval %v", - time.Duration(req.Payload.(uint64))) + ret += fmt.Sprintf("%v", time.Duration(req.Payload.(uint64))) case StateChangeK: - ret += fmt.Sprintf("Type:ChangeK %v", req.Payload.(uint64)) + ret += fmt.Sprintf("%v", req.Payload.(uint64)) case StateChangePhiRatio: - ret += fmt.Sprintf( - "{Type:ChangePhiRatio %v", math.Float32frombits(req.Payload.(uint32))) + ret += fmt.Sprintf("%v", math.Float32frombits(req.Payload.(uint32))) case StateChangeNotarySetSize: - ret += fmt.Sprintf("{Type:ChangeNotarySetSize %v", req.Payload.(uint32)) + ret += fmt.Sprintf("%v", req.Payload.(uint32)) case StateChangeDKGSetSize: - ret += fmt.Sprintf("{Type:ChangeDKGSetSize %v", req.Payload.(uint32)) + ret += fmt.Sprintf("%v", req.Payload.(uint32)) case StateAddNode: ret += fmt.Sprintf( - "{Type:AddNode %s", - types.NewNodeID(req.Payload.(crypto.PublicKey)).String()[:6]) + "%s", types.NewNodeID(req.Payload.(crypto.PublicKey)).String()[:6]) default: panic(fmt.Errorf( "attempting to dump unknown type of state change request: %v", |