From: Antoine Riard Date: Sat, 21 Mar 2020 00:06:13 +0000 (-0400) Subject: Cache funding_redeemscript in OnchainTxHandler X-Git-Tag: v0.0.12~84^2~16 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=04a17b2a152396384b108e8ef284c85bd9f0b50b;p=rust-lightning Cache funding_redeemscript in OnchainTxHandler As transaction generation and signature is headed to be moved inside OnchainTxHandler, cache any usefule witness element. --- diff --git a/lightning/src/ln/channelmonitor.rs b/lightning/src/ln/channelmonitor.rs index 8b116b9d6..6855ac15a 100644 --- a/lightning/src/ln/channelmonitor.rs +++ b/lightning/src/ln/channelmonitor.rs @@ -1098,7 +1098,7 @@ impl ChannelMonitor { onchain_detection: onchain_detection, their_htlc_base_key: Some(their_htlc_base_key.clone()), their_delayed_payment_base_key: Some(their_delayed_payment_base_key.clone()), - funding_redeemscript: Some(funding_redeemscript), + funding_redeemscript: Some(funding_redeemscript.clone()), channel_value_satoshis: Some(channel_value_satoshis), their_cur_revocation_points: None, @@ -1121,7 +1121,7 @@ impl ChannelMonitor { onchain_events_waiting_threshold_conf: HashMap::new(), outputs_to_watch: HashMap::new(), - onchain_tx_handler: OnchainTxHandler::new(destination_script.clone(), keys, logger.clone()), + onchain_tx_handler: OnchainTxHandler::new(destination_script.clone(), keys, funding_redeemscript, logger.clone()), last_block_hash: Default::default(), secp_ctx: Secp256k1::new(), diff --git a/lightning/src/ln/onchaintx.rs b/lightning/src/ln/onchaintx.rs index 40d9f18ab..d5db6950f 100644 --- a/lightning/src/ln/onchaintx.rs +++ b/lightning/src/ln/onchaintx.rs @@ -141,6 +141,7 @@ macro_rules! subtract_high_prio_fee { /// do RBF bumping if possible. pub struct OnchainTxHandler { destination_script: Script, + funding_redeemscript: Script, key_storage: ChanSigner, @@ -180,6 +181,7 @@ pub struct OnchainTxHandler { 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.key_storage.write(writer)?; @@ -221,6 +223,7 @@ impl OnchainTxHandler { impl ReadableArgs> for OnchainTxHandler { fn read(reader: &mut R, logger: Arc) -> Result { let destination_script = Readable::read(reader)?; + let funding_redeemscript = Readable::read(reader)?; let key_storage = Readable::read(reader)?; @@ -269,6 +272,7 @@ impl ReadableArgs> for OnchainTx Ok(OnchainTxHandler { destination_script, + funding_redeemscript, key_storage, claimable_outpoints, pending_claim_requests, @@ -280,12 +284,13 @@ impl ReadableArgs> for OnchainTx } impl OnchainTxHandler { - pub(super) fn new(destination_script: Script, keys: ChanSigner, logger: Arc) -> Self { + pub(super) fn new(destination_script: Script, keys: ChanSigner, funding_redeemscript: Script, logger: Arc) -> Self { let key_storage = keys; OnchainTxHandler { destination_script, + funding_redeemscript, key_storage, pending_claim_requests: HashMap::new(), claimable_outpoints: HashMap::new(),