Skip to content
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
56736ef
chore(db): replace rocksdb-sharp with Nethermind.RocksDbBindings
rubo Aug 13, 2026
da8f195
fix(db): handle nullable returns from the RocksDB bindings
rubo Aug 14, 2026
5143e17
chore: update RocksDB package
rubo Aug 14, 2026
3b03d3c
Merge branch 'master' into feature/rocksdb-bindings
rubo Aug 14, 2026
8cae8aa
refactor: replace raw RocksDB interop with the managed bindings API
rubo Aug 16, 2026
b953af0
Merge branch 'master' into feature/rocksdb-bindings
rubo Aug 16, 2026
72ec01a
Merge branch 'master' into feature/rocksdb-bindings
rubo Aug 16, 2026
a7fea59
chore: update the package
rubo Aug 16, 2026
6b3d571
chore: update package
rubo Aug 17, 2026
584fc8e
refactor(db): address review feedback on the bindings migration
rubo Aug 17, 2026
b1fcaed
fix(db): reject a zero block cache capacity
rubo Aug 17, 2026
f6cdf01
Merge branch 'master' into feature/rocksdb-bindings
rubo Aug 17, 2026
f4122b0
refactor(db): read write options through the managed getters
rubo Aug 17, 2026
cc14ece
chore(deps): update RocksDB bindings
rubo Aug 17, 2026
66fea0c
refactor(db): correct stale comments and cover the cache budget confi…
rubo Aug 17, 2026
649da20
Merge branch 'master' into feature/rocksdb-bindings
rubo Aug 17, 2026
cd2197c
Merge branch 'master' into feature/rocksdb-bindings
rubo Aug 18, 2026
5f4847d
Merge branch 'master' into feature/rocksdb-bindings
rubo Aug 18, 2026
14ab26e
chore(deps): update package
rubo Aug 18, 2026
b31e422
fix: update packages.lock.json
rubo Aug 18, 2026
b170044
Merge branch 'master' into feature/rocksdb-bindings
rubo Aug 19, 2026
e433bc5
chore(deps): update package
rubo Aug 19, 2026
b9c22cc
feat(stateless): adopt tests-zkevm v0.8.2 and glamsterdam devnet-8
rubo Aug 19, 2026
68a7e1e
Merge branch 'master' into feature/rocksdb-bindings
rubo Aug 19, 2026
4b81c53
chore: move project into the folder
rubo Aug 19, 2026
1fd67da
test: fix failing test
rubo Aug 19, 2026
9c4801c
Merge branch 'master' into worktree-zkevm-stateless-v0.8
rubo Aug 19, 2026
7d30abe
Merge branch 'master' into worktree-zkevm-stateless-v0.8
rubo Aug 20, 2026
0c263d8
Merge branch 'master' into worktree-zkevm-stateless-v0.8
rubo Aug 20, 2026
fc9af16
refactor(stateless): drop a dead accessor and correct two stale descr…
rubo Aug 20, 2026
6730757
chore: remove stale
rubo Aug 20, 2026
7a716de
Merge branch 'master' into worktree-zkevm-stateless-v0.8
rubo Aug 20, 2026
ae93437
Merge branch 'worktree-zkevm-stateless-v0.8' into feature/rocksdb-bin…
rubo Aug 20, 2026
c814def
fix(db): restore memory pressure balance on abandoned block caches
rubo Aug 20, 2026
e505159
Merge branch 'master' into feature/rocksdb-bindings
rubo Aug 20, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
<PackageVersion Include="Nethermind.Libp2p.Protocols.PubsubPeerDiscovery" Version="1.0.0-preview.45" />
<PackageVersion Include="Nethermind.MclBindings" Version="1.0.5" />
<PackageVersion Include="Nethermind.Numerics.Int256" Version="1.6.0" />
<PackageVersion Include="Nethermind.RocksDbBindings" Version="11.8.1-preview.68" />
Comment thread
rubo marked this conversation as resolved.
Outdated
<PackageVersion Include="Nethermind.TurboPForBindings" Version="1.0.0" />
<PackageVersion Include="Nethermind.Zkvm.Abstractions" Version="1.0.0-preview.2" />
<PackageVersion Include="Nethermind.ZiskOS.Runtime" Version="1.0.0-preview.4" />
Expand All @@ -84,7 +85,6 @@
<PackageVersion Include="Prometheus.Client.MetricPusher" Version="3.3.0" />
<PackageVersion Include="Pyroscope" Version="1.4.0" />
<PackageVersion Include="RichardSzalay.MockHttp" Version="7.0.0" />
<PackageVersion Include="RocksDB" Version="[10.10.1.1747]" />
<PackageVersion Include="SCrypt" Version="2.0.0.2" />
<PackageVersion Include="SlackNet" Version="0.17.9" />
<PackageVersion Include="SmartFormat" Version="3.6.1" />
Expand Down
1 change: 1 addition & 0 deletions nuget.config
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<package pattern="Microsoft.Diagnostics.Runtime.*" />
</packageSource>
<packageSource key="nugettest.org">
<package pattern="Nethermind.RocksDbBindings" />
<package pattern="Nethermind.ZiskOS.Runtime" />
<package pattern="Nethermind.Zkvm.Abstractions" />
</packageSource>
Expand Down
16 changes: 9 additions & 7 deletions src/Nethermind/Nethermind.Db.Rocks/ColumnDb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using Nethermind.Core.Buffers;
using Nethermind.Core.Crypto;
using Nethermind.Core.Extensions;
using RocksDbSharp;
using Nethermind.RocksDbBindings;
using IWriteBatch = Nethermind.Core.IWriteBatch;

namespace Nethermind.Db.Rocks;
Expand All @@ -17,7 +17,7 @@ public class ColumnDb : IDb, ISortedKeyValueStore, IMergeableKeyValueStore, IKey
{
private readonly RocksDb _rocksDb;
internal readonly DbOnTheRocks _mainDb;
internal readonly ColumnFamilyHandle _columnFamily;
internal readonly IColumnFamilyHandle _columnFamily;

private readonly DbOnTheRocks.IteratorManager _iteratorManager;
private readonly RocksDbReader _reader;
Expand Down Expand Up @@ -67,7 +67,7 @@ public void Merge(ReadOnlySpan<byte> key, ReadOnlySpan<byte> value, WriteFlags w
{
get
{
ColumnFamilyHandle[] columnFamilies = new ColumnFamilyHandle[keys.Length];
IColumnFamilyHandle[] columnFamilies = new IColumnFamilyHandle[keys.Length];
Array.Fill(columnFamilies, _columnFamily);
return _rocksDb.MultiGet(keys, columnFamilies);
}
Expand Down Expand Up @@ -137,10 +137,12 @@ public void Compact() =>

public void SetWriteBuffer(long sizeBytes)
{
string[] keys = ["write_buffer_size", "max_bytes_for_level_base"];
string[] values = [sizeBytes.ToString(), (sizeBytes * 4).ToString()];
Native.Instance.rocksdb_set_options_cf(
_rocksDb.Handle, _columnFamily.Handle, keys.Length, keys, values);
KeyValuePair<string, string>[] options =
[
new("write_buffer_size", sizeBytes.ToString()),
new("max_bytes_for_level_base", (sizeBytes * 4).ToString()),
];
_rocksDb.SetOptions(_columnFamily, options);
}

public byte[]? FirstKey
Expand Down
23 changes: 8 additions & 15 deletions src/Nethermind/Nethermind.Db.Rocks/ColumnsDb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
using Nethermind.Core;
using Nethermind.Db.Rocks.Config;
using Nethermind.Logging;
using RocksDbSharp;
using Nethermind.RocksDbBindings;
using IWriteBatch = Nethermind.Core.IWriteBatch;

namespace Nethermind.Db.Rocks;
Expand All @@ -24,12 +24,12 @@ public class ColumnsDb<T> : DbOnTheRocks, IColumnsDb<T> where T : struct, Enum
private volatile T[]? _cachedColumnKeys;
private volatile int _cachedMaxOrdinal = -1;

public ColumnsDb(string basePath, DbSettings settings, IDbConfig dbConfig, IRocksDbConfigFactory rocksDbConfigFactory, ILogManager logManager, IReadOnlyList<T> keys, IntPtr? sharedCache = null)
public ColumnsDb(string basePath, DbSettings settings, IDbConfig dbConfig, IRocksDbConfigFactory rocksDbConfigFactory, ILogManager logManager, IReadOnlyList<T> keys, nint? sharedCache = null)
: this(basePath, settings, dbConfig, rocksDbConfigFactory, logManager, ResolveKeys(keys), sharedCache)
{
}

private ColumnsDb(string basePath, DbSettings settings, IDbConfig dbConfig, IRocksDbConfigFactory rocksDbConfigFactory, ILogManager logManager, (IReadOnlyList<T> Keys, IList<string> ColumnNames) keyInfo, IntPtr? sharedCache)
private ColumnsDb(string basePath, DbSettings settings, IDbConfig dbConfig, IRocksDbConfigFactory rocksDbConfigFactory, ILogManager logManager, (IReadOnlyList<T> Keys, IList<string> ColumnNames) keyInfo, nint? sharedCache)
: base(basePath, settings, dbConfig, rocksDbConfigFactory, logManager, keyInfo.ColumnNames, sharedCache: sharedCache)
{
foreach (T key in keyInfo.Keys)
Expand All @@ -43,11 +43,7 @@ protected override long FetchTotalPropertyValue(string propertyName)
long total = 0;
foreach (KeyValuePair<T, ColumnDb> kv in _columnDbs)
{
long value = long.TryParse(_db.GetProperty(propertyName, kv.Value._columnFamily), out long parsedValue)
? parsedValue
: 0;

total += value;
total += _db.TryGetIntProperty(propertyName, kv.Value._columnFamily, out ulong value) ? (long)value : 0;
}

return total;
Expand Down Expand Up @@ -98,7 +94,7 @@ private static (IReadOnlyList<T> Keys, IList<string> ColumnNames) ResolveKeys(IR
return (resolvedKeys, columnNames);
}

protected override void BuildOptions<TOptions>(IRocksDbConfig dbConfig, Options<TOptions> options, IntPtr? sharedCache, IMergeOperator? mergeOperator)
protected override void BuildOptions<TOptions>(IRocksDbConfig dbConfig, Options<TOptions> options, nint? sharedCache, IMergeOperator? mergeOperator)
{
base.BuildOptions(dbConfig, options, sharedCache, mergeOperator);
options.SetCreateMissingColumnFamilies();
Expand All @@ -114,11 +110,9 @@ protected override void BuildOptions<TOptions>(IRocksDbConfig dbConfig, Options<

protected override void ApplyOptions(IDictionary<string, string> options)
{
string[] keys = options.Select<KeyValuePair<string, string>, string>(static e => e.Key).ToArray();
string[] values = options.Select<KeyValuePair<string, string>, string>(static e => e.Value).ToArray();
foreach (KeyValuePair<T, ColumnDb> cols in _columnDbs)
{
_rocksDbNative.rocksdb_set_options_cf(_db.Handle, cols.Value._columnFamily.Handle, keys.Length, keys, values);
_db.SetOptions(cols.Value._columnFamily, options);
}
base.ApplyOptions(options);
}
Expand Down Expand Up @@ -263,9 +257,8 @@ public void Dispose()
if (Interlocked.Exchange(ref _disposed, 1) != 0) return;

// Explicitly destroy native ReadOptions handles to prevent finalizer queue buildup.
// GC.SuppressFinalize prevents the finalizer from running on already-destroyed handles.
RocksDbReader.DestroyReadOptions(_sharedReadOptions);
RocksDbReader.DestroyReadOptions(_sharedCacheMissReadOptions);
_sharedReadOptions.Dispose();
_sharedCacheMissReadOptions.Dispose();
Comment thread
rubo marked this conversation as resolved.

_snapshot.Dispose();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
// SPDX-FileCopyrightText: 2025 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using System;

namespace Nethermind.Db.Rocks.Config;

public class AdjustedRocksdbConfig(
IRocksDbConfig baseConfig,
string additionalRocksDbOptions,
ulong writeBufferSize,
IntPtr? blockCache = null
nint? blockCache = null
) : IRocksDbConfig
{
public ulong? WriteBufferSize => writeBufferSize;
Expand Down Expand Up @@ -40,5 +38,5 @@ public class AdjustedRocksdbConfig(
public double CompressibilityHint => baseConfig.CompressibilityHint;

public FlushOnExitMode FlushOnExit => baseConfig.FlushOnExit;
public IntPtr? BlockCache => blockCache ?? baseConfig.BlockCache;
public nint? BlockCache => blockCache ?? baseConfig.BlockCache;
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// SPDX-FileCopyrightText: 2025 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using System;

namespace Nethermind.Db.Rocks.Config;

public interface IRocksDbConfig
Expand All @@ -21,5 +19,5 @@ public interface IRocksDbConfig
bool EnableFileWarmer { get; }
double CompressibilityHint { get; }
FlushOnExitMode FlushOnExit { get; }
IntPtr? BlockCache { get; }
nint? BlockCache { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private void EnsureConfigIsAvailable(string propertyName)
public bool EnableFileWarmer => ReadConfig<bool>(nameof(EnableFileWarmer));
public double CompressibilityHint => ReadConfig<double>(nameof(CompressibilityHint));
public FlushOnExitMode FlushOnExit => ReadConfig<FlushOnExitMode?>(nameof(FlushOnExit)) ?? FlushOnExitMode.WalOnly;
public IntPtr? BlockCache => null;
public nint? BlockCache => null;

private T? ReadConfig<T>(string propertyName) => ReadConfig<T>(_dbConfig, propertyName, _reversedPrefixes);

Expand Down
Loading
Loading