Skip to content

Commit 8721dee

Browse files
committed
Allow any Deref to an EntropySource in BlindedPath building
This matches our normal API semantics and allows, for example, `Arc`s to `EntropySource`s.
1 parent b26a652 commit 8721dee

File tree

1 file changed

+14
-12
lines changed
  • lightning/src/blinded_path

1 file changed

+14
-12
lines changed

lightning/src/blinded_path/mod.rs

+14-12
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ pub(crate) mod utils;
1515

1616
use bitcoin::secp256k1::{self, PublicKey, Secp256k1, SecretKey};
1717

18+
use core::ops::Deref;
19+
1820
use crate::ln::msgs::DecodeError;
1921
use crate::offers::invoice::BlindedPayInfo;
2022
use crate::routing::gossip::{NodeId, ReadOnlyNetworkGraph};
@@ -115,9 +117,9 @@ pub struct BlindedHop {
115117

116118
impl BlindedPath {
117119
/// Create a one-hop blinded path for a message.
118-
pub fn one_hop_for_message<ES: EntropySource + ?Sized, T: secp256k1::Signing + secp256k1::Verification>(
119-
recipient_node_id: PublicKey, entropy_source: &ES, secp_ctx: &Secp256k1<T>
120-
) -> Result<Self, ()> {
120+
pub fn one_hop_for_message<ES: Deref, T: secp256k1::Signing + secp256k1::Verification>(
121+
recipient_node_id: PublicKey, entropy_source: ES, secp_ctx: &Secp256k1<T>
122+
) -> Result<Self, ()> where ES::Target: EntropySource {
121123
Self::new_for_message(&[recipient_node_id], entropy_source, secp_ctx)
122124
}
123125

@@ -126,9 +128,9 @@ impl BlindedPath {
126128
///
127129
/// Errors if no hops are provided or if `node_pk`(s) are invalid.
128130
// TODO: make all payloads the same size with padding + add dummy hops
129-
pub fn new_for_message<ES: EntropySource + ?Sized, T: secp256k1::Signing + secp256k1::Verification>(
130-
node_pks: &[PublicKey], entropy_source: &ES, secp_ctx: &Secp256k1<T>
131-
) -> Result<Self, ()> {
131+
pub fn new_for_message<ES: Deref, T: secp256k1::Signing + secp256k1::Verification>(
132+
node_pks: &[PublicKey], entropy_source: ES, secp_ctx: &Secp256k1<T>
133+
) -> Result<Self, ()> where ES::Target: EntropySource {
132134
if node_pks.is_empty() { return Err(()) }
133135
let blinding_secret_bytes = entropy_source.get_secure_random_bytes();
134136
let blinding_secret = SecretKey::from_slice(&blinding_secret_bytes[..]).expect("RNG is busted");
@@ -142,10 +144,10 @@ impl BlindedPath {
142144
}
143145

144146
/// Create a one-hop blinded path for a payment.
145-
pub fn one_hop_for_payment<ES: EntropySource + ?Sized, T: secp256k1::Signing + secp256k1::Verification>(
147+
pub fn one_hop_for_payment<ES: Deref, T: secp256k1::Signing + secp256k1::Verification>(
146148
payee_node_id: PublicKey, payee_tlvs: payment::ReceiveTlvs, min_final_cltv_expiry_delta: u16,
147-
entropy_source: &ES, secp_ctx: &Secp256k1<T>
148-
) -> Result<(BlindedPayInfo, Self), ()> {
149+
entropy_source: ES, secp_ctx: &Secp256k1<T>
150+
) -> Result<(BlindedPayInfo, Self), ()> where ES::Target: EntropySource {
149151
// This value is not considered in pathfinding for 1-hop blinded paths, because it's intended to
150152
// be in relation to a specific channel.
151153
let htlc_maximum_msat = u64::max_value();
@@ -164,11 +166,11 @@ impl BlindedPath {
164166
///
165167
/// [`ForwardTlvs`]: crate::blinded_path::payment::ForwardTlvs
166168
// TODO: make all payloads the same size with padding + add dummy hops
167-
pub fn new_for_payment<ES: EntropySource + ?Sized, T: secp256k1::Signing + secp256k1::Verification>(
169+
pub fn new_for_payment<ES: Deref, T: secp256k1::Signing + secp256k1::Verification>(
168170
intermediate_nodes: &[payment::ForwardNode], payee_node_id: PublicKey,
169171
payee_tlvs: payment::ReceiveTlvs, htlc_maximum_msat: u64, min_final_cltv_expiry_delta: u16,
170-
entropy_source: &ES, secp_ctx: &Secp256k1<T>
171-
) -> Result<(BlindedPayInfo, Self), ()> {
172+
entropy_source: ES, secp_ctx: &Secp256k1<T>
173+
) -> Result<(BlindedPayInfo, Self), ()> where ES::Target: EntropySource {
172174
let introduction_node = IntroductionNode::NodeId(
173175
intermediate_nodes.first().map_or(payee_node_id, |n| n.node_id)
174176
);

0 commit comments

Comments
 (0)