Rewrite `core/qbft` to async-Rust-friendly API

未关闭
#393 4 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
25/100
Issue 类型
重构
描述清晰度
描述清楚
活跃度
冷清
技术栈
rust

调研方向

从 crates/core/src/qbft/mod.rs 及其 internal_test.rs 开始,然后与 Go 参考实现和 strategysim_internal_test.go 进行比较。在更改并发模型之前,先运行现有的 QBFT 测试。完成的标准是:提供异步公共 API,提供等价的异步测试(包括与 strategysim 的对等性),clippy 和格式检查均无问题,并为公共项编写文档。

由索引模型根据 Issue 内容生成。

描述

enhancement rust track:duty-pipeline

Context

The current Rust port of core/qbft (crates/core/src/qbft/mod.rs) is a faithful translation of the Go reference but built on synchronous, thread-based primitives:

  • crossbeam::channel for transport
  • std::thread::scope for spawning per-process workers
  • A blocking pub fn run(...) entry point
  • cancellation::CancellationToken (third-party crate, not tokio_util)

This is at odds with the rest of Pluto, which is tokio-async end to end. Every consumer that will eventually wire QBFT in (core/consensus, core/scheduler, the duty pipeline) is async. The current shape forces either (a) bridging via spawn_blocking and ad-hoc channel adapters, or (b) blocking inside async tasks — both bad.

Closes the gap left by #13, which produced the initial sync port.

Goal

Rewrite core/qbft with an async-Rust-native API that integrates cleanly with the rest of the workspace and preserves the Byzantine-safety guarantees of the Go reference.

Scope

API
  • run becomes pub async fn run(...) -> Result<Decision, QbftError>
  • Transport trait methods return impl Future<Output = Result<...>> + Send (or are async fn via trait async)
  • Cancellation uses tokio_util::sync::CancellationToken (already used elsewhere in Pluto)
  • Channels: tokio::sync::mpsc (and oneshot where appropriate)
  • No std::thread, no crossbeam, no std::sync::mpsc anywhere in the public or internal API
Internals
  • Replace thread::scope with tokio::spawn + JoinSet (or select! for per-instance loops)
  • Replace blocking sleeps/timers with tokio::time::sleep / Interval
  • Clock abstraction (fake_clock.rs) becomes async-aware so deterministic tests still work — likely using tokio::time::pause() + advance() rather than the current fake clock
  • Keep the algorithm shape (rounds, justifications, message bookkeeping) bit-for-bit identical to the Go reference — only the concurrency primitives change
Safety net (mandatory)
  • Port charon/core/consensus/qbft/strategysim_internal_test.go (~1040 LOC) as the parity gate. This is the test that catches BFT correctness regressions; without it we cannot trust the rewrite.
  • All current crates/core/src/qbft/internal_test.rs cases pass (or are replaced by equivalent async versions)

Acceptance criteria

  • Public API is fully async; no pub fn run blocking entry point remains
  • No crossbeam, std::thread, or third-party cancellation crate usage in crates/core/src/qbft/
  • All existing QBFT unit tests pass (rewritten as async where needed)
  • Strategysim parity test ported from Go and green
  • cargo clippy --workspace --all-targets --all-features -- -D warnings clean
  • cargo +nightly fmt --all --check clean
  • Public API documented; missing_docs warning re-enabled for the module

References

Notes

This is on the critical path for the duty-flow pipeline. core/consensus (#157) and downstream modules (core/scheduler #176, etc.) will consume the new async API directly, so this should land before consensus framework integration begins.

主要语言
Rust
星标
8
派生
5
PR 合并指标
30 天内没有已合并 PR

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

NethermindEth/pluto 的其他 Issue

查看 NethermindEth/pluto 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。