Skip to content

Commit 38bcda3

Browse files
committed
Update PaymentPath args
1 parent 98ba859 commit 38bcda3

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

lightning/src/ln/functional_test_utils.rs

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ use crate::ln::peer_handler::IgnoringMessageHandler;
3737
use crate::ln::types::ChannelId;
3838
use crate::onion_message::messenger::OnionMessenger;
3939
use crate::routing::gossip::{NetworkGraph, NetworkUpdate, P2PGossipSync};
40-
use crate::routing::router::{self, PaymentParameters, Route, RouteParameters};
40+
use crate::routing::router::{
41+
self, PaymentParameters, Route, RouteParameters, DEFAULT_PAYMENT_DUMMY_HOPS,
42+
};
4143
use crate::sign::{EntropySource, RandomBytes};
4244
use crate::types::features::ChannelTypeFeatures;
4345
use crate::types::features::InitFeatures;
@@ -3276,6 +3278,7 @@ fn fail_payment_along_path<'a, 'b, 'c>(expected_path: &[&Node<'a, 'b, 'c>]) {
32763278
pub struct PassAlongPathArgs<'a, 'b, 'c, 'd> {
32773279
pub origin_node: &'a Node<'b, 'c, 'd>,
32783280
pub expected_path: &'a [&'a Node<'b, 'c, 'd>],
3281+
pub dummy_hop_override: Option<usize>,
32793282
pub recv_value: u64,
32803283
pub payment_hash: PaymentHash,
32813284
pub payment_secret: Option<PaymentSecret>,
@@ -3297,6 +3300,7 @@ impl<'a, 'b, 'c, 'd> PassAlongPathArgs<'a, 'b, 'c, 'd> {
32973300
Self {
32983301
origin_node,
32993302
expected_path,
3303+
dummy_hop_override: None,
33003304
recv_value,
33013305
payment_hash,
33023306
payment_secret: None,
@@ -3344,12 +3348,17 @@ impl<'a, 'b, 'c, 'd> PassAlongPathArgs<'a, 'b, 'c, 'd> {
33443348
self.expected_failure = Some(failure);
33453349
self
33463350
}
3351+
pub fn with_dummy_override(mut self, dummy_override: usize) -> Self {
3352+
self.dummy_hop_override = Some(dummy_override);
3353+
self
3354+
}
33473355
}
33483356

33493357
pub fn do_pass_along_path<'a, 'b, 'c>(args: PassAlongPathArgs) -> Option<Event> {
33503358
let PassAlongPathArgs {
33513359
origin_node,
33523360
expected_path,
3361+
dummy_hop_override,
33533362
recv_value,
33543363
payment_hash: our_payment_hash,
33553364
payment_secret: our_payment_secret,
@@ -3383,6 +3392,14 @@ pub fn do_pass_along_path<'a, 'b, 'c>(args: PassAlongPathArgs) -> Option<Event>
33833392
node.node.process_pending_htlc_forwards();
33843393
}
33853394

3395+
if is_last_hop {
3396+
let dummy_count = dummy_hop_override.unwrap_or(DEFAULT_PAYMENT_DUMMY_HOPS);
3397+
for _ in 0..dummy_count {
3398+
println!("This ran");
3399+
node.node.process_pending_htlc_forwards();
3400+
}
3401+
}
3402+
33863403
if is_last_hop && clear_recipient_events {
33873404
let events_2 = node.node.get_and_clear_pending_events();
33883405
if payment_claimable_expected {
@@ -3494,9 +3511,33 @@ pub fn pass_along_path<'a, 'b, 'c>(
34943511
origin_node: &Node<'a, 'b, 'c>, expected_path: &[&Node<'a, 'b, 'c>], recv_value: u64,
34953512
our_payment_hash: PaymentHash, our_payment_secret: Option<PaymentSecret>, ev: MessageSendEvent,
34963513
payment_claimable_expected: bool, expected_preimage: Option<PaymentPreimage>,
3514+
) -> Option<Event> {
3515+
pass_along_path_with_dummy(
3516+
origin_node,
3517+
expected_path,
3518+
None, // no dummy hops
3519+
recv_value,
3520+
our_payment_hash,
3521+
our_payment_secret,
3522+
ev,
3523+
payment_claimable_expected,
3524+
expected_preimage,
3525+
)
3526+
}
3527+
3528+
pub fn pass_along_path_with_dummy<'a, 'b, 'c>(
3529+
origin_node: &Node<'a, 'b, 'c>, expected_path: &[&Node<'a, 'b, 'c>],
3530+
dummy_count: Option<usize>, recv_value: u64, our_payment_hash: PaymentHash,
3531+
our_payment_secret: Option<PaymentSecret>, ev: MessageSendEvent,
3532+
payment_claimable_expected: bool, expected_preimage: Option<PaymentPreimage>,
34973533
) -> Option<Event> {
34983534
let mut args =
34993535
PassAlongPathArgs::new(origin_node, expected_path, recv_value, our_payment_hash, ev);
3536+
3537+
if let Some(count) = dummy_count {
3538+
args = args.with_dummy_override(count);
3539+
}
3540+
35003541
if !payment_claimable_expected {
35013542
args = args.without_claimable_event();
35023543
}

lightning/src/routing/router.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ pub struct DefaultRouter<
7474
score_params: SP,
7575
}
7676

77+
/// Default number of Dummy Hops
78+
pub const DEFAULT_PAYMENT_DUMMY_HOPS: usize = 0;
79+
7780
impl<
7881
G: Deref<Target = NetworkGraph<L>>,
7982
L: Deref,

0 commit comments

Comments
 (0)