mirror of
https://github.com/lightningdevkit/rust-lightning.git
synced 2025-02-25 07:17:40 +01:00
Struct-ify test util pass_along_path args.
Lays groundwork to make pass_along_path easier to adapt without changing a million callsites.
This commit is contained in:
parent
2c22055589
commit
203be7096e
3 changed files with 78 additions and 8 deletions
|
@ -2472,7 +2472,60 @@ fn fail_payment_along_path<'a, 'b, 'c>(expected_path: &[&Node<'a, 'b, 'c>]) {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn do_pass_along_path<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_path: &[&Node<'a, 'b, 'c>], recv_value: u64, our_payment_hash: PaymentHash, our_payment_secret: Option<PaymentSecret>, ev: MessageSendEvent, payment_claimable_expected: bool, clear_recipient_events: bool, expected_preimage: Option<PaymentPreimage>, is_probe: bool) -> Option<Event> {
|
||||
pub struct PassAlongPathArgs<'a, 'b, 'c, 'd> {
|
||||
pub origin_node: &'a Node<'b, 'c, 'd>,
|
||||
pub expected_path: &'a [&'a Node<'b, 'c, 'd>],
|
||||
pub recv_value: u64,
|
||||
pub payment_hash: PaymentHash,
|
||||
pub payment_secret: Option<PaymentSecret>,
|
||||
pub event: MessageSendEvent,
|
||||
pub payment_claimable_expected: bool,
|
||||
pub clear_recipient_events: bool,
|
||||
pub expected_preimage: Option<PaymentPreimage>,
|
||||
pub is_probe: bool,
|
||||
}
|
||||
|
||||
impl<'a, 'b, 'c, 'd> PassAlongPathArgs<'a, 'b, 'c, 'd> {
|
||||
pub fn new(
|
||||
origin_node: &'a Node<'b, 'c, 'd>, expected_path: &'a [&'a Node<'b, 'c, 'd>], recv_value: u64,
|
||||
payment_hash: PaymentHash, event: MessageSendEvent,
|
||||
) -> Self {
|
||||
Self {
|
||||
origin_node, expected_path, recv_value, payment_hash, payment_secret: None, event,
|
||||
payment_claimable_expected: true, clear_recipient_events: true, expected_preimage: None,
|
||||
is_probe: false,
|
||||
}
|
||||
}
|
||||
pub fn without_clearing_recipient_events(mut self) -> Self {
|
||||
self.clear_recipient_events = false;
|
||||
self
|
||||
}
|
||||
pub fn is_probe(mut self) -> Self {
|
||||
self.payment_claimable_expected = false;
|
||||
self.is_probe = true;
|
||||
self
|
||||
}
|
||||
pub fn without_claimable_event(mut self) -> Self {
|
||||
self.payment_claimable_expected = false;
|
||||
self
|
||||
}
|
||||
pub fn with_payment_secret(mut self, payment_secret: PaymentSecret) -> Self {
|
||||
self.payment_secret = Some(payment_secret);
|
||||
self
|
||||
}
|
||||
pub fn with_payment_preimage(mut self, payment_preimage: PaymentPreimage) -> Self {
|
||||
self.expected_preimage = Some(payment_preimage);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
pub fn do_pass_along_path<'a, 'b, 'c>(args: PassAlongPathArgs) -> Option<Event> {
|
||||
let PassAlongPathArgs {
|
||||
origin_node, expected_path, recv_value, payment_hash: our_payment_hash,
|
||||
payment_secret: our_payment_secret, event: ev, payment_claimable_expected,
|
||||
clear_recipient_events, expected_preimage, is_probe
|
||||
} = args;
|
||||
|
||||
let mut payment_event = SendEvent::from_event(ev);
|
||||
let mut prev_node = origin_node;
|
||||
let mut event = None;
|
||||
|
@ -2539,7 +2592,17 @@ pub fn do_pass_along_path<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_p
|
|||
}
|
||||
|
||||
pub fn pass_along_path<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_path: &[&Node<'a, 'b, 'c>], recv_value: u64, our_payment_hash: PaymentHash, our_payment_secret: Option<PaymentSecret>, ev: MessageSendEvent, payment_claimable_expected: bool, expected_preimage: Option<PaymentPreimage>) -> Option<Event> {
|
||||
do_pass_along_path(origin_node, expected_path, recv_value, our_payment_hash, our_payment_secret, ev, payment_claimable_expected, true, expected_preimage, false)
|
||||
let mut args = PassAlongPathArgs::new(origin_node, expected_path, recv_value, our_payment_hash, ev);
|
||||
if !payment_claimable_expected {
|
||||
args = args.without_claimable_event();
|
||||
}
|
||||
if let Some(payment_secret) = our_payment_secret {
|
||||
args = args.with_payment_secret(payment_secret);
|
||||
}
|
||||
if let Some(payment_preimage) = expected_preimage {
|
||||
args = args.with_payment_preimage(payment_preimage);
|
||||
}
|
||||
do_pass_along_path(args)
|
||||
}
|
||||
|
||||
pub fn send_probe_along_route<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_route: &[&[&Node<'a, 'b, 'c>]]) {
|
||||
|
@ -2551,7 +2614,10 @@ pub fn send_probe_along_route<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expect
|
|||
for path in expected_route.iter() {
|
||||
let ev = remove_first_msg_event_to_node(&path[0].node.get_our_node_id(), &mut events);
|
||||
|
||||
do_pass_along_path(origin_node, path, 0, PaymentHash([0_u8; 32]), None, ev, false, false, None, true);
|
||||
do_pass_along_path(PassAlongPathArgs::new(origin_node, path, 0, PaymentHash([0_u8; 32]), ev)
|
||||
.is_probe()
|
||||
.without_clearing_recipient_events());
|
||||
|
||||
let nodes_to_fail_payment: Vec<_> = vec![origin_node].into_iter().chain(path.iter().cloned()).collect();
|
||||
|
||||
fail_payment_along_path(nodes_to_fail_payment.as_slice());
|
||||
|
|
|
@ -112,9 +112,9 @@ fn route_bolt12_payment<'a, 'b, 'c>(
|
|||
// invoice contains the payment_hash but it was encrypted inside an onion message.
|
||||
let amount_msats = invoice.amount_msats();
|
||||
let payment_hash = invoice.payment_hash();
|
||||
do_pass_along_path(
|
||||
node, path, amount_msats, payment_hash, None, ev, false, false, None, false
|
||||
);
|
||||
let args = PassAlongPathArgs::new(node, path, amount_msats, payment_hash, ev)
|
||||
.without_clearing_recipient_events();
|
||||
do_pass_along_path(args);
|
||||
}
|
||||
|
||||
fn claim_bolt12_payment<'a, 'b, 'c>(node: &Node<'a, 'b, 'c>, path: &[&Node<'a, 'b, 'c>]) {
|
||||
|
|
|
@ -823,8 +823,12 @@ fn do_test_partial_claim_before_restart(persist_both_monitors: bool) {
|
|||
assert_eq!(send_events.len(), 2);
|
||||
let node_1_msgs = remove_first_msg_event_to_node(&nodes[1].node.get_our_node_id(), &mut send_events);
|
||||
let node_2_msgs = remove_first_msg_event_to_node(&nodes[2].node.get_our_node_id(), &mut send_events);
|
||||
do_pass_along_path(&nodes[0], &[&nodes[1], &nodes[3]], 15_000_000, payment_hash, Some(payment_secret), node_1_msgs, true, false, None, false);
|
||||
do_pass_along_path(&nodes[0], &[&nodes[2], &nodes[3]], 15_000_000, payment_hash, Some(payment_secret), node_2_msgs, true, false, None, false);
|
||||
do_pass_along_path(PassAlongPathArgs::new(&nodes[0],&[&nodes[1], &nodes[3]], 15_000_000, payment_hash, node_1_msgs)
|
||||
.with_payment_secret(payment_secret)
|
||||
.without_clearing_recipient_events());
|
||||
do_pass_along_path(PassAlongPathArgs::new(&nodes[0], &[&nodes[2], &nodes[3]], 15_000_000, payment_hash, node_2_msgs)
|
||||
.with_payment_secret(payment_secret)
|
||||
.without_clearing_recipient_events());
|
||||
|
||||
// Now that we have an MPP payment pending, get the latest encoded copies of nodes[3]'s
|
||||
// monitors and ChannelManager, for use later, if we don't want to persist both monitors.
|
||||
|
|
Loading…
Add table
Reference in a new issue