Copy Payee into Routes to provide them to ChannelManager

This commit is contained in:
Matt Corallo 2021-10-25 04:42:29 +00:00
parent 87da91042e
commit fe237f9280
4 changed files with 27 additions and 8 deletions

View file

@ -305,6 +305,7 @@ fn send_payment(source: &ChanMan, dest: &ChanMan, dest_chan_id: u64, amt: u64, p
fee_msat: amt, fee_msat: amt,
cltv_expiry_delta: 200, cltv_expiry_delta: 200,
}]], }]],
payee: None,
}, payment_hash, &Some(payment_secret)) { }, payment_hash, &Some(payment_secret)) {
check_payment_err(err); check_payment_err(err);
false false
@ -330,6 +331,7 @@ fn send_hop_payment(source: &ChanMan, middle: &ChanMan, middle_chan_id: u64, des
fee_msat: amt, fee_msat: amt,
cltv_expiry_delta: 200, cltv_expiry_delta: 200,
}]], }]],
payee: None,
}, payment_hash, &Some(payment_secret)) { }, payment_hash, &Some(payment_secret)) {
check_payment_err(err); check_payment_err(err);
false false

View file

@ -919,7 +919,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[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; 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![hops] }, &vec!(&nodes[2], &nodes[3], &nodes[1])[..], 1000000).0; let payment_preimage_1 = send_along_route(&nodes[1], Route { paths: vec![hops], payee: None }, &vec!(&nodes[2], &nodes[3], &nodes[1])[..], 1000000).0;
let mut hops = Vec::with_capacity(3); let mut hops = Vec::with_capacity(3);
hops.push(RouteHop { hops.push(RouteHop {
@ -948,7 +948,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[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; 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![hops] }, &vec!(&nodes[3], &nodes[2], &nodes[1])[..], 1000000).1; let payment_hash_2 = send_along_route(&nodes[1], Route { paths: vec![hops], payee: None }, &vec!(&nodes[3], &nodes[2], &nodes[1])[..], 1000000).1;
// Claim the rebalances... // Claim the rebalances...
fail_payment(&nodes[1], &vec!(&nodes[3], &nodes[2], &nodes[1])[..], payment_hash_2); fail_payment(&nodes[1], &vec!(&nodes[3], &nodes[2], &nodes[1])[..], payment_hash_2);

View file

@ -555,6 +555,7 @@ mod tests {
short_channel_id: 0, fee_msat: 0, cltv_expiry_delta: 0 // Test vectors are garbage and not generateble from a RouteHop, we fill in payloads manually short_channel_id: 0, fee_msat: 0, cltv_expiry_delta: 0 // Test vectors are garbage and not generateble from a RouteHop, we fill in payloads manually
}, },
]], ]],
payee: None,
}; };
let session_priv = SecretKey::from_slice(&hex::decode("4141414141414141414141414141414141414141414141414141414141414141").unwrap()[..]).unwrap(); let session_priv = SecretKey::from_slice(&hex::decode("4141414141414141414141414141414141414141414141414141414141414141").unwrap()[..]).unwrap();

View file

@ -70,6 +70,12 @@ pub struct Route {
/// given path is variable, keeping the length of any path to less than 20 should currently /// given path is variable, keeping the length of any path to less than 20 should currently
/// ensure it is viable. /// ensure it is viable.
pub paths: Vec<Vec<RouteHop>>, pub paths: Vec<Vec<RouteHop>>,
/// The `payee` parameter passed to [`get_route`].
/// This is used by `ChannelManager` to track information which may be required for retries,
/// provided back to you via [`Event::PaymentPathFailed`].
///
/// [`Event::PaymentPathFailed`]: crate::util::events::Event::PaymentPathFailed
pub payee: Option<Payee>,
} }
impl Route { impl Route {
@ -106,7 +112,9 @@ impl Writeable for Route {
hop.write(writer)?; hop.write(writer)?;
} }
} }
write_tlv_fields!(writer, {}); write_tlv_fields!(writer, {
(1, self.payee, option),
});
Ok(()) Ok(())
} }
} }
@ -124,8 +132,11 @@ impl Readable for Route {
} }
paths.push(hops); paths.push(hops);
} }
read_tlv_fields!(reader, {}); let mut payee = None;
Ok(Route { paths }) read_tlv_fields!(reader, {
(1, payee, option),
});
Ok(Route { paths, payee })
} }
} }
@ -153,7 +164,7 @@ impl_writeable_tlv_based!(PaymentPathRetry, {
}); });
/// The recipient of a payment. /// The recipient of a payment.
#[derive(Clone, Debug)] #[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub struct Payee { pub struct Payee {
/// The node id of the payee. /// The node id of the payee.
pub pubkey: PublicKey, pub pubkey: PublicKey,
@ -1442,7 +1453,10 @@ where L::Target: Logger {
} }
} }
let route = Route { paths: selected_paths.into_iter().map(|path| path.into_iter().collect()).collect::<Result<Vec<_>, _>>()? }; let route = Route {
paths: selected_paths.into_iter().map(|path| path.into_iter().collect()).collect::<Result<Vec<_>, _>>()?,
payee: Some(payee.clone()),
};
log_info!(logger, "Got route to {}: {}", payee.pubkey, log_route!(route)); log_info!(logger, "Got route to {}: {}", payee.pubkey, log_route!(route));
Ok(route) Ok(route)
} }
@ -4600,6 +4614,7 @@ mod tests {
short_channel_id: 0, fee_msat: 225, cltv_expiry_delta: 0 short_channel_id: 0, fee_msat: 225, cltv_expiry_delta: 0
}, },
]], ]],
payee: None,
}; };
assert_eq!(route.get_total_fees(), 250); assert_eq!(route.get_total_fees(), 250);
@ -4632,6 +4647,7 @@ mod tests {
short_channel_id: 0, fee_msat: 150, cltv_expiry_delta: 0 short_channel_id: 0, fee_msat: 150, cltv_expiry_delta: 0
}, },
]], ]],
payee: None,
}; };
assert_eq!(route.get_total_fees(), 200); assert_eq!(route.get_total_fees(), 200);
@ -4643,7 +4659,7 @@ mod tests {
// In an earlier version of `Route::get_total_fees` and `Route::get_total_amount`, they // In an earlier version of `Route::get_total_fees` and `Route::get_total_amount`, they
// would both panic if the route was completely empty. We test to ensure they return 0 // would both panic if the route was completely empty. We test to ensure they return 0
// here, even though its somewhat nonsensical as a route. // here, even though its somewhat nonsensical as a route.
let route = Route { paths: Vec::new() }; let route = Route { paths: Vec::new(), payee: None };
assert_eq!(route.get_total_fees(), 0); assert_eq!(route.get_total_fees(), 0);
assert_eq!(route.get_total_amount(), 0); assert_eq!(route.get_total_amount(), 0);