feat: update L2 base fee formula (#951)

* update `CalcBaseFee`

* update `TestCalcBaseFee`

* update `TestStateProcessorErrors`

* bump version

* update threshold
This commit is contained in:
HAOYUatHZ 2024-08-02 10:09:33 +08:00 committed by GitHub
parent b84f4ed6f8
commit ee0410ec10
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 14 additions and 13 deletions

View file

@ -25,7 +25,7 @@ import (
) )
// Protocol-enforced maximum L2 base fee. // Protocol-enforced maximum L2 base fee.
// We would only go above this if L1 base fee hits 2164 Gwei. // We would only go above this if L1 base fee hits 2931 Gwei.
const MaximumL2BaseFee = 10000000000 const MaximumL2BaseFee = 10000000000
// VerifyEip1559Header verifies some header attributes which were changed in EIP-1559, // VerifyEip1559Header verifies some header attributes which were changed in EIP-1559,
@ -55,11 +55,11 @@ func CalcBaseFee(config *params.ChainConfig, parent *types.Header, parentL1BaseF
return big.NewInt(10000000) // 0.01 Gwei return big.NewInt(10000000) // 0.01 Gwei
} }
l2SequencerFee := big.NewInt(1000000) // 0.001 Gwei l2SequencerFee := big.NewInt(1000000) // 0.001 Gwei
provingFee := big.NewInt(47700000) // 0.0477 Gwei provingFee := big.NewInt(33700000) // 0.0337 Gwei
// L1_base_fee * 0.0046 // L1_base_fee * 0.0034
verificationFee := parentL1BaseFee verificationFee := parentL1BaseFee
verificationFee = new(big.Int).Mul(verificationFee, big.NewInt(46)) verificationFee = new(big.Int).Mul(verificationFee, big.NewInt(34))
verificationFee = new(big.Int).Div(verificationFee, big.NewInt(10000)) verificationFee = new(big.Int).Div(verificationFee, big.NewInt(10000))
baseFee := big.NewInt(0) baseFee := big.NewInt(0)

View file

@ -112,12 +112,13 @@ func TestCalcBaseFee(t *testing.T) {
parentL1BaseFee int64 parentL1BaseFee int64
expectedL2BaseFee int64 expectedL2BaseFee int64
}{ }{
{0, 48700000}, {0, 34700000},
{1000000000, 53300000}, {1000000000, 38100000},
{2000000000, 57900000}, {2000000000, 41500000},
{100000000000, 508700000}, {100000000000, 374700000},
{111111111111, 559811111}, {111111111111, 412477777},
{2164000000000, 10000000000}, // cap at max L2 base fee {2164000000000, 7392300000},
{2931000000000, 10000000000}, // cap at max L2 base fee
} }
for i, test := range tests { for i, test := range tests {
if have, want := CalcBaseFee(config(), nil, big.NewInt(test.parentL1BaseFee)), big.NewInt(test.expectedL2BaseFee); have.Cmp(want) != 0 { if have, want := CalcBaseFee(config(), nil, big.NewInt(test.parentL1BaseFee)), big.NewInt(test.expectedL2BaseFee); have.Cmp(want) != 0 {

View file

@ -360,13 +360,13 @@ func TestStateProcessorErrors(t *testing.T) {
txs: []*types.Transaction{ txs: []*types.Transaction{
mkDynamicCreationTx(0, 500000, common.Big0, misc.CalcBaseFee(config, genesis.Header(), parentL1BaseFee), tooBigInitCode[:]), mkDynamicCreationTx(0, 500000, common.Big0, misc.CalcBaseFee(config, genesis.Header(), parentL1BaseFee), tooBigInitCode[:]),
}, },
want: "could not apply tx 0 [0x13f95e090076d99bb91e3c61923b4ddfa270940363b282ac2d17ea07dada4aa4]: max initcode size exceeded: code size 49153 limit 49152", want: "could not apply tx 0 [0x8f780c3573ac61e2d7796f7b447afd0ad753623ed95bc99ef94eb083d9e0d039]: max initcode size exceeded: code size 49153 limit 49152",
}, },
{ // ErrIntrinsicGas: Not enough gas to cover init code { // ErrIntrinsicGas: Not enough gas to cover init code
txs: []*types.Transaction{ txs: []*types.Transaction{
mkDynamicCreationTx(0, 54299, common.Big0, misc.CalcBaseFee(config, genesis.Header(), parentL1BaseFee), smallInitCode[:]), mkDynamicCreationTx(0, 54299, common.Big0, misc.CalcBaseFee(config, genesis.Header(), parentL1BaseFee), smallInitCode[:]),
}, },
want: "could not apply tx 0 [0x74d818187d75665003870481a53dc4bc938fe7ee79d24ebf941ca9042d8ef3ae]: intrinsic gas too low: have 54299, want 54300", want: "could not apply tx 0 [0xbf812bb88c3f53402b6cf5488ac89360595e524b65582b648d1f4ef197690e89]: intrinsic gas too low: have 54299, want 54300",
}, },
} { } {
block := GenerateBadBlock(genesis, ethash.NewFaker(), tt.txs, gspec.Config) block := GenerateBadBlock(genesis, ethash.NewFaker(), tt.txs, gspec.Config)

View file

@ -24,7 +24,7 @@ import (
const ( const (
VersionMajor = 5 // Major version component of the current release VersionMajor = 5 // Major version component of the current release
VersionMinor = 5 // Minor version component of the current release VersionMinor = 5 // Minor version component of the current release
VersionPatch = 20 // Patch version component of the current release VersionPatch = 21 // Patch version component of the current release
VersionMeta = "mainnet" // Version metadata to append to the version string VersionMeta = "mainnet" // Version metadata to append to the version string
) )