Skip to content

Commit cad0985

Browse files
committed
De-couple MessageRouter from Router
Now that ChannelManager is parameterized by both a MessageRouter and a Router, Router implementations no longer need to implement MessageRouter, too.
1 parent bde331f commit cad0985

File tree

2 files changed

+1
-60
lines changed

2 files changed

+1
-60
lines changed

lightning/src/routing/router.rs

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use bitcoin::secp256k1::{PublicKey, Secp256k1, self};
1313

1414
use crate::blinded_path::{BlindedHop, Direction, IntroductionNode};
15-
use crate::blinded_path::message::{BlindedMessagePath, MessageContext, MessageForwardNode};
1615
use crate::blinded_path::payment::{BlindedPaymentPath, ForwardTlvs, PaymentConstraints, PaymentForwardNode, PaymentRelay, ReceiveTlvs};
1716
use crate::ln::{PaymentHash, PaymentPreimage};
1817
use crate::ln::channel_state::ChannelDetails;
@@ -23,7 +22,6 @@ use crate::ln::onion_utils;
2322
#[cfg(async_payments)]
2423
use crate::offers::static_invoice::StaticInvoice;
2524
use crate::offers::invoice::Bolt12Invoice;
26-
use crate::onion_message::messenger::{DefaultMessageRouter, Destination, MessageRouter, OnionMessagePath};
2725
use crate::routing::gossip::{DirectedChannelInfo, EffectiveCapacity, ReadOnlyNetworkGraph, NetworkGraph, NodeId};
2826
use crate::routing::scoring::{ChannelUsage, LockableScore, ScoreLookUp};
2927
use crate::sign::EntropySource;
@@ -49,9 +47,6 @@ pub use lightning_types::routing::{RouteHint, RouteHintHop};
4947
/// it will create a one-hop path using the recipient as the introduction node if it is a announced
5048
/// node. Otherwise, there is no way to find a path to the introduction node in order to send a
5149
/// payment, and thus an `Err` is returned.
52-
///
53-
/// Implements [`MessageRouter`] by delegating to [`DefaultMessageRouter`]. See those docs for
54-
/// privacy implications.
5550
pub struct DefaultRouter<G: Deref<Target = NetworkGraph<L>>, L: Deref, ES: Deref, S: Deref, SP: Sized, Sc: ScoreLookUp<ScoreParams = SP>> where
5651
L::Target: Logger,
5752
S::Target: for <'a> LockableScore<'a, ScoreLookUp = Sc>,
@@ -190,36 +185,8 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, ES: Deref, S: Deref, SP: Size
190185
}
191186
}
192187

193-
impl< G: Deref<Target = NetworkGraph<L>>, L: Deref, ES: Deref, S: Deref, SP: Sized, Sc: ScoreLookUp<ScoreParams = SP>> MessageRouter for DefaultRouter<G, L, ES, S, SP, Sc> where
194-
L::Target: Logger,
195-
S::Target: for <'a> LockableScore<'a, ScoreLookUp = Sc>,
196-
ES::Target: EntropySource,
197-
{
198-
fn find_path(
199-
&self, sender: PublicKey, peers: Vec<PublicKey>, destination: Destination
200-
) -> Result<OnionMessagePath, ()> {
201-
DefaultMessageRouter::<_, _, ES>::find_path(&self.network_graph, sender, peers, destination)
202-
}
203-
204-
fn create_blinded_paths<
205-
T: secp256k1::Signing + secp256k1::Verification
206-
> (
207-
&self, recipient: PublicKey, context: MessageContext, peers: Vec<PublicKey>, secp_ctx: &Secp256k1<T>,
208-
) -> Result<Vec<BlindedMessagePath>, ()> {
209-
DefaultMessageRouter::create_blinded_paths(&self.network_graph, recipient, context, peers, &self.entropy_source, secp_ctx)
210-
}
211-
212-
fn create_compact_blinded_paths<
213-
T: secp256k1::Signing + secp256k1::Verification
214-
> (
215-
&self, recipient: PublicKey, context: MessageContext, peers: Vec<MessageForwardNode>, secp_ctx: &Secp256k1<T>,
216-
) -> Result<Vec<BlindedMessagePath>, ()> {
217-
DefaultMessageRouter::create_compact_blinded_paths(&self.network_graph, recipient, context, peers, &self.entropy_source, secp_ctx)
218-
}
219-
}
220-
221188
/// A trait defining behavior for routing a payment.
222-
pub trait Router: MessageRouter {
189+
pub trait Router {
223190
/// Finds a [`Route`] for a payment between the given `payer` and a payee.
224191
///
225192
/// The `payee` and the payment's value are given in [`RouteParameters::payment_params`]

lightning/src/util/test_utils.rs

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -265,32 +265,6 @@ impl<'a> Router for TestRouter<'a> {
265265
}
266266
}
267267

268-
impl<'a> MessageRouter for TestRouter<'a> {
269-
fn find_path(
270-
&self, sender: PublicKey, peers: Vec<PublicKey>, destination: Destination
271-
) -> Result<OnionMessagePath, ()> {
272-
self.router.find_path(sender, peers, destination)
273-
}
274-
275-
fn create_blinded_paths<
276-
T: secp256k1::Signing + secp256k1::Verification
277-
>(
278-
&self, recipient: PublicKey, context: MessageContext,
279-
peers: Vec<PublicKey>, secp_ctx: &Secp256k1<T>,
280-
) -> Result<Vec<BlindedMessagePath>, ()> {
281-
self.router.create_blinded_paths(recipient, context, peers, secp_ctx)
282-
}
283-
284-
fn create_compact_blinded_paths<
285-
T: secp256k1::Signing + secp256k1::Verification
286-
>(
287-
&self, recipient: PublicKey, context: MessageContext,
288-
peers: Vec<MessageForwardNode>, secp_ctx: &Secp256k1<T>,
289-
) -> Result<Vec<BlindedMessagePath>, ()> {
290-
self.router.create_compact_blinded_paths(recipient, context, peers, secp_ctx)
291-
}
292-
}
293-
294268
impl<'a> Drop for TestRouter<'a> {
295269
fn drop(&mut self) {
296270
if std::thread::panicking() {

0 commit comments

Comments
 (0)