mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 06:36:43 +00:00
core/vm: unexported Depth (review change)
This commit is contained in:
parent
64ac1ec1d7
commit
4e777fb7aa
3 changed files with 18 additions and 18 deletions
|
|
@ -67,7 +67,7 @@ type EVM struct {
|
||||||
// StateDB gives access to the underlying state
|
// StateDB gives access to the underlying state
|
||||||
StateDB StateDB
|
StateDB StateDB
|
||||||
// Depth is the current call stack
|
// Depth is the current call stack
|
||||||
Depth int
|
depth int
|
||||||
|
|
||||||
// chainConfig contains information about the current chain
|
// chainConfig contains information about the current chain
|
||||||
chainConfig *params.ChainConfig
|
chainConfig *params.ChainConfig
|
||||||
|
|
@ -113,12 +113,12 @@ func (evm *EVM) init() {
|
||||||
// necessary value transfer required and takes the necessary steps to create accounts and reverses the state in
|
// necessary value transfer required and takes the necessary steps to create accounts and reverses the state in
|
||||||
// case of an execution error or failed value transfer.
|
// case of an execution error or failed value transfer.
|
||||||
func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas, value *big.Int) (ret []byte, err error) {
|
func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas, value *big.Int) (ret []byte, err error) {
|
||||||
if evm.Depth == 0 {
|
if evm.depth == 0 {
|
||||||
evm.init()
|
evm.init()
|
||||||
defer close(evm.quit)
|
defer close(evm.quit)
|
||||||
}
|
}
|
||||||
|
|
||||||
if evm.vmConfig.NoRecursion && evm.Depth > 0 {
|
if evm.vmConfig.NoRecursion && evm.depth > 0 {
|
||||||
caller.ReturnGas(gas)
|
caller.ReturnGas(gas)
|
||||||
|
|
||||||
return nil, nil
|
return nil, nil
|
||||||
|
|
@ -126,7 +126,7 @@ func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas,
|
||||||
|
|
||||||
// Depth check execution. Fail if we're trying to execute above the
|
// Depth check execution. Fail if we're trying to execute above the
|
||||||
// limit.
|
// limit.
|
||||||
if evm.Depth > int(params.CallCreateDepth.Int64()) {
|
if evm.depth > int(params.CallCreateDepth.Int64()) {
|
||||||
caller.ReturnGas(gas)
|
caller.ReturnGas(gas)
|
||||||
|
|
||||||
return nil, ErrDepth
|
return nil, ErrDepth
|
||||||
|
|
@ -178,12 +178,12 @@ func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas,
|
||||||
//
|
//
|
||||||
// CallCode differs from Call in the sense that it executes the given address' code with the caller as context.
|
// CallCode differs from Call in the sense that it executes the given address' code with the caller as context.
|
||||||
func (evm *EVM) CallCode(caller ContractRef, addr common.Address, input []byte, gas, value *big.Int) (ret []byte, err error) {
|
func (evm *EVM) CallCode(caller ContractRef, addr common.Address, input []byte, gas, value *big.Int) (ret []byte, err error) {
|
||||||
if evm.Depth == 0 {
|
if evm.depth == 0 {
|
||||||
evm.init()
|
evm.init()
|
||||||
defer close(evm.quit)
|
defer close(evm.quit)
|
||||||
}
|
}
|
||||||
|
|
||||||
if evm.vmConfig.NoRecursion && evm.Depth > 0 {
|
if evm.vmConfig.NoRecursion && evm.depth > 0 {
|
||||||
caller.ReturnGas(gas)
|
caller.ReturnGas(gas)
|
||||||
|
|
||||||
return nil, nil
|
return nil, nil
|
||||||
|
|
@ -191,7 +191,7 @@ func (evm *EVM) CallCode(caller ContractRef, addr common.Address, input []byte,
|
||||||
|
|
||||||
// Depth check execution. Fail if we're trying to execute above the
|
// Depth check execution. Fail if we're trying to execute above the
|
||||||
// limit.
|
// limit.
|
||||||
if evm.Depth > int(params.CallCreateDepth.Int64()) {
|
if evm.depth > int(params.CallCreateDepth.Int64()) {
|
||||||
caller.ReturnGas(gas)
|
caller.ReturnGas(gas)
|
||||||
|
|
||||||
return nil, ErrDepth
|
return nil, ErrDepth
|
||||||
|
|
@ -229,12 +229,12 @@ func (evm *EVM) CallCode(caller ContractRef, addr common.Address, input []byte,
|
||||||
// DelegateCall differs from CallCode in the sense that it executes the given address' code with the caller as context
|
// DelegateCall differs from CallCode in the sense that it executes the given address' code with the caller as context
|
||||||
// and the caller is set to the caller of the caller.
|
// and the caller is set to the caller of the caller.
|
||||||
func (evm *EVM) DelegateCall(caller ContractRef, addr common.Address, input []byte, gas *big.Int) (ret []byte, err error) {
|
func (evm *EVM) DelegateCall(caller ContractRef, addr common.Address, input []byte, gas *big.Int) (ret []byte, err error) {
|
||||||
if evm.Depth == 0 {
|
if evm.depth == 0 {
|
||||||
evm.init()
|
evm.init()
|
||||||
defer close(evm.quit)
|
defer close(evm.quit)
|
||||||
}
|
}
|
||||||
|
|
||||||
if evm.vmConfig.NoRecursion && evm.Depth > 0 {
|
if evm.vmConfig.NoRecursion && evm.depth > 0 {
|
||||||
caller.ReturnGas(gas)
|
caller.ReturnGas(gas)
|
||||||
|
|
||||||
return nil, nil
|
return nil, nil
|
||||||
|
|
@ -242,7 +242,7 @@ func (evm *EVM) DelegateCall(caller ContractRef, addr common.Address, input []by
|
||||||
|
|
||||||
// Depth check execution. Fail if we're trying to execute above the
|
// Depth check execution. Fail if we're trying to execute above the
|
||||||
// limit.
|
// limit.
|
||||||
if evm.Depth > int(params.CallCreateDepth.Int64()) {
|
if evm.depth > int(params.CallCreateDepth.Int64()) {
|
||||||
caller.ReturnGas(gas)
|
caller.ReturnGas(gas)
|
||||||
return nil, ErrDepth
|
return nil, ErrDepth
|
||||||
}
|
}
|
||||||
|
|
@ -269,12 +269,12 @@ func (evm *EVM) DelegateCall(caller ContractRef, addr common.Address, input []by
|
||||||
|
|
||||||
// Create creates a new contract using code as deployment code.
|
// Create creates a new contract using code as deployment code.
|
||||||
func (evm *EVM) Create(caller ContractRef, code []byte, gas, value *big.Int) (ret []byte, contractAddr common.Address, err error) {
|
func (evm *EVM) Create(caller ContractRef, code []byte, gas, value *big.Int) (ret []byte, contractAddr common.Address, err error) {
|
||||||
if evm.Depth == 0 {
|
if evm.depth == 0 {
|
||||||
evm.init()
|
evm.init()
|
||||||
defer close(evm.quit)
|
defer close(evm.quit)
|
||||||
}
|
}
|
||||||
|
|
||||||
if evm.vmConfig.NoRecursion && evm.Depth > 0 {
|
if evm.vmConfig.NoRecursion && evm.depth > 0 {
|
||||||
caller.ReturnGas(gas)
|
caller.ReturnGas(gas)
|
||||||
|
|
||||||
return nil, common.Address{}, nil
|
return nil, common.Address{}, nil
|
||||||
|
|
@ -282,7 +282,7 @@ func (evm *EVM) Create(caller ContractRef, code []byte, gas, value *big.Int) (re
|
||||||
|
|
||||||
// Depth check execution. Fail if we're trying to execute above the
|
// Depth check execution. Fail if we're trying to execute above the
|
||||||
// limit.
|
// limit.
|
||||||
if evm.Depth > int(params.CallCreateDepth.Int64()) {
|
if evm.depth > int(params.CallCreateDepth.Int64()) {
|
||||||
caller.ReturnGas(gas)
|
caller.ReturnGas(gas)
|
||||||
|
|
||||||
return nil, common.Address{}, ErrDepth
|
return nil, common.Address{}, ErrDepth
|
||||||
|
|
|
||||||
|
|
@ -155,7 +155,7 @@ func (l *StructLogger) CaptureState(env *EVM, pc uint64, op OpCode, gas, cost *b
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// create a new snaptshot of the EVM.
|
// create a new snaptshot of the EVM.
|
||||||
log := StructLog{pc, op, new(big.Int).Set(gas), cost, mem, stck, storage, env.Depth, err}
|
log := StructLog{pc, op, new(big.Int).Set(gas), cost, mem, stck, storage, env.depth, err}
|
||||||
|
|
||||||
l.logs = append(l.logs, log)
|
l.logs = append(l.logs, log)
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
|
|
@ -67,8 +67,8 @@ func NewInterpreter(env *EVM, cfg Config) *Interpreter {
|
||||||
|
|
||||||
// Run loops and evaluates the contract's code with the given input data
|
// Run loops and evaluates the contract's code with the given input data
|
||||||
func (evm *Interpreter) Run(contract *Contract, input []byte) (ret []byte, err error) {
|
func (evm *Interpreter) Run(contract *Contract, input []byte) (ret []byte, err error) {
|
||||||
evm.env.Depth++
|
evm.env.depth++
|
||||||
defer func() { evm.env.Depth-- }()
|
defer func() { evm.env.depth-- }()
|
||||||
|
|
||||||
if contract.CodeAddr != nil {
|
if contract.CodeAddr != nil {
|
||||||
if p := PrecompiledContracts[*contract.CodeAddr]; p != nil {
|
if p := PrecompiledContracts[*contract.CodeAddr]; p != nil {
|
||||||
|
|
@ -100,7 +100,7 @@ func (evm *Interpreter) Run(contract *Contract, input []byte) (ret []byte, err e
|
||||||
// User defer pattern to check for an error and, based on the error being nil or not, use all gas and return.
|
// User defer pattern to check for an error and, based on the error being nil or not, use all gas and return.
|
||||||
defer func() {
|
defer func() {
|
||||||
if err != nil && evm.cfg.Debug {
|
if err != nil && evm.cfg.Debug {
|
||||||
evm.cfg.Tracer.CaptureState(evm.env, pc, op, contract.Gas, cost, mem, stack, contract, evm.env.Depth, err)
|
evm.cfg.Tracer.CaptureState(evm.env, pc, op, contract.Gas, cost, mem, stack, contract, evm.env.depth, err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
|
@ -157,7 +157,7 @@ func (evm *Interpreter) Run(contract *Contract, input []byte) (ret []byte, err e
|
||||||
}
|
}
|
||||||
|
|
||||||
if evm.cfg.Debug {
|
if evm.cfg.Debug {
|
||||||
evm.cfg.Tracer.CaptureState(evm.env, pc, op, contract.Gas, cost, mem, stack, contract, evm.env.Depth, err)
|
evm.cfg.Tracer.CaptureState(evm.env, pc, op, contract.Gas, cost, mem, stack, contract, evm.env.depth, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// execute the operation
|
// execute the operation
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue