Skip to content

Commit 431e7b5

Browse files
committed
info out of funding_created_signature
1 parent a2fe96d commit 431e7b5

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

lightning/src/ln/chan_utils.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,11 @@ impl CommitmentTransactionInfo {
775775
.signature_hash(0, funding_redeemscript, channel_value_satoshis, SigHashType::All)[..]);
776776
(sighash, unsigned_tx)
777777
}
778+
779+
pub(crate) fn to_holder_commitment_tx<T: secp256k1::Signing + secp256k1::Verification>(&self, counterparty_sig: Signature, htlcs_with_sig: Vec<(HTLCOutputInCommitment, Option<Signature>)>, holder_pubkeys: &ChannelPublicKeys, counterparty_pubkeys: &ChannelPublicKeys, funding_outpoint: &OutPoint, contest_delay: u16, is_outbound: bool, secp_ctx: &Secp256k1<T>) -> HolderCommitmentTransaction {
780+
let (tx, _, _) = self.build(holder_pubkeys, counterparty_pubkeys, funding_outpoint, contest_delay, is_outbound, secp_ctx).unwrap();
781+
HolderCommitmentTransaction::new_missing_holder_sig(tx, counterparty_sig, &holder_pubkeys.funding_pubkey, &counterparty_pubkeys.funding_pubkey, self.keys.clone(), self.feerate_per_kw, htlcs_with_sig)
782+
}
778783
}
779784

780785
/// Get the transaction number obscure factor

lightning/src/ln/channel.rs

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1456,7 +1456,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
14561456
Ok(())
14571457
}
14581458

1459-
fn funding_created_signature<L: Deref>(&mut self, sig: &Signature, logger: &L) -> Result<(Transaction, HolderCommitmentTransaction, Signature), ChannelError> where L::Target: Logger {
1459+
fn funding_created_signature<L: Deref>(&mut self, sig: &Signature, logger: &L) -> Result<(Transaction, CommitmentTransactionInfo, Signature), ChannelError> where L::Target: Logger {
14601460
let funding_script = self.get_funding_redeemscript();
14611461

14621462
let keys = self.build_holder_transaction_keys(self.cur_holder_commitment_transaction_number)?;
@@ -1467,8 +1467,6 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
14671467
log_trace!(logger, "Checking funding_created tx signature {} by key {} against tx {} (sighash {}) with redeemscript {}", log_bytes!(sig.serialize_compact()[..]), log_bytes!(self.counterparty_funding_pubkey().serialize()), encode::serialize_hex(&initial_commitment_tx), log_bytes!(sighash[..]), encode::serialize_hex(&funding_script));
14681468
secp_check!(self.secp_ctx.verify(&sighash, &sig, self.counterparty_funding_pubkey()), "Invalid funding_created signature from peer".to_owned());
14691469

1470-
let tx = HolderCommitmentTransaction::new_missing_holder_sig(initial_commitment_tx, sig.clone(), &self.holder_keys.pubkeys().funding_pubkey, self.counterparty_funding_pubkey(), keys, self.feerate_per_kw, Vec::new());
1471-
14721470
let counterparty_keys = self.build_remote_transaction_keys()?;
14731471
let counterparty_initial_commitment_info = self.build_commitment_transaction(self.cur_counterparty_commitment_transaction_number, &counterparty_keys, false, false, self.feerate_per_kw, logger);
14741472
let counterparty_initial_commitment_tx = counterparty_initial_commitment_info.0.build(self.counterparty_pubkeys.as_ref().unwrap(), self.holder_keys.pubkeys(), &self.funding_txo.unwrap().into_bitcoin_outpoint(), self.holder_selected_contest_delay,!self.is_outbound(), &self.secp_ctx).unwrap().0;
@@ -1477,7 +1475,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
14771475
.map_err(|_| ChannelError::Close("Failed to get signatures for new commitment_signed".to_owned()))?.0;
14781476

14791477
// We sign "counterparty" commitment transaction, allowing them to broadcast the tx if they wish.
1480-
Ok((counterparty_initial_commitment_tx, tx, counterparty_signature))
1478+
Ok((counterparty_initial_commitment_tx, initial_commitment_info.0, counterparty_signature))
14811479
}
14821480

14831481
fn counterparty_funding_pubkey(&self) -> &PublicKey {
@@ -1503,14 +1501,27 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
15031501
let funding_txo = OutPoint{ txid: msg.funding_txid, index: msg.funding_output_index };
15041502
self.funding_txo = Some(funding_txo.clone());
15051503

1506-
let (counterparty_initial_commitment_tx, initial_commitment_tx, signature) = match self.funding_created_signature(&msg.signature, logger) {
1504+
let (counterparty_initial_commitment_tx, initial_commitment_info, signature) = match self.funding_created_signature(&msg.signature, logger) {
15071505
Ok(res) => res,
15081506
Err(e) => {
15091507
self.funding_txo = None;
15101508
return Err(e);
15111509
}
15121510
};
15131511

1512+
// TODO some of the needed fields are already passed into ChannelMonitor, but some still need
1513+
// to be passed in if we are to replace HolderCommitmentTransaction with CommitmentTransactionInfo
1514+
let initial_commitment_tx = initial_commitment_info.to_holder_commitment_tx(
1515+
msg.signature, // provide in a wrapper named HolderCommitmentTransactionInfo?
1516+
Vec::new(), // provide in a wrapper named HolderCommitmentTransactionInfo?
1517+
&self.holder_keys.pubkeys(), // DONE
1518+
self.counterparty_pubkeys.as_ref().unwrap(), // partially
1519+
&self.funding_txo.unwrap().into_bitcoin_outpoint(), // DONE
1520+
self.counterparty_selected_contest_delay, // DONE
1521+
self.is_outbound(), // provide
1522+
&self.secp_ctx, // not needed
1523+
);
1524+
15141525
// Now that we're past error-generating stuff, update our local state:
15151526

15161527
let counterparty_pubkeys = self.counterparty_pubkeys.as_ref().unwrap();
@@ -1524,7 +1535,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
15241535
&counterparty_pubkeys.htlc_basepoint, &counterparty_pubkeys.delayed_payment_basepoint,
15251536
self.counterparty_selected_contest_delay, funding_redeemscript.clone(), self.channel_value_satoshis,
15261537
self.get_commitment_transaction_number_obscure_factor(),
1527-
initial_commitment_tx.clone());
1538+
initial_commitment_tx);
15281539

15291540
channel_monitor.provide_latest_counterparty_commitment_tx_info(&counterparty_initial_commitment_tx, Vec::new(), self.cur_counterparty_commitment_transaction_number, self.counterparty_cur_commitment_point.unwrap(), logger);
15301541
channel_monitor

0 commit comments

Comments
 (0)