Skip to content

Commit

Permalink
Fixes OP CL driven block production (#7240)
Browse files Browse the repository at this point in the history
  • Loading branch information
flcl42 committed Jul 5, 2024
1 parent f9b4cac commit d75ad69
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 31 deletions.
9 changes: 9 additions & 0 deletions src/Nethermind/Nethermind.JsonRpc/ResultWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,16 @@ private ResultWrapper()
? Fail("Missing result.")
: rpcResult.IsValid ? Success(rpcResult.Result) : Fail(rpcResult.Error.Message);

public static ResultWrapper<T> 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<T>>(ResultWrapper<T> resultWrapper) => Task.FromResult(resultWrapper);

public void Dispose()
{
if (Data is IDisposable disposable)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -78,8 +88,8 @@ public class OptimismBlockProducerEnvFactory(
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)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public interface IOptimismEngineRpcModule : IRpcModule
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<ResultWrapper<GetPayloadV3Result?>> engine_getPayloadV3(byte[] payloadId);
Task<ResultWrapper<OptimismGetPayloadV3Result?>> 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.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ public async Task<ResultWrapper<ForkchoiceUpdatedV1Result>> engine_forkchoiceUpd
return await _engineRpcModule.engine_forkchoiceUpdatedV3(forkchoiceState, payloadAttributes);
}

public Task<ResultWrapper<GetPayloadV3Result?>> engine_getPayloadV3(byte[] payloadId)
public async Task<ResultWrapper<OptimismGetPayloadV3Result?>> engine_getPayloadV3(byte[] payloadId)
{
return _engineRpcModule.engine_getPayloadV3(payloadId);
ResultWrapper<GetPayloadV3Result?> result = await _engineRpcModule.engine_getPayloadV3(payloadId);
return ResultWrapper<OptimismGetPayloadV3Result?>.From(result, result.Data is null ? null : new OptimismGetPayloadV3Result(result.Data));
}

public Task<ResultWrapper<PayloadStatusV1>> engine_newPayloadV3(ExecutionPayloadV3 executionPayload, byte[]?[] blobVersionedHashes, Hash256? parentBeaconBlockRoot)
Expand Down
Original file line number Diff line number Diff line change
@@ -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}}}";
}

0 comments on commit d75ad69

Please sign in to comment.