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

Added MutatedActiveLoan storage for PoV optimization #1283

Closed
wants to merge 4 commits into from

Conversation

lemunozm
Copy link
Contributor

Description

Fixes #1193

Tasks

  • Implementation
  • Test passing
  • Update benchmarks

Changes and Descriptions

  • Added new storage MutatedActiveLoans.
  • Remove not needed loan_id from ActiveLoan.

Type of change

  • Breaking change

@lemunozm lemunozm added D5-breaks-api Pull request changes public api. Document changes publicly. crcl-protocol Circle protocol related. labels Mar 24, 2023
@lemunozm lemunozm self-assigned this Mar 24, 2023
@lemunozm
Copy link
Contributor Author

I think this change adds a lot of complexity to the code and makes the benchmarks difficult to measure correctly. Please double-check this. Is this PR really really needed if we get #1269 done?

pub trait BoundedVecExt<T> {
/// Same as [`BoundedVec::try_push()`] but returns a reference to the pushed element in the
/// vector
fn try_push_fetch(&mut self, element: T) -> Result<&mut T, T>;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

A better name for this method?

Copy link
Collaborator

Choose a reason for hiding this comment

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

push_fetch_(trying_to_at_least)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I do not get well what you mean here 🙂

@mustermeiszer
Copy link
Collaborator

I think this change adds a lot of complexity to the code and makes the benchmarks difficult to measure correctly. Please double-check this. Is this PR really really needed if we get #1269 done?

I agree. We should definitely wait till PoV is benched too.

And given a second thought, why would this even be a reduction in PoV size? It rather looks like an increase, but maybe I am getting the size impact not correctly

For a successful state transition from block x to block x+1 the relay chain needs

  • block x+1 → extrinsics and final root
  • (key, value)-pairs of touched keys at the state of x

if this assumption is correct, than we will anyways send the whole vector all the time, due to reading.

@lemunozm
Copy link
Contributor Author

lemunozm commented Mar 24, 2023

I think (or I understand from previous conversations) each extrinsic is measured isolated for the PoV Size.

So, for each active loan modification, we are writing now into MutatedActiveLoans storage which is smaller than ActiveLoans, so we are not increasing too much the PoV Size.

This increases the PoV Size for portfolio_valuation, but it's ok if other calls are smaller. Statistically, if we sum all extrinsic done in pallet-loans per block, the PoV Size will be smaller than writing always the whole ActiveLoan vector for each modification of each loan.

@mustermeiszer
Copy link
Collaborator

I think (or I understand from previous conversations) each extrinsic is measured isolated for the PoV Size.

Ahh, yeah, that is correct and a benchmarking issue... mmh

@mustermeiszer
Copy link
Collaborator

cc @lemunozm

@lemunozm
Copy link
Contributor Author

I think we can close it 👍🏻. In case we want to go with this solution we can reopen, although I think the database has changed a lot from this.

@lemunozm lemunozm closed this Nov 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crcl-protocol Circle protocol related. D5-breaks-api Pull request changes public api. Document changes publicly.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Loans: Add ActiveLoanMutations storage to avoid PoV limits
2 participants