-
Notifications
You must be signed in to change notification settings - Fork 15
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
Batch methods modification #437
base: main
Are you sure you want to change the base?
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.
Good job with the exception of mod leaser::migrate
@@ -20,7 +20,7 @@ where | |||
Lpns: Group, | |||
Self: Into<LppBatch<LppRef<Lpn, Lpns>>>, | |||
{ | |||
fn open_loan_req(&mut self, amount: Coin<Lpn>) -> Result<()>; | |||
fn open_loan_req(self, amount: Coin<Lpn>) -> Result<Batch>; | |||
fn open_loan_resp(&self, resp: Reply) -> Result<LoanResponse<Lpn>>; |
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.
for more consistent API please transform all the fn-s to consume its self
be aware that this would make obsolete more code - a debug assert at the calling location
In addition, the recent changes call for further simplification;
- remove the batch member variable at LppLenderStub
- remove the impl From<LppLenderStub<...>> for LppBatch
- ....
} | ||
|
||
lease_account.send(self.position.amount(), self.customer); | ||
let updated_account = if !surplus.is_zero() { |
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.
too generic naming, please make it more specific
fn migrate_leases<Leases, MsgFactory>( | ||
&mut self, | ||
mut self, |
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.
don't mutate self if you return a new instance, remove mut
to check what is wrong
Ok(MigrationStatus::CapacityReached(not_migrated_self)) | ||
} | ||
}, | ||
Err(err) => Err(err), |
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.
Don't you think this calls for another construct that is more relevant here?
struct MigrateBatch { | ||
new_code: Code, | ||
leases_left: MaxLeases, | ||
msgs: Batch, | ||
result: MigrationResult, | ||
} | ||
|
||
enum MigrationStatus { | ||
CapacityReached(MigrateBatch), | ||
Success(MigrateBatch), | ||
} |
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 MigrationStatus
smells
- used as a result of
MigrateBatch::migrate_leases
that does not deal withnext_customer
at all - used often with long delegation calls, for example:
state.result.msgs
andmigrated_self.result.next_customer
- multiple
match
expressions
similarly, MigrateBatch's result is also a bad choice:
- it's mutated
- used in cases where it's not suitable
Please reconsider this design choice. As a first step, I'd suggest reverting the MigrateBatch
to the previous member data and mutate-instead-of-consume
logic to its operations.
…ownership of 'self'
b74a4cb
to
29b2dfb
Compare
No description provided.