Skip to content

refactor: batch updating of asset team#869

Merged
rflechtner merged 3 commits intobonded-coins-audit-fixesfrom
audit-issue-6
Mar 6, 2025
Merged

refactor: batch updating of asset team#869
rflechtner merged 3 commits intobonded-coins-audit-fixesfrom
audit-issue-6

Conversation

@rflechtner
Copy link
Contributor

@rflechtner rflechtner commented Mar 5, 2025

fixes https://github.com/KILTprotocol/ticket/issues/3801

Changes the reset_team extrinsic to perform batch updates in order to avoid that asset management teams differ between assets of one pool.

Recommended by auditors and desired by our team - see linked ticket.

TBD

  • Update benchmarks to account for different numbers of currencies on a pool.

Checklist:

  • I have verified that the code works
    • No panics! (checked arithmetic ops, no indexing array[3] use get(3), ...)
  • I have verified that the code is easy to understand
    • If not, I have left a well-balanced amount of inline comments
  • I have left the code in a better state
  • I have documented the changes (where applicable)
    • Either PR or Ticket to update the Docs
    • Link the PR/Ticket here

@rflechtner rflechtner requested a review from ntn-x2 March 5, 2025 14:56
Copy link
Contributor

@ntn-x2 ntn-x2 left a comment

Choose a reason for hiding this comment

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

Makes sense to enforce this within the pallet. This must be mentioned somewhere in the docs tho.

@rflechtner
Copy link
Contributor Author

Makes sense to enforce this within the pallet. This must be mentioned somewhere in the docs tho.

I updated the extrinsic's description, is there any other place where the change should be documented? I don't think we have actual docs for this pallet rn.

@ntn-x2
Copy link
Contributor

ntn-x2 commented Mar 6, 2025

No I think that's all there is for now.

@rflechtner rflechtner marked this pull request as ready for review March 6, 2025 10:09
@rflechtner
Copy link
Contributor Author

@ntn-x2 I updated the benchmarks in 701410c, based on the implementation of start_destroy's benchmarks. Let me know if there are any issues here.

/// the pool is larger than `currency_count`.
/// - Other errors depending on the types in the config.
#[pallet::call_index(1)]
#[pallet::weight(T::WeightInfo::reset_team())]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
#[pallet::weight(T::WeightInfo::reset_team())]
#[pallet::weight(T::WeightInfo::reset_team(currency_count.to_owned()))]

I'm realising this needs to be changed, but in order for this to work it seems that I'd have to re-run benchmarks? I'll definitely need guidance for that, I have never done this before.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, that is correct. I think it would make sense to tackle benchmarks in a separate PR tho at the end of all changes, since benchmarking itself has some "fixed costs" which we could lower if we were to batch all changes into one benchmarking operation.

Copy link
Contributor

Choose a reason for hiding this comment

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

But in general, what you would need to do, is to pre-populate the storage with as many pools as the theoretical maximum, and then use the range of possible inputs to pass to the extrinsic. You can see an example of it for the create_pool_polynomial benchmark here:

fn create_pool_polynomial(c: Linear<1, { T::MaxCurrenciesPerPool::get() }>) {
. So I think it's sufficient to pre-populate the storage with N assets where N is the benchmark input, and then simply call reset_team(N). That should be enough.

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'm not sure I understand, 701410c already makes changes in line with the snippet you linked to, but I still can't make the change I suggested in #869 (comment) because default_weights.rs has not been updated (the compiler complains that this function takes 0 arguments but 1 argument was supplied). Should I just manually mess around in the default_weights.rs for now until it compiles, even though it's an autogenerated file?

Copy link
Contributor

Choose a reason for hiding this comment

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

Just leave the previous weight for now. Once the new benchmarks are run, the pallet will complain that it now requires one parameter, and then you can fill in the result of the benchmarks. Sorry I did not see the commit you previously linked. But yeah, just leave the old weight for the extrinsic. As soon as the new benchmarks are run, the code won't compile and you will update that. As a temporary solution, you COULD also update the weight file, since it will be overwritten anyway upon new benchmarks, but I would not recommend that.

@rflechtner rflechtner merged commit cc4475c into bonded-coins-audit-fixes Mar 6, 2025
14 of 15 checks passed
@rflechtner rflechtner deleted the audit-issue-6 branch March 6, 2025 15:18
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