Skip to content

Commit

Permalink
Fix/flush on snap finish (#6444)
Browse files Browse the repository at this point in the history
* Flush on snap finish

* Added test
  • Loading branch information
asdacap committed Jan 2, 2024
1 parent a3caae8 commit cbc3e67
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using FluentAssertions;
using Nethermind.Blockchain;
using Nethermind.Core.Crypto;
using Nethermind.Core.Test;
using Nethermind.Core.Test.Builders;
using Nethermind.Db;
using Nethermind.Logging;
Expand Down Expand Up @@ -135,4 +136,24 @@ public void Will_deque_storage_request_if_high()
request.CodesRequest.Should().BeNull();
request.StorageRangeRequest.Should().NotBeNull();
}

[Test]
public void Will_mark_progress_and_flush_when_finished()
{
BlockTree blockTree = Build.A.BlockTree().WithBlocks(Build.A.Block
.WithStateRoot(Keccak.EmptyTreeHash)
.TestObject).TestObject;
TestMemDb memDb = new TestMemDb();
ProgressTracker progressTracker = new ProgressTracker(blockTree, memDb, LimboLogs.Instance, 1);

(SnapSyncBatch request, bool finished) = progressTracker.GetNextRequest();
request.AccountRangeRequest.Should().NotBeNull();
progressTracker.UpdateAccountRangePartitionProgress(request.AccountRangeRequest!.LimitHash!.Value, Keccak.MaxValue, false);
progressTracker.ReportAccountRangePartitionFinished(request.AccountRangeRequest!.LimitHash!.Value);
(_, finished) = progressTracker.GetNextRequest();
finished.Should().BeTrue();

memDb.WasFlushed.Should().BeTrue();
memDb[ProgressTracker.ACC_PROGRESS_KEY].Should().BeEquivalentTo(Keccak.MaxValue.BytesToArray());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class ProgressTracker
public const int HIGH_STORAGE_QUEUE_SIZE = STORAGE_BATCH_SIZE * 100;
private const int CODES_BATCH_SIZE = 1_000;
public const int HIGH_CODES_QUEUE_SIZE = CODES_BATCH_SIZE * 5;
private readonly byte[] ACC_PROGRESS_KEY = Encoding.ASCII.GetBytes("AccountProgressKey");
internal static readonly byte[] ACC_PROGRESS_KEY = Encoding.ASCII.GetBytes("AccountProgressKey");

// This does not need to be a lot as it spawn other requests. In fact 8 is probably too much. It is severely
// bottlenecked by _syncCommit lock in SnapProviderHelper, which in turns is limited by the IO.
Expand Down Expand Up @@ -416,7 +416,8 @@ private void GetSyncProgress()

private void FinishRangePhase()
{
_db.PutSpan(ACC_PROGRESS_KEY, ValueKeccak.MaxValue.Bytes);
_db.PutSpan(ACC_PROGRESS_KEY, ValueKeccak.MaxValue.Bytes, WriteFlags.DisableWAL);
_db.Flush();
}

private void LogRequest(string reqType)
Expand Down

0 comments on commit cbc3e67

Please sign in to comment.