Skip to content

Commit 890633d

Browse files
committed
f use bool for monitor_pending_tx_signatures
1 parent 8ca6d79 commit 890633d

File tree

2 files changed

+21
-23
lines changed

2 files changed

+21
-23
lines changed

lightning/src/ln/channel.rs

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2314,7 +2314,7 @@ where
23142314
monitor_pending_failures: Vec<(HTLCSource, PaymentHash, HTLCFailReason)>,
23152315
monitor_pending_finalized_fulfills: Vec<HTLCSource>,
23162316
monitor_pending_update_adds: Vec<msgs::UpdateAddHTLC>,
2317-
monitor_pending_tx_signatures: Option<msgs::TxSignatures>,
2317+
monitor_pending_tx_signatures: bool,
23182318

23192319
/// If we went to send a revoke_and_ack but our signer was unable to give us a signature,
23202320
/// we should retry at some point in the future when the signer indicates it may have a
@@ -3280,7 +3280,7 @@ where
32803280
monitor_pending_failures: Vec::new(),
32813281
monitor_pending_finalized_fulfills: Vec::new(),
32823282
monitor_pending_update_adds: Vec::new(),
3283-
monitor_pending_tx_signatures: None,
3283+
monitor_pending_tx_signatures: false,
32843284

32853285
signer_pending_revoke_and_ack: false,
32863286
signer_pending_commitment_update: false,
@@ -3521,7 +3521,7 @@ where
35213521
monitor_pending_failures: Vec::new(),
35223522
monitor_pending_finalized_fulfills: Vec::new(),
35233523
monitor_pending_update_adds: Vec::new(),
3524-
monitor_pending_tx_signatures: None,
3524+
monitor_pending_tx_signatures: false,
35253525

35263526
signer_pending_revoke_and_ack: false,
35273527
signer_pending_commitment_update: false,
@@ -6715,12 +6715,12 @@ where
67156715

67166716
self.monitor_updating_paused(false, false, false, Vec::new(), Vec::new(), Vec::new());
67176717

6718-
if let Some(tx_signatures) = self.interactive_tx_signing_session.as_mut().and_then(
6718+
if self.interactive_tx_signing_session.as_mut().map(
67196719
|session| session.received_commitment_signed()
6720-
) {
6720+
).unwrap_or(false) {
67216721
// We're up first for submitting our tx_signatures, but our monitor has not persisted yet
67226722
// so they'll be sent as soon as that's done.
6723-
self.context.monitor_pending_tx_signatures = Some(tx_signatures);
6723+
self.context.monitor_pending_tx_signatures = true;
67246724
}
67256725

67266726
Ok(channel_monitor)
@@ -6804,13 +6804,13 @@ where
68046804
channel_id: Some(self.context.channel_id()),
68056805
};
68066806

6807-
let tx_signatures = self
6807+
let tx_signatures_available = self
68086808
.interactive_tx_signing_session
68096809
.as_mut()
68106810
.expect("Signing session must exist for negotiated pending splice")
68116811
.received_commitment_signed();
68126812
self.monitor_updating_paused(false, false, false, Vec::new(), Vec::new(), Vec::new());
6813-
self.context.monitor_pending_tx_signatures = tx_signatures;
6813+
self.context.monitor_pending_tx_signatures = tx_signatures_available;
68146814

68156815
Ok(self.push_ret_blockable_mon_update(monitor_update))
68166816
}
@@ -7646,7 +7646,7 @@ where
76467646
{
76477647
if self.is_awaiting_initial_mon_persist() {
76487648
log_debug!(logger, "Not sending tx_signatures: a monitor update is in progress. Setting monitor_pending_tx_signatures.");
7649-
self.context.monitor_pending_tx_signatures = Some(holder_tx_signatures);
7649+
self.context.monitor_pending_tx_signatures = true;
76507650
return Ok(None);
76517651
}
76527652
return Ok(Some(holder_tx_signatures));
@@ -7730,7 +7730,7 @@ where
77307730
// and sets it as pending.
77317731
if holder_tx_signatures_opt.is_some() && self.is_awaiting_initial_mon_persist() {
77327732
log_debug!(logger, "Not sending tx_signatures: a monitor update is in progress. Setting monitor_pending_tx_signatures.");
7733-
self.context.monitor_pending_tx_signatures = holder_tx_signatures_opt;
7733+
self.context.monitor_pending_tx_signatures = true;
77347734
return Ok((None, None));
77357735
}
77367736

@@ -7989,14 +7989,16 @@ where
79897989
// For channels established with V2 establishment we won't send a `tx_signatures` when we're in
79907990
// MonitorUpdateInProgress (and we assume the user will never directly broadcast the funding
79917991
// transaction and waits for us to do it).
7992-
let tx_signatures = self.context.monitor_pending_tx_signatures.take();
7993-
if tx_signatures.is_some() {
7992+
let tx_signatures_ready = self.context.monitor_pending_tx_signatures;
7993+
self.context.monitor_pending_tx_signatures = false;
7994+
let tx_signatures = if tx_signatures_ready {
79947995
if self.context.channel_state.is_their_tx_signatures_sent() {
79957996
self.context.channel_state = ChannelState::AwaitingChannelReady(AwaitingChannelReadyFlags::new());
79967997
} else {
79977998
self.context.channel_state.set_our_tx_signatures_ready();
79987999
}
7999-
}
8000+
self.interactive_tx_signing_session.as_ref().and_then(|session| session.holder_tx_signatures().clone())
8001+
} else { None };
80008002

80018003
if self.context.channel_state.is_peer_disconnected() {
80028004
self.context.monitor_pending_revoke_and_ack = false;
@@ -8498,10 +8500,10 @@ where
84988500
if self.context.channel_state.is_monitor_update_in_progress() {
84998501
// The `monitor_pending_tx_signatures` field should have already been set in `commitment_signed_initial_v2`
85008502
// if we were up first for signing and had a monitor update in progress, but check again just in case.
8501-
debug_assert!(self.context.monitor_pending_tx_signatures.is_some(), "monitor_pending_tx_signatures should already be set");
8503+
debug_assert!(self.context.monitor_pending_tx_signatures, "monitor_pending_tx_signatures should already be set");
85028504
log_debug!(logger, "Not sending tx_signatures: a monitor update is in progress. Setting monitor_pending_tx_signatures.");
8503-
if self.context.monitor_pending_tx_signatures.is_none() {
8504-
self.context.monitor_pending_tx_signatures = session.holder_tx_signatures().clone();
8505+
if !self.context.monitor_pending_tx_signatures {
8506+
self.context.monitor_pending_tx_signatures = session.holder_tx_signatures().is_some();
85058507
}
85068508
None
85078509
} else {
@@ -13226,7 +13228,7 @@ where
1322613228
monitor_pending_failures,
1322713229
monitor_pending_finalized_fulfills: monitor_pending_finalized_fulfills.unwrap(),
1322813230
monitor_pending_update_adds: monitor_pending_update_adds.unwrap_or_default(),
13229-
monitor_pending_tx_signatures: None,
13231+
monitor_pending_tx_signatures: false,
1323013232

1323113233
signer_pending_revoke_and_ack: false,
1323213234
signer_pending_commitment_update: false,

lightning/src/ln/interactivetxs.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -344,13 +344,9 @@ impl InteractiveTxSigningSession {
344344
&self.holder_tx_signatures
345345
}
346346

347-
pub fn received_commitment_signed(&mut self) -> Option<TxSignatures> {
347+
pub fn received_commitment_signed(&mut self) -> bool {
348348
self.has_received_commitment_signed = true;
349-
if self.holder_sends_tx_signatures_first {
350-
self.holder_tx_signatures.clone()
351-
} else {
352-
None
353-
}
349+
self.holder_sends_tx_signatures_first && self.holder_tx_signatures.is_some()
354350
}
355351

356352
/// Handles a `tx_signatures` message received from the counterparty.

0 commit comments

Comments
 (0)