Skip to content

Commit 1c95f69

Browse files
multi: remove listeners field and method from ChainWatchInterface
This includes the purpose of this PR, which is to remove the circular reference created by ChainListeners self-adding themselves to their ChainWatchInterface's `listeners` field.
1 parent 2afd531 commit 1c95f69

7 files changed

+7
-29
lines changed

fuzz/fuzz_targets/chanmon_fail_consistency.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ pub fn do_test(data: &[u8]) {
193193
config.channel_options.fee_proportional_millionths = 0;
194194
config.channel_options.announced_channel = true;
195195
config.peer_channel_config_limits.min_dust_limit_satoshis = 0;
196-
(ChannelManager::new(Network::Bitcoin, fee_est.clone(), monitor.clone(), watch.clone(), broadcast.clone(), Arc::clone(&logger), keys_manager.clone(), config).unwrap(),
196+
(ChannelManager::new(Network::Bitcoin, fee_est.clone(), monitor.clone(), broadcast.clone(), Arc::clone(&logger), keys_manager.clone(), config).unwrap(),
197197
monitor)
198198
} }
199199
}

fuzz/fuzz_targets/full_stack_target.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ pub fn do_test(data: &[u8], logger: &Arc<Logger>) {
331331
config.channel_options.fee_proportional_millionths = slice_to_be32(get_slice!(4));
332332
config.channel_options.announced_channel = get_slice!(1)[0] != 0;
333333
config.peer_channel_config_limits.min_dust_limit_satoshis = 0;
334-
let channelmanager = ChannelManager::new(Network::Bitcoin, fee_est.clone(), monitor.clone(), watch.clone(), broadcast.clone(), Arc::clone(&logger), keys_manager.clone(), config).unwrap();
334+
let channelmanager = ChannelManager::new(Network::Bitcoin, fee_est.clone(), monitor.clone(), broadcast.clone(), Arc::clone(&logger), keys_manager.clone(), config).unwrap();
335335
let router = Arc::new(Router::new(PublicKey::from_secret_key(&Secp256k1::signing_only(), &keys_manager.get_node_secret()), watch.clone(), Arc::clone(&logger)));
336336

337337
let peers = RefCell::new([false; 256]);

src/chain/chaininterface.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,6 @@ pub trait ChainWatchInterface: Sync + Send {
4545
/// Indicates that a listener needs to see all transactions.
4646
fn watch_all_txn(&self);
4747

48-
/// Register the given listener to receive events. Only a weak pointer is provided and the
49-
/// registration should be freed once that pointer expires.
50-
fn register_listener(&self, listener: Weak<ChainListener>);
51-
//TODO: unregister
52-
5348
/// Gets the script and value in satoshis for a given unspent transaction output given a
5449
/// short_channel_id (aka unspent_tx_output_identier). For BTC/tBTC channels the top three
5550
/// bytes are the block height, the next 3 the transaction index within the block, and the
@@ -204,7 +199,6 @@ impl ChainWatchedUtil {
204199
pub struct ChainWatchInterfaceUtil {
205200
network: Network,
206201
watched: Mutex<ChainWatchedUtil>,
207-
listeners: Mutex<Vec<Weak<ChainListener>>>,
208202
reentered: AtomicUsize,
209203
logger: Arc<Logger>,
210204
}
@@ -232,11 +226,6 @@ impl ChainWatchInterface for ChainWatchInterfaceUtil {
232226
}
233227
}
234228

235-
fn register_listener(&self, listener: Weak<ChainListener>) {
236-
let mut vec = self.listeners.lock().unwrap();
237-
vec.push(listener);
238-
}
239-
240229
fn get_chain_utxo(&self, genesis_hash: Sha256dHash, _unspent_tx_output_identifier: u64) -> Result<(Script, u64), ChainError> {
241230
if genesis_hash != genesis_block(self.network).header.bitcoin_hash() {
242231
return Err(ChainError::NotWatched);

src/ln/channelmanager.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use secp256k1::Secp256k1;
2525
use secp256k1::ecdh::SharedSecret;
2626
use secp256k1;
2727

28-
use chain::chaininterface::{BroadcasterInterface,ChainListener,ChainWatchInterface,FeeEstimator};
28+
use chain::chaininterface::{BroadcasterInterface,ChainListener,FeeEstimator};
2929
use chain::transaction::OutPoint;
3030
use ln::channel::{Channel, ChannelError};
3131
use ln::channelmonitor::{ChannelMonitor, ChannelMonitorUpdateErr, ManyChannelMonitor, CLTV_CLAIM_BUFFER, LATENCY_GRACE_PERIOD_BLOCKS, ANTI_REORG_DELAY};
@@ -323,7 +323,6 @@ pub struct ChannelManager {
323323
genesis_hash: Sha256dHash,
324324
fee_estimator: Arc<FeeEstimator>,
325325
monitor: Arc<ManyChannelMonitor>,
326-
chain_monitor: Arc<ChainWatchInterface>,
327326
tx_broadcaster: Arc<BroadcasterInterface>,
328327

329328
#[cfg(test)]
@@ -593,7 +592,6 @@ impl ChannelManager {
593592
genesis_hash: genesis_block(network).header.bitcoin_hash(),
594593
fee_estimator: feeest.clone(),
595594
monitor: monitor.clone(),
596-
chain_monitor,
597595
tx_broadcaster,
598596

599597
latest_block_height: AtomicUsize::new(0), //TODO: Get an init value
@@ -616,8 +614,7 @@ impl ChannelManager {
616614

617615
logger,
618616
});
619-
let weak_res = Arc::downgrade(&res);
620-
res.chain_monitor.register_listener(weak_res);
617+
621618
Ok(res)
622619
}
623620

@@ -3088,10 +3085,7 @@ pub struct ChannelManagerReadArgs<'a> {
30883085
/// you have deserialized ChannelMonitors separately and will add them to your
30893086
/// ManyChannelMonitor after deserializing this ChannelManager.
30903087
pub monitor: Arc<ManyChannelMonitor>,
3091-
/// The ChainWatchInterface for use in the ChannelManager in the future.
3092-
///
3093-
/// No calls to the ChainWatchInterface will be made during deserialization.
3094-
pub chain_monitor: Arc<ChainWatchInterface>,
3088+
30953089
/// The BroadcasterInterface which will be used in the ChannelManager in the future and may be
30963090
/// used to broadcast the latest local commitment transactions of channels which must be
30973091
/// force-closed during deserialization.
@@ -3194,7 +3188,6 @@ impl<'a, R : ::std::io::Read> ReadableArgs<R, ChannelManagerReadArgs<'a>> for (S
31943188
genesis_hash,
31953189
fee_estimator: args.fee_estimator,
31963190
monitor: args.monitor,
3197-
chain_monitor: args.chain_monitor,
31983191
tx_broadcaster: args.tx_broadcaster,
31993192

32003193
latest_block_height: AtomicUsize::new(latest_block_height as usize),

src/ln/channelmonitor.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,7 @@ impl<Key : Send + cmp::Eq + hash::Hash + 'static> SimpleManyChannelMonitor<Key>
223223
logger,
224224
fee_estimator: feeest,
225225
});
226-
let weak_res = Arc::downgrade(&res);
227-
res.chain_monitor.register_listener(weak_res);
226+
228227
res
229228
}
230229

src/ln/functional_test_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,7 @@ pub fn create_network(node_count: usize, node_config: &[Option<UserConfig>]) ->
844844
let mut default_config = UserConfig::new();
845845
default_config.channel_options.announced_channel = true;
846846
default_config.peer_channel_config_limits.force_announced_channel_preference = false;
847-
let node = ChannelManager::new(Network::Testnet, feeest.clone(), chan_monitor.clone(), chain_monitor.clone(), tx_broadcaster.clone(), Arc::clone(&logger), keys_manager.clone(), if node_config[i].is_some() { node_config[i].clone().unwrap() } else { default_config }).unwrap();
847+
let node = ChannelManager::new(Network::Testnet, feeest.clone(), chan_monitor.clone(), tx_broadcaster.clone(), Arc::clone(&logger), keys_manager.clone(), if node_config[i].is_some() { node_config[i].clone().unwrap() } else { default_config }).unwrap();
848848
let router = Router::new(PublicKey::from_secret_key(&secp_ctx, &keys_manager.get_node_secret()), chain_monitor.clone(), Arc::clone(&logger));
849849
nodes.push(Node { chain_monitor, tx_broadcaster, chan_monitor, node, router, keys_manager, node_seed: seed,
850850
network_payment_count: payment_count.clone(),

src/ln/functional_tests.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3300,7 +3300,6 @@ fn test_no_txn_manager_serialize_deserialize() {
33003300
keys_manager,
33013301
fee_estimator: Arc::new(test_utils::TestFeeEstimator { sat_per_kw: 253 }),
33023302
monitor: nodes[0].chan_monitor.clone(),
3303-
chain_monitor: nodes[0].chain_monitor.clone(),
33043303
tx_broadcaster: nodes[0].tx_broadcaster.clone(),
33053304
logger: Arc::new(test_utils::TestLogger::new()),
33063305
channel_monitors: &channel_monitors,
@@ -3426,7 +3425,6 @@ fn test_manager_serialize_deserialize_inconsistent_monitor() {
34263425
keys_manager,
34273426
fee_estimator: Arc::new(test_utils::TestFeeEstimator { sat_per_kw: 253 }),
34283427
monitor: nodes[0].chan_monitor.clone(),
3429-
chain_monitor: nodes[0].chain_monitor.clone(),
34303428
tx_broadcaster: nodes[0].tx_broadcaster.clone(),
34313429
logger: Arc::new(test_utils::TestLogger::new()),
34323430
channel_monitors: &node_0_monitors.iter().map(|monitor| { (monitor.get_funding_txo().unwrap(), monitor) }).collect(),
@@ -6037,7 +6035,6 @@ fn test_data_loss_protect() {
60376035
keys_manager: Arc::new(keysinterface::KeysManager::new(&nodes[0].node_seed, Network::Testnet, Arc::clone(&logger), 42, 21)),
60386036
fee_estimator: feeest.clone(),
60396037
monitor: monitor.clone(),
6040-
chain_monitor: chain_monitor.clone(),
60416038
logger: Arc::clone(&logger),
60426039
tx_broadcaster,
60436040
default_config: UserConfig::new(),

0 commit comments

Comments
 (0)