Skip to content

Commit

Permalink
[R4R]-{develop}: fix ignore error in NewStateTransition of l2geth (#1295
Browse files Browse the repository at this point in the history
)

* fix ignore error in NewStateTransition of l2geth

* handle error for ApplyMessage

* fix

* fix simulate code
  • Loading branch information
guoshijiang authored Jul 18, 2023
1 parent 1e4099e commit 2cbc722
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
9 changes: 7 additions & 2 deletions l2geth/accounts/abi/bind/backends/simulated.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
"github.com/mantlenetworkio/mantle/l2geth/eth/filters"
"github.com/mantlenetworkio/mantle/l2geth/ethdb"
"github.com/mantlenetworkio/mantle/l2geth/event"
"github.com/mantlenetworkio/mantle/l2geth/log"
"github.com/mantlenetworkio/mantle/l2geth/params"
"github.com/mantlenetworkio/mantle/l2geth/rpc"
)
Expand Down Expand Up @@ -436,8 +437,12 @@ func (b *SimulatedBackend) callContract(ctx context.Context, call ethereum.CallM
// about the transaction and calling mechanisms.
vmenv := vm.NewEVM(evmContext, statedb, b.config, vm.Config{})
gaspool := new(core.GasPool).AddGas(math.MaxUint64)

return core.NewStateTransition(vmenv, msg, gaspool).TransitionDb()
stateTransition, err := core.NewStateTransition(vmenv, msg, gaspool)
if err != nil {
log.Error("new state transition fail", "err", err)
return nil, 0, false, err
}
return stateTransition.TransitionDb()
}

// SendTransaction updates the pending block to include the given transaction.
Expand Down
24 changes: 19 additions & 5 deletions l2geth/core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,22 +127,31 @@ func IntrinsicGas(data []byte, contractCreation, isHomestead bool, isEIP2028 boo
}

// NewStateTransition initialises and returns a new state transition object.
func NewStateTransition(evm *vm.EVM, msg Message, gp *GasPool) *StateTransition {
func NewStateTransition(evm *vm.EVM, msg Message, gp *GasPool) (*StateTransition, error) {
l1Fee := new(big.Int)
daFee := new(big.Int)
var err error
gasPrice := msg.GasPrice()
if rcfg.UsingBVM {
if msg.GasPrice().Cmp(common.Big0) != 0 {
// Compute the L1 fee before the state transition
// so it only has to be read from state one time.
l1Fee, _ = fees.CalculateL1MsgFee(msg, evm.StateDB, nil)
l1Fee, err = fees.CalculateL1MsgFee(msg, evm.StateDB, nil)
if err != nil {
log.Error("calculate l1 message fee fail", "err", err)
return nil, err
}
charge := evm.StateDB.GetState(rcfg.L2GasPriceOracleAddress, rcfg.ChargeSlot).Big()
if charge.Cmp(common.Big0) == 0 {
gasPrice = common.Big0
}
daCharge := evm.StateDB.GetState(rcfg.L2GasPriceOracleAddress, rcfg.DaSwitchSlot).Big()
if daCharge.Cmp(common.Big1) == 0 {
daFee, _ = fees.CalculateDAMsgFee(msg, evm.StateDB, nil)
daFee, err = fees.CalculateDAMsgFee(msg, evm.StateDB, nil)
if err != nil {
log.Error("calculate mantle da message fee fail", "err", err)
return nil, err
}
}
}
}
Expand All @@ -157,7 +166,7 @@ func NewStateTransition(evm *vm.EVM, msg Message, gp *GasPool) *StateTransition
state: evm.StateDB,
l1Fee: l1Fee,
daFee: daFee,
}
}, nil
}

// ApplyMessage computes the new state by applying the given message
Expand All @@ -168,7 +177,12 @@ func NewStateTransition(evm *vm.EVM, msg Message, gp *GasPool) *StateTransition
// indicates a core error meaning that the message would always fail for that particular
// state and would never be accepted within a block.
func ApplyMessage(evm *vm.EVM, msg Message, gp *GasPool) ([]byte, uint64, bool, error) {
return NewStateTransition(evm, msg, gp).TransitionDb()
stateTransition, err := NewStateTransition(evm, msg, gp)
if err == nil {
log.Error("apply message fall", "err", err)
return nil, 0, false, err
}
return stateTransition.TransitionDb()
}

// to returns the recipient of the message.
Expand Down

0 comments on commit 2cbc722

Please sign in to comment.