Skip to content

Commit 7161338

Browse files
author
Antoine Riard
committed
-f Kill OnchainRequest
1 parent b359219 commit 7161338

File tree

3 files changed

+59
-92
lines changed

3 files changed

+59
-92
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ use chain::chaininterface::{BroadcasterInterface, FeeEstimator};
4343
use chain::transaction::{OutPoint, TransactionData};
4444
use chain::keysinterface::{SpendableOutputDescriptor, StaticPaymentOutputDescriptor, DelayedPaymentOutputDescriptor, Sign, KeysInterface};
4545
use chain::onchaintx::OnchainTxHandler;
46-
use chain::onchain_utils::{CounterpartyHTLCOutput, HolderFundingOutput, HolderHTLCOutput, InputDescriptors, OnchainRequest, PackageMalleability, PackageSolvingData, PackageTemplate, RevokedOutput};
46+
use chain::onchain_utils::{CounterpartyHTLCOutput, HolderFundingOutput, HolderHTLCOutput, InputDescriptors, PackageMalleability, PackageSolvingData, PackageTemplate, RevokedOutput};
4747
use chain::Filter;
4848
use util::logger::Logger;
4949
use util::ser::{Readable, ReadableArgs, MaybeReadable, Writer, Writeable, U48};
@@ -1549,7 +1549,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
15491549
/// HTLC-Success/HTLC-Timeout transactions.
15501550
/// Return updates for HTLC pending in the channel and failed automatically by the broadcast of
15511551
/// revoked counterparty commitment tx
1552-
fn check_spend_counterparty_transaction<L: Deref>(&mut self, tx: &Transaction, height: u32, logger: &L) -> (Vec<OnchainRequest>, TransactionOutputs) where L::Target: Logger {
1552+
fn check_spend_counterparty_transaction<L: Deref>(&mut self, tx: &Transaction, height: u32, logger: &L) -> (Vec<PackageTemplate>, TransactionOutputs) where L::Target: Logger {
15531553
// Most secp and related errors trying to create keys means we have no hope of constructing
15541554
// a spend transaction...so we return no transactions to broadcast
15551555
let mut claimable_outpoints = Vec::new();
@@ -1583,7 +1583,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
15831583
if outp.script_pubkey == revokeable_p2wsh {
15841584
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);
15851585
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);
1586-
claimable_outpoints.push(OnchainRequest { content: justice_package});
1586+
claimable_outpoints.push(justice_package);
15871587
}
15881588
}
15891589

@@ -1597,7 +1597,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
15971597
}
15981598
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);
15991599
let justice_package = PackageTemplate::build_package(commitment_txid, transaction_output_index, PackageSolvingData::RevokedOutput(revk_outp), PackageMalleability::Malleable, htlc.cltv_expiry, true, 0, None, height);
1600-
claimable_outpoints.push(OnchainRequest { content: justice_package});
1600+
claimable_outpoints.push(justice_package);
16011601
}
16021602
}
16031603
}
@@ -1719,7 +1719,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
17191719
(claimable_outpoints, (commitment_txid, watch_outputs))
17201720
}
17211721

1722-
fn get_counterparty_htlc_output_claim_reqs(&self, commitment_number: u64, commitment_txid: Txid, tx: Option<&Transaction>) -> Vec<OnchainRequest> {
1722+
fn get_counterparty_htlc_output_claim_reqs(&self, commitment_number: u64, commitment_txid: Txid, tx: Option<&Transaction>) -> Vec<PackageTemplate> {
17231723
let mut claimable_outpoints = Vec::new();
17241724
if let Some(htlc_outputs) = self.counterparty_claimable_outpoints.get(&commitment_txid) {
17251725
if let Some(revocation_points) = self.their_cur_revocation_points {
@@ -1746,7 +1746,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
17461746
if preimage.is_some() || !htlc.offered {
17471747
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());
17481748
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);
1749-
claimable_outpoints.push(OnchainRequest { content: counterparty_package });
1749+
claimable_outpoints.push(counterparty_package);
17501750
}
17511751
}
17521752
}
@@ -1757,7 +1757,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
17571757
}
17581758

17591759
/// Attempts to claim a counterparty HTLC-Success/HTLC-Timeout's outputs using the revocation key
1760-
fn check_spend_counterparty_htlc<L: Deref>(&mut self, tx: &Transaction, commitment_number: u64, height: u32, logger: &L) -> (Vec<OnchainRequest>, Option<TransactionOutputs>) where L::Target: Logger {
1760+
fn check_spend_counterparty_htlc<L: Deref>(&mut self, tx: &Transaction, commitment_number: u64, height: u32, logger: &L) -> (Vec<PackageTemplate>, Option<TransactionOutputs>) where L::Target: Logger {
17611761
let htlc_txid = tx.txid();
17621762
if tx.input.len() != 1 || tx.output.len() != 1 || tx.input[0].witness.len() != 5 {
17631763
return (Vec::new(), None)
@@ -1779,15 +1779,15 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
17791779
log_trace!(logger, "Counterparty HTLC broadcast {}:{}", htlc_txid, 0);
17801780
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);
17811781
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);
1782-
let claimable_outpoints = vec!(OnchainRequest { content: justice_package });
1782+
let claimable_outpoints = vec!(justice_package);
17831783
let outputs = vec![(0, tx.output[0].clone())];
17841784
(claimable_outpoints, Some((htlc_txid, outputs)))
17851785
}
17861786

1787-
// Returns (1) `OnchainRequest`s that can be given to the OnChainTxHandler, so that the handler can
1787+
// Returns (1) `PackageTemplate`s that can be given to the OnChainTxHandler, so that the handler can
17881788
// broadcast transactions claiming holder HTLC commitment outputs and (2) a holder revokable
17891789
// script so we can detect whether a holder transaction has been seen on-chain.
1790-
fn get_broadcasted_holder_claims(&self, holder_tx: &HolderSignedTx, height: u32) -> (Vec<OnchainRequest>, Option<(Script, PublicKey, PublicKey)>) {
1790+
fn get_broadcasted_holder_claims(&self, holder_tx: &HolderSignedTx, height: u32) -> (Vec<PackageTemplate>, Option<(Script, PublicKey, PublicKey)>) {
17911791
let mut claim_requests = Vec::with_capacity(holder_tx.htlc_outputs.len());
17921792

17931793
let redeemscript = chan_utils::get_revokeable_redeemscript(&holder_tx.revocation_key, self.on_holder_tx_csv, &holder_tx.delayed_payment_key);
@@ -1804,7 +1804,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
18041804
}
18051805
} else { None }, htlc.amount_msat);
18061806
let htlc_package = PackageTemplate::build_package(holder_tx.txid, transaction_output_index, PackageSolvingData::HolderHTLCOutput(htlc_output), PackageMalleability::Untractable, height, false, 0, None, height);
1807-
claim_requests.push(OnchainRequest { content: htlc_package });
1807+
claim_requests.push(htlc_package);
18081808
}
18091809
}
18101810

@@ -1825,7 +1825,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
18251825
/// Attempts to claim any claimable HTLCs in a commitment transaction which was not (yet)
18261826
/// revoked using data in holder_claimable_outpoints.
18271827
/// Should not be used if check_spend_revoked_transaction succeeds.
1828-
fn check_spend_holder_transaction<L: Deref>(&mut self, tx: &Transaction, height: u32, logger: &L) -> (Vec<OnchainRequest>, TransactionOutputs) where L::Target: Logger {
1828+
fn check_spend_holder_transaction<L: Deref>(&mut self, tx: &Transaction, height: u32, logger: &L) -> (Vec<PackageTemplate>, TransactionOutputs) where L::Target: Logger {
18291829
let commitment_txid = tx.txid();
18301830
let mut claim_requests = Vec::new();
18311831
let mut watch_outputs = Vec::new();
@@ -2064,7 +2064,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
20642064
height: u32,
20652065
txn_matched: Vec<&Transaction>,
20662066
mut watch_outputs: Vec<TransactionOutputs>,
2067-
mut claimable_outpoints: Vec<OnchainRequest>,
2067+
mut claimable_outpoints: Vec<PackageTemplate>,
20682068
broadcaster: B,
20692069
fee_estimator: F,
20702070
logger: L,
@@ -2078,7 +2078,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
20782078
if should_broadcast {
20792079
let funding_outp = HolderFundingOutput::build(self.funding_redeemscript.clone());
20802080
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);
2081-
claimable_outpoints.push(OnchainRequest { content: commitment_package });
2081+
claimable_outpoints.push(commitment_package);
20822082
self.pending_monitor_events.push(MonitorEvent::CommitmentTxBroadcasted(self.funding_info.0));
20832083
let commitment_tx = self.onchain_tx_handler.get_fully_signed_holder_tx(&self.funding_redeemscript);
20842084
self.holder_tx_signed = true;

lightning/src/chain/onchain_utils.rs

Lines changed: 14 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,20 @@ impl Readable for PackageMalleability {
475475
/// the claim-settlement tx in itself has its feerate increased or Child-Pay-For-Parent, a child
476476
/// of the claim tx has its feerate increased. For the latter case, access to the whole package
477477
/// sizea and pre-committed fee is required to compute an efficient bump.
478+
///
479+
/// Metadata are related to multiple fields playing a role in package lifetime.
480+
/// Once issued, it may be aggregated with other package if it's judged safe
481+
/// and feerate opportunistic.
482+
/// Current LN fees model, pre-committed fees with update_fee adjustement, means
483+
/// that counter-signed transactions must be CPFP to be dynamically confirmed as a
484+
/// bumping strategy. If transactions aren't lockdown (i.e justice transactions) we
485+
/// may RBF them.
486+
/// Feerate previous will serve as a feerate floor between different bumping attempts.
487+
/// Height timer clocks these different bumping attempts.
488+
/// Absolute timelock defines the block barrier at which claiming isn't exclusive
489+
/// to us anymore and thus we MUST have get it solved before.
490+
/// Height original serves as a packet timestamps to prune out claim in case of reorg.
491+
/// Content embeds transactions elements to generate transaction. See PackageTemplate.
478492
#[derive(Clone, PartialEq)]
479493
pub(crate) struct PackageTemplate {
480494
inputs: Vec<(BitcoinOutPoint, PackageSolvingData)>,
@@ -721,53 +735,6 @@ impl Readable for PackageTemplate {
721735
}
722736
}
723737

724-
/// A structure to describe a claim content and its metadatas which is generated
725-
/// by ChannelMonitor and used by OnchainTxHandler to generate feerate-competive
726-
/// transactions.
727-
///
728-
/// Metadata are related to multiple fields playing a role in packet lifetime.
729-
/// Once issued, it may be aggregated with other requests if it's judged safe
730-
/// and feerate opportunistic.
731-
/// Current LN fees model, pre-committed fees with update_fee adjustement, means
732-
/// that counter-signed transactions must be CPFP to be dynamically confirmed as a
733-
/// bumping strategy. If transactions aren't lockdown (i.e justice transactions) we
734-
/// may RBF them.
735-
/// Feerate previous will serve as a feerate floor between different bumping attempts.
736-
/// Height timer clocks these different bumping attempts.
737-
/// Absolute timelock defines the block barrier at which claiming isn't exclusive
738-
/// to us anymore and thus we MUST have get it solved before.
739-
/// Height original serves as a packet timestamps to prune out claim in case of reorg.
740-
/// Content embeds transactions elements to generate transaction. See PackageTemplate.
741-
#[derive(PartialEq, Clone)]
742-
pub struct OnchainRequest {
743-
// Content of request.
744-
pub(crate) content: PackageTemplate,
745-
}
746-
747-
impl OnchainRequest {
748-
pub(crate) fn request_merge(&mut self, req: OnchainRequest) {
749-
self.content.merge_package(req.content);
750-
}
751-
}
752-
753-
impl Writeable for OnchainRequest {
754-
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), ::std::io::Error> {
755-
self.content.write(writer)?;
756-
757-
Ok(())
758-
}
759-
}
760-
761-
impl Readable for OnchainRequest {
762-
fn read<R: ::std::io::Read>(reader: &mut R) -> Result<Self, DecodeError> {
763-
let content = Readable::read(reader)?;
764-
765-
Ok(OnchainRequest {
766-
content
767-
})
768-
}
769-
}
770-
771738
fn subtract_high_prio_fee<F: Deref, L: Deref>(input_amounts: u64, predicted_weight: usize, fee_estimator: &F, logger: &L) -> Option<(u64, u64)>
772739
where F::Target: FeeEstimator,
773740
L::Target: Logger,

0 commit comments

Comments
 (0)