mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 15:16:43 +00:00
core, core/state, core/vm: review changes
This commit is contained in:
parent
5f4f75cc47
commit
1a02e71376
8 changed files with 33 additions and 54 deletions
|
|
@ -214,8 +214,6 @@ func (self *BlockChain) loadLastState() error {
|
|||
return err
|
||||
}
|
||||
self.stateCache = statedb
|
||||
// XXX Reviewers: what's this for? I need to know if I need to backport this somehow
|
||||
//self.stateCache.GetAccount(common.Address{})
|
||||
|
||||
// Issue a status log for the user
|
||||
headerTd := self.GetTd(currentHeader.Hash(), currentHeader.Number.Uint64())
|
||||
|
|
|
|||
|
|
@ -381,19 +381,3 @@ func (self *stateObject) Nonce() uint64 {
|
|||
func (self *stateObject) Value() *big.Int {
|
||||
panic("Value on stateObject should never be called")
|
||||
}
|
||||
|
||||
func (self *stateObject) ForEachStorage(cb func(key, value common.Hash) bool) {
|
||||
// When iterating over the storage check the cache first
|
||||
for h, value := range self.cachedStorage {
|
||||
cb(h, value)
|
||||
}
|
||||
|
||||
it := self.getTrie(self.db.db).Iterator()
|
||||
for it.Next() {
|
||||
// ignore cached values
|
||||
key := common.BytesToHash(self.trie.GetKey(it.Key))
|
||||
if _, ok := self.cachedStorage[key]; !ok {
|
||||
cb(key, common.BytesToHash(it.Value))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -332,11 +332,10 @@ func (test *snapshotTest) checkEqual(state, checkstate *StateDB) error {
|
|||
checkeq("GetCodeSize", state.GetCodeSize(addr), checkstate.GetCodeSize(addr))
|
||||
// Check storage.
|
||||
if obj := state.getStateObject(addr); obj != nil {
|
||||
obj.ForEachStorage(func(key, val common.Hash) bool {
|
||||
state.ForEachStorage(addr, func(key, val common.Hash) bool {
|
||||
return checkeq("GetState("+key.Hex()+")", val, checkstate.GetState(addr, key))
|
||||
})
|
||||
checkobj := checkstate.getStateObject(addr)
|
||||
checkobj.ForEachStorage(func(key, checkval common.Hash) bool {
|
||||
checkstate.ForEachStorage(addr, func(key, checkval common.Hash) bool {
|
||||
return checkeq("GetState("+key.Hex()+")", state.GetState(addr, key), checkval)
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -142,7 +142,7 @@ func (self *StateTransition) from() vm.AccountRef {
|
|||
if !self.state.Exist(f) {
|
||||
self.state.CreateAccount(f)
|
||||
}
|
||||
return vm.Reference(f)
|
||||
return vm.AccountRef(f)
|
||||
}
|
||||
|
||||
func (self *StateTransition) to() vm.AccountRef {
|
||||
|
|
@ -154,7 +154,7 @@ func (self *StateTransition) to() vm.AccountRef {
|
|||
return vm.AccountRef{} // contract creation
|
||||
}
|
||||
|
||||
reference := vm.Reference(*to)
|
||||
reference := vm.AccountRef(*to)
|
||||
if !self.state.Exist(*to) {
|
||||
self.state.CreateAccount(*to)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,9 +39,6 @@ type AccountRef common.Address
|
|||
// Address casts AccountRef to a Address
|
||||
func (ar AccountRef) Address() common.Address { return (common.Address)(ar) }
|
||||
|
||||
// Reference returns a casted Address to AccountRef
|
||||
func Reference(addr common.Address) AccountRef { return (AccountRef)(addr) }
|
||||
|
||||
// Contract represents an ethereum contract in the state database. It contains
|
||||
// the the contract code, calling arguments. Contract implements ContractRef
|
||||
type Contract struct {
|
||||
|
|
|
|||
|
|
@ -116,7 +116,7 @@ func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas
|
|||
}
|
||||
|
||||
var (
|
||||
to = Reference(addr)
|
||||
to = AccountRef(addr)
|
||||
snapshot = evm.StateDB.Snapshot()
|
||||
)
|
||||
if !evm.StateDB.Exist(addr) {
|
||||
|
|
@ -167,7 +167,7 @@ func (evm *EVM) CallCode(caller ContractRef, addr common.Address, input []byte,
|
|||
|
||||
var (
|
||||
snapshot = evm.StateDB.Snapshot()
|
||||
to = Reference(caller.Address())
|
||||
to = AccountRef(caller.Address())
|
||||
)
|
||||
// initialise a new contract and set the code that is to be used by the
|
||||
// E The contract is a scoped evmironment for this execution context
|
||||
|
|
@ -203,7 +203,7 @@ func (evm *EVM) DelegateCall(caller ContractRef, addr common.Address, input []by
|
|||
|
||||
var (
|
||||
snapshot = evm.StateDB.Snapshot()
|
||||
to = Reference(caller.Address())
|
||||
to = AccountRef(caller.Address())
|
||||
)
|
||||
|
||||
// Iinitialise a new contract and make initialise the delegate values
|
||||
|
|
@ -250,7 +250,7 @@ func (evm *EVM) Create(caller ContractRef, code []byte, gas uint64, value *big.I
|
|||
// initialise a new contract and set the code that is to be used by the
|
||||
// E The contract is a scoped evmironment for this execution context
|
||||
// only.
|
||||
contract := NewContract(caller, Reference(contractAddr), value, gas)
|
||||
contract := NewContract(caller, AccountRef(contractAddr), value, gas)
|
||||
contract.SetCallCode(&contractAddr, crypto.Keccak256Hash(code), code)
|
||||
|
||||
ret, err = evm.interpreter.Run(contract, nil)
|
||||
|
|
|
|||
|
|
@ -67,3 +67,4 @@ func (NoopStateDB) RevertToSnapshot(int) {}
|
|||
func (NoopStateDB) Snapshot() int { return 0 }
|
||||
func (NoopStateDB) AddLog(*types.Log) {}
|
||||
func (NoopStateDB) AddPreimage(common.Hash, []byte) {}
|
||||
func (NoopStateDB) ForEachStorage(common.Address, func(common.Hash, common.Hash) bool) {}
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ func Execute(code, input []byte, cfg *Config) ([]byte, *state.StateDB, error) {
|
|||
var (
|
||||
address = common.StringToAddress("contract")
|
||||
vmenv = NewEnv(cfg, cfg.State)
|
||||
sender = vm.Reference(cfg.Origin)
|
||||
sender = vm.AccountRef(cfg.Origin)
|
||||
)
|
||||
cfg.State.CreateAccount(address)
|
||||
// set the receiver's (the executing contract) code for execution.
|
||||
|
|
@ -137,7 +137,7 @@ func Create(input []byte, cfg *Config) ([]byte, common.Address, error) {
|
|||
}
|
||||
var (
|
||||
vmenv = NewEnv(cfg, cfg.State)
|
||||
sender = vm.Reference(cfg.Origin)
|
||||
sender = vm.AccountRef(cfg.Origin)
|
||||
)
|
||||
|
||||
// Call the code with the given configuration.
|
||||
|
|
|
|||
Loading…
Reference in a new issue