Skip to content

Commit

Permalink
Increase tolerance for default barrier again (#6550)
Browse files Browse the repository at this point in the history
  • Loading branch information
smartprogrammer93 authored and kamilchodola committed Jan 16, 2024
1 parent bc54883 commit e37c10d
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -140,45 +140,46 @@ public async Task ShouldRecoverOnInsertFailure()
req.Infos[0]!.BlockNumber.Should().Be(95);
}

[TestCase(99, false, null, false)]
[TestCase(11051474, false, null, true)]
[TestCase(11052984, false, null, true)]
[TestCase(11052985, false, null, false)]
[TestCase(99, false, 11052984, false)]
[TestCase(11051474, false, 11052984, true)]
[TestCase(11052984, false, 11052984, true)]
[TestCase(11052985, false, 11052984, false)]
[TestCase(99, true, null, false)]
[TestCase(11051474, true, null, false)]
[TestCase(11052984, true, null, false)]
[TestCase(11052985, true, null, false)]
[TestCase(99, false, 0, false)]
[TestCase(11051474, false, 0, false)]
[TestCase(11052984, false, 0, false)]
[TestCase(11052985, false, 0, false)]
public async Task When_finished_sync_with_old_default_barrier_then_finishes_imedietely(
long? lowestInsertedBlockNumber,
[TestCase(1, 99, false, null, false)]
[TestCase(1, 11051474, false, null, true)]
[TestCase(1, 11052984, false, null, true)]
[TestCase(1, 11052985, false, null, false)]
[TestCase(11051474, 11052984, false, null, false)]
[TestCase(11051474, 11051474, false, null, true)]
[TestCase(1, 99, false, 11052984, false)]
[TestCase(1, 11051474, false, 11052984, true)]
[TestCase(1, 11052984, false, 11052984, true)]
[TestCase(1, 11052985, false, 11052984, false)]
[TestCase(11051474, 11052984, false, 11052984, false)]
[TestCase(11051474, 11051474, false, 11052984, true)]
[TestCase(1, 99, true, null, false)]
[TestCase(1, 11051474, true, null, false)]
[TestCase(1, 11052984, true, null, false)]
[TestCase(1, 11052985, true, null, false)]
[TestCase(11051474, 11052984, true, null, false)]
[TestCase(11051474, 11051474, true, null, true)]
[TestCase(1, 99, false, 0, false)]
[TestCase(1, 11051474, false, 0, false)]
[TestCase(1, 11052984, false, 0, false)]
[TestCase(1, 11052985, false, 0, false)]
[TestCase(11051474, 11052984, false, 0, false)]
[TestCase(11051474, 11051474, false, 0, true)]
public void When_finished_sync_with_old_default_barrier_then_finishes_imedietely(
long AncientBarrierInConfig,
long lowestInsertedBlockNumber,
bool JustStarted,
long? previousBarrierInDb,
bool shouldfinish)
{
_syncConfig.AncientReceiptsBarrier = 0;
_syncConfig.AncientBodiesBarrier = AncientBarrierInConfig;
_syncConfig.AncientReceiptsBarrier = AncientBarrierInConfig;
_syncConfig.PivotNumber = (AncientBarrierInConfig + 1_000_000).ToString();
_syncingToBlockTree.LowestInsertedBodyNumber = JustStarted ? null : _pivotBlock.Number;
if (previousBarrierInDb != null)
_metadataDb.Set(MetadataDbKeys.BodiesBarrierWhenStarted, previousBarrierInDb.Value.ToBigEndianByteArrayWithoutLeadingZeros());
_feed.InitializeFeed();
_syncingToBlockTree.LowestInsertedBodyNumber = lowestInsertedBlockNumber;

BodiesSyncBatch? request = await _feed.PrepareRequest();
if (shouldfinish)
{
request.Should().BeNull();
_feed.CurrentState.Should().Be(SyncFeedState.Finished);
}
else
{
request.Should().NotBeNull();
_feed.CurrentState.Should().NotBe(SyncFeedState.Finished);
}
_feed.IsFinished.Should().Be(shouldfinish);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public Scenario(ISpecProvider specProvider, int nonEmptyBlocks, int txPerBlock,
private IBlockTree _blockTree = null!;
private IDb _metadataDb = null!;

private static readonly long _pivotNumber = 1024;
private static long _pivotNumber = 1024;

private static readonly Scenario _1024BodiesWithOneTxEach;
private static readonly Scenario _256BodiesWithOneTxEach;
Expand Down Expand Up @@ -240,48 +240,46 @@ public async Task When_configured_to_skip_receipts_then_finishes_immediately()
_measuredProgressQueue.HasEnded.Should().BeTrue();
}

[TestCase(1024, false, null, false)]
[TestCase(11051474, false, null, true)]
[TestCase(11052984, false, null, true)]
[TestCase(11052985, false, null, false)]
[TestCase(1024, false, 11052984, false)]
[TestCase(11051474, false, 11052984, true)]
[TestCase(11052984, false, 11052984, true)]
[TestCase(11052985, false, 11052984, false)]
[TestCase(1024, true, null, false)]
[TestCase(11051474, true, null, false)]
[TestCase(11052984, true, null, false)]
[TestCase(11052985, true, null, false)]
[TestCase(1024, false, 0, false)]
[TestCase(11051474, false, 0, false)]
[TestCase(11052984, false, 0, false)]
[TestCase(11052985, false, 0, false)]
public async Task When_finished_sync_with_old_default_barrier_then_finishes_imedietely(
[TestCase(1, 1024, false, null, false)]
[TestCase(1, 11051474, false, null, true)]
[TestCase(1, 11052984, false, null, true)]
[TestCase(11051474, 11052984, false, null, false)]
[TestCase(11051474, 11051474, false, null, true)]
[TestCase(1, 11052985, false, null, false)]
[TestCase(1, 1024, false, 11052984, false)]
[TestCase(1, 11051474, false, 11052984, true)]
[TestCase(1, 11052984, false, 11052984, true)]
[TestCase(11051474, 11052984, false, 11052984, false)]
[TestCase(11051474, 11051474, false, 11052984, true)]
[TestCase(1, 11052985, false, 11052984, false)]
[TestCase(1, 1024, true, null, false)]
[TestCase(1, 11051474, true, null, false)]
[TestCase(1, 11052984, true, null, false)]
[TestCase(11051474, 11052984, true, null, false)]
[TestCase(11051474, 11051474, true, null, true)]
[TestCase(1, 11052985, true, null, false)]
[TestCase(1, 1024, false, 0, false)]
[TestCase(1, 11051474, false, 0, false)]
[TestCase(1, 11052984, false, 0, false)]
[TestCase(11051474, 11052984, false, 0, false)]
[TestCase(11051474, 11051474, false, 0, true)]
[TestCase(1, 11052985, false, 0, false)]
public void When_finished_sync_with_old_default_barrier_then_finishes_imedietely(
long AncientBarrierInConfig,
long? lowestInsertedReceiptBlockNumber,
bool JustStarted,
long? previousBarrierInDb,
bool shouldfinish)
{
_syncConfig.AncientReceiptsBarrier = 0;
_syncConfig.AncientBodiesBarrier = AncientBarrierInConfig;
_syncConfig.AncientReceiptsBarrier = AncientBarrierInConfig;
_pivotNumber = AncientBarrierInConfig + 1_000_000;
_receiptStorage.HasBlock(Arg.Is(_pivotNumber), Arg.Any<Hash256>()).Returns(!JustStarted);
if (previousBarrierInDb != null)
_metadataDb.Set(MetadataDbKeys.ReceiptsBarrierWhenStarted, previousBarrierInDb.Value.ToBigEndianByteArrayWithoutLeadingZeros());
LoadScenario(_256BodiesWithOneTxEach);
_receiptStorage.LowestInsertedReceiptBlockNumber.Returns(lowestInsertedReceiptBlockNumber);

ReceiptsSyncBatch? request = await _feed.PrepareRequest();
if (shouldfinish)
{
request.Should().BeNull();
_feed.CurrentState.Should().Be(SyncFeedState.Finished);
}
else
{
request.Should().NotBeNull();
_feed.CurrentState.Should().NotBe(SyncFeedState.Finished);
}
_measuredProgress.HasEnded.Should().Be(shouldfinish);
_measuredProgressQueue.HasEnded.Should().Be(shouldfinish);
_feed.IsFinished.Should().Be(shouldfinish);
}

private void LoadScenario(Scenario scenario)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,13 @@ public async Task Dispatch(PeerInfo peerInfo, TestBatch request, CancellationTok
}

await Task.CompletedTask;
Console.WriteLine("Setting result");
int[] result = new int[request.Length];
for (int i = 0; i < request.Length; i++)
{
result[i] = request.Start + i;
}

request.Result = result;
Console.WriteLine("Finished Execution");
}
}

Expand Down Expand Up @@ -181,12 +179,10 @@ public override SyncResponseHandlingResult HandleResponse(TestBatch response, Pe
_responseLock.WaitOne();
if (response.Result is null)
{
Console.WriteLine("Handling failed response");
_returned.Enqueue(response);
}
else
{
Console.WriteLine("Handling OK response");
for (int i = 0; i < response.Length; i++)
{
lock (_results)
Expand All @@ -196,7 +192,7 @@ public override SyncResponseHandlingResult HandleResponse(TestBatch response, Pe
}
}

Console.WriteLine($"Decrementing Pending Requests {Interlocked.Decrement(ref _pendingRequests)}");
Interlocked.Decrement(ref _pendingRequests);
return SyncResponseHandlingResult.OK;
}

Expand All @@ -215,7 +211,6 @@ public override async Task<TestBatch> PrepareRequest(CancellationToken token = d
TestBatch testBatch;
if (_returned.TryDequeue(out TestBatch? returned))
{
Console.WriteLine("Sending previously failed batch");
testBatch = returned;
}
else
Expand All @@ -226,10 +221,8 @@ public override async Task<TestBatch> PrepareRequest(CancellationToken token = d

if (HighestRequested >= Max)
{
Console.WriteLine("Pending: " + _pendingRequests);
if (_pendingRequests == 0)
{
Console.WriteLine("Changing to finished");
Finish();
}

Expand All @@ -245,7 +238,7 @@ public override async Task<TestBatch> PrepareRequest(CancellationToken token = d
testBatch = new TestBatch(start, 8);
}

Console.WriteLine($"Incrementing Pending Requests {Interlocked.Increment(ref _pendingRequests)}");
Interlocked.Increment(ref _pendingRequests);
return testBatch;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Nethermind.Synchronization.FastBlocks;
public abstract class BarrierSyncFeed<T> : ActivatedSyncFeed<T>
{
internal const int DepositContractBarrier = 11052984;
internal const int OldBarrierDefaultExtraRange = 8192;
internal const int OldBarrierDefaultExtraRange = 64_000;

protected abstract long? LowestInsertedNumber { get; }
protected abstract int BarrierWhenStartedMetadataDbKey { get; }
Expand All @@ -32,6 +32,7 @@ public abstract class BarrierSyncFeed<T> : ActivatedSyncFeed<T>

// This property was introduced when we switched defaults of barriers on mainnet from 11052984 to 0 to not disturb existing node operators
protected bool WithinOldBarrierDefault => _specProvider.ChainId == BlockchainIds.Mainnet
&& _barrier == 1
&& _barrierWhenStarted == DepositContractBarrier
&& LowestInsertedNumber <= DepositContractBarrier
&& LowestInsertedNumber > DepositContractBarrier - OldBarrierDefaultExtraRange; // this is intentional. this is a magic number as to the amount of possible blocks that had been synced. We noticed on previous versions that the client synced a bit below the default barrier by more than just the GethRequest limit (128).
Expand Down

0 comments on commit e37c10d

Please sign in to comment.