-
Notifications
You must be signed in to change notification settings - Fork 30
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
refactor: Unify Dispatch of Random and Defined Activity #160
Conversation
Concept ack ✅ And yes the Rust looks crusty! |
I'll be reviewing the PR this week, sorry for taking so long |
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.
Approack ACK. There are some simplifications that we can discuss once the code is cleaned up.
There is only one comment I have regarding the approach. Check inline.
dc176bd
to
3aaaf6b
Compare
This trait is used to pick destinations for sending payments, so we rename it to more accurately reflect this.
In preparation for different implementations of this trait, we rename sample_node_by_capacity to a more general choose_destination to accommodate different ways of picking destinations.
…ivity In preparation for other types of payment activity generators, rename random implementation to be more specific.
df00c4e
to
3ac677c
Compare
Ready for another review with all the proposed name changed, apologies for the long turnaround! @enigbe this has quite a few renames / refactors in it, so will be worthwhile for you to take a pass while you're getting familiar with the codebase. |
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.
tACK 3ac677c ✅
Left stylistic comments on trait declarations, otherwise the change looks good to me
Here are the suggested patches
dyn-traits-patch.txt
ceaeec0
to
9ff717b
Compare
Whoop, just saw this now. Added a commit that does the same for |
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 good!
Just dropping by to acknowledge that I owe a review here, will do it ASAP (hopefully this week) |
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.
LGTM, I left some comments but mostly about rustlang idiomatics, the logic looks sound.
.gitignore
Outdated
/results |
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: remove empty trailing line
sim-lib/src/lib.rs
Outdated
pub trait DestinationGenerator: Send { | ||
// choose_destination picks a destination node within the network, returning the node's information and its | ||
// capacity (if available). | ||
fn choose_destination(&self, source: PublicKey) -> (NodeInfo, Option<u64>); | ||
} | ||
|
||
#[derive(Debug, Error)] | ||
#[error("Payment generation error: {0}")] | ||
pub struct PaymentGenerationError(String); | ||
pub trait PaymentGenerator { | ||
|
||
pub trait PaymentGenerator: Display + Send { | ||
// Returns the number of seconds that a node should wait until firing its next payment. | ||
fn next_payment_wait(&self) -> time::Duration; | ||
|
||
// Returns a payment amount based on the capacity of the sending and receiving node. | ||
fn payment_amount(&self, destination_capacity: u64) -> Result<u64, PaymentGenerationError>; | ||
// Returns a payment amount based, with a destination capacity optionally provided to inform the amount picked. | ||
fn payment_amount( | ||
&self, | ||
destination_capacity: Option<u64>, | ||
) -> Result<u64, PaymentGenerationError>; |
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.
Aren't all these supposed to be docs? (///
)
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.
Codebase is a little all over the place, going to add a commit to fix all the // -> ///
in one go.
70ca4ba
sim-lib/src/defined_activity.rs
Outdated
impl DestinationGenerator for DefinedPaymentActivity { | ||
fn choose_destination( | ||
&self, | ||
_source: bitcoin::secp256k1::PublicKey, |
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: this could be just _: bitcoin::secp256k1::PublicKey
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.
Is just a _
idiomatic rust, out of interest?
(old golang habits die hard)
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.
Ummm, not sure if I picked this up from rustlang or where if I'm honest
In preparation for implementing our generation traits for defined activities, we loosen the tie to destination capacity in our trait definition (which is a characteristic of the random activity generation implementation).
9aab9e1
to
3e85c5a
Compare
3e85c5a
to
75ac437
Compare
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.
ACK 75ac437
This PR unifies dispatch of random and defined activities. I think that this is worthwhile doing:
produce_events
andproduce_random_events
)Opening up in draft for an early look (still needs some cleanup). This is my first foray into trait objects, so this PR only exists by the good graces of crust of rust / suggestions for more canonical rust ways of doing this are very welcome!