Skip to content

Commit 448b191

Browse files
authored
Merge pull request #2514 from valentinewallace/2023-08-compute-blindedpayinfo
Aggregate `BlindedPayInfo` for blinded routes
2 parents 6436232 + f3616e6 commit 448b191

File tree

2 files changed

+382
-38
lines changed

2 files changed

+382
-38
lines changed

lightning/src/blinded_path/mod.rs

+17-10
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ pub(crate) mod utils;
1515

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

18-
use crate::sign::EntropySource;
1918
use crate::ln::msgs::DecodeError;
19+
use crate::offers::invoice::BlindedPayInfo;
20+
use crate::sign::EntropySource;
2021
use crate::util::ser::{Readable, Writeable, Writer};
2122

2223
use crate::io;
@@ -75,25 +76,31 @@ impl BlindedPath {
7576
})
7677
}
7778

78-
/// Create a blinded path for a payment, to be forwarded along `path`. The last node
79-
/// in `path` will be the destination node.
79+
/// Create a blinded path for a payment, to be forwarded along `intermediate_nodes`.
80+
///
81+
/// Errors if:
82+
/// * a provided node id is invalid
83+
/// * [`BlindedPayInfo`] calculation results in an integer overflow
84+
/// * any unknown features are required in the provided [`ForwardTlvs`]
8085
///
81-
/// Errors if `path` is empty or a node id in `path` is invalid.
86+
/// [`ForwardTlvs`]: crate::blinded_path::payment::ForwardTlvs
8287
// TODO: make all payloads the same size with padding + add dummy hops
8388
pub fn new_for_payment<ES: EntropySource, T: secp256k1::Signing + secp256k1::Verification>(
84-
intermediate_nodes: &[(PublicKey, payment::ForwardTlvs)], payee_node_id: PublicKey,
85-
payee_tlvs: payment::ReceiveTlvs, entropy_source: &ES, secp_ctx: &Secp256k1<T>
86-
) -> Result<Self, ()> {
89+
intermediate_nodes: &[payment::ForwardNode], payee_node_id: PublicKey,
90+
payee_tlvs: payment::ReceiveTlvs, htlc_maximum_msat: u64, entropy_source: &ES,
91+
secp_ctx: &Secp256k1<T>
92+
) -> Result<(BlindedPayInfo, Self), ()> {
8793
let blinding_secret_bytes = entropy_source.get_secure_random_bytes();
8894
let blinding_secret = SecretKey::from_slice(&blinding_secret_bytes[..]).expect("RNG is busted");
8995

90-
Ok(BlindedPath {
91-
introduction_node_id: intermediate_nodes.first().map_or(payee_node_id, |n| n.0),
96+
let blinded_payinfo = payment::compute_payinfo(intermediate_nodes, &payee_tlvs, htlc_maximum_msat)?;
97+
Ok((blinded_payinfo, BlindedPath {
98+
introduction_node_id: intermediate_nodes.first().map_or(payee_node_id, |n| n.node_id),
9299
blinding_point: PublicKey::from_secret_key(secp_ctx, &blinding_secret),
93100
blinded_hops: payment::blinded_hops(
94101
secp_ctx, intermediate_nodes, payee_node_id, payee_tlvs, &blinding_secret
95102
).map_err(|_| ())?,
96-
})
103+
}))
97104
}
98105
}
99106

0 commit comments

Comments
 (0)