Skip to content

Commit 653c482

Browse files
committed
Drop return value from provide_latest_holder_commitment_tx
`provide_latest_holder_commitment_tx` is used to handle `ChannelMonitorUpdateStep::LatestHolderCommitmentTXInfo` updates and returns an `Err` if we've set `holder_tx_signed`. However, later in `ChannelMonitorImpl::update_monitor` (the only non-test place that `provide_latest_holder_commitment_tx` is called), we will fail the entire update if `holder_tx_signed` is (or a few other flags are) are set if the update contained a `LatestHolderCommitmentTXInfo` (or a few other update types). Thus, the check in `provide_latest_holder_commitment_tx` is entirely redundant and can be removed.
1 parent 7c56f21 commit 653c482

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,8 +1509,8 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
15091509
fn provide_latest_holder_commitment_tx(
15101510
&self, holder_commitment_tx: HolderCommitmentTransaction,
15111511
htlc_outputs: Vec<(HTLCOutputInCommitment, Option<Signature>, Option<HTLCSource>)>,
1512-
) -> Result<(), ()> {
1513-
self.inner.lock().unwrap().provide_latest_holder_commitment_tx(holder_commitment_tx, htlc_outputs, &Vec::new(), Vec::new()).map_err(|_| ())
1512+
) {
1513+
self.inner.lock().unwrap().provide_latest_holder_commitment_tx(holder_commitment_tx, htlc_outputs, &Vec::new(), Vec::new())
15141514
}
15151515

15161516
/// This is used to provide payment preimage(s) out-of-band during startup without updating the
@@ -2901,7 +2901,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
29012901
/// is important that any clones of this channel monitor (including remote clones) by kept
29022902
/// up-to-date as our holder commitment transaction is updated.
29032903
/// Panics if set_on_holder_tx_csv has never been called.
2904-
fn provide_latest_holder_commitment_tx(&mut self, holder_commitment_tx: HolderCommitmentTransaction, mut htlc_outputs: Vec<(HTLCOutputInCommitment, Option<Signature>, Option<HTLCSource>)>, claimed_htlcs: &[(SentHTLCId, PaymentPreimage)], nondust_htlc_sources: Vec<HTLCSource>) -> Result<(), &'static str> {
2904+
fn provide_latest_holder_commitment_tx(&mut self, holder_commitment_tx: HolderCommitmentTransaction, mut htlc_outputs: Vec<(HTLCOutputInCommitment, Option<Signature>, Option<HTLCSource>)>, claimed_htlcs: &[(SentHTLCId, PaymentPreimage)], nondust_htlc_sources: Vec<HTLCSource>) {
29052905
if htlc_outputs.iter().any(|(_, s, _)| s.is_some()) {
29062906
// If we have non-dust HTLCs in htlc_outputs, ensure they match the HTLCs in the
29072907
// `holder_commitment_tx`. In the future, we'll no longer provide the redundant data
@@ -2978,10 +2978,6 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
29782978
}
29792979
self.counterparty_fulfilled_htlcs.insert(*claimed_htlc_id, *claimed_preimage);
29802980
}
2981-
if self.holder_tx_signed {
2982-
return Err("Latest holder commitment signed has already been signed, update is rejected");
2983-
}
2984-
Ok(())
29852981
}
29862982

29872983
/// Provides a payment_hash->payment_preimage mapping. Will be automatically pruned when all
@@ -3202,11 +3198,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
32023198
ChannelMonitorUpdateStep::LatestHolderCommitmentTXInfo { commitment_tx, htlc_outputs, claimed_htlcs, nondust_htlc_sources } => {
32033199
log_trace!(logger, "Updating ChannelMonitor with latest holder commitment transaction info");
32043200
if self.lockdown_from_offchain { panic!(); }
3205-
if let Err(e) = self.provide_latest_holder_commitment_tx(commitment_tx.clone(), htlc_outputs.clone(), &claimed_htlcs, nondust_htlc_sources.clone()) {
3206-
log_error!(logger, "Providing latest holder commitment transaction failed/was refused:");
3207-
log_error!(logger, " {}", e);
3208-
ret = Err(());
3209-
}
3201+
self.provide_latest_holder_commitment_tx(commitment_tx.clone(), htlc_outputs.clone(), &claimed_htlcs, nondust_htlc_sources.clone());
32103202
}
32113203
ChannelMonitorUpdateStep::LatestCounterpartyCommitmentTXInfo { commitment_txid, htlc_outputs, commitment_number, their_per_commitment_point, .. } => {
32123204
log_trace!(logger, "Updating ChannelMonitor with latest counterparty commitment transaction info");
@@ -5386,7 +5378,7 @@ mod tests {
53865378
let dummy_commitment_tx = HolderCommitmentTransaction::dummy(&mut htlcs);
53875379

53885380
monitor.provide_latest_holder_commitment_tx(dummy_commitment_tx.clone(),
5389-
htlcs.into_iter().map(|(htlc, _)| (htlc, Some(dummy_sig), None)).collect()).unwrap();
5381+
htlcs.into_iter().map(|(htlc, _)| (htlc, Some(dummy_sig), None)).collect());
53905382
monitor.provide_latest_counterparty_commitment_tx(Txid::from_byte_array(Sha256::hash(b"1").to_byte_array()),
53915383
preimages_slice_to_htlc_outputs!(preimages[5..15]), 281474976710655, dummy_key, &logger);
53925384
monitor.provide_latest_counterparty_commitment_tx(Txid::from_byte_array(Sha256::hash(b"2").to_byte_array()),
@@ -5424,7 +5416,7 @@ mod tests {
54245416
let mut htlcs = preimages_slice_to_htlcs!(preimages[0..5]);
54255417
let dummy_commitment_tx = HolderCommitmentTransaction::dummy(&mut htlcs);
54265418
monitor.provide_latest_holder_commitment_tx(dummy_commitment_tx.clone(),
5427-
htlcs.into_iter().map(|(htlc, _)| (htlc, Some(dummy_sig), None)).collect()).unwrap();
5419+
htlcs.into_iter().map(|(htlc, _)| (htlc, Some(dummy_sig), None)).collect());
54285420
secret[0..32].clone_from_slice(&<Vec<u8>>::from_hex("2273e227a5b7449b6e70f1fb4652864038b1cbf9cd7c043a7d6456b7fc275ad8").unwrap());
54295421
monitor.provide_secret(281474976710653, secret.clone()).unwrap();
54305422
assert_eq!(monitor.inner.lock().unwrap().payment_preimages.len(), 12);
@@ -5435,7 +5427,7 @@ mod tests {
54355427
let mut htlcs = preimages_slice_to_htlcs!(preimages[0..3]);
54365428
let dummy_commitment_tx = HolderCommitmentTransaction::dummy(&mut htlcs);
54375429
monitor.provide_latest_holder_commitment_tx(dummy_commitment_tx,
5438-
htlcs.into_iter().map(|(htlc, _)| (htlc, Some(dummy_sig), None)).collect()).unwrap();
5430+
htlcs.into_iter().map(|(htlc, _)| (htlc, Some(dummy_sig), None)).collect());
54395431
secret[0..32].clone_from_slice(&<Vec<u8>>::from_hex("27cddaa5624534cb6cb9d7da077cf2b22ab21e9b506fd4998a51d54502e99116").unwrap());
54405432
monitor.provide_secret(281474976710652, secret.clone()).unwrap();
54415433
assert_eq!(monitor.inner.lock().unwrap().payment_preimages.len(), 5);

0 commit comments

Comments
 (0)