Skip to content

Commit 0fd5b66

Browse files
committed
fix: release rgb_send_lock on all channel open failure paths
Three targeted fixes in the LDK event handlers: - FundingGenerationReady: release lock unconditionally after funding_transaction_generated(), not just on error. Once the funding TX is handed to LDK the RGB wallet operations are complete. - ChannelPending: release lock before spawn_blocking so it is freed even if the subsequent rgb_send_end task panics. - ChannelClosed: release lock when channel_funding_txo is None (channel closed during negotiation, before any funding was created). Ref: #111
1 parent 2e507b6 commit 0fd5b66

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

src/ldk.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -690,8 +690,8 @@ async fn handle_ldk_events(
690690
{
691691
tracing::error!(
692692
"ERROR: Channel went away before we could fund it. The peer disconnected or refused the channel.");
693-
*unlocked_state.rgb_send_lock.lock().unwrap() = false;
694693
}
694+
*unlocked_state.rgb_send_lock.lock().unwrap() = false;
695695
}
696696
Event::FundingTxBroadcastSafe { .. } => {
697697
// We don't use the manual broadcasting feature, so this event should never be seen.
@@ -1055,6 +1055,8 @@ async fn handle_ldk_events(
10551055
is_channel_rgb(&channel_id, &PathBuf::from(&static_state.ldk_data_dir));
10561056
tracing::info!("Initiator of the channel (colored: {})", is_chan_colored);
10571057

1058+
*unlocked_state.rgb_send_lock.lock().unwrap() = false;
1059+
10581060
let _txid = tokio::task::spawn_blocking(move || {
10591061
if is_chan_colored {
10601062
state_copy.rgb_send_end(psbt_str_copy).map(|r| r.txid)
@@ -1068,8 +1070,6 @@ async fn handle_ldk_events(
10681070
tracing::error!("Error completing channel opening: {e:?}");
10691071
ReplayEvent()
10701072
})?;
1071-
1072-
*unlocked_state.rgb_send_lock.lock().unwrap() = false;
10731073
} else {
10741074
// acceptor
10751075
let consignment_path = static_state
@@ -1115,7 +1115,7 @@ async fn handle_ldk_events(
11151115
user_channel_id: _,
11161116
counterparty_node_id,
11171117
channel_capacity_sats: _,
1118-
channel_funding_txo: _,
1118+
channel_funding_txo,
11191119
last_local_balance_msat: _,
11201120
} => {
11211121
tracing::info!(
@@ -1127,6 +1127,10 @@ async fn handle_ldk_events(
11271127
reason
11281128
);
11291129

1130+
if channel_funding_txo.is_none() {
1131+
*unlocked_state.rgb_send_lock.lock().unwrap() = false;
1132+
}
1133+
11301134
unlocked_state.delete_channel_id(channel_id);
11311135
}
11321136
Event::DiscardFunding { channel_id, .. } => {

0 commit comments

Comments
 (0)