Skip to content

Commit 95e453a

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 8d1d136 commit 95e453a

File tree

5 files changed

+739
-86
lines changed

5 files changed

+739
-86
lines changed

lightning/src/blinded_path/payment.rs

+25-11
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
1212
use bitcoin::hashes::hmac::Hmac;
1313
use bitcoin::hashes::sha256::Hash as Sha256;
14+
use bitcoin::secp256k1::ecdh::SharedSecret;
1415
use bitcoin::secp256k1::{self, PublicKey, Secp256k1, SecretKey};
1516

1617
use crate::blinded_path::utils;
@@ -193,17 +194,11 @@ impl BlindedPaymentPath {
193194
NL::Target: NodeIdLookUp,
194195
T: secp256k1::Signing + secp256k1::Verification,
195196
{
196-
let control_tlvs_ss =
197-
node_signer.ecdh(Recipient::Node, &self.inner_path.blinding_point, None)?;
198-
let rho = onion_utils::gen_rho_from_shared_secret(&control_tlvs_ss.secret_bytes());
199-
let encrypted_control_tlvs =
200-
&self.inner_path.blinded_hops.get(0).ok_or(())?.encrypted_payload;
201-
let mut s = Cursor::new(encrypted_control_tlvs);
202-
let mut reader = FixedLengthReader::new(&mut s, encrypted_control_tlvs.len() as u64);
203-
match ChaChaPolyReadAdapter::read(&mut reader, rho) {
204-
Ok(ChaChaPolyReadAdapter {
205-
readable: BlindedPaymentTlvs::Forward(ForwardTlvs { short_channel_id, .. }),
206-
}) => {
197+
match self.decrypt_intro_payload::<NS>(node_signer) {
198+
Ok((
199+
BlindedPaymentTlvs::Forward(ForwardTlvs { short_channel_id, .. }),
200+
control_tlvs_ss,
201+
)) => {
207202
let next_node_id = match node_id_lookup.next_node_id(short_channel_id) {
208203
Some(node_id) => node_id,
209204
None => return Err(()),
@@ -223,6 +218,25 @@ impl BlindedPaymentPath {
223218
}
224219
}
225220

221+
pub(crate) fn decrypt_intro_payload<NS: Deref>(
222+
&self, node_signer: &NS,
223+
) -> Result<(BlindedPaymentTlvs, SharedSecret), ()>
224+
where
225+
NS::Target: NodeSigner,
226+
{
227+
let control_tlvs_ss =
228+
node_signer.ecdh(Recipient::Node, &self.inner_path.blinding_point, None)?;
229+
let rho = onion_utils::gen_rho_from_shared_secret(&control_tlvs_ss.secret_bytes());
230+
let encrypted_control_tlvs =
231+
&self.inner_path.blinded_hops.get(0).ok_or(())?.encrypted_payload;
232+
let mut s = Cursor::new(encrypted_control_tlvs);
233+
let mut reader = FixedLengthReader::new(&mut s, encrypted_control_tlvs.len() as u64);
234+
match ChaChaPolyReadAdapter::read(&mut reader, rho) {
235+
Ok(ChaChaPolyReadAdapter { readable, .. }) => Ok((readable, control_tlvs_ss)),
236+
_ => Err(()),
237+
}
238+
}
239+
226240
pub(crate) fn inner_blinded_path(&self) -> &BlindedPath {
227241
&self.inner_path
228242
}

0 commit comments

Comments
 (0)