Skip to content

Commit fa2c4c5

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 91f5296 commit fa2c4c5

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
@@ -2649,6 +2649,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
26492649
let outbound_payment = match source {
26502650
None => panic!("Outbound HTLCs should have a source"),
26512651
Some(&HTLCSource::PreviousHopData(_)) => false,
2652+
Some(&HTLCSource::TrampolineForward { .. }) => false,
26522653
Some(&HTLCSource::OutboundRoute { .. }) => true,
26532654
};
26542655
return Some(Balance::MaybeTimeoutClaimableHTLC {
@@ -2858,6 +2859,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitor<Signer> {
28582859
let outbound_payment = match source {
28592860
None => panic!("Outbound HTLCs should have a source"),
28602861
Some(HTLCSource::PreviousHopData(_)) => false,
2862+
Some(&HTLCSource::TrampolineForward { .. }) => false,
28612863
Some(HTLCSource::OutboundRoute { .. }) => true,
28622864
};
28632865
if outbound_payment {

lightning/src/ln/channelmanager.rs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,7 @@ impl SentHTLCId {
653653
short_channel_id: hop_data.short_channel_id,
654654
htlc_id: hop_data.htlc_id,
655655
},
656+
HTLCSource::TrampolineForward { .. } => todo!(),
656657
HTLCSource::OutboundRoute { session_priv, .. } => {
657658
Self::OutboundRoute { session_priv: session_priv.secret_bytes() }
658659
},
@@ -676,13 +677,25 @@ type PerSourcePendingForward =
676677
type FailedHTLCForward = (HTLCSource, PaymentHash, HTLCFailReason, HTLCHandlingFailureType);
677678

678679
mod fuzzy_channelmanager {
680+
use crate::routing::router::RouteHop;
681+
679682
use super::*;
680683

681684
/// Tracks the inbound corresponding to an outbound HTLC
682685
#[allow(clippy::derive_hash_xor_eq)] // Our Hash is faithful to the data, we just don't have SecretKey::hash
683686
#[derive(Clone, Debug, PartialEq, Eq)]
684687
pub enum HTLCSource {
685688
PreviousHopData(HTLCPreviousHopData),
689+
TrampolineForward {
690+
/// We might be forwarding an incoming payment that was received over MPP, and therefore
691+
/// need to store the vector of corresponding `HTLCPreviousHopId` values.
692+
previous_hop_data: Vec<HTLCPreviousHopData>,
693+
incoming_trampoline_shared_secret: [u8; 32],
694+
hops: Vec<RouteHop>,
695+
/// In order to decode inter-Trampoline errors, we need to store the session_priv key
696+
/// given we're effectively creating new outbound routes.
697+
session_priv: SecretKey,
698+
},
686699
OutboundRoute {
687700
path: Path,
688701
session_priv: SecretKey,
@@ -745,6 +758,18 @@ impl core::hash::Hash for HTLCSource {
745758
first_hop_htlc_msat.hash(hasher);
746759
bolt12_invoice.hash(hasher);
747760
},
761+
HTLCSource::TrampolineForward {
762+
previous_hop_data,
763+
incoming_trampoline_shared_secret,
764+
hops,
765+
session_priv,
766+
} => {
767+
2u8.hash(hasher);
768+
previous_hop_data.hash(hasher);
769+
incoming_trampoline_shared_secret.hash(hasher);
770+
hops.hash(hasher);
771+
session_priv[..].hash(hasher);
772+
},
748773
}
749774
}
750775
}
@@ -7944,6 +7969,7 @@ where
79447969
None,
79457970
));
79467971
},
7972+
HTLCSource::TrampolineForward { .. } => todo!(),
79477973
}
79487974
}
79497975

@@ -8661,6 +8687,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
86618687
},
86628688
);
86638689
},
8690+
HTLCSource::TrampolineForward { .. } => todo!(),
86648691
}
86658692
}
86668693

@@ -14952,6 +14979,24 @@ impl Readable for HTLCSource {
1495214979
})
1495314980
}
1495414981
1 => Ok(HTLCSource::PreviousHopData(Readable::read(reader)?)),
14982+
2 => {
14983+
let mut previous_hop_data = Vec::new();
14984+
let mut incoming_trampoline_shared_secret: crate::util::ser::RequiredWrapper<[u8; 32]> = crate::util::ser::RequiredWrapper(None);
14985+
let mut session_priv: crate::util::ser::RequiredWrapper<SecretKey> = crate::util::ser::RequiredWrapper(None);
14986+
let mut hops = Vec::new();
14987+
read_tlv_fields!(reader, {
14988+
(0, previous_hop_data, required_vec),
14989+
(2, incoming_trampoline_shared_secret, required),
14990+
(4, session_priv, required),
14991+
(6, hops, required_vec),
14992+
});
14993+
Ok(HTLCSource::TrampolineForward {
14994+
previous_hop_data,
14995+
incoming_trampoline_shared_secret: incoming_trampoline_shared_secret.0.unwrap(),
14996+
hops,
14997+
session_priv: session_priv.0.unwrap(),
14998+
})
14999+
},
1495515000
_ => Err(DecodeError::UnknownRequiredFeature),
1495615001
}
1495715002
}
@@ -14984,6 +15029,22 @@ impl Writeable for HTLCSource {
1498415029
1u8.write(writer)?;
1498515030
field.write(writer)?;
1498615031
},
15032+
HTLCSource::TrampolineForward {
15033+
previous_hop_data: previous_hop_data_ref,
15034+
ref incoming_trampoline_shared_secret,
15035+
ref session_priv,
15036+
hops: hops_ref,
15037+
} => {
15038+
2u8.write(writer)?;
15039+
let previous_hop_data = previous_hop_data_ref.clone();
15040+
let hops = hops_ref.clone();
15041+
write_tlv_fields!(writer, {
15042+
(0, previous_hop_data, required_vec),
15043+
(2, incoming_trampoline_shared_secret, required),
15044+
(4, session_priv, required),
15045+
(6, hops, required_vec),
15046+
});
15047+
},
1498715048
}
1498815049
Ok(())
1498915050
}
@@ -16427,6 +16488,7 @@ where
1642716488
} else { true }
1642816489
});
1642916490
},
16491+
HTLCSource::TrampolineForward { .. } => todo!(),
1643016492
HTLCSource::OutboundRoute {
1643116493
payment_id,
1643216494
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);
@@ -1086,6 +1087,7 @@ impl_for_vec!(NegotiatedTxInput);
10861087
impl_for_vec!(InteractiveTxOutput);
10871088
impl_writeable_for_vec!(&crate::routing::router::BlindedTail);
10881089
impl_readable_for_vec!(crate::routing::router::BlindedTail);
1090+
impl_for_vec!(crate::routing::router::RouteHop);
10891091
impl_for_vec!(crate::routing::router::TrampolineHop);
10901092
impl_for_vec_with_element_length_prefix!(crate::ln::msgs::UpdateAddHTLC);
10911093
impl_writeable_for_vec_with_element_length_prefix!(&crate::ln::msgs::UpdateAddHTLC);

0 commit comments

Comments
 (0)