1
1
// Copyright (c) 2021 Demerzel Solutions Limited
2
2
// This file is part of the Nethermind library.
3
- //
3
+ //
4
4
// The Nethermind library is free software: you can redistribute it and/or modify
5
5
// it under the terms of the GNU Lesser General Public License as published by
6
6
// the Free Software Foundation, either version 3 of the License, or
7
7
// (at your option) any later version.
8
- //
8
+ //
9
9
// The Nethermind library is distributed in the hope that it will be useful,
10
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
12
// GNU Lesser General Public License for more details.
13
- //
13
+ //
14
14
// You should have received a copy of the GNU Lesser General Public License
15
15
// along with the Nethermind. If not, see <http://www.gnu.org/licenses/>.
16
16
21
21
using System . IO . Abstractions ;
22
22
using System . Linq ;
23
23
using System . Reflection ;
24
+ using System . Runtime . InteropServices ;
24
25
using System . Text ;
25
26
using System . Threading ;
26
27
using System . Threading . Tasks ;
27
28
using Microsoft . Extensions . CommandLineUtils ;
29
+ using NativeImport ;
28
30
using Nethermind . Api ;
29
31
using Nethermind . Api . Extensions ;
30
32
using Nethermind . Config ;
@@ -142,6 +144,8 @@ private static void Run(string[] args)
142
144
Console . CancelKeyPress += ConsoleOnCancelKeyPress ;
143
145
144
146
SetFinalDataDirectory ( dataDir . HasValue ( ) ? dataDir . Value ( ) : null , initConfig , keyStoreConfig ) ;
147
+
148
+
145
149
NLogManager logManager = new ( initConfig . LogFileName , initConfig . LogDirectory , initConfig . LogRules ) ;
146
150
147
151
_logger = logManager . GetClassLogger ( ) ;
@@ -151,6 +155,8 @@ private static void Run(string[] args)
151
155
SetFinalDbPath ( dbBasePath . HasValue ( ) ? dbBasePath . Value ( ) : null , initConfig ) ;
152
156
LogMemoryConfiguration ( ) ;
153
157
158
+ PatchRockDbVersion ( initConfig . BaseDbPath ) ;
159
+
154
160
EthereumJsonSerializer serializer = new ( ) ;
155
161
if ( _logger . IsDebug ) _logger . Debug ( $ "Nethermind config:{ Environment . NewLine } { serializer . Serialize ( initConfig , true ) } { Environment . NewLine } ") ;
156
162
@@ -196,6 +202,46 @@ await ethereumRunner.Start(_processCloseCancellationSource.Token).ContinueWith(x
196
202
_appClosed . Wait ( ) ;
197
203
}
198
204
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
+
199
245
private static void BuildOptionsFromConfigFiles ( CommandLineApplication app )
200
246
{
201
247
Type configurationType = typeof ( IConfig ) ;
@@ -253,7 +299,7 @@ private static string LoadPluginsDirectory(string[] args)
253
299
{
254
300
string shortCommand = "-pd" ;
255
301
string longCommand = "--pluginsDirectory" ;
256
-
302
+
257
303
string [ ] GetPluginArgs ( )
258
304
{
259
305
for ( int i = 0 ; i < args . Length ; i ++ )
@@ -267,7 +313,7 @@ string[] GetPluginArgs()
267
313
268
314
return Array . Empty < string > ( ) ;
269
315
}
270
-
316
+
271
317
CommandLineApplication pluginsApp = new ( ) { Name = "Nethermind.Runner.Plugins" } ;
272
318
CommandOption pluginsAppDirectory = pluginsApp . Option ( $ "{ shortCommand } |{ longCommand } <pluginsDirectory>", "plugins directory" , CommandOptionType . SingleValue ) ;
273
319
string pluginDirectory = "plugins" ;
@@ -462,7 +508,7 @@ private static void ConfigureSeqLogger(IConfigProvider configProvider)
462
508
ISeqConfig seqConfig = configProvider . GetConfig < ISeqConfig > ( ) ;
463
509
if ( seqConfig . MinLevel != "Off" )
464
510
{
465
- if ( _logger . IsInfo )
511
+ if ( _logger . IsInfo )
466
512
_logger . Info ( $ "Seq Logging enabled on host: { seqConfig . ServerUrl } with level: { seqConfig . MinLevel } ") ;
467
513
NLogConfigurator . ConfigureSeqBufferTarget ( seqConfig . ServerUrl , seqConfig . ApiKey , seqConfig . MinLevel ) ;
468
514
}
0 commit comments