Skip to content

Commit 9c5dccd

Browse files
committed
Add integration test for InvoicePayerretry on an immediate failure
1 parent 2b8c287 commit 9c5dccd

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

lightning-invoice/src/payment.rs

+45
Original file line numberDiff line numberDiff line change
@@ -1259,4 +1259,49 @@ mod tests {
12591259
assert_eq!(htlc_msgs.len(), 2);
12601260
check_added_monitors!(nodes[0], 2);
12611261
}
1262+
1263+
#[test]
1264+
fn immediate_retry_on_failure() {
1265+
// Tests that we can/will retry immediately after a failure
1266+
let chanmon_cfgs = create_chanmon_cfgs(2);
1267+
let node_cfgs = create_node_cfgs(2, &chanmon_cfgs);
1268+
let node_chanmgrs = create_node_chanmgrs(2, &node_cfgs, &[None, None, None]);
1269+
let nodes = create_network(2, &node_cfgs, &node_chanmgrs);
1270+
1271+
create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 0, InitFeatures::known(), InitFeatures::known());
1272+
create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1_000_000, 0, InitFeatures::known(), InitFeatures::known());
1273+
let chans = nodes[0].node.list_usable_channels();
1274+
let mut route = Route {
1275+
paths: vec![
1276+
vec![RouteHop {
1277+
pubkey: nodes[1].node.get_our_node_id(),
1278+
node_features: NodeFeatures::known(),
1279+
short_channel_id: chans[0].short_channel_id.unwrap(),
1280+
channel_features: ChannelFeatures::known(),
1281+
fee_msat: 100_000_001, // Our default max-HTLC-value is 10% of the channel value, which this is one more than
1282+
cltv_expiry_delta: 100,
1283+
}],
1284+
],
1285+
payee: Some(Payee::new(nodes[1].node.get_our_node_id())),
1286+
};
1287+
let router = ManualRouter(RefCell::new(VecDeque::new()));
1288+
router.expect_find_route(Ok(route.clone()));
1289+
// On retry, split the payment across both channels.
1290+
route.paths.push(route.paths[0].clone());
1291+
route.paths[0][0].short_channel_id = chans[1].short_channel_id.unwrap();
1292+
route.paths[0][0].fee_msat = 50_000_000;
1293+
route.paths[1][0].fee_msat = 50_000_001;
1294+
router.expect_find_route(Ok(route.clone()));
1295+
1296+
let event_handler = |_: &_| { panic!(); };
1297+
let scorer = RefCell::new(TestScorer::new());
1298+
let invoice_payer = InvoicePayer::new(nodes[0].node, router, &scorer, nodes[0].logger, event_handler, RetryAttempts(1));
1299+
1300+
assert!(invoice_payer.pay_invoice(&create_invoice_from_channelmanager(
1301+
&nodes[1].node, nodes[1].keys_manager, Currency::Bitcoin, Some(100_010_000), "Invoice".to_string()).unwrap())
1302+
.is_ok());
1303+
let htlc_msgs = nodes[0].node.get_and_clear_pending_msg_events();
1304+
assert_eq!(htlc_msgs.len(), 2);
1305+
check_added_monitors!(nodes[0], 2);
1306+
}
12621307
}

0 commit comments

Comments
 (0)