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/flush on snap finish #6444

Merged
merged 2 commits into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading