From f04857bf7159c336d15f46a67ab426fca5f53c94 Mon Sep 17 00:00:00 2001 From: Ruben Buniatyan Date: Mon, 3 Jun 2024 16:26:39 +0200 Subject: [PATCH 1/2] Revise git commit hash handling --- Dockerfile | 1 - Dockerfile.chiseled | 1 - Dockerfile.diag | 1 - src/Nethermind/Directory.Build.props | 6 +-- src/Nethermind/Directory.Packages.props | 3 +- src/Nethermind/Nethermind.Core/ProductInfo.cs | 37 +++++++++++-------- .../EngineModuleTests.V1.cs | 1 - .../Data/ClientVersionV1.cs | 4 +- .../Nethermind.Runner.csproj | 25 ++----------- 9 files changed, 31 insertions(+), 48 deletions(-) diff --git a/Dockerfile b/Dockerfile index eeaf6602ab6..ccdea679109 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,7 +9,6 @@ ARG CI ARG COMMIT_HASH ARG TARGETARCH -COPY .git .git COPY src/Nethermind src/Nethermind RUN arch=$([ "$TARGETARCH" = "amd64" ] && echo "x64" || echo "$TARGETARCH") && \ diff --git a/Dockerfile.chiseled b/Dockerfile.chiseled index 7d7b570e966..936c78877dc 100644 --- a/Dockerfile.chiseled +++ b/Dockerfile.chiseled @@ -9,7 +9,6 @@ ARG CI ARG COMMIT_HASH ARG TARGETARCH -COPY .git .git COPY src/Nethermind src/Nethermind RUN arch=$([ "$TARGETARCH" = "amd64" ] && echo "x64" || echo "$TARGETARCH") && \ diff --git a/Dockerfile.diag b/Dockerfile.diag index a2d952143b9..768e8fa9c2e 100644 --- a/Dockerfile.diag +++ b/Dockerfile.diag @@ -9,7 +9,6 @@ ARG CI ARG COMMIT_HASH ARG TARGETARCH -COPY .git .git COPY src/Nethermind src/Nethermind RUN arch=$([ "$TARGETARCH" = "amd64" ] && echo "x64" || echo "$TARGETARCH") && \ diff --git a/src/Nethermind/Directory.Build.props b/src/Nethermind/Directory.Build.props index 44dcc89eb8c..b1ac734da65 100644 --- a/src/Nethermind/Directory.Build.props +++ b/src/Nethermind/Directory.Build.props @@ -13,7 +13,7 @@ $([System.DateTimeOffset]::UtcNow.ToUnixTimeSeconds()) Demerzel Solutions Limited Nethermind - $(Commit.Substring(0, 8)) + $(Commit) 1.27.0 unstable @@ -23,10 +23,6 @@ <_Parameter1>BuildTimestamp <_Parameter2>$(BuildTimestamp) - - <_Parameter1>Commit - <_Parameter2>$(Commit) - diff --git a/src/Nethermind/Directory.Packages.props b/src/Nethermind/Directory.Packages.props index cb88a1ae0d9..5d784e7530d 100644 --- a/src/Nethermind/Directory.Packages.props +++ b/src/Nethermind/Directory.Packages.props @@ -28,6 +28,7 @@ + @@ -76,4 +77,4 @@ - + \ No newline at end of file diff --git a/src/Nethermind/Nethermind.Core/ProductInfo.cs b/src/Nethermind/Nethermind.Core/ProductInfo.cs index 9cbf70bb8e9..85ecf6f451a 100644 --- a/src/Nethermind/Nethermind.Core/ProductInfo.cs +++ b/src/Nethermind/Nethermind.Core/ProductInfo.cs @@ -4,34 +4,39 @@ using System; using System.Linq; using System.Reflection; -using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -[assembly: InternalsVisibleTo("Nethermind.Merge.Plugin.Test")] namespace Nethermind.Core; public static class ProductInfo { static ProductInfo() { - var assembly = Assembly.GetEntryAssembly(); - var infoAttr = assembly?.GetCustomAttribute(); - var metadataAttrs = assembly?.GetCustomAttributes(); - var productAttr = assembly?.GetCustomAttribute(); - var commit = metadataAttrs?.FirstOrDefault(a => a.Key.Equals("Commit", StringComparison.Ordinal))?.Value; + var assembly = Assembly.GetEntryAssembly()!; + var metadataAttrs = assembly.GetCustomAttributes()!; + var productAttr = assembly.GetCustomAttribute()!; + var versionAttr = assembly.GetCustomAttribute()!; var timestamp = metadataAttrs?.FirstOrDefault(a => a.Key.Equals("BuildTimestamp", StringComparison.Ordinal))?.Value; BuildTimestamp = long.TryParse(timestamp, out var t) ? DateTimeOffset.FromUnixTimeSeconds(t) : DateTimeOffset.MinValue; - Commit = commit ?? string.Empty; Name = productAttr?.Product ?? "Nethermind"; OS = Platform.GetPlatformName(); OSArchitecture = RuntimeInformation.OSArchitecture.ToString().ToLowerInvariant(); Runtime = RuntimeInformation.FrameworkDescription; - Version = infoAttr?.InformationalVersion ?? string.Empty; - ClientCode = "NM"; + var version = versionAttr.InformationalVersion; + var index = version.IndexOf('+', StringComparison.Ordinal); + + if (index == -1) + Version = version; + else + { + Commit = version[(index + 1)..]; + Version = version[..Math.Min(index + 9, version.Length - 1)]; + } + ClientId = $"{Name}/v{Version}/{OS.ToLowerInvariant()}-{OSArchitecture}/dotnet{Runtime[5..]}"; } @@ -39,9 +44,9 @@ static ProductInfo() public static string ClientId { get; } - public static string ClientCode { get; } + public static string ClientCode { get; } = "NM"; - public static string Commit { get; internal set; } + public static string Commit { get; set; } = string.Empty; public static string Name { get; } @@ -53,11 +58,11 @@ static ProductInfo() public static string Version { get; } - public static string Network { get; set; } = ""; + public static string Network { get; set; } = string.Empty; - public static string Instance { get; set; } = ""; + public static string Instance { get; set; } = string.Empty; - public static string SyncType { get; set; } = ""; + public static string SyncType { get; set; } = string.Empty; - public static string PruningMode { get; set; } = ""; + public static string PruningMode { get; set; } = string.Empty; } diff --git a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V1.cs b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V1.cs index 43b6793f1d1..bfd1368d636 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V1.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin.Test/EngineModuleTests.V1.cs @@ -1520,7 +1520,6 @@ await rpc.engine_forkchoiceUpdatedV1(forkChoiceState1, [Test] public async Task Should_return_ClientVersionV1() { - ProductInfo.Commit = "0000000000000000000000000000000000000000000000000000000000000000"; using MergeTestBlockchain chain = await CreateBlockchain(); IEngineRpcModule rpcModule = CreateEngineModule(chain); ResultWrapper result = rpcModule.engine_getClientVersionV1(new ClientVersionV1()); diff --git a/src/Nethermind/Nethermind.Merge.Plugin/Data/ClientVersionV1.cs b/src/Nethermind/Nethermind.Merge.Plugin/Data/ClientVersionV1.cs index c6e5a853031..e2108102c3f 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin/Data/ClientVersionV1.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin/Data/ClientVersionV1.cs @@ -16,7 +16,9 @@ public ClientVersionV1() Code = ProductInfo.ClientCode; Name = ProductInfo.Name; Version = ProductInfo.Version; - Commit = ProductInfo.Commit[..8]; + Commit = ProductInfo.Commit.Length < 8 + ? string.Empty.PadLeft(8, '0') + : ProductInfo.Commit[..8]; } public string Code { get; } diff --git a/src/Nethermind/Nethermind.Runner/Nethermind.Runner.csproj b/src/Nethermind/Nethermind.Runner/Nethermind.Runner.csproj index 52b6fa2c85d..e675b2dbd2e 100644 --- a/src/Nethermind/Nethermind.Runner/Nethermind.Runner.csproj +++ b/src/Nethermind/Nethermind.Runner/Nethermind.Runner.csproj @@ -21,6 +21,10 @@ + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + @@ -106,25 +110,4 @@ - - - - - - $(Commit.Substring(0, 8)) - - - - <_Parameter1>Commit - <_Parameter2>$(Commit) - - - - - - - - - - From ecfd954ad86206a723094403a685507a57d9b3f1 Mon Sep 17 00:00:00 2001 From: Ruben Buniatyan Date: Mon, 3 Jun 2024 16:50:50 +0200 Subject: [PATCH 2/2] Shorten commit check --- src/Nethermind/Nethermind.Core/ProductInfo.cs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/Nethermind/Nethermind.Core/ProductInfo.cs b/src/Nethermind/Nethermind.Core/ProductInfo.cs index 85ecf6f451a..b23e63c3006 100644 --- a/src/Nethermind/Nethermind.Core/ProductInfo.cs +++ b/src/Nethermind/Nethermind.Core/ProductInfo.cs @@ -25,16 +25,14 @@ static ProductInfo() OS = Platform.GetPlatformName(); OSArchitecture = RuntimeInformation.OSArchitecture.ToString().ToLowerInvariant(); Runtime = RuntimeInformation.FrameworkDescription; + Version = versionAttr.InformationalVersion; - var version = versionAttr.InformationalVersion; - var index = version.IndexOf('+', StringComparison.Ordinal); + var index = Version.IndexOf('+', StringComparison.Ordinal); - if (index == -1) - Version = version; - else + if (index != -1) { - Commit = version[(index + 1)..]; - Version = version[..Math.Min(index + 9, version.Length - 1)]; + Commit = Version[(index + 1)..]; + Version = Version[..Math.Min(index + 9, Version.Length - 1)]; } ClientId = $"{Name}/v{Version}/{OS.ToLowerInvariant()}-{OSArchitecture}/dotnet{Runtime[5..]}";