From 51dd7c8fb92140e0bbd6c388621709bd70518139 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Garamv=C3=B6lgyi?= Date: Tue, 1 Oct 2024 09:25:20 +0200 Subject: [PATCH 1/5] feat: update L2 base fee formula --- consensus/misc/eip1559.go | 8 ++++---- params/version.go | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/consensus/misc/eip1559.go b/consensus/misc/eip1559.go index f02d5fcd9514..483878fc0e4a 100644 --- a/consensus/misc/eip1559.go +++ b/consensus/misc/eip1559.go @@ -55,12 +55,12 @@ func CalcBaseFee(config *params.ChainConfig, parent *types.Header, parentL1BaseF return big.NewInt(10000000) // 0.01 Gwei } l2SequencerFee := big.NewInt(1000000) // 0.001 Gwei - provingFee := big.NewInt(33700000) // 0.0337 Gwei + provingFee := big.NewInt(38200000) // 0.0382 Gwei - // L1_base_fee * 0.0034 + // L1_base_fee * 0.00017 verificationFee := parentL1BaseFee - verificationFee = new(big.Int).Mul(verificationFee, big.NewInt(34)) - verificationFee = new(big.Int).Div(verificationFee, big.NewInt(10000)) + verificationFee = new(big.Int).Mul(verificationFee, big.NewInt(17)) + verificationFee = new(big.Int).Div(verificationFee, big.NewInt(100000)) baseFee := big.NewInt(0) baseFee.Add(baseFee, l2SequencerFee) diff --git a/params/version.go b/params/version.go index 47191375efc0..91a69450932c 100644 --- a/params/version.go +++ b/params/version.go @@ -24,7 +24,7 @@ import ( const ( VersionMajor = 5 // Major version component of the current release VersionMinor = 7 // Minor version component of the current release - VersionPatch = 22 // Patch version component of the current release + VersionPatch = 23 // Patch version component of the current release VersionMeta = "mainnet" // Version metadata to append to the version string ) From 95a7837dae567f77f866c2c79edede4ece0c2b88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Garamv=C3=B6lgyi?= Date: Tue, 1 Oct 2024 12:55:35 +0200 Subject: [PATCH 2/5] update 1559 unit test --- consensus/misc/eip1559_test.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/consensus/misc/eip1559_test.go b/consensus/misc/eip1559_test.go index 5a8c69101505..3b48c2e58107 100644 --- a/consensus/misc/eip1559_test.go +++ b/consensus/misc/eip1559_test.go @@ -112,13 +112,13 @@ func TestCalcBaseFee(t *testing.T) { parentL1BaseFee int64 expectedL2BaseFee int64 }{ - {0, 34700000}, - {1000000000, 38100000}, - {2000000000, 41500000}, - {100000000000, 374700000}, - {111111111111, 412477777}, - {2164000000000, 7392300000}, - {2931000000000, 10000000000}, // cap at max L2 base fee + {0, 39200000}, + {1000000000, 39370000}, + {2000000000, 39540000}, + {100000000000, 56200000}, + {111111111111, 58088888}, + {2164000000000, 407080000}, + {58592942000000, 10000000000}, // cap at max L2 base fee } for i, test := range tests { if have, want := CalcBaseFee(config(), nil, big.NewInt(test.parentL1BaseFee)), big.NewInt(test.expectedL2BaseFee); have.Cmp(want) != 0 { From 8a7d7ff87d6a9fb5124d72767c9ca24302673752 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Garamv=C3=B6lgyi?= Date: Tue, 1 Oct 2024 12:58:51 +0200 Subject: [PATCH 3/5] use current block's base fee in txpool --- core/tx_pool.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/core/tx_pool.go b/core/tx_pool.go index e7d5062fd523..5c694a97a78e 100644 --- a/core/tx_pool.go +++ b/core/tx_pool.go @@ -28,7 +28,6 @@ import ( "github.com/scroll-tech/go-ethereum/common" "github.com/scroll-tech/go-ethereum/common/prque" - "github.com/scroll-tech/go-ethereum/consensus/misc" "github.com/scroll-tech/go-ethereum/core/rawdb" "github.com/scroll-tech/go-ethereum/core/state" "github.com/scroll-tech/go-ethereum/core/types" @@ -1334,9 +1333,9 @@ func (pool *TxPool) runReorg(done chan struct{}, reset *txpoolResetRequest, dirt if reset != nil { pool.demoteUnexecutables() if reset.newHead != nil && pool.chainconfig.IsCurie(new(big.Int).Add(reset.newHead.Number, big.NewInt(1))) { - l1BaseFee := fees.GetL1BaseFee(pool.currentState) - pendingBaseFee := misc.CalcBaseFee(pool.chainconfig, reset.newHead, l1BaseFee) - pool.priced.SetBaseFee(pendingBaseFee) + // note: we cannot predict the next block's base fee since it is set + // by the sequencer, so we use the current block's base fee instead. + pool.priced.SetBaseFee(reset.newHead.BaseFee) } // Update all accounts to the latest known pending nonce nonces := make(map[common.Address]uint64, len(pool.pending)) From a874fdb0f59bd2c7e350222cbc7381692a3d6804 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Garamv=C3=B6lgyi?= Date: Tue, 1 Oct 2024 13:08:38 +0200 Subject: [PATCH 4/5] fix unit test --- core/state_processor_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/state_processor_test.go b/core/state_processor_test.go index e9d6e426e11b..e565b7062b69 100644 --- a/core/state_processor_test.go +++ b/core/state_processor_test.go @@ -361,13 +361,13 @@ func TestStateProcessorErrors(t *testing.T) { txs: []*types.Transaction{ mkDynamicCreationTx(0, 500000, common.Big0, misc.CalcBaseFee(config, genesis.Header(), parentL1BaseFee), tooBigInitCode[:]), }, - want: "could not apply tx 0 [0x8f780c3573ac61e2d7796f7b447afd0ad753623ed95bc99ef94eb083d9e0d039]: max initcode size exceeded: code size 49153 limit 49152", + want: "could not apply tx 0 [0xa31de6e26bd5ffba0ca91a2bc29fc2eaad6a6cfc5ad9ab6ffb69cac121e0125c]: max initcode size exceeded: code size 49153 limit 49152", }, { // ErrIntrinsicGas: Not enough gas to cover init code txs: []*types.Transaction{ mkDynamicCreationTx(0, 54299, common.Big0, misc.CalcBaseFee(config, genesis.Header(), parentL1BaseFee), smallInitCode[:]), }, - want: "could not apply tx 0 [0xbf812bb88c3f53402b6cf5488ac89360595e524b65582b648d1f4ef197690e89]: intrinsic gas too low: have 54299, want 54300", + want: "could not apply tx 0 [0xf36b7d68cf239f956f7c36be26688a97aaa317ea5f5230d109bb30dbc8598ccb]: intrinsic gas too low: have 54299, want 54300", }, } { block := GenerateBadBlock(genesis, ethash.NewFaker(), tt.txs, gspec.Config) From 7823bdffaf4d628244ddcfe61211198eae438ca0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Garamv=C3=B6lgyi?= Date: Tue, 1 Oct 2024 16:23:23 +0200 Subject: [PATCH 5/5] Revert "use current block's base fee in txpool" This reverts commit 8a7d7ff87d6a9fb5124d72767c9ca24302673752. --- core/tx_pool.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/core/tx_pool.go b/core/tx_pool.go index 5c694a97a78e..e7d5062fd523 100644 --- a/core/tx_pool.go +++ b/core/tx_pool.go @@ -28,6 +28,7 @@ import ( "github.com/scroll-tech/go-ethereum/common" "github.com/scroll-tech/go-ethereum/common/prque" + "github.com/scroll-tech/go-ethereum/consensus/misc" "github.com/scroll-tech/go-ethereum/core/rawdb" "github.com/scroll-tech/go-ethereum/core/state" "github.com/scroll-tech/go-ethereum/core/types" @@ -1333,9 +1334,9 @@ func (pool *TxPool) runReorg(done chan struct{}, reset *txpoolResetRequest, dirt if reset != nil { pool.demoteUnexecutables() if reset.newHead != nil && pool.chainconfig.IsCurie(new(big.Int).Add(reset.newHead.Number, big.NewInt(1))) { - // note: we cannot predict the next block's base fee since it is set - // by the sequencer, so we use the current block's base fee instead. - pool.priced.SetBaseFee(reset.newHead.BaseFee) + l1BaseFee := fees.GetL1BaseFee(pool.currentState) + pendingBaseFee := misc.CalcBaseFee(pool.chainconfig, reset.newHead, l1BaseFee) + pool.priced.SetBaseFee(pendingBaseFee) } // Update all accounts to the latest known pending nonce nonces := make(map[common.Address]uint64, len(pool.pending))