Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix RpcDB connection so one can attach local Instance to remote DB for debugging purpose #8049

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
5 changes: 4 additions & 1 deletion src/Nethermind/Nethermind.Db.Rpc/RpcDb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;
using Nethermind.Core;
using Nethermind.Core.Extensions;
using Nethermind.JsonRpc;
Expand Down Expand Up @@ -96,7 +97,9 @@ private byte[] GetThroughRpc(ReadOnlySpan<byte> key)
byte[] value = null;
if (response.Result is not null)
{
value = Bytes.FromHexString((string)response.Result);
JsonElement jsonElement = (JsonElement)response.Result;
string rawHex = jsonElement.GetString();
value = Bytes.FromHexString(rawHex);
kamilchodola marked this conversation as resolved.
Show resolved Hide resolved
if (_recordDb is not null)
{
_recordDb[key] = value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private DbSettings GetRocksDbSettings(DbSettings originalSetting)
bool firstDb = _index == -1;

// if first DB, then we will put it into main directory and not use indexed subdirectory
string dbName = firstDb ? originalSetting.DbName : originalSetting.DbName + _index;
string dbName = originalSetting.DbName;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmmm, my intuition is telling me that it could cause issues with full-pruning

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah wrote to Ashraf already as was not confident about this one

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But path still point to proper location - just DbName is different - without this change RPC was looking for a DB called "State0"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be fine 'Path' is more important and 'Name' is mostly for our convenience. You might want to change FullPruningInnerDbFactoryTests.MatchSettings

string dbPath = firstDb ? originalSetting.DbPath : _fileSystem.Path.Combine(originalSetting.DbPath, _index.ToString());
DbSettings dbSettings = originalSetting.Clone(dbName, dbPath);
dbSettings.CanDeleteFolder = !firstDb; // we cannot delete main db folder, only indexed subfolders
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ public DebugBridge(
IDb headersDb = dbProvider.HeadersDb ?? throw new ArgumentNullException(nameof(dbProvider.HeadersDb));
IDb codeDb = dbProvider.CodeDb ?? throw new ArgumentNullException(nameof(dbProvider.CodeDb));
IDb metadataDb = dbProvider.MetadataDb ?? throw new ArgumentNullException(nameof(dbProvider.MetadataDb));
IDb blockNumbersDb = dbProvider.BlockNumbersDb ?? throw new ArgumentNullException(nameof(dbProvider.BlockNumbersDb));
IDb bloomDb = dbProvider.BloomDb ?? throw new ArgumentNullException(nameof(dbProvider.BloomDb));

_dbMappings = new Dictionary<string, IDb>(StringComparer.InvariantCultureIgnoreCase)
{
Expand All @@ -70,6 +72,9 @@ public DebugBridge(
{DbNames.Headers, headersDb},
{DbNames.Metadata, metadataDb},
{DbNames.Code, codeDb},
{DbNames.Blocks, blocksDb},
{DbNames.BlockNumbers, blockNumbersDb},
{DbNames.Bloom, bloomDb},
};

_blockStore = new BlockStore(blocksDb);
Expand Down
Loading