Skip to content

Commit 0a18bd3

Browse files
committed
more cleanup
1 parent 700b72b commit 0a18bd3

File tree

3 files changed

+56
-37
lines changed

3 files changed

+56
-37
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -502,9 +502,9 @@ pub(crate) enum ChannelMonitorUpdateStep {
502502
impl Writeable for ChannelMonitorUpdateStep {
503503
fn write<W: Writer>(&self, w: &mut W) -> Result<(), ::std::io::Error> {
504504
match self {
505-
&ChannelMonitorUpdateStep::LatestHolderCommitmentTXInfo { commitment_info: ref commitment_tx, ref htlc_outputs } => {
505+
&ChannelMonitorUpdateStep::LatestHolderCommitmentTXInfo { ref commitment_info, ref htlc_outputs } => {
506506
0u8.write(w)?;
507-
commitment_tx.write(w)?;
507+
commitment_info.write(w)?;
508508
(htlc_outputs.len() as u64).write(w)?;
509509
for &(ref output, ref signature, ref source) in htlc_outputs.iter() {
510510
output.write(w)?;
@@ -953,19 +953,26 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
953953

954954
let mut onchain_tx_handler = OnchainTxHandler::new(destination_script.clone(), keys.clone(), channel_static_info.clone());
955955

956-
let current_holder_commitment_number = initial_holder_commitment_info.info.commitment_number;
957956
let secp_ctx = Secp256k1::new();
958957

959958
let txid = initial_holder_commitment_info.txid(channel_static_info, &secp_ctx);
960-
let holder_commitment_tx = HolderSignedTx {
961-
txid,
962-
revocation_key: initial_holder_commitment_info.info.keys.revocation_key,
963-
a_htlc_key: initial_holder_commitment_info.info.keys.broadcaster_htlc_key,
964-
b_htlc_key: initial_holder_commitment_info.info.keys.countersignatory_htlc_key,
965-
delayed_payment_key: initial_holder_commitment_info.info.keys.broadcaster_delayed_payment_key,
966-
per_commitment_point: initial_holder_commitment_info.info.keys.per_commitment_point,
967-
feerate_per_kw: initial_holder_commitment_info.info.feerate_per_kw,
968-
htlc_outputs: Vec::new(), // There are never any HTLCs in the initial commitment transactions
959+
960+
// block for Rust 1.34 compat
961+
let (holder_commitment_tx, current_holder_commitment_number) = {
962+
let info = &initial_holder_commitment_info.info;
963+
let tx_keys = &info.keys;
964+
let current_holder_commitment_number = info.commitment_number;
965+
let holder_commitment_tx = HolderSignedTx {
966+
txid,
967+
revocation_key: tx_keys.revocation_key,
968+
a_htlc_key: tx_keys.broadcaster_htlc_key,
969+
b_htlc_key: tx_keys.countersignatory_htlc_key,
970+
delayed_payment_key: tx_keys.broadcaster_delayed_payment_key,
971+
per_commitment_point: tx_keys.per_commitment_point,
972+
feerate_per_kw: info.feerate_per_kw,
973+
htlc_outputs: Vec::new(), // There are never any HTLCs in the initial commitment transactions
974+
};
975+
(holder_commitment_tx, current_holder_commitment_number)
969976
};
970977
onchain_tx_handler.provide_latest_holder_tx(initial_holder_commitment_info);
971978

@@ -1017,7 +1024,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
10171024
holder_tx_signed: false,
10181025

10191026
last_block_hash: Default::default(),
1020-
secp_ctx: secp_ctx,
1027+
secp_ctx,
10211028
}
10221029
}
10231030

@@ -1127,17 +1134,23 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
11271134
/// Panics if set_on_holder_tx_csv has never been called.
11281135
fn provide_latest_holder_commitment_tx_info(&mut self, commitment_info: HolderCommitmentTransactionInfo, htlc_outputs: Vec<(HTLCOutputInCommitment, Option<Signature>, Option<HTLCSource>)>) -> Result<(), MonitorUpdateError> {
11291136
let txid = commitment_info.txid(&self.onchain_tx_handler.channel_static_info, &self.secp_ctx);
1130-
let mut new_holder_commitment_tx = HolderSignedTx {
1131-
txid,
1132-
revocation_key: commitment_info.info.keys.revocation_key,
1133-
a_htlc_key: commitment_info.info.keys.broadcaster_htlc_key,
1134-
b_htlc_key: commitment_info.info.keys.countersignatory_htlc_key,
1135-
delayed_payment_key: commitment_info.info.keys.broadcaster_delayed_payment_key,
1136-
per_commitment_point: commitment_info.info.keys.per_commitment_point,
1137-
feerate_per_kw: commitment_info.info.feerate_per_kw,
1138-
htlc_outputs,
1137+
1138+
// block for Rust 1.34 compat
1139+
let mut new_holder_commitment_tx = {
1140+
let info = &commitment_info.info;
1141+
let tx_keys = &info.keys;
1142+
self.current_holder_commitment_number = info.commitment_number;
1143+
HolderSignedTx {
1144+
txid,
1145+
revocation_key: tx_keys.revocation_key,
1146+
a_htlc_key: tx_keys.broadcaster_htlc_key,
1147+
b_htlc_key: tx_keys.countersignatory_htlc_key,
1148+
delayed_payment_key: tx_keys.broadcaster_delayed_payment_key,
1149+
per_commitment_point: tx_keys.per_commitment_point,
1150+
feerate_per_kw: info.feerate_per_kw,
1151+
htlc_outputs,
1152+
}
11391153
};
1140-
self.current_holder_commitment_number = commitment_info.info.commitment_number;
11411154
self.onchain_tx_handler.provide_latest_holder_tx(commitment_info);
11421155
mem::swap(&mut new_holder_commitment_tx, &mut self.current_holder_commitment_tx);
11431156
self.prev_holder_signed_commitment_tx = Some(new_holder_commitment_tx);
@@ -1176,9 +1189,9 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
11761189
}
11771190
for update in updates.updates.drain(..) {
11781191
match update {
1179-
ChannelMonitorUpdateStep::LatestHolderCommitmentTXInfo { commitment_info: commitment_tx, htlc_outputs } => {
1192+
ChannelMonitorUpdateStep::LatestHolderCommitmentTXInfo { commitment_info, htlc_outputs } => {
11801193
if self.lockdown_from_offchain { panic!(); }
1181-
self.provide_latest_holder_commitment_tx_info(commitment_tx, htlc_outputs)?
1194+
self.provide_latest_holder_commitment_tx_info(commitment_info, htlc_outputs)?
11821195
},
11831196
ChannelMonitorUpdateStep::LatestCounterpartyCommitmentTXInfo { unsigned_commitment_tx, htlc_outputs, commitment_number, their_revocation_point } =>
11841197
self.provide_latest_counterparty_commitment_tx_info(&unsigned_commitment_tx, htlc_outputs, commitment_number, their_revocation_point, logger),

lightning/src/ln/chan_utils.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -604,16 +604,18 @@ impl ChannelStaticInfo {
604604
}
605605
}
606606

607-
/// This class tracks the information needed to build a holder's commitment transaction and to actually
608-
/// build and sign. It is used for holder transactions that we sign only when needed.
607+
/// This class tracks the information needed to build a holder's commitment transaction.
608+
/// It is used for holder transactions that we sign only when needed.
609+
///
610+
/// TODO(devrandom): take over signing functionality from HolderCommitmentTransaction
609611
#[derive(Clone)]
610612
pub struct HolderCommitmentTransactionInfo {
611613
/// The non-party-specific transaction information
612614
pub info: CommitmentTransactionInfo,
613615
/// Our counterparty's signature for the transaction
614616
pub counterparty_sig: Signature,
615617
/// All non-dust counterparty HTLC signatures, in the order they appear in the transaction
616-
pub htlc_sigs: Vec<Signature>,
618+
pub counterparty_htlc_sigs: Vec<Signature>,
617619
}
618620

619621
impl PartialEq for HolderCommitmentTransactionInfo {
@@ -624,7 +626,7 @@ impl PartialEq for HolderCommitmentTransactionInfo {
624626
}
625627

626628
impl_writeable!(HolderCommitmentTransactionInfo, 0, {
627-
info, counterparty_sig, htlc_sigs
629+
info, counterparty_sig, counterparty_htlc_sigs
628630
});
629631

630632
impl HolderCommitmentTransactionInfo {
@@ -649,7 +651,7 @@ impl HolderCommitmentTransactionInfo {
649651
}
650652
},
651653
counterparty_sig: dummy_sig,
652-
htlc_sigs: Vec::new()
654+
counterparty_htlc_sigs: Vec::new()
653655
}
654656
}
655657
pub(crate) fn txid<T: secp256k1::Signing + secp256k1::Verification>(&self, channel_static_info: &ChannelStaticInfo, secp_ctx: &Secp256k1<T>) -> Txid {
@@ -659,7 +661,7 @@ impl HolderCommitmentTransactionInfo {
659661

660662
impl HolderCommitmentTransactionInfo {
661663
pub(crate) fn to_holder_commitment_tx<T: secp256k1::Signing + secp256k1::Verification>(&self, channel_static_info: &ChannelStaticInfo, secp_ctx: &Secp256k1<T>) -> HolderCommitmentTransaction {
662-
let opt_sigs: Vec<Option<Signature>> = self.htlc_sigs.iter().map(|s| Some(s.clone())).collect();
664+
let opt_sigs: Vec<Option<Signature>> = self.counterparty_htlc_sigs.iter().map(|s| Some(s.clone())).collect();
663665
let mut htlcs = self.info.htlcs.clone();
664666
let htlcs_with_sig = htlcs.drain(..).zip(opt_sigs).collect();
665667
self.info.to_holder_commitment_tx(self.counterparty_sig, htlcs_with_sig, channel_static_info, secp_ctx)
@@ -683,7 +685,9 @@ pub struct CommitmentTransactionInfo {
683685
pub to_countersignatory_value_sat: u64,
684686
/// The feerate paid per 1000-weight-unit in this commitment transaction.
685687
pub feerate_per_kw: u32,
686-
/// The HTLCs which were included in this commitment transaction in output order.
688+
/// The non-dust HTLCs (direction, amt, height expiration, hash, transaction output index)
689+
/// which were included in this commitment transaction in output order.
690+
/// The transaction index is always populated.
687691
pub htlcs: Vec<HTLCOutputInCommitment>,
688692
// A cache of pubkeys required to construct the transaction
689693
pub(crate) keys: TxCreationKeys,
@@ -728,7 +732,9 @@ impl_writeable!(CommitmentTransactionInfo, 0, {
728732
impl CommitmentTransactionInfo {
729733
/// Construct an object of the class while assigning transaction output indices to HTLCs.
730734
///
731-
/// Also keeps track of associated HTLC data and returns it along with the mutated HTLCs.
735+
/// Also keeps track of auxiliary HTLC data and returns it along with the mutated and sorted HTLCs.
736+
/// This allows the caller to match the HTLC output index with the auxiliary data.
737+
/// This auxiliary data is not stored in this object.
732738
pub fn new_with_auxiliary_htlc_data<T: Copy>(
733739
commitment_number: u64,
734740
to_broadcaster_value_sat: u64,
@@ -741,7 +747,7 @@ impl CommitmentTransactionInfo {
741747
contest_delay: u16,
742748
secp_ctx: &Secp256k1<secp256k1::All>
743749
) -> (CommitmentTransactionInfo, Vec<(HTLCOutputInCommitment, T)>) {
744-
// Populate output indices while keeping track of the auxiliary data
750+
// Sort outputs and populate output indices while keeping track of the auxiliary data
745751
let mut txouts = Self::do_build_outputs(&keys, to_broadcaster_value_sat, to_countersignatory_value_sat, &htlcs_with_aux, broadcaster_pubkeys, countersignatory_pubkeys, contest_delay, &secp_ctx).unwrap();
746752
let mut result_htlcs_with_aux = Vec::new();
747753
let mut htlcs = Vec::new();

lightning/src/ln/channel.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,7 +1525,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
15251525
let holder_info = HolderCommitmentTransactionInfo {
15261526
info: initial_commitment_info,
15271527
counterparty_sig: msg.signature,
1528-
htlc_sigs: Vec::new(),
1528+
counterparty_htlc_sigs: Vec::new(),
15291529
};
15301530

15311531
let channel_static_info = self.get_channel_static_info();
@@ -1584,7 +1584,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
15841584
let holder_info = HolderCommitmentTransactionInfo {
15851585
info: initial_commitment_info,
15861586
counterparty_sig: msg.signature,
1587-
htlc_sigs: Vec::new()
1587+
counterparty_htlc_sigs: Vec::new()
15881588
};
15891589

15901590
let counterparty_funding_pubkey = &self.counterparty_pubkeys.as_ref().unwrap().funding_pubkey;
@@ -2024,7 +2024,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
20242024
let holder_info = HolderCommitmentTransactionInfo {
20252025
info: commitment_tx.3,
20262026
counterparty_sig: msg.signature,
2027-
htlc_sigs: msg.htlc_signatures.clone()
2027+
counterparty_htlc_sigs: msg.htlc_signatures.clone()
20282028
};
20292029

20302030
let next_per_commitment_point = self.holder_keys.get_per_commitment_point(self.cur_holder_commitment_transaction_number - 1, &self.secp_ctx);

0 commit comments

Comments
 (0)