Skip to content

Commit 403ced3

Browse files
committed
Remove redundant Arc wrapping of HRNResolver
Streamlines the storage and passing of HRNResolver by holding it by value in the Node and UnifiedPayment structs. Changes: - Removed the outer Arc wrapper around HRNResolver in Node and UnifiedPayment. - Implemented Clone for HRNResolver to facilitate easy sharing of the internal Arcs. - Updated UnifiedPayment method calls to pass HRNResolver by reference instead of using .as_ref() on an outer Arc. Since HRNResolver variants already contain internal Arcs, the outer Arc was redundant and added unnecessary memory indirection.
1 parent 7e11a61 commit 403ced3

4 files changed

Lines changed: 8 additions & 7 deletions

File tree

src/builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2051,7 +2051,7 @@ fn build_with_store_internal(
20512051
node_metrics,
20522052
om_mailbox,
20532053
async_payments_role,
2054-
hrn_resolver: Arc::new(hrn_resolver),
2054+
hrn_resolver,
20552055
#[cfg(cycle_tests)]
20562056
_leak_checker,
20572057
})

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ pub struct Node {
238238
node_metrics: Arc<RwLock<NodeMetrics>>,
239239
om_mailbox: Option<Arc<OnionMessageMailbox>>,
240240
async_payments_role: Option<AsyncPaymentsRole>,
241-
hrn_resolver: Arc<HRNResolver>,
241+
hrn_resolver: HRNResolver,
242242
#[cfg(cycle_tests)]
243243
_leak_checker: LeakChecker,
244244
}
@@ -1006,7 +1006,7 @@ impl Node {
10061006
self.bolt12_payment().into(),
10071007
Arc::clone(&self.config),
10081008
Arc::clone(&self.logger),
1009-
Arc::clone(&self.hrn_resolver),
1009+
self.hrn_resolver.clone(),
10101010
)
10111011
}
10121012

src/payment/unified.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ pub struct UnifiedPayment {
7474
bolt12_payment: Arc<Bolt12Payment>,
7575
config: Arc<Config>,
7676
logger: Arc<Logger>,
77-
hrn_resolver: Arc<HRNResolver>,
77+
hrn_resolver: HRNResolver,
7878
#[cfg(hrn_tests)]
7979
test_offer: std::sync::Mutex<Option<Offer>>,
8080
}
@@ -83,7 +83,7 @@ impl UnifiedPayment {
8383
pub(crate) fn new(
8484
onchain_payment: Arc<OnchainPayment>, bolt11_invoice: Arc<Bolt11Payment>,
8585
bolt12_payment: Arc<Bolt12Payment>, config: Arc<Config>, logger: Arc<Logger>,
86-
hrn_resolver: Arc<HRNResolver>,
86+
hrn_resolver: HRNResolver,
8787
) -> Self {
8888
Self {
8989
onchain_payment,
@@ -197,7 +197,7 @@ impl UnifiedPayment {
197197
}
198198

199199
let parse_fut =
200-
PaymentInstructions::parse(uri_str, target_network, self.hrn_resolver.as_ref(), false);
200+
PaymentInstructions::parse(uri_str, target_network, &self.hrn_resolver, false);
201201

202202
let instructions =
203203
tokio::time::timeout(Duration::from_secs(HRN_RESOLUTION_TIMEOUT_SECS), parse_fut)
@@ -223,7 +223,7 @@ impl UnifiedPayment {
223223
Error::InvalidAmount
224224
})?;
225225

226-
let fut = instr.set_amount(amt, self.hrn_resolver.as_ref());
226+
let fut = instr.set_amount(amt, &self.hrn_resolver);
227227

228228
tokio::time::timeout(Duration::from_secs(HRN_RESOLUTION_TIMEOUT_SECS), fut)
229229
.await

src/types.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,7 @@ pub(crate) type OnionMessenger = lightning::onion_message::messenger::OnionMesse
330330
IgnoringMessageHandler,
331331
>;
332332

333+
#[derive(Clone)]
333334
pub enum HRNResolver {
334335
Onion(Arc<LDKOnionMessageDNSSECHrnResolver<Arc<Graph>, Arc<Logger>>>),
335336
Local(Arc<DNSHrnResolver>),

0 commit comments

Comments
 (0)