Skip to content

Commit 4b523bb

Browse files
committed
Rename CounterpartyCommitmentTransaction to Params as it is static
1 parent 16b1c2f commit 4b523bb

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
@@ -288,16 +288,16 @@ impl_writeable_tlv_based!(HolderSignedTx, {
288288
(14, htlc_outputs, vec_type)
289289
});
290290

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

300-
impl Writeable for CounterpartyCommitmentTransaction {
300+
impl Writeable for CounterpartyCommitmentParameters {
301301
fn write<W: Writer>(&self, w: &mut W) -> Result<(), io::Error> {
302302
w.write_all(&byte_utils::be64_to_array(0))?;
303303
write_tlv_fields!(w, {
@@ -308,7 +308,7 @@ impl Writeable for CounterpartyCommitmentTransaction {
308308
Ok(())
309309
}
310310
}
311-
impl Readable for CounterpartyCommitmentTransaction {
311+
impl Readable for CounterpartyCommitmentParameters {
312312
fn read<R: io::Read>(r: &mut R) -> Result<Self, DecodeError> {
313313
let counterparty_commitment_transaction = {
314314
// Versions prior to 0.0.100 had some per-HTLC state stored here, which is no longer
@@ -330,7 +330,7 @@ impl Readable for CounterpartyCommitmentTransaction {
330330
(2, counterparty_htlc_base_key, required),
331331
(4, on_counterparty_tx_csv, required),
332332
});
333-
CounterpartyCommitmentTransaction {
333+
CounterpartyCommitmentParameters {
334334
counterparty_delayed_payment_base_key: counterparty_delayed_payment_base_key.0.unwrap(),
335335
counterparty_htlc_base_key: counterparty_htlc_base_key.0.unwrap(),
336336
on_counterparty_tx_csv,
@@ -514,7 +514,7 @@ pub(crate) struct ChannelMonitorImpl<Signer: Sign> {
514514
current_counterparty_commitment_txid: Option<Txid>,
515515
prev_counterparty_commitment_txid: Option<Txid>,
516516

517-
counterparty_tx_cache: CounterpartyCommitmentTransaction,
517+
counterparty_commitment_params: CounterpartyCommitmentParameters,
518518
funding_redeemscript: Script,
519519
channel_value_satoshis: u64,
520520
// first is the idx of the first of the two revocation points
@@ -624,7 +624,7 @@ impl<Signer: Sign> PartialEq for ChannelMonitorImpl<Signer> {
624624
self.funding_info != other.funding_info ||
625625
self.current_counterparty_commitment_txid != other.current_counterparty_commitment_txid ||
626626
self.prev_counterparty_commitment_txid != other.prev_counterparty_commitment_txid ||
627-
self.counterparty_tx_cache != other.counterparty_tx_cache ||
627+
self.counterparty_commitment_params != other.counterparty_commitment_params ||
628628
self.funding_redeemscript != other.funding_redeemscript ||
629629
self.channel_value_satoshis != other.channel_value_satoshis ||
630630
self.their_cur_revocation_points != other.their_cur_revocation_points ||
@@ -692,7 +692,7 @@ impl<Signer: Sign> Writeable for ChannelMonitorImpl<Signer> {
692692
self.current_counterparty_commitment_txid.write(writer)?;
693693
self.prev_counterparty_commitment_txid.write(writer)?;
694694

695-
self.counterparty_tx_cache.write(writer)?;
695+
self.counterparty_commitment_params.write(writer)?;
696696
self.funding_redeemscript.write(writer)?;
697697
self.channel_value_satoshis.write(writer)?;
698698

@@ -829,7 +829,7 @@ impl<Signer: Sign> ChannelMonitor<Signer> {
829829
let counterparty_channel_parameters = channel_parameters.counterparty_parameters.as_ref().unwrap();
830830
let counterparty_delayed_payment_base_key = counterparty_channel_parameters.pubkeys.delayed_payment_basepoint;
831831
let counterparty_htlc_base_key = counterparty_channel_parameters.pubkeys.htlc_basepoint;
832-
let counterparty_tx_cache = CounterpartyCommitmentTransaction { counterparty_delayed_payment_base_key, counterparty_htlc_base_key, on_counterparty_tx_csv };
832+
let counterparty_commitment_params = CounterpartyCommitmentParameters { counterparty_delayed_payment_base_key, counterparty_htlc_base_key, on_counterparty_tx_csv };
833833

834834
let channel_keys_id = keys.channel_keys_id();
835835
let holder_revocation_basepoint = keys.pubkeys().revocation_basepoint;
@@ -877,7 +877,7 @@ impl<Signer: Sign> ChannelMonitor<Signer> {
877877
current_counterparty_commitment_txid: None,
878878
prev_counterparty_commitment_txid: None,
879879

880-
counterparty_tx_cache,
880+
counterparty_commitment_params,
881881
funding_redeemscript,
882882
channel_value_satoshis,
883883
their_cur_revocation_points: None,
@@ -1596,16 +1596,16 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
15961596
let per_commitment_key = ignore_error!(SecretKey::from_slice(&secret));
15971597
let per_commitment_point = PublicKey::from_secret_key(&self.secp_ctx, &per_commitment_key);
15981598
let revocation_pubkey = ignore_error!(chan_utils::derive_public_revocation_key(&self.secp_ctx, &per_commitment_point, &self.holder_revocation_basepoint));
1599-
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));
1599+
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));
16001600

1601-
let revokeable_redeemscript = chan_utils::get_revokeable_redeemscript(&revocation_pubkey, self.counterparty_tx_cache.on_counterparty_tx_csv, &delayed_key);
1601+
let revokeable_redeemscript = chan_utils::get_revokeable_redeemscript(&revocation_pubkey, self.counterparty_commitment_params.on_counterparty_tx_csv, &delayed_key);
16021602
let revokeable_p2wsh = revokeable_redeemscript.to_v0_p2wsh();
16031603

16041604
// First, process non-htlc outputs (to_holder & to_counterparty)
16051605
for (idx, outp) in tx.output.iter().enumerate() {
16061606
if outp.script_pubkey == revokeable_p2wsh {
1607-
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);
1608-
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);
1607+
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);
1608+
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);
16091609
claimable_outpoints.push(justice_package);
16101610
}
16111611
}
@@ -1618,7 +1618,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
16181618
tx.output[transaction_output_index as usize].value != htlc.amount_msat / 1000 {
16191619
return (claimable_outpoints, (commitment_txid, watch_outputs)); // Corrupted per_commitment_data, fuck this user
16201620
}
1621-
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());
1621+
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());
16221622
let justice_package = PackageTemplate::build_package(commitment_txid, transaction_output_index, PackageSolvingData::RevokedHTLCOutput(revk_htlc_outp), htlc.cltv_expiry, true, height);
16231623
claimable_outpoints.push(justice_package);
16241624
}
@@ -1686,7 +1686,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
16861686
}
16871687
let preimage = if htlc.offered { if let Some(p) = self.payment_preimages.get(&htlc.payment_hash) { Some(*p) } else { None } } else { None };
16881688
if preimage.is_some() || !htlc.offered {
1689-
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())) };
1689+
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())) };
16901690
let aggregation = if !htlc.offered { false } else { true };
16911691
let counterparty_package = PackageTemplate::build_package(commitment_txid, transaction_output_index, counterparty_htlc_outp, htlc.cltv_expiry,aggregation, 0);
16921692
claimable_outpoints.push(counterparty_package);
@@ -1720,8 +1720,8 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
17201720
let per_commitment_point = PublicKey::from_secret_key(&self.secp_ctx, &per_commitment_key);
17211721

17221722
log_error!(logger, "Got broadcast of revoked counterparty HTLC transaction, spending {}:{}", htlc_txid, 0);
1723-
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);
1724-
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);
1723+
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);
1724+
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);
17251725
let claimable_outpoints = vec!(justice_package);
17261726
let outputs = vec![(0, tx.output[0].clone())];
17271727
(claimable_outpoints, Some((htlc_txid, outputs)))
@@ -2588,7 +2588,7 @@ impl<'a, Signer: Sign, K: KeysInterface<Signer = Signer>> ReadableArgs<&'a K>
25882588
let current_counterparty_commitment_txid = Readable::read(reader)?;
25892589
let prev_counterparty_commitment_txid = Readable::read(reader)?;
25902590

2591-
let counterparty_tx_cache = Readable::read(reader)?;
2591+
let counterparty_commitment_params = Readable::read(reader)?;
25922592
let funding_redeemscript = Readable::read(reader)?;
25932593
let channel_value_satoshis = Readable::read(reader)?;
25942594

@@ -2769,7 +2769,7 @@ impl<'a, Signer: Sign, K: KeysInterface<Signer = Signer>> ReadableArgs<&'a K>
27692769
current_counterparty_commitment_txid,
27702770
prev_counterparty_commitment_txid,
27712771

2772-
counterparty_tx_cache,
2772+
counterparty_commitment_params,
27732773
funding_redeemscript,
27742774
channel_value_satoshis,
27752775
their_cur_revocation_points,

0 commit comments

Comments
 (0)