Reduce Generic Parameter Proliferation with `dyn` Trait Objects

未關閉
#4,309 7 則留言 1 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
5/5
預估耗時
一週以上
新手友好度
22/100
Issue 類型
重構
描述清晰度
基本清楚
活躍度
停滯
技術堆疊
rust

研究方向

This is a design-level change to core LDK types (ChannelManager, OnionMessenger, PeerManager) rather than a first-timer edit. Start from how those types are parameterized and from existing DynSigner usage as the stated precedent. The issue names object-safe candidates (BroadcasterInterface, FeeEstimator, Logger, EntropySource) versus traits that are not yet object-safe (Watch, SignerProvider, Router). Done means fewer type parameters on ChannelManager with no measurable hot-path change; expect many impls and downstream consumers to move together.

由索引模型根據 Issue 內容生成。

描述

Core types have excessive generic parameters that harm maintainability:

  • ChannelManager - 10 type parameters
  • OnionMessenger - 9 type parameters
  • PeerManager - 8 type parameters

This makes certain refactors nearly impossible. Adding a new dependency to ChannelManager means threading a new generic through dozens of impl blocks, all their where clauses, and every downstream consumer. The friction discourages improvements that would otherwise be straightforward.

Performance concerns are overstated

The traits behind these parameters do I/O, networking, disk access, and cryptographic operations - all measured in microseconds to milliseconds. A vtable call costs ~1 nanosecond. The overhead is unmeasurable noise.

There are no hot paths here. Lightning nodes are I/O-bound, not CPU-bound. No one has ever profiled LDK and found vtable dispatch as a bottleneck - because it isn't one.

Precedent

DynSigner already exists in the codebase and demonstrates that dynamic dispatch works fine for signing operations - one of the more performance-sensitive areas.

Proposal

Start with ChannelManager and convert object-safe traits to dyn. Candidates:

  • BroadcasterInterface
  • FeeEstimator
  • Logger
  • EntropySource

Traits with associated types (Watch, SignerProvider) or generic methods (Router) would need more work to become object-safe.

Expected outcome

Significantly reduce ChannelManager's type parameter count. Make future refactors tractable. No measurable performance change.

(co-authored by Claude)

主要語言
Rust
星號
1.4k
分支
482
PR 合併指標
30 天內沒有已合併 PR

環境準備

  • 沒有 Dockerfile 或 Docker Compose 檔案
  • 沒有 Pull Request 範本
  • 閱讀貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

lightningdevkit/rust-lightning 的其他 Issue

查看 lightningdevkit/rust-lightning 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。