diff --git a/src/Nethermind/Nethermind.JsonRpc/ResultWrapper.cs b/src/Nethermind/Nethermind.JsonRpc/ResultWrapper.cs index 80d69d2ae4d..f728b274a69 100644 --- a/src/Nethermind/Nethermind.JsonRpc/ResultWrapper.cs +++ b/src/Nethermind/Nethermind.JsonRpc/ResultWrapper.cs @@ -47,7 +47,16 @@ rpcResult is null ? Fail("Missing result.") : rpcResult.IsValid ? Success(rpcResult.Result) : Fail(rpcResult.Error.Message); + public static ResultWrapper From(IResultWrapper source, T? data = default) => new() + { + Data = data ?? (T)source.Data, + Result = source.Result, + ErrorCode = source.ErrorCode, + IsTemporary = source.IsTemporary, + }; + public static implicit operator Task>(ResultWrapper resultWrapper) => Task.FromResult(resultWrapper); + public void Dispose() { if (Data is IDisposable disposable) diff --git a/src/Nethermind/Nethermind.Optimism/OptimismBlockProducerEnvFactory.cs b/src/Nethermind/Nethermind.Optimism/OptimismBlockProducerEnvFactory.cs index 1069b90a688..f60c6638468 100644 --- a/src/Nethermind/Nethermind.Optimism/OptimismBlockProducerEnvFactory.cs +++ b/src/Nethermind/Nethermind.Optimism/OptimismBlockProducerEnvFactory.cs @@ -20,35 +20,45 @@ namespace Nethermind.Optimism; -public class OptimismBlockProducerEnvFactory( - IWorldStateManager worldStateManager, - IBlockTree blockTree, - ISpecProvider specProvider, - IBlockValidator blockValidator, - IRewardCalculatorSource rewardCalculatorSource, - IReceiptStorage receiptStorage, - IBlockPreprocessorStep blockPreprocessorStep, - ITxPool txPool, - ITransactionComparerProvider transactionComparerProvider, - IBlocksConfig blocksConfig, - OptimismSpecHelper specHelper, - OPL1CostHelper l1CostHelper, - ILogManager logManager) : BlockProducerEnvFactory( - worldStateManager, - blockTree, - specProvider, - blockValidator, - rewardCalculatorSource, - receiptStorage, - blockPreprocessorStep, - txPool, - transactionComparerProvider, - blocksConfig, - logManager) +public class OptimismBlockProducerEnvFactory : BlockProducerEnvFactory { + private readonly OptimismSpecHelper _specHelper; + private readonly OPL1CostHelper _l1CostHelper; + + public OptimismBlockProducerEnvFactory( + IWorldStateManager worldStateManager, + IBlockTree blockTree, + ISpecProvider specProvider, + IBlockValidator blockValidator, + IRewardCalculatorSource rewardCalculatorSource, + IReceiptStorage receiptStorage, + IBlockPreprocessorStep blockPreprocessorStep, + ITxPool txPool, + ITransactionComparerProvider transactionComparerProvider, + IBlocksConfig blocksConfig, + OptimismSpecHelper specHelper, + OPL1CostHelper l1CostHelper, + ILogManager logManager) : base( + worldStateManager, + blockTree, + specProvider, + blockValidator, + rewardCalculatorSource, + receiptStorage, + blockPreprocessorStep, + txPool, + transactionComparerProvider, + blocksConfig, + logManager) + { + _specHelper = specHelper; + _l1CostHelper = l1CostHelper; + TransactionsExecutorFactory = new OptimismTransactionsExecutorFactory(specProvider, logManager); + } + protected override ReadOnlyTxProcessingEnv CreateReadonlyTxProcessingEnv(IWorldStateManager worldStateManager, ReadOnlyBlockTree readOnlyBlockTree) => - new OptimismReadOnlyTxProcessingEnv(worldStateManager, readOnlyBlockTree, _specProvider, _logManager, l1CostHelper, specHelper); + new OptimismReadOnlyTxProcessingEnv(worldStateManager, readOnlyBlockTree, _specProvider, _logManager, _l1CostHelper, _specHelper); protected override ITxSource CreateTxSourceForProducer(ITxSource? additionalTxSource, ReadOnlyTxProcessingEnv processingEnv, @@ -78,8 +88,8 @@ protected override BlockProcessor CreateBlockProcessor( receiptStorage, new BlockhashStore(specProvider, readOnlyTxProcessingEnv.WorldState), logManager, - specHelper, - new Create2DeployerContractRewriter(specHelper, _specProvider, _blockTree), + _specHelper, + new Create2DeployerContractRewriter(_specHelper, _specProvider, _blockTree), new BlockProductionWithdrawalProcessor(new WithdrawalProcessor(readOnlyTxProcessingEnv.WorldState, logManager))); } } diff --git a/src/Nethermind/Nethermind.Optimism/Rpc/IOptimismEngineRpcModule.cs b/src/Nethermind/Nethermind.Optimism/Rpc/IOptimismEngineRpcModule.cs index a4fff0ee437..c8eae2f7a2c 100644 --- a/src/Nethermind/Nethermind.Optimism/Rpc/IOptimismEngineRpcModule.cs +++ b/src/Nethermind/Nethermind.Optimism/Rpc/IOptimismEngineRpcModule.cs @@ -61,7 +61,7 @@ Task> engine_forkchoiceUpdatedV3( Description = "Returns the most recent version of an execution payload with respect to the transaction set contained by the mempool.", IsSharable = true, IsImplemented = true)] - Task> engine_getPayloadV3(byte[] payloadId); + Task> engine_getPayloadV3(byte[] payloadId); [JsonRpcMethod( Description = "Verifies the payload according to the execution environment rules and returns the verification status and hash of the last valid block.", diff --git a/src/Nethermind/Nethermind.Optimism/Rpc/OptimismEngineRpcModule.cs b/src/Nethermind/Nethermind.Optimism/Rpc/OptimismEngineRpcModule.cs index 92aba891d7b..9d0bf66a565 100644 --- a/src/Nethermind/Nethermind.Optimism/Rpc/OptimismEngineRpcModule.cs +++ b/src/Nethermind/Nethermind.Optimism/Rpc/OptimismEngineRpcModule.cs @@ -48,9 +48,10 @@ public async Task> engine_forkchoiceUpd return await _engineRpcModule.engine_forkchoiceUpdatedV3(forkchoiceState, payloadAttributes); } - public Task> engine_getPayloadV3(byte[] payloadId) + public async Task> engine_getPayloadV3(byte[] payloadId) { - return _engineRpcModule.engine_getPayloadV3(payloadId); + ResultWrapper result = await _engineRpcModule.engine_getPayloadV3(payloadId); + return ResultWrapper.From(result, result.Data is null ? null : new OptimismGetPayloadV3Result(result.Data)); } public Task> engine_newPayloadV3(ExecutionPayloadV3 executionPayload, byte[]?[] blobVersionedHashes, Hash256? parentBeaconBlockRoot) diff --git a/src/Nethermind/Nethermind.Optimism/Rpc/OptimismGetPayloadV3Result.cs b/src/Nethermind/Nethermind.Optimism/Rpc/OptimismGetPayloadV3Result.cs new file mode 100644 index 00000000000..5a03afce861 --- /dev/null +++ b/src/Nethermind/Nethermind.Optimism/Rpc/OptimismGetPayloadV3Result.cs @@ -0,0 +1,32 @@ +// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited +// SPDX-License-Identifier: LGPL-3.0-only + +using Nethermind.Core.Crypto; +using Nethermind.Int256; +using Nethermind.Merge.Plugin.Data; + +namespace Nethermind.Optimism.Rpc; + +public class OptimismGetPayloadV3Result +{ + public OptimismGetPayloadV3Result(GetPayloadV3Result result) + { + ExecutionPayload = result.ExecutionPayload; + BlockValue = result.BlockValue; + + BlobsBundle = result.BlobsBundle; + ParentBeaconBlockRoot = result.ExecutionPayload.ParentBeaconBlockRoot!; + ShouldOverrideBuilder = result.ShouldOverrideBuilder; + } + + public UInt256 BlockValue { get; } + public ExecutionPayload ExecutionPayload { get; } + + public BlobsBundleV1 BlobsBundle { get; } + + public Hash256 ParentBeaconBlockRoot { get; set; } + + public bool ShouldOverrideBuilder { get; } + + public override string ToString() => $"{{ExecutionPayload: {ExecutionPayload}, Fees: {BlockValue}, BlobsBundle blobs count: {BlobsBundle.Blobs.Length}, ParentBeaconBlockRoot: {ParentBeaconBlockRoot}, ShouldOverrideBuilder {ShouldOverrideBuilder}}}"; +}