]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Cache csv_local inside OnchainTxHandler
authorAntoine Riard <ariard@student.42.fr>
Mon, 23 Mar 2020 05:36:37 +0000 (01:36 -0400)
committerAntoine Riard <ariard@student.42.fr>
Fri, 17 Apr 2020 21:43:50 +0000 (17:43 -0400)
csv_local is csv_delay encumbering local revokable_redeemscript
for to_local an htlc output on local commitment/HTLC transactions.

lightning/src/ln/channelmonitor.rs
lightning/src/ln/onchaintx.rs

index 4a89f5002e175a969a6435fc7aacdab3c368844a..0f6cc826e5df294cda33c4550d6336584fbceea9 100644 (file)
@@ -1145,7 +1145,7 @@ impl<ChanSigner: ChannelKeys> ChannelMonitor<ChanSigner> {
                        onchain_events_waiting_threshold_conf: HashMap::new(),
                        outputs_to_watch: HashMap::new(),
 
-                       onchain_tx_handler: OnchainTxHandler::new(destination_script.clone(), keys, funding_redeemscript, logger.clone()),
+                       onchain_tx_handler: OnchainTxHandler::new(destination_script.clone(), keys, funding_redeemscript, their_to_self_delay, logger.clone()),
 
                        last_block_hash: Default::default(),
                        secp_ctx: Secp256k1::new(),
index 406d9f38bd12b72e3eea04e07c0294ab38252854..fce935549024ae697e5e611bb730382ce8f5f83f 100644 (file)
@@ -157,6 +157,7 @@ pub struct OnchainTxHandler<ChanSigner: ChannelKeys> {
        prev_local_commitment: Option<LocalCommitmentTransaction>,
        current_htlc_cache: Option<HTLCTxCache>,
        prev_htlc_cache: Option<HTLCTxCache>,
+       local_csv: u16,
 
        key_storage: ChanSigner,
 
@@ -230,6 +231,7 @@ impl<ChanSigner: ChannelKeys + Writeable> OnchainTxHandler<ChanSigner> {
                } else {
                        writer.write_all(&[0; 1])?;
                }
+               self.local_csv.write(writer)?;
 
                self.key_storage.write(writer)?;
 
@@ -315,6 +317,7 @@ impl<ChanSigner: ChannelKeys + Readable> ReadableArgs<Arc<Logger>> for OnchainTx
                        }
                        _ => return Err(DecodeError::InvalidValue),
                };
+               let local_csv = Readable::read(reader)?;
 
                let key_storage = Readable::read(reader)?;
 
@@ -368,6 +371,7 @@ impl<ChanSigner: ChannelKeys + Readable> ReadableArgs<Arc<Logger>> for OnchainTx
                        prev_local_commitment,
                        current_htlc_cache,
                        prev_htlc_cache,
+                       local_csv,
                        key_storage,
                        claimable_outpoints,
                        pending_claim_requests,
@@ -379,7 +383,7 @@ impl<ChanSigner: ChannelKeys + Readable> ReadableArgs<Arc<Logger>> for OnchainTx
 }
 
 impl<ChanSigner: ChannelKeys> OnchainTxHandler<ChanSigner> {
-       pub(super) fn new(destination_script: Script, keys: ChanSigner, funding_redeemscript: Script, logger: Arc<Logger>) -> Self {
+       pub(super) fn new(destination_script: Script, keys: ChanSigner, funding_redeemscript: Script, local_csv: u16, logger: Arc<Logger>) -> Self {
 
                let key_storage = keys;
 
@@ -390,6 +394,7 @@ impl<ChanSigner: ChannelKeys> OnchainTxHandler<ChanSigner> {
                        prev_local_commitment: None,
                        current_htlc_cache: None,
                        prev_htlc_cache: None,
+                       local_csv,
                        key_storage,
                        pending_claim_requests: HashMap::new(),
                        claimable_outpoints: HashMap::new(),