Skip to content

Commit be7b4ab

Browse files
flcl42MarekM25Alexey Osipov
authored
Patch further versions if 1.13.5 touched the dbs (#4333)
* 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 <[email protected]> Co-authored-by: Alexey Osipov <[email protected]>
1 parent 60aaf7f commit be7b4ab

File tree

8 files changed

+72
-6
lines changed

8 files changed

+72
-6
lines changed

src/Nethermind/Nethermind.Runner/Nethermind.Runner.csproj

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,26 @@
117117
<ItemGroup>
118118
<_ContentIncludedByDefault Remove="Contracts\EntryPoint.json" />
119119
</ItemGroup>
120+
<ItemGroup>
121+
<None Update="runtimes-1.13.5\linux-arm64\native\librocksdb.so">
122+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
123+
</None>
124+
<None Update="runtimes-1.13.5\linux-arm\native\librocksdb.so">
125+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
126+
</None>
127+
<None Update="runtimes-1.13.5\linux-x64\native\librocksdb.so">
128+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
129+
</None>
130+
<None Update="runtimes-1.13.5\osx-arm64\native\librocksdb.dylib">
131+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
132+
</None>
133+
<None Update="runtimes-1.13.5\osx-x64\native\librocksdb.dylib">
134+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
135+
</None>
136+
<None Update="runtimes-1.13.5\win-x64\native\rocksdb.dll">
137+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
138+
</None>
139+
</ItemGroup>
120140

121141
<Target Name="StoreGitHashBeforeBuild" BeforeTargets="BeforeBuild">
122142
<Message Text="---&gt; Generating Git Hash file Before Build" Importance="High" />

src/Nethermind/Nethermind.Runner/Program.cs

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
// Copyright (c) 2021 Demerzel Solutions Limited
22
// This file is part of the Nethermind library.
3-
//
3+
//
44
// The Nethermind library is free software: you can redistribute it and/or modify
55
// it under the terms of the GNU Lesser General Public License as published by
66
// the Free Software Foundation, either version 3 of the License, or
77
// (at your option) any later version.
8-
//
8+
//
99
// The Nethermind library is distributed in the hope that it will be useful,
1010
// but WITHOUT ANY WARRANTY; without even the implied warranty of
1111
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1212
// GNU Lesser General Public License for more details.
13-
//
13+
//
1414
// You should have received a copy of the GNU Lesser General Public License
1515
// along with the Nethermind. If not, see <http://www.gnu.org/licenses/>.
1616

@@ -21,10 +21,12 @@
2121
using System.IO.Abstractions;
2222
using System.Linq;
2323
using System.Reflection;
24+
using System.Runtime.InteropServices;
2425
using System.Text;
2526
using System.Threading;
2627
using System.Threading.Tasks;
2728
using Microsoft.Extensions.CommandLineUtils;
29+
using NativeImport;
2830
using Nethermind.Api;
2931
using Nethermind.Api.Extensions;
3032
using Nethermind.Config;
@@ -142,6 +144,8 @@ private static void Run(string[] args)
142144
Console.CancelKeyPress += ConsoleOnCancelKeyPress;
143145

144146
SetFinalDataDirectory(dataDir.HasValue() ? dataDir.Value() : null, initConfig, keyStoreConfig);
147+
148+
145149
NLogManager logManager = new(initConfig.LogFileName, initConfig.LogDirectory, initConfig.LogRules);
146150

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

158+
PatchRockDbVersion(initConfig.BaseDbPath);
159+
154160
EthereumJsonSerializer serializer = new();
155161
if (_logger.IsDebug) _logger.Debug($"Nethermind config:{Environment.NewLine}{serializer.Serialize(initConfig, true)}{Environment.NewLine}");
156162

@@ -196,6 +202,46 @@ await ethereumRunner.Start(_processCloseCancellationSource.Token).ContinueWith(x
196202
_appClosed.Wait();
197203
}
198204

205+
private static void PatchRockDbVersion(string baseDbPath)
206+
{
207+
void CheckAndPatch(string versiontoPatch, string[] versions)
208+
{
209+
if (!versions.Contains(versiontoPatch))
210+
{
211+
return;
212+
}
213+
214+
_logger.Info($"Patching RocksDB versions: {string.Join(", ", versions)}");
215+
foreach (var file in Directory.GetFiles(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "runtimes-1.13.5"), "*", SearchOption.AllDirectories))
216+
{
217+
File.Copy(file, file.Replace("runtimes-1.13.5", "runtimes"), true);
218+
}
219+
}
220+
221+
try
222+
{
223+
if (!Directory.Exists(baseDbPath))
224+
{
225+
return;
226+
}
227+
228+
var versions = Directory.GetFiles(baseDbPath, "OPTIONS-*", SearchOption.AllDirectories)
229+
.Select(f => File.ReadLines(f).SkipWhile(x => !x.StartsWith(" rocksdb_version=")).First().Replace(" rocksdb_version=", ""))
230+
.Distinct()
231+
.ToArray();
232+
233+
_logger.Info($"RocksDB files versions found: {string.Join(", ", versions)}");
234+
235+
CheckAndPatch("6.15.5", versions);
236+
CheckAndPatch("6.26.1", versions); // TODO: check arm
237+
}
238+
catch(Exception ex)
239+
{
240+
_logger.Warn($"RocksDB patching failed {ex.Message}\n{ex.StackTrace}");
241+
}
242+
}
243+
244+
199245
private static void BuildOptionsFromConfigFiles(CommandLineApplication app)
200246
{
201247
Type configurationType = typeof(IConfig);
@@ -253,7 +299,7 @@ private static string LoadPluginsDirectory(string[] args)
253299
{
254300
string shortCommand = "-pd";
255301
string longCommand = "--pluginsDirectory";
256-
302+
257303
string[] GetPluginArgs()
258304
{
259305
for (int i = 0; i < args.Length; i++)
@@ -267,7 +313,7 @@ string[] GetPluginArgs()
267313

268314
return Array.Empty<string>();
269315
}
270-
316+
271317
CommandLineApplication pluginsApp = new() {Name = "Nethermind.Runner.Plugins"};
272318
CommandOption pluginsAppDirectory = pluginsApp.Option($"{shortCommand}|{longCommand} <pluginsDirectory>", "plugins directory", CommandOptionType.SingleValue);
273319
string pluginDirectory = "plugins";
@@ -462,7 +508,7 @@ private static void ConfigureSeqLogger(IConfigProvider configProvider)
462508
ISeqConfig seqConfig = configProvider.GetConfig<ISeqConfig>();
463509
if (seqConfig.MinLevel != "Off")
464510
{
465-
if (_logger.IsInfo)
511+
if (_logger.IsInfo)
466512
_logger.Info($"Seq Logging enabled on host: {seqConfig.ServerUrl} with level: {seqConfig.MinLevel}");
467513
NLogConfigurator.ConfigureSeqBufferTarget(seqConfig.ServerUrl, seqConfig.ApiKey, seqConfig.MinLevel);
468514
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)