Skip to content

refactor(workspace): standardise on async_trait, drop hand-rolled BoxFuture - #698

Open
varex83agent wants to merge 1 commit into
mainfrom
fix/issue-613-native-afit
Open

refactor(workspace): standardise on async_trait, drop hand-rolled BoxFuture#698
varex83agent wants to merge 1 commit into
mainfrom
fix/issue-613-native-afit

Conversation

@varex83agent

@varex83agent varex83agent commented Sep 10, 2026

Copy link
Copy Markdown
Collaborator

Closes #613.

Reworked after review: instead of splitting traits between native async-fn-in-trait and #[async_trait], every trait with an async method now uses #[async_trait].

  • Traits that hand-rolled BoxFuture-returning methods purely to wrap already-async inherent methods (consensus::wrapper::Consensus, dkg::bcast::RegisteredMessage) now declare plain async fn.
  • priority's non-trait send_receive is a plain async fn instead of returning a boxed future.
  • The attribute is spelled the same way workspace-wide: bare #[async_trait] plus use async_trait::async_trait, which was already the majority form (29 vs 6). The six qualified #[async_trait::async_trait] uses were normalised.
  • cli's DiskTestTool — the one native-AFIT trait in the tree — joins them, retiring the lone #[allow(async_fn_in_trait)] and its comment.
  • core's duplicate BoxFuture alias is dropped in favour of futures::future::BoxFuture.

Out of scope and untouched: the libp2p ConnectionHandler state-machine BoxFutures, and the subscriber callback type aliases owned by #606.

Note

This inverts issue #613's stated acceptance criterion ("#[async_trait] remains only on dyn-used traits") in favour of the uniformity asked for in review. Worth editing or closing #613 to match.

Co-Authored-By: Bohdan Ohorodnii 35969035+varex83@users.noreply.github.com

@emlautarom1 emlautarom1 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Not sure we gain much from switching between native and async_trait definitions. I'd suggest using async_trait everywhere that we have a trait with an async method for consistency. Be consistent on the attribute usage: either #[async_trait::async_trait] or #[async_trait]. Also remove the comments detailing how the trait is being used, it can and will get stale and provides no value at all to the reader.

The replacement of the custom BoxFuture with the one from futures makes sense and looks good.

Comment thread crates/consensus/src/wrapper.rs Outdated
Comment on lines +33 to +35
///
/// Held as `Arc<dyn Consensus>` by [`ConsensusWrapper`] and the controller, so
/// the trait must stay dyn-compatible and keeps `#[async_trait]`.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Drop these kind of comments.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done — removed.

…Future

Traits that hand-rolled `BoxFuture`-returning methods purely to wrap
already-async inherent methods (`consensus::wrapper::Consensus`,
`dkg::bcast::RegisteredMessage`) now declare plain `async fn` under
`#[async_trait]`, and `priority`'s non-trait `send_receive` is a plain
`async fn`.

Every trait with an async method uses `#[async_trait]`, spelled the same
way workspace-wide (bare attribute plus `use async_trait::async_trait`,
which was already the majority form). `cli`'s `DiskTestTool` joins them,
retiring the lone `#[allow(async_fn_in_trait)]`.

Drops `core`'s duplicate `BoxFuture` alias in favour of
`futures::future::BoxFuture`.

Out of scope and untouched: the libp2p `ConnectionHandler` state-machine
`BoxFuture`s, and the subscriber callback type aliases owned by #606.

Co-Authored-By: Bohdan Ohorodnii <35969035+varex83@users.noreply.github.com>
@varex83agent
varex83agent force-pushed the fix/issue-613-native-afit branch from bbdb5c3 to f58fd00 Compare September 12, 2026 13:54
@varex83agent varex83agent changed the title refactor(workspace): prefer native async fn in traits over BoxFuture refactor(workspace): standardise on async_trait, drop hand-rolled BoxFuture Sep 12, 2026
@varex83agent

Copy link
Copy Markdown
Collaborator Author

Thanks — reworked to go the other way. Everything with an async trait method is now #[async_trait]:

  • Reverted the native-AFIT conversions on AggSigDB and FTransport; they're back on #[async_trait].
  • Kept the conversions of the hand-rolled BoxFuture-returning trait methods (consensus::wrapper::Consensus, dkg::bcast::RegisteredMessage) — they're plain async fn under #[async_trait] now, so the Box::pin(async move { ... }) wrappers over already-async inherent methods are gone.
  • Consistent spelling: bare #[async_trait] with use async_trait::async_trait everywhere. That was already the majority (29 vs 6), so the six qualified #[async_trait::async_trait] uses were normalised — including three files outside the original diff (priority/{component,prioritiser}.rs, priority/tests/prioritiser_test.rs).
  • Dropped all the comments explaining how each trait is used.
  • Kept the BoxFuturefutures::future::BoxFuture swap.

One judgement call worth a look: cli's DiskTestTool was the tree's only native-AFIT trait, carrying an #[allow(async_fn_in_trait)] and a four-line comment about it. To make "async_trait everywhere" actually true I converted it too, which adds async-trait to crates/cli (already a workspace dep). Happy to drop that hunk if you'd rather keep the diff to the files originally touched.

Note this inverts #613's acceptance criterion ("#[async_trait] remains only on dyn-used traits") — the issue probably wants editing or closing to match.

Gates: fmt, clippy -D warnings, test --workspace --all-features (57 suites), cargo deny all green.

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.

Prefer native async fn in traits over BoxFuture; reserve async-trait for dyn traits

3 participants