diff --git a/src/Nethermind/Nethermind.Synchronization.Test/SnapSync/ProgressTrackerTests.cs b/src/Nethermind/Nethermind.Synchronization.Test/SnapSync/ProgressTrackerTests.cs index f702e409258..921b5baa7df 100644 --- a/src/Nethermind/Nethermind.Synchronization.Test/SnapSync/ProgressTrackerTests.cs +++ b/src/Nethermind/Nethermind.Synchronization.Test/SnapSync/ProgressTrackerTests.cs @@ -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; @@ -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()); + } } diff --git a/src/Nethermind/Nethermind.Synchronization/SnapSync/ProgressTracker.cs b/src/Nethermind/Nethermind.Synchronization/SnapSync/ProgressTracker.cs index 15b99c6c7f8..f73edf4c79c 100644 --- a/src/Nethermind/Nethermind.Synchronization/SnapSync/ProgressTracker.cs +++ b/src/Nethermind/Nethermind.Synchronization/SnapSync/ProgressTracker.cs @@ -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. @@ -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)