From 204ac81188e43900835c6aa5bad6b3e48f3a16d0 Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 8 Apr 2015 23:30:07 +0200 Subject: Moved handling of nonces to the managed state --- core/state/managed_state.go | 4 ++-- core/state/managed_state_test.go | 9 ++++++--- eth/backend.go | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/core/state/managed_state.go b/core/state/managed_state.go index ddf337af3..9d2fc48e7 100644 --- a/core/state/managed_state.go +++ b/core/state/managed_state.go @@ -62,7 +62,7 @@ func (ms *ManagedState) NewNonce(addr common.Address) uint64 { } } account.nonces = append(account.nonces, true) - return uint64(len(account.nonces)) + account.nstart + return uint64(len(account.nonces)-1) + account.nstart } // GetNonce returns the canonical nonce for the managed or unmanged account @@ -109,5 +109,5 @@ func (ms *ManagedState) getAccount(addr common.Address) *account { } func newAccount(so *StateObject) *account { - return &account{so, so.nonce - 1, nil} + return &account{so, so.nonce, nil} } diff --git a/core/state/managed_state_test.go b/core/state/managed_state_test.go index 766231d21..c7ef2b323 100644 --- a/core/state/managed_state_test.go +++ b/core/state/managed_state_test.go @@ -4,12 +4,15 @@ import ( "testing" "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/ethdb" ) var addr = common.BytesToAddress([]byte("test")) func create() (*ManagedState, *account) { - ms := ManageState(&StateDB{stateObjects: make(map[string]*StateObject)}) + db, _ := ethdb.NewMemDatabase() + statedb := New(common.Hash{}, db) + ms := ManageState(statedb) so := &StateObject{address: addr, nonce: 100} ms.StateDB.stateObjects[addr.Str()] = so ms.accounts[addr.Str()] = newAccount(so) @@ -95,13 +98,13 @@ func TestSetNonce(t *testing.T) { ms.SetNonce(addr, 10) if ms.GetNonce(addr) != 10 { - t.Errorf("Expected nonce of 10, got", ms.GetNonce(addr)) + t.Error("Expected nonce of 10, got", ms.GetNonce(addr)) } addr[0] = 1 ms.StateDB.SetNonce(addr, 1) if ms.GetNonce(addr) != 1 { - t.Errorf("Expected nonce of 1, got", ms.GetNonce(addr)) + t.Error("Expected nonce of 1, got", ms.GetNonce(addr)) } } diff --git a/eth/backend.go b/eth/backend.go index 327a5c7f8..c7a5b233f 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -449,7 +449,7 @@ func (self *Ethereum) syncAccounts(tx *types.Transaction) { if self.accountManager.HasAccount(from.Bytes()) { if self.chainManager.TxState().GetNonce(from) < tx.Nonce() { - self.chainManager.TxState().SetNonce(from, tx.Nonce()+1) + self.chainManager.TxState().SetNonce(from, tx.Nonce()) } } } -- cgit v1.2.3