From c6915376e2ae8f0bc2753f7f92c8bc48f8bf62c7 Mon Sep 17 00:00:00 2001 From: anhnhgutech Date: Mon, 4 Nov 2024 14:37:39 +0700 Subject: [PATCH 1/4] feat: add config to protocols in admin_nodeInfo api --- src/Nethermind/Nethermind.Init/Steps/RegisterRpcModules.cs | 4 +++- .../Nethermind.JsonRpc/Modules/Admin/AdminRpcModule.cs | 7 ++++++- .../Nethermind.JsonRpc/Modules/Admin/EthProtocolInfo.cs | 3 +++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Nethermind/Nethermind.Init/Steps/RegisterRpcModules.cs b/src/Nethermind/Nethermind.Init/Steps/RegisterRpcModules.cs index 5bc4f2ffc9a..570ec346d9b 100644 --- a/src/Nethermind/Nethermind.Init/Steps/RegisterRpcModules.cs +++ b/src/Nethermind/Nethermind.Init/Steps/RegisterRpcModules.cs @@ -132,6 +132,7 @@ public virtual async Task Execute(CancellationToken cancellationToken) ManualPruningTrigger pruningTrigger = new(); _api.PruningTrigger.Add(pruningTrigger); + (IApiWithStores getFromApi, IApiWithBlockchain setInApi) = _api.ForInit; AdminRpcModule adminRpcModule = new( _api.BlockTree, networkConfig, @@ -139,7 +140,8 @@ public virtual async Task Execute(CancellationToken cancellationToken) _api.StaticNodesManager, _api.Enode, initConfig.BaseDbPath, - pruningTrigger); + pruningTrigger, + getFromApi.ChainSpec.Parameters); rpcModuleProvider.RegisterSingle(adminRpcModule); StepDependencyException.ThrowIfNull(_api.TxPoolInfoProvider); diff --git a/src/Nethermind/Nethermind.JsonRpc/Modules/Admin/AdminRpcModule.cs b/src/Nethermind/Nethermind.JsonRpc/Modules/Admin/AdminRpcModule.cs index 22a2e715903..b9a02a646b9 100644 --- a/src/Nethermind/Nethermind.JsonRpc/Modules/Admin/AdminRpcModule.cs +++ b/src/Nethermind/Nethermind.JsonRpc/Modules/Admin/AdminRpcModule.cs @@ -11,12 +11,14 @@ using Nethermind.Core.Crypto; using Nethermind.Network; using Nethermind.Network.Config; +using Nethermind.Specs.ChainSpecStyle; using Nethermind.Stats.Model; namespace Nethermind.JsonRpc.Modules.Admin; public class AdminRpcModule : IAdminRpcModule { + private readonly ChainParameters _parameters; private readonly IBlockTree _blockTree; private readonly INetworkConfig _networkConfig; private readonly IPeerPool _peerPool; @@ -33,7 +35,8 @@ public AdminRpcModule( IStaticNodesManager staticNodesManager, IEnode enode, string dataDir, - ManualPruningTrigger pruningTrigger) + ManualPruningTrigger pruningTrigger, + ChainParameters parameters) { _enode = enode ?? throw new ArgumentNullException(nameof(enode)); _dataDir = dataDir ?? throw new ArgumentNullException(nameof(dataDir)); @@ -42,6 +45,7 @@ public AdminRpcModule( _networkConfig = networkConfig ?? throw new ArgumentNullException(nameof(networkConfig)); _staticNodesManager = staticNodesManager ?? throw new ArgumentNullException(nameof(staticNodesManager)); _pruningTrigger = pruningTrigger; + _parameters = parameters ?? throw new ArgumentNullException(nameof(parameters)); BuildNodeInfo(); } @@ -66,6 +70,7 @@ private void UpdateEthProtocolInfo() _nodeInfo.Protocols["eth"].NewtorkId = _blockTree.ChainId; _nodeInfo.Protocols["eth"].HeadHash = _blockTree.HeadHash; _nodeInfo.Protocols["eth"].GenesisHash = _blockTree.GenesisHash; + _nodeInfo.Protocols["eth"].Config = _parameters; } public async Task> admin_addPeer(string enode, bool addToStaticNodes = false) diff --git a/src/Nethermind/Nethermind.JsonRpc/Modules/Admin/EthProtocolInfo.cs b/src/Nethermind/Nethermind.JsonRpc/Modules/Admin/EthProtocolInfo.cs index 87024cede4c..228f91c7dda 100644 --- a/src/Nethermind/Nethermind.JsonRpc/Modules/Admin/EthProtocolInfo.cs +++ b/src/Nethermind/Nethermind.JsonRpc/Modules/Admin/EthProtocolInfo.cs @@ -3,6 +3,7 @@ using Nethermind.Core.Crypto; using Nethermind.Int256; +using Nethermind.Specs.ChainSpecStyle; using System.Text.Json.Serialization; namespace Nethermind.JsonRpc.Modules.Admin @@ -17,5 +18,7 @@ public class EthProtocolInfo public Hash256 HeadHash { get; set; } [JsonPropertyName("network")] public ulong NewtorkId { get; set; } + [JsonPropertyName("config")] + public ChainParameters Config { get; set; } } } From 2d2a013210beb4a6d0c698dc6f5aba3c09fa3be6 Mon Sep 17 00:00:00 2001 From: anhnhgutech Date: Tue, 5 Nov 2024 16:26:27 +0700 Subject: [PATCH 2/4] update rpc test config --- .../Nethermind.JsonRpc.Test/Modules/AdminModuleTests.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Nethermind/Nethermind.JsonRpc.Test/Modules/AdminModuleTests.cs b/src/Nethermind/Nethermind.JsonRpc.Test/Modules/AdminModuleTests.cs index dc40547d637..9d9c38ed16a 100644 --- a/src/Nethermind/Nethermind.JsonRpc.Test/Modules/AdminModuleTests.cs +++ b/src/Nethermind/Nethermind.JsonRpc.Test/Modules/AdminModuleTests.cs @@ -15,6 +15,7 @@ using Nethermind.Network; using Nethermind.Network.Config; using Nethermind.Serialization.Json; +using Nethermind.Specs.ChainSpecStyle; using Nethermind.Stats.Model; using NSubstitute; using NUnit.Framework; @@ -51,7 +52,8 @@ public void Setup() staticNodesManager, enode, _exampleDataDir, - new ManualPruningTrigger()); + new ManualPruningTrigger(), + new ChainParameters()); _serializer = new EthereumJsonSerializer(); } From e4efbd5b385953220d302701e42bf5c878316f3b Mon Sep 17 00:00:00 2001 From: anhnhgutech Date: Tue, 5 Nov 2024 17:16:35 +0700 Subject: [PATCH 3/4] fix format code --- .../Nethermind.JsonRpc.Test/Modules/AdminModuleTests.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Nethermind/Nethermind.JsonRpc.Test/Modules/AdminModuleTests.cs b/src/Nethermind/Nethermind.JsonRpc.Test/Modules/AdminModuleTests.cs index 9d9c38ed16a..c4af338d7fb 100644 --- a/src/Nethermind/Nethermind.JsonRpc.Test/Modules/AdminModuleTests.cs +++ b/src/Nethermind/Nethermind.JsonRpc.Test/Modules/AdminModuleTests.cs @@ -45,6 +45,11 @@ public void Setup() IStaticNodesManager staticNodesManager = Substitute.For(); Enode enode = new(_enodeString); + ChainSpec chainSpec = new() + { + Parameters = new ChainParameters() + }; + _adminRpcModule = new AdminRpcModule( _blockTree, _networkConfig, @@ -52,8 +57,8 @@ public void Setup() staticNodesManager, enode, _exampleDataDir, - new ManualPruningTrigger(), - new ChainParameters()); + new ManualPruningTrigger(), + chainSpec.Parameters); _serializer = new EthereumJsonSerializer(); } From caecf86f0e22d123370f9298c64485418799b323 Mon Sep 17 00:00:00 2001 From: anhnhgutech Date: Tue, 5 Nov 2024 19:17:29 +0700 Subject: [PATCH 4/4] fix: update test in context mock --- .../Nethermind.Runner.Test/Ethereum/ContextWithMocks.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Nethermind/Nethermind.Runner.Test/Ethereum/ContextWithMocks.cs b/src/Nethermind/Nethermind.Runner.Test/Ethereum/ContextWithMocks.cs index 190f5cfb667..2cbc5284269 100644 --- a/src/Nethermind/Nethermind.Runner.Test/Ethereum/ContextWithMocks.cs +++ b/src/Nethermind/Nethermind.Runner.Test/Ethereum/ContextWithMocks.cs @@ -56,7 +56,7 @@ public static class Build public static NethermindApi ContextWithMocks() { var api = new NethermindApi(Substitute.For(), Substitute.For(), LimboLogs.Instance, - new ChainSpec()) + new ChainSpec { Parameters = new ChainParameters(), }) { Enode = Substitute.For(), TxPool = Substitute.For(),