Reduce Generic Parameter Proliferation with `dyn` Trait Objects

オープン
#4,309 コメント 7 件 リアクション 1 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
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 はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

lightningdevkit/rust-lightning のほかの issue

lightningdevkit/rust-lightning の issue をすべて見る

似ている issue

Rust の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。