Skip to content

Commit d356b97

Browse files
committed
Rename CounterpartyCommitmentTransaction to Params as it is static
1 parent 02e73b8 commit d356b97

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -290,16 +290,16 @@ impl_writeable_tlv_based!(HolderSignedTx, {
290290
(14, htlc_outputs, vec_type)
291291
});
292292

293-
/// We use this to track counterparty commitment transactions and htlcs outputs and
294-
/// use it to generate any justice or 2nd-stage preimage/timeout transactions.
293+
/// We use this to track static counterparty commitment transaction data and to generate any
294+
/// justice or 2nd-stage preimage/timeout transactions.
295295
#[derive(PartialEq)]
296-
struct CounterpartyCommitmentTransaction {
296+
struct CounterpartyCommitmentParameters {
297297
counterparty_delayed_payment_base_key: PublicKey,
298298
counterparty_htlc_base_key: PublicKey,
299299
on_counterparty_tx_csv: u16,
300300
}
301301

302-
impl Writeable for CounterpartyCommitmentTransaction {
302+
impl Writeable for CounterpartyCommitmentParameters {
303303
fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
304304
w.write_all(&byte_utils::be64_to_array(0))?;
305305
write_tlv_fields!(w, {
@@ -310,7 +310,7 @@ impl Writeable for CounterpartyCommitmentTransaction {
310310
Ok(())
311311
}
312312
}
313-
impl Readable for CounterpartyCommitmentTransaction {
313+
impl Readable for CounterpartyCommitmentParameters {
314314
fn read<R: io::Read>(r: &mut R) -> Result<Self, DecodeError> {
315315
let counterparty_commitment_transaction = {
316316
// Versions prior to 0.0.100 had some per-HTLC state stored here, which is no longer
@@ -332,7 +332,7 @@ impl Readable for CounterpartyCommitmentTransaction {
332332
(2, counterparty_htlc_base_key, required),
333333
(4, on_counterparty_tx_csv, required),
334334
});
335-
CounterpartyCommitmentTransaction {
335+
CounterpartyCommitmentParameters {
336336
counterparty_delayed_payment_base_key: counterparty_delayed_payment_base_key.0.unwrap(),
337337
counterparty_htlc_base_key: counterparty_htlc_base_key.0.unwrap(),
338338
on_counterparty_tx_csv,
@@ -524,7 +524,7 @@ pub(crate) struct ChannelMonitorImpl<Signer: Sign> {
524524
current_counterparty_commitment_txid: Option<Txid>,
525525
prev_counterparty_commitment_txid: Option<Txid>,
526526

527-
counterparty_tx_cache: CounterpartyCommitmentTransaction,
527+
counterparty_commitment_params: CounterpartyCommitmentParameters,
528528
funding_redeemscript: Script,
529529
channel_value_satoshis: u64,
530530
// first is the idx of the first of the two revocation points
@@ -637,7 +637,7 @@ impl<Signer: Sign> PartialEq for ChannelMonitorImpl<Signer> {
637637
self.funding_info != other.funding_info ||
638638
self.current_counterparty_commitment_txid != other.current_counterparty_commitment_txid ||
639639
self.prev_counterparty_commitment_txid != other.prev_counterparty_commitment_txid ||
640-
self.counterparty_tx_cache != other.counterparty_tx_cache ||
640+
self.counterparty_commitment_params != other.counterparty_commitment_params ||
641641
self.funding_redeemscript != other.funding_redeemscript ||
642642
self.channel_value_satoshis != other.channel_value_satoshis ||
643643
self.their_cur_revocation_points != other.their_cur_revocation_points ||
@@ -708,7 +708,7 @@ impl<Signer: Sign> Writeable for ChannelMonitorImpl<Signer> {
708708
self.current_counterparty_commitment_txid.write(writer)?;
709709
self.prev_counterparty_commitment_txid.write(writer)?;
710710

711-
self.counterparty_tx_cache.write(writer)?;
711+
self.counterparty_commitment_params.write(writer)?;
712712
self.funding_redeemscript.write(writer)?;
713713
self.channel_value_satoshis.write(writer)?;
714714

@@ -843,7 +843,7 @@ impl<Signer: Sign> ChannelMonitor<Signer> {
843843
let counterparty_channel_parameters = channel_parameters.counterparty_parameters.as_ref().unwrap();
844844
let counterparty_delayed_payment_base_key = counterparty_channel_parameters.pubkeys.delayed_payment_basepoint;
845845
let counterparty_htlc_base_key = counterparty_channel_parameters.pubkeys.htlc_basepoint;
846-
let counterparty_tx_cache = CounterpartyCommitmentTransaction { counterparty_delayed_payment_base_key, counterparty_htlc_base_key, on_counterparty_tx_csv };
846+
let counterparty_commitment_params = CounterpartyCommitmentParameters { counterparty_delayed_payment_base_key, counterparty_htlc_base_key, on_counterparty_tx_csv };
847847

848848
let channel_keys_id = keys.channel_keys_id();
849849
let holder_revocation_basepoint = keys.pubkeys().revocation_basepoint;
@@ -891,7 +891,7 @@ impl<Signer: Sign> ChannelMonitor<Signer> {
891891
current_counterparty_commitment_txid: None,
892892
prev_counterparty_commitment_txid: None,
893893

894-
counterparty_tx_cache,
894+
counterparty_commitment_params,
895895
funding_redeemscript,
896896
channel_value_satoshis,
897897
their_cur_revocation_points: None,
@@ -1629,16 +1629,16 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
16291629
let per_commitment_key = ignore_error!(SecretKey::from_slice(&secret));
16301630
let per_commitment_point = PublicKey::from_secret_key(&self.secp_ctx, &per_commitment_key);
16311631
let revocation_pubkey = ignore_error!(chan_utils::derive_public_revocation_key(&self.secp_ctx, &per_commitment_point, &self.holder_revocation_basepoint));
1632-
let delayed_key = ignore_error!(chan_utils::derive_public_key(&self.secp_ctx, &PublicKey::from_secret_key(&self.secp_ctx, &per_commitment_key), &self.counterparty_tx_cache.counterparty_delayed_payment_base_key));
1632+
let delayed_key = ignore_error!(chan_utils::derive_public_key(&self.secp_ctx, &PublicKey::from_secret_key(&self.secp_ctx, &per_commitment_key), &self.counterparty_commitment_params.counterparty_delayed_payment_base_key));
16331633

1634-
let revokeable_redeemscript = chan_utils::get_revokeable_redeemscript(&revocation_pubkey, self.counterparty_tx_cache.on_counterparty_tx_csv, &delayed_key);
1634+
let revokeable_redeemscript = chan_utils::get_revokeable_redeemscript(&revocation_pubkey, self.counterparty_commitment_params.on_counterparty_tx_csv, &delayed_key);
16351635
let revokeable_p2wsh = revokeable_redeemscript.to_v0_p2wsh();
16361636

16371637
// First, process non-htlc outputs (to_holder & to_counterparty)
16381638
for (idx, outp) in tx.output.iter().enumerate() {
16391639
if outp.script_pubkey == revokeable_p2wsh {
1640-
let revk_outp = RevokedOutput::build(per_commitment_point, self.counterparty_tx_cache.counterparty_delayed_payment_base_key, self.counterparty_tx_cache.counterparty_htlc_base_key, per_commitment_key, outp.value, self.counterparty_tx_cache.on_counterparty_tx_csv);
1641-
let justice_package = PackageTemplate::build_package(commitment_txid, idx as u32, PackageSolvingData::RevokedOutput(revk_outp), height + self.counterparty_tx_cache.on_counterparty_tx_csv as u32, true, height);
1640+
let revk_outp = RevokedOutput::build(per_commitment_point, self.counterparty_commitment_params.counterparty_delayed_payment_base_key, self.counterparty_commitment_params.counterparty_htlc_base_key, per_commitment_key, outp.value, self.counterparty_commitment_params.on_counterparty_tx_csv);
1641+
let justice_package = PackageTemplate::build_package(commitment_txid, idx as u32, PackageSolvingData::RevokedOutput(revk_outp), height + self.counterparty_commitment_params.on_counterparty_tx_csv as u32, true, height);
16421642
claimable_outpoints.push(justice_package);
16431643
}
16441644
}
@@ -1651,7 +1651,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
16511651
tx.output[transaction_output_index as usize].value != htlc.amount_msat / 1000 {
16521652
return (claimable_outpoints, (commitment_txid, watch_outputs)); // Corrupted per_commitment_data, fuck this user
16531653
}
1654-
let revk_htlc_outp = RevokedHTLCOutput::build(per_commitment_point, self.counterparty_tx_cache.counterparty_delayed_payment_base_key, self.counterparty_tx_cache.counterparty_htlc_base_key, per_commitment_key, htlc.amount_msat / 1000, htlc.clone());
1654+
let revk_htlc_outp = RevokedHTLCOutput::build(per_commitment_point, self.counterparty_commitment_params.counterparty_delayed_payment_base_key, self.counterparty_commitment_params.counterparty_htlc_base_key, per_commitment_key, htlc.amount_msat / 1000, htlc.clone());
16551655
let justice_package = PackageTemplate::build_package(commitment_txid, transaction_output_index, PackageSolvingData::RevokedHTLCOutput(revk_htlc_outp), htlc.cltv_expiry, true, height);
16561656
claimable_outpoints.push(justice_package);
16571657
}
@@ -1719,7 +1719,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
17191719
}
17201720
let preimage = if htlc.offered { if let Some(p) = self.payment_preimages.get(&htlc.payment_hash) { Some(*p) } else { None } } else { None };
17211721
if preimage.is_some() || !htlc.offered {
1722-
let counterparty_htlc_outp = if htlc.offered { PackageSolvingData::CounterpartyOfferedHTLCOutput(CounterpartyOfferedHTLCOutput::build(*revocation_point, self.counterparty_tx_cache.counterparty_delayed_payment_base_key, self.counterparty_tx_cache.counterparty_htlc_base_key, preimage.unwrap(), htlc.clone())) } else { PackageSolvingData::CounterpartyReceivedHTLCOutput(CounterpartyReceivedHTLCOutput::build(*revocation_point, self.counterparty_tx_cache.counterparty_delayed_payment_base_key, self.counterparty_tx_cache.counterparty_htlc_base_key, htlc.clone())) };
1722+
let counterparty_htlc_outp = if htlc.offered { PackageSolvingData::CounterpartyOfferedHTLCOutput(CounterpartyOfferedHTLCOutput::build(*revocation_point, self.counterparty_commitment_params.counterparty_delayed_payment_base_key, self.counterparty_commitment_params.counterparty_htlc_base_key, preimage.unwrap(), htlc.clone())) } else { PackageSolvingData::CounterpartyReceivedHTLCOutput(CounterpartyReceivedHTLCOutput::build(*revocation_point, self.counterparty_commitment_params.counterparty_delayed_payment_base_key, self.counterparty_commitment_params.counterparty_htlc_base_key, htlc.clone())) };
17231723
let aggregation = if !htlc.offered { false } else { true };
17241724
let counterparty_package = PackageTemplate::build_package(commitment_txid, transaction_output_index, counterparty_htlc_outp, htlc.cltv_expiry,aggregation, 0);
17251725
claimable_outpoints.push(counterparty_package);
@@ -1753,8 +1753,8 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
17531753
let per_commitment_point = PublicKey::from_secret_key(&self.secp_ctx, &per_commitment_key);
17541754

17551755
log_error!(logger, "Got broadcast of revoked counterparty HTLC transaction, spending {}:{}", htlc_txid, 0);
1756-
let revk_outp = RevokedOutput::build(per_commitment_point, self.counterparty_tx_cache.counterparty_delayed_payment_base_key, self.counterparty_tx_cache.counterparty_htlc_base_key, per_commitment_key, tx.output[0].value, self.counterparty_tx_cache.on_counterparty_tx_csv);
1757-
let justice_package = PackageTemplate::build_package(htlc_txid, 0, PackageSolvingData::RevokedOutput(revk_outp), height + self.counterparty_tx_cache.on_counterparty_tx_csv as u32, true, height);
1756+
let revk_outp = RevokedOutput::build(per_commitment_point, self.counterparty_commitment_params.counterparty_delayed_payment_base_key, self.counterparty_commitment_params.counterparty_htlc_base_key, per_commitment_key, tx.output[0].value, self.counterparty_commitment_params.on_counterparty_tx_csv);
1757+
let justice_package = PackageTemplate::build_package(htlc_txid, 0, PackageSolvingData::RevokedOutput(revk_outp), height + self.counterparty_commitment_params.on_counterparty_tx_csv as u32, true, height);
17581758
let claimable_outpoints = vec!(justice_package);
17591759
let outputs = vec![(0, tx.output[0].clone())];
17601760
(claimable_outpoints, Some((htlc_txid, outputs)))
@@ -2630,7 +2630,7 @@ impl<'a, Signer: Sign, K: KeysInterface<Signer = Signer>> ReadableArgs<&'a K>
26302630
let current_counterparty_commitment_txid = Readable::read(reader)?;
26312631
let prev_counterparty_commitment_txid = Readable::read(reader)?;
26322632

2633-
let counterparty_tx_cache = Readable::read(reader)?;
2633+
let counterparty_commitment_params = Readable::read(reader)?;
26342634
let funding_redeemscript = Readable::read(reader)?;
26352635
let channel_value_satoshis = Readable::read(reader)?;
26362636

@@ -2811,7 +2811,7 @@ impl<'a, Signer: Sign, K: KeysInterface<Signer = Signer>> ReadableArgs<&'a K>
28112811
current_counterparty_commitment_txid,
28122812
prev_counterparty_commitment_txid,
28132813

2814-
counterparty_tx_cache,
2814+
counterparty_commitment_params,
28152815
funding_redeemscript,
28162816
channel_value_satoshis,
28172817
their_cur_revocation_points,

0 commit comments

Comments
 (0)