]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Implement chain::Confirm for relevant structs
authorJeffrey Czyz <jkczyz@gmail.com>
Tue, 20 Apr 2021 20:39:00 +0000 (13:39 -0700)
committerJeffrey Czyz <jkczyz@gmail.com>
Thu, 22 Apr 2021 21:17:26 +0000 (14:17 -0700)
fuzz/src/chanmon_consistency.rs
fuzz/src/full_stack.rs
lightning/src/chain/chainmonitor.rs
lightning/src/chain/channelmonitor.rs
lightning/src/ln/channel.rs
lightning/src/ln/channelmanager.rs
lightning/src/ln/functional_test_utils.rs
lightning/src/ln/reorg_tests.rs

index 9d0a90ee1cdc0736ea6e3384348136eaef44c9a8..96da87b624e4e54d8950fde5ecb55b376be2d69d 100644 (file)
@@ -30,6 +30,7 @@ use bitcoin::hashes::sha256::Hash as Sha256;
 use bitcoin::hash_types::{BlockHash, WPubkeyHash};
 
 use lightning::chain;
+use lightning::chain::Confirm;
 use lightning::chain::chainmonitor;
 use lightning::chain::channelmonitor;
 use lightning::chain::channelmonitor::{ChannelMonitor, ChannelMonitorUpdateErr, MonitorEvent};
@@ -428,11 +429,11 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
                        let chain_hash = genesis_block(Network::Bitcoin).block_hash();
                        let mut header = BlockHeader { version: 0x20000000, prev_blockhash: chain_hash, merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 };
                        let txdata: Vec<_> = channel_txn.iter().enumerate().map(|(i, tx)| (i + 1, tx)).collect();
-                       $node.transactions_confirmed(&header, 1, &txdata);
+                       $node.transactions_confirmed(&header, &txdata, 1);
                        for _ in 2..100 {
                                header = BlockHeader { version: 0x20000000, prev_blockhash: header.block_hash(), merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 };
                        }
-                       $node.update_best_block(&header, 99);
+                       $node.best_block_updated(&header, 99);
                } }
        }
 
index 91ebb99018cca6cc5171c964394a32d5604a0bd1..dac57613ce03b5475aa9bd9d790a1715b737239a 100644 (file)
@@ -27,7 +27,7 @@ use bitcoin::hashes::sha256::Hash as Sha256;
 use bitcoin::hash_types::{Txid, BlockHash, WPubkeyHash};
 
 use lightning::chain;
-use lightning::chain::Listen;
+use lightning::chain::{Confirm, Listen};
 use lightning::chain::chaininterface::{BroadcasterInterface, ConfirmationTarget, FeeEstimator};
 use lightning::chain::chainmonitor;
 use lightning::chain::transaction::OutPoint;
@@ -207,8 +207,8 @@ impl<'a> MoneyLossDetector<'a> {
                self.blocks_connected += 1;
                let header = BlockHeader { version: 0x20000000, prev_blockhash: self.header_hashes[self.height].0, merkle_root: Default::default(), time: self.blocks_connected, bits: 42, nonce: 42 };
                self.height += 1;
-               self.manager.transactions_confirmed(&header, self.height as u32, &txdata);
-               self.manager.update_best_block(&header, self.height as u32);
+               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);
                if self.header_hashes.len() > self.height {
                        self.header_hashes[self.height] = (header.block_hash(), self.blocks_connected);
index ee6df63a1e07ee272fda9f2217526e15c3d7beca..aeab80a7ae55bc05e603d5f1ef165f2edcd83a35 100644 (file)
@@ -94,11 +94,11 @@ where C::Target: chain::Filter,
        /// [`ChannelMonitor::transactions_confirmed`].
        ///
        /// Used instead of [`block_connected`] by clients that are notified of transactions rather than
-       /// blocks. May be called before or after [`update_best_block`] for transactions in the
-       /// corresponding block. See [`update_best_block`] for further calling expectations.
+       /// blocks. May be called before or after [`best_block_updated`] for transactions in the
+       /// corresponding block. See [`best_block_updated`] for further calling expectations.
        ///
        /// [`block_connected`]: Self::block_connected
-       /// [`update_best_block`]: Self::update_best_block
+       /// [`best_block_updated`]: Self::best_block_updated
        pub fn transactions_confirmed(&self, header: &BlockHeader, txdata: &TransactionData, height: u32) {
                self.process_chain_data(header, txdata, |monitor, txdata| {
                        monitor.transactions_confirmed(
@@ -108,7 +108,7 @@ where C::Target: chain::Filter,
 
        /// Dispatches to per-channel monitors, which are responsible for updating their on-chain view
        /// of a channel and reacting accordingly based on the new chain tip. For details, see
-       /// [`ChannelMonitor::update_best_block`].
+       /// [`ChannelMonitor::best_block_updated`].
        ///
        /// Used instead of [`block_connected`] by clients that are notified of transactions rather than
        /// blocks. May be called before or after [`transactions_confirmed`] for the corresponding
@@ -122,12 +122,12 @@ where C::Target: chain::Filter,
        /// [`block_connected`]: Self::block_connected
        /// [`transactions_confirmed`]: Self::transactions_confirmed
        /// [`transaction_unconfirmed`]: Self::transaction_unconfirmed
-       pub fn update_best_block(&self, header: &BlockHeader, height: u32) {
+       pub fn best_block_updated(&self, header: &BlockHeader, height: u32) {
                self.process_chain_data(header, &[], |monitor, txdata| {
                        // While in practice there shouldn't be any recursive calls when given empty txdata,
                        // it's still possible if a chain::Filter implementation returns a transaction.
                        debug_assert!(txdata.is_empty());
-                       monitor.update_best_block(
+                       monitor.best_block_updated(
                                header, height, &*self.broadcaster, &*self.fee_estimator, &*self.logger)
                });
        }
@@ -187,11 +187,11 @@ where C::Target: chain::Filter,
        /// [`ChannelMonitor::transaction_unconfirmed`] for details.
        ///
        /// Used instead of [`block_disconnected`] by clients that are notified of transactions rather
-       /// than blocks. May be called before or after [`update_best_block`] for transactions in the
-       /// corresponding block. See [`update_best_block`] for further calling expectations. 
+       /// than blocks. May be called before or after [`best_block_updated`] for transactions in the
+       /// corresponding block. See [`best_block_updated`] for further calling expectations.
        ///
        /// [`block_disconnected`]: Self::block_disconnected
-       /// [`update_best_block`]: Self::update_best_block
+       /// [`best_block_updated`]: Self::best_block_updated
        pub fn transaction_unconfirmed(&self, txid: &Txid) {
                let monitors = self.monitors.read().unwrap();
                for monitor in monitors.values() {
index 777bc06bfb882745545c3db089c2f918a43c9b95..d6fd023b4de759396e8ae7e8fa127cee4c35f2dd 100644 (file)
@@ -1311,11 +1311,9 @@ impl<Signer: Sign> ChannelMonitor<Signer> {
        /// outputs to watch. See [`block_connected`] for details.
        ///
        /// Used instead of [`block_connected`] by clients that are notified of transactions rather than
-       /// blocks. May be called before or after [`update_best_block`] for transactions in the
-       /// corresponding block. See [`update_best_block`] for further calling expectations. 
+       /// blocks. See [`chain::Confirm`] for calling expectations.
        ///
        /// [`block_connected`]: Self::block_connected
-       /// [`update_best_block`]: Self::update_best_block
        pub fn transactions_confirmed<B: Deref, F: Deref, L: Deref>(
                &self,
                header: &BlockHeader,
@@ -1337,11 +1335,9 @@ impl<Signer: Sign> ChannelMonitor<Signer> {
        /// Processes a transaction that was reorganized out of the chain.
        ///
        /// Used instead of [`block_disconnected`] by clients that are notified of transactions rather
-       /// than blocks. May be called before or after [`update_best_block`] for transactions in the
-       /// corresponding block. See [`update_best_block`] for further calling expectations.
+       /// than blocks. See [`chain::Confirm`] for calling expectations.
        ///
        /// [`block_disconnected`]: Self::block_disconnected
-       /// [`update_best_block`]: Self::update_best_block
        pub fn transaction_unconfirmed<B: Deref, F: Deref, L: Deref>(
                &self,
                txid: &Txid,
@@ -1361,18 +1357,10 @@ impl<Signer: Sign> ChannelMonitor<Signer> {
        /// [`block_connected`] for details.
        ///
        /// Used instead of [`block_connected`] by clients that are notified of transactions rather than
-       /// blocks. May be called before or after [`transactions_confirmed`] for the corresponding
-       /// block.
-       ///
-       /// Must be called after new blocks become available for the most recent block. Intermediary
-       /// blocks, however, may be safely skipped. In the event of a chain re-organization, this only
-       /// needs to be called for the most recent block assuming `transaction_unconfirmed` is called
-       /// for any affected transactions.
+       /// blocks. See [`chain::Confirm`] for calling expectations.
        ///
        /// [`block_connected`]: Self::block_connected
-       /// [`transactions_confirmed`]: Self::transactions_confirmed
-       /// [`transaction_unconfirmed`]: Self::transaction_unconfirmed
-       pub fn update_best_block<B: Deref, F: Deref, L: Deref>(
+       pub fn best_block_updated<B: Deref, F: Deref, L: Deref>(
                &self,
                header: &BlockHeader,
                height: u32,
@@ -1385,7 +1373,7 @@ impl<Signer: Sign> ChannelMonitor<Signer> {
                F::Target: FeeEstimator,
                L::Target: Logger,
        {
-               self.inner.lock().unwrap().update_best_block(
+               self.inner.lock().unwrap().best_block_updated(
                        header, height, broadcaster, fee_estimator, logger)
        }
 
@@ -2109,7 +2097,7 @@ impl<Signer: Sign> ChannelMonitorImpl<Signer> {
                self.transactions_confirmed(header, txdata, height, broadcaster, fee_estimator, logger)
        }
 
-       fn update_best_block<B: Deref, F: Deref, L: Deref>(
+       fn best_block_updated<B: Deref, F: Deref, L: Deref>(
                &mut self,
                header: &BlockHeader,
                height: u32,
@@ -2727,6 +2715,29 @@ where
        }
 }
 
+impl<Signer: Sign, T: Deref, F: Deref, L: Deref> chain::Confirm for (ChannelMonitor<Signer>, T, F, L)
+where
+       T::Target: BroadcasterInterface,
+       F::Target: FeeEstimator,
+       L::Target: Logger,
+{
+       fn transactions_confirmed(&self, header: &BlockHeader, txdata: &TransactionData, height: u32) {
+               self.0.transactions_confirmed(header, txdata, height, &*self.1, &*self.2, &*self.3);
+       }
+
+       fn transaction_unconfirmed(&self, txid: &Txid) {
+               self.0.transaction_unconfirmed(txid, &*self.1, &*self.2, &*self.3);
+       }
+
+       fn best_block_updated(&self, header: &BlockHeader, height: u32) {
+               self.0.best_block_updated(header, height, &*self.1, &*self.2, &*self.3);
+       }
+
+       fn get_relevant_txids(&self) -> Vec<Txid> {
+               self.0.get_relevant_txids()
+       }
+}
+
 const MAX_ALLOC_SIZE: usize = 64*1024;
 
 impl<'a, Signer: Sign, K: KeysInterface<Signer = Signer>> ReadableArgs<&'a K>
index 5f987427979cbb9d267a73ea7f3fc0b0dd374378..512b6d96ab32782942b6a992331642d2e0f00344 100644 (file)
@@ -3600,7 +3600,7 @@ impl<Signer: Sign> Channel<Signer> {
                                                }
                                        }
                                        // If we allow 1-conf funding, we may need to check for funding_locked here and
-                                       // send it immediately instead of waiting for an update_best_block call (which
+                                       // send it immediately instead of waiting for a best_block_updated call (which
                                        // may have already happened for this block).
                                        if let Some(funding_locked) = self.check_get_funding_locked(height) {
                                                return Ok(Some(funding_locked));
@@ -3631,7 +3631,7 @@ impl<Signer: Sign> Channel<Signer> {
        ///
        /// May return some HTLCs (and their payment_hash) which have timed out and should be failed
        /// back.
-       pub fn update_best_block(&mut self, height: u32, highest_header_time: u32) -> Result<(Option<msgs::FundingLocked>, Vec<(HTLCSource, PaymentHash)>), msgs::ErrorMessage> {
+       pub fn best_block_updated(&mut self, height: u32, highest_header_time: u32) -> Result<(Option<msgs::FundingLocked>, Vec<(HTLCSource, PaymentHash)>), msgs::ErrorMessage> {
                let mut timed_out_htlcs = Vec::new();
                let unforwarded_htlc_cltv_limit = height + HTLC_FAIL_BACK_BUFFER;
                self.holding_cell_htlc_updates.retain(|htlc_update| {
@@ -3683,14 +3683,14 @@ impl<Signer: Sign> Channel<Signer> {
        /// before the channel has reached funding_locked and we can just wait for more blocks.
        pub fn funding_transaction_unconfirmed(&mut self) -> Result<(), msgs::ErrorMessage> {
                if self.funding_tx_confirmation_height != 0 {
-                       // We handle the funding disconnection by calling update_best_block with a height one
+                       // We handle the funding disconnection by calling best_block_updated with a height one
                        // below where our funding was connected, implying a reorg back to conf_height - 1.
                        let reorg_height = self.funding_tx_confirmation_height - 1;
                        // We use the time field to bump the current time we set on channel updates if its
                        // larger. If we don't know that time has moved forward, we can just set it to the last
                        // time we saw and it will be ignored.
                        let best_time = self.update_time_counter;
-                       match self.update_best_block(reorg_height, best_time) {
+                       match self.best_block_updated(reorg_height, best_time) {
                                Ok((funding_locked, timed_out_htlcs)) => {
                                        assert!(funding_locked.is_none(), "We can't generate a funding with 0 confirmations?");
                                        assert!(timed_out_htlcs.is_empty(), "We can't have accepted HTLCs with a timeout before our funding confirmation?");
index 39426b3fa7b2656b7667c29b94d94c50d6b4cc96..978171b1ba4f5bb68f600c543f6e5f6fc75ada73 100644 (file)
@@ -36,6 +36,7 @@ use bitcoin::secp256k1::ecdh::SharedSecret;
 use bitcoin::secp256k1;
 
 use chain;
+use chain::Confirm;
 use chain::Watch;
 use chain::chaininterface::{BroadcasterInterface, FeeEstimator};
 use chain::channelmonitor::{ChannelMonitor, ChannelMonitorUpdate, ChannelMonitorUpdateStep, ChannelMonitorUpdateErr, HTLC_FAIL_BACK_BUFFER, CLTV_CLAIM_BUFFER, LATENCY_GRACE_PERIOD_BLOCKS, ANTI_REORG_DELAY, MonitorEvent, CLOSED_CHANNEL_UPDATE_ID};
@@ -3363,8 +3364,8 @@ where
                }
 
                let txdata: Vec<_> = block.txdata.iter().enumerate().collect();
-               self.transactions_confirmed(&block.header, height, &txdata);
-               self.update_best_block(&block.header, height);
+               self.transactions_confirmed(&block.header, &txdata, height);
+               self.best_block_updated(&block.header, height);
        }
 
        fn block_disconnected(&self, header: &BlockHeader, height: u32) {
@@ -3379,16 +3380,88 @@ where
                        *best_block = BestBlock::new(header.prev_blockhash, new_height)
                }
 
-               self.do_chain_event(Some(new_height), |channel| channel.update_best_block(new_height, header.time));
+               self.do_chain_event(Some(new_height), |channel| channel.best_block_updated(new_height, header.time));
+       }
+}
+
+impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> chain::Confirm for ChannelManager<Signer, M, T, K, F, L>
+where
+       M::Target: chain::Watch<Signer>,
+       T::Target: BroadcasterInterface,
+       K::Target: KeysInterface<Signer = Signer>,
+       F::Target: FeeEstimator,
+       L::Target: Logger,
+{
+       fn transactions_confirmed(&self, header: &BlockHeader, txdata: &TransactionData, height: u32) {
+               // Note that we MUST NOT end up calling methods on self.chain_monitor here - we're called
+               // during initialization prior to the chain_monitor being fully configured in some cases.
+               // See the docs for `ChannelManagerReadArgs` for more.
+
+               let block_hash = header.block_hash();
+               log_trace!(self.logger, "{} transactions included in block {} at height {} provided", txdata.len(), block_hash, height);
+
+               let _persistence_guard = PersistenceNotifierGuard::new(&self.total_consistency_lock, &self.persistence_notifier);
+               self.do_chain_event(Some(height), |channel| channel.transactions_confirmed(&block_hash, height, txdata, &self.logger).map(|a| (a, Vec::new())));
+       }
+
+       fn best_block_updated(&self, header: &BlockHeader, height: u32) {
+               // Note that we MUST NOT end up calling methods on self.chain_monitor here - we're called
+               // during initialization prior to the chain_monitor being fully configured in some cases.
+               // See the docs for `ChannelManagerReadArgs` for more.
+
+               let block_hash = header.block_hash();
+               log_trace!(self.logger, "New best block: {} at height {}", block_hash, height);
+
+               let _persistence_guard = PersistenceNotifierGuard::new(&self.total_consistency_lock, &self.persistence_notifier);
+
+               *self.best_block.write().unwrap() = BestBlock::new(block_hash, height);
+
+               self.do_chain_event(Some(height), |channel| channel.best_block_updated(height, header.time));
+
+               loop {
+                       // Update last_node_announcement_serial to be the max of its current value and the
+                       // block timestamp. This should keep us close to the current time without relying on
+                       // having an explicit local time source.
+                       // Just in case we end up in a race, we loop until we either successfully update
+                       // last_node_announcement_serial or decide we don't need to.
+                       let old_serial = self.last_node_announcement_serial.load(Ordering::Acquire);
+                       if old_serial >= header.time as usize { break; }
+                       if self.last_node_announcement_serial.compare_exchange(old_serial, header.time as usize, Ordering::AcqRel, Ordering::Relaxed).is_ok() {
+                               break;
+                       }
+               }
+       }
+
+       fn get_relevant_txids(&self) -> Vec<Txid> {
+               let channel_state = self.channel_state.lock().unwrap();
+               let mut res = Vec::with_capacity(channel_state.short_to_id.len());
+               for chan in channel_state.by_id.values() {
+                       if let Some(funding_txo) = chan.get_funding_txo() {
+                               res.push(funding_txo.txid);
+                       }
+               }
+               res
+       }
+
+       fn transaction_unconfirmed(&self, txid: &Txid) {
+               let _persistence_guard = PersistenceNotifierGuard::new(&self.total_consistency_lock, &self.persistence_notifier);
+               self.do_chain_event(None, |channel| {
+                       if let Some(funding_txo) = channel.get_funding_txo() {
+                               if funding_txo.txid == *txid {
+                                       channel.funding_transaction_unconfirmed().map(|_| (None, Vec::new()))
+                               } else { Ok((None, Vec::new())) }
+                       } else { Ok((None, Vec::new())) }
+               });
        }
 }
 
 impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelManager<Signer, M, T, K, F, L>
-       where M::Target: chain::Watch<Signer>,
-        T::Target: BroadcasterInterface,
-        K::Target: KeysInterface<Signer = Signer>,
-        F::Target: FeeEstimator,
-        L::Target: Logger,
+where
+       M::Target: chain::Watch<Signer>,
+       T::Target: BroadcasterInterface,
+       K::Target: KeysInterface<Signer = Signer>,
+       F::Target: FeeEstimator,
+       L::Target: Logger,
 {
        /// Calls a function which handles an on-chain event (blocks dis/connected, transactions
        /// un/confirmed, etc) on each channel, handling any resulting errors or messages generated by
@@ -3482,131 +3555,6 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
                }
        }
 
-       /// Updates channel state to take note of transactions which were confirmed in the given block
-       /// at the given height.
-       ///
-       /// Note that you must still call (or have called) [`update_best_block`] with the block
-       /// information which is included here.
-       ///
-       /// This method may be called before or after [`update_best_block`] for a given block's
-       /// transaction data and may be called multiple times with additional transaction data for a
-       /// given block.
-       ///
-       /// This method may be called for a previous block after an [`update_best_block`] call has
-       /// been made for a later block, however it must *not* be called with transaction data from a
-       /// block which is no longer in the best chain (ie where [`update_best_block`] has already
-       /// been informed about a blockchain reorganization which no longer includes the block which
-       /// corresponds to `header`).
-       ///
-       /// [`update_best_block`]: `Self::update_best_block`
-       pub fn transactions_confirmed(&self, header: &BlockHeader, height: u32, txdata: &TransactionData) {
-               // Note that we MUST NOT end up calling methods on self.chain_monitor here - we're called
-               // during initialization prior to the chain_monitor being fully configured in some cases.
-               // See the docs for `ChannelManagerReadArgs` for more.
-
-               let block_hash = header.block_hash();
-               log_trace!(self.logger, "{} transactions included in block {} at height {} provided", txdata.len(), block_hash, height);
-
-               let _persistence_guard = PersistenceNotifierGuard::new(&self.total_consistency_lock, &self.persistence_notifier);
-               self.do_chain_event(Some(height), |channel| channel.transactions_confirmed(&block_hash, height, txdata, &self.logger).map(|a| (a, Vec::new())));
-       }
-
-       /// Updates channel state with the current best blockchain tip. You should attempt to call this
-       /// quickly after a new block becomes available, however if multiple new blocks become
-       /// available at the same time, only a single `update_best_block()` call needs to be made.
-       ///
-       /// This method should also be called immediately after any block disconnections, once at the
-       /// reorganization fork point, and once with the new chain tip. Calling this method at the
-       /// blockchain reorganization fork point ensures we learn when a funding transaction which was
-       /// previously confirmed is reorganized out of the blockchain, ensuring we do not continue to
-       /// accept payments which cannot be enforced on-chain.
-       ///
-       /// In both the block-connection and block-disconnection case, this method may be called either
-       /// once per block connected or disconnected, or simply at the fork point and new tip(s),
-       /// skipping any intermediary blocks.
-       pub fn update_best_block(&self, header: &BlockHeader, height: u32) {
-               // Note that we MUST NOT end up calling methods on self.chain_monitor here - we're called
-               // during initialization prior to the chain_monitor being fully configured in some cases.
-               // See the docs for `ChannelManagerReadArgs` for more.
-
-               let block_hash = header.block_hash();
-               log_trace!(self.logger, "New best block: {} at height {}", block_hash, height);
-
-               let _persistence_guard = PersistenceNotifierGuard::new(&self.total_consistency_lock, &self.persistence_notifier);
-
-               *self.best_block.write().unwrap() = BestBlock::new(block_hash, height);
-
-               self.do_chain_event(Some(height), |channel| channel.update_best_block(height, header.time));
-
-               loop {
-                       // Update last_node_announcement_serial to be the max of its current value and the
-                       // block timestamp. This should keep us close to the current time without relying on
-                       // having an explicit local time source.
-                       // Just in case we end up in a race, we loop until we either successfully update
-                       // last_node_announcement_serial or decide we don't need to.
-                       let old_serial = self.last_node_announcement_serial.load(Ordering::Acquire);
-                       if old_serial >= header.time as usize { break; }
-                       if self.last_node_announcement_serial.compare_exchange(old_serial, header.time as usize, Ordering::AcqRel, Ordering::Relaxed).is_ok() {
-                               break;
-                       }
-               }
-       }
-
-       /// Gets the set of txids which should be monitored for their confirmation state.
-       ///
-       /// If you're providing information about reorganizations via [`transaction_unconfirmed`], this
-       /// is the set of transactions which you may need to call [`transaction_unconfirmed`] for.
-       ///
-       /// This may be useful to poll to determine the set of transactions which must be registered
-       /// with an Electrum server or for which an Electrum server needs to be polled to determine
-       /// transaction confirmation state.
-       ///
-       /// This may update after any [`transactions_confirmed`] or [`block_connected`] call.
-       ///
-       /// Note that this is NOT the set of transactions which must be included in calls to
-       /// [`transactions_confirmed`] if they are confirmed, but a small subset of it.
-       ///
-       /// [`transactions_confirmed`]: Self::transactions_confirmed
-       /// [`transaction_unconfirmed`]: Self::transaction_unconfirmed
-       /// [`block_connected`]: chain::Listen::block_connected
-       pub fn get_relevant_txids(&self) -> Vec<Txid> {
-               let channel_state = self.channel_state.lock().unwrap();
-               let mut res = Vec::with_capacity(channel_state.short_to_id.len());
-               for chan in channel_state.by_id.values() {
-                       if let Some(funding_txo) = chan.get_funding_txo() {
-                               res.push(funding_txo.txid);
-                       }
-               }
-               res
-       }
-
-       /// Marks a transaction as having been reorganized out of the blockchain.
-       ///
-       /// If a transaction is included in [`get_relevant_txids`], and is no longer in the main branch
-       /// of the blockchain, this function should be called to indicate that the transaction should
-       /// be considered reorganized out.
-       ///
-       /// Once this is called, the given transaction will no longer appear on [`get_relevant_txids`],
-       /// though this may be called repeatedly for a given transaction without issue.
-       ///
-       /// Note that if the transaction is confirmed on the main chain in a different block (indicated
-       /// via a call to [`transactions_confirmed`]), it may re-appear in [`get_relevant_txids`], thus
-       /// be very wary of race-conditions wherein the final state of a transaction indicated via
-       /// these APIs is not the same as its state on the blockchain.
-       ///
-       /// [`transactions_confirmed`]: Self::transactions_confirmed
-       /// [`get_relevant_txids`]: Self::get_relevant_txids
-       pub fn transaction_unconfirmed(&self, txid: &Txid) {
-               let _persistence_guard = PersistenceNotifierGuard::new(&self.total_consistency_lock, &self.persistence_notifier);
-               self.do_chain_event(None, |channel| {
-                       if let Some(funding_txo) = channel.get_funding_txo() {
-                               if funding_txo.txid == *txid {
-                                       channel.funding_transaction_unconfirmed().map(|_| (None, Vec::new()))
-                               } else { Ok((None, Vec::new())) }
-                       } else { Ok((None, Vec::new())) }
-               });
-       }
-
        /// Blocks until ChannelManager needs to be persisted or a timeout is reached. It returns a bool
        /// indicating whether persistence is necessary. Only one listener on
        /// `await_persistable_update` or `await_persistable_update_timeout` is guaranteed to be woken
index dee3c6ea3957b4ccf5b84c907df6bb2888bee40e..53d0ad8561fc695ff66783be0b9b3ed998a412e4 100644 (file)
@@ -10,7 +10,7 @@
 //! A bunch of useful utilities for building networks of nodes and exchanging messages between
 //! nodes for functional tests.
 
-use chain::{Listen, Watch};
+use chain::{Confirm, Listen, Watch};
 use chain::channelmonitor::ChannelMonitor;
 use chain::transaction::OutPoint;
 use ln::channelmanager::{BestBlock, ChainParameters, ChannelManager, ChannelManagerReadArgs, RAACommitmentOrder, PaymentPreimage, PaymentHash, PaymentSecret, PaymentSendFailure};
@@ -79,17 +79,17 @@ pub fn confirm_transaction_at<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, tx: &T
 /// The possible ways we may notify a ChannelManager of a new block
 #[derive(Clone, Copy, PartialEq)]
 pub enum ConnectStyle {
-       /// Calls update_best_block first, detecting transactions in the block only after receiving the
+       /// Calls best_block_updated first, detecting transactions in the block only after receiving the
        /// header and height information.
        BestBlockFirst,
        /// The same as BestBlockFirst, however when we have multiple blocks to connect, we only
-       /// make a single update_best_block call.
+       /// make a single best_block_updated call.
        BestBlockFirstSkippingBlocks,
        /// Calls transactions_confirmed first, detecting transactions in the block before updating the
        /// header and height information.
        TransactionsFirst,
        /// The same as TransactionsFirst, however when we have multiple blocks to connect, we only
-       /// make a single update_best_block call.
+       /// make a single best_block_updated call.
        TransactionsFirstSkippingBlocks,
        /// Provides the full block via the chain::Listen interface. In the current code this is
        /// equivalent to TransactionsFirst with some additional assertions.
@@ -128,16 +128,16 @@ fn do_connect_block<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, block: &Block, s
                let txdata: Vec<_> = block.txdata.iter().enumerate().collect();
                match *node.connect_style.borrow() {
                        ConnectStyle::BestBlockFirst|ConnectStyle::BestBlockFirstSkippingBlocks => {
-                               node.chain_monitor.chain_monitor.update_best_block(&block.header, height);
+                               node.chain_monitor.chain_monitor.best_block_updated(&block.header, height);
                                node.chain_monitor.chain_monitor.transactions_confirmed(&block.header, &txdata, height);
-                               node.node.update_best_block(&block.header, height);
-                               node.node.transactions_confirmed(&block.header, height, &txdata);
+                               node.node.best_block_updated(&block.header, height);
+                               node.node.transactions_confirmed(&block.header, &txdata, height);
                        },
                        ConnectStyle::TransactionsFirst|ConnectStyle::TransactionsFirstSkippingBlocks => {
                                node.chain_monitor.chain_monitor.transactions_confirmed(&block.header, &txdata, height);
-                               node.chain_monitor.chain_monitor.update_best_block(&block.header, height);
-                               node.node.transactions_confirmed(&block.header, height, &txdata);
-                               node.node.update_best_block(&block.header, height);
+                               node.chain_monitor.chain_monitor.best_block_updated(&block.header, height);
+                               node.node.transactions_confirmed(&block.header, &txdata, height);
+                               node.node.best_block_updated(&block.header, height);
                        },
                        ConnectStyle::FullBlockViaListen => {
                                node.chain_monitor.chain_monitor.block_connected(&block.header, &txdata, height);
@@ -162,13 +162,13 @@ pub fn disconnect_blocks<'a, 'b, 'c, 'd>(node: &'a Node<'b, 'c, 'd>, count: u32)
                        },
                        ConnectStyle::BestBlockFirstSkippingBlocks|ConnectStyle::TransactionsFirstSkippingBlocks => {
                                if i == count - 1 {
-                                       node.chain_monitor.chain_monitor.update_best_block(&prev_header.0, prev_header.1);
-                                       node.node.update_best_block(&prev_header.0, prev_header.1);
+                                       node.chain_monitor.chain_monitor.best_block_updated(&prev_header.0, prev_header.1);
+                                       node.node.best_block_updated(&prev_header.0, prev_header.1);
                                }
                        },
                        _ => {
-                               node.chain_monitor.chain_monitor.update_best_block(&prev_header.0, prev_header.1);
-                               node.node.update_best_block(&prev_header.0, prev_header.1);
+                               node.chain_monitor.chain_monitor.best_block_updated(&prev_header.0, prev_header.1);
+                               node.node.best_block_updated(&prev_header.0, prev_header.1);
                        },
                }
        }
index d5a3d042f297846d3d4af516a878b8985f48427d..05001d69e0c72a5c1765b5fec23bffe6344cf132 100644 (file)
@@ -10,7 +10,7 @@
 //! Further functional tests which test blockchain reorganizations.
 
 use chain::channelmonitor::{ANTI_REORG_DELAY, ChannelMonitor};
-use chain::Watch;
+use chain::{Confirm, Watch};
 use ln::channelmanager::{ChannelManager, ChannelManagerReadArgs};
 use ln::features::InitFeatures;
 use ln::msgs::{ChannelMessageHandler, ErrorAction, HTLCFailChannelUpdate};