v3 into main (#390)

This commit is contained in:
Amar Singh
2024-12-25 00:20:08 -05:00
committed by GitHub
parent 8cb7cda000
commit 9158633607
36 changed files with 3296 additions and 1222 deletions
+69 -16
View File
@@ -1,13 +1,18 @@
pub mod asset_config;
pub mod governance;
pub mod weight;
pub mod xcm_config;
use asset_config::*;
#[cfg(feature = "tanssi")]
use cumulus_pallet_parachain_system::ExpectParentIncluded;
#[cfg(feature = "async-backing")]
use cumulus_pallet_parachain_system::RelayNumberMonotonicallyIncreases;
#[cfg(not(feature = "async-backing"))]
use cumulus_pallet_parachain_system::RelayNumberStrictlyIncreases;
use cumulus_primitives_core::{AggregateMessageOrigin, ParaId};
#[cfg(not(feature = "tanssi"))]
use frame_support::PalletId;
use frame_support::{
derive_impl,
dispatch::DispatchClass,
@@ -17,7 +22,6 @@ use frame_support::{
EitherOfDiverse, Everything, FindAuthor, Nothing, TransformOrigin,
},
weights::{ConstantMultiplier, Weight},
PalletId,
};
use frame_system::{
limits::{BlockLength, BlockWeights},
@@ -25,16 +29,26 @@ use frame_system::{
};
pub use governance::origins::pallet_custom_origins;
use governance::{origins::Treasurer, tracks, Spender, WhitelistedCaller};
use openzeppelin_polkadot_wrappers::{
impl_openzeppelin_assets, impl_openzeppelin_consensus, impl_openzeppelin_evm,
impl_openzeppelin_governance, impl_openzeppelin_system, impl_openzeppelin_xcm, AssetsConfig,
ConsensusConfig, EvmConfig, GovernanceConfig, SystemConfig, XcmConfig,
#[cfg(feature = "tanssi")]
use nimbus_primitives::NimbusId;
use openzeppelin_pallet_abstractions::{
impl_openzeppelin_assets, impl_openzeppelin_evm, impl_openzeppelin_governance,
impl_openzeppelin_system, impl_openzeppelin_xcm, AssetsConfig, AssetsWeight, EvmConfig,
EvmWeight, GovernanceConfig, GovernanceWeight, SystemConfig, SystemWeight, XcmConfig,
XcmWeight,
};
#[cfg(not(feature = "tanssi"))]
use openzeppelin_pallet_abstractions::{
impl_openzeppelin_consensus, ConsensusConfig, ConsensusWeight,
};
#[cfg(feature = "tanssi")]
use openzeppelin_pallet_abstractions::{impl_openzeppelin_tanssi, TanssiConfig, TanssiWeight};
use pallet_ethereum::PostLogContent;
use pallet_evm::{EVMCurrencyAdapter, EnsureAccountId20, IdentityAddressMapping};
use parachains_common::message_queue::{NarrowOriginToSibling, ParaIdToSibling};
use parity_scale_codec::{Decode, Encode};
use polkadot_runtime_common::{BlockHashCount, SlowAdjustingFeeUpdate};
#[cfg(not(feature = "tanssi"))]
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
use sp_core::{H160, U256};
use sp_runtime::{
@@ -57,39 +71,58 @@ use xcm_primitives::{AbsoluteAndRelativeReserve, AccountIdToLocation, AsAssetTyp
#[cfg(feature = "runtime-benchmarks")]
use crate::benchmark::{OpenHrmpChannel, PayWithEnsure};
#[cfg(feature = "tanssi")]
use crate::AuthorInherent;
#[cfg(not(feature = "tanssi"))]
use crate::{
constants::HOURS,
types::{BlockNumber, CollatorSelectionUpdateOrigin, ConsensusHook},
Aura, CollatorSelection, Session, SessionKeys,
};
use crate::{
constants::{
currency::{deposit, CENTS, EXISTENTIAL_DEPOSIT, MICROCENTS, MILLICENTS},
AVERAGE_ON_INITIALIZE_RATIO, DAYS, HOURS, MAXIMUM_BLOCK_WEIGHT, MAX_BLOCK_LENGTH,
NORMAL_DISPATCH_RATIO, WEIGHT_PER_GAS,
AVERAGE_ON_INITIALIZE_RATIO, DAYS, MAXIMUM_BLOCK_WEIGHT, MAX_BLOCK_LENGTH,
NORMAL_DISPATCH_RATIO, SLOT_DURATION, WEIGHT_PER_GAS,
},
opaque,
types::{
AccountId, AssetId, AssetKind, Balance, Beneficiary, Block, BlockNumber,
CollatorSelectionUpdateOrigin, ConsensusHook, Hash, MessageQueueServiceWeight, Nonce,
PrecompilesValue, PriceForSiblingParachainDelivery, ProxyType, TreasuryInteriorLocation,
TreasuryPalletId, TreasuryPaymaster, Version,
AccountId, AssetId, AssetKind, Balance, Beneficiary, Block, Hash,
MessageQueueServiceWeight, Nonce, PrecompilesValue, PriceForSiblingParachainDelivery,
ProxyType, TreasuryInteriorLocation, TreasuryPalletId, TreasuryPaymaster, Version,
},
weights::{self, BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight},
AllPalletsWithSystem, AssetManager, Aura, Balances, BaseFee, CollatorSelection, EVMChainId,
Erc20XcmBridge, MessageQueue, OpenZeppelinPrecompiles, OriginCaller, PalletInfo, ParachainInfo,
weights::{BlockExecutionWeight, ExtrinsicBaseWeight},
AllPalletsWithSystem, AssetManager, Balances, BaseFee, EVMChainId, Erc20XcmBridge,
MessageQueue, OpenZeppelinPrecompiles, OriginCaller, PalletInfo, ParachainInfo,
ParachainSystem, PolkadotXcm, Preimage, Referenda, Runtime, RuntimeCall, RuntimeEvent,
RuntimeFreezeReason, RuntimeHoldReason, RuntimeOrigin, RuntimeTask, Scheduler, Session,
SessionKeys, System, Timestamp, Treasury, UncheckedExtrinsic, WeightToFee, XcmpQueue,
RuntimeFreezeReason, RuntimeHoldReason, RuntimeOrigin, RuntimeTask, Scheduler, System,
Timestamp, Treasury, UncheckedExtrinsic, WeightToFee, XcmpQueue,
};
// OpenZeppelin runtime wrappers configuration
pub struct OpenZeppelinRuntime;
impl SystemConfig for OpenZeppelinRuntime {
type AccountId = AccountId;
#[cfg(not(feature = "tanssi"))]
type ConsensusHook = ConsensusHook;
#[cfg(feature = "tanssi")]
type ConsensusHook = ExpectParentIncluded;
type ExistentialDeposit = ConstU128<EXISTENTIAL_DEPOSIT>;
type Lookup = IdentityLookup<AccountId>;
#[cfg(not(feature = "tanssi"))]
type OnTimestampSet = Aura;
#[cfg(feature = "tanssi")]
type OnTimestampSet = ();
type PreimageOrigin = EnsureRoot<AccountId>;
type ProxyType = ProxyType;
type SS58Prefix = ConstU16<42>;
type ScheduleOrigin = EnsureRoot<AccountId>;
type SlotDuration = ConstU64<SLOT_DURATION>;
type Version = Version;
}
#[cfg(feature = "tanssi")]
impl TanssiConfig for OpenZeppelinRuntime {}
#[cfg(not(feature = "tanssi"))]
impl ConsensusConfig for OpenZeppelinRuntime {
type CollatorSelectionUpdateOrigin = CollatorSelectionUpdateOrigin;
}
@@ -158,7 +191,10 @@ impl EvmConfig for OpenZeppelinRuntime {
type AddressMapping = IdentityAddressMapping;
type CallOrigin = EnsureAccountId20;
type Erc20XcmBridgeTransferGasLimit = ConstU64<800_000>;
#[cfg(not(feature = "tanssi"))]
type FindAuthor = FindAuthorSession<Aura>;
#[cfg(feature = "tanssi")]
type FindAuthor = FindAuthorSession<AuthorInherent>;
type LocationToH160 = LocationToH160;
type PrecompilesType = OpenZeppelinPrecompiles<Runtime>;
type PrecompilesValue = PrecompilesValue;
@@ -181,12 +217,16 @@ impl AssetsConfig for OpenZeppelinRuntime {
}
impl_openzeppelin_assets!(OpenZeppelinRuntime);
impl_openzeppelin_system!(OpenZeppelinRuntime);
#[cfg(not(feature = "tanssi"))]
impl_openzeppelin_consensus!(OpenZeppelinRuntime);
#[cfg(feature = "tanssi")]
impl_openzeppelin_tanssi!();
impl_openzeppelin_governance!(OpenZeppelinRuntime);
impl_openzeppelin_xcm!(OpenZeppelinRuntime);
impl_openzeppelin_evm!(OpenZeppelinRuntime);
pub struct FindAuthorSession<F>(PhantomData<F>);
#[cfg(not(feature = "tanssi"))]
impl<F: FindAuthor<u32>> FindAuthor<H160> for FindAuthorSession<F> {
fn find_author<'a, I>(digests: I) -> Option<H160>
where
@@ -200,6 +240,19 @@ impl<F: FindAuthor<u32>> FindAuthor<H160> for FindAuthorSession<F> {
}
}
#[cfg(feature = "tanssi")]
impl<F: FindAuthor<NimbusId>> FindAuthor<H160> for FindAuthorSession<F> {
fn find_author<'a, I>(digests: I) -> Option<H160>
where
I: 'a + IntoIterator<Item = (ConsensusEngineId, &'a [u8])>,
{
if let Some(author) = F::find_author(digests) {
return Some(H160::from_slice(&author.encode()[0..20]));
}
None
}
}
#[derive(Clone)]
pub struct TransactionConverter;
@@ -0,0 +1,62 @@
#[cfg(not(feature = "tanssi"))]
use openzeppelin_pallet_abstractions::ConsensusWeight;
#[cfg(feature = "tanssi")]
use openzeppelin_pallet_abstractions::TanssiWeight;
use openzeppelin_pallet_abstractions::{
AssetsWeight, EvmWeight, GovernanceWeight, SystemWeight, XcmWeight,
};
use crate::{
configs::OpenZeppelinRuntime,
weights::{self, RocksDbWeight},
Runtime,
};
impl SystemWeight for OpenZeppelinRuntime {
type Balances = weights::pallet_balances::WeightInfo<Runtime>;
type DbWeight = RocksDbWeight;
type Multisig = weights::pallet_multisig::WeightInfo<Runtime>;
type ParachainSystem = weights::cumulus_pallet_parachain_system::WeightInfo<Runtime>;
type Preimage = weights::pallet_preimage::WeightInfo<Runtime>;
type Proxy = weights::pallet_proxy::WeightInfo<Runtime>;
type Scheduler = weights::pallet_scheduler::WeightInfo<Runtime>;
type Timestamp = weights::pallet_timestamp::WeightInfo<Runtime>;
type Utility = weights::pallet_utility::WeightInfo<Runtime>;
}
#[cfg(not(feature = "tanssi"))]
impl ConsensusWeight for OpenZeppelinRuntime {
type CollatorSelection = weights::pallet_collator_selection::WeightInfo<Runtime>;
type Session = weights::pallet_session::WeightInfo<Runtime>;
}
impl AssetsWeight for OpenZeppelinRuntime {
type AssetManager = weights::pallet_asset_manager::WeightInfo<Runtime>;
type Assets = weights::pallet_assets::WeightInfo<Runtime>;
}
impl GovernanceWeight for OpenZeppelinRuntime {
type ConvictionVoting = weights::pallet_conviction_voting::WeightInfo<Runtime>;
type Referenda = weights::pallet_referenda::WeightInfo<Runtime>;
type Sudo = weights::pallet_sudo::WeightInfo<Runtime>;
type Treasury = weights::pallet_treasury::WeightInfo<Runtime>;
type Whitelist = weights::pallet_whitelist::WeightInfo<Runtime>;
}
impl XcmWeight for OpenZeppelinRuntime {
type MessageQueue = weights::pallet_message_queue::WeightInfo<Runtime>;
type Xcm = weights::pallet_xcm::WeightInfo<Runtime>;
type XcmTransactor = weights::pallet_xcm_transactor::WeightInfo<Runtime>;
type XcmWeightTrader = weights::pallet_xcm_weight_trader::WeightInfo<Runtime>;
type XcmpQueue = weights::cumulus_pallet_xcmp_queue::WeightInfo<Runtime>;
}
impl EvmWeight for OpenZeppelinRuntime {
type Evm = weights::pallet_evm::WeightInfo<Runtime>;
}
#[cfg(feature = "tanssi")]
impl TanssiWeight for OpenZeppelinRuntime {
type AuthorInherent = pallet_author_inherent::weights::SubstrateWeight<Runtime>;
type AuthoritiesNoting = pallet_cc_authorities_noting::weights::SubstrateWeight<Runtime>;
}
+80 -13
View File
@@ -168,11 +168,16 @@ pub mod opaque {
pub type Hash = <BlakeTwo256 as HashT>::Output;
}
#[cfg(not(feature = "tanssi"))]
impl_opaque_keys! {
pub struct SessionKeys {
pub aura: Aura,
}
}
#[cfg(feature = "tanssi")]
impl_opaque_keys! {
pub struct SessionKeys {}
}
/// The version information used to identify this runtime when compiled
/// natively.
@@ -183,50 +188,60 @@ pub fn native_version() -> NativeVersion {
NativeVersion { runtime_version: VERSION, can_author_with: Default::default() }
}
use openzeppelin_polkadot_wrappers_proc::openzeppelin_construct_runtime;
use openzeppelin_pallet_abstractions_proc::openzeppelin_construct_runtime;
#[cfg(not(feature = "tanssi"))]
#[openzeppelin_construct_runtime]
mod runtime {
#[abstraction]
struct System;
#[abstraction]
struct Consensus;
#[abstraction]
struct XCM;
#[abstraction]
struct Assets;
#[abstraction]
struct Governance;
#[abstraction]
struct EVM;
}
use openzeppelin_polkadot_wrappers_proc::openzeppelin_runtime_apis;
#[cfg(feature = "tanssi")]
#[openzeppelin_construct_runtime]
mod runtime {
struct System;
struct Tanssi;
struct XCM;
struct Assets;
struct Governance;
struct EVM;
}
use openzeppelin_pallet_abstractions_proc::openzeppelin_runtime_apis;
#[cfg(not(feature = "tanssi"))]
#[openzeppelin_runtime_apis]
mod apis {
type Runtime = Runtime;
type Block = Block;
#[abstraction]
mod evm {
type RuntimeCall = RuntimeCall;
type Executive = Executive;
type Ethereum = Ethereum;
}
#[abstraction]
mod assets {
type RuntimeCall = RuntimeCall;
type TransactionPayment = TransactionPayment;
type Balance = Balance;
}
#[abstraction]
mod consensus {
type SessionKeys = SessionKeys;
#[cfg(not(feature = "async-backing"))]
@@ -237,7 +252,6 @@ mod apis {
type ConsensusHook = ConsensusHook;
}
#[abstraction]
mod system {
type Executive = Executive;
type System = System;
@@ -249,7 +263,60 @@ mod apis {
type RuntimeBlockWeights = RuntimeBlockWeights;
}
#[abstraction]
mod benchmarks {
type AllPalletsWithSystem = AllPalletsWithSystem;
type Assets = Assets;
type AssetManager = AssetManager;
type AssetType = AssetType;
type RuntimeOrigin = RuntimeOrigin;
type RelayLocation = RelayLocation;
type ParachainSystem = ParachainSystem;
type System = System;
type ExistentialDeposit = ExistentialDeposit;
type AssetId = AssetId;
type XCMConfig = XcmExecutorConfig;
type AccountId = AccountId;
type Cents = CENTS;
type FeeAssetId = FeeAssetId;
type TransactionByteFee = TransactionByteFee;
type Address = Address;
type Balances = Balances;
}
}
#[cfg(feature = "tanssi")]
#[openzeppelin_runtime_apis]
mod apis {
type Runtime = Runtime;
type Block = Block;
mod evm {
type RuntimeCall = RuntimeCall;
type Executive = Executive;
type Ethereum = Ethereum;
}
mod assets {
type RuntimeCall = RuntimeCall;
type TransactionPayment = TransactionPayment;
type Balance = Balance;
}
mod tanssi {
type SessionKeys = SessionKeys;
}
mod system {
type Executive = Executive;
type System = System;
type ParachainSystem = ParachainSystem;
type RuntimeVersion = VERSION;
type AccountId = AccountId;
type Nonce = Nonce;
type RuntimeGenesisConfig = RuntimeGenesisConfig;
type RuntimeBlockWeights = RuntimeBlockWeights;
}
mod benchmarks {
type AllPalletsWithSystem = AllPalletsWithSystem;
type Assets = Assets;
+17 -14
View File
@@ -1,11 +1,10 @@
use fp_account::EthereumSignature;
use frame_support::{
parameter_types,
traits::{EitherOfDiverse, InstanceFilter},
weights::Weight,
PalletId,
};
#[cfg(not(feature = "tanssi"))]
use frame_support::traits::EitherOfDiverse;
use frame_support::{parameter_types, traits::InstanceFilter, weights::Weight, PalletId};
#[cfg(not(feature = "tanssi"))]
use frame_system::EnsureRoot;
#[cfg(not(feature = "tanssi"))]
use pallet_xcm::{EnsureXcm, IsVoiceOfBody};
use parity_scale_codec::{Decode, Encode, MaxEncodedLen};
use polkadot_runtime_common::impls::{
@@ -26,19 +25,19 @@ use xcm::{
use xcm_builder::PayOverXcm;
use crate::{
configs::{
xcm_config::{self, RelayLocation},
FeeAssetId, StakingAdminBodyId, ToSiblingBaseDeliveryFee, TransactionByteFee,
},
configs::{xcm_config, FeeAssetId, ToSiblingBaseDeliveryFee, TransactionByteFee},
constants::HOURS,
};
pub use crate::{
#[cfg(not(feature = "tanssi"))]
use crate::{
configs::{xcm_config::RelayLocation, StakingAdminBodyId},
constants::{
BLOCK_PROCESSING_VELOCITY, RELAY_CHAIN_SLOT_DURATION_MILLIS, UNINCLUDED_SEGMENT_CAPACITY,
VERSION,
},
AllPalletsWithSystem, OpenZeppelinPrecompiles, Runtime, RuntimeBlockWeights, RuntimeCall,
Treasury, XcmpQueue,
};
pub use crate::{
constants::VERSION, AllPalletsWithSystem, OpenZeppelinPrecompiles, Runtime,
RuntimeBlockWeights, RuntimeCall, Treasury, XcmpQueue,
};
/// Unchecked extrinsic type as expected by this runtime.
@@ -107,6 +106,7 @@ pub type PriceForSiblingParachainDelivery = polkadot_runtime_common::xcm_sender:
>;
/// Configures the number of blocks that can be created without submission of validity proof to the relay chain
#[cfg(not(feature = "tanssi"))]
pub type ConsensusHook = cumulus_pallet_aura_ext::FixedVelocityConsensusHook<
Runtime,
RELAY_CHAIN_SLOT_DURATION_MILLIS,
@@ -116,6 +116,7 @@ pub type ConsensusHook = cumulus_pallet_aura_ext::FixedVelocityConsensusHook<
/// We allow root and the StakingAdmin to execute privileged collator selection
/// operations.
#[cfg(not(feature = "tanssi"))]
pub type CollatorSelectionUpdateOrigin = EitherOfDiverse<
EnsureRoot<AccountId>,
EnsureXcm<IsVoiceOfBody<RelayLocation, StakingAdminBodyId>>,
@@ -162,6 +163,7 @@ pub enum ProxyType {
/// Allows to finish the proxy
CancelProxy,
/// Allows to operate with collators list (invulnerables, candidates, etc.)
#[cfg(not(feature = "tanssi"))]
Collator,
}
@@ -175,6 +177,7 @@ impl InstanceFilter<RuntimeCall> for ProxyType {
RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. })
| RuntimeCall::Multisig { .. }
),
#[cfg(not(feature = "tanssi"))]
ProxyType::Collator => {
matches!(c, RuntimeCall::CollatorSelection { .. } | RuntimeCall::Multisig { .. })
}
+2
View File
@@ -24,6 +24,7 @@ pub mod extrinsic_weights;
pub mod pallet_asset_manager;
pub mod pallet_assets;
pub mod pallet_balances;
#[cfg(not(feature = "tanssi"))]
pub mod pallet_collator_selection;
pub mod pallet_conviction_voting;
pub mod pallet_evm;
@@ -33,6 +34,7 @@ pub mod pallet_preimage;
pub mod pallet_proxy;
pub mod pallet_referenda;
pub mod pallet_scheduler;
#[cfg(not(feature = "tanssi"))]
pub mod pallet_session;
pub mod pallet_sudo;
pub mod pallet_timestamp;