Skip to content

Commit

Permalink
Clean just one db and while not in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
flcl42 committed Jan 29, 2024
1 parent 3d5ab6f commit bfd91b5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace Nethermind.Merge.Plugin.Test;

[TestFixture]
[Parallelizable(ParallelScope.Self)]
public class BlobTransactionsDbCleanerTests
public class ProcessedTransactionsDbCleanerTests
{
private readonly ILogManager _logManager = LimboLogs.Instance;
private readonly ISpecProvider _specProvider = MainnetSpecProvider.Instance;
Expand Down Expand Up @@ -48,7 +48,7 @@ Transaction GetTx(PrivateKey sender)
returnedTxs!.Length.Should().Be(2);

IBlockFinalizationManager finalizationManager = Substitute.For<IBlockFinalizationManager>();
BlobTransactionsDbCleaner dbCleaner = new(finalizationManager, columnsDb, _logManager);
ProcessedTransactionsDbCleaner dbCleaner = new(finalizationManager, columnsDb.GetColumnDb(BlobTxsColumns.ProcessedTxs), _logManager);

finalizationManager.BlocksFinalized += Raise.EventWith(
new FinalizeEventArgs(Build.A.BlockHeader.TestObject,
Expand Down
2 changes: 1 addition & 1 deletion src/Nethermind/Nethermind.Merge.Plugin/MergePlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public virtual Task Init(INethermindApi nethermindApi)
_blockFinalizationManager = new ManualBlockFinalizationManager();
if (_txPoolConfig.BlobsSupport.SupportsReorgs())
{
BlobTransactionsDbCleaner processedTransactionsDbCleaner = new(_blockFinalizationManager, _api.DbProvider.BlobTransactionsDb, _api.LogManager);
ProcessedTransactionsDbCleaner processedTransactionsDbCleaner = new(_blockFinalizationManager, _api.DbProvider.BlobTransactionsDb.GetColumnDb(BlobTxsColumns.ProcessedTxs), _api.LogManager);
_api.DisposeStack.Push(processedTransactionsDbCleaner);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,26 @@

namespace Nethermind.Merge.Plugin;

public class BlobTransactionsDbCleaner : IDisposable
public class ProcessedTransactionsDbCleaner : IDisposable
{
private readonly IBlockFinalizationManager _finalizationManager;
private readonly IDb _processedTxsDb;
private readonly IColumnsDb<BlobTxsColumns> _db;
private readonly ILogger _logger;
private long _lastFinalizedBlock = 0;
public Task CleaningTask { get; private set; } = Task.CompletedTask;

public BlobTransactionsDbCleaner(IBlockFinalizationManager finalizationManager, IColumnsDb<BlobTxsColumns> db, ILogManager logManager)
public ProcessedTransactionsDbCleaner(IBlockFinalizationManager finalizationManager, IDb processedDb, ILogManager logManager)
{
_finalizationManager = finalizationManager ?? throw new ArgumentNullException(nameof(finalizationManager));
_db = db ?? throw new ArgumentNullException(nameof(db));
_processedTxsDb = db?.GetColumnDb(BlobTxsColumns.ProcessedTxs) ?? throw new ArgumentNullException(nameof(db));
_processedTxsDb = processedDb ?? throw new ArgumentNullException(nameof(db));

Check failure on line 26 in src/Nethermind/Nethermind.Merge.Plugin/ProcessedTransactionsDbCleaner.cs

View workflow job for this annotation

GitHub Actions / Build (release, Nethermind)

The name 'db' does not exist in the current context

Check failure on line 26 in src/Nethermind/Nethermind.Merge.Plugin/ProcessedTransactionsDbCleaner.cs

View workflow job for this annotation

GitHub Actions / Build (release, Nethermind)

The name 'db' does not exist in the current context

Check failure on line 26 in src/Nethermind/Nethermind.Merge.Plugin/ProcessedTransactionsDbCleaner.cs

View workflow job for this annotation

GitHub Actions / Build (debug, Nethermind)

The name 'db' does not exist in the current context

Check failure on line 26 in src/Nethermind/Nethermind.Merge.Plugin/ProcessedTransactionsDbCleaner.cs

View workflow job for this annotation

GitHub Actions / Build (debug, Nethermind)

The name 'db' does not exist in the current context
_logger = logManager?.GetClassLogger() ?? throw new ArgumentNullException(nameof(logManager));

_finalizationManager.BlocksFinalized += OnBlocksFinalized;
}

private void OnBlocksFinalized(object? sender, FinalizeEventArgs e)
{
if (e.FinalizedBlocks.Count > 0 && e.FinalizedBlocks[0].Number > _lastFinalizedBlock)
if (e.FinalizedBlocks.Count > 0 && e.FinalizedBlocks[0].Number > _lastFinalizedBlock && CleaningTask.IsCompleted)
{
CleaningTask = Task.Run(() => CleanProcessedTransactionsDb(e.FinalizedBlocks[0].Number));
}
Expand All @@ -58,7 +56,7 @@ private void CleanProcessedTransactionsDb(long newlyFinalizedBlockNumber)

if (_logger.IsDebug) _logger.Debug($"Cleaned processed blob txs from block {_lastFinalizedBlock} to block {newlyFinalizedBlockNumber}");

_db.Compact();
_processedTxsDb.Compact();

if (_logger.IsDebug) _logger.Debug($"Blob transactions database columns have been compacted");

Expand Down

0 comments on commit bfd91b5

Please sign in to comment.