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

feat: add optional name for activity descriptions #170

Conversation

Anyitechs
Copy link

This PR closes issue #127 and the implementation follows the conversation on the issue thread.

@Anyitechs Anyitechs marked this pull request as ready for review March 8, 2024 23:55
@Anyitechs Anyitechs marked this pull request as draft March 8, 2024 23:56
Copy link
Contributor

@carlaKC carlaKC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conceptually looks good, a few comments. Feel free to pull out of draft once addressed.

sim-lib/src/lib.rs Outdated Show resolved Hide resolved
sim-lib/src/lib.rs Outdated Show resolved Hide resolved
sim-lib/src/lib.rs Outdated Show resolved Hide resolved
@Anyitechs Anyitechs marked this pull request as ready for review March 14, 2024 07:41
@Anyitechs
Copy link
Author

@carlaKC I made the requested changes. Let me know if this looks good now. Thank you.

Copy link
Collaborator

@enigbe enigbe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Anyitechs Good job on the PR. Here are a few comments I have:

  1. To make the new activity_name field even clearer for users, I'd recommend adding some documentation to the README. This could explain its optional nature and how it's handled in the code.

  2. I noticed that the activity_name or index is used in logs related to activities and at most the simulation events (when they're sent to the events consumer). I'm curious about why we'd have a name/index prefix that doesn't extend to the simulation outputs and results as well. Shouldn't there be consistency across board? I don't think it will be easy to relate activity -> event -> output -> result logs if only the activities and the events have the prefix. I know this is out of the scope of the issue but happy to get your (as well as @carlaKC's) thoughts on this.

@Anyitechs
Copy link
Author

@Anyitechs Good job on the PR. Here are a few comments I have:

Thank you.

  1. To make the new activity_name field even clearer for users, I'd recommend adding some documentation to the README. This could explain its optional nature and how it's handled in the code.

Sure! I'll update the README in a seperate PR following this.

  1. I noticed that the activity_name or index is used in logs related to activities and at most the simulation events (when they're sent to the events consumer). I'm curious about why we'd have a name/index prefix that doesn't extend to the simulation outputs and results as well. Shouldn't there be consistency across board? I don't think it will be easy to relate activity -> event -> output -> result logs if only the activities and the events have the prefix. I know this is out of the scope of the issue but happy to get your (as well as @carlaKC's) thoughts on this.

I agree @enigbe . I guess that's what @carlaKC referred to as "activity-related" logging above. I'll work on that and update the PR.

@carlaKC
Copy link
Contributor

carlaKC commented Mar 15, 2024

Sure! I'll update the README in a seperate PR following this.

Please update readme in the same PR, it's easy for things to get out of sync/be forgotten otherwise.

Copy link
Contributor

@carlaKC carlaKC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shaping up!

I think that this still needs better handling for random activity - what we have right now will print odd looking lines.

README.md Outdated Show resolved Hide resolved
@@ -819,32 +838,32 @@ async fn produce_events<N: DestinationGenerator + ?Sized, A: PaymentGenerator +
let amount = match node_generator.payment_amount(capacity) {
Ok(amt) => {
if amt == 0 {
log::debug!("Skipping zero amount payment for {source} -> {destination}.");
log::debug!("{activity_name} activity => Skipping zero amount payment for {source} -> {destination}.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: replace => with :, also won't this print activity if a name is not set?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. I'll replace that.

And if a name isn't set, it should print the index of the activity. But I'll confirm this is true for this as well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't set an activity_name for randomly generated activity (above, line 776) right?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we don't set an activity_name for randomly generated activity. I see your point on this logging activity if a name isn't set for it.

How best do you think we can handle this? I had a name set for it before but you earlier mentioned we should take it off.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By only logging the prefix if we've got a value there?

if self.activity_name != "" { format!("{} activity:", self.activity_name) } else {"".to_string()}

Could inline, pulled out into a impl of Payment, or leave activity_name as an option so that we can use some of the uwrap_or functionality.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the clarification. I've addressed this and updated the PR.

sim-cli/src/main.rs Show resolved Hide resolved
@Anyitechs Anyitechs requested review from enigbe and carlaKC April 7, 2024 00:12
Copy link
Contributor

@carlaKC carlaKC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs a rebase on master!

for validated_activity in &validated_activities {
if validated_activity.activity_name == act.activity_name {
anyhow::bail!(LightningError::ValidationError(
"Duplicate activity name is not allowed".to_string(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be helpful to provide the user with the name so they know what to fix?

if self.activity_name.is_empty() {
write!(
f,
"Processed {} payments sending {} msat total with {:.2}% success rate.",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Surely we can do this with fewer LOC?

@@ -182,11 +182,20 @@ async fn main() -> anyhow::Result<()> {
},
};

for validated_activity in &validated_activities {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Build a hashmap like we do for alias and pubkey rather than iterating through every activity every time

README.md Outdated
provide a set of nodes and the simulator will generate activity based
on the topology of the underlying graph. Note that payments will only
be sent between the `nodes` that are provided so that liquidity does
To run the simulator with random activity generation, you just need to
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please pull wholesale formatting changes out into their own commit

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still hasn't been addressed?

If you want to run all these formatting changes on the README, please run them first and then make your changes.

@Anyitechs
Copy link
Author

Thank you for the detailed review @carlaKC. I've addressed all the feedbacks, rebased, and updated the PR as well.

Let me know if there's anything else I need to look at.

@Anyitechs Anyitechs requested a review from carlaKC April 11, 2024 16:14
Copy link
Contributor

@carlaKC carlaKC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the functionality is mostly here (though I think we still need to clean up the logging for random activity).

On a higher level, the commit structure in this PR needs some work. Most of the changes can be squashed down to a single commit, and formatting changes / docs / unrelated fixups left in their own commit.

sim-lib/src/lib.rs Outdated Show resolved Hide resolved
@Anyitechs
Copy link
Author

Looks like the functionality is mostly here (though I think we still need to clean up the logging for random activity).

On a higher level, the commit structure in this PR needs some work. Most of the changes can be squashed down to a single commit, and formatting changes / docs / unrelated fixups left in their own commit.

Thank you. I've addressed the feedbacks and neatened up the commit structure.

@carlaKC
Copy link
Contributor

carlaKC commented Apr 23, 2024

Thank you. I've addressed the feedbacks and neatened up the commit structure.

Have you? The first commit is still a mix of formatting and logical changes, and has a dangling TODO comment.

To me, the logical commit structure would be:

  • Formatting changes to the README (or remove all of those)
  • Commit with actual rust changes
  • Commit with documentation updates for features

Right now everything is intermingled in the first commit - formatting changes to the readme, and rust code.

README.md Show resolved Hide resolved
sim-lib/src/lib.rs Outdated Show resolved Hide resolved
@Anyitechs
Copy link
Author

Anyitechs commented Apr 24, 2024

Thank you. I've addressed the feedbacks and neatened up the commit structure.

Have you? The first commit is still a mix of formatting and logical changes, and has a dangling TODO comment.

To me, the logical commit structure would be:

  • Formatting changes to the README (or remove all of those)
  • Commit with actual rust changes
  • Commit with documentation updates for features

Right now everything is intermingled in the first commit - formatting changes to the readme, and rust code.

Thank you @carlaKC for taking the time to review this and providing feedbacks as well. I really appreciate it.

I've worked on the commit structure and it's currently being squashed into two commits:

  • The actual code implementation, and
  • The documentation update of the feature

Let me know if I missed anything. Thank you.

Copy link
Contributor

@carlaKC carlaKC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for updating the commit ordering!

Please try to test changes with a few standard inputs before you push/request review - there's a panic in this change.

The various logging issues that I've pointed out also become more apparent when you spend some time running the project and getting familiar. I know that these seem like frustrating nits, but when we're looking at a change like this which really is just aesthetic we really do need to get things right to justify changing the code at all.

sim-cli/src/main.rs Outdated Show resolved Hide resolved
@@ -182,13 +183,23 @@ async fn main() -> anyhow::Result<()> {
},
};

if activity_name_map.contains_key(&act.activity_name) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When there are two activities with no activity_name set, this will detect that None is in the map twice, error out and then panic on unwrap.

I think it makes sense to put this whole block in if act.activity_name.IsSome() so that we're only adding items that actually have values. Using an Option as a key gets tricky (as seen here).

@@ -1105,7 +1136,8 @@ impl Display for PaymentResultLogger {
let total_payments = self.success_payment + self.failed_payment;
write!(
f,
"Processed {} payments sending {} msat total with {:.2}% success rate.",
"{} Processed {} payments sending {} msat total with {:.2}% success rate.",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line represents a summary of all payments - why are use using a single activity name here?

Comment on lines 873 to 935
"Starting {} activity producer for {}: {}.",
executor.activity_name,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prints: Starting activity for random payments, as above perhaps think about using this strictly as a prefix.

sim-lib/src/lib.rs Outdated Show resolved Hide resolved
sim-lib/src/lib.rs Outdated Show resolved Hide resolved
@carlaKC
Copy link
Contributor

carlaKC commented Apr 24, 2024

If it's useful to getting this in, we can also just re-add random activity as a name, but perhaps with an index. I don't like it but it's not really I hill I'm willing to die on - hopefully that simplifies all the logging.

@carlaKC
Copy link
Contributor

carlaKC commented May 6, 2024

Needs rebase!

@carlaKC
Copy link
Contributor

carlaKC commented May 13, 2024

Ping @Anyitechs any updated here?

@Anyitechs
Copy link
Author

Ping @Anyitechs any updated here?

Yes, will update the PR by EOD.

@Anyitechs Anyitechs force-pushed the feat/optional-activity-name branch from 0fa96c9 to b2c27d7 Compare May 14, 2024 21:39
@Anyitechs
Copy link
Author

Ping @Anyitechs any updated here?

Yes, will update the PR by EOD.

I just updated the PR now.

Copy link
Contributor

@carlaKC carlaKC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be rebased on master to fix unrelated build failure.

I think that this change is high impact enough if we just have logging in produce_events, so final comment is to remove this entirely from PaymentResultLogger.

let total_payments = activity_result.success_payment + activity_result.failed_payment;
writeln!(
f,
"{} Processed {} payments sending {} msat total with {:.2}% success rate.",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The intent behind this comment was to remove the names from PaymentResultLogger completely - we don't want to print these results on a per-activity basis, it'll be too spammy where the whole point here is to give a very high level aggregate.

I believe we can also remove activity_name from Payment completely if we don't have this logging?

@@ -352,6 +358,16 @@ struct Payment {
dispatch_time: SystemTime,
}

impl Payment {
fn activity_prefix(&self) -> String {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: add a comment explaining usage here / that this should be added before a log with no space

impl Payment {
fn activity_prefix(&self) -> String {
if !self.activity_name.is_empty() {
format!("{} activity:", self.activity_name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: should have a space after : otherwise it reads X activity:Payment when we use it below

generators.push(ExecutorKit {
source_info: node_info.clone(),
network_generator: network_generator.clone(),
activity_name: format!("Index {index} random"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Random index {}

@@ -788,10 +812,11 @@ impl Simulation {
network_generator.lock().await
);

for (node_info, capacity) in active_nodes.values() {
for (index, (node_info, capacity)) in active_nodes.values().enumerate() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: just use i, more idiomatic

@Anyitechs Anyitechs force-pushed the feat/optional-activity-name branch from b2c27d7 to fe51df7 Compare May 23, 2024 11:58
@Anyitechs
Copy link
Author

Can be rebased on master to fix unrelated build failure.

I think that this change is high impact enough if we just have logging in produce_events, so final comment is to remove this entirely from PaymentResultLogger.

Thank you for taking the time to always review and give feedback on this PR @carlaKC. I've addressed all the comments and updated the PR. Let me know if there's anything I'm missing.

Copy link
Contributor

@carlaKC carlaKC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some superfluous changes leftover from previous iterations of this PR, and activity_name isn't being used in logs in produce_events in several places.

@@ -1083,7 +1098,7 @@ async fn produce_events<N: DestinationGenerator + ?Sized, A: PaymentGenerator +
log::debug!("Generated payment: {source} -> {}: {amount} msat.", destination);

// Send the payment, exiting if we can no longer send to the consumer.
let event = SimulationEvent::SendPayment(destination.clone(), amount);
let event = SimulationEvent::SendPayment(destination.clone(), amount,);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnecessary comma after amount,

@@ -380,7 +384,7 @@ pub enum PaymentOutcome {
}

/// Describes a payment from a source node to a destination node.
#[derive(Debug, Clone, Copy, Serialize)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unnecessary change?

@@ -1241,14 +1256,14 @@ async fn produce_simulation_results(
SimulationOutput::SendPaymentSuccess(payment) => {
if let Some(source_node) = nodes.get(&payment.source) {
set.spawn(track_payment_result(
source_node.clone(), results.clone(), payment, listener.clone()
source_node.clone(), results.clone(), payment.clone(), listener.clone()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary clone here and 3x below?

@@ -1083,7 +1098,7 @@ async fn produce_events<N: DestinationGenerator + ?Sized, A: PaymentGenerator +
log::debug!("Generated payment: {source} -> {}: {amount} msat.", destination);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use activity_name here?

@carlaKC
Copy link
Contributor

carlaKC commented May 24, 2024

We've spent quite a lot of time on review for a purely aesthetic change, and I don't have much capacity left to see this to the finish line review-wise. If somebody has need for this feature and has the time to review I'll happily come back and give this a final pass + merge once it's been cleaned up.

@carlaKC
Copy link
Contributor

carlaKC commented Jun 18, 2024

Closing due to inactivity.

@carlaKC carlaKC closed this Jun 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants