Skip to content

Commit

Permalink
Patch further versions if 1.13.5 touched the dbs (#4333)
Browse files Browse the repository at this point in the history
* Patch further versions if 1.13.5 touched the dbs

* Clearer text

* Add patching

* Add logging, confirm MacOS

* Add directory check

* logger change

* Fix dbPath calculation

* Simplify version check

Co-authored-by: MarekM25 <marekm2504@gmail.com>
Co-authored-by: Alexey Osipov <alexey.osipov@flcl.me>
  • Loading branch information
3 people authored Jul 30, 2022
1 parent 60aaf7f commit be7b4ab
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 6 deletions.
20 changes: 20 additions & 0 deletions src/Nethermind/Nethermind.Runner/Nethermind.Runner.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,26 @@
<ItemGroup>
<_ContentIncludedByDefault Remove="Contracts\EntryPoint.json" />
</ItemGroup>
<ItemGroup>
<None Update="runtimes-1.13.5\linux-arm64\native\librocksdb.so">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="runtimes-1.13.5\linux-arm\native\librocksdb.so">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="runtimes-1.13.5\linux-x64\native\librocksdb.so">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="runtimes-1.13.5\osx-arm64\native\librocksdb.dylib">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="runtimes-1.13.5\osx-x64\native\librocksdb.dylib">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="runtimes-1.13.5\win-x64\native\rocksdb.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

<Target Name="StoreGitHashBeforeBuild" BeforeTargets="BeforeBuild">
<Message Text="---&gt; Generating Git Hash file Before Build" Importance="High" />
Expand Down
58 changes: 52 additions & 6 deletions src/Nethermind/Nethermind.Runner/Program.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// Copyright (c) 2021 Demerzel Solutions Limited
// This file is part of the Nethermind library.
//
//
// The Nethermind library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
//
// The Nethermind library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
//
// You should have received a copy of the GNU Lesser General Public License
// along with the Nethermind. If not, see <http://www.gnu.org/licenses/>.

Expand All @@ -21,10 +21,12 @@
using System.IO.Abstractions;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.CommandLineUtils;
using NativeImport;
using Nethermind.Api;
using Nethermind.Api.Extensions;
using Nethermind.Config;
Expand Down Expand Up @@ -142,6 +144,8 @@ private static void Run(string[] args)
Console.CancelKeyPress += ConsoleOnCancelKeyPress;

SetFinalDataDirectory(dataDir.HasValue() ? dataDir.Value() : null, initConfig, keyStoreConfig);


NLogManager logManager = new(initConfig.LogFileName, initConfig.LogDirectory, initConfig.LogRules);

_logger = logManager.GetClassLogger();
Expand All @@ -151,6 +155,8 @@ private static void Run(string[] args)
SetFinalDbPath(dbBasePath.HasValue() ? dbBasePath.Value() : null, initConfig);
LogMemoryConfiguration();

PatchRockDbVersion(initConfig.BaseDbPath);

EthereumJsonSerializer serializer = new();
if (_logger.IsDebug) _logger.Debug($"Nethermind config:{Environment.NewLine}{serializer.Serialize(initConfig, true)}{Environment.NewLine}");

Expand Down Expand Up @@ -196,6 +202,46 @@ await ethereumRunner.Start(_processCloseCancellationSource.Token).ContinueWith(x
_appClosed.Wait();
}

private static void PatchRockDbVersion(string baseDbPath)
{
void CheckAndPatch(string versiontoPatch, string[] versions)
{
if (!versions.Contains(versiontoPatch))
{
return;
}

_logger.Info($"Patching RocksDB versions: {string.Join(", ", versions)}");
foreach (var file in Directory.GetFiles(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "runtimes-1.13.5"), "*", SearchOption.AllDirectories))
{
File.Copy(file, file.Replace("runtimes-1.13.5", "runtimes"), true);
}
}

try
{
if (!Directory.Exists(baseDbPath))
{
return;
}

var versions = Directory.GetFiles(baseDbPath, "OPTIONS-*", SearchOption.AllDirectories)
.Select(f => File.ReadLines(f).SkipWhile(x => !x.StartsWith(" rocksdb_version=")).First().Replace(" rocksdb_version=", ""))
.Distinct()
.ToArray();

_logger.Info($"RocksDB files versions found: {string.Join(", ", versions)}");

CheckAndPatch("6.15.5", versions);
CheckAndPatch("6.26.1", versions); // TODO: check arm
}
catch(Exception ex)
{
_logger.Warn($"RocksDB patching failed {ex.Message}\n{ex.StackTrace}");
}
}


private static void BuildOptionsFromConfigFiles(CommandLineApplication app)
{
Type configurationType = typeof(IConfig);
Expand Down Expand Up @@ -253,7 +299,7 @@ private static string LoadPluginsDirectory(string[] args)
{
string shortCommand = "-pd";
string longCommand = "--pluginsDirectory";

string[] GetPluginArgs()
{
for (int i = 0; i < args.Length; i++)
Expand All @@ -267,7 +313,7 @@ string[] GetPluginArgs()

return Array.Empty<string>();
}

CommandLineApplication pluginsApp = new() {Name = "Nethermind.Runner.Plugins"};
CommandOption pluginsAppDirectory = pluginsApp.Option($"{shortCommand}|{longCommand} <pluginsDirectory>", "plugins directory", CommandOptionType.SingleValue);
string pluginDirectory = "plugins";
Expand Down Expand Up @@ -462,7 +508,7 @@ private static void ConfigureSeqLogger(IConfigProvider configProvider)
ISeqConfig seqConfig = configProvider.GetConfig<ISeqConfig>();
if (seqConfig.MinLevel != "Off")
{
if (_logger.IsInfo)
if (_logger.IsInfo)
_logger.Info($"Seq Logging enabled on host: {seqConfig.ServerUrl} with level: {seqConfig.MinLevel}");
NLogConfigurator.ConfigureSeqBufferTarget(seqConfig.ServerUrl, seqConfig.ApiKey, seqConfig.MinLevel);
}
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit be7b4ab

Please sign in to comment.