Skip to content

Commit

Permalink
chore: make precompile associated type
Browse files Browse the repository at this point in the history
  • Loading branch information
mustermeiszer committed Jun 12, 2024
1 parent 12bedc7 commit 857d618
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 35 deletions.
6 changes: 3 additions & 3 deletions node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ pub type CentrifugeChainSpec =
pub type DevelopmentChainSpec =
sc_service::GenericChainSpec<development_runtime::RuntimeGenesisConfig, Extensions>;

use altair_runtime::AltairPrecompiles;
use centrifuge_runtime::CentrifugePrecompiles;
use altair_runtime::Precompiles;
use centrifuge_runtime::Precompiles;
use cfg_types::fixed_point::Rate;
use development_runtime::DevelopmentPrecompiles;
use development_runtime::Precompiles;

/// Helper function to generate a crypto pair from seed
pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {
Expand Down
8 changes: 4 additions & 4 deletions runtime/altair/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ use runtime_common::{
account_conversion::{AccountConverter, RuntimeAccountConverter},
asset_registry,
evm::{
precompile::Precompiles, BaseFeeThreshold, FindAuthorTruncated, GAS_LIMIT_POV_SIZE_RATIO,
self, BaseFeeThreshold, FindAuthorTruncated, GAS_LIMIT_POV_SIZE_RATIO,
GAS_LIMIT_STORAGE_GROWTH_RATIO, WEIGHT_PER_GAS,
},
fees::{DealWithFees, FeeToTreasury, WeightToFee},
Expand Down Expand Up @@ -1866,11 +1866,11 @@ impl pallet_transfer_allowlist::Config for Runtime {
type WeightInfo = weights::pallet_transfer_allowlist::WeightInfo<Runtime>;
}

pub type AltairPrecompiles = Precompiles<crate::Runtime, TokenSymbol>;
pub type Precompiles = evm::precompile::Precompiles<crate::Runtime, TokenSymbol>;

parameter_types! {
pub BlockGasLimit: U256 = U256::from(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT.ref_time() / WEIGHT_PER_GAS);
pub PrecompilesValue: AltairPrecompiles = Precompiles::<_, _>::new();
pub PrecompilesValue: Precompiles = Precompiles::new();
pub WeightPerGas: Weight = Weight::from_parts(WEIGHT_PER_GAS, 0);
pub const TokenSymbol: &'static str = "AIR";
}
Expand All @@ -1889,7 +1889,7 @@ impl pallet_evm::Config for Runtime {
type GasWeightMapping = pallet_evm::FixedGasWeightMapping<Self>;
type OnChargeTransaction = ();
type OnCreate = ();
type PrecompilesType = AltairPrecompiles;
type PrecompilesType = Precompiles;
type PrecompilesValue = PrecompilesValue;
type Runner = pallet_evm::runner::stack::Runner<Self>;
type RuntimeEvent = RuntimeEvent;
Expand Down
8 changes: 4 additions & 4 deletions runtime/centrifuge/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ use runtime_common::{
account_conversion::{AccountConverter, RuntimeAccountConverter},
asset_registry,
evm::{
precompile::Precompiles, BaseFeeThreshold, FindAuthorTruncated, GAS_LIMIT_POV_SIZE_RATIO,
self, BaseFeeThreshold, FindAuthorTruncated, GAS_LIMIT_POV_SIZE_RATIO,
GAS_LIMIT_STORAGE_GROWTH_RATIO, WEIGHT_PER_GAS,
},
fees::{DealWithFees, FeeToTreasury, WeightToFee},
Expand Down Expand Up @@ -1980,11 +1980,11 @@ impl pallet_remarks::Config for Runtime {
type WeightInfo = weights::pallet_remarks::WeightInfo<Runtime>;
}

pub type CentrifugePrecompiles = Precompiles<crate::Runtime, TokenSymbol>;
pub type Precompiles = evm::precompile::Precompiles<crate::Runtime, TokenSymbol>;

parameter_types! {
pub BlockGasLimit: U256 = U256::from(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT.ref_time() / WEIGHT_PER_GAS);
pub PrecompilesValue: CentrifugePrecompiles = Precompiles::<_, _>::new();
pub PrecompilesValue: Precompiles = Precompiles::new();
pub WeightPerGas: Weight = Weight::from_parts(WEIGHT_PER_GAS, 0);
pub const TokenSymbol: &'static str = "CFG";
}
Expand All @@ -2003,7 +2003,7 @@ impl pallet_evm::Config for Runtime {
type GasWeightMapping = pallet_evm::FixedGasWeightMapping<Self>;
type OnChargeTransaction = ();
type OnCreate = ();
type PrecompilesType = CentrifugePrecompiles;
type PrecompilesType = Precompiles;
type PrecompilesValue = PrecompilesValue;
type Runner = pallet_evm::runner::stack::Runner<Self>;
type RuntimeEvent = RuntimeEvent;
Expand Down
8 changes: 4 additions & 4 deletions runtime/development/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ use runtime_common::{
asset_registry,
changes::FastDelay,
evm::{
precompile::Precompiles, BaseFeeThreshold, FindAuthorTruncated, GAS_LIMIT_POV_SIZE_RATIO,
self, BaseFeeThreshold, FindAuthorTruncated, GAS_LIMIT_POV_SIZE_RATIO,
GAS_LIMIT_STORAGE_GROWTH_RATIO, WEIGHT_PER_GAS,
},
fees::{DealWithFees, FeeToTreasury, WeightToFee},
Expand Down Expand Up @@ -1957,11 +1957,11 @@ parameter_types! {
pub type XcmWeigher =
staging_xcm_builder::FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;

pub type DevelopmentPrecompiles = Precompiles<crate::Runtime, TokenSymbol>;
pub type Precompiles = evm::precompile::Precompiles<crate::Runtime, TokenSymbol>;

parameter_types! {
pub BlockGasLimit: U256 = U256::from(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT.ref_time() / WEIGHT_PER_GAS);
pub PrecompilesValue: DevelopmentPrecompiles = Precompiles::<_, _>::new();
pub PrecompilesValue: Precompiles = Precompiles::new();
pub WeightPerGas: Weight = Weight::from_parts(WEIGHT_PER_GAS, 0);
pub const TokenSymbol: &'static str = "DCFG";
}
Expand All @@ -1980,7 +1980,7 @@ impl pallet_evm::Config for Runtime {
type GasWeightMapping = pallet_evm::FixedGasWeightMapping<Self>;
type OnChargeTransaction = ();
type OnCreate = ();
type PrecompilesType = DevelopmentPrecompiles;
type PrecompilesType = Precompiles;
type PrecompilesValue = PrecompilesValue;
type Runner = pallet_evm::runner::stack::Runner<Self>;
type RuntimeEvent = RuntimeEvent;
Expand Down
4 changes: 4 additions & 0 deletions runtime/integration-tests/src/generic/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use cfg_types::{
permissions::{PermissionScope, Role},
tokens::{AssetStringLimit, CurrencyId, CustomMetadata, FilterCurrency, TrancheCurrency},
};
use fp_evm::PrecompileSet;
use fp_self_contained::{SelfContainedCall, UncheckedExtrinsic};
use frame_support::{
dispatch::{DispatchInfo, GetDispatchInfo, PostDispatchInfo, RawOrigin},
Expand All @@ -26,6 +27,7 @@ use pallet_transaction_payment::CurrencyAdapter;
use parity_scale_codec::Codec;
use runtime_common::{
apis,
evm::precompile::H160Addresses,
fees::{DealWithFees, WeightToFee},
instances,
oracle::Feeder,
Expand Down Expand Up @@ -338,5 +340,7 @@ pub trait Runtime:

type SessionKeysExt: OpaqueKeys + Member + Parameter + MaybeSerializeDeserialize;

type PrecompilesTypeExt: PrecompileSet + H160Addresses;

fn initialize_session_keys(public_id: Public) -> Self::SessionKeysExt;
}
24 changes: 4 additions & 20 deletions runtime/integration-tests/src/generic/envs/runtime_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use sp_timestamp::Timestamp;

use crate::{
generic::{
config::{Runtime, RuntimeKind},
config::Runtime,
env::{utils, Env, EnvEvmExtension},
envs::evm_env::EvmEnv,
},
Expand Down Expand Up @@ -191,27 +191,11 @@ impl<T: Runtime> RuntimeEnv<T> {
let mut ext = sp_io::TestExternalities::new(storage);

ext.execute_with(|| {
let accounts = match T::KIND {
RuntimeKind::Centrifuge => {
runtime_common::evm::precompile::utils::precompile_account_genesis::<
centrifuge_runtime::CentrifugePrecompiles,
>()
}
RuntimeKind::Altair => {
runtime_common::evm::precompile::utils::precompile_account_genesis::<
altair_runtime::AltairPrecompiles,
>()
}
RuntimeKind::Development => {
runtime_common::evm::precompile::utils::precompile_account_genesis::<
development_runtime::DevelopmentPrecompiles,
>()
}
};

// Precompiles need to have code-set
pallet_evm::GenesisConfig::<T> {
accounts,
accounts: runtime_common::evm::precompile::utils::precompile_account_genesis::<
T::PrecompilesTypeExt,
>(),
_marker: PhantomData::default(),
}
.build();
Expand Down
1 change: 1 addition & 0 deletions runtime/integration-tests/src/generic/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ macro_rules! impl_runtime {
type Api = Self;
type BlockExt = $runtime_path::Block;
type MaxTranchesExt = $runtime_path::MaxTranches;
type PrecompilesTypeExt = $runtime_path::Precompiles;
type RuntimeCallExt = $runtime_path::RuntimeCall;
type RuntimeEventExt = $runtime_path::RuntimeEvent;
type RuntimeOriginExt = $runtime_path::RuntimeOrigin;
Expand Down

0 comments on commit 857d618

Please sign in to comment.