[Refactor] Remove BFT channels #4065
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
consensusandbftcrates. This indirection exists mostly to avoid circular dependencies between modules, but has the following drawbacks.tokiotasks, as the receiving side of each channel has a distinct task waiting on it.oneshot::Receiver, that we then need to handle in the code.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
BFTSenderandBFTReceiver, but leaves other channels in place. The BFT channels are replaced by two callback traits, one for thePrimaryand one forSync. Instead of waiting onBFTReceivertheBFTstruct now implements those to traits and registers itself as a callback for each.