Skip to content

Commit c4fa1ef

Browse files
committed
Insert channel funding outputs into Wallet
When doing a splice, to properly calculate fees we need the channel's funding utxo in our wallet, otherwise our wallet won't know the channel's original size. This adds the channel funding txo on ChannelReady events and modifies the splicing test to make sure we can calculate fees on splice-ins.
1 parent 3c4236c commit c4fa1ef

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

src/event.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1458,6 +1458,33 @@ where
14581458
counterparty_node_id,
14591459
funding_txo,
14601460
);
1461+
1462+
let chans =
1463+
self.channel_manager.list_channels_with_counterparty(&counterparty_node_id);
1464+
let chan_output = chans
1465+
.iter()
1466+
.find(|c| c.user_channel_id == user_channel_id)
1467+
.and_then(|c| c.get_funding_output());
1468+
match chan_output {
1469+
None => {
1470+
log_error!(
1471+
self.logger,
1472+
"Failed to find channel info for pending channel {channel_id} with counterparty {counterparty_node_id}"
1473+
);
1474+
debug_assert!(false,
1475+
"Failed to find channel info for pending channel {channel_id} with counterparty {counterparty_node_id}"
1476+
);
1477+
},
1478+
Some(output) => {
1479+
if let Err(e) = self.wallet.insert_txo(funding_txo, output) {
1480+
log_error!(
1481+
self.logger,
1482+
"Failed to insert funding TXO into wallet: {e}"
1483+
);
1484+
return Err(ReplayEvent());
1485+
}
1486+
},
1487+
}
14611488
} else {
14621489
log_info!(
14631490
self.logger,

tests/integration_tests_rust.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -995,7 +995,7 @@ async fn splice_channel() {
995995
// Splice-in funds for Node B so that it has outbound liquidity to make a payment
996996
node_b.splice_in(&user_channel_id_b, node_a.node_id(), 4_000_000).unwrap();
997997

998-
expect_splice_pending_event!(node_a, node_b.node_id());
998+
let txo = expect_splice_pending_event!(node_a, node_b.node_id());
999999
expect_splice_pending_event!(node_b, node_a.node_id());
10001000

10011001
generate_blocks_and_wait(&bitcoind.client, &electrsd.client, 6).await;
@@ -1006,11 +1006,16 @@ async fn splice_channel() {
10061006
expect_channel_ready_event!(node_a, node_b.node_id());
10071007
expect_channel_ready_event!(node_b, node_a.node_id());
10081008

1009-
let splice_in_fee_sat = 252;
1009+
let expected_splice_in_fee_sat = 252;
1010+
1011+
let payments = node_b.list_payments();
1012+
let payment =
1013+
payments.into_iter().find(|p| p.id == PaymentId(txo.txid.to_byte_array())).unwrap();
1014+
assert_eq!(payment.fee_paid_msat, Some(expected_splice_in_fee_sat * 1_000));
10101015

10111016
assert_eq!(
10121017
node_b.list_balances().total_onchain_balance_sats,
1013-
premine_amount_sat - 4_000_000 - splice_in_fee_sat
1018+
premine_amount_sat - 4_000_000 - expected_splice_in_fee_sat
10141019
);
10151020
assert_eq!(node_b.list_balances().total_lightning_balance_sats, 4_000_000);
10161021

0 commit comments

Comments
 (0)