Skip to content

Commit 2def89c

Browse files
author
Antoine Riard
committed
Add local_commitment_tx at funding_created to claim sizeable push_msat
1 parent 2a5460e commit 2def89c

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/ln/channel.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,22 +1373,25 @@ impl Channel {
13731373
Ok(())
13741374
}
13751375

1376-
fn funding_created_signature(&mut self, sig: &Signature) -> Result<(Transaction, Signature), HandleError> {
1376+
fn funding_created_signature(&mut self, sig: &Signature) -> Result<(Transaction, Transaction, Signature, TxCreationKeys), HandleError> {
13771377
let funding_script = self.get_funding_redeemscript();
13781378

13791379
let local_keys = self.build_local_transaction_keys(self.cur_local_commitment_transaction_number)?;
1380-
let local_initial_commitment_tx = self.build_commitment_transaction(self.cur_local_commitment_transaction_number, &local_keys, true, false, self.feerate_per_kw).0;
1380+
let mut local_initial_commitment_tx = self.build_commitment_transaction(self.cur_local_commitment_transaction_number, &local_keys, true, false, self.feerate_per_kw).0;
13811381
let local_sighash = Message::from_slice(&bip143::SighashComponents::new(&local_initial_commitment_tx).sighash_all(&local_initial_commitment_tx.input[0], &funding_script, self.channel_value_satoshis)[..]).unwrap();
13821382

1383-
// They sign the "local" commitment transaction, allowing us to broadcast the tx if we wish.
1383+
// They sign the "local" commitment transaction...
13841384
secp_call!(self.secp_ctx.verify(&local_sighash, &sig, &self.their_funding_pubkey.unwrap()), "Invalid funding_created signature from peer", self.channel_id());
13851385

1386+
// ...and we sign it, allowing us ot broadcast the tx if we wish
1387+
self.sign_commitment_transaction(&mut local_initial_commitment_tx, sig);
1388+
13861389
let remote_keys = self.build_remote_transaction_keys()?;
13871390
let remote_initial_commitment_tx = self.build_commitment_transaction(self.cur_remote_commitment_transaction_number, &remote_keys, false, false, self.feerate_per_kw).0;
13881391
let remote_sighash = Message::from_slice(&bip143::SighashComponents::new(&remote_initial_commitment_tx).sighash_all(&remote_initial_commitment_tx.input[0], &funding_script, self.channel_value_satoshis)[..]).unwrap();
13891392

13901393
// We sign the "remote" commitment transaction, allowing them to broadcast the tx if they wish.
1391-
Ok((remote_initial_commitment_tx, self.secp_ctx.sign(&remote_sighash, &self.local_keys.funding_key)))
1394+
Ok((remote_initial_commitment_tx, local_initial_commitment_tx, self.secp_ctx.sign(&remote_sighash, &self.local_keys.funding_key), local_keys))
13921395
}
13931396

13941397
pub fn funding_created(&mut self, msg: &msgs::FundingCreated) -> Result<(msgs::FundingSigned, ChannelMonitor), HandleError> {
@@ -1411,7 +1414,7 @@ impl Channel {
14111414
let funding_txo_script = self.get_funding_redeemscript().to_v0_p2wsh();
14121415
self.channel_monitor.set_funding_info((funding_txo, funding_txo_script));
14131416

1414-
let (remote_initial_commitment_tx, our_signature) = match self.funding_created_signature(&msg.signature) {
1417+
let (remote_initial_commitment_tx, local_initial_commitment_tx, our_signature, local_keys) = match self.funding_created_signature(&msg.signature) {
14151418
Ok(res) => res,
14161419
Err(e) => {
14171420
self.channel_monitor.unset_funding_info();
@@ -1422,6 +1425,8 @@ impl Channel {
14221425
// Now that we're past error-generating stuff, update our local state:
14231426

14241427
self.channel_monitor.provide_latest_remote_commitment_tx_info(&remote_initial_commitment_tx, Vec::new(), self.cur_remote_commitment_transaction_number);
1428+
self.last_local_commitment_txn = vec![local_initial_commitment_tx.clone()];
1429+
self.channel_monitor.provide_latest_local_commitment_tx_info(local_initial_commitment_tx, local_keys, self.feerate_per_kw, Vec::new());
14251430
self.channel_state = ChannelState::FundingSent as u32;
14261431
self.channel_id = funding_txo.to_channel_id();
14271432
self.cur_remote_commitment_transaction_number -= 1;

0 commit comments

Comments
 (0)