Skip to content

Pre-0.0.103 Bindings Tweaks #1150

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

Merged
merged 6 commits into from
Nov 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions fuzz/src/full_stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ pub fn do_test(data: &[u8], logger: &Arc<dyn Logger>) {
},
4 => {
let final_value_msat = slice_to_be24(get_slice!(3)) as u64;
let payee = Payee::new(get_pubkey!());
let payee = Payee::from_node_id(get_pubkey!());
let params = RouteParameters {
payee,
final_value_msat,
Expand All @@ -461,7 +461,7 @@ pub fn do_test(data: &[u8], logger: &Arc<dyn Logger>) {
},
15 => {
let final_value_msat = slice_to_be24(get_slice!(3)) as u64;
let payee = Payee::new(get_pubkey!());
let payee = Payee::from_node_id(get_pubkey!());
let params = RouteParameters {
payee,
final_value_msat,
Expand Down
2 changes: 1 addition & 1 deletion fuzz/src/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
let scorer = Scorer::with_fixed_penalty(0);
for target in node_pks.iter() {
let params = RouteParameters {
payee: Payee::new(*target).with_route_hints(last_hops.clone()),
payee: Payee::from_node_id(*target).with_route_hints(last_hops.clone()),
final_value_msat: slice_to_be64(get_slice!(8)),
final_cltv_expiry_delta: slice_to_be32(get_slice!(4)),
};
Expand Down
3 changes: 2 additions & 1 deletion lightning-invoice/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,8 @@ pub enum TaggedField {

/// SHA-256 hash
#[derive(Clone, Debug, Hash, Eq, PartialEq)]
pub struct Sha256(pub sha256::Hash);
pub struct Sha256(/// (C-not exported) as the native hash types are not currently mapped
pub sha256::Hash);

/// Description string
///
Expand Down
15 changes: 8 additions & 7 deletions lightning-invoice/src/payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
//! # fn channel_penalty_msat(
//! # &self, _short_channel_id: u64, _source: &NodeId, _target: &NodeId
//! # ) -> u64 { 0 }
//! # fn payment_path_failed(&mut self, _path: &Vec<RouteHop>, _short_channel_id: u64) {}
//! # fn payment_path_failed(&mut self, _path: &[&RouteHop], _short_channel_id: u64) {}
//! # }
//! #
//! # struct FakeLogger {};
Expand Down Expand Up @@ -262,7 +262,7 @@ where
match payment_cache.entry(payment_hash) {
hash_map::Entry::Vacant(entry) => {
let payer = self.payer.node_id();
let mut payee = Payee::new(invoice.recover_payee_pub_key())
let mut payee = Payee::from_node_id(invoice.recover_payee_pub_key())
.with_expiry_time(expiry_time_from_unix_epoch(&invoice).as_secs())
.with_route_hints(invoice.route_hints());
if let Some(features) = invoice.features() {
Expand Down Expand Up @@ -415,7 +415,8 @@ where
all_paths_failed, payment_id, payment_hash, rejected_by_dest, path, short_channel_id, retry, ..
} => {
if let Some(short_channel_id) = short_channel_id {
self.scorer.lock().payment_path_failed(path, *short_channel_id);
let t = path.iter().collect::<Vec<_>>();
self.scorer.lock().payment_path_failed(&t, *short_channel_id);
}

if *rejected_by_dest {
Expand Down Expand Up @@ -1034,7 +1035,7 @@ mod tests {
}

fn retry_for_invoice(invoice: &Invoice) -> RouteParameters {
let mut payee = Payee::new(invoice.recover_payee_pub_key())
let mut payee = Payee::from_node_id(invoice.recover_payee_pub_key())
.with_expiry_time(expiry_time_from_unix_epoch(invoice).as_secs())
.with_route_hints(invoice.route_hints());
if let Some(features) = invoice.features() {
Expand Down Expand Up @@ -1099,7 +1100,7 @@ mod tests {
&self, _short_channel_id: u64, _source: &NodeId, _target: &NodeId
) -> u64 { 0 }

fn payment_path_failed(&mut self, _path: &Vec<RouteHop>, short_channel_id: u64) {
fn payment_path_failed(&mut self, _path: &[&RouteHop], short_channel_id: u64) {
if let Some(expected_short_channel_id) = self.expectations.pop_front() {
assert_eq!(short_channel_id, expected_short_channel_id);
}
Expand Down Expand Up @@ -1266,7 +1267,7 @@ mod tests {
cltv_expiry_delta: 100,
}],
],
payee: Some(Payee::new(nodes[1].node.get_our_node_id())),
payee: Some(Payee::from_node_id(nodes[1].node.get_our_node_id())),
};
let router = ManualRouter(RefCell::new(VecDeque::new()));
router.expect_find_route(Ok(route.clone()));
Expand Down Expand Up @@ -1309,7 +1310,7 @@ mod tests {
cltv_expiry_delta: 100,
}],
],
payee: Some(Payee::new(nodes[1].node.get_our_node_id())),
payee: Some(Payee::from_node_id(nodes[1].node.get_our_node_id())),
};
let router = ManualRouter(RefCell::new(VecDeque::new()));
router.expect_find_route(Ok(route.clone()));
Expand Down
2 changes: 1 addition & 1 deletion lightning-invoice/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ mod test {
assert_eq!(invoice.min_final_cltv_expiry(), MIN_FINAL_CLTV_EXPIRY as u64);
assert_eq!(invoice.description(), InvoiceDescription::Direct(&Description("test".to_string())));

let payee = Payee::new(invoice.recover_payee_pub_key())
let payee = Payee::from_node_id(invoice.recover_payee_pub_key())
.with_features(invoice.features().unwrap().clone())
.with_route_hints(invoice.route_hints());
let params = RouteParameters {
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 @@ -1141,7 +1141,7 @@ macro_rules! handle_monitor_err {
res
} };
($self: ident, $err: expr, $channel_state: expr, $entry: expr, $action_type: path, $resend_raa: expr, $resend_commitment: expr, $failed_forwards: expr, $failed_fails: expr) => {
handle_monitor_err!($self, $err, $channel_state, $entry, $action_type, $resend_raa, $resend_commitment, $failed_forwards, $failed_fails, Vec::new());
handle_monitor_err!($self, $err, $channel_state, $entry, $action_type, $resend_raa, $resend_commitment, $failed_forwards, $failed_fails, Vec::new())
}
}

Expand Down Expand Up @@ -6646,7 +6646,7 @@ pub mod bench {
macro_rules! send_payment {
($node_a: expr, $node_b: expr) => {
let usable_channels = $node_a.list_usable_channels();
let payee = Payee::new($node_b.get_our_node_id())
let payee = Payee::from_node_id($node_b.get_our_node_id())
.with_features(InvoiceFeatures::known());
let scorer = Scorer::with_fixed_penalty(0);
let route = get_route(&$node_a.get_our_node_id(), &payee, &dummy_graph,
Expand Down
6 changes: 3 additions & 3 deletions lightning/src/ln/functional_test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1012,7 +1012,7 @@ macro_rules! get_route_and_payment_hash {
}};
($send_node: expr, $recv_node: expr, $last_hops: expr, $recv_value: expr, $cltv: expr) => {{
let (payment_preimage, payment_hash, payment_secret) = get_payment_preimage_hash!($recv_node, Some($recv_value));
let payee = $crate::routing::router::Payee::new($recv_node.node.get_our_node_id())
let payee = $crate::routing::router::Payee::from_node_id($recv_node.node.get_our_node_id())
.with_features($crate::ln::features::InvoiceFeatures::known())
.with_route_hints($last_hops);
let scorer = ::util::test_utils::TestScorer::with_fixed_penalty(0);
Expand Down Expand Up @@ -1350,7 +1350,7 @@ pub fn claim_payment<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_route:
pub const TEST_FINAL_CLTV: u32 = 70;

pub fn route_payment<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_route: &[&Node<'a, 'b, 'c>], recv_value: u64) -> (PaymentPreimage, PaymentHash, PaymentSecret) {
let payee = Payee::new(expected_route.last().unwrap().node.get_our_node_id())
let payee = Payee::from_node_id(expected_route.last().unwrap().node.get_our_node_id())
.with_features(InvoiceFeatures::known());
let scorer = test_utils::TestScorer::with_fixed_penalty(0);
let route = get_route(
Expand All @@ -1368,7 +1368,7 @@ pub fn route_payment<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_route:
}

pub fn route_over_limit<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_route: &[&Node<'a, 'b, 'c>], recv_value: u64) {
let payee = Payee::new(expected_route.last().unwrap().node.get_our_node_id())
let payee = Payee::from_node_id(expected_route.last().unwrap().node.get_our_node_id())
.with_features(InvoiceFeatures::known());
let scorer = test_utils::TestScorer::with_fixed_penalty(0);
let route = get_route(&origin_node.node.get_our_node_id(), &payee, origin_node.network_graph, None, recv_value, TEST_FINAL_CLTV, origin_node.logger, &scorer).unwrap();
Expand Down
6 changes: 3 additions & 3 deletions lightning/src/ln/functional_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7161,7 +7161,7 @@ fn test_check_htlc_underpaying() {
create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known());

let scorer = test_utils::TestScorer::with_fixed_penalty(0);
let payee = Payee::new(nodes[1].node.get_our_node_id()).with_features(InvoiceFeatures::known());
let payee = Payee::from_node_id(nodes[1].node.get_our_node_id()).with_features(InvoiceFeatures::known());
let route = get_route(&nodes[0].node.get_our_node_id(), &payee, nodes[0].network_graph, None, 10_000, TEST_FINAL_CLTV, nodes[0].logger, &scorer).unwrap();
let (_, our_payment_hash, _) = get_payment_preimage_hash!(nodes[0]);
let our_payment_secret = nodes[1].node.create_inbound_payment_for_hash(our_payment_hash, Some(100_000), 7200, 0).unwrap();
Expand Down Expand Up @@ -7559,12 +7559,12 @@ fn test_bump_penalty_txn_on_revoked_htlcs() {

let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1000000, 59000000, InitFeatures::known(), InitFeatures::known());
// Lock HTLC in both directions (using a slightly lower CLTV delay to provide timely RBF bumps)
let payee = Payee::new(nodes[1].node.get_our_node_id()).with_features(InvoiceFeatures::known());
let payee = Payee::from_node_id(nodes[1].node.get_our_node_id()).with_features(InvoiceFeatures::known());
let scorer = test_utils::TestScorer::with_fixed_penalty(0);
let route = get_route(&nodes[0].node.get_our_node_id(), &payee, &nodes[0].network_graph, None,
3_000_000, 50, nodes[0].logger, &scorer).unwrap();
let payment_preimage = send_along_route(&nodes[0], route, &[&nodes[1]], 3_000_000).0;
let payee = Payee::new(nodes[0].node.get_our_node_id()).with_features(InvoiceFeatures::known());
let payee = Payee::from_node_id(nodes[0].node.get_our_node_id()).with_features(InvoiceFeatures::known());
let route = get_route(&nodes[1].node.get_our_node_id(), &payee, nodes[1].network_graph, None,
3_000_000, 50, nodes[0].logger, &scorer).unwrap();
send_along_route(&nodes[1], route, &[&nodes[0]], 3_000_000);
Expand Down
4 changes: 2 additions & 2 deletions lightning/src/ln/shutdown_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ fn updates_shutdown_wait() {

let (_, payment_hash, payment_secret) = get_payment_preimage_hash!(nodes[0]);

let payee_1 = Payee::new(nodes[1].node.get_our_node_id()).with_features(InvoiceFeatures::known());
let payee_1 = Payee::from_node_id(nodes[1].node.get_our_node_id()).with_features(InvoiceFeatures::known());
let route_1 = get_route(&nodes[0].node.get_our_node_id(), &payee_1, nodes[0].network_graph, None, 100000, TEST_FINAL_CLTV, &logger, &scorer).unwrap();
let payee_2 = Payee::new(nodes[0].node.get_our_node_id()).with_features(InvoiceFeatures::known());
let payee_2 = Payee::from_node_id(nodes[0].node.get_our_node_id()).with_features(InvoiceFeatures::known());
let route_2 = get_route(&nodes[1].node.get_our_node_id(), &payee_2, nodes[1].network_graph, None, 100000, TEST_FINAL_CLTV, &logger, &scorer).unwrap();
unwrap_send_err!(nodes[0].node.send_payment(&route_1, payment_hash, &Some(payment_secret)), true, APIError::ChannelUnavailable {..}, {});
unwrap_send_err!(nodes[1].node.send_payment(&route_2, payment_hash, &Some(payment_secret)), true, APIError::ChannelUnavailable {..}, {});
Expand Down
5 changes: 2 additions & 3 deletions lightning/src/routing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ pub mod scorer;
use routing::network_graph::NodeId;
use routing::router::RouteHop;

use prelude::*;
use core::cell::{RefCell, RefMut};
use core::ops::DerefMut;
use sync::{Mutex, MutexGuard};
Expand All @@ -30,7 +29,7 @@ pub trait Score {
fn channel_penalty_msat(&self, short_channel_id: u64, source: &NodeId, target: &NodeId) -> u64;

/// Handles updating channel penalties after failing to route through a channel.
fn payment_path_failed(&mut self, path: &Vec<RouteHop>, short_channel_id: u64);
fn payment_path_failed(&mut self, path: &[&RouteHop], short_channel_id: u64);
}

/// A scorer that is accessed under a lock.
Expand Down Expand Up @@ -70,7 +69,7 @@ impl<S: Score, T: DerefMut<Target=S>> Score for T {
self.deref().channel_penalty_msat(short_channel_id, source, target)
}

fn payment_path_failed(&mut self, path: &Vec<RouteHop>, short_channel_id: u64) {
fn payment_path_failed(&mut self, path: &[&RouteHop], short_channel_id: u64) {
self.deref_mut().payment_path_failed(path, short_channel_id)
}
}
Loading