Skip to content

Commit 46f495b

Browse files
author
Antoine Riard
committed
Make acces and signature of local commitment transaction unique
Local commitment transaction broadcast can be triggered by a) a Channel force-close or b) reaching some block height implying a onchain HTLC-timeout. If one of this condition is fulfilled, commitment is signed and from then any state update would be rejected. ChannelMonitor init at Channel creation need to be refactored before to make get_fully_signed_local_tx infaillible to avoid choking in the test framework.
1 parent a0ac647 commit 46f495b

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

lightning/src/ln/onchaintx.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -537,18 +537,15 @@ impl<ChanSigner: ChannelKeys> OnchainTxHandler<ChanSigner> {
537537
return None;
538538
},
539539
&InputMaterial::Funding { ref channel_value } => {
540-
if let Some(ref mut local_commitment) = self.local_commitment {
541-
self.key_storage.sign_local_commitment(local_commitment, &self.funding_redeemscript, *channel_value, &self.secp_ctx);
542-
let signed_tx = local_commitment.with_valid_witness().clone();
543-
let mut amt_outputs = 0;
544-
for outp in signed_tx.output.iter() {
545-
amt_outputs += outp.value;
546-
}
547-
let feerate = (channel_value - amt_outputs) * 1000 / signed_tx.get_weight() as u64;
548-
// Timer set to $NEVER given we can't bump tx without anchor outputs
549-
log_trace!(self, "Going to broadcast Local Transaction {} claiming funding output {} from {}...", signed_tx.txid(), outp.vout, outp.txid);
550-
return Some((None, feerate, signed_tx));
540+
let signed_tx = self.get_fully_signed_local_tx(*channel_value).unwrap();
541+
let mut amt_outputs = 0;
542+
for outp in signed_tx.output.iter() {
543+
amt_outputs += outp.value;
551544
}
545+
let feerate = (channel_value - amt_outputs) * 1000 / signed_tx.get_weight() as u64;
546+
// Timer set to $NEVER given we can't bump tx without anchor outputs
547+
log_trace!(self, "Going to broadcast Local Transaction {} claiming funding output {} from {}...", signed_tx.txid(), outp.vout, outp.txid);
548+
return Some((None, feerate, signed_tx));
552549
}
553550
_ => unreachable!()
554551
}
@@ -796,6 +793,10 @@ impl<ChanSigner: ChannelKeys> OnchainTxHandler<ChanSigner> {
796793
Ok(())
797794
}
798795

796+
//TODO: getting lastest local transactions should be infaillible and result in us "force-closing the channel", but we may
797+
// have empty local commitment transaction if a ChannelMonitor is asked to force-close just after Channel::get_outbound_funding_created,
798+
// before providing a initial commitment transaction. For outbound channel, init ChannelMonitor at Channel::funding_signed, there is nothing
799+
// to monitor before.
799800
pub(super) fn get_fully_signed_local_tx(&mut self, channel_value_satoshis: u64) -> Option<Transaction> {
800801
if let Some(ref mut local_commitment) = self.local_commitment {
801802
self.key_storage.sign_local_commitment(local_commitment, &self.funding_redeemscript, channel_value_satoshis, &self.secp_ctx);

0 commit comments

Comments
 (0)