Skip to content

Commit 26643d8

Browse files
author
Antoine Riard
committed
Add local_commitment_tx at funding_created to claim sizeable push_msat
1 parent a819e17 commit 26643d8

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
@@ -1336,22 +1336,25 @@ impl Channel {
13361336
Ok(())
13371337
}
13381338

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

13421342
let local_keys = self.build_local_transaction_keys(self.cur_local_commitment_transaction_number)?;
1343-
let local_initial_commitment_tx = self.build_commitment_transaction(self.cur_local_commitment_transaction_number, &local_keys, true, false, self.feerate_per_kw).0;
1343+
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;
13441344
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();
13451345

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

1349+
// ...and we sign it, allowing us ot broadcast the tx if we wish
1350+
self.sign_commitment_transaction(&mut local_initial_commitment_tx, sig);
1351+
13491352
let remote_keys = self.build_remote_transaction_keys()?;
13501353
let remote_initial_commitment_tx = self.build_commitment_transaction(self.cur_remote_commitment_transaction_number, &remote_keys, false, false, self.feerate_per_kw).0;
13511354
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();
13521355

13531356
// We sign the "remote" commitment transaction, allowing them to broadcast the tx if they wish.
1354-
Ok((remote_initial_commitment_tx, self.secp_ctx.sign(&remote_sighash, &self.local_keys.funding_key)))
1357+
Ok((remote_initial_commitment_tx, local_initial_commitment_tx, self.secp_ctx.sign(&remote_sighash, &self.local_keys.funding_key), local_keys))
13551358
}
13561359

13571360
pub fn funding_created(&mut self, msg: &msgs::FundingCreated) -> Result<(msgs::FundingSigned, ChannelMonitor), HandleError> {
@@ -1374,7 +1377,7 @@ impl Channel {
13741377
let funding_txo_script = self.get_funding_redeemscript().to_v0_p2wsh();
13751378
self.channel_monitor.set_funding_info((funding_txo, funding_txo_script));
13761379

1377-
let (remote_initial_commitment_tx, our_signature) = match self.funding_created_signature(&msg.signature) {
1380+
let (remote_initial_commitment_tx, local_initial_commitment_tx, our_signature, local_keys) = match self.funding_created_signature(&msg.signature) {
13781381
Ok(res) => res,
13791382
Err(e) => {
13801383
self.channel_monitor.unset_funding_info();
@@ -1385,6 +1388,8 @@ impl Channel {
13851388
// Now that we're past error-generating stuff, update our local state:
13861389

13871390
self.channel_monitor.provide_latest_remote_commitment_tx_info(&remote_initial_commitment_tx, Vec::new(), self.cur_remote_commitment_transaction_number);
1391+
self.last_local_commitment_txn = vec![local_initial_commitment_tx.clone()];
1392+
self.channel_monitor.provide_latest_local_commitment_tx_info(local_initial_commitment_tx, local_keys, self.feerate_per_kw, Vec::new());
13881393
self.channel_state = ChannelState::FundingSent as u32;
13891394
self.channel_id = funding_txo.to_channel_id();
13901395
self.cur_remote_commitment_transaction_number -= 1;

0 commit comments

Comments
 (0)