Skip to content

Commit

Permalink
Move pending_dns_onion_messages to flow.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
shaavan committed Nov 30, 2024
1 parent 003a409 commit e15d10a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 19 deletions.
19 changes: 2 additions & 17 deletions lightning/src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ use crate::util::logger::{Level, Logger, WithContext};
use crate::util::errors::APIError;

#[cfg(feature = "dnssec")]
use crate::onion_message::dns_resolution::{DNSResolverMessage, OMNameResolver};
use crate::onion_message::dns_resolution::OMNameResolver;

#[cfg(not(c_bindings))]
use {
Expand All @@ -107,7 +107,7 @@ use core::{cmp, mem};
use core::borrow::Borrow;
use core::cell::RefCell;
use crate::io::Read;
use crate::sync::{Arc, FairRwLock, LockHeldState, LockTestExt, Mutex, MutexGuard, RwLock, RwLockReadGuard};
use crate::sync::{Arc, FairRwLock, LockHeldState, LockTestExt, Mutex, RwLock, RwLockReadGuard};
use core::sync::atomic::{AtomicUsize, AtomicBool, Ordering};
use core::time::Duration;
use core::ops::Deref;
Expand Down Expand Up @@ -2380,8 +2380,6 @@ where

#[cfg(feature = "dnssec")]
hrn_resolver: OMNameResolver,
#[cfg(feature = "dnssec")]
pending_dns_onion_messages: Mutex<Vec<(DNSResolverMessage, MessageSendInstructions)>>,

#[cfg(test)]
pub(super) entropy_source: ES,
Expand Down Expand Up @@ -3233,8 +3231,6 @@ where

#[cfg(feature = "dnssec")]
hrn_resolver: OMNameResolver::new(current_timestamp, params.best_block.height),
#[cfg(feature = "dnssec")]
pending_dns_onion_messages: Mutex::new(Vec::new()),
}
}

Expand Down Expand Up @@ -9465,10 +9461,6 @@ impl Default for Bolt11InvoiceParameters {
///
/// [`OffersMessageFlow`]: crate::offers::flow::OffersMessageFlow
pub trait OffersMessageCommons {
#[cfg(feature = "dnssec")]
/// Get pending DNS onion messages
fn get_pending_dns_onion_messages(&self) -> MutexGuard<'_, Vec<(DNSResolverMessage, MessageSendInstructions)>>;

#[cfg(feature = "dnssec")]
/// Get hrn resolver
fn get_hrn_resolver(&self) -> &OMNameResolver;
Expand Down Expand Up @@ -9601,11 +9593,6 @@ where
MR::Target: MessageRouter,
L::Target: Logger,
{
#[cfg(feature = "dnssec")]
fn get_pending_dns_onion_messages(&self) -> MutexGuard<'_, Vec<(DNSResolverMessage, MessageSendInstructions)>> {
self.pending_dns_onion_messages.lock().expect("Mutex is locked by other thread.")
}

#[cfg(feature = "dnssec")]
fn get_hrn_resolver(&self) -> &OMNameResolver {
&self.hrn_resolver
Expand Down Expand Up @@ -13122,8 +13109,6 @@ where

#[cfg(feature = "dnssec")]
hrn_resolver: OMNameResolver::new(highest_seen_timestamp, best_block_height),
#[cfg(feature = "dnssec")]
pending_dns_onion_messages: Mutex::new(Vec::new()),
};

for (_, monitor) in args.channel_monitors.iter() {
Expand Down
11 changes: 9 additions & 2 deletions lightning/src/offers/flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,9 @@ where
#[cfg(any(test, feature = "_test_utils"))]
pub(crate) pending_offers_messages: Mutex<Vec<(OffersMessage, MessageSendInstructions)>>,

#[cfg(feature = "dnssec")]
pending_dns_onion_messages: Mutex<Vec<(DNSResolverMessage, MessageSendInstructions)>>,

#[cfg(feature = "_test_utils")]
/// In testing, it is useful be able to forge a name -> offer mapping so that we can pay an
/// offer generated in the test.
Expand Down Expand Up @@ -455,6 +458,10 @@ where
message_router,

pending_offers_messages: Mutex::new(Vec::new()),

#[cfg(feature = "dnssec")]
pending_dns_onion_messages: Mutex::new(Vec::new()),

#[cfg(feature = "_test_utils")]
testing_dnssec_proof_offer_resolution_override: Mutex::new(new_hash_map()),
logger,
Expand Down Expand Up @@ -1369,7 +1376,7 @@ where
.flat_map(|destination| reply_paths.iter().map(move |path| (path, destination)))
.take(OFFERS_MESSAGE_REQUEST_LIMIT);
for (reply_path, destination) in message_params {
self.commons.get_pending_dns_onion_messages().push((
self.pending_dns_onion_messages.lock().unwrap().push((
DNSResolverMessage::DNSSECQuery(onion_message.clone()),
MessageSendInstructions::WithSpecifiedReplyPath {
destination: destination.clone(),
Expand Down Expand Up @@ -1449,6 +1456,6 @@ where
}

fn release_pending_messages(&self) -> Vec<(DNSResolverMessage, MessageSendInstructions)> {
core::mem::take(&mut self.commons.get_pending_dns_onion_messages())
core::mem::take(&mut self.pending_dns_onion_messages.lock().unwrap())
}
}

0 comments on commit e15d10a

Please sign in to comment.