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

Fix TotalIssuance on migration and TotalStake check #1166

Merged
merged 12 commits into from
Jan 30, 2025

Conversation

ales-otf
Copy link
Contributor

@ales-otf ales-otf commented Jan 17, 2025

Description

Fixes the issue we have with try-runtime.

It splits the state checker into two parts:

  • checking TotalIssuance
  • checking TotalStake

First, there is a bug in "migrate rao". It was increasing the currency issuance, because it returned a part of lock to coldkey. But TotalIssuance storage hadn't been updated. We have frame_config::Config::SingleBlockMigrations, where TotalIssuance is recalculated, but it happens before pallet's migrations are triggered. Probably, we should refactor migrations to use frame_config::Config::SingleBlockMigrations instead to prevent such issues in the future.

Another issue was related to removing of Stake storage. Because of that, it's not possible to sum all the stakes to check TotalStake. From the chat:

Regarding the try-runtime failure. I've fixed it for devnet. The 100 TAO difference was indeed caused by the root network, which wasn't initialized with the initial supply (judging by the genesis builder - let me know, if there are other places where it could be set).

But with or without it, the things are more complicated on testnet and finney.

This is how pool_initial_tao is initialized (from do_register_network implementation on devnet-ready):

        let mut pool_initial_tao = POOL_INITIAL_TAO;
        if pool_initial_tao > actual_tao_lock_amount {
            pool_initial_tao = actual_tao_lock_amount;
        }
        if pool_initial_tao < 1 {
            pool_initial_tao = 1;
        }

As you can see, it can also be actual_tao_lock_amount and 1 (is 1 ok btw?). The exact value is not written into a separate store, so we can't determine what was the value for a particular subnet. I can be wrong in all of this, but if the only source of staked TAO per subnet is SubnetTAO store, we can't calculate the exact value of TotalStake to verify it. If all of this true, the only "fix" is to remove this check.

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):

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.

@ales-otf ales-otf changed the base branch from main to devnet-ready January 17, 2025 16:57
@ales-otf ales-otf added the skip-cargo-audit This PR fails cargo audit but needs to be merged anyway label Jan 17, 2025
@ales-otf ales-otf force-pushed the fix/total-stake-migration branch from 6e74ccc to 9637986 Compare January 17, 2025 17:07
@ales-otf ales-otf marked this pull request as ready for review January 23, 2025 18:40
@ales-otf ales-otf requested a review from unconst as a code owner January 23, 2025 18:40
@ales-otf ales-otf force-pushed the fix/total-stake-migration branch from d15288b to 4163b91 Compare January 23, 2025 18:44
@ales-otf ales-otf marked this pull request as draft January 29, 2025 19:06
@ales-otf ales-otf force-pushed the fix/total-stake-migration branch 2 times, most recently from 2bc042e to bf9ab94 Compare January 30, 2025 15:29
@ales-otf ales-otf force-pushed the fix/total-stake-migration branch from bf9ab94 to d39a6ea Compare January 30, 2025 16:10
@ales-otf ales-otf changed the title Fix try-runtime accounting invariants check Fix TotalIssuance on migration and TotalStake check Jan 30, 2025
@ales-otf ales-otf marked this pull request as ready for review January 30, 2025 17:39
@sam0x17 sam0x17 removed the skip-cargo-audit This PR fails cargo audit but needs to be merged anyway label Jan 30, 2025
@sam0x17 sam0x17 merged commit 86fdc36 into devnet-ready Jan 30, 2025
19 of 20 checks passed
@ales-otf ales-otf deleted the fix/total-stake-migration branch January 31, 2025 13:52
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.

3 participants