Skip to content

Commit ea0e287

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 53e42bb commit ea0e287

File tree

1 file changed

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

1 file changed

+12
-12
lines changed

lightning/src/blinded_path/mod.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,9 @@ pub struct BlindedHop {
121121

122122
impl BlindedPath {
123123
/// Create a one-hop blinded path for a message.
124-
pub fn one_hop_for_message<ES: EntropySource + ?Sized, T: secp256k1::Signing + secp256k1::Verification>(
125-
recipient_node_id: PublicKey, entropy_source: &ES, secp_ctx: &Secp256k1<T>
126-
) -> Result<Self, ()> {
124+
pub fn one_hop_for_message<ES: Deref, T: secp256k1::Signing + secp256k1::Verification>(
125+
recipient_node_id: PublicKey, entropy_source: ES, secp_ctx: &Secp256k1<T>
126+
) -> Result<Self, ()> where ES::Target: EntropySource {
127127
Self::new_for_message(&[recipient_node_id], entropy_source, secp_ctx)
128128
}
129129

@@ -132,9 +132,9 @@ impl BlindedPath {
132132
///
133133
/// Errors if no hops are provided or if `node_pk`(s) are invalid.
134134
// TODO: make all payloads the same size with padding + add dummy hops
135-
pub fn new_for_message<ES: EntropySource + ?Sized, T: secp256k1::Signing + secp256k1::Verification>(
136-
node_pks: &[PublicKey], entropy_source: &ES, secp_ctx: &Secp256k1<T>
137-
) -> Result<Self, ()> {
135+
pub fn new_for_message<ES: Deref, T: secp256k1::Signing + secp256k1::Verification>(
136+
node_pks: &[PublicKey], entropy_source: ES, secp_ctx: &Secp256k1<T>
137+
) -> Result<Self, ()> where ES::Target: EntropySource {
138138
if node_pks.is_empty() { return Err(()) }
139139
let blinding_secret_bytes = entropy_source.get_secure_random_bytes();
140140
let blinding_secret = SecretKey::from_slice(&blinding_secret_bytes[..]).expect("RNG is busted");
@@ -148,10 +148,10 @@ impl BlindedPath {
148148
}
149149

150150
/// Create a one-hop blinded path for a payment.
151-
pub fn one_hop_for_payment<ES: EntropySource + ?Sized, T: secp256k1::Signing + secp256k1::Verification>(
151+
pub fn one_hop_for_payment<ES: Deref, T: secp256k1::Signing + secp256k1::Verification>(
152152
payee_node_id: PublicKey, payee_tlvs: payment::ReceiveTlvs, min_final_cltv_expiry_delta: u16,
153-
entropy_source: &ES, secp_ctx: &Secp256k1<T>
154-
) -> Result<(BlindedPayInfo, Self), ()> {
153+
entropy_source: ES, secp_ctx: &Secp256k1<T>
154+
) -> Result<(BlindedPayInfo, Self), ()> where ES::Target: EntropySource {
155155
// This value is not considered in pathfinding for 1-hop blinded paths, because it's intended to
156156
// be in relation to a specific channel.
157157
let htlc_maximum_msat = u64::max_value();
@@ -170,11 +170,11 @@ impl BlindedPath {
170170
///
171171
/// [`ForwardTlvs`]: crate::blinded_path::payment::ForwardTlvs
172172
// TODO: make all payloads the same size with padding + add dummy hops
173-
pub fn new_for_payment<ES: EntropySource + ?Sized, T: secp256k1::Signing + secp256k1::Verification>(
173+
pub fn new_for_payment<ES: Deref, T: secp256k1::Signing + secp256k1::Verification>(
174174
intermediate_nodes: &[payment::ForwardNode], payee_node_id: PublicKey,
175175
payee_tlvs: payment::ReceiveTlvs, htlc_maximum_msat: u64, min_final_cltv_expiry_delta: u16,
176-
entropy_source: &ES, secp_ctx: &Secp256k1<T>
177-
) -> Result<(BlindedPayInfo, Self), ()> {
176+
entropy_source: ES, secp_ctx: &Secp256k1<T>
177+
) -> Result<(BlindedPayInfo, Self), ()> where ES::Target: EntropySource {
178178
let introduction_node = IntroductionNode::NodeId(
179179
intermediate_nodes.first().map_or(payee_node_id, |n| n.node_id)
180180
);

0 commit comments

Comments
 (0)