Skip to content

Conversation

@kaimast
Copy link
Contributor

@kaimast kaimast commented Jan 12, 2026

The following changes are included in #4039, but I moved them to a separate PR so they are easier to review.

snarkOS relies on channels for communication between modules in the consensus and bft crates. This indirection exists mostly to avoid circular dependencies between modules, but has the following drawbacks.

  • The code is generally harder to read as, instead of a simple function call, it relies on two channels: one to send the call and one to return the result to.
  • A single operation now involves multiple tokio tasks, as the receiving side of each channel has a distinct task waiting on it.
  • Error handling is more complicated, because panics do not propagate through channels easily.
  • Channels can return errors, e.g., while waiting on a oneshot::Receiver, that we then need to handle in the code.
  • Waiting on a channel is an async task and, thus, requires await.

The last point, especially, makes it harder to improve locking/coordination between different tasks as regular locks cannot be held across awaits and blocking tasks cannot call async functions. The former can be solved through async locks, but those are generally less efficient regular locks. The latter is harder to solve, as we use blocking tasks in multiple places while advancing the ledger.

This PR removes BFTSender and BFTReceiver, but leaves other channels in place. The BFT channels are replaced by two callback traits, one for the Primary and one for Sync. Instead of waiting on BFTReceiver the BFT struct now implements those to traits and registers itself as a callback for each.

@kaimast kaimast force-pushed the refactor/no-bft-channels branch 2 times, most recently from 8fe8f14 to 87e1008 Compare January 12, 2026 20:29
@kaimast kaimast force-pushed the refactor/no-bft-channels branch from 87e1008 to fc48778 Compare January 23, 2026 18:06
@kaimast kaimast force-pushed the refactor/no-bft-channels branch from fc48778 to c40eae6 Compare February 5, 2026 23:42
@kaimast kaimast changed the base branch from staging to ci/updated_network_delay_test February 5, 2026 23:43
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.

1 participant