Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trampoline Payload Construction Method #3386

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
2 changes: 2 additions & 0 deletions fuzz/src/chanmon_consistency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,7 @@ fn send_payment(
maybe_announced_channel: true,
}],
blinded_tail: None,
trampoline_hops: vec![],
}],
route_params: None,
});
Expand Down Expand Up @@ -648,6 +649,7 @@ fn send_hop_payment(
},
],
blinded_tail: None,
trampoline_hops: vec![],
}],
route_params: None,
});
Expand Down
2 changes: 1 addition & 1 deletion lightning-background-processor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2540,7 +2540,7 @@ mod tests {
fee_msat: 0,
cltv_expiry_delta: MIN_CLTV_EXPIRY_DELTA as u32,
maybe_announced_channel: true,
}], blinded_tail: None };
}], trampoline_hops: vec![], blinded_tail: None };

$nodes[0].scorer.write_lock().expect(TestResult::PaymentFailure { path: path.clone(), short_channel_id: scored_scid });
$nodes[0].node.push_pending_event(Event::PaymentPathFailed {
Expand Down
19 changes: 12 additions & 7 deletions lightning/src/events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use crate::types::payment::{PaymentPreimage, PaymentHash, PaymentSecret};
use crate::offers::invoice::Bolt12Invoice;
use crate::onion_message::messenger::Responder;
use crate::routing::gossip::NetworkUpdate;
use crate::routing::router::{BlindedTail, Path, RouteHop, RouteParameters};
use crate::routing::router::{BlindedTail, Path, RouteHop, RouteParameters, TrampolineHop};
use crate::sign::SpendableOutputDescriptor;
use crate::util::errors::APIError;
use crate::util::ser::{BigSize, FixedLengthReader, Writeable, Writer, MaybeReadable, Readable, RequiredWrapper, UpgradableRequired, WithoutLength};
Expand Down Expand Up @@ -1185,12 +1185,12 @@ pub enum Event {
/// events generated or serialized by versions prior to 0.0.122.
next_user_channel_id: Option<u128>,
/// The node id of the previous node.
///
///
/// This is only `None` for HTLCs received prior to 0.1 or for events serialized by
/// versions prior to 0.1
prev_node_id: Option<PublicKey>,
/// The node id of the next node.
///
///
/// This is only `None` for HTLCs received prior to 0.1 or for events serialized by
/// versions prior to 0.1
next_node_id: Option<PublicKey>,
Expand Down Expand Up @@ -1584,6 +1584,7 @@ impl Writeable for Event {
(9, None::<RouteParameters>, option), // retry in LDK versions prior to 0.0.115
(11, payment_id, option),
(13, failure, required),
(15, path.trampoline_hops, optional_vec),
});
},
&Event::PendingHTLCsForwardable { time_forwardable: _ } => {
Expand Down Expand Up @@ -1670,6 +1671,7 @@ impl Writeable for Event {
(2, payment_hash, option),
(4, path.hops, required_vec),
(6, path.blinded_tail, option),
(8, path.trampoline_hops, optional_vec),
})
},
&Event::PaymentFailed { ref payment_id, ref payment_hash, ref reason } => {
Expand Down Expand Up @@ -1919,6 +1921,7 @@ impl MaybeReadable for Event {
let mut network_update = None;
let mut blinded_tail: Option<BlindedTail> = None;
let mut path: Option<Vec<RouteHop>> = Some(vec![]);
let mut trampoline_path: Option<Vec<TrampolineHop>> = Some(vec![]);
let mut short_channel_id = None;
let mut payment_id = None;
let mut failure_opt = None;
Expand All @@ -1933,14 +1936,15 @@ impl MaybeReadable for Event {
(7, short_channel_id, option),
(11, payment_id, option),
(13, failure_opt, upgradable_option),
(15, trampoline_path, optional_vec),
});
let failure = failure_opt.unwrap_or_else(|| PathFailure::OnPath { network_update });
Ok(Some(Event::PaymentPathFailed {
payment_id,
payment_hash,
payment_failed_permanently,
failure,
path: Path { hops: path.unwrap(), blinded_tail },
path: Path { hops: path.unwrap(), trampoline_hops: trampoline_path.unwrap_or(vec![]), blinded_tail },
short_channel_id,
#[cfg(test)]
error_code,
Expand Down Expand Up @@ -2081,11 +2085,12 @@ impl MaybeReadable for Event {
(2, payment_hash, option),
(4, path, required_vec),
(6, blinded_tail, option),
(8, trampoline_path, optional_vec),
});
Ok(Some(Event::PaymentPathSuccessful {
payment_id: payment_id.0.unwrap(),
payment_hash,
path: Path { hops: path, blinded_tail },
path: Path { hops: path, trampoline_hops: trampoline_path.unwrap_or(vec![]), blinded_tail },
}))
};
f()
Expand Down Expand Up @@ -2165,7 +2170,7 @@ impl MaybeReadable for Event {
Ok(Some(Event::ProbeSuccessful {
payment_id: payment_id.0.unwrap(),
payment_hash: payment_hash.0.unwrap(),
path: Path { hops: path, blinded_tail },
path: Path { hops: path, trampoline_hops: vec![], blinded_tail },
}))
};
f()
Expand All @@ -2182,7 +2187,7 @@ impl MaybeReadable for Event {
Ok(Some(Event::ProbeFailed {
payment_id: payment_id.0.unwrap(),
payment_hash: payment_hash.0.unwrap(),
path: Path { hops: path, blinded_tail },
path: Path { hops: path, trampoline_hops: vec![], blinded_tail },
short_channel_id,
}))
};
Expand Down
4 changes: 3 additions & 1 deletion lightning/src/ln/blinded_payment_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1505,11 +1505,13 @@ fn route_blinding_spec_test_vector() {
cltv_expiry_delta: 42,
maybe_announced_channel: false,
}],
trampoline_hops: vec![],
blinded_tail: Some(BlindedTail {
hops: blinded_hops,
blinding_point: bob_blinding_point,
excess_final_cltv_expiry_delta: 0,
final_value_msat: amt_msat
final_value_msat: amt_msat,
final_hop_supports_trampoline: false
}),
};
let cur_height = 747_000;
Expand Down
3 changes: 2 additions & 1 deletion lightning/src/ln/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10378,7 +10378,7 @@ mod tests {
cltv_expiry: 200000000,
state: OutboundHTLCState::Committed,
source: HTLCSource::OutboundRoute {
path: Path { hops: Vec::new(), blinded_tail: None },
path: Path { hops: Vec::new(), trampoline_hops: vec![], blinded_tail: None },
session_priv: SecretKey::from_slice(&<Vec<u8>>::from_hex("0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").unwrap()[..]).unwrap(),
first_hop_htlc_msat: 548,
payment_id: PaymentId([42; 32]),
Expand Down Expand Up @@ -10754,6 +10754,7 @@ mod tests {
node_features: NodeFeatures::empty(), short_channel_id: 0, fee_msat: 0,
cltv_expiry_delta: 0, maybe_announced_channel: false,
}],
trampoline_hops: vec![],
blinded_tail: None
},
session_priv: test_utils::privkey(42),
Expand Down
4 changes: 2 additions & 2 deletions lightning/src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ impl HTLCSource {
pub fn dummy() -> Self {
assert!(cfg!(not(feature = "grind_signatures")));
HTLCSource::OutboundRoute {
path: Path { hops: Vec::new(), blinded_tail: None },
path: Path { hops: Vec::new(), trampoline_hops: Vec::new(), blinded_tail: None },
session_priv: SecretKey::from_slice(&[1; 32]).unwrap(),
first_hop_htlc_msat: 0,
payment_id: PaymentId([2; 32]),
Expand Down Expand Up @@ -12575,7 +12575,7 @@ impl Readable for HTLCSource {
// instead.
payment_id = Some(PaymentId(*session_priv.0.unwrap().as_ref()));
}
let path = Path { hops: path_hops, blinded_tail };
let path = Path { hops: path_hops, trampoline_hops: vec![], blinded_tail };
if path.hops.len() == 0 {
return Err(DecodeError::InvalidValue);
}
Expand Down
4 changes: 2 additions & 2 deletions lightning/src/ln/functional_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1097,7 +1097,7 @@ fn fake_network_test() {
).with_bolt11_features(nodes[1].node.bolt11_invoice_features()).unwrap();
let route_params = RouteParameters::from_payment_params_and_value(payment_params, 1000000);
let payment_preimage_1 = send_along_route(&nodes[1],
Route { paths: vec![Path { hops, blinded_tail: None }], route_params: Some(route_params.clone()) },
Route { paths: vec![Path { hops, trampoline_hops: vec![], blinded_tail: None }], route_params: Some(route_params.clone()) },
&vec!(&nodes[2], &nodes[3], &nodes[1])[..], 1000000).0;

let mut hops = Vec::with_capacity(3);
Expand Down Expand Up @@ -1131,7 +1131,7 @@ fn fake_network_test() {
hops[1].fee_msat = chan_2.1.contents.fee_base_msat as u64 + chan_2.1.contents.fee_proportional_millionths as u64 * hops[2].fee_msat as u64 / 1000000;
hops[0].fee_msat = chan_3.1.contents.fee_base_msat as u64 + chan_3.1.contents.fee_proportional_millionths as u64 * hops[1].fee_msat as u64 / 1000000;
let payment_hash_2 = send_along_route(&nodes[1],
Route { paths: vec![Path { hops, blinded_tail: None }], route_params: Some(route_params) },
Route { paths: vec![Path { hops, trampoline_hops: vec![], blinded_tail: None }], route_params: Some(route_params) },
&vec!(&nodes[3], &nodes[2], &nodes[1])[..], 1000000).1;

// Claim the rebalances...
Expand Down
4 changes: 0 additions & 4 deletions lightning/src/ln/msgs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1801,7 +1801,6 @@ mod fuzzy_internal_msgs {
amt_to_forward: u64,
outgoing_cltv_value: u32,
},
#[allow(unused)]
TrampolineEntrypoint {
amt_to_forward: u64,
outgoing_cltv_value: u32,
Expand Down Expand Up @@ -1833,7 +1832,6 @@ mod fuzzy_internal_msgs {
}

pub(crate) enum OutboundTrampolinePayload<'a> {
#[allow(unused)]
Forward {
/// The value, in msat, of the payment after this hop's fee is deducted.
amt_to_forward: u64,
Expand All @@ -1853,12 +1851,10 @@ mod fuzzy_internal_msgs {
/// If applicable, features of the BOLT12 invoice being paid.
invoice_features: Option<Bolt12InvoiceFeatures>,
},
#[allow(unused)]
BlindedForward {
encrypted_tlvs: &'a Vec<u8>,
intro_node_blinding_point: Option<PublicKey>,
},
#[allow(unused)]
BlindedReceive {
sender_intended_htlc_amt_msat: u64,
total_msat: u64,
Expand Down
3 changes: 2 additions & 1 deletion lightning/src/ln/onion_payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ mod tests {
// Ensure the onion will not fit all the payloads by adding a large custom TLV.
recipient_onion.custom_tlvs.push((13377331, vec![0; 1156]));

let path = Path { hops, blinded_tail: None, };
let path = Path { hops, trampoline_hops: vec![], blinded_tail: None, };
let onion_keys = super::onion_utils::construct_onion_keys(&secp_ctx, &path, &session_priv).unwrap();
let (onion_payloads, ..) = super::onion_utils::build_onion_payloads(
&path, total_amt_msat, &recipient_onion, cur_height + 1, &Some(keysend_preimage), None
Expand All @@ -558,6 +558,7 @@ mod tests {

let path = Path {
hops: hops,
trampoline_hops: vec![],
blinded_tail: None,
};

Expand Down
Loading
Loading