Skip to content

Commit 3324799

Browse files
authored
Merge pull request #4060 from wpaulino/splice-misc-fixes
Fix minor miscellaneous splicing issues
2 parents 4e32d85 + 1dc190d commit 3324799

File tree

15 files changed

+339
-429
lines changed

15 files changed

+339
-429
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ check-cfg = [
6565
"cfg(ldk_test_vectors)",
6666
"cfg(taproot)",
6767
"cfg(require_route_graph_test)",
68-
"cfg(splicing)",
6968
"cfg(simple_close)",
7069
"cfg(peer_storage)",
7170
]

ci/ci-tests.sh

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,6 @@ fi
151151
echo -e "\n\nTest cfg-flag builds"
152152
RUSTFLAGS="--cfg=taproot" cargo test --verbose --color always -p lightning
153153
[ "$CI_MINIMIZE_DISK_USAGE" != "" ] && cargo clean
154-
RUSTFLAGS="--cfg=splicing" cargo test --verbose --color always -p lightning
155-
[ "$CI_MINIMIZE_DISK_USAGE" != "" ] && cargo clean
156154
RUSTFLAGS="--cfg=async_payments" cargo test --verbose --color always -p lightning
157155
[ "$CI_MINIMIZE_DISK_USAGE" != "" ] && cargo clean
158156
RUSTFLAGS="--cfg=simple_close" cargo test --verbose --color always -p lightning

lightning-net-tokio/src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -742,11 +742,8 @@ mod tests {
742742
fn handle_open_channel_v2(&self, _their_node_id: PublicKey, _msg: &OpenChannelV2) {}
743743
fn handle_accept_channel_v2(&self, _their_node_id: PublicKey, _msg: &AcceptChannelV2) {}
744744
fn handle_stfu(&self, _their_node_id: PublicKey, _msg: &Stfu) {}
745-
#[cfg(splicing)]
746745
fn handle_splice_init(&self, _their_node_id: PublicKey, _msg: &SpliceInit) {}
747-
#[cfg(splicing)]
748746
fn handle_splice_ack(&self, _their_node_id: PublicKey, _msg: &SpliceAck) {}
749-
#[cfg(splicing)]
750747
fn handle_splice_locked(&self, _their_node_id: PublicKey, _msg: &SpliceLocked) {}
751748
fn handle_tx_add_input(&self, _their_node_id: PublicKey, _msg: &TxAddInput) {}
752749
fn handle_tx_add_output(&self, _their_node_id: PublicKey, _msg: &TxAddOutput) {}

lightning/src/chain/channelmonitor.rs

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3399,26 +3399,35 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
33993399

34003400
// Prune HTLCs from the previous counterparty commitment tx so we don't generate failure/fulfill
34013401
// events for now-revoked/fulfilled HTLCs.
3402-
if let Some(txid) = self.funding.prev_counterparty_commitment_txid.take() {
3403-
if self.funding.current_counterparty_commitment_txid.unwrap() != txid {
3404-
let cur_claimables = self.funding.counterparty_claimable_outpoints.get(
3405-
&self.funding.current_counterparty_commitment_txid.unwrap()).unwrap();
3406-
for (_, ref source_opt) in self.funding.counterparty_claimable_outpoints.get(&txid).unwrap() {
3407-
if let Some(source) = source_opt {
3408-
if !cur_claimables.iter()
3409-
.any(|(_, cur_source_opt)| cur_source_opt == source_opt)
3410-
{
3411-
self.counterparty_fulfilled_htlcs.remove(&SentHTLCId::from_source(source));
3402+
let mut removed_fulfilled_htlcs = false;
3403+
let prune_htlc_sources = |funding: &mut FundingScope| {
3404+
if let Some(txid) = funding.prev_counterparty_commitment_txid.take() {
3405+
if funding.current_counterparty_commitment_txid.unwrap() != txid {
3406+
let cur_claimables = funding.counterparty_claimable_outpoints.get(
3407+
&funding.current_counterparty_commitment_txid.unwrap()).unwrap();
3408+
// We only need to remove fulfilled HTLCs once for the first `FundingScope` we
3409+
// come across since all `FundingScope`s share the same set of HTLC sources.
3410+
if !removed_fulfilled_htlcs {
3411+
for (_, ref source_opt) in funding.counterparty_claimable_outpoints.get(&txid).unwrap() {
3412+
if let Some(source) = source_opt {
3413+
if !cur_claimables.iter()
3414+
.any(|(_, cur_source_opt)| cur_source_opt == source_opt)
3415+
{
3416+
self.counterparty_fulfilled_htlcs.remove(&SentHTLCId::from_source(source));
3417+
}
3418+
}
34123419
}
3420+
removed_fulfilled_htlcs = true;
34133421
}
3422+
for &mut (_, ref mut source_opt) in funding.counterparty_claimable_outpoints.get_mut(&txid).unwrap() {
3423+
*source_opt = None;
3424+
}
3425+
} else {
3426+
assert!(cfg!(fuzzing), "Commitment txids are unique outside of fuzzing, where hashes can collide");
34143427
}
3415-
for &mut (_, ref mut source_opt) in self.funding.counterparty_claimable_outpoints.get_mut(&txid).unwrap() {
3416-
*source_opt = None;
3417-
}
3418-
} else {
3419-
assert!(cfg!(fuzzing), "Commitment txids are unique outside of fuzzing, where hashes can collide");
34203428
}
3421-
}
3429+
};
3430+
core::iter::once(&mut self.funding).chain(&mut self.pending_funding).for_each(prune_htlc_sources);
34223431

34233432
if !self.payment_preimages.is_empty() {
34243433
let min_idx = self.get_min_seen_secret();
@@ -4049,6 +4058,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
40494058

40504059
mem::swap(&mut self.funding, &mut new_funding);
40514060
self.onchain_tx_handler.update_after_renegotiated_funding_locked(
4061+
self.funding.channel_parameters.clone(),
40524062
self.funding.current_holder_commitment_tx.clone(),
40534063
self.funding.prev_holder_commitment_tx.clone(),
40544064
);
@@ -5164,6 +5174,10 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
51645174
let txid = tx.compute_txid();
51655175
log_trace!(logger, "Transaction {} confirmed in block {}", txid , block_hash);
51665176
// If a transaction has already been confirmed, ensure we don't bother processing it duplicatively.
5177+
if self.alternative_funding_confirmed.map(|(alternative_funding_txid, _)| alternative_funding_txid == txid).unwrap_or(false) {
5178+
log_debug!(logger, "Skipping redundant processing of funding-spend tx {} as it was previously confirmed", txid);
5179+
continue 'tx_iter;
5180+
}
51675181
if Some(txid) == self.funding_spend_confirmed {
51685182
log_debug!(logger, "Skipping redundant processing of funding-spend tx {} as it was previously confirmed", txid);
51695183
continue 'tx_iter;

lightning/src/chain/onchaintx.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,11 +1236,14 @@ impl<ChannelSigner: EcdsaChannelSigner> OnchainTxHandler<ChannelSigner> {
12361236
self.prev_holder_commitment = Some(replace(&mut self.holder_commitment, tx));
12371237
}
12381238

1239-
/// Replaces the current/prev holder commitment transactions spending the currently confirmed
1240-
/// funding outpoint with those spending the new funding outpoint.
1239+
/// Replaces all the data pertaining to the currently locked funding transaction after a new
1240+
/// funding transaction has been renegotiated and locked.
12411241
pub(crate) fn update_after_renegotiated_funding_locked(
1242-
&mut self, current: HolderCommitmentTransaction, prev: Option<HolderCommitmentTransaction>,
1242+
&mut self, channel_parameters: ChannelTransactionParameters,
1243+
current: HolderCommitmentTransaction, prev: Option<HolderCommitmentTransaction>,
12431244
) {
1245+
self.channel_value_satoshis = channel_parameters.channel_value_satoshis;
1246+
self.channel_transaction_parameters = channel_parameters;
12441247
self.holder_commitment = current;
12451248
self.prev_holder_commitment = prev;
12461249
}

0 commit comments

Comments
 (0)