Skip to content

Commit df49139

Browse files
committed
Add TrampolineForward variant to HTLCSource enum
Add new HTLCSource::TrampolineForward variant to track trampoline routing information. Implement hash trait and serialization for the new variant.
1 parent cfbade2 commit df49139

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2726,6 +2726,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
27262726
let outbound_payment = match source {
27272727
None => panic!("Outbound HTLCs should have a source"),
27282728
Some(&HTLCSource::PreviousHopData(_)) => false,
2729+
Some(&HTLCSource::TrampolineForward { .. }) => false,
27292730
Some(&HTLCSource::OutboundRoute { .. }) => true,
27302731
};
27312732
return Some(Balance::MaybeTimeoutClaimableHTLC {
@@ -2935,6 +2936,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
29352936
let outbound_payment = match source {
29362937
None => panic!("Outbound HTLCs should have a source"),
29372938
Some(HTLCSource::PreviousHopData(_)) => false,
2939+
Some(&HTLCSource::TrampolineForward { .. }) => false,
29382940
Some(HTLCSource::OutboundRoute { .. }) => true,
29392941
};
29402942
if outbound_payment {

lightning/src/ln/channelmanager.rs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,7 @@ impl SentHTLCId {
646646
short_channel_id: hop_data.short_channel_id,
647647
htlc_id: hop_data.htlc_id,
648648
},
649+
HTLCSource::TrampolineForward { .. } => todo!(),
649650
HTLCSource::OutboundRoute { session_priv, .. } => {
650651
Self::OutboundRoute { session_priv: session_priv.secret_bytes() }
651652
},
@@ -669,13 +670,25 @@ type PerSourcePendingForward =
669670
type FailedHTLCForward = (HTLCSource, PaymentHash, HTLCFailReason, HTLCHandlingFailureType);
670671

671672
mod fuzzy_channelmanager {
673+
use crate::routing::router::RouteHop;
674+
672675
use super::*;
673676

674677
/// Tracks the inbound corresponding to an outbound HTLC
675678
#[allow(clippy::derive_hash_xor_eq)] // Our Hash is faithful to the data, we just don't have SecretKey::hash
676679
#[derive(Clone, Debug, PartialEq, Eq)]
677680
pub enum HTLCSource {
678681
PreviousHopData(HTLCPreviousHopData),
682+
TrampolineForward {
683+
/// We might be forwarding an incoming payment that was received over MPP, and therefore
684+
/// need to store the vector of corresponding `HTLCPreviousHopId` values.
685+
previous_hop_data: Vec<HTLCPreviousHopData>,
686+
incoming_trampoline_shared_secret: [u8; 32],
687+
hops: Vec<RouteHop>,
688+
/// In order to decode inter-Trampoline errors, we need to store the session_priv key
689+
/// given we're effectively creating new outbound routes.
690+
session_priv: SecretKey,
691+
},
679692
OutboundRoute {
680693
path: Path,
681694
session_priv: SecretKey,
@@ -738,6 +751,18 @@ impl core::hash::Hash for HTLCSource {
738751
first_hop_htlc_msat.hash(hasher);
739752
bolt12_invoice.hash(hasher);
740753
},
754+
HTLCSource::TrampolineForward {
755+
previous_hop_data,
756+
incoming_trampoline_shared_secret,
757+
hops,
758+
session_priv,
759+
} => {
760+
2u8.hash(hasher);
761+
previous_hop_data.hash(hasher);
762+
incoming_trampoline_shared_secret.hash(hasher);
763+
hops.hash(hasher);
764+
session_priv[..].hash(hasher);
765+
},
741766
}
742767
}
743768
}
@@ -8050,6 +8075,7 @@ where
80508075
None,
80518076
));
80528077
},
8078+
HTLCSource::TrampolineForward { .. } => todo!(),
80538079
}
80548080
}
80558081

@@ -8767,6 +8793,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
87678793
},
87688794
);
87698795
},
8796+
HTLCSource::TrampolineForward { .. } => todo!(),
87708797
}
87718798
}
87728799

@@ -15064,6 +15091,24 @@ impl Readable for HTLCSource {
1506415091
})
1506515092
}
1506615093
1 => Ok(HTLCSource::PreviousHopData(Readable::read(reader)?)),
15094+
2 => {
15095+
let mut previous_hop_data = Vec::new();
15096+
let mut incoming_trampoline_shared_secret: crate::util::ser::RequiredWrapper<[u8; 32]> = crate::util::ser::RequiredWrapper(None);
15097+
let mut session_priv: crate::util::ser::RequiredWrapper<SecretKey> = crate::util::ser::RequiredWrapper(None);
15098+
let mut hops = Vec::new();
15099+
read_tlv_fields!(reader, {
15100+
(0, previous_hop_data, required_vec),
15101+
(2, incoming_trampoline_shared_secret, required),
15102+
(4, session_priv, required),
15103+
(6, hops, required_vec),
15104+
});
15105+
Ok(HTLCSource::TrampolineForward {
15106+
previous_hop_data,
15107+
incoming_trampoline_shared_secret: incoming_trampoline_shared_secret.0.unwrap(),
15108+
hops,
15109+
session_priv: session_priv.0.unwrap(),
15110+
})
15111+
},
1506715112
_ => Err(DecodeError::UnknownRequiredFeature),
1506815113
}
1506915114
}
@@ -15096,6 +15141,22 @@ impl Writeable for HTLCSource {
1509615141
1u8.write(writer)?;
1509715142
field.write(writer)?;
1509815143
},
15144+
HTLCSource::TrampolineForward {
15145+
previous_hop_data: previous_hop_data_ref,
15146+
ref incoming_trampoline_shared_secret,
15147+
ref session_priv,
15148+
hops: hops_ref,
15149+
} => {
15150+
2u8.write(writer)?;
15151+
let previous_hop_data = previous_hop_data_ref.clone();
15152+
let hops = hops_ref.clone();
15153+
write_tlv_fields!(writer, {
15154+
(0, previous_hop_data, required_vec),
15155+
(2, incoming_trampoline_shared_secret, required),
15156+
(4, session_priv, required),
15157+
(6, hops, required_vec),
15158+
});
15159+
},
1509915160
}
1510015161
Ok(())
1510115162
}
@@ -16539,6 +16600,7 @@ where
1653916600
} else { true }
1654016601
});
1654116602
},
16603+
HTLCSource::TrampolineForward { .. } => todo!(),
1654216604
HTLCSource::OutboundRoute {
1654316605
payment_id,
1654416606
session_priv,

lightning/src/util/ser.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,6 +1077,7 @@ impl Readable for Vec<u8> {
10771077

10781078
impl_for_vec!(ecdsa::Signature);
10791079
impl_for_vec!(crate::chain::channelmonitor::ChannelMonitorUpdate);
1080+
impl_for_vec!(crate::ln::channelmanager::HTLCPreviousHopData);
10801081
impl_for_vec!(crate::ln::channelmanager::MonitorUpdateCompletionAction);
10811082
impl_for_vec!(crate::ln::channelmanager::PaymentClaimDetails);
10821083
impl_for_vec!(crate::ln::msgs::SocketAddress);
@@ -1087,6 +1088,7 @@ impl_for_vec!(InteractiveTxOutput);
10871088
impl_for_vec!(crate::ln::our_peer_storage::PeerStorageMonitorHolder);
10881089
impl_writeable_for_vec!(&crate::routing::router::BlindedTail);
10891090
impl_readable_for_vec!(crate::routing::router::BlindedTail);
1091+
impl_for_vec!(crate::routing::router::RouteHop);
10901092
impl_for_vec!(crate::routing::router::TrampolineHop);
10911093
impl_for_vec_with_element_length_prefix!(crate::ln::msgs::UpdateAddHTLC);
10921094
impl_writeable_for_vec_with_element_length_prefix!(&crate::ln::msgs::UpdateAddHTLC);

0 commit comments

Comments
 (0)