Skip to content

Commit e37c10d

Browse files
smartprogrammer93kamilchodola
authored andcommitted
Increase tolerance for default barrier again (#6550)
1 parent bc54883 commit e37c10d

File tree

4 files changed

+66
-73
lines changed

4 files changed

+66
-73
lines changed

src/Nethermind/Nethermind.Synchronization.Test/FastBlocks/BodiesSyncFeedTests.cs

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -140,45 +140,46 @@ public async Task ShouldRecoverOnInsertFailure()
140140
req.Infos[0]!.BlockNumber.Should().Be(95);
141141
}
142142

143-
[TestCase(99, false, null, false)]
144-
[TestCase(11051474, false, null, true)]
145-
[TestCase(11052984, false, null, true)]
146-
[TestCase(11052985, false, null, false)]
147-
[TestCase(99, false, 11052984, false)]
148-
[TestCase(11051474, false, 11052984, true)]
149-
[TestCase(11052984, false, 11052984, true)]
150-
[TestCase(11052985, false, 11052984, false)]
151-
[TestCase(99, true, null, false)]
152-
[TestCase(11051474, true, null, false)]
153-
[TestCase(11052984, true, null, false)]
154-
[TestCase(11052985, true, null, false)]
155-
[TestCase(99, false, 0, false)]
156-
[TestCase(11051474, false, 0, false)]
157-
[TestCase(11052984, false, 0, false)]
158-
[TestCase(11052985, false, 0, false)]
159-
public async Task When_finished_sync_with_old_default_barrier_then_finishes_imedietely(
160-
long? lowestInsertedBlockNumber,
143+
[TestCase(1, 99, false, null, false)]
144+
[TestCase(1, 11051474, false, null, true)]
145+
[TestCase(1, 11052984, false, null, true)]
146+
[TestCase(1, 11052985, false, null, false)]
147+
[TestCase(11051474, 11052984, false, null, false)]
148+
[TestCase(11051474, 11051474, false, null, true)]
149+
[TestCase(1, 99, false, 11052984, false)]
150+
[TestCase(1, 11051474, false, 11052984, true)]
151+
[TestCase(1, 11052984, false, 11052984, true)]
152+
[TestCase(1, 11052985, false, 11052984, false)]
153+
[TestCase(11051474, 11052984, false, 11052984, false)]
154+
[TestCase(11051474, 11051474, false, 11052984, true)]
155+
[TestCase(1, 99, true, null, false)]
156+
[TestCase(1, 11051474, true, null, false)]
157+
[TestCase(1, 11052984, true, null, false)]
158+
[TestCase(1, 11052985, true, null, false)]
159+
[TestCase(11051474, 11052984, true, null, false)]
160+
[TestCase(11051474, 11051474, true, null, true)]
161+
[TestCase(1, 99, false, 0, false)]
162+
[TestCase(1, 11051474, false, 0, false)]
163+
[TestCase(1, 11052984, false, 0, false)]
164+
[TestCase(1, 11052985, false, 0, false)]
165+
[TestCase(11051474, 11052984, false, 0, false)]
166+
[TestCase(11051474, 11051474, false, 0, true)]
167+
public void When_finished_sync_with_old_default_barrier_then_finishes_imedietely(
168+
long AncientBarrierInConfig,
169+
long lowestInsertedBlockNumber,
161170
bool JustStarted,
162171
long? previousBarrierInDb,
163172
bool shouldfinish)
164173
{
165-
_syncConfig.AncientReceiptsBarrier = 0;
174+
_syncConfig.AncientBodiesBarrier = AncientBarrierInConfig;
175+
_syncConfig.AncientReceiptsBarrier = AncientBarrierInConfig;
176+
_syncConfig.PivotNumber = (AncientBarrierInConfig + 1_000_000).ToString();
166177
_syncingToBlockTree.LowestInsertedBodyNumber = JustStarted ? null : _pivotBlock.Number;
167178
if (previousBarrierInDb != null)
168179
_metadataDb.Set(MetadataDbKeys.BodiesBarrierWhenStarted, previousBarrierInDb.Value.ToBigEndianByteArrayWithoutLeadingZeros());
169180
_feed.InitializeFeed();
170181
_syncingToBlockTree.LowestInsertedBodyNumber = lowestInsertedBlockNumber;
171182

172-
BodiesSyncBatch? request = await _feed.PrepareRequest();
173-
if (shouldfinish)
174-
{
175-
request.Should().BeNull();
176-
_feed.CurrentState.Should().Be(SyncFeedState.Finished);
177-
}
178-
else
179-
{
180-
request.Should().NotBeNull();
181-
_feed.CurrentState.Should().NotBe(SyncFeedState.Finished);
182-
}
183+
_feed.IsFinished.Should().Be(shouldfinish);
183184
}
184185
}

src/Nethermind/Nethermind.Synchronization.Test/FastBlocks/ReceiptsSyncFeedTests.cs

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public Scenario(ISpecProvider specProvider, int nonEmptyBlocks, int txPerBlock,
7575
private IBlockTree _blockTree = null!;
7676
private IDb _metadataDb = null!;
7777

78-
private static readonly long _pivotNumber = 1024;
78+
private static long _pivotNumber = 1024;
7979

8080
private static readonly Scenario _1024BodiesWithOneTxEach;
8181
private static readonly Scenario _256BodiesWithOneTxEach;
@@ -240,48 +240,46 @@ public async Task When_configured_to_skip_receipts_then_finishes_immediately()
240240
_measuredProgressQueue.HasEnded.Should().BeTrue();
241241
}
242242

243-
[TestCase(1024, false, null, false)]
244-
[TestCase(11051474, false, null, true)]
245-
[TestCase(11052984, false, null, true)]
246-
[TestCase(11052985, false, null, false)]
247-
[TestCase(1024, false, 11052984, false)]
248-
[TestCase(11051474, false, 11052984, true)]
249-
[TestCase(11052984, false, 11052984, true)]
250-
[TestCase(11052985, false, 11052984, false)]
251-
[TestCase(1024, true, null, false)]
252-
[TestCase(11051474, true, null, false)]
253-
[TestCase(11052984, true, null, false)]
254-
[TestCase(11052985, true, null, false)]
255-
[TestCase(1024, false, 0, false)]
256-
[TestCase(11051474, false, 0, false)]
257-
[TestCase(11052984, false, 0, false)]
258-
[TestCase(11052985, false, 0, false)]
259-
public async Task When_finished_sync_with_old_default_barrier_then_finishes_imedietely(
243+
[TestCase(1, 1024, false, null, false)]
244+
[TestCase(1, 11051474, false, null, true)]
245+
[TestCase(1, 11052984, false, null, true)]
246+
[TestCase(11051474, 11052984, false, null, false)]
247+
[TestCase(11051474, 11051474, false, null, true)]
248+
[TestCase(1, 11052985, false, null, false)]
249+
[TestCase(1, 1024, false, 11052984, false)]
250+
[TestCase(1, 11051474, false, 11052984, true)]
251+
[TestCase(1, 11052984, false, 11052984, true)]
252+
[TestCase(11051474, 11052984, false, 11052984, false)]
253+
[TestCase(11051474, 11051474, false, 11052984, true)]
254+
[TestCase(1, 11052985, false, 11052984, false)]
255+
[TestCase(1, 1024, true, null, false)]
256+
[TestCase(1, 11051474, true, null, false)]
257+
[TestCase(1, 11052984, true, null, false)]
258+
[TestCase(11051474, 11052984, true, null, false)]
259+
[TestCase(11051474, 11051474, true, null, true)]
260+
[TestCase(1, 11052985, true, null, false)]
261+
[TestCase(1, 1024, false, 0, false)]
262+
[TestCase(1, 11051474, false, 0, false)]
263+
[TestCase(1, 11052984, false, 0, false)]
264+
[TestCase(11051474, 11052984, false, 0, false)]
265+
[TestCase(11051474, 11051474, false, 0, true)]
266+
[TestCase(1, 11052985, false, 0, false)]
267+
public void When_finished_sync_with_old_default_barrier_then_finishes_imedietely(
268+
long AncientBarrierInConfig,
260269
long? lowestInsertedReceiptBlockNumber,
261270
bool JustStarted,
262271
long? previousBarrierInDb,
263272
bool shouldfinish)
264273
{
265-
_syncConfig.AncientReceiptsBarrier = 0;
274+
_syncConfig.AncientBodiesBarrier = AncientBarrierInConfig;
275+
_syncConfig.AncientReceiptsBarrier = AncientBarrierInConfig;
276+
_pivotNumber = AncientBarrierInConfig + 1_000_000;
266277
_receiptStorage.HasBlock(Arg.Is(_pivotNumber), Arg.Any<Hash256>()).Returns(!JustStarted);
267278
if (previousBarrierInDb != null)
268279
_metadataDb.Set(MetadataDbKeys.ReceiptsBarrierWhenStarted, previousBarrierInDb.Value.ToBigEndianByteArrayWithoutLeadingZeros());
269280
LoadScenario(_256BodiesWithOneTxEach);
270281
_receiptStorage.LowestInsertedReceiptBlockNumber.Returns(lowestInsertedReceiptBlockNumber);
271-
272-
ReceiptsSyncBatch? request = await _feed.PrepareRequest();
273-
if (shouldfinish)
274-
{
275-
request.Should().BeNull();
276-
_feed.CurrentState.Should().Be(SyncFeedState.Finished);
277-
}
278-
else
279-
{
280-
request.Should().NotBeNull();
281-
_feed.CurrentState.Should().NotBe(SyncFeedState.Finished);
282-
}
283-
_measuredProgress.HasEnded.Should().Be(shouldfinish);
284-
_measuredProgressQueue.HasEnded.Should().Be(shouldfinish);
282+
_feed.IsFinished.Should().Be(shouldfinish);
285283
}
286284

287285
private void LoadScenario(Scenario scenario)

src/Nethermind/Nethermind.Synchronization.Test/ParallelSync/SyncDispatcherTests.cs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,13 @@ public async Task Dispatch(PeerInfo peerInfo, TestBatch request, CancellationTok
139139
}
140140

141141
await Task.CompletedTask;
142-
Console.WriteLine("Setting result");
143142
int[] result = new int[request.Length];
144143
for (int i = 0; i < request.Length; i++)
145144
{
146145
result[i] = request.Start + i;
147146
}
148147

149148
request.Result = result;
150-
Console.WriteLine("Finished Execution");
151149
}
152150
}
153151

@@ -181,12 +179,10 @@ public override SyncResponseHandlingResult HandleResponse(TestBatch response, Pe
181179
_responseLock.WaitOne();
182180
if (response.Result is null)
183181
{
184-
Console.WriteLine("Handling failed response");
185182
_returned.Enqueue(response);
186183
}
187184
else
188185
{
189-
Console.WriteLine("Handling OK response");
190186
for (int i = 0; i < response.Length; i++)
191187
{
192188
lock (_results)
@@ -196,7 +192,7 @@ public override SyncResponseHandlingResult HandleResponse(TestBatch response, Pe
196192
}
197193
}
198194

199-
Console.WriteLine($"Decrementing Pending Requests {Interlocked.Decrement(ref _pendingRequests)}");
195+
Interlocked.Decrement(ref _pendingRequests);
200196
return SyncResponseHandlingResult.OK;
201197
}
202198

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

227222
if (HighestRequested >= Max)
228223
{
229-
Console.WriteLine("Pending: " + _pendingRequests);
230224
if (_pendingRequests == 0)
231225
{
232-
Console.WriteLine("Changing to finished");
233226
Finish();
234227
}
235228

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

248-
Console.WriteLine($"Incrementing Pending Requests {Interlocked.Increment(ref _pendingRequests)}");
241+
Interlocked.Increment(ref _pendingRequests);
249242
return testBatch;
250243
}
251244
}

src/Nethermind/Nethermind.Synchronization/FastBlocks/BarrierSyncFeed.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace Nethermind.Synchronization.FastBlocks;
1515
public abstract class BarrierSyncFeed<T> : ActivatedSyncFeed<T>
1616
{
1717
internal const int DepositContractBarrier = 11052984;
18-
internal const int OldBarrierDefaultExtraRange = 8192;
18+
internal const int OldBarrierDefaultExtraRange = 64_000;
1919

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

3333
// This property was introduced when we switched defaults of barriers on mainnet from 11052984 to 0 to not disturb existing node operators
3434
protected bool WithinOldBarrierDefault => _specProvider.ChainId == BlockchainIds.Mainnet
35+
&& _barrier == 1
3536
&& _barrierWhenStarted == DepositContractBarrier
3637
&& LowestInsertedNumber <= DepositContractBarrier
3738
&& 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).

0 commit comments

Comments
 (0)