-
Notifications
You must be signed in to change notification settings - Fork 28
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
feat: add optional name for activity descriptions #170
Conversation
There was a problem hiding this 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.
@carlaKC I made the requested changes. Let me know if this looks good now. Thank you. |
There was a problem hiding this 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:
-
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. -
I noticed that the
activity_name
orindex
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 relateactivity -> 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.
Thank you.
Sure! I'll update the README in a seperate PR following 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. |
Please update readme in the same PR, it's easy for things to get out of sync/be forgotten otherwise. |
There was a problem hiding this 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.
sim-lib/src/lib.rs
Outdated
@@ -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}."); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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!
sim-cli/src/main.rs
Outdated
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(), |
There was a problem hiding this comment.
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?
sim-lib/src/lib.rs
Outdated
if self.activity_name.is_empty() { | ||
write!( | ||
f, | ||
"Processed {} payments sending {} msat total with {:.2}% success rate.", |
There was a problem hiding this comment.
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?
sim-cli/src/main.rs
Outdated
@@ -182,11 +182,20 @@ async fn main() -> anyhow::Result<()> { | |||
}, | |||
}; | |||
|
|||
for validated_activity in &validated_activities { |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
16fd20d
to
6f92f3a
Compare
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. |
There was a problem hiding this 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.
6f92f3a
to
c14ef99
Compare
Thank you. I've addressed the feedbacks and neatened up the commit structure. |
c14ef99
to
62229d9
Compare
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:
Right now everything is intermingled in the first commit - formatting changes to the readme, and rust code. |
62229d9
to
0fa96c9
Compare
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:
Let me know if I missed anything. Thank you. |
There was a problem hiding this 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
@@ -182,13 +183,23 @@ async fn main() -> anyhow::Result<()> { | |||
}, | |||
}; | |||
|
|||
if activity_name_map.contains_key(&act.activity_name) { |
There was a problem hiding this comment.
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).
sim-lib/src/lib.rs
Outdated
@@ -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.", |
There was a problem hiding this comment.
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?
sim-lib/src/lib.rs
Outdated
"Starting {} activity producer for {}: {}.", | ||
executor.activity_name, |
There was a problem hiding this comment.
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.
If it's useful to getting this in, we can also just re-add |
Needs rebase! |
Ping @Anyitechs any updated here? |
Yes, will update the PR by EOD. |
0fa96c9
to
b2c27d7
Compare
I just updated the PR now. |
There was a problem hiding this 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
.
sim-lib/src/lib.rs
Outdated
let total_payments = activity_result.success_payment + activity_result.failed_payment; | ||
writeln!( | ||
f, | ||
"{} Processed {} payments sending {} msat total with {:.2}% success rate.", |
There was a problem hiding this comment.
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?
sim-lib/src/lib.rs
Outdated
@@ -352,6 +358,16 @@ struct Payment { | |||
dispatch_time: SystemTime, | |||
} | |||
|
|||
impl Payment { | |||
fn activity_prefix(&self) -> String { |
There was a problem hiding this comment.
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
sim-lib/src/lib.rs
Outdated
impl Payment { | ||
fn activity_prefix(&self) -> String { | ||
if !self.activity_name.is_empty() { | ||
format!("{} activity:", self.activity_name) |
There was a problem hiding this comment.
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
sim-lib/src/lib.rs
Outdated
generators.push(ExecutorKit { | ||
source_info: node_info.clone(), | ||
network_generator: network_generator.clone(), | ||
activity_name: format!("Index {index} random"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Random index {}
sim-lib/src/lib.rs
Outdated
@@ -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() { |
There was a problem hiding this comment.
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
b2c27d7
to
fe51df7
Compare
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. |
There was a problem hiding this 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,); |
There was a problem hiding this comment.
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)] |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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?
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. |
Closing due to inactivity. |
This PR closes issue #127 and the implementation follows the conversation on the issue thread.