Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Nethermind as Optimism Sequencer #7287

Merged
merged 12 commits into from
Jul 31, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ IOptimismSpecHelper opSpecHelper
private readonly IGasPriceOracle _gasPriceOracle = gasPriceOracle ?? throw new ArgumentNullException(nameof(gasPriceOracle));
private readonly IEthSyncingInfo _ethSyncingInfo = ethSyncingInfo ?? throw new ArgumentNullException(nameof(ethSyncingInfo));
private readonly IFeeHistoryOracle _feeHistoryOracle = feeHistoryOracle ?? throw new ArgumentNullException(nameof(feeHistoryOracle));
private readonly IJsonRpcClient? _sequencerRpcClient = sequencerRpcClient ?? throw new ArgumentNullException(nameof(sequencerRpcClient));
private readonly IAccountStateProvider _accountStateProvider = accountStateProvider ?? throw new ArgumentNullException(nameof(accountStateProvider));
private readonly IEthereumEcdsa _ecdsa = ecdsa ?? throw new ArgumentNullException(nameof(ecdsa));
private readonly ITxSealer _sealer = sealer ?? throw new ArgumentNullException(nameof(sealer));
Expand All @@ -82,7 +81,7 @@ public override IOptimismEthRpcModule Create()
_feeHistoryOracle,
secondsPerSlot,

_sequencerRpcClient,
sequencerRpcClient,
_accountStateProvider,
_ecdsa,
_sealer,
Expand Down
40 changes: 34 additions & 6 deletions src/Nethermind/Nethermind.Optimism/Rpc/OptimismEthRpcModule.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using System;
using System.Linq;
using System.Security;
using System.Threading.Tasks;
using Nethermind.Blockchain.Find;
using Nethermind.Blockchain.Receipts;
Expand Down Expand Up @@ -128,16 +130,42 @@ public override async Task<ResultWrapper<Hash256>> eth_sendTransaction(Transacti

public override async Task<ResultWrapper<Hash256>> eth_sendRawTransaction(byte[] transaction)
{
if (_sequencerRpcClient is null)
if (_sequencerRpcClient is not null)
{
return ResultWrapper<Hash256>.Fail("No sequencer url in the config");
Hash256? result = await _sequencerRpcClient.Post<Hash256>(nameof(eth_sendRawTransaction), transaction);
if (result is null)
{
return ResultWrapper<Hash256>.Fail("Failed to forward transaction");
}

return ResultWrapper<Hash256>.Success(result);
}
Hash256? result = await _sequencerRpcClient.Post<Hash256>(nameof(eth_sendRawTransaction), transaction);
if (result is null)
else
{
return ResultWrapper<Hash256>.Fail("Failed to forward transaction");
try
{
Transaction tx = Rlp.Decode<Transaction>(transaction, RlpBehaviors.AllowUnsigned | RlpBehaviors.SkipTypedWrapping | RlpBehaviors.InMempoolForm);

(Hash256 txHash, AcceptTxResult? acceptTxResult) = await _txSender.SendTransaction(tx, TxHandlingOptions.None | TxHandlingOptions.PersistentBroadcast);

return acceptTxResult.Equals(AcceptTxResult.Accepted)
? ResultWrapper<Hash256>.Success(txHash)
: ResultWrapper<Hash256>.Fail(acceptTxResult?.ToString() ?? string.Empty, ErrorCodes.TransactionRejected);
}
catch (SecurityException e)
{
return ResultWrapper<Hash256>.Fail(e.Message, ErrorCodes.AccountLocked);
}
catch (RlpException)
{
return ResultWrapper<Hash256>.Fail("Invalid RLP.", ErrorCodes.TransactionRejected);
}
catch (Exception e)
{
if (_logger.IsError) _logger.Error("Failed to send transaction.", e);
return ResultWrapper<Hash256>.Fail(e.Message, ErrorCodes.TransactionRejected);
}
}
return ResultWrapper<Hash256>.Success(result);
}

public new ResultWrapper<OptimismReceiptForRpc?> eth_getTransactionReceipt(Hash256 txHash)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected override void RegisterEthRpcModule(IRpcModuleProvider rpcModuleProvide

if (_config.SequencerUrl is null && _logger.IsWarn)
{
_logger.Warn($"SequencerUrl is not set.");
_logger.Warn($"SequencerUrl is not set. Nethermind will behave as a Sequencer");
}

BasicJsonRpcClient? sequencerJsonRpcClient = _config.SequencerUrl is null
Expand Down