Skip to content

Commit 0f741ab

Browse files
committed
f - move default Router::create_blinded_payment_paths implementation
1 parent ace7b21 commit 0f741ab

File tree

4 files changed

+72
-38
lines changed

4 files changed

+72
-38
lines changed

fuzz/src/chanmon_consistency.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ use bitcoin::hashes::sha256d::Hash as Sha256dHash;
3131
use bitcoin::hash_types::{BlockHash, WPubkeyHash};
3232

3333
use lightning::blinded_path::BlindedPath;
34+
use lightning::blinded_path::payment::ReceiveTlvs;
3435
use lightning::chain;
3536
use lightning::chain::{BestBlock, ChannelMonitorUpdateStatus, chainmonitor, channelmonitor, Confirm, Watch};
3637
use lightning::chain::channelmonitor::{ChannelMonitor, MonitorEvent};
@@ -45,7 +46,7 @@ use lightning::ln::channel::FEE_SPIKE_BUFFER_FEE_INCREASE_MULTIPLE;
4546
use lightning::ln::msgs::{self, CommitmentUpdate, ChannelMessageHandler, DecodeError, UpdateAddHTLC, Init};
4647
use lightning::ln::script::ShutdownScript;
4748
use lightning::ln::functional_test_utils::*;
48-
use lightning::offers::invoice::UnsignedBolt12Invoice;
49+
use lightning::offers::invoice::{BlindedPayInfo, UnsignedBolt12Invoice};
4950
use lightning::offers::invoice_request::UnsignedInvoiceRequest;
5051
use lightning::onion_message::{Destination, MessageRouter, OnionMessagePath};
5152
use lightning::util::test_channel_signer::{TestChannelSigner, EnforcementState};
@@ -101,6 +102,15 @@ impl Router for FuzzRouter {
101102
action: msgs::ErrorAction::IgnoreError
102103
})
103104
}
105+
106+
fn create_blinded_payment_paths<
107+
ES: EntropySource + ?Sized, T: secp256k1::Signing + secp256k1::Verification
108+
>(
109+
&self, _recipient: PublicKey, _first_hops: Vec<ChannelDetails>, _tlvs: ReceiveTlvs,
110+
_amount_msats: u64, _entropy_source: &ES, _secp_ctx: &Secp256k1<T>
111+
) -> Result<Vec<(BlindedPayInfo, BlindedPath)>, ()> {
112+
unreachable!()
113+
}
104114
}
105115

106116
impl MessageRouter for FuzzRouter {

fuzz/src/full_stack.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use bitcoin::hashes::sha256d::Hash as Sha256dHash;
2929
use bitcoin::hash_types::{Txid, BlockHash, WPubkeyHash};
3030

3131
use lightning::blinded_path::BlindedPath;
32+
use lightning::blinded_path::payment::ReceiveTlvs;
3233
use lightning::chain;
3334
use lightning::chain::{BestBlock, ChannelMonitorUpdateStatus, Confirm, Listen};
3435
use lightning::chain::chaininterface::{BroadcasterInterface, ConfirmationTarget, FeeEstimator};
@@ -42,7 +43,7 @@ use lightning::ln::peer_handler::{MessageHandler,PeerManager,SocketDescriptor,Ig
4243
use lightning::ln::msgs::{self, DecodeError};
4344
use lightning::ln::script::ShutdownScript;
4445
use lightning::ln::functional_test_utils::*;
45-
use lightning::offers::invoice::UnsignedBolt12Invoice;
46+
use lightning::offers::invoice::{BlindedPayInfo, UnsignedBolt12Invoice};
4647
use lightning::offers::invoice_request::UnsignedInvoiceRequest;
4748
use lightning::onion_message::{Destination, MessageRouter, OnionMessagePath};
4849
use lightning::routing::gossip::{P2PGossipSync, NetworkGraph};
@@ -144,6 +145,15 @@ impl Router for FuzzRouter {
144145
action: msgs::ErrorAction::IgnoreError
145146
})
146147
}
148+
149+
fn create_blinded_payment_paths<
150+
ES: EntropySource + ?Sized, T: secp256k1::Signing + secp256k1::Verification
151+
>(
152+
&self, _recipient: PublicKey, _first_hops: Vec<ChannelDetails>, _tlvs: ReceiveTlvs,
153+
_amount_msats: u64, _entropy_source: &ES, _secp_ctx: &Secp256k1<T>
154+
) -> Result<Vec<(BlindedPayInfo, BlindedPath)>, ()> {
155+
unreachable!()
156+
}
147157
}
148158

149159
impl MessageRouter for FuzzRouter {

lightning/src/routing/router.rs

Lines changed: 37 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,42 @@ impl< G: Deref<Target = NetworkGraph<L>> + Clone, L: Deref, S: Deref, SP: Sized,
8383
&random_seed_bytes
8484
)
8585
}
86+
87+
fn create_blinded_payment_paths<
88+
ES: EntropySource + ?Sized, T: secp256k1::Signing + secp256k1::Verification
89+
>(
90+
&self, recipient: PublicKey, first_hops: Vec<ChannelDetails>, tlvs: ReceiveTlvs,
91+
amount_msats: u64, entropy_source: &ES, secp_ctx: &Secp256k1<T>
92+
) -> Result<Vec<(BlindedPayInfo, BlindedPath)>, ()> {
93+
first_hops.into_iter()
94+
.filter(|details| details.is_public)
95+
.filter(|details| details.counterparty.features.supports_route_blinding())
96+
.filter(|details| amount_msats >= details.inbound_htlc_minimum_msat.unwrap_or(0))
97+
.filter(|details| amount_msats <= details.inbound_htlc_maximum_msat.unwrap_or(0))
98+
.map(|details| {
99+
let short_channel_id = details.get_inbound_payment_scid().unwrap();
100+
let payment_relay: PaymentRelay = details.counterparty.forwarding_info.unwrap().into();
101+
let payment_constraints = PaymentConstraints {
102+
max_cltv_expiry: tlvs.payment_constraints.max_cltv_expiry
103+
+ payment_relay.cltv_expiry_delta as u32,
104+
htlc_minimum_msat: details.inbound_htlc_minimum_msat.unwrap_or(0),
105+
};
106+
let forward_node = ForwardNode {
107+
tlvs: ForwardTlvs {
108+
short_channel_id,
109+
payment_relay,
110+
payment_constraints,
111+
features: BlindedHopFeatures::empty(),
112+
},
113+
node_id: details.counterparty.node_id,
114+
htlc_maximum_msat: details.inbound_htlc_maximum_msat.unwrap_or(0),
115+
};
116+
BlindedPath::new_for_payment(
117+
&[forward_node], recipient, tlvs.clone(), u64::MAX, entropy_source, secp_ctx
118+
)
119+
})
120+
.collect()
121+
}
86122
}
87123

88124
impl< G: Deref<Target = NetworkGraph<L>> + Clone, L: Deref, S: Deref, SP: Sized, Sc: ScoreLookUp<ScoreParams = SP>> MessageRouter for DefaultRouter<G, L, S, SP, Sc> where
@@ -134,44 +170,12 @@ pub trait Router: MessageRouter {
134170
/// Creates [`BlindedPath`]s for payment to the `recipient` node. The channels in `first_hops`
135171
/// are assumed to be with the `recipient`'s peers. The payment secret and any constraints are
136172
/// given in `tlvs`.
137-
///
138-
/// The default implementation returns two-hop payment paths for each channel in `first_hops`
139-
/// with the `recipient` node (i.e., the channel counterparty is the introduction point).
140173
fn create_blinded_payment_paths<
141174
ES: EntropySource + ?Sized, T: secp256k1::Signing + secp256k1::Verification
142175
>(
143176
&self, recipient: PublicKey, first_hops: Vec<ChannelDetails>, tlvs: ReceiveTlvs,
144177
amount_msats: u64, entropy_source: &ES, secp_ctx: &Secp256k1<T>
145-
) -> Result<Vec<(BlindedPayInfo, BlindedPath)>, ()> {
146-
first_hops.into_iter()
147-
.filter(|details| details.is_public)
148-
.filter(|details| details.counterparty.features.supports_route_blinding())
149-
.filter(|details| amount_msats >= details.inbound_htlc_minimum_msat.unwrap_or(0))
150-
.filter(|details| amount_msats <= details.inbound_htlc_maximum_msat.unwrap_or(0))
151-
.map(|details| {
152-
let short_channel_id = details.get_inbound_payment_scid().unwrap();
153-
let payment_relay: PaymentRelay = details.counterparty.forwarding_info.unwrap().into();
154-
let payment_constraints = PaymentConstraints {
155-
max_cltv_expiry: tlvs.payment_constraints.max_cltv_expiry
156-
+ payment_relay.cltv_expiry_delta as u32,
157-
htlc_minimum_msat: details.inbound_htlc_minimum_msat.unwrap_or(0),
158-
};
159-
let forward_node = ForwardNode {
160-
tlvs: ForwardTlvs {
161-
short_channel_id,
162-
payment_relay,
163-
payment_constraints,
164-
features: BlindedHopFeatures::empty(),
165-
},
166-
node_id: details.counterparty.node_id,
167-
htlc_maximum_msat: details.inbound_htlc_maximum_msat.unwrap_or(0),
168-
};
169-
BlindedPath::new_for_payment(
170-
&[forward_node], recipient, tlvs.clone(), u64::MAX, entropy_source, secp_ctx
171-
)
172-
})
173-
.collect()
174-
}
178+
) -> Result<Vec<(BlindedPayInfo, BlindedPath)>, ()>;
175179
}
176180

177181
/// [`ScoreLookUp`] implementation that factors in in-flight HTLC liquidity.

lightning/src/util/test_utils.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// licenses.
99

1010
use crate::blinded_path::BlindedPath;
11+
use crate::blinded_path::payment::ReceiveTlvs;
1112
use crate::chain;
1213
use crate::chain::WatchedOutput;
1314
use crate::chain::chaininterface;
@@ -23,13 +24,13 @@ use crate::sign;
2324
use crate::events;
2425
use crate::events::bump_transaction::{WalletSource, Utxo};
2526
use crate::ln::ChannelId;
26-
use crate::ln::channelmanager;
27+
use crate::ln::channelmanager::{ChannelDetails, self};
2728
use crate::ln::chan_utils::CommitmentTransaction;
2829
use crate::ln::features::{ChannelFeatures, InitFeatures, NodeFeatures};
2930
use crate::ln::{msgs, wire};
3031
use crate::ln::msgs::LightningError;
3132
use crate::ln::script::ShutdownScript;
32-
use crate::offers::invoice::UnsignedBolt12Invoice;
33+
use crate::offers::invoice::{BlindedPayInfo, UnsignedBolt12Invoice};
3334
use crate::offers::invoice_request::UnsignedInvoiceRequest;
3435
use crate::onion_message::{Destination, MessageRouter, OnionMessagePath};
3536
use crate::routing::gossip::{EffectiveCapacity, NetworkGraph, NodeId, RoutingFees};
@@ -120,7 +121,7 @@ impl<'a> TestRouter<'a> {
120121

121122
impl<'a> Router for TestRouter<'a> {
122123
fn find_route(
123-
&self, payer: &PublicKey, params: &RouteParameters, first_hops: Option<&[&channelmanager::ChannelDetails]>,
124+
&self, payer: &PublicKey, params: &RouteParameters, first_hops: Option<&[&ChannelDetails]>,
124125
inflight_htlcs: InFlightHtlcs
125126
) -> Result<Route, msgs::LightningError> {
126127
if let Some((find_route_query, find_route_res)) = self.next_routes.lock().unwrap().pop_front() {
@@ -190,6 +191,15 @@ impl<'a> Router for TestRouter<'a> {
190191
&[42; 32]
191192
)
192193
}
194+
195+
fn create_blinded_payment_paths<
196+
ES: EntropySource + ?Sized, T: secp256k1::Signing + secp256k1::Verification
197+
>(
198+
&self, _recipient: PublicKey, _first_hops: Vec<ChannelDetails>, _tlvs: ReceiveTlvs,
199+
_amount_msats: u64, _entropy_source: &ES, _secp_ctx: &Secp256k1<T>
200+
) -> Result<Vec<(BlindedPayInfo, BlindedPath)>, ()> {
201+
unreachable!()
202+
}
193203
}
194204

195205
impl<'a> MessageRouter for TestRouter<'a> {

0 commit comments

Comments
 (0)