aboutsummaryrefslogtreecommitdiffstats
path: root/core/test/state.go
diff options
context:
space:
mode:
authorMission Liao <mission.liao@dexon.org>2018-10-30 14:34:14 +0800
committerGitHub <noreply@github.com>2018-10-30 14:34:14 +0800
commit39a1c5bf189a2be4d0bc9b9c50cc73f1599ce732 (patch)
treea87c5f90957d88d49c6255259efad5d2299d95be /core/test/state.go
parent9c08b810e12f0a828e1de47b40b4e5de30c1c929 (diff)
downloaddexon-consensus-39a1c5bf189a2be4d0bc9b9c50cc73f1599ce732.tar
dexon-consensus-39a1c5bf189a2be4d0bc9b9c50cc73f1599ce732.tar.gz
dexon-consensus-39a1c5bf189a2be4d0bc9b9c50cc73f1599ce732.tar.bz2
dexon-consensus-39a1c5bf189a2be4d0bc9b9c50cc73f1599ce732.tar.lz
dexon-consensus-39a1c5bf189a2be4d0bc9b9c50cc73f1599ce732.tar.xz
dexon-consensus-39a1c5bf189a2be4d0bc9b9c50cc73f1599ce732.tar.zst
dexon-consensus-39a1c5bf189a2be4d0bc9b9c50cc73f1599ce732.zip
test: integrate state to gov (#275)
* Fix dummy error * Check validity before apply state changes. * Add RegisterConfigChange method to test.Governance * Add SwitchToRemoteMode method to test.State
Diffstat (limited to 'core/test/state.go')
-rw-r--r--core/test/state.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/core/test/state.go b/core/test/state.go
index 34c38bc..51c7ab7 100644
--- a/core/test/state.go
+++ b/core/test/state.go
@@ -180,6 +180,14 @@ func NewState(
}
}
+// SwitchToRemoteMode turn this State instance into remote mode: all changes
+// are pending, and need to be packed/unpacked to apply.
+func (s *State) SwitchToRemoteMode() {
+ s.lock.Lock()
+ defer s.lock.Unlock()
+ s.local = false
+}
+
// Snapshot returns configration that could be snapshotted.
func (s *State) Snapshot() (*types.Config, []crypto.PublicKey) {
s.lock.RLock()
@@ -575,6 +583,13 @@ func (s *State) Apply(reqsAsBytes []byte) (err error) {
s.lock.Lock()
defer s.lock.Unlock()
for _, req := range reqs {
+ if err = s.isValidRequest(req); err != nil {
+ if err == ErrDuplicatedChange {
+ err = nil
+ continue
+ }
+ return
+ }
if err = s.applyRequest(req); err != nil {
return
}