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

Add config to protocols in admin_nodeInfo api #7707

Merged
Merged
4 changes: 3 additions & 1 deletion src/Nethermind/Nethermind.Init/Steps/RegisterRpcModules.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,16 @@ 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,
_api.PeerPool,
_api.StaticNodesManager,
_api.Enode,
initConfig.BaseDbPath,
pruningTrigger);
pruningTrigger,
getFromApi.ChainSpec.Parameters);
rpcModuleProvider.RegisterSingle<IAdminRpcModule>(adminRpcModule);

StepDependencyException.ThrowIfNull(_api.TxPoolInfoProvider);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -44,14 +45,20 @@ public void Setup()

IStaticNodesManager staticNodesManager = Substitute.For<IStaticNodesManager>();
Enode enode = new(_enodeString);
ChainSpec chainSpec = new()
{
Parameters = new ChainParameters()
};

_adminRpcModule = new AdminRpcModule(
_blockTree,
_networkConfig,
peerPool,
staticNodesManager,
enode,
_exampleDataDir,
new ManualPruningTrigger());
new ManualPruningTrigger(),
chainSpec.Parameters);

_serializer = new EthereumJsonSerializer();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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));
Expand All @@ -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();
}
Expand Down Expand Up @@ -71,6 +75,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<ResultWrapper<string>> admin_addPeer(string enode, bool addToStaticNodes = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static class Build
public static NethermindApi ContextWithMocks()
{
var api = new NethermindApi(Substitute.For<IConfigProvider>(), Substitute.For<IJsonSerializer>(), LimboLogs.Instance,
new ChainSpec())
new ChainSpec { Parameters = new ChainParameters(), })
{
Enode = Substitute.For<IEnode>(),
TxPool = Substitute.For<ITxPool>(),
Expand Down