Skip to content

Commit adee671

Browse files
committed
Split up send_commitment into a const and non-const version
1 parent 9252ddb commit adee671

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
@@ -2431,8 +2431,6 @@ impl Channel {
24312431
}
24322432
/// Only fails in case of bad keys
24332433
fn send_commitment_no_status_check(&mut self) -> Result<(msgs::CommitmentSigned, ChannelMonitor), HandleError> {
2434-
let funding_script = self.get_funding_redeemscript();
2435-
24362434
// We can upgrade the status of some HTLCs that are waiting on a commitment, even if we
24372435
// fail to generate this, we still are at least at a position where upgrading their status
24382436
// is acceptable.
@@ -2447,6 +2445,22 @@ impl Channel {
24472445
}
24482446
}
24492447

2448+
match self.send_commitment_no_state_update() {
2449+
Ok((res, remote_commitment_tx)) => {
2450+
// Update state now that we've passed all the can-fail calls...
2451+
self.channel_monitor.provide_latest_remote_commitment_tx_info(&remote_commitment_tx.0, remote_commitment_tx.1, self.cur_remote_commitment_transaction_number);
2452+
self.channel_state |= ChannelState::AwaitingRemoteRevoke as u32;
2453+
Ok((res, self.channel_monitor.clone()))
2454+
},
2455+
Err(e) => Err(e),
2456+
}
2457+
}
2458+
2459+
/// Only fails in case of bad keys. Used for channel_reestablish commitment_signed generation
2460+
/// when we shouldn't change HTLC/channel state.
2461+
fn send_commitment_no_state_update(&self) -> Result<(msgs::CommitmentSigned, (Transaction, Vec<HTLCOutputInCommitment>)), HandleError> {
2462+
let funding_script = self.get_funding_redeemscript();
2463+
24502464
let remote_keys = self.build_remote_transaction_keys()?;
24512465
let remote_commitment_tx = self.build_commitment_transaction(self.cur_remote_commitment_transaction_number, &remote_keys, false, true);
24522466
let remote_commitment_txid = remote_commitment_tx.0.txid();
@@ -2463,15 +2477,11 @@ impl Channel {
24632477
htlc_sigs.push(self.secp_ctx.sign(&htlc_sighash, &our_htlc_key));
24642478
}
24652479

2466-
// Update state now that we've passed all the can-fail calls...
2467-
self.channel_monitor.provide_latest_remote_commitment_tx_info(&remote_commitment_tx.0, remote_commitment_tx.1, self.cur_remote_commitment_transaction_number);
2468-
self.channel_state |= ChannelState::AwaitingRemoteRevoke as u32;
2469-
24702480
Ok((msgs::CommitmentSigned {
24712481
channel_id: self.channel_id,
24722482
signature: our_sig,
24732483
htlc_signatures: htlc_sigs,
2474-
}, self.channel_monitor.clone()))
2484+
}, remote_commitment_tx))
24752485
}
24762486

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

0 commit comments

Comments
 (0)