aboutsummaryrefslogtreecommitdiffstats
path: root/core/test/state.go
diff options
context:
space:
mode:
authorMission Liao <mission.liao@dexon.org>2019-03-17 09:56:23 +0800
committerJimmy Hu <jimmy.hu@dexon.org>2019-03-17 09:56:23 +0800
commit4b40c1b8990d2a371a77018feea32d038163f2ec (patch)
treeb482aee945e1f60c6c9c9efd86c39abe812a353b /core/test/state.go
parentb636901c60aa666c6c6b532d06e78b529537d315 (diff)
downloaddexon-consensus-4b40c1b8990d2a371a77018feea32d038163f2ec.tar
dexon-consensus-4b40c1b8990d2a371a77018feea32d038163f2ec.tar.gz
dexon-consensus-4b40c1b8990d2a371a77018feea32d038163f2ec.tar.bz2
dexon-consensus-4b40c1b8990d2a371a77018feea32d038163f2ec.tar.lz
dexon-consensus-4b40c1b8990d2a371a77018feea32d038163f2ec.tar.xz
dexon-consensus-4b40c1b8990d2a371a77018feea32d038163f2ec.tar.zst
dexon-consensus-4b40c1b8990d2a371a77018feea32d038163f2ec.zip
dkg: add reset field (#492)
* Add Reset fields to DKG types * Fix crypto part after adding Reset field * Prohibit DKG messages with different resetCount * Add TODO * Add reset parameter to dkgProtocol constructor * Add TODO * Fix inconsist hash to prepare CRS * Add reset parameter when runnning DKG * Fix test for utils.RoundEvent * Add dummy test to prohibit DKG messages with unexpected reset count * Fix test.App
Diffstat (limited to 'core/test/state.go')
-rw-r--r--core/test/state.go30
1 files changed, 27 insertions, 3 deletions
diff --git a/core/test/state.go b/core/test/state.go
index fbf4505..89d2e90 100644
--- a/core/test/state.go
+++ b/core/test/state.go
@@ -74,6 +74,12 @@ var (
// ErrStatePendingChangesNotEqual means pending change requests of two
// states are not equal.
ErrStatePendingChangesNotEqual = errors.New("pending changes not equal")
+ // ErrChangeWontApply means the state change won't be applied for some
+ // reason.
+ ErrChangeWontApply = errors.New("change won't apply")
+ // ErrUnmatchedResetCount means an DKG message attempt to apply is not
+ // the latest reset count in State module.
+ ErrUnmatchedResetCount = errors.New("unmatched reset count of DKG message")
// ErrNotInRemoteMode means callers attempts to call functions for remote
// mode when the State instance is still in local mode.
ErrNotInRemoteMode = errors.New(
@@ -628,20 +634,33 @@ func (s *State) PackOwnRequests() (b []byte, err error) {
}
// isValidRequest checks if this request is valid to proceed or not.
-func (s *State) isValidRequest(req *StateChangeRequest) (err error) {
+func (s *State) isValidRequest(req *StateChangeRequest) error {
// NOTE: there would be no lock in this helper, callers should be
// responsible for acquiring appropriate lock.
switch req.Type {
+ case StateAddDKGMPKReady:
+ ready := req.Payload.(*typesDKG.MPKReady)
+ if ready.Reset != s.dkgResetCount[ready.Round] {
+ return ErrUnmatchedResetCount
+ }
+ case StateAddDKGFinal:
+ final := req.Payload.(*typesDKG.Finalize)
+ if final.Reset != s.dkgResetCount[final.Round] {
+ return ErrUnmatchedResetCount
+ }
case StateAddDKGMasterPublicKey:
mpk := req.Payload.(*typesDKG.MasterPublicKey)
+ if mpk.Reset != s.dkgResetCount[mpk.Round] {
+ return ErrUnmatchedResetCount
+ }
// If we've received identical MPK, ignore it.
mpkForRound, exists := s.dkgMasterPublicKeys[mpk.Round]
if exists {
if oldMpk, exists := mpkForRound[mpk.ProposerID]; exists {
if !oldMpk.Equal(mpk) {
- err = ErrDuplicatedChange
+ return ErrDuplicatedChange
}
- return
+ return ErrChangeWontApply
}
}
// If we've received MPK from that proposer, we would ignore
@@ -651,6 +670,9 @@ func (s *State) isValidRequest(req *StateChangeRequest) (err error) {
}
case StateAddDKGComplaint:
comp := req.Payload.(*typesDKG.Complaint)
+ if comp.Reset != s.dkgResetCount[comp.Round] {
+ return ErrUnmatchedResetCount
+ }
// If we've received DKG final from that proposer, we would ignore
// its complaint.
if _, exists := s.dkgFinals[comp.Round][comp.ProposerID]; exists {
@@ -687,6 +709,8 @@ func (s *State) isValidRequest(req *StateChangeRequest) (err error) {
if s.crs[len(s.crs)-1].Equal(newCRS) {
return ErrDuplicatedChange
}
+ // TODO(mission): find a smart way to make sure the caller call request
+ // this change with correct resetCount.
}
return nil
}