diff --git a/src/Nethermind/Nethermind.Merge.Plugin/Synchronization/BeaconHeadersSyncFeed.cs b/src/Nethermind/Nethermind.Merge.Plugin/Synchronization/BeaconHeadersSyncFeed.cs index a8b87acf98f..fce551b041a 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin/Synchronization/BeaconHeadersSyncFeed.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin/Synchronization/BeaconHeadersSyncFeed.cs @@ -41,8 +41,9 @@ protected override BlockHeader? LowestInsertedBlockHeader get => _blockTree.LowestInsertedBeaconHeader; set { - // Set in blocktree - } + // LowestInsertedBeaconHeader is set in blocktree when BeaconHeaderInsert is set. + // TODO: Probably should move that logic here so that `LowestInsertedBeaconHeader` is set only once per batch. +v } } protected override MeasuredProgress HeadersSyncProgressReport => _syncReport.BeaconHeaders; diff --git a/src/Nethermind/Nethermind.Synchronization/FastBlocks/FastBlocksBatch.cs b/src/Nethermind/Nethermind.Synchronization/FastBlocks/FastBlocksBatch.cs index 9d6cc9b7a90..36995814285 100644 --- a/src/Nethermind/Nethermind.Synchronization/FastBlocks/FastBlocksBatch.cs +++ b/src/Nethermind/Nethermind.Synchronization/FastBlocks/FastBlocksBatch.cs @@ -83,7 +83,7 @@ public double? HandlingTime => (_handlingEndTime ?? _stopwatch.ElapsedMilliseconds) - (_handlingStartTime ?? _stopwatch.ElapsedMilliseconds); /// Minimum header number for allocation strategy. - public virtual long? MinNumber { get; } + public abstract long? MinNumber { get; } public virtual void Dispose() { } } } diff --git a/src/Nethermind/Nethermind.Synchronization/FastBlocks/FastHeadersSyncFeed.cs b/src/Nethermind/Nethermind.Synchronization/FastBlocks/FastHeadersSyncFeed.cs index 5f8d6743a45..2521eed6467 100644 --- a/src/Nethermind/Nethermind.Synchronization/FastBlocks/FastHeadersSyncFeed.cs +++ b/src/Nethermind/Nethermind.Synchronization/FastBlocks/FastHeadersSyncFeed.cs @@ -316,7 +316,7 @@ private bool HasDependencyToProcess } else if (ShouldBuildANewBatch()) { - batch = BuildNewBatch(); + batch = ProcessPersistedHeadersOrBuildNewBatch(); if (_logger.IsTrace) _logger.Trace($"New batch {batch}"); } @@ -339,23 +339,26 @@ private bool HasDependencyToProcess } } - private HeadersSyncBatch? BuildNewBatch() + private HeadersSyncBatch? ProcessPersistedHeadersOrBuildNewBatch() { HeadersSyncBatch? batch = null; do { - batch = new(); - batch.StartNumber = Math.Max(HeadersDestinationNumber, - _lowestRequestedHeaderNumber - _headersRequestSize); - batch.RequestSize = (int)Math.Min(_lowestRequestedHeaderNumber - HeadersDestinationNumber, - _headersRequestSize); - _lowestRequestedHeaderNumber = batch.StartNumber; - + batch = BuildNewBatch(); batch = ProcessPersistedPortion(batch); } while (batch is null && ShouldBuildANewBatch()); return batch; } + private HeadersSyncBatch BuildNewBatch() + { + HeadersSyncBatch batch = new(); + batch.StartNumber = Math.Max(HeadersDestinationNumber, _lowestRequestedHeaderNumber - _headersRequestSize); + batch.RequestSize = (int)Math.Min(_lowestRequestedHeaderNumber - HeadersDestinationNumber, _headersRequestSize); + _lowestRequestedHeaderNumber = batch.StartNumber; + return batch; + } + private void LogStateOnPrepare() { if (_logger.IsDebug) _logger.Debug($"FastHeader LogStateOnPrepare: LOWEST_INSERTED {LowestInsertedBlockHeader?.Number}, LOWEST_REQUESTED {_lowestRequestedHeaderNumber}, DEPENDENCIES {_dependencies.Count}, SENT: {_sent.Count}, PENDING: {_pending.Count}");