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

Calculate Trampoline onion packet sizes dynamically. #3333

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
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 @@ -646,6 +647,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
8 changes: 4 additions & 4 deletions lightning/src/events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1894,7 +1894,7 @@ impl MaybeReadable for Event {
payment_hash,
payment_failed_permanently,
failure,
path: Path { hops: path.unwrap(), blinded_tail },
path: Path { hops: path.unwrap(), trampoline_hops: vec![], blinded_tail },
short_channel_id,
#[cfg(test)]
error_code,
Expand Down Expand Up @@ -2034,7 +2034,7 @@ impl MaybeReadable for Event {
Ok(Some(Event::PaymentPathSuccessful {
payment_id: payment_id.0.unwrap(),
payment_hash,
path: Path { hops: path, blinded_tail },
path: Path { hops: path, trampoline_hops: vec![], blinded_tail },
}))
};
f()
Expand Down Expand Up @@ -2114,7 +2114,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 @@ -2131,7 +2131,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 @@ -1439,11 +1439,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 @@ -9835,7 +9835,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 @@ -10211,6 +10211,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 @@ -639,7 +639,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 @@ -11667,7 +11667,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
16 changes: 8 additions & 8 deletions lightning/src/ln/functional_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1093,7 +1093,7 @@ fn fake_network_test() {
hops[1].fee_msat = chan_4.1.contents.fee_base_msat as u64 + chan_4.1.contents.fee_proportional_millionths as u64 * hops[2].fee_msat as u64 / 1000000;
hops[0].fee_msat = chan_3.0.contents.fee_base_msat as u64 + chan_3.0.contents.fee_proportional_millionths as u64 * hops[1].fee_msat as u64 / 1000000;
let payment_preimage_1 = send_along_route(&nodes[1],
Route { paths: vec![Path { hops, blinded_tail: None }], route_params: None },
Route { paths: vec![Path { hops, trampoline_hops: vec![], blinded_tail: None }], route_params: None },
&vec!(&nodes[2], &nodes[3], &nodes[1])[..], 1000000).0;

let mut hops = Vec::with_capacity(3);
Expand Down Expand Up @@ -1127,7 +1127,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: None },
Route { paths: vec![Path { hops, trampoline_hops: vec![], blinded_tail: None }], route_params: None },
&vec!(&nodes[3], &nodes[2], &nodes[1])[..], 1000000).1;

// Claim the rebalances...
Expand Down Expand Up @@ -1437,7 +1437,7 @@ fn test_fee_spike_violation_fails_htlc() {

let onion_keys = onion_utils::construct_onion_keys(&secp_ctx, &route.paths[0], &session_priv).unwrap();
let recipient_onion_fields = RecipientOnionFields::secret_only(payment_secret);
let (onion_payloads, htlc_msat, htlc_cltv) = onion_utils::build_onion_payloads(&route.paths[0],
let (onion_payloads, _, htlc_msat, htlc_cltv) = onion_utils::build_onion_payloads(&route.paths[0],
3460001, &recipient_onion_fields, cur_height, &None).unwrap();
let onion_packet = onion_utils::construct_onion_packet(onion_payloads, onion_keys, [0; 32], &payment_hash).unwrap();
let msg = msgs::UpdateAddHTLC {
Expand Down Expand Up @@ -1636,7 +1636,7 @@ fn test_chan_reserve_violation_inbound_htlc_outbound_channel() {
let cur_height = nodes[1].node.best_block.read().unwrap().height + 1;
let onion_keys = onion_utils::construct_onion_keys(&secp_ctx, &route.paths[0], &session_priv).unwrap();
let recipient_onion_fields = RecipientOnionFields::secret_only(payment_secret);
let (onion_payloads, htlc_msat, htlc_cltv) = onion_utils::build_onion_payloads(&route.paths[0],
let (onion_payloads, _, htlc_msat, htlc_cltv) = onion_utils::build_onion_payloads(&route.paths[0],
700_000, &recipient_onion_fields, cur_height, &None).unwrap();
let onion_packet = onion_utils::construct_onion_packet(onion_payloads, onion_keys, [0; 32], &payment_hash).unwrap();
let msg = msgs::UpdateAddHTLC {
Expand Down Expand Up @@ -1816,7 +1816,7 @@ fn test_chan_reserve_violation_inbound_htlc_inbound_chan() {
let cur_height = nodes[0].node.best_block.read().unwrap().height + 1;
let onion_keys = onion_utils::construct_onion_keys(&secp_ctx, &route_2.paths[0], &session_priv).unwrap();
let recipient_onion_fields = RecipientOnionFields::spontaneous_empty();
let (onion_payloads, htlc_msat, htlc_cltv) = onion_utils::build_onion_payloads(
let (onion_payloads, _, htlc_msat, htlc_cltv) = onion_utils::build_onion_payloads(
&route_2.paths[0], recv_value_2, &recipient_onion_fields, cur_height, &None).unwrap();
let onion_packet = onion_utils::construct_onion_packet(onion_payloads, onion_keys, [0; 32], &our_payment_hash_1).unwrap();
let msg = msgs::UpdateAddHTLC {
Expand Down Expand Up @@ -3555,7 +3555,7 @@ fn fail_backward_pending_htlc_upon_channel_failure() {
let session_priv = SecretKey::from_slice(&[42; 32]).unwrap();
let current_height = nodes[1].node.best_block.read().unwrap().height + 1;
let recipient_onion_fields = RecipientOnionFields::secret_only(payment_secret);
let (onion_payloads, _amount_msat, cltv_expiry) = onion_utils::build_onion_payloads(
let (onion_payloads, __trampoline_payloads, amount_msat, cltv_expiry) = onion_utils::build_onion_payloads(
&route.paths[0], 50_000, &recipient_onion_fields, current_height, &None).unwrap();
let onion_keys = onion_utils::construct_onion_keys(&secp_ctx, &route.paths[0], &session_priv).unwrap();
let onion_routing_packet = onion_utils::construct_onion_packet(onion_payloads, onion_keys, [0; 32], &payment_hash).unwrap();
Expand Down Expand Up @@ -6547,7 +6547,7 @@ fn test_update_add_htlc_bolt2_receiver_check_max_htlc_limit() {
let cur_height = nodes[0].node.best_block.read().unwrap().height + 1;
let onion_keys = onion_utils::construct_onion_keys(&Secp256k1::signing_only(), &route.paths[0], &session_priv).unwrap();
let recipient_onion_fields = RecipientOnionFields::secret_only(our_payment_secret);
let (onion_payloads, _htlc_msat, htlc_cltv) = onion_utils::build_onion_payloads(
let (onion_payloads, _trampoline_payloads, _htlc_msat, htlc_cltv) = onion_utils::build_onion_payloads(
&route.paths[0], send_amt, &recipient_onion_fields, cur_height, &None).unwrap();
let onion_packet = onion_utils::construct_onion_packet(onion_payloads, onion_keys, [0; 32], &our_payment_hash).unwrap();

Expand Down Expand Up @@ -8290,7 +8290,7 @@ fn test_onion_value_mpp_set_calculation() {
let session_priv = SecretKey::from_slice(&session_priv).unwrap();
let mut onion_keys = onion_utils::construct_onion_keys(&Secp256k1::new(), &route.paths[0], &session_priv).unwrap();
let recipient_onion_fields = RecipientOnionFields::secret_only(our_payment_secret);
let (mut onion_payloads, _, _) = onion_utils::build_onion_payloads(&route.paths[0], 100_000,
let (mut onion_payloads, _, _, _) = onion_utils::build_onion_payloads(&route.paths[0], 100_000,
&recipient_onion_fields, height + 1, &None).unwrap();
// Edit amt_to_forward to simulate the sender having set
// the final amount and the routing node taking less fee
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 @@ -538,7 +538,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)
Expand All @@ -564,6 +564,7 @@ mod tests {

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

Expand Down
10 changes: 5 additions & 5 deletions lightning/src/ln/onion_route_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ fn test_onion_failure() {
let cur_height = nodes[0].best_block_info().1 + 1;
let onion_keys = onion_utils::construct_onion_keys(&Secp256k1::new(), &route.paths[0], &session_priv).unwrap();
let recipient_onion_fields = RecipientOnionFields::spontaneous_empty();
let (mut onion_payloads, _htlc_msat, _htlc_cltv) = onion_utils::build_onion_payloads(
let (mut onion_payloads, _trampoline_payloads, _htlc_msat, _htlc_cltv) = onion_utils::build_onion_payloads(
&route.paths[0], 40000, &recipient_onion_fields, cur_height, &None).unwrap();
let mut new_payloads = Vec::new();
for payload in onion_payloads.drain(..) {
Expand All @@ -374,7 +374,7 @@ fn test_onion_failure() {
let cur_height = nodes[0].best_block_info().1 + 1;
let onion_keys = onion_utils::construct_onion_keys(&Secp256k1::new(), &route.paths[0], &session_priv).unwrap();
let recipient_onion_fields = RecipientOnionFields::spontaneous_empty();
let (mut onion_payloads, _htlc_msat, _htlc_cltv) = onion_utils::build_onion_payloads(
let (mut onion_payloads, _trampoline_payloads, _htlc_msat, _htlc_cltv) = onion_utils::build_onion_payloads(
&route.paths[0], 40000, &recipient_onion_fields, cur_height, &None).unwrap();
let mut new_payloads = Vec::new();
for payload in onion_payloads.drain(..) {
Expand Down Expand Up @@ -626,7 +626,7 @@ fn test_onion_failure() {
route.paths[0].hops[1].cltv_expiry_delta += CLTV_FAR_FAR_AWAY + route.paths[0].hops[0].cltv_expiry_delta + 1;
let onion_keys = onion_utils::construct_onion_keys(&Secp256k1::new(), &route.paths[0], &session_priv).unwrap();
let recipient_onion_fields = RecipientOnionFields::spontaneous_empty();
let (onion_payloads, _, htlc_cltv) = onion_utils::build_onion_payloads(
let (onion_payloads, _, _, htlc_cltv) = onion_utils::build_onion_payloads(
&route.paths[0], 40000, &recipient_onion_fields, height, &None).unwrap();
let onion_packet = onion_utils::construct_onion_packet(onion_payloads, onion_keys, [0; 32], &payment_hash).unwrap();
msg.cltv_expiry = htlc_cltv;
Expand Down Expand Up @@ -963,7 +963,7 @@ fn test_always_create_tlv_format_onion_payloads() {

let cur_height = nodes[0].best_block_info().1 + 1;
let recipient_onion_fields = RecipientOnionFields::spontaneous_empty();
let (onion_payloads, _htlc_msat, _htlc_cltv) = onion_utils::build_onion_payloads(
let (onion_payloads, _trampoline_payloads, _htlc_msat, _htlc_cltv) = onion_utils::build_onion_payloads(
&route.paths[0], 40000, &recipient_onion_fields, cur_height, &None).unwrap();

match onion_payloads[0] {
Expand Down Expand Up @@ -1219,7 +1219,7 @@ fn test_phantom_invalid_onion_payload() {
let session_priv = SecretKey::from_slice(&session_priv).unwrap();
let mut onion_keys = onion_utils::construct_onion_keys(&Secp256k1::new(), &route.paths[0], &session_priv).unwrap();
let recipient_onion_fields = RecipientOnionFields::secret_only(payment_secret);
let (mut onion_payloads, _, _) = onion_utils::build_onion_payloads(
let (mut onion_payloads, _, _, _) = onion_utils::build_onion_payloads(
&route.paths[0], msgs::MAX_VALUE_MSAT + 1,
&recipient_onion_fields, height + 1, &None).unwrap();
// We only want to construct the onion packet for the last hop, not the entire route, so
Expand Down
Loading