Skip to content

Commit 55fc0a1

Browse files
authored
Merge pull request #1150 from TheBlueMatt/2021-11-103-bindings
Pre-0.0.103 Bindings Tweaks
2 parents 094ddb2 + 0c1b70c commit 55fc0a1

15 files changed

+72
-68
lines changed

fuzz/src/full_stack.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ pub fn do_test(data: &[u8], logger: &Arc<dyn Logger>) {
438438
},
439439
4 => {
440440
let final_value_msat = slice_to_be24(get_slice!(3)) as u64;
441-
let payee = Payee::new(get_pubkey!());
441+
let payee = Payee::from_node_id(get_pubkey!());
442442
let params = RouteParameters {
443443
payee,
444444
final_value_msat,
@@ -461,7 +461,7 @@ pub fn do_test(data: &[u8], logger: &Arc<dyn Logger>) {
461461
},
462462
15 => {
463463
let final_value_msat = slice_to_be24(get_slice!(3)) as u64;
464-
let payee = Payee::new(get_pubkey!());
464+
let payee = Payee::from_node_id(get_pubkey!());
465465
let params = RouteParameters {
466466
payee,
467467
final_value_msat,

fuzz/src/router.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
251251
let scorer = Scorer::with_fixed_penalty(0);
252252
for target in node_pks.iter() {
253253
let params = RouteParameters {
254-
payee: Payee::new(*target).with_route_hints(last_hops.clone()),
254+
payee: Payee::from_node_id(*target).with_route_hints(last_hops.clone()),
255255
final_value_msat: slice_to_be64(get_slice!(8)),
256256
final_cltv_expiry_delta: slice_to_be32(get_slice!(4)),
257257
};

lightning-invoice/src/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,8 @@ pub enum TaggedField {
379379

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

384385
/// Description string
385386
///

lightning-invoice/src/payment.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
//! # fn channel_penalty_msat(
7272
//! # &self, _short_channel_id: u64, _source: &NodeId, _target: &NodeId
7373
//! # ) -> u64 { 0 }
74-
//! # fn payment_path_failed(&mut self, _path: &Vec<RouteHop>, _short_channel_id: u64) {}
74+
//! # fn payment_path_failed(&mut self, _path: &[&RouteHop], _short_channel_id: u64) {}
7575
//! # }
7676
//! #
7777
//! # struct FakeLogger {};
@@ -262,7 +262,7 @@ where
262262
match payment_cache.entry(payment_hash) {
263263
hash_map::Entry::Vacant(entry) => {
264264
let payer = self.payer.node_id();
265-
let mut payee = Payee::new(invoice.recover_payee_pub_key())
265+
let mut payee = Payee::from_node_id(invoice.recover_payee_pub_key())
266266
.with_expiry_time(expiry_time_from_unix_epoch(&invoice).as_secs())
267267
.with_route_hints(invoice.route_hints());
268268
if let Some(features) = invoice.features() {
@@ -415,7 +415,8 @@ where
415415
all_paths_failed, payment_id, payment_hash, rejected_by_dest, path, short_channel_id, retry, ..
416416
} => {
417417
if let Some(short_channel_id) = short_channel_id {
418-
self.scorer.lock().payment_path_failed(path, *short_channel_id);
418+
let t = path.iter().collect::<Vec<_>>();
419+
self.scorer.lock().payment_path_failed(&t, *short_channel_id);
419420
}
420421

421422
if *rejected_by_dest {
@@ -1034,7 +1035,7 @@ mod tests {
10341035
}
10351036

10361037
fn retry_for_invoice(invoice: &Invoice) -> RouteParameters {
1037-
let mut payee = Payee::new(invoice.recover_payee_pub_key())
1038+
let mut payee = Payee::from_node_id(invoice.recover_payee_pub_key())
10381039
.with_expiry_time(expiry_time_from_unix_epoch(invoice).as_secs())
10391040
.with_route_hints(invoice.route_hints());
10401041
if let Some(features) = invoice.features() {
@@ -1099,7 +1100,7 @@ mod tests {
10991100
&self, _short_channel_id: u64, _source: &NodeId, _target: &NodeId
11001101
) -> u64 { 0 }
11011102

1102-
fn payment_path_failed(&mut self, _path: &Vec<RouteHop>, short_channel_id: u64) {
1103+
fn payment_path_failed(&mut self, _path: &[&RouteHop], short_channel_id: u64) {
11031104
if let Some(expected_short_channel_id) = self.expectations.pop_front() {
11041105
assert_eq!(short_channel_id, expected_short_channel_id);
11051106
}
@@ -1266,7 +1267,7 @@ mod tests {
12661267
cltv_expiry_delta: 100,
12671268
}],
12681269
],
1269-
payee: Some(Payee::new(nodes[1].node.get_our_node_id())),
1270+
payee: Some(Payee::from_node_id(nodes[1].node.get_our_node_id())),
12701271
};
12711272
let router = ManualRouter(RefCell::new(VecDeque::new()));
12721273
router.expect_find_route(Ok(route.clone()));
@@ -1309,7 +1310,7 @@ mod tests {
13091310
cltv_expiry_delta: 100,
13101311
}],
13111312
],
1312-
payee: Some(Payee::new(nodes[1].node.get_our_node_id())),
1313+
payee: Some(Payee::from_node_id(nodes[1].node.get_our_node_id())),
13131314
};
13141315
let router = ManualRouter(RefCell::new(VecDeque::new()));
13151316
router.expect_find_route(Ok(route.clone()));

lightning-invoice/src/utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ mod test {
171171
assert_eq!(invoice.min_final_cltv_expiry(), MIN_FINAL_CLTV_EXPIRY as u64);
172172
assert_eq!(invoice.description(), InvoiceDescription::Direct(&Description("test".to_string())));
173173

174-
let payee = Payee::new(invoice.recover_payee_pub_key())
174+
let payee = Payee::from_node_id(invoice.recover_payee_pub_key())
175175
.with_features(invoice.features().unwrap().clone())
176176
.with_route_hints(invoice.route_hints());
177177
let params = RouteParameters {

lightning/src/ln/channelmanager.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1141,7 +1141,7 @@ macro_rules! handle_monitor_err {
11411141
res
11421142
} };
11431143
($self: ident, $err: expr, $channel_state: expr, $entry: expr, $action_type: path, $resend_raa: expr, $resend_commitment: expr, $failed_forwards: expr, $failed_fails: expr) => {
1144-
handle_monitor_err!($self, $err, $channel_state, $entry, $action_type, $resend_raa, $resend_commitment, $failed_forwards, $failed_fails, Vec::new());
1144+
handle_monitor_err!($self, $err, $channel_state, $entry, $action_type, $resend_raa, $resend_commitment, $failed_forwards, $failed_fails, Vec::new())
11451145
}
11461146
}
11471147

@@ -6646,7 +6646,7 @@ pub mod bench {
66466646
macro_rules! send_payment {
66476647
($node_a: expr, $node_b: expr) => {
66486648
let usable_channels = $node_a.list_usable_channels();
6649-
let payee = Payee::new($node_b.get_our_node_id())
6649+
let payee = Payee::from_node_id($node_b.get_our_node_id())
66506650
.with_features(InvoiceFeatures::known());
66516651
let scorer = Scorer::with_fixed_penalty(0);
66526652
let route = get_route(&$node_a.get_our_node_id(), &payee, &dummy_graph,

lightning/src/ln/functional_test_utils.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,7 @@ macro_rules! get_route_and_payment_hash {
10121012
}};
10131013
($send_node: expr, $recv_node: expr, $last_hops: expr, $recv_value: expr, $cltv: expr) => {{
10141014
let (payment_preimage, payment_hash, payment_secret) = get_payment_preimage_hash!($recv_node, Some($recv_value));
1015-
let payee = $crate::routing::router::Payee::new($recv_node.node.get_our_node_id())
1015+
let payee = $crate::routing::router::Payee::from_node_id($recv_node.node.get_our_node_id())
10161016
.with_features($crate::ln::features::InvoiceFeatures::known())
10171017
.with_route_hints($last_hops);
10181018
let scorer = ::util::test_utils::TestScorer::with_fixed_penalty(0);
@@ -1350,7 +1350,7 @@ pub fn claim_payment<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_route:
13501350
pub const TEST_FINAL_CLTV: u32 = 70;
13511351

13521352
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) {
1353-
let payee = Payee::new(expected_route.last().unwrap().node.get_our_node_id())
1353+
let payee = Payee::from_node_id(expected_route.last().unwrap().node.get_our_node_id())
13541354
.with_features(InvoiceFeatures::known());
13551355
let scorer = test_utils::TestScorer::with_fixed_penalty(0);
13561356
let route = get_route(
@@ -1368,7 +1368,7 @@ pub fn route_payment<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_route:
13681368
}
13691369

13701370
pub fn route_over_limit<'a, 'b, 'c>(origin_node: &Node<'a, 'b, 'c>, expected_route: &[&Node<'a, 'b, 'c>], recv_value: u64) {
1371-
let payee = Payee::new(expected_route.last().unwrap().node.get_our_node_id())
1371+
let payee = Payee::from_node_id(expected_route.last().unwrap().node.get_our_node_id())
13721372
.with_features(InvoiceFeatures::known());
13731373
let scorer = test_utils::TestScorer::with_fixed_penalty(0);
13741374
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();

lightning/src/ln/functional_tests.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -7161,7 +7161,7 @@ fn test_check_htlc_underpaying() {
71617161
create_announced_chan_between_nodes(&nodes, 0, 1, InitFeatures::known(), InitFeatures::known());
71627162

71637163
let scorer = test_utils::TestScorer::with_fixed_penalty(0);
7164-
let payee = Payee::new(nodes[1].node.get_our_node_id()).with_features(InvoiceFeatures::known());
7164+
let payee = Payee::from_node_id(nodes[1].node.get_our_node_id()).with_features(InvoiceFeatures::known());
71657165
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();
71667166
let (_, our_payment_hash, _) = get_payment_preimage_hash!(nodes[0]);
71677167
let our_payment_secret = nodes[1].node.create_inbound_payment_for_hash(our_payment_hash, Some(100_000), 7200, 0).unwrap();
@@ -7559,12 +7559,12 @@ fn test_bump_penalty_txn_on_revoked_htlcs() {
75597559

75607560
let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 1000000, 59000000, InitFeatures::known(), InitFeatures::known());
75617561
// Lock HTLC in both directions (using a slightly lower CLTV delay to provide timely RBF bumps)
7562-
let payee = Payee::new(nodes[1].node.get_our_node_id()).with_features(InvoiceFeatures::known());
7562+
let payee = Payee::from_node_id(nodes[1].node.get_our_node_id()).with_features(InvoiceFeatures::known());
75637563
let scorer = test_utils::TestScorer::with_fixed_penalty(0);
75647564
let route = get_route(&nodes[0].node.get_our_node_id(), &payee, &nodes[0].network_graph, None,
75657565
3_000_000, 50, nodes[0].logger, &scorer).unwrap();
75667566
let payment_preimage = send_along_route(&nodes[0], route, &[&nodes[1]], 3_000_000).0;
7567-
let payee = Payee::new(nodes[0].node.get_our_node_id()).with_features(InvoiceFeatures::known());
7567+
let payee = Payee::from_node_id(nodes[0].node.get_our_node_id()).with_features(InvoiceFeatures::known());
75687568
let route = get_route(&nodes[1].node.get_our_node_id(), &payee, nodes[1].network_graph, None,
75697569
3_000_000, 50, nodes[0].logger, &scorer).unwrap();
75707570
send_along_route(&nodes[1], route, &[&nodes[0]], 3_000_000);

lightning/src/ln/shutdown_tests.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ fn updates_shutdown_wait() {
9696

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

99-
let payee_1 = Payee::new(nodes[1].node.get_our_node_id()).with_features(InvoiceFeatures::known());
99+
let payee_1 = Payee::from_node_id(nodes[1].node.get_our_node_id()).with_features(InvoiceFeatures::known());
100100
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();
101-
let payee_2 = Payee::new(nodes[0].node.get_our_node_id()).with_features(InvoiceFeatures::known());
101+
let payee_2 = Payee::from_node_id(nodes[0].node.get_our_node_id()).with_features(InvoiceFeatures::known());
102102
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();
103103
unwrap_send_err!(nodes[0].node.send_payment(&route_1, payment_hash, &Some(payment_secret)), true, APIError::ChannelUnavailable {..}, {});
104104
unwrap_send_err!(nodes[1].node.send_payment(&route_2, payment_hash, &Some(payment_secret)), true, APIError::ChannelUnavailable {..}, {});

lightning/src/routing/mod.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ pub mod scorer;
1616
use routing::network_graph::NodeId;
1717
use routing::router::RouteHop;
1818

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

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

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

73-
fn payment_path_failed(&mut self, path: &Vec<RouteHop>, short_channel_id: u64) {
72+
fn payment_path_failed(&mut self, path: &[&RouteHop], short_channel_id: u64) {
7473
self.deref_mut().payment_path_failed(path, short_channel_id)
7574
}
7675
}

0 commit comments

Comments
 (0)