Skip to content

Commit 11a5a7b

Browse files
committed
Add integration test for InvoicePayerretry on an immediate failure
1 parent 0b44713 commit 11a5a7b

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

0 commit comments

Comments
 (0)