Skip to content

Commit 3d19e8a

Browse files
committed
Add integration test for InvoicePayerretry on an immediate failure
1 parent 514df33 commit 3d19e8a

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

lightning-invoice/src/payment.rs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,4 +1246,50 @@ mod tests {
12461246
check_added_monitors!(nodes[0], 2);
12471247
assert!(!*event_handled.borrow());
12481248
}
1249+
1250+
#[test]
1251+
fn immediate_retry_on_failure() {
1252+
// Tests that we can/will retry immediately after a failure
1253+
let chanmon_cfgs = create_chanmon_cfgs(2);
1254+
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
1255+
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None, None]);
1256+
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
1257+
1258+
create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 0, InitFeatures::known(), InitFeatures::known());
1259+
create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 0, InitFeatures::known(), InitFeatures::known());
1260+
let chans = nodes[0].node.list_usable_channels();
1261+
let mut route = Route {
1262+
paths: vec![
1263+
vec![RouteHop {
1264+
pubkey: nodes[1].node.get_our_node_id(),
1265+
node_features: NodeFeatures::known(),
1266+
short_channel_id: chans[0].short_channel_id.unwrap(),
1267+
channel_features: ChannelFeatures::known(),
1268+
fee_msat: 100_000_001, // Our default max-HTLC-value is 10% of the channel value
1269+
cltv_expiry_delta: 100,
1270+
}],
1271+
],
1272+
payee: Some(Payee::new(nodes[1].node.get_our_node_id())),
1273+
};
1274+
let mut routes = LinkedList::new();
1275+
routes.push_back(Ok(route.clone()));
1276+
// On retry, split the payment across both channels.
1277+
route.paths.push(route.paths[0].clone());
1278+
route.paths[0][0].short_channel_id = chans[1].short_channel_id.unwrap();
1279+
route.paths[0][0].fee_msat = 50_000_000;
1280+
route.paths[1][0].fee_msat = 50_000_001;
1281+
routes.push_back(Ok(route.clone()));
1282+
let route_res = ManualRouter(Mutex::new(routes));
1283+
1284+
let event_handled = core::cell::RefCell::new(false);
1285+
let event_handler = |_: &_| { *event_handled.borrow_mut() = true; };
1286+
let invoice_payer = InvoicePayer::new(nodes[0].node, route_res, nodes[0].logger, event_handler, RetryAttempts(1));
1287+
1288+
invoice_payer.pay_invoice(&create_invoice_from_channelmanager(
1289+
&nodes[1].node, nodes[1].keys_manager, Currency::Bitcoin, Some(100_010_000), "Invoice".to_string()).unwrap()).unwrap();
1290+
let htlc_msgs = nodes[0].node.get_and_clear_pending_msg_events();
1291+
assert_eq!(htlc_msgs.len(), 2);
1292+
check_added_monitors!(nodes[0], 2);
1293+
assert!(!*event_handled.borrow());
1294+
}
12491295
}

0 commit comments

Comments
 (0)