core/state, core/vm: rename field

This commit is contained in:
rjl493456442 2019-07-15 10:54:06 +08:00
parent a8711c035d
commit 8c62b0e500
9 changed files with 64 additions and 64 deletions

View file

@ -29,15 +29,15 @@ import (
// DumpAccount represents an account in the state // DumpAccount represents an account in the state
type DumpAccount struct { type DumpAccount struct {
Balance string `json:"balance"` Balance string `json:"balance"`
Nonce uint64 `json:"nonce"` Nonce uint64 `json:"nonce"`
Root string `json:"root"` Root string `json:"root"`
CodeHash string `json:"codeHash"` CodeHash string `json:"codeHash"`
Code string `json:"code,omitempty"` Code string `json:"code,omitempty"`
CodeVersion uint64 `json:"codeVersion"` Version uint64 `json:"version"`
Storage map[common.Hash]string `json:"storage,omitempty"` Storage map[common.Hash]string `json:"storage,omitempty"`
Address *common.Address `json:"address,omitempty"` // Address only present in iterative (line-by-line) mode 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 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) { func (self iterativeDump) onAccount(addr common.Address, account DumpAccount) {
dumpAccount := &DumpAccount{ dumpAccount := &DumpAccount{
Balance: account.Balance, Balance: account.Balance,
Nonce: account.Nonce, Nonce: account.Nonce,
Root: account.Root, Root: account.Root,
CodeHash: account.CodeHash, CodeHash: account.CodeHash,
Code: account.Code, Code: account.Code,
CodeVersion: account.CodeVersion, Version: account.Version,
Storage: account.Storage, Storage: account.Storage,
SecureKey: account.SecureKey, SecureKey: account.SecureKey,
Address: nil, Address: nil,
} }
if addr != (common.Address{}) { if addr != (common.Address{}) {
dumpAccount.Address = &addr dumpAccount.Address = &addr
@ -100,11 +100,11 @@ func (self *StateDB) dump(c collector, excludeCode, excludeStorage, excludeMissi
addr := common.BytesToAddress(self.trie.GetKey(it.Key)) addr := common.BytesToAddress(self.trie.GetKey(it.Key))
obj := newObject(nil, addr, data) obj := newObject(nil, addr, data)
account := DumpAccount{ account := DumpAccount{
Balance: data.Balance.String(), Balance: data.Balance.String(),
Nonce: data.Nonce, Nonce: data.Nonce,
Root: common.Bytes2Hex(data.Root[:]), Root: common.Bytes2Hex(data.Root[:]),
CodeHash: common.Bytes2Hex(data.CodeHash), CodeHash: common.Bytes2Hex(data.CodeHash),
CodeVersion: data.CodeVersion, Version: data.Version,
} }
if emptyAddress == addr { if emptyAddress == addr {
// Preimage missing // Preimage missing

View file

@ -109,16 +109,16 @@ type storedAccount Account
// Account is ethereum consensus representation of accounts. These objects are // Account is ethereum consensus representation of accounts. These objects are
// stored in the main account trie. // stored in the main account trie.
type Account struct { type Account struct {
Nonce uint64 // The nonce of account. Nonce uint64 // The nonce of account.
Balance *big.Int // The balance of account. Balance *big.Int // The balance of account.
Root common.Hash // Merkle root of the storage trie. Root common.Hash // Merkle root of the storage trie.
CodeHash []byte // The code hash of account. CodeHash []byte // The code hash of account.
CodeVersion uint64 // The version of account code. Version uint64 // The version of account as well as the version of code.
} }
// EncodeRLP implements rlp.Encoder. // EncodeRLP implements rlp.Encoder.
func (a *Account) EncodeRLP(w io.Writer) error { 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, legacyStoredAccount{a.Nonce, a.Balance, a.Root, a.CodeHash})
} }
return rlp.Encode(w, storedAccount(*a)) return rlp.Encode(w, storedAccount(*a))
@ -421,7 +421,7 @@ func (s *stateObject) SetCode(codeHash common.Hash, code []byte, version uint64)
account: &s.address, account: &s.address,
prevhash: s.CodeHash(), prevhash: s.CodeHash(),
prevcode: prevcode, prevcode: prevcode,
version: s.data.CodeVersion, version: s.data.Version,
}) })
s.setCode(codeHash, code, 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) { func (s *stateObject) setCode(codeHash common.Hash, code []byte, version uint64) {
s.code = code s.code = code
s.data.CodeHash = codeHash[:] s.data.CodeHash = codeHash[:]
s.data.CodeVersion = version s.data.Version = version
s.dirtyCode = true s.dirtyCode = true
} }
@ -458,7 +458,7 @@ func (s *stateObject) Nonce() uint64 {
} }
func (s *stateObject) CodeVersion() 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 // Never called, but must be present to allow stateObject to be used

View file

@ -61,14 +61,14 @@ func (s *StateSuite) TestDump(c *checker.C) {
"nonce": 0, "nonce": 0,
"root": "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", "root": "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"codeHash": "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470", "codeHash": "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470",
"codeVersion": 0 "version": 0
}, },
"0x0000000000000000000000000000000000000002": { "0x0000000000000000000000000000000000000002": {
"balance": "44", "balance": "44",
"nonce": 0, "nonce": 0,
"root": "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", "root": "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"codeHash": "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470", "codeHash": "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470",
"codeVersion": 0 "version": 0
}, },
"0x0000000000000000000000000000000000000102": { "0x0000000000000000000000000000000000000102": {
"balance": "0", "balance": "0",
@ -76,7 +76,7 @@ func (s *StateSuite) TestDump(c *checker.C) {
"root": "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421", "root": "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"codeHash": "87874902497a5bb968da31a2998d8f22e949d1ef6214bcdedd8bae24cca4b9e3", "codeHash": "87874902497a5bb968da31a2998d8f22e949d1ef6214bcdedd8bae24cca4b9e3",
"code": "03030303030303", "code": "03030303030303",
"codeVersion": 0 "version": 0
} }
} }
}` }`

View file

@ -278,7 +278,7 @@ func (self *StateDB) GetCodeHash(addr common.Address) common.Hash {
return common.BytesToHash(stateObject.CodeHash()) 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) stateObject := self.getStateObject(addr)
if stateObject == nil { if stateObject == nil {
return 0 return 0

View file

@ -460,25 +460,25 @@ func TestStateObjectDecoding(t *testing.T) {
CodeHash: []byte{0x01, 0x02, 0x03}, CodeHash: []byte{0x01, 0x02, 0x03},
}, },
{ {
Nonce: 100, Nonce: 100,
Balance: big.NewInt(100), Balance: big.NewInt(100),
Root: common.HexToHash("deadbeef"), Root: common.HexToHash("deadbeef"),
CodeHash: []byte{0x01, 0x02, 0x03}, CodeHash: []byte{0x01, 0x02, 0x03},
CodeVersion: 0, Version: 0,
}, },
{ {
Nonce: 100, Nonce: 100,
Balance: big.NewInt(100), Balance: big.NewInt(100),
Root: common.HexToHash("deadbeef"), Root: common.HexToHash("deadbeef"),
CodeHash: []byte{0x01, 0x02, 0x03}, CodeHash: []byte{0x01, 0x02, 0x03},
CodeVersion: 1, Version: 1,
}, },
{ {
Nonce: 100, Nonce: 100,
Balance: big.NewInt(100), Balance: big.NewInt(100),
Root: common.HexToHash("deadbeef"), Root: common.HexToHash("deadbeef"),
CodeHash: []byte{0x01, 0x02, 0x03}, CodeHash: []byte{0x01, 0x02, 0x03},
CodeVersion: math.MaxUint64, Version: math.MaxUint64,
}, },
} }
for _, acct := range accounts { for _, acct := range accounts {

View file

@ -57,9 +57,9 @@ type Contract struct {
CodeAddr *common.Address CodeAddr *common.Address
Input []byte Input []byte
CodeVersion uint64 Version uint64
Gas uint64 Gas uint64
value *big.Int value *big.Int
} }
// NewContract returns a new contract environment for the execution of EVM. // 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.Code = code
c.CodeHash = hash c.CodeHash = hash
c.CodeAddr = addr c.CodeAddr = addr
c.CodeVersion = version c.Version = version
} }
// SetCodeOptionalHash can be used to provide code, but it's optional to provide hash. // 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.Code = codeAndHash.code
c.CodeHash = codeAndHash.hash c.CodeHash = codeAndHash.hash
c.CodeAddr = addr c.CodeAddr = addr
c.CodeVersion = version c.Version = version
} }

View file

@ -61,7 +61,7 @@ func run(evm *EVM, contract *Contract, input []byte, readOnly bool) ([]byte, err
return RunPrecompiledContract(p, input, contract) return RunPrecompiledContract(p, input, contract)
} }
} }
interpreters := evm.interpreters[contract.CodeVersion] interpreters := evm.interpreters[contract.Version]
for _, interpreter := range interpreters { for _, interpreter := range interpreters {
if interpreter.CanRun(contract.Code) { if interpreter.CanRun(contract.Code) {
if evm.interpreter != interpreter { 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. // 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. // The contract is a scoped environment for this execution context only.
contract := NewContract(caller, to, value, gas) 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 // Even if the account has no code, we need to continue because it might be a precompile
start := time.Now() 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. // 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. // The contract is a scoped environment for this execution context only.
contract := NewContract(caller, to, value, gas) 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) ret, err = run(evm, contract, input, false)
if err != nil { 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 // Initialise a new contract and make initialise the delegate values
contract := NewContract(caller, to, nil, gas).AsDelegate() 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) ret, err = run(evm, contract, input, false)
if err != nil { 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. // 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. // The contract is a scoped environment for this execution context only.
contract := NewContract(caller, to, new(big.Int), gas) 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. // 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, // This doesn't matter on Mainnet, where all empties are gone at the time of Byzantium,

View file

@ -699,7 +699,7 @@ func opCreate(pc *uint64, interpreter *EVMInterpreter, contract *Contract, memor
} }
contract.UseGas(gas) 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 // Push item on the stack based on the returned error. If the ruleset is
// homestead we must check for CodeStoreOutOfGasError (homestead only // homestead we must check for CodeStoreOutOfGasError (homestead only
// rule) and treat as an error, if the ruleset is frontier we must // 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 // Apply EIP150
gas -= gas / 64 gas -= gas / 64
contract.UseGas(gas) 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. // Push item on the stack based on the returned error.
if suberr != nil { if suberr != nil {
stack.push(interpreter.intPool.getZero()) stack.push(interpreter.intPool.getZero())

View file

@ -38,7 +38,7 @@ type StateDB interface {
GetCode(common.Address) []byte GetCode(common.Address) []byte
SetCode(common.Address, []byte, uint64) SetCode(common.Address, []byte, uint64)
GetCodeSize(common.Address) int GetCodeSize(common.Address) int
GetCodeVersion(address common.Address) uint64 GetVersion(address common.Address) uint64
AddRefund(uint64) AddRefund(uint64)
SubRefund(uint64) SubRefund(uint64)