aboutsummaryrefslogtreecommitdiffstats
path: root/state/managed_state.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-03-14 00:47:00 +0800
committerobscuren <geffobscura@gmail.com>2015-03-14 00:47:00 +0800
commita0266489b4592af751d87c59087ed25a32899de6 (patch)
tree4adeaf731ad8d2a0c20a7738caf25ef3a086248a /state/managed_state.go
parentb663e8b29a7451a79b909c017f8a244d23c8fef4 (diff)
downloaddexon-a0266489b4592af751d87c59087ed25a32899de6.tar
dexon-a0266489b4592af751d87c59087ed25a32899de6.tar.gz
dexon-a0266489b4592af751d87c59087ed25a32899de6.tar.bz2
dexon-a0266489b4592af751d87c59087ed25a32899de6.tar.lz
dexon-a0266489b4592af751d87c59087ed25a32899de6.tar.xz
dexon-a0266489b4592af751d87c59087ed25a32899de6.tar.zst
dexon-a0266489b4592af751d87c59087ed25a32899de6.zip
Make remote dominant
Diffstat (limited to 'state/managed_state.go')
-rw-r--r--state/managed_state.go20
1 files changed, 17 insertions, 3 deletions
diff --git a/state/managed_state.go b/state/managed_state.go
index 1914e977a..aff0206b2 100644
--- a/state/managed_state.go
+++ b/state/managed_state.go
@@ -23,13 +23,19 @@ func ManageState(statedb *StateDB) *ManagedState {
}
}
+func (ms *ManagedState) SetState(statedb *StateDB) {
+ ms.mu.Lock()
+ defer ms.mu.Unlock()
+ ms.StateDB = statedb
+}
+
func (ms *ManagedState) RemoveNonce(addr []byte, n uint64) {
if ms.hasAccount(addr) {
ms.mu.Lock()
defer ms.mu.Unlock()
account := ms.getAccount(addr)
- if n-account.nstart < uint64(len(account.nonces)) {
+ if n-account.nstart <= uint64(len(account.nonces)) {
reslice := make([]bool, n-account.nstart)
copy(reslice, account.nonces[:n-account.nstart])
account.nonces = reslice
@@ -47,7 +53,7 @@ func (ms *ManagedState) NewNonce(addr []byte) uint64 {
return account.nstart + uint64(i)
}
}
- account.nonces = append(account.nonces, false)
+ account.nonces = append(account.nonces, true)
return uint64(len(account.nonces)) + account.nstart
}
@@ -57,9 +63,17 @@ func (ms *ManagedState) hasAccount(addr []byte) bool {
}
func (ms *ManagedState) getAccount(addr []byte) *account {
- if _, ok := ms.accounts[string(addr)]; !ok {
+ if account, ok := ms.accounts[string(addr)]; !ok {
so := ms.GetOrNewStateObject(addr)
ms.accounts[string(addr)] = newAccount(so)
+ } else {
+ // Always make sure the state account nonce isn't actually higher
+ // than the tracked one.
+ so := ms.StateDB.GetStateObject(addr)
+ if so != nil && uint64(len(account.nonces))+account.nstart < so.nonce {
+ ms.accounts[string(addr)] = newAccount(so)
+ }
+
}
return ms.accounts[string(addr)]