Skip to content

Commit 4d9eca7

Browse files
atheiactions-useryrong
authored
Add pallet_revive to Polkadot AssetHub (#1050)
In addition to adding the pallet I also: - KSM: Removed the old `WeightToFee` definition and replaced all occurrences with the new one - KSM: Removed magic numbers from the `WeightToFee` definition - DOT: Replaced `WeightToFee` with new definition required for `pallet_revive` - Fees: Moved the fee definition to the constants crate so they are shared between all system chains The only difference to the Kusama config is: ```rust type NativeToEthRatio = ConstU32<100_000_000>; // vs. 1_000_000 on KSM due to different decimals type GasScale = ConstU32<1_000>; // vs 100_000 on KSM due to different decimals ``` --------- Co-authored-by: GitHub Action <[email protected]> Co-authored-by: Ron <[email protected]>
1 parent ef33993 commit 4d9eca7

File tree

59 files changed

+292
-244
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+292
-244
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
99
### Added
1010
- Bridge-Hubs - Add proxy pallet ([#1045](https://github.com/polkadot-fellows/runtimes/pull/1045)).
1111
- AH Polkadot - A new stepped curve primitive. Used for the 'Hard Pressure' inflation changes from [Ref 1710](https://polkadot.subsquare.io/referenda/1710) ([#898](https://github.com/polkadot-fellows/runtimes/pull/898)).
12+
- AH Polkadot - Added `pallet_revive` and changed proof size fee formula ([polkadot-fellows/runtimes/pull/1050](https://github.com/polkadot-fellows/runtimes/pull/1050))
1213

1314
### Changed
1415

Cargo.lock

Lines changed: 9 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ pallet-ranked-collective = { version = "44.0.0", default-features = false }
158158
pallet-recovery = { version = "44.0.0", default-features = false }
159159
pallet-referenda = { version = "44.0.0", default-features = false }
160160
pallet-remote-proxy = { path = "pallets/remote-proxy", default-features = false }
161-
pallet-revive = { version = "0.11.2", default-features = false }
161+
pallet-revive = { version = "0.11.3", default-features = false }
162162
pallet-salary = { version = "29.0.0", default-features = false }
163163
pallet-scheduler = { version = "45.0.0", default-features = false }
164164
pallet-session = { version = "44.0.0", default-features = false }
@@ -191,7 +191,7 @@ parachains-common = { version = "26.0.0", default-features = false }
191191
parachains-runtimes-test-utils = { version = "27.0.1" }
192192
paste = { version = "1.0.14" }
193193
penpal-emulated-chain = { path = "integration-tests/emulated/chains/parachains/testing/penpal" }
194-
penpal-runtime = { version = "0.34.0" }
194+
penpal-runtime = { version = "0.34.1" }
195195
people-kusama-emulated-chain = { path = "integration-tests/emulated/chains/parachains/people/people-kusama" }
196196
people-kusama-runtime = { path = "system-parachains/people/people-kusama" }
197197
people-polkadot-emulated-chain = { path = "integration-tests/emulated/chains/parachains/people/people-polkadot" }

integration-tests/emulated/tests/bridges/bridge-hub-polkadot/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ sp-core = { workspace = true, default-features = true }
1717
sp-io = { workspace = true, default-features = true }
1818
sp-runtime = { workspace = true, default-features = true }
1919
frame-support = { workspace = true, default-features = true }
20+
frame-system = { workspace = true, default-features = true }
2021
pallet-balances = { workspace = true, default-features = true }
2122
pallet-asset-conversion = { workspace = true, default-features = true }
2223
pallet-assets = { workspace = true, default-features = true }
@@ -75,6 +76,7 @@ runtime-benchmarks = [
7576
"cumulus-pallet-parachain-system/runtime-benchmarks",
7677
"cumulus-pallet-xcmp-queue/runtime-benchmarks",
7778
"frame-support/runtime-benchmarks",
79+
"frame-system/runtime-benchmarks",
7880
"integration-tests-helpers/runtime-benchmarks",
7981
"kusama-polkadot-system-emulated-network/runtime-benchmarks",
8082
"pallet-asset-conversion/runtime-benchmarks",

integration-tests/emulated/tests/bridges/bridge-hub-polkadot/src/tests/snowbridge.rs

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ fn make_register_token_message() -> EventFixture {
648648
}
649649
}
650650

651-
fn send_token_from_ethereum_to_asset_hub_with_fee(account_id: [u8; 32], fee: u128) {
651+
fn send_token_from_ethereum_to_asset_hub_with_fee(account_id: [u8; 32], amount: u128, fee: u128) {
652652
// Fund asset hub sovereign on bridge hub
653653
let asset_hub_sovereign = BridgeHubPolkadot::sovereign_account_id_of(Location::new(
654654
1,
@@ -668,7 +668,7 @@ fn send_token_from_ethereum_to_asset_hub_with_fee(account_id: [u8; 32], fee: u12
668668
command: Command::SendToken {
669669
token: WETH.into(),
670670
destination: Destination::AccountId32 { id: account_id },
671-
amount: MIN_ETHER_BALANCE,
671+
amount,
672672
fee,
673673
},
674674
});
@@ -687,7 +687,11 @@ fn send_token_from_ethereum_to_asset_hub_with_fee(account_id: [u8; 32], fee: u12
687687

688688
#[test]
689689
fn send_token_from_ethereum_to_existent_account_on_asset_hub() {
690-
send_token_from_ethereum_to_asset_hub_with_fee(AssetHubPolkadotSender::get().into(), XCM_FEE);
690+
send_token_from_ethereum_to_asset_hub_with_fee(
691+
AssetHubPolkadotSender::get().into(),
692+
MIN_ETHER_BALANCE,
693+
XCM_FEE,
694+
);
691695

692696
AssetHubPolkadot::execute_with(|| {
693697
type RuntimeEvent = <AssetHubPolkadot as Chain>::RuntimeEvent;
@@ -704,7 +708,7 @@ fn send_token_from_ethereum_to_existent_account_on_asset_hub() {
704708

705709
#[test]
706710
fn send_token_from_ethereum_to_non_existent_account_on_asset_hub() {
707-
send_token_from_ethereum_to_asset_hub_with_fee([1; 32], XCM_FEE);
711+
send_token_from_ethereum_to_asset_hub_with_fee([1; 32], MIN_ETHER_BALANCE, XCM_FEE);
708712

709713
AssetHubPolkadot::execute_with(|| {
710714
type RuntimeEvent = <AssetHubPolkadot as Chain>::RuntimeEvent;
@@ -721,7 +725,11 @@ fn send_token_from_ethereum_to_non_existent_account_on_asset_hub() {
721725

722726
#[test]
723727
fn send_token_from_ethereum_to_non_existent_account_on_asset_hub_with_insufficient_fee() {
724-
send_token_from_ethereum_to_asset_hub_with_fee([1; 32], INSUFFICIENT_XCM_FEE);
728+
send_token_from_ethereum_to_asset_hub_with_fee(
729+
[1; 32],
730+
MIN_ETHER_BALANCE,
731+
INSUFFICIENT_XCM_FEE,
732+
);
725733

726734
AssetHubPolkadot::execute_with(|| {
727735
type RuntimeEvent = <AssetHubPolkadot as Chain>::RuntimeEvent;
@@ -740,19 +748,42 @@ fn send_token_from_ethereum_to_non_existent_account_on_asset_hub_with_insufficie
740748
#[test]
741749
fn send_token_from_ethereum_to_non_existent_account_on_asset_hub_with_sufficient_fee_but_do_not_satisfy_ed(
742750
) {
743-
// On AH the xcm fee is 26_789_690 and the ED is 3_300_000
744-
send_token_from_ethereum_to_asset_hub_with_fee([1; 32], 30_000_000);
751+
// On AH, ED is 0.1 DOT. Make both the transfer amount (in WETH) and the XCM fee below the ED.
752+
let insufficient_token_amount_in_weth_below_ed = MIN_ETHER_BALANCE - 1;
753+
let sufficient_fee_in_dot_below_ed = ASSET_HUB_POLKADOT_ED - 1;
754+
// let sufficient_fee_above_ed = XCM_FEE;
755+
send_token_from_ethereum_to_asset_hub_with_fee(
756+
[1; 32],
757+
insufficient_token_amount_in_weth_below_ed,
758+
sufficient_fee_in_dot_below_ed,
759+
);
745760

746761
AssetHubPolkadot::execute_with(|| {
747762
type RuntimeEvent = <AssetHubPolkadot as Chain>::RuntimeEvent;
748-
749-
// Check that the message was not processed successfully due to insufficient ED
763+
// Since the XCM fee is sufficient, the message is processed successfully.
750764
assert_expected_events!(
751765
AssetHubPolkadot,
752766
vec![
753-
RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed { success:false, .. }) => {},
767+
RuntimeEvent::MessageQueue(pallet_message_queue::Event::Processed { success:true, .. }) => {},
754768
]
755769
);
770+
let events = AssetHubPolkadot::events();
771+
//Check that no foreign assets were issued
772+
assert!(
773+
!events.iter().any(|event| matches!(
774+
event,
775+
RuntimeEvent::ForeignAssets(pallet_assets::Event::Issued { .. })
776+
)),
777+
"Assets issued, should not happen."
778+
);
779+
//Check that no new account created
780+
assert!(
781+
!events.iter().any(|event| matches!(
782+
event,
783+
RuntimeEvent::System(frame_system::Event::NewAccount { .. })
784+
)),
785+
"Account created, should not happen."
786+
);
756787
});
757788
}
758789

system-parachains/asset-hubs/asset-hub-kusama/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ try-runtime = [
296296
"polkadot-runtime-common/try-runtime",
297297
"sp-runtime/try-runtime",
298298
"system-parachains-common/try-runtime",
299+
"system-parachains-constants/try-runtime",
299300
]
300301
std = [
301302
"assets-common/std",

system-parachains/asset-hubs/asset-hub-kusama/src/lib.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ use pallet_assets_precompiles::{InlineIdConfig, ERC20};
7777
use pallet_nfts::PalletFeatures;
7878
use pallet_nomination_pools::PoolId;
7979
use pallet_proxy::ProxyDefinition;
80-
use pallet_revive::evm::runtime::EthExtra;
8180
use pallet_xcm::{EnsureXcm, IsVoiceOfBody};
8281
use pallet_xcm_precompiles::XcmPrecompile;
8382
use parachains_common::{
@@ -115,7 +114,7 @@ use system_parachains_constants::{
115114
RELAY_CHAIN_SLOT_DURATION_MILLIS,
116115
},
117116
currency::*,
118-
fee::WeightToFee,
117+
fee::WeightToFee as KsmWeightToFee,
119118
},
120119
};
121120
use weights::{BlockExecutionWeight, ExtrinsicBaseWeight, InMemoryDbWeight};
@@ -311,7 +310,7 @@ impl pallet_transaction_payment::Config for Runtime {
311310
// - The numerator is `currency::CENTS` = 1_000_000_000_000 / 30 / 100 = 333_333_333
312311
// - The denominator is `100 * Balance::from(ExtrinsicBaseWeight::get().ref_time())`
313312
// - which is 100 * 1_000 * 108_157 = 10_815_700_000
314-
type WeightToFee = pallet_revive::evm::fees::BlockRatioFee<333333333, 10_815_700_000, Self>;
313+
type WeightToFee = KsmWeightToFee<Self>;
315314
type LengthToFee = ConstantMultiplier<Balance, TransactionByteFee>;
316315
type FeeMultiplierUpdate = SlowAdjustingFeeUpdate<Self>;
317316
type OperationalFeeMultiplier = ConstU8<5>;
@@ -1700,7 +1699,7 @@ pub type TxExtension = cumulus_pallet_weight_reclaim::StorageWeightReclaim<
17001699
#[derive(Clone, PartialEq, Eq, Debug)]
17011700
pub struct EthExtraImpl;
17021701

1703-
impl EthExtra for EthExtraImpl {
1702+
impl pallet_revive::evm::runtime::EthExtra for EthExtraImpl {
17041703
type Config = Runtime;
17051704
type Extension = TxExtension;
17061705

@@ -1740,7 +1739,7 @@ pub mod migrations {
17401739
pub type SingleBlockMigrations = (Unreleased, Permanent);
17411740

17421741
/// MBM migrations to apply on runtime upgrade.
1743-
pub type MbmMigrations = pallet_revive::migrations::v2::Migration<Runtime>;
1742+
pub type MbmMigrations = ();
17441743
}
17451744

17461745
/// Executive: handles dispatch to the various modules.
@@ -2779,8 +2778,9 @@ ord_parameter_types! {
27792778
mod tests {
27802779
use super::*;
27812780
use sp_runtime::traits::Zero;
2782-
use sp_weights::WeightToFee;
2783-
use system_parachains_constants::kusama::fee;
2781+
use sp_weights::WeightToFee as WeightToFeeT;
2782+
2783+
type WeightToFee = KsmWeightToFee<Runtime>;
27842784

27852785
/// We can fit at least 1000 transfers in a block.
27862786
#[test]
@@ -2803,18 +2803,18 @@ mod tests {
28032803
let transfer =
28042804
base + weights::pallet_balances::WeightInfo::<Runtime>::transfer_allow_death();
28052805

2806-
let fee: Balance = fee::WeightToFee::weight_to_fee(&transfer);
2806+
let fee: Balance = WeightToFee::weight_to_fee(&transfer);
28072807
assert!(fee <= CENTS, "{} MILLICENTS should be at most 1000", fee / MILLICENTS);
28082808
}
28092809

28102810
/// Weight is being charged for both dimensions.
28112811
#[test]
28122812
fn weight_charged_for_both_components() {
2813-
let fee: Balance = fee::WeightToFee::weight_to_fee(&Weight::from_parts(10_000, 0));
2813+
let fee: Balance = WeightToFee::weight_to_fee(&Weight::from_parts(10_000, 0));
28142814
assert!(!fee.is_zero(), "Charges for ref time");
28152815

2816-
let fee: Balance = fee::WeightToFee::weight_to_fee(&Weight::from_parts(0, 10_000));
2817-
assert_eq!(fee, CENTS, "10kb maps to CENT");
2816+
let fee: Balance = WeightToFee::weight_to_fee(&Weight::from_parts(0, 10_000));
2817+
assert!(!fee.is_zero(), "Charges for proof size");
28182818
}
28192819

28202820
/// Filling up a block by proof size is at most 30 times more expensive than ref time.
@@ -2824,9 +2824,9 @@ mod tests {
28242824
fn full_block_fee_ratio() {
28252825
let block = RuntimeBlockWeights::get().max_block;
28262826
let time_fee: Balance =
2827-
fee::WeightToFee::weight_to_fee(&Weight::from_parts(block.ref_time(), 0));
2827+
WeightToFee::weight_to_fee(&Weight::from_parts(block.ref_time(), 0));
28282828
let proof_fee: Balance =
2829-
fee::WeightToFee::weight_to_fee(&Weight::from_parts(0, block.proof_size()));
2829+
WeightToFee::weight_to_fee(&Weight::from_parts(0, block.proof_size()));
28302830

28312831
let proof_o_time = proof_fee.checked_div(time_fee).unwrap_or_default();
28322832
assert!(proof_o_time <= 30, "{proof_o_time} should be at most 30");

system-parachains/asset-hubs/asset-hub-kusama/src/staking/mod.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ use frame_support::traits::tokens::imbalance::ResolveTo;
2727
use pallet_election_provider_multi_block::{self as multi_block, SolutionAccuracyOf};
2828
use pallet_staking_async::UseValidatorsMap;
2929
use pallet_staking_async_rc_client as rc_client;
30-
use scale_info::TypeInfo;
31-
use sp_runtime::{transaction_validity::TransactionPriority, Perquintill};
30+
use sp_runtime::{generic, transaction_validity::TransactionPriority, Perquintill};
3231
use sp_staking::SessionIndex;
3332
use system_parachains_common::apis::InflationInfo;
3433
use xcm::v5::prelude::*;
@@ -498,7 +497,7 @@ where
498497
type Extension = TxExtension;
499498

500499
fn create_transaction(call: RuntimeCall, extension: TxExtension) -> UncheckedExtrinsic {
501-
<UncheckedExtrinsic as TypeInfo>::Identity::new_transaction(call, extension).into()
500+
generic::UncheckedExtrinsic::new_transaction(call, extension).into()
502501
}
503502
}
504503

@@ -507,7 +506,7 @@ where
507506
RuntimeCall: From<LocalCall>,
508507
{
509508
fn create_bare(call: RuntimeCall) -> UncheckedExtrinsic {
510-
<UncheckedExtrinsic as TypeInfo>::Identity::new_bare(call).into()
509+
generic::UncheckedExtrinsic::new_bare(call).into()
511510
}
512511
}
513512

system-parachains/asset-hubs/asset-hub-kusama/src/xcm_config.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ pub use TreasuryAccount as RelayTreasuryPalletAccount;
1818

1919
use super::{
2020
AccountId, AllPalletsWithSystem, AssetConversion, Assets, Balance, Balances, CollatorSelection,
21-
FellowshipAdmin, GeneralAdmin, NativeAndAssets, ParachainInfo, ParachainSystem, PolkadotXcm,
22-
PoolAssets, PriceForParentDelivery, Runtime, RuntimeCall, RuntimeEvent, RuntimeHoldReason,
23-
RuntimeOrigin, StakingAdmin, ToPolkadotXcmRouter, WeightToFee, XcmpQueue,
21+
FellowshipAdmin, GeneralAdmin, KsmWeightToFee as WeightToFee, NativeAndAssets, ParachainInfo,
22+
ParachainSystem, PolkadotXcm, PoolAssets, PriceForParentDelivery, Runtime, RuntimeCall,
23+
RuntimeEvent, RuntimeHoldReason, RuntimeOrigin, StakingAdmin, ToPolkadotXcmRouter, XcmpQueue,
2424
};
2525
use crate::ForeignAssets;
2626
use alloc::{vec, vec::Vec};
@@ -384,7 +384,7 @@ impl xcm_executor::Config for XcmConfig {
384384
>;
385385
type Trader = (
386386
UsingComponents<
387-
WeightToFee,
387+
WeightToFee<Runtime>,
388388
KsmLocation,
389389
AccountId,
390390
Balances,
@@ -395,7 +395,7 @@ impl xcm_executor::Config for XcmConfig {
395395
cumulus_primitives_utility::SwapFirstAssetTrader<
396396
KsmLocation,
397397
AssetConversion,
398-
WeightToFee,
398+
WeightToFee<Runtime>,
399399
NativeAndAssets,
400400
(
401401
TrustBackedAssetsAsLocation<TrustBackedAssetsPalletLocation, Balance, Location>,

system-parachains/asset-hubs/asset-hub-kusama/tests/tests.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ use sp_consensus_aura::SlotDuration;
5050
use sp_core::crypto::Ss58Codec;
5151
use sp_runtime::{traits::MaybeEquivalence, Either, TryRuntimeError};
5252
use system_parachains_constants::kusama::{
53-
consensus::RELAY_CHAIN_SLOT_DURATION_MILLIS, currency::UNITS, fee::WeightToFee,
53+
consensus::RELAY_CHAIN_SLOT_DURATION_MILLIS, currency::UNITS,
54+
fee::WeightToFee as KsmWeightToFee,
5455
};
5556
use xcm::latest::{
5657
prelude::{Assets as XcmAssets, *},
@@ -70,8 +71,8 @@ frame_support::parameter_types! {
7071

7172
type AssetIdForTrustBackedAssetsConvertLatest =
7273
assets_common::AssetIdForTrustBackedAssetsConvert<TrustBackedAssetsPalletLocation>;
73-
7474
type RuntimeHelper = asset_test_utils::RuntimeHelper<Runtime, AllPalletsWithoutSystem>;
75+
type WeightToFee = KsmWeightToFee<Runtime>;
7576

7677
fn collator_session_key(account: [u8; 32]) -> CollatorSessionKey<Runtime> {
7778
CollatorSessionKey::new(

0 commit comments

Comments
 (0)