Skip to content

Commit 1ec0c14

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 8d2c4e7 commit 1ec0c14

File tree

7 files changed

+7
-29
lines changed

7 files changed

+7
-29
lines changed

lightning/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, 0).unwrap(),
196+
(ChannelManager::new(Network::Bitcoin, fee_est.clone(), monitor.clone(), broadcast.clone(), Arc::clone(&logger), keys_manager.clone(), config, 0).unwrap(),
197197
monitor)
198198
} }
199199
}

lightning/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, 0).unwrap();
334+
let channelmanager = ChannelManager::new(Network::Bitcoin, fee_est.clone(), monitor.clone(), broadcast.clone(), Arc::clone(&logger), keys_manager.clone(), config, 0).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]);

lightning/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);

lightning/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)]
@@ -596,7 +595,6 @@ impl ChannelManager {
596595
genesis_hash: genesis_block(network).header.bitcoin_hash(),
597596
fee_estimator: feeest.clone(),
598597
monitor: monitor.clone(),
599-
chain_monitor,
600598
tx_broadcaster,
601599

602600
latest_block_height: AtomicUsize::new(current_blockchain_height),
@@ -619,8 +617,7 @@ impl ChannelManager {
619617

620618
logger,
621619
});
622-
let weak_res = Arc::downgrade(&res);
623-
res.chain_monitor.register_listener(weak_res);
620+
624621
Ok(res)
625622
}
626623

@@ -3142,10 +3139,7 @@ pub struct ChannelManagerReadArgs<'a> {
31423139
/// you have deserialized ChannelMonitors separately and will add them to your
31433140
/// ManyChannelMonitor after deserializing this ChannelManager.
31443141
pub monitor: Arc<ManyChannelMonitor>,
3145-
/// The ChainWatchInterface for use in the ChannelManager in the future.
3146-
///
3147-
/// No calls to the ChainWatchInterface will be made during deserialization.
3148-
pub chain_monitor: Arc<ChainWatchInterface>,
3142+
31493143
/// The BroadcasterInterface which will be used in the ChannelManager in the future and may be
31503144
/// used to broadcast the latest local commitment transactions of channels which must be
31513145
/// force-closed during deserialization.
@@ -3248,7 +3242,6 @@ impl<'a, R : ::std::io::Read> ReadableArgs<R, ChannelManagerReadArgs<'a>> for (S
32483242
genesis_hash,
32493243
fee_estimator: args.fee_estimator,
32503244
monitor: args.monitor,
3251-
chain_monitor: args.chain_monitor,
32523245
tx_broadcaster: args.tx_broadcaster,
32533246

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

lightning/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

lightning/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 }, 0).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 }, 0).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(),

lightning/src/ln/functional_tests.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3398,7 +3398,6 @@ fn test_no_txn_manager_serialize_deserialize() {
33983398
keys_manager,
33993399
fee_estimator: Arc::new(test_utils::TestFeeEstimator { sat_per_kw: 253 }),
34003400
monitor: nodes[0].chan_monitor.clone(),
3401-
chain_monitor: nodes[0].chain_monitor.clone(),
34023401
tx_broadcaster: nodes[0].tx_broadcaster.clone(),
34033402
logger: Arc::new(test_utils::TestLogger::new()),
34043403
channel_monitors: &channel_monitors,
@@ -3524,7 +3523,6 @@ fn test_manager_serialize_deserialize_inconsistent_monitor() {
35243523
keys_manager,
35253524
fee_estimator: Arc::new(test_utils::TestFeeEstimator { sat_per_kw: 253 }),
35263525
monitor: nodes[0].chan_monitor.clone(),
3527-
chain_monitor: nodes[0].chain_monitor.clone(),
35283526
tx_broadcaster: nodes[0].tx_broadcaster.clone(),
35293527
logger: Arc::new(test_utils::TestLogger::new()),
35303528
channel_monitors: &node_0_monitors.iter().map(|monitor| { (monitor.get_funding_txo().unwrap(), monitor) }).collect(),
@@ -6131,7 +6129,6 @@ fn test_data_loss_protect() {
61316129
keys_manager: Arc::new(keysinterface::KeysManager::new(&nodes[0].node_seed, Network::Testnet, Arc::clone(&logger), 42, 21)),
61326130
fee_estimator: feeest.clone(),
61336131
monitor: monitor.clone(),
6134-
chain_monitor: chain_monitor.clone(),
61356132
logger: Arc::clone(&logger),
61366133
tx_broadcaster,
61376134
default_config: UserConfig::new(),

0 commit comments

Comments
 (0)