This repository has been archived by the owner on Oct 22, 2024. It is now read-only.
forked from paritytech/polkadot-sdk
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge commit '64b8cc1acdfe8e4c904844984572f5d84e278a22' into ron/merg…
…e-to-upstream
- Loading branch information
Showing
8 changed files
with
202 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
bridges/snowbridge/parachain/pallets/system/src/migration.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: 2023 Snowfork <[email protected]> | ||
//! Governance API for controlling the Ethereum side of the bridge | ||
use super::*; | ||
use frame_support::traits::OnRuntimeUpgrade; | ||
use log; | ||
|
||
#[cfg(feature = "try-runtime")] | ||
use sp_runtime::TryRuntimeError; | ||
|
||
pub mod v0 { | ||
use frame_support::{pallet_prelude::*, weights::Weight}; | ||
|
||
use super::*; | ||
|
||
const LOG_TARGET: &str = "ethereum_system::migration"; | ||
|
||
pub struct InitializeOnUpgrade<T, BridgeHubParaId, AssetHubParaId>( | ||
sp_std::marker::PhantomData<(T, BridgeHubParaId, AssetHubParaId)>, | ||
); | ||
impl<T, BridgeHubParaId, AssetHubParaId> OnRuntimeUpgrade | ||
for InitializeOnUpgrade<T, BridgeHubParaId, AssetHubParaId> | ||
where | ||
T: Config, | ||
BridgeHubParaId: Get<u32>, | ||
AssetHubParaId: Get<u32>, | ||
{ | ||
fn on_runtime_upgrade() -> Weight { | ||
if !Pallet::<T>::is_initialized() { | ||
Pallet::<T>::initialize( | ||
BridgeHubParaId::get().into(), | ||
AssetHubParaId::get().into(), | ||
) | ||
.expect("infallible; qed"); | ||
log::info!( | ||
target: LOG_TARGET, | ||
"Ethereum system initialized." | ||
); | ||
T::DbWeight::get().reads_writes(2, 5) | ||
} else { | ||
log::info!( | ||
target: LOG_TARGET, | ||
"Ethereum system already initialized. Skipping." | ||
); | ||
T::DbWeight::get().reads(2) | ||
} | ||
} | ||
|
||
#[cfg(feature = "try-runtime")] | ||
fn pre_upgrade() -> Result<Vec<u8>, TryRuntimeError> { | ||
if !Pallet::<T>::is_initialized() { | ||
log::info!( | ||
target: LOG_TARGET, | ||
"Agents and channels not initialized. Initialization will run." | ||
); | ||
} else { | ||
log::info!( | ||
target: LOG_TARGET, | ||
"Agents and channels are initialized. Initialization will not run." | ||
); | ||
} | ||
Ok(vec![]) | ||
} | ||
|
||
#[cfg(feature = "try-runtime")] | ||
fn post_upgrade(_: Vec<u8>) -> Result<(), TryRuntimeError> { | ||
frame_support::ensure!( | ||
Pallet::<T>::is_initialized(), | ||
"Agents and channels were not initialized." | ||
); | ||
Ok(()) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.