Skip to content

Commit

Permalink
Addressing comment
Browse files Browse the repository at this point in the history
  • Loading branch information
asdacap committed Dec 12, 2024
1 parent 86199a5 commit fb9833f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() { }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ private bool HasDependencyToProcess
}
else if (ShouldBuildANewBatch())
{
batch = BuildNewBatch();
batch = ProcessPersistedHeadersOrBuildNewBatch();
if (_logger.IsTrace) _logger.Trace($"New batch {batch}");
}

Expand All @@ -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}");
Expand Down

0 comments on commit fb9833f

Please sign in to comment.