Skip to content

Commit

Permalink
Don't boost priority of forkchoice if syncing (#7158)
Browse files Browse the repository at this point in the history
  • Loading branch information
benaadams authored Jun 10, 2024
1 parent 04674fa commit 1d6a536
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
7 changes: 5 additions & 2 deletions src/Nethermind/Nethermind.Core/Threading/ThreadExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public static class ThreadExtensions
{
public readonly struct Disposable : IDisposable
{
private readonly Thread _thread;
private readonly Thread? _thread;
private readonly ThreadPriority _previousPriority;

internal Disposable(Thread thread)
Expand All @@ -22,7 +22,10 @@ internal Disposable(Thread thread)

public void Dispose()
{
_thread.Priority = _previousPriority;
if (_thread is not null && Thread.CurrentThread == _thread)
{
_thread.Priority = _previousPriority;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,19 @@ public async Task<ResultWrapper<ForkchoiceUpdatedV1Result>> Handle(ForkchoiceSta

private async Task<ResultWrapper<ForkchoiceUpdatedV1Result>?> ApplyForkchoiceUpdate(Block? newHeadBlock, ForkchoiceStateV1 forkchoiceState, PayloadAttributes? payloadAttributes)
{
using ThreadExtensions.Disposable handle = Thread.CurrentThread.BoostPriority();
// if a head is unknown we are syncing
bool isDefinitelySyncing = newHeadBlock is null;
using ThreadExtensions.Disposable handle = isDefinitelySyncing ?
default : // Don't boost priority if we are definitely syncing
Thread.CurrentThread.BoostPriority();

if (_invalidChainTracker.IsOnKnownInvalidChain(forkchoiceState.HeadBlockHash, out Hash256? lastValidHash))
{
if (_logger.IsInfo) _logger.Info($"Received Invalid {forkchoiceState} {payloadAttributes} - {forkchoiceState.HeadBlockHash} is known to be a part of an invalid chain.");
return ForkchoiceUpdatedV1Result.Invalid(lastValidHash);
}

if (newHeadBlock is null) // if a head is unknown we are syncing
if (isDefinitelySyncing)
{
string simpleRequestStr = payloadAttributes is null ? forkchoiceState.ToString() : $"{forkchoiceState} {payloadAttributes}";
if (_logger.IsInfo) _logger.Info($"Received {simpleRequestStr}");
Expand Down Expand Up @@ -134,7 +138,7 @@ public async Task<ResultWrapper<ForkchoiceUpdatedV1Result>> Handle(ForkchoiceSta
return ForkchoiceUpdatedV1Result.Syncing;
}

BlockInfo? blockInfo = _blockTree.GetInfo(newHeadBlock.Number, newHeadBlock.GetOrCalculateHash()).Info;
BlockInfo? blockInfo = _blockTree.GetInfo(newHeadBlock!.Number, newHeadBlock.GetOrCalculateHash()).Info;
BlockHeader? safeBlockHeader = ValidateBlockHash(forkchoiceState.SafeBlockHash, out string? safeBlockErrorMsg);
BlockHeader? finalizedHeader = ValidateBlockHash(forkchoiceState.FinalizedBlockHash, out string? finalizationErrorMsg);
string requestStr = payloadAttributes is null
Expand Down

0 comments on commit 1d6a536

Please sign in to comment.