Skip to content

Commit

Permalink
feat: v5.37.0 release prep (#1226)
Browse files Browse the repository at this point in the history
* feat: add lockdrop to astar and bump version

* feat: remove previous migrations

* feat: put back astar migration

* feat: add asset ce to astar and adjust precompile address

* fix: enable asset ce integration test for astar
  • Loading branch information
ashutoshvarma committed Apr 22, 2024
1 parent 8846dae commit 9801add
Show file tree
Hide file tree
Showing 13 changed files with 103 additions and 79 deletions.
12 changes: 7 additions & 5 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
@@ -1,6 +1,6 @@
[package]
name = "astar-collator"
version = "5.36.0"
version = "5.37.0"
description = "Astar collator implementation in Rust."
build = "build.rs"
default-run = "astar-collator"
Expand Down
8 changes: 7 additions & 1 deletion runtime/astar/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "astar-runtime"
version = "5.36.0"
version = "5.37.0"
build = "build.rs"
authors.workspace = true
edition.workspace = true
Expand Down Expand Up @@ -107,6 +107,7 @@ pallet-dapp-staking-v3 = { workspace = true }
pallet-dapps-staking = { workspace = true }
pallet-evm-precompile-assets-erc20 = { workspace = true }
pallet-evm-precompile-dapp-staking-v3 = { workspace = true }
pallet-evm-precompile-dispatch-lockdrop = { workspace = true }
pallet-evm-precompile-sr25519 = { workspace = true }
pallet-evm-precompile-substrate-ecdsa = { workspace = true }
pallet-evm-precompile-xcm = { workspace = true }
Expand All @@ -123,6 +124,9 @@ moonbeam-rpc-primitives-debug = { workspace = true, optional = true }
moonbeam-rpc-primitives-txpool = { workspace = true, optional = true }
precompile-utils = { workspace = true }

# chain-extensions
pallet-chain-extension-assets = { workspace = true }

[build-dependencies]
substrate-wasm-builder = { workspace = true, optional = true }

Expand Down Expand Up @@ -171,6 +175,7 @@ std = [
"pallet-evm-precompile-simple/std",
"pallet-evm-precompile-bn128/std",
"pallet-evm-precompile-dispatch/std",
"pallet-evm-precompile-dispatch-lockdrop/std",
"pallet-evm-precompile-ed25519/std",
"pallet-evm-precompile-modexp/std",
"pallet-evm-precompile-sha3fips/std",
Expand Down Expand Up @@ -210,6 +215,7 @@ std = [
"xcm-executor/std",
"pallet-xc-asset-config/std",
"substrate-wasm-builder",
"pallet-chain-extension-assets/std",
"orml-xtokens/std",
"orml-xcm-support/std",
"astar-primitives/std",
Expand Down
30 changes: 30 additions & 0 deletions runtime/astar/src/chain_extensions.rs
@@ -0,0 +1,30 @@
// This file is part of Astar.

// Copyright (C) 2019-2023 Stake Technologies Pte.Ltd.
// SPDX-License-Identifier: GPL-3.0-or-later

// Astar is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Astar is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Astar. If not, see <http://www.gnu.org/licenses/>.

use super::Runtime;

/// Registered WASM contracts chain extensions.
pub use pallet_chain_extension_assets::AssetsExtension;
use pallet_contracts::chain_extension::RegisteredChainExtension;

// Following impls defines chain extension IDs.
impl RegisteredChainExtension<Runtime> for AssetsExtension<Runtime> {
const ID: u16 = 02;
}

pub type AstarChainExtensions<Runtime> = AssetsExtension<Runtime>;
7 changes: 5 additions & 2 deletions runtime/astar/src/lib.rs
Expand Up @@ -92,6 +92,7 @@ pub use sp_consensus_aura::sr25519::AuthorityId as AuraId;
#[cfg(any(feature = "std", test))]
pub use sp_runtime::BuildStorage;

mod chain_extensions;
mod precompiles;
mod weights;
mod xcm_config;
Expand All @@ -101,6 +102,8 @@ pub type AstarAssetLocationIdConverter = AssetLocationIdConverter<AssetId, XcAss
pub use precompiles::{AstarPrecompiles, ASSET_PRECOMPILE_ADDRESS_PREFIX};
pub type Precompiles = AstarPrecompiles<Runtime, AstarAssetLocationIdConverter>;

use chain_extensions::AstarChainExtensions;

/// Constant values used within the runtime.
pub const MICROASTR: Balance = 1_000_000_000_000;
pub const MILLIASTR: Balance = 1_000 * MICROASTR;
Expand Down Expand Up @@ -148,7 +151,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("astar"),
impl_name: create_runtime_str!("astar"),
authoring_version: 1,
spec_version: 84,
spec_version: 85,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 2,
Expand Down Expand Up @@ -669,7 +672,7 @@ impl pallet_contracts::Config for Runtime {
type CallStack = [pallet_contracts::Frame<Self>; 5];
type WeightPrice = pallet_transaction_payment::Pallet<Self>;
type WeightInfo = pallet_contracts::weights::SubstrateWeight<Self>;
type ChainExtension = ();
type ChainExtension = AstarChainExtensions<Self>;
type Schedule = Schedule;
type AddressGenerator = pallet_contracts::DefaultAddressGenerator;
type MaxCodeLen = ConstU32<{ 123 * 1024 }>;
Expand Down
42 changes: 41 additions & 1 deletion runtime/astar/src/precompiles.rs
Expand Up @@ -26,6 +26,7 @@ use pallet_evm_precompile_blake2::Blake2F;
use pallet_evm_precompile_bn128::{Bn128Add, Bn128Mul, Bn128Pairing};
use pallet_evm_precompile_dapp_staking_v3::DappStakingV3Precompile;
use pallet_evm_precompile_dispatch::Dispatch;
use pallet_evm_precompile_dispatch_lockdrop::DispatchLockdrop;
use pallet_evm_precompile_ed25519::Ed25519Verify;
use pallet_evm_precompile_modexp::Modexp;
use pallet_evm_precompile_sha3fips::Sha3FIPS256;
Expand All @@ -34,6 +35,7 @@ use pallet_evm_precompile_sr25519::Sr25519Precompile;
use pallet_evm_precompile_substrate_ecdsa::SubstrateEcdsaPrecompile;
use pallet_evm_precompile_xcm::XcmPrecompile;
use precompile_utils::precompile_set::*;
use sp_core::ConstU32;
use sp_std::fmt::Debug;

/// The asset precompile address prefix. Addresses that match against this prefix will be routed
Expand Down Expand Up @@ -65,6 +67,32 @@ impl Contains<RuntimeCall> for WhitelistedCalls {
}
}
}

/// Filter that only allows whitelisted runtime call to pass through dispatch-lockdrop precompile
pub struct WhitelistedLockdropCalls;

impl Contains<RuntimeCall> for WhitelistedLockdropCalls {
fn contains(t: &RuntimeCall) -> bool {
match t {
RuntimeCall::Utility(pallet_utility::Call::batch { calls })
| RuntimeCall::Utility(pallet_utility::Call::batch_all { calls }) => calls
.iter()
.all(|call| WhitelistedLockdropCalls::contains(call)),
RuntimeCall::DappStaking(pallet_dapp_staking_v3::Call::unbond_and_unstake {
..
}) => true,
RuntimeCall::DappStaking(pallet_dapp_staking_v3::Call::withdraw_unbonded {
..
}) => true,
RuntimeCall::Balances(pallet_balances::Call::transfer_all { .. }) => true,
RuntimeCall::Balances(pallet_balances::Call::transfer_keep_alive { .. }) => true,
RuntimeCall::Balances(pallet_balances::Call::transfer_allow_death { .. }) => true,
RuntimeCall::Assets(pallet_assets::Call::transfer { .. }) => true,
_ => false,
}
}
}

/// The PrecompileSet installed in the Astar runtime.
#[precompile_utils::precompile_name_from_address]
pub type AstarPrecompilesSetAt<R, C> = (
Expand Down Expand Up @@ -115,6 +143,18 @@ pub type AstarPrecompilesSetAt<R, C> = (
CallableByPrecompile,
),
>,
// Skipping 20485 and 20486 to make sure all network have consistent
// precompiles address
PrecompileAt<
AddressU64<20487>,
DispatchLockdrop<
R,
DispatchFilterValidate<RuntimeCall, WhitelistedLockdropCalls>,
ConstU32<8>,
>,
// Not callable from smart contract nor precompiled, only EOA accounts
(),
>,
);

pub type AstarPrecompiles<R, C> = PrecompileSetBuilder<
Expand All @@ -123,7 +163,7 @@ pub type AstarPrecompiles<R, C> = PrecompileSetBuilder<
// Skip precompiles if out of range.
PrecompilesInRangeInclusive<
// We take range as last precompile index, UPDATE this once new prcompile is added
(AddressU64<1>, AddressU64<20484>),
(AddressU64<1>, AddressU64<20487>),
AstarPrecompilesSetAt<R, C>,
>,
// Prefixed precompile sets (XC20)
Expand Down
2 changes: 1 addition & 1 deletion runtime/local/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "local-runtime"
version = "5.36.0"
version = "5.37.0"
build = "build.rs"
authors.workspace = true
edition.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion runtime/shibuya/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "shibuya-runtime"
version = "5.36.0"
version = "5.37.0"
build = "build.rs"
authors.workspace = true
edition.workspace = true
Expand Down
30 changes: 2 additions & 28 deletions runtime/shibuya/src/lib.rs
Expand Up @@ -174,7 +174,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("shibuya"),
impl_name: create_runtime_str!("shibuya"),
authoring_version: 1,
spec_version: 126,
spec_version: 127,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 2,
Expand Down Expand Up @@ -1459,33 +1459,7 @@ pub type Executive = frame_executive::Executive<
/// All migrations that will run on the next runtime upgrade.
///
/// Once done, migrations should be removed from the tuple.
pub type Migrations = (
OracleIntegrationLogic,
pallet_price_aggregator::PriceAggregatorInitializer<Runtime, InitPrice>,
);

pub struct InitPrice;
impl Get<CurrencyAmount> for InitPrice {
fn get() -> CurrencyAmount {
// 0.15 $
CurrencyAmount::from_rational(15, 100)
}
}

use frame_support::traits::OnRuntimeUpgrade;
pub struct OracleIntegrationLogic;
impl OnRuntimeUpgrade for OracleIntegrationLogic {
fn on_runtime_upgrade() -> Weight {
// 1. Set initial storage versions for the membership pallet
use frame_support::traits::StorageVersion;
StorageVersion::new(4)
.put::<pallet_membership::Pallet<Runtime, OracleMembershipInstance>>();

// No storage version for the `orml_oracle` pallet, it's essentially 0

<Runtime as frame_system::Config>::DbWeight::get().writes(1)
}
}
pub type Migrations = ();

type EventRecord = frame_system::EventRecord<
<Runtime as frame_system::Config>::RuntimeEvent,
Expand Down
2 changes: 1 addition & 1 deletion runtime/shiden/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "shiden-runtime"
version = "5.36.0"
version = "5.37.0"
build = "build.rs"
authors.workspace = true
edition.workspace = true
Expand Down
37 changes: 2 additions & 35 deletions runtime/shiden/src/lib.rs
Expand Up @@ -153,7 +153,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("shiden"),
impl_name: create_runtime_str!("shiden"),
authoring_version: 1,
spec_version: 123,
spec_version: 124,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 2,
Expand Down Expand Up @@ -1129,40 +1129,7 @@ parameter_types! {
/// All migrations that will run on the next runtime upgrade.
///
/// Once done, migrations should be removed from the tuple.
pub type Migrations = (pallet_static_price_provider::ActivePriceUpdate<Runtime, InitPrice>,);

use frame_support::traits::OnRuntimeUpgrade;
pub struct SetNewTierConfig;
impl OnRuntimeUpgrade for SetNewTierConfig {
fn on_runtime_upgrade() -> Weight {
use astar_primitives::oracle::PriceProvider;
use frame_support::BoundedVec;

// Set new init tier config values according to the forum post
let mut init_tier_config = pallet_dapp_staking_v3::TierConfig::<Runtime>::get();
init_tier_config.number_of_slots = 55;
init_tier_config.slots_per_tier =
BoundedVec::try_from(vec![2, 11, 16, 24]).unwrap_or_default();

#[cfg(feature = "try-runtime")]
{
assert!(
init_tier_config.number_of_slots >= init_tier_config.slots_per_tier.iter().sum::<u16>() as u16,
"Safety check, sum of slots per tier must be equal or less than max number of slots (due to possible rounding)"
);
}

// Based on the new init config, calculate the new tier config based on the 'average' price
let price = StaticPriceProvider::average_price();
let tier_params = pallet_dapp_staking_v3::StaticTierParams::<Runtime>::get();

let new_tier_config = init_tier_config.calculate_new(price, &tier_params);

pallet_dapp_staking_v3::TierConfig::<Runtime>::put(new_tier_config);

<Runtime as frame_system::Config>::DbWeight::get().reads_writes(3, 1)
}
}
pub type Migrations = ();

type EventRecord = frame_system::EventRecord<
<Runtime as frame_system::Config>::RuntimeEvent,
Expand Down
6 changes: 4 additions & 2 deletions runtime/shiden/src/precompiles.rs
Expand Up @@ -142,8 +142,10 @@ pub type ShidenPrecompilesSetAt<R, C> = (
CallableByPrecompile,
),
>,
// Skipping 20485 and 20486 to make sure all network have consistent
// precompiles address
PrecompileAt<
AddressU64<20485>,
AddressU64<20487>,
DispatchLockdrop<
R,
DispatchFilterValidate<RuntimeCall, WhitelistedLockdropCalls>,
Expand All @@ -160,7 +162,7 @@ pub type ShidenPrecompiles<R, C> = PrecompileSetBuilder<
// Skip precompiles if out of range.
PrecompilesInRangeInclusive<
// We take range as last precompile index, UPDATE this once new prcompile is added
(AddressU64<1>, AddressU64<20485>),
(AddressU64<1>, AddressU64<20487>),
ShidenPrecompilesSetAt<R, C>,
>,
// Prefixed precompile sets (XC20)
Expand Down

0 comments on commit 9801add

Please sign in to comment.