Skip to content

Commit

Permalink
feat: Shiden runtime upgrade for pallet-dapps-staking 3.1.0 (#602)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakehemmerle authored Mar 30, 2022
1 parent 1d311bf commit 9624f9f
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 31 deletions.
18 changes: 9 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion bin/collator/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "astar-collator"
version = "3.13.0"
version = "3.14.0"
authors = ["Stake Technologies <[email protected]>"]
description = "Astar collator implementation in Rust."
build = "build.rs"
Expand Down
2 changes: 1 addition & 1 deletion runtime/astar/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "astar-runtime"
version = "3.13.0"
version = "3.14.0"
authors = ["Stake Technologies <[email protected]>"]
edition = "2018"
build = "build.rs"
Expand Down
2 changes: 1 addition & 1 deletion runtime/local/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "local-runtime"
version = "3.13.0"
version = "3.14.0"
authors = ["Stake Technologies <[email protected]>"]
edition = "2018"
build = "build.rs"
Expand Down
2 changes: 1 addition & 1 deletion runtime/shibuya/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "shibuya-runtime"
version = "3.13.0"
version = "3.14.0"
authors = ["Stake Technologies <[email protected]>"]
edition = "2018"
build = "build.rs"
Expand Down
6 changes: 3 additions & 3 deletions runtime/shiden/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "shiden-runtime"
version = "3.13.0"
version = "3.14.0"
authors = ["Stake Technologies <[email protected]>"]
edition = "2018"
build = "build.rs"
Expand Down Expand Up @@ -80,8 +80,8 @@ try-runtime-cli = { git = "https://github.com/paritytech/substrate", branch = "p
# Astar pallets
pallet-block-reward = { git = "https://github.com/AstarNetwork/astar-frame", branch = "polkadot-v0.9.17", default-features = false }
pallet-custom-signatures = { git = "https://github.com/AstarNetwork/astar-frame", branch = "polkadot-v0.9.17", default-features = false }
pallet-dapps-staking = { git = "https://github.com/AstarNetwork/astar-frame", tag = "pallet-dapps-staking-3.0.4/polkadot-v0.9.17", default-features = false }
pallet-precompile-dapps-staking = { git = "https://github.com/AstarNetwork/astar-frame", tag = "pallet-dapps-staking-3.0.4/polkadot-v0.9.17", default-features = false }
pallet-dapps-staking = { git = "https://github.com/AstarNetwork/astar-frame", tag = "pallet-dapps-staking-3.1.0/polkadot-v0.9.17", default-features = false }
pallet-precompile-dapps-staking = { git = "https://github.com/AstarNetwork/astar-frame", tag = "pallet-dapps-staking-3.1.0/polkadot-v0.9.17", default-features = false }
pallet-evm-precompile-sr25519 = { git = "https://github.com/AstarNetwork/astar-frame", tag = "pallet-evm-precompile-sr25519-1.0.0/polkadot-v0.9.17", default-features = false }

[build-dependencies]
Expand Down
36 changes: 21 additions & 15 deletions runtime/shiden/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("shiden"),
impl_name: create_runtime_str!("shiden"),
authoring_version: 1,
spec_version: 42,
spec_version: 43,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 2,
Expand Down Expand Up @@ -748,26 +748,32 @@ pub type Executive = frame_executive::Executive<
frame_system::ChainContext<Runtime>,
Runtime,
AllPalletsWithSystem,
(DappsStakingMigrationV3,),
DappsStakingFixEraLength,
>;

pub struct DappsStakingMigrationV3;
// Migration for fixing era length in dapps staking.
pub struct DappsStakingFixEraLength;

impl OnRuntimeUpgrade for DappsStakingMigrationV3 {
impl OnRuntimeUpgrade for DappsStakingFixEraLength {
fn on_runtime_upgrade() -> frame_support::weights::Weight {
pallet_dapps_staking::migrations::v3::stateful_migrate::<Runtime>(
RuntimeBlockWeights::get().max_block / 5, // should be 100_000_000_000 [ps]
)
}
use frame_system::pallet::Config;
use pallet_dapps_staking::{Config as DappStakingConfig, CurrentEra, NextEraStartingBlock};
use sp_runtime::SaturatedConversion;

#[cfg(feature = "try-runtime")]
fn pre_upgrade() -> Result<(), &'static str> {
pallet_dapps_staking::migrations::v3::pre_migrate::<Runtime, Self>()
}
let dapps_staking_block_offset: u32 = 489600; // calculated 2022/03/29
// Shiden: 1384490 - (1384490 % 7200) - (124 * 7200)

#[cfg(feature = "try-runtime")]
fn post_upgrade() -> Result<(), &'static str> {
pallet_dapps_staking::migrations::v3::post_migrate::<Runtime, Self>()
let blocks_per_era =
<Runtime as DappStakingConfig>::BlockPerEra::get().saturated_into::<u32>();
let current_era = CurrentEra::<Runtime>::get();

let next_era_starting_block =
dapps_staking_block_offset + ((current_era + 1) * blocks_per_era);

NextEraStartingBlock::<Runtime>::put(
next_era_starting_block.saturated_into::<<Runtime as Config>::BlockNumber>(),
);
<Runtime as Config>::DbWeight::get().reads_writes(1, 1)
}
}

Expand Down

0 comments on commit 9624f9f

Please sign in to comment.