X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fchain%2Fonchaintx.rs;h=5daa2463de99ec0d129bd3e28f0cf6a11b161e9c;hb=eea19de198a359d9014d704baaffc70bdb93f4f7;hp=beb0dfc10353eabe0b9339fd67bdca22f988edae;hpb=b4d082b833422b9f055ea920462b0771ebfc3b2b;p=rust-lightning diff --git a/lightning/src/chain/onchaintx.rs b/lightning/src/chain/onchaintx.rs index beb0dfc1..5daa2463 100644 --- a/lightning/src/chain/onchaintx.rs +++ b/lightning/src/chain/onchaintx.rs @@ -50,7 +50,7 @@ const MAX_ALLOC_SIZE: usize = 64*1024; /// transaction causing it. /// /// Used to determine when the on-chain event can be considered safe from a chain reorganization. -#[derive(PartialEq, Eq)] +#[derive(Clone, PartialEq, Eq)] struct OnchainEventEntry { txid: Txid, height: u32, @@ -70,7 +70,7 @@ impl OnchainEventEntry { /// Events for claims the [`OnchainTxHandler`] has generated. Once the events are considered safe /// from a chain reorg, the [`OnchainTxHandler`] will act accordingly. -#[derive(PartialEq, Eq)] +#[derive(Clone, PartialEq, Eq)] enum OnchainEvent { /// A pending request has been claimed by a transaction spending the exact same set of outpoints /// as the request. This claim can either be ours or from the counterparty. Once the claiming @@ -172,6 +172,7 @@ impl Writeable for Option>> { } /// The claim commonly referred to as the pre-signed second-stage HTLC transaction. +#[derive(Clone, PartialEq, Eq)] pub(crate) struct ExternalHTLCClaim { pub(crate) commitment_txid: Txid, pub(crate) per_commitment_number: u64, @@ -182,6 +183,7 @@ pub(crate) struct ExternalHTLCClaim { // Represents the different types of claims for which events are yielded externally to satisfy said // claims. +#[derive(Clone, PartialEq, Eq)] pub(crate) enum ClaimEvent { /// Event yielded to signal that the commitment transaction fee must be bumped to claim any /// encumbered funds and proceed to HTLC resolution, if any HTLCs exist. @@ -211,6 +213,7 @@ pub(crate) enum OnchainClaim { /// OnchainTxHandler receives claiming requests, aggregates them if it's sound, broadcast and /// do RBF bumping if possible. +#[derive(Clone)] pub struct OnchainTxHandler { destination_script: Script, holder_commitment: HolderCommitmentTransaction, @@ -633,11 +636,12 @@ impl OnchainTxHandler .compute_package_feerate(fee_estimator, conf_target, force_feerate_bump); if let Some(input_amount_sat) = output.funding_amount { let fee_sat = input_amount_sat - tx.output.iter().map(|output| output.value).sum::(); - if compute_feerate_sat_per_1000_weight(fee_sat, tx.weight() as u64) >= - package_target_feerate_sat_per_1000_weight - { - log_debug!(logger, "Commitment transaction {} already meets required feerate {} sat/kW", - tx.txid(), package_target_feerate_sat_per_1000_weight); + let commitment_tx_feerate_sat_per_1000_weight = + compute_feerate_sat_per_1000_weight(fee_sat, tx.weight() as u64); + if commitment_tx_feerate_sat_per_1000_weight >= package_target_feerate_sat_per_1000_weight { + log_debug!(logger, "Pre-signed {} already has feerate {} sat/kW above required {} sat/kW", + log_tx!(tx), commitment_tx_feerate_sat_per_1000_weight, + package_target_feerate_sat_per_1000_weight); return Some((new_timer, 0, OnchainClaim::Tx(tx.clone()))); } } @@ -1119,6 +1123,10 @@ impl OnchainTxHandler ret } + pub(crate) fn get_unsigned_holder_commitment_tx(&self) -> &Transaction { + &self.holder_commitment.trust().built_transaction().transaction + } + //TODO: getting lastest holder transactions should be infallible and result in us "force-closing the channel", but we may // have empty holder commitment transaction if a ChannelMonitor is asked to force-close just after OutboundV1Channel::get_funding_created, // before providing a initial commitment transaction. For outbound channel, init ChannelMonitor at Channel::funding_signed, there is nothing