Skip to content

Commit 2bd09e4

Browse files
Hold peer lock when pushing to decode_update_adds
This avoids race conditions where we're unable to properly update an HTLC's state because we need to update its state in the ChannelManager, but the HTLC is stuck in transit from the Channel to ChannelManager::decode_update_add_htlcs. Now the HTLC will atomically go from the Channel to the ChannelManager decode queue under the same lock.
1 parent 8cab7d0 commit 2bd09e4

1 file changed

Lines changed: 12 additions & 14 deletions

File tree

lightning/src/ln/channelmanager.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,7 +1516,6 @@ enum PostMonitorUpdateChanResume {
15161516
unbroadcasted_batch_funding_txid: Option<Txid>,
15171517
update_actions: Vec<MonitorUpdateCompletionAction>,
15181518
htlc_forwards: Vec<PendingAddHTLCInfo>,
1519-
decode_update_add_htlcs: Option<(u64, Vec<msgs::UpdateAddHTLC>)>,
15201519
finalized_claimed_htlcs: Vec<(HTLCSource, Option<AttributionData>)>,
15211520
failed_htlcs: Vec<(HTLCSource, PaymentHash, HTLCFailReason)>,
15221521
committed_outbound_htlc_sources: Vec<(HTLCPreviousHopData, u64)>,
@@ -10116,7 +10115,6 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1011610115
&self, channel_id: ChannelId, counterparty_node_id: PublicKey, funding_txo: OutPoint,
1011710116
user_channel_id: u128, unbroadcasted_batch_funding_txid: Option<Txid>,
1011810117
update_actions: Vec<MonitorUpdateCompletionAction>, htlc_forwards: Vec<PendingAddHTLCInfo>,
10119-
decode_update_add_htlcs: Option<(u64, Vec<msgs::UpdateAddHTLC>)>,
1012010118
finalized_claimed_htlcs: Vec<(HTLCSource, Option<AttributionData>)>,
1012110119
failed_htlcs: Vec<(HTLCSource, PaymentHash, HTLCFailReason)>,
1012210120
committed_outbound_htlc_sources: Vec<(HTLCPreviousHopData, u64)>,
@@ -10177,9 +10175,6 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1017710175
self.handle_monitor_update_completion_actions(update_actions);
1017810176

1017910177
self.forward_htlcs(htlc_forwards);
10180-
if let Some(decode) = decode_update_add_htlcs {
10181-
self.push_decode_update_add_htlcs(decode);
10182-
}
1018310178
self.finalize_claims(finalized_claimed_htlcs);
1018410179
for failure in failed_htlcs {
1018510180
let failure_type = failure.0.failure_type(counterparty_node_id, channel_id);
@@ -10667,6 +10662,10 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1066710662
pending_msg_events.push(upd);
1066810663
}
1066910664

10665+
if let Some(update_adds) = decode_update_add_htlcs {
10666+
self.push_decode_update_add_htlcs(update_adds);
10667+
}
10668+
1067010669
let unbroadcasted_batch_funding_txid =
1067110670
chan.context.unbroadcasted_batch_funding_txid(&chan.funding);
1067210671

@@ -10678,7 +10677,6 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1067810677
unbroadcasted_batch_funding_txid,
1067910678
update_actions,
1068010679
htlc_forwards,
10681-
decode_update_add_htlcs,
1068210680
finalized_claimed_htlcs: updates.finalized_claimed_htlcs,
1068310681
failed_htlcs: updates.failed_htlcs,
1068410682
committed_outbound_htlc_sources: updates.committed_outbound_htlc_sources,
@@ -10780,7 +10778,6 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1078010778
unbroadcasted_batch_funding_txid,
1078110779
update_actions,
1078210780
htlc_forwards,
10783-
decode_update_add_htlcs,
1078410781
finalized_claimed_htlcs,
1078510782
failed_htlcs,
1078610783
committed_outbound_htlc_sources,
@@ -10793,7 +10790,6 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1079310790
unbroadcasted_batch_funding_txid,
1079410791
update_actions,
1079510792
htlc_forwards,
10796-
decode_update_add_htlcs,
1079710793
finalized_claimed_htlcs,
1079810794
failed_htlcs,
1079910795
committed_outbound_htlc_sources,
@@ -17920,12 +17916,6 @@ impl<
1792017916
}
1792117917
}
1792217918

17923-
let mut decode_update_add_htlcs_opt = None;
17924-
let decode_update_add_htlcs = self.decode_update_add_htlcs.lock().unwrap();
17925-
if !decode_update_add_htlcs.is_empty() {
17926-
decode_update_add_htlcs_opt = Some(decode_update_add_htlcs);
17927-
}
17928-
1792917919
let claimable_payments = self.claimable_payments.lock().unwrap();
1793017920
let pending_outbound_payments = self.pending_outbound_payments.pending_outbound_payments.lock().unwrap();
1793117921

@@ -17951,6 +17941,14 @@ impl<
1795117941
peer_states.push(peer_state_mutex.unsafe_well_ordered_double_lock_self());
1795217942
}
1795317943

17944+
let mut decode_update_add_htlcs_opt = None;
17945+
{
17946+
let decode_update_add_htlcs = self.decode_update_add_htlcs.lock().unwrap();
17947+
if !decode_update_add_htlcs.is_empty() {
17948+
decode_update_add_htlcs_opt = Some(decode_update_add_htlcs);
17949+
}
17950+
}
17951+
1795417952
let mut peer_storage_dir: Vec<(&PublicKey, &Vec<u8>)> = Vec::new();
1795517953

1795617954
(serializable_peer_count).write(writer)?;

0 commit comments

Comments
 (0)