-
Notifications
You must be signed in to change notification settings - Fork 486
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
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
86ca77b
Behave as sequencer when no sequencerUrl is provided
emlautarom1 d99a710
Merge branch 'master' into feat/optimism-sequencer
emlautarom1 b7cc98c
Add `WithEthRpcModule` stage
emlautarom1 1ad4025
Fallback to base instead of duplicating code
emlautarom1 524c54f
Initial `OptimismEthRpcModule` tests
emlautarom1 b34cc48
Autoformatting
emlautarom1 bf77470
Remove unused imports
emlautarom1 bbebda9
Add `SequencerMode` flag
emlautarom1 512f498
Revert "Add `SequencerMode` flag"
emlautarom1 173cfdf
Use Substitutes instead of null
emlautarom1 d410acc
Merge branch 'master' into feat/optimism-sequencer
emlautarom1 a867b11
Merge branch 'master' into feat/optimism-sequencer
emlautarom1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
src/Nethermind/Nethermind.Optimism.Test/Rpc/OptimismEthRpcModuleTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
using System.Threading.Tasks; | ||
using Nethermind.Blockchain.Synchronization; | ||
using Nethermind.Config; | ||
using Nethermind.Core; | ||
using Nethermind.Core.Extensions; | ||
using Nethermind.Core.Test.Builders; | ||
using Nethermind.Crypto; | ||
using Nethermind.Facade; | ||
using Nethermind.Facade.Eth; | ||
using Nethermind.JsonRpc.Client; | ||
using Nethermind.JsonRpc.Modules.Eth.FeeHistory; | ||
using Nethermind.JsonRpc.Test.Modules; | ||
using Nethermind.Logging; | ||
using Nethermind.Optimism.Rpc; | ||
using Nethermind.Serialization.Rlp; | ||
using Nethermind.Synchronization.ParallelSync; | ||
using Nethermind.TxPool; | ||
using NSubstitute; | ||
using NUnit.Framework; | ||
|
||
namespace Nethermind.Optimism.Test.Rpc; | ||
|
||
public class OptimismEthRpcModuleTest | ||
{ | ||
[Test] | ||
public async Task Sequencer_send_transaction_with_signature_will_not_try_to_sign() | ||
{ | ||
IBlockchainBridge bridge = Substitute.For<IBlockchainBridge>(); | ||
ITxSender txSender = Substitute.For<ITxSender>(); | ||
txSender.SendTransaction(tx: Arg.Any<Transaction>(), txHandlingOptions: TxHandlingOptions.PersistentBroadcast) | ||
.Returns(returnThis: (TestItem.KeccakA, AcceptTxResult.Accepted)); | ||
|
||
EthereumEcdsa ethereumEcdsa = new EthereumEcdsa(chainId: TestBlockchainIds.ChainId, logManager: LimboLogs.Instance); | ||
TestRpcBlockchain rpcBlockchain = await TestRpcBlockchain | ||
.ForTest(sealEngineType: SealEngineType.Optimism) | ||
.WithBlockchainBridge(bridge) | ||
.WithTxSender(txSender) | ||
.WithOptimismEthRpcModule( | ||
sequencerRpcClient: null /* explicitly using null to behave as Sequencer */, | ||
accountStateProvider: Substitute.For<IAccountStateProvider>(), | ||
ecdsa: new OptimismEthereumEcdsa(ethereumEcdsa), | ||
sealer: Substitute.For<ITxSealer>(), | ||
opSpecHelper: Substitute.For<IOptimismSpecHelper>()) | ||
.Build(); | ||
|
||
Transaction tx = Build.A.Transaction | ||
.Signed(ecdsa: ethereumEcdsa, privateKey: TestItem.PrivateKeyA) | ||
.TestObject; | ||
string serialized = await rpcBlockchain.TestEthRpc("eth_sendRawTransaction", Rlp.Encode(item: tx, behaviors: RlpBehaviors.None).Bytes.ToHexString()); | ||
|
||
await txSender.Received().SendTransaction(tx: Arg.Any<Transaction>(), txHandlingOptions: TxHandlingOptions.PersistentBroadcast); | ||
Assert.That(actual: serialized, expression: Is.EqualTo(expected: $$"""{"jsonrpc":"2.0","result":"{{TestItem.KeccakA.Bytes.ToHexString(withZeroX: true)}}","id":67}""")); | ||
} | ||
} | ||
|
||
internal static class TestRpcBlockchainExt | ||
{ | ||
public static TestRpcBlockchain.Builder<TestRpcBlockchain> WithOptimismEthRpcModule( | ||
this TestRpcBlockchain.Builder<TestRpcBlockchain> @this, | ||
IJsonRpcClient? sequencerRpcClient, | ||
IAccountStateProvider accountStateProvider, | ||
IEthereumEcdsa ecdsa, | ||
ITxSealer sealer, | ||
IOptimismSpecHelper opSpecHelper) | ||
{ | ||
return @this.WithEthRpcModule(blockchain => new OptimismEthRpcModule( | ||
blockchain.RpcConfig, | ||
blockchain.Bridge, | ||
blockchain.BlockFinder, | ||
blockchain.ReceiptFinder, | ||
blockchain.StateReader, | ||
blockchain.TxPool, | ||
blockchain.TxSender, | ||
blockchain.TestWallet, | ||
LimboLogs.Instance, | ||
blockchain.SpecProvider, | ||
blockchain.GasPriceOracle, | ||
new EthSyncingInfo(blockchain.BlockTree, blockchain.ReceiptStorage, new SyncConfig(), | ||
new StaticSelector(SyncMode.All), Substitute.For<ISyncProgressResolver>(), blockchain.LogManager), | ||
blockchain.FeeHistoryOracle ?? | ||
new FeeHistoryOracle(blockchain.BlockTree, blockchain.ReceiptStorage, blockchain.SpecProvider), | ||
new BlocksConfig().SecondsPerSlot, | ||
|
||
sequencerRpcClient, accountStateProvider, ecdsa, sealer, opSpecHelper | ||
)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is pretty much a copy/paste of:
nethermind/src/Nethermind/Nethermind.JsonRpc.Test/Modules/Eth/EthRpcModuleTests.cs
Line 1030 in 2d9dd7c