diff --git a/Cargo.toml b/Cargo.toml index 0f881d3..cb3c463 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,28 +8,28 @@ repository = "https://github.com/paritytech/substrate-contracts-node" [workspace] resolver = "2" -members = [ - "node", - "runtime", - "parachain-runtime", -] +members = ["node", "runtime", "parachain-runtime"] [profile.release] panic = 'unwind' [workspace.dependencies] clap = { version = "4.5.10", features = ["derive"] } -codec = { package = "parity-scale-codec", version = "3.6.12", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "3.6.12", default-features = false, features = [ + "derive", +] } futures = "0.3.30" -hex-literal = { version = "0.4.1"} +hex-literal = { version = "0.4.1" } jsonrpsee = { version = "0.24.3", features = ["server"] } log = { version = "0.4.22", default-features = false } serde = { version = "1.0.209", features = ["derive"] } serde_json = "1.0.127" -scale-info = { version = "2.11.1", default-features = false, features = ["derive"] } +scale-info = { version = "2.11.1", default-features = false, features = [ + "derive", +] } smallvec = "1.11.0" color-print = "0.3.4" -wasmtime="8.0.1" +wasmtime = "8.0.1" # Substrate frame-benchmarking = { version = "38.0.0", default-features = false } @@ -44,6 +44,7 @@ frame-try-runtime = { version = "0.44.0", default-features = false } pallet-aura = { version = "37.0.0", default-features = false } pallet-authorship = { version = "38.0.0", default-features = false } pallet-balances = { version = "39.0.0", default-features = false } +pallet-contracts = { version = "38.0.0", default-features = false } pallet-session = { version = "38.0.0", default-features = false } pallet-sudo = { version = "38.0.0", default-features = false } pallet-timestamp = { version = "37.0.0", default-features = false } @@ -98,10 +99,10 @@ sp-storage = { version = "21.0.0", default-features = false } sc-consensus-aura = { version = "0.45.0", default-features = false } sc-consensus-manual-seal = { version = "0.46.0", default-features = false } -# extra deps for setting up pallet-contracts -pallet-contracts = { version = "38.0.0", default-features = false } -pallet-insecure-randomness-collective-flip = { version = "26.0.0", default-features = false } +# extra deps for setting up pallet-revive pallet-assets = { version = "40.0.0", default-features = false } +pallet-insecure-randomness-collective-flip = { version = "26.0.0", default-features = false } +pallet-revive = { version = "0.2.0", default-features = false } pallet-utility = { version = "38.0.0", default-features = false } # Polkadot @@ -136,4 +137,3 @@ cumulus-relay-chain-interface = { version = "0.18.0" } pallet-collator-selection = { version = "19.0.0", default-features = false } parachain-info = { version = "0.17.0", package = "staging-parachain-info", default-features = false } parachains-common = { version = "18.0.0", default-features = false } - diff --git a/node/Cargo.toml b/node/Cargo.toml index a3e555c..696930d 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -2,7 +2,7 @@ name = "contracts-node" version.workspace = true authors.workspace = true -description = "Substrate node configured for smart contracts via `pallet-contracts`." +description = "Substrate node configured for smart contracts via `pallet-contracts` and `pallet-revive`." edition.workspace = true license.workspace = true build = "build.rs" @@ -27,8 +27,10 @@ serde_json = { workspace = true } wasmtime = { workspace = true } # Local -contracts-parachain-runtime = { path = "../parachain-runtime", features = ["parachain"], version = "0.42.0" } -contracts-node-runtime = { path = "../runtime", version = "0.42.0" } +contracts-parachain-runtime = { path = "../parachain-runtime", features = [ + "parachain", +], version = "0.42.0" } +contracts-node-runtime = { path = "../runtime", version = "0.42.0" } # Substrate frame-benchmarking = { workspace = true } @@ -93,10 +95,10 @@ substrate-build-script-utils = { workspace = true } [features] default = [] runtime-benchmarks = [ - "contracts-parachain-runtime/runtime-benchmarks", - "polkadot-cli/runtime-benchmarks", + "contracts-parachain-runtime/runtime-benchmarks", + "polkadot-cli/runtime-benchmarks", ] try-runtime = [ - "try-runtime-cli/try-runtime", - "contracts-parachain-runtime/try-runtime" + "try-runtime-cli/try-runtime", + "contracts-parachain-runtime/try-runtime", ] diff --git a/parachain-runtime/Cargo.toml b/parachain-runtime/Cargo.toml index b6d1885..a76ad4b 100644 --- a/parachain-runtime/Cargo.toml +++ b/parachain-runtime/Cargo.toml @@ -3,7 +3,7 @@ name = "contracts-parachain-runtime" version.workspace = true authors.workspace = true edition.workspace = true -description = "Parachain Runtime configured for smart contracts via `pallet-contracts`." +description = "Parachain Runtime configured for smart contracts via `pallet-contracts` and `pallet-revive`." license.workspace = true homepage.workspace = true repository.workspace = true @@ -11,12 +11,10 @@ repository.workspace = true [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] [build-dependencies] -substrate-wasm-builder = {workspace = true, optional = true } +substrate-wasm-builder = { workspace = true, optional = true } [dependencies] -codec = { features = [ - "derive", -], workspace = true } +codec = { features = ["derive"], workspace = true } hex-literal = { version = "0.4.1", optional = true } log = { version = "0.4.21", default-features = false } scale-info = { workspace = true } @@ -27,9 +25,9 @@ frame-benchmarking = { workspace = true, optional = true } frame-executive = { workspace = true } frame-support = { workspace = true } frame-system = { workspace = true } -frame-system-benchmarking = {workspace = true, optional = true} +frame-system-benchmarking = { workspace = true, optional = true } frame-system-rpc-runtime-api = { workspace = true } -frame-try-runtime = { workspace = true, optional = true} +frame-try-runtime = { workspace = true, optional = true } pallet-aura = { workspace = true } pallet-authorship = { workspace = true } pallet-balances = { workspace = true } @@ -75,111 +73,113 @@ pallet-collator-selection = { workspace = true } parachain-info = { workspace = true } parachains-common = { workspace = true } -# extra deps for setting up pallet-contracts +# extra deps for setting up pallet-contracts and pallet-revive pallet-contracts = { workspace = true } +pallet-revive = { workspace = true } pallet-utility = { workspace = true } pallet-insecure-randomness-collective-flip = { workspace = true } pallet-assets = { workspace = true } [features] -default = [ - "std", -] +default = ["std"] std = [ - "codec/std", - "cumulus-pallet-aura-ext/std", - "cumulus-pallet-dmp-queue/std", - "cumulus-pallet-parachain-system/std", - "cumulus-pallet-xcm/std", - "cumulus-pallet-xcmp-queue/std", - "cumulus-primitives-aura/std", - "cumulus-primitives-core/std", - "cumulus-primitives-timestamp/std", - "cumulus-primitives-utility/std", - "frame-executive/std", - "frame-support/std", - "frame-system-rpc-runtime-api/std", - "frame-system/std", - "log/std", - "pallet-assets/std", - "pallet-aura/std", - "pallet-authorship/std", - "pallet-balances/std", - "pallet-collator-selection/std", - "pallet-contracts/std", - "pallet-insecure-randomness-collective-flip/std", - "pallet-session/std", - "pallet-sudo/std", - "pallet-xcm/std", - "pallet-timestamp/std", - "pallet-transaction-payment-rpc-runtime-api/std", - "pallet-transaction-payment/std", - "pallet-xcm/std", - "parachain-info/std", - "polkadot-parachain-primitives/std", - "polkadot-runtime-common/std", - "scale-info/std", - "scale-info/std", - "sp-api/std", - "sp-block-builder/std", - "sp-consensus-aura/std", - "sp-core/std", - "sp-inherents/std", - "sp-offchain/std", - "sp-runtime/std", - "sp-session/std", - "sp-std/std", - "sp-transaction-pool/std", - "sp-version/std", - "substrate-wasm-builder", - "xcm-builder/std", - "xcm-executor/std", - "xcm/std", + "codec/std", + "cumulus-pallet-aura-ext/std", + "cumulus-pallet-dmp-queue/std", + "cumulus-pallet-parachain-system/std", + "cumulus-pallet-xcm/std", + "cumulus-pallet-xcmp-queue/std", + "cumulus-primitives-aura/std", + "cumulus-primitives-core/std", + "cumulus-primitives-timestamp/std", + "cumulus-primitives-utility/std", + "frame-executive/std", + "frame-support/std", + "frame-system-rpc-runtime-api/std", + "frame-system/std", + "log/std", + "pallet-assets/std", + "pallet-aura/std", + "pallet-authorship/std", + "pallet-balances/std", + "pallet-collator-selection/std", + "pallet-contracts/std", + "pallet-revive/std", + "pallet-insecure-randomness-collective-flip/std", + "pallet-session/std", + "pallet-sudo/std", + "pallet-xcm/std", + "pallet-timestamp/std", + "pallet-transaction-payment-rpc-runtime-api/std", + "pallet-transaction-payment/std", + "pallet-xcm/std", + "parachain-info/std", + "polkadot-parachain-primitives/std", + "polkadot-runtime-common/std", + "scale-info/std", + "scale-info/std", + "sp-api/std", + "sp-block-builder/std", + "sp-consensus-aura/std", + "sp-core/std", + "sp-inherents/std", + "sp-offchain/std", + "sp-runtime/std", + "sp-session/std", + "sp-std/std", + "sp-transaction-pool/std", + "sp-version/std", + "substrate-wasm-builder", + "xcm-builder/std", + "xcm-executor/std", + "xcm/std", ] runtime-benchmarks = [ - "cumulus-pallet-parachain-system/runtime-benchmarks", - "cumulus-pallet-session-benchmarking/runtime-benchmarks", - "cumulus-pallet-xcmp-queue/runtime-benchmarks", - "frame-benchmarking/runtime-benchmarks", - "frame-support/runtime-benchmarks", - "frame-system-benchmarking/runtime-benchmarks", - "frame-system/runtime-benchmarks", - "hex-literal", - "polkadot-parachain-primitives/runtime-benchmarks", - "pallet-balances/runtime-benchmarks", - "pallet-collator-selection/runtime-benchmarks", - "pallet-sudo/runtime-benchmarks", - "pallet-timestamp/runtime-benchmarks", - "pallet-xcm/runtime-benchmarks", - "polkadot-runtime-common/runtime-benchmarks", - "sp-runtime/runtime-benchmarks", - "xcm-builder/runtime-benchmarks", - "xcm-executor/runtime-benchmarks", + "cumulus-pallet-parachain-system/runtime-benchmarks", + "cumulus-pallet-session-benchmarking/runtime-benchmarks", + "cumulus-pallet-xcmp-queue/runtime-benchmarks", + "frame-benchmarking/runtime-benchmarks", + "frame-support/runtime-benchmarks", + "frame-system-benchmarking/runtime-benchmarks", + "frame-system/runtime-benchmarks", + "hex-literal", + "polkadot-parachain-primitives/runtime-benchmarks", + "pallet-balances/runtime-benchmarks", + "pallet-collator-selection/runtime-benchmarks", + "pallet-sudo/runtime-benchmarks", + "pallet-timestamp/runtime-benchmarks", + "pallet-xcm/runtime-benchmarks", + "polkadot-runtime-common/runtime-benchmarks", + "sp-runtime/runtime-benchmarks", + "xcm-builder/runtime-benchmarks", + "xcm-executor/runtime-benchmarks", ] try-runtime = [ - "cumulus-pallet-aura-ext/try-runtime", - "cumulus-pallet-dmp-queue/try-runtime", - "cumulus-pallet-parachain-system/try-runtime", - "cumulus-pallet-xcm/try-runtime", - "cumulus-pallet-xcmp-queue/try-runtime", - "frame-executive/try-runtime", - "frame-support/try-runtime", - "frame-system/try-runtime", - "frame-try-runtime/try-runtime", - "pallet-aura/try-runtime", - "pallet-authorship/try-runtime", - "pallet-balances/try-runtime", - "pallet-collator-selection/try-runtime", - "pallet-session/try-runtime", - "pallet-sudo/try-runtime", - "pallet-timestamp/try-runtime", - "pallet-transaction-payment/try-runtime", - "pallet-xcm/try-runtime", - "parachain-info/try-runtime", - "polkadot-runtime-common/try-runtime", - "sp-runtime/try-runtime", + "cumulus-pallet-aura-ext/try-runtime", + "cumulus-pallet-dmp-queue/try-runtime", + "cumulus-pallet-parachain-system/try-runtime", + "cumulus-pallet-xcm/try-runtime", + "cumulus-pallet-xcmp-queue/try-runtime", + "frame-executive/try-runtime", + "frame-support/try-runtime", + "frame-system/try-runtime", + "frame-try-runtime/try-runtime", + "pallet-aura/try-runtime", + "pallet-authorship/try-runtime", + "pallet-balances/try-runtime", + "pallet-collator-selection/try-runtime", + "pallet-contracts/try-runtime", + "pallet-revive/try-runtime", + "pallet-session/try-runtime", + "pallet-sudo/try-runtime", + "pallet-timestamp/try-runtime", + "pallet-transaction-payment/try-runtime", + "pallet-xcm/try-runtime", + "parachain-info/try-runtime", + "polkadot-runtime-common/try-runtime", + "sp-runtime/try-runtime", ] parachain = [] diff --git a/parachain-runtime/src/lib.rs b/parachain-runtime/src/lib.rs index b810336..6e20b73 100644 --- a/parachain-runtime/src/lib.rs +++ b/parachain-runtime/src/lib.rs @@ -6,9 +6,9 @@ #[cfg(feature = "std")] include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); -// mod contracts_config; mod assets_config; mod contracts_config; +mod revive_config; mod weights; mod xcm_config; @@ -543,30 +543,32 @@ mod runtime { #[runtime::pallet_index(8)] pub type Contracts = pallet_contracts; #[runtime::pallet_index(9)] + pub type Revive = pallet_revive; + #[runtime::pallet_index(10)] pub type Assets = pallet_assets; // Parachain support. - #[runtime::pallet_index(10)] - pub type ParachainSystem = cumulus_pallet_parachain_system; #[runtime::pallet_index(11)] + pub type ParachainSystem = cumulus_pallet_parachain_system; + #[runtime::pallet_index(12)] pub type ParachainInfo = parachain_info; // Collator support. The order of these 4 are important and shall not change. - #[runtime::pallet_index(12)] - pub type CollatorSelection = pallet_collator_selection; #[runtime::pallet_index(13)] - pub type Session = pallet_session; + pub type CollatorSelection = pallet_collator_selection; #[runtime::pallet_index(14)] - pub type Aura = pallet_aura; + pub type Session = pallet_session; #[runtime::pallet_index(15)] + pub type Aura = pallet_aura; + #[runtime::pallet_index(16)] pub type AuraExt = cumulus_pallet_aura_ext; // XCM helpers. - #[runtime::pallet_index(16)] - pub type XcmpQueue = cumulus_pallet_xcmp_queue; #[runtime::pallet_index(17)] - pub type PolkadotXcm = pallet_xcm; + pub type XcmpQueue = cumulus_pallet_xcmp_queue; #[runtime::pallet_index(18)] - pub type CumulusXcm = cumulus_pallet_xcm; + pub type PolkadotXcm = pallet_xcm; #[runtime::pallet_index(19)] + pub type CumulusXcm = cumulus_pallet_xcm; + #[runtime::pallet_index(20)] pub type MessageQueue = pallet_message_queue; } @@ -590,12 +592,14 @@ type EventRecord = frame_system::EventRecord< ::Hash, >; -// Prints debug output of the `contracts` pallet to stdout if the node is -// started with `-lruntime::contracts=debug`. +// Prints debug output of the `revive` pallet to stdout if the node is +// started with `-lruntime::revive=trace` or `-lruntime::contracts=debug`. const CONTRACTS_DEBUG_OUTPUT: pallet_contracts::DebugInfo = pallet_contracts::DebugInfo::UnsafeDebug; const CONTRACTS_EVENTS: pallet_contracts::CollectEvents = pallet_contracts::CollectEvents::UnsafeCollect; +const REVIVE_DEBUG_OUTPUT: pallet_revive::DebugInfo = pallet_revive::DebugInfo::UnsafeDebug; +const REVIVE_EVENTS: pallet_revive::CollectEvents = pallet_revive::CollectEvents::UnsafeCollect; impl_runtime_apis! { impl sp_consensus_aura::AuraApi for Runtime { @@ -819,6 +823,75 @@ impl_runtime_apis! { } } + impl pallet_revive::ReviveApi for Runtime + { + fn call( + origin: AccountId, + dest: AccountId, + value: Balance, + gas_limit: Option, + storage_deposit_limit: Option, + input_data: Vec, + ) -> pallet_revive::ContractExecResult { + 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, + REVIVE_DEBUG_OUTPUT, + REVIVE_EVENTS, + ) + } + + fn instantiate( + origin: AccountId, + value: Balance, + gas_limit: Option, + storage_deposit_limit: Option, + code: pallet_revive::Code, + data: Vec, + salt: Vec, + ) -> pallet_revive::ContractInstantiateResult + { + 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, + REVIVE_DEBUG_OUTPUT, + REVIVE_EVENTS, + ) + } + + fn upload_code( + origin: AccountId, + code: Vec, + storage_deposit_limit: Option, + ) -> pallet_revive::CodeUploadResult + { + Revive::bare_upload_code( + RuntimeOrigin::signed(origin), + code, + storage_deposit_limit.unwrap_or(u128::MAX), + ) + } + + fn get_storage( + address: AccountId, + key: Vec, + ) -> pallet_revive::GetStorageResult { + Revive::get_storage( + address, + key + ) + } + } + impl pallet_contracts::ContractsApi for Runtime { @@ -886,6 +959,7 @@ impl_runtime_apis! { } } + impl sp_genesis_builder::GenesisBuilder for Runtime { fn build_state(config: Vec) -> sp_genesis_builder::Result { build_state::(config) diff --git a/parachain-runtime/src/revive_config.rs b/parachain-runtime/src/revive_config.rs new file mode 120000 index 0000000..41b2903 --- /dev/null +++ b/parachain-runtime/src/revive_config.rs @@ -0,0 +1 @@ +../../runtime/src/revive_config.rs \ No newline at end of file diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index 319354d..9bce6ef 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -3,7 +3,7 @@ name = "contracts-node-runtime" version.workspace = true authors.workspace = true edition.workspace = true -description = "Runtime configured for smart contracts via `pallet-contracts`." +description = "Runtime configured for smart contracts via `pallet-contracts` and `pallet-revive`." license.workspace = true homepage.workspace = true repository.workspace = true @@ -13,9 +13,7 @@ build = "build.rs" targets = ["x86_64-unknown-linux-gnu"] [dependencies] -codec = { features = [ - "derive", -], workspace = true } +codec = { features = ["derive"], workspace = true } scale-info = { workspace = true } frame-executive = { workspace = true } @@ -47,84 +45,86 @@ sp-version = { workspace = true } # Polkadot polkadot-runtime-common = { workspace = true } -# extra deps for setting up pallet-contracts +# extra deps for setting up pallet-contracts and pallet-revive pallet-assets = { workspace = true } -pallet-authorship = { workspace = true } -pallet-contracts = { workspace = true } +pallet-authorship = { workspace = true } pallet-insecure-randomness-collective-flip = { workspace = true } +pallet-revive = { workspace = true } +pallet-contracts = { workspace = true } pallet-utility = { workspace = true } # Used for runtime benchmarking frame-benchmarking = { workspace = true, optional = true } -frame-system-benchmarking = { workspace = true , optional = true} +frame-system-benchmarking = { workspace = true, optional = true } [build-dependencies] substrate-wasm-builder = { workspace = true, optional = true } [features] -default = [ "std" ] +default = ["std"] std = [ - "codec/std", - "frame-benchmarking?/std", - "frame-executive/std", - "frame-support/std", - "frame-system-benchmarking?/std", - "frame-system-rpc-runtime-api/std", - "frame-system/std", - "frame-try-runtime?/std", - "pallet-assets/std", - "pallet-aura/std", - "pallet-authorship/std", - "pallet-balances/std", - "pallet-contracts/std", - "pallet-grandpa/std", - "pallet-insecure-randomness-collective-flip/std", - "pallet-sudo/std", - "pallet-timestamp/std", - "pallet-transaction-payment-rpc-runtime-api/std", - "pallet-transaction-payment/std", - "scale-info/std", - "sp-api/std", - "sp-block-builder/std", - "sp-consensus-aura/std", - "sp-consensus-grandpa/std", - "sp-core/std", - "sp-genesis-builder/std", - "sp-inherents/std", - "sp-offchain/std", - "sp-runtime/std", - "sp-session/std", - "sp-storage/std", - "sp-transaction-pool/std", - "sp-version/std", - "polkadot-runtime-common/std", - "substrate-wasm-builder", + "codec/std", + "frame-benchmarking?/std", + "frame-executive/std", + "frame-support/std", + "frame-system-benchmarking?/std", + "frame-system-rpc-runtime-api/std", + "frame-system/std", + "frame-try-runtime?/std", + "pallet-assets/std", + "pallet-aura/std", + "pallet-authorship/std", + "pallet-balances/std", + "pallet-grandpa/std", + "pallet-insecure-randomness-collective-flip/std", + "pallet-revive/std", + "pallet-contracts/std", + "pallet-sudo/std", + "pallet-timestamp/std", + "pallet-transaction-payment-rpc-runtime-api/std", + "pallet-transaction-payment/std", + "scale-info/std", + "sp-api/std", + "sp-block-builder/std", + "sp-consensus-aura/std", + "sp-consensus-grandpa/std", + "sp-core/std", + "sp-genesis-builder/std", + "sp-inherents/std", + "sp-offchain/std", + "sp-runtime/std", + "sp-session/std", + "sp-storage/std", + "sp-transaction-pool/std", + "sp-version/std", + "polkadot-runtime-common/std", + "substrate-wasm-builder", ] runtime-benchmarks = [ - "frame-benchmarking/runtime-benchmarks", - "frame-support/runtime-benchmarks", - "frame-system-benchmarking/runtime-benchmarks", - "frame-system/runtime-benchmarks", - "pallet-balances/runtime-benchmarks", - "pallet-grandpa/runtime-benchmarks", - "pallet-sudo/runtime-benchmarks", - "pallet-timestamp/runtime-benchmarks", - "pallet-contracts/runtime-benchmarks", - "pallet-assets/runtime-benchmarks", - "sp-runtime/runtime-benchmarks", + "frame-benchmarking/runtime-benchmarks", + "frame-support/runtime-benchmarks", + "frame-system-benchmarking/runtime-benchmarks", + "frame-system/runtime-benchmarks", + "pallet-balances/runtime-benchmarks", + "pallet-grandpa/runtime-benchmarks", + "pallet-sudo/runtime-benchmarks", + "pallet-timestamp/runtime-benchmarks", + "pallet-assets/runtime-benchmarks", + "sp-runtime/runtime-benchmarks", ] try-runtime = [ - "frame-executive/try-runtime", - "frame-support/try-runtime", - "frame-system/try-runtime", - "frame-try-runtime/try-runtime", - "pallet-aura/try-runtime", - "pallet-balances/try-runtime", - "pallet-grandpa/try-runtime", - "pallet-sudo/try-runtime", - "pallet-timestamp/try-runtime", - "pallet-transaction-payment/try-runtime", - "pallet-contracts/try-runtime", - "pallet-assets/try-runtime", - "sp-runtime/try-runtime", + "frame-executive/try-runtime", + "frame-support/try-runtime", + "frame-system/try-runtime", + "frame-try-runtime/try-runtime", + "pallet-assets/try-runtime", + "pallet-aura/try-runtime", + "pallet-balances/try-runtime", + "pallet-grandpa/try-runtime", + "pallet-sudo/try-runtime", + "pallet-timestamp/try-runtime", + "pallet-transaction-payment/try-runtime", + "pallet-revive/try-runtime", + "pallet-contracts/try-runtime", + "sp-runtime/try-runtime", ] diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 6d6d774..ff47bdd 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -8,6 +8,7 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); mod assets_config; mod contracts_config; +mod revive_config; extern crate alloc; use alloc::vec::Vec; @@ -127,12 +128,14 @@ const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(10); const MAXIMUM_BLOCK_WEIGHT: Weight = Weight::from_parts(WEIGHT_REF_TIME_PER_SECOND.saturating_mul(2), u64::MAX); -// Prints debug output of the `contracts` pallet to stdout if the node is -// started with `-lruntime::contracts=debug`. +// Prints debug output of the `revive` pallet to stdout if the node is +// started with `-lruntime::revive=trace` or `-lruntime::contracts=debug`. const CONTRACTS_DEBUG_OUTPUT: pallet_contracts::DebugInfo = pallet_contracts::DebugInfo::UnsafeDebug; const CONTRACTS_EVENTS: pallet_contracts::CollectEvents = pallet_contracts::CollectEvents::UnsafeCollect; +const REVIVE_DEBUG_OUTPUT: pallet_revive::DebugInfo = pallet_revive::DebugInfo::UnsafeDebug; +const REVIVE_EVENTS: pallet_revive::CollectEvents = pallet_revive::CollectEvents::UnsafeCollect; // Unit = the base number of indivisible units for balances const MILLIUNIT: Balance = 1_000_000_000; @@ -302,6 +305,8 @@ mod runtime { #[runtime::pallet_index(8)] pub type Contracts = pallet_contracts; #[runtime::pallet_index(9)] + pub type Revive = pallet_revive; + #[runtime::pallet_index(10)] pub type Assets = pallet_assets; } @@ -334,7 +339,6 @@ pub type Executive = frame_executive::Executive< frame_system::ChainContext, Runtime, AllPalletsWithSystem, - pallet_contracts::Migration, >; type EventRecord = frame_system::EventRecord< @@ -534,6 +538,75 @@ impl_runtime_apis! { } } + impl pallet_revive::ReviveApi for Runtime + { + fn call( + origin: AccountId, + dest: AccountId, + value: Balance, + gas_limit: Option, + storage_deposit_limit: Option, + input_data: Vec, + ) -> pallet_revive::ContractExecResult { + 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, + REVIVE_DEBUG_OUTPUT, + REVIVE_EVENTS, + ) + } + + fn instantiate( + origin: AccountId, + value: Balance, + gas_limit: Option, + storage_deposit_limit: Option, + code: pallet_revive::Code, + data: Vec, + salt: Vec, + ) -> pallet_revive::ContractInstantiateResult + { + 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, + REVIVE_DEBUG_OUTPUT, + REVIVE_EVENTS, + ) + } + + fn upload_code( + origin: AccountId, + code: Vec, + storage_deposit_limit: Option, + ) -> pallet_revive::CodeUploadResult + { + Revive::bare_upload_code( + RuntimeOrigin::signed(origin), + code, + storage_deposit_limit.unwrap_or(u128::MAX), + ) + } + + fn get_storage( + address: AccountId, + key: Vec, + ) -> pallet_revive::GetStorageResult { + Revive::get_storage( + address, + key + ) + } + } + impl sp_genesis_builder::GenesisBuilder for Runtime { fn build_state(config: Vec) -> sp_genesis_builder::Result { build_state::(config) diff --git a/runtime/src/revive_config.rs b/runtime/src/revive_config.rs new file mode 100644 index 0000000..1bbd899 --- /dev/null +++ b/runtime/src/revive_config.rs @@ -0,0 +1,67 @@ +use crate::{ + Balance, Balances, BalancesCall, Perbill, Runtime, RuntimeCall, RuntimeEvent, + RuntimeHoldReason, Timestamp, +}; +use frame_support::{ + parameter_types, + traits::{ConstBool, ConstU32}, +}; +use frame_system::EnsureSigned; + +pub enum AllowBalancesCall {} + +impl frame_support::traits::Contains for AllowBalancesCall { + fn contains(call: &RuntimeCall) -> bool { + matches!(call, RuntimeCall::Balances(BalancesCall::transfer_allow_death { .. })) + } +} + +// Unit = the base number of indivisible units for balances +const UNIT: Balance = 1_000_000_000_000; +const MILLIUNIT: Balance = 1_000_000_000; + +const fn deposit(items: u32, bytes: u32) -> Balance { + (items as Balance * UNIT + (bytes as Balance) * (5 * MILLIUNIT / 100)) / 10 +} + +parameter_types! { + pub const DepositPerItem: Balance = deposit(1, 0); + pub const DepositPerByte: Balance = deposit(0, 1); + pub const DefaultDepositLimit: Balance = deposit(1024, 1024 * 1024); + pub const CodeHashLockupDepositPercent: Perbill = Perbill::from_percent(0); + pub const MaxDelegateDependencies: u32 = 32; +} + +impl pallet_revive::Config for Runtime { + type Time = Timestamp; + type Currency = Balances; + type RuntimeEvent = RuntimeEvent; + type RuntimeCall = RuntimeCall; + /// The safest default is to allow no calls at all. + /// + /// Runtimes should whitelist dispatchables that are allowed to be called from contracts + /// and make sure they are stable. Dispatchables exposed to contracts are not allowed to + /// change because that would break already deployed contracts. The `RuntimeCall` structure + /// itself is not allowed to change the indices of existing pallets, too. + type CallFilter = AllowBalancesCall; + type DepositPerItem = DepositPerItem; + type DepositPerByte = DepositPerByte; + type WeightPrice = pallet_transaction_payment::Pallet; + type WeightInfo = pallet_revive::weights::SubstrateWeight; + type ChainExtension = (); + type AddressGenerator = pallet_revive::DefaultAddressGenerator; + type MaxCodeLen = ConstU32<{ 123 * 1024 }>; + type RuntimeMemory = ConstU32<{ 128 * 1024 * 1024 }>; + type PVFMemory = ConstU32<{ 512 * 1024 * 1024 }>; + type UnsafeUnstableInterface = ConstBool; + type CodeHashLockupDepositPercent = CodeHashLockupDepositPercent; + type RuntimeHoldReason = RuntimeHoldReason; + type Debug = (); + type Migrations = (); + #[cfg(feature = "parachain")] + type Xcm = pallet_xcm::Pallet; + #[cfg(not(feature = "parachain"))] + type Xcm = (); + type UploadOrigin = EnsureSigned; + type InstantiateOrigin = EnsureSigned; +}