Files
pezkuwi-sdk/bridges/snowbridge/pallets/system/src/migration.rs
T
pezkuwichain 379cb741ed feat: Rebrand Polkadot/Substrate references to PezkuwiChain
This commit systematically rebrands various references from Parity Technologies'
Polkadot/Substrate ecosystem to PezkuwiChain within the kurdistan-sdk.

Key changes include:
- Updated external repository URLs (zombienet-sdk, parity-db, parity-scale-codec, wasm-instrument) to point to pezkuwichain forks.
- Modified internal documentation and code comments to reflect PezkuwiChain naming and structure.
- Replaced direct references to  with  or specific paths within the  for XCM, Pezkuwi, and other modules.
- Cleaned up deprecated  issue and PR references in various  and  files, particularly in  and  modules.
- Adjusted image and logo URLs in documentation to point to PezkuwiChain assets.
- Removed or rephrased comments related to external Polkadot/Substrate PRs and issues.

This is a significant step towards fully customizing the SDK for the PezkuwiChain ecosystem.
2025-12-14 00:04:10 +03:00

224 lines
6.1 KiB
Rust

// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2023 Snowfork <hello@snowfork.com>
//! Governance API for controlling the Ethereum side of the bridge
use super::*;
use pezframe_support::{
migrations::VersionedMigration,
pezpallet_prelude::*,
traits::{OnRuntimeUpgrade, UncheckedOnRuntimeUpgrade},
weights::Weight,
};
use pezsp_std::marker::PhantomData;
#[cfg(feature = "try-runtime")]
use pezsp_runtime::TryRuntimeError;
const LOG_TARGET: &str = "ethereum_system::migration";
/// The in-code storage version.
pub const STORAGE_VERSION: StorageVersion = StorageVersion::new(1);
pub mod v0 {
use super::*;
pub struct InitializeOnUpgrade<T, BridgeHubParaId, AssetHubParaId>(
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");
tracing::info!(
target: LOG_TARGET,
"Ethereum system initialized."
);
T::DbWeight::get().reads_writes(2, 5)
} else {
tracing::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() {
tracing::info!(
target: LOG_TARGET,
"Agents and channels not initialized. Initialization will run."
);
} else {
tracing::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> {
pezframe_support::ensure!(
Pallet::<T>::is_initialized(),
"Agents and channels were not initialized."
);
Ok(())
}
}
}
pub mod v1 {
use super::*;
#[cfg(feature = "try-runtime")]
use pezsp_core::U256;
/// Descreases the fee per gas.
pub struct FeePerGasMigration<T>(PhantomData<T>);
#[cfg(feature = "try-runtime")]
impl<T> FeePerGasMigration<T>
where
T: Config,
{
/// Calculate the fee required to pay for gas on Ethereum.
fn calculate_remote_fee_v1(params: &PricingParametersOf<T>) -> U256 {
use snowbridge_outbound_queue_primitives::v1::{
AgentExecuteCommand, Command, ConstantGasMeter, GasMeter,
};
let command = Command::AgentExecute {
agent_id: H256::zero(),
command: AgentExecuteCommand::TransferToken {
token: H160::zero(),
recipient: H160::zero(),
amount: 0,
},
};
let gas_used_at_most = ConstantGasMeter::maximum_gas_used_at_most(&command);
params
.fee_per_gas
.saturating_mul(gas_used_at_most.into())
.saturating_add(params.rewards.remote)
}
/// Calculate the fee required to pay for gas on Ethereum.
fn calculate_remote_fee_v2(params: &PricingParametersOf<T>) -> U256 {
use snowbridge_outbound_queue_primitives::v2::{Command, ConstantGasMeter, GasMeter};
let command = Command::UnlockNativeToken {
token: H160::zero(),
recipient: H160::zero(),
amount: 0,
};
let gas_used_at_most = ConstantGasMeter::maximum_dispatch_gas_used_at_most(&command);
params
.fee_per_gas
.saturating_mul(gas_used_at_most.into())
.saturating_add(params.rewards.remote)
}
}
/// The percentage gas increase. We must adjust the fee per gas by this percentage.
const GAS_INCREASE_PERCENTAGE: u64 = 70;
impl<T> UncheckedOnRuntimeUpgrade for FeePerGasMigration<T>
where
T: Config,
{
fn on_runtime_upgrade() -> Weight {
let mut params = Pallet::<T>::parameters();
let old_fee_per_gas = params.fee_per_gas;
// Fee per gas can be set based on a percentage in order to keep the remote fee the
// same.
params.fee_per_gas = params.fee_per_gas * GAS_INCREASE_PERCENTAGE / 100;
tracing::info!(
target: LOG_TARGET,
from=?old_fee_per_gas,
to=?params.fee_per_gas,
"Fee per gas migrated."
);
PricingParameters::<T>::put(params);
T::DbWeight::get().reads_writes(1, 1)
}
#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<Vec<u8>, TryRuntimeError> {
use codec::Encode;
let params = Pallet::<T>::parameters();
let remote_fee_v1 = Self::calculate_remote_fee_v1(&params);
let remote_fee_v2 = Self::calculate_remote_fee_v2(&params);
tracing::info!(
target: LOG_TARGET,
pricing_parameters=?params, ?remote_fee_v1, ?remote_fee_v2,
"Pre fee per gas migration"
);
Ok((params, remote_fee_v1, remote_fee_v2).encode())
}
#[cfg(feature = "try-runtime")]
fn post_upgrade(state: Vec<u8>) -> Result<(), TryRuntimeError> {
use codec::Decode;
let (old_params, old_remote_fee_v1, old_remote_fee_v2): (
PricingParametersOf<T>,
U256,
U256,
) = Decode::decode(&mut &state[..]).unwrap();
let params = Pallet::<T>::parameters();
ensure!(old_params.exchange_rate == params.exchange_rate, "Exchange rate unchanged.");
ensure!(old_params.rewards == params.rewards, "Rewards unchanged.");
ensure!(
(old_params.fee_per_gas * GAS_INCREASE_PERCENTAGE / 100) == params.fee_per_gas,
"Fee per gas decreased."
);
ensure!(old_params.multiplier == params.multiplier, "Multiplier unchanged.");
let remote_fee_v1 = Self::calculate_remote_fee_v1(&params);
let remote_fee_v2 = Self::calculate_remote_fee_v2(&params);
ensure!(
remote_fee_v1 <= old_remote_fee_v1,
"The v1 remote fee can cover the cost of the previous fee."
);
ensure!(
remote_fee_v2 <= old_remote_fee_v2,
"The v2 remote fee can cover the cost of the previous fee."
);
tracing::info!(
target: LOG_TARGET,
pricing_parameters=?params, ?remote_fee_v1, ?remote_fee_v2,
"Post fee per gas migration"
);
Ok(())
}
}
}
/// Run the migration of the gas price and increment the pallet version so it cannot be re-run.
pub type FeePerGasMigrationV0ToV1<T> = VersionedMigration<
0,
1,
v1::FeePerGasMigration<T>,
Pallet<T>,
<T as pezframe_system::Config>::DbWeight,
>;