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 Dec 12, 2024
1 parent c3c3658 commit 7555bb8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 22 deletions.
15 changes: 2 additions & 13 deletions lightning/src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,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(async_payments)]
use {
Expand All @@ -110,7 +110,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 @@ -2400,8 +2400,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 @@ -3311,8 +3309,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 @@ -9497,11 +9493,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 @@ -13097,8 +13088,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
18 changes: 9 additions & 9 deletions lightning/src/offers/flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ use crate::onion_message::messenger::{
Destination, MessageRouter, MessageSendInstructions, Responder, ResponseInstruction,
};
use crate::onion_message::offers::{OffersMessage, OffersMessageHandler};
use crate::sync::MutexGuard;

use crate::offers::invoice_error::InvoiceError;
use crate::offers::nonce::Nonce;
Expand Down Expand Up @@ -75,12 +74,6 @@ use {
///
/// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
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 @@ -578,6 +571,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 @@ -617,6 +613,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 @@ -1528,7 +1528,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 @@ -1608,6 +1608,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 7555bb8

Please sign in to comment.