Skip to content

Commit

Permalink
add engine_getClientVersionV1 API support (#6814)
Browse files Browse the repository at this point in the history
  • Loading branch information
rjnrohit authored Mar 5, 2024
1 parent fdc62b0 commit 37ef033
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 0 deletions.
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,15 @@ 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.Should().BeEquivalentTo([new ClientVersionV1()]);
}

[Test]
public async Task Should_return_capabilities()
{
Expand Down Expand Up @@ -1544,6 +1553,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
27 changes: 27 additions & 0 deletions src/Nethermind/Nethermind.Merge.Plugin/Data/ClientVersionV1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// 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()
{
Code = ProductInfo.ClientCode;
Name = ProductInfo.Name;
Version = ProductInfo.Version;
Commit = ProductInfo.Commit;
}

public string Code { get; }
public string Name { get; }
public string Version { get; }
public string Commit { get; }
}

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, false);
#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);
}

0 comments on commit 37ef033

Please sign in to comment.