]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Drop pub functions for ChainMonitor's Listen impl
authorJeffrey Czyz <jkczyz@gmail.com>
Thu, 22 Apr 2021 16:52:10 +0000 (09:52 -0700)
committerJeffrey Czyz <jkczyz@gmail.com>
Thu, 22 Apr 2021 21:17:26 +0000 (14:17 -0700)
fuzz/src/full_stack.rs
lightning/src/chain/chainmonitor.rs
lightning/src/ln/chanmon_update_fail_tests.rs
lightning/src/ln/functional_test_utils.rs
lightning/src/ln/functional_tests.rs

index dac57613ce03b5475aa9bd9d790a1715b737239a..73a9a67a74ef8ed5b774abd20905635e531ea73e 100644 (file)
@@ -209,7 +209,8 @@ impl<'a> MoneyLossDetector<'a> {
                self.height += 1;
                self.manager.transactions_confirmed(&header, &txdata, self.height as u32);
                self.manager.best_block_updated(&header, self.height as u32);
-               (*self.monitor).block_connected(&header, &txdata, self.height as u32);
+               (*self.monitor).transactions_confirmed(&header, &txdata, self.height as u32);
+               (*self.monitor).best_block_updated(&header, self.height as u32);
                if self.header_hashes.len() > self.height {
                        self.header_hashes[self.height] = (header.block_hash(), self.blocks_connected);
                } else {
index 8c2e761fa46dad5445dece213b4fc38e85f01475..95a786f696dbc29174324f540590166c36d09553 100644 (file)
@@ -74,7 +74,7 @@ where C::Target: chain::Filter,
            P::Target: channelmonitor::Persist<ChannelSigner>,
 {
        /// Dispatches to per-channel monitors, which are responsible for updating their on-chain view
-       /// of a channel and reacting accordingly based on transactions in the connected block. See
+       /// of a channel and reacting accordingly based on transactions in the given chain data. See
        /// [`ChannelMonitor::block_connected`] for details. Any HTLCs that were resolved on chain will
        /// be returned by [`chain::Watch::release_pending_monitor_events`].
        ///
@@ -82,13 +82,6 @@ where C::Target: chain::Filter,
        /// calls must not exclude any transactions matching the new outputs nor any in-block
        /// descendants of such transactions. It is not necessary to re-fetch the block to obtain
        /// updated `txdata`.
-       pub fn block_connected(&self, header: &BlockHeader, txdata: &TransactionData, height: u32) {
-               self.process_chain_data(header, txdata, |monitor, txdata| {
-                       monitor.block_connected(
-                               header, txdata, height, &*self.broadcaster, &*self.fee_estimator, &*self.logger)
-               });
-       }
-
        fn process_chain_data<FN>(&self, header: &BlockHeader, txdata: &TransactionData, process: FN)
        where
                FN: Fn(&ChannelMonitor<ChannelSigner>, &TransactionData) -> Vec<TransactionOutputs>
@@ -129,16 +122,6 @@ where C::Target: chain::Filter,
                }
        }
 
-       /// Dispatches to per-channel monitors, which are responsible for updating their on-chain view
-       /// of a channel based on the disconnected block. See [`ChannelMonitor::block_disconnected`] for
-       /// details.
-       pub fn block_disconnected(&self, header: &BlockHeader, disconnected_height: u32) {
-               let monitors = self.monitors.read().unwrap();
-               for monitor in monitors.values() {
-                       monitor.block_disconnected(header, disconnected_height, &*self.broadcaster, &*self.fee_estimator, &*self.logger);
-               }
-       }
-
        /// Creates a new `ChainMonitor` used to watch on-chain activity pertaining to channels.
        ///
        /// When an optional chain source implementing [`chain::Filter`] is provided, the chain monitor
@@ -158,7 +141,7 @@ where C::Target: chain::Filter,
        }
 }
 
-impl<ChannelSigner: Sign, C: Deref + Send + Sync, T: Deref + Send + Sync, F: Deref + Send + Sync, L: Deref + Send + Sync, P: Deref + Send + Sync>
+impl<ChannelSigner: Sign, C: Deref, T: Deref, F: Deref, L: Deref, P: Deref>
 chain::Listen for ChainMonitor<ChannelSigner, C, T, F, L, P>
 where
        ChannelSigner: Sign,
@@ -169,12 +152,20 @@ where
        P::Target: channelmonitor::Persist<ChannelSigner>,
 {
        fn block_connected(&self, block: &Block, height: u32) {
+               let header = &block.header;
                let txdata: Vec<_> = block.txdata.iter().enumerate().collect();
-               ChainMonitor::block_connected(self, &block.header, &txdata, height);
+               self.process_chain_data(header, &txdata, |monitor, txdata| {
+                       monitor.block_connected(
+                               header, txdata, height, &*self.broadcaster, &*self.fee_estimator, &*self.logger)
+               });
        }
 
        fn block_disconnected(&self, header: &BlockHeader, height: u32) {
-               ChainMonitor::block_disconnected(self, header, height);
+               let monitors = self.monitors.read().unwrap();
+               for monitor in monitors.values() {
+                       monitor.block_disconnected(
+                               header, height, &*self.broadcaster, &*self.fee_estimator, &*self.logger);
+               }
        }
 }
 
index a7cc5377a2532a14644619e623a64ed6a0278ad1..ee9936b3329222a9974a93014849ad38be82bd3b 100644 (file)
 //! There are a bunch of these as their handling is relatively error-prone so they are split out
 //! here. See also the chanmon_fail_consistency fuzz test.
 
-use bitcoin::blockdata::block::BlockHeader;
+use bitcoin::blockdata::block::{Block, BlockHeader};
 use bitcoin::hash_types::BlockHash;
 use bitcoin::network::constants::Network;
 use chain::channelmonitor::{ChannelMonitor, ChannelMonitorUpdateErr};
 use chain::transaction::OutPoint;
+use chain::Listen;
 use chain::Watch;
 use ln::channelmanager::{RAACommitmentOrder, PaymentPreimage, PaymentHash, PaymentSecret, PaymentSendFailure};
 use ln::features::InitFeatures;
@@ -114,7 +115,7 @@ fn test_monitor_and_persister_update_fail() {
                chain_mon
        };
        let header = BlockHeader { version: 0x20000000, prev_blockhash: Default::default(), merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 };
-       chain_mon.chain_monitor.block_connected(&header, &[], 200);
+       chain_mon.chain_monitor.block_connected(&Block { header, txdata: vec![] }, 200);
 
        // Set the persister's return value to be a TemporaryFailure.
        persister.set_update_ret(Err(ChannelMonitorUpdateErr::TemporaryFailure));
index 53d0ad8561fc695ff66783be0b9b3ed998a412e4..dce4e6289b9536352270bcbbe9eb33268192571a 100644 (file)
@@ -140,8 +140,8 @@ fn do_connect_block<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, block: &Block, s
                                node.node.best_block_updated(&block.header, height);
                        },
                        ConnectStyle::FullBlockViaListen => {
-                               node.chain_monitor.chain_monitor.block_connected(&block.header, &txdata, height);
-                               Listen::block_connected(node.node, &block, height);
+                               node.chain_monitor.chain_monitor.block_connected(&block, height);
+                               node.node.block_connected(&block, height);
                        }
                }
        }
index 9a0c06e776cf4db266050b7986d08dc7fab67d2b..731bf7c1b0e213133072b10b5afc8bd11daf23aa 100644 (file)
@@ -12,6 +12,7 @@
 //! claim outputs on-chain.
 
 use chain;
+use chain::Listen;
 use chain::Watch;
 use chain::channelmonitor;
 use chain::channelmonitor::{ChannelMonitor, CLTV_CLAIM_BUFFER, LATENCY_GRACE_PERIOD_BLOCKS, ANTI_REORG_DELAY};
@@ -8225,7 +8226,7 @@ fn test_update_err_monitor_lockdown() {
                watchtower
        };
        let header = BlockHeader { version: 0x20000000, prev_blockhash: Default::default(), merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 };
-       watchtower.chain_monitor.block_connected(&header, &[], 200);
+       watchtower.chain_monitor.block_connected(&Block { header, txdata: vec![] }, 200);
 
        // Try to update ChannelMonitor
        assert!(nodes[1].node.claim_funds(preimage, &None, 9_000_000));
@@ -8284,7 +8285,7 @@ fn test_concurrent_monitor_claim() {
                watchtower
        };
        let header = BlockHeader { version: 0x20000000, prev_blockhash: Default::default(), merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 };
-       watchtower_alice.chain_monitor.block_connected(&header, &vec![], CHAN_CONFIRM_DEPTH + 1 + TEST_FINAL_CLTV + LATENCY_GRACE_PERIOD_BLOCKS);
+       watchtower_alice.chain_monitor.block_connected(&Block { header, txdata: vec![] }, CHAN_CONFIRM_DEPTH + 1 + TEST_FINAL_CLTV + LATENCY_GRACE_PERIOD_BLOCKS);
 
        // Watchtower Alice should have broadcast a commitment/HTLC-timeout
        {
@@ -8310,7 +8311,7 @@ fn test_concurrent_monitor_claim() {
                watchtower
        };
        let header = BlockHeader { version: 0x20000000, prev_blockhash: Default::default(), merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 };
-       watchtower_bob.chain_monitor.block_connected(&header, &vec![], CHAN_CONFIRM_DEPTH + TEST_FINAL_CLTV + LATENCY_GRACE_PERIOD_BLOCKS);
+       watchtower_bob.chain_monitor.block_connected(&Block { header, txdata: vec![] }, CHAN_CONFIRM_DEPTH + TEST_FINAL_CLTV + LATENCY_GRACE_PERIOD_BLOCKS);
 
        // Route another payment to generate another update with still previous HTLC pending
        let (_, payment_hash) = get_payment_preimage_hash!(nodes[0]);
@@ -8336,7 +8337,8 @@ fn test_concurrent_monitor_claim() {
        check_added_monitors!(nodes[0], 1);
 
        //// Provide one more block to watchtower Bob, expect broadcast of commitment and HTLC-Timeout
-       watchtower_bob.chain_monitor.block_connected(&header, &vec![], CHAN_CONFIRM_DEPTH + 1 + TEST_FINAL_CLTV + LATENCY_GRACE_PERIOD_BLOCKS);
+       let header = BlockHeader { version: 0x20000000, prev_blockhash: Default::default(), merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 };
+       watchtower_bob.chain_monitor.block_connected(&Block { header, txdata: vec![] }, CHAN_CONFIRM_DEPTH + 1 + TEST_FINAL_CLTV + LATENCY_GRACE_PERIOD_BLOCKS);
 
        // Watchtower Bob should have broadcast a commitment/HTLC-timeout
        let bob_state_y;
@@ -8348,7 +8350,8 @@ fn test_concurrent_monitor_claim() {
        };
 
        // We confirm Bob's state Y on Alice, she should broadcast a HTLC-timeout
-       watchtower_alice.chain_monitor.block_connected(&header, &vec![(0, &bob_state_y)], CHAN_CONFIRM_DEPTH + 2 + TEST_FINAL_CLTV + LATENCY_GRACE_PERIOD_BLOCKS);
+       let header = BlockHeader { version: 0x20000000, prev_blockhash: Default::default(), merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 };
+       watchtower_alice.chain_monitor.block_connected(&Block { header, txdata: vec![bob_state_y.clone()] }, CHAN_CONFIRM_DEPTH + 2 + TEST_FINAL_CLTV + LATENCY_GRACE_PERIOD_BLOCKS);
        {
                let htlc_txn = chanmon_cfgs[0].tx_broadcaster.txn_broadcasted.lock().unwrap();
                // We broadcast twice the transaction, once due to the HTLC-timeout, once due