]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Make acces and signature of local commitment transaction unique
authorAntoine Riard <ariard@student.42.fr>
Mon, 6 Apr 2020 22:32:57 +0000 (18:32 -0400)
committerAntoine Riard <ariard@student.42.fr>
Fri, 17 Apr 2020 21:50:26 +0000 (17:50 -0400)
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.

lightning/src/ln/onchaintx.rs

index b2115c0f8ac973c86d0827e0b3aaa0d8dd8291f9..2f08fe291d2e922682c41290f597ab30594c235f 100644 (file)
@@ -537,18 +537,15 @@ impl<ChanSigner: ChannelKeys> OnchainTxHandler<ChanSigner> {
                                                return None;
                                        },
                                        &InputMaterial::Funding { ref channel_value } => {
-                                               if let Some(ref mut local_commitment) = self.local_commitment {
-                                                       self.key_storage.sign_local_commitment(local_commitment, &self.funding_redeemscript, *channel_value, &self.secp_ctx);
-                                                       let signed_tx = local_commitment.with_valid_witness().clone();
-                                                       let mut amt_outputs = 0;
-                                                       for outp in signed_tx.output.iter() {
-                                                               amt_outputs += outp.value;
-                                                       }
-                                                       let feerate = (channel_value - amt_outputs) * 1000 / signed_tx.get_weight() as u64;
-                                                       // Timer set to $NEVER given we can't bump tx without anchor outputs
-                                                       log_trace!(self, "Going to broadcast Local Transaction {} claiming funding output {} from {}...", signed_tx.txid(), outp.vout, outp.txid);
-                                                       return Some((None, feerate, signed_tx));
+                                               let signed_tx = self.get_fully_signed_local_tx(*channel_value).unwrap();
+                                               let mut amt_outputs = 0;
+                                               for outp in signed_tx.output.iter() {
+                                                       amt_outputs += outp.value;
                                                }
+                                               let feerate = (channel_value - amt_outputs) * 1000 / signed_tx.get_weight() as u64;
+                                               // Timer set to $NEVER given we can't bump tx without anchor outputs
+                                               log_trace!(self, "Going to broadcast Local Transaction {} claiming funding output {} from {}...", signed_tx.txid(), outp.vout, outp.txid);
+                                               return Some((None, feerate, signed_tx));
                                        }
                                        _ => unreachable!()
                                }
@@ -793,6 +790,10 @@ impl<ChanSigner: ChannelKeys> OnchainTxHandler<ChanSigner> {
                Ok(())
        }
 
+       //TODO: getting lastest local transactions should be infaillible and result in us "force-closing the channel", but we may
+       // have empty local commitment transaction if a ChannelMonitor is asked to force-close just after Channel::get_outbound_funding_created,
+       // before providing a initial commitment transaction. For outbound channel, init ChannelMonitor at Channel::funding_signed, there is nothing
+       // to monitor before.
        pub(super) fn get_fully_signed_local_tx(&mut self, channel_value_satoshis: u64) -> Option<Transaction> {
                if let Some(ref mut local_commitment) = self.local_commitment {
                        self.key_storage.sign_local_commitment(local_commitment, &self.funding_redeemscript, channel_value_satoshis, &self.secp_ctx);