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 engine_getClientVersionV1 API support #6814

Merged
merged 3 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Nethermind/Nethermind.Core/ProductInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,16 @@ static ProductInfo()
Runtime = RuntimeInformation.FrameworkDescription;
Version = infoAttr?.InformationalVersion ?? string.Empty;

ClientCode = "NM";
ClientId = $"{Name}/v{Version}/{OS.ToLowerInvariant()}-{OSArchitecture}/dotnet{Runtime[5..]}";
}

public static DateTimeOffset BuildTimestamp { get; }

public static string ClientId { get; }

public static string ClientCode { get; }

public static string Commit { get; }

public static string Name { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1517,6 +1517,18 @@ await rpc.engine_forkchoiceUpdatedV1(forkChoiceState1,
}
}

[Test]
public async Task Should_return_ClientVersionV1()
{
using MergeTestBlockchain chain = await CreateBlockchain();
IEngineRpcModule rpcModule = CreateEngineModule(chain);
ResultWrapper<ClientVersionV1[]> result = rpcModule.engine_getClientVersionV1(new ClientVersionV1());
result.Data[0].code.Should().Be(ProductInfo.ClientCode);
result.Data[0].version.Should().Be(ProductInfo.Version);
result.Data[0].name.Should().Be(ProductInfo.Name);
result.Data[0].commit.Should().Be(ProductInfo.Commit);
rjnrohit marked this conversation as resolved.
Show resolved Hide resolved
}

[Test]
public async Task Should_return_capabilities()
{
Expand Down Expand Up @@ -1544,6 +1556,8 @@ public void Should_return_expected_capabilities_for_mainnet()
string[] result = exchangeCapabilitiesHandler.Handle(Array.Empty<string>()).Data.ToArray();
var expectedMethods = new string[]
{
nameof(IEngineRpcModule.engine_getClientVersionV1),

nameof(IEngineRpcModule.engine_getPayloadV1),
nameof(IEngineRpcModule.engine_forkchoiceUpdatedV1),
nameof(IEngineRpcModule.engine_newPayloadV1),
Expand Down
31 changes: 31 additions & 0 deletions src/Nethermind/Nethermind.Merge.Plugin/Data/ClientVersionV1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using Nethermind.Core;

namespace Nethermind.Merge.Plugin.Data;

/// <summary>
/// The client version specification.
/// <seealso cref="https://github.com/ethereum/execution-apis/pull/517/files?short_path=f1e647c#diff-f1e647ce063c92e6fd6cd448746b1d1effcfd2fa2e1b031a71f8ce2f74ba0952"/>
/// </summary>
public readonly struct ClientVersionV1
{
public ClientVersionV1()
{
this.code = ProductInfo.ClientCode;
this.name = ProductInfo.Name;
this.version = ProductInfo.Version;
this.commit = ProductInfo.Commit;
rjnrohit marked this conversation as resolved.
Show resolved Hide resolved
}

public string code { get; }
public string name { get; }
public string version { get; }
public string commit { get; }
rjnrohit marked this conversation as resolved.
Show resolved Hide resolved

public override string ToString() => $"{name}/v{version}/{code}";

public string ToJson() => $"{{\"code\":\"{code}\",\"name\":\"{name}\",\"version\":\"{version}\",\"commit\":\"{commit}\"}}";
rjnrohit marked this conversation as resolved.
Show resolved Hide resolved
}

5 changes: 5 additions & 0 deletions src/Nethermind/Nethermind.Merge.Plugin/EngineRpcModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,9 @@ public EngineRpcModule(

public ResultWrapper<IEnumerable<string>> engine_exchangeCapabilities(IEnumerable<string> methods)
=> _capabilitiesHandler.Handle(methods);

public ResultWrapper<ClientVersionV1[]> engine_getClientVersionV1(ClientVersionV1 clientVersionV1)
{
return ResultWrapper<ClientVersionV1[]>.Success([new ClientVersionV1()]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public EngineRpcCapabilitiesProvider(ISpecProvider specProvider)
_capabilities[nameof(IEngineRpcModule.engine_forkchoiceUpdatedV1)] = (true, true);
_capabilities[nameof(IEngineRpcModule.engine_getPayloadV1)] = (true, true);
_capabilities[nameof(IEngineRpcModule.engine_newPayloadV1)] = (true, true);
_capabilities[nameof(IEngineRpcModule.engine_getClientVersionV1)] = (true, true);
rjnrohit marked this conversation as resolved.
Show resolved Hide resolved
#endregion

#region Shanghai
Expand Down
8 changes: 8 additions & 0 deletions src/Nethermind/Nethermind.Merge.Plugin/IEngineRpcModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Collections.Generic;
using Nethermind.JsonRpc;
using Nethermind.JsonRpc.Modules;
using Nethermind.Merge.Plugin.Data;

namespace Nethermind.Merge.Plugin;

Expand All @@ -15,4 +16,11 @@ public partial interface IEngineRpcModule : IRpcModule
IsSharable = true,
IsImplemented = true)]
ResultWrapper<IEnumerable<string>> engine_exchangeCapabilities(IEnumerable<string> methods);

[JsonRpcMethod(
Description = "Returns the client version specification.",
IsSharable = true,
IsImplemented = true)]

ResultWrapper<ClientVersionV1[]> engine_getClientVersionV1(ClientVersionV1 clientVersionV1);
}