Skip to content

Commit

Permalink
Separate blocks and transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
asdacap committed Jun 4, 2024
1 parent 50566e2 commit b2062d1
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 16 deletions.
12 changes: 8 additions & 4 deletions src/Nethermind/Nethermind.Db.Rocks/Config/PerTableDbConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,14 @@ private string[] GetPrefixes()
if (propertyInfo.PropertyType.CanBeAssignedNull())
{
// If its nullable check if its null first
T? val = (T?)propertyInfo.GetValue(dbConfig);
if (val is not null)
object? valObj = propertyInfo.GetValue(dbConfig);
if (valObj is not null)
{
return val;
T? val = (T?)valObj;
if (val is not null)
{
return val;
}
}
}
else
Expand All @@ -132,7 +136,7 @@ private string[] GetPrefixes()
}
catch (Exception e)
{
throw new InvalidDataException($"Unable to read property from DB config. Prefixes: ${prefixes}", e);
throw new InvalidDataException($"Unable to read property {propertyName} from DB config. Prefixes: {string.Join(",", prefixes)}", e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public class SyncDbTunerTests
private ITunableDb _stateDb = null!;
private ITunableDb _codeDb = null!;
private ITunableDb _blockDb = null!;
private ITunableDb _receiptDb = null!;
private ITunableDb _receiptBlocksDb = null!;
private ITunableDb _receiptTransactionsDb = null!;

[SetUp]
public void Setup()
Expand All @@ -42,7 +43,8 @@ public void Setup()
_stateDb = Substitute.For<ITunableDb>();
_codeDb = Substitute.For<ITunableDb>();
_blockDb = Substitute.For<ITunableDb>();
_receiptDb = Substitute.For<ITunableDb>();
_receiptBlocksDb = Substitute.For<ITunableDb>();
_receiptTransactionsDb = Substitute.For<ITunableDb>();

SyncDbTuner _ = new SyncDbTuner(
_syncConfig,
Expand All @@ -52,15 +54,17 @@ public void Setup()
_stateDb,
_codeDb,
_blockDb,
_receiptDb);
_receiptBlocksDb,
_receiptTransactionsDb);
}

[TearDown]
public void TearDown()
{
_blockDb?.Dispose();
_codeDb?.Dispose();
_receiptDb?.Dispose();
_receiptBlocksDb?.Dispose();
_receiptTransactionsDb?.Dispose();
_stateDb?.Dispose();
}

Expand All @@ -83,9 +87,15 @@ public void WhenBodiesIsOn_TriggerBlocksDbTune()
}

[Test]
public void WhenReceiptsIsOn_TriggerReceiptsDbTune()
public void WhenReceiptsIsOn_TriggerReceiptBlocksDbTune()
{
TestFeedAndDbTune(_receiptSyncFeed, _receiptDb, _receiptsTuneType);
TestFeedAndDbTune(_receiptSyncFeed, _receiptBlocksDb, _receiptsTuneType);
}

[Test]
public void WhenReceiptsIsOn_TriggerReceiptsTransactionsDbTune()
{
TestFeedAndDbTune(_receiptSyncFeed, _receiptTransactionsDb, _tuneType);
}

private void TestFeedAndDbTune<T>(ISyncFeed<T> feed, ITunableDb db, ITunableDb.TuneType? tuneType = null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public class SyncDbTuner
private readonly ITunableDb? _stateDb;
private readonly ITunableDb? _codeDb;
private readonly ITunableDb? _blockDb;
private readonly ITunableDb? _receiptDb;
private readonly ITunableDb? _receiptBlocksDb;
private readonly ITunableDb? _receiptTransactionsDb;

private readonly ITunableDb.TuneType _tuneType;
private readonly ITunableDb.TuneType _blocksDbTuneType;
Expand All @@ -28,7 +29,8 @@ public SyncDbTuner(
ITunableDb? stateDb,
ITunableDb? codeDb,
ITunableDb? blockDb,
ITunableDb? receiptDb
ITunableDb? receiptBlocksDb,
ITunableDb? receiptTransactionsDb
)
{
// Only these three make sense as they are write heavy
Expand All @@ -52,7 +54,8 @@ public SyncDbTuner(
_stateDb = stateDb;
_codeDb = codeDb;
_blockDb = blockDb;
_receiptDb = receiptDb;
_receiptBlocksDb = receiptBlocksDb;
_receiptTransactionsDb = receiptTransactionsDb;

_tuneType = syncConfig.TuneDbMode;
_blocksDbTuneType = syncConfig.BlocksDbTuneDbMode;
Expand Down Expand Up @@ -89,11 +92,13 @@ private void ReceiptsStateChanged(object? sender, SyncFeedStateEventArgs e)
{
if (e.NewState == SyncFeedState.Active)
{
_receiptDb?.Tune(_receiptsDbTuneType);
_receiptBlocksDb?.Tune(_receiptsDbTuneType);
_receiptTransactionsDb?.Tune(_tuneType);
}
else if (e.NewState == SyncFeedState.Finished)
{
_receiptDb?.Tune(ITunableDb.TuneType.Default);
_receiptBlocksDb?.Tune(ITunableDb.TuneType.Default);
_receiptTransactionsDb?.Tune(ITunableDb.TuneType.Default);
}
}
}
3 changes: 2 additions & 1 deletion src/Nethermind/Nethermind.Synchronization/Synchronizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,8 @@ private void SetupDbOptimizer()
_dbProvider.StateDb as ITunableDb,
_dbProvider.CodeDb as ITunableDb,
_dbProvider.BlocksDb as ITunableDb,
_dbProvider.ReceiptsDb as ITunableDb);
_dbProvider.ReceiptsDb.GetColumnDb(ReceiptsColumns.Blocks) as ITunableDb,
_dbProvider.ReceiptsDb.GetColumnDb(ReceiptsColumns.Transactions) as ITunableDb);
}

private void StartFullSyncComponents()
Expand Down

0 comments on commit b2062d1

Please sign in to comment.