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

Migrate neo-swaps pools to bounded storage #1253

Merged
merged 12 commits into from
Apr 8, 2024

Conversation

maltekliemann
Copy link
Contributor

What does it do?

Migrates neo-swaps pools from BTreeMap to BoundedBTreeMap to avoid potentially faulty manual MaxEncodedLen implementations. Fixes #1214.

What important points should reviewers know?

Is there something left for follow-up PRs?

What alternative implementations were considered?

Are there relevant PRs or issues?

References

@maltekliemann maltekliemann requested a review from sea212 as a code owner February 7, 2024 15:08
@maltekliemann maltekliemann self-assigned this Feb 7, 2024
@maltekliemann maltekliemann added the s:review-needed The pull request requires reviews label Feb 7, 2024
@codecov-commenter
Copy link

codecov-commenter commented Feb 7, 2024

Codecov Report

Attention: Patch coverage is 94.20290% with 8 lines in your changes are missing coverage. Please review.

Project coverage is 91.89%. Comparing base (d3017c1) to head (fee8921).

Files Patch % Lines
zrml/neo-swaps/src/lib.rs 76.19% 5 Missing ⚠️
zrml/neo-swaps/src/migration.rs 97.27% 3 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1253      +/-   ##
==========================================
+ Coverage   91.82%   91.89%   +0.07%     
==========================================
  Files         190      191       +1     
  Lines       34682    34793     +111     
==========================================
+ Hits        31847    31974     +127     
+ Misses       2835     2819      -16     
Flag Coverage Δ
tests 91.89% <94.20%> (+0.07%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@maltekliemann maltekliemann added s:review-needed The pull request requires reviews and removed s:review-needed The pull request requires reviews labels Feb 7, 2024
@mergify mergify bot added s:in-progress The pull requests is currently being worked on and removed s:review-needed The pull request requires reviews labels Feb 7, 2024
@maltekliemann maltekliemann added s:review-needed The pull request requires reviews and removed s:in-progress The pull requests is currently being worked on labels Feb 7, 2024
Chralt98
Chralt98 previously approved these changes Feb 8, 2024
Comment on lines +138 to +141
log::info!(
"MigratePoolReservesToBoundedBTreeMap: Post-upgrade pool count is {}!",
new_pool_count
);
Copy link
Member

Choose a reason for hiding this comment

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

How many pools were shown on battery station and main-net? Just want to verify without running it myself.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

51 and 74

@maltekliemann maltekliemann added this to the v0.5.1 milestone Feb 8, 2024
@sea212 sea212 modified the milestones: v0.5.1, v0.5.2 Apr 2, 2024
Copy link
Contributor

mergify bot commented Apr 2, 2024

This pull request is now in conflicts. Could you fix it @maltekliemann? 🙏

@mergify mergify bot added s:revision-needed The pull requests must be revised and removed s:review-needed The pull request requires reviews labels Apr 2, 2024
@maltekliemann maltekliemann added s:review-needed The pull request requires reviews and removed s:revision-needed The pull requests must be revised labels Apr 4, 2024
@maltekliemann maltekliemann removed the s:review-needed The pull request requires reviews label Apr 5, 2024
@mergify mergify bot added the s:in-progress The pull requests is currently being worked on label Apr 5, 2024
@maltekliemann maltekliemann added s:review-needed The pull request requires reviews and removed s:in-progress The pull requests is currently being worked on labels Apr 5, 2024
zrml/neo-swaps/src/consts.rs Show resolved Hide resolved
zrml/neo-swaps/src/lib.rs Outdated Show resolved Hide resolved
Comment on lines 1 to 27
// Copyright 2023-2024 Forecasting Technologies LTD.
//
// This file is part of Zeitgeist.
//
// Zeitgeist is free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the
// Free Software Foundation, either version 3 of the License, or (at
// your option) any later version.
//
// Zeitgeist is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Zeitgeist. If not, see <https://www.gnu.org/licenses/>.

use crate::consts::MAX_ASSETS;
use sp_runtime::traits::Get;

pub(crate) struct MaxAssets;

impl Get<u32> for MaxAssets {
fn get() -> u32 {
MAX_ASSETS
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Why is that necessary? Why don't we use a Config type for that?

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 was worried about a misconfiguration. The thing is that there's a (hard-coded!) minimum spot price required when creating a pool, so there should be a maximum number of assets allowed, because if there are too many assets, it becomes impossible to keep all spot prices above the minimum spot price. I'll add a comment to the code.

Copy link
Member

Choose a reason for hiding this comment

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

Seems a bit overkill to me to create a whole new file for that. I was thinking along the lines of putting the following line next to the constant:

pub type MaxAssets = frame_support::pallet_prelude::ConstU32<MAX_ASSETS>;

zrml/neo-swaps/src/types/max_assets.rs Outdated Show resolved Hide resolved
zrml/prediction-markets/src/mock.rs Outdated Show resolved Hide resolved
zrml/neo-swaps/src/migration.rs Show resolved Hide resolved
@mergify mergify bot added s:in-progress The pull requests is currently being worked on and removed s:review-needed The pull request requires reviews labels Apr 7, 2024
@maltekliemann maltekliemann added s:review-needed The pull request requires reviews and removed s:in-progress The pull requests is currently being worked on labels Apr 7, 2024
sea212
sea212 previously approved these changes Apr 8, 2024
Comment on lines +849 to +853
let asset_count_u16: u16 =
spot_prices.len().try_into().map_err(|_| Error::<T>::NarrowingConversion)?;
let asset_count_u32: u32 = asset_count_u16.into();
ensure!(asset_count_u16 == market.outcomes(), Error::<T>::IncorrectVecLen);
ensure!(asset_count_u32 <= MaxAssets::get(), Error::<T>::AssetCountAboveMax);
Copy link
Member

@Chralt98 Chralt98 Apr 8, 2024

Choose a reason for hiding this comment

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

You can use shadowing here if you like. I mean this:

            let asset_count: u16 =
                spot_prices.len().try_into().map_err(|_| Error::<T>::NarrowingConversion)?;
            ensure!(asset_count == market.outcomes(), Error::<T>::IncorrectVecLen);
            let asset_count: u32 = asset_count.into();
            ensure!(asset_count <= MaxAssets::get(), Error::<T>::AssetCountAboveMax);

Let me know if this doesn't work.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, you use it below... mhhh... then it's fine I guess.

Chralt98
Chralt98 previously approved these changes Apr 8, 2024
@maltekliemann maltekliemann added s:accepted This pull request is ready for merge and removed s:review-needed The pull request requires reviews labels Apr 8, 2024
@mergify mergify bot added s:review-needed The pull request requires reviews and removed s:review-needed The pull request requires reviews labels Apr 8, 2024
@maltekliemann maltekliemann dismissed stale reviews from Chralt98 and sea212 via 58ccf5e April 8, 2024 19:53
@mergify mergify bot added s:in-progress The pull requests is currently being worked on and removed s:accepted This pull request is ready for merge labels Apr 8, 2024
@maltekliemann maltekliemann added s:review-needed The pull request requires reviews and removed s:in-progress The pull requests is currently being worked on labels Apr 8, 2024
@sea212 sea212 added s:accepted This pull request is ready for merge and removed s:review-needed The pull request requires reviews labels Apr 8, 2024
@mergify mergify bot added s:review-needed The pull request requires reviews and removed s:review-needed The pull request requires reviews labels Apr 8, 2024
@mergify mergify bot merged commit fd18a90 into main Apr 8, 2024
14 checks passed
@mergify mergify bot deleted the mkl-neo-swaps-bounded-b-tree-map branch April 8, 2024 22:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
s:accepted This pull request is ready for merge
Projects
None yet
4 participants