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

Batch methods modification #437

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open

Batch methods modification #437

wants to merge 10 commits into from

Conversation

maneva3
Copy link
Collaborator

@maneva3 maneva3 commented Oct 9, 2024

No description provided.

@maneva3 maneva3 requested a review from gmanev7 October 9, 2024 13:37
Copy link
Member

@gmanev7 gmanev7 left a 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

platform/packages/platform/src/batch.rs Outdated Show resolved Hide resolved
platform/packages/platform/src/batch.rs Outdated Show resolved Hide resolved
protocol/contracts/lpp/src/stub/lender.rs Outdated Show resolved Hide resolved
@@ -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>>;
Copy link
Member

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() {
Copy link
Member

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

protocol/contracts/leaser/src/migrate.rs Outdated Show resolved Hide resolved
protocol/contracts/leaser/src/migrate.rs Outdated Show resolved Hide resolved
fn migrate_leases<Leases, MsgFactory>(
&mut self,
mut self,
Copy link
Member

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),
Copy link
Member

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?

Comment on lines 104 to 108
struct MigrateBatch {
new_code: Code,
leases_left: MaxLeases,
msgs: Batch,
result: MigrationResult,
}

enum MigrationStatus {
CapacityReached(MigrateBatch),
Success(MigrateBatch),
}
Copy link
Member

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 with next_customer at all
  • used often with long delegation calls, for example: state.result.msgs and migrated_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.

@maneva3 maneva3 force-pushed the batch_methods_modification branch from b74a4cb to 29b2dfb Compare November 6, 2024 07:25
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.

2 participants