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: account migration #338

Merged
merged 3 commits into from
Apr 18, 2024
Merged

fix: account migration #338

merged 3 commits into from
Apr 18, 2024

Conversation

orriin
Copy link
Contributor

@orriin orriin commented Apr 17, 2024

Fixes minor issues with the last account migration and vastly improves test coverage / sanity checks.

Issues fixed

  1. I was decoding Account straight into
        pub struct AccountDataStruct<Balance> {
            pub free: Balance,
            pub reserved: Balance,
            pub misc_frozen: Balance,
            pub fee_frozen: Balance,
        }

instead of

        pub struct AccountStruct<Balance> {
            pub nonce: u32,
            pub consumers: u32,
            pub providers: u32,
            pub sufficients: u32,
            pub data: AccountDataStruct<Balance>,
        }

which caused free to be set to nonce, reserved to be set to consumers, etc.

  1. I was updating storage using ::mutate while the state was still undecodable, leading to the new state being set in storage with everything except data reset to defaults (zero). Switching to ::insert and passing the entire new state resolves this issue.

Other changes

  • Moved migration to dedicated file, now that it's getting large
  • Greatly improved thoroughness of pre_upgrade and post_upgrade checks

@orriin orriin added the blue team defensive programming, CI, etc label Apr 17, 2024
}

const TARGET: &'static str = "runtime::account_data_migration";
pub struct Migration;
Copy link
Contributor

Choose a reason for hiding this comment

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

Might wanna give this a more descriptive name.

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 mean it is the only Migration in the account_data_migration module :P

/// Ensures post-upgrade that
/// 1. Number of accounts has not changed.
/// 2. Each account exists in storage and decodes.
/// 3. Each account has a provider val >0.
Copy link
Contributor

Choose a reason for hiding this comment

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

Was this something you wrote? I was thinking how it was even possible to get an old lifecycle runtime upgrade hook from upstream to execute in our chain, but if you wrote a brand new one, it does the job just fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I wrote this from scratch.

Co-authored-by: Keith <keith@opentensor.dev>
@sam0x17 sam0x17 merged commit be93b9a into development Apr 18, 2024
7 checks passed
@keithtensor keithtensor deleted the fix/account-migration branch April 22, 2024 21:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blue team defensive programming, CI, etc
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants