Skip to content

Commit 32d40c1

Browse files
committed
Add integration test for InvoicePayerretry on an immediate failure
1 parent 8aeb692 commit 32d40c1

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

lightning-invoice/src/payment.rs

+46
Original file line numberDiff line numberDiff line change
@@ -1130,4 +1130,50 @@ mod tests {
11301130
check_added_monitors!(nodes[0], 2);
11311131
assert!(!*event_handled.borrow());
11321132
}
1133+
1134+
#[test]
1135+
fn immediate_retry_on_failure() {
1136+
// Tests that we can/will retry immediately after a failure
1137+
let chanmon_cfgs = create_chanmon_cfgs(2);
1138+
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
1139+
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None, None]);
1140+
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
1141+
1142+
create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 0, InitFeatures::known(), InitFeatures::known());
1143+
create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 0, InitFeatures::known(), InitFeatures::known());
1144+
let chans = nodes[0].node.list_usable_channels();
1145+
let mut route = Route {
1146+
paths: vec![
1147+
vec![RouteHop {
1148+
pubkey: nodes[1].node.get_our_node_id(),
1149+
node_features: NodeFeatures::known(),
1150+
short_channel_id: chans[0].short_channel_id.unwrap(),
1151+
channel_features: ChannelFeatures::known(),
1152+
fee_msat: 100_000_001, // Our default max-HTLC-value is 10% of the channel value
1153+
cltv_expiry_delta: 100,
1154+
}],
1155+
],
1156+
payee: Some(Payee::new(nodes[1].node.get_our_node_id())),
1157+
};
1158+
let mut routes = LinkedList::new();
1159+
routes.push_back(Ok(route.clone()));
1160+
// On retry, split the payment across both channels.
1161+
route.paths.push(route.paths[0].clone());
1162+
route.paths[0][0].short_channel_id = chans[1].short_channel_id.unwrap();
1163+
route.paths[0][0].fee_msat = 50_000_000;
1164+
route.paths[1][0].fee_msat = 50_000_001;
1165+
routes.push_back(Ok(route.clone()));
1166+
let route_res = ManualRouter(Mutex::new(routes));
1167+
1168+
let event_handled = core::cell::RefCell::new(false);
1169+
let event_handler = |_: &_| { *event_handled.borrow_mut() = true; };
1170+
let invoice_payer = InvoicePayer::new(nodes[0].node, route_res, nodes[0].logger, event_handler, RetryAttempts(1));
1171+
1172+
invoice_payer.pay_invoice(&create_invoice_from_channelmanager(
1173+
&nodes[1].node, nodes[1].keys_manager, Currency::Bitcoin, Some(100_010_000), "Invoice".to_string()).unwrap()).unwrap();
1174+
let htlc_msgs = nodes[0].node.get_and_clear_pending_msg_events();
1175+
assert_eq!(htlc_msgs.len(), 2);
1176+
check_added_monitors!(nodes[0], 2);
1177+
assert!(!*event_handled.borrow());
1178+
}
11331179
}

0 commit comments

Comments
 (0)