-
Notifications
You must be signed in to change notification settings - Fork 20
Storage migration for pallet-xcm SafeXcmVersion constant #2422
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
Changes from 9 commits
4799abb
67a8195
a84832c
23fe781
53de125
7d99c7f
baf3fbc
d00ba6c
caf456c
dffbf3b
46a9483
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# AGENT GUIDELINES | ||
- This document provides guidelines for contributing to the project. | ||
- Please ensure that your contributions adhere to the project's coding standards and style guidelines. | ||
|
||
## How to Contribute | ||
- Fork the repository and create a new branch for your feature or bug fix. | ||
- Make your changes and commit them with clear, descriptive commit messages. | ||
- Submit a pull request with a detailed description of your changes. | ||
|
||
## Code Review Process | ||
- All contributions will be reviewed by the project maintainers. | ||
- Feedback will be provided, and changes may be requested before merging. | ||
|
||
## Testing Your Changes | ||
- Ensure that your changes are covered by tests. | ||
- Run the test suite to verify that all tests pass before submitting your pull request. | ||
|
||
## Documentation | ||
- Update the documentation to reflect any changes made to the codebase. | ||
- Ensure that the documentation is clear and easy to understand. | ||
|
||
## Issues and Bug Reports | ||
- If you find a bug, please open an issue in the repository. | ||
- Provide as much detail as possible, including steps to reproduce the issue and any relevant logs or screenshots. | ||
|
||
## Coding Standards | ||
- Follow the project's coding standards and style guidelines. | ||
- Use meaningful variable and function names. | ||
- Write clear and concise comments where necessary. | ||
|
||
## License | ||
- By contributing to this project, you agree that your contributions will be licensed under the project's license. | ||
|
||
## Dev Environment Tips | ||
- Set up your development environment according to the project's guidelines. | ||
- Use the provided scripts or tools to manage dependencies and run the project locally. | ||
- Regularly pull the latest changes from the main branch to keep your branch up to date. | ||
|
||
## Testing Instructions | ||
- Find the CI plan in the .github directory. `verify-pr-commit.yml` is the main CI plan that runs on every PR. | ||
- First run `make check` to ensure that cargo is installed and the project is set up correctly. | ||
- Run the build to ensure that the project compiles without errors. | ||
```bash | ||
make build-no-relay | ||
``` | ||
- Rust builds can take up to 20 minutes, so be patient. | ||
- Run the unit test suite using the provided commands. Network access is not required for these tests. | ||
```bash | ||
make test | ||
``` | ||
- Run the e2e test suite using the provided commands. Network access is not required for these tests, only that you have a local node running. | ||
```bash | ||
make e2e-tests | ||
``` | ||
- Run the linter to check for code style issues. | ||
```bash | ||
make lint | ||
``` | ||
- Run the formatter to ensure code style consistency. | ||
```bash | ||
make lint-fix | ||
``` | ||
|
||
## PR Instructions | ||
Title Format: `[AGENT] <short description>` |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -373,29 +373,55 @@ check-try-runtime-installed: | |||||
try-runtime-create-snapshot-paseo-testnet: check-try-runtime-installed | ||||||
try-runtime create-snapshot --uri wss://0.rpc.testnet.amplica.io:443 testnet-paseo-all-pallets.state | ||||||
|
||||||
try-runtime-create-snapshot-westend-testnet: check-try-runtime-installed | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we change the RPC to not include the API key, then we can remove this check. Otherwise, being cautious and not checking in API keys. |
||||||
@if [ -z "$(ONFINALITY_APIKEY)" ]; then \ | ||||||
echo "Error: ONFINALITY_APIKEY environment variable is not set. Please set it before running this target."; \ | ||||||
echo "Example: ONFINALITY_APIKEY=your-api-key-here make try-runtime-check-migrations-westend-testnet"; \ | ||||||
exit 1; \ | ||||||
fi | ||||||
try-runtime create-snapshot --uri wss://node-7330371704012918784.nv.onfinality.io/ws?apikey=$(ONFINALITY_APIKEY) testnet-paseo-all-pallets.state | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The snapshot filename
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
|
||||||
# mainnet snapshot takes as many as 24 hours to complete | ||||||
try-runtime-create-snapshot-mainnet: check-try-runtime-installed | ||||||
try-runtime create-snapshot --uri wss://1.rpc.frequency.xyz:443 mainnet-all-pallets.state | ||||||
|
||||||
try-runtime-upgrade-paseo-testnet: check-try-runtime-installed | ||||||
cargo build --release --features frequency-testnet,try-runtime && \ | ||||||
try-runtime --runtime ./target/release/wbuild/frequency-runtime/frequency_runtime.wasm on-runtime-upgrade live --uri wss://0.rpc.testnet.amplica.io:443 | ||||||
try-runtime --runtime ./target/release/wbuild/frequency-runtime/frequency_runtime.wasm on-runtime-upgrade --blocktime=6000 live --uri wss://0.rpc.testnet.amplica.io:443 | ||||||
|
||||||
try-runtime-upgrade-mainnet: check-try-runtime-installed | ||||||
cargo build --release --features frequency,try-runtime && \ | ||||||
try-runtime --runtime ./target/release/wbuild/frequency-runtime/frequency_runtime.wasm on-runtime-upgrade live --uri wss://1.rpc.frequency.xyz:443 | ||||||
try-runtime --runtime ./target/release/wbuild/frequency-runtime/frequency_runtime.wasm on-runtime-upgrade --blocktime=6000 live --uri wss://1.rpc.frequency.xyz:443 | ||||||
|
||||||
try-runtime-use-snapshot-paseo-testnet: check-try-runtime-installed | ||||||
cargo build --release --features frequency-testnet,try-runtime && \ | ||||||
try-runtime --runtime ./target/release/wbuild/frequency-runtime/frequency_runtime.wasm on-runtime-upgrade snap --path testnet-paseo-all-pallets.state | ||||||
try-runtime --runtime ./target/release/wbuild/frequency-runtime/frequency_runtime.wasm on-runtime-upgrade --blocktime=6000 snap --path testnet-paseo-all-pallets.state | ||||||
|
||||||
try-runtime-use-snapshot-mainnet: check-try-runtime-installed | ||||||
cargo build --release --features frequency,try-runtime && \ | ||||||
try-runtime --runtime ./target/release/wbuild/frequency-runtime/frequency_runtime.wasm on-runtime-upgrade snap --path mainnet-all-pallets.state | ||||||
try-runtime --runtime ./target/release/wbuild/frequency-runtime/frequency_runtime.wasm on-runtime-upgrade --blocktime=6000 snap --path mainnet-all-pallets.state | ||||||
|
||||||
try-runtime-check-migrations-paseo-testnet: check-try-runtime-installed | ||||||
cargo build --release --features frequency-testnet,try-runtime -q --locked && \ | ||||||
try-runtime --runtime ./target/release/wbuild/frequency-runtime/frequency_runtime.wasm on-runtime-upgrade --checks="pre-and-post" --disable-spec-version-check --no-weight-warnings live --uri wss://0.rpc.testnet.amplica.io:443 | ||||||
try-runtime --runtime ./target/release/wbuild/frequency-runtime/frequency_runtime.wasm on-runtime-upgrade --blocktime=6000 --checks="pre-and-post" --disable-spec-version-check --no-weight-warnings live --uri wss://0.rpc.testnet.amplica.io:443 | ||||||
|
||||||
try-runtime-check-migrations-westend-testnet: check-try-runtime-installed | ||||||
@if [ -z "$(ONFINALITY_APIKEY)" ]; then \ | ||||||
echo "Error: ONFINALITY_APIKEY environment variable is not set. Please set it before running this target."; \ | ||||||
echo "Example: ONFINALITY_APIKEY=your-api-key-here make try-runtime-check-migrations-westend-testnet"; \ | ||||||
exit 1; \ | ||||||
fi | ||||||
cargo build --release --features frequency-westend,frequency-bridging,try-runtime -q --locked && \ | ||||||
try-runtime --runtime ./target/release/wbuild/frequency-runtime/frequency_runtime.wasm on-runtime-upgrade --blocktime=6000 --checks="pre-and-post" --disable-spec-version-check --no-weight-warnings live --uri wss://node-7330371704012918784.nv.onfinality.io/ws?apikey=$(ONFINALITY_APIKEY) | ||||||
|
||||||
try-runtime-check-migrations-local: check-try-runtime-installed | ||||||
cargo build --features frequency-local,frequency-bridging,try-runtime -q --locked && \ | ||||||
try-runtime --runtime ./target/debug/wbuild/frequency-runtime/frequency_runtime.wasm on-runtime-upgrade --blocktime=6000 --checks="pre-and-post" --disable-spec-version-check --disable-mbm-checks --no-weight-warnings live --uri ws://localhost:9944 | ||||||
|
||||||
try-runtime-check-migrations-none-local: check-try-runtime-installed | ||||||
cargo build --features frequency-local,frequency-bridging,try-runtime -q --locked && \ | ||||||
try-runtime --runtime ./target/debug/wbuild/frequency-runtime/frequency_runtime.wasm on-runtime-upgrade --blocktime=6000 --checks="none" --disable-spec-version-check --disable-mbm-checks --no-weight-warnings live --uri ws://localhost:9944 | ||||||
|
||||||
# Pull the Polkadot version from the polkadot-cli package in the Cargo.lock file. | ||||||
# This will break if the lock file format changes | ||||||
POLKADOT_VERSION=$(shell grep "^polkadot-cli" Cargo.toml | grep -o 'branch[[:space:]]*=[[:space:]]*"\(.*\)"' | sed 's/branch *= *"\(.*\)"/\1/' | head -n 1) | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -400,3 +400,12 @@ pub type CapacityRewardEraLength = | |
ConstU32<{ prod_or_testnet_or_local!(14 * DAYS, 1 * HOURS, 50) }>; | ||
|
||
// -end- Capacity Pallet --- | ||
|
||
// --- XCM Version --- | ||
#[cfg(feature = "frequency-bridging")] | ||
pub mod xcm_version { | ||
/// The default XCM version considered safe for the network. | ||
/// This is not the latest version, but the one that is considered stable and safe to use. | ||
/// It is used to ensure that the network can handle XCM messages without issues. | ||
pub const SAFE_XCM_VERSION: u32 = 4; | ||
} | ||
Comment on lines
+403
to
+411
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can probably be moved to an xcm commmon or other, but don't want to step on other refactoring coming in soon. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#![cfg(all(feature = "frequency-bridging", feature = "try-runtime"))] | ||
use super::*; | ||
use crate::xcm::tests::mock::{new_test_ext_with_balances, TestRuntime}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This mock runtime is enough to test storage migration for the SafeXcmVersion constant. |
||
use common_runtime::constants::xcm_version::SAFE_XCM_VERSION; | ||
use parity_scale_codec::Decode; | ||
|
||
#[test] | ||
fn pre_upgrade_returns_current_value() { | ||
new_test_ext_with_balances(vec![]).execute_with(|| { | ||
let encoded_result = SetSafeXcmVersion::<TestRuntime>::pre_upgrade().unwrap(); | ||
let decoded_result = Option::<u32>::decode(&mut &encoded_result[..]).unwrap(); | ||
assert_eq!(decoded_result, None); | ||
}); | ||
} | ||
|
||
#[test] | ||
fn post_upgrade_sets_safe_version() { | ||
new_test_ext_with_balances(vec![]).execute_with(|| { | ||
let storage_key = frame_support::storage::storage_prefix(b"PolkadotXcm", b"SafeXcmVersion"); | ||
|
||
// Clear the storage | ||
frame_support::storage::unhashed::kill(&storage_key); | ||
let pre = SetSafeXcmVersion::<TestRuntime>::pre_upgrade().unwrap(); | ||
SetSafeXcmVersion::<TestRuntime>::on_runtime_upgrade(); | ||
SetSafeXcmVersion::<TestRuntime>::post_upgrade(pre).unwrap(); | ||
assert_eq!( | ||
frame_support::storage::unhashed::get::<u32>(&storage_key).unwrap(), | ||
SAFE_XCM_VERSION | ||
); | ||
}); | ||
} | ||
|
||
#[test] | ||
fn migration_is_idempotent() { | ||
new_test_ext_with_balances(vec![]).execute_with(|| { | ||
let storage_key = frame_support::storage::storage_prefix(b"PolkadotXcm", b"SafeXcmVersion"); | ||
|
||
// Clear the storage initially | ||
frame_support::storage::unhashed::kill(&storage_key); | ||
|
||
// Run migration first time | ||
let weight1 = SetSafeXcmVersion::<TestRuntime>::on_runtime_upgrade(); | ||
assert_eq!( | ||
frame_support::storage::unhashed::get::<u32>(&storage_key).unwrap(), | ||
SAFE_XCM_VERSION | ||
); | ||
|
||
// Run migration second time - should be a no-op | ||
let weight2 = SetSafeXcmVersion::<TestRuntime>::on_runtime_upgrade(); | ||
assert_eq!( | ||
frame_support::storage::unhashed::get::<u32>(&storage_key).unwrap(), | ||
SAFE_XCM_VERSION | ||
); | ||
|
||
// Second run should only do a read (less weight) | ||
assert!(weight2.ref_time() < weight1.ref_time()); | ||
}); | ||
} | ||
|
||
#[test] | ||
fn test_weight_calculation() { | ||
new_test_ext_with_balances(vec![]).execute_with(|| { | ||
let storage_key = frame_support::storage::storage_prefix(b"PolkadotXcm", b"SafeXcmVersion"); | ||
|
||
// Test weight when migration is needed | ||
frame_support::storage::unhashed::kill(&storage_key); | ||
let weight_with_write = SetSafeXcmVersion::<TestRuntime>::on_runtime_upgrade(); | ||
|
||
// Test weight when migration is not needed (value already exists) | ||
let weight_read_only = SetSafeXcmVersion::<TestRuntime>::on_runtime_upgrade(); | ||
|
||
// Weight with write should be greater than read-only weight | ||
assert!(weight_with_write.ref_time() > weight_read_only.ref_time()); | ||
}); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
//! Mock runtime for tests. | ||
//! Implements both runtime APIs for fee estimation and getting the messages for transfers. | ||
|
||
use common_runtime::weights::rocksdb_weights::constants::RocksDbWeight; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updating for migration tests, which were returning 0 weight in all cases. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nitpick] Importing and using production Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||
use core::{cell::RefCell, marker::PhantomData}; | ||
use frame_support::{ | ||
construct_runtime, derive_impl, parameter_types, sp_runtime, | ||
|
@@ -81,6 +82,7 @@ impl frame_system::Config for TestRuntime { | |
type AccountId = AccountId; | ||
type AccountData = pallet_balances::AccountData<Balance>; | ||
type Lookup = IdentityLookup<AccountId>; | ||
type DbWeight = RocksDbWeight; | ||
} | ||
|
||
#[derive_impl(pallet_balances::config_preludes::TestDefaultConfig)] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
mod mock; | ||
pub mod mock; | ||
|
||
mod check_whitelist; | ||
mod fee_estimation; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file is useful for testing with OpenAI's Codex, which is enabled as a research preview.