X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fchain%2Fchannelmonitor.rs;h=1a9afb7cca75d55f4dc2d37de30c43b5e59f4ff1;hb=ba342de241f0b5e968d6ad0106e5690e7c9c68bc;hp=a9ef37564277143c3bd4742c2d3376322ae01e55;hpb=498f2331459d8031031ef151a44c90d700aa8c7e;p=rust-lightning diff --git a/lightning/src/chain/channelmonitor.rs b/lightning/src/chain/channelmonitor.rs index a9ef3756..1a9afb7c 100644 --- a/lightning/src/chain/channelmonitor.rs +++ b/lightning/src/chain/channelmonitor.rs @@ -651,6 +651,40 @@ pub enum Balance { }, } +impl Balance { + /// The amount claimable, in satoshis. This excludes balances that we are unsure if we are able + /// to claim, this is because we are waiting for a preimage or for a timeout to expire. For more + /// information on these balances see [`Balance::MaybeTimeoutClaimableHTLC`] and + /// [`Balance::MaybePreimageClaimableHTLC`]. + /// + /// On-chain fees required to claim the balance are not included in this amount. + pub fn claimable_amount_satoshis(&self) -> u64 { + match self { + Balance::ClaimableOnChannelClose { + claimable_amount_satoshis, + } => *claimable_amount_satoshis, + Balance::ClaimableAwaitingConfirmations { + claimable_amount_satoshis, + .. + } => *claimable_amount_satoshis, + Balance::ContentiousClaimable { + claimable_amount_satoshis, + .. + } => *claimable_amount_satoshis, + Balance::MaybeTimeoutClaimableHTLC { + .. + } => 0, + Balance::MaybePreimageClaimableHTLC { + .. + } => 0, + Balance::CounterpartyRevokedOutputClaimable { + claimable_amount_satoshis, + .. + } => *claimable_amount_satoshis, + } + } +} + /// An HTLC which has been irrevocably resolved on-chain, and has reached ANTI_REORG_DELAY. #[derive(PartialEq, Eq)] struct IrrevocablyResolvedHTLC { @@ -2327,10 +2361,13 @@ impl ChannelMonitorImpl { where B::Target: BroadcasterInterface, L::Target: Logger, { - for tx in self.get_latest_holder_commitment_txn(logger).iter() { + let commit_txs = self.get_latest_holder_commitment_txn(logger); + let mut txs = vec![]; + for tx in commit_txs.iter() { log_info!(logger, "Broadcasting local {}", log_tx!(tx)); - broadcaster.broadcast_transaction(tx); + txs.push(tx); } + broadcaster.broadcast_transactions(&txs); self.pending_monitor_events.push(MonitorEvent::CommitmentTxConfirmed(self.funding_info.0)); } @@ -2502,7 +2539,7 @@ impl ChannelMonitorImpl { let mut ret = Vec::new(); mem::swap(&mut ret, &mut self.pending_events); #[cfg(anchors)] - for claim_event in self.onchain_tx_handler.get_and_clear_pending_claim_events().drain(..) { + for (claim_id, claim_event) in self.onchain_tx_handler.get_and_clear_pending_claim_events().drain(..) { match claim_event { ClaimEvent::BumpCommitment { package_target_feerate_sat_per_1000_weight, commitment_tx, anchor_output_idx, @@ -2513,6 +2550,7 @@ impl ChannelMonitorImpl { let commitment_tx_fee_satoshis = self.channel_value_satoshis - commitment_tx.output.iter().fold(0u64, |sum, output| sum + output.value); ret.push(Event::BumpTransaction(BumpTransactionEvent::ChannelClose { + claim_id, package_target_feerate_sat_per_1000_weight, commitment_tx, commitment_tx_fee_satoshis, @@ -2544,6 +2582,7 @@ impl ChannelMonitorImpl { }); } ret.push(Event::BumpTransaction(BumpTransactionEvent::HTLCResolution { + claim_id, target_feerate_sat_per_1000_weight, htlc_descriptors, tx_lock_time,