From 90b545ffe3e6855e09156361ecb1d5384add1e46 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Fri, 7 Sep 2018 11:12:22 -0400 Subject: [PATCH] Narrow ChainWatchInterface::install_watch_script --- fuzz/fuzz_targets/router_target.rs | 2 +- src/chain/chaininterface.rs | 12 ++++++------ src/ln/channelmonitor.rs | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/fuzz/fuzz_targets/router_target.rs b/fuzz/fuzz_targets/router_target.rs index d87559562..6476f812f 100644 --- a/fuzz/fuzz_targets/router_target.rs +++ b/fuzz/fuzz_targets/router_target.rs @@ -76,7 +76,7 @@ struct DummyChainWatcher { } impl ChainWatchInterface for DummyChainWatcher { - fn install_watch_script(&self, _script_pub_key: &Script) { } + fn install_watch_tx(&self, _txid: &Sha256dHash, _script_pub_key: &Script) { } fn install_watch_outpoint(&self, _outpoint: (Sha256dHash, u32), _out_script: &Script) { } fn watch_all_txn(&self) { } fn register_listener(&self, _listener: Weak) { } diff --git a/src/chain/chaininterface.rs b/src/chain/chaininterface.rs index 78a40099c..3a0b2d735 100644 --- a/src/chain/chaininterface.rs +++ b/src/chain/chaininterface.rs @@ -25,8 +25,8 @@ pub enum ChainError { /// called from inside the library in response to ChainListener events, P2P events, or timer /// events). pub trait ChainWatchInterface: Sync + Send { - /// Provides a scriptPubKey which much be watched for. - fn install_watch_script(&self, script_pub_key: &Script); + /// Provides a txid/random-scriptPubKey-in-the-tx which much be watched for. + fn install_watch_tx(&self, txid: &Sha256dHash, script_pub_key: &Script); /// Provides an outpoint which must be watched for, providing any transactions which spend the /// given outpoint. @@ -54,9 +54,9 @@ pub trait BroadcasterInterface: Sync + Send { /// A trait indicating a desire to listen for events from the chain pub trait ChainListener: Sync + Send { /// Notifies a listener that a block was connected. - /// Note that if a new script/transaction is watched during a block_connected call, the block - /// *must* be re-scanned with the new script/transaction and block_connected should be called - /// again with the same header and (at least) the new transactions. + /// Note that if a new transaction/outpoint is watched during a block_connected call, the block + /// *must* be re-scanned with the new transaction/outpoints and block_connected should be + /// called again with the same header and (at least) the new transactions. /// This also means those counting confirmations using block_connected callbacks should watch /// for duplicate headers and not count them towards confirmations! fn block_connected(&self, header: &BlockHeader, height: u32, txn_matched: &[&Transaction], indexes_of_txn_matched: &[u32]); @@ -97,7 +97,7 @@ pub struct ChainWatchInterfaceUtil { /// Register listener impl ChainWatchInterface for ChainWatchInterfaceUtil { - fn install_watch_script(&self, script_pub_key: &Script) { + fn install_watch_tx(&self, _txid: &Sha256dHash, script_pub_key: &Script) { let mut watched = self.watched.lock().unwrap(); watched.0.push(script_pub_key.clone()); self.reentered.fetch_add(1, Ordering::Relaxed); diff --git a/src/ln/channelmonitor.rs b/src/ln/channelmonitor.rs index 52bb6d65c..e467772b1 100644 --- a/src/ln/channelmonitor.rs +++ b/src/ln/channelmonitor.rs @@ -97,7 +97,7 @@ impl SimpleManyChannelMonitor match &monitor.funding_txo { &None => self.chain_monitor.watch_all_txn(), &Some((ref outpoint, ref script)) => { - self.chain_monitor.install_watch_script(script); + self.chain_monitor.install_watch_tx(&outpoint.txid, script); self.chain_monitor.install_watch_outpoint((outpoint.txid, outpoint.index as u32), script); }, } -- 2.39.5