Skip to content

Commit

Permalink
Merge pull request #1790 from OffchainLabs/disable-l1-charging
Browse files Browse the repository at this point in the history
Add disable L1 charging option to eth_call
  • Loading branch information
PlasmaPower authored Aug 2, 2023
2 parents 36ff11b + 1598315 commit f5e7c28
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
5 changes: 4 additions & 1 deletion arbos/tx_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,10 @@ func (p *TxProcessor) GasChargingHook(gasRemaining *uint64) (common.Address, err
poster = p.evm.Context.Coinbase
}

if basefee.Sign() > 0 {
if p.msg.TxRunMode == core.MessageCommitMode {
p.msg.SkipL1Charging = false
}
if basefee.Sign() > 0 && !p.msg.SkipL1Charging {
// Since tips go to the network, and not to the poster, we use the basefee.
// Note, this only determines the amount of gas bought, not the price per gas.

Expand Down
33 changes: 33 additions & 0 deletions system_tests/estimation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,36 @@ func TestComponentEstimate(t *testing.T) {
Fatal(t, l2Estimate, l2Used)
}
}

func TestDisableL1Charging(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

_, node, client := CreateTestL2(t, ctx)
defer node.StopAndWait()
addr := common.HexToAddress("0x12345678")

gasWithL1Charging, err := client.EstimateGas(ctx, ethereum.CallMsg{To: &addr})
Require(t, err)

gasWithoutL1Charging, err := client.EstimateGas(ctx, ethereum.CallMsg{To: &addr, SkipL1Charging: true})
Require(t, err)

if gasWithL1Charging <= gasWithoutL1Charging {
Fatal(t, "SkipL1Charging didn't disable L1 charging")
}
if gasWithoutL1Charging != params.TxGas {
Fatal(t, "Incorrect gas estimate with disabled L1 charging")
}

_, err = client.CallContract(ctx, ethereum.CallMsg{To: &addr, Gas: gasWithL1Charging}, nil)
Require(t, err)

_, err = client.CallContract(ctx, ethereum.CallMsg{To: &addr, Gas: gasWithoutL1Charging}, nil)
if err == nil {
Fatal(t, "CallContract passed with insufficient gas")
}

_, err = client.CallContract(ctx, ethereum.CallMsg{To: &addr, Gas: gasWithoutL1Charging, SkipL1Charging: true}, nil)
Require(t, err)
}

0 comments on commit f5e7c28

Please sign in to comment.