Skip to content

Commit 6803c47

Browse files
committed
Split up send_commitment into a const and non-const version
1 parent e6d8b9d commit 6803c47

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

src/ln/channel.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2506,8 +2506,6 @@ impl Channel {
25062506
}
25072507
/// Only fails in case of bad keys
25082508
fn send_commitment_no_status_check(&mut self) -> Result<(msgs::CommitmentSigned, ChannelMonitor), HandleError> {
2509-
let funding_script = self.get_funding_redeemscript();
2510-
25112509
// We can upgrade the status of some HTLCs that are waiting on a commitment, even if we
25122510
// fail to generate this, we still are at least at a position where upgrading their status
25132511
// is acceptable.
@@ -2522,6 +2520,22 @@ impl Channel {
25222520
}
25232521
}
25242522

2523+
match self.send_commitment_no_state_update() {
2524+
Ok((res, remote_commitment_tx)) => {
2525+
// Update state now that we've passed all the can-fail calls...
2526+
self.channel_monitor.provide_latest_remote_commitment_tx_info(&remote_commitment_tx.0, remote_commitment_tx.1, self.cur_remote_commitment_transaction_number);
2527+
self.channel_state |= ChannelState::AwaitingRemoteRevoke as u32;
2528+
Ok((res, self.channel_monitor.clone()))
2529+
},
2530+
Err(e) => Err(e),
2531+
}
2532+
}
2533+
2534+
/// Only fails in case of bad keys. Used for channel_reestablish commitment_signed generation
2535+
/// when we shouldn't change HTLC/channel state.
2536+
fn send_commitment_no_state_update(&self) -> Result<(msgs::CommitmentSigned, (Transaction, Vec<HTLCOutputInCommitment>)), HandleError> {
2537+
let funding_script = self.get_funding_redeemscript();
2538+
25252539
let remote_keys = self.build_remote_transaction_keys()?;
25262540
let remote_commitment_tx = self.build_commitment_transaction(self.cur_remote_commitment_transaction_number, &remote_keys, false, true);
25272541
let remote_commitment_txid = remote_commitment_tx.0.txid();
@@ -2538,15 +2552,11 @@ impl Channel {
25382552
htlc_sigs.push(self.secp_ctx.sign(&htlc_sighash, &our_htlc_key));
25392553
}
25402554

2541-
// Update state now that we've passed all the can-fail calls...
2542-
self.channel_monitor.provide_latest_remote_commitment_tx_info(&remote_commitment_tx.0, remote_commitment_tx.1, self.cur_remote_commitment_transaction_number);
2543-
self.channel_state |= ChannelState::AwaitingRemoteRevoke as u32;
2544-
25452555
Ok((msgs::CommitmentSigned {
25462556
channel_id: self.channel_id,
25472557
signature: our_sig,
25482558
htlc_signatures: htlc_sigs,
2549-
}, self.channel_monitor.clone()))
2559+
}, remote_commitment_tx))
25502560
}
25512561

25522562
/// Adds a pending outbound HTLC to this channel, and creates a signed commitment transaction

0 commit comments

Comments
 (0)