diff --git a/src/Nethermind/Nethermind.Synchronization.Test/FastBlocks/SyncStatusListTests.cs b/src/Nethermind/Nethermind.Synchronization.Test/FastBlocks/SyncStatusListTests.cs index f4ecba86a8b..24f30a52b8c 100644 --- a/src/Nethermind/Nethermind.Synchronization.Test/FastBlocks/SyncStatusListTests.cs +++ b/src/Nethermind/Nethermind.Synchronization.Test/FastBlocks/SyncStatusListTests.cs @@ -4,7 +4,13 @@ using System; using System.Linq; using System.Threading.Tasks; +using FluentAssertions; +using Nethermind.Blockchain; +using Nethermind.Core; +using Nethermind.Core.Crypto; +using Nethermind.Core.Test.Builders; using Nethermind.Synchronization.FastBlocks; +using NSubstitute; using NUnit.Framework; namespace Nethermind.Synchronization.Test.FastBlocks @@ -32,7 +38,6 @@ public void Can_read_back_all_set_values() { const int length = 4096; - FastBlockStatusList list = CreateFastBlockStatusList(length, false); for (int i = 0; i < length; i++) { @@ -40,6 +45,19 @@ public void Can_read_back_all_set_values() } } + [Test] + public void Will_not_go_below_ancient_barrier() + { + IBlockTree blockTree = Substitute.For(); + blockTree.FindCanonicalBlockInfo(Arg.Any()).Returns(new BlockInfo(TestItem.KeccakA, 0)); + SyncStatusList syncStatusList = new SyncStatusList(blockTree, 1000, null, 900); + + BlockInfo?[] infos = new BlockInfo?[500]; + syncStatusList.GetInfosForBatch(infos); + + infos.Count((it) => it != null).Should().Be(101); + } + [Test] public void Can_read_back_all_parallel_set_values() { diff --git a/src/Nethermind/Nethermind.Synchronization/FastBlocks/BodiesSyncFeed.cs b/src/Nethermind/Nethermind.Synchronization/FastBlocks/BodiesSyncFeed.cs index 5e441723d73..bde6114aa74 100644 --- a/src/Nethermind/Nethermind.Synchronization/FastBlocks/BodiesSyncFeed.cs +++ b/src/Nethermind/Nethermind.Synchronization/FastBlocks/BodiesSyncFeed.cs @@ -81,7 +81,8 @@ private void ResetSyncStatusList() _syncStatusList = new SyncStatusList( _blockTree, _pivotNumber, - _blockTree.LowestInsertedBodyNumber); + _blockTree.LowestInsertedBodyNumber, + _syncConfig.AncientBodiesBarrier); } protected override SyncMode ActivationSyncModes { get; } = SyncMode.FastBodies & ~SyncMode.FastBlocks; diff --git a/src/Nethermind/Nethermind.Synchronization/FastBlocks/ReceiptsSyncFeed.cs b/src/Nethermind/Nethermind.Synchronization/FastBlocks/ReceiptsSyncFeed.cs index ea63f4405b3..b1b8e3bdc13 100644 --- a/src/Nethermind/Nethermind.Synchronization/FastBlocks/ReceiptsSyncFeed.cs +++ b/src/Nethermind/Nethermind.Synchronization/FastBlocks/ReceiptsSyncFeed.cs @@ -90,7 +90,8 @@ private void ResetSyncStatusList() _syncStatusList = new SyncStatusList( _blockTree, _pivotNumber, - _receiptStorage.LowestInsertedReceiptBlockNumber); + _receiptStorage.LowestInsertedReceiptBlockNumber, + _syncConfig.AncientReceiptsBarrier); } protected override SyncMode ActivationSyncModes { get; } diff --git a/src/Nethermind/Nethermind.Synchronization/FastBlocks/SyncStatusList.cs b/src/Nethermind/Nethermind.Synchronization/FastBlocks/SyncStatusList.cs index 42130e96c44..373afedd1d2 100644 --- a/src/Nethermind/Nethermind.Synchronization/FastBlocks/SyncStatusList.cs +++ b/src/Nethermind/Nethermind.Synchronization/FastBlocks/SyncStatusList.cs @@ -16,6 +16,7 @@ internal class SyncStatusList private readonly FastBlockStatusList _statuses; private readonly LruCache _cache = new(maxCapacity: 64, startCapacity: 64, "blockInfo Cache"); private long _lowestInsertWithoutGaps; + private readonly long _lowerBound; public long LowestInsertWithoutGaps { @@ -25,19 +26,20 @@ public long LowestInsertWithoutGaps public long QueueSize => _queueSize; - public SyncStatusList(IBlockTree blockTree, long pivotNumber, long? lowestInserted) + public SyncStatusList(IBlockTree blockTree, long pivotNumber, long? lowestInserted, long lowerBound) { _blockTree = blockTree ?? throw new ArgumentNullException(nameof(blockTree)); _statuses = new FastBlockStatusList(pivotNumber + 1); LowestInsertWithoutGaps = lowestInserted ?? pivotNumber; + _lowerBound = lowerBound; } public void GetInfosForBatch(BlockInfo?[] blockInfos) { int collected = 0; long currentNumber = Volatile.Read(ref _lowestInsertWithoutGaps); - while (collected < blockInfos.Length && currentNumber != 0) + while (collected < blockInfos.Length && currentNumber != 0 && currentNumber >= _lowerBound) { if (blockInfos[collected] is not null) {