Skip to content

Conversation

@LukaszRozmej
Copy link
Member

Changes

  • Rename BackgroundTaskScheduler.ScheduleTask -> TryScheduleTask and avoid exceptions
  • In HistoryPruner add checks before going into lock and doing pruning.
  • In HistoryPruner make pruning task exclusive - don't schedule another before previous isn't finished.
  • Remove lock from BackgroundTaskScheduler
  • Move CancelledToken out of generic type
  • Specify channel options explicitly

Types of changes

What types of changes does your code introduce?

  • Bugfix (a non-breaking change that fixes an issue)
  • Optimization
  • Refactoring

Testing

Requires testing

  • Yes

If yes, did you write tests?

  • No

Notes on testing

  • Test normal node operation (BackgroundTaskScheduler won't be throwing exceptions which can affect networking a bit?)
  • Test History pruning

…oid exceptions

In HistoryPruner add checks before going into lock and doing pruning.
In historyPruner make pruning task exclusive - don't schedule another before previous isn't finished.
Move CancelledToken out of generic type
Specify channel options explicitly
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the IBackgroundTaskScheduler API to return a boolean success indicator instead of void, renaming ScheduleTask to TryScheduleTask. The changes also include refactoring of HistoryPruner to add concurrency control, spelling corrections, and related test updates.

Key Changes:

  • Changed ScheduleTask to TryScheduleTask with bool return value across the codebase to indicate scheduling success/failure
  • Refactored HistoryPruner.SchedulePruneHistory to use Task.Run and added _currentlyPruning flag for concurrency control
  • Optimized BackgroundTaskScheduler by removing lock and using lock-free operations with Interlocked

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
Nethermind.Consensus/Scheduler/IBackgroundTaskScheduler.cs Updated interface signature to return bool
Nethermind.Consensus/Scheduler/BackgroundTaskScheduler.cs Implemented TryScheduleTask, removed lock, improved documentation, moved CancelledToken to class level
Nethermind.Network/P2P/Utils/BackgroundTaskSchedulerWrapper.cs Updated method calls to use TrySchedule* variants
Nethermind.Network/P2P/ProtocolHandlers/ProtocolHandlerBase.cs Updated calls to wrapper methods
Nethermind.Network/P2P/Subprotocols/Eth/V62/Eth62ProtocolHandler.cs Updated background task scheduling calls
Nethermind.History/HistoryPruner.cs Added concurrency control, changed TryPruneHistory from Task to void, refactored logic, fixed typos
Nethermind.Consensus.Test/Scheduler/BackgroundTaskSchedulerTests.cs Updated test calls to use TryScheduleTask
Nethermind.Network.Test/P2P/Subprotocols/Eth/V62/Eth62ProtocolHandlerTests.cs Updated mock implementation to return bool
Nethermind.History.Test/HistoryPrunerTests.cs Removed await from TryPruneHistory calls since it's now void
Nethermind.Core.Test/RunImmediatelyScheduler.cs Updated test scheduler to return bool

{
bool lockTaken = false;
// take lock before updating delete pointer
// take lock before updating delete the pointer
Copy link

Copilot AI Nov 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected spelling: "delete the pointer" should be "delete pointer"

Suggested change
// take lock before updating delete the pointer
// take lock before updating delete pointer

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove change

LukaszRozmej and others added 3 commits November 10, 2025 11:56
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Contributor

Copilot AI commented Nov 10, 2025

@LukaszRozmej I've opened a new pull request, #9679, to work on those changes. Once the pull request is ready, I'll request review from you.

LukaszRozmej and others added 2 commits November 10, 2025 12:30
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…heduler.cs

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
{
bool lockTaken = false;
// take lock before updating delete pointer
// take lock before updating delete the pointer
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove change

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants