Reduce Generic Parameter Proliferation with `dyn` Trait Objects

Abierto
#4,309 7 comentarios 1 reacción 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
22/100
Tipo de issue
Refactorización
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
rust

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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)

Lenguaje dominante
Rust
Estrellas
1.4k
Forks
482
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de lightningdevkit/rust-lightning

Todos los issues de lightningdevkit/rust-lightning

Issues similares

Más issues de Rust

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.