diff --git a/core/state/dump.go b/core/state/dump.go index f38e5481cb..1c32eed542 100644 --- a/core/state/dump.go +++ b/core/state/dump.go @@ -29,15 +29,15 @@ import ( // DumpAccount represents an account in the state type DumpAccount struct { - Balance string `json:"balance"` - Nonce uint64 `json:"nonce"` - Root string `json:"root"` - CodeHash string `json:"codeHash"` - Code string `json:"code,omitempty"` - CodeVersion uint64 `json:"codeVersion"` - Storage map[common.Hash]string `json:"storage,omitempty"` - Address *common.Address `json:"address,omitempty"` // Address only present in iterative (line-by-line) mode - SecureKey hexutil.Bytes `json:"key,omitempty"` // If we don't have address, we can output the key + Balance string `json:"balance"` + Nonce uint64 `json:"nonce"` + Root string `json:"root"` + CodeHash string `json:"codeHash"` + Code string `json:"code,omitempty"` + Version uint64 `json:"version"` + Storage map[common.Hash]string `json:"storage,omitempty"` + Address *common.Address `json:"address,omitempty"` // Address only present in iterative (line-by-line) mode + SecureKey hexutil.Bytes `json:"key,omitempty"` // If we don't have address, we can output the key } @@ -66,15 +66,15 @@ func (self *Dump) onAccount(addr common.Address, account DumpAccount) { func (self iterativeDump) onAccount(addr common.Address, account DumpAccount) { dumpAccount := &DumpAccount{ - Balance: account.Balance, - Nonce: account.Nonce, - Root: account.Root, - CodeHash: account.CodeHash, - Code: account.Code, - CodeVersion: account.CodeVersion, - Storage: account.Storage, - SecureKey: account.SecureKey, - Address: nil, + Balance: account.Balance, + Nonce: account.Nonce, + Root: account.Root, + CodeHash: account.CodeHash, + Code: account.Code, + Version: account.Version, + Storage: account.Storage, + SecureKey: account.SecureKey, + Address: nil, } if addr != (common.Address{}) { dumpAccount.Address = &addr @@ -100,11 +100,11 @@ func (self *StateDB) dump(c collector, excludeCode, excludeStorage, excludeMissi addr := common.BytesToAddress(self.trie.GetKey(it.Key)) obj := newObject(nil, addr, data) account := DumpAccount{ - Balance: data.Balance.String(), - Nonce: data.Nonce, - Root: common.Bytes2Hex(data.Root[:]), - CodeHash: common.Bytes2Hex(data.CodeHash), - CodeVersion: data.CodeVersion, + Balance: data.Balance.String(), + Nonce: data.Nonce, + Root: common.Bytes2Hex(data.Root[:]), + CodeHash: common.Bytes2Hex(data.CodeHash), + Version: data.Version, } if emptyAddress == addr { // Preimage missing diff --git a/core/state/state_object.go b/core/state/state_object.go index 2d0b2cd8f1..29dc375bb9 100644 --- a/core/state/state_object.go +++ b/core/state/state_object.go @@ -109,16 +109,16 @@ type storedAccount Account // Account is ethereum consensus representation of accounts. These objects are // stored in the main account trie. type Account struct { - Nonce uint64 // The nonce of account. - Balance *big.Int // The balance of account. - Root common.Hash // Merkle root of the storage trie. - CodeHash []byte // The code hash of account. - CodeVersion uint64 // The version of account code. + Nonce uint64 // The nonce of account. + Balance *big.Int // The balance of account. + Root common.Hash // Merkle root of the storage trie. + CodeHash []byte // The code hash of account. + Version uint64 // The version of account as well as the version of code. } // EncodeRLP implements rlp.Encoder. func (a *Account) EncodeRLP(w io.Writer) error { - if a.CodeVersion == 0 { + if a.Version == 0 { return rlp.Encode(w, legacyStoredAccount{a.Nonce, a.Balance, a.Root, a.CodeHash}) } return rlp.Encode(w, storedAccount(*a)) @@ -421,7 +421,7 @@ func (s *stateObject) SetCode(codeHash common.Hash, code []byte, version uint64) account: &s.address, prevhash: s.CodeHash(), prevcode: prevcode, - version: s.data.CodeVersion, + version: s.data.Version, }) s.setCode(codeHash, code, version) } @@ -429,7 +429,7 @@ func (s *stateObject) SetCode(codeHash common.Hash, code []byte, version uint64) func (s *stateObject) setCode(codeHash common.Hash, code []byte, version uint64) { s.code = code s.data.CodeHash = codeHash[:] - s.data.CodeVersion = version + s.data.Version = version s.dirtyCode = true } @@ -458,7 +458,7 @@ func (s *stateObject) Nonce() uint64 { } func (s *stateObject) CodeVersion() uint64 { - return s.data.CodeVersion + return s.data.Version } // Never called, but must be present to allow stateObject to be used diff --git a/core/state/state_test.go b/core/state/state_test.go index 3a1e3f13a8..0a4b96daab 100644 --- a/core/state/state_test.go +++ b/core/state/state_test.go @@ -61,14 +61,14 @@ func (s *StateSuite) TestDump(c *checker.C) { "nonce": 0, "root": "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", "codeHash": "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470", - "codeVersion": 0 + "version": 0 }, "0x0000000000000000000000000000000000000002": { "balance": "44", "nonce": 0, "root": "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", "codeHash": "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470", - "codeVersion": 0 + "version": 0 }, "0x0000000000000000000000000000000000000102": { "balance": "0", @@ -76,7 +76,7 @@ func (s *StateSuite) TestDump(c *checker.C) { "root": "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", "codeHash": "87874902497a5bb968da31a2998d8f22e949d1ef6214bcdedd8bae24cca4b9e3", "code": "03030303030303", - "codeVersion": 0 + "version": 0 } } }` diff --git a/core/state/statedb.go b/core/state/statedb.go index 0435b90969..b6f13554b0 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -278,7 +278,7 @@ func (self *StateDB) GetCodeHash(addr common.Address) common.Hash { return common.BytesToHash(stateObject.CodeHash()) } -func (self *StateDB) GetCodeVersion(addr common.Address) uint64 { +func (self *StateDB) GetVersion(addr common.Address) uint64 { stateObject := self.getStateObject(addr) if stateObject == nil { return 0 diff --git a/core/state/statedb_test.go b/core/state/statedb_test.go index dcb14131aa..651beb2944 100644 --- a/core/state/statedb_test.go +++ b/core/state/statedb_test.go @@ -460,25 +460,25 @@ func TestStateObjectDecoding(t *testing.T) { CodeHash: []byte{0x01, 0x02, 0x03}, }, { - Nonce: 100, - Balance: big.NewInt(100), - Root: common.HexToHash("deadbeef"), - CodeHash: []byte{0x01, 0x02, 0x03}, - CodeVersion: 0, + Nonce: 100, + Balance: big.NewInt(100), + Root: common.HexToHash("deadbeef"), + CodeHash: []byte{0x01, 0x02, 0x03}, + Version: 0, }, { - Nonce: 100, - Balance: big.NewInt(100), - Root: common.HexToHash("deadbeef"), - CodeHash: []byte{0x01, 0x02, 0x03}, - CodeVersion: 1, + Nonce: 100, + Balance: big.NewInt(100), + Root: common.HexToHash("deadbeef"), + CodeHash: []byte{0x01, 0x02, 0x03}, + Version: 1, }, { - Nonce: 100, - Balance: big.NewInt(100), - Root: common.HexToHash("deadbeef"), - CodeHash: []byte{0x01, 0x02, 0x03}, - CodeVersion: math.MaxUint64, + Nonce: 100, + Balance: big.NewInt(100), + Root: common.HexToHash("deadbeef"), + CodeHash: []byte{0x01, 0x02, 0x03}, + Version: math.MaxUint64, }, } for _, acct := range accounts { diff --git a/core/vm/contract.go b/core/vm/contract.go index b1b1bf4b71..55363ccf23 100644 --- a/core/vm/contract.go +++ b/core/vm/contract.go @@ -57,9 +57,9 @@ type Contract struct { CodeAddr *common.Address Input []byte - CodeVersion uint64 - Gas uint64 - value *big.Int + Version uint64 + Gas uint64 + value *big.Int } // NewContract returns a new contract environment for the execution of EVM. @@ -174,7 +174,7 @@ func (c *Contract) SetCallCode(addr *common.Address, hash common.Hash, code []by c.Code = code c.CodeHash = hash c.CodeAddr = addr - c.CodeVersion = version + c.Version = version } // SetCodeOptionalHash can be used to provide code, but it's optional to provide hash. @@ -183,5 +183,5 @@ func (c *Contract) SetCodeOptionalHash(addr *common.Address, codeAndHash *codeAn c.Code = codeAndHash.code c.CodeHash = codeAndHash.hash c.CodeAddr = addr - c.CodeVersion = version + c.Version = version } diff --git a/core/vm/evm.go b/core/vm/evm.go index b80ef19bf0..4f13413176 100644 --- a/core/vm/evm.go +++ b/core/vm/evm.go @@ -61,7 +61,7 @@ func run(evm *EVM, contract *Contract, input []byte, readOnly bool) ([]byte, err return RunPrecompiledContract(p, input, contract) } } - interpreters := evm.interpreters[contract.CodeVersion] + interpreters := evm.interpreters[contract.Version] for _, interpreter := range interpreters { if interpreter.CanRun(contract.Code) { if evm.interpreter != interpreter { @@ -239,7 +239,7 @@ func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas // Initialise a new contract and set the code that is to be used by the EVM. // The contract is a scoped environment for this execution context only. contract := NewContract(caller, to, value, gas) - contract.SetCallCode(&addr, evm.StateDB.GetCodeHash(addr), evm.StateDB.GetCode(addr), evm.StateDB.GetCodeVersion(addr)) + contract.SetCallCode(&addr, evm.StateDB.GetCodeHash(addr), evm.StateDB.GetCode(addr), evm.StateDB.GetVersion(addr)) // Even if the account has no code, we need to continue because it might be a precompile start := time.Now() @@ -294,7 +294,7 @@ func (evm *EVM) CallCode(caller ContractRef, addr common.Address, input []byte, // Initialise a new contract and set the code that is to be used by the EVM. // The contract is a scoped environment for this execution context only. contract := NewContract(caller, to, value, gas) - contract.SetCallCode(&addr, evm.StateDB.GetCodeHash(addr), evm.StateDB.GetCode(addr), evm.StateDB.GetCodeVersion(addr)) + contract.SetCallCode(&addr, evm.StateDB.GetCodeHash(addr), evm.StateDB.GetCode(addr), evm.StateDB.GetVersion(addr)) ret, err = run(evm, contract, input, false) if err != nil { @@ -327,7 +327,7 @@ func (evm *EVM) DelegateCall(caller ContractRef, addr common.Address, input []by // Initialise a new contract and make initialise the delegate values contract := NewContract(caller, to, nil, gas).AsDelegate() - contract.SetCallCode(&addr, evm.StateDB.GetCodeHash(addr), evm.StateDB.GetCode(addr), evm.StateDB.GetCodeVersion(addr)) + contract.SetCallCode(&addr, evm.StateDB.GetCodeHash(addr), evm.StateDB.GetCode(addr), evm.StateDB.GetVersion(addr)) ret, err = run(evm, contract, input, false) if err != nil { @@ -359,7 +359,7 @@ func (evm *EVM) StaticCall(caller ContractRef, addr common.Address, input []byte // Initialise a new contract and set the code that is to be used by the EVM. // The contract is a scoped environment for this execution context only. contract := NewContract(caller, to, new(big.Int), gas) - contract.SetCallCode(&addr, evm.StateDB.GetCodeHash(addr), evm.StateDB.GetCode(addr), evm.StateDB.GetCodeVersion(addr)) + contract.SetCallCode(&addr, evm.StateDB.GetCodeHash(addr), evm.StateDB.GetCode(addr), evm.StateDB.GetVersion(addr)) // We do an AddBalance of zero here, just in order to trigger a touch. // This doesn't matter on Mainnet, where all empties are gone at the time of Byzantium, diff --git a/core/vm/instructions.go b/core/vm/instructions.go index f2a189b656..a0181c9337 100644 --- a/core/vm/instructions.go +++ b/core/vm/instructions.go @@ -699,7 +699,7 @@ func opCreate(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memor } contract.UseGas(gas) - res, addr, returnGas, suberr := interpreter.evm.Create(contract, input, gas, value, contract.CodeVersion) + res, addr, returnGas, suberr := interpreter.evm.Create(contract, input, gas, value, contract.Version) // Push item on the stack based on the returned error. If the ruleset is // homestead we must check for CodeStoreOutOfGasError (homestead only // rule) and treat as an error, if the ruleset is frontier we must @@ -732,7 +732,7 @@ func opCreate2(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memo // Apply EIP150 gas -= gas / 64 contract.UseGas(gas) - res, addr, returnGas, suberr := interpreter.evm.Create2(contract, input, gas, endowment, salt, contract.CodeVersion) + res, addr, returnGas, suberr := interpreter.evm.Create2(contract, input, gas, endowment, salt, contract.Version) // Push item on the stack based on the returned error. if suberr != nil { stack.push(interpreter.intPool.getZero()) diff --git a/core/vm/interface.go b/core/vm/interface.go index bb3b37f4d5..b64e1f7e32 100644 --- a/core/vm/interface.go +++ b/core/vm/interface.go @@ -38,7 +38,7 @@ type StateDB interface { GetCode(common.Address) []byte SetCode(common.Address, []byte, uint64) GetCodeSize(common.Address) int - GetCodeVersion(address common.Address) uint64 + GetVersion(address common.Address) uint64 AddRefund(uint64) SubRefund(uint64)