Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions runtime/devnet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ pallet-nft-fractionalization.workspace = true
pallet-nfts-runtime-api.workspace = true
pallet-preimage.workspace = true
pallet-proxy.workspace = true
pallet-revive.workspace = true
pallet-scheduler.workspace = true
pallet-session.workspace = true
pallet-sudo.workspace = true
Expand Down Expand Up @@ -147,6 +148,7 @@ std = [
"pallet-nfts/std",
"pallet-preimage/std",
"pallet-proxy/std",
"pallet-revive/std",
"pallet-scheduler/std",
"pallet-session/std",
"pallet-sudo/std",
Expand Down Expand Up @@ -204,6 +206,7 @@ runtime-benchmarks = [
"pallet-nfts/runtime-benchmarks",
"pallet-preimage/runtime-benchmarks",
"pallet-proxy/runtime-benchmarks",
"pallet-revive/runtime-benchmarks",
"pallet-scheduler/runtime-benchmarks",
"pallet-sudo/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",
Expand Down Expand Up @@ -244,6 +247,7 @@ try-runtime = [
"pallet-nfts/try-runtime",
"pallet-preimage/try-runtime",
"pallet-proxy/try-runtime",
"pallet-revive/try-runtime",
"pallet-scheduler/try-runtime",
"pallet-session/try-runtime",
"pallet-sudo/try-runtime",
Expand Down
56 changes: 52 additions & 4 deletions runtime/devnet/src/config/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

use frame_support::{
parameter_types,
traits::{ConstBool, ConstU32, Nothing, Randomness},
traits::{ConstBool, ConstU32, ConstU64, Nothing, Randomness},

Check warning on line 5 in runtime/devnet/src/config/contracts.rs

View workflow job for this annotation

GitHub Actions / clippy

unused import: `ConstU64`

warning: unused import: `ConstU64` --> runtime/devnet/src/config/contracts.rs:5:32 | 5 | traits::{ConstBool, ConstU32, ConstU64, Nothing, Randomness}, | ^^^^^^^^ | = note: `#[warn(unused_imports)]` on by default
};
use frame_system::{pallet_prelude::BlockNumberFor, EnsureSigned};
use pop_runtime_common::UNIT;

use super::api::{self, Config};
use crate::{
deposit, Balance, Balances, Perbill, Runtime, RuntimeCall, RuntimeEvent, RuntimeHoldReason,
Timestamp,
deposit, Balance, Balances, Perbill, PolkadotXcm, Runtime, RuntimeCall, RuntimeEvent,
RuntimeHoldReason, Timestamp, TransactionPayment,
};

fn schedule<T: pallet_contracts::Config>() -> pallet_contracts::Schedule<T> {
Expand All @@ -33,12 +34,18 @@
}
}

// 18 decimals
const ETH: u128 = 1_000_000_000_000_000_000;

parameter_types! {
pub ChainId: u64 = u32::from(crate::genesis::PARA_ID) as u64;
pub const DepositPerItem: Balance = deposit(1, 0);
pub const DepositPerByte: Balance = deposit(0, 1);
pub Schedule: pallet_contracts::Schedule<Runtime> = schedule::<Runtime>();
pub const DefaultDepositLimit: Balance = deposit(1024, 1024 * 1024);
pub const CodeHashLockupDepositPercent: Perbill = Perbill::from_percent(0);
// 30 percent of storage deposit held for using a code hash.
pub const CodeHashLockupDepositPercent: Perbill = Perbill::from_percent(30);
pub const NativeToEthRatio: u32 = (ETH/UNIT) as u32;
}

impl pallet_contracts::Config for Runtime {
Expand Down Expand Up @@ -83,6 +90,47 @@
type Xcm = pallet_xcm::Pallet<Self>;
}

impl pallet_revive::Config for Runtime {
type AddressMapper = pallet_revive::AccountId32Mapper<Self>;
// No runtime dispatchables are callable from contracts.
type CallFilter = Nothing;
type ChainExtension = ();
type ChainId = ChainId;
type CodeHashLockupDepositPercent = CodeHashLockupDepositPercent;
type Currency = Balances;
type Debug = ();
type DepositPerByte = DepositPerByte;
type DepositPerItem = DepositPerItem;
type InstantiateOrigin = EnsureSigned<Self::AccountId>;
// 1 ETH : 1_000_000 UNIT
type NativeToEthRatio = NativeToEthRatio;
// 512 MB. Used in an integrity test that verifies the runtime has enough memory.
type PVFMemory = ConstU32<{ 512 * 1024 * 1024 }>;
type RuntimeCall = RuntimeCall;
type RuntimeEvent = RuntimeEvent;
type RuntimeHoldReason = RuntimeHoldReason;
// 128 MB. Used in an integrity that verifies the runtime has enough memory.
type RuntimeMemory = ConstU32<{ 128 * 1024 * 1024 }>;
type Time = Timestamp;
// Disables access to unsafe host fns such as xcm_send.
type UnsafeUnstableInterface = ConstBool<false>;
type UploadOrigin = EnsureSigned<Self::AccountId>;
type WeightInfo = pallet_revive::weights::SubstrateWeight<Self>;
type WeightPrice = TransactionPayment;
type Xcm = PolkadotXcm;
}

impl TryFrom<RuntimeCall> for pallet_revive::Call<Runtime> {
type Error = ();

fn try_from(value: RuntimeCall) -> Result<Self, Self::Error> {
match value {
RuntimeCall::Revive(call) => Ok(call),
_ => Err(()),
}
}
}

// IMPORTANT: only runtime calls through the api are allowed.
#[test]
fn contracts_prevents_runtime_calls() {
Expand Down
177 changes: 162 additions & 15 deletions runtime/devnet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));

// Public due to integration tests crate.
pub mod config;

Check warning on line 10 in runtime/devnet/src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for a module

warning: missing documentation for a module --> runtime/devnet/src/lib.rs:10:1 | 10 | pub mod config; | ^^^^^^^^^^^^^^
/// The genesis state presets available.
pub mod genesis;
mod weights;
Expand All @@ -22,18 +22,22 @@
host::StateMachine,
router::{Request, Response},
};
use codec::Encode;
use config::xcm::{RelayLocation, XcmOriginToTransactDispatchOrigin};
use cumulus_pallet_parachain_system::{RelayChainState, RelayNumberMonotonicallyIncreases};
use cumulus_primitives_core::{AggregateMessageOrigin, ParaId};
use cumulus_primitives_storage_weight_reclaim::StorageWeightReclaim;
use frame_metadata_hash_extension::CheckMetadataHash;
use frame_support::{
derive_impl,
dispatch::DispatchClass,
genesis_builder_helper::{build_state, get_preset},
parameter_types,
traits::{
fungible::HoldConsideration, tokens::nonfungibles_v2::Inspect, ConstBool, ConstU32,
ConstU64, ConstU8, Contains, EitherOfDiverse, EqualPrivilegeOnly, EverythingBut,
LinearStoragePrice, TransformOrigin, VariantCountOf,
fungible::HoldConsideration,
tokens::{nonfungibles_v2::Inspect, Fortitude::Polite, Preservation::Preserve},
ConstBool, ConstU32, ConstU64, ConstU8, Contains, EitherOfDiverse, EqualPrivilegeOnly,
EverythingBut, LinearStoragePrice, TransformOrigin, VariantCountOf,
},
weights::{
ConstantMultiplier, Weight, WeightToFeeCoefficient, WeightToFeeCoefficients,
Expand All @@ -43,11 +47,14 @@
};
use frame_system::{
limits::{BlockLength, BlockWeights},
EnsureRoot,
CheckGenesis, CheckMortality, CheckNonZeroSender, CheckNonce, CheckSpecVersion, CheckTxVersion,
CheckWeight, EnsureRoot,
};
use pallet_api::{fungibles, nonfungibles};
use pallet_balances::Call as BalancesCall;
use pallet_ismp::offchain::{Leaf, Proof, ProofKeys};
use pallet_revive::{evm::H160, AddressMapper};
use pallet_transaction_payment::ChargeTransactionPayment;
use pallet_xcm::{EnsureXcm, IsVoiceOfBody};
use parachains_common::message_queue::{NarrowOriginToSibling, ParaIdToSibling};
use polkadot_runtime_common::xcm_sender::NoPriceForMessageDelivery;
Expand Down Expand Up @@ -99,21 +106,45 @@

/// The extension to the basic transaction logic.
pub type TxExtension = (
frame_system::CheckNonZeroSender<Runtime>,
frame_system::CheckSpecVersion<Runtime>,
frame_system::CheckTxVersion<Runtime>,
frame_system::CheckGenesis<Runtime>,
frame_system::CheckMortality<Runtime>,
frame_system::CheckNonce<Runtime>,
frame_system::CheckWeight<Runtime>,
pallet_transaction_payment::ChargeTransactionPayment<Runtime>,
cumulus_primitives_storage_weight_reclaim::StorageWeightReclaim<Runtime>,
frame_metadata_hash_extension::CheckMetadataHash<Runtime>,
CheckNonZeroSender<Runtime>,
CheckSpecVersion<Runtime>,
CheckTxVersion<Runtime>,
CheckGenesis<Runtime>,
CheckMortality<Runtime>,
CheckNonce<Runtime>,
CheckWeight<Runtime>,
ChargeTransactionPayment<Runtime>,
StorageWeightReclaim<Runtime>,
CheckMetadataHash<Runtime>,
);

/// EthExtra converts an unsigned Call::eth_transact into a CheckedExtrinsic.
#[derive(Clone, PartialEq, Eq, Debug)]
pub struct EthExtraImpl;

impl pallet_revive::evm::runtime::EthExtra for EthExtraImpl {
type Config = Runtime;
type Extension = TxExtension;

fn get_eth_extension(nonce: u32, tip: Balance) -> Self::Extension {
(
CheckNonZeroSender::<Runtime>::new(),
CheckSpecVersion::<Runtime>::new(),
CheckTxVersion::<Runtime>::new(),
CheckGenesis::<Runtime>::new(),
CheckMortality::from(generic::Era::Immortal),
CheckNonce::<Runtime>::from(nonce),
CheckWeight::<Runtime>::new(),
ChargeTransactionPayment::<Runtime>::from(tip),
StorageWeightReclaim::<Runtime>::new(),
CheckMetadataHash::<Runtime>::new(false),
)
}
}

/// Unchecked extrinsic type as expected by this runtime.
pub type UncheckedExtrinsic =
generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, TxExtension>;
pallet_revive::evm::runtime::UncheckedExtrinsic<Address, Signature, EthExtraImpl>;

/// All migrations of the runtime, aside from the ones declared in the pallets.
///
Expand Down Expand Up @@ -142,6 +173,7 @@
/// - Setting it to `0` will essentially disable the weight fee.
/// - Setting it to `1` will cause the literal `#[weight = x]` values to be charged.
pub struct WeightToFee;

impl WeightToFeePolynomial for WeightToFee {
type Balance = Balance;

Expand Down Expand Up @@ -171,6 +203,7 @@
};

use super::*;

/// Opaque block header type.
pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
/// Opaque block type.
Expand All @@ -188,7 +221,7 @@
}

#[sp_version::runtime_version]
pub const VERSION: RuntimeVersion = RuntimeVersion {

Check warning on line 224 in runtime/devnet/src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for a constant

warning: missing documentation for a constant --> runtime/devnet/src/lib.rs:224:1 | 224 | pub const VERSION: RuntimeVersion = RuntimeVersion { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
spec_name: Cow::Borrowed("pop"),
impl_name: Cow::Borrowed("pop"),
authoring_version: 1,
Expand Down Expand Up @@ -558,7 +591,7 @@
type WeightInfo = pallet_utility::weights::SubstrateWeight<Runtime>;
}

#[frame_support::runtime]

Check warning on line 594 in runtime/devnet/src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for an associated function

warning: missing documentation for an associated function --> runtime/devnet/src/lib.rs:594:1 | 594 | #[frame_support::runtime] | ^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: this warning originates in the attribute macro `frame_support::runtime` (in Nightly builds, run with -Z macro-backtrace for more info)

Check warning on line 594 in runtime/devnet/src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for a type alias

warning: missing documentation for a type alias --> runtime/devnet/src/lib.rs:594:1 | 594 | #[frame_support::runtime] | ^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: this warning originates in the attribute macro `frame_support::runtime` (in Nightly builds, run with -Z macro-backtrace for more info)

Check warning on line 594 in runtime/devnet/src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for a struct field

warning: missing documentation for a struct field --> runtime/devnet/src/lib.rs:594:1 | 594 | #[frame_support::runtime] | ^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: this warning originates in the attribute macro `frame_support::runtime` (in Nightly builds, run with -Z macro-backtrace for more info)

Check warning on line 594 in runtime/devnet/src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for a variant

warning: missing documentation for a variant --> runtime/devnet/src/lib.rs:594:1 | 594 | #[frame_support::runtime] | ^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: this warning originates in the attribute macro `frame_support::runtime` (in Nightly builds, run with -Z macro-backtrace for more info)

Check warning on line 594 in runtime/devnet/src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for an enum

warning: missing documentation for an enum --> runtime/devnet/src/lib.rs:594:1 | 594 | #[frame_support::runtime] | ^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: this warning originates in the attribute macro `frame_support::runtime` (in Nightly builds, run with -Z macro-backtrace for more info)

Check warning on line 594 in runtime/devnet/src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

missing documentation for a struct

warning: missing documentation for a struct --> runtime/devnet/src/lib.rs:594:1 | 594 | #[frame_support::runtime] | ^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: this warning originates in the attribute macro `frame_support::runtime` (in Nightly builds, run with -Z macro-backtrace for more info)
mod runtime {
// Create the runtime by composing the FRAME pallets that were previously configured.
#[runtime::runtime]
Expand Down Expand Up @@ -632,6 +665,8 @@
// Contracts
#[runtime::pallet_index(40)]
pub type Contracts = pallet_contracts::Pallet<Runtime>;
#[runtime::pallet_index(60)]
pub type Revive = pallet_revive::Pallet<Runtime>;

// Proxy
#[runtime::pallet_index(41)]
Expand Down Expand Up @@ -957,6 +992,118 @@
}
}

impl pallet_revive::ReviveApi<Block, AccountId, Balance, Nonce, BlockNumber, EventRecord> for Runtime
{
fn balance(address: H160) -> Balance {
use frame_support::traits::fungible::Inspect;
let account = <Runtime as pallet_revive::Config>::AddressMapper::to_account_id(&address);
Balances::reducible_balance(&account, Preserve, Polite)
}

fn nonce(address: H160) -> Nonce {
let account = <Runtime as pallet_revive::Config>::AddressMapper::to_account_id(&address);
System::account_nonce(account)
}

fn eth_transact(
from: H160,
dest: Option<H160>,
value: Balance,
input: Vec<u8>,
gas_limit: Option<Weight>,
storage_deposit_limit: Option<Balance>,
) -> pallet_revive::EthContractResult<Balance>
{
use pallet_revive::AddressMapper;
let blockweights: BlockWeights = <Runtime as frame_system::Config>::BlockWeights::get();
let origin = <Runtime as pallet_revive::Config>::AddressMapper::to_account_id(&from);

let encoded_size = |pallet_call| {
let call = RuntimeCall::Revive(pallet_call);
let uxt: UncheckedExtrinsic = sp_runtime::generic::UncheckedExtrinsic::new_bare(call).into();
uxt.encoded_size() as u32
};

Revive::bare_eth_transact(
origin,
dest,
value,
input,
gas_limit.unwrap_or(blockweights.max_block),
storage_deposit_limit.unwrap_or(u128::MAX),
encoded_size,
pallet_revive::DebugInfo::UnsafeDebug,
pallet_revive::CollectEvents::UnsafeCollect,
)
}

fn call(
origin: AccountId,
dest: H160,
value: Balance,
gas_limit: Option<Weight>,
storage_deposit_limit: Option<Balance>,
input_data: Vec<u8>,
) -> pallet_revive::ContractResult<pallet_revive::ExecReturnValue, Balance, EventRecord> {
Revive::bare_call(
RuntimeOrigin::signed(origin),
dest,
value,
gas_limit.unwrap_or(RuntimeBlockWeights::get().max_block),
storage_deposit_limit.unwrap_or(u128::MAX),
input_data,
pallet_revive::DebugInfo::UnsafeDebug,
pallet_revive::CollectEvents::UnsafeCollect,
)
}

fn instantiate(
origin: AccountId,
value: Balance,
gas_limit: Option<Weight>,
storage_deposit_limit: Option<Balance>,
code: pallet_revive::Code,
data: Vec<u8>,
salt: Option<[u8; 32]>,
) -> pallet_revive::ContractResult<pallet_revive::InstantiateReturnValue, Balance, EventRecord>
{
Revive::bare_instantiate(
RuntimeOrigin::signed(origin),
value,
gas_limit.unwrap_or(RuntimeBlockWeights::get().max_block),
storage_deposit_limit.unwrap_or(u128::MAX),
code,
data,
salt,
pallet_revive::DebugInfo::UnsafeDebug,
pallet_revive::CollectEvents::UnsafeCollect,
)
}

fn upload_code(
origin: AccountId,
code: Vec<u8>,
storage_deposit_limit: Option<Balance>,
) -> pallet_revive::CodeUploadResult<Balance>
{
Revive::bare_upload_code(
RuntimeOrigin::signed(origin),
code,
storage_deposit_limit.unwrap_or(u128::MAX),
)
}

fn get_storage(
address: H160,
key: [u8; 32],
) -> pallet_revive::GetStorageResult {
Revive::get_storage(
address,
key
)
}
}

#[cfg(feature = "try-runtime")]
impl frame_try_runtime::TryRuntime<Block> for Runtime {
fn on_runtime_upgrade(checks: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) {
Expand Down Expand Up @@ -1000,7 +1147,7 @@
use frame_benchmarking::{BenchmarkError, Benchmarking, BenchmarkBatch};

use frame_system_benchmarking::Pallet as SystemBench;
impl frame_system_benchmarking::Config for Runtime {

Check warning on line 1150 in runtime/devnet/src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

non-local `impl` definition, `impl` blocks should be written at the same level as their item

warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item --> runtime/devnet/src/lib.rs:1150:4 | 1144 | / fn dispatch_benchmark( 1145 | | config: frame_benchmarking::BenchmarkConfig 1146 | | ) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, alloc::string::String> { | |___________________________________________________________________________________- move the `impl` block outside of this associated function `dispatch_benchmark` ... 1150 | impl frame_system_benchmarking::Config for Runtime { | ^^^^^---------------------------------^^^^^------- | | | | | `Runtime` is not local | `Config` is not local | = note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl` = note: `#[warn(non_local_definitions)]` on by default
fn setup_set_code_requirements(code: &Vec<u8>) -> Result<(), BenchmarkError> {
ParachainSystem::initialize_for_set_code_benchmark(code.len() as u32);
Ok(())
Expand All @@ -1012,7 +1159,7 @@
}

use cumulus_pallet_session_benchmarking::Pallet as SessionBench;
impl cumulus_pallet_session_benchmarking::Config for Runtime {}

Check warning on line 1162 in runtime/devnet/src/lib.rs

View workflow job for this annotation

GitHub Actions / clippy

non-local `impl` definition, `impl` blocks should be written at the same level as their item

warning: non-local `impl` definition, `impl` blocks should be written at the same level as their item --> runtime/devnet/src/lib.rs:1162:4 | 1144 | / fn dispatch_benchmark( 1145 | | config: frame_benchmarking::BenchmarkConfig 1146 | | ) -> Result<Vec<frame_benchmarking::BenchmarkBatch>, alloc::string::String> { | |___________________________________________________________________________________- move the `impl` block outside of this associated function `dispatch_benchmark` ... 1162 | impl cumulus_pallet_session_benchmarking::Config for Runtime {} | ^^^^^-------------------------------------------^^^^^------- | | | | | `Runtime` is not local | `Config` is not local | = note: an `impl` is never scoped, even when it is nested inside an item, as it may impact type checking outside of that item, which can be the case if neither the trait or the self type are at the same nesting level as the `impl`

use frame_support::traits::WhitelistedStorageKeys;
let whitelist = AllPalletsWithSystem::whitelisted_storage_keys();
Expand Down
Loading