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

Add fallback decoding for the pallet-domains v3 storage migration #3407

Merged
merged 2 commits into from
Feb 27, 2025

Conversation

teor2345
Copy link
Member

This PR makes all production reads of the domain registry go through a new domain_registry_fallback() method. This method first tries decoding as the v3 storage format, then tries v2 if that doesn't work.

This is required so that code which queries the domain registry between runtime activation and storage migration still works.

Early writes to the storage using the v3 format are fine: they will be skipped as "corrupted" by the migration (which reads as v2), and be read as v3 correctly by the fallback decoder:
https://docs.rs/frame-support/latest/frame_support/storage/types/struct.StorageMap.html#method.translate_values

During local dev testing, the upgrade block logs some spurious corrupted state warnings, then the next block imports without any warnings:

2025-02-27T04:57:24.626389Z  INFO Consensus: substrate: 🏆 Imported #40 (0xf06c…371c → 0xe0d6…e46a)    
2025-02-27T04:57:25.962553Z ERROR Domain: runtime::storage: Corrupted state at `0x0b41d0c7f7b4485bd7be1d66066b00ad32214eaa0b8523eaebb7f83e73660c1b00000000`: Error    
2025-02-27T04:57:25.962925Z  WARN Domain: domain_client_operator::bundle_processor: Slow consensus block preprocessing, took 1336ms consensus_block_info=(0xe0d6391593445327fd3773219914a535407ad725ae647d8f91ca353558e5e46a, 40)
2025-02-27T04:57:26.089486Z ERROR Domain: runtime::storage: Corrupted state at `0x0b41d0c7f7b4485bd7be1d66066b00ad32214eaa0b8523eaebb7f83e73660c1b00000000`: Error    
2025-02-27T04:57:26.089795Z ERROR Domain: runtime::storage: Corrupted state at `0x0b41d0c7f7b4485bd7be1d66066b00ad32214eaa0b8523eaebb7f83e73660c1b00000000`: Error    
2025-02-27T04:57:26.090665Z ERROR Domain: runtime::storage: Corrupted state at `0x0b41d0c7f7b4485bd7be1d66066b00ad32214eaa0b8523eaebb7f83e73660c1b00000000`: Error    
...
2025-02-27T04:57:26.092961Z  INFO Consensus: sc_basic_authorship::basic_authorship: 🙌 Starting consensus session on top of parent 0xe0d6391593445327fd3773219914a535407ad725ae647d8f91ca353558e5e46a (#40)    
2025-02-27T04:57:26.093188Z ERROR Domain: runtime::storage: Corrupted state at `0x0b41d0c7f7b4485bd7be1d66066b00ad32214eaa0b8523eaebb7f83e73660c1b00000000`: Error    
2025-02-27T04:57:26.094389Z  INFO Consensus: runtime::frame-support: 🐥 New pallet "Multisig" detected in the runtime. Initializing the on-chain storage version to match the storage version defined in the pallet: StorageVersion(1)    
2025-02-27T04:57:26.094524Z  WARN Consensus: frame_support::migrations: 🚚 Pallet "Messenger" VersionedMigration migration 0->1 can be removed; on-chain is already at StorageVersion(1).    
2025-02-27T04:57:26.094592Z  INFO Consensus: frame_support::migrations: 🚚 Pallet "Domains" VersionedMigration migrating storage version from 2 to 3.
...
2025-02-27T04:57:26.101735Z  INFO Consensus: substrate: 🏆 Imported #41 (0xe0d6…e46a → 0x7063…f2be)    
2025-02-27T04:57:27.603282Z  INFO Domain: substrate: 💤 Idle (0 peers), best: #21 (0xed9f…85de), finalized #0 (0x4e8c…00f8), ⬇ 0 ⬆ 0    
2025-02-27T04:57:27.603282Z  INFO Consensus: substrate: 💤 Idle (0 peers), best: #41 (0x7063…f2be), finalized #0 (0x44cc…3a30), ⬇ 0 ⬆ 0  
...
2025-02-27T04:57:29.480017Z  INFO Consensus: sc_basic_authorship::basic_authorship: 🙌 Starting consensus session on top of parent 0x70634939d6d28c7c02409d020d276fe28901914357663e7f5141de157f68f2be (#41

Code contributor checklist:

@teor2345 teor2345 added bug Something isn't working execution Subspace execution labels Feb 27, 2025
@teor2345 teor2345 self-assigned this Feb 27, 2025
vedhavyas

This comment was marked as resolved.

Copy link
Member

@NingLin-P NingLin-P left a comment

Choose a reason for hiding this comment

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

Make sense! just one nit.

Comment on lines +371 to +372
let mut domain_obj =
Pallet::<T>::domain_registry_fallback(domain_id).ok_or(Error::DomainNotFound)?;
Copy link
Member

Choose a reason for hiding this comment

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

The issue only shortly exists in runtime API calls on the block that contains the runtime upgrade.

While do_update_domain_allow_list (and also do_register_operator) is only called during block execution, where it is either using the old runtime and before migration or the new runtime and after the migration, it should not have the issue so not needed to use domain_registry_fallback.

Though it is also no harm to use domain_registry_fallback thus non-blocker.

Copy link
Member

Choose a reason for hiding this comment

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

fine by me 👍🏼

Copy link
Member

@vedhavyas vedhavyas left a comment

Choose a reason for hiding this comment

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

LGTM!

Thank you!

Comment on lines +371 to +372
let mut domain_obj =
Pallet::<T>::domain_registry_fallback(domain_id).ok_or(Error::DomainNotFound)?;
Copy link
Member

Choose a reason for hiding this comment

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

fine by me 👍🏼

@teor2345 teor2345 added this pull request to the merge queue Feb 27, 2025
Merged via the queue into main with commit e352368 Feb 27, 2025
8 checks passed
@teor2345 teor2345 deleted the domain-registry-migration branch February 27, 2025 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working execution Subspace execution
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants