diff --git a/src/Nethermind/Nethermind.Blockchain/ChainHeadInfoProvider.cs b/src/Nethermind/Nethermind.Blockchain/ChainHeadInfoProvider.cs index 870713c1861..90a356fdf4b 100644 --- a/src/Nethermind/Nethermind.Blockchain/ChainHeadInfoProvider.cs +++ b/src/Nethermind/Nethermind.Blockchain/ChainHeadInfoProvider.cs @@ -59,7 +59,8 @@ private void OnHeadChanged(object? sender, BlockReplacementEventArgs e) BlockGasLimit = e.Block!.GasLimit; CurrentBaseFee = e.Block.Header.BaseFeePerGas; CurrentFeePerBlobGas = - BlobGasCalculator.TryCalculateFeePerBlobGas(e.Block.Header, out UInt256 currentFeePerBlobGas, SpecProvider) + BlobGasCalculator.TryCalculateFeePerBlobGas(e.Block.Header, out UInt256 currentFeePerBlobGas, + SpecProvider.GetSpec(e.Block.Header)) ? currentFeePerBlobGas : UInt256.Zero; HeadChanged?.Invoke(sender, e); diff --git a/src/Nethermind/Nethermind.Blockchain/Contracts/CallableContract.cs b/src/Nethermind/Nethermind.Blockchain/Contracts/CallableContract.cs index 2df49d11d1c..52aefe6f9ff 100644 --- a/src/Nethermind/Nethermind.Blockchain/Contracts/CallableContract.cs +++ b/src/Nethermind/Nethermind.Blockchain/Contracts/CallableContract.cs @@ -68,7 +68,7 @@ private bool TryCall(BlockHeader header, Transaction transaction, out byte[] res try { - _transactionProcessor.Execute(transaction, new BlockExecutionContext(header, SpecProvider), tracer); + _transactionProcessor.Execute(transaction, new BlockExecutionContext(header, SpecProvider.GetSpec(header)), tracer); result = tracer.ReturnValue; return tracer.StatusCode == StatusCode.Success; } diff --git a/src/Nethermind/Nethermind.Blockchain/Contracts/Contract.cs b/src/Nethermind/Nethermind.Blockchain/Contracts/Contract.cs index 15cf0d2425f..134aa2f6f35 100644 --- a/src/Nethermind/Nethermind.Blockchain/Contracts/Contract.cs +++ b/src/Nethermind/Nethermind.Blockchain/Contracts/Contract.cs @@ -182,11 +182,11 @@ protected byte[] CallCore(ITransactionProcessor transactionProcessor, BlockHeade { if (callAndRestore) { - transactionProcessor.CallAndRestore(transaction, new BlockExecutionContext(header, SpecProvider), tracer); + transactionProcessor.CallAndRestore(transaction, new BlockExecutionContext(header, SpecProvider.GetSpec(header)), tracer); } else { - transactionProcessor.Execute(transaction, new BlockExecutionContext(header, SpecProvider), tracer); + transactionProcessor.Execute(transaction, new BlockExecutionContext(header, SpecProvider.GetSpec(header)), tracer); } failure = tracer.StatusCode != StatusCode.Success; diff --git a/src/Nethermind/Nethermind.Blockchain/GenesisLoader.cs b/src/Nethermind/Nethermind.Blockchain/GenesisLoader.cs index 50c5543a619..6479fe07cb7 100644 --- a/src/Nethermind/Nethermind.Blockchain/GenesisLoader.cs +++ b/src/Nethermind/Nethermind.Blockchain/GenesisLoader.cs @@ -80,7 +80,7 @@ private void Preallocate(Block genesis) }; CallOutputTracer outputTracer = new(); - _transactionProcessor.Execute(constructorTransaction, new BlockExecutionContext(genesis.Header, _specProvider), outputTracer); + _transactionProcessor.Execute(constructorTransaction, new BlockExecutionContext(genesis.Header, _specProvider.GetSpec(genesis.Header)), outputTracer); if (outputTracer.StatusCode != StatusCode.Success) { diff --git a/src/Nethermind/Nethermind.Consensus/Producers/PayloadAttributes.cs b/src/Nethermind/Nethermind.Consensus/Producers/PayloadAttributes.cs index 66c5942b8a6..4888f407058 100644 --- a/src/Nethermind/Nethermind.Consensus/Producers/PayloadAttributes.cs +++ b/src/Nethermind/Nethermind.Consensus/Producers/PayloadAttributes.cs @@ -28,6 +28,8 @@ public class PayloadAttributes public ulong? TargetBlobCount { get; set; } + public ulong? MaxBlobCount { get; set; } + public virtual long? GetGasLimit() => null; public override string ToString() => ToString(string.Empty); @@ -54,6 +56,11 @@ public string ToString(string indentation) sb.Append($", {nameof(TargetBlobCount)} : {TargetBlobCount}"); } + if (MaxBlobCount is not null) + { + sb.Append($", {nameof(MaxBlobCount)} : {MaxBlobCount}"); + } + sb.Append('}'); return sb.ToString(); @@ -79,7 +86,8 @@ protected virtual int ComputePayloadIdMembersSize() => + Address.Size // suggested fee recipient + (Withdrawals is null ? 0 : Keccak.Size) // withdrawals root hash + (ParentBeaconBlockRoot is null ? 0 : Keccak.Size) // parent beacon block root - + (TargetBlobCount is null ? 0 : sizeof(ulong)); // target blob count + + (TargetBlobCount is null ? 0 : sizeof(ulong)) // target blob count + + (MaxBlobCount is null ? 0 : sizeof(ulong)); // max blob count protected static string ComputePayloadId(Span inputSpan) { @@ -124,6 +132,12 @@ protected virtual int WritePayloadIdMembers(BlockHeader parentHeader, Span position += sizeof(ulong); } + if (MaxBlobCount.HasValue) + { + BinaryPrimitives.WriteUInt64BigEndian(inputSpan.Slice(position, sizeof(ulong)), MaxBlobCount.Value); + position += sizeof(ulong); + } + return position; } @@ -180,7 +194,7 @@ public static class PayloadAttributesExtensions public static int GetVersion(this PayloadAttributes executionPayload) => executionPayload switch { - { TargetBlobCount: not null } => EngineApiVersions.Prague, + { MaxBlobCount: not null, TargetBlobCount: not null } => EngineApiVersions.Prague, { ParentBeaconBlockRoot: not null, Withdrawals: not null } => EngineApiVersions.Cancun, { Withdrawals: not null } => EngineApiVersions.Shanghai, _ => EngineApiVersions.Paris diff --git a/src/Nethermind/Nethermind.Consensus/Producers/TxPoolTxSource.cs b/src/Nethermind/Nethermind.Consensus/Producers/TxPoolTxSource.cs index 091d71593a9..233b44315c2 100644 --- a/src/Nethermind/Nethermind.Consensus/Producers/TxPoolTxSource.cs +++ b/src/Nethermind/Nethermind.Consensus/Producers/TxPoolTxSource.cs @@ -62,7 +62,7 @@ public IEnumerable GetTransactions(BlockHeader parent, long gasLimi int checkedTransactions = 0; int selectedTransactions = 0; - using ArrayPoolList selectedBlobTxs = new((int)(parent.TargetBlobCount * 2 ?? Eip4844Constants.GetMaxBlobsPerBlock())); + using ArrayPoolList selectedBlobTxs = new((int)(payloadAttributes?.MaxBlobCount ?? Eip4844Constants.GetMaxBlobsPerBlock())); SelectBlobTransactions(blobTransactions, parent, spec, selectedBlobTxs); diff --git a/src/Nethermind/Nethermind.Evm/BlobGasCalculator.cs b/src/Nethermind/Nethermind.Evm/BlobGasCalculator.cs index ba59d49f2b8..ae8a5fc51de 100644 --- a/src/Nethermind/Nethermind.Evm/BlobGasCalculator.cs +++ b/src/Nethermind/Nethermind.Evm/BlobGasCalculator.cs @@ -45,11 +45,6 @@ public static bool TryCalculateFeePerBlobGas(BlockHeader header, out UInt256 fee return TryCalculateFeePerBlobGas(header.ExcessBlobGas, out feePerBlobGas, header.TargetBlobCount, spec); } - public static bool TryCalculateFeePerBlobGas(BlockHeader header, out UInt256 feePerBlobGas, ISpecProvider specProvider) - { - return TryCalculateFeePerBlobGas(header.ExcessBlobGas, out feePerBlobGas, header.TargetBlobCount, specProvider.GetSpec(header)); - } - public static bool TryCalculateFeePerBlobGas(ulong? excessBlobGas, out UInt256 feePerBlobGas, UInt256? targetBlobCount, IReleaseSpec? spec) { static bool FakeExponentialOverflow(UInt256 factor, UInt256 num, UInt256 denominator, out UInt256 feePerBlobGas) diff --git a/src/Nethermind/Nethermind.Evm/BlockExecutionContext.cs b/src/Nethermind/Nethermind.Evm/BlockExecutionContext.cs index 053910c4d32..8af467bbb14 100644 --- a/src/Nethermind/Nethermind.Evm/BlockExecutionContext.cs +++ b/src/Nethermind/Nethermind.Evm/BlockExecutionContext.cs @@ -26,11 +26,6 @@ public BlockExecutionContext(BlockHeader blockHeader, IReleaseSpec spec) } } - public BlockExecutionContext(BlockHeader blockHeader, ISpecProvider specProvider) : this(blockHeader, - specProvider.GetSpec(blockHeader)) - { - } - public BlockExecutionContext(BlockHeader blockHeader, UInt256 forceBlobBaseFee) { Header = blockHeader; diff --git a/src/Nethermind/Nethermind.Evm/Tracing/GasEstimator.cs b/src/Nethermind/Nethermind.Evm/Tracing/GasEstimator.cs index b75c58548ac..e05eeb5234b 100644 --- a/src/Nethermind/Nethermind.Evm/Tracing/GasEstimator.cs +++ b/src/Nethermind/Nethermind.Evm/Tracing/GasEstimator.cs @@ -114,7 +114,7 @@ private bool TryExecutableTransaction(Transaction transaction, BlockHeader block transaction.GasLimit = gasLimit; - BlockExecutionContext blCtx = new(block, _specProvider); + BlockExecutionContext blCtx = new(block, _specProvider.GetSpec(block)); _transactionProcessor.CallAndRestore(transaction, in blCtx, tracer.WithCancellation(token)); transaction.GasLimit = originalGasLimit; diff --git a/src/Nethermind/Nethermind.Evm/TransactionProcessing/TransactionProcessor.cs b/src/Nethermind/Nethermind.Evm/TransactionProcessing/TransactionProcessor.cs index eada805a2c0..5b9c745bc39 100644 --- a/src/Nethermind/Nethermind.Evm/TransactionProcessing/TransactionProcessor.cs +++ b/src/Nethermind/Nethermind.Evm/TransactionProcessing/TransactionProcessor.cs @@ -102,7 +102,7 @@ protected TransactionProcessorBase( } public TransactionResult CallAndRestore(Transaction transaction, in BlockHeader header, ITxTracer txTracer) => - ExecuteCore(transaction, new BlockExecutionContext(header, SpecProvider), txTracer, ExecutionOptions.CommitAndRestore); + ExecuteCore(transaction, new BlockExecutionContext(header, SpecProvider.GetSpec(header)), txTracer, ExecutionOptions.CommitAndRestore); public TransactionResult CallAndRestore(Transaction transaction, in BlockExecutionContext blCtx, ITxTracer txTracer) => ExecuteCore(transaction, in blCtx, txTracer, ExecutionOptions.CommitAndRestore); @@ -112,7 +112,7 @@ public TransactionResult BuildUp(Transaction transaction, in BlockHeader header, // we need to treat the result of previous transaction as the original value of next transaction // when we do not commit WorldState.TakeSnapshot(true); - return ExecuteCore(transaction, new BlockExecutionContext(header, SpecProvider), txTracer, ExecutionOptions.None); + return ExecuteCore(transaction, new BlockExecutionContext(header, SpecProvider.GetSpec(header)), txTracer, ExecutionOptions.None); } public TransactionResult BuildUp(Transaction transaction, in BlockExecutionContext blCtx, ITxTracer txTracer) @@ -124,19 +124,19 @@ public TransactionResult BuildUp(Transaction transaction, in BlockExecutionConte } public TransactionResult Execute(Transaction transaction, in BlockHeader header, ITxTracer txTracer) => - ExecuteCore(transaction, new BlockExecutionContext(header, SpecProvider), txTracer, ExecutionOptions.Commit); + ExecuteCore(transaction, new BlockExecutionContext(header, SpecProvider.GetSpec(header)), txTracer, ExecutionOptions.Commit); public TransactionResult Execute(Transaction transaction, in BlockExecutionContext blCtx, ITxTracer txTracer) => ExecuteCore(transaction, in blCtx, txTracer, ExecutionOptions.Commit); public TransactionResult Trace(Transaction transaction, in BlockHeader header, ITxTracer txTracer) => - ExecuteCore(transaction, new BlockExecutionContext(header, SpecProvider), txTracer, ExecutionOptions.NoValidation); + ExecuteCore(transaction, new BlockExecutionContext(header, SpecProvider.GetSpec(header)), txTracer, ExecutionOptions.NoValidation); public TransactionResult Trace(Transaction transaction, in BlockExecutionContext blCtx, ITxTracer txTracer) => ExecuteCore(transaction, in blCtx, txTracer, ExecutionOptions.NoValidation); public TransactionResult Warmup(Transaction transaction, in BlockHeader header, ITxTracer txTracer) => - ExecuteCore(transaction, new BlockExecutionContext(header, SpecProvider), txTracer, ExecutionOptions.Warmup); + ExecuteCore(transaction, new BlockExecutionContext(header, SpecProvider.GetSpec(header)), txTracer, ExecutionOptions.Warmup); public TransactionResult Warmup(Transaction transaction, in BlockExecutionContext blCtx, ITxTracer txTracer) => ExecuteCore(transaction, in blCtx, txTracer, ExecutionOptions.Warmup); @@ -146,7 +146,7 @@ private TransactionResult ExecuteCore(Transaction tx, in BlockExecutionContext b if (tx.IsSystem()) { _systemTransactionProcessor ??= new SystemTransactionProcessor(SpecProvider, WorldState, VirtualMachine, _codeInfoRepository, _logManager); - return _systemTransactionProcessor.Execute(tx, new BlockExecutionContext(blCtx.Header, SpecProvider), tracer, opts); + return _systemTransactionProcessor.Execute(tx, new BlockExecutionContext(blCtx.Header, SpecProvider.GetSpec(blCtx.Header)), tracer, opts); } return Execute(tx, in blCtx, tracer, opts); diff --git a/src/Nethermind/Nethermind.Merge.Plugin/Data/ExecutionPayload.cs b/src/Nethermind/Nethermind.Merge.Plugin/Data/ExecutionPayload.cs index 6160db547db..54614d4b82d 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin/Data/ExecutionPayload.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin/Data/ExecutionPayload.cs @@ -123,12 +123,6 @@ public byte[][] Transactions /// public virtual ulong? TargetBlobCount { get; set; } - /// - /// Gets or sets as defined in - /// EIP-7742. - /// - public virtual ulong? MaxBlobCount { get; set; } - public static ExecutionPayload Create(Block block) => Create(block); protected static TExecutionPayload Create(Block block) where TExecutionPayload : ExecutionPayload, new() diff --git a/src/Nethermind/Nethermind.Merge.Plugin/Data/ExecutionPayloadV4.cs b/src/Nethermind/Nethermind.Merge.Plugin/Data/ExecutionPayloadV4.cs index 6da49b70fba..1d0643c96aa 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin/Data/ExecutionPayloadV4.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin/Data/ExecutionPayloadV4.cs @@ -109,11 +109,4 @@ public override bool ValidateFork(ISpecProvider specProvider) => /// [JsonRequired] public sealed override ulong? TargetBlobCount { get; set; } - - /// - /// Gets or sets as defined in - /// EIP-7742. - /// - [JsonRequired] - public sealed override ulong? MaxBlobCount { get; set; } } diff --git a/src/Nethermind/Nethermind.Taiko/Rpc/TaikoEngineRpcModule.cs b/src/Nethermind/Nethermind.Taiko/Rpc/TaikoEngineRpcModule.cs index 53081672f97..0c784d67b51 100644 --- a/src/Nethermind/Nethermind.Taiko/Rpc/TaikoEngineRpcModule.cs +++ b/src/Nethermind/Nethermind.Taiko/Rpc/TaikoEngineRpcModule.cs @@ -162,7 +162,7 @@ void CommitAndDisposeBatch(Batch batch) batch.Dispose(); } - BlockExecutionContext blkCtx = new(blockHeader, _specProvider); + BlockExecutionContext blkCtx = new(blockHeader, _specProvider.GetSpec(blockHeader)); worldState.StateRoot = blockHeader.StateRoot; Batch batch = new(maxBytesPerTxList, txSource.Length, txDecoder); diff --git a/src/Nethermind/Nethermind.TxPool/TxPool.cs b/src/Nethermind/Nethermind.TxPool/TxPool.cs index d5da02b0b75..29ea5e63d80 100644 --- a/src/Nethermind/Nethermind.TxPool/TxPool.cs +++ b/src/Nethermind/Nethermind.TxPool/TxPool.cs @@ -302,7 +302,7 @@ private void ReAddReorganisedTransactions(Block? previousBlock) private void RemoveProcessedTransactions(Block block) { Transaction[] blockTransactions = block.Transactions; - using ArrayPoolList blobTxsToSave = new((int)(block.TargetBlobCount * 2 ?? Eip4844Constants.GetMaxBlobsPerBlock())); + using ArrayPoolList blobTxsToSave = new(blockTransactions.Length); long discoveredForPendingTxs = 0; long discoveredForHashCache = 0; long eip1559Txs = 0;