Skip to content

Commit 7aae256

Browse files
author
Antoine Riard
committed
-f Kill OnchainRequest
1 parent 083f87d commit 7aae256

File tree

3 files changed

+58
-91
lines changed

3 files changed

+58
-91
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 13 additions & 13 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};
@@ -1429,7 +1429,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
14291429
/// HTLC-Success/HTLC-Timeout transactions.
14301430
/// Return updates for HTLC pending in the channel and failed automatically by the broadcast of
14311431
/// revoked counterparty commitment tx
1432-
fn check_spend_counterparty_transaction<L: Deref>(&mut self, tx: &Transaction, height: u32, logger: &L) -> (Vec<OnchainRequest>, (Txid, Vec<(u32, TxOut)>)) where L::Target: Logger {
1432+
fn check_spend_counterparty_transaction<L: Deref>(&mut self, tx: &Transaction, height: u32, logger: &L) -> (Vec<PackageTemplate>, (Txid, Vec<(u32, TxOut)>)) where L::Target: Logger {
14331433
// Most secp and related errors trying to create keys means we have no hope of constructing
14341434
// a spend transaction...so we return no transactions to broadcast
14351435
let mut claimable_outpoints = Vec::new();
@@ -1463,7 +1463,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
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);
14651465
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});
1466+
claimable_outpoints.push(justice_package);
14671467
}
14681468
}
14691469

@@ -1477,7 +1477,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
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);
14791479
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});
1480+
claimable_outpoints.push(justice_package);
14811481
}
14821482
}
14831483
}
@@ -1600,7 +1600,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
16001600
(claimable_outpoints, (commitment_txid, watch_outputs))
16011601
}
16021602

1603-
fn get_counterparty_htlc_output_claim_reqs(&self, commitment_number: u64, commitment_txid: Txid, tx: Option<&Transaction>) -> Vec<OnchainRequest> {
1603+
fn get_counterparty_htlc_output_claim_reqs(&self, commitment_number: u64, commitment_txid: Txid, tx: Option<&Transaction>) -> Vec<PackageTemplate> {
16041604
let mut claimable_outpoints = Vec::new();
16051605
if let Some(htlc_outputs) = self.counterparty_claimable_outpoints.get(&commitment_txid) {
16061606
if let Some(revocation_points) = self.their_cur_revocation_points {
@@ -1627,7 +1627,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
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());
16291629
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 });
1630+
claimable_outpoints.push(counterparty_package);
16311631
}
16321632
}
16331633
}
@@ -1638,7 +1638,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
16381638
}
16391639

16401640
/// Attempts to claim a counterparty HTLC-Success/HTLC-Timeout's outputs using the revocation key
1641-
fn check_spend_counterparty_htlc<L: Deref>(&mut self, tx: &Transaction, commitment_number: u64, height: u32, logger: &L) -> (Vec<OnchainRequest>, Option<(Txid, Vec<(u32, TxOut)>)>) where L::Target: Logger {
1641+
fn check_spend_counterparty_htlc<L: Deref>(&mut self, tx: &Transaction, commitment_number: u64, height: u32, logger: &L) -> (Vec<PackageTemplate>, Option<(Txid, Vec<(u32, TxOut)>)>) where L::Target: Logger {
16421642
let htlc_txid = tx.txid();
16431643
if tx.input.len() != 1 || tx.output.len() != 1 || tx.input[0].witness.len() != 5 {
16441644
return (Vec::new(), None)
@@ -1660,15 +1660,15 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
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);
16621662
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 });
1663+
let claimable_outpoints = vec!(justice_package);
16641664
let outputs = vec![(0, tx.output[0].clone())];
16651665
(claimable_outpoints, Some((htlc_txid, outputs)))
16661666
}
16671667

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

16741674
let redeemscript = chan_utils::get_revokeable_redeemscript(&holder_tx.revocation_key, self.on_holder_tx_csv, &holder_tx.delayed_payment_key);
@@ -1685,7 +1685,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
16851685
}
16861686
} else { None }, htlc.amount_msat);
16871687
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 });
1688+
claim_requests.push(htlc_package);
16891689
}
16901690
}
16911691

@@ -1706,7 +1706,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
17061706
/// Attempts to claim any claimable HTLCs in a commitment transaction which was not (yet)
17071707
/// revoked using data in holder_claimable_outpoints.
17081708
/// Should not be used if check_spend_revoked_transaction succeeds.
1709-
fn check_spend_holder_transaction<L: Deref>(&mut self, tx: &Transaction, height: u32, logger: &L) -> (Vec<OnchainRequest>, (Txid, Vec<(u32, TxOut)>)) where L::Target: Logger {
1709+
fn check_spend_holder_transaction<L: Deref>(&mut self, tx: &Transaction, height: u32, logger: &L) -> (Vec<PackageTemplate>, (Txid, Vec<(u32, TxOut)>)) where L::Target: Logger {
17101710
let commitment_txid = tx.txid();
17111711
let mut claim_requests = Vec::new();
17121712
let mut watch_outputs = Vec::new();
@@ -1894,7 +1894,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
18941894
if should_broadcast {
18951895
let funding_outp = HolderFundingOutput::build(self.funding_redeemscript.clone());
18961896
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 });
1897+
claimable_outpoints.push(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: 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)