From: Antoine Riard Date: Sat, 21 Mar 2020 00:26:23 +0000 (-0400) Subject: Cache local_commitment_tx in OnchainTxHandler X-Git-Tag: v0.0.12~84^2~15 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=73e0a0112adae5086ae6617fec2131f362086797;p=rust-lightning Cache local_commitment_tx in OnchainTxHandler As transaction generation and signature is headed to be moved inside OnchainTxHandler, cache local_commitment_tx signed by remote. If access to local commitment transaction is needed, we extend Onchain TxHandler API to do so. --- diff --git a/lightning/src/ln/channelmonitor.rs b/lightning/src/ln/channelmonitor.rs index 6855ac15a..70c92143a 100644 --- a/lightning/src/ln/channelmonitor.rs +++ b/lightning/src/ln/channelmonitor.rs @@ -1244,7 +1244,7 @@ impl ChannelMonitor { self.prev_local_signed_commitment_tx = self.current_local_signed_commitment_tx.take(); self.current_local_signed_commitment_tx = Some(LocalSignedTx { txid: commitment_tx.txid(), - tx: commitment_tx, + tx: commitment_tx.clone(), revocation_key: local_keys.revocation_key, a_htlc_key: local_keys.a_htlc_key, b_htlc_key: local_keys.b_htlc_key, @@ -1253,6 +1253,7 @@ impl ChannelMonitor { feerate_per_kw, htlc_outputs, }); + self.onchain_tx_handler.provide_latest_local_tx(commitment_tx); Ok(()) } diff --git a/lightning/src/ln/onchaintx.rs b/lightning/src/ln/onchaintx.rs index d5db6950f..4c935ea65 100644 --- a/lightning/src/ln/onchaintx.rs +++ b/lightning/src/ln/onchaintx.rs @@ -15,7 +15,7 @@ use secp256k1; use ln::msgs::DecodeError; use ln::channelmonitor::{ANTI_REORG_DELAY, CLTV_SHARED_CLAIM_BUFFER, InputMaterial, ClaimRequest}; -use ln::chan_utils::HTLCType; +use ln::chan_utils::{HTLCType, LocalCommitmentTransaction}; use chain::chaininterface::{FeeEstimator, BroadcasterInterface, ConfirmationTarget, MIN_RELAY_FEE_SAT_PER_1000_WEIGHT}; use chain::keysinterface::ChannelKeys; use util::logger::Logger; @@ -142,6 +142,8 @@ macro_rules! subtract_high_prio_fee { pub struct OnchainTxHandler { destination_script: Script, funding_redeemscript: Script, + local_commitment: Option, + prev_local_commitment: Option, key_storage: ChanSigner, @@ -182,6 +184,8 @@ impl OnchainTxHandler { pub(crate) fn write(&self, writer: &mut W) -> Result<(), ::std::io::Error> { self.destination_script.write(writer)?; self.funding_redeemscript.write(writer)?; + self.local_commitment.write(writer)?; + self.prev_local_commitment.write(writer)?; self.key_storage.write(writer)?; @@ -224,6 +228,8 @@ impl ReadableArgs> for OnchainTx fn read(reader: &mut R, logger: Arc) -> Result { let destination_script = Readable::read(reader)?; let funding_redeemscript = Readable::read(reader)?; + let local_commitment = Readable::read(reader)?; + let prev_local_commitment = Readable::read(reader)?; let key_storage = Readable::read(reader)?; @@ -273,6 +279,8 @@ impl ReadableArgs> for OnchainTx Ok(OnchainTxHandler { destination_script, funding_redeemscript, + local_commitment, + prev_local_commitment, key_storage, claimable_outpoints, pending_claim_requests, @@ -291,6 +299,8 @@ impl OnchainTxHandler { OnchainTxHandler { destination_script, funding_redeemscript, + local_commitment: None, + prev_local_commitment: None, key_storage, pending_claim_requests: HashMap::new(), claimable_outpoints: HashMap::new(), @@ -714,4 +724,9 @@ impl OnchainTxHandler { self.pending_claim_requests.remove(&req); } } + + pub(super) fn provide_latest_local_tx(&mut self, tx: LocalCommitmentTransaction) { + self.prev_local_commitment = self.local_commitment.take(); + self.local_commitment = Some(tx); + } }