Skip to content

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

Merged
merged 15 commits into from
May 7, 2025

Conversation

l0r1s
Copy link
Collaborator

@l0r1s l0r1s commented May 5, 2025

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)

  • Closes #[issue number]

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Other (please describe):

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

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have run cargo fmt and cargo clippy to ensure my code is formatted and linted correctly
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

Screenshots (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.

@github-actions github-actions bot added the run-bittensor-e2e-tests Runs Bittensor SDK and BTCLI tests label May 5, 2025
@l0r1s l0r1s added the skip-cargo-audit This PR fails cargo audit but needs to be merged anyway label May 6, 2025
@@ -157,11 +166,21 @@ pub mod pallet {
OptionQuery,
>;

/// A map of crowdloan ids to their contributors count.
#[pallet::storage]
pub type ContributorsCount<T: Config> =
Copy link
Collaborator

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.

Copy link
Collaborator Author

@l0r1s l0r1s May 6, 2025

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 {
Copy link
Collaborator

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?

Copy link
Collaborator Author

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.

Copy link
Collaborator

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.

@@ -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);
Copy link
Collaborator

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.

@sam0x17 sam0x17 merged commit b7f2fbb into devnet-ready May 7, 2025
53 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
run-bittensor-e2e-tests Runs Bittensor SDK and BTCLI tests skip-cargo-audit This PR fails cargo audit but needs to be merged anyway
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants