Skip to content

Commit f2ac259

Browse files
Test async receive
In the previous commit we completed support for async receive from an always-online sender to an often-offline receiver, minus support for acting as the async receiver's always-online channel counterparty.
1 parent 7da413c commit f2ac259

File tree

5 files changed

+733
-84
lines changed

5 files changed

+733
-84
lines changed

lightning/src/blinded_path/payment.rs

+17-9
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use bitcoin::hashes::hmac::Hmac;
1313
use bitcoin::hashes::sha256::Hash as Sha256;
1414
use bitcoin::secp256k1::{self, PublicKey, Secp256k1, SecretKey};
15+
use bitcoin::secp256k1::ecdh::SharedSecret;
1516

1617
use crate::blinded_path::{BlindedHop, BlindedPath, IntroductionNode, NodeIdLookUp};
1718
use crate::blinded_path::utils;
@@ -170,15 +171,8 @@ impl BlindedPaymentPath {
170171
NL::Target: NodeIdLookUp,
171172
T: secp256k1::Signing + secp256k1::Verification,
172173
{
173-
let control_tlvs_ss = node_signer.ecdh(Recipient::Node, &self.inner_path.blinding_point, None)?;
174-
let rho = onion_utils::gen_rho_from_shared_secret(&control_tlvs_ss.secret_bytes());
175-
let encrypted_control_tlvs = &self.inner_path.blinded_hops.get(0).ok_or(())?.encrypted_payload;
176-
let mut s = Cursor::new(encrypted_control_tlvs);
177-
let mut reader = FixedLengthReader::new(&mut s, encrypted_control_tlvs.len() as u64);
178-
match ChaChaPolyReadAdapter::read(&mut reader, rho) {
179-
Ok(ChaChaPolyReadAdapter {
180-
readable: BlindedPaymentTlvs::Forward(ForwardTlvs { short_channel_id, .. })
181-
}) => {
174+
match self.decrypt_intro_payload::<NS>(node_signer) {
175+
Ok((BlindedPaymentTlvs::Forward(ForwardTlvs { short_channel_id, .. }), control_tlvs_ss)) => {
182176
let next_node_id = match node_id_lookup.next_node_id(short_channel_id) {
183177
Some(node_id) => node_id,
184178
None => return Err(()),
@@ -195,6 +189,20 @@ impl BlindedPaymentPath {
195189
}
196190
}
197191

192+
pub(crate) fn decrypt_intro_payload<NS: Deref>(
193+
&self, node_signer: &NS
194+
) -> Result<(BlindedPaymentTlvs, SharedSecret), ()> where NS::Target: NodeSigner {
195+
let control_tlvs_ss = node_signer.ecdh(Recipient::Node, &self.inner_path.blinding_point, None)?;
196+
let rho = onion_utils::gen_rho_from_shared_secret(&control_tlvs_ss.secret_bytes());
197+
let encrypted_control_tlvs = &self.inner_path.blinded_hops.get(0).ok_or(())?.encrypted_payload;
198+
let mut s = Cursor::new(encrypted_control_tlvs);
199+
let mut reader = FixedLengthReader::new(&mut s, encrypted_control_tlvs.len() as u64);
200+
match ChaChaPolyReadAdapter::read(&mut reader, rho) {
201+
Ok(ChaChaPolyReadAdapter { readable, .. }) => Ok((readable, control_tlvs_ss)),
202+
_ => Err(())
203+
}
204+
}
205+
198206
pub(crate) fn inner_blinded_path(&self) -> &BlindedPath {
199207
&self.inner_path
200208
}

0 commit comments

Comments
 (0)