mirror of
https://github.com/lightningdevkit/rust-lightning.git
synced 2025-03-15 15:39:09 +01:00
Merge pull request #3595 from arik-so/arik/trampoline/inbound-prefactors
Prefactor for inbound Trampoline parsing/decryption
This commit is contained in:
commit
b05402ae78
4 changed files with 69 additions and 3 deletions
|
@ -62,6 +62,7 @@ check-cfg = [
|
||||||
"cfg(ldk_bench)",
|
"cfg(ldk_bench)",
|
||||||
"cfg(ldk_test_vectors)",
|
"cfg(ldk_test_vectors)",
|
||||||
"cfg(taproot)",
|
"cfg(taproot)",
|
||||||
|
"cfg(trampoline)",
|
||||||
"cfg(require_route_graph_test)",
|
"cfg(require_route_graph_test)",
|
||||||
"cfg(splicing)",
|
"cfg(splicing)",
|
||||||
"cfg(async_payments)",
|
"cfg(async_payments)",
|
||||||
|
|
|
@ -131,6 +131,8 @@ RUSTFLAGS="--cfg=taproot" cargo test --verbose --color always -p lightning
|
||||||
[ "$CI_MINIMIZE_DISK_USAGE" != "" ] && cargo clean
|
[ "$CI_MINIMIZE_DISK_USAGE" != "" ] && cargo clean
|
||||||
RUSTFLAGS="--cfg=splicing" cargo test --verbose --color always -p lightning
|
RUSTFLAGS="--cfg=splicing" cargo test --verbose --color always -p lightning
|
||||||
[ "$CI_MINIMIZE_DISK_USAGE" != "" ] && cargo clean
|
[ "$CI_MINIMIZE_DISK_USAGE" != "" ] && cargo clean
|
||||||
|
RUSTFLAGS="--cfg=trampoline" cargo test --verbose --color always -p lightning
|
||||||
|
[ "$CI_MINIMIZE_DISK_USAGE" != "" ] && cargo clean
|
||||||
RUSTFLAGS="--cfg=async_payments" cargo test --verbose --color always -p lightning
|
RUSTFLAGS="--cfg=async_payments" cargo test --verbose --color always -p lightning
|
||||||
[ "$CI_MINIMIZE_DISK_USAGE" != "" ] && cargo clean
|
[ "$CI_MINIMIZE_DISK_USAGE" != "" ] && cargo clean
|
||||||
RUSTFLAGS="--cfg=lsps1_service" cargo test --verbose --color always -p lightning-liquidity
|
RUSTFLAGS="--cfg=lsps1_service" cargo test --verbose --color always -p lightning-liquidity
|
||||||
|
|
|
@ -55,6 +55,8 @@ use crate::ln::channel_state::ChannelDetails;
|
||||||
use crate::types::features::{Bolt12InvoiceFeatures, ChannelFeatures, ChannelTypeFeatures, InitFeatures, NodeFeatures};
|
use crate::types::features::{Bolt12InvoiceFeatures, ChannelFeatures, ChannelTypeFeatures, InitFeatures, NodeFeatures};
|
||||||
#[cfg(any(feature = "_test_utils", test))]
|
#[cfg(any(feature = "_test_utils", test))]
|
||||||
use crate::types::features::Bolt11InvoiceFeatures;
|
use crate::types::features::Bolt11InvoiceFeatures;
|
||||||
|
#[cfg(trampoline)]
|
||||||
|
use crate::routing::gossip::NodeId;
|
||||||
use crate::routing::router::{BlindedTail, FixedRouter, InFlightHtlcs, Path, Payee, PaymentParameters, Route, RouteParameters, Router};
|
use crate::routing::router::{BlindedTail, FixedRouter, InFlightHtlcs, Path, Payee, PaymentParameters, Route, RouteParameters, Router};
|
||||||
use crate::ln::onion_payment::{check_incoming_htlc_cltv, create_recv_pending_htlc_info, create_fwd_pending_htlc_info, decode_incoming_update_add_htlc_onion, InboundHTLCErr, NextPacketDetails};
|
use crate::ln::onion_payment::{check_incoming_htlc_cltv, create_recv_pending_htlc_info, create_fwd_pending_htlc_info, decode_incoming_update_add_htlc_onion, InboundHTLCErr, NextPacketDetails};
|
||||||
use crate::ln::msgs;
|
use crate::ln::msgs;
|
||||||
|
@ -168,6 +170,24 @@ pub enum PendingHTLCRouting {
|
||||||
/// The absolute CLTV of the inbound HTLC
|
/// The absolute CLTV of the inbound HTLC
|
||||||
incoming_cltv_expiry: Option<u32>,
|
incoming_cltv_expiry: Option<u32>,
|
||||||
},
|
},
|
||||||
|
/// An HTLC which should be forwarded on to another Trampoline node.
|
||||||
|
#[cfg(trampoline)]
|
||||||
|
TrampolineForward {
|
||||||
|
/// The onion shared secret we build with the sender (or the preceding Trampoline node) used
|
||||||
|
/// to decrypt the onion.
|
||||||
|
///
|
||||||
|
/// This is later used to encrypt failure packets in the event that the HTLC is failed.
|
||||||
|
incoming_shared_secret: [u8; 32],
|
||||||
|
/// The onion which should be included in the forwarded HTLC, telling the next hop what to
|
||||||
|
/// do with the HTLC.
|
||||||
|
onion_packet: msgs::TrampolineOnionPacket,
|
||||||
|
/// The node ID of the Trampoline node which we need to route this HTLC to.
|
||||||
|
node_id: NodeId,
|
||||||
|
/// Set if this HTLC is being forwarded within a blinded path.
|
||||||
|
blinded: Option<BlindedForward>,
|
||||||
|
/// The absolute CLTV of the inbound HTLC
|
||||||
|
incoming_cltv_expiry: u32,
|
||||||
|
},
|
||||||
/// The onion indicates that this is a payment for an invoice (supposedly) generated by us.
|
/// The onion indicates that this is a payment for an invoice (supposedly) generated by us.
|
||||||
///
|
///
|
||||||
/// Note that at this point, we have not checked that the invoice being paid was actually
|
/// Note that at this point, we have not checked that the invoice being paid was actually
|
||||||
|
@ -269,6 +289,8 @@ impl PendingHTLCRouting {
|
||||||
fn blinded_failure(&self) -> Option<BlindedFailure> {
|
fn blinded_failure(&self) -> Option<BlindedFailure> {
|
||||||
match self {
|
match self {
|
||||||
Self::Forward { blinded: Some(BlindedForward { failure, .. }), .. } => Some(*failure),
|
Self::Forward { blinded: Some(BlindedForward { failure, .. }), .. } => Some(*failure),
|
||||||
|
#[cfg(trampoline)]
|
||||||
|
Self::TrampolineForward { blinded: Some(BlindedForward { failure, .. }), .. } => Some(*failure),
|
||||||
Self::Receive { requires_blinded_error: true, .. } => Some(BlindedFailure::FromBlindedNode),
|
Self::Receive { requires_blinded_error: true, .. } => Some(BlindedFailure::FromBlindedNode),
|
||||||
Self::ReceiveKeysend { requires_blinded_error: true, .. } => Some(BlindedFailure::FromBlindedNode),
|
Self::ReceiveKeysend { requires_blinded_error: true, .. } => Some(BlindedFailure::FromBlindedNode),
|
||||||
_ => None,
|
_ => None,
|
||||||
|
@ -278,6 +300,8 @@ impl PendingHTLCRouting {
|
||||||
fn incoming_cltv_expiry(&self) -> Option<u32> {
|
fn incoming_cltv_expiry(&self) -> Option<u32> {
|
||||||
match self {
|
match self {
|
||||||
Self::Forward { incoming_cltv_expiry, .. } => *incoming_cltv_expiry,
|
Self::Forward { incoming_cltv_expiry, .. } => *incoming_cltv_expiry,
|
||||||
|
#[cfg(trampoline)]
|
||||||
|
Self::TrampolineForward { incoming_cltv_expiry, .. } => Some(*incoming_cltv_expiry),
|
||||||
Self::Receive { incoming_cltv_expiry, .. } => Some(*incoming_cltv_expiry),
|
Self::Receive { incoming_cltv_expiry, .. } => Some(*incoming_cltv_expiry),
|
||||||
Self::ReceiveKeysend { incoming_cltv_expiry, .. } => Some(*incoming_cltv_expiry),
|
Self::ReceiveKeysend { incoming_cltv_expiry, .. } => Some(*incoming_cltv_expiry),
|
||||||
}
|
}
|
||||||
|
@ -8908,6 +8932,8 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
|
||||||
for (forward_info, prev_htlc_id) in pending_forwards.drain(..) {
|
for (forward_info, prev_htlc_id) in pending_forwards.drain(..) {
|
||||||
let scid = match forward_info.routing {
|
let scid = match forward_info.routing {
|
||||||
PendingHTLCRouting::Forward { short_channel_id, .. } => short_channel_id,
|
PendingHTLCRouting::Forward { short_channel_id, .. } => short_channel_id,
|
||||||
|
#[cfg(trampoline)]
|
||||||
|
PendingHTLCRouting::TrampolineForward { .. } => 0,
|
||||||
PendingHTLCRouting::Receive { .. } => 0,
|
PendingHTLCRouting::Receive { .. } => 0,
|
||||||
PendingHTLCRouting::ReceiveKeysend { .. } => 0,
|
PendingHTLCRouting::ReceiveKeysend { .. } => 0,
|
||||||
};
|
};
|
||||||
|
@ -12448,6 +12474,7 @@ impl_writeable_tlv_based!(BlindedForward, {
|
||||||
(3, next_blinding_override, option),
|
(3, next_blinding_override, option),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
#[cfg(not(trampoline))]
|
||||||
impl_writeable_tlv_based_enum!(PendingHTLCRouting,
|
impl_writeable_tlv_based_enum!(PendingHTLCRouting,
|
||||||
(0, Forward) => {
|
(0, Forward) => {
|
||||||
(0, onion_packet, required),
|
(0, onion_packet, required),
|
||||||
|
@ -12476,6 +12503,42 @@ impl_writeable_tlv_based_enum!(PendingHTLCRouting,
|
||||||
(11, invoice_request, option),
|
(11, invoice_request, option),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
#[cfg(trampoline)]
|
||||||
|
impl_writeable_tlv_based_enum!(PendingHTLCRouting,
|
||||||
|
(0, Forward) => {
|
||||||
|
(0, onion_packet, required),
|
||||||
|
(1, blinded, option),
|
||||||
|
(2, short_channel_id, required),
|
||||||
|
(3, incoming_cltv_expiry, option),
|
||||||
|
},
|
||||||
|
(1, Receive) => {
|
||||||
|
(0, payment_data, required),
|
||||||
|
(1, phantom_shared_secret, option),
|
||||||
|
(2, incoming_cltv_expiry, required),
|
||||||
|
(3, payment_metadata, option),
|
||||||
|
(5, custom_tlvs, optional_vec),
|
||||||
|
(7, requires_blinded_error, (default_value, false)),
|
||||||
|
(9, payment_context, option),
|
||||||
|
},
|
||||||
|
(2, ReceiveKeysend) => {
|
||||||
|
(0, payment_preimage, required),
|
||||||
|
(1, requires_blinded_error, (default_value, false)),
|
||||||
|
(2, incoming_cltv_expiry, required),
|
||||||
|
(3, payment_metadata, option),
|
||||||
|
(4, payment_data, option), // Added in 0.0.116
|
||||||
|
(5, custom_tlvs, optional_vec),
|
||||||
|
(7, has_recipient_created_payment_secret, (default_value, false)),
|
||||||
|
(9, payment_context, option),
|
||||||
|
(11, invoice_request, option),
|
||||||
|
},
|
||||||
|
(3, TrampolineForward) => {
|
||||||
|
(0, incoming_shared_secret, required),
|
||||||
|
(2, onion_packet, required),
|
||||||
|
(4, blinded, option),
|
||||||
|
(6, node_id, required),
|
||||||
|
(8, incoming_cltv_expiry, required),
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
impl_writeable_tlv_based!(PendingHTLCInfo, {
|
impl_writeable_tlv_based!(PendingHTLCInfo, {
|
||||||
(0, routing, required),
|
(0, routing, required),
|
||||||
|
|
|
@ -403,10 +403,10 @@ impl<T: Readable> MaybeReadable for T {
|
||||||
///
|
///
|
||||||
/// This is not exported to bindings users as manual TLV building is not currently supported in bindings
|
/// This is not exported to bindings users as manual TLV building is not currently supported in bindings
|
||||||
pub struct RequiredWrapper<T>(pub Option<T>);
|
pub struct RequiredWrapper<T>(pub Option<T>);
|
||||||
impl<T: Readable> Readable for RequiredWrapper<T> {
|
impl<T: LengthReadable> LengthReadable for RequiredWrapper<T> {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn read<R: Read>(reader: &mut R) -> Result<Self, DecodeError> {
|
fn read_from_fixed_length_buffer<R: LengthRead>(reader: &mut R) -> Result<Self, DecodeError> {
|
||||||
Ok(Self(Some(Readable::read(reader)?)))
|
Ok(Self(Some(LengthReadable::read_from_fixed_length_buffer(reader)?)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl<A, T: ReadableArgs<A>> ReadableArgs<A> for RequiredWrapper<T> {
|
impl<A, T: ReadableArgs<A>> ReadableArgs<A> for RequiredWrapper<T> {
|
||||||
|
|
Loading…
Add table
Reference in a new issue