@@ -3630,6 +3630,8 @@ impl<
36303630 our_network_pubkey, current_timestamp, expanded_inbound_key,
36313631 node_signer.get_receive_auth_key(), secp_ctx.clone(), message_router, logger.clone(),
36323632 );
3633+ #[cfg(test)]
3634+ let override_persistent_monitor_events = config.override_persistent_monitor_events;
36333635
36343636 ChannelManager {
36353637 config: RwLock::new(config),
@@ -3686,7 +3688,27 @@ impl<
36863688
36873689 logger,
36883690
3689- persistent_monitor_events: false,
3691+ persistent_monitor_events: {
3692+ #[cfg(not(test))]
3693+ { false }
3694+ #[cfg(test)]
3695+ {
3696+ override_persistent_monitor_events.unwrap_or_else(|| {
3697+ use core::hash::{BuildHasher, Hasher};
3698+ match std::env::var("LDK_TEST_PERSISTENT_MON_EVENTS") {
3699+ Ok(val) => match val.as_str() {
3700+ "1" => true,
3701+ "0" => false,
3702+ _ => panic!("LDK_TEST_PERSISTENT_MON_EVENTS must be 0 or 1, got: {}", val),
3703+ },
3704+ Err(_) => {
3705+ let rand_val = std::collections::hash_map::RandomState::new().build_hasher().finish();
3706+ rand_val % 2 == 0
3707+ },
3708+ }
3709+ })
3710+ }
3711+ },
36903712
36913713 #[cfg(feature = "_test_utils")]
36923714 testing_dnssec_proof_offer_resolution_override: Mutex::new(new_hash_map()),
@@ -11570,6 +11592,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1157011592 fail_chan!("Already had channel with the new channel_id");
1157111593 },
1157211594 hash_map::Entry::Vacant(e) => {
11595+ monitor.set_persistent_events_enabled(self.persistent_monitor_events);
1157311596 let monitor_res = self.chain_monitor.watch_channel(monitor.channel_id(), monitor);
1157411597 if let Ok(persist_state) = monitor_res {
1157511598 // There's no problem signing a counterparty's funding transaction if our monitor
@@ -11740,6 +11763,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1174011763 match chan
1174111764 .funding_signed(&msg, best_block, &self.signer_provider, &self.logger)
1174211765 .and_then(|(funded_chan, monitor)| {
11766+ monitor.set_persistent_events_enabled(self.persistent_monitor_events);
1174311767 self.chain_monitor
1174411768 .watch_channel(funded_chan.context.channel_id(), monitor)
1174511769 .map_err(|()| {
@@ -12655,6 +12679,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1265512679
1265612680 if let Some(chan) = chan.as_funded_mut() {
1265712681 if let Some(monitor) = monitor_opt {
12682+ monitor.set_persistent_events_enabled(self.persistent_monitor_events);
1265812683 let monitor_res =
1265912684 self.chain_monitor.watch_channel(monitor.channel_id(), monitor);
1266012685 if let Ok(persist_state) = monitor_res {
0 commit comments