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

feat(pallet-tfgrid): check storage state #817

Draft
wants to merge 11 commits into
base: development
Choose a base branch
from

Conversation

renauter
Copy link
Collaborator

@renauter renauter commented Jul 25, 2023

Description

The goal of this PR is to provide a mechanism to be able to check if storage is consistent in pallet-tfgrid.

1. try-runtime

For this, we use the try-runtime tool that allows to run tests on storage from simulated environment.
Here is how such tool can be executed against devnet:

RUST_LOG=debug cargo run --release --features=try-runtime try-runtime --runtime target/release/wbuild/tfchain-runtime/tfchain_runtime.compact.wasm --chain chainspecs/main/chainSpecRaw.json on-runtime-upgrade live --uri ws://10.10.0.151:9944

2. CheckStorageState

Ideally it should be part of some CI flow (TBD) to validate a given storage version.

For each storage version, we should implement a CheckStorageState struct with the associated checks.
This implementation should be included in the migration module that corresponds to the storage version at the end of the migration.
Example for V17Struct version of pallet-tfgrid, implementation is included in v17 module:

pub struct CheckStorageState<T: Config>(PhantomData<T>);

impl<T: Config> OnRuntimeUpgrade for CheckStorageState<T> {
    #[cfg(feature = "try-runtime")]
    fn pre_upgrade() -> Result<Vec<u8>, &'static str> {
        info!("current pallet version: {:?}", PalletVersion::<T>::get());
        assert!(PalletVersion::<T>::get() == types::StorageVersion::V17Struct);

        check_pallet_tfgrid::<T>();

        Ok(vec![])
    }
}

It also should be added in runtime the migration type to be triggered by the try-runtime command above.
Make sure you take into account the ordering of the migration stack according to the simulated environment and its current storage version (i.e if current version is V16Struct, you should have migration from V16Struct to V17Struct just before CheckStorageState of V17Struct).

type Migrations = (
    pallet_tfgrid::migrations::v17::MigrationV16toV17<Runtime>,
    pallet_tfgrid::migrations::v17::CheckStorageState<Runtime>,
);

3. check_pallet_tfgrid()

The code related to a specific storage version should be included in the following function:

pub fn check_pallet_tfgrid<T: Config>() {
    ...
}

To avoid code redundancy we will try as much as possible to take advantage of check functions from previous storage versions.

Related Issues:

Checklist:

@renauter renauter marked this pull request as ready for review November 17, 2023 21:48
@renauter renauter marked this pull request as draft March 21, 2024 15:32
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.

Pallet TFGrid: storage state checking
1 participant