Skip to content

Commit db1db6e

Browse files
committed
Added changes
1 parent 0e8da58 commit db1db6e

File tree

9 files changed

+469
-443
lines changed

9 files changed

+469
-443
lines changed

fuzz/src/router.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ pub fn do_test<Out: test_logger::Output>(data: &[u8], out: Out) {
293293
}]));
294294
}
295295
}
296-
let scorer = ProbabilisticScorer::new(Default::default(), &net_graph, &logger);
296+
let scorer = ProbabilisticScorer::new(&net_graph, &logger);
297297
let random_seed_bytes: [u8; 32] = [get_slice!(1)[0]; 32];
298298
for target in node_pks.iter() {
299299
let final_value_msat = slice_to_be64(get_slice!(8));

lightning-background-processor/src/lib.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -236,26 +236,28 @@ fn handle_network_graph_update<L: Deref>(
236236
}
237237

238238
fn update_scorer<'a, S: 'static + Deref<Target = SC> + Send + Sync, SC: 'a + WriteableScore<'a>>(
239-
scorer: &'a S, event: &Event
239+
scorer: &'a S,
240+
event: &Event,
241+
score_params: &<S::Target as Score>::ScoreParams
240242
) {
241243
let mut score = scorer.lock();
242244
match event {
243245
Event::PaymentPathFailed { ref path, short_channel_id: Some(scid), .. } => {
244-
score.payment_path_failed(path, *scid);
246+
score.payment_path_failed(path, *scid, score_params);
245247
},
246248
Event::PaymentPathFailed { ref path, payment_failed_permanently: true, .. } => {
247249
// Reached if the destination explicitly failed it back. We treat this as a successful probe
248250
// because the payment made it all the way to the destination with sufficient liquidity.
249-
score.probe_successful(path);
251+
score.probe_successful(path, score_params);
250252
},
251253
Event::PaymentPathSuccessful { path, .. } => {
252-
score.payment_path_successful(path);
254+
score.payment_path_successful(path, score_params);
253255
},
254256
Event::ProbeSuccessful { path, .. } => {
255-
score.probe_successful(path);
257+
score.probe_successful(path, score_params);
256258
},
257259
Event::ProbeFailed { path, short_channel_id: Some(scid), .. } => {
258-
score.probe_failed(path, *scid);
260+
score.probe_failed(path, *scid, score_params);
259261
},
260262
_ => {},
261263
}
@@ -766,7 +768,7 @@ impl BackgroundProcessor {
766768
handle_network_graph_update(network_graph, &event)
767769
}
768770
if let Some(ref scorer) = scorer {
769-
update_scorer(scorer, &event);
771+
update_scorer(scorer, &event, &0);
770772
}
771773
event_handler.handle_event(event);
772774
};
@@ -1015,11 +1017,12 @@ mod tests {
10151017
}
10161018

10171019
impl Score for TestScorer {
1020+
type ScoreParams = i32;
10181021
fn channel_penalty_msat(
1019-
&self, _short_channel_id: u64, _source: &NodeId, _target: &NodeId, _usage: ChannelUsage
1022+
&self, _short_channel_id: u64, _source: &NodeId, _target: &NodeId, _usage: ChannelUsage, _score_params: &Self::ScoreParams
10201023
) -> u64 { unimplemented!(); }
10211024

1022-
fn payment_path_failed(&mut self, actual_path: &Path, actual_short_channel_id: u64) {
1025+
fn payment_path_failed(&mut self, actual_path: &Path, actual_short_channel_id: u64, _score_params: &Self::ScoreParams) {
10231026
if let Some(expectations) = &mut self.event_expectations {
10241027
match expectations.pop_front().unwrap() {
10251028
TestResult::PaymentFailure { path, short_channel_id } => {
@@ -1039,7 +1042,7 @@ mod tests {
10391042
}
10401043
}
10411044

1042-
fn payment_path_successful(&mut self, actual_path: &Path) {
1045+
fn payment_path_successful(&mut self, actual_path: &Path, _score_params: &Self::ScoreParams) {
10431046
if let Some(expectations) = &mut self.event_expectations {
10441047
match expectations.pop_front().unwrap() {
10451048
TestResult::PaymentFailure { path, .. } => {
@@ -1058,7 +1061,7 @@ mod tests {
10581061
}
10591062
}
10601063

1061-
fn probe_failed(&mut self, actual_path: &Path, _: u64) {
1064+
fn probe_failed(&mut self, actual_path: &Path, _: u64, _score_params: &Self::ScoreParams) {
10621065
if let Some(expectations) = &mut self.event_expectations {
10631066
match expectations.pop_front().unwrap() {
10641067
TestResult::PaymentFailure { path, .. } => {
@@ -1076,7 +1079,7 @@ mod tests {
10761079
}
10771080
}
10781081
}
1079-
fn probe_successful(&mut self, actual_path: &Path) {
1082+
fn probe_successful(&mut self, actual_path: &Path, _score_params: &Self::ScoreParams) {
10801083
if let Some(expectations) = &mut self.event_expectations {
10811084
match expectations.pop_front().unwrap() {
10821085
TestResult::PaymentFailure { path, .. } => {
@@ -1129,7 +1132,7 @@ mod tests {
11291132
let network_graph = Arc::new(NetworkGraph::new(network, logger.clone()));
11301133
let scorer = Arc::new(Mutex::new(TestScorer::new()));
11311134
let seed = [i as u8; 32];
1132-
let router = Arc::new(DefaultRouter::new(network_graph.clone(), logger.clone(), seed, scorer.clone()));
1135+
let router = Arc::new(DefaultRouter::new(network_graph.clone(), logger.clone(), seed, scorer.clone(), &0));
11331136
let chain_source = Arc::new(test_utils::TestChainSource::new(Network::Testnet));
11341137
let persister = Arc::new(FilesystemPersister::new(format!("{}_persister_{}", &persist_dir, i)));
11351138
let now = Duration::from_secs(genesis_block.header.time as u64);

lightning/src/ln/channelmanager.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ pub type SimpleArcChannelManager<M, T, F, L> = ChannelManager<
624624
/// of [`KeysManager`] and [`DefaultRouter`].
625625
///
626626
/// This is not exported to bindings users as Arcs don't make sense in bindings
627-
pub type SimpleRefChannelManager<'a, 'b, 'c, 'd, 'e, 'f, 'g, 'h, M, T, F, L> = ChannelManager<&'a M, &'b T, &'c KeysManager, &'c KeysManager, &'c KeysManager, &'d F, &'e DefaultRouter<&'f NetworkGraph<&'g L>, &'g L, &'h Mutex<ProbabilisticScorer<&'f NetworkGraph<&'g L>, &'g L>>>, &'g L>;
627+
pub type SimpleRefChannelManager<'a, 'b, 'c, 'd, 'e, 'f, 'g, 'h,'i, 'j, M, T, F, L> = ChannelManager<&'a M, &'b T, &'c KeysManager, &'c KeysManager, &'c KeysManager, &'d F, &'e DefaultRouter<&'f NetworkGraph<&'g L>, &'g L, &'h Mutex<ProbabilisticScorer<&'f NetworkGraph<&'g L>, &'g L>>>, &'g L>;
628628

629629
/// A trivial trait which describes any [`ChannelManager`] used in testing.
630630
#[cfg(any(test, feature = "_test_utils"))]
@@ -8324,7 +8324,7 @@ mod tests {
83248324
};
83258325
let route = find_route(
83268326
&nodes[0].node.get_our_node_id(), &route_params, &nodes[0].network_graph,
8327-
None, nodes[0].logger, &scorer, &random_seed_bytes
8327+
None, nodes[0].logger, &scorer, &0, &random_seed_bytes
83288328
).unwrap();
83298329
nodes[0].node.send_spontaneous_payment(&route, Some(payment_preimage),
83308330
RecipientOnionFields::spontaneous_empty(), PaymentId(payment_preimage.0)).unwrap();
@@ -8358,7 +8358,7 @@ mod tests {
83588358
let payment_preimage = PaymentPreimage([42; 32]);
83598359
let route = find_route(
83608360
&nodes[0].node.get_our_node_id(), &route_params, &nodes[0].network_graph,
8361-
None, nodes[0].logger, &scorer, &random_seed_bytes
8361+
None, nodes[0].logger, &scorer,&0, &random_seed_bytes
83628362
).unwrap();
83638363
let payment_hash = nodes[0].node.send_spontaneous_payment(&route, Some(payment_preimage),
83648364
RecipientOnionFields::spontaneous_empty(), PaymentId(payment_preimage.0)).unwrap();
@@ -8421,7 +8421,7 @@ mod tests {
84218421
let random_seed_bytes = chanmon_cfgs[1].keys_manager.get_secure_random_bytes();
84228422
let route = find_route(
84238423
&payer_pubkey, &route_params, &network_graph, Some(&first_hops.iter().collect::<Vec<_>>()),
8424-
nodes[0].logger, &scorer, &random_seed_bytes
8424+
nodes[0].logger, &scorer,&0, &random_seed_bytes
84258425
).unwrap();
84268426

84278427
let test_preimage = PaymentPreimage([42; 32]);
@@ -8465,7 +8465,7 @@ mod tests {
84658465
let random_seed_bytes = chanmon_cfgs[1].keys_manager.get_secure_random_bytes();
84668466
let route = find_route(
84678467
&payer_pubkey, &route_params, &network_graph, Some(&first_hops.iter().collect::<Vec<_>>()),
8468-
nodes[0].logger, &scorer, &random_seed_bytes
8468+
nodes[0].logger, &scorer, &0,&random_seed_bytes
84698469
).unwrap();
84708470

84718471
let test_preimage = PaymentPreimage([42; 32]);

lightning/src/ln/functional_test_utils.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1705,6 +1705,7 @@ pub fn get_route(send_node: &Node, payment_params: &PaymentParameters, recv_valu
17051705
&send_node.node.get_our_node_id(), payment_params, &send_node.network_graph.read_only(),
17061706
Some(&send_node.node.list_usable_channels().iter().collect::<Vec<_>>()),
17071707
recv_value, send_node.logger, &scorer, &random_seed_bytes
1708+
recv_value, final_cltv_expiry_delta, send_node.logger, &scorer, &0, &random_seed_bytes
17081709
)
17091710
}
17101711

lightning/src/ln/functional_tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9520,7 +9520,7 @@ fn test_keysend_payments_to_public_node() {
95209520
};
95219521
let scorer = test_utils::TestScorer::new();
95229522
let random_seed_bytes = chanmon_cfgs[1].keys_manager.get_secure_random_bytes();
9523-
let route = find_route(&payer_pubkey, &route_params, &network_graph, None, nodes[0].logger, &scorer, &random_seed_bytes).unwrap();
9523+
let route = find_route(&payer_pubkey, &route_params, &network_graph, None, nodes[0].logger, &scorer, &0, &random_seed_bytes).unwrap();
95249524

95259525
let test_preimage = PaymentPreimage([42; 32]);
95269526
let payment_hash = nodes[0].node.send_spontaneous_payment(&route, Some(test_preimage),
@@ -9555,7 +9555,7 @@ fn test_keysend_payments_to_private_node() {
95559555
let random_seed_bytes = chanmon_cfgs[1].keys_manager.get_secure_random_bytes();
95569556
let route = find_route(
95579557
&payer_pubkey, &route_params, &network_graph, Some(&first_hops.iter().collect::<Vec<_>>()),
9558-
nodes[0].logger, &scorer, &random_seed_bytes
9558+
nodes[0].logger, &scorer, &0, &random_seed_bytes
95599559
).unwrap();
95609560

95619561
let test_preimage = PaymentPreimage([42; 32]);

lightning/src/ln/peer_handler.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ impl Peer {
523523
/// issues such as overly long function definitions.
524524
///
525525
/// This is not exported to bindings users as `Arc`s don't make sense in bindings.
526-
pub type SimpleArcPeerManager<SD, M, T, F, C, L> = PeerManager<SD, Arc<SimpleArcChannelManager<M, T, F, L>>, Arc<P2PGossipSync<Arc<NetworkGraph<Arc<L>>>, Arc<C>, Arc<L>>>, Arc<SimpleArcOnionMessenger<L>>, Arc<L>, IgnoringMessageHandler, Arc<KeysManager>>;
526+
pub type SimpleArcPeerManager<'a, SD, M, T, F, C, L> = PeerManager<SD, Arc<SimpleArcChannelManager<M, T, F, L>>, Arc<P2PGossipSync<Arc<NetworkGraph<Arc<L>>>, Arc<C>, Arc<L>>>, Arc<SimpleArcOnionMessenger<L>>, Arc<L>, IgnoringMessageHandler, Arc<KeysManager>>;
527527

528528
/// SimpleRefPeerManager is a type alias for a PeerManager reference, and is the reference
529529
/// counterpart to the SimpleArcPeerManager type alias. Use this type by default when you don't
@@ -533,7 +533,7 @@ pub type SimpleArcPeerManager<SD, M, T, F, C, L> = PeerManager<SD, Arc<SimpleArc
533533
/// helps with issues such as long function definitions.
534534
///
535535
/// This is not exported to bindings users as general type aliases don't make sense in bindings.
536-
pub type SimpleRefPeerManager<'a, 'b, 'c, 'd, 'e, 'f, 'g, 'h, 'i, 'j, 'k, 'l, 'm, SD, M, T, F, C, L> = PeerManager<SD, SimpleRefChannelManager<'a, 'b, 'c, 'd, 'e, 'f, 'g, 'm, M, T, F, L>, &'f P2PGossipSync<&'g NetworkGraph<&'f L>, &'h C, &'f L>, &'i SimpleRefOnionMessenger<'j, 'k, L>, &'f L, IgnoringMessageHandler, &'c KeysManager>;
536+
pub type SimpleRefPeerManager<'a, 'b, 'c, 'd, 'e, 'f, 'g, 'h, 'i, 'j, 'k, 'l, 'm, 'n, SD, M, T, F, C, L> = PeerManager<SD, SimpleRefChannelManager<'a, 'b, 'c, 'd, 'e, 'f, 'g, 'm, 'n, 'n, M, T, F, L>, &'f P2PGossipSync<&'g NetworkGraph<&'f L>, &'h C, &'f L>, &'i SimpleRefOnionMessenger<'j, 'k, L>, &'f L, IgnoringMessageHandler, &'c KeysManager>;
537537

538538
/// A PeerManager manages a set of peers, described by their [`SocketDescriptor`] and marshalls
539539
/// socket events into messages which it passes on to its [`MessageHandler`].

0 commit comments

Comments
 (0)