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.
Squashed 'bridges/snowbridge/' changes from afc668ef63..0becdae2b8
0becdae2b8 Take LengthToFee into account (#1065) dfb015035b Init agents and channels with migration (#1063) git-subtree-dir: bridges/snowbridge git-subtree-split: 0becdae2b8d3827a6e5502ff445f418bdab75943
- Loading branch information
Showing
9 changed files
with
203 additions
and
78 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
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.