From af09fd042746d9514e099b1964aa80940f3a18d7 Mon Sep 17 00:00:00 2001 From: pcw109550 Date: Mon, 27 May 2024 16:34:26 +0900 Subject: [PATCH 1/2] Refactor l1cost for txpool and tests --- erigon-lib/opstack/rollup_cost.go | 160 ++++++++---------- erigon-lib/opstack/rollup_cost_test.go | 4 +- erigon-lib/txpool/pool.go | 145 +++++++++++++++- erigon-lib/txpool/pool_fuzz_test.go | 4 +- erigon-lib/txpool/pool_test.go | 20 +-- .../txpool/txpooluitl/all_components.go | 9 +- turbo/jsonrpc/eth_receipts_test.go | 4 +- turbo/stages/mock/mock_sentry.go | 2 +- 8 files changed, 237 insertions(+), 111 deletions(-) diff --git a/erigon-lib/opstack/rollup_cost.go b/erigon-lib/opstack/rollup_cost.go index 6592b4369fb..262dd24874a 100644 --- a/erigon-lib/opstack/rollup_cost.go +++ b/erigon-lib/opstack/rollup_cost.go @@ -47,8 +47,8 @@ const ( // four. scalarSectionStart = 32 - BaseFeeScalarSlotOffset - 4 - LegacyL1InfoBytes = 4 + 32*8 - EcotoneL1InfoBytes = 164 + PreEcotoneL1InfoBytes = 4 + 32*8 + PostEcotoneL1InfoBytes = 164 ) func init() { @@ -116,7 +116,7 @@ func NewL1CostFunc(config *chain.Config, statedb StateGetter) L1CostFunc { var cachedFunc l1CostFunc selectFunc := func(blockTime uint64) l1CostFunc { if !config.IsOptimismEcotone(blockTime) { - return newL1CostFuncBedrock(config, statedb, blockTime) + return newL1CostFuncPreEcotone(config, statedb, blockTime) } // Note: the various state variables below are not initialized from the DB until this @@ -136,8 +136,8 @@ func NewL1CostFunc(config *chain.Config, statedb StateGetter) L1CostFunc { firstEcotoneBlock := l1BlobBaseFee.BitLen() == 0 && bytes.Equal(emptyScalars, l1FeeScalars[scalarSectionStart:scalarSectionStart+8]) if firstEcotoneBlock { - log.Info("using bedrock l1 cost func for first Ecotone block", "time", blockTime) - return newL1CostFuncBedrock(config, statedb, blockTime) + log.Info("using pre-ecotone l1 cost func for first Ecotone block", "time", blockTime) + return newL1CostFuncPreEcotone(config, statedb, blockTime) } l1BaseFeeScalar, l1BlobBaseFeeScalar := extractEcotoneFeeParams(l1FeeScalars[:]) @@ -166,20 +166,20 @@ func NewL1CostFunc(config *chain.Config, statedb StateGetter) L1CostFunc { } } -// newL1CostFuncBedrock returns an L1 cost function suitable for Bedrock, Regolith, and the first +// newL1CostFuncPreEcotone returns an L1 cost function suitable for Bedrock, Regolith, and the first // block only of the Ecotone upgrade. -func newL1CostFuncBedrock(config *chain.Config, statedb StateGetter, blockTime uint64) l1CostFunc { +func newL1CostFuncPreEcotone(config *chain.Config, statedb StateGetter, blockTime uint64) l1CostFunc { var l1BaseFee, overhead, scalar uint256.Int statedb.GetState(L1BlockAddr, &L1BaseFeeSlot, &l1BaseFee) statedb.GetState(L1BlockAddr, &OverheadSlot, &overhead) statedb.GetState(L1BlockAddr, &ScalarSlot, &scalar) isRegolith := config.IsRegolith(blockTime) - return newL1CostFuncBedrockHelper(&l1BaseFee, &overhead, &scalar, isRegolith) + return newL1CostFuncPreEcotoneHelper(&l1BaseFee, &overhead, &scalar, isRegolith) } -// newL1CostFuncBedrockHelper is lower level version of newL1CostFuncBedrock that expects already +// newL1CostFuncPreEcotoneHelper is lower level version of newL1CostFuncPreEcotone that expects already // extracted parameters -func newL1CostFuncBedrockHelper(l1BaseFee, overhead, scalar *uint256.Int, isRegolith bool) l1CostFunc { +func newL1CostFuncPreEcotoneHelper(l1BaseFee, overhead, scalar *uint256.Int, isRegolith bool) l1CostFunc { return func(rollupCostData types.RollupCostData) (fee, gasUsed *uint256.Int) { if rollupCostData == (types.RollupCostData{}) { return nil, nil // Do not charge if there is no rollup cost-data (e.g. RPC call or deposit) @@ -192,7 +192,7 @@ func newL1CostFuncBedrockHelper(l1BaseFee, overhead, scalar *uint256.Int, isRego } gasWithOverhead := uint256.NewInt(gas) gasWithOverhead.Add(gasWithOverhead, overhead) - l1Cost := l1CostHelper(gasWithOverhead, l1BaseFee, scalar) + l1Cost := l1CostPreEcotoneHelper(gasWithOverhead, l1BaseFee, scalar) return l1Cost, gasWithOverhead } } @@ -261,17 +261,25 @@ func ExtractL1GasParams(config *chain.Config, time uint64, data []byte) (gasPara return extractL1GasParamsPreEcotone(config, time, data) } -func extractL1GasParamsPreEcotone(config *chain.Config, time uint64, data []byte) (gasParams, error) { +func extractL1InfoPreEcotone(data []byte) (l1BaseFee, overhead, scalar *uint256.Int, feeScalar *big.Float, err error) { // data consists of func selector followed by 7 ABI-encoded parameters (32 bytes each) - if len(data) < 4+32*8 { - return gasParams{}, fmt.Errorf("expected at least %d L1 info bytes, got %d", 4+32*8, len(data)) + if len(data) < PreEcotoneL1InfoBytes { + return nil, nil, nil, nil, fmt.Errorf("expected at least %d L1 info bytes, got %d", PreEcotoneL1InfoBytes, len(data)) + } + data = data[4:] // trim function selector + l1BaseFee = new(uint256.Int).SetBytes(data[32*2 : 32*3]) // arg index 2 + overhead = new(uint256.Int).SetBytes(data[32*6 : 32*7]) // arg index 6 + scalar = new(uint256.Int).SetBytes(data[32*7 : 32*8]) // arg index 7 + feeScalar = intToScaledFloat(scalar) // legacy: format fee scalar as big Float + return +} + +func extractL1GasParamsPreEcotone(config *chain.Config, time uint64, data []byte) (gasParams, error) { + l1BaseFee, overhead, scalar, feeScalar, err := extractL1InfoPreEcotone(data) + if err != nil { + return gasParams{}, err } - data = data[4:] // trim function selector - l1BaseFee := new(uint256.Int).SetBytes(data[32*2 : 32*3]) // arg index 2 - overhead := new(uint256.Int).SetBytes(data[32*6 : 32*7]) // arg index 6 - scalar := new(uint256.Int).SetBytes(data[32*7 : 32*8]) // arg index 7 - feeScalar := intToScaledFloat(scalar) // legacy: format fee scalar as big Float - costFunc := newL1CostFuncBedrockHelper(l1BaseFee, overhead, scalar, config.IsRegolith(time)) + costFunc := newL1CostFuncPreEcotoneHelper(l1BaseFee, overhead, scalar, config.IsRegolith(time)) return gasParams{ L1BaseFee: l1BaseFee, CostFunc: costFunc, @@ -279,11 +287,9 @@ func extractL1GasParamsPreEcotone(config *chain.Config, time uint64, data []byte }, nil } -// extractL1GasParamsPostEcotone extracts the gas parameters necessary to compute gas from L1 attribute -// info calldata after the Ecotone upgrade, but not for the very first Ecotone block. -func extractL1GasParamsPostEcotone(data []byte) (gasParams, error) { - if len(data) != EcotoneL1InfoBytes { - return gasParams{}, fmt.Errorf("expected 164 L1 info bytes, got %d", len(data)) +func extractL1InfoPostEcotone(data []byte) (l1BaseFee, l1BlobBaseFee *uint256.Int, l1BaseFeeScalar, l1BlobBaseFeeScalar uint32, err error) { + if len(data) != PostEcotoneL1InfoBytes { + return nil, nil, 0, 0, fmt.Errorf("expected 164 L1 info bytes, got %d", len(data)) } // data layout assumed for Ecotone: // offset type varname @@ -297,10 +303,20 @@ func extractL1GasParamsPostEcotone(data []byte) (gasParams, error) { // 68 uint256 _blobBaseFee, // 100 bytes32 _hash, // 132 bytes32 _batcherHash, - l1BaseFee := new(uint256.Int).SetBytes(data[36:68]) - l1BlobBaseFee := new(uint256.Int).SetBytes(data[68:100]) - l1BaseFeeScalar := binary.BigEndian.Uint32(data[4:8]) - l1BlobBaseFeeScalar := binary.BigEndian.Uint32(data[8:12]) + l1BaseFee = new(uint256.Int).SetBytes(data[36:68]) + l1BlobBaseFee = new(uint256.Int).SetBytes(data[68:100]) + l1BaseFeeScalar = binary.BigEndian.Uint32(data[4:8]) + l1BlobBaseFeeScalar = binary.BigEndian.Uint32(data[8:12]) + return +} + +// extractL1GasParamsPostEcotone extracts the gas parameters necessary to compute gas from L1 attribute +// info calldata after the Ecotone upgrade, but not for the very first Ecotone block. +func extractL1GasParamsPostEcotone(data []byte) (gasParams, error) { + l1BaseFee, l1BlobBaseFee, l1BaseFeeScalar, l1BlobBaseFeeScalar, err := extractL1InfoPostEcotone(data) + if err != nil { + return gasParams{}, err + } return gasParams{ L1BaseFee: l1BaseFee, L1BlobBaseFee: l1BlobBaseFee, @@ -325,77 +341,49 @@ func intToScaledFloat(scalar *uint256.Int) *big.Float { return new(big.Float).Quo(fscalar, fdivisor) } -func extractL1GasParamsLegacy(isRegolith bool, data []byte) (l1BaseFee *uint256.Int, costFunc l1CostFunc, feeScalar *big.Float, err error) { - // data consists of func selector followed by 7 ABI-encoded parameters (32 bytes each) - if len(data) < LegacyL1InfoBytes { - return nil, nil, nil, fmt.Errorf("expected at least %d L1 info bytes, got %d", LegacyL1InfoBytes, len(data)) - } - data = data[4:] // trim function selector - l1BaseFee = new(uint256.Int).SetBytes(data[32*2 : 32*3]) // arg index 2 - overhead := new(uint256.Int).SetBytes(data[32*6 : 32*7]) // arg index 6 - scalar := new(uint256.Int).SetBytes(data[32*7 : 32*8]) // arg index 7 - fscalar := new(big.Float).SetInt(scalar.ToBig()) // legacy: format fee scalar as big Float - fdivisor := new(big.Float).SetUint64(1_000_000) // 10**6, i.e. 6 decimals - feeScalar = new(big.Float).Quo(fscalar, fdivisor) - costFunc = newL1CostFuncBedrockHelper(l1BaseFee, overhead, scalar, isRegolith) - return l1BaseFee, costFunc, feeScalar, nil -} - -// extractEcotoneL1GasParams extracts the gas parameters necessary to compute gas from L1 attribute -// info calldata after the Ecotone upgrade, but not for the very first Ecotone block. -func extractL1GasParamsEcotone(data []byte) (l1BaseFee *uint256.Int, costFunc l1CostFunc, err error) { - if len(data) != EcotoneL1InfoBytes { - return nil, nil, fmt.Errorf("expected 164 L1 info bytes, got %d", len(data)) - } - // data layout assumed for Ecotone: - // offset type varname - // 0 - // 4 uint32 _baseFeeScalar - // 8 uint32 _blobBaseFeeScalar - // 12 uint64 _sequenceNumber, - // 20 uint64 _timestamp, - // 28 uint64 _l1BlockNumber - // 36 uint256 _baseFee, - // 68 uint256 _blobBaseFee, - // 100 bytes32 _hash, - // 132 bytes32 _batcherHash, - l1BaseFee = new(uint256.Int).SetBytes(data[36:68]) - l1BlobBaseFee := new(uint256.Int).SetBytes(data[68:100]) - l1BaseFeeScalar := new(uint256.Int).SetBytes(data[4:8]) - l1BlobBaseFeeScalar := new(uint256.Int).SetBytes(data[8:12]) - costFunc = newL1CostFuncEcotone(l1BaseFee, l1BlobBaseFee, l1BaseFeeScalar, l1BlobBaseFeeScalar) - return -} - -// L1Cost computes the the data availability fee for transactions in blocks prior to the Ecotone +// L1CostPreEcotone computes the the data availability fee for transactions in blocks prior to the Ecotone // upgrade. It is used by e2e tests so must remain exported. -func L1Cost(rollupDataGas uint64, l1BaseFee, overhead, scalar *uint256.Int) *uint256.Int { +func L1CostPreEcotone(rollupDataGas uint64, l1BaseFee, overhead, scalar *uint256.Int) *uint256.Int { l1GasUsed := uint256.NewInt(rollupDataGas) l1GasUsed.Add(l1GasUsed, overhead) - return l1CostHelper(l1GasUsed, l1BaseFee, scalar) + return l1CostPreEcotoneHelper(l1GasUsed, l1BaseFee, scalar) } -func l1CostHelper(gasWithOverhead, l1BaseFee, scalar *uint256.Int) *uint256.Int { +func l1CostPreEcotoneHelper(gasWithOverhead, l1BaseFee, scalar *uint256.Int) *uint256.Int { fee := new(uint256.Int).Set(gasWithOverhead) fee.Mul(fee, l1BaseFee).Mul(fee, scalar).Div(fee, oneMillion) return fee } -func L1CostFnForTxPool(data []byte) (types.L1CostFn, error) { - var costFunc l1CostFunc - var err error - if len(data) == EcotoneL1InfoBytes { - _, costFunc, err = extractL1GasParamsEcotone(data) +func L1CostFnForTxPool(data []byte, isRegolith, isEcotone, isFjord bool) (types.L1CostFn, error) { + var costFunc l1CostFunc = nil + if isEcotone && len(data) >= 4 && !bytes.Equal(data[0:4], BedrockL1AttributesSelector) { + l1BaseFee, l1BlobBaseFee, l1BaseFeeScalar, l1BlobBaseFeeScalar, err := extractL1InfoPostEcotone(data) if err != nil { - return nil, err + return nil, fmt.Errorf("L1CostFnForTxPool error: %w", err) + } + if isFjord { + costFunc = NewL1CostFuncFjord( + l1BaseFee, + l1BlobBaseFee, + new(uint256.Int).SetUint64(uint64(l1BaseFeeScalar)), + new(uint256.Int).SetUint64(uint64(l1BlobBaseFeeScalar)), + ) + } else { + costFunc = newL1CostFuncEcotone( + l1BaseFee, + l1BlobBaseFee, + new(uint256.Int).SetUint64(uint64(l1BaseFeeScalar)), + new(uint256.Int).SetUint64(uint64(l1BlobBaseFeeScalar)), + ) } - } else { - // This method is used for txpool that is needed for OP sequencer. - // Assume that isRegolith will be always true for new block. - _, costFunc, _, err = extractL1GasParamsLegacy(true, data) + } + if costFunc != nil { + l1BaseFee, overhead, scalar, _, err := extractL1InfoPreEcotone(data) if err != nil { - return nil, err + return nil, fmt.Errorf("L1CostFnForTxPool error: %w", err) } + costFunc = newL1CostFuncPreEcotoneHelper(l1BaseFee, overhead, scalar, isRegolith) } return func(tx *types.TxSlot) *uint256.Int { fee, _ := costFunc(tx.RollupCostData) diff --git a/erigon-lib/opstack/rollup_cost_test.go b/erigon-lib/opstack/rollup_cost_test.go index ad606bb6688..d8bf26da869 100644 --- a/erigon-lib/opstack/rollup_cost_test.go +++ b/erigon-lib/opstack/rollup_cost_test.go @@ -48,8 +48,8 @@ var ( ) func TestBedrockL1CostFunc(t *testing.T) { - costFunc0 := newL1CostFuncBedrockHelper(basefee, overhead, scalar, false /*isRegolith*/) - costFunc1 := newL1CostFuncBedrockHelper(basefee, overhead, scalar, true) + costFunc0 := newL1CostFuncPreEcotoneHelper(basefee, overhead, scalar, false /*isRegolith*/) + costFunc1 := newL1CostFuncPreEcotoneHelper(basefee, overhead, scalar, true) c0, g0 := costFunc0(emptyTxRollupCostData) // pre-Regolith c1, g1 := costFunc1(emptyTxRollupCostData) diff --git a/erigon-lib/txpool/pool.go b/erigon-lib/txpool/pool.go index 40bfcfefd8f..45f4fa60e83 100644 --- a/erigon-lib/txpool/pool.go +++ b/erigon-lib/txpool/pool.go @@ -236,7 +236,15 @@ type TxPool struct { feeCalculator FeeCalculator logger log.Logger - l1Cost types.L1CostFn + l1Cost types.L1CostFn + regolithTime *uint64 + isPostRegolith atomic.Bool + canyonTime *uint64 + isPostCanyon atomic.Bool + ecotoneTime *uint64 + isPostEcotone atomic.Bool + fjordTime *uint64 + isPostFjord atomic.Bool } type FeeCalculator interface { @@ -244,8 +252,9 @@ type FeeCalculator interface { } func New(newTxs chan types.Announcements, coreDB kv.RoDB, cfg txpoolcfg.Config, cache kvcache.Cache, - chainID uint256.Int, shanghaiTime, agraBlock, cancunTime *big.Int, maxBlobsPerBlock uint64, - feeCalculator FeeCalculator, logger log.Logger, + chainID uint256.Int, shanghaiTime, agraBlock, cancunTime *big.Int, + regolithTime, canyonTime, ecotoneTime, fjordTime *big.Int, + maxBlobsPerBlock uint64, feeCalculator FeeCalculator, logger log.Logger, ) (*TxPool, error) { localsHistory, err := simplelru.NewLRU[string, struct{}](10_000, nil) if err != nil { @@ -317,10 +326,32 @@ func New(newTxs chan types.Announcements, coreDB kv.RoDB, cfg txpoolcfg.Config, res.cancunTime = &cancunTimeU64 } + if regolithTime != nil { + if !regolithTime.IsUint64() { + return nil, errors.New("regolithTime overflow") + } + regolithTimeU64 := regolithTime.Uint64() + res.regolithTime = ®olithTimeU64 + } + if ecotoneTime != nil { + if !ecotoneTime.IsUint64() { + return nil, errors.New("ecotoneTime overflow") + } + ecotoneTimeU64 := ecotoneTime.Uint64() + res.ecotoneTime = &ecotoneTimeU64 + } + if fjordTime != nil { + if !fjordTime.IsUint64() { + return nil, errors.New("fjordTime overflow") + } + fjordTimeU64 := fjordTime.Uint64() + res.fjordTime = &fjordTimeU64 + } + return res, nil } -func RawRLPTxToOptimismL1CostFn(payload []byte) (types.L1CostFn, error) { +func RawRLPTxToOptimismL1CostFn(payload []byte, isRegolith, isEcotone, isFjord bool) (types.L1CostFn, error) { // skip prefix byte if len(payload) == 0 { return nil, fmt.Errorf("empty tx payload") @@ -367,7 +398,7 @@ func RawRLPTxToOptimismL1CostFn(payload []byte) (types.L1CostFn, error) { return nil, fmt.Errorf("failed to read tx data entry rlp prefix: %w", err) } txCalldata := payload[dataPos : dataPos+dataLen] - return opstack.L1CostFnForTxPool(txCalldata) + return opstack.L1CostFnForTxPool(txCalldata, isRegolith, isEcotone, isFjord) } func (p *TxPool) Start(ctx context.Context, db kv.RwDB) error { @@ -448,7 +479,7 @@ func (p *TxPool) OnNewBlock(ctx context.Context, stateChanges *remote.StateChang if p.cfg.Optimism { lastChangeBatch := stateChanges.ChangeBatch[len(stateChanges.ChangeBatch)-1] if len(lastChangeBatch.Txs) > 0 { - l1CostFn, err := RawRLPTxToOptimismL1CostFn(lastChangeBatch.Txs[0]) + l1CostFn, err := RawRLPTxToOptimismL1CostFn(lastChangeBatch.Txs[0], p.isRegolith(), p.isEcotone(), p.isFjord()) if err == nil { p.l1Cost = l1CostFn } else { @@ -783,7 +814,7 @@ func (p *TxPool) best(n uint16, txs *types.TxsRlp, tx kv.Tx, onTopOf, availableG best := p.pending.best - isShanghai := p.isShanghai() || p.isAgra() + isShanghai := p.isShanghai() || p.isAgra() || p.isCanyon() txs.Resize(uint(cmp.Min(int(n), len(best.ms)))) var toRemove []*metaTx @@ -1134,6 +1165,106 @@ func (p *TxPool) isCancun() bool { return activated } +func (p *TxPool) isRegolith() bool { + // once this flag has been set for the first time we no longer need to check the timestamp + set := p.isPostRegolith.Load() + if set { + return true + } + if p.regolithTime == nil { + return false + } + regolithTime := *p.regolithTime + + // a zero here means Cancun is always active + if regolithTime == 0 { + p.isPostRegolith.Swap(true) + return true + } + + now := time.Now().Unix() + activated := uint64(now) >= regolithTime + if activated { + p.isPostRegolith.Swap(true) + } + return activated +} + +func (p *TxPool) isCanyon() bool { + // once this flag has been set for the first time we no longer need to check the timestamp + set := p.isPostCanyon.Load() + if set { + return true + } + if p.canyonTime == nil { + return false + } + canyonTime := *p.canyonTime + + // a zero here means Cancun is always active + if canyonTime == 0 { + p.isPostCanyon.Swap(true) + return true + } + + now := time.Now().Unix() + activated := uint64(now) >= canyonTime + if activated { + p.isPostCanyon.Swap(true) + } + return activated +} + +func (p *TxPool) isEcotone() bool { + // once this flag has been set for the first time we no longer need to check the timestamp + set := p.isPostEcotone.Load() + if set { + return true + } + if p.ecotoneTime == nil { + return false + } + ecotoneTime := *p.ecotoneTime + + // a zero here means Cancun is always active + if ecotoneTime == 0 { + p.isPostEcotone.Swap(true) + return true + } + + now := time.Now().Unix() + activated := uint64(now) >= ecotoneTime + if activated { + p.isPostEcotone.Swap(true) + } + return activated +} + +func (p *TxPool) isFjord() bool { + // once this flag has been set for the first time we no longer need to check the timestamp + set := p.isPostFjord.Load() + if set { + return true + } + if p.fjordTime == nil { + return false + } + fjordTime := *p.fjordTime + + // a zero here means Cancun is always active + if fjordTime == 0 { + p.isPostFjord.Swap(true) + return true + } + + now := time.Now().Unix() + activated := uint64(now) >= fjordTime + if activated { + p.isPostFjord.Swap(true) + } + return activated +} + // Check that the serialized txn should not exceed a certain max size func (p *TxPool) ValidateSerializedTxn(serializedTxn []byte) error { const ( diff --git a/erigon-lib/txpool/pool_fuzz_test.go b/erigon-lib/txpool/pool_fuzz_test.go index 54b1beb0238..e840f3b079d 100644 --- a/erigon-lib/txpool/pool_fuzz_test.go +++ b/erigon-lib/txpool/pool_fuzz_test.go @@ -314,7 +314,7 @@ func FuzzOnNewBlocks(f *testing.F) { cfg := txpoolcfg.DefaultConfig sendersCache := kvcache.New(kvcache.DefaultCoherentConfig) - pool, err := New(ch, coreDB, cfg, sendersCache, *u256.N1, nil, nil, nil, fixedgas.DefaultMaxBlobsPerBlock, nil, log.New()) + pool, err := New(ch, coreDB, cfg, sendersCache, *u256.N1, nil, nil, nil, nil, nil, nil, nil, fixedgas.DefaultMaxBlobsPerBlock, nil, log.New()) assert.NoError(err) err = pool.Start(ctx, db) @@ -540,7 +540,7 @@ func FuzzOnNewBlocks(f *testing.F) { check(p2pReceived, types.TxSlots{}, "after_flush") checkNotify(p2pReceived, types.TxSlots{}, "after_flush") - p2, err := New(ch, coreDB, txpoolcfg.DefaultConfig, sendersCache, *u256.N1, nil, nil, nil, fixedgas.DefaultMaxBlobsPerBlock, nil, log.New()) + p2, err := New(ch, coreDB, txpoolcfg.DefaultConfig, sendersCache, *u256.N1, nil, nil, nil, nil, nil, nil, nil, fixedgas.DefaultMaxBlobsPerBlock, nil, log.New()) assert.NoError(err) p2.senders = pool.senders // senders are not persisted diff --git a/erigon-lib/txpool/pool_test.go b/erigon-lib/txpool/pool_test.go index c2b369c019a..c36f2640d02 100644 --- a/erigon-lib/txpool/pool_test.go +++ b/erigon-lib/txpool/pool_test.go @@ -53,7 +53,7 @@ func TestNonceFromAddress(t *testing.T) { cfg := txpoolcfg.DefaultConfig sendersCache := kvcache.New(kvcache.DefaultCoherentConfig) - pool, err := New(ch, coreDB, cfg, sendersCache, *u256.N1, nil, nil, nil, fixedgas.DefaultMaxBlobsPerBlock, nil, log.New()) + pool, err := New(ch, coreDB, cfg, sendersCache, *u256.N1, nil, nil, nil, nil, nil, nil, nil, fixedgas.DefaultMaxBlobsPerBlock, nil, log.New()) assert.NoError(err) require.True(pool != nil) ctx := context.Background() @@ -173,7 +173,7 @@ func TestReplaceWithHigherFee(t *testing.T) { cfg := txpoolcfg.DefaultConfig sendersCache := kvcache.New(kvcache.DefaultCoherentConfig) - pool, err := New(ch, coreDB, cfg, sendersCache, *u256.N1, nil, nil, nil, fixedgas.DefaultMaxBlobsPerBlock, nil, log.New()) + pool, err := New(ch, coreDB, cfg, sendersCache, *u256.N1, nil, nil, nil, nil, nil, nil, nil, fixedgas.DefaultMaxBlobsPerBlock, nil, log.New()) assert.NoError(err) require.NotEqual(nil, pool) ctx := context.Background() @@ -290,7 +290,7 @@ func TestReverseNonces(t *testing.T) { cfg := txpoolcfg.DefaultConfig sendersCache := kvcache.New(kvcache.DefaultCoherentConfig) - pool, err := New(ch, coreDB, cfg, sendersCache, *u256.N1, nil, nil, nil, fixedgas.DefaultMaxBlobsPerBlock, nil, log.New()) + pool, err := New(ch, coreDB, cfg, sendersCache, *u256.N1, nil, nil, nil, nil, nil, nil, nil, fixedgas.DefaultMaxBlobsPerBlock, nil, log.New()) assert.NoError(err) require.True(pool != nil) ctx := context.Background() @@ -417,7 +417,7 @@ func TestTxPoke(t *testing.T) { cfg := txpoolcfg.DefaultConfig sendersCache := kvcache.New(kvcache.DefaultCoherentConfig) - pool, err := New(ch, coreDB, cfg, sendersCache, *u256.N1, nil, nil, nil, fixedgas.DefaultMaxBlobsPerBlock, nil, log.New()) + pool, err := New(ch, coreDB, cfg, sendersCache, *u256.N1, nil, nil, nil, nil, nil, nil, nil, fixedgas.DefaultMaxBlobsPerBlock, nil, log.New()) assert.NoError(err) require.True(pool != nil) ctx := context.Background() @@ -682,7 +682,7 @@ func TestShanghaiValidateTx(t *testing.T) { } cache := &kvcache.DummyCache{} - pool, err := New(ch, coreDB, cfg, cache, *u256.N1, shanghaiTime, nil /* agraBlock */, nil /* cancunTime */, fixedgas.DefaultMaxBlobsPerBlock, nil, logger) + pool, err := New(ch, coreDB, cfg, cache, *u256.N1, shanghaiTime, nil /* agraBlock */, nil /* cancunTime */, nil, nil, nil, nil, fixedgas.DefaultMaxBlobsPerBlock, nil, logger) asrt.NoError(err) ctx := context.Background() tx, err := coreDB.BeginRw(ctx) @@ -728,7 +728,7 @@ func TestBlobTxReplacement(t *testing.T) { db, coreDB := memdb.NewTestPoolDB(t), memdb.NewTestDB(t) cfg := txpoolcfg.DefaultConfig sendersCache := kvcache.New(kvcache.DefaultCoherentConfig) - pool, err := New(ch, coreDB, cfg, sendersCache, *u256.N1, common.Big0, nil, common.Big0, fixedgas.DefaultMaxBlobsPerBlock, nil, log.New()) + pool, err := New(ch, coreDB, cfg, sendersCache, *u256.N1, common.Big0, nil, common.Big0, nil, nil, nil, nil, fixedgas.DefaultMaxBlobsPerBlock, nil, log.New()) assert.NoError(err) require.True(pool != nil) ctx := context.Background() @@ -944,7 +944,7 @@ func TestDepositTxValidateTx(t *testing.T) { shanghaiTime := big.NewInt(0) cache := &kvcache.DummyCache{} - pool, err := New(ch, coreDB, cfg, cache, *u256.N1, shanghaiTime, big.NewInt(0), nil, fixedgas.DefaultMaxBlobsPerBlock, nil, logger) + pool, err := New(ch, coreDB, cfg, cache, *u256.N1, shanghaiTime, big.NewInt(0), nil, nil, nil, nil, nil, fixedgas.DefaultMaxBlobsPerBlock, nil, logger) asrt.NoError(err) ctx := context.Background() tx, err := coreDB.BeginRw(ctx) @@ -994,7 +994,7 @@ func TestDropRemoteAtNoGossip(t *testing.T) { logger := log.New() sendersCache := kvcache.New(kvcache.DefaultCoherentConfig) - txPool, err := New(ch, coreDB, cfg, sendersCache, *u256.N1, big.NewInt(0), big.NewInt(0), nil, fixedgas.DefaultMaxBlobsPerBlock, nil, logger) + txPool, err := New(ch, coreDB, cfg, sendersCache, *u256.N1, big.NewInt(0), big.NewInt(0), nil, nil, nil, nil, nil, fixedgas.DefaultMaxBlobsPerBlock, nil, logger) assert.NoError(err) require.True(txPool != nil) @@ -1100,7 +1100,7 @@ func TestBlobSlots(t *testing.T) { cfg.TotalBlobPoolLimit = 20 sendersCache := kvcache.New(kvcache.DefaultCoherentConfig) - pool, err := New(ch, coreDB, cfg, sendersCache, *u256.N1, common.Big0, nil, common.Big0, fixedgas.DefaultMaxBlobsPerBlock, nil, log.New()) + pool, err := New(ch, coreDB, cfg, sendersCache, *u256.N1, common.Big0, nil, common.Big0, nil, nil, nil, nil, fixedgas.DefaultMaxBlobsPerBlock, nil, log.New()) assert.NoError(err) require.True(pool != nil) ctx := context.Background() @@ -1174,7 +1174,7 @@ func TestGasLimitChanged(t *testing.T) { cfg := txpoolcfg.DefaultConfig sendersCache := kvcache.New(kvcache.DefaultCoherentConfig) - pool, err := New(ch, coreDB, cfg, sendersCache, *u256.N1, nil, nil, nil, fixedgas.DefaultMaxBlobsPerBlock, nil, log.New()) + pool, err := New(ch, coreDB, cfg, sendersCache, *u256.N1, nil, nil, nil, nil, nil, nil, nil, fixedgas.DefaultMaxBlobsPerBlock, nil, log.New()) assert.NoError(err) require.True(pool != nil) ctx := context.Background() diff --git a/erigon-lib/txpool/txpooluitl/all_components.go b/erigon-lib/txpool/txpooluitl/all_components.go index c5f5790537e..e1d23a4c47d 100644 --- a/erigon-lib/txpool/txpooluitl/all_components.go +++ b/erigon-lib/txpool/txpooluitl/all_components.go @@ -141,8 +141,15 @@ func AllComponents(ctx context.Context, cfg txpoolcfg.Config, cache kvcache.Cach } cancunTime := chainConfig.CancunTime + regolithTime := chainConfig.RegolithTime + canyonTime := chainConfig.CanyonTime + ecotoneTime := chainConfig.EcotoneTime + fjordTime := chainConfig.FjordTime + var pool txpool.Pool - txPool, err := txpool.New(newTxs, chainDB, cfg, cache, *chainID, shanghaiTime, agraBlock, cancunTime, maxBlobsPerBlock, feeCalculator, logger) + txPool, err := txpool.New(newTxs, chainDB, cfg, cache, *chainID, shanghaiTime, agraBlock, cancunTime, + regolithTime, canyonTime, ecotoneTime, fjordTime, + maxBlobsPerBlock, feeCalculator, logger) if err != nil { return nil, nil, nil, nil, nil, err } diff --git a/turbo/jsonrpc/eth_receipts_test.go b/turbo/jsonrpc/eth_receipts_test.go index 46e00373e4b..1dc90728c06 100644 --- a/turbo/jsonrpc/eth_receipts_test.go +++ b/turbo/jsonrpc/eth_receipts_test.go @@ -126,13 +126,13 @@ func TestGetReceipts(t *testing.T) { require.Equal(t, new(uint256.Int).SetBytes(l1BaseFee[:]).ToBig(), receipts[0].L1GasPrice) rollupDataGas1 := uint64(2492) require.Equal(t, new(big.Int).Add(new(big.Int).SetUint64(rollupDataGas1), new(uint256.Int).SetBytes(overhead[:]).ToBig()), receipts[0].L1GasUsed) - require.Equal(t, opstack.L1Cost(rollupDataGas1, new(uint256.Int).SetBytes(l1BaseFee[:]), new(uint256.Int).SetBytes(overhead[:]), new(uint256.Int).SetBytes(scalar[:])).ToBig(), receipts[0].L1Fee) + require.Equal(t, opstack.L1CostPreEcotone(rollupDataGas1, new(uint256.Int).SetBytes(l1BaseFee[:]), new(uint256.Int).SetBytes(overhead[:]), new(uint256.Int).SetBytes(scalar[:])).ToBig(), receipts[0].L1Fee) require.Equal(t, feeScalar, receipts[0].FeeScalar) require.Equal(t, new(uint256.Int).SetBytes(l1BaseFee[:]).ToBig(), receipts[1].L1GasPrice) rollupDataGas2 := uint64(1340) require.Equal(t, new(big.Int).Add(new(big.Int).SetUint64(rollupDataGas2), new(uint256.Int).SetBytes(overhead[:]).ToBig()), receipts[1].L1GasUsed) - require.Equal(t, opstack.L1Cost(rollupDataGas2, new(uint256.Int).SetBytes(l1BaseFee[:]), new(uint256.Int).SetBytes(overhead[:]), new(uint256.Int).SetBytes(scalar[:])).ToBig(), receipts[1].L1Fee) + require.Equal(t, opstack.L1CostPreEcotone(rollupDataGas2, new(uint256.Int).SetBytes(l1BaseFee[:]), new(uint256.Int).SetBytes(overhead[:]), new(uint256.Int).SetBytes(scalar[:])).ToBig(), receipts[1].L1Fee) require.Equal(t, feeScalar, receipts[1].FeeScalar) } diff --git a/turbo/stages/mock/mock_sentry.go b/turbo/stages/mock/mock_sentry.go index 7a8113f3eb9..9172f8faf65 100644 --- a/turbo/stages/mock/mock_sentry.go +++ b/turbo/stages/mock/mock_sentry.go @@ -310,7 +310,7 @@ func MockWithEverything(tb testing.TB, gspec *types.Genesis, key *ecdsa.PrivateK shanghaiTime := mock.ChainConfig.ShanghaiTime cancunTime := mock.ChainConfig.CancunTime maxBlobsPerBlock := mock.ChainConfig.GetMaxBlobsPerBlock() - mock.TxPool, err = txpool.New(newTxs, mock.DB, poolCfg, kvcache.NewDummy(), *chainID, shanghaiTime, nil /* agraBlock */, cancunTime, maxBlobsPerBlock, nil, logger) + mock.TxPool, err = txpool.New(newTxs, mock.DB, poolCfg, kvcache.NewDummy(), *chainID, shanghaiTime, nil /* agraBlock */, cancunTime, nil, nil, nil, nil, maxBlobsPerBlock, nil, logger) if err != nil { tb.Fatal(err) } From b145e0a09aa5f85e2b89897720fff71cdfedfb7c Mon Sep 17 00:00:00 2001 From: pcw109550 Date: Mon, 27 May 2024 16:49:04 +0900 Subject: [PATCH 2/2] fix comment --- erigon-lib/txpool/pool.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/erigon-lib/txpool/pool.go b/erigon-lib/txpool/pool.go index 45f4fa60e83..d5b3d793773 100644 --- a/erigon-lib/txpool/pool.go +++ b/erigon-lib/txpool/pool.go @@ -1176,7 +1176,7 @@ func (p *TxPool) isRegolith() bool { } regolithTime := *p.regolithTime - // a zero here means Cancun is always active + // a zero here means Regolith is always active if regolithTime == 0 { p.isPostRegolith.Swap(true) return true @@ -1201,7 +1201,7 @@ func (p *TxPool) isCanyon() bool { } canyonTime := *p.canyonTime - // a zero here means Cancun is always active + // a zero here means Canyon is always active if canyonTime == 0 { p.isPostCanyon.Swap(true) return true @@ -1226,7 +1226,7 @@ func (p *TxPool) isEcotone() bool { } ecotoneTime := *p.ecotoneTime - // a zero here means Cancun is always active + // a zero here means Ecotone is always active if ecotoneTime == 0 { p.isPostEcotone.Swap(true) return true @@ -1251,7 +1251,7 @@ func (p *TxPool) isFjord() bool { } fjordTime := *p.fjordTime - // a zero here means Cancun is always active + // a zero here means Fjord is always active if fjordTime == 0 { p.isPostFjord.Swap(true) return true