Skip to content

Commit bed68ce

Browse files
committed
HolderCommitmentTransactionInfo
1 parent 431e7b5 commit bed68ce

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

lightning/src/ln/chan_utils.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,8 +554,25 @@ pub fn build_htlc_transaction(prev_hash: &Txid, feerate_per_kw: u32, contest_del
554554
}
555555
}
556556

557+
/// This class tracks the information needed to build a holder's commitment transaction and to actually
558+
/// build and sign. It is used for holder transactions that we sign only when needed.
559+
pub struct HolderCommitmentTransactionInfo {
560+
/// The non-party-specific transaction information
561+
pub info: CommitmentTransactionInfo,
562+
/// Our counterparty's signature for the transaction
563+
pub counterparty_sig: Signature,
564+
/// All HTLCs (including dust ones) with an optional counterparty signature
565+
pub htlcs_with_sig: Vec<(HTLCOutputInCommitment, Option<Signature>)>,
566+
}
567+
568+
impl HolderCommitmentTransactionInfo {
569+
pub(crate) fn to_holder_commitment_tx<T: secp256k1::Signing + secp256k1::Verification>(&self, holder_pubkeys: &ChannelPublicKeys, counterparty_pubkeys: &ChannelPublicKeys, funding_outpoint: &OutPoint, contest_delay: u16, is_outbound: bool, secp_ctx: &Secp256k1<T>) -> HolderCommitmentTransaction {
570+
self.info.to_holder_commitment_tx(self.counterparty_sig, self.htlcs_with_sig.clone(), holder_pubkeys, counterparty_pubkeys, funding_outpoint, contest_delay, is_outbound, secp_ctx)
571+
}
572+
}
573+
557574
#[derive(Clone)]
558-
/// We use this class to track the information needed to build a commitment transaction and to actually
575+
/// This class tracks the information needed to build a commitment transaction and to actually
559576
/// build and sign. It is used for holder transactions that we sign only when needed
560577
/// and for transactions we sign for the counterparty.
561578
///

lightning/src/ln/channel.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use ln::features::{ChannelFeatures, InitFeatures};
2626
use ln::msgs;
2727
use ln::msgs::{DecodeError, OptionalField, DataLossProtect};
2828
use ln::channelmanager::{PendingHTLCStatus, HTLCSource, HTLCFailReason, HTLCFailureMsg, PendingHTLCInfo, RAACommitmentOrder, PaymentPreimage, PaymentHash, BREAKDOWN_TIMEOUT, MAX_LOCAL_BREAKDOWN_TIMEOUT};
29-
use ln::chan_utils::{CounterpartyCommitmentSecrets, HolderCommitmentTransaction, TxCreationKeys, HTLCOutputInCommitment, HTLC_SUCCESS_TX_WEIGHT, HTLC_TIMEOUT_TX_WEIGHT, make_funding_redeemscript, ChannelPublicKeys, PreCalculatedTxCreationKeys, CommitmentTransactionInfo};
29+
use ln::chan_utils::{CounterpartyCommitmentSecrets, HolderCommitmentTransaction, TxCreationKeys, HTLCOutputInCommitment, HTLC_SUCCESS_TX_WEIGHT, HTLC_TIMEOUT_TX_WEIGHT, make_funding_redeemscript, ChannelPublicKeys, PreCalculatedTxCreationKeys, CommitmentTransactionInfo, HolderCommitmentTransactionInfo};
3030
use ln::chan_utils;
3131
use chain::chaininterface::{FeeEstimator,ConfirmationTarget};
3232
use chain::channelmonitor::{ChannelMonitor, ChannelMonitorUpdate, ChannelMonitorUpdateStep, HTLC_FAIL_BACK_BUFFER};
@@ -1509,15 +1509,19 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
15091509
}
15101510
};
15111511

1512+
let holder_info = HolderCommitmentTransactionInfo {
1513+
info: initial_commitment_info,
1514+
counterparty_sig: msg.signature,
1515+
htlcs_with_sig: Vec::new(),
1516+
};
1517+
15121518
// TODO some of the needed fields are already passed into ChannelMonitor, but some still need
15131519
// 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
1520+
let initial_commitment_tx = holder_info.to_holder_commitment_tx(
1521+
&self.holder_keys.pubkeys(), // self.holder_keys already provided
1522+
self.counterparty_pubkeys.as_ref().unwrap(), // partially provided
1523+
&self.funding_txo.unwrap().into_bitcoin_outpoint(), // self.funding_txo already provided
1524+
self.counterparty_selected_contest_delay, // already provided
15211525
self.is_outbound(), // provide
15221526
&self.secp_ctx, // not needed
15231527
);

0 commit comments

Comments
 (0)