Skip to content

Commit 083f87d

Browse files
author
Antoine Riard
committed
-f Dry-up height_original from OnchainRequest to PackageTemplate
1 parent 04084e9 commit 083f87d

File tree

2 files changed

+22
-19
lines changed

2 files changed

+22
-19
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,8 +1462,8 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
14621462
for (idx, outp) in tx.output.iter().enumerate() {
14631463
if outp.script_pubkey == revokeable_p2wsh {
14641464
let revk_outp = RevokedOutput::build(per_commitment_point, per_commitment_key, self.counterparty_tx_cache.counterparty_delayed_payment_base_key, self.counterparty_tx_cache.counterparty_htlc_base_key, InputDescriptors::RevokedOutput, outp.value, None, self.counterparty_tx_cache.on_counterparty_tx_csv);
1465-
let justice_package = PackageTemplate::build_package(commitment_txid, idx as u32, PackageSolvingData::RevokedOutput(revk_outp), PackageMalleability::Malleable, height + self.counterparty_tx_cache.on_counterparty_tx_csv as u32, true, 0, None);
1466-
claimable_outpoints.push(OnchainRequest { height_original: height, content: justice_package});
1465+
let justice_package = PackageTemplate::build_package(commitment_txid, idx as u32, PackageSolvingData::RevokedOutput(revk_outp), PackageMalleability::Malleable, height + self.counterparty_tx_cache.on_counterparty_tx_csv as u32, true, 0, None, height);
1466+
claimable_outpoints.push(OnchainRequest { content: justice_package});
14671467
}
14681468
}
14691469

@@ -1476,8 +1476,8 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
14761476
return (claimable_outpoints, (commitment_txid, watch_outputs)); // Corrupted per_commitment_data, fuck this user
14771477
}
14781478
let revk_outp = RevokedOutput::build(per_commitment_point, per_commitment_key, self.counterparty_tx_cache.counterparty_delayed_payment_base_key, self.counterparty_tx_cache.counterparty_htlc_base_key, if htlc.offered { InputDescriptors::RevokedOfferedHTLC } else { InputDescriptors::RevokedReceivedHTLC }, htlc.amount_msat / 1000, Some(htlc.clone()), self.counterparty_tx_cache.on_counterparty_tx_csv);
1479-
let justice_package = PackageTemplate::build_package(commitment_txid, transaction_output_index, PackageSolvingData::RevokedOutput(revk_outp), PackageMalleability::Malleable, htlc.cltv_expiry, true, 0, None);
1480-
claimable_outpoints.push(OnchainRequest { height_original: height, content: justice_package});
1479+
let justice_package = PackageTemplate::build_package(commitment_txid, transaction_output_index, PackageSolvingData::RevokedOutput(revk_outp), PackageMalleability::Malleable, htlc.cltv_expiry, true, 0, None, height);
1480+
claimable_outpoints.push(OnchainRequest { content: justice_package});
14811481
}
14821482
}
14831483
}
@@ -1626,8 +1626,8 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
16261626
let preimage = if htlc.offered { if let Some(p) = self.payment_preimages.get(&htlc.payment_hash) { Some(*p) } else { None } } else { None };
16271627
if preimage.is_some() || !htlc.offered {
16281628
let counterparty_htlc_outp = CounterpartyHTLCOutput::build(*revocation_point, self.counterparty_tx_cache.counterparty_delayed_payment_base_key, self.counterparty_tx_cache.counterparty_htlc_base_key, preimage, htlc.clone());
1629-
let counterparty_package = PackageTemplate::build_package(commitment_txid, transaction_output_index, PackageSolvingData::CounterpartyHTLCOutput(counterparty_htlc_outp), PackageMalleability::Malleable, htlc.cltv_expiry, if !htlc.offered { false } else { true }, 0, None);
1630-
claimable_outpoints.push(OnchainRequest { height_original: /*XXX(ariard) Option<height> */ 0, content: counterparty_package });
1629+
let counterparty_package = PackageTemplate::build_package(commitment_txid, transaction_output_index, PackageSolvingData::CounterpartyHTLCOutput(counterparty_htlc_outp), PackageMalleability::Malleable, htlc.cltv_expiry, if !htlc.offered { false } else { true }, 0, None, 0);
1630+
claimable_outpoints.push(OnchainRequest { content: counterparty_package });
16311631
}
16321632
}
16331633
}
@@ -1659,8 +1659,8 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
16591659

16601660
log_trace!(logger, "Counterparty HTLC broadcast {}:{}", htlc_txid, 0);
16611661
let revk_outp = RevokedOutput::build(per_commitment_point, per_commitment_key, self.counterparty_tx_cache.counterparty_delayed_payment_base_key, self.counterparty_tx_cache.counterparty_htlc_base_key, InputDescriptors::RevokedOutput, tx.output[0].value, None, self.counterparty_tx_cache.on_counterparty_tx_csv);
1662-
let justice_package = PackageTemplate::build_package(htlc_txid, 0, PackageSolvingData::RevokedOutput(revk_outp), PackageMalleability::Malleable, height + self.counterparty_tx_cache.on_counterparty_tx_csv as u32, true, 0, None);
1663-
let claimable_outpoints = vec!(OnchainRequest { height_original: height, content: justice_package });
1662+
let justice_package = PackageTemplate::build_package(htlc_txid, 0, PackageSolvingData::RevokedOutput(revk_outp), PackageMalleability::Malleable, height + self.counterparty_tx_cache.on_counterparty_tx_csv as u32, true, 0, None, height);
1663+
let claimable_outpoints = vec!(OnchainRequest { content: justice_package });
16641664
let outputs = vec![(0, tx.output[0].clone())];
16651665
(claimable_outpoints, Some((htlc_txid, outputs)))
16661666
}
@@ -1684,8 +1684,8 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
16841684
continue;
16851685
}
16861686
} else { None }, htlc.amount_msat);
1687-
let htlc_package = PackageTemplate::build_package(holder_tx.txid, transaction_output_index, PackageSolvingData::HolderHTLCOutput(htlc_output), PackageMalleability::Untractable, height, false, 0, None);
1688-
claim_requests.push(OnchainRequest { height_original: height, content: htlc_package });
1687+
let htlc_package = PackageTemplate::build_package(holder_tx.txid, transaction_output_index, PackageSolvingData::HolderHTLCOutput(htlc_output), PackageMalleability::Untractable, height, false, 0, None, height);
1688+
claim_requests.push(OnchainRequest { content: htlc_package });
16891689
}
16901690
}
16911691

@@ -1893,8 +1893,8 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
18931893
let should_broadcast = self.would_broadcast_at_height(height, &logger);
18941894
if should_broadcast {
18951895
let funding_outp = HolderFundingOutput::build(self.funding_redeemscript.clone());
1896-
let commitment_package = PackageTemplate::build_package(self.funding_info.0.txid.clone(), self.funding_info.0.index as u32, PackageSolvingData::HolderFundingOutput(funding_outp), PackageMalleability::Untractable, height, false, 0, None);
1897-
claimable_outpoints.push(OnchainRequest { height_original: height, content: commitment_package });
1896+
let commitment_package = PackageTemplate::build_package(self.funding_info.0.txid.clone(), self.funding_info.0.index as u32, PackageSolvingData::HolderFundingOutput(funding_outp), PackageMalleability::Untractable, height, false, 0, None, height);
1897+
claimable_outpoints.push(OnchainRequest { content: commitment_package });
18981898
}
18991899
if should_broadcast {
19001900
self.pending_monitor_events.push(MonitorEvent::CommitmentTxBroadcasted(self.funding_info.0));

lightning/src/chain/onchain_utils.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,8 @@ pub(crate) struct PackageTemplate {
494494
// At every block tick, used to check if pending claiming tx is taking too
495495
// much time for confirmation and we need to bump it.
496496
height_timer: Option<u32>,
497+
// Tracked in case of reorg to wipe out now-superflous request.
498+
height_original: u32,
497499
}
498500

499501
impl PackageTemplate {
@@ -536,6 +538,7 @@ impl PackageTemplate {
536538
let aggregation = self.aggregation;
537539
let feerate_previous = self.feerate_previous;
538540
let height_timer = self.height_timer;
541+
let height_original = self.height_original;
539542
self.inputs.retain(|outp| {
540543
if *split_outp == outp.0 {
541544
split_package = Some(PackageTemplate {
@@ -545,6 +548,7 @@ impl PackageTemplate {
545548
aggregation,
546549
feerate_previous,
547550
height_timer,
551+
height_original,
548552
});
549553
return false;
550554
}
@@ -563,6 +567,7 @@ impl PackageTemplate {
563567
}
564568
}
565569
pub(crate) fn merge_package(&mut self, mut merge_from: PackageTemplate) {
570+
assert_eq!(self.height_original, merge_from.height_original);
566571
if self.malleability == PackageMalleability::Untractable || merge_from.malleability == PackageMalleability::Untractable {
567572
panic!("Merging template on untractable packages");
568573
}
@@ -657,7 +662,7 @@ impl PackageTemplate {
657662
},
658663
}
659664
}
660-
pub (crate) fn build_package(txid: Txid, vout: u32, input_solving_data: PackageSolvingData, malleability: PackageMalleability, absolute_timelock: u32, aggregation: bool, feerate_previous: u64, height_timer: Option<u32>) -> Self {
665+
pub (crate) fn build_package(txid: Txid, vout: u32, input_solving_data: PackageSolvingData, malleability: PackageMalleability, absolute_timelock: u32, aggregation: bool, feerate_previous: u64, height_timer: Option<u32>, height_original: u32) -> Self {
661666
let mut inputs = Vec::with_capacity(1);
662667
inputs.push((BitcoinOutPoint { txid, vout }, input_solving_data));
663668
PackageTemplate {
@@ -667,6 +672,7 @@ impl PackageTemplate {
667672
aggregation,
668673
feerate_previous,
669674
height_timer,
675+
height_original,
670676
}
671677
}
672678
}
@@ -683,6 +689,7 @@ impl Writeable for PackageTemplate {
683689
self.aggregation.write(writer)?;
684690
self.feerate_previous.write(writer)?;
685691
self.height_timer.write(writer)?;
692+
self.height_original.write(writer)?;
686693
Ok(())
687694
}
688695
}
@@ -701,13 +708,15 @@ impl Readable for PackageTemplate {
701708
let aggregation = Readable::read(reader)?;
702709
let feerate_previous = Readable::read(reader)?;
703710
let height_timer = Readable::read(reader)?;
711+
let height_original = Readable::read(reader)?;
704712
Ok(PackageTemplate {
705713
inputs,
706714
malleability,
707715
absolute_timelock,
708716
aggregation,
709717
feerate_previous,
710718
height_timer,
719+
height_original,
711720
})
712721
}
713722
}
@@ -731,22 +740,18 @@ impl Readable for PackageTemplate {
731740
/// Content embeds transactions elements to generate transaction. See PackageTemplate.
732741
#[derive(PartialEq, Clone)]
733742
pub struct OnchainRequest {
734-
// Tracked in case of reorg to wipe out now-superflous request.
735-
pub(crate) height_original: u32,
736743
// Content of request.
737744
pub(crate) content: PackageTemplate,
738745
}
739746

740747
impl OnchainRequest {
741748
pub(crate) fn request_merge(&mut self, req: OnchainRequest) {
742-
assert_eq!(self.height_original, req.height_original);
743749
self.content.merge_package(req.content);
744750
}
745751
}
746752

747753
impl Writeable for OnchainRequest {
748754
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), ::std::io::Error> {
749-
self.height_original.write(writer)?;
750755
self.content.write(writer)?;
751756

752757
Ok(())
@@ -755,11 +760,9 @@ impl Writeable for OnchainRequest {
755760

756761
impl Readable for OnchainRequest {
757762
fn read<R: ::std::io::Read>(reader: &mut R) -> Result<Self, DecodeError> {
758-
let height_original = Readable::read(reader)?;
759763
let content = Readable::read(reader)?;
760764

761765
Ok(OnchainRequest {
762-
height_original,
763766
content
764767
})
765768
}

0 commit comments

Comments
 (0)