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

feature/plmc-306-fix-testsbenchmarks-for-new-bucket-system #93

Merged

Conversation

vstam1
Copy link
Collaborator

@vstam1 vstam1 commented Oct 17, 2023

No description provided.

@linear
Copy link

linear bot commented Oct 17, 2023

PLMC-306 Fix tests/benchmarks for new Bucket System

  • Remove ct_usd_price from (do_)bid function.
  • Change testing setup to use Buckets instead of prices
  • Update tests
  • Update Benchmarks

@vstam1 vstam1 marked this pull request as ready for review October 27, 2023 08:05
Copy link
Contributor

@lrazovic lrazovic left a comment

Choose a reason for hiding this comment

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

At present, the benchmarks cannot be compiled due to a missing parameter in the calculate_auction_plmc_spent within the bid benchmark. I've provided a suggestion in the comments to address this.

Aside from that, I see this as a significant improvement and a step towards more rigorous testing.

Regarding the changes inside the instantiator I would like to get a second feedback from @JuaniRios

@vstam1: Can you also provide a brief overview of the changes in the PR description?

pallets/funding/src/instantiator.rs Outdated Show resolved Hide resolved
pallets/funding/src/benchmarking.rs Outdated Show resolved Hide resolved
pallets/funding/src/benchmarking.rs Outdated Show resolved Hide resolved
pallets/funding/src/instantiator.rs Show resolved Hide resolved
Copy link
Contributor

@JuaniRios JuaniRios left a comment

Choose a reason for hiding this comment

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

Overall I really like the new additions.
Just be aware we duplicated logic with the new MergeAccounts trait.

Also let's avoid precomputing any inputs to extrinsic (bucket pre-splitting of bids)

}
output
}

pub fn calculate_auction_funding_asset_spent(bids: Vec<BidParams<T>>) -> Vec<UserToStatemintAsset<T>> {
pub fn simulate_bids_with_bucket(bids: Vec<BidParams<T>>, metadata: &ProjectMetadataOf<T>) -> Vec<BidParams<T>> {
Copy link
Contributor

Choose a reason for hiding this comment

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

So if I understand correctly, our instantiator can only calculate auction PLMC and USDT when the whole bid amount fits in one bucket, so we need to split down these bids to neatly fit in buckets with this function?

If that's the case, we should also test that the behaviour of bucket splitting works on-chain

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Our current bucket logic in pallet-funding does exactly this split down. So I tried to keep most functions as is in the instantiator, and keep the idea of BidParams having a price. The actual price for the BidParams is calculated by the simulate_bids_with_bucket. We could still pass the original bids to the actual bidding functionality or to the bid_for_users function, as it does all the price calculation there. So it doesn't really matter if we pre split the bids or let the funding pallet logic split the bids. However, for calculating the funding/plmc assets necessary for the operation, we do have to pre calculate the actually used amount, and for that we do have to precalculate the price. I was thinking about removing the price parameter and add a ticket_size parameter, however for eventually calculating which bids made it into the auction, we have to know which parts of a bid where pushed into a new bucket. So the split in simulate_bids_with_bucket was useful to simplify the filter_bids_after_auction function

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's use the on-chain bucket instead of assuming always a zero bucket

@@ -1403,6 +1484,11 @@ pub trait Accounts {

fn accounts(&self) -> Vec<Self::Account>;
}

pub trait AccountMerge {
Copy link
Contributor

Choose a reason for hiding this comment

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

I like this approach, but it's duplicating the same logic as merge_add_mappings_by_user.

Copy link
Collaborator Author

@vstam1 vstam1 Oct 30, 2023

Choose a reason for hiding this comment

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

How I understood merge_add_mappings_by_user it does not merge the duplicate accounts in the first vector. So if the first vector contains [alice, alice, bob] then it returns [alice, alice, bob]. But I might be mistaken.

Edit: yes it keeps the duplicates. We could choose to merge the duplicates as well. What do you think @JuaniRios

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, I do not think that keeping duplicates on the first vector is intended. Let's test if fixing that breaks anything, and add that feature.
The only difference between .merge_accounts() and merge_add_mappings_by_user seems to be that one works for a single vector, and the other one for a vector of vectors.

I do like your solution more though, and if we find a way to also do vector of vectors we could completely replace the old one.
Do you think we should keep the old merge for vectors, or do something like a generic impl of merge_accounts for vector of vectors?
Open to suggestions

LockType::Participation(project_id),
);
self.do_bid_transferred_statemint_asset_assertions(funding_asset_deposits.merge_accounts(), project_id);
self.do_free_plmc_assertions(expected_free_plmc_balances.merge_accounts());
Copy link
Contributor

Choose a reason for hiding this comment

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

Already merged with merge_add_mappings_by_user

pallets/funding/src/instantiator.rs Show resolved Hide resolved
self.do_free_plmc_assertions(expected_free_plmc_balances);
self.do_free_statemint_asset_assertions(prev_funding_asset_balances);
self.do_reserved_plmc_assertions(
total_plmc_participation_locked.merge_accounts(),
Copy link
Contributor

Choose a reason for hiding this comment

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

already merged with merge_add_mappings_by_user

funding_asset_deposits.merge_accounts(),
project_id,
);
self.do_free_plmc_assertions(expected_free_plmc_balances.merge_accounts());
Copy link
Contributor

Choose a reason for hiding this comment

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

already merged

self.do_free_plmc_assertions(expected_free_plmc_balances);
// self.do_free_statemint_asset_assertions(prev_funding_asset_balances);
self.do_reserved_plmc_assertions(
total_plmc_participation_locked.merge_accounts(),
Copy link
Contributor

Choose a reason for hiding this comment

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

already merged

funding_asset_deposits.merge_accounts(),
project_id,
);
self.do_free_plmc_assertions(expected_free_plmc_balances.merge_accounts());
Copy link
Contributor

Choose a reason for hiding this comment

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

already merged

glutton_bid_1.clone(),
glutton_bid_2.clone(),
]);
let bids = MockInstantiator::simulate_bids_with_bucket(
Copy link
Contributor

Choose a reason for hiding this comment

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

We should let the protocol split the bids, and not do it ourselves before submitting the extrinsic. Although I understand that calculate_auction_plmc_spent and funding_spent do not support the calculation across multiple buckets.

Making it support it now and avoiding pre-computing the extrinsic inputs will save us future headaches

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@Polimec Polimec deleted a comment from github-actions bot Oct 31, 2023
@Polimec Polimec deleted a comment from github-actions bot Oct 31, 2023
@lrazovic
Copy link
Contributor

/bot test pallet-funding

@github-actions
Copy link

@Polimec Polimec deleted a comment from github-actions bot Oct 31, 2023
@lrazovic
Copy link
Contributor

/bot benchmark pallet-funding

@github-actions
Copy link

benchmark: Succeeded! ✅
https://github.com/Polimec/polimec-node/actions/runs/6705891334

@lrazovic
Copy link
Contributor

lrazovic commented Nov 1, 2023

/bot test pallet-funding

@lrazovic
Copy link
Contributor

lrazovic commented Nov 1, 2023

/bot benchmark pallet-funding

Copy link

github-actions bot commented Nov 1, 2023

benchmark: Succeeded! ✅
https://github.com/Polimec/polimec-node/actions/runs/6717914771

Copy link

github-actions bot commented Nov 1, 2023

@lrazovic lrazovic self-requested a review November 2, 2023 10:05
Copy link
Contributor

@lrazovic lrazovic left a comment

Choose a reason for hiding this comment

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

This second round of changes brought really interesting changes to the Instantiator and the first of many cleanups to the code, such as the new generic_map_operation. LGTM!

@lrazovic lrazovic merged commit 5e80c0e into main Nov 2, 2023
@lrazovic lrazovic deleted the feature/plmc-306-fix-testsbenchmarks-for-new-bucket-system branch November 23, 2023 14:01
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.

None yet

3 participants