-
Notifications
You must be signed in to change notification settings - Fork 218
Crowdloan max contributors limit to avoid unbounded work #1591
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
Conversation
pallets/crowdloan/src/lib.rs
Outdated
@@ -157,11 +166,21 @@ pub mod pallet { | |||
OptionQuery, | |||
>; | |||
|
|||
/// A map of crowdloan ids to their contributors count. | |||
#[pallet::storage] | |||
pub type ContributorsCount<T: Config> = |
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.
Why did you choose a separate storage map instead of the field within the crowdload structure? We already have the "raised" computational field. The new storage map increases the DB operations number.
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.
At first I wanted to replace Contributions with CountedStorageMap but I decided to have a simple independent map, but you are are right it would probably make everything easier to put this in the crowdloan directly but in this case we still need a migration or we may have decoding issues.
|
||
use crate::*; | ||
|
||
pub fn migrate_add_contributors_count<T: Config>() -> Weight { |
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.
Could we get away without the migration since the crowdloan code didn't get to mainnet?
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.
Probably, there is only 1 crowdloan on the testnet at the moment.
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.
It's likely dependent on the next release date.
pallets/crowdloan/src/lib.rs
Outdated
@@ -630,6 +681,7 @@ pub mod pallet { | |||
// Clear refunded contributors | |||
for contributor in refunded_contributors { | |||
Contributions::<T>::remove(crowdloan_id, &contributor); | |||
Self::decrement_contributor_count(crowdloan_id); |
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.
Suboptimal operation: we could insert the final value in the map.
Description
Added a contributors limit (500) to avoid unbounded iterations when distributing dividends (being implemented for subnet leasing) and also keep track of the contributors count for each crowdloan to enforce this rule and make it easier to benchmark.
A migration to migrate existing crowdloan count (which is only on devnet atm).
Related Issue(s)
Type of Change
Breaking Change
If this PR introduces a breaking change, please provide a detailed description of the impact and the migration path for existing applications.
Checklist
cargo fmt
andcargo clippy
to ensure my code is formatted and linted correctlyScreenshots (if applicable)
Please include any relevant screenshots or GIFs that demonstrate the changes made.
Additional Notes
Please provide any additional information or context that may be helpful for reviewers.