diff --git a/Cargo.lock b/Cargo.lock index ae208c8153..1bdf69ae30 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1056,7 +1056,7 @@ checksum = "9b34d609dfbaf33d6889b2b7106d3ca345eacad44200913df5ba02bfd31d2ba9" [[package]] name = "assets-common" version = "0.22.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "cumulus-primitives-core", "ethereum-standards", @@ -1435,7 +1435,7 @@ checksum = "55248b47b0caf0546f7988906588779981c43bb1bc9d0c44087278f80cdb44ba" [[package]] name = "binary-merkle-tree" version = "16.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "hash-db", "log", @@ -1704,7 +1704,7 @@ dependencies = [ [[package]] name = "bp-header-chain" version = "0.21.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "bp-runtime", "finality-grandpa", @@ -1721,7 +1721,7 @@ dependencies = [ [[package]] name = "bp-messages" version = "0.21.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "bp-header-chain", "bp-runtime", @@ -1737,7 +1737,7 @@ dependencies = [ [[package]] name = "bp-parachains" version = "0.21.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "bp-header-chain", "bp-polkadot-core", @@ -1754,7 +1754,7 @@ dependencies = [ [[package]] name = "bp-polkadot-core" version = "0.21.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "bp-messages", "bp-runtime", @@ -1770,7 +1770,7 @@ dependencies = [ [[package]] name = "bp-relayers" version = "0.21.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "bp-header-chain", "bp-messages", @@ -1788,7 +1788,7 @@ dependencies = [ [[package]] name = "bp-runtime" version = "0.21.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-support", "frame-system", @@ -1811,7 +1811,7 @@ dependencies = [ [[package]] name = "bp-test-utils" version = "0.21.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "bp-header-chain", "bp-parachains", @@ -1831,7 +1831,7 @@ dependencies = [ [[package]] name = "bp-xcm-bridge-hub" version = "0.7.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "bp-messages", "bp-runtime", @@ -1848,7 +1848,7 @@ dependencies = [ [[package]] name = "bp-xcm-bridge-hub-router" version = "0.18.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "parity-scale-codec", "scale-info", @@ -1860,7 +1860,7 @@ dependencies = [ [[package]] name = "bridge-hub-common" version = "0.14.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "cumulus-primitives-core", "frame-support", @@ -1879,7 +1879,7 @@ dependencies = [ [[package]] name = "bridge-runtime-common" version = "0.22.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "bp-header-chain", "bp-messages", @@ -2742,7 +2742,7 @@ dependencies = [ [[package]] name = "cumulus-client-bootnodes" version = "0.2.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "array-bytes 6.2.3", "async-channel 1.9.0", @@ -2768,7 +2768,7 @@ dependencies = [ [[package]] name = "cumulus-client-cli" version = "0.24.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "clap", "parity-scale-codec", @@ -2785,7 +2785,7 @@ dependencies = [ [[package]] name = "cumulus-client-collator" version = "0.24.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "cumulus-client-consensus-common", "cumulus-client-network", @@ -2808,7 +2808,7 @@ dependencies = [ [[package]] name = "cumulus-client-consensus-aura" version = "0.24.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "async-trait", "cumulus-client-collator", @@ -2855,7 +2855,7 @@ dependencies = [ [[package]] name = "cumulus-client-consensus-common" version = "0.24.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "async-trait", "cumulus-client-pov-recovery", @@ -2887,7 +2887,7 @@ dependencies = [ [[package]] name = "cumulus-client-consensus-proposer" version = "0.20.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "anyhow", "async-trait", @@ -2902,7 +2902,7 @@ dependencies = [ [[package]] name = "cumulus-client-consensus-relay-chain" version = "0.24.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "async-trait", "cumulus-client-consensus-common", @@ -2925,7 +2925,7 @@ dependencies = [ [[package]] name = "cumulus-client-network" version = "0.24.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "async-trait", "cumulus-relay-chain-interface", @@ -2952,7 +2952,7 @@ dependencies = [ [[package]] name = "cumulus-client-parachain-inherent" version = "0.18.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "async-trait", "cumulus-primitives-core", @@ -2962,7 +2962,7 @@ dependencies = [ "parity-scale-codec", "sc-client-api", "sc-consensus-babe", - "sp-crypto-hashing 0.1.0 (git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7)", + "sp-crypto-hashing 0.1.0 (git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8)", "sp-inherents", "sp-runtime", "sp-state-machine", @@ -2973,7 +2973,7 @@ dependencies = [ [[package]] name = "cumulus-client-pov-recovery" version = "0.24.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "async-trait", "cumulus-primitives-core", @@ -3001,7 +3001,7 @@ dependencies = [ [[package]] name = "cumulus-client-service" version = "0.25.1" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "async-channel 1.9.0", "cumulus-client-cli", @@ -3041,7 +3041,7 @@ dependencies = [ [[package]] name = "cumulus-pallet-aura-ext" version = "0.21.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "cumulus-pallet-parachain-system", "frame-support", @@ -3058,7 +3058,7 @@ dependencies = [ [[package]] name = "cumulus-pallet-dmp-queue" version = "0.21.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "cumulus-primitives-core", "frame-benchmarking", @@ -3075,7 +3075,7 @@ dependencies = [ [[package]] name = "cumulus-pallet-parachain-system" version = "0.21.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "bytes", "cumulus-pallet-parachain-system-proc-macro", @@ -3112,7 +3112,7 @@ dependencies = [ [[package]] name = "cumulus-pallet-parachain-system-proc-macro" version = "0.6.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "proc-macro-crate 3.4.0", "proc-macro2", @@ -3123,7 +3123,7 @@ dependencies = [ [[package]] name = "cumulus-pallet-session-benchmarking" version = "22.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-benchmarking", "frame-support", @@ -3136,7 +3136,7 @@ dependencies = [ [[package]] name = "cumulus-pallet-solo-to-para" version = "0.21.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "cumulus-pallet-parachain-system", "frame-support", @@ -3151,7 +3151,7 @@ dependencies = [ [[package]] name = "cumulus-pallet-weight-reclaim" version = "0.3.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "cumulus-primitives-storage-weight-reclaim", "derive-where", @@ -3170,7 +3170,7 @@ dependencies = [ [[package]] name = "cumulus-pallet-xcm" version = "0.20.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "cumulus-primitives-core", "frame-support", @@ -3185,7 +3185,7 @@ dependencies = [ [[package]] name = "cumulus-pallet-xcmp-queue" version = "0.21.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "approx", "bounded-collections 0.2.4", @@ -3210,7 +3210,7 @@ dependencies = [ [[package]] name = "cumulus-ping" version = "0.21.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "cumulus-pallet-xcm", "cumulus-primitives-core", @@ -3225,7 +3225,7 @@ dependencies = [ [[package]] name = "cumulus-primitives-aura" version = "0.18.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "sp-api", "sp-consensus-aura", @@ -3234,7 +3234,7 @@ dependencies = [ [[package]] name = "cumulus-primitives-core" version = "0.19.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "parity-scale-codec", "polkadot-core-primitives", @@ -3251,7 +3251,7 @@ dependencies = [ [[package]] name = "cumulus-primitives-parachain-inherent" version = "0.19.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "async-trait", "cumulus-primitives-core", @@ -3265,7 +3265,7 @@ dependencies = [ [[package]] name = "cumulus-primitives-proof-size-hostfunction" version = "0.13.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "sp-externalities", "sp-runtime-interface", @@ -3275,7 +3275,7 @@ dependencies = [ [[package]] name = "cumulus-primitives-storage-weight-reclaim" version = "12.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "cumulus-primitives-core", "cumulus-primitives-proof-size-hostfunction", @@ -3292,7 +3292,7 @@ dependencies = [ [[package]] name = "cumulus-primitives-utility" version = "0.21.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "cumulus-primitives-core", "frame-support", @@ -3309,7 +3309,7 @@ dependencies = [ [[package]] name = "cumulus-relay-chain-inprocess-interface" version = "0.25.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "async-channel 1.9.0", "async-trait", @@ -3337,7 +3337,7 @@ dependencies = [ [[package]] name = "cumulus-relay-chain-interface" version = "0.24.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "async-trait", "cumulus-primitives-core", @@ -3357,7 +3357,7 @@ dependencies = [ [[package]] name = "cumulus-relay-chain-minimal-node" version = "0.25.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "array-bytes 6.2.3", "async-channel 1.9.0", @@ -3393,7 +3393,7 @@ dependencies = [ [[package]] name = "cumulus-relay-chain-rpc-interface" version = "0.24.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "async-trait", "cumulus-primitives-core", @@ -3434,7 +3434,7 @@ dependencies = [ [[package]] name = "cumulus-relay-chain-streams" version = "0.2.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "cumulus-relay-chain-interface", "futures", @@ -3448,7 +3448,7 @@ dependencies = [ [[package]] name = "cumulus-test-relay-sproof-builder" version = "0.20.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "cumulus-primitives-core", "parity-scale-codec", @@ -4230,7 +4230,7 @@ dependencies = [ [[package]] name = "ethereum-standards" version = "0.1.1" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "alloy-core", ] @@ -4447,7 +4447,7 @@ dependencies = [ [[package]] name = "fc-api" version = "1.0.0-dev" -source = "git+https://github.com/opentensor/frontier?rev=d553a11551333c2457d9e64d6d912e2210a4ca26#d553a11551333c2457d9e64d6d912e2210a4ca26" +source = "git+https://github.com/opentensor/frontier?rev=59b4442c222bfaecd37acd81071cfa6fb12bffc6#59b4442c222bfaecd37acd81071cfa6fb12bffc6" dependencies = [ "async-trait", "fp-storage", @@ -4459,7 +4459,7 @@ dependencies = [ [[package]] name = "fc-aura" version = "1.0.0-dev" -source = "git+https://github.com/opentensor/frontier?rev=d553a11551333c2457d9e64d6d912e2210a4ca26#d553a11551333c2457d9e64d6d912e2210a4ca26" +source = "git+https://github.com/opentensor/frontier?rev=59b4442c222bfaecd37acd81071cfa6fb12bffc6#59b4442c222bfaecd37acd81071cfa6fb12bffc6" dependencies = [ "fc-rpc", "fp-storage", @@ -4475,7 +4475,7 @@ dependencies = [ [[package]] name = "fc-babe" version = "1.0.0-dev" -source = "git+https://github.com/opentensor/frontier?rev=d553a11551333c2457d9e64d6d912e2210a4ca26#d553a11551333c2457d9e64d6d912e2210a4ca26" +source = "git+https://github.com/opentensor/frontier?rev=59b4442c222bfaecd37acd81071cfa6fb12bffc6#59b4442c222bfaecd37acd81071cfa6fb12bffc6" dependencies = [ "fc-rpc", "sc-client-api", @@ -4491,7 +4491,7 @@ dependencies = [ [[package]] name = "fc-consensus" version = "2.0.0-dev" -source = "git+https://github.com/opentensor/frontier?rev=d553a11551333c2457d9e64d6d912e2210a4ca26#d553a11551333c2457d9e64d6d912e2210a4ca26" +source = "git+https://github.com/opentensor/frontier?rev=59b4442c222bfaecd37acd81071cfa6fb12bffc6#59b4442c222bfaecd37acd81071cfa6fb12bffc6" dependencies = [ "async-trait", "fp-consensus", @@ -4507,7 +4507,7 @@ dependencies = [ [[package]] name = "fc-db" version = "2.0.0-dev" -source = "git+https://github.com/opentensor/frontier?rev=d553a11551333c2457d9e64d6d912e2210a4ca26#d553a11551333c2457d9e64d6d912e2210a4ca26" +source = "git+https://github.com/opentensor/frontier?rev=59b4442c222bfaecd37acd81071cfa6fb12bffc6#59b4442c222bfaecd37acd81071cfa6fb12bffc6" dependencies = [ "async-trait", "ethereum", @@ -4537,7 +4537,7 @@ dependencies = [ [[package]] name = "fc-mapping-sync" version = "2.0.0-dev" -source = "git+https://github.com/opentensor/frontier?rev=d553a11551333c2457d9e64d6d912e2210a4ca26#d553a11551333c2457d9e64d6d912e2210a4ca26" +source = "git+https://github.com/opentensor/frontier?rev=59b4442c222bfaecd37acd81071cfa6fb12bffc6#59b4442c222bfaecd37acd81071cfa6fb12bffc6" dependencies = [ "fc-db", "fc-storage", @@ -4560,7 +4560,7 @@ dependencies = [ [[package]] name = "fc-rpc" version = "2.0.0-dev" -source = "git+https://github.com/opentensor/frontier?rev=d553a11551333c2457d9e64d6d912e2210a4ca26#d553a11551333c2457d9e64d6d912e2210a4ca26" +source = "git+https://github.com/opentensor/frontier?rev=59b4442c222bfaecd37acd81071cfa6fb12bffc6#59b4442c222bfaecd37acd81071cfa6fb12bffc6" dependencies = [ "ethereum", "ethereum-types", @@ -4611,7 +4611,7 @@ dependencies = [ [[package]] name = "fc-rpc-core" version = "1.1.0-dev" -source = "git+https://github.com/opentensor/frontier?rev=d553a11551333c2457d9e64d6d912e2210a4ca26#d553a11551333c2457d9e64d6d912e2210a4ca26" +source = "git+https://github.com/opentensor/frontier?rev=59b4442c222bfaecd37acd81071cfa6fb12bffc6#59b4442c222bfaecd37acd81071cfa6fb12bffc6" dependencies = [ "ethereum", "ethereum-types", @@ -4620,13 +4620,13 @@ dependencies = [ "rustc-hex", "serde", "serde_json", - "sp-crypto-hashing 0.1.0 (git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7)", + "sp-crypto-hashing 0.1.0 (git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8)", ] [[package]] name = "fc-storage" version = "1.0.0-dev" -source = "git+https://github.com/opentensor/frontier?rev=d553a11551333c2457d9e64d6d912e2210a4ca26#d553a11551333c2457d9e64d6d912e2210a4ca26" +source = "git+https://github.com/opentensor/frontier?rev=59b4442c222bfaecd37acd81071cfa6fb12bffc6#59b4442c222bfaecd37acd81071cfa6fb12bffc6" dependencies = [ "ethereum", "ethereum-types", @@ -4791,7 +4791,7 @@ checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" [[package]] name = "fork-tree" version = "13.0.1" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "parity-scale-codec", ] @@ -4818,7 +4818,7 @@ dependencies = [ [[package]] name = "fp-account" version = "1.0.0-dev" -source = "git+https://github.com/opentensor/frontier?rev=d553a11551333c2457d9e64d6d912e2210a4ca26#d553a11551333c2457d9e64d6d912e2210a4ca26" +source = "git+https://github.com/opentensor/frontier?rev=59b4442c222bfaecd37acd81071cfa6fb12bffc6#59b4442c222bfaecd37acd81071cfa6fb12bffc6" dependencies = [ "hex", "impl-serde", @@ -4836,7 +4836,7 @@ dependencies = [ [[package]] name = "fp-consensus" version = "2.0.0-dev" -source = "git+https://github.com/opentensor/frontier?rev=d553a11551333c2457d9e64d6d912e2210a4ca26#d553a11551333c2457d9e64d6d912e2210a4ca26" +source = "git+https://github.com/opentensor/frontier?rev=59b4442c222bfaecd37acd81071cfa6fb12bffc6#59b4442c222bfaecd37acd81071cfa6fb12bffc6" dependencies = [ "ethereum", "parity-scale-codec", @@ -4847,7 +4847,7 @@ dependencies = [ [[package]] name = "fp-ethereum" version = "1.0.0-dev" -source = "git+https://github.com/opentensor/frontier?rev=d553a11551333c2457d9e64d6d912e2210a4ca26#d553a11551333c2457d9e64d6d912e2210a4ca26" +source = "git+https://github.com/opentensor/frontier?rev=59b4442c222bfaecd37acd81071cfa6fb12bffc6#59b4442c222bfaecd37acd81071cfa6fb12bffc6" dependencies = [ "ethereum", "ethereum-types", @@ -4859,7 +4859,7 @@ dependencies = [ [[package]] name = "fp-evm" version = "3.0.0-dev" -source = "git+https://github.com/opentensor/frontier?rev=d553a11551333c2457d9e64d6d912e2210a4ca26#d553a11551333c2457d9e64d6d912e2210a4ca26" +source = "git+https://github.com/opentensor/frontier?rev=59b4442c222bfaecd37acd81071cfa6fb12bffc6#59b4442c222bfaecd37acd81071cfa6fb12bffc6" dependencies = [ "environmental", "evm", @@ -4875,7 +4875,7 @@ dependencies = [ [[package]] name = "fp-rpc" version = "3.0.0-dev" -source = "git+https://github.com/opentensor/frontier?rev=d553a11551333c2457d9e64d6d912e2210a4ca26#d553a11551333c2457d9e64d6d912e2210a4ca26" +source = "git+https://github.com/opentensor/frontier?rev=59b4442c222bfaecd37acd81071cfa6fb12bffc6#59b4442c222bfaecd37acd81071cfa6fb12bffc6" dependencies = [ "ethereum", "ethereum-types", @@ -4891,7 +4891,7 @@ dependencies = [ [[package]] name = "fp-self-contained" version = "1.0.0-dev" -source = "git+https://github.com/opentensor/frontier?rev=d553a11551333c2457d9e64d6d912e2210a4ca26#d553a11551333c2457d9e64d6d912e2210a4ca26" +source = "git+https://github.com/opentensor/frontier?rev=59b4442c222bfaecd37acd81071cfa6fb12bffc6#59b4442c222bfaecd37acd81071cfa6fb12bffc6" dependencies = [ "frame-support", "parity-scale-codec", @@ -4903,7 +4903,7 @@ dependencies = [ [[package]] name = "fp-storage" version = "2.0.0" -source = "git+https://github.com/opentensor/frontier?rev=d553a11551333c2457d9e64d6d912e2210a4ca26#d553a11551333c2457d9e64d6d912e2210a4ca26" +source = "git+https://github.com/opentensor/frontier?rev=59b4442c222bfaecd37acd81071cfa6fb12bffc6#59b4442c222bfaecd37acd81071cfa6fb12bffc6" dependencies = [ "parity-scale-codec", "serde", @@ -4918,7 +4918,7 @@ checksum = "28dd6caf6059519a65843af8fe2a3ae298b14b80179855aeb4adc2c1934ee619" [[package]] name = "frame-benchmarking" version = "41.0.1" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-support", "frame-support-procedural", @@ -4942,7 +4942,7 @@ dependencies = [ [[package]] name = "frame-benchmarking-cli" version = "49.1.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "Inflector", "array-bytes 6.2.3", @@ -5007,7 +5007,7 @@ dependencies = [ [[package]] name = "frame-benchmarking-pallet-pov" version = "31.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-benchmarking", "frame-support", @@ -5035,7 +5035,7 @@ dependencies = [ [[package]] name = "frame-election-provider-solution-type" version = "16.1.1" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "proc-macro-crate 3.4.0", "proc-macro2", @@ -5046,7 +5046,7 @@ dependencies = [ [[package]] name = "frame-election-provider-support" version = "41.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-election-provider-solution-type", "frame-support", @@ -5063,7 +5063,7 @@ dependencies = [ [[package]] name = "frame-executive" version = "41.0.1" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "aquamarine", "frame-support", @@ -5116,7 +5116,7 @@ dependencies = [ [[package]] name = "frame-metadata-hash-extension" version = "0.9.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "array-bytes 6.2.3", "const-hex", @@ -5132,7 +5132,7 @@ dependencies = [ [[package]] name = "frame-storage-access-test-runtime" version = "0.2.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "cumulus-pallet-parachain-system", "parity-scale-codec", @@ -5146,7 +5146,7 @@ dependencies = [ [[package]] name = "frame-support" version = "41.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "aquamarine", "array-bytes 6.2.3", @@ -5187,31 +5187,31 @@ dependencies = [ [[package]] name = "frame-support-procedural" version = "34.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "Inflector", "cfg-expr", "derive-syn-parse", "docify", "expander", - "frame-support-procedural-tools 13.0.1", + "frame-support-procedural-core", + "frame-support-procedural-tools", "itertools 0.11.0", "macro_magic", "proc-macro-warning", "proc-macro2", "quote", - "sp-crypto-hashing 0.1.0 (git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7)", + "sp-crypto-hashing 0.1.0 (git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8)", "syn 2.0.106", ] [[package]] -name = "frame-support-procedural-tools" -version = "10.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3363df38464c47a73eb521a4f648bfcc7537a82d70347ef8af3f73b6d019e910" +name = "frame-support-procedural-core" +version = "34.0.0" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ - "frame-support-procedural-tools-derive 11.0.0", - "proc-macro-crate 3.4.0", + "cfg-expr", + "frame-support-procedural-tools", "proc-macro2", "quote", "syn 2.0.106", @@ -5220,30 +5220,19 @@ dependencies = [ [[package]] name = "frame-support-procedural-tools" version = "13.0.1" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ - "frame-support-procedural-tools-derive 12.0.0", + "frame-support-procedural-tools-derive", "proc-macro-crate 3.4.0", "proc-macro2", "quote", "syn 2.0.106", ] -[[package]] -name = "frame-support-procedural-tools-derive" -version = "11.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68672b9ec6fe72d259d3879dc212c5e42e977588cdac830c76f54d9f492aeb58" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.106", -] - [[package]] name = "frame-support-procedural-tools-derive" version = "12.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "proc-macro2", "quote", @@ -5253,7 +5242,7 @@ dependencies = [ [[package]] name = "frame-system" version = "41.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "cfg-if", "docify", @@ -5272,7 +5261,7 @@ dependencies = [ [[package]] name = "frame-system-benchmarking" version = "41.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-benchmarking", "frame-support", @@ -5286,7 +5275,7 @@ dependencies = [ [[package]] name = "frame-system-rpc-runtime-api" version = "37.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "docify", "parity-scale-codec", @@ -5296,7 +5285,7 @@ dependencies = [ [[package]] name = "frame-try-runtime" version = "0.47.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-support", "parity-scale-codec", @@ -7906,7 +7895,7 @@ dependencies = [ [[package]] name = "mmr-gadget" version = "46.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "futures", "log", @@ -7925,7 +7914,7 @@ dependencies = [ [[package]] name = "mmr-rpc" version = "41.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "jsonrpsee", "parity-scale-codec", @@ -8422,6 +8411,7 @@ dependencies = [ "pallet-nomination-pools-runtime-api", "pallet-offences", "pallet-preimage", + "pallet-proxy", "pallet-registry", "pallet-safe-mode", "pallet-scheduler", @@ -8432,14 +8422,13 @@ dependencies = [ "pallet-staking-reward-fn", "pallet-staking-runtime-api", "pallet-subtensor", - "pallet-subtensor-proxy", "pallet-subtensor-swap", "pallet-subtensor-swap-runtime-api", - "pallet-subtensor-utility", "pallet-sudo", "pallet-timestamp", "pallet-transaction-payment", "pallet-transaction-payment-rpc-runtime-api", + "pallet-utility", "parity-scale-codec", "polkadot-runtime-common", "precompile-utils", @@ -8874,7 +8863,7 @@ dependencies = [ [[package]] name = "pallet-alliance" version = "40.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "array-bytes 6.2.3", "frame-benchmarking", @@ -8886,7 +8875,7 @@ dependencies = [ "parity-scale-codec", "scale-info", "sp-core", - "sp-crypto-hashing 0.1.0 (git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7)", + "sp-crypto-hashing 0.1.0 (git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8)", "sp-io", "sp-runtime", ] @@ -8910,7 +8899,7 @@ dependencies = [ [[package]] name = "pallet-asset-conversion" version = "23.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-benchmarking", "frame-support", @@ -8928,7 +8917,7 @@ dependencies = [ [[package]] name = "pallet-asset-conversion-ops" version = "0.9.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-benchmarking", "frame-support", @@ -8946,7 +8935,7 @@ dependencies = [ [[package]] name = "pallet-asset-conversion-tx-payment" version = "23.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-benchmarking", "frame-support", @@ -8961,7 +8950,7 @@ dependencies = [ [[package]] name = "pallet-asset-rate" version = "20.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-benchmarking", "frame-support", @@ -8975,7 +8964,7 @@ dependencies = [ [[package]] name = "pallet-asset-rewards" version = "0.3.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-benchmarking", "frame-support", @@ -8993,7 +8982,7 @@ dependencies = [ [[package]] name = "pallet-asset-tx-payment" version = "41.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-benchmarking", "frame-support", @@ -9009,7 +8998,7 @@ dependencies = [ [[package]] name = "pallet-assets" version = "43.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "ethereum-standards", "frame-benchmarking", @@ -9027,7 +9016,7 @@ dependencies = [ [[package]] name = "pallet-assets-freezer" version = "0.8.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "log", "pallet-assets", @@ -9039,7 +9028,7 @@ dependencies = [ [[package]] name = "pallet-assets-holder" version = "0.3.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-benchmarking", "frame-support", @@ -9054,7 +9043,7 @@ dependencies = [ [[package]] name = "pallet-atomic-swap" version = "41.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "parity-scale-codec", "polkadot-sdk-frame", @@ -9064,7 +9053,7 @@ dependencies = [ [[package]] name = "pallet-aura" version = "40.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-support", "frame-system", @@ -9080,7 +9069,7 @@ dependencies = [ [[package]] name = "pallet-authority-discovery" version = "41.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-support", "frame-system", @@ -9095,7 +9084,7 @@ dependencies = [ [[package]] name = "pallet-authorship" version = "41.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-support", "frame-system", @@ -9108,7 +9097,7 @@ dependencies = [ [[package]] name = "pallet-babe" version = "41.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-benchmarking", "frame-support", @@ -9131,7 +9120,7 @@ dependencies = [ [[package]] name = "pallet-bags-list" version = "40.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "aquamarine", "docify", @@ -9152,7 +9141,7 @@ dependencies = [ [[package]] name = "pallet-balances" version = "42.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "docify", "frame-benchmarking", @@ -9168,7 +9157,7 @@ dependencies = [ [[package]] name = "pallet-base-fee" version = "1.0.0" -source = "git+https://github.com/opentensor/frontier?rev=d553a11551333c2457d9e64d6d912e2210a4ca26#d553a11551333c2457d9e64d6d912e2210a4ca26" +source = "git+https://github.com/opentensor/frontier?rev=59b4442c222bfaecd37acd81071cfa6fb12bffc6#59b4442c222bfaecd37acd81071cfa6fb12bffc6" dependencies = [ "fp-evm", "frame-support", @@ -9182,7 +9171,7 @@ dependencies = [ [[package]] name = "pallet-beefy" version = "42.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-support", "frame-system", @@ -9201,7 +9190,7 @@ dependencies = [ [[package]] name = "pallet-beefy-mmr" version = "42.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "array-bytes 6.2.3", "binary-merkle-tree", @@ -9226,7 +9215,7 @@ dependencies = [ [[package]] name = "pallet-bounties" version = "40.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-benchmarking", "frame-support", @@ -9243,7 +9232,7 @@ dependencies = [ [[package]] name = "pallet-bridge-grandpa" version = "0.21.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "bp-header-chain", "bp-runtime", @@ -9262,7 +9251,7 @@ dependencies = [ [[package]] name = "pallet-bridge-messages" version = "0.21.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "bp-header-chain", "bp-messages", @@ -9281,7 +9270,7 @@ dependencies = [ [[package]] name = "pallet-bridge-parachains" version = "0.21.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "bp-header-chain", "bp-parachains", @@ -9301,7 +9290,7 @@ dependencies = [ [[package]] name = "pallet-bridge-relayers" version = "0.21.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "bp-header-chain", "bp-messages", @@ -9324,7 +9313,7 @@ dependencies = [ [[package]] name = "pallet-broker" version = "0.20.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "bitvec", "frame-benchmarking", @@ -9342,7 +9331,7 @@ dependencies = [ [[package]] name = "pallet-child-bounties" version = "40.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-benchmarking", "frame-support", @@ -9360,7 +9349,7 @@ dependencies = [ [[package]] name = "pallet-collator-selection" version = "22.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-benchmarking", "frame-support", @@ -9379,7 +9368,7 @@ dependencies = [ [[package]] name = "pallet-collective" version = "41.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "docify", "frame-benchmarking", @@ -9396,7 +9385,7 @@ dependencies = [ [[package]] name = "pallet-collective-content" version = "0.19.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-benchmarking", "frame-support", @@ -9437,7 +9426,7 @@ dependencies = [ [[package]] name = "pallet-contracts" version = "41.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "environmental", "frame-benchmarking", @@ -9468,7 +9457,7 @@ dependencies = [ [[package]] name = "pallet-contracts-mock-network" version = "18.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-support", "frame-system", @@ -9499,7 +9488,7 @@ dependencies = [ [[package]] name = "pallet-contracts-proc-macro" version = "23.0.3" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "proc-macro2", "quote", @@ -9509,7 +9498,7 @@ dependencies = [ [[package]] name = "pallet-contracts-uapi" version = "14.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "bitflags 1.3.2", "parity-scale-codec", @@ -9520,7 +9509,7 @@ dependencies = [ [[package]] name = "pallet-conviction-voting" version = "41.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "assert_matches", "frame-benchmarking", @@ -9536,7 +9525,7 @@ dependencies = [ [[package]] name = "pallet-core-fellowship" version = "25.0.1" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-benchmarking", "frame-support", @@ -9574,7 +9563,7 @@ dependencies = [ [[package]] name = "pallet-delegated-staking" version = "8.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-support", "frame-system", @@ -9589,7 +9578,7 @@ dependencies = [ [[package]] name = "pallet-democracy" version = "41.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-benchmarking", "frame-support", @@ -9606,7 +9595,7 @@ dependencies = [ [[package]] name = "pallet-dev-mode" version = "23.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-support", "frame-system", @@ -9655,7 +9644,7 @@ dependencies = [ [[package]] name = "pallet-dummy-dim" version = "0.2.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-benchmarking", "frame-support", @@ -9673,7 +9662,7 @@ dependencies = [ [[package]] name = "pallet-election-provider-multi-block" version = "0.2.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -9694,7 +9683,7 @@ dependencies = [ [[package]] name = "pallet-election-provider-multi-phase" version = "40.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -9715,7 +9704,7 @@ dependencies = [ [[package]] name = "pallet-election-provider-support-benchmarking" version = "40.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -9728,7 +9717,7 @@ dependencies = [ [[package]] name = "pallet-elections-phragmen" version = "42.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-benchmarking", "frame-support", @@ -9746,7 +9735,7 @@ dependencies = [ [[package]] name = "pallet-ethereum" version = "4.0.0-dev" -source = "git+https://github.com/opentensor/frontier?rev=d553a11551333c2457d9e64d6d912e2210a4ca26#d553a11551333c2457d9e64d6d912e2210a4ca26" +source = "git+https://github.com/opentensor/frontier?rev=59b4442c222bfaecd37acd81071cfa6fb12bffc6#59b4442c222bfaecd37acd81071cfa6fb12bffc6" dependencies = [ "ethereum", "ethereum-types", @@ -9769,7 +9758,7 @@ dependencies = [ [[package]] name = "pallet-evm" version = "6.0.0-dev" -source = "git+https://github.com/opentensor/frontier?rev=d553a11551333c2457d9e64d6d912e2210a4ca26#d553a11551333c2457d9e64d6d912e2210a4ca26" +source = "git+https://github.com/opentensor/frontier?rev=59b4442c222bfaecd37acd81071cfa6fb12bffc6#59b4442c222bfaecd37acd81071cfa6fb12bffc6" dependencies = [ "cumulus-primitives-storage-weight-reclaim", "environmental", @@ -9794,7 +9783,7 @@ dependencies = [ [[package]] name = "pallet-evm-chain-id" version = "1.0.0-dev" -source = "git+https://github.com/opentensor/frontier?rev=d553a11551333c2457d9e64d6d912e2210a4ca26#d553a11551333c2457d9e64d6d912e2210a4ca26" +source = "git+https://github.com/opentensor/frontier?rev=59b4442c222bfaecd37acd81071cfa6fb12bffc6#59b4442c222bfaecd37acd81071cfa6fb12bffc6" dependencies = [ "frame-support", "frame-system", @@ -9805,7 +9794,7 @@ dependencies = [ [[package]] name = "pallet-evm-precompile-bn128" version = "2.0.0-dev" -source = "git+https://github.com/opentensor/frontier?rev=d553a11551333c2457d9e64d6d912e2210a4ca26#d553a11551333c2457d9e64d6d912e2210a4ca26" +source = "git+https://github.com/opentensor/frontier?rev=59b4442c222bfaecd37acd81071cfa6fb12bffc6#59b4442c222bfaecd37acd81071cfa6fb12bffc6" dependencies = [ "fp-evm", "sp-core", @@ -9815,7 +9804,7 @@ dependencies = [ [[package]] name = "pallet-evm-precompile-dispatch" version = "2.0.0-dev" -source = "git+https://github.com/opentensor/frontier?rev=d553a11551333c2457d9e64d6d912e2210a4ca26#d553a11551333c2457d9e64d6d912e2210a4ca26" +source = "git+https://github.com/opentensor/frontier?rev=59b4442c222bfaecd37acd81071cfa6fb12bffc6#59b4442c222bfaecd37acd81071cfa6fb12bffc6" dependencies = [ "fp-evm", "frame-support", @@ -9827,7 +9816,7 @@ dependencies = [ [[package]] name = "pallet-evm-precompile-modexp" version = "2.0.0-dev" -source = "git+https://github.com/opentensor/frontier?rev=d553a11551333c2457d9e64d6d912e2210a4ca26#d553a11551333c2457d9e64d6d912e2210a4ca26" +source = "git+https://github.com/opentensor/frontier?rev=59b4442c222bfaecd37acd81071cfa6fb12bffc6#59b4442c222bfaecd37acd81071cfa6fb12bffc6" dependencies = [ "fp-evm", "num", @@ -9836,7 +9825,7 @@ dependencies = [ [[package]] name = "pallet-evm-precompile-sha3fips" version = "2.0.0-dev" -source = "git+https://github.com/opentensor/frontier?rev=d553a11551333c2457d9e64d6d912e2210a4ca26#d553a11551333c2457d9e64d6d912e2210a4ca26" +source = "git+https://github.com/opentensor/frontier?rev=59b4442c222bfaecd37acd81071cfa6fb12bffc6#59b4442c222bfaecd37acd81071cfa6fb12bffc6" dependencies = [ "fp-evm", "tiny-keccak", @@ -9845,7 +9834,7 @@ dependencies = [ [[package]] name = "pallet-evm-precompile-simple" version = "2.0.0-dev" -source = "git+https://github.com/opentensor/frontier?rev=d553a11551333c2457d9e64d6d912e2210a4ca26#d553a11551333c2457d9e64d6d912e2210a4ca26" +source = "git+https://github.com/opentensor/frontier?rev=59b4442c222bfaecd37acd81071cfa6fb12bffc6#59b4442c222bfaecd37acd81071cfa6fb12bffc6" dependencies = [ "fp-evm", "ripemd", @@ -9855,7 +9844,7 @@ dependencies = [ [[package]] name = "pallet-fast-unstake" version = "40.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "docify", "frame-benchmarking", @@ -9873,7 +9862,7 @@ dependencies = [ [[package]] name = "pallet-glutton" version = "27.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "blake2 0.10.6", "frame-benchmarking", @@ -9891,7 +9880,7 @@ dependencies = [ [[package]] name = "pallet-grandpa" version = "41.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-benchmarking", "frame-support", @@ -9913,7 +9902,7 @@ dependencies = [ [[package]] name = "pallet-hotfix-sufficients" version = "1.0.0" -source = "git+https://github.com/opentensor/frontier?rev=d553a11551333c2457d9e64d6d912e2210a4ca26#d553a11551333c2457d9e64d6d912e2210a4ca26" +source = "git+https://github.com/opentensor/frontier?rev=59b4442c222bfaecd37acd81071cfa6fb12bffc6#59b4442c222bfaecd37acd81071cfa6fb12bffc6" dependencies = [ "frame-benchmarking", "frame-support", @@ -9928,7 +9917,7 @@ dependencies = [ [[package]] name = "pallet-identity" version = "41.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "enumflags2", "frame-benchmarking", @@ -9944,7 +9933,7 @@ dependencies = [ [[package]] name = "pallet-im-online" version = "40.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-benchmarking", "frame-support", @@ -9963,7 +9952,7 @@ dependencies = [ [[package]] name = "pallet-indices" version = "41.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-benchmarking", "frame-support", @@ -9978,7 +9967,7 @@ dependencies = [ [[package]] name = "pallet-insecure-randomness-collective-flip" version = "29.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "parity-scale-codec", "polkadot-sdk-frame", @@ -10011,7 +10000,7 @@ dependencies = [ [[package]] name = "pallet-lottery" version = "41.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-benchmarking", "frame-support", @@ -10024,7 +10013,7 @@ dependencies = [ [[package]] name = "pallet-membership" version = "41.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-benchmarking", "frame-support", @@ -10040,7 +10029,7 @@ dependencies = [ [[package]] name = "pallet-message-queue" version = "44.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "environmental", "frame-benchmarking", @@ -10059,7 +10048,7 @@ dependencies = [ [[package]] name = "pallet-meta-tx" version = "0.3.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "docify", "frame-benchmarking", @@ -10077,7 +10066,7 @@ dependencies = [ [[package]] name = "pallet-migrations" version = "11.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "docify", "frame-benchmarking", @@ -10096,7 +10085,7 @@ dependencies = [ [[package]] name = "pallet-mixnet" version = "0.17.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "log", "parity-scale-codec", @@ -10110,7 +10099,7 @@ dependencies = [ [[package]] name = "pallet-mmr" version = "41.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "log", "parity-scale-codec", @@ -10122,7 +10111,7 @@ dependencies = [ [[package]] name = "pallet-multisig" version = "41.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "log", "parity-scale-codec", @@ -10133,7 +10122,7 @@ dependencies = [ [[package]] name = "pallet-nft-fractionalization" version = "24.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "log", "pallet-assets", @@ -10146,7 +10135,7 @@ dependencies = [ [[package]] name = "pallet-nfts" version = "35.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "enumflags2", "frame-benchmarking", @@ -10163,7 +10152,7 @@ dependencies = [ [[package]] name = "pallet-nis" version = "41.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "parity-scale-codec", "polkadot-sdk-frame", @@ -10173,7 +10162,7 @@ dependencies = [ [[package]] name = "pallet-node-authorization" version = "41.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "log", "parity-scale-codec", @@ -10184,7 +10173,7 @@ dependencies = [ [[package]] name = "pallet-nomination-pools" version = "39.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-support", "frame-system", @@ -10202,7 +10191,7 @@ dependencies = [ [[package]] name = "pallet-nomination-pools-benchmarking" version = "39.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -10222,7 +10211,7 @@ dependencies = [ [[package]] name = "pallet-nomination-pools-runtime-api" version = "37.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "pallet-nomination-pools", "parity-scale-codec", @@ -10232,7 +10221,7 @@ dependencies = [ [[package]] name = "pallet-offences" version = "40.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-support", "frame-system", @@ -10247,7 +10236,7 @@ dependencies = [ [[package]] name = "pallet-offences-benchmarking" version = "41.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -10270,7 +10259,7 @@ dependencies = [ [[package]] name = "pallet-origin-restriction" version = "0.2.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-benchmarking", "frame-support", @@ -10288,7 +10277,7 @@ dependencies = [ [[package]] name = "pallet-paged-list" version = "0.19.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "docify", "parity-scale-codec", @@ -10299,7 +10288,7 @@ dependencies = [ [[package]] name = "pallet-parameters" version = "0.12.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "docify", "frame-benchmarking", @@ -10316,7 +10305,7 @@ dependencies = [ [[package]] name = "pallet-people" version = "0.2.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-benchmarking", "frame-support", @@ -10334,7 +10323,7 @@ dependencies = [ [[package]] name = "pallet-preimage" version = "41.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-benchmarking", "frame-support", @@ -10350,8 +10339,10 @@ dependencies = [ [[package]] name = "pallet-proxy" version = "41.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ + "frame-support", + "frame-system", "parity-scale-codec", "polkadot-sdk-frame", "scale-info", @@ -10360,7 +10351,7 @@ dependencies = [ [[package]] name = "pallet-ranked-collective" version = "41.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-benchmarking", "frame-support", @@ -10378,7 +10369,7 @@ dependencies = [ [[package]] name = "pallet-recovery" version = "41.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "parity-scale-codec", "polkadot-sdk-frame", @@ -10388,7 +10379,7 @@ dependencies = [ [[package]] name = "pallet-referenda" version = "41.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "assert_matches", "frame-benchmarking", @@ -10425,7 +10416,7 @@ dependencies = [ [[package]] name = "pallet-remark" version = "41.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-benchmarking", "frame-support", @@ -10440,7 +10431,7 @@ dependencies = [ [[package]] name = "pallet-revive" version = "0.7.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "alloy-core", "derive_more 0.99.20", @@ -10486,7 +10477,7 @@ dependencies = [ [[package]] name = "pallet-revive-fixtures" version = "0.4.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "anyhow", "cargo_metadata", @@ -10500,7 +10491,7 @@ dependencies = [ [[package]] name = "pallet-revive-proc-macro" version = "0.3.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "proc-macro2", "quote", @@ -10510,7 +10501,7 @@ dependencies = [ [[package]] name = "pallet-revive-uapi" version = "0.5.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "bitflags 1.3.2", "pallet-revive-proc-macro", @@ -10522,7 +10513,7 @@ dependencies = [ [[package]] name = "pallet-root-offences" version = "38.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-support", "frame-system", @@ -10538,7 +10529,7 @@ dependencies = [ [[package]] name = "pallet-root-testing" version = "17.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-support", "frame-system", @@ -10551,7 +10542,7 @@ dependencies = [ [[package]] name = "pallet-safe-mode" version = "22.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "docify", "pallet-balances", @@ -10565,7 +10556,7 @@ dependencies = [ [[package]] name = "pallet-salary" version = "26.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "log", "pallet-ranked-collective", @@ -10577,7 +10568,7 @@ dependencies = [ [[package]] name = "pallet-scheduler" version = "42.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "docify", "frame-benchmarking", @@ -10594,7 +10585,7 @@ dependencies = [ [[package]] name = "pallet-scored-pool" version = "41.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-support", "frame-system", @@ -10607,7 +10598,7 @@ dependencies = [ [[package]] name = "pallet-session" version = "41.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-support", "frame-system", @@ -10628,7 +10619,7 @@ dependencies = [ [[package]] name = "pallet-session-benchmarking" version = "41.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-benchmarking", "frame-support", @@ -10652,8 +10643,8 @@ dependencies = [ "log", "ml-kem", "pallet-aura", - "pallet-subtensor-utility", "pallet-timestamp", + "pallet-utility", "parity-scale-codec", "rand_chacha 0.3.1", "scale-info", @@ -10674,7 +10665,7 @@ dependencies = [ [[package]] name = "pallet-skip-feeless-payment" version = "16.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-support", "frame-system", @@ -10686,7 +10677,7 @@ dependencies = [ [[package]] name = "pallet-society" version = "41.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-benchmarking", "frame-support", @@ -10703,7 +10694,7 @@ dependencies = [ [[package]] name = "pallet-staking" version = "41.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -10725,7 +10716,7 @@ dependencies = [ [[package]] name = "pallet-staking-async" version = "0.2.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-benchmarking", "frame-election-provider-support", @@ -10748,7 +10739,7 @@ dependencies = [ [[package]] name = "pallet-staking-async-ah-client" version = "0.2.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-support", "frame-system", @@ -10767,7 +10758,7 @@ dependencies = [ [[package]] name = "pallet-staking-async-rc-client" version = "0.2.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-support", "frame-system", @@ -10784,7 +10775,7 @@ dependencies = [ [[package]] name = "pallet-staking-reward-curve" version = "12.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "proc-macro-crate 3.4.0", "proc-macro2", @@ -10795,7 +10786,7 @@ dependencies = [ [[package]] name = "pallet-staking-reward-fn" version = "23.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "log", "sp-arithmetic", @@ -10804,7 +10795,7 @@ dependencies = [ [[package]] name = "pallet-staking-runtime-api" version = "27.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "parity-scale-codec", "sp-api", @@ -10814,7 +10805,7 @@ dependencies = [ [[package]] name = "pallet-state-trie-migration" version = "46.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-benchmarking", "frame-support", @@ -10830,7 +10821,7 @@ dependencies = [ [[package]] name = "pallet-statement" version = "23.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-support", "frame-system", @@ -10866,12 +10857,12 @@ dependencies = [ "pallet-crowdloan", "pallet-drand", "pallet-preimage", + "pallet-proxy", "pallet-scheduler", "pallet-shield", - "pallet-subtensor-proxy", "pallet-subtensor-swap", - "pallet-subtensor-utility", "pallet-transaction-payment", + "pallet-utility", "parity-scale-codec", "polkadot-runtime-common", "rand 0.10.0", @@ -10900,20 +10891,6 @@ dependencies = [ "w3f-bls 0.1.3", ] -[[package]] -name = "pallet-subtensor-proxy" -version = "40.1.0" -dependencies = [ - "frame-support", - "frame-system", - "pallet-balances", - "pallet-subtensor-utility", - "parity-scale-codec", - "polkadot-sdk-frame", - "scale-info", - "subtensor-macros", -] - [[package]] name = "pallet-subtensor-swap" version = "0.1.0" @@ -10969,28 +10946,10 @@ dependencies = [ "subtensor-swap-interface", ] -[[package]] -name = "pallet-subtensor-utility" -version = "40.0.0" -dependencies = [ - "frame-benchmarking", - "frame-support", - "frame-system", - "pallet-balances", - "pallet-root-testing", - "pallet-timestamp", - "parity-scale-codec", - "scale-info", - "sp-core", - "sp-io", - "sp-runtime", - "subtensor-macros", -] - [[package]] name = "pallet-sudo" version = "41.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "docify", "frame-benchmarking", @@ -11005,7 +10964,7 @@ dependencies = [ [[package]] name = "pallet-timestamp" version = "40.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "docify", "frame-benchmarking", @@ -11023,7 +10982,7 @@ dependencies = [ [[package]] name = "pallet-tips" version = "40.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-benchmarking", "frame-support", @@ -11041,7 +11000,7 @@ dependencies = [ [[package]] name = "pallet-transaction-payment" version = "41.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-benchmarking", "frame-support", @@ -11056,7 +11015,7 @@ dependencies = [ [[package]] name = "pallet-transaction-payment-rpc" version = "44.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "jsonrpsee", "pallet-transaction-payment-rpc-runtime-api", @@ -11072,7 +11031,7 @@ dependencies = [ [[package]] name = "pallet-transaction-payment-rpc-runtime-api" version = "41.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "pallet-transaction-payment", "parity-scale-codec", @@ -11084,7 +11043,7 @@ dependencies = [ [[package]] name = "pallet-transaction-storage" version = "40.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "array-bytes 6.2.3", "frame-benchmarking", @@ -11103,7 +11062,7 @@ dependencies = [ [[package]] name = "pallet-treasury" version = "40.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "docify", "frame-benchmarking", @@ -11122,7 +11081,7 @@ dependencies = [ [[package]] name = "pallet-tx-pause" version = "22.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "docify", "parity-scale-codec", @@ -11133,7 +11092,7 @@ dependencies = [ [[package]] name = "pallet-uniques" version = "41.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-benchmarking", "frame-support", @@ -11147,7 +11106,7 @@ dependencies = [ [[package]] name = "pallet-utility" version = "41.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-benchmarking", "frame-support", @@ -11162,7 +11121,7 @@ dependencies = [ [[package]] name = "pallet-verify-signature" version = "0.4.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-benchmarking", "frame-support", @@ -11177,7 +11136,7 @@ dependencies = [ [[package]] name = "pallet-vesting" version = "41.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-benchmarking", "frame-support", @@ -11191,7 +11150,7 @@ dependencies = [ [[package]] name = "pallet-whitelist" version = "40.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "parity-scale-codec", "polkadot-sdk-frame", @@ -11201,7 +11160,7 @@ dependencies = [ [[package]] name = "pallet-xcm" version = "20.1.3" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "bounded-collections 0.2.4", "frame-benchmarking", @@ -11227,7 +11186,7 @@ dependencies = [ [[package]] name = "pallet-xcm-benchmarks" version = "21.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-benchmarking", "frame-support", @@ -11244,7 +11203,7 @@ dependencies = [ [[package]] name = "pallet-xcm-bridge-hub" version = "0.17.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "bp-messages", "bp-runtime", @@ -11266,7 +11225,7 @@ dependencies = [ [[package]] name = "pallet-xcm-bridge-hub-router" version = "0.19.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "bp-xcm-bridge-hub-router", "frame-benchmarking", @@ -11286,7 +11245,7 @@ dependencies = [ [[package]] name = "parachains-common" version = "22.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "cumulus-primitives-core", "cumulus-primitives-utility", @@ -11625,7 +11584,7 @@ checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" [[package]] name = "polkadot-approval-distribution" version = "24.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "futures", "futures-timer", @@ -11643,7 +11602,7 @@ dependencies = [ [[package]] name = "polkadot-availability-bitfield-distribution" version = "24.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "futures", "futures-timer", @@ -11658,7 +11617,7 @@ dependencies = [ [[package]] name = "polkadot-availability-distribution" version = "24.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "fatality", "futures", @@ -11681,7 +11640,7 @@ dependencies = [ [[package]] name = "polkadot-availability-recovery" version = "24.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "async-trait", "fatality", @@ -11714,7 +11673,7 @@ dependencies = [ [[package]] name = "polkadot-cli" version = "25.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "clap", "frame-benchmarking-cli", @@ -11738,7 +11697,7 @@ dependencies = [ [[package]] name = "polkadot-collator-protocol" version = "24.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "bitvec", "fatality", @@ -11761,7 +11720,7 @@ dependencies = [ [[package]] name = "polkadot-core-primitives" version = "18.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "parity-scale-codec", "scale-info", @@ -11772,7 +11731,7 @@ dependencies = [ [[package]] name = "polkadot-dispute-distribution" version = "24.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "fatality", "futures", @@ -11794,7 +11753,7 @@ dependencies = [ [[package]] name = "polkadot-erasure-coding" version = "20.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "parity-scale-codec", "polkadot-node-primitives", @@ -11808,7 +11767,7 @@ dependencies = [ [[package]] name = "polkadot-gossip-support" version = "24.0.1" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "futures", "futures-timer", @@ -11821,7 +11780,7 @@ dependencies = [ "sc-network", "sp-application-crypto", "sp-core", - "sp-crypto-hashing 0.1.0 (git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7)", + "sp-crypto-hashing 0.1.0 (git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8)", "sp-keystore", "tracing-gum", ] @@ -11829,7 +11788,7 @@ dependencies = [ [[package]] name = "polkadot-network-bridge" version = "24.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "always-assert", "async-trait", @@ -11852,7 +11811,7 @@ dependencies = [ [[package]] name = "polkadot-node-collation-generation" version = "24.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "futures", "parity-scale-codec", @@ -11870,7 +11829,7 @@ dependencies = [ [[package]] name = "polkadot-node-core-approval-voting" version = "24.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "async-trait", "bitvec", @@ -11902,7 +11861,7 @@ dependencies = [ [[package]] name = "polkadot-node-core-approval-voting-parallel" version = "0.7.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "async-trait", "futures", @@ -11926,7 +11885,7 @@ dependencies = [ [[package]] name = "polkadot-node-core-av-store" version = "24.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "bitvec", "futures", @@ -11945,7 +11904,7 @@ dependencies = [ [[package]] name = "polkadot-node-core-backing" version = "24.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "bitvec", "fatality", @@ -11966,7 +11925,7 @@ dependencies = [ [[package]] name = "polkadot-node-core-bitfield-signing" version = "24.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "futures", "polkadot-node-subsystem", @@ -11981,7 +11940,7 @@ dependencies = [ [[package]] name = "polkadot-node-core-candidate-validation" version = "24.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "async-trait", "futures", @@ -12003,7 +11962,7 @@ dependencies = [ [[package]] name = "polkadot-node-core-chain-api" version = "24.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "futures", "polkadot-node-metrics", @@ -12017,7 +11976,7 @@ dependencies = [ [[package]] name = "polkadot-node-core-chain-selection" version = "24.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "futures", "futures-timer", @@ -12033,7 +11992,7 @@ dependencies = [ [[package]] name = "polkadot-node-core-dispute-coordinator" version = "24.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "fatality", "futures", @@ -12051,7 +12010,7 @@ dependencies = [ [[package]] name = "polkadot-node-core-parachains-inherent" version = "24.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "async-trait", "futures", @@ -12068,7 +12027,7 @@ dependencies = [ [[package]] name = "polkadot-node-core-prospective-parachains" version = "23.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "fatality", "futures", @@ -12082,7 +12041,7 @@ dependencies = [ [[package]] name = "polkadot-node-core-provisioner" version = "24.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "bitvec", "fatality", @@ -12099,7 +12058,7 @@ dependencies = [ [[package]] name = "polkadot-node-core-pvf" version = "24.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "always-assert", "array-bytes 6.2.3", @@ -12127,7 +12086,7 @@ dependencies = [ [[package]] name = "polkadot-node-core-pvf-checker" version = "24.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "futures", "polkadot-node-subsystem", @@ -12140,7 +12099,7 @@ dependencies = [ [[package]] name = "polkadot-node-core-pvf-common" version = "20.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "cpu-time", "futures", @@ -12155,7 +12114,7 @@ dependencies = [ "sc-executor-wasmtime", "seccompiler", "sp-core", - "sp-crypto-hashing 0.1.0 (git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7)", + "sp-crypto-hashing 0.1.0 (git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8)", "sp-externalities", "sp-io", "sp-tracing", @@ -12166,7 +12125,7 @@ dependencies = [ [[package]] name = "polkadot-node-core-runtime-api" version = "24.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "futures", "polkadot-node-metrics", @@ -12181,7 +12140,7 @@ dependencies = [ [[package]] name = "polkadot-node-metrics" version = "24.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "bs58", "futures", @@ -12198,7 +12157,7 @@ dependencies = [ [[package]] name = "polkadot-node-network-protocol" version = "24.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "async-channel 1.9.0", "async-trait", @@ -12223,7 +12182,7 @@ dependencies = [ [[package]] name = "polkadot-node-primitives" version = "20.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "bitvec", "bounded-vec", @@ -12247,7 +12206,7 @@ dependencies = [ [[package]] name = "polkadot-node-subsystem" version = "24.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "polkadot-node-subsystem-types", "polkadot-overseer", @@ -12256,7 +12215,7 @@ dependencies = [ [[package]] name = "polkadot-node-subsystem-types" version = "24.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "async-trait", "derive_more 0.99.20", @@ -12284,7 +12243,7 @@ dependencies = [ [[package]] name = "polkadot-node-subsystem-util" version = "24.0.1" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "fatality", "futures", @@ -12315,7 +12274,7 @@ dependencies = [ [[package]] name = "polkadot-omni-node-lib" version = "0.7.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "async-trait", "clap", @@ -12403,7 +12362,7 @@ dependencies = [ [[package]] name = "polkadot-overseer" version = "24.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "async-trait", "futures", @@ -12423,7 +12382,7 @@ dependencies = [ [[package]] name = "polkadot-parachain-primitives" version = "17.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "bounded-collections 0.2.4", "derive_more 0.99.20", @@ -12439,7 +12398,7 @@ dependencies = [ [[package]] name = "polkadot-primitives" version = "19.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "bitvec", "bounded-collections 0.2.4", @@ -12468,7 +12427,7 @@ dependencies = [ [[package]] name = "polkadot-rpc" version = "25.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "jsonrpsee", "mmr-rpc", @@ -12501,7 +12460,7 @@ dependencies = [ [[package]] name = "polkadot-runtime-common" version = "20.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "bitvec", "frame-benchmarking", @@ -12551,7 +12510,7 @@ dependencies = [ [[package]] name = "polkadot-runtime-metrics" version = "21.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "bs58", "frame-benchmarking", @@ -12563,7 +12522,7 @@ dependencies = [ [[package]] name = "polkadot-runtime-parachains" version = "20.0.2" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "bitflags 1.3.2", "bitvec", @@ -12611,7 +12570,7 @@ dependencies = [ [[package]] name = "polkadot-sdk" version = "2506.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "assets-common", "bridge-hub-common", @@ -12769,7 +12728,7 @@ dependencies = [ [[package]] name = "polkadot-sdk-frame" version = "0.10.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "docify", "frame-benchmarking", @@ -12804,7 +12763,7 @@ dependencies = [ [[package]] name = "polkadot-service" version = "25.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "async-trait", "frame-benchmarking", @@ -12914,7 +12873,7 @@ dependencies = [ [[package]] name = "polkadot-statement-distribution" version = "24.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "bitvec", "fatality", @@ -12934,7 +12893,7 @@ dependencies = [ [[package]] name = "polkadot-statement-table" version = "20.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "parity-scale-codec", "polkadot-primitives", @@ -13207,7 +13166,7 @@ dependencies = [ [[package]] name = "precompile-utils" version = "0.1.0" -source = "git+https://github.com/opentensor/frontier?rev=d553a11551333c2457d9e64d6d912e2210a4ca26#d553a11551333c2457d9e64d6d912e2210a4ca26" +source = "git+https://github.com/opentensor/frontier?rev=59b4442c222bfaecd37acd81071cfa6fb12bffc6#59b4442c222bfaecd37acd81071cfa6fb12bffc6" dependencies = [ "derive_more 1.0.0", "environmental", @@ -13236,14 +13195,14 @@ dependencies = [ [[package]] name = "precompile-utils-macro" version = "0.1.0" -source = "git+https://github.com/opentensor/frontier?rev=d553a11551333c2457d9e64d6d912e2210a4ca26#d553a11551333c2457d9e64d6d912e2210a4ca26" +source = "git+https://github.com/opentensor/frontier?rev=59b4442c222bfaecd37acd81071cfa6fb12bffc6#59b4442c222bfaecd37acd81071cfa6fb12bffc6" dependencies = [ "case", "num_enum", "prettyplease", "proc-macro2", "quote", - "sp-crypto-hashing 0.1.0 (git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7)", + "sp-crypto-hashing 0.1.0 (git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8)", "syn 2.0.106", ] @@ -13410,25 +13369,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "procedural-fork" -version = "1.10.0-rc3" -dependencies = [ - "Inflector", - "cfg-expr", - "derive-syn-parse", - "expander", - "frame-support-procedural-tools 10.0.0", - "itertools 0.10.5", - "macro_magic", - "proc-macro-warning", - "proc-macro2", - "quote", - "regex", - "sp-crypto-hashing 0.1.0 (git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7)", - "syn 2.0.106", -] - [[package]] name = "prometheus" version = "0.13.4" @@ -14072,7 +14012,7 @@ dependencies = [ [[package]] name = "rococo-runtime" version = "24.0.1" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "binary-merkle-tree", "bitvec", @@ -14170,7 +14110,7 @@ dependencies = [ [[package]] name = "rococo-runtime-constants" version = "21.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-support", "polkadot-primitives", @@ -14566,7 +14506,7 @@ dependencies = [ [[package]] name = "sc-allocator" version = "32.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "log", "sp-core", @@ -14577,7 +14517,7 @@ dependencies = [ [[package]] name = "sc-authority-discovery" version = "0.51.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "async-trait", "futures", @@ -14608,7 +14548,7 @@ dependencies = [ [[package]] name = "sc-basic-authorship" version = "0.50.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "futures", "log", @@ -14630,7 +14570,7 @@ dependencies = [ [[package]] name = "sc-block-builder" version = "0.45.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "parity-scale-codec", "sp-api", @@ -14645,7 +14585,7 @@ dependencies = [ [[package]] name = "sc-chain-spec" version = "44.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "array-bytes 6.2.3", "clap", @@ -14661,7 +14601,7 @@ dependencies = [ "serde_json", "sp-blockchain", "sp-core", - "sp-crypto-hashing 0.1.0 (git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7)", + "sp-crypto-hashing 0.1.0 (git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8)", "sp-genesis-builder", "sp-io", "sp-runtime", @@ -14672,7 +14612,7 @@ dependencies = [ [[package]] name = "sc-chain-spec-derive" version = "12.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "proc-macro-crate 3.4.0", "proc-macro2", @@ -14683,7 +14623,7 @@ dependencies = [ [[package]] name = "sc-cli" version = "0.53.1" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "array-bytes 6.2.3", "chrono", @@ -14725,7 +14665,7 @@ dependencies = [ [[package]] name = "sc-client-api" version = "40.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "fnv", "futures", @@ -14751,7 +14691,7 @@ dependencies = [ [[package]] name = "sc-client-db" version = "0.47.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "hash-db", "kvdb", @@ -14779,7 +14719,7 @@ dependencies = [ [[package]] name = "sc-consensus" version = "0.50.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "async-trait", "futures", @@ -14802,7 +14742,7 @@ dependencies = [ [[package]] name = "sc-consensus-aura" version = "0.51.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "async-trait", "futures", @@ -14831,7 +14771,7 @@ dependencies = [ [[package]] name = "sc-consensus-babe" version = "0.51.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "async-trait", "fork-tree", @@ -14856,7 +14796,7 @@ dependencies = [ "sp-consensus-babe", "sp-consensus-slots", "sp-core", - "sp-crypto-hashing 0.1.0 (git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7)", + "sp-crypto-hashing 0.1.0 (git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8)", "sp-inherents", "sp-keystore", "sp-runtime", @@ -14867,7 +14807,7 @@ dependencies = [ [[package]] name = "sc-consensus-babe-rpc" version = "0.51.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "futures", "jsonrpsee", @@ -14889,7 +14829,7 @@ dependencies = [ [[package]] name = "sc-consensus-beefy" version = "30.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "array-bytes 6.2.3", "async-channel 1.9.0", @@ -14923,7 +14863,7 @@ dependencies = [ [[package]] name = "sc-consensus-beefy-rpc" version = "30.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "futures", "jsonrpsee", @@ -14943,7 +14883,7 @@ dependencies = [ [[package]] name = "sc-consensus-epochs" version = "0.50.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "fork-tree", "parity-scale-codec", @@ -14956,7 +14896,7 @@ dependencies = [ [[package]] name = "sc-consensus-grandpa" version = "0.36.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "ahash", "array-bytes 6.2.3", @@ -14990,7 +14930,7 @@ dependencies = [ "sp-consensus", "sp-consensus-grandpa", "sp-core", - "sp-crypto-hashing 0.1.0 (git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7)", + "sp-crypto-hashing 0.1.0 (git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8)", "sp-keystore", "sp-runtime", "substrate-prometheus-endpoint", @@ -15000,7 +14940,7 @@ dependencies = [ [[package]] name = "sc-consensus-grandpa-rpc" version = "0.36.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "finality-grandpa", "futures", @@ -15020,7 +14960,7 @@ dependencies = [ [[package]] name = "sc-consensus-manual-seal" version = "0.52.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "assert_matches", "async-trait", @@ -15055,7 +14995,7 @@ dependencies = [ [[package]] name = "sc-consensus-slots" version = "0.50.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "async-trait", "futures", @@ -15078,7 +15018,7 @@ dependencies = [ [[package]] name = "sc-executor" version = "0.43.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "parity-scale-codec", "parking_lot 0.12.5", @@ -15101,7 +15041,7 @@ dependencies = [ [[package]] name = "sc-executor-common" version = "0.39.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "polkavm 0.24.0", "sc-allocator", @@ -15114,7 +15054,7 @@ dependencies = [ [[package]] name = "sc-executor-polkavm" version = "0.36.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "log", "polkavm 0.24.0", @@ -15125,7 +15065,7 @@ dependencies = [ [[package]] name = "sc-executor-wasmtime" version = "0.39.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "anyhow", "log", @@ -15141,7 +15081,7 @@ dependencies = [ [[package]] name = "sc-informant" version = "0.50.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "console", "futures", @@ -15157,7 +15097,7 @@ dependencies = [ [[package]] name = "sc-keystore" version = "36.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "array-bytes 6.2.3", "parking_lot 0.12.5", @@ -15171,7 +15111,7 @@ dependencies = [ [[package]] name = "sc-mixnet" version = "0.21.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "array-bytes 6.2.3", "arrayvec 0.7.6", @@ -15199,7 +15139,7 @@ dependencies = [ [[package]] name = "sc-network" version = "0.51.1" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "array-bytes 6.2.3", "async-channel 1.9.0", @@ -15249,7 +15189,7 @@ dependencies = [ [[package]] name = "sc-network-common" version = "0.49.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "bitflags 1.3.2", "parity-scale-codec", @@ -15259,7 +15199,7 @@ dependencies = [ [[package]] name = "sc-network-gossip" version = "0.51.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "ahash", "futures", @@ -15278,7 +15218,7 @@ dependencies = [ [[package]] name = "sc-network-light" version = "0.50.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "array-bytes 6.2.3", "async-channel 1.9.0", @@ -15299,7 +15239,7 @@ dependencies = [ [[package]] name = "sc-network-statement" version = "0.33.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "array-bytes 6.2.3", "async-channel 1.9.0", @@ -15319,7 +15259,7 @@ dependencies = [ [[package]] name = "sc-network-sync" version = "0.50.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "array-bytes 6.2.3", "async-channel 1.9.0", @@ -15354,7 +15294,7 @@ dependencies = [ [[package]] name = "sc-network-transactions" version = "0.50.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "array-bytes 6.2.3", "futures", @@ -15373,7 +15313,7 @@ dependencies = [ [[package]] name = "sc-network-types" version = "0.17.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "bs58", "bytes", @@ -15394,7 +15334,7 @@ dependencies = [ [[package]] name = "sc-offchain" version = "46.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "bytes", "fnv", @@ -15428,7 +15368,7 @@ dependencies = [ [[package]] name = "sc-proposer-metrics" version = "0.20.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "log", "substrate-prometheus-endpoint", @@ -15437,7 +15377,7 @@ dependencies = [ [[package]] name = "sc-rpc" version = "46.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "futures", "jsonrpsee", @@ -15469,7 +15409,7 @@ dependencies = [ [[package]] name = "sc-rpc-api" version = "0.50.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "jsonrpsee", "parity-scale-codec", @@ -15489,7 +15429,7 @@ dependencies = [ [[package]] name = "sc-rpc-server" version = "23.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "dyn-clone", "forwarded-header-value", @@ -15513,7 +15453,7 @@ dependencies = [ [[package]] name = "sc-rpc-spec-v2" version = "0.51.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "array-bytes 6.2.3", "futures", @@ -15546,13 +15486,13 @@ dependencies = [ [[package]] name = "sc-runtime-utilities" version = "0.3.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "parity-scale-codec", "sc-executor", "sc-executor-common", "sp-core", - "sp-crypto-hashing 0.1.0 (git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7)", + "sp-crypto-hashing 0.1.0 (git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8)", "sp-state-machine", "sp-wasm-interface", "thiserror 1.0.69", @@ -15561,7 +15501,7 @@ dependencies = [ [[package]] name = "sc-service" version = "0.52.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "async-trait", "directories", @@ -15625,7 +15565,7 @@ dependencies = [ [[package]] name = "sc-state-db" version = "0.39.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "log", "parity-scale-codec", @@ -15636,7 +15576,7 @@ dependencies = [ [[package]] name = "sc-statement-store" version = "22.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "log", "parity-db", @@ -15655,7 +15595,7 @@ dependencies = [ [[package]] name = "sc-storage-monitor" version = "0.25.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "clap", "fs4", @@ -15668,7 +15608,7 @@ dependencies = [ [[package]] name = "sc-sync-state-rpc" version = "0.51.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "jsonrpsee", "parity-scale-codec", @@ -15687,7 +15627,7 @@ dependencies = [ [[package]] name = "sc-sysinfo" version = "43.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "derive_more 0.99.20", "futures", @@ -15700,14 +15640,14 @@ dependencies = [ "serde", "serde_json", "sp-core", - "sp-crypto-hashing 0.1.0 (git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7)", + "sp-crypto-hashing 0.1.0 (git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8)", "sp-io", ] [[package]] name = "sc-telemetry" version = "29.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "chrono", "futures", @@ -15726,7 +15666,7 @@ dependencies = [ [[package]] name = "sc-tracing" version = "40.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "chrono", "console", @@ -15754,7 +15694,7 @@ dependencies = [ [[package]] name = "sc-tracing-proc-macro" version = "11.1.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "proc-macro-crate 3.4.0", "proc-macro2", @@ -15765,7 +15705,7 @@ dependencies = [ [[package]] name = "sc-transaction-pool" version = "40.1.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "async-trait", "futures", @@ -15782,7 +15722,7 @@ dependencies = [ "sp-api", "sp-blockchain", "sp-core", - "sp-crypto-hashing 0.1.0 (git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7)", + "sp-crypto-hashing 0.1.0 (git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8)", "sp-runtime", "sp-tracing", "sp-transaction-pool", @@ -15796,7 +15736,7 @@ dependencies = [ [[package]] name = "sc-transaction-pool-api" version = "40.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "async-trait", "futures", @@ -15813,7 +15753,7 @@ dependencies = [ [[package]] name = "sc-utils" version = "19.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "async-channel 1.9.0", "futures", @@ -16540,7 +16480,7 @@ checksum = "826167069c09b99d56f31e9ae5c99049e932a98c9dc2dac47645b08dbbf76ba7" [[package]] name = "slot-range-helper" version = "18.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "enumn", "parity-scale-codec", @@ -16803,7 +16743,7 @@ dependencies = [ [[package]] name = "snowbridge-core" version = "0.14.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "bp-relayers", "frame-support", @@ -16887,7 +16827,7 @@ dependencies = [ [[package]] name = "sp-api" version = "37.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "docify", "hash-db", @@ -16909,7 +16849,7 @@ dependencies = [ [[package]] name = "sp-api-proc-macro" version = "23.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "Inflector", "blake2 0.10.6", @@ -16923,7 +16863,7 @@ dependencies = [ [[package]] name = "sp-application-crypto" version = "41.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "parity-scale-codec", "scale-info", @@ -16935,7 +16875,7 @@ dependencies = [ [[package]] name = "sp-arithmetic" version = "27.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "docify", "integer-sqrt", @@ -16949,7 +16889,7 @@ dependencies = [ [[package]] name = "sp-authority-discovery" version = "37.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "parity-scale-codec", "scale-info", @@ -16961,7 +16901,7 @@ dependencies = [ [[package]] name = "sp-block-builder" version = "37.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "sp-api", "sp-inherents", @@ -16971,7 +16911,7 @@ dependencies = [ [[package]] name = "sp-blockchain" version = "40.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "futures", "parity-scale-codec", @@ -16990,7 +16930,7 @@ dependencies = [ [[package]] name = "sp-consensus" version = "0.43.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "async-trait", "futures", @@ -17004,7 +16944,7 @@ dependencies = [ [[package]] name = "sp-consensus-aura" version = "0.43.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "async-trait", "parity-scale-codec", @@ -17020,7 +16960,7 @@ dependencies = [ [[package]] name = "sp-consensus-babe" version = "0.43.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "async-trait", "parity-scale-codec", @@ -17038,7 +16978,7 @@ dependencies = [ [[package]] name = "sp-consensus-beefy" version = "25.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "parity-scale-codec", "scale-info", @@ -17046,7 +16986,7 @@ dependencies = [ "sp-api", "sp-application-crypto", "sp-core", - "sp-crypto-hashing 0.1.0 (git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7)", + "sp-crypto-hashing 0.1.0 (git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8)", "sp-io", "sp-keystore", "sp-mmr-primitives", @@ -17058,7 +16998,7 @@ dependencies = [ [[package]] name = "sp-consensus-grandpa" version = "24.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "finality-grandpa", "log", @@ -17075,7 +17015,7 @@ dependencies = [ [[package]] name = "sp-consensus-slots" version = "0.43.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "parity-scale-codec", "scale-info", @@ -17086,7 +17026,7 @@ dependencies = [ [[package]] name = "sp-core" version = "37.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "ark-vrf", "array-bytes 6.2.3", @@ -17117,7 +17057,7 @@ dependencies = [ "secrecy 0.8.0", "serde", "sha2 0.10.9", - "sp-crypto-hashing 0.1.0 (git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7)", + "sp-crypto-hashing 0.1.0 (git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8)", "sp-debug-derive", "sp-externalities", "sp-runtime-interface", @@ -17134,7 +17074,7 @@ dependencies = [ [[package]] name = "sp-crypto-ec-utils" version = "0.16.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "ark-bls12-377", "ark-bls12-377-ext", @@ -17168,7 +17108,7 @@ dependencies = [ [[package]] name = "sp-crypto-hashing" version = "0.1.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "blake2b_simd", "byteorder", @@ -17181,17 +17121,17 @@ dependencies = [ [[package]] name = "sp-crypto-hashing-proc-macro" version = "0.1.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "quote", - "sp-crypto-hashing 0.1.0 (git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7)", + "sp-crypto-hashing 0.1.0 (git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8)", "syn 2.0.106", ] [[package]] name = "sp-database" version = "10.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "kvdb", "parking_lot 0.12.5", @@ -17200,7 +17140,7 @@ dependencies = [ [[package]] name = "sp-debug-derive" version = "14.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "proc-macro2", "quote", @@ -17210,7 +17150,7 @@ dependencies = [ [[package]] name = "sp-externalities" version = "0.30.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "environmental", "parity-scale-codec", @@ -17220,7 +17160,7 @@ dependencies = [ [[package]] name = "sp-genesis-builder" version = "0.18.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "parity-scale-codec", "scale-info", @@ -17232,7 +17172,7 @@ dependencies = [ [[package]] name = "sp-inherents" version = "37.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "async-trait", "impl-trait-for-tuples", @@ -17245,7 +17185,7 @@ dependencies = [ [[package]] name = "sp-io" version = "41.0.1" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "bytes", "docify", @@ -17257,7 +17197,7 @@ dependencies = [ "rustversion", "secp256k1 0.28.2", "sp-core", - "sp-crypto-hashing 0.1.0 (git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7)", + "sp-crypto-hashing 0.1.0 (git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8)", "sp-externalities", "sp-keystore", "sp-runtime-interface", @@ -17271,7 +17211,7 @@ dependencies = [ [[package]] name = "sp-keyring" version = "42.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "sp-core", "sp-runtime", @@ -17281,7 +17221,7 @@ dependencies = [ [[package]] name = "sp-keystore" version = "0.43.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "parity-scale-codec", "parking_lot 0.12.5", @@ -17292,7 +17232,7 @@ dependencies = [ [[package]] name = "sp-maybe-compressed-blob" version = "11.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "thiserror 1.0.69", "zstd 0.12.4", @@ -17301,7 +17241,7 @@ dependencies = [ [[package]] name = "sp-metadata-ir" version = "0.11.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-metadata 23.0.0", "parity-scale-codec", @@ -17311,7 +17251,7 @@ dependencies = [ [[package]] name = "sp-mixnet" version = "0.15.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "parity-scale-codec", "scale-info", @@ -17322,7 +17262,7 @@ dependencies = [ [[package]] name = "sp-mmr-primitives" version = "37.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "log", "parity-scale-codec", @@ -17339,7 +17279,7 @@ dependencies = [ [[package]] name = "sp-npos-elections" version = "37.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "parity-scale-codec", "scale-info", @@ -17352,7 +17292,7 @@ dependencies = [ [[package]] name = "sp-offchain" version = "37.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "sp-api", "sp-core", @@ -17362,7 +17302,7 @@ dependencies = [ [[package]] name = "sp-panic-handler" version = "13.0.2" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "backtrace", "regex", @@ -17371,7 +17311,7 @@ dependencies = [ [[package]] name = "sp-rpc" version = "35.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "rustc-hash 1.1.0", "serde", @@ -17381,7 +17321,7 @@ dependencies = [ [[package]] name = "sp-runtime" version = "42.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "binary-merkle-tree", "docify", @@ -17410,7 +17350,7 @@ dependencies = [ [[package]] name = "sp-runtime-interface" version = "30.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "bytes", "impl-trait-for-tuples", @@ -17429,7 +17369,7 @@ dependencies = [ [[package]] name = "sp-runtime-interface-proc-macro" version = "19.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "Inflector", "expander", @@ -17442,7 +17382,7 @@ dependencies = [ [[package]] name = "sp-session" version = "39.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "parity-scale-codec", "scale-info", @@ -17456,7 +17396,7 @@ dependencies = [ [[package]] name = "sp-staking" version = "39.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "impl-trait-for-tuples", "parity-scale-codec", @@ -17469,7 +17409,7 @@ dependencies = [ [[package]] name = "sp-state-machine" version = "0.46.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "hash-db", "log", @@ -17489,7 +17429,7 @@ dependencies = [ [[package]] name = "sp-statement-store" version = "21.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "aes-gcm", "curve25519-dalek", @@ -17502,7 +17442,7 @@ dependencies = [ "sp-api", "sp-application-crypto", "sp-core", - "sp-crypto-hashing 0.1.0 (git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7)", + "sp-crypto-hashing 0.1.0 (git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8)", "sp-externalities", "sp-runtime", "sp-runtime-interface", @@ -17513,12 +17453,12 @@ dependencies = [ [[package]] name = "sp-std" version = "14.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" [[package]] name = "sp-storage" version = "22.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "impl-serde", "parity-scale-codec", @@ -17530,7 +17470,7 @@ dependencies = [ [[package]] name = "sp-timestamp" version = "37.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "async-trait", "parity-scale-codec", @@ -17542,7 +17482,7 @@ dependencies = [ [[package]] name = "sp-tracing" version = "17.1.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "parity-scale-codec", "tracing", @@ -17553,7 +17493,7 @@ dependencies = [ [[package]] name = "sp-transaction-pool" version = "37.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "sp-api", "sp-runtime", @@ -17562,7 +17502,7 @@ dependencies = [ [[package]] name = "sp-transaction-storage-proof" version = "37.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "async-trait", "parity-scale-codec", @@ -17576,7 +17516,7 @@ dependencies = [ [[package]] name = "sp-trie" version = "40.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "ahash", "foldhash 0.1.5", @@ -17601,7 +17541,7 @@ dependencies = [ [[package]] name = "sp-version" version = "40.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "impl-serde", "parity-scale-codec", @@ -17618,7 +17558,7 @@ dependencies = [ [[package]] name = "sp-version-proc-macro" version = "15.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "parity-scale-codec", "proc-macro-warning", @@ -17630,7 +17570,7 @@ dependencies = [ [[package]] name = "sp-wasm-interface" version = "22.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "anyhow", "impl-trait-for-tuples", @@ -17642,7 +17582,7 @@ dependencies = [ [[package]] name = "sp-weights" version = "32.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "bounded-collections 0.2.4", "parity-scale-codec", @@ -17816,7 +17756,7 @@ checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" [[package]] name = "staging-chain-spec-builder" version = "12.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "clap", "docify", @@ -17829,7 +17769,7 @@ dependencies = [ [[package]] name = "staging-node-inspect" version = "0.29.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "clap", "parity-scale-codec", @@ -17847,7 +17787,7 @@ dependencies = [ [[package]] name = "staging-parachain-info" version = "0.21.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "cumulus-primitives-core", "frame-support", @@ -17860,7 +17800,7 @@ dependencies = [ [[package]] name = "staging-xcm" version = "17.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "array-bytes 6.2.3", "bounded-collections 0.2.4", @@ -17881,7 +17821,7 @@ dependencies = [ [[package]] name = "staging-xcm-builder" version = "21.1.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "environmental", "frame-support", @@ -17905,7 +17845,7 @@ dependencies = [ [[package]] name = "staging-xcm-executor" version = "20.0.1" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "environmental", "frame-benchmarking", @@ -17959,7 +17899,7 @@ dependencies = [ [[package]] name = "stc-shield" version = "0.1.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "anyhow", "async-trait", @@ -17980,7 +17920,7 @@ dependencies = [ [[package]] name = "stp-shield" version = "0.1.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "parity-scale-codec", "scale-info", @@ -18050,7 +17990,7 @@ dependencies = [ [[package]] name = "substrate-bip39" version = "0.6.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "hmac 0.12.1", "pbkdf2", @@ -18075,7 +18015,7 @@ dependencies = [ [[package]] name = "substrate-build-script-utils" version = "11.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" [[package]] name = "substrate-fixed" @@ -18091,7 +18031,7 @@ dependencies = [ [[package]] name = "substrate-frame-rpc-system" version = "45.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "docify", "frame-system-rpc-runtime-api", @@ -18111,7 +18051,7 @@ dependencies = [ [[package]] name = "substrate-prometheus-endpoint" version = "0.17.6" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "http-body-util", "hyper 1.7.0", @@ -18125,7 +18065,7 @@ dependencies = [ [[package]] name = "substrate-state-trie-migration-rpc" version = "44.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "jsonrpsee", "parity-scale-codec", @@ -18152,7 +18092,7 @@ dependencies = [ [[package]] name = "substrate-wasm-builder" version = "27.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "array-bytes 6.2.3", "build-helper", @@ -18205,12 +18145,12 @@ dependencies = [ "pallet-crowdloan", "pallet-drand", "pallet-preimage", + "pallet-proxy", "pallet-scheduler", "pallet-subtensor", - "pallet-subtensor-proxy", "pallet-subtensor-swap", - "pallet-subtensor-utility", "pallet-timestamp", + "pallet-utility", "parity-scale-codec", "scale-info", "sp-core", @@ -18251,8 +18191,8 @@ dependencies = [ name = "subtensor-linting" version = "0.1.0" dependencies = [ + "frame-support-procedural-core", "proc-macro2", - "procedural-fork", "quote", "syn 2.0.106", ] @@ -18289,10 +18229,10 @@ dependencies = [ "pallet-evm-precompile-sha3fips", "pallet-evm-precompile-simple", "pallet-preimage", + "pallet-proxy", "pallet-scheduler", "pallet-shield", "pallet-subtensor", - "pallet-subtensor-proxy", "pallet-subtensor-swap", "pallet-timestamp", "parity-scale-codec", @@ -19207,7 +19147,7 @@ dependencies = [ [[package]] name = "tracing-gum" version = "20.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "coarsetime", "polkadot-primitives", @@ -19218,7 +19158,7 @@ dependencies = [ [[package]] name = "tracing-gum-proc-macro" version = "5.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "expander", "proc-macro-crate 3.4.0", @@ -20212,7 +20152,7 @@ checksum = "5f20c57d8d7db6d3b86154206ae5d8fba62dd39573114de97c2cb0578251f8e1" [[package]] name = "westend-runtime" version = "24.0.1" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "binary-merkle-tree", "bitvec", @@ -20319,7 +20259,7 @@ dependencies = [ [[package]] name = "westend-runtime-constants" version = "21.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-support", "polkadot-primitives", @@ -20960,7 +20900,7 @@ dependencies = [ [[package]] name = "xcm-procedural" version = "11.0.2" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "Inflector", "proc-macro2", @@ -20971,7 +20911,7 @@ dependencies = [ [[package]] name = "xcm-runtime-apis" version = "0.8.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-support", "parity-scale-codec", @@ -20985,7 +20925,7 @@ dependencies = [ [[package]] name = "xcm-simulator" version = "21.0.0" -source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=7cc54bf2d50ae3921d718736dfeb0de9468539c7#7cc54bf2d50ae3921d718736dfeb0de9468539c7" +source = "git+https://github.com/opentensor/polkadot-sdk.git?rev=6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8#6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8" dependencies = [ "frame-support", "frame-system", diff --git a/Cargo.toml b/Cargo.toml index 70441ab056..52b1c4f98d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -65,7 +65,6 @@ pallet-subtensor = { path = "pallets/subtensor", default-features = false } pallet-subtensor-swap = { path = "pallets/swap", default-features = false } pallet-subtensor-swap-runtime-api = { path = "pallets/swap/runtime-api", default-features = false } pallet-subtensor-swap-rpc = { path = "pallets/swap/rpc", default-features = false } -procedural-fork = { path = "support/procedural-fork", default-features = false } safe-math = { path = "primitives/safe-math", default-features = false } share-pool = { path = "primitives/share-pool", default-features = false } subtensor-macros = { path = "support/macros", default-features = false } @@ -76,8 +75,8 @@ subtensor-runtime-common = { default-features = false, path = "common" } subtensor-swap-interface = { default-features = false, path = "primitives/swap-interface" } subtensor-transaction-fee = { default-features = false, path = "pallets/transaction-fee" } subtensor-chain-extensions = { default-features = false, path = "chain-extensions" } -stp-shield = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -stc-shield = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } +stp-shield = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +stc-shield = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } ed25519-dalek = { version = "2.1.0", default-features = false } async-trait = "0.1" @@ -130,159 +129,161 @@ num_enum = { version = "0.7.4", default-features = false } environmental = { version = "1.1.4", default-features = false } tokio = { version = "1.38", default-features = false } -frame = { package = "polkadot-sdk-frame", git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -frame-support = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -frame-system = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -frame-executive = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -frame-system-rpc-runtime-api = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -frame-system-benchmarking = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -frame-try-runtime = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -frame-benchmarking = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -frame-benchmarking-cli = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -frame-metadata-hash-extension = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } +frame = { package = "polkadot-sdk-frame", git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +frame-support = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +frame-system = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +frame-executive = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +frame-system-rpc-runtime-api = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +frame-system-benchmarking = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +frame-try-runtime = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +frame-benchmarking = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +frame-benchmarking-cli = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +frame-metadata-hash-extension = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } frame-metadata = { version = "23.0.0", default-features = false } -pallet-subtensor-proxy = { path = "pallets/proxy", default-features = false } -pallet-subtensor-utility = { path = "pallets/utility", default-features = false } -pallet-babe = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -pallet-aura = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -pallet-balances = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -pallet-grandpa = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -pallet-insecure-randomness-collective-flip = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -pallet-multisig = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -pallet-preimage = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -pallet-safe-mode = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -pallet-scheduler = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -pallet-sudo = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -pallet-timestamp = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -pallet-transaction-payment = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -pallet-transaction-payment-rpc = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -pallet-root-testing = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -pallet-contracts = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } +pallet-babe = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +pallet-aura = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +pallet-balances = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +pallet-grandpa = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +pallet-insecure-randomness-collective-flip = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +pallet-multisig = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +pallet-preimage = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +pallet-safe-mode = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +pallet-scheduler = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +pallet-sudo = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +pallet-timestamp = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +pallet-transaction-payment = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +pallet-transaction-payment-rpc = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +pallet-root-testing = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +pallet-contracts = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +pallet-proxy = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +pallet-utility = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } # NPoS -frame-election-provider-support = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -pallet-authority-discovery = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -pallet-authorship = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -pallet-bags-list = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -pallet-election-provider-multi-phase = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -pallet-fast-unstake = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -pallet-nomination-pools = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -pallet-nomination-pools-runtime-api = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -pallet-session = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -pallet-staking = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -pallet-staking-runtime-api = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -pallet-staking-reward-fn = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -pallet-staking-reward-curve = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -pallet-offences = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } +frame-election-provider-support = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +pallet-authority-discovery = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +pallet-authorship = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +pallet-bags-list = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +pallet-election-provider-multi-phase = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +pallet-fast-unstake = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +pallet-nomination-pools = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +pallet-nomination-pools-runtime-api = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +pallet-session = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +pallet-staking = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +pallet-staking-runtime-api = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +pallet-staking-reward-fn = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +pallet-staking-reward-curve = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +pallet-offences = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } -sc-basic-authorship = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -sc-cli = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -sc-client-api = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -sc-consensus = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -sc-consensus-aura = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -sc-consensus-babe = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -sc-consensus-babe-rpc = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -sc-consensus-grandpa = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -sc-consensus-grandpa-rpc = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -sc-consensus-epochs = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -sc-chain-spec-derive = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -sc-chain-spec = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -sc-consensus-slots = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -sc-executor = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -sc-keystore = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -sc-network = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -sc-offchain = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -sc-rpc = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -sc-rpc-api = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -sc-service = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -sc-telemetry = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -sc-transaction-pool = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -sc-transaction-pool-api = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -sc-consensus-manual-seal = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -sc-network-sync = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } +sc-basic-authorship = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +sc-cli = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +sc-client-api = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +sc-consensus = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +sc-consensus-aura = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +sc-consensus-babe = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +sc-consensus-babe-rpc = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +sc-consensus-grandpa = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +sc-consensus-grandpa-rpc = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +sc-consensus-epochs = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +sc-chain-spec-derive = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +sc-chain-spec = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +sc-consensus-slots = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +sc-executor = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +sc-keystore = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +sc-network = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +sc-offchain = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +sc-rpc = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +sc-rpc-api = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +sc-service = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +sc-telemetry = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +sc-transaction-pool = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +sc-transaction-pool-api = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +sc-consensus-manual-seal = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +sc-network-sync = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } -sp-api = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -sp-authority-discovery = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -sp-arithmetic = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -sp-block-builder = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -sp-blockchain = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -sp-staking = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -sp-consensus = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -sp-consensus-aura = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -sp-consensus-babe = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -sp-consensus-slots = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -sp-npos-elections = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -sp-consensus-grandpa = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -sp-genesis-builder = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -sp-core = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -sp-inherents = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -sp-io = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -sp-keyring = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -sp-offchain = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -sp-rpc = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -sp-runtime = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -sp-session = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -sp-std = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -sp-storage = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -sp-timestamp = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -sp-tracing = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -sp-transaction-pool = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -sp-version = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -sp-weights = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -sp-crypto-hashing = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -sp-application-crypto = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -sp-debug-derive = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -sp-externalities = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -sp-runtime-interface = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } +sp-api = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +sp-authority-discovery = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +sp-arithmetic = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +sp-block-builder = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +sp-blockchain = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +sp-staking = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +sp-consensus = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +sp-consensus-aura = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +sp-consensus-babe = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +sp-consensus-slots = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +sp-npos-elections = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +sp-consensus-grandpa = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +sp-genesis-builder = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +sp-core = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +sp-inherents = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +sp-io = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +sp-keyring = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +sp-offchain = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +sp-rpc = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +sp-runtime = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +sp-session = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +sp-std = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +sp-storage = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +sp-timestamp = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +sp-tracing = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +sp-transaction-pool = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +sp-version = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +sp-weights = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +sp-crypto-hashing = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +sp-application-crypto = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +sp-debug-derive = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +sp-externalities = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +sp-runtime-interface = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } -substrate-build-script-utils = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } +frame-support-procedural-core = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } + +substrate-build-script-utils = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } substrate-fixed = { git = "https://github.com/encointer/substrate-fixed.git", tag = "v0.6.0", default-features = false } -substrate-frame-rpc-system = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -substrate-wasm-builder = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -substrate-prometheus-endpoint = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } +substrate-frame-rpc-system = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +substrate-wasm-builder = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +substrate-prometheus-endpoint = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } -polkadot-sdk = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } +polkadot-sdk = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } -runtime-common = { package = "polkadot-runtime-common", git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } +runtime-common = { package = "polkadot-runtime-common", git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } # Frontier # current frontier branch is polkadot-stable2506-2-otf-get-call-indices-metadata -fp-evm = { git = "https://github.com/opentensor/frontier", rev = "d553a11551333c2457d9e64d6d912e2210a4ca26", default-features = false } -fp-rpc = { git = "https://github.com/opentensor/frontier", rev = "d553a11551333c2457d9e64d6d912e2210a4ca26", default-features = false } -fp-self-contained = { git = "https://github.com/opentensor/frontier", rev = "d553a11551333c2457d9e64d6d912e2210a4ca26", default-features = false } -fp-account = { git = "https://github.com/opentensor/frontier", rev = "d553a11551333c2457d9e64d6d912e2210a4ca26", default-features = false } -fc-storage = { git = "https://github.com/opentensor/frontier", rev = "d553a11551333c2457d9e64d6d912e2210a4ca26", default-features = false } -fc-db = { git = "https://github.com/opentensor/frontier", rev = "d553a11551333c2457d9e64d6d912e2210a4ca26", default-features = false } -fc-consensus = { git = "https://github.com/opentensor/frontier", rev = "d553a11551333c2457d9e64d6d912e2210a4ca26", default-features = false } -fp-consensus = { git = "https://github.com/opentensor/frontier", rev = "d553a11551333c2457d9e64d6d912e2210a4ca26", default-features = false } -fp-dynamic-fee = { git = "https://github.com/opentensor/frontier", rev = "d553a11551333c2457d9e64d6d912e2210a4ca26", default-features = false } -fc-api = { git = "https://github.com/opentensor/frontier", rev = "d553a11551333c2457d9e64d6d912e2210a4ca26", default-features = false } -fc-rpc = { git = "https://github.com/opentensor/frontier", rev = "d553a11551333c2457d9e64d6d912e2210a4ca26", default-features = false } -fc-rpc-core = { git = "https://github.com/opentensor/frontier", rev = "d553a11551333c2457d9e64d6d912e2210a4ca26", default-features = false } -fc-aura = { git = "https://github.com/opentensor/frontier", rev = "d553a11551333c2457d9e64d6d912e2210a4ca26", default-features = false } -fc-babe = { git = "https://github.com/opentensor/frontier", rev = "d553a11551333c2457d9e64d6d912e2210a4ca26", default-features = false } -fc-mapping-sync = { git = "https://github.com/opentensor/frontier", rev = "d553a11551333c2457d9e64d6d912e2210a4ca26", default-features = false } -precompile-utils = { git = "https://github.com/opentensor/frontier", rev = "d553a11551333c2457d9e64d6d912e2210a4ca26", default-features = false } +fp-evm = { git = "https://github.com/opentensor/frontier", rev = "59b4442c222bfaecd37acd81071cfa6fb12bffc6", default-features = false } +fp-rpc = { git = "https://github.com/opentensor/frontier", rev = "59b4442c222bfaecd37acd81071cfa6fb12bffc6", default-features = false } +fp-self-contained = { git = "https://github.com/opentensor/frontier", rev = "59b4442c222bfaecd37acd81071cfa6fb12bffc6", default-features = false } +fp-account = { git = "https://github.com/opentensor/frontier", rev = "59b4442c222bfaecd37acd81071cfa6fb12bffc6", default-features = false } +fc-storage = { git = "https://github.com/opentensor/frontier", rev = "59b4442c222bfaecd37acd81071cfa6fb12bffc6", default-features = false } +fc-db = { git = "https://github.com/opentensor/frontier", rev = "59b4442c222bfaecd37acd81071cfa6fb12bffc6", default-features = false } +fc-consensus = { git = "https://github.com/opentensor/frontier", rev = "59b4442c222bfaecd37acd81071cfa6fb12bffc6", default-features = false } +fp-consensus = { git = "https://github.com/opentensor/frontier", rev = "59b4442c222bfaecd37acd81071cfa6fb12bffc6", default-features = false } +fp-dynamic-fee = { git = "https://github.com/opentensor/frontier", rev = "59b4442c222bfaecd37acd81071cfa6fb12bffc6", default-features = false } +fc-api = { git = "https://github.com/opentensor/frontier", rev = "59b4442c222bfaecd37acd81071cfa6fb12bffc6", default-features = false } +fc-rpc = { git = "https://github.com/opentensor/frontier", rev = "59b4442c222bfaecd37acd81071cfa6fb12bffc6", default-features = false } +fc-rpc-core = { git = "https://github.com/opentensor/frontier", rev = "59b4442c222bfaecd37acd81071cfa6fb12bffc6", default-features = false } +fc-aura = { git = "https://github.com/opentensor/frontier", rev = "59b4442c222bfaecd37acd81071cfa6fb12bffc6", default-features = false } +fc-babe = { git = "https://github.com/opentensor/frontier", rev = "59b4442c222bfaecd37acd81071cfa6fb12bffc6", default-features = false } +fc-mapping-sync = { git = "https://github.com/opentensor/frontier", rev = "59b4442c222bfaecd37acd81071cfa6fb12bffc6", default-features = false } +precompile-utils = { git = "https://github.com/opentensor/frontier", rev = "59b4442c222bfaecd37acd81071cfa6fb12bffc6", default-features = false } # Frontier FRAME -pallet-base-fee = { git = "https://github.com/opentensor/frontier", rev = "d553a11551333c2457d9e64d6d912e2210a4ca26", default-features = false } -pallet-dynamic-fee = { git = "https://github.com/opentensor/frontier", rev = "d553a11551333c2457d9e64d6d912e2210a4ca26", default-features = false } -pallet-ethereum = { git = "https://github.com/opentensor/frontier", rev = "d553a11551333c2457d9e64d6d912e2210a4ca26", default-features = false } -pallet-evm = { git = "https://github.com/opentensor/frontier", rev = "d553a11551333c2457d9e64d6d912e2210a4ca26", default-features = false } -pallet-evm-precompile-dispatch = { git = "https://github.com/opentensor/frontier", rev = "d553a11551333c2457d9e64d6d912e2210a4ca26", default-features = false } -pallet-evm-chain-id = { git = "https://github.com/opentensor/frontier", rev = "d553a11551333c2457d9e64d6d912e2210a4ca26", default-features = false } -pallet-evm-precompile-modexp = { git = "https://github.com/opentensor/frontier", rev = "d553a11551333c2457d9e64d6d912e2210a4ca26", default-features = false } -pallet-evm-precompile-sha3fips = { git = "https://github.com/opentensor/frontier", rev = "d553a11551333c2457d9e64d6d912e2210a4ca26", default-features = false } -pallet-evm-precompile-simple = { git = "https://github.com/opentensor/frontier", rev = "d553a11551333c2457d9e64d6d912e2210a4ca26", default-features = false } -pallet-evm-precompile-bn128 = { git = "https://github.com/opentensor/frontier", rev = "d553a11551333c2457d9e64d6d912e2210a4ca26", default-features = false } -pallet-hotfix-sufficients = { git = "https://github.com/opentensor/frontier", rev = "d553a11551333c2457d9e64d6d912e2210a4ca26", default-features = false } +pallet-base-fee = { git = "https://github.com/opentensor/frontier", rev = "59b4442c222bfaecd37acd81071cfa6fb12bffc6", default-features = false } +pallet-dynamic-fee = { git = "https://github.com/opentensor/frontier", rev = "59b4442c222bfaecd37acd81071cfa6fb12bffc6", default-features = false } +pallet-ethereum = { git = "https://github.com/opentensor/frontier", rev = "59b4442c222bfaecd37acd81071cfa6fb12bffc6", default-features = false } +pallet-evm = { git = "https://github.com/opentensor/frontier", rev = "59b4442c222bfaecd37acd81071cfa6fb12bffc6", default-features = false } +pallet-evm-precompile-dispatch = { git = "https://github.com/opentensor/frontier", rev = "59b4442c222bfaecd37acd81071cfa6fb12bffc6", default-features = false } +pallet-evm-chain-id = { git = "https://github.com/opentensor/frontier", rev = "59b4442c222bfaecd37acd81071cfa6fb12bffc6", default-features = false } +pallet-evm-precompile-modexp = { git = "https://github.com/opentensor/frontier", rev = "59b4442c222bfaecd37acd81071cfa6fb12bffc6", default-features = false } +pallet-evm-precompile-sha3fips = { git = "https://github.com/opentensor/frontier", rev = "59b4442c222bfaecd37acd81071cfa6fb12bffc6", default-features = false } +pallet-evm-precompile-simple = { git = "https://github.com/opentensor/frontier", rev = "59b4442c222bfaecd37acd81071cfa6fb12bffc6", default-features = false } +pallet-evm-precompile-bn128 = { git = "https://github.com/opentensor/frontier", rev = "59b4442c222bfaecd37acd81071cfa6fb12bffc6", default-features = false } +pallet-hotfix-sufficients = { git = "https://github.com/opentensor/frontier", rev = "59b4442c222bfaecd37acd81071cfa6fb12bffc6", default-features = false } #DRAND pallet-drand = { path = "pallets/drand", default-features = false } -sp-crypto-ec-utils = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } -sp-keystore = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "7cc54bf2d50ae3921d718736dfeb0de9468539c7", default-features = false } +sp-crypto-ec-utils = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } +sp-keystore = { git = "https://github.com/opentensor/polkadot-sdk.git", rev = "6a62332f1ff8b6b2fe1488ee740de1d35e1cecb8", default-features = false } w3f-bls = { git = "https://github.com/opentensor/bls", branch = "fix-no-std", default-features = false } ark-crypto-primitives = { version = "0.4.0", default-features = false } ark-scale = { version = "0.0.11", default-features = false } @@ -301,6 +302,7 @@ ml-kem = { version = "0.2.2", default-features = false } chacha20poly1305 = { version = "0.10", default-features = false } blake2 = "0.10.6" + # Primitives [profile.release] diff --git a/build.rs b/build.rs index 854778873e..3c21c67160 100644 --- a/build.rs +++ b/build.rs @@ -2,13 +2,14 @@ use rayon::prelude::*; use std::{ env, fs, path::{Path, PathBuf}, - str::FromStr, sync::mpsc::channel, }; use walkdir::WalkDir; use subtensor_linting::*; +const LINT_THREAD_STACK_SIZE: usize = 8 * 1024 * 1024; + fn main() { // need to list all rust directories here println!("cargo:rerun-if-changed=pallets"); @@ -29,45 +30,49 @@ fn main() { // as we process each Rust file let (tx, rx) = channel(); - // Parse each rust file with syn and run the linting suite on it in parallel - rust_files.par_iter().for_each_with(tx.clone(), |tx, file| { - let is_test = file.display().to_string().contains("test"); - let Ok(content) = fs::read_to_string(file) else { - return; - }; - let Ok(parsed_tokens) = proc_macro2::TokenStream::from_str(&content) else { - return; - }; - let Ok(parsed_file) = syn::parse2::(parsed_tokens) else { - return; - }; + let lint_pool = rayon::ThreadPoolBuilder::new() + .stack_size(LINT_THREAD_STACK_SIZE) + .build() + .expect("failed to initialize custom lint thread pool"); - let track_lint = |result: Result| { - let Err(errors) = result else { + // Parse each rust file with syn and run the linting suite on it in parallel + lint_pool.install(|| { + rust_files.par_iter().for_each_with(tx.clone(), |tx, file| { + let is_test = file.display().to_string().contains("test"); + let Ok(content) = fs::read_to_string(file) else { + return; + }; + let Ok(parsed_file) = syn::parse_file(&content) else { return; }; - let relative_path = file.strip_prefix(workspace_root).unwrap_or(file.as_path()); - for error in errors { - let loc = error.span().start(); - let file_path = relative_path.display(); - // note that spans can't go across thread boundaries without losing their location - // info so we we serialize here and send a String - tx.send(format!( - "cargo:warning={}:{}:{}: {}", - file_path, loc.line, loc.column, error, - )) - .unwrap(); - } - }; - track_lint(ForbidAsPrimitiveConversion::lint(&parsed_file)); - track_lint(ForbidKeysRemoveCall::lint(&parsed_file)); - track_lint(RequireFreezeStruct::lint(&parsed_file)); - track_lint(RequireExplicitPalletIndex::lint(&parsed_file)); + let track_lint = |result: Result| { + let Err(errors) = result else { + return; + }; + let relative_path = file.strip_prefix(workspace_root).unwrap_or(file.as_path()); + for error in errors { + let loc = error.span().start(); + let file_path = relative_path.display(); + // note that spans can't go across thread boundaries without losing their location + // info so we we serialize here and send a String + tx.send(format!( + "cargo:warning={}:{}:{}: {}", + file_path, loc.line, loc.column, error, + )) + .unwrap(); + } + }; - if is_test { - track_lint(ForbidSaturatingMath::lint(&parsed_file)); - } + track_lint(ForbidAsPrimitiveConversion::lint(&parsed_file)); + track_lint(ForbidKeysRemoveCall::lint(&parsed_file)); + track_lint(RequireFreezeStruct::lint(&parsed_file)); + track_lint(RequireExplicitPalletIndex::lint(&parsed_file)); + + if is_test { + track_lint(ForbidSaturatingMath::lint(&parsed_file)); + } + }); }); // Collect and print all errors after the parallel processing is done diff --git a/chain-extensions/Cargo.toml b/chain-extensions/Cargo.toml index 74fa71e78a..1da41d8e69 100644 --- a/chain-extensions/Cargo.toml +++ b/chain-extensions/Cargo.toml @@ -30,8 +30,8 @@ pallet-scheduler.workspace = true pallet-preimage.workspace = true pallet-timestamp.workspace = true pallet-crowdloan.workspace = true -pallet-subtensor-utility.workspace = true -pallet-subtensor-proxy.workspace = true +pallet-utility.workspace = true +pallet-proxy.workspace = true pallet-drand.workspace = true subtensor-swap-interface.workspace = true num_enum.workspace = true @@ -62,8 +62,8 @@ std = [ "pallet-preimage/std", "pallet-timestamp/std", "pallet-crowdloan/std", - "pallet-subtensor-utility/std", - "pallet-subtensor-proxy/std", + "pallet-utility/std", + "pallet-proxy/std", "pallet-drand/std", "subtensor-swap-interface/std", "num_enum/std", @@ -81,8 +81,8 @@ runtime-benchmarks = [ "pallet-drand/runtime-benchmarks", "pallet-preimage/runtime-benchmarks", "pallet-scheduler/runtime-benchmarks", - "pallet-subtensor-proxy/runtime-benchmarks", - "pallet-subtensor-utility/runtime-benchmarks", + "pallet-proxy/runtime-benchmarks", + "pallet-utility/runtime-benchmarks", "pallet-timestamp/runtime-benchmarks", "subtensor-runtime-common/runtime-benchmarks", "subtensor-swap-interface/runtime-benchmarks" diff --git a/chain-extensions/src/lib.rs b/chain-extensions/src/lib.rs index 1aa1a2f966..4f9b2a4a78 100644 --- a/chain-extensions/src/lib.rs +++ b/chain-extensions/src/lib.rs @@ -14,9 +14,8 @@ use frame_system::RawOrigin; use pallet_contracts::chain_extension::{ BufInBufOutState, ChainExtension, Environment, Ext, InitState, RetVal, SysConfig, }; +use pallet_proxy::WeightInfo; use pallet_subtensor::weights::WeightInfo as SubtensorWeightInfo; -use pallet_subtensor_proxy as pallet_proxy; -use pallet_subtensor_proxy::WeightInfo; use sp_runtime::{DispatchError, Weight, traits::StaticLookup}; use sp_std::marker::PhantomData; use substrate_fixed::types::U96F32; diff --git a/chain-extensions/src/mock.rs b/chain-extensions/src/mock.rs index fc3398bbb9..2065824238 100644 --- a/chain-extensions/src/mock.rs +++ b/chain-extensions/src/mock.rs @@ -17,8 +17,6 @@ use frame_system as system; use frame_system::{EnsureRoot, RawOrigin, limits, offchain::CreateTransactionBase}; use pallet_contracts::HoldReason as ContractsHoldReason; use pallet_subtensor::*; -use pallet_subtensor_proxy as pallet_proxy; -use pallet_subtensor_utility as pallet_utility; use sp_core::{ConstU64, H256, U256, offchain::KeyTypeId}; use sp_runtime::Perbill; use sp_runtime::{ @@ -177,6 +175,7 @@ impl frame_support::traits::InstanceFilter for subtensor_runtime_co } impl pallet_proxy::Config for Test { + type RuntimeEvent = RuntimeEvent; type RuntimeCall = RuntimeCall; type Currency = Balances; type ProxyType = subtensor_runtime_common::ProxyType; @@ -495,6 +494,7 @@ impl pallet_scheduler::Config for Test { } impl pallet_utility::Config for Test { + type RuntimeEvent = RuntimeEvent; type RuntimeCall = RuntimeCall; type PalletsOrigin = OriginCaller; type WeightInfo = pallet_utility::weights::SubstrateWeight; diff --git a/chain-extensions/src/tests.rs b/chain-extensions/src/tests.rs index eeac0ce451..7b8f76e1e7 100644 --- a/chain-extensions/src/tests.rs +++ b/chain-extensions/src/tests.rs @@ -630,9 +630,7 @@ fn add_proxy_success_creates_proxy_relationship() { add_balance_to_coldkey_account(&delegator, 1_000_000_000.into()); assert_eq!( - pallet_subtensor_proxy::Proxies::::get(delegator) - .0 - .len(), + pallet_proxy::Proxies::::get(delegator).0.len(), 0 ); @@ -641,7 +639,7 @@ fn add_proxy_success_creates_proxy_relationship() { let ret = SubtensorChainExtension::::dispatch(&mut env).unwrap(); assert_success(ret); - let proxies = pallet_subtensor_proxy::Proxies::::get(delegator).0; + let proxies = pallet_proxy::Proxies::::get(delegator).0; assert_eq!(proxies.len(), 1); if let Some(proxy) = proxies.first() { assert_eq!(proxy.delegate, delegate); @@ -668,14 +666,14 @@ fn remove_proxy_success_removes_proxy_relationship() { let ret = SubtensorChainExtension::::dispatch(&mut add_env).unwrap(); assert_success(ret); - let proxies_before = pallet_subtensor_proxy::Proxies::::get(delegator).0; + let proxies_before = pallet_proxy::Proxies::::get(delegator).0; assert_eq!(proxies_before.len(), 1); let mut remove_env = MockEnv::new(FunctionId::RemoveProxyV1, delegator, delegate.encode()); let ret = SubtensorChainExtension::::dispatch(&mut remove_env).unwrap(); assert_success(ret); - let proxies_after = pallet_subtensor_proxy::Proxies::::get(delegator).0; + let proxies_after = pallet_proxy::Proxies::::get(delegator).0; assert_eq!(proxies_after.len(), 0); }); } @@ -2371,7 +2369,7 @@ mod caller_dispatch_tests { let ret = SubtensorChainExtension::::dispatch(&mut env).unwrap(); assert_success(ret); - let proxies = pallet_subtensor_proxy::Proxies::::get(delegator).0; + let proxies = pallet_proxy::Proxies::::get(delegator).0; assert_eq!(proxies.len(), 1); }); } @@ -2396,7 +2394,7 @@ mod caller_dispatch_tests { let ret = SubtensorChainExtension::::dispatch(&mut remove_env).unwrap(); assert_success(ret); - let proxies_after = pallet_subtensor_proxy::Proxies::::get(delegator).0; + let proxies_after = pallet_proxy::Proxies::::get(delegator).0; assert_eq!(proxies_after.len(), 0); }); } diff --git a/eco-tests/Cargo.toml b/eco-tests/Cargo.toml index b00e2ced42..7a0b525b88 100644 --- a/eco-tests/Cargo.toml +++ b/eco-tests/Cargo.toml @@ -34,8 +34,8 @@ pallet-preimage = { git = "https://github.com/opentensor/polkadot-sdk.git", rev pallet-drand = { path = "../pallets/drand", default-features = false, features = ["std"] } pallet-subtensor-swap = { path = "../pallets/swap", default-features = false, features = ["std"] } pallet-crowdloan = { path = "../pallets/crowdloan", default-features = false, features = ["std"] } -pallet-subtensor-proxy = { path = "../pallets/proxy", default-features = false, features = ["std"] } -pallet-subtensor-utility = { path = "../pallets/utility", default-features = false, features = ["std"] } +pallet-proxy = { path = "../pallets/proxy", default-features = false, features = ["std"] } +pallet-utility = { path = "../pallets/utility", default-features = false, features = ["std"] } pallet-shield = { path = "../pallets/shield", default-features = false, features = ["std"] } subtensor-runtime-common = { path = "../common", default-features = false, features = ["std"] } subtensor-swap-interface = { path = "../primitives/swap-interface", default-features = false, features = ["std"] } diff --git a/eco-tests/src/mock.rs b/eco-tests/src/mock.rs index aba98da9b5..c0c9829d2c 100644 --- a/eco-tests/src/mock.rs +++ b/eco-tests/src/mock.rs @@ -16,8 +16,6 @@ use frame_support::{parameter_types, traits::PrivilegeCmp}; use frame_system as system; use frame_system::{EnsureRoot, limits, offchain::CreateTransactionBase}; use pallet_subtensor::*; -use pallet_subtensor_proxy as pallet_proxy; -use pallet_subtensor_utility as pallet_utility; use sp_core::{ConstU64, H256, U256, offchain::KeyTypeId}; use sp_runtime::Perbill; use sp_runtime::{ @@ -44,7 +42,7 @@ frame_support::construct_runtime!( Drand: pallet_drand = 8, Swap: pallet_subtensor_swap = 9, Crowdloan: pallet_crowdloan = 10, - Proxy: pallet_subtensor_proxy = 11, + Proxy: pallet_proxy = 11, AlphaAssets: pallet_alpha_assets = 12, } ); diff --git a/pallets/proxy/Cargo.toml b/pallets/proxy/Cargo.toml deleted file mode 100644 index 9331739325..0000000000 --- a/pallets/proxy/Cargo.toml +++ /dev/null @@ -1,51 +0,0 @@ -[package] -name = "pallet-subtensor-proxy" -version = "40.1.0" -authors = ["Bittensor Nucleus Team"] -edition.workspace = true -license = "Apache-2.0" -homepage = "https://bittensor.com" -description = "FRAME proxying pallet" -readme = "README.md" - -[lints] -workspace = true - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] - -[dependencies] -codec = { workspace = true, features = ["max-encoded-len"] } -frame = { workspace = true, features = ["runtime"] } -scale-info = { workspace = true, features = ["derive"] } -subtensor-macros.workspace = true -frame-system.workspace = true -frame-support.workspace = true - -[dev-dependencies] -pallet-balances = { default-features = true, workspace = true } -pallet-subtensor-utility = { default-features = true, workspace = true } - -[features] -default = ["std"] -std = [ - "codec/std", - "frame/std", - "scale-info/std", - "frame-support/std", - "frame-system/std", -] -runtime-benchmarks = [ - "frame/runtime-benchmarks", - "pallet-balances/runtime-benchmarks", - "pallet-subtensor-utility/runtime-benchmarks", - "frame-support/runtime-benchmarks", - "frame-system/runtime-benchmarks", -] -try-runtime = [ - "frame/try-runtime", - "pallet-balances/try-runtime", - "pallet-subtensor-utility/try-runtime", - "frame-support/try-runtime", - "frame-system/try-runtime", -] diff --git a/pallets/proxy/README.md b/pallets/proxy/README.md deleted file mode 100644 index 290c49c050..0000000000 --- a/pallets/proxy/README.md +++ /dev/null @@ -1,26 +0,0 @@ -# Proxy Module -A module allowing accounts to give permission to other accounts to dispatch types of calls from -their signed origin. - -The accounts to which permission is delegated may be required to announce the action that they -wish to execute some duration prior to execution happens. In this case, the target account may -reject the announcement and in doing so, veto the execution. - -- [`Config`](https://docs.rs/pallet-proxy/latest/pallet_proxy/pallet/trait.Config.html) -- [`Call`](https://docs.rs/pallet-proxy/latest/pallet_proxy/pallet/enum.Call.html) - -## Overview - -## Interface - -### Dispatchable Functions - -[`Call`]: ./enum.Call.html -[`Config`]: ./trait.Config.html - -License: Apache-2.0 - - -## Release - -Polkadot SDK stable2409 diff --git a/pallets/proxy/src/benchmarking.rs b/pallets/proxy/src/benchmarking.rs deleted file mode 100644 index 9bf21cb951..0000000000 --- a/pallets/proxy/src/benchmarking.rs +++ /dev/null @@ -1,518 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Benchmarks for Proxy Pallet - -#![cfg(feature = "runtime-benchmarks")] -#![allow(clippy::arithmetic_side_effects, clippy::unwrap_used)] - -use super::*; -use crate::Pallet as Proxy; -use alloc::{boxed::Box, vec}; -use frame::benchmarking::prelude::{ - BenchmarkError, RawOrigin, account, benchmarks, impl_test_function, whitelisted_caller, -}; - -const SEED: u32 = 0; - -fn assert_last_event( - generic_event: ::RuntimeEvent, -) { - frame_system::Pallet::::assert_last_event(generic_event.into()); -} - -fn assert_has_event(generic_event: ::RuntimeEvent) { - frame_system::Pallet::::assert_has_event(generic_event.into()); -} - -fn add_proxies(n: u32, maybe_who: Option) -> Result<(), &'static str> { - let caller = maybe_who.unwrap_or_else(whitelisted_caller); - T::Currency::make_free_balance_be(&caller, BalanceOf::::max_value() / 2u32.into()); - for i in 0..n { - let real = T::Lookup::unlookup(account("target", i, SEED)); - - Proxy::::add_proxy( - RawOrigin::Signed(caller.clone()).into(), - real, - T::ProxyType::default(), - BlockNumberFor::::zero(), - )?; - } - Ok(()) -} - -fn add_announcements( - n: u32, - maybe_who: Option, - maybe_real: Option, -) -> Result<(), &'static str> { - let caller = maybe_who.unwrap_or_else(|| account("caller", 0, SEED)); - let caller_lookup = T::Lookup::unlookup(caller.clone()); - T::Currency::make_free_balance_be(&caller, BalanceOf::::max_value() / 2u32.into()); - let real = if let Some(real) = maybe_real { - real - } else { - let real = account("real", 0, SEED); - T::Currency::make_free_balance_be(&real, BalanceOf::::max_value() / 2u32.into()); - Proxy::::add_proxy( - RawOrigin::Signed(real.clone()).into(), - caller_lookup, - T::ProxyType::default(), - BlockNumberFor::::zero(), - )?; - real - }; - let real_lookup = T::Lookup::unlookup(real); - for _ in 0..n { - Proxy::::announce( - RawOrigin::Signed(caller.clone()).into(), - real_lookup.clone(), - T::CallHasher::hash_of(&("add_announcement", n)), - )?; - } - Ok(()) -} - -#[benchmarks] -mod benchmarks { - use super::*; - - #[benchmark] - fn proxy(p: Linear<1, { T::MaxProxies::get() - 1 }>) -> Result<(), BenchmarkError> { - add_proxies::(p, None)?; - // In this case the caller is the "target" proxy - let caller: T::AccountId = account("target", p - 1, SEED); - T::Currency::make_free_balance_be(&caller, BalanceOf::::max_value() / 2u32.into()); - // ... and "real" is the traditional caller. This is not a typo. - let real: T::AccountId = whitelisted_caller(); - let real_lookup = T::Lookup::unlookup(real); - let call: ::RuntimeCall = - frame_system::Call::::remark { remark: vec![] }.into(); - - #[extrinsic_call] - _( - RawOrigin::Signed(caller), - real_lookup, - Some(T::ProxyType::default()), - Box::new(call), - ); - - assert_last_event::(Event::ProxyExecuted { result: Ok(()) }.into()); - - Ok(()) - } - - #[benchmark] - fn proxy_announced( - a: Linear<0, { T::MaxPending::get() - 1 }>, - p: Linear<1, { T::MaxProxies::get() - 1 }>, - ) -> Result<(), BenchmarkError> { - add_proxies::(p, None)?; - // In this case the caller is the "target" proxy - let caller: T::AccountId = account("pure", 0, SEED); - let delegate: T::AccountId = account("target", p - 1, SEED); - let delegate_lookup = T::Lookup::unlookup(delegate.clone()); - T::Currency::make_free_balance_be(&delegate, BalanceOf::::max_value() / 2u32.into()); - // ... and "real" is the traditional caller. This is not a typo. - let real: T::AccountId = whitelisted_caller(); - let real_lookup = T::Lookup::unlookup(real); - let call: ::RuntimeCall = - frame_system::Call::::remark { remark: vec![] }.into(); - Proxy::::announce( - RawOrigin::Signed(delegate.clone()).into(), - real_lookup.clone(), - T::CallHasher::hash_of(&call), - )?; - add_announcements::(a, Some(delegate.clone()), None)?; - - #[extrinsic_call] - _( - RawOrigin::Signed(caller), - delegate_lookup, - real_lookup, - Some(T::ProxyType::default()), - Box::new(call), - ); - - assert_last_event::(Event::ProxyExecuted { result: Ok(()) }.into()); - - Ok(()) - } - - #[benchmark] - fn remove_announcement( - a: Linear<0, { T::MaxPending::get() - 1 }>, - p: Linear<1, { T::MaxProxies::get() - 1 }>, - ) -> Result<(), BenchmarkError> { - add_proxies::(p, None)?; - // In this case the caller is the "target" proxy - let caller: T::AccountId = account("target", p - 1, SEED); - T::Currency::make_free_balance_be(&caller, BalanceOf::::max_value() / 2u32.into()); - // ... and "real" is the traditional caller. This is not a typo. - let real: T::AccountId = whitelisted_caller(); - let real_lookup = T::Lookup::unlookup(real); - let call: ::RuntimeCall = - frame_system::Call::::remark { remark: vec![] }.into(); - Proxy::::announce( - RawOrigin::Signed(caller.clone()).into(), - real_lookup.clone(), - T::CallHasher::hash_of(&call), - )?; - add_announcements::(a, Some(caller.clone()), None)?; - - #[extrinsic_call] - _( - RawOrigin::Signed(caller.clone()), - real_lookup, - T::CallHasher::hash_of(&call), - ); - - let (announcements, _) = Announcements::::get(&caller); - assert_eq!(announcements.len() as u32, a); - - Ok(()) - } - - #[benchmark] - fn reject_announcement( - a: Linear<0, { T::MaxPending::get() - 1 }>, - p: Linear<1, { T::MaxProxies::get() - 1 }>, - ) -> Result<(), BenchmarkError> { - add_proxies::(p, None)?; - // In this case the caller is the "target" proxy - let caller: T::AccountId = account("target", p - 1, SEED); - let caller_lookup = T::Lookup::unlookup(caller.clone()); - T::Currency::make_free_balance_be(&caller, BalanceOf::::max_value() / 2u32.into()); - // ... and "real" is the traditional caller. This is not a typo. - let real: T::AccountId = whitelisted_caller(); - let real_lookup = T::Lookup::unlookup(real.clone()); - let call: ::RuntimeCall = - frame_system::Call::::remark { remark: vec![] }.into(); - Proxy::::announce( - RawOrigin::Signed(caller.clone()).into(), - real_lookup, - T::CallHasher::hash_of(&call), - )?; - add_announcements::(a, Some(caller.clone()), None)?; - - #[extrinsic_call] - _( - RawOrigin::Signed(real), - caller_lookup, - T::CallHasher::hash_of(&call), - ); - - let (announcements, _) = Announcements::::get(&caller); - assert_eq!(announcements.len() as u32, a); - - Ok(()) - } - - #[benchmark] - fn announce( - a: Linear<0, { T::MaxPending::get() - 1 }>, - p: Linear<1, { T::MaxProxies::get() - 1 }>, - ) -> Result<(), BenchmarkError> { - add_proxies::(p, None)?; - // In this case the caller is the "target" proxy - let caller: T::AccountId = account("target", p - 1, SEED); - T::Currency::make_free_balance_be(&caller, BalanceOf::::max_value() / 2u32.into()); - // ... and "real" is the traditional caller. This is not a typo. - let real: T::AccountId = whitelisted_caller(); - let real_lookup = T::Lookup::unlookup(real.clone()); - add_announcements::(a, Some(caller.clone()), None)?; - let call: ::RuntimeCall = - frame_system::Call::::remark { remark: vec![] }.into(); - let call_hash = T::CallHasher::hash_of(&call); - - #[extrinsic_call] - _(RawOrigin::Signed(caller.clone()), real_lookup, call_hash); - - assert_last_event::( - Event::Announced { - real, - proxy: caller, - call_hash, - } - .into(), - ); - - Ok(()) - } - - #[benchmark] - fn add_proxy(p: Linear<1, { T::MaxProxies::get() - 1 }>) -> Result<(), BenchmarkError> { - add_proxies::(p, None)?; - let caller: T::AccountId = whitelisted_caller(); - let real = T::Lookup::unlookup(account("target", T::MaxProxies::get(), SEED)); - - #[extrinsic_call] - _( - RawOrigin::Signed(caller.clone()), - real, - T::ProxyType::default(), - BlockNumberFor::::zero(), - ); - - let (proxies, _) = Proxies::::get(caller); - assert_eq!(proxies.len() as u32, p + 1); - - Ok(()) - } - - #[benchmark] - fn remove_proxy(p: Linear<1, { T::MaxProxies::get() - 1 }>) -> Result<(), BenchmarkError> { - add_proxies::(p, None)?; - let caller: T::AccountId = whitelisted_caller(); - let delegate = T::Lookup::unlookup(account("target", 0, SEED)); - - #[extrinsic_call] - _( - RawOrigin::Signed(caller.clone()), - delegate, - T::ProxyType::default(), - BlockNumberFor::::zero(), - ); - - let (proxies, _) = Proxies::::get(caller); - assert_eq!(proxies.len() as u32, p - 1); - - Ok(()) - } - - #[benchmark] - fn remove_proxies(p: Linear<1, { T::MaxProxies::get() - 1 }>) -> Result<(), BenchmarkError> { - add_proxies::(p, None)?; - let caller: T::AccountId = whitelisted_caller(); - - #[extrinsic_call] - _(RawOrigin::Signed(caller.clone())); - - let (proxies, _) = Proxies::::get(caller); - assert_eq!(proxies.len() as u32, 0); - - Ok(()) - } - - #[benchmark] - fn create_pure(p: Linear<1, { T::MaxProxies::get() - 1 }>) -> Result<(), BenchmarkError> { - add_proxies::(p, None)?; - let caller: T::AccountId = whitelisted_caller(); - - #[extrinsic_call] - _( - RawOrigin::Signed(caller.clone()), - T::ProxyType::default(), - BlockNumberFor::::zero(), - 0, - ); - - let pure_account = - Pallet::::pure_account(&caller, &T::ProxyType::default(), 0, None).unwrap(); - assert_last_event::( - Event::PureCreated { - pure: pure_account, - who: caller, - proxy_type: T::ProxyType::default(), - disambiguation_index: 0, - } - .into(), - ); - - Ok(()) - } - - #[benchmark] - fn kill_pure(p: Linear<0, { T::MaxProxies::get() - 2 }>) -> Result<(), BenchmarkError> { - let caller: T::AccountId = whitelisted_caller(); - let caller_lookup = T::Lookup::unlookup(caller.clone()); - T::Currency::make_free_balance_be(&caller, BalanceOf::::max_value()); - Pallet::::create_pure( - RawOrigin::Signed(whitelisted_caller()).into(), - T::ProxyType::default(), - BlockNumberFor::::zero(), - 0, - )?; - let height = T::BlockNumberProvider::current_block_number(); - let ext_index = frame_system::Pallet::::extrinsic_index().unwrap_or(0); - let pure_account = - Pallet::::pure_account(&caller, &T::ProxyType::default(), 0, None).unwrap(); - - add_proxies::(p, Some(pure_account.clone()))?; - ensure!( - Proxies::::contains_key(&pure_account), - "pure proxy not created" - ); - - #[extrinsic_call] - _( - RawOrigin::Signed(pure_account.clone()), - caller_lookup, - T::ProxyType::default(), - 0, - height, - ext_index, - ); - - assert!(!Proxies::::contains_key(&pure_account)); - - Ok(()) - } - - #[benchmark] - fn poke_deposit() -> Result<(), BenchmarkError> { - // Create accounts using the same pattern as other benchmarks - let account_1: T::AccountId = account("account", 1, SEED); - let account_2: T::AccountId = account("account", 2, SEED); - let account_3: T::AccountId = account("account", 3, SEED); - - // Fund accounts - T::Currency::make_free_balance_be(&account_1, BalanceOf::::max_value() / 100u8.into()); - T::Currency::make_free_balance_be(&account_2, BalanceOf::::max_value() / 100u8.into()); - T::Currency::make_free_balance_be(&account_3, BalanceOf::::max_value() / 100u8.into()); - - // Add proxy relationships - Proxy::::add_proxy( - RawOrigin::Signed(account_1.clone()).into(), - T::Lookup::unlookup(account_2.clone()), - T::ProxyType::default(), - BlockNumberFor::::zero(), - )?; - Proxy::::add_proxy( - RawOrigin::Signed(account_2.clone()).into(), - T::Lookup::unlookup(account_3.clone()), - T::ProxyType::default(), - BlockNumberFor::::zero(), - )?; - let (proxies, initial_proxy_deposit) = Proxies::::get(&account_2); - assert!(!initial_proxy_deposit.is_zero()); - assert_eq!( - initial_proxy_deposit, - T::Currency::reserved_balance(&account_2) - ); - - // Create announcement - Proxy::::announce( - RawOrigin::Signed(account_2.clone()).into(), - T::Lookup::unlookup(account_1.clone()), - T::CallHasher::hash_of(&("add_announcement", 1)), - )?; - let (announcements, initial_announcement_deposit) = Announcements::::get(&account_2); - assert!(!initial_announcement_deposit.is_zero()); - assert_eq!( - initial_announcement_deposit.saturating_add(initial_proxy_deposit), - T::Currency::reserved_balance(&account_2) - ); - - // Artificially inflate deposits and reserve the extra amount - let extra_proxy_deposit = initial_proxy_deposit; // Double the deposit - let extra_announcement_deposit = initial_announcement_deposit; // Double the deposit - let total = extra_proxy_deposit.saturating_add(extra_announcement_deposit); - - T::Currency::reserve(&account_2, total)?; - - let initial_reserved = T::Currency::reserved_balance(&account_2); - assert_eq!(initial_reserved, total.saturating_add(total)); // Double - - // Update storage with increased deposits - Proxies::::insert( - &account_2, - ( - proxies, - initial_proxy_deposit.saturating_add(extra_proxy_deposit), - ), - ); - Announcements::::insert( - &account_2, - ( - announcements, - initial_announcement_deposit.saturating_add(extra_announcement_deposit), - ), - ); - - // Verify artificial state - let (_, inflated_proxy_deposit) = Proxies::::get(&account_2); - let (_, inflated_announcement_deposit) = Announcements::::get(&account_2); - assert_eq!( - inflated_proxy_deposit, - initial_proxy_deposit.saturating_add(extra_proxy_deposit) - ); - assert_eq!( - inflated_announcement_deposit, - initial_announcement_deposit.saturating_add(extra_announcement_deposit) - ); - - #[extrinsic_call] - _(RawOrigin::Signed(account_2.clone())); - - // Verify results - let (_, final_proxy_deposit) = Proxies::::get(&account_2); - let (_, final_announcement_deposit) = Announcements::::get(&account_2); - assert_eq!(final_proxy_deposit, initial_proxy_deposit); - assert_eq!(final_announcement_deposit, initial_announcement_deposit); - - let final_reserved = T::Currency::reserved_balance(&account_2); - assert_eq!(final_reserved, initial_reserved.saturating_sub(total)); - - // Verify events - assert_has_event::( - Event::DepositPoked { - who: account_2.clone(), - kind: DepositKind::Proxies, - old_deposit: inflated_proxy_deposit, - new_deposit: final_proxy_deposit, - } - .into(), - ); - assert_last_event::( - Event::DepositPoked { - who: account_2, - kind: DepositKind::Announcements, - old_deposit: inflated_announcement_deposit, - new_deposit: final_announcement_deposit, - } - .into(), - ); - - Ok(()) - } - - #[benchmark] - fn set_real_pays_fee(p: Linear<1, { T::MaxProxies::get() - 1 }>) -> Result<(), BenchmarkError> { - add_proxies::(p, None)?; - let caller: T::AccountId = whitelisted_caller(); - let delegate: T::AccountId = account("target", 0, SEED); - let delegate_lookup = T::Lookup::unlookup(delegate.clone()); - - #[extrinsic_call] - _(RawOrigin::Signed(caller.clone()), delegate_lookup, true); - - assert!(RealPaysFee::::contains_key(&caller, &delegate)); - assert_last_event::( - Event::RealPaysFeeSet { - real: caller, - delegate, - pays_fee: true, - } - .into(), - ); - - Ok(()) - } - - impl_benchmark_test_suite!(Proxy, crate::tests::new_test_ext(), crate::tests::Test); -} diff --git a/pallets/proxy/src/lib.rs b/pallets/proxy/src/lib.rs deleted file mode 100644 index 1fca855327..0000000000 --- a/pallets/proxy/src/lib.rs +++ /dev/null @@ -1,1154 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//! # Proxy Pallet -//! A pallet allowing accounts to give permission to other accounts to dispatch types of calls from -//! their signed origin. -//! -//! The accounts to which permission is delegated may be required to announce the action that they -//! wish to execute some duration prior to execution happens. In this case, the target account may -//! reject the announcement and in doing so, veto the execution. -//! -//! - [`Config`] -//! - [`Call`] - -// Ensure we're `no_std` when compiling for Wasm. -#![cfg_attr(not(feature = "std"), no_std)] - -mod benchmarking; -mod tests; -pub mod weights; - -extern crate alloc; -use alloc::{boxed::Box, vec}; -use frame::{ - prelude::*, - traits::{Currency, InstanceFilter, ReservableCurrency}, -}; -use frame_system::pallet_prelude::BlockNumberFor as SystemBlockNumberFor; -pub use pallet::*; -use subtensor_macros::freeze_struct; -pub use weights::WeightInfo; - -type CallHashOf = <::CallHasher as Hash>::Output; - -type BalanceOf = - <::Currency as Currency<::AccountId>>::Balance; - -pub type BlockNumberFor = - <::BlockNumberProvider as BlockNumberProvider>::BlockNumber; - -type AccountIdLookupOf = <::Lookup as StaticLookup>::Source; - -/// The parameters under which a particular account has a proxy relationship with some other -/// account. -#[derive( - Encode, - Decode, - DecodeWithMemTracking, - Clone, - Copy, - Eq, - PartialEq, - Ord, - PartialOrd, - RuntimeDebug, - MaxEncodedLen, - TypeInfo, -)] -#[freeze_struct("a37bb67fe5520678")] -pub struct ProxyDefinition { - /// The account which may act on behalf of another. - pub delegate: AccountId, - /// A value defining the subset of calls that it is allowed to make. - pub proxy_type: ProxyType, - /// The number of blocks that an announcement must be in place for before the corresponding - /// call may be dispatched. If zero, then no announcement is needed. - pub delay: BlockNumber, -} - -/// Details surrounding a specific instance of an announcement to make a call. -#[derive(Encode, Decode, Clone, Copy, Eq, PartialEq, RuntimeDebug, MaxEncodedLen, TypeInfo)] -#[freeze_struct("4c1b5c8c3bc489ad")] -pub struct Announcement { - /// The account which made the announcement. - real: AccountId, - /// The hash of the call to be made. - call_hash: Hash, - /// The height at which the announcement was made. - height: BlockNumber, -} - -/// The type of deposit -#[derive( - Encode, - Decode, - Clone, - Copy, - Eq, - PartialEq, - RuntimeDebug, - MaxEncodedLen, - TypeInfo, - DecodeWithMemTracking, -)] -pub enum DepositKind { - /// Proxy registration deposit - Proxies, - /// Announcement deposit - Announcements, -} - -#[frame::pallet] -#[allow(clippy::expect_used)] -pub mod pallet { - use super::*; - - #[pallet::pallet] - pub struct Pallet(_); - - /// Configuration trait. - #[pallet::config] - pub trait Config: frame_system::Config { - /// The overarching call type. - type RuntimeCall: Parameter - + Dispatchable - + GetDispatchInfo - + From> - + IsSubType> - + IsType<::RuntimeCall>; - - /// The currency mechanism. - type Currency: ReservableCurrency; - - /// A kind of proxy; specified with the proxy and passed in to the `IsProxyable` filter. - /// The instance filter determines whether a given call may be proxied under this type. - /// - /// IMPORTANT: `Default` must be provided and MUST BE the the *most permissive* value. - type ProxyType: Parameter - + Member - + Ord - + PartialOrd - + frame::traits::InstanceFilter<::RuntimeCall> - + Default - + MaxEncodedLen; - - /// The base amount of currency needed to reserve for creating a proxy. - /// - /// This is held for an additional storage item whose value size is - /// `sizeof(Balance)` bytes and whose key size is `sizeof(AccountId)` bytes. - #[pallet::constant] - type ProxyDepositBase: Get>; - - /// The amount of currency needed per proxy added. - /// - /// This is held for adding 32 bytes plus an instance of `ProxyType` more into a - /// pre-existing storage value. Thus, when configuring `ProxyDepositFactor` one should take - /// into account `32 + proxy_type.encode().len()` bytes of data. - #[pallet::constant] - type ProxyDepositFactor: Get>; - - /// The maximum amount of proxies allowed for a single account. - #[pallet::constant] - type MaxProxies: Get; - - /// Weight information for extrinsics in this pallet. - type WeightInfo: WeightInfo; - - /// The maximum amount of time-delayed announcements that are allowed to be pending. - #[pallet::constant] - type MaxPending: Get; - - /// The type of hash used for hashing the call. - type CallHasher: Hash; - - /// The base amount of currency needed to reserve for creating an announcement. - /// - /// This is held when a new storage item holding a `Balance` is created (typically 16 - /// bytes). - #[pallet::constant] - type AnnouncementDepositBase: Get>; - - /// The amount of currency needed per announcement made. - /// - /// This is held for adding an `AccountId`, `Hash` and `BlockNumber` (typically 68 bytes) - /// into a pre-existing storage value. - #[pallet::constant] - type AnnouncementDepositFactor: Get>; - - /// Query the current block number. - /// - /// Must return monotonically increasing values when called from consecutive blocks. - /// Can be configured to return either: - /// - the local block number of the runtime via `frame_system::Pallet` - /// - a remote block number, eg from the relay chain through `RelaychainDataProvider` - /// - an arbitrary value through a custom implementation of the trait - /// - /// There is currently no migration provided to "hot-swap" block number providers and it may - /// result in undefined behavior when doing so. Parachains are therefore best off setting - /// this to their local block number provider if they have the pallet already deployed. - /// - /// Suggested values: - /// - Solo- and Relay-chains: `frame_system::Pallet` - /// - Parachains that may produce blocks sparingly or only when needed (on-demand): - /// - already have the pallet deployed: `frame_system::Pallet` - /// - are freshly deploying this pallet: `RelaychainDataProvider` - /// - Parachains with a reliably block production rate (PLO or bulk-coretime): - /// - already have the pallet deployed: `frame_system::Pallet` - /// - are freshly deploying this pallet: no strong recommendation. Both local and remote - /// providers can be used. Relay provider can be a bit better in cases where the - /// parachain is lagging its block production to avoid clock skew. - type BlockNumberProvider: BlockNumberProvider; - } - - #[pallet::call] - impl Pallet { - #![deny(clippy::expect_used)] - - /// Dispatch the given `call` from an account that the sender is authorised for through - /// `add_proxy`. - /// - /// The dispatch origin for this call must be _Signed_. - /// - /// Parameters: - /// - `real`: The account that the proxy will make a call on behalf of. - /// - `force_proxy_type`: Specify the exact proxy type to be used and checked for this call. - /// - `call`: The call to be made by the `real` account. - #[pallet::call_index(0)] - #[pallet::weight({ - let di = call.get_dispatch_info(); - (T::WeightInfo::proxy(T::MaxProxies::get()) - // AccountData for inner call origin accountdata. - .saturating_add(T::DbWeight::get().reads_writes(1, 1)) - .saturating_add(di.call_weight), - DispatchClass::Normal, di.pays_fee) - })] - pub fn proxy( - origin: OriginFor, - real: AccountIdLookupOf, - force_proxy_type: Option, - call: Box<::RuntimeCall>, - ) -> DispatchResult { - let who = ensure_signed(origin)?; - let real = T::Lookup::lookup(real)?; - let def = Self::find_proxy(&real, &who, force_proxy_type)?; - ensure!(def.delay.is_zero(), Error::::Unannounced); - - Self::do_proxy(def, real, *call); - - Ok(()) - } - - /// Register a proxy account for the sender that is able to make calls on its behalf. - /// - /// The dispatch origin for this call must be _Signed_. - /// - /// Parameters: - /// - `proxy`: The account that the `caller` would like to make a proxy. - /// - `proxy_type`: The permissions allowed for this proxy account. - /// - `delay`: The announcement period required of the initial proxy. Will generally be - /// zero. - #[pallet::call_index(1)] - #[pallet::weight(T::WeightInfo::add_proxy(T::MaxProxies::get()))] - pub fn add_proxy( - origin: OriginFor, - delegate: AccountIdLookupOf, - proxy_type: T::ProxyType, - delay: BlockNumberFor, - ) -> DispatchResult { - let who = ensure_signed(origin)?; - let delegate = T::Lookup::lookup(delegate)?; - Self::add_proxy_delegate(&who, delegate, proxy_type, delay) - } - - /// Unregister a proxy account for the sender. - /// - /// The dispatch origin for this call must be _Signed_. - /// - /// Parameters: - /// - `proxy`: The account that the `caller` would like to remove as a proxy. - /// - `proxy_type`: The permissions currently enabled for the removed proxy account. - #[pallet::call_index(2)] - #[pallet::weight(T::WeightInfo::remove_proxy(T::MaxProxies::get()))] - pub fn remove_proxy( - origin: OriginFor, - delegate: AccountIdLookupOf, - proxy_type: T::ProxyType, - delay: BlockNumberFor, - ) -> DispatchResult { - let who = ensure_signed(origin)?; - let delegate = T::Lookup::lookup(delegate)?; - Self::remove_proxy_delegate(&who, delegate, proxy_type, delay) - } - - /// Unregister all proxy accounts for the sender. - /// - /// The dispatch origin for this call must be _Signed_. - /// - /// WARNING: This may be called on accounts created by `create_pure`, however if done, then - /// the unreserved fees will be inaccessible. **All access to this account will be lost.** - #[pallet::call_index(3)] - #[pallet::weight(T::WeightInfo::remove_proxies(T::MaxProxies::get()))] - pub fn remove_proxies(origin: OriginFor) -> DispatchResult { - let who = ensure_signed(origin)?; - Self::remove_all_proxy_delegates(&who); - Ok(()) - } - - /// Spawn a fresh new account that is guaranteed to be otherwise inaccessible, and - /// initialize it with a proxy of `proxy_type` for `origin` sender. - /// - /// Requires a `Signed` origin. - /// - /// - `proxy_type`: The type of the proxy that the sender will be registered as over the - /// new account. This will almost always be the most permissive `ProxyType` possible to - /// allow for maximum flexibility. - /// - `index`: A disambiguation index, in case this is called multiple times in the same - /// transaction (e.g. with `utility::batch`). Unless you're using `batch` you probably just - /// want to use `0`. - /// - `delay`: The announcement period required of the initial proxy. Will generally be - /// zero. - /// - /// Fails with `Duplicate` if this has already been called in this transaction, from the - /// same sender, with the same parameters. - /// - /// Fails if there are insufficient funds to pay for deposit. - #[pallet::call_index(4)] - #[pallet::weight(T::WeightInfo::create_pure(T::MaxProxies::get()))] - pub fn create_pure( - origin: OriginFor, - proxy_type: T::ProxyType, - delay: BlockNumberFor, - index: u16, - ) -> DispatchResult { - let who = ensure_signed(origin)?; - - let pure = Self::pure_account(&who, &proxy_type, index, None)?; - ensure!(!Proxies::::contains_key(&pure), Error::::Duplicate); - - let proxy_def = ProxyDefinition { - delegate: who.clone(), - proxy_type: proxy_type.clone(), - delay, - }; - let bounded_proxies: BoundedVec<_, T::MaxProxies> = vec![proxy_def] - .try_into() - .map_err(|_| Error::::TooMany)?; - - let deposit = T::ProxyDepositBase::get().saturating_add(T::ProxyDepositFactor::get()); - T::Currency::reserve(&who, deposit)?; - - Proxies::::insert(&pure, (bounded_proxies, deposit)); - Self::deposit_event(Event::PureCreated { - pure, - who, - proxy_type, - disambiguation_index: index, - }); - - Ok(()) - } - - /// Removes a previously spawned pure proxy. - /// - /// WARNING: **All access to this account will be lost.** Any funds held in it will be - /// inaccessible. - /// - /// Requires a `Signed` origin, and the sender account must have been created by a call to - /// `create_pure` with corresponding parameters. - /// - /// - `spawner`: The account that originally called `create_pure` to create this account. - /// - `index`: The disambiguation index originally passed to `create_pure`. Probably `0`. - /// - `proxy_type`: The proxy type originally passed to `create_pure`. - /// - `height`: The height of the chain when the call to `create_pure` was processed. - /// - `ext_index`: The extrinsic index in which the call to `create_pure` was processed. - /// - /// Fails with `NoPermission` in case the caller is not a previously created pure - /// account whose `create_pure` call has corresponding parameters. - #[pallet::call_index(5)] - #[pallet::weight(T::WeightInfo::kill_pure(T::MaxProxies::get()))] - pub fn kill_pure( - origin: OriginFor, - spawner: AccountIdLookupOf, - proxy_type: T::ProxyType, - index: u16, - #[pallet::compact] height: BlockNumberFor, - #[pallet::compact] ext_index: u32, - ) -> DispatchResult { - let who = ensure_signed(origin)?; - let spawner = T::Lookup::lookup(spawner)?; - - let when = (height, ext_index); - let proxy = Self::pure_account(&spawner, &proxy_type, index, Some(when))?; - ensure!(proxy == who, Error::::NoPermission); - - let (_, deposit) = Proxies::::take(&who); - T::Currency::unreserve(&spawner, deposit); - - Self::deposit_event(Event::PureKilled { - pure: who, - spawner, - proxy_type, - disambiguation_index: index, - }); - - Ok(()) - } - - /// Publish the hash of a proxy-call that will be made in the future. - /// - /// This must be called some number of blocks before the corresponding `proxy` is attempted - /// if the delay associated with the proxy relationship is greater than zero. - /// - /// No more than `MaxPending` announcements may be made at any one time. - /// - /// This will take a deposit of `AnnouncementDepositFactor` as well as - /// `AnnouncementDepositBase` if there are no other pending announcements. - /// - /// The dispatch origin for this call must be _Signed_ and a proxy of `real`. - /// - /// Parameters: - /// - `real`: The account that the proxy will make a call on behalf of. - /// - `call_hash`: The hash of the call to be made by the `real` account. - #[pallet::call_index(6)] - #[pallet::weight(T::WeightInfo::announce(T::MaxPending::get(), T::MaxProxies::get()))] - pub fn announce( - origin: OriginFor, - real: AccountIdLookupOf, - call_hash: CallHashOf, - ) -> DispatchResult { - let who = ensure_signed(origin)?; - let real = T::Lookup::lookup(real)?; - Proxies::::get(&real) - .0 - .into_iter() - .find(|x| x.delegate == who) - .ok_or(Error::::NotProxy)?; - - let announcement = Announcement { - real: real.clone(), - call_hash, - height: T::BlockNumberProvider::current_block_number(), - }; - - Announcements::::try_mutate(&who, |(pending, deposit)| { - pending - .try_push(announcement) - .map_err(|_| Error::::TooMany)?; - let new_deposit = Self::rejig_deposit( - &who, - *deposit, - T::AnnouncementDepositBase::get(), - T::AnnouncementDepositFactor::get(), - pending.len(), - )? - .ok_or(Error::::AnnouncementDepositInvariantViolated)?; - - *deposit = new_deposit; - Ok::<(), DispatchError>(()) - })?; - - Self::deposit_event(Event::Announced { - real, - proxy: who, - call_hash, - }); - Ok(()) - } - - /// Remove a given announcement. - /// - /// May be called by a proxy account to remove a call they previously announced and return - /// the deposit. - /// - /// The dispatch origin for this call must be _Signed_. - /// - /// Parameters: - /// - `real`: The account that the proxy will make a call on behalf of. - /// - `call_hash`: The hash of the call to be made by the `real` account. - #[pallet::call_index(7)] - #[pallet::weight(T::WeightInfo::remove_announcement( - T::MaxPending::get(), - T::MaxProxies::get() - ))] - pub fn remove_announcement( - origin: OriginFor, - real: AccountIdLookupOf, - call_hash: CallHashOf, - ) -> DispatchResult { - let who = ensure_signed(origin)?; - let real = T::Lookup::lookup(real)?; - Self::edit_announcements(&who, |ann| ann.real != real || ann.call_hash != call_hash)?; - - Ok(()) - } - - /// Remove the given announcement of a delegate. - /// - /// May be called by a target (proxied) account to remove a call that one of their delegates - /// (`delegate`) has announced they want to execute. The deposit is returned. - /// - /// The dispatch origin for this call must be _Signed_. - /// - /// Parameters: - /// - `delegate`: The account that previously announced the call. - /// - `call_hash`: The hash of the call to be made. - #[pallet::call_index(8)] - #[pallet::weight(T::WeightInfo::reject_announcement( - T::MaxPending::get(), - T::MaxProxies::get() - ))] - pub fn reject_announcement( - origin: OriginFor, - delegate: AccountIdLookupOf, - call_hash: CallHashOf, - ) -> DispatchResult { - let who = ensure_signed(origin)?; - let delegate = T::Lookup::lookup(delegate)?; - Self::edit_announcements(&delegate, |ann| { - ann.real != who || ann.call_hash != call_hash - })?; - - Ok(()) - } - - /// Dispatch the given `call` from an account that the sender is authorized for through - /// `add_proxy`. - /// - /// Removes any corresponding announcement(s). - /// - /// The dispatch origin for this call must be _Signed_. - /// - /// Parameters: - /// - `real`: The account that the proxy will make a call on behalf of. - /// - `force_proxy_type`: Specify the exact proxy type to be used and checked for this call. - /// - `call`: The call to be made by the `real` account. - #[pallet::call_index(9)] - #[pallet::weight({ - let di = call.get_dispatch_info(); - (T::WeightInfo::proxy_announced(T::MaxPending::get(), T::MaxProxies::get()) - // AccountData for inner call origin accountdata. - .saturating_add(T::DbWeight::get().reads_writes(1, 1)) - .saturating_add(di.call_weight), - DispatchClass::Normal) - })] - pub fn proxy_announced( - origin: OriginFor, - delegate: AccountIdLookupOf, - real: AccountIdLookupOf, - force_proxy_type: Option, - call: Box<::RuntimeCall>, - ) -> DispatchResult { - ensure_signed(origin)?; - let delegate = T::Lookup::lookup(delegate)?; - let real = T::Lookup::lookup(real)?; - let def = Self::find_proxy(&real, &delegate, force_proxy_type)?; - - let call_hash = T::CallHasher::hash_of(&call); - let now = T::BlockNumberProvider::current_block_number(); - Self::edit_announcements(&delegate, |ann| { - ann.real != real - || ann.call_hash != call_hash - || now.saturating_sub(ann.height) < def.delay - }) - .map_err(|_| Error::::Unannounced)?; - - Self::do_proxy(def, real, *call); - - Ok(()) - } - - /// Poke / Adjust deposits made for proxies and announcements based on current values. - /// This can be used by accounts to possibly lower their locked amount. - /// - /// The dispatch origin for this call must be _Signed_. - /// - /// The transaction fee is waived if the deposit amount has changed. - /// - /// Emits `DepositPoked` if successful. - #[pallet::call_index(10)] - #[pallet::weight(T::WeightInfo::poke_deposit())] - pub fn poke_deposit(origin: OriginFor) -> DispatchResultWithPostInfo { - let who = ensure_signed(origin)?; - let mut deposit_updated = false; - - // Check and update proxy deposits - Proxies::::try_mutate_exists(&who, |maybe_proxies| -> DispatchResult { - let (proxies, old_deposit) = maybe_proxies.take().unwrap_or_default(); - let maybe_new_deposit = Self::rejig_deposit( - &who, - old_deposit, - T::ProxyDepositBase::get(), - T::ProxyDepositFactor::get(), - proxies.len(), - )?; - - match maybe_new_deposit { - Some(new_deposit) if new_deposit != old_deposit => { - *maybe_proxies = Some((proxies, new_deposit)); - deposit_updated = true; - Self::deposit_event(Event::DepositPoked { - who: who.clone(), - kind: DepositKind::Proxies, - old_deposit, - new_deposit, - }); - } - Some(_) => { - *maybe_proxies = Some((proxies, old_deposit)); - } - None => { - *maybe_proxies = None; - if !old_deposit.is_zero() { - deposit_updated = true; - Self::deposit_event(Event::DepositPoked { - who: who.clone(), - kind: DepositKind::Proxies, - old_deposit, - new_deposit: BalanceOf::::zero(), - }); - } - } - } - Ok(()) - })?; - - // Check and update announcement deposits - Announcements::::try_mutate_exists(&who, |maybe_announcements| -> DispatchResult { - let (announcements, old_deposit) = maybe_announcements.take().unwrap_or_default(); - let maybe_new_deposit = Self::rejig_deposit( - &who, - old_deposit, - T::AnnouncementDepositBase::get(), - T::AnnouncementDepositFactor::get(), - announcements.len(), - )?; - - match maybe_new_deposit { - Some(new_deposit) if new_deposit != old_deposit => { - *maybe_announcements = Some((announcements, new_deposit)); - deposit_updated = true; - Self::deposit_event(Event::DepositPoked { - who: who.clone(), - kind: DepositKind::Announcements, - old_deposit, - new_deposit, - }); - } - Some(_) => { - *maybe_announcements = Some((announcements, old_deposit)); - } - None => { - *maybe_announcements = None; - if !old_deposit.is_zero() { - deposit_updated = true; - Self::deposit_event(Event::DepositPoked { - who: who.clone(), - kind: DepositKind::Announcements, - old_deposit, - new_deposit: BalanceOf::::zero(), - }); - } - } - } - Ok(()) - })?; - - Ok(if deposit_updated { - Pays::No.into() - } else { - Pays::Yes.into() - }) - } - - /// Set whether the real account pays transaction fees for proxy calls made by a - /// specific delegate. - /// - /// The dispatch origin for this call must be _Signed_ and must be the real (delegator) - /// account that has an existing proxy relationship with the delegate. - /// - /// Parameters: - /// - `delegate`: The proxy account for which to set the fee payment preference. - /// - `pays_fee`: If `true`, the real account will pay fees for proxy calls made by - /// this delegate. If `false`, the delegate pays (default behavior). - #[pallet::call_index(11)] - #[pallet::weight(T::WeightInfo::set_real_pays_fee(T::MaxProxies::get()))] - pub fn set_real_pays_fee( - origin: OriginFor, - delegate: AccountIdLookupOf, - pays_fee: bool, - ) -> DispatchResult { - let real = ensure_signed(origin)?; - let delegate = T::Lookup::lookup(delegate)?; - - // Verify proxy relationship exists - Self::find_proxy(&real, &delegate, None)?; - - if pays_fee { - RealPaysFee::::insert(&real, &delegate, ()); - } else { - RealPaysFee::::remove(&real, &delegate); - } - - Self::deposit_event(Event::RealPaysFeeSet { - real, - delegate, - pays_fee, - }); - - Ok(()) - } - } - - #[pallet::event] - #[pallet::generate_deposit(pub(super) fn deposit_event)] - pub enum Event { - /// A proxy was executed correctly, with the given. - ProxyExecuted { result: DispatchResult }, - /// A pure account has been created by new proxy with given - /// disambiguation index and proxy type. - PureCreated { - pure: T::AccountId, - who: T::AccountId, - proxy_type: T::ProxyType, - disambiguation_index: u16, - }, - /// A pure proxy was killed by its spawner. - PureKilled { - // The pure proxy account that was destroyed. - pure: T::AccountId, - // The account that created the pure proxy. - spawner: T::AccountId, - // The proxy type of the pure proxy that was destroyed. - proxy_type: T::ProxyType, - // The index originally passed to `create_pure` when this pure proxy was created. - disambiguation_index: u16, - }, - /// An announcement was placed to make a call in the future. - Announced { - real: T::AccountId, - proxy: T::AccountId, - call_hash: CallHashOf, - }, - /// A proxy was added. - ProxyAdded { - delegator: T::AccountId, - delegatee: T::AccountId, - proxy_type: T::ProxyType, - delay: BlockNumberFor, - }, - /// A proxy was removed. - ProxyRemoved { - delegator: T::AccountId, - delegatee: T::AccountId, - proxy_type: T::ProxyType, - delay: BlockNumberFor, - }, - /// A deposit stored for proxies or announcements was poked / updated. - DepositPoked { - who: T::AccountId, - kind: DepositKind, - old_deposit: BalanceOf, - new_deposit: BalanceOf, - }, - /// The real-pays-fee setting was updated for a proxy relationship. - RealPaysFeeSet { - real: T::AccountId, - delegate: T::AccountId, - pays_fee: bool, - }, - } - - #[pallet::error] - pub enum Error { - /// There are too many proxies registered or too many announcements pending. - TooMany, - /// Proxy registration not found. - NotFound, - /// Sender is not a proxy of the account to be proxied. - NotProxy, - /// A call which is incompatible with the proxy type's filter was attempted. - Unproxyable, - /// Account is already a proxy. - Duplicate, - /// Call may not be made by proxy because it may escalate its privileges. - NoPermission, - /// Announcement, if made at all, was made too recently. - Unannounced, - /// Cannot add self as proxy. - NoSelfProxy, - /// Invariant violated: deposit recomputation returned None after updating announcements. - AnnouncementDepositInvariantViolated, - /// Failed to derive a valid account id from the provided entropy. - InvalidDerivedAccountId, - } - - #[pallet::hooks] - impl Hooks> for Pallet { - fn on_finalize(_n: SystemBlockNumberFor) { - // clear this map on end of each block - let _ = LastCallResult::::clear(u32::MAX, None); - } - } - - /// The set of account proxies. Maps the account which has delegated to the accounts - /// which are being delegated to, together with the amount held on deposit. - #[pallet::storage] - pub type Proxies = StorageMap< - _, - Twox64Concat, - T::AccountId, - ( - BoundedVec< - ProxyDefinition>, - T::MaxProxies, - >, - BalanceOf, - ), - ValueQuery, - >; - - /// The announcements made by the proxy (key). - #[pallet::storage] - pub type Announcements = StorageMap< - _, - Twox64Concat, - T::AccountId, - ( - BoundedVec, BlockNumberFor>, T::MaxPending>, - BalanceOf, - ), - ValueQuery, - >; - - /// The result of the last call made by the proxy (key). - #[pallet::storage] - pub type LastCallResult = - StorageMap<_, Twox64Concat, T::AccountId, DispatchResult, OptionQuery>; - - /// Tracks which (real, delegate) pairs have opted in to the real account paying - /// transaction fees for proxy calls made by the delegate. - /// Existence of an entry means the real account pays; absence means the delegate pays - /// (default). - #[pallet::storage] - pub type RealPaysFee = StorageDoubleMap< - _, - Twox64Concat, - T::AccountId, // real - Twox64Concat, - T::AccountId, // delegate - (), - OptionQuery, - >; - - #[pallet::view_functions] - impl Pallet { - /// Check if a `RuntimeCall` is allowed for a given `ProxyType`. - pub fn check_permissions( - call: ::RuntimeCall, - proxy_type: T::ProxyType, - ) -> bool { - proxy_type.filter(&call) - } - - /// Check if one `ProxyType` is a subset of another `ProxyType`. - pub fn is_superset(to_check: T::ProxyType, against: T::ProxyType) -> bool { - to_check.is_superset(&against) - } - } -} - -impl Pallet { - /// Public function to proxies storage. - pub fn proxies( - account: T::AccountId, - ) -> ( - BoundedVec>, T::MaxProxies>, - BalanceOf, - ) { - Proxies::::get(account) - } - - /// Public function to announcements storage. - pub fn announcements( - account: T::AccountId, - ) -> ( - BoundedVec, BlockNumberFor>, T::MaxPending>, - BalanceOf, - ) { - Announcements::::get(account) - } - - /// Calculate the address of an pure account. - /// - /// - `who`: The spawner account. - /// - `proxy_type`: The type of the proxy that the sender will be registered as over the - /// new account. This will almost always be the most permissive `ProxyType` possible to - /// allow for maximum flexibility. - /// - `index`: A disambiguation index, in case this is called multiple times in the same - /// transaction (e.g. with `utility::batch`). Unless you're using `batch` you probably just - /// want to use `0`. - /// - `maybe_when`: The block height and extrinsic index of when the pure account was - /// created. None to use current block height and extrinsic index. - pub fn pure_account( - who: &T::AccountId, - proxy_type: &T::ProxyType, - index: u16, - maybe_when: Option<(BlockNumberFor, u32)>, - ) -> Result { - let (height, ext_index) = maybe_when.unwrap_or_else(|| { - ( - T::BlockNumberProvider::current_block_number(), - frame_system::Pallet::::extrinsic_index().unwrap_or_default(), - ) - }); - let entropy = ( - b"modlpy/proxy____", - who, - height, - ext_index, - proxy_type, - index, - ) - .using_encoded(blake2_256); - - T::AccountId::decode(&mut TrailingZeroInput::new(entropy.as_ref())) - .map_err(|_| Error::::InvalidDerivedAccountId.into()) - } - - /// Register a proxy account for the delegator that is able to make calls on its behalf. - /// - /// Parameters: - /// - `delegator`: The delegator account. - /// - `delegatee`: The account that the `delegator` would like to make a proxy. - /// - `proxy_type`: The permissions allowed for this proxy account. - /// - `delay`: The announcement period required of the initial proxy. Will generally be - /// zero. - pub fn add_proxy_delegate( - delegator: &T::AccountId, - delegatee: T::AccountId, - proxy_type: T::ProxyType, - delay: BlockNumberFor, - ) -> DispatchResult { - ensure!(delegator != &delegatee, Error::::NoSelfProxy); - Proxies::::try_mutate(delegator, |(proxies, deposit)| { - let proxy_def = ProxyDefinition { - delegate: delegatee.clone(), - proxy_type: proxy_type.clone(), - delay, - }; - let i = proxies - .binary_search(&proxy_def) - .err() - .ok_or(Error::::Duplicate)?; - proxies - .try_insert(i, proxy_def) - .map_err(|_| Error::::TooMany)?; - let new_deposit = Self::deposit(proxies.len() as u32); - if new_deposit > *deposit { - T::Currency::reserve(delegator, new_deposit.saturating_sub(*deposit))?; - } else if new_deposit < *deposit { - T::Currency::unreserve(delegator, (*deposit).saturating_sub(new_deposit)); - } - *deposit = new_deposit; - Self::deposit_event(Event::::ProxyAdded { - delegator: delegator.clone(), - delegatee, - proxy_type, - delay, - }); - Ok(()) - }) - } - - /// Unregister a proxy account for the delegator. - /// - /// Parameters: - /// - `delegator`: The delegator account. - /// - `delegatee`: The account that the `delegator` would like to make a proxy. - /// - `proxy_type`: The permissions allowed for this proxy account. - /// - `delay`: The announcement period required of the initial proxy. Will generally be - /// zero. - pub fn remove_proxy_delegate( - delegator: &T::AccountId, - delegatee: T::AccountId, - proxy_type: T::ProxyType, - delay: BlockNumberFor, - ) -> DispatchResult { - Proxies::::try_mutate_exists(delegator, |x| { - let (mut proxies, old_deposit) = x.take().ok_or(Error::::NotFound)?; - let proxy_def = ProxyDefinition { - delegate: delegatee.clone(), - proxy_type: proxy_type.clone(), - delay, - }; - let i = proxies - .binary_search(&proxy_def) - .ok() - .ok_or(Error::::NotFound)?; - proxies.remove(i); - let new_deposit = Self::deposit(proxies.len() as u32); - if new_deposit > old_deposit { - T::Currency::reserve(delegator, new_deposit.saturating_sub(old_deposit))?; - } else if new_deposit < old_deposit { - T::Currency::unreserve(delegator, old_deposit.saturating_sub(new_deposit)); - } - if !proxies.is_empty() { - *x = Some((proxies, new_deposit)) - } - // Clean up real-pays-fee flag for this specific proxy relationship - RealPaysFee::::remove(delegator, &delegatee); - - Self::deposit_event(Event::::ProxyRemoved { - delegator: delegator.clone(), - delegatee, - proxy_type, - delay, - }); - Ok(()) - }) - } - - pub fn deposit(num_proxies: u32) -> BalanceOf { - if num_proxies == 0 { - Zero::zero() - } else { - T::ProxyDepositBase::get() - .saturating_add(T::ProxyDepositFactor::get().saturating_mul(num_proxies.into())) - } - } - - fn rejig_deposit( - who: &T::AccountId, - old_deposit: BalanceOf, - base: BalanceOf, - factor: BalanceOf, - len: usize, - ) -> Result>, DispatchError> { - let new_deposit = if len == 0 { - BalanceOf::::zero() - } else { - base.saturating_add(factor.saturating_mul((len as u32).into())) - }; - if new_deposit > old_deposit { - T::Currency::reserve(who, new_deposit.saturating_sub(old_deposit))?; - } else if new_deposit < old_deposit { - let excess = old_deposit.saturating_sub(new_deposit); - let remaining_unreserved = T::Currency::unreserve(who, excess); - if !remaining_unreserved.is_zero() { - defensive!( - "Failed to unreserve full amount. (Requested, Actual)", - (excess, excess.saturating_sub(remaining_unreserved)) - ); - } - } - Ok(if len == 0 { None } else { Some(new_deposit) }) - } - - fn edit_announcements< - F: FnMut(&Announcement, BlockNumberFor>) -> bool, - >( - delegate: &T::AccountId, - f: F, - ) -> DispatchResult { - Announcements::::try_mutate_exists(delegate, |x| { - let (mut pending, old_deposit) = x.take().ok_or(Error::::NotFound)?; - let orig_pending_len = pending.len(); - pending.retain(f); - ensure!(orig_pending_len > pending.len(), Error::::NotFound); - *x = Self::rejig_deposit( - delegate, - old_deposit, - T::AnnouncementDepositBase::get(), - T::AnnouncementDepositFactor::get(), - pending.len(), - )? - .map(|deposit| (pending, deposit)); - Ok(()) - }) - } - - pub fn find_proxy( - real: &T::AccountId, - delegate: &T::AccountId, - force_proxy_type: Option, - ) -> Result>, DispatchError> { - let f = |x: &ProxyDefinition>| -> bool { - &x.delegate == delegate && force_proxy_type.as_ref().is_none_or(|y| &x.proxy_type == y) - }; - Ok(Proxies::::get(real) - .0 - .into_iter() - .find(f) - .ok_or(Error::::NotProxy)?) - } - - fn do_proxy( - def: ProxyDefinition>, - real: T::AccountId, - call: ::RuntimeCall, - ) { - use frame::traits::{InstanceFilter as _, OriginTrait as _}; - // This is a freshly authenticated new account, the origin restrictions doesn't apply. - let mut origin: T::RuntimeOrigin = frame_system::RawOrigin::Signed(real.clone()).into(); - origin.add_filter(move |c: &::RuntimeCall| { - let c = ::RuntimeCall::from_ref(c); - // We make sure the proxy call does access this pallet to change modify proxies. - match c.is_sub_type() { - // Proxy call cannot add or remove a proxy with more permissions than it already - // has. - Some(Call::add_proxy { proxy_type, .. }) - | Some(Call::remove_proxy { proxy_type, .. }) - if !def.proxy_type.is_superset(proxy_type) => - { - false - } - // Proxy call cannot remove all proxies or kill pure proxies unless it has full - // permissions. - Some(Call::remove_proxies { .. }) | Some(Call::kill_pure { .. }) - if def.proxy_type != T::ProxyType::default() => - { - false - } - _ => def.proxy_type.filter(c), - } - }); - let e = call.dispatch(origin); - - LastCallResult::::insert(real, e.map(|_| ()).map_err(|e| e.error)); - - Self::deposit_event(Event::ProxyExecuted { - result: e.map(|_| ()).map_err(|e| e.error), - }); - } - - /// Removes all proxy delegates for a given delegator. - /// - /// Parameters: - /// - `delegator`: The delegator account. - pub fn remove_all_proxy_delegates(delegator: &T::AccountId) { - let (_, old_deposit) = Proxies::::take(delegator); - T::Currency::unreserve(delegator, old_deposit); - // Clean up all real-pays-fee flags for this delegator - let _ = RealPaysFee::::clear_prefix(delegator, u32::MAX, None); - } - - /// Check if the real account has opted in to paying fees for a specific delegate. - pub fn is_real_pays_fee(real: &T::AccountId, delegate: &T::AccountId) -> bool { - RealPaysFee::::contains_key(real, delegate) - } -} diff --git a/pallets/proxy/src/tests.rs b/pallets/proxy/src/tests.rs deleted file mode 100644 index 5bc5be2415..0000000000 --- a/pallets/proxy/src/tests.rs +++ /dev/null @@ -1,1375 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Tests for Proxy Pallet - -#![cfg(test)] -#![allow( - clippy::arithmetic_side_effects, - clippy::unwrap_used, - clippy::indexing_slicing -)] - -use super::*; -use crate as proxy; -use alloc::{vec, vec::Vec}; -use frame::testing_prelude::*; - -type Block = frame_system::mocking::MockBlock; - -construct_runtime!( - pub enum Test { - System: frame_system = 1, - Balances: pallet_balances = 2, - Proxy: proxy = 3, - Utility: pallet_utility = 4, - } -); - -#[derive_impl(frame_system::config_preludes::TestDefaultConfig)] -impl frame_system::Config for Test { - type Block = Block; - type BaseCallFilter = BaseFilter; - type AccountData = pallet_balances::AccountData; -} - -#[derive_impl(pallet_balances::config_preludes::TestDefaultConfig)] -impl pallet_balances::Config for Test { - type ReserveIdentifier = [u8; 8]; - type AccountStore = System; -} - -impl pallet_utility::Config for Test { - type RuntimeCall = RuntimeCall; - type PalletsOrigin = OriginCaller; - type WeightInfo = (); -} - -#[derive( - Copy, - Clone, - Eq, - PartialEq, - Ord, - PartialOrd, - Encode, - Decode, - DecodeWithMemTracking, - RuntimeDebug, - MaxEncodedLen, - scale_info::TypeInfo, -)] -pub enum ProxyType { - Any, - JustTransfer, - JustUtility, -} -impl Default for ProxyType { - fn default() -> Self { - Self::Any - } -} -impl frame::traits::InstanceFilter for ProxyType { - fn filter(&self, c: &RuntimeCall) -> bool { - match self { - ProxyType::Any => true, - ProxyType::JustTransfer => { - matches!( - c, - RuntimeCall::Balances(pallet_balances::Call::transfer_allow_death { .. }) - ) - } - ProxyType::JustUtility => matches!(c, RuntimeCall::Utility { .. }), - } - } - fn is_superset(&self, o: &Self) -> bool { - self == &ProxyType::Any || self == o - } -} -pub struct BaseFilter; -impl Contains for BaseFilter { - fn contains(c: &RuntimeCall) -> bool { - match *c { - // Remark is used as a no-op call in the benchmarking - RuntimeCall::System(SystemCall::remark { .. }) => true, - RuntimeCall::System(_) => false, - _ => true, - } - } -} - -parameter_types! { - pub static ProxyDepositBase: u64 = 1; - pub static ProxyDepositFactor: u64 = 1; - pub static AnnouncementDepositBase: u64 = 1; - pub static AnnouncementDepositFactor: u64 = 1; -} - -impl Config for Test { - type RuntimeCall = RuntimeCall; - type Currency = Balances; - type ProxyType = ProxyType; - type ProxyDepositBase = ProxyDepositBase; - type ProxyDepositFactor = ProxyDepositFactor; - type MaxProxies = ConstU32<4>; - type WeightInfo = (); - type CallHasher = BlakeTwo256; - type MaxPending = ConstU32<2>; - type AnnouncementDepositBase = AnnouncementDepositBase; - type AnnouncementDepositFactor = AnnouncementDepositFactor; - type BlockNumberProvider = frame_system::Pallet; -} - -use super::{Call as ProxyCall, Event as ProxyEvent}; -use frame_system::Call as SystemCall; -use pallet_balances::{Call as BalancesCall, Error as BalancesError, Event as BalancesEvent}; -use pallet_subtensor_utility as pallet_utility; -use pallet_subtensor_utility::{Call as UtilityCall, Event as UtilityEvent}; - -type SystemError = frame_system::Error; - -pub fn new_test_ext() -> TestState { - let mut t = frame_system::GenesisConfig::::default() - .build_storage() - .unwrap(); - pallet_balances::GenesisConfig:: { - balances: vec![(1, 10), (2, 10), (3, 10), (4, 10), (5, 3)], - ..Default::default() - } - .assimilate_storage(&mut t) - .unwrap(); - let mut ext = TestState::new(t); - ext.execute_with(|| System::set_block_number(1)); - ext -} - -fn last_events(n: usize) -> Vec { - frame_system::Pallet::::events() - .into_iter() - .rev() - .take(n) - .rev() - .map(|e| e.event) - .collect() -} - -fn expect_events(e: Vec) { - assert_eq!(last_events(e.len()), e); -} - -fn call_transfer(dest: u64, value: u64) -> RuntimeCall { - RuntimeCall::Balances(BalancesCall::transfer_allow_death { dest, value }) -} - -#[test] -fn announcement_works() { - new_test_ext().execute_with(|| { - assert_ok!(Proxy::add_proxy( - RuntimeOrigin::signed(1), - 3, - ProxyType::Any, - 1 - )); - System::assert_last_event( - ProxyEvent::ProxyAdded { - delegator: 1, - delegatee: 3, - proxy_type: ProxyType::Any, - delay: 1, - } - .into(), - ); - assert_ok!(Proxy::add_proxy( - RuntimeOrigin::signed(2), - 3, - ProxyType::Any, - 1 - )); - assert_eq!(Balances::reserved_balance(3), 0); - - assert_ok!(Proxy::announce(RuntimeOrigin::signed(3), 1, [1; 32].into())); - let announcements = Announcements::::get(3); - assert_eq!( - announcements.0, - vec![Announcement { - real: 1, - call_hash: [1; 32].into(), - height: 1 - }] - ); - assert_eq!(Balances::reserved_balance(3), announcements.1); - - assert_ok!(Proxy::announce(RuntimeOrigin::signed(3), 2, [2; 32].into())); - let announcements = Announcements::::get(3); - assert_eq!( - announcements.0, - vec![ - Announcement { - real: 1, - call_hash: [1; 32].into(), - height: 1 - }, - Announcement { - real: 2, - call_hash: [2; 32].into(), - height: 1 - }, - ] - ); - assert_eq!(Balances::reserved_balance(3), announcements.1); - - assert_noop!( - Proxy::announce(RuntimeOrigin::signed(3), 2, [3; 32].into()), - Error::::TooMany - ); - }); -} - -#[test] -fn remove_announcement_works() { - new_test_ext().execute_with(|| { - assert_ok!(Proxy::add_proxy( - RuntimeOrigin::signed(1), - 3, - ProxyType::Any, - 1 - )); - assert_ok!(Proxy::add_proxy( - RuntimeOrigin::signed(2), - 3, - ProxyType::Any, - 1 - )); - assert_ok!(Proxy::announce(RuntimeOrigin::signed(3), 1, [1; 32].into())); - assert_ok!(Proxy::announce(RuntimeOrigin::signed(3), 2, [2; 32].into())); - let e = Error::::NotFound; - assert_noop!( - Proxy::remove_announcement(RuntimeOrigin::signed(3), 1, [0; 32].into()), - e - ); - assert_ok!(Proxy::remove_announcement( - RuntimeOrigin::signed(3), - 1, - [1; 32].into() - )); - let announcements = Announcements::::get(3); - assert_eq!( - announcements.0, - vec![Announcement { - real: 2, - call_hash: [2; 32].into(), - height: 1 - }] - ); - assert_eq!(Balances::reserved_balance(3), announcements.1); - }); -} - -#[test] -fn reject_announcement_works() { - new_test_ext().execute_with(|| { - assert_ok!(Proxy::add_proxy( - RuntimeOrigin::signed(1), - 3, - ProxyType::Any, - 1 - )); - assert_ok!(Proxy::add_proxy( - RuntimeOrigin::signed(2), - 3, - ProxyType::Any, - 1 - )); - assert_ok!(Proxy::announce(RuntimeOrigin::signed(3), 1, [1; 32].into())); - assert_ok!(Proxy::announce(RuntimeOrigin::signed(3), 2, [2; 32].into())); - let e = Error::::NotFound; - assert_noop!( - Proxy::reject_announcement(RuntimeOrigin::signed(1), 3, [0; 32].into()), - e - ); - let e = Error::::NotFound; - assert_noop!( - Proxy::reject_announcement(RuntimeOrigin::signed(4), 3, [1; 32].into()), - e - ); - assert_ok!(Proxy::reject_announcement( - RuntimeOrigin::signed(1), - 3, - [1; 32].into() - )); - let announcements = Announcements::::get(3); - assert_eq!( - announcements.0, - vec![Announcement { - real: 2, - call_hash: [2; 32].into(), - height: 1 - }] - ); - assert_eq!(Balances::reserved_balance(3), announcements.1); - }); -} - -#[test] -fn announcer_must_be_proxy() { - new_test_ext().execute_with(|| { - assert_noop!( - Proxy::announce(RuntimeOrigin::signed(2), 1, H256::zero()), - Error::::NotProxy - ); - }); -} - -#[test] -fn calling_proxy_doesnt_remove_announcement() { - new_test_ext().execute_with(|| { - assert_ok!(Proxy::add_proxy( - RuntimeOrigin::signed(1), - 2, - ProxyType::Any, - 0 - )); - - let call = Box::new(call_transfer(6, 1)); - let call_hash = BlakeTwo256::hash_of(&call); - - assert_ok!(Proxy::announce(RuntimeOrigin::signed(2), 1, call_hash)); - assert_ok!(Proxy::proxy(RuntimeOrigin::signed(2), 1, None, call)); - - // The announcement is not removed by calling proxy. - let announcements = Announcements::::get(2); - assert_eq!( - announcements.0, - vec![Announcement { - real: 1, - call_hash, - height: 1 - }] - ); - }); -} - -#[test] -fn delayed_requires_pre_announcement() { - new_test_ext().execute_with(|| { - assert_ok!(Proxy::add_proxy( - RuntimeOrigin::signed(1), - 2, - ProxyType::Any, - 1 - )); - let call = Box::new(call_transfer(6, 1)); - let e = Error::::Unannounced; - assert_noop!( - Proxy::proxy(RuntimeOrigin::signed(2), 1, None, call.clone()), - e - ); - let e = Error::::Unannounced; - assert_noop!( - Proxy::proxy_announced(RuntimeOrigin::signed(0), 2, 1, None, call.clone()), - e - ); - let call_hash = BlakeTwo256::hash_of(&call); - assert_ok!(Proxy::announce(RuntimeOrigin::signed(2), 1, call_hash)); - frame_system::Pallet::::set_block_number(2); - assert_ok!(Proxy::proxy_announced( - RuntimeOrigin::signed(0), - 2, - 1, - None, - call.clone() - )); - }); -} - -#[test] -fn proxy_announced_removes_announcement_and_returns_deposit() { - new_test_ext().execute_with(|| { - assert_ok!(Proxy::add_proxy( - RuntimeOrigin::signed(1), - 3, - ProxyType::Any, - 1 - )); - assert_ok!(Proxy::add_proxy( - RuntimeOrigin::signed(2), - 3, - ProxyType::Any, - 1 - )); - let call = Box::new(call_transfer(6, 1)); - let call_hash = BlakeTwo256::hash_of(&call); - assert_ok!(Proxy::announce(RuntimeOrigin::signed(3), 1, call_hash)); - assert_ok!(Proxy::announce(RuntimeOrigin::signed(3), 2, call_hash)); - // Too early to execute announced call - let e = Error::::Unannounced; - assert_noop!( - Proxy::proxy_announced(RuntimeOrigin::signed(0), 3, 1, None, call.clone()), - e - ); - - frame_system::Pallet::::set_block_number(2); - assert_ok!(Proxy::proxy_announced( - RuntimeOrigin::signed(0), - 3, - 1, - None, - call.clone() - )); - let announcements = Announcements::::get(3); - assert_eq!( - announcements.0, - vec![Announcement { - real: 2, - call_hash, - height: 1 - }] - ); - assert_eq!(Balances::reserved_balance(3), announcements.1); - }); -} - -#[test] -fn filtering_works() { - new_test_ext().execute_with(|| { - Balances::make_free_balance_be(&1, 1000); - assert_ok!(Proxy::add_proxy( - RuntimeOrigin::signed(1), - 2, - ProxyType::Any, - 0 - )); - assert_ok!(Proxy::add_proxy( - RuntimeOrigin::signed(1), - 3, - ProxyType::JustTransfer, - 0 - )); - assert_ok!(Proxy::add_proxy( - RuntimeOrigin::signed(1), - 4, - ProxyType::JustUtility, - 0 - )); - - let call = Box::new(call_transfer(6, 1)); - assert_ok!(Proxy::proxy( - RuntimeOrigin::signed(2), - 1, - None, - call.clone() - )); - System::assert_last_event(ProxyEvent::ProxyExecuted { result: Ok(()) }.into()); - assert_ok!(Proxy::proxy( - RuntimeOrigin::signed(3), - 1, - None, - call.clone() - )); - System::assert_last_event(ProxyEvent::ProxyExecuted { result: Ok(()) }.into()); - assert_ok!(Proxy::proxy( - RuntimeOrigin::signed(4), - 1, - None, - call.clone() - )); - System::assert_last_event( - ProxyEvent::ProxyExecuted { - result: Err(SystemError::CallFiltered.into()), - } - .into(), - ); - - let derivative_id = Utility::derivative_account_id(1, 0).unwrap(); - Balances::make_free_balance_be(&derivative_id, 1000); - let inner = Box::new(call_transfer(6, 1)); - - let call = Box::new(RuntimeCall::Utility(UtilityCall::as_derivative { - index: 0, - call: inner.clone(), - })); - assert_ok!(Proxy::proxy( - RuntimeOrigin::signed(2), - 1, - None, - call.clone() - )); - System::assert_last_event(ProxyEvent::ProxyExecuted { result: Ok(()) }.into()); - assert_ok!(Proxy::proxy( - RuntimeOrigin::signed(3), - 1, - None, - call.clone() - )); - System::assert_last_event( - ProxyEvent::ProxyExecuted { - result: Err(SystemError::CallFiltered.into()), - } - .into(), - ); - assert_ok!(Proxy::proxy( - RuntimeOrigin::signed(4), - 1, - None, - call.clone() - )); - System::assert_last_event( - ProxyEvent::ProxyExecuted { - result: Err(SystemError::CallFiltered.into()), - } - .into(), - ); - - let call = Box::new(RuntimeCall::Utility(UtilityCall::batch { - calls: vec![*inner], - })); - assert_ok!(Proxy::proxy( - RuntimeOrigin::signed(2), - 1, - None, - call.clone() - )); - expect_events(vec![ - UtilityEvent::BatchCompleted.into(), - ProxyEvent::ProxyExecuted { result: Ok(()) }.into(), - ]); - assert_ok!(Proxy::proxy( - RuntimeOrigin::signed(3), - 1, - None, - call.clone() - )); - System::assert_last_event( - ProxyEvent::ProxyExecuted { - result: Err(SystemError::CallFiltered.into()), - } - .into(), - ); - assert_ok!(Proxy::proxy( - RuntimeOrigin::signed(4), - 1, - None, - call.clone() - )); - expect_events(vec![ - UtilityEvent::BatchInterrupted { - index: 0, - error: SystemError::CallFiltered.into(), - } - .into(), - ProxyEvent::ProxyExecuted { result: Ok(()) }.into(), - ]); - - let inner = Box::new(RuntimeCall::Proxy(ProxyCall::new_call_variant_add_proxy( - 5, - ProxyType::Any, - 0, - ))); - let call = Box::new(RuntimeCall::Utility(UtilityCall::batch { - calls: vec![*inner], - })); - assert_ok!(Proxy::proxy( - RuntimeOrigin::signed(2), - 1, - None, - call.clone() - )); - expect_events(vec![ - UtilityEvent::BatchCompleted.into(), - ProxyEvent::ProxyExecuted { result: Ok(()) }.into(), - ]); - assert_ok!(Proxy::proxy( - RuntimeOrigin::signed(3), - 1, - None, - call.clone() - )); - System::assert_last_event( - ProxyEvent::ProxyExecuted { - result: Err(SystemError::CallFiltered.into()), - } - .into(), - ); - assert_ok!(Proxy::proxy( - RuntimeOrigin::signed(4), - 1, - None, - call.clone() - )); - expect_events(vec![ - UtilityEvent::BatchInterrupted { - index: 0, - error: SystemError::CallFiltered.into(), - } - .into(), - ProxyEvent::ProxyExecuted { result: Ok(()) }.into(), - ]); - - let call = Box::new(RuntimeCall::Proxy(ProxyCall::remove_proxies {})); - assert_ok!(Proxy::proxy( - RuntimeOrigin::signed(3), - 1, - None, - call.clone() - )); - System::assert_last_event( - ProxyEvent::ProxyExecuted { - result: Err(SystemError::CallFiltered.into()), - } - .into(), - ); - assert_ok!(Proxy::proxy( - RuntimeOrigin::signed(4), - 1, - None, - call.clone() - )); - System::assert_last_event( - ProxyEvent::ProxyExecuted { - result: Err(SystemError::CallFiltered.into()), - } - .into(), - ); - assert_ok!(Proxy::proxy( - RuntimeOrigin::signed(2), - 1, - None, - call.clone() - )); - expect_events(vec![ - BalancesEvent::::Unreserved { who: 1, amount: 5 }.into(), - ProxyEvent::ProxyExecuted { result: Ok(()) }.into(), - ]); - }); -} - -#[test] -fn add_remove_proxies_works() { - new_test_ext().execute_with(|| { - assert_ok!(Proxy::add_proxy( - RuntimeOrigin::signed(1), - 2, - ProxyType::Any, - 0 - )); - assert_noop!( - Proxy::add_proxy(RuntimeOrigin::signed(1), 2, ProxyType::Any, 0), - Error::::Duplicate - ); - assert_eq!(Balances::reserved_balance(1), 2); - assert_ok!(Proxy::add_proxy( - RuntimeOrigin::signed(1), - 2, - ProxyType::JustTransfer, - 0 - )); - assert_eq!(Balances::reserved_balance(1), 3); - assert_ok!(Proxy::add_proxy( - RuntimeOrigin::signed(1), - 3, - ProxyType::Any, - 0 - )); - assert_eq!(Balances::reserved_balance(1), 4); - assert_ok!(Proxy::add_proxy( - RuntimeOrigin::signed(1), - 4, - ProxyType::JustUtility, - 0 - )); - assert_eq!(Balances::reserved_balance(1), 5); - assert_noop!( - Proxy::add_proxy(RuntimeOrigin::signed(1), 4, ProxyType::Any, 0), - Error::::TooMany - ); - assert_noop!( - Proxy::remove_proxy(RuntimeOrigin::signed(1), 3, ProxyType::JustTransfer, 0), - Error::::NotFound - ); - assert_ok!(Proxy::remove_proxy( - RuntimeOrigin::signed(1), - 4, - ProxyType::JustUtility, - 0 - )); - System::assert_last_event( - ProxyEvent::ProxyRemoved { - delegator: 1, - delegatee: 4, - proxy_type: ProxyType::JustUtility, - delay: 0, - } - .into(), - ); - assert_eq!(Balances::reserved_balance(1), 4); - assert_ok!(Proxy::remove_proxy( - RuntimeOrigin::signed(1), - 3, - ProxyType::Any, - 0 - )); - assert_eq!(Balances::reserved_balance(1), 3); - System::assert_last_event( - ProxyEvent::ProxyRemoved { - delegator: 1, - delegatee: 3, - proxy_type: ProxyType::Any, - delay: 0, - } - .into(), - ); - assert_ok!(Proxy::remove_proxy( - RuntimeOrigin::signed(1), - 2, - ProxyType::Any, - 0 - )); - assert_eq!(Balances::reserved_balance(1), 2); - System::assert_last_event( - ProxyEvent::ProxyRemoved { - delegator: 1, - delegatee: 2, - proxy_type: ProxyType::Any, - delay: 0, - } - .into(), - ); - assert_ok!(Proxy::remove_proxy( - RuntimeOrigin::signed(1), - 2, - ProxyType::JustTransfer, - 0 - )); - assert_eq!(Balances::reserved_balance(1), 0); - System::assert_last_event( - ProxyEvent::ProxyRemoved { - delegator: 1, - delegatee: 2, - proxy_type: ProxyType::JustTransfer, - delay: 0, - } - .into(), - ); - assert_noop!( - Proxy::add_proxy(RuntimeOrigin::signed(1), 1, ProxyType::Any, 0), - Error::::NoSelfProxy - ); - }); -} - -#[test] -fn cannot_add_proxy_without_balance() { - new_test_ext().execute_with(|| { - assert_ok!(Proxy::add_proxy( - RuntimeOrigin::signed(5), - 3, - ProxyType::Any, - 0 - )); - assert_eq!(Balances::reserved_balance(5), 2); - assert_noop!( - Proxy::add_proxy(RuntimeOrigin::signed(5), 4, ProxyType::Any, 0), - DispatchError::ConsumerRemaining, - ); - }); -} - -#[test] -fn proxying_works() { - new_test_ext().execute_with(|| { - assert_ok!(Proxy::add_proxy( - RuntimeOrigin::signed(1), - 2, - ProxyType::JustTransfer, - 0 - )); - assert_ok!(Proxy::add_proxy( - RuntimeOrigin::signed(1), - 3, - ProxyType::Any, - 0 - )); - - let call = Box::new(call_transfer(6, 1)); - assert_noop!( - Proxy::proxy(RuntimeOrigin::signed(4), 1, None, call.clone()), - Error::::NotProxy - ); - assert_noop!( - Proxy::proxy( - RuntimeOrigin::signed(2), - 1, - Some(ProxyType::Any), - call.clone() - ), - Error::::NotProxy - ); - assert_ok!(Proxy::proxy( - RuntimeOrigin::signed(2), - 1, - None, - call.clone() - )); - System::assert_last_event(ProxyEvent::ProxyExecuted { result: Ok(()) }.into()); - assert_eq!(Balances::free_balance(6), 1); - - let call = Box::new(RuntimeCall::System(SystemCall::set_code { code: vec![] })); - assert_ok!(Proxy::proxy( - RuntimeOrigin::signed(3), - 1, - None, - call.clone() - )); - System::assert_last_event( - ProxyEvent::ProxyExecuted { - result: Err(SystemError::CallFiltered.into()), - } - .into(), - ); - - let call = Box::new(RuntimeCall::Balances(BalancesCall::transfer_keep_alive { - dest: 6, - value: 1, - })); - assert_ok!( - RuntimeCall::Proxy(super::Call::new_call_variant_proxy(1, None, call.clone())) - .dispatch(RuntimeOrigin::signed(2)) - ); - System::assert_last_event( - ProxyEvent::ProxyExecuted { - result: Err(SystemError::CallFiltered.into()), - } - .into(), - ); - assert_ok!(Proxy::proxy( - RuntimeOrigin::signed(3), - 1, - None, - call.clone() - )); - System::assert_last_event(ProxyEvent::ProxyExecuted { result: Ok(()) }.into()); - assert_eq!(Balances::free_balance(6), 2); - }); -} - -#[test] -fn pure_works() { - new_test_ext().execute_with(|| { - Balances::make_free_balance_be(&1, 11); // An extra one for the ED. - assert_ok!(Proxy::create_pure( - RuntimeOrigin::signed(1), - ProxyType::Any, - 0, - 0 - )); - let anon = Proxy::pure_account(&1, &ProxyType::Any, 0, None).unwrap(); - System::assert_last_event( - ProxyEvent::PureCreated { - pure: anon, - who: 1, - proxy_type: ProxyType::Any, - disambiguation_index: 0, - } - .into(), - ); - - // other calls to pure allowed as long as they're not exactly the same. - assert_ok!(Proxy::create_pure( - RuntimeOrigin::signed(1), - ProxyType::JustTransfer, - 0, - 0 - )); - assert_ok!(Proxy::create_pure( - RuntimeOrigin::signed(1), - ProxyType::Any, - 0, - 1 - )); - let anon2 = Proxy::pure_account(&2, &ProxyType::Any, 0, None).unwrap(); - assert_ok!(Proxy::create_pure( - RuntimeOrigin::signed(2), - ProxyType::Any, - 0, - 0 - )); - assert_noop!( - Proxy::create_pure(RuntimeOrigin::signed(1), ProxyType::Any, 0, 0), - Error::::Duplicate - ); - System::set_extrinsic_index(1); - assert_ok!(Proxy::create_pure( - RuntimeOrigin::signed(1), - ProxyType::Any, - 0, - 0 - )); - System::set_extrinsic_index(0); - System::set_block_number(2); - assert_ok!(Proxy::create_pure( - RuntimeOrigin::signed(1), - ProxyType::Any, - 0, - 0 - )); - - let call = Box::new(call_transfer(6, 1)); - assert_ok!(Balances::transfer_allow_death( - RuntimeOrigin::signed(3), - anon, - 5 - )); - assert_ok!(Proxy::proxy(RuntimeOrigin::signed(1), anon, None, call)); - System::assert_last_event(ProxyEvent::ProxyExecuted { result: Ok(()) }.into()); - assert_eq!(Balances::free_balance(6), 1); - - let call = Box::new(RuntimeCall::Proxy(ProxyCall::new_call_variant_kill_pure( - 1, - ProxyType::Any, - 0, - 1, - 0, - ))); - assert_ok!(Proxy::proxy( - RuntimeOrigin::signed(2), - anon2, - None, - call.clone() - )); - let de = DispatchError::from(Error::::NoPermission).stripped(); - System::assert_last_event(ProxyEvent::ProxyExecuted { result: Err(de) }.into()); - assert_noop!( - Proxy::kill_pure(RuntimeOrigin::signed(1), 1, ProxyType::Any, 0, 1, 0), - Error::::NoPermission - ); - assert_eq!(Balances::free_balance(1), 1); - assert_ok!(Proxy::proxy( - RuntimeOrigin::signed(1), - anon, - None, - call.clone() - )); - assert_eq!(Balances::free_balance(1), 3); - assert_noop!( - Proxy::proxy(RuntimeOrigin::signed(1), anon, None, call.clone()), - Error::::NotProxy - ); - }); -} - -#[test] -fn poke_deposit_works_for_proxy_deposits() { - new_test_ext().execute_with(|| { - // Add a proxy and check initial deposit - assert_ok!(Proxy::add_proxy( - RuntimeOrigin::signed(1), - 2, - ProxyType::Any, - 0 - )); - assert_eq!(Balances::reserved_balance(1), 2); // Base(1) + Factor(1) * 1 - - // Change the proxy deposit base to trigger deposit update - ProxyDepositBase::set(2); - let result = Proxy::poke_deposit(RuntimeOrigin::signed(1)); - assert_ok!(result.as_ref()); - assert_eq!(result.unwrap().pays_fee, Pays::No); - assert_eq!(Balances::reserved_balance(1), 3); // New Base(2) + Factor(1) * 1 - System::assert_last_event( - ProxyEvent::DepositPoked { - who: 1, - kind: DepositKind::Proxies, - old_deposit: 2, - new_deposit: 3, - } - .into(), - ); - assert!(System::events().iter().any(|record| matches!( - record.event, - RuntimeEvent::Proxy(Event::DepositPoked { .. }) - ))); - }); -} - -#[test] -fn poke_deposit_works_for_announcement_deposits() { - new_test_ext().execute_with(|| { - // Setup proxy and make announcement - assert_ok!(Proxy::add_proxy( - RuntimeOrigin::signed(1), - 3, - ProxyType::Any, - 1 - )); - assert_eq!(Balances::reserved_balance(1), 2); // Base(1) + Factor(1) * 1 - assert_ok!(Proxy::announce(RuntimeOrigin::signed(3), 1, [1; 32].into())); - let announcements = Announcements::::get(3); - assert_eq!( - announcements.0, - vec![Announcement { - real: 1, - call_hash: [1; 32].into(), - height: 1 - }] - ); - assert_eq!(Balances::reserved_balance(3), announcements.1); - let initial_deposit = Balances::reserved_balance(3); - - // Change announcement deposit base to trigger update - AnnouncementDepositBase::set(2); - let result = Proxy::poke_deposit(RuntimeOrigin::signed(3)); - assert_ok!(result.as_ref()); - assert_eq!(result.unwrap().pays_fee, Pays::No); - let new_deposit = initial_deposit.saturating_add(1); // Base increased by 1 - assert_eq!(Balances::reserved_balance(3), new_deposit); - System::assert_last_event( - ProxyEvent::DepositPoked { - who: 3, - kind: DepositKind::Announcements, - old_deposit: initial_deposit, - new_deposit, - } - .into(), - ); - assert!(System::events().iter().any(|record| matches!( - record.event, - RuntimeEvent::Proxy(Event::DepositPoked { .. }) - ))); - }); -} - -#[test] -fn poke_deposit_charges_fee_when_deposit_unchanged() { - new_test_ext().execute_with(|| { - // Add a proxy and check initial deposit - assert_ok!(Proxy::add_proxy( - RuntimeOrigin::signed(1), - 3, - ProxyType::Any, - 0 - )); - assert_eq!(Balances::reserved_balance(1), 2); // Base(1) + Factor(1) * 1 - - // Poke the deposit without changing deposit required and check fee - let result = Proxy::poke_deposit(RuntimeOrigin::signed(1)); - assert_ok!(result.as_ref()); - assert_eq!(result.unwrap().pays_fee, Pays::Yes); // Pays fee - assert_eq!(Balances::reserved_balance(1), 2); // No change - - // No event emitted - assert!(!System::events().iter().any(|record| matches!( - record.event, - RuntimeEvent::Proxy(Event::DepositPoked { .. }) - ))); - - // Add an announcement and check initial deposit - assert_ok!(Proxy::announce(RuntimeOrigin::signed(3), 1, [1; 32].into())); - let announcements = Announcements::::get(3); - assert_eq!( - announcements.0, - vec![Announcement { - real: 1, - call_hash: [1; 32].into(), - height: 1 - }] - ); - assert_eq!(Balances::reserved_balance(3), announcements.1); - let initial_deposit = Balances::reserved_balance(3); - - // Poke the deposit without changing deposit required and check fee - let result = Proxy::poke_deposit(RuntimeOrigin::signed(3)); - assert_ok!(result.as_ref()); - assert_eq!(result.unwrap().pays_fee, Pays::Yes); // Pays fee - assert_eq!(Balances::reserved_balance(3), initial_deposit); // No change - - // No event emitted - assert!(!System::events().iter().any(|record| matches!( - record.event, - RuntimeEvent::Proxy(Event::DepositPoked { .. }) - ))); - }); -} - -#[test] -fn poke_deposit_handles_insufficient_balance() { - new_test_ext().execute_with(|| { - // Setup with account that has minimal balance - assert_ok!(Proxy::add_proxy( - RuntimeOrigin::signed(5), - 3, - ProxyType::Any, - 0 - )); - let initial_deposit = Balances::reserved_balance(5); - - // Change deposit base to require more than available balance - ProxyDepositBase::set(10); - - // Poking should fail due to insufficient balance - assert_noop!( - Proxy::poke_deposit(RuntimeOrigin::signed(5)), - BalancesError::::InsufficientBalance, - ); - - // Original deposit should remain unchanged - assert_eq!(Balances::reserved_balance(5), initial_deposit); - }); -} - -#[test] -fn poke_deposit_updates_both_proxy_and_announcement_deposits() { - new_test_ext().execute_with(|| { - // Setup both proxy and announcement for the same account - assert_ok!(Proxy::add_proxy( - RuntimeOrigin::signed(1), - 2, - ProxyType::Any, - 0 - )); - assert_eq!(Balances::reserved_balance(1), 2); // Base(1) + Factor(1) * 1 - assert_ok!(Proxy::add_proxy( - RuntimeOrigin::signed(2), - 3, - ProxyType::Any, - 1 - )); - assert_eq!(Balances::reserved_balance(2), 2); // Base(1) + Factor(1) * 1 - assert_ok!(Proxy::announce(RuntimeOrigin::signed(2), 1, [1; 32].into())); - let announcements = Announcements::::get(2); - assert_eq!( - announcements.0, - vec![Announcement { - real: 1, - call_hash: [1; 32].into(), - height: 1 - }] - ); - assert_eq!(announcements.1, 2); // Base(1) + Factor(1) * 1 - - // Record initial deposits - let initial_proxy_deposit = Proxies::::get(2).1; - let initial_announcement_deposit = Announcements::::get(2).1; - - // Total reserved = deposit for proxy + deposit for announcement - assert_eq!( - Balances::reserved_balance(2), - initial_proxy_deposit.saturating_add(initial_announcement_deposit) - ); - - // Change both deposit requirements - ProxyDepositBase::set(2); - AnnouncementDepositBase::set(2); - - // Poke deposits - should update both deposits and emit two events - let result = Proxy::poke_deposit(RuntimeOrigin::signed(2)); - assert_ok!(result.as_ref()); - assert_eq!(result.unwrap().pays_fee, Pays::No); - - // Check both deposits were updated - let (_, new_proxy_deposit) = Proxies::::get(2); - let (_, new_announcement_deposit) = Announcements::::get(2); - assert_eq!(new_proxy_deposit, 3); // Base(2) + Factor(1) * 1 - assert_eq!(new_announcement_deposit, 3); // Base(2) + Factor(1) * 1 - assert_eq!( - Balances::reserved_balance(2), - new_proxy_deposit.saturating_add(new_announcement_deposit) - ); - - // Verify both events were emitted in the correct order - let events = System::events(); - let relevant_events: Vec<_> = events - .iter() - .filter(|record| { - matches!( - record.event, - RuntimeEvent::Proxy(ProxyEvent::DepositPoked { .. }) - ) - }) - .collect(); - - assert_eq!(relevant_events.len(), 2); - - // First event should be for Proxies - assert_eq!( - relevant_events[0].event, - ProxyEvent::DepositPoked { - who: 2, - kind: DepositKind::Proxies, - old_deposit: initial_proxy_deposit, - new_deposit: new_proxy_deposit, - } - .into() - ); - - // Second event should be for Announcements - assert_eq!( - relevant_events[1].event, - ProxyEvent::DepositPoked { - who: 2, - kind: DepositKind::Announcements, - old_deposit: initial_announcement_deposit, - new_deposit: new_announcement_deposit, - } - .into() - ); - - // Poking again should charge fee as nothing changes - let result = Proxy::poke_deposit(RuntimeOrigin::signed(2)); - assert_ok!(result.as_ref()); - assert_eq!(result.unwrap().pays_fee, Pays::Yes); - - // Verify deposits remained the same - assert_eq!(Proxies::::get(2).1, new_proxy_deposit); - assert_eq!(Announcements::::get(2).1, new_announcement_deposit); - assert_eq!( - Balances::reserved_balance(2), - new_proxy_deposit.saturating_add(new_announcement_deposit) - ); - }); -} - -#[test] -fn poke_deposit_fails_for_unsigned_origin() { - new_test_ext().execute_with(|| { - assert_noop!( - Proxy::poke_deposit(RuntimeOrigin::none()), - DispatchError::BadOrigin, - ); - }); -} - -#[test] -fn set_real_pays_fee_works() { - new_test_ext().execute_with(|| { - // Account 1 adds account 3 as proxy - assert_ok!(Proxy::add_proxy( - RuntimeOrigin::signed(1), - 3, - ProxyType::Any, - 0 - )); - - // Account 1 (real) enables real-pays-fee for delegate 3 - assert_ok!(Proxy::set_real_pays_fee(RuntimeOrigin::signed(1), 3, true)); - assert!(Proxy::is_real_pays_fee(&1, &3)); - System::assert_last_event( - ProxyEvent::RealPaysFeeSet { - real: 1, - delegate: 3, - pays_fee: true, - } - .into(), - ); - - // Disable it - assert_ok!(Proxy::set_real_pays_fee(RuntimeOrigin::signed(1), 3, false)); - assert!(!Proxy::is_real_pays_fee(&1, &3)); - System::assert_last_event( - ProxyEvent::RealPaysFeeSet { - real: 1, - delegate: 3, - pays_fee: false, - } - .into(), - ); - }); -} - -#[test] -fn set_real_pays_fee_fails_without_proxy() { - new_test_ext().execute_with(|| { - // No proxy relationship between 1 and 3 - assert_noop!( - Proxy::set_real_pays_fee(RuntimeOrigin::signed(1), 3, true), - Error::::NotProxy, - ); - }); -} - -#[test] -fn set_real_pays_fee_fails_unsigned() { - new_test_ext().execute_with(|| { - assert_noop!( - Proxy::set_real_pays_fee(RuntimeOrigin::none(), 3, true), - DispatchError::BadOrigin, - ); - }); -} - -#[test] -fn set_real_pays_fee_fails_root() { - new_test_ext().execute_with(|| { - assert_noop!( - Proxy::set_real_pays_fee(RuntimeOrigin::root(), 3, true), - DispatchError::BadOrigin, - ); - }); -} - -#[test] -fn real_pays_fee_cleaned_on_remove_proxy() { - new_test_ext().execute_with(|| { - assert_ok!(Proxy::add_proxy( - RuntimeOrigin::signed(1), - 3, - ProxyType::Any, - 0 - )); - assert_ok!(Proxy::set_real_pays_fee(RuntimeOrigin::signed(1), 3, true)); - assert!(Proxy::is_real_pays_fee(&1, &3)); - - // Remove the proxy - assert_ok!(Proxy::remove_proxy( - RuntimeOrigin::signed(1), - 3, - ProxyType::Any, - 0 - )); - - // Flag should be cleaned up - assert!(!Proxy::is_real_pays_fee(&1, &3)); - }); -} - -#[test] -fn real_pays_fee_cleaned_on_remove_proxies() { - new_test_ext().execute_with(|| { - assert_ok!(Proxy::add_proxy( - RuntimeOrigin::signed(1), - 2, - ProxyType::Any, - 0 - )); - assert_ok!(Proxy::add_proxy( - RuntimeOrigin::signed(1), - 3, - ProxyType::Any, - 0 - )); - assert_ok!(Proxy::set_real_pays_fee(RuntimeOrigin::signed(1), 2, true)); - assert_ok!(Proxy::set_real_pays_fee(RuntimeOrigin::signed(1), 3, true)); - assert!(Proxy::is_real_pays_fee(&1, &2)); - assert!(Proxy::is_real_pays_fee(&1, &3)); - - // Remove all proxies - assert_ok!(Proxy::remove_proxies(RuntimeOrigin::signed(1))); - - // Both flags should be cleaned up - assert!(!Proxy::is_real_pays_fee(&1, &2)); - assert!(!Proxy::is_real_pays_fee(&1, &3)); - }); -} diff --git a/pallets/proxy/src/weights.rs b/pallets/proxy/src/weights.rs deleted file mode 100644 index 38ae8c69ac..0000000000 --- a/pallets/proxy/src/weights.rs +++ /dev/null @@ -1,484 +0,0 @@ - -//! Autogenerated weights for `pallet_subtensor_proxy` -//! -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 49.1.0 -//! DATE: 2026-05-31, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `runnervm3jyl0`, CPU: `AMD EPYC 9V74 80-Core Processor` -//! WASM-EXECUTION: `Compiled`, CHAIN: `None`, DB CACHE: `1024` - -// Executed Command: -// /home/runner/work/subtensor/subtensor/target/production/node-subtensor -// benchmark -// pallet -// --runtime=/home/runner/work/subtensor/subtensor/target/production/wbuild/node-subtensor-runtime/node_subtensor_runtime.compact.compressed.wasm -// --genesis-builder=runtime -// --genesis-builder-preset=benchmark -// --wasm-execution=compiled -// --pallet=pallet_subtensor_proxy -// --extrinsic=* -// --steps=50 -// --repeat=20 -// --no-storage-info -// --no-min-squares -// --no-median-slopes -// --output=/tmp/tmp.dW1NaIslV8 -// --template=/home/runner/work/subtensor/subtensor/.maintain/frame-weight-template.hbs - -#![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] -#![allow(unused_imports)] -#![allow(missing_docs)] -#![allow(dead_code)] - -use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; -use core::marker::PhantomData; - -/// Weight functions needed for `pallet_subtensor_proxy`. -pub trait WeightInfo { - fn proxy(p: u32, ) -> Weight; - fn proxy_announced(a: u32, p: u32, ) -> Weight; - fn remove_announcement(a: u32, p: u32, ) -> Weight; - fn reject_announcement(a: u32, p: u32, ) -> Weight; - fn announce(a: u32, p: u32, ) -> Weight; - fn add_proxy(p: u32, ) -> Weight; - fn remove_proxy(p: u32, ) -> Weight; - fn remove_proxies(p: u32, ) -> Weight; - fn create_pure(p: u32, ) -> Weight; - fn kill_pure(p: u32, ) -> Weight; - fn poke_deposit() -> Weight; - fn set_real_pays_fee(p: u32, ) -> Weight; -} - -/// Weights for `pallet_subtensor_proxy` using the Substrate node and recommended hardware. -pub struct SubstrateWeight(PhantomData); -impl WeightInfo for SubstrateWeight { - /// Storage: `Proxy::Proxies` (r:1 w:0) - /// Proof: `Proxy::Proxies` (`max_values`: None, `max_size`: Some(789), added: 3264, mode: `MaxEncodedLen`) - /// Storage: `SafeMode::EnteredUntil` (r:1 w:0) - /// Proof: `SafeMode::EnteredUntil` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) - /// Storage: `SubtensorModule::ColdkeySwapAnnouncements` (r:1 w:0) - /// Proof: `SubtensorModule::ColdkeySwapAnnouncements` (`max_values`: None, `max_size`: None, mode: `Measured`) - /// Storage: `Proxy::LastCallResult` (r:0 w:1) - /// Proof: `Proxy::LastCallResult` (`max_values`: None, `max_size`: Some(47), added: 2522, mode: `MaxEncodedLen`) - /// The range of component `p` is `[1, 19]`. - fn proxy(p: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `637 + p * (37 ±0)` - // Estimated: `4254 + p * (37 ±0)` - // Minimum execution time: 23_374_000 picoseconds. - Weight::from_parts(24_151_161, 4254) - // Standard Error: 3_337 - .saturating_add(Weight::from_parts(96_756, 0).saturating_mul(p.into())) - .saturating_add(T::DbWeight::get().reads(3_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) - .saturating_add(Weight::from_parts(0, 37).saturating_mul(p.into())) - } - /// Storage: `Proxy::Proxies` (r:1 w:0) - /// Proof: `Proxy::Proxies` (`max_values`: None, `max_size`: Some(789), added: 3264, mode: `MaxEncodedLen`) - /// Storage: `Proxy::Announcements` (r:1 w:1) - /// Proof: `Proxy::Announcements` (`max_values`: None, `max_size`: Some(5150), added: 7625, mode: `MaxEncodedLen`) - /// Storage: `System::Account` (r:1 w:1) - /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(104), added: 2579, mode: `MaxEncodedLen`) - /// Storage: `SafeMode::EnteredUntil` (r:1 w:0) - /// Proof: `SafeMode::EnteredUntil` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) - /// Storage: `SubtensorModule::ColdkeySwapAnnouncements` (r:1 w:0) - /// Proof: `SubtensorModule::ColdkeySwapAnnouncements` (`max_values`: None, `max_size`: None, mode: `Measured`) - /// Storage: `Proxy::LastCallResult` (r:0 w:1) - /// Proof: `Proxy::LastCallResult` (`max_values`: None, `max_size`: Some(47), added: 2522, mode: `MaxEncodedLen`) - /// The range of component `a` is `[0, 74]`. - /// The range of component `p` is `[1, 19]`. - fn proxy_announced(a: u32, p: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `894 + a * (68 ±0) + p * (37 ±0)` - // Estimated: `8615 + a * (68 ±0) + p * (37 ±0)` - // Minimum execution time: 47_420_000 picoseconds. - Weight::from_parts(48_607_796, 8615) - // Standard Error: 1_429 - .saturating_add(Weight::from_parts(261_812, 0).saturating_mul(a.into())) - // Standard Error: 5_727 - .saturating_add(Weight::from_parts(54_276, 0).saturating_mul(p.into())) - .saturating_add(T::DbWeight::get().reads(5_u64)) - .saturating_add(T::DbWeight::get().writes(3_u64)) - .saturating_add(Weight::from_parts(0, 68).saturating_mul(a.into())) - .saturating_add(Weight::from_parts(0, 37).saturating_mul(p.into())) - } - /// Storage: `Proxy::Announcements` (r:1 w:1) - /// Proof: `Proxy::Announcements` (`max_values`: None, `max_size`: Some(5150), added: 7625, mode: `MaxEncodedLen`) - /// Storage: `System::Account` (r:1 w:1) - /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(104), added: 2579, mode: `MaxEncodedLen`) - /// The range of component `a` is `[0, 74]`. - /// The range of component `p` is `[1, 19]`. - fn remove_announcement(a: u32, p: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `299 + a * (68 ±0)` - // Estimated: `8615` - // Minimum execution time: 23_295_000 picoseconds. - Weight::from_parts(24_193_917, 8615) - // Standard Error: 886 - .saturating_add(Weight::from_parts(211_445, 0).saturating_mul(a.into())) - // Standard Error: 3_552 - .saturating_add(Weight::from_parts(20_637, 0).saturating_mul(p.into())) - .saturating_add(T::DbWeight::get().reads(2_u64)) - .saturating_add(T::DbWeight::get().writes(2_u64)) - } - /// Storage: `Proxy::Announcements` (r:1 w:1) - /// Proof: `Proxy::Announcements` (`max_values`: None, `max_size`: Some(5150), added: 7625, mode: `MaxEncodedLen`) - /// Storage: `System::Account` (r:1 w:1) - /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(104), added: 2579, mode: `MaxEncodedLen`) - /// The range of component `a` is `[0, 74]`. - /// The range of component `p` is `[1, 19]`. - fn reject_announcement(a: u32, p: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `299 + a * (68 ±0)` - // Estimated: `8615` - // Minimum execution time: 23_334_000 picoseconds. - Weight::from_parts(24_226_028, 8615) - // Standard Error: 891 - .saturating_add(Weight::from_parts(211_311, 0).saturating_mul(a.into())) - // Standard Error: 3_572 - .saturating_add(Weight::from_parts(19_850, 0).saturating_mul(p.into())) - .saturating_add(T::DbWeight::get().reads(2_u64)) - .saturating_add(T::DbWeight::get().writes(2_u64)) - } - /// Storage: `Proxy::Proxies` (r:1 w:0) - /// Proof: `Proxy::Proxies` (`max_values`: None, `max_size`: Some(789), added: 3264, mode: `MaxEncodedLen`) - /// Storage: `Proxy::Announcements` (r:1 w:1) - /// Proof: `Proxy::Announcements` (`max_values`: None, `max_size`: Some(5150), added: 7625, mode: `MaxEncodedLen`) - /// Storage: `System::Account` (r:1 w:1) - /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(104), added: 2579, mode: `MaxEncodedLen`) - /// The range of component `a` is `[0, 74]`. - /// The range of component `p` is `[1, 19]`. - fn announce(a: u32, p: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `308 + a * (68 ±0) + p * (37 ±0)` - // Estimated: `8615` - // Minimum execution time: 30_775_000 picoseconds. - Weight::from_parts(29_900_605, 8615) - // Standard Error: 2_656 - .saturating_add(Weight::from_parts(245_681, 0).saturating_mul(a.into())) - // Standard Error: 10_638 - .saturating_add(Weight::from_parts(108_442, 0).saturating_mul(p.into())) - .saturating_add(T::DbWeight::get().reads(3_u64)) - .saturating_add(T::DbWeight::get().writes(2_u64)) - } - /// Storage: `Proxy::Proxies` (r:1 w:1) - /// Proof: `Proxy::Proxies` (`max_values`: None, `max_size`: Some(789), added: 3264, mode: `MaxEncodedLen`) - /// The range of component `p` is `[1, 19]`. - fn add_proxy(p: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `119 + p * (37 ±0)` - // Estimated: `4254` - // Minimum execution time: 22_393_000 picoseconds. - Weight::from_parts(23_099_598, 4254) - // Standard Error: 1_922 - .saturating_add(Weight::from_parts(76_038, 0).saturating_mul(p.into())) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) - } - /// Storage: `Proxy::Proxies` (r:1 w:1) - /// Proof: `Proxy::Proxies` (`max_values`: None, `max_size`: Some(789), added: 3264, mode: `MaxEncodedLen`) - /// Storage: `Proxy::RealPaysFee` (r:0 w:1) - /// Proof: `Proxy::RealPaysFee` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) - /// The range of component `p` is `[1, 19]`. - fn remove_proxy(p: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `119 + p * (37 ±0)` - // Estimated: `4254` - // Minimum execution time: 23_635_000 picoseconds. - Weight::from_parts(24_761_635, 4254) - // Standard Error: 2_310 - .saturating_add(Weight::from_parts(58_413, 0).saturating_mul(p.into())) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(2_u64)) - } - /// Storage: `Proxy::Proxies` (r:1 w:1) - /// Proof: `Proxy::Proxies` (`max_values`: None, `max_size`: Some(789), added: 3264, mode: `MaxEncodedLen`) - /// The range of component `p` is `[1, 19]`. - fn remove_proxies(p: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `119 + p * (37 ±0)` - // Estimated: `4254` - // Minimum execution time: 23_715_000 picoseconds. - Weight::from_parts(24_632_652, 4254) - // Standard Error: 2_253 - .saturating_add(Weight::from_parts(48_858, 0).saturating_mul(p.into())) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) - } - /// Storage: `Proxy::Proxies` (r:1 w:1) - /// Proof: `Proxy::Proxies` (`max_values`: None, `max_size`: Some(789), added: 3264, mode: `MaxEncodedLen`) - /// The range of component `p` is `[1, 19]`. - fn create_pure(p: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `139` - // Estimated: `4254` - // Minimum execution time: 23_865_000 picoseconds. - Weight::from_parts(24_892_331, 4254) - // Standard Error: 2_007 - .saturating_add(Weight::from_parts(21_649, 0).saturating_mul(p.into())) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) - } - /// Storage: `Proxy::Proxies` (r:1 w:1) - /// Proof: `Proxy::Proxies` (`max_values`: None, `max_size`: Some(789), added: 3264, mode: `MaxEncodedLen`) - /// The range of component `p` is `[0, 18]`. - fn kill_pure(p: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `156 + p * (37 ±0)` - // Estimated: `4254` - // Minimum execution time: 22_854_000 picoseconds. - Weight::from_parts(23_802_763, 4254) - // Standard Error: 2_166 - .saturating_add(Weight::from_parts(41_019, 0).saturating_mul(p.into())) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) - } - /// Storage: `Proxy::Proxies` (r:1 w:1) - /// Proof: `Proxy::Proxies` (`max_values`: None, `max_size`: Some(789), added: 3264, mode: `MaxEncodedLen`) - /// Storage: `System::Account` (r:1 w:1) - /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(104), added: 2579, mode: `MaxEncodedLen`) - /// Storage: `Proxy::Announcements` (r:1 w:1) - /// Proof: `Proxy::Announcements` (`max_values`: None, `max_size`: Some(5150), added: 7625, mode: `MaxEncodedLen`) - fn poke_deposit() -> Weight { - // Proof Size summary in bytes: - // Measured: `412` - // Estimated: `8615` - // Minimum execution time: 42_413_000 picoseconds. - Weight::from_parts(43_264_000, 8615) - .saturating_add(T::DbWeight::get().reads(3_u64)) - .saturating_add(T::DbWeight::get().writes(3_u64)) - } - /// Storage: `Proxy::Proxies` (r:1 w:0) - /// Proof: `Proxy::Proxies` (`max_values`: None, `max_size`: Some(789), added: 3264, mode: `MaxEncodedLen`) - /// Storage: `Proxy::RealPaysFee` (r:0 w:1) - /// Proof: `Proxy::RealPaysFee` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) - /// The range of component `p` is `[1, 19]`. - fn set_real_pays_fee(p: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `119 + p * (37 ±0)` - // Estimated: `4254` - // Minimum execution time: 11_487_000 picoseconds. - Weight::from_parts(12_050_045, 4254) - // Standard Error: 1_620 - .saturating_add(Weight::from_parts(45_828, 0).saturating_mul(p.into())) - .saturating_add(T::DbWeight::get().reads(1_u64)) - .saturating_add(T::DbWeight::get().writes(1_u64)) - } -} - -// For backwards compatibility and tests. -impl WeightInfo for () { - /// Storage: `Proxy::Proxies` (r:1 w:0) - /// Proof: `Proxy::Proxies` (`max_values`: None, `max_size`: Some(789), added: 3264, mode: `MaxEncodedLen`) - /// Storage: `SafeMode::EnteredUntil` (r:1 w:0) - /// Proof: `SafeMode::EnteredUntil` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) - /// Storage: `SubtensorModule::ColdkeySwapAnnouncements` (r:1 w:0) - /// Proof: `SubtensorModule::ColdkeySwapAnnouncements` (`max_values`: None, `max_size`: None, mode: `Measured`) - /// Storage: `Proxy::LastCallResult` (r:0 w:1) - /// Proof: `Proxy::LastCallResult` (`max_values`: None, `max_size`: Some(47), added: 2522, mode: `MaxEncodedLen`) - /// The range of component `p` is `[1, 19]`. - fn proxy(p: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `637 + p * (37 ±0)` - // Estimated: `4254 + p * (37 ±0)` - // Minimum execution time: 23_374_000 picoseconds. - Weight::from_parts(24_151_161, 4254) - // Standard Error: 3_337 - .saturating_add(Weight::from_parts(96_756, 0).saturating_mul(p.into())) - .saturating_add(RocksDbWeight::get().reads(3_u64)) - .saturating_add(RocksDbWeight::get().writes(1_u64)) - .saturating_add(Weight::from_parts(0, 37).saturating_mul(p.into())) - } - /// Storage: `Proxy::Proxies` (r:1 w:0) - /// Proof: `Proxy::Proxies` (`max_values`: None, `max_size`: Some(789), added: 3264, mode: `MaxEncodedLen`) - /// Storage: `Proxy::Announcements` (r:1 w:1) - /// Proof: `Proxy::Announcements` (`max_values`: None, `max_size`: Some(5150), added: 7625, mode: `MaxEncodedLen`) - /// Storage: `System::Account` (r:1 w:1) - /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(104), added: 2579, mode: `MaxEncodedLen`) - /// Storage: `SafeMode::EnteredUntil` (r:1 w:0) - /// Proof: `SafeMode::EnteredUntil` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) - /// Storage: `SubtensorModule::ColdkeySwapAnnouncements` (r:1 w:0) - /// Proof: `SubtensorModule::ColdkeySwapAnnouncements` (`max_values`: None, `max_size`: None, mode: `Measured`) - /// Storage: `Proxy::LastCallResult` (r:0 w:1) - /// Proof: `Proxy::LastCallResult` (`max_values`: None, `max_size`: Some(47), added: 2522, mode: `MaxEncodedLen`) - /// The range of component `a` is `[0, 74]`. - /// The range of component `p` is `[1, 19]`. - fn proxy_announced(a: u32, p: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `894 + a * (68 ±0) + p * (37 ±0)` - // Estimated: `8615 + a * (68 ±0) + p * (37 ±0)` - // Minimum execution time: 47_420_000 picoseconds. - Weight::from_parts(48_607_796, 8615) - // Standard Error: 1_429 - .saturating_add(Weight::from_parts(261_812, 0).saturating_mul(a.into())) - // Standard Error: 5_727 - .saturating_add(Weight::from_parts(54_276, 0).saturating_mul(p.into())) - .saturating_add(RocksDbWeight::get().reads(5_u64)) - .saturating_add(RocksDbWeight::get().writes(3_u64)) - .saturating_add(Weight::from_parts(0, 68).saturating_mul(a.into())) - .saturating_add(Weight::from_parts(0, 37).saturating_mul(p.into())) - } - /// Storage: `Proxy::Announcements` (r:1 w:1) - /// Proof: `Proxy::Announcements` (`max_values`: None, `max_size`: Some(5150), added: 7625, mode: `MaxEncodedLen`) - /// Storage: `System::Account` (r:1 w:1) - /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(104), added: 2579, mode: `MaxEncodedLen`) - /// The range of component `a` is `[0, 74]`. - /// The range of component `p` is `[1, 19]`. - fn remove_announcement(a: u32, p: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `299 + a * (68 ±0)` - // Estimated: `8615` - // Minimum execution time: 23_295_000 picoseconds. - Weight::from_parts(24_193_917, 8615) - // Standard Error: 886 - .saturating_add(Weight::from_parts(211_445, 0).saturating_mul(a.into())) - // Standard Error: 3_552 - .saturating_add(Weight::from_parts(20_637, 0).saturating_mul(p.into())) - .saturating_add(RocksDbWeight::get().reads(2_u64)) - .saturating_add(RocksDbWeight::get().writes(2_u64)) - } - /// Storage: `Proxy::Announcements` (r:1 w:1) - /// Proof: `Proxy::Announcements` (`max_values`: None, `max_size`: Some(5150), added: 7625, mode: `MaxEncodedLen`) - /// Storage: `System::Account` (r:1 w:1) - /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(104), added: 2579, mode: `MaxEncodedLen`) - /// The range of component `a` is `[0, 74]`. - /// The range of component `p` is `[1, 19]`. - fn reject_announcement(a: u32, p: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `299 + a * (68 ±0)` - // Estimated: `8615` - // Minimum execution time: 23_334_000 picoseconds. - Weight::from_parts(24_226_028, 8615) - // Standard Error: 891 - .saturating_add(Weight::from_parts(211_311, 0).saturating_mul(a.into())) - // Standard Error: 3_572 - .saturating_add(Weight::from_parts(19_850, 0).saturating_mul(p.into())) - .saturating_add(RocksDbWeight::get().reads(2_u64)) - .saturating_add(RocksDbWeight::get().writes(2_u64)) - } - /// Storage: `Proxy::Proxies` (r:1 w:0) - /// Proof: `Proxy::Proxies` (`max_values`: None, `max_size`: Some(789), added: 3264, mode: `MaxEncodedLen`) - /// Storage: `Proxy::Announcements` (r:1 w:1) - /// Proof: `Proxy::Announcements` (`max_values`: None, `max_size`: Some(5150), added: 7625, mode: `MaxEncodedLen`) - /// Storage: `System::Account` (r:1 w:1) - /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(104), added: 2579, mode: `MaxEncodedLen`) - /// The range of component `a` is `[0, 74]`. - /// The range of component `p` is `[1, 19]`. - fn announce(a: u32, p: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `308 + a * (68 ±0) + p * (37 ±0)` - // Estimated: `8615` - // Minimum execution time: 30_775_000 picoseconds. - Weight::from_parts(29_900_605, 8615) - // Standard Error: 2_656 - .saturating_add(Weight::from_parts(245_681, 0).saturating_mul(a.into())) - // Standard Error: 10_638 - .saturating_add(Weight::from_parts(108_442, 0).saturating_mul(p.into())) - .saturating_add(RocksDbWeight::get().reads(3_u64)) - .saturating_add(RocksDbWeight::get().writes(2_u64)) - } - /// Storage: `Proxy::Proxies` (r:1 w:1) - /// Proof: `Proxy::Proxies` (`max_values`: None, `max_size`: Some(789), added: 3264, mode: `MaxEncodedLen`) - /// The range of component `p` is `[1, 19]`. - fn add_proxy(p: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `119 + p * (37 ±0)` - // Estimated: `4254` - // Minimum execution time: 22_393_000 picoseconds. - Weight::from_parts(23_099_598, 4254) - // Standard Error: 1_922 - .saturating_add(Weight::from_parts(76_038, 0).saturating_mul(p.into())) - .saturating_add(RocksDbWeight::get().reads(1_u64)) - .saturating_add(RocksDbWeight::get().writes(1_u64)) - } - /// Storage: `Proxy::Proxies` (r:1 w:1) - /// Proof: `Proxy::Proxies` (`max_values`: None, `max_size`: Some(789), added: 3264, mode: `MaxEncodedLen`) - /// Storage: `Proxy::RealPaysFee` (r:0 w:1) - /// Proof: `Proxy::RealPaysFee` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) - /// The range of component `p` is `[1, 19]`. - fn remove_proxy(p: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `119 + p * (37 ±0)` - // Estimated: `4254` - // Minimum execution time: 23_635_000 picoseconds. - Weight::from_parts(24_761_635, 4254) - // Standard Error: 2_310 - .saturating_add(Weight::from_parts(58_413, 0).saturating_mul(p.into())) - .saturating_add(RocksDbWeight::get().reads(1_u64)) - .saturating_add(RocksDbWeight::get().writes(2_u64)) - } - /// Storage: `Proxy::Proxies` (r:1 w:1) - /// Proof: `Proxy::Proxies` (`max_values`: None, `max_size`: Some(789), added: 3264, mode: `MaxEncodedLen`) - /// The range of component `p` is `[1, 19]`. - fn remove_proxies(p: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `119 + p * (37 ±0)` - // Estimated: `4254` - // Minimum execution time: 23_715_000 picoseconds. - Weight::from_parts(24_632_652, 4254) - // Standard Error: 2_253 - .saturating_add(Weight::from_parts(48_858, 0).saturating_mul(p.into())) - .saturating_add(RocksDbWeight::get().reads(1_u64)) - .saturating_add(RocksDbWeight::get().writes(1_u64)) - } - /// Storage: `Proxy::Proxies` (r:1 w:1) - /// Proof: `Proxy::Proxies` (`max_values`: None, `max_size`: Some(789), added: 3264, mode: `MaxEncodedLen`) - /// The range of component `p` is `[1, 19]`. - fn create_pure(p: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `139` - // Estimated: `4254` - // Minimum execution time: 23_865_000 picoseconds. - Weight::from_parts(24_892_331, 4254) - // Standard Error: 2_007 - .saturating_add(Weight::from_parts(21_649, 0).saturating_mul(p.into())) - .saturating_add(RocksDbWeight::get().reads(1_u64)) - .saturating_add(RocksDbWeight::get().writes(1_u64)) - } - /// Storage: `Proxy::Proxies` (r:1 w:1) - /// Proof: `Proxy::Proxies` (`max_values`: None, `max_size`: Some(789), added: 3264, mode: `MaxEncodedLen`) - /// The range of component `p` is `[0, 18]`. - fn kill_pure(p: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `156 + p * (37 ±0)` - // Estimated: `4254` - // Minimum execution time: 22_854_000 picoseconds. - Weight::from_parts(23_802_763, 4254) - // Standard Error: 2_166 - .saturating_add(Weight::from_parts(41_019, 0).saturating_mul(p.into())) - .saturating_add(RocksDbWeight::get().reads(1_u64)) - .saturating_add(RocksDbWeight::get().writes(1_u64)) - } - /// Storage: `Proxy::Proxies` (r:1 w:1) - /// Proof: `Proxy::Proxies` (`max_values`: None, `max_size`: Some(789), added: 3264, mode: `MaxEncodedLen`) - /// Storage: `System::Account` (r:1 w:1) - /// Proof: `System::Account` (`max_values`: None, `max_size`: Some(104), added: 2579, mode: `MaxEncodedLen`) - /// Storage: `Proxy::Announcements` (r:1 w:1) - /// Proof: `Proxy::Announcements` (`max_values`: None, `max_size`: Some(5150), added: 7625, mode: `MaxEncodedLen`) - fn poke_deposit() -> Weight { - // Proof Size summary in bytes: - // Measured: `412` - // Estimated: `8615` - // Minimum execution time: 42_413_000 picoseconds. - Weight::from_parts(43_264_000, 8615) - .saturating_add(RocksDbWeight::get().reads(3_u64)) - .saturating_add(RocksDbWeight::get().writes(3_u64)) - } - /// Storage: `Proxy::Proxies` (r:1 w:0) - /// Proof: `Proxy::Proxies` (`max_values`: None, `max_size`: Some(789), added: 3264, mode: `MaxEncodedLen`) - /// Storage: `Proxy::RealPaysFee` (r:0 w:1) - /// Proof: `Proxy::RealPaysFee` (`max_values`: None, `max_size`: Some(80), added: 2555, mode: `MaxEncodedLen`) - /// The range of component `p` is `[1, 19]`. - fn set_real_pays_fee(p: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `119 + p * (37 ±0)` - // Estimated: `4254` - // Minimum execution time: 11_487_000 picoseconds. - Weight::from_parts(12_050_045, 4254) - // Standard Error: 1_620 - .saturating_add(Weight::from_parts(45_828, 0).saturating_mul(p.into())) - .saturating_add(RocksDbWeight::get().reads(1_u64)) - .saturating_add(RocksDbWeight::get().writes(1_u64)) - } -} diff --git a/pallets/shield/Cargo.toml b/pallets/shield/Cargo.toml index 8888b249b9..2232b93356 100644 --- a/pallets/shield/Cargo.toml +++ b/pallets/shield/Cargo.toml @@ -47,7 +47,7 @@ rand_chacha = { workspace = true, optional = true } [dev-dependencies] stc-shield.workspace = true -pallet-subtensor-utility.workspace = true +pallet-utility.workspace = true rand_chacha.workspace = true pallet-timestamp.workspace = true pallet-aura.workspace = true @@ -76,7 +76,7 @@ std = [ "pallet-aura?/std", "sp-consensus-aura?/std", "rand_chacha?/std", - "pallet-subtensor-utility/std", + "pallet-utility/std", "stc-shield/std", "subtensor-runtime-common/std", "sp-keystore/std", @@ -88,7 +88,7 @@ runtime-benchmarks = [ "frame-support/runtime-benchmarks", "frame-system/runtime-benchmarks", "sp-runtime/runtime-benchmarks", - "pallet-subtensor-utility/runtime-benchmarks", + "pallet-utility/runtime-benchmarks", "subtensor-runtime-common/runtime-benchmarks", "pallet-timestamp/runtime-benchmarks", "pallet-aura", @@ -101,6 +101,6 @@ try-runtime = [ "frame-system/try-runtime", "sp-runtime/try-runtime", "pallet-aura/try-runtime", - "pallet-subtensor-utility/try-runtime", + "pallet-utility/try-runtime", "pallet-timestamp/try-runtime", ] diff --git a/pallets/shield/src/mock.rs b/pallets/shield/src/mock.rs index 1bb6fa018a..c23aef86ec 100644 --- a/pallets/shield/src/mock.rs +++ b/pallets/shield/src/mock.rs @@ -23,7 +23,7 @@ construct_runtime!( Timestamp: pallet_timestamp = 1, Aura: pallet_aura = 2, MevShield: pallet_shield = 3, - Utility: pallet_subtensor_utility = 4, + Utility: pallet_utility = 4, } ); @@ -54,7 +54,8 @@ impl pallet_aura::Config for Test { type SlotDuration = SlotDuration; } -impl pallet_subtensor_utility::Config for Test { +impl pallet_utility::Config for Test { + type RuntimeEvent = RuntimeEvent; type RuntimeCall = RuntimeCall; type PalletsOrigin = OriginCaller; type WeightInfo = (); @@ -135,7 +136,7 @@ pub fn set_authors(current: Option, next_next: Option) { pub fn nest_call(call: RuntimeCall, depth: usize) -> RuntimeCall { (0..depth).fold(call, |inner, _| { - RuntimeCall::Utility(pallet_subtensor_utility::Call::batch { calls: vec![inner] }) + RuntimeCall::Utility(pallet_utility::Call::batch { calls: vec![inner] }) }) } diff --git a/pallets/subtensor/Cargo.toml b/pallets/subtensor/Cargo.toml index 0433975acd..7e8c1a5e32 100644 --- a/pallets/subtensor/Cargo.toml +++ b/pallets/subtensor/Cargo.toml @@ -33,7 +33,7 @@ libsecp256k1.workspace = true log.workspace = true substrate-fixed.workspace = true pallet-transaction-payment.workspace = true -pallet-subtensor-utility.workspace = true +pallet-utility.workspace = true ndarray.workspace = true hex.workspace = true share-pool.workspace = true @@ -55,13 +55,13 @@ w3f-bls.workspace = true sha2.workspace = true rand_chacha.workspace = true pallet-crowdloan.workspace = true -pallet-subtensor-proxy.workspace = true +pallet-proxy.workspace = true pallet-shield.workspace = true pallet-scheduler.workspace = true [dev-dependencies] pallet-balances = { workspace = true, features = ["std"] } -pallet-subtensor-proxy.workspace = true +pallet-proxy.workspace = true pallet-aura.workspace = true subtensor-runtime-common.workspace = true pallet-subtensor-swap.workspace = true @@ -90,8 +90,8 @@ try-runtime = [ "pallet-commitments/try-runtime", "pallet-crowdloan/try-runtime", "pallet-drand/try-runtime", - "pallet-subtensor-proxy/try-runtime", - "pallet-subtensor-utility/try-runtime", + "pallet-proxy/try-runtime", + "pallet-utility/try-runtime", "pallet-shield/try-runtime", "pallet-aura/try-runtime", ] @@ -120,12 +120,12 @@ std = [ "pallet-commitments/std", "pallet-crowdloan/std", "pallet-drand/std", - "pallet-subtensor-proxy/std", + "pallet-proxy/std", "pallet-subtensor-swap/std", "pallet-shield/std", "pallet-aura/std", "subtensor-swap-interface/std", - "pallet-subtensor-utility/std", + "pallet-utility/std", "safe-math/std", "share-pool/std", "ark-serialize/std", @@ -155,9 +155,9 @@ runtime-benchmarks = [ "pallet-commitments/runtime-benchmarks", "pallet-crowdloan/runtime-benchmarks", "pallet-drand/runtime-benchmarks", - "pallet-subtensor-proxy/runtime-benchmarks", + "pallet-proxy/runtime-benchmarks", "pallet-subtensor-swap/runtime-benchmarks", - "pallet-subtensor-utility/runtime-benchmarks", + "pallet-utility/runtime-benchmarks", "pallet-shield/runtime-benchmarks", "subtensor-runtime-common/runtime-benchmarks", "subtensor-swap-interface/runtime-benchmarks", diff --git a/pallets/subtensor/src/guards/check_coldkey_swap.rs b/pallets/subtensor/src/guards/check_coldkey_swap.rs index 14b1a25ac9..307dc0d912 100644 --- a/pallets/subtensor/src/guards/check_coldkey_swap.rs +++ b/pallets/subtensor/src/guards/check_coldkey_swap.rs @@ -85,7 +85,7 @@ mod tests { use crate::{ColdkeySwapAnnouncements, ColdkeySwapDisputes, Error, tests::mock::*}; use frame_support::{BoundedVec, assert_ok}; use frame_system::Call as SystemCall; - use pallet_subtensor_proxy::Call as ProxyCall; + use pallet_proxy::Call as ProxyCall; use sp_core::U256; use sp_runtime::traits::{Dispatchable, Hash}; use subtensor_runtime_common::{ProxyType, TaoBalance}; @@ -269,7 +269,7 @@ mod tests { // The inner call was blocked — check via LastCallResult storage. assert_eq!( - pallet_subtensor_proxy::LastCallResult::::get(real), + pallet_proxy::LastCallResult::::get(real), Some(Err(Error::::ColdkeySwapAnnounced.into())) ); }); @@ -319,7 +319,7 @@ mod tests { // The innermost call (remark as real) was blocked. assert_eq!( - pallet_subtensor_proxy::LastCallResult::::get(real), + pallet_proxy::LastCallResult::::get(real), Some(Err(Error::::ColdkeySwapAnnounced.into())) ); }); diff --git a/pallets/subtensor/src/tests/batch_tx.rs b/pallets/subtensor/src/tests/batch_tx.rs index 07f63c9933..4fea47c855 100644 --- a/pallets/subtensor/src/tests/batch_tx.rs +++ b/pallets/subtensor/src/tests/batch_tx.rs @@ -4,7 +4,6 @@ use frame_support::{ traits::{Contains, Currency}, }; use frame_system::Config; -use pallet_subtensor_utility as pallet_utility; use sp_core::U256; // SKIP_WASM_BUILD=1 RUST_LOG=debug cargo test --package pallet-subtensor --lib -- tests::batch_tx::test_batch_txs --exact --show-output --nocapture diff --git a/pallets/subtensor/src/tests/mock.rs b/pallets/subtensor/src/tests/mock.rs index 5c47a04389..4986c013d5 100644 --- a/pallets/subtensor/src/tests/mock.rs +++ b/pallets/subtensor/src/tests/mock.rs @@ -19,8 +19,6 @@ use frame_support::{ }; use frame_system as system; use frame_system::{EnsureRoot, RawOrigin, limits, offchain::CreateTransactionBase}; -use pallet_subtensor_proxy as pallet_proxy; -use pallet_subtensor_utility as pallet_utility; use share_pool::SafeFloat; use sp_core::{ConstU64, Get, H256, U256, offchain::KeyTypeId}; use sp_runtime::Perbill; @@ -51,7 +49,7 @@ frame_support::construct_runtime!( Drand: pallet_drand = 9, Swap: pallet_subtensor_swap = 10, Crowdloan: pallet_crowdloan = 11, - Proxy: pallet_subtensor_proxy = 12, + Proxy: pallet_proxy = 12, } ); @@ -394,6 +392,7 @@ impl pallet_scheduler::Config for Test { } impl pallet_utility::Config for Test { + type RuntimeEvent = RuntimeEvent; type RuntimeCall = RuntimeCall; type PalletsOrigin = OriginCaller; type WeightInfo = pallet_utility::weights::SubstrateWeight; @@ -479,6 +478,7 @@ parameter_types! { } impl pallet_proxy::Config for Test { + type RuntimeEvent = RuntimeEvent; type RuntimeCall = RuntimeCall; type Currency = Balances; type ProxyType = subtensor_runtime_common::ProxyType; diff --git a/pallets/subtensor/src/tests/mock_high_ed.rs b/pallets/subtensor/src/tests/mock_high_ed.rs index 5f19edf455..2fa9883265 100644 --- a/pallets/subtensor/src/tests/mock_high_ed.rs +++ b/pallets/subtensor/src/tests/mock_high_ed.rs @@ -14,7 +14,6 @@ use frame_support::{PalletId, derive_impl}; use frame_support::{parameter_types, traits::PrivilegeCmp}; use frame_system as system; use frame_system::{EnsureRoot, limits, offchain::CreateTransactionBase}; -use pallet_subtensor_proxy as pallet_proxy; use sp_core::{ConstU64, H256, U256, offchain::KeyTypeId}; use sp_runtime::Perbill; use sp_runtime::{ @@ -42,7 +41,7 @@ frame_support::construct_runtime!( Drand: pallet_drand = 8, Swap: pallet_subtensor_swap = 9, Crowdloan: pallet_crowdloan = 10, - Proxy: pallet_subtensor_proxy = 11, + Proxy: pallet_proxy = 11, } ); @@ -408,6 +407,7 @@ parameter_types! { } impl pallet_proxy::Config for Test { + type RuntimeEvent = RuntimeEvent; type RuntimeCall = RuntimeCall; type Currency = Balances; type ProxyType = subtensor_runtime_common::ProxyType; diff --git a/pallets/utility/Cargo.toml b/pallets/utility/Cargo.toml deleted file mode 100644 index 5bb38fcf82..0000000000 --- a/pallets/utility/Cargo.toml +++ /dev/null @@ -1,59 +0,0 @@ -[package] -name = "pallet-subtensor-utility" -version = "40.0.0" -edition.workspace = true -license = "Apache-2.0" -description = "FRAME utilities pallet" -readme = "README.md" - -[lints] -workspace = true - -[package.metadata.docs.rs] -targets = ["x86_64-unknown-linux-gnu"] - -[dependencies] -codec = { workspace = true } -frame-benchmarking = { optional = true, workspace = true } -frame-support.workspace = true -frame-system.workspace = true -scale-info = { features = ["derive"], workspace = true } -sp-core.workspace = true -sp-io.workspace = true -sp-runtime.workspace = true -subtensor-macros.workspace = true - -[dev-dependencies] -pallet-balances = { workspace = true, default-features = true } -pallet-root-testing = { workspace = true, default-features = true } -pallet-timestamp = { workspace = true, default-features = true } -sp-core = { workspace = true, default-features = true } - -[features] -default = ["std"] -std = [ - "codec/std", - "frame-benchmarking?/std", - "frame-support/std", - "frame-system/std", - "scale-info/std", - "sp-core/std", - "sp-io/std", - "sp-runtime/std", -] -runtime-benchmarks = [ - "frame-benchmarking/runtime-benchmarks", - "frame-support/runtime-benchmarks", - "frame-system/runtime-benchmarks", - "pallet-balances/runtime-benchmarks", - "pallet-timestamp/runtime-benchmarks", - "sp-runtime/runtime-benchmarks", -] -try-runtime = [ - "frame-support/try-runtime", - "frame-system/try-runtime", - "pallet-balances/try-runtime", - "pallet-root-testing/try-runtime", - "pallet-timestamp/try-runtime", - "sp-runtime/try-runtime", -] diff --git a/pallets/utility/README.md b/pallets/utility/README.md deleted file mode 100644 index 5366951a89..0000000000 --- a/pallets/utility/README.md +++ /dev/null @@ -1,43 +0,0 @@ -# Utility Module -A stateless module with helpers for dispatch management which does no re-authentication. - -- [`utility::Config`](https://docs.rs/pallet-utility/latest/pallet_utility/pallet/trait.Config.html) -- [`Call`](https://docs.rs/pallet-utility/latest/pallet_utility/pallet/enum.Call.html) - -## Overview - -This module contains two basic pieces of functionality: -- Batch dispatch: A stateless operation, allowing any origin to execute multiple calls in a - single dispatch. This can be useful to amalgamate proposals, combining `set_code` with - corresponding `set_storage`s, for efficient multiple payouts with just a single signature - verify, or in combination with one of the other two dispatch functionality. -- Pseudonymal dispatch: A stateless operation, allowing a signed origin to execute a call from - an alternative signed origin. Each account has 2 * 2**16 possible "pseudonyms" (alternative - account IDs) and these can be stacked. This can be useful as a key management tool, where you - need multiple distinct accounts (e.g. as controllers for many staking accounts), but where - it's perfectly fine to have each of them controlled by the same underlying keypair. - Derivative accounts are, for the purposes of proxy filtering considered exactly the same as - the origin and are thus hampered with the origin's filters. - -Since proxy filters are respected in all dispatches of this module, it should never need to be -filtered by any proxy. - -## Interface - -### Dispatchable Functions - -#### For batch dispatch -- `batch` - Dispatch multiple calls from the sender's origin. - -#### For pseudonymal dispatch -- `as_derivative` - Dispatch a call from a derivative signed origin. - -[`Call`]: ./enum.Call.html -[`Config`]: ./trait.Config.html - -License: Apache-2.0 - - -## Release - -Polkadot SDK stable2409 diff --git a/pallets/utility/src/benchmarking.rs b/pallets/utility/src/benchmarking.rs deleted file mode 100644 index c8e3202986..0000000000 --- a/pallets/utility/src/benchmarking.rs +++ /dev/null @@ -1,125 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Benchmarks for Utility Pallet - -#![cfg(feature = "runtime-benchmarks")] - -use alloc::vec; -use frame_benchmarking::{benchmarking::add_to_whitelist, v2::*}; -use frame_system::RawOrigin; - -use crate::*; - -const SEED: u32 = 0; - -fn assert_last_event( - generic_event: ::RuntimeEvent, -) { - frame_system::Pallet::::assert_last_event(generic_event.into()); -} - -#[benchmarks] -mod benchmark { - use super::*; - - #[benchmark] - fn batch(c: Linear<0, 1000>) { - let calls = vec![frame_system::Call::remark { remark: vec![] }.into(); c as usize]; - let caller = whitelisted_caller(); - - #[extrinsic_call] - _(RawOrigin::Signed(caller), calls); - - assert_last_event::(Event::BatchCompleted.into()); - } - - #[benchmark] - fn as_derivative() { - let caller = account("caller", SEED, SEED); - let call = Box::new(frame_system::Call::remark { remark: vec![] }.into()); - // Whitelist caller account from further DB operations. - let caller_key = frame_system::Account::::hashed_key_for(&caller); - add_to_whitelist(caller_key.into()); - - #[extrinsic_call] - _(RawOrigin::Signed(caller), SEED as u16, call); - } - - #[benchmark] - fn batch_all(c: Linear<0, 1000>) { - let calls = vec![frame_system::Call::remark { remark: vec![] }.into(); c as usize]; - let caller = whitelisted_caller(); - - #[extrinsic_call] - _(RawOrigin::Signed(caller), calls); - - assert_last_event::(Event::BatchCompleted.into()); - } - - #[benchmark] - fn dispatch_as() { - let caller = account("caller", SEED, SEED); - let call = Box::new(frame_system::Call::remark { remark: vec![] }.into()); - let origin = T::RuntimeOrigin::from(RawOrigin::Signed(caller)); - let pallets_origin = origin.caller().clone(); - let pallets_origin = T::PalletsOrigin::from(pallets_origin); - - #[extrinsic_call] - _(RawOrigin::Root, Box::new(pallets_origin), call); - } - - #[benchmark] - fn force_batch(c: Linear<0, 1000>) { - let calls = vec![frame_system::Call::remark { remark: vec![] }.into(); c as usize]; - let caller = whitelisted_caller(); - - #[extrinsic_call] - _(RawOrigin::Signed(caller), calls); - - assert_last_event::(Event::BatchCompleted.into()); - } - - #[benchmark] - fn dispatch_as_fallible() { - let caller = account("caller", SEED, SEED); - let call = Box::new(frame_system::Call::remark { remark: vec![] }.into()); - let origin: T::RuntimeOrigin = RawOrigin::Signed(caller).into(); - let pallets_origin = origin.caller().clone(); - let pallets_origin = T::PalletsOrigin::from(pallets_origin); - - #[extrinsic_call] - _(RawOrigin::Root, Box::new(pallets_origin), call); - } - - #[benchmark] - fn if_else() { - // Failing main call. - let main_call = Box::new(frame_system::Call::set_code { code: vec![1] }.into()); - let fallback_call = Box::new(frame_system::Call::remark { remark: vec![1] }.into()); - let caller = whitelisted_caller(); - - #[extrinsic_call] - _(RawOrigin::Signed(caller), main_call, fallback_call); - } - - impl_benchmark_test_suite! { - Pallet, - tests::new_test_ext(), - tests::Test - } -} diff --git a/pallets/utility/src/lib.rs b/pallets/utility/src/lib.rs deleted file mode 100644 index 5143d92917..0000000000 --- a/pallets/utility/src/lib.rs +++ /dev/null @@ -1,642 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//! # Utility Pallet -//! A stateless pallet with helpers for dispatch management which does no re-authentication. -//! -//! - [`Config`] -//! - [`Call`] -//! -//! ## Overview -//! -//! This pallet contains two basic pieces of functionality: -//! - Batch dispatch: A stateless operation, allowing any origin to execute multiple calls in a -//! single dispatch. This can be useful to amalgamate proposals, combining `set_code` with -//! corresponding `set_storage`s, for efficient multiple payouts with just a single signature -//! verify, or in combination with one of the other two dispatch functionality. -//! - Pseudonymal dispatch: A stateless operation, allowing a signed origin to execute a call from -//! an alternative signed origin. Each account has 2 * 2**16 possible "pseudonyms" (alternative -//! account IDs) and these can be stacked. This can be useful as a key management tool, where you -//! need multiple distinct accounts (e.g. as controllers for many staking accounts), but where -//! it's perfectly fine to have each of them controlled by the same underlying keypair. Derivative -//! accounts are, for the purposes of proxy filtering considered exactly the same as the origin -//! and are thus hampered with the origin's filters. -//! -//! Since proxy filters are respected in all dispatches of this pallet, it should never need to be -//! filtered by any proxy. -//! -//! ## Interface -//! -//! ### Dispatchable Functions -//! -//! #### For batch dispatch -//! * `batch` - Dispatch multiple calls from the sender's origin. -//! -//! #### For pseudonymal dispatch -//! * `as_derivative` - Dispatch a call from a derivative signed origin. - -// Ensure we're `no_std` when compiling for Wasm. -#![cfg_attr(not(feature = "std"), no_std)] - -mod benchmarking; -mod tests; -pub mod weights; - -extern crate alloc; - -use alloc::{boxed::Box, vec::Vec}; -use codec::{Decode, Encode}; -use frame_support::{ - dispatch::{GetDispatchInfo, PostDispatchInfo, extract_actual_weight}, - traits::{IsSubType, OriginTrait, UnfilteredDispatchable}, -}; -use sp_core::TypeId; -use sp_io::hashing::blake2_256; -use sp_runtime::{ - DispatchError, - traits::{BadOrigin, Dispatchable, TrailingZeroInput}, -}; -pub use weights::WeightInfo; - -use subtensor_macros::freeze_struct; - -pub use pallet::*; - -#[frame_support::pallet] -#[allow(clippy::expect_used)] -pub mod pallet { - use super::*; - use frame_support::{dispatch::DispatchClass, pallet_prelude::*}; - use frame_system::pallet_prelude::*; - - #[pallet::pallet] - pub struct Pallet(_); - - /// Configuration trait. - #[pallet::config] - pub trait Config: frame_system::Config { - /// The overarching call type. - type RuntimeCall: Parameter - + Dispatchable - + GetDispatchInfo - + From> - + UnfilteredDispatchable - + IsSubType> - + IsType<::RuntimeCall>; - - /// The caller origin, overarching type of all pallets origins. - type PalletsOrigin: Parameter + - Into<::RuntimeOrigin> + - IsType<<::RuntimeOrigin as frame_support::traits::OriginTrait>::PalletsOrigin>; - - /// Weight information for extrinsics in this pallet. - type WeightInfo: WeightInfo; - } - - #[pallet::event] - #[pallet::generate_deposit(pub(super) fn deposit_event)] - pub enum Event { - /// Batch of dispatches did not complete fully. Index of first failing dispatch given, as - /// well as the error. - BatchInterrupted { index: u32, error: DispatchError }, - /// Batch of dispatches completed fully with no error. - BatchCompleted, - /// Batch of dispatches completed but has errors. - BatchCompletedWithErrors, - /// A single item within a Batch of dispatches has completed with no error. - ItemCompleted, - /// A single item within a Batch of dispatches has completed with error. - ItemFailed { error: DispatchError }, - /// A call was dispatched. - DispatchedAs { result: DispatchResult }, - /// Main call was dispatched. - IfElseMainSuccess, - /// The fallback call was dispatched. - IfElseFallbackCalled { main_error: DispatchError }, - } - - // Align the call size to 1KB. As we are currently compiling the runtime for native/wasm - // the `size_of` of the `Call` can be different. To ensure that this don't leads to - // mismatches between native/wasm or to different metadata for the same runtime, we - // algin the call size. The value is chosen big enough to hopefully never reach it. - const CALL_ALIGN: u32 = 1024; - - #[pallet::extra_constants] - impl Pallet { - /// The limit on the number of batched calls. - fn batched_calls_limit() -> u32 { - let allocator_limit = sp_core::MAX_POSSIBLE_ALLOCATION; - let call_size = (core::mem::size_of::<::RuntimeCall>() as u32) - .div_ceil(CALL_ALIGN) - .saturating_mul(CALL_ALIGN); - // The margin to take into account vec doubling capacity. - let margin_factor = 3; - - allocator_limit - .checked_div(margin_factor) - .map_or(0, |x| x.checked_div(call_size).unwrap_or(0)) - } - } - - #[pallet::hooks] - impl Hooks> for Pallet { - fn integrity_test() { - // If you hit this error, you need to try to `Box` big dispatchable parameters. - assert!( - core::mem::size_of::<::RuntimeCall>() as u32 <= CALL_ALIGN, - "Call enum size should be smaller than {CALL_ALIGN} bytes.", - ); - } - } - - #[pallet::error] - pub enum Error { - /// Too many calls batched. - TooManyCalls, - /// Bad input data for derived account ID - InvalidDerivedAccount, - } - - #[pallet::call] - impl Pallet { - #![deny(clippy::expect_used)] - - /// Send a batch of dispatch calls. - /// - /// May be called from any origin except `None`. - /// - /// - `calls`: The calls to be dispatched from the same origin. The number of call must not - /// exceed the constant: `batched_calls_limit` (available in constant metadata). - /// - /// If origin is root then the calls are dispatched without checking origin filter. (This - /// includes bypassing `frame_system::Config::BaseCallFilter`). - /// - /// ## Complexity - /// - O(C) where C is the number of calls to be batched. - /// - /// This will return `Ok` in all circumstances. To determine the success of the batch, an - /// event is deposited. If a call failed and the batch was interrupted, then the - /// `BatchInterrupted` event is deposited, along with the number of successful calls made - /// and the error of the failed call. If all were successful, then the `BatchCompleted` - /// event is deposited. - #[pallet::call_index(0)] - #[pallet::weight({ - let (dispatch_weight, pays) = Pallet::::weight_and_dispatch_class(calls); - let dispatch_weight = dispatch_weight.saturating_add(T::WeightInfo::batch(calls.len() as u32)); - (dispatch_weight, DispatchClass::Normal, pays) - })] - pub fn batch( - origin: OriginFor, - calls: Vec<::RuntimeCall>, - ) -> DispatchResultWithPostInfo { - // Do not allow the `None` origin. - if ensure_none(origin.clone()).is_ok() { - return Err(BadOrigin.into()); - } - - let is_root = ensure_root(origin.clone()).is_ok(); - let calls_len = calls.len(); - ensure!( - calls_len <= Self::batched_calls_limit() as usize, - Error::::TooManyCalls - ); - - // Track the actual weight of each of the batch calls. - let mut weight = Weight::zero(); - for (index, call) in calls.into_iter().enumerate() { - let info = call.get_dispatch_info(); - // If origin is root, don't apply any dispatch filters; root can call anything. - let result = if is_root { - call.dispatch_bypass_filter(origin.clone()) - } else { - call.dispatch(origin.clone()) - }; - // Add the weight of this call. - weight = weight.saturating_add(extract_actual_weight(&result, &info)); - if let Err(e) = result { - Self::deposit_event(Event::BatchInterrupted { - index: index as u32, - error: e.error, - }); - // Take the weight of this function itself into account. - let base_weight = T::WeightInfo::batch(index.saturating_add(1) as u32); - // Return the actual used weight + base_weight of this call. - return Ok(Some(base_weight.saturating_add(weight)).into()); - } - Self::deposit_event(Event::ItemCompleted); - } - Self::deposit_event(Event::BatchCompleted); - let base_weight = T::WeightInfo::batch(calls_len as u32); - Ok(Some(base_weight.saturating_add(weight)).into()) - } - - /// Send a call through an indexed pseudonym of the sender. - /// - /// Filter from origin are passed along. The call will be dispatched with an origin which - /// use the same filter as the origin of this call. - /// - /// NOTE: If you need to ensure that any account-based filtering is not honored (i.e. - /// because you expect `proxy` to have been used prior in the call stack and you do not want - /// the call restrictions to apply to any sub-accounts), then use `as_multi_threshold_1` - /// in the Multisig pallet instead. - /// - /// NOTE: Prior to version *12, this was called `as_limited_sub`. - /// - /// The dispatch origin for this call must be _Signed_. - #[pallet::call_index(1)] - #[pallet::weight({ - let dispatch_info = call.get_dispatch_info(); - ( - T::WeightInfo::as_derivative() - // AccountData for inner call origin accountdata. - .saturating_add(T::DbWeight::get().reads_writes(1, 1)) - .saturating_add(dispatch_info.call_weight), - DispatchClass::Normal, - ) - })] - pub fn as_derivative( - origin: OriginFor, - index: u16, - call: Box<::RuntimeCall>, - ) -> DispatchResultWithPostInfo { - let mut origin = origin; - let who = ensure_signed(origin.clone())?; - let pseudonym = Self::derivative_account_id(who, index)?; - origin.set_caller_from(frame_system::RawOrigin::Signed(pseudonym)); - let info = call.get_dispatch_info(); - let result = call.dispatch(origin); - // Always take into account the base weight of this call. - let mut weight = T::WeightInfo::as_derivative() - .saturating_add(T::DbWeight::get().reads_writes(1, 1)); - // Add the real weight of the dispatch. - weight = weight.saturating_add(extract_actual_weight(&result, &info)); - result - .map_err(|mut err| { - err.post_info = Some(weight).into(); - err - }) - .map(|_| Some(weight).into()) - } - - /// Send a batch of dispatch calls and atomically execute them. - /// The whole transaction will rollback and fail if any of the calls failed. - /// - /// May be called from any origin except `None`. - /// - /// - `calls`: The calls to be dispatched from the same origin. The number of call must not - /// exceed the constant: `batched_calls_limit` (available in constant metadata). - /// - /// If origin is root then the calls are dispatched without checking origin filter. (This - /// includes bypassing `frame_system::Config::BaseCallFilter`). - /// - /// ## Complexity - /// - O(C) where C is the number of calls to be batched. - #[pallet::call_index(2)] - #[pallet::weight({ - let (dispatch_weight, pays) = Pallet::::weight_and_dispatch_class(calls); - let dispatch_weight = dispatch_weight.saturating_add(T::WeightInfo::batch_all(calls.len() as u32)); - (dispatch_weight, DispatchClass::Normal, pays) - })] - pub fn batch_all( - origin: OriginFor, - calls: Vec<::RuntimeCall>, - ) -> DispatchResultWithPostInfo { - // Do not allow the `None` origin. - if ensure_none(origin.clone()).is_ok() { - return Err(BadOrigin.into()); - } - - let is_root = ensure_root(origin.clone()).is_ok(); - let calls_len = calls.len(); - ensure!( - calls_len <= Self::batched_calls_limit() as usize, - Error::::TooManyCalls - ); - - // Track the actual weight of each of the batch calls. - let mut weight = Weight::zero(); - for (index, call) in calls.into_iter().enumerate() { - let info = call.get_dispatch_info(); - // If origin is root, bypass any dispatch filter; root can call anything. - let result = if is_root { - call.dispatch_bypass_filter(origin.clone()) - } else { - let mut filtered_origin = origin.clone(); - // Don't allow users to nest `batch_all` calls. - filtered_origin.add_filter( - move |c: &::RuntimeCall| { - let c = ::RuntimeCall::from_ref(c); - !matches!(c.is_sub_type(), Some(Call::batch_all { .. })) - }, - ); - call.dispatch(filtered_origin) - }; - // Add the weight of this call. - weight = weight.saturating_add(extract_actual_weight(&result, &info)); - result.map_err(|mut err| { - // Take the weight of this function itself into account. - let base_weight = T::WeightInfo::batch_all(index.saturating_add(1) as u32); - // Return the actual used weight + base_weight of this call. - err.post_info = Some(base_weight.saturating_add(weight)).into(); - err - })?; - Self::deposit_event(Event::ItemCompleted); - } - Self::deposit_event(Event::BatchCompleted); - let base_weight = T::WeightInfo::batch_all(calls_len as u32); - Ok(Some(base_weight.saturating_add(weight)).into()) - } - - /// Dispatches a function call with a provided origin. - /// - /// The dispatch origin for this call must be _Root_. - /// - /// ## Complexity - /// - O(1). - #[pallet::call_index(3)] - #[pallet::weight({ - let dispatch_info = call.get_dispatch_info(); - ( - T::WeightInfo::dispatch_as() - .saturating_add(dispatch_info.call_weight), - DispatchClass::Normal, - ) - })] - pub fn dispatch_as( - origin: OriginFor, - as_origin: Box, - call: Box<::RuntimeCall>, - ) -> DispatchResult { - ensure_root(origin)?; - - let res = call.dispatch_bypass_filter((*as_origin).into()); - - Self::deposit_event(Event::DispatchedAs { - result: res.map(|_| ()).map_err(|e| e.error), - }); - Ok(()) - } - - /// Send a batch of dispatch calls. - /// Unlike `batch`, it allows errors and won't interrupt. - /// - /// May be called from any origin except `None`. - /// - /// - `calls`: The calls to be dispatched from the same origin. The number of call must not - /// exceed the constant: `batched_calls_limit` (available in constant metadata). - /// - /// If origin is root then the calls are dispatch without checking origin filter. (This - /// includes bypassing `frame_system::Config::BaseCallFilter`). - /// - /// ## Complexity - /// - O(C) where C is the number of calls to be batched. - #[pallet::call_index(4)] - #[pallet::weight({ - let (dispatch_weight, pays) = Pallet::::weight_and_dispatch_class(calls); - let dispatch_weight = dispatch_weight.saturating_add(T::WeightInfo::force_batch(calls.len() as u32)); - (dispatch_weight, DispatchClass::Normal, pays) - })] - pub fn force_batch( - origin: OriginFor, - calls: Vec<::RuntimeCall>, - ) -> DispatchResultWithPostInfo { - // Do not allow the `None` origin. - if ensure_none(origin.clone()).is_ok() { - return Err(BadOrigin.into()); - } - - let is_root = ensure_root(origin.clone()).is_ok(); - let calls_len = calls.len(); - ensure!( - calls_len <= Self::batched_calls_limit() as usize, - Error::::TooManyCalls - ); - - // Track the actual weight of each of the batch calls. - let mut weight = Weight::zero(); - // Track failed dispatch occur. - let mut has_error: bool = false; - for call in calls.into_iter() { - let info = call.get_dispatch_info(); - // If origin is root, don't apply any dispatch filters; root can call anything. - let result = if is_root { - call.dispatch_bypass_filter(origin.clone()) - } else { - call.dispatch(origin.clone()) - }; - // Add the weight of this call. - weight = weight.saturating_add(extract_actual_weight(&result, &info)); - if let Err(e) = result { - has_error = true; - Self::deposit_event(Event::ItemFailed { error: e.error }); - } else { - Self::deposit_event(Event::ItemCompleted); - } - } - if has_error { - Self::deposit_event(Event::BatchCompletedWithErrors); - } else { - Self::deposit_event(Event::BatchCompleted); - } - let base_weight = T::WeightInfo::force_batch(calls_len as u32); - Ok(Some(base_weight.saturating_add(weight)).into()) - } - - /// Dispatch a function call with a specified weight. - /// - /// This function does not check the weight of the call, and instead allows the - /// Root origin to specify the weight of the call. - /// - /// The dispatch origin for this call must be _Root_. - #[pallet::call_index(5)] - #[pallet::weight((*weight, DispatchClass::Normal))] - pub fn with_weight( - origin: OriginFor, - call: Box<::RuntimeCall>, - weight: Weight, - ) -> DispatchResult { - ensure_root(origin)?; - let _ = weight; // Explicitly don't check the the weight witness. - - let res = call.dispatch_bypass_filter(frame_system::RawOrigin::Root.into()); - res.map(|_| ()).map_err(|e| e.error) - } - - /// Dispatch a fallback call in the event the main call fails to execute. - /// May be called from any origin except `None`. - /// - /// This function first attempts to dispatch the `main` call. - /// If the `main` call fails, the `fallback` is attemted. - /// if the fallback is successfully dispatched, the weights of both calls - /// are accumulated and an event containing the main call error is deposited. - /// - /// In the event of a fallback failure the whole call fails - /// with the weights returned. - /// - /// - `main`: The main call to be dispatched. This is the primary action to execute. - /// - `fallback`: The fallback call to be dispatched in case the `main` call fails. - /// - /// ## Dispatch Logic - /// - If the origin is `root`, both the main and fallback calls are executed without - /// applying any origin filters. - /// - If the origin is not `root`, the origin filter is applied to both the `main` and - /// `fallback` calls. - /// - /// ## Use Case - /// - Some use cases might involve submitting a `batch` type call in either main, fallback - /// or both. - #[pallet::call_index(6)] - #[pallet::weight({ - let main = main.get_dispatch_info(); - let fallback = fallback.get_dispatch_info(); - ( - T::WeightInfo::if_else() - .saturating_add(main.call_weight) - .saturating_add(fallback.call_weight), - DispatchClass::Normal, - ) - })] - pub fn if_else( - origin: OriginFor, - main: Box<::RuntimeCall>, - fallback: Box<::RuntimeCall>, - ) -> DispatchResultWithPostInfo { - // Do not allow the `None` origin. - if ensure_none(origin.clone()).is_ok() { - return Err(BadOrigin.into()); - } - - let is_root = ensure_root(origin.clone()).is_ok(); - - // Track the weights - let mut weight = T::WeightInfo::if_else(); - - let main_info = main.get_dispatch_info(); - - // Execute the main call first - let main_result = if is_root { - main.dispatch_bypass_filter(origin.clone()) - } else { - main.dispatch(origin.clone()) - }; - - // Add weight of the main call - weight = weight.saturating_add(extract_actual_weight(&main_result, &main_info)); - - let Err(main_error) = main_result else { - // If the main result is Ok, we skip the fallback logic entirely - Self::deposit_event(Event::IfElseMainSuccess); - return Ok(Some(weight).into()); - }; - - // If the main call failed, execute the fallback call - let fallback_info = fallback.get_dispatch_info(); - - let fallback_result = if is_root { - fallback.dispatch_bypass_filter(origin.clone()) - } else { - fallback.dispatch(origin) - }; - - // Add weight of the fallback call - weight = weight.saturating_add(extract_actual_weight(&fallback_result, &fallback_info)); - - let Err(fallback_error) = fallback_result else { - // Fallback succeeded. - Self::deposit_event(Event::IfElseFallbackCalled { - main_error: main_error.error, - }); - return Ok(Some(weight).into()); - }; - - // Both calls have failed, return fallback error - Err(sp_runtime::DispatchErrorWithPostInfo { - error: fallback_error.error, - post_info: Some(weight).into(), - }) - } - - /// Dispatches a function call with a provided origin. - /// - /// Almost the same as [`Pallet::dispatch_as`] but forwards any error of the inner call. - /// - /// The dispatch origin for this call must be _Root_. - #[pallet::call_index(7)] - #[pallet::weight({ - let dispatch_info = call.get_dispatch_info(); - ( - T::WeightInfo::dispatch_as_fallible() - .saturating_add(dispatch_info.call_weight), - DispatchClass::Normal, - ) - })] - pub fn dispatch_as_fallible( - origin: OriginFor, - as_origin: Box, - call: Box<::RuntimeCall>, - ) -> DispatchResult { - ensure_root(origin)?; - - call.dispatch_bypass_filter((*as_origin).into()) - .map_err(|e| e.error)?; - - Self::deposit_event(Event::DispatchedAs { result: Ok(()) }); - - Ok(()) - } - } - - impl Pallet { - /// Get the accumulated `weight` and `pays` for the given `calls`. - /// The outer dispatch class is intentionally always `Normal`. - fn weight_and_dispatch_class(calls: &[::RuntimeCall]) -> (Weight, Pays) { - let mut total_weight = Weight::zero(); - let mut pays = Pays::No; - - for di in calls.iter().map(|call| call.get_dispatch_info()) { - total_weight = total_weight.saturating_add(di.call_weight); - if di.pays_fee == Pays::Yes { - pays = Pays::Yes; - } - } - - (total_weight, pays) - } - } -} - -/// A pallet identifier. These are per pallet and should be stored in a registry somewhere. -#[allow(unused)] -#[freeze_struct("8b0fb6b91f673972")] -#[derive(Clone, Copy, Eq, PartialEq, Encode, Decode)] -struct IndexedUtilityPalletId(u16); - -impl TypeId for IndexedUtilityPalletId { - const TYPE_ID: [u8; 4] = *b"suba"; -} - -impl Pallet { - /// Derive a derivative account ID from the owner account and the sub-account index. - pub fn derivative_account_id( - who: T::AccountId, - index: u16, - ) -> Result { - let entropy = (b"modlpy/utilisuba", who, index).using_encoded(blake2_256); - T::AccountId::decode(&mut TrailingZeroInput::new(entropy.as_ref())) - .map_err(|_| Error::::InvalidDerivedAccount.into()) - } -} diff --git a/pallets/utility/src/tests.rs b/pallets/utility/src/tests.rs deleted file mode 100644 index 14020ec8bf..0000000000 --- a/pallets/utility/src/tests.rs +++ /dev/null @@ -1,1019 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Tests for Utility Pallet - -#![cfg(test)] -#![allow( - clippy::arithmetic_side_effects, - clippy::expect_used, - clippy::unwrap_used -)] - -use super::*; - -use crate as utility; -use frame_support::{ - assert_err_ignore_postinfo, assert_noop, assert_ok, derive_impl, - dispatch::{DispatchErrorWithPostInfo, Pays}, - parameter_types, storage, - traits::{ConstU64, Contains}, - weights::Weight, -}; -use sp_runtime::{ - BuildStorage, DispatchError, TokenError, - traits::{BadOrigin, Dispatchable}, -}; - -type BlockNumber = u64; - -// example module to test behaviors. -#[frame_support::pallet(dev_mode)] -#[allow(clippy::large_enum_variant)] -pub mod example { - use frame_support::{dispatch::WithPostDispatchInfo, pallet_prelude::*}; - use frame_system::pallet_prelude::*; - - #[pallet::pallet] - pub struct Pallet(_); - - #[pallet::config] - pub trait Config: frame_system::Config {} - - #[pallet::call] - impl Pallet { - #[pallet::call_index(0)] - #[pallet::weight(*_weight)] - pub fn noop(_origin: OriginFor, _weight: Weight) -> DispatchResult { - Ok(()) - } - - #[pallet::call_index(1)] - #[pallet::weight(*_start_weight)] - pub fn foobar( - origin: OriginFor, - err: bool, - _start_weight: Weight, - end_weight: Option, - ) -> DispatchResultWithPostInfo { - let _ = ensure_signed(origin)?; - if err { - let error: DispatchError = "The cake is a lie.".into(); - if let Some(weight) = end_weight { - Err(error.with_weight(weight)) - } else { - Err(error)? - } - } else { - Ok(end_weight.into()) - } - } - - #[pallet::call_index(2)] - #[pallet::weight(0)] - pub fn big_variant(_origin: OriginFor, _arg: [u8; 400]) -> DispatchResult { - Ok(()) - } - } -} - -type Block = frame_system::mocking::MockBlock; - -frame_support::construct_runtime!( - pub enum Test - { - System: frame_system = 1, - Timestamp: pallet_timestamp = 2, - Balances: pallet_balances = 3, - RootTesting: pallet_root_testing = 4, - Utility: utility = 6, - Example: example = 7, - } -); - -parameter_types! { - pub BlockWeights: frame_system::limits::BlockWeights = - frame_system::limits::BlockWeights::simple_max(Weight::MAX); -} -#[derive_impl(frame_system::config_preludes::TestDefaultConfig)] -impl frame_system::Config for Test { - type BaseCallFilter = TestBaseCallFilter; - type BlockWeights = BlockWeights; - type Block = Block; - type AccountData = pallet_balances::AccountData; -} - -#[derive_impl(pallet_balances::config_preludes::TestDefaultConfig)] -impl pallet_balances::Config for Test { - type AccountStore = System; -} - -impl pallet_root_testing::Config for Test { - type RuntimeEvent = RuntimeEvent; -} - -impl pallet_timestamp::Config for Test { - type Moment = u64; - type OnTimestampSet = (); - type MinimumPeriod = ConstU64<3>; - type WeightInfo = (); -} - -parameter_types! { - pub const MultisigDepositBase: u64 = 1; - pub const MultisigDepositFactor: u64 = 1; - pub const MaxSignatories: u32 = 3; - pub const MotionDuration: BlockNumber = 3; - pub const MaxProposals: u32 = 100; - pub const MaxMembers: u32 = 100; - pub MaxProposalWeight: Weight = BlockWeights::get().max_block.saturating_div(2); -} - -impl example::Config for Test {} - -pub struct TestBaseCallFilter; -impl Contains for TestBaseCallFilter { - fn contains(c: &RuntimeCall) -> bool { - match *c { - // Transfer works. Use `transfer_keep_alive` for a call that doesn't pass the filter. - RuntimeCall::Balances(pallet_balances::Call::transfer_allow_death { .. }) => true, - RuntimeCall::Utility(_) => true, - // For benchmarking, this acts as a noop call - RuntimeCall::System(frame_system::Call::remark { .. }) => true, - // For tests - RuntimeCall::Example(_) => true, - _ => false, - } - } -} - -impl Config for Test { - type RuntimeCall = RuntimeCall; - type PalletsOrigin = OriginCaller; - type WeightInfo = (); -} - -type ExampleCall = example::Call; -type UtilityCall = crate::Call; - -use frame_system::Call as SystemCall; -use pallet_balances::Call as BalancesCall; -use pallet_root_testing::Call as RootTestingCall; -use pallet_timestamp::Call as TimestampCall; - -pub fn new_test_ext() -> sp_io::TestExternalities { - let mut t = frame_system::GenesisConfig::::default() - .build_storage() - .unwrap(); - pallet_balances::GenesisConfig:: { - balances: vec![(1, 10), (2, 10), (3, 10), (4, 10), (5, 2)], - ..Default::default() - } - .assimilate_storage(&mut t) - .unwrap(); - - let mut ext = sp_io::TestExternalities::new(t); - ext.execute_with(|| System::set_block_number(1)); - ext -} - -fn call_transfer(dest: u64, value: u64) -> RuntimeCall { - RuntimeCall::Balances(BalancesCall::transfer_allow_death { dest, value }) -} - -fn call_foobar(err: bool, start_weight: Weight, end_weight: Option) -> RuntimeCall { - RuntimeCall::Example(ExampleCall::foobar { - err, - start_weight, - end_weight, - }) -} - -fn utility_events() -> Vec { - System::events() - .into_iter() - .map(|r| r.event) - .filter_map(|e| { - if let RuntimeEvent::Utility(inner) = e { - Some(inner) - } else { - None - } - }) - .collect() -} - -#[test] -fn as_derivative_works() { - new_test_ext().execute_with(|| { - let sub_1_0 = Utility::derivative_account_id(1, 0).unwrap(); - assert_ok!(Balances::transfer_allow_death( - RuntimeOrigin::signed(1), - sub_1_0, - 5 - )); - assert_err_ignore_postinfo!( - Utility::as_derivative(RuntimeOrigin::signed(1), 1, Box::new(call_transfer(6, 3)),), - TokenError::FundsUnavailable, - ); - assert_ok!(Utility::as_derivative( - RuntimeOrigin::signed(1), - 0, - Box::new(call_transfer(2, 3)), - )); - assert_eq!(Balances::free_balance(sub_1_0), 2); - assert_eq!(Balances::free_balance(2), 13); - }); -} - -#[test] -fn as_derivative_handles_weight_refund() { - new_test_ext().execute_with(|| { - let start_weight = Weight::from_parts(100, 0); - let end_weight = Weight::from_parts(75, 0); - let diff = start_weight - end_weight; - - // Full weight when ok - let inner_call = call_foobar(false, start_weight, None); - let call = RuntimeCall::Utility(UtilityCall::as_derivative { - index: 0, - call: Box::new(inner_call), - }); - let info = call.get_dispatch_info(); - let result = call.dispatch(RuntimeOrigin::signed(1)); - assert_ok!(result); - assert_eq!(extract_actual_weight(&result, &info), info.call_weight); - - // Refund weight when ok - let inner_call = call_foobar(false, start_weight, Some(end_weight)); - let call = RuntimeCall::Utility(UtilityCall::as_derivative { - index: 0, - call: Box::new(inner_call), - }); - let info = call.get_dispatch_info(); - let result = call.dispatch(RuntimeOrigin::signed(1)); - assert_ok!(result); - // Diff is refunded - assert_eq!( - extract_actual_weight(&result, &info), - info.call_weight - diff - ); - - // Full weight when err - let inner_call = call_foobar(true, start_weight, None); - let call = RuntimeCall::Utility(UtilityCall::as_derivative { - index: 0, - call: Box::new(inner_call), - }); - let info = call.get_dispatch_info(); - let result = call.dispatch(RuntimeOrigin::signed(1)); - assert_noop!( - result, - DispatchErrorWithPostInfo { - post_info: PostDispatchInfo { - // No weight is refunded - actual_weight: Some(info.call_weight), - pays_fee: Pays::Yes, - }, - error: DispatchError::Other("The cake is a lie."), - } - ); - - // Refund weight when err - let inner_call = call_foobar(true, start_weight, Some(end_weight)); - let call = RuntimeCall::Utility(UtilityCall::as_derivative { - index: 0, - call: Box::new(inner_call), - }); - let info = call.get_dispatch_info(); - let result = call.dispatch(RuntimeOrigin::signed(1)); - assert_noop!( - result, - DispatchErrorWithPostInfo { - post_info: PostDispatchInfo { - // Diff is refunded - actual_weight: Some(info.call_weight - diff), - pays_fee: Pays::Yes, - }, - error: DispatchError::Other("The cake is a lie."), - } - ); - }); -} - -#[test] -fn as_derivative_filters() { - new_test_ext().execute_with(|| { - assert_err_ignore_postinfo!( - Utility::as_derivative( - RuntimeOrigin::signed(1), - 1, - Box::new(RuntimeCall::Balances( - pallet_balances::Call::transfer_keep_alive { dest: 2, value: 1 } - )), - ), - DispatchError::from(frame_system::Error::::CallFiltered), - ); - }); -} - -#[test] -fn batch_with_root_works() { - new_test_ext().execute_with(|| { - let k = b"a".to_vec(); - let call = RuntimeCall::System(frame_system::Call::set_storage { - items: vec![(k.clone(), k.clone())], - }); - assert!(!TestBaseCallFilter::contains(&call)); - assert_eq!(Balances::free_balance(1), 10); - assert_eq!(Balances::free_balance(2), 10); - assert_ok!(Utility::batch( - RuntimeOrigin::root(), - vec![ - RuntimeCall::Balances(BalancesCall::force_transfer { - source: 1, - dest: 2, - value: 5 - }), - RuntimeCall::Balances(BalancesCall::force_transfer { - source: 1, - dest: 2, - value: 5 - }), - call, // Check filters are correctly bypassed - ] - )); - assert_eq!(Balances::free_balance(1), 0); - assert_eq!(Balances::free_balance(2), 20); - assert_eq!(storage::unhashed::get_raw(&k), Some(k)); - }); -} - -#[test] -fn batch_with_signed_works() { - new_test_ext().execute_with(|| { - assert_eq!(Balances::free_balance(1), 10); - assert_eq!(Balances::free_balance(2), 10); - assert_ok!(Utility::batch( - RuntimeOrigin::signed(1), - vec![call_transfer(2, 5), call_transfer(2, 5)] - ),); - assert_eq!(Balances::free_balance(1), 0); - assert_eq!(Balances::free_balance(2), 20); - }); -} - -#[test] -fn batch_with_signed_filters() { - new_test_ext().execute_with(|| { - assert_ok!(Utility::batch( - RuntimeOrigin::signed(1), - vec![RuntimeCall::Balances( - pallet_balances::Call::transfer_keep_alive { dest: 2, value: 1 } - )] - ),); - System::assert_last_event( - utility::Event::BatchInterrupted { - index: 0, - error: frame_system::Error::::CallFiltered.into(), - } - .into(), - ); - }); -} - -#[test] -fn batch_early_exit_works() { - new_test_ext().execute_with(|| { - assert_eq!(Balances::free_balance(1), 10); - assert_eq!(Balances::free_balance(2), 10); - assert_ok!(Utility::batch( - RuntimeOrigin::signed(1), - vec![ - call_transfer(2, 5), - call_transfer(2, 10), - call_transfer(2, 5), - ] - ),); - assert_eq!(Balances::free_balance(1), 5); - assert_eq!(Balances::free_balance(2), 15); - }); -} - -#[test] -fn batch_weight_calculation_doesnt_overflow() { - use sp_runtime::Perbill; - new_test_ext().execute_with(|| { - let big_call = RuntimeCall::RootTesting(RootTestingCall::fill_block { - ratio: Perbill::from_percent(50), - }); - assert_eq!(big_call.get_dispatch_info().call_weight, Weight::MAX / 2); - - // 3 * 50% saturates to 100% - let batch_call = RuntimeCall::Utility(crate::Call::batch { - calls: vec![big_call.clone(), big_call.clone(), big_call.clone()], - }); - - assert_eq!(batch_call.get_dispatch_info().call_weight, Weight::MAX); - }); -} - -#[test] -fn batch_handles_weight_refund() { - new_test_ext().execute_with(|| { - let start_weight = Weight::from_parts(100, 0); - let end_weight = Weight::from_parts(75, 0); - let diff = start_weight - end_weight; - let batch_len = 4; - - // Full weight when ok - let inner_call = call_foobar(false, start_weight, None); - let batch_calls = vec![inner_call; batch_len as usize]; - let call = RuntimeCall::Utility(UtilityCall::batch { calls: batch_calls }); - let info = call.get_dispatch_info(); - let result = call.dispatch(RuntimeOrigin::signed(1)); - assert_ok!(result); - assert_eq!(extract_actual_weight(&result, &info), info.call_weight); - - // Refund weight when ok - let inner_call = call_foobar(false, start_weight, Some(end_weight)); - let batch_calls = vec![inner_call; batch_len as usize]; - let call = RuntimeCall::Utility(UtilityCall::batch { calls: batch_calls }); - let info = call.get_dispatch_info(); - let result = call.dispatch(RuntimeOrigin::signed(1)); - assert_ok!(result); - // Diff is refunded - assert_eq!( - extract_actual_weight(&result, &info), - info.call_weight - diff * batch_len - ); - - // Full weight when err - let good_call = call_foobar(false, start_weight, None); - let bad_call = call_foobar(true, start_weight, None); - let batch_calls = vec![good_call, bad_call]; - let call = RuntimeCall::Utility(UtilityCall::batch { calls: batch_calls }); - let info = call.get_dispatch_info(); - let result = call.dispatch(RuntimeOrigin::signed(1)); - assert_ok!(result); - System::assert_last_event( - utility::Event::BatchInterrupted { - index: 1, - error: DispatchError::Other(""), - } - .into(), - ); - // No weight is refunded - assert_eq!(extract_actual_weight(&result, &info), info.call_weight); - - // Refund weight when err - let good_call = call_foobar(false, start_weight, Some(end_weight)); - let bad_call = call_foobar(true, start_weight, Some(end_weight)); - let batch_calls = vec![good_call, bad_call]; - let batch_len = batch_calls.len() as u64; - let call = RuntimeCall::Utility(UtilityCall::batch { calls: batch_calls }); - let info = call.get_dispatch_info(); - let result = call.dispatch(RuntimeOrigin::signed(1)); - assert_ok!(result); - System::assert_last_event( - utility::Event::BatchInterrupted { - index: 1, - error: DispatchError::Other(""), - } - .into(), - ); - assert_eq!( - extract_actual_weight(&result, &info), - info.call_weight - diff * batch_len - ); - - // Partial batch completion - let good_call = call_foobar(false, start_weight, Some(end_weight)); - let bad_call = call_foobar(true, start_weight, Some(end_weight)); - let batch_calls = vec![good_call, bad_call.clone(), bad_call]; - let call = RuntimeCall::Utility(UtilityCall::batch { calls: batch_calls }); - let info = call.get_dispatch_info(); - let result = call.dispatch(RuntimeOrigin::signed(1)); - assert_ok!(result); - System::assert_last_event( - utility::Event::BatchInterrupted { - index: 1, - error: DispatchError::Other(""), - } - .into(), - ); - assert_eq!( - extract_actual_weight(&result, &info), - // Real weight is 2 calls at end_weight - ::WeightInfo::batch(2) + end_weight * 2, - ); - }); -} - -#[test] -fn batch_all_works() { - new_test_ext().execute_with(|| { - assert_eq!(Balances::free_balance(1), 10); - assert_eq!(Balances::free_balance(2), 10); - assert_ok!(Utility::batch_all( - RuntimeOrigin::signed(1), - vec![call_transfer(2, 5), call_transfer(2, 5)] - ),); - assert_eq!(Balances::free_balance(1), 0); - assert_eq!(Balances::free_balance(2), 20); - }); -} - -#[test] -fn batch_all_revert() { - new_test_ext().execute_with(|| { - let call = call_transfer(2, 5); - let info = call.get_dispatch_info(); - - assert_eq!(Balances::free_balance(1), 10); - assert_eq!(Balances::free_balance(2), 10); - let batch_all_calls = RuntimeCall::Utility(crate::Call::::batch_all { - calls: vec![ - call_transfer(2, 5), - call_transfer(2, 10), - call_transfer(2, 5), - ], - }); - assert_noop!( - batch_all_calls.dispatch(RuntimeOrigin::signed(1)), - DispatchErrorWithPostInfo { - post_info: PostDispatchInfo { - actual_weight: Some( - ::WeightInfo::batch_all(2) + info.call_weight * 2 - ), - pays_fee: Pays::Yes - }, - error: TokenError::FundsUnavailable.into(), - } - ); - assert_eq!(Balances::free_balance(1), 10); - assert_eq!(Balances::free_balance(2), 10); - }); -} - -#[test] -fn batch_all_handles_weight_refund() { - new_test_ext().execute_with(|| { - let start_weight = Weight::from_parts(100, 0); - let end_weight = Weight::from_parts(75, 0); - let diff = start_weight - end_weight; - let batch_len = 4; - - // Full weight when ok - let inner_call = call_foobar(false, start_weight, None); - let batch_calls = vec![inner_call; batch_len as usize]; - let call = RuntimeCall::Utility(UtilityCall::batch_all { calls: batch_calls }); - let info = call.get_dispatch_info(); - let result = call.dispatch(RuntimeOrigin::signed(1)); - assert_ok!(result); - assert_eq!(extract_actual_weight(&result, &info), info.call_weight); - - // Refund weight when ok - let inner_call = call_foobar(false, start_weight, Some(end_weight)); - let batch_calls = vec![inner_call; batch_len as usize]; - let call = RuntimeCall::Utility(UtilityCall::batch_all { calls: batch_calls }); - let info = call.get_dispatch_info(); - let result = call.dispatch(RuntimeOrigin::signed(1)); - assert_ok!(result); - // Diff is refunded - assert_eq!( - extract_actual_weight(&result, &info), - info.call_weight - diff * batch_len - ); - - // Full weight when err - let good_call = call_foobar(false, start_weight, None); - let bad_call = call_foobar(true, start_weight, None); - let batch_calls = vec![good_call, bad_call]; - let call = RuntimeCall::Utility(UtilityCall::batch_all { calls: batch_calls }); - let info = call.get_dispatch_info(); - let result = call.dispatch(RuntimeOrigin::signed(1)); - assert_err_ignore_postinfo!(result, "The cake is a lie."); - // No weight is refunded - assert_eq!(extract_actual_weight(&result, &info), info.call_weight); - - // Refund weight when err - let good_call = call_foobar(false, start_weight, Some(end_weight)); - let bad_call = call_foobar(true, start_weight, Some(end_weight)); - let batch_calls = vec![good_call, bad_call]; - let batch_len = batch_calls.len() as u64; - let call = RuntimeCall::Utility(UtilityCall::batch_all { calls: batch_calls }); - let info = call.get_dispatch_info(); - let result = call.dispatch(RuntimeOrigin::signed(1)); - assert_err_ignore_postinfo!(result, "The cake is a lie."); - assert_eq!( - extract_actual_weight(&result, &info), - info.call_weight - diff * batch_len - ); - - // Partial batch completion - let good_call = call_foobar(false, start_weight, Some(end_weight)); - let bad_call = call_foobar(true, start_weight, Some(end_weight)); - let batch_calls = vec![good_call, bad_call.clone(), bad_call]; - let call = RuntimeCall::Utility(UtilityCall::batch_all { calls: batch_calls }); - let info = call.get_dispatch_info(); - let result = call.dispatch(RuntimeOrigin::signed(1)); - assert_err_ignore_postinfo!(result, "The cake is a lie."); - assert_eq!( - extract_actual_weight(&result, &info), - // Real weight is 2 calls at end_weight - ::WeightInfo::batch_all(2) + end_weight * 2, - ); - }); -} - -#[test] -fn batch_all_does_not_nest() { - new_test_ext().execute_with(|| { - let batch_all = RuntimeCall::Utility(UtilityCall::batch_all { - calls: vec![ - call_transfer(2, 1), - call_transfer(2, 1), - call_transfer(2, 1), - ], - }); - - let info = batch_all.get_dispatch_info(); - - assert_eq!(Balances::free_balance(1), 10); - assert_eq!(Balances::free_balance(2), 10); - // A nested batch_all call will not pass the filter, and fail with `BadOrigin`. - assert_noop!( - Utility::batch_all(RuntimeOrigin::signed(1), vec![batch_all.clone()]), - DispatchErrorWithPostInfo { - post_info: PostDispatchInfo { - actual_weight: Some( - ::WeightInfo::batch_all(1) + info.call_weight - ), - pays_fee: Pays::Yes - }, - error: frame_system::Error::::CallFiltered.into(), - } - ); - - // And for those who want to get a little fancy, we check that the filter persists across - // other kinds of dispatch wrapping functions... in this case - // `batch_all(batch(batch_all(..)))` - let batch_nested = RuntimeCall::Utility(UtilityCall::batch { - calls: vec![batch_all], - }); - // Batch will end with `Ok`, but does not actually execute as we can see from the event - // and balances. - assert_ok!(Utility::batch_all( - RuntimeOrigin::signed(1), - vec![batch_nested] - )); - System::assert_has_event( - utility::Event::BatchInterrupted { - index: 0, - error: frame_system::Error::::CallFiltered.into(), - } - .into(), - ); - assert_eq!(Balances::free_balance(1), 10); - assert_eq!(Balances::free_balance(2), 10); - }); -} - -#[test] -fn batch_limit() { - new_test_ext().execute_with(|| { - let calls = vec![RuntimeCall::System(SystemCall::remark { remark: vec![] }); 40_000]; - assert_noop!( - Utility::batch(RuntimeOrigin::signed(1), calls.clone()), - Error::::TooManyCalls - ); - assert_noop!( - Utility::batch_all(RuntimeOrigin::signed(1), calls), - Error::::TooManyCalls - ); - }); -} - -#[test] -fn force_batch_works() { - new_test_ext().execute_with(|| { - assert_eq!(Balances::free_balance(1), 10); - assert_eq!(Balances::free_balance(2), 10); - assert_ok!(Utility::force_batch( - RuntimeOrigin::signed(1), - vec![ - call_transfer(2, 5), - call_foobar(true, Weight::from_parts(75, 0), None), - call_transfer(2, 10), - call_transfer(2, 5), - ] - )); - System::assert_last_event(utility::Event::BatchCompletedWithErrors.into()); - System::assert_has_event( - utility::Event::ItemFailed { - error: DispatchError::Other(""), - } - .into(), - ); - assert_eq!(Balances::free_balance(1), 0); - assert_eq!(Balances::free_balance(2), 20); - - assert_ok!(Utility::force_batch( - RuntimeOrigin::signed(2), - vec![call_transfer(1, 5), call_transfer(1, 5),] - )); - System::assert_last_event(utility::Event::BatchCompleted.into()); - - assert_ok!(Utility::force_batch( - RuntimeOrigin::signed(1), - vec![call_transfer(2, 50),] - ),); - System::assert_last_event(utility::Event::BatchCompletedWithErrors.into()); - }); -} - -#[test] -fn none_origin_does_not_work() { - new_test_ext().execute_with(|| { - assert_noop!( - Utility::force_batch(RuntimeOrigin::none(), vec![]), - BadOrigin - ); - assert_noop!(Utility::batch(RuntimeOrigin::none(), vec![]), BadOrigin); - assert_noop!(Utility::batch_all(RuntimeOrigin::none(), vec![]), BadOrigin); - }) -} - -#[test] -fn batch_doesnt_work_with_inherents() { - new_test_ext().execute_with(|| { - // fails because inherents expect the origin to be none. - assert_ok!(Utility::batch( - RuntimeOrigin::signed(1), - vec![RuntimeCall::Timestamp(TimestampCall::set { now: 42 }),] - )); - System::assert_last_event( - utility::Event::BatchInterrupted { - index: 0, - error: frame_system::Error::::CallFiltered.into(), - } - .into(), - ); - }) -} - -#[test] -fn force_batch_doesnt_work_with_inherents() { - new_test_ext().execute_with(|| { - // fails because inherents expect the origin to be none. - assert_ok!(Utility::force_batch( - RuntimeOrigin::root(), - vec![RuntimeCall::Timestamp(TimestampCall::set { now: 42 }),] - )); - System::assert_last_event(utility::Event::BatchCompletedWithErrors.into()); - }) -} - -#[test] -fn batch_all_doesnt_work_with_inherents() { - new_test_ext().execute_with(|| { - let batch_all = RuntimeCall::Utility(UtilityCall::batch_all { - calls: vec![RuntimeCall::Timestamp(TimestampCall::set { now: 42 })], - }); - let info = batch_all.get_dispatch_info(); - - // fails because inherents expect the origin to be none. - assert_noop!( - batch_all.dispatch(RuntimeOrigin::signed(1)), - DispatchErrorWithPostInfo { - post_info: PostDispatchInfo { - actual_weight: Some(info.call_weight), - pays_fee: Pays::Yes - }, - error: frame_system::Error::::CallFiltered.into(), - } - ); - }) -} - -#[test] -fn with_weight_works() { - new_test_ext().execute_with(|| { - use frame_system::WeightInfo; - let upgrade_code_call = Box::new(RuntimeCall::System( - frame_system::Call::set_code_without_checks { code: vec![] }, - )); - // Weight before is max. - assert_eq!( - upgrade_code_call.get_dispatch_info().call_weight, - ::SystemWeightInfo::set_code() - ); - assert_eq!( - upgrade_code_call.get_dispatch_info().class, - frame_support::dispatch::DispatchClass::Operational - ); - - let with_weight_call = Call::::with_weight { - call: upgrade_code_call, - weight: Weight::from_parts(123, 456), - }; - // Weight after is set by Root. - assert_eq!( - with_weight_call.get_dispatch_info().call_weight, - Weight::from_parts(123, 456) - ); - assert_eq!( - with_weight_call.get_dispatch_info().class, - frame_support::dispatch::DispatchClass::Normal // We only allow normal in subtensor - ); - }) -} - -#[test] -fn dispatch_as_works() { - new_test_ext().execute_with(|| { - Balances::force_set_balance(RuntimeOrigin::root(), 666, 100).unwrap(); - assert_eq!(Balances::free_balance(666), 100); - assert_eq!(Balances::free_balance(777), 0); - assert_ok!(Utility::dispatch_as( - RuntimeOrigin::root(), - Box::new(OriginCaller::system(frame_system::RawOrigin::Signed(666))), - Box::new(call_transfer(777, 100)) - )); - assert_eq!(Balances::free_balance(666), 0); - assert_eq!(Balances::free_balance(777), 100); - - System::reset_events(); - assert_ok!(Utility::dispatch_as( - RuntimeOrigin::root(), - Box::new(OriginCaller::system(frame_system::RawOrigin::Signed(777))), - Box::new(RuntimeCall::Timestamp(TimestampCall::set { now: 0 })) - )); - assert_eq!( - utility_events(), - vec![Event::DispatchedAs { - result: Err(DispatchError::BadOrigin) - }] - ); - }) -} - -#[test] -fn if_else_with_root_works() { - new_test_ext().execute_with(|| { - let k = b"a".to_vec(); - let call = RuntimeCall::System(frame_system::Call::set_storage { - items: vec![(k.clone(), k.clone())], - }); - assert!(!TestBaseCallFilter::contains(&call)); - assert_eq!(Balances::free_balance(1), 10); - assert_eq!(Balances::free_balance(2), 10); - assert_ok!(Utility::if_else( - RuntimeOrigin::root(), - RuntimeCall::Balances(BalancesCall::force_transfer { - source: 1, - dest: 2, - value: 11 - }) - .into(), - call.into(), - )); - assert_eq!(Balances::free_balance(1), 10); - assert_eq!(Balances::free_balance(2), 10); - assert_eq!(storage::unhashed::get_raw(&k), Some(k)); - System::assert_last_event( - utility::Event::IfElseFallbackCalled { - main_error: TokenError::FundsUnavailable.into(), - } - .into(), - ); - }); -} - -#[test] -fn if_else_with_signed_works() { - new_test_ext().execute_with(|| { - assert_eq!(Balances::free_balance(1), 10); - assert_eq!(Balances::free_balance(2), 10); - assert_ok!(Utility::if_else( - RuntimeOrigin::signed(1), - call_transfer(2, 11).into(), - call_transfer(2, 5).into() - )); - assert_eq!(Balances::free_balance(1), 5); - assert_eq!(Balances::free_balance(2), 15); - - System::assert_last_event( - utility::Event::IfElseFallbackCalled { - main_error: TokenError::FundsUnavailable.into(), - } - .into(), - ); - }); -} - -#[test] -fn if_else_successful_main_call() { - new_test_ext().execute_with(|| { - assert_eq!(Balances::free_balance(1), 10); - assert_eq!(Balances::free_balance(2), 10); - assert_ok!(Utility::if_else( - RuntimeOrigin::signed(1), - call_transfer(2, 9).into(), - call_transfer(2, 1).into() - )); - assert_eq!(Balances::free_balance(1), 1); - assert_eq!(Balances::free_balance(2), 19); - - System::assert_last_event(utility::Event::IfElseMainSuccess.into()); - }) -} - -#[test] -fn dispatch_as_fallible_works() { - new_test_ext().execute_with(|| { - Balances::force_set_balance(RuntimeOrigin::root(), 666, 100).unwrap(); - assert_eq!(Balances::free_balance(666), 100); - assert_eq!(Balances::free_balance(777), 0); - assert_ok!(Utility::dispatch_as_fallible( - RuntimeOrigin::root(), - Box::new(OriginCaller::system(frame_system::RawOrigin::Signed(666))), - Box::new(call_transfer(777, 100)) - )); - assert_eq!(Balances::free_balance(666), 0); - assert_eq!(Balances::free_balance(777), 100); - - assert_noop!( - Utility::dispatch_as_fallible( - RuntimeOrigin::root(), - Box::new(OriginCaller::system(frame_system::RawOrigin::Signed(777))), - Box::new(RuntimeCall::Timestamp(TimestampCall::set { now: 0 })) - ), - DispatchError::BadOrigin, - ); - }) -} - -#[test] -fn if_else_failing_fallback_call() { - new_test_ext().execute_with(|| { - assert_eq!(Balances::free_balance(1), 10); - assert_eq!(Balances::free_balance(2), 10); - assert_err_ignore_postinfo!( - Utility::if_else( - RuntimeOrigin::signed(1), - call_transfer(2, 11).into(), - call_transfer(2, 11).into() - ), - TokenError::FundsUnavailable - ); - assert_eq!(Balances::free_balance(1), 10); - assert_eq!(Balances::free_balance(2), 10); - }) -} - -#[test] -fn if_else_with_nested_if_else_works() { - new_test_ext().execute_with(|| { - assert_eq!(Balances::free_balance(1), 10); - assert_eq!(Balances::free_balance(2), 10); - - let main_call = call_transfer(2, 11).into(); - let fallback_call = call_transfer(2, 5).into(); - - let nested_if_else_call = RuntimeCall::Utility(UtilityCall::if_else { - main: main_call, - fallback: fallback_call, - }) - .into(); - - // Nested `if_else` call. - assert_ok!(Utility::if_else( - RuntimeOrigin::signed(1), - nested_if_else_call, - call_transfer(2, 7).into() - )); - - // inner if_else fallback is executed. - assert_eq!(Balances::free_balance(1), 5); - assert_eq!(Balances::free_balance(2), 15); - - // Ensure the correct event was triggered for the main call(nested if_else). - System::assert_last_event(utility::Event::IfElseMainSuccess.into()); - }); -} diff --git a/pallets/utility/src/weights.rs b/pallets/utility/src/weights.rs deleted file mode 100644 index 0287a464fe..0000000000 --- a/pallets/utility/src/weights.rs +++ /dev/null @@ -1,221 +0,0 @@ - -//! Autogenerated weights for `pallet_subtensor_utility` -//! -//! THIS FILE WAS AUTO-GENERATED USING THE SUBSTRATE BENCHMARK CLI VERSION 49.1.0 -//! DATE: 2026-05-31, STEPS: `50`, REPEAT: `20`, LOW RANGE: `[]`, HIGH RANGE: `[]` -//! WORST CASE MAP SIZE: `1000000` -//! HOSTNAME: `runnervm3jyl0`, CPU: `AMD EPYC 9V74 80-Core Processor` -//! WASM-EXECUTION: `Compiled`, CHAIN: `None`, DB CACHE: `1024` - -// Executed Command: -// /home/runner/work/subtensor/subtensor/target/production/node-subtensor -// benchmark -// pallet -// --runtime=/home/runner/work/subtensor/subtensor/target/production/wbuild/node-subtensor-runtime/node_subtensor_runtime.compact.compressed.wasm -// --genesis-builder=runtime -// --genesis-builder-preset=benchmark -// --wasm-execution=compiled -// --pallet=pallet_subtensor_utility -// --extrinsic=* -// --steps=50 -// --repeat=20 -// --no-storage-info -// --no-min-squares -// --no-median-slopes -// --output=/tmp/tmp.wsE00cetaq -// --template=/home/runner/work/subtensor/subtensor/.maintain/frame-weight-template.hbs - -#![cfg_attr(rustfmt, rustfmt_skip)] -#![allow(unused_parens)] -#![allow(unused_imports)] -#![allow(missing_docs)] -#![allow(dead_code)] - -use frame_support::{traits::Get, weights::{Weight, constants::RocksDbWeight}}; -use core::marker::PhantomData; - -/// Weight functions needed for `pallet_subtensor_utility`. -pub trait WeightInfo { - fn batch(c: u32, ) -> Weight; - fn as_derivative() -> Weight; - fn batch_all(c: u32, ) -> Weight; - fn dispatch_as() -> Weight; - fn force_batch(c: u32, ) -> Weight; - fn dispatch_as_fallible() -> Weight; - fn if_else() -> Weight; -} - -/// Weights for `pallet_subtensor_utility` using the Substrate node and recommended hardware. -pub struct SubstrateWeight(PhantomData); -impl WeightInfo for SubstrateWeight { - /// Storage: `SafeMode::EnteredUntil` (r:1 w:0) - /// Proof: `SafeMode::EnteredUntil` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) - /// Storage: `SubtensorModule::ColdkeySwapAnnouncements` (r:1 w:0) - /// Proof: `SubtensorModule::ColdkeySwapAnnouncements` (`max_values`: None, `max_size`: None, mode: `Measured`) - /// The range of component `c` is `[0, 1000]`. - fn batch(c: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `518` - // Estimated: `3983` - // Minimum execution time: 4_006_000 picoseconds. - Weight::from_parts(12_108_520, 3983) - // Standard Error: 3_458 - .saturating_add(Weight::from_parts(5_277_918, 0).saturating_mul(c.into())) - .saturating_add(T::DbWeight::get().reads(2_u64)) - } - /// Storage: `SafeMode::EnteredUntil` (r:1 w:0) - /// Proof: `SafeMode::EnteredUntil` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) - /// Storage: `SubtensorModule::ColdkeySwapAnnouncements` (r:1 w:0) - /// Proof: `SubtensorModule::ColdkeySwapAnnouncements` (`max_values`: None, `max_size`: None, mode: `Measured`) - fn as_derivative() -> Weight { - // Proof Size summary in bytes: - // Measured: `518` - // Estimated: `3983` - // Minimum execution time: 13_480_000 picoseconds. - Weight::from_parts(13_830_000, 3983) - .saturating_add(T::DbWeight::get().reads(2_u64)) - } - /// Storage: `SafeMode::EnteredUntil` (r:1 w:0) - /// Proof: `SafeMode::EnteredUntil` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) - /// Storage: `SubtensorModule::ColdkeySwapAnnouncements` (r:1 w:0) - /// Proof: `SubtensorModule::ColdkeySwapAnnouncements` (`max_values`: None, `max_size`: None, mode: `Measured`) - /// The range of component `c` is `[0, 1000]`. - fn batch_all(c: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `518` - // Estimated: `3983` - // Minimum execution time: 3_825_000 picoseconds. - Weight::from_parts(15_244_012, 3983) - // Standard Error: 2_052 - .saturating_add(Weight::from_parts(5_505_817, 0).saturating_mul(c.into())) - .saturating_add(T::DbWeight::get().reads(2_u64)) - } - fn dispatch_as() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 5_398_000 picoseconds. - Weight::from_parts(5_768_000, 0) - } - /// Storage: `SafeMode::EnteredUntil` (r:1 w:0) - /// Proof: `SafeMode::EnteredUntil` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) - /// Storage: `SubtensorModule::ColdkeySwapAnnouncements` (r:1 w:0) - /// Proof: `SubtensorModule::ColdkeySwapAnnouncements` (`max_values`: None, `max_size`: None, mode: `Measured`) - /// The range of component `c` is `[0, 1000]`. - fn force_batch(c: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `518` - // Estimated: `3983` - // Minimum execution time: 3_896_000 picoseconds. - Weight::from_parts(1_067_442, 3983) - // Standard Error: 4_142 - .saturating_add(Weight::from_parts(5_312_644, 0).saturating_mul(c.into())) - .saturating_add(T::DbWeight::get().reads(2_u64)) - } - fn dispatch_as_fallible() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 5_498_000 picoseconds. - Weight::from_parts(5_708_000, 0) - } - /// Storage: `SafeMode::EnteredUntil` (r:1 w:0) - /// Proof: `SafeMode::EnteredUntil` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) - /// Storage: `SubtensorModule::ColdkeySwapAnnouncements` (r:1 w:0) - /// Proof: `SubtensorModule::ColdkeySwapAnnouncements` (`max_values`: None, `max_size`: None, mode: `Measured`) - fn if_else() -> Weight { - // Proof Size summary in bytes: - // Measured: `518` - // Estimated: `3983` - // Minimum execution time: 18_757_000 picoseconds. - Weight::from_parts(19_459_000, 3983) - .saturating_add(T::DbWeight::get().reads(2_u64)) - } -} - -// For backwards compatibility and tests. -impl WeightInfo for () { - /// Storage: `SafeMode::EnteredUntil` (r:1 w:0) - /// Proof: `SafeMode::EnteredUntil` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) - /// Storage: `SubtensorModule::ColdkeySwapAnnouncements` (r:1 w:0) - /// Proof: `SubtensorModule::ColdkeySwapAnnouncements` (`max_values`: None, `max_size`: None, mode: `Measured`) - /// The range of component `c` is `[0, 1000]`. - fn batch(c: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `518` - // Estimated: `3983` - // Minimum execution time: 4_006_000 picoseconds. - Weight::from_parts(12_108_520, 3983) - // Standard Error: 3_458 - .saturating_add(Weight::from_parts(5_277_918, 0).saturating_mul(c.into())) - .saturating_add(RocksDbWeight::get().reads(2_u64)) - } - /// Storage: `SafeMode::EnteredUntil` (r:1 w:0) - /// Proof: `SafeMode::EnteredUntil` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) - /// Storage: `SubtensorModule::ColdkeySwapAnnouncements` (r:1 w:0) - /// Proof: `SubtensorModule::ColdkeySwapAnnouncements` (`max_values`: None, `max_size`: None, mode: `Measured`) - fn as_derivative() -> Weight { - // Proof Size summary in bytes: - // Measured: `518` - // Estimated: `3983` - // Minimum execution time: 13_480_000 picoseconds. - Weight::from_parts(13_830_000, 3983) - .saturating_add(RocksDbWeight::get().reads(2_u64)) - } - /// Storage: `SafeMode::EnteredUntil` (r:1 w:0) - /// Proof: `SafeMode::EnteredUntil` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) - /// Storage: `SubtensorModule::ColdkeySwapAnnouncements` (r:1 w:0) - /// Proof: `SubtensorModule::ColdkeySwapAnnouncements` (`max_values`: None, `max_size`: None, mode: `Measured`) - /// The range of component `c` is `[0, 1000]`. - fn batch_all(c: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `518` - // Estimated: `3983` - // Minimum execution time: 3_825_000 picoseconds. - Weight::from_parts(15_244_012, 3983) - // Standard Error: 2_052 - .saturating_add(Weight::from_parts(5_505_817, 0).saturating_mul(c.into())) - .saturating_add(RocksDbWeight::get().reads(2_u64)) - } - fn dispatch_as() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 5_398_000 picoseconds. - Weight::from_parts(5_768_000, 0) - } - /// Storage: `SafeMode::EnteredUntil` (r:1 w:0) - /// Proof: `SafeMode::EnteredUntil` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) - /// Storage: `SubtensorModule::ColdkeySwapAnnouncements` (r:1 w:0) - /// Proof: `SubtensorModule::ColdkeySwapAnnouncements` (`max_values`: None, `max_size`: None, mode: `Measured`) - /// The range of component `c` is `[0, 1000]`. - fn force_batch(c: u32, ) -> Weight { - // Proof Size summary in bytes: - // Measured: `518` - // Estimated: `3983` - // Minimum execution time: 3_896_000 picoseconds. - Weight::from_parts(1_067_442, 3983) - // Standard Error: 4_142 - .saturating_add(Weight::from_parts(5_312_644, 0).saturating_mul(c.into())) - .saturating_add(RocksDbWeight::get().reads(2_u64)) - } - fn dispatch_as_fallible() -> Weight { - // Proof Size summary in bytes: - // Measured: `0` - // Estimated: `0` - // Minimum execution time: 5_498_000 picoseconds. - Weight::from_parts(5_708_000, 0) - } - /// Storage: `SafeMode::EnteredUntil` (r:1 w:0) - /// Proof: `SafeMode::EnteredUntil` (`max_values`: Some(1), `max_size`: Some(4), added: 499, mode: `MaxEncodedLen`) - /// Storage: `SubtensorModule::ColdkeySwapAnnouncements` (r:1 w:0) - /// Proof: `SubtensorModule::ColdkeySwapAnnouncements` (`max_values`: None, `max_size`: None, mode: `Measured`) - fn if_else() -> Weight { - // Proof Size summary in bytes: - // Measured: `518` - // Estimated: `3983` - // Minimum execution time: 18_757_000 picoseconds. - Weight::from_parts(19_459_000, 3983) - .saturating_add(RocksDbWeight::get().reads(2_u64)) - } -} diff --git a/precompiles/Cargo.toml b/precompiles/Cargo.toml index dd5e20dfd0..9fa430d8b7 100644 --- a/precompiles/Cargo.toml +++ b/precompiles/Cargo.toml @@ -25,7 +25,7 @@ pallet-evm-precompile-modexp.workspace = true pallet-evm-precompile-sha3fips.workspace = true pallet-evm-precompile-simple.workspace = true pallet-evm-precompile-bn128.workspace = true -pallet-subtensor-proxy.workspace = true +pallet-proxy.workspace = true precompile-utils.workspace = true scale-info.workspace = true sp-core.workspace = true @@ -67,7 +67,7 @@ std = [ "pallet-evm/std", "pallet-preimage/std", "pallet-scheduler/std", - "pallet-subtensor-proxy/std", + "pallet-proxy/std", "pallet-subtensor-swap/std", "pallet-subtensor/std", "pallet-shield/std", @@ -94,7 +94,7 @@ runtime-benchmarks = [ "pallet-scheduler/runtime-benchmarks", "pallet-shield/runtime-benchmarks", "pallet-subtensor-swap/runtime-benchmarks", - "pallet-subtensor-proxy/runtime-benchmarks", + "pallet-proxy/runtime-benchmarks", "pallet-subtensor/runtime-benchmarks", "pallet-timestamp/runtime-benchmarks", "sp-runtime/runtime-benchmarks", diff --git a/precompiles/src/address_mapping.rs b/precompiles/src/address_mapping.rs index c8f3815c49..9787c0e147 100644 --- a/precompiles/src/address_mapping.rs +++ b/precompiles/src/address_mapping.rs @@ -8,7 +8,6 @@ use sp_core::{ByteArray, H256}; use frame_support::dispatch::{DispatchInfo, GetDispatchInfo, PostDispatchInfo}; use frame_support::traits::IsSubType; use pallet_evm::PrecompileHandle; -use pallet_subtensor_proxy as pallet_proxy; use precompile_utils::EvmResult; use precompile_utils::prelude::Address; use sp_runtime::traits::{AsSystemOriginSigner, Dispatchable}; diff --git a/precompiles/src/balance_transfer.rs b/precompiles/src/balance_transfer.rs index d8d10970a3..39b06d221b 100644 --- a/precompiles/src/balance_transfer.rs +++ b/precompiles/src/balance_transfer.rs @@ -19,7 +19,7 @@ where + pallet_evm::Config + pallet_subtensor::Config + pallet_shield::Config - + pallet_subtensor_proxy::Config + + pallet_proxy::Config + Send + Sync + scale_info::TypeInfo, @@ -30,7 +30,7 @@ where + IsSubType> + IsSubType> + IsSubType> - + IsSubType>, + + IsSubType>, ::RuntimeCall: From> + GetDispatchInfo + Dispatchable, @@ -48,7 +48,7 @@ where + pallet_evm::Config + pallet_subtensor::Config + pallet_shield::Config - + pallet_subtensor_proxy::Config + + pallet_proxy::Config + Send + Sync + scale_info::TypeInfo, @@ -59,7 +59,7 @@ where + IsSubType> + IsSubType> + IsSubType> - + IsSubType>, + + IsSubType>, ::RuntimeCall: From> + GetDispatchInfo + Dispatchable, diff --git a/precompiles/src/crowdloan.rs b/precompiles/src/crowdloan.rs index c474ab9405..c7d4a80699 100644 --- a/precompiles/src/crowdloan.rs +++ b/precompiles/src/crowdloan.rs @@ -7,7 +7,6 @@ use frame_support::traits::IsSubType; use frame_system::RawOrigin; use pallet_evm::AddressMapping; use pallet_evm::PrecompileHandle; -use pallet_subtensor_proxy as pallet_proxy; use precompile_utils::prelude::Address; use precompile_utils::{EvmResult, solidity::Codec}; use sp_core::{ByteArray, H256}; @@ -26,7 +25,7 @@ where + pallet_proxy::Config + pallet_subtensor::Config + pallet_shield::Config - + pallet_subtensor_proxy::Config + + pallet_proxy::Config + Send + Sync + scale_info::TypeInfo, @@ -38,7 +37,7 @@ where + IsSubType> + IsSubType> + IsSubType> - + IsSubType>, + + IsSubType>, ::AddressMapping: AddressMapping, { const INDEX: u64 = 2057; @@ -54,7 +53,7 @@ where + pallet_proxy::Config + pallet_subtensor::Config + pallet_shield::Config - + pallet_subtensor_proxy::Config + + pallet_proxy::Config + Send + Sync + scale_info::TypeInfo, @@ -66,7 +65,7 @@ where + IsSubType> + IsSubType> + IsSubType> - + IsSubType>, + + IsSubType>, ::RuntimeCall: From> + GetDispatchInfo + Dispatchable, diff --git a/precompiles/src/extensions.rs b/precompiles/src/extensions.rs index 4a7c418c86..02466572b5 100644 --- a/precompiles/src/extensions.rs +++ b/precompiles/src/extensions.rs @@ -60,7 +60,7 @@ pub(crate) trait PrecompileHandleExt: PrecompileHandle { + pallet_evm::Config + pallet_subtensor::Config + pallet_shield::Config - + pallet_subtensor_proxy::Config + + pallet_proxy::Config + Send + Sync + TypeInfo, @@ -70,7 +70,7 @@ pub(crate) trait PrecompileHandleExt: PrecompileHandle { + IsSubType> + IsSubType> + IsSubType> - + IsSubType>, + + IsSubType>, ::RuntimeOrigin: From> + AsSystemOriginSigner + Clone, { diff --git a/precompiles/src/leasing.rs b/precompiles/src/leasing.rs index 005782c776..700000932b 100644 --- a/precompiles/src/leasing.rs +++ b/precompiles/src/leasing.rs @@ -27,7 +27,7 @@ where + pallet_subtensor::Config + pallet_crowdloan::Config + pallet_shield::Config - + pallet_subtensor_proxy::Config + + pallet_proxy::Config + Send + Sync + scale_info::TypeInfo, @@ -40,7 +40,7 @@ where + IsSubType> + IsSubType> + IsSubType> - + IsSubType>, + + IsSubType>, ::AddressMapping: AddressMapping, { const INDEX: u64 = 2058; @@ -55,7 +55,7 @@ where + pallet_subtensor::Config + pallet_crowdloan::Config + pallet_shield::Config - + pallet_subtensor_proxy::Config + + pallet_proxy::Config + Send + Sync + scale_info::TypeInfo, @@ -68,7 +68,7 @@ where + IsSubType> + IsSubType> + IsSubType> - + IsSubType>, + + IsSubType>, ::AddressMapping: AddressMapping, { #[precompile::public("getLease(uint32)")] diff --git a/precompiles/src/lib.rs b/precompiles/src/lib.rs index 39815a6946..beef2f88a6 100644 --- a/precompiles/src/lib.rs +++ b/precompiles/src/lib.rs @@ -20,7 +20,6 @@ use pallet_evm_precompile_dispatch::Dispatch; use pallet_evm_precompile_modexp::Modexp; use pallet_evm_precompile_sha3fips::Sha3FIPS256; use pallet_evm_precompile_simple::{ECRecover, ECRecoverPublicKey, Identity, Ripemd160, Sha256}; -use pallet_subtensor_proxy as pallet_proxy; use sp_core::{H160, U256, crypto::ByteArray}; use sp_runtime::traits::{AsSystemOriginSigner, Dispatchable, StaticLookup}; use subtensor_runtime_common::ProxyType; @@ -77,7 +76,7 @@ where + pallet_proxy::Config + pallet_crowdloan::Config + pallet_shield::Config - + pallet_subtensor_proxy::Config + + pallet_proxy::Config + Send + Sync + scale_info::TypeInfo, @@ -93,7 +92,7 @@ where + IsSubType> + IsSubType> + IsSubType> - + IsSubType>, + + IsSubType>, ::AddressMapping: AddressMapping, ::Balance: TryFrom, <::Lookup as StaticLookup>::Source: From, @@ -114,7 +113,7 @@ where + pallet_proxy::Config + pallet_crowdloan::Config + pallet_shield::Config - + pallet_subtensor_proxy::Config + + pallet_proxy::Config + Send + Sync + scale_info::TypeInfo, @@ -130,7 +129,7 @@ where + IsSubType> + IsSubType> + IsSubType> - + IsSubType>, + + IsSubType>, ::AddressMapping: AddressMapping, ::Balance: TryFrom, <::Lookup as StaticLookup>::Source: From, @@ -182,7 +181,7 @@ where + pallet_proxy::Config + pallet_crowdloan::Config + pallet_shield::Config - + pallet_subtensor_proxy::Config + + pallet_proxy::Config + Send + Sync + scale_info::TypeInfo, @@ -198,7 +197,7 @@ where + IsSubType> + IsSubType> + IsSubType> - + IsSubType> + + IsSubType> + Decode, <::RuntimeCall as Dispatchable>::RuntimeOrigin: From>>, diff --git a/precompiles/src/mock.rs b/precompiles/src/mock.rs index 037e02d864..a21ea01edd 100644 --- a/precompiles/src/mock.rs +++ b/precompiles/src/mock.rs @@ -44,7 +44,7 @@ frame_support::construct_runtime!( Drand: pallet_drand::{Pallet, Call, Storage, Event} = 8, Swap: pallet_subtensor_swap::{Pallet, Call, Storage, Event} = 9, Crowdloan: pallet_crowdloan::{Pallet, Call, Storage, Event} = 10, - Proxy: pallet_subtensor_proxy = 11, + Proxy: pallet_proxy = 11, Evm: pallet_evm = 12, AdminUtils: pallet_admin_utils = 13, EVMChainId: pallet_evm_chain_id = 14, @@ -509,14 +509,15 @@ impl frame_support::traits::InstanceFilter for ProxyType { } } -impl pallet_subtensor_proxy::Config for Runtime { +impl pallet_proxy::Config for Runtime { + type RuntimeEvent = RuntimeEvent; type RuntimeCall = RuntimeCall; type Currency = Balances; type ProxyType = ProxyType; type ProxyDepositBase = ProxyDepositBase; type ProxyDepositFactor = ProxyDepositFactor; type MaxProxies = MaxProxies; - type WeightInfo = pallet_subtensor_proxy::weights::SubstrateWeight; + type WeightInfo = pallet_proxy::weights::SubstrateWeight; type MaxPending = MaxPending; type CallHasher = BlakeTwo256; type AnnouncementDepositBase = AnnouncementDepositBase; diff --git a/precompiles/src/neuron.rs b/precompiles/src/neuron.rs index 1397baf272..4ac450c1ba 100644 --- a/precompiles/src/neuron.rs +++ b/precompiles/src/neuron.rs @@ -20,7 +20,7 @@ where + pallet_evm::Config + pallet_subtensor::Config + pallet_shield::Config - + pallet_subtensor_proxy::Config + + pallet_proxy::Config + Send + Sync + scale_info::TypeInfo, @@ -32,7 +32,7 @@ where + IsSubType> + IsSubType> + IsSubType> - + IsSubType>, + + IsSubType>, ::AddressMapping: AddressMapping, { const INDEX: u64 = 2052; @@ -46,7 +46,7 @@ where + pallet_evm::Config + pallet_subtensor::Config + pallet_shield::Config - + pallet_subtensor_proxy::Config + + pallet_proxy::Config + Send + Sync + scale_info::TypeInfo, @@ -58,7 +58,7 @@ where + IsSubType> + IsSubType> + IsSubType> - + IsSubType>, + + IsSubType>, ::AddressMapping: AddressMapping, { #[precompile::public("setWeights(uint16,uint16[],uint16[],uint64)")] diff --git a/precompiles/src/proxy.rs b/precompiles/src/proxy.rs index 3312b67194..d5bd17c2b2 100644 --- a/precompiles/src/proxy.rs +++ b/precompiles/src/proxy.rs @@ -8,7 +8,6 @@ use frame_support::dispatch::{DispatchInfo, GetDispatchInfo, PostDispatchInfo}; use frame_support::traits::IsSubType; use frame_system::RawOrigin; use pallet_evm::{AddressMapping, PrecompileHandle}; -use pallet_subtensor_proxy as pallet_proxy; use precompile_utils::EvmResult; use sp_core::{H256, U256}; use sp_runtime::{ @@ -31,7 +30,7 @@ where + pallet_subtensor::Config + pallet_proxy::Config + pallet_shield::Config - + pallet_subtensor_proxy::Config + + pallet_proxy::Config + Send + Sync + scale_info::TypeInfo, @@ -45,7 +44,7 @@ where + IsSubType> + IsSubType> + IsSubType> - + IsSubType>, + + IsSubType>, ::AddressMapping: AddressMapping, <::Lookup as StaticLookup>::Source: From, { @@ -61,7 +60,7 @@ where + pallet_subtensor::Config + pallet_proxy::Config + pallet_shield::Config - + pallet_subtensor_proxy::Config + + pallet_proxy::Config + Send + Sync + scale_info::TypeInfo, @@ -75,7 +74,7 @@ where + IsSubType> + IsSubType> + IsSubType> - + IsSubType>, + + IsSubType>, <::Lookup as StaticLookup>::Source: From, { #[precompile::public("createPureProxy(uint8,uint32,uint16)")] diff --git a/precompiles/src/staking.rs b/precompiles/src/staking.rs index f13619058c..bacbe8cea1 100644 --- a/precompiles/src/staking.rs +++ b/precompiles/src/staking.rs @@ -41,7 +41,6 @@ use pallet_evm::{ AddressMapping, BalanceConverter, EvmBalance, ExitError, PrecompileFailure, PrecompileHandle, SubstrateBalance, }; -use pallet_subtensor_proxy as pallet_proxy; use precompile_utils::EvmResult; use precompile_utils::prelude::{Address, RuntimeHelper, revert}; use sp_core::{H160, H256, U256}; @@ -90,7 +89,7 @@ where + pallet_subtensor::Config + pallet_proxy::Config + pallet_shield::Config - + pallet_subtensor_proxy::Config + + pallet_proxy::Config + Send + Sync + scale_info::TypeInfo, @@ -103,7 +102,7 @@ where + IsSubType> + IsSubType> + IsSubType> - + IsSubType>, + + IsSubType>, ::AddressMapping: AddressMapping, <::Lookup as StaticLookup>::Source: From, { @@ -119,7 +118,7 @@ where + pallet_subtensor::Config + pallet_proxy::Config + pallet_shield::Config - + pallet_subtensor_proxy::Config + + pallet_proxy::Config + Send + Sync + scale_info::TypeInfo, @@ -132,7 +131,7 @@ where + IsSubType> + IsSubType> + IsSubType> - + IsSubType>, + + IsSubType>, ::AddressMapping: AddressMapping, <::Lookup as StaticLookup>::Source: From, { @@ -679,7 +678,7 @@ where + pallet_proxy::Config + pallet_balances::Config + pallet_shield::Config - + pallet_subtensor_proxy::Config + + pallet_proxy::Config + Send + Sync + scale_info::TypeInfo, @@ -693,7 +692,7 @@ where + IsSubType> + IsSubType> + IsSubType> - + IsSubType>, + + IsSubType>, ::AddressMapping: AddressMapping, ::Balance: TryFrom, <::Lookup as StaticLookup>::Source: From, @@ -710,7 +709,7 @@ where + pallet_proxy::Config + pallet_balances::Config + pallet_shield::Config - + pallet_subtensor_proxy::Config + + pallet_proxy::Config + Send + Sync + scale_info::TypeInfo, @@ -724,7 +723,7 @@ where + IsSubType> + IsSubType> + IsSubType> - + IsSubType>, + + IsSubType>, ::AddressMapping: AddressMapping, ::Balance: TryFrom, <::Lookup as StaticLookup>::Source: From, @@ -1038,7 +1037,7 @@ mod tests { ensure_hotkey_exists(&hotkey); - let proxies = pallet_subtensor_proxy::Proxies::::get(&caller_account).0; + let proxies = pallet_proxy::Proxies::::get(&caller_account).0; assert_eq!(proxies.len(), 1); assert_eq!(proxies[0].delegate, delegate); @@ -1618,7 +1617,7 @@ mod tests { ) .execute_returns(()); - let proxies = pallet_subtensor_proxy::Proxies::::get(&caller_account).0; + let proxies = pallet_proxy::Proxies::::get(&caller_account).0; assert!(proxies.is_empty()); }); } @@ -1659,7 +1658,7 @@ mod tests { ) .execute_returns(()); - let proxies = pallet_subtensor_proxy::Proxies::::get(&caller_account).0; + let proxies = pallet_proxy::Proxies::::get(&caller_account).0; assert!(proxies.is_empty()); }); } diff --git a/precompiles/src/subnet.rs b/precompiles/src/subnet.rs index da9ff4c79b..d8526d924f 100644 --- a/precompiles/src/subnet.rs +++ b/precompiles/src/subnet.rs @@ -26,7 +26,7 @@ where + pallet_subtensor::Config + pallet_admin_utils::Config + pallet_shield::Config - + pallet_subtensor_proxy::Config + + pallet_proxy::Config + Send + Sync + scale_info::TypeInfo, @@ -39,7 +39,7 @@ where + IsSubType> + IsSubType> + IsSubType> - + IsSubType>, + + IsSubType>, ::AddressMapping: AddressMapping, { const INDEX: u64 = 2051; @@ -54,7 +54,7 @@ where + pallet_subtensor::Config + pallet_shield::Config + pallet_admin_utils::Config - + pallet_subtensor_proxy::Config + + pallet_proxy::Config + Send + Sync + scale_info::TypeInfo, @@ -67,7 +67,7 @@ where + IsSubType> + IsSubType> + IsSubType> - + IsSubType>, + + IsSubType>, ::AddressMapping: AddressMapping, { #[precompile::public("registerNetwork(bytes32)")] diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index bff2b3d935..c1a1855cea 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -40,7 +40,7 @@ frame-system = { workspace = true } frame-try-runtime = { workspace = true, optional = true } pallet-timestamp.workspace = true pallet-transaction-payment.workspace = true -pallet-subtensor-utility.workspace = true +pallet-utility.workspace = true frame-executive.workspace = true frame-metadata-hash-extension.workspace = true sp-api.workspace = true @@ -71,7 +71,7 @@ pallet-admin-utils.workspace = true pallet-multisig.workspace = true # Proxy Pallet -pallet-subtensor-proxy.workspace = true +pallet-proxy.workspace = true # Scheduler pallet pallet-scheduler.workspace = true @@ -199,10 +199,10 @@ std = [ "pallet-timestamp/std", "pallet-transaction-payment-rpc-runtime-api/std", "pallet-transaction-payment/std", - "pallet-subtensor-utility/std", + "pallet-utility/std", "pallet-sudo/std", "pallet-multisig/std", - "pallet-subtensor-proxy/std", + "pallet-proxy/std", "pallet-scheduler/std", "pallet-preimage/std", "pallet-commitments/std", @@ -297,11 +297,11 @@ runtime-benchmarks = [ "pallet-balances/runtime-benchmarks", "pallet-grandpa/runtime-benchmarks", "pallet-timestamp/runtime-benchmarks", - "pallet-subtensor-utility/runtime-benchmarks", + "pallet-utility/runtime-benchmarks", "sp-runtime/runtime-benchmarks", "pallet-safe-mode/runtime-benchmarks", "pallet-subtensor/runtime-benchmarks", - "pallet-subtensor-proxy/runtime-benchmarks", + "pallet-proxy/runtime-benchmarks", "pallet-registry/runtime-benchmarks", "pallet-commitments/runtime-benchmarks", "pallet-admin-utils/runtime-benchmarks", @@ -352,10 +352,10 @@ try-runtime = [ "pallet-insecure-randomness-collective-flip/try-runtime", "pallet-timestamp/try-runtime", "pallet-transaction-payment/try-runtime", - "pallet-subtensor-utility/try-runtime", + "pallet-utility/try-runtime", "pallet-safe-mode/try-runtime", "pallet-subtensor/try-runtime", - "pallet-subtensor-proxy/try-runtime", + "pallet-proxy/try-runtime", "pallet-multisig/try-runtime", "pallet-scheduler/try-runtime", "pallet-preimage/try-runtime", diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index a709b8a068..38ddf7b8ee 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -44,9 +44,7 @@ use pallet_subtensor::rpc_info::{ }, }; use pallet_subtensor::{CommitmentsInterface, ProxyInterface}; -use pallet_subtensor_proxy as pallet_proxy; use pallet_subtensor_swap_runtime_api::{SimSwapResult, SubnetPrice}; -use pallet_subtensor_utility as pallet_utility; use runtime_common::prod_or_fast; use safe_math::FixedExt; use sp_api::impl_runtime_apis; @@ -451,6 +449,7 @@ impl pallet_timestamp::Config for Runtime { } impl pallet_utility::Config for Runtime { + type RuntimeEvent = RuntimeEvent; type RuntimeCall = RuntimeCall; type PalletsOrigin = OriginCaller; type WeightInfo = pallet_utility::weights::SubstrateWeight; @@ -796,6 +795,7 @@ impl InstanceFilter for ProxyType { } impl pallet_proxy::Config for Runtime { + type RuntimeEvent = RuntimeEvent; type RuntimeCall = RuntimeCall; type Currency = Balances; type ProxyType = ProxyType; @@ -1757,8 +1757,8 @@ mod benches { [pallet_crowdloan, Crowdloan] [pallet_subtensor_swap, Swap] [pallet_shield, MevShield] - [pallet_subtensor_proxy, Proxy] - [pallet_subtensor_utility, Utility] + [pallet_proxy, Proxy] + [pallet_utility, Utility] [pallet_limit_orders, LimitOrders] ); } @@ -2231,8 +2231,6 @@ impl_runtime_apis! { _ => (None, None), }; - let whitelist = pallet_evm::WhitelistedCreators::::get(); - let whitelist_disabled = pallet_evm::DisableWhitelistCheck::::get(); ::Runner::create( from, data, @@ -2242,8 +2240,6 @@ impl_runtime_apis! { max_priority_fee_per_gas, nonce, access_list.unwrap_or_default(), - whitelist, - whitelist_disabled, authorization_list.unwrap_or_default(), false, true, diff --git a/runtime/src/transaction_payment_wrapper.rs b/runtime/src/transaction_payment_wrapper.rs index b16773daf9..106714b147 100644 --- a/runtime/src/transaction_payment_wrapper.rs +++ b/runtime/src/transaction_payment_wrapper.rs @@ -4,8 +4,6 @@ use frame_election_provider_support::private::sp_arithmetic::traits::SaturatedCo use frame_support::dispatch::{DispatchClass, DispatchInfo, PostDispatchInfo}; use frame_support::pallet_prelude::TypeInfo; use frame_support::traits::{Get, IsSubType, IsType}; -use pallet_subtensor_proxy as pallet_proxy; -use pallet_subtensor_utility as pallet_utility; use pallet_transaction_payment::OnChargeTransaction; use pallet_transaction_payment::{ChargeTransactionPayment, Config, Pre, Val}; use sp_runtime::DispatchResult; diff --git a/runtime/tests/pallet_proxy.rs b/runtime/tests/pallet_proxy.rs index 481c17b53d..ab480b33ff 100644 --- a/runtime/tests/pallet_proxy.rs +++ b/runtime/tests/pallet_proxy.rs @@ -6,7 +6,6 @@ use node_subtensor_runtime::{ RuntimeOrigin, SubtensorModule, System, SystemCall, get_all_proxy_filters, get_all_proxy_type_infos, }; -use pallet_subtensor_proxy as pallet_proxy; use subtensor_runtime_common::{ AccountId, CallCondition, FilterMode, NetUid, ProxyType, SMALL_ALPHA_TRANSFER_LIMIT, SMALL_TRANSFER_LIMIT, TaoBalance, diff --git a/runtime/tests/transaction_payment_wrapper.rs b/runtime/tests/transaction_payment_wrapper.rs index bbc9798a3e..0bd5c473ce 100644 --- a/runtime/tests/transaction_payment_wrapper.rs +++ b/runtime/tests/transaction_payment_wrapper.rs @@ -9,8 +9,6 @@ use node_subtensor_runtime::{ RuntimeCall, RuntimeGenesisConfig, RuntimeOrigin, System, SystemCall, transaction_payment_wrapper::ChargeTransactionPaymentWrapper, }; -use pallet_subtensor_proxy as pallet_proxy; -use pallet_subtensor_utility as pallet_utility; use pallet_transaction_payment::Val; use sp_runtime::traits::{TransactionExtension, TxBaseImplication}; use sp_runtime::transaction_validity::{ diff --git a/support/linting/Cargo.toml b/support/linting/Cargo.toml index 1b7528cb17..333f54c3ac 100644 --- a/support/linting/Cargo.toml +++ b/support/linting/Cargo.toml @@ -13,7 +13,7 @@ syn = { workspace = true, features = [ ] } quote.workspace = true proc-macro2.workspace = true -procedural-fork.workspace = true +frame-support-procedural-core.workspace = true [lints] workspace = true diff --git a/support/linting/src/pallet_index.rs b/support/linting/src/pallet_index.rs index e14617be24..9a462a1221 100644 --- a/support/linting/src/pallet_index.rs +++ b/support/linting/src/pallet_index.rs @@ -1,6 +1,6 @@ use super::*; +use frame_support_procedural_core::construct_runtime::parse::RuntimeDeclaration; use proc_macro2::TokenStream as TokenStream2; -use procedural_fork::exports::construct_runtime::parse::RuntimeDeclaration; use quote::ToTokens; use syn::{File, visit::Visit}; @@ -81,7 +81,7 @@ impl ConstructRuntimeVisitor { fn check_pallets_for_index( &mut self, - pallets: &[procedural_fork::exports::construct_runtime::parse::Pallet], + pallets: &[frame_support_procedural_core::construct_runtime::parse::Pallet], ) { for pallet in pallets { // Check for explicit index and detect missing indices @@ -168,12 +168,12 @@ mod tests { Balances : pallet_balances = 5, TransactionPayment : pallet_transaction_payment = 6, SubtensorModule : pallet_subtensor = 7, - Utility : pallet_subtensor_utility = 11, + Utility : pallet_utility = 11, Sudo : pallet_sudo = 12, Multisig : pallet_multisig = 13, Preimage : pallet_preimage = 14, Scheduler : pallet_scheduler = 15, - Proxy : pallet_subtensor_proxy = 16, + Proxy : pallet_proxy = 16, Registry : pallet_registry = 17, Commitments : pallet_commitments = 18, AdminUtils : pallet_admin_utils = 19, diff --git a/support/procedural-fork/Cargo.toml b/support/procedural-fork/Cargo.toml deleted file mode 100644 index fdc280ec14..0000000000 --- a/support/procedural-fork/Cargo.toml +++ /dev/null @@ -1,40 +0,0 @@ -[package] -name = "procedural-fork" -version = "1.10.0-rc3" -edition.workspace = true - -[lints.clippy] -all = "allow" - -[dependencies] -derive-syn-parse.workspace = true -Inflector.workspace = true -cfg-expr.workspace = true -itertools.workspace = true -proc-macro2.workspace = true -quote.workspace = true -syn = { workspace = true, features = [ - "full", - "visit-mut", - "visit", - "extra-traits", - "parsing", -] } -macro_magic = { workspace = true, features = ["proc_support"] } -frame-support-procedural-tools.workspace = true -proc-macro-warning.workspace = true -expander.workspace = true -sp-crypto-hashing.workspace = true - -[dev-dependencies] -regex.workspace = true - -[features] -default = ["std"] -std = ["sp-crypto-hashing/std", "regex/std"] -no-metadata-docs = [] -experimental = [] -# Generate impl-trait for tuples with the given number of tuples. Will be needed as the number of -# pallets in a runtime grows. Does increase the compile time! -tuples-96 = [] -tuples-128 = [] diff --git a/support/procedural-fork/src/benchmark.rs b/support/procedural-fork/src/benchmark.rs deleted file mode 100644 index 61cda35c66..0000000000 --- a/support/procedural-fork/src/benchmark.rs +++ /dev/null @@ -1,1284 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//! Home of the parsing and expansion code for the new pallet benchmarking syntax - -use derive_syn_parse::Parse; -use frame_support_procedural_tools::generate_access_from_frame_or_crate; -use proc_macro::TokenStream; -use proc_macro2::{Ident, Span, TokenStream as TokenStream2}; -use quote::{ToTokens, quote}; -use syn::{ - Attribute, Error, Expr, ExprBlock, ExprCall, ExprPath, FnArg, Item, ItemFn, ItemMod, Pat, Path, - PathArguments, PathSegment, Result, ReturnType, Signature, Stmt, Token, Type, TypePath, - Visibility, WhereClause, - parse::{Nothing, ParseStream}, - parse_quote, - punctuated::Punctuated, - spanned::Spanned, - token::{Comma, Gt, Lt, PathSep}, -}; - -mod keywords { - use syn::custom_keyword; - - custom_keyword!(benchmark); - custom_keyword!(benchmarks); - custom_keyword!(block); - custom_keyword!(extra); - custom_keyword!(pov_mode); - custom_keyword!(extrinsic_call); - custom_keyword!(skip_meta); - custom_keyword!(BenchmarkError); - custom_keyword!(Result); - custom_keyword!(MaxEncodedLen); - custom_keyword!(Measured); - custom_keyword!(Ignored); - - pub const BENCHMARK_TOKEN: &str = stringify!(benchmark); - pub const BENCHMARKS_TOKEN: &str = stringify!(benchmarks); -} - -/// This represents the raw parsed data for a param definition such as `x: Linear<10, 20>`. -#[derive(Clone)] -struct ParamDef { - name: String, - _typ: Type, - start: syn::GenericArgument, - end: syn::GenericArgument, -} - -/// Allows easy parsing of the `<10, 20>` component of `x: Linear<10, 20>`. -#[derive(Parse)] -struct RangeArgs { - _lt_token: Lt, - start: syn::GenericArgument, - _comma: Comma, - end: syn::GenericArgument, - _trailing_comma: Option, - _gt_token: Gt, -} - -#[derive(Clone, Debug)] -struct BenchmarkAttrs { - skip_meta: bool, - extra: bool, - pov_mode: Option, -} - -/// Represents a single benchmark option -enum BenchmarkAttr { - Extra, - SkipMeta, - /// How the PoV should be measured. - PoV(PovModeAttr), -} - -impl syn::parse::Parse for PovModeAttr { - fn parse(input: ParseStream) -> Result { - let _pov: keywords::pov_mode = input.parse()?; - let _eq: Token![=] = input.parse()?; - let root = PovEstimationMode::parse(input)?; - - let mut maybe_content = None; - let _ = || -> Result<()> { - let content; - syn::braced!(content in input); - maybe_content = Some(content); - Ok(()) - }(); - - let per_key = match maybe_content { - Some(content) => { - let per_key = Punctuated::::parse_terminated(&content)?; - per_key.into_iter().collect() - } - None => Vec::new(), - }; - - Ok(Self { root, per_key }) - } -} - -impl syn::parse::Parse for BenchmarkAttr { - fn parse(input: ParseStream) -> Result { - let lookahead = input.lookahead1(); - if lookahead.peek(keywords::extra) { - let _extra: keywords::extra = input.parse()?; - Ok(BenchmarkAttr::Extra) - } else if lookahead.peek(keywords::skip_meta) { - let _skip_meta: keywords::skip_meta = input.parse()?; - Ok(BenchmarkAttr::SkipMeta) - } else if lookahead.peek(keywords::pov_mode) { - PovModeAttr::parse(input).map(BenchmarkAttr::PoV) - } else { - Err(lookahead.error()) - } - } -} - -/// A `#[pov_mode = .. { .. }]` attribute. -#[derive(Debug, Clone)] -struct PovModeAttr { - /// The root mode for this benchmarks. - root: PovEstimationMode, - /// The pov-mode for a specific key. This overwrites `root` for this key. - per_key: Vec, -} - -/// A single key-value pair inside the `{}` of a `#[pov_mode = .. { .. }]` attribute. -#[derive(Debug, Clone, derive_syn_parse::Parse)] -struct PovModeKeyAttr { - /// A specific storage key for which to set the PoV mode. - key: Path, - _underscore: Token![:], - /// The PoV mode for this key. - mode: PovEstimationMode, -} - -/// How the PoV should be estimated. -#[derive(Debug, Eq, PartialEq, Clone, Copy)] -pub enum PovEstimationMode { - /// Use the maximal encoded length as provided by [`codec::MaxEncodedLen`]. - MaxEncodedLen, - /// Measure the accessed value size in the pallet benchmarking and add some trie overhead. - Measured, - /// Do not estimate the PoV size for this storage item or benchmark. - Ignored, -} - -impl syn::parse::Parse for PovEstimationMode { - fn parse(input: ParseStream) -> Result { - let lookahead = input.lookahead1(); - if lookahead.peek(keywords::MaxEncodedLen) { - let _max_encoded_len: keywords::MaxEncodedLen = input.parse()?; - return Ok(PovEstimationMode::MaxEncodedLen); - } else if lookahead.peek(keywords::Measured) { - let _measured: keywords::Measured = input.parse()?; - return Ok(PovEstimationMode::Measured); - } else if lookahead.peek(keywords::Ignored) { - let _ignored: keywords::Ignored = input.parse()?; - return Ok(PovEstimationMode::Ignored); - } else { - return Err(lookahead.error()); - } - } -} - -impl ToString for PovEstimationMode { - fn to_string(&self) -> String { - match self { - PovEstimationMode::MaxEncodedLen => "MaxEncodedLen".into(), - PovEstimationMode::Measured => "Measured".into(), - PovEstimationMode::Ignored => "Ignored".into(), - } - } -} - -impl quote::ToTokens for PovEstimationMode { - fn to_tokens(&self, tokens: &mut TokenStream2) { - match self { - PovEstimationMode::MaxEncodedLen => tokens.extend(quote!(MaxEncodedLen)), - PovEstimationMode::Measured => tokens.extend(quote!(Measured)), - PovEstimationMode::Ignored => tokens.extend(quote!(Ignored)), - } - } -} - -impl syn::parse::Parse for BenchmarkAttrs { - fn parse(input: ParseStream) -> syn::Result { - let mut extra = false; - let mut skip_meta = false; - let mut pov_mode = None; - let args = Punctuated::::parse_terminated(&input)?; - - for arg in args.into_iter() { - match arg { - BenchmarkAttr::Extra => { - if extra { - return Err(input.error("`extra` can only be specified once")); - } - extra = true; - } - BenchmarkAttr::SkipMeta => { - if skip_meta { - return Err(input.error("`skip_meta` can only be specified once")); - } - skip_meta = true; - } - BenchmarkAttr::PoV(mode) => { - if pov_mode.is_some() { - return Err(input.error("`pov_mode` can only be specified once")); - } - pov_mode = Some(mode); - } - } - } - Ok(BenchmarkAttrs { - extra, - skip_meta, - pov_mode, - }) - } -} - -/// Represents the parsed extrinsic call for a benchmark -#[derive(Clone)] -enum BenchmarkCallDef { - ExtrinsicCall { - origin: Expr, - expr_call: ExprCall, - attr_span: Span, - }, // #[extrinsic_call] - Block { - block: ExprBlock, - attr_span: Span, - }, // #[block] -} - -impl BenchmarkCallDef { - /// Returns the `span()` for attribute - fn attr_span(&self) -> Span { - match self { - BenchmarkCallDef::ExtrinsicCall { - origin: _, - expr_call: _, - attr_span, - } => *attr_span, - BenchmarkCallDef::Block { - block: _, - attr_span, - } => *attr_span, - } - } -} - -/// Represents a parsed `#[benchmark]` or `#[instance_benchmark]` item. -#[derive(Clone)] -struct BenchmarkDef { - params: Vec, - setup_stmts: Vec, - call_def: BenchmarkCallDef, - verify_stmts: Vec, - last_stmt: Option, - fn_sig: Signature, - fn_vis: Visibility, - fn_attrs: Vec, -} - -/// used to parse something compatible with `Result` -#[derive(Parse)] -struct ResultDef { - _result_kw: keywords::Result, - _lt: Token![<], - unit: Type, - _comma: Comma, - e_type: TypePath, - _gt: Token![>], -} - -/// Ensures that `ReturnType` is a `Result<(), BenchmarkError>`, if specified -fn ensure_valid_return_type(item_fn: &ItemFn) -> Result<()> { - if let ReturnType::Type(_, typ) = &item_fn.sig.output { - let non_unit = |span| return Err(Error::new(span, "expected `()`")); - let Type::Path(TypePath { path, qself: _ }) = &**typ else { - return Err(Error::new( - typ.span(), - "Only `Result<(), BenchmarkError>` or a blank return type is allowed on benchmark function definitions", - )); - }; - let seg = path - .segments - .last() - .expect("to be parsed as a TypePath, it must have at least one segment; qed"); - let res: ResultDef = syn::parse2(seg.to_token_stream())?; - // ensure T in Result is () - let Type::Tuple(tup) = res.unit else { - return non_unit(res.unit.span()); - }; - if !tup.elems.is_empty() { - return non_unit(tup.span()); - } - let TypePath { path, qself: _ } = res.e_type; - let seg = path - .segments - .last() - .expect("to be parsed as a TypePath, it must have at least one segment; qed"); - syn::parse2::(seg.to_token_stream())?; - } - Ok(()) -} - -/// Ensure that the passed statements do not contain any forbidden variable names -fn ensure_no_forbidden_variable_names(stmts: &[Stmt]) -> Result<()> { - const FORBIDDEN_VAR_NAMES: [&str; 2] = ["recording", "verify"]; - for stmt in stmts { - let Stmt::Local(l) = stmt else { continue }; - let Pat::Ident(ident) = &l.pat else { continue }; - if FORBIDDEN_VAR_NAMES.contains(&ident.ident.to_string().as_str()) { - return Err(Error::new( - ident.span(), - format!( - "Variables {FORBIDDEN_VAR_NAMES:?} are reserved for benchmarking internals.", - ), - )); - } - } - Ok(()) -} - -/// Parses params such as `x: Linear<0, 1>` -fn parse_params(item_fn: &ItemFn) -> Result> { - let mut params: Vec = Vec::new(); - for arg in &item_fn.sig.inputs { - let invalid_param = |span| { - return Err(Error::new( - span, - "Invalid benchmark function param. A valid example would be `x: Linear<5, 10>`.", - )); - }; - - let FnArg::Typed(arg) = arg else { - return invalid_param(arg.span()); - }; - let Pat::Ident(ident) = &*arg.pat else { - return invalid_param(arg.span()); - }; - - // check param name - let var_span = ident.span(); - let invalid_param_name = || { - return Err(Error::new( - var_span, - "Benchmark parameter names must consist of a single lowercase letter (a-z) and no other characters.", - )); - }; - let name = ident.ident.to_token_stream().to_string(); - if name.len() > 1 { - return invalid_param_name(); - }; - let Some(name_char) = name.chars().next() else { - return invalid_param_name(); - }; - if !name_char.is_alphabetic() || !name_char.is_lowercase() { - return invalid_param_name(); - } - - // parse type - let typ = &*arg.ty; - let Type::Path(tpath) = typ else { - return invalid_param(typ.span()); - }; - let Some(segment) = tpath.path.segments.last() else { - return invalid_param(typ.span()); - }; - let args = segment.arguments.to_token_stream().into(); - let Ok(args) = syn::parse::(args) else { - return invalid_param(typ.span()); - }; - - params.push(ParamDef { - name, - _typ: typ.clone(), - start: args.start, - end: args.end, - }); - } - Ok(params) -} - -/// Used in several places where the `#[extrinsic_call]` or `#[body]` annotation is missing -fn missing_call(item_fn: &ItemFn) -> Result { - return Err(Error::new( - item_fn.block.brace_token.span.join(), - "No valid #[extrinsic_call] or #[block] annotation could be found in benchmark function body.", - )); -} - -/// Finds the `BenchmarkCallDef` and its index (within the list of stmts for the fn) and -/// returns them. Also handles parsing errors for invalid / extra call defs. AKA this is -/// general handling for `#[extrinsic_call]` and `#[block]` -fn parse_call_def(item_fn: &ItemFn) -> Result<(usize, BenchmarkCallDef)> { - // #[extrinsic_call] / #[block] handling - let call_defs = item_fn.block.stmts.iter().enumerate().filter_map(|(i, child)| { - if let Stmt::Expr(Expr::Call(expr_call), _semi) = child { - // #[extrinsic_call] case - expr_call.attrs.iter().enumerate().find_map(|(k, attr)| { - let segment = attr.path().segments.last()?; - let _: keywords::extrinsic_call = syn::parse(segment.ident.to_token_stream().into()).ok()?; - let mut expr_call = expr_call.clone(); - - // consume #[extrinsic_call] tokens - expr_call.attrs.remove(k); - - // extract origin from expr_call - let Some(origin) = expr_call.args.first().cloned() else { - return Some(Err(Error::new(expr_call.span(), "Single-item extrinsic calls must specify their origin as the first argument."))) - }; - - Some(Ok((i, BenchmarkCallDef::ExtrinsicCall { origin, expr_call, attr_span: attr.span() }))) - }) - } else if let Stmt::Expr(Expr::Block(block), _) = child { - // #[block] case - block.attrs.iter().enumerate().find_map(|(k, attr)| { - let segment = attr.path().segments.last()?; - let _: keywords::block = syn::parse(segment.ident.to_token_stream().into()).ok()?; - let mut block = block.clone(); - - // consume #[block] tokens - block.attrs.remove(k); - - Some(Ok((i, BenchmarkCallDef::Block { block, attr_span: attr.span() }))) - }) - } else { - None - } - }).collect::>>()?; - Ok(match &call_defs[..] { - [(i, call_def)] => (*i, call_def.clone()), // = 1 - [] => return missing_call(item_fn), - _ => { - return Err(Error::new( - call_defs[1].1.attr_span(), - "Only one #[extrinsic_call] or #[block] attribute is allowed per benchmark.", - )); - } - }) -} - -impl BenchmarkDef { - /// Constructs a [`BenchmarkDef`] by traversing an existing [`ItemFn`] node. - pub fn from(item_fn: &ItemFn) -> Result { - let params = parse_params(item_fn)?; - ensure_valid_return_type(item_fn)?; - let (i, call_def) = parse_call_def(&item_fn)?; - - let (verify_stmts, last_stmt) = match item_fn.sig.output { - ReturnType::Default => - // no return type, last_stmt should be None - { - ( - Vec::from(&item_fn.block.stmts[(i + 1)..item_fn.block.stmts.len()]), - None, - ) - } - ReturnType::Type(_, _) => { - // defined return type, last_stmt should be Result<(), BenchmarkError> - // compatible and should not be included in verify_stmts - if i + 1 >= item_fn.block.stmts.len() { - return Err(Error::new( - item_fn.block.span(), - "Benchmark `#[block]` or `#[extrinsic_call]` item cannot be the \ - last statement of your benchmark function definition if you have \ - defined a return type. You should return something compatible \ - with Result<(), BenchmarkError> (i.e. `Ok(())`) as the last statement \ - or change your signature to a blank return type.", - )); - } - let Some(stmt) = item_fn.block.stmts.last() else { - return missing_call(item_fn); - }; - ( - Vec::from(&item_fn.block.stmts[(i + 1)..item_fn.block.stmts.len() - 1]), - Some(stmt.clone()), - ) - } - }; - - let setup_stmts = Vec::from(&item_fn.block.stmts[0..i]); - ensure_no_forbidden_variable_names(&setup_stmts)?; - - Ok(BenchmarkDef { - params, - setup_stmts, - call_def, - verify_stmts, - last_stmt, - fn_sig: item_fn.sig.clone(), - fn_vis: item_fn.vis.clone(), - fn_attrs: item_fn.attrs.clone(), - }) - } -} - -/// Parses and expands a `#[benchmarks]` or `#[instance_benchmarks]` invocation -pub fn benchmarks( - attrs: TokenStream, - tokens: TokenStream, - instance: bool, -) -> syn::Result { - let krate = generate_access_from_frame_or_crate("frame-benchmarking")?; - // gather module info - let module: ItemMod = syn::parse(tokens)?; - let mod_span = module.span(); - let where_clause = match syn::parse::(attrs.clone()) { - Ok(_) => quote!(), - Err(_) => syn::parse::(attrs)? - .predicates - .to_token_stream(), - }; - let mod_vis = module.vis; - let mod_name = module.ident; - - // consume #[benchmarks] attribute by excluding it from mod_attrs - let mod_attrs: Vec<&Attribute> = module - .attrs - .iter() - .filter(|attr| !attr.path().is_ident(keywords::BENCHMARKS_TOKEN)) - .collect(); - - let mut benchmark_names: Vec = Vec::new(); - let mut extra_benchmark_names: Vec = Vec::new(); - let mut skip_meta_benchmark_names: Vec = Vec::new(); - // Map benchmarks to PoV modes. - let mut pov_modes = Vec::new(); - - let (_brace, mut content) = module - .content - .ok_or(syn::Error::new(mod_span, "Module cannot be empty!"))?; - - // find all function defs marked with #[benchmark] - let benchmark_fn_metas = content.iter_mut().filter_map(|stmt| { - // parse as a function def first - let Item::Fn(func) = stmt else { return None }; - - // find #[benchmark] attribute on function def - let benchmark_attr = func - .attrs - .iter() - .find(|attr| attr.path().is_ident(keywords::BENCHMARK_TOKEN))?; - - Some((benchmark_attr.clone(), func.clone(), stmt)) - }); - - // parse individual benchmark defs and args - for (benchmark_attr, func, stmt) in benchmark_fn_metas { - // parse benchmark def - let benchmark_def = BenchmarkDef::from(&func)?; - - // record benchmark name - let name = &func.sig.ident; - benchmark_names.push(name.clone()); - - // Check if we need to parse any args - if benchmark_attr.meta.require_path_only().is_err() { - // parse any args provided to #[benchmark] - let benchmark_attrs: BenchmarkAttrs = benchmark_attr.parse_args()?; - - // record name sets - if benchmark_attrs.extra { - extra_benchmark_names.push(name.clone()); - } else if benchmark_attrs.skip_meta { - skip_meta_benchmark_names.push(name.clone()); - } - - if let Some(mode) = benchmark_attrs.pov_mode { - let mut modes = Vec::new(); - // We cannot expand strings here since it is no-std, but syn does not expand bytes. - let name = name.to_string(); - let m = mode.root.to_string(); - modes.push(quote!(("ALL".as_bytes().to_vec(), #m.as_bytes().to_vec()))); - - for attr in mode.per_key.iter() { - // syn always puts spaces in quoted paths: - let key = attr - .key - .clone() - .into_token_stream() - .to_string() - .replace(" ", ""); - let mode = attr.mode.to_string(); - modes.push(quote!((#key.as_bytes().to_vec(), #mode.as_bytes().to_vec()))); - } - - pov_modes.push( - quote!((#name.as_bytes().to_vec(), #krate::__private::vec![#(#modes),*])), - ); - } - } - - // expand benchmark - let expanded = expand_benchmark(benchmark_def, name, instance, where_clause.clone()); - - // replace original function def with expanded code - *stmt = Item::Verbatim(expanded); - } - - // generics - let type_use_generics = match instance { - false => quote!(T), - true => quote!(T, I), - }; - let type_impl_generics = match instance { - false => quote!(T: Config), - true => quote!(T: Config, I: 'static), - }; - - let frame_system = generate_access_from_frame_or_crate("frame-system")?; - - // benchmark name variables - let benchmark_names_str: Vec = benchmark_names.iter().map(|n| n.to_string()).collect(); - let extra_benchmark_names_str: Vec = extra_benchmark_names - .iter() - .map(|n| n.to_string()) - .collect(); - let skip_meta_benchmark_names_str: Vec = skip_meta_benchmark_names - .iter() - .map(|n| n.to_string()) - .collect(); - let mut selected_benchmark_mappings: Vec = Vec::new(); - let mut benchmarks_by_name_mappings: Vec = Vec::new(); - let test_idents: Vec = benchmark_names_str - .iter() - .map(|n| Ident::new(format!("test_benchmark_{}", n).as_str(), Span::call_site())) - .collect(); - for i in 0..benchmark_names.len() { - let name_ident = &benchmark_names[i]; - let name_str = &benchmark_names_str[i]; - let test_ident = &test_idents[i]; - selected_benchmark_mappings.push(quote!(#name_str => SelectedBenchmark::#name_ident)); - benchmarks_by_name_mappings.push(quote!(#name_str => Self::#test_ident())) - } - - let impl_test_function = content - .iter_mut() - .find_map(|item| { - let Item::Macro(item_macro) = item else { - return None; - }; - - if !item_macro - .mac - .path - .segments - .iter() - .any(|s| s.ident == "impl_benchmark_test_suite") - { - return None; - } - - let tokens = item_macro.mac.tokens.clone(); - *item = Item::Verbatim(quote! {}); - - Some(quote! { - impl_test_function!( - (#( {} #benchmark_names )*) - (#( #extra_benchmark_names )*) - (#( #skip_meta_benchmark_names )*) - #tokens - ); - }) - }) - .unwrap_or(quote! {}); - - // emit final quoted tokens - let res = quote! { - #(#mod_attrs) - * - #mod_vis mod #mod_name { - #(#content) - * - - #[allow(non_camel_case_types)] - enum SelectedBenchmark { - #(#benchmark_names), - * - } - - impl<#type_impl_generics> #krate::BenchmarkingSetup<#type_use_generics> for SelectedBenchmark where #where_clause { - fn components(&self) -> #krate::__private::Vec<(#krate::BenchmarkParameter, u32, u32)> { - match self { - #( - Self::#benchmark_names => { - <#benchmark_names as #krate::BenchmarkingSetup<#type_use_generics>>::components(&#benchmark_names) - } - ) - * - } - } - - fn instance( - &self, - recording: &mut impl #krate::Recording, - components: &[(#krate::BenchmarkParameter, u32)], - verify: bool, - ) -> Result<(), #krate::BenchmarkError> { - match self { - #( - Self::#benchmark_names => { - <#benchmark_names as #krate::BenchmarkingSetup< - #type_use_generics - >>::instance(&#benchmark_names, recording, components, verify) - } - ) - * - } - } - } - #[cfg(any(feature = "runtime-benchmarks", test))] - impl<#type_impl_generics> #krate::Benchmarking for Pallet<#type_use_generics> - where T: #frame_system::Config, #where_clause - { - fn benchmarks( - extra: bool, - ) -> #krate::__private::Vec<#krate::BenchmarkMetadata> { - let mut all_names = #krate::__private::vec![ - #(#benchmark_names_str), - * - ]; - if !extra { - let extra = [ - #(#extra_benchmark_names_str), - * - ]; - all_names.retain(|x| !extra.contains(x)); - } - let pov_modes: - #krate::__private::Vec<( - #krate::__private::Vec, - #krate::__private::Vec<( - #krate::__private::Vec, - #krate::__private::Vec - )>, - )> = #krate::__private::vec![ - #( #pov_modes ),* - ]; - all_names.into_iter().map(|benchmark| { - let selected_benchmark = match benchmark { - #(#selected_benchmark_mappings), - *, - _ => panic!("all benchmarks should be selectable") - }; - let components = >::components(&selected_benchmark); - let name = benchmark.as_bytes().to_vec(); - let modes = pov_modes.iter().find(|p| p.0 == name).map(|p| p.1.clone()); - - #krate::BenchmarkMetadata { - name: benchmark.as_bytes().to_vec(), - components, - pov_modes: modes.unwrap_or_default(), - } - }).collect::<#krate::__private::Vec<_>>() - } - - fn run_benchmark( - extrinsic: &[u8], - c: &[(#krate::BenchmarkParameter, u32)], - whitelist: &[#krate::__private::TrackedStorageKey], - verify: bool, - internal_repeats: u32, - ) -> Result<#krate::__private::Vec<#krate::BenchmarkResult>, #krate::BenchmarkError> { - let extrinsic = #krate::__private::str::from_utf8(extrinsic).map_err(|_| "`extrinsic` is not a valid utf-8 string!")?; - let selected_benchmark = match extrinsic { - #(#selected_benchmark_mappings), - *, - _ => return Err("Could not find extrinsic.".into()), - }; - let mut whitelist = whitelist.to_vec(); - let whitelisted_caller_key = <#frame_system::Account< - T, - > as #krate::__private::storage::StorageMap<_, _,>>::hashed_key_for( - #krate::whitelisted_caller::() - ); - whitelist.push(whitelisted_caller_key.into()); - let transactional_layer_key = #krate::__private::TrackedStorageKey::new( - #krate::__private::storage::transactional::TRANSACTION_LEVEL_KEY.into(), - ); - whitelist.push(transactional_layer_key); - // Whitelist the `:extrinsic_index`. - let extrinsic_index = #krate::__private::TrackedStorageKey::new( - #krate::__private::well_known_keys::EXTRINSIC_INDEX.into() - ); - whitelist.push(extrinsic_index); - // Whitelist the `:intrablock_entropy`. - let intrablock_entropy = #krate::__private::TrackedStorageKey::new( - #krate::__private::well_known_keys::INTRABLOCK_ENTROPY.into() - ); - whitelist.push(intrablock_entropy); - - #krate::benchmarking::set_whitelist(whitelist.clone()); - let mut results: #krate::__private::Vec<#krate::BenchmarkResult> = #krate::__private::Vec::new(); - - let on_before_start = || { - // Set the block number to at least 1 so events are deposited. - if #krate::__private::Zero::is_zero(&#frame_system::Pallet::::block_number()) { - #frame_system::Pallet::::set_block_number(1u32.into()); - } - - // Commit the externalities to the database, flushing the DB cache. - // This will enable worst case scenario for reading from the database. - #krate::benchmarking::commit_db(); - - // Access all whitelisted keys to get them into the proof recorder since the - // recorder does now have a whitelist. - for key in &whitelist { - #krate::__private::storage::unhashed::get_raw(&key.key); - } - - // Reset the read/write counter so we don't count operations in the setup process. - #krate::benchmarking::reset_read_write_count(); - }; - - // Always do at least one internal repeat... - for _ in 0 .. internal_repeats.max(1) { - // Always reset the state after the benchmark. - #krate::__private::defer!(#krate::benchmarking::wipe_db()); - - // Time the extrinsic logic. - #krate::__private::log::trace!( - target: "benchmark", - "Start Benchmark: {} ({:?})", - extrinsic, - c - ); - - let mut recording = #krate::BenchmarkRecording::new(&on_before_start); - >::instance(&selected_benchmark, &mut recording, c, verify)?; - - // Calculate the diff caused by the benchmark. - let elapsed_extrinsic = recording.elapsed_extrinsic().expect("elapsed time should be recorded"); - let diff_pov = recording.diff_pov().unwrap_or_default(); - - // Commit the changes to get proper write count - #krate::benchmarking::commit_db(); - #krate::__private::log::trace!( - target: "benchmark", - "End Benchmark: {} ns", elapsed_extrinsic - ); - let read_write_count = #krate::benchmarking::read_write_count(); - #krate::__private::log::trace!( - target: "benchmark", - "Read/Write Count {:?}", read_write_count - ); - - // Time the storage root recalculation. - let start_storage_root = #krate::benchmarking::current_time(); - #krate::__private::storage_root(#krate::__private::StateVersion::V1); - let finish_storage_root = #krate::benchmarking::current_time(); - let elapsed_storage_root = finish_storage_root - start_storage_root; - - let skip_meta = [ #(#skip_meta_benchmark_names_str),* ]; - let read_and_written_keys = if skip_meta.contains(&extrinsic) { - #krate::__private::vec![(b"Skipped Metadata".to_vec(), 0, 0, false)] - } else { - #krate::benchmarking::get_read_and_written_keys() - }; - - results.push(#krate::BenchmarkResult { - components: c.to_vec(), - extrinsic_time: elapsed_extrinsic, - storage_root_time: elapsed_storage_root, - reads: read_write_count.0, - repeat_reads: read_write_count.1, - writes: read_write_count.2, - repeat_writes: read_write_count.3, - proof_size: diff_pov, - keys: read_and_written_keys, - }); - } - - return Ok(results); - } - } - - #[cfg(test)] - impl<#type_impl_generics> Pallet<#type_use_generics> where T: #frame_system::Config, #where_clause { - /// Test a particular benchmark by name. - /// - /// This isn't called `test_benchmark_by_name` just in case some end-user eventually - /// writes a benchmark, itself called `by_name`; the function would be shadowed in - /// that case. - /// - /// This is generally intended to be used by child test modules such as those created - /// by the `impl_benchmark_test_suite` macro. However, it is not an error if a pallet - /// author chooses not to implement benchmarks. - #[allow(unused)] - fn test_bench_by_name(name: &[u8]) -> Result<(), #krate::BenchmarkError> { - let name = #krate::__private::str::from_utf8(name) - .map_err(|_| -> #krate::BenchmarkError { "`name` is not a valid utf8 string!".into() })?; - match name { - #(#benchmarks_by_name_mappings), - *, - _ => Err("Could not find test for requested benchmark.".into()), - } - } - } - - #impl_test_function - } - #mod_vis use #mod_name::*; - }; - Ok(res.into()) -} - -/// Prepares a [`Vec`] to be interpolated by [`quote!`] by creating easily-iterable -/// arrays formatted in such a way that they can be interpolated directly. -struct UnrolledParams { - param_ranges: Vec, - param_names: Vec, -} - -impl UnrolledParams { - /// Constructs an [`UnrolledParams`] from a [`Vec`] - fn from(params: &Vec) -> UnrolledParams { - let param_ranges: Vec = params - .iter() - .map(|p| { - let name = Ident::new(&p.name, Span::call_site()); - let start = &p.start; - let end = &p.end; - quote!(#name, #start, #end) - }) - .collect(); - let param_names: Vec = params - .iter() - .map(|p| { - let name = Ident::new(&p.name, Span::call_site()); - quote!(#name) - }) - .collect(); - UnrolledParams { - param_ranges, - param_names, - } - } -} - -/// Performs expansion of an already-parsed [`BenchmarkDef`]. -fn expand_benchmark( - benchmark_def: BenchmarkDef, - name: &Ident, - is_instance: bool, - where_clause: TokenStream2, -) -> TokenStream2 { - // set up variables needed during quoting - let krate = match generate_access_from_frame_or_crate("frame-benchmarking") { - Ok(ident) => ident, - Err(err) => return err.to_compile_error().into(), - }; - let frame_system = match generate_access_from_frame_or_crate("frame-system") { - Ok(path) => path, - Err(err) => return err.to_compile_error().into(), - }; - let codec = quote!(#krate::__private::codec); - let traits = quote!(#krate::__private::traits); - let setup_stmts = benchmark_def.setup_stmts; - let verify_stmts = benchmark_def.verify_stmts; - let last_stmt = benchmark_def.last_stmt; - let test_ident = Ident::new( - format!("test_benchmark_{}", name.to_string()).as_str(), - Span::call_site(), - ); - - // unroll params (prepare for quoting) - let unrolled = UnrolledParams::from(&benchmark_def.params); - let param_names = unrolled.param_names; - let param_ranges = unrolled.param_ranges; - - let type_use_generics = match is_instance { - false => quote!(T), - true => quote!(T, I), - }; - - let type_impl_generics = match is_instance { - false => quote!(T: Config), - true => quote!(T: Config, I: 'static), - }; - - // used in the benchmarking impls - let (pre_call, post_call, fn_call_body) = match &benchmark_def.call_def { - BenchmarkCallDef::ExtrinsicCall { - origin, - expr_call, - attr_span: _, - } => { - let mut expr_call = expr_call.clone(); - - // remove first arg from expr_call - let mut final_args = Punctuated::::new(); - let args: Vec<&Expr> = expr_call.args.iter().collect(); - for arg in &args[1..] { - final_args.push((*(*arg)).clone()); - } - expr_call.args = final_args; - - let origin = match origin { - Expr::Cast(t) => { - let ty = t.ty.clone(); - quote! { - <::RuntimeOrigin as From<#ty>>::from(#origin); - } - } - _ => quote! { - #origin.into(); - }, - }; - - // determine call name (handles `_` and normal call syntax) - let expr_span = expr_call.span(); - let call_err = || { - syn::Error::new(expr_span, "Extrinsic call must be a function call or `_`") - .to_compile_error() - }; - let call_name = match *expr_call.func { - Expr::Path(expr_path) => { - // normal function call - let Some(segment) = expr_path.path.segments.last() else { - return call_err(); - }; - segment.ident.to_string() - } - Expr::Infer(_) => { - // `_` style - // replace `_` with fn name - name.to_string() - } - _ => return call_err(), - }; - - // modify extrinsic call to be prefixed with "new_call_variant" - let call_name = format!("new_call_variant_{}", call_name); - let mut punct: Punctuated = Punctuated::new(); - punct.push(PathSegment { - arguments: PathArguments::None, - ident: Ident::new(call_name.as_str(), Span::call_site()), - }); - *expr_call.func = Expr::Path(ExprPath { - attrs: vec![], - qself: None, - path: Path { - leading_colon: None, - segments: punct, - }, - }); - let pre_call = quote! { - let __call = Call::<#type_use_generics>::#expr_call; - let __benchmarked_call_encoded = #codec::Encode::encode(&__call); - }; - let post_call = quote! { - let __call_decoded = as #codec::Decode> - ::decode(&mut &__benchmarked_call_encoded[..]) - .expect("call is encoded above, encoding must be correct"); - let __origin = #origin; - as #traits::UnfilteredDispatchable>::dispatch_bypass_filter( - __call_decoded, - __origin, - ) - }; - ( - // (pre_call, post_call, fn_call_body): - pre_call.clone(), - quote!(#post_call?;), - quote! { - #pre_call - #post_call.unwrap(); - }, - ) - } - BenchmarkCallDef::Block { - block, - attr_span: _, - } => (quote!(), quote!(#block), quote!(#block)), - }; - - let vis = benchmark_def.fn_vis; - - // remove #[benchmark] attribute - let fn_attrs = benchmark_def - .fn_attrs - .iter() - .filter(|attr| !attr.path().is_ident(keywords::BENCHMARK_TOKEN)); - - // modify signature generics, ident, and inputs, e.g: - // before: `fn bench(u: Linear<1, 100>) -> Result<(), BenchmarkError>` - // after: `fn _bench , I: 'static>(u: u32, verify: bool) -> Result<(), - // BenchmarkError>` - let mut sig = benchmark_def.fn_sig; - sig.generics = parse_quote!(<#type_impl_generics>); - if !where_clause.is_empty() { - sig.generics.where_clause = parse_quote!(where #where_clause); - } - sig.ident = Ident::new( - format!("_{}", name.to_token_stream().to_string()).as_str(), - Span::call_site(), - ); - let mut fn_param_inputs: Vec = - param_names.iter().map(|name| quote!(#name: u32)).collect(); - fn_param_inputs.push(quote!(verify: bool)); - sig.inputs = parse_quote!(#(#fn_param_inputs),*); - - // used in instance() impl - let impl_last_stmt = match &last_stmt { - Some(stmt) => quote!(#stmt), - None => quote!(Ok(())), - }; - let fn_attrs_clone = fn_attrs.clone(); - - let fn_def = quote! { - #( - #fn_attrs_clone - )* - #vis #sig { - #( - #setup_stmts - )* - #fn_call_body - if verify { - #( - #verify_stmts - )* - } - #last_stmt - } - }; - - // generate final quoted tokens - let res = quote! { - // benchmark function definition - #fn_def - - #[allow(non_camel_case_types)] - #( - #fn_attrs - )* - struct #name; - - #[allow(unused_variables)] - impl<#type_impl_generics> #krate::BenchmarkingSetup<#type_use_generics> - for #name where #where_clause { - fn components(&self) -> #krate::__private::Vec<(#krate::BenchmarkParameter, u32, u32)> { - #krate::__private::vec! [ - #( - (#krate::BenchmarkParameter::#param_ranges) - ),* - ] - } - - fn instance( - &self, - recording: &mut impl #krate::Recording, - components: &[(#krate::BenchmarkParameter, u32)], - verify: bool - ) -> Result<(), #krate::BenchmarkError> { - #( - // prepare instance #param_names - let #param_names = components.iter() - .find(|&c| c.0 == #krate::BenchmarkParameter::#param_names) - .ok_or("Could not find component during benchmark preparation.")? - .1; - )* - - // benchmark setup code - #( - #setup_stmts - )* - #pre_call - recording.start(); - #post_call - recording.stop(); - if verify { - #( - #verify_stmts - )* - } - #impl_last_stmt - } - } - - #[cfg(test)] - impl<#type_impl_generics> Pallet<#type_use_generics> where T: #frame_system::Config, #where_clause { - #[allow(unused)] - fn #test_ident() -> Result<(), #krate::BenchmarkError> { - let selected_benchmark = SelectedBenchmark::#name; - let components = < - SelectedBenchmark as #krate::BenchmarkingSetup - >::components(&selected_benchmark); - let execute_benchmark = | - c: #krate::__private::Vec<(#krate::BenchmarkParameter, u32)> - | -> Result<(), #krate::BenchmarkError> { - // Always reset the state after the benchmark. - #krate::__private::defer!(#krate::benchmarking::wipe_db()); - - let on_before_start = || { - // Set the block number to at least 1 so events are deposited. - if #krate::__private::Zero::is_zero(&#frame_system::Pallet::::block_number()) { - #frame_system::Pallet::::set_block_number(1u32.into()); - } - }; - - // Run execution + verification - >::test_instance(&selected_benchmark, &c, &on_before_start) - }; - - if components.is_empty() { - execute_benchmark(Default::default())?; - } else { - let num_values: u32 = if let Ok(ev) = std::env::var("VALUES_PER_COMPONENT") { - ev.parse().map_err(|_| { - #krate::BenchmarkError::Stop( - "Could not parse env var `VALUES_PER_COMPONENT` as u32." - ) - })? - } else { - 6 - }; - - if num_values < 2 { - return Err("`VALUES_PER_COMPONENT` must be at least 2".into()); - } - - for (name, low, high) in components.clone().into_iter() { - // Test the lowest, highest (if its different from the lowest) - // and up to num_values-2 more equidistant values in between. - // For 0..10 and num_values=6 this would mean: [0, 2, 4, 6, 8, 10] - if high < low { - return Err("The start of a `ParamRange` must be less than or equal to the end".into()); - } - - let mut values = #krate::__private::vec![low]; - let diff = (high - low).min(num_values - 1); - let slope = (high - low) as f32 / diff as f32; - - for i in 1..=diff { - let value = ((low as f32 + slope * i as f32) as u32) - .clamp(low, high); - values.push(value); - } - - for component_value in values { - // Select the max value for all the other components. - let c: #krate::__private::Vec<(#krate::BenchmarkParameter, u32)> = components - .iter() - .map(|(n, _, h)| - if *n == name { - (*n, component_value) - } else { - (*n, *h) - } - ) - .collect(); - - execute_benchmark(c)?; - } - } - } - return Ok(()); - } - } - }; - res -} diff --git a/support/procedural-fork/src/construct_runtime/expand/call.rs b/support/procedural-fork/src/construct_runtime/expand/call.rs deleted file mode 100644 index cc467c31d3..0000000000 --- a/support/procedural-fork/src/construct_runtime/expand/call.rs +++ /dev/null @@ -1,227 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License - -use crate::construct_runtime::Pallet; -use proc_macro2::TokenStream; -use quote::quote; -use std::str::FromStr; -use syn::Ident; - -pub fn expand_outer_dispatch( - runtime: &Ident, - system_pallet: &Pallet, - pallet_decls: &[Pallet], - scrate: &TokenStream, -) -> TokenStream { - let mut variant_defs = TokenStream::new(); - let mut variant_patterns = Vec::new(); - let mut query_call_part_macros = Vec::new(); - let mut pallet_names = Vec::new(); - let mut pallet_attrs = Vec::new(); - let system_path = &system_pallet.path; - - let pallets_with_call = pallet_decls.iter().filter(|decl| decl.exists_part("Call")); - - for pallet_declaration in pallets_with_call { - let name = &pallet_declaration.name; - let path = &pallet_declaration.path; - let index = pallet_declaration.index; - let attr = - pallet_declaration - .cfg_pattern - .iter() - .fold(TokenStream::new(), |acc, pattern| { - let attr = TokenStream::from_str(&format!("#[cfg({})]", pattern.original())) - .expect("was successfully parsed before; qed"); - quote! { - #acc - #attr - } - }); - - variant_defs.extend(quote! { - #attr - #[codec(index = #index)] - #name( #scrate::dispatch::CallableCallFor<#name, #runtime> ), - }); - variant_patterns.push(quote!(RuntimeCall::#name(call))); - pallet_names.push(name); - pallet_attrs.push(attr); - query_call_part_macros.push(quote! { - #path::__substrate_call_check::is_call_part_defined!(#name); - }); - } - - quote! { - #( #query_call_part_macros )* - - /// The aggregated runtime call type. - #[derive( - Clone, PartialEq, Eq, - #scrate::__private::codec::Encode, - #scrate::__private::codec::Decode, - #scrate::__private::scale_info::TypeInfo, - #scrate::__private::RuntimeDebug, - )] - pub enum RuntimeCall { - #variant_defs - } - #[cfg(test)] - impl RuntimeCall { - /// Return a list of the module names together with their size in memory. - pub const fn sizes() -> &'static [( &'static str, usize )] { - use #scrate::dispatch::Callable; - use core::mem::size_of; - &[#( - #pallet_attrs - ( - stringify!(#pallet_names), - size_of::< <#pallet_names as Callable<#runtime>>::RuntimeCall >(), - ), - )*] - } - - /// Panics with diagnostic information if the size is greater than the given `limit`. - pub fn assert_size_under(limit: usize) { - let size = core::mem::size_of::(); - let call_oversize = size > limit; - if call_oversize { - println!("Size of `Call` is {} bytes (provided limit is {} bytes)", size, limit); - let mut sizes = Self::sizes().to_vec(); - sizes.sort_by_key(|x| -(x.1 as isize)); - for (i, &(name, size)) in sizes.iter().enumerate().take(5) { - println!("Offender #{}: {} at {} bytes", i + 1, name, size); - } - if let Some((_, next_size)) = sizes.get(5) { - println!("{} others of size {} bytes or less", sizes.len() - 5, next_size); - } - panic!( - "Size of `Call` is more than limit; use `Box` on complex parameter types to reduce the - size of `Call`. - If the limit is too strong, maybe consider providing a higher limit." - ); - } - } - } - impl #scrate::dispatch::GetDispatchInfo for RuntimeCall { - fn get_dispatch_info(&self) -> #scrate::dispatch::DispatchInfo { - match self { - #( - #pallet_attrs - #variant_patterns => call.get_dispatch_info(), - )* - } - } - } - - impl #scrate::dispatch::CheckIfFeeless for RuntimeCall { - type Origin = #system_path::pallet_prelude::OriginFor<#runtime>; - fn is_feeless(&self, origin: &Self::Origin) -> bool { - match self { - #( - #pallet_attrs - #variant_patterns => call.is_feeless(origin), - )* - } - } - } - - impl #scrate::traits::GetCallMetadata for RuntimeCall { - fn get_call_metadata(&self) -> #scrate::traits::CallMetadata { - use #scrate::traits::GetCallName; - match self { - #( - #pallet_attrs - #variant_patterns => { - let function_name = call.get_call_name(); - let pallet_name = stringify!(#pallet_names); - #scrate::traits::CallMetadata { function_name, pallet_name } - } - )* - } - } - - fn get_module_names() -> &'static [&'static str] { - &[#( - #pallet_attrs - stringify!(#pallet_names), - )*] - } - - fn get_call_names(module: &str) -> &'static [&'static str] { - use #scrate::{dispatch::Callable, traits::GetCallName}; - match module { - #( - #pallet_attrs - stringify!(#pallet_names) => - <<#pallet_names as Callable<#runtime>>::RuntimeCall - as GetCallName>::get_call_names(), - )* - _ => unreachable!(), - } - } - } - impl #scrate::__private::Dispatchable for RuntimeCall { - type RuntimeOrigin = RuntimeOrigin; - type Config = RuntimeCall; - type Info = #scrate::dispatch::DispatchInfo; - type PostInfo = #scrate::dispatch::PostDispatchInfo; - fn dispatch(self, origin: RuntimeOrigin) -> #scrate::dispatch::DispatchResultWithPostInfo { - if !::filter_call(&origin, &self) { - return ::core::result::Result::Err( - #system_path::Error::<#runtime>::CallFiltered.into() - ); - } - - #scrate::traits::UnfilteredDispatchable::dispatch_bypass_filter(self, origin) - } - } - impl #scrate::traits::UnfilteredDispatchable for RuntimeCall { - type RuntimeOrigin = RuntimeOrigin; - fn dispatch_bypass_filter(self, origin: RuntimeOrigin) -> #scrate::dispatch::DispatchResultWithPostInfo { - match self { - #( - #pallet_attrs - #variant_patterns => - #scrate::traits::UnfilteredDispatchable::dispatch_bypass_filter(call, origin), - )* - } - } - } - - #( - #pallet_attrs - impl #scrate::traits::IsSubType<#scrate::dispatch::CallableCallFor<#pallet_names, #runtime>> for RuntimeCall { - #[allow(unreachable_patterns)] - fn is_sub_type(&self) -> Option<&#scrate::dispatch::CallableCallFor<#pallet_names, #runtime>> { - match self { - #variant_patterns => Some(call), - // May be unreachable - _ => None, - } - } - } - - #pallet_attrs - impl From<#scrate::dispatch::CallableCallFor<#pallet_names, #runtime>> for RuntimeCall { - fn from(call: #scrate::dispatch::CallableCallFor<#pallet_names, #runtime>) -> Self { - #variant_patterns - } - } - )* - } -} diff --git a/support/procedural-fork/src/construct_runtime/expand/composite_helper.rs b/support/procedural-fork/src/construct_runtime/expand/composite_helper.rs deleted file mode 100644 index be6b2f085d..0000000000 --- a/support/procedural-fork/src/construct_runtime/expand/composite_helper.rs +++ /dev/null @@ -1,101 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License - -use crate::construct_runtime::parse::PalletPath; -use proc_macro2::{Ident, TokenStream}; -use quote::quote; - -pub(crate) fn expand_conversion_fn( - composite_name: &str, - path: &PalletPath, - instance: Option<&Ident>, - variant_name: &Ident, -) -> TokenStream { - let composite_name = quote::format_ident!("{}", composite_name); - let runtime_composite_name = quote::format_ident!("Runtime{}", composite_name); - - if let Some(inst) = instance { - quote! { - impl From<#path::#composite_name<#path::#inst>> for #runtime_composite_name { - fn from(hr: #path::#composite_name<#path::#inst>) -> Self { - #runtime_composite_name::#variant_name(hr) - } - } - } - } else { - quote! { - impl From<#path::#composite_name> for #runtime_composite_name { - fn from(hr: #path::#composite_name) -> Self { - #runtime_composite_name::#variant_name(hr) - } - } - } - } -} - -pub(crate) fn expand_variant( - composite_name: &str, - index: u8, - path: &PalletPath, - instance: Option<&Ident>, - variant_name: &Ident, -) -> TokenStream { - let composite_name = quote::format_ident!("{}", composite_name); - - if let Some(inst) = instance { - quote! { - #[codec(index = #index)] - #variant_name(#path::#composite_name<#path::#inst>), - } - } else { - quote! { - #[codec(index = #index)] - #variant_name(#path::#composite_name), - } - } -} - -pub(crate) fn expand_variant_count( - composite_name: &str, - path: &PalletPath, - instance: Option<&Ident>, -) -> TokenStream { - let composite_name = quote::format_ident!("{}", composite_name); - - if let Some(inst) = instance { - quote! { - #path::#composite_name::<#path::#inst>::VARIANT_COUNT - } - } else { - // Wrapped `<`..`>` means: use default type parameter for enum. - // - // This is used for pallets without instance support or pallets with instance support when - // we don't specify instance: - // - // ``` - // pub struct Pallet{..} - // - // #[pallet::composite_enum] - // pub enum HoldReason {..} - // - // Pallet1: pallet_x, // <- default type parameter - // ``` - quote! { - <#path::#composite_name>::VARIANT_COUNT - } - } -} diff --git a/support/procedural-fork/src/construct_runtime/expand/config.rs b/support/procedural-fork/src/construct_runtime/expand/config.rs deleted file mode 100644 index 1fbcd107f6..0000000000 --- a/support/procedural-fork/src/construct_runtime/expand/config.rs +++ /dev/null @@ -1,157 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License - -use crate::construct_runtime::Pallet; -use inflector::Inflector; -use proc_macro2::TokenStream; -use quote::{ToTokens, format_ident, quote}; -use std::str::FromStr; -use syn::Ident; - -pub fn expand_outer_config( - runtime: &Ident, - pallet_decls: &[Pallet], - scrate: &TokenStream, -) -> TokenStream { - let mut types = TokenStream::new(); - let mut fields = TokenStream::new(); - let mut genesis_build_calls = TokenStream::new(); - let mut query_genesis_config_part_macros = Vec::new(); - - for decl in pallet_decls { - if let Some(pallet_entry) = decl.find_part("Config") { - let path = &decl.path; - let pallet_name = &decl.name; - let path_str = path.into_token_stream().to_string(); - let config = format_ident!("{}Config", pallet_name); - let field_name = - &Ident::new(&pallet_name.to_string().to_snake_case(), decl.name.span()); - let part_is_generic = !pallet_entry.generics.params.is_empty(); - let attr = &decl - .cfg_pattern - .iter() - .fold(TokenStream::new(), |acc, pattern| { - let attr = TokenStream::from_str(&format!("#[cfg({})]", pattern.original())) - .expect("was successfully parsed before; qed"); - quote! { - #acc - #attr - } - }); - - types.extend(expand_config_types( - attr, - runtime, - decl, - &config, - part_is_generic, - )); - fields.extend(quote!(#attr pub #field_name: #config,)); - genesis_build_calls.extend(expand_config_build_storage_call( - scrate, &config, attr, field_name, - )); - query_genesis_config_part_macros.push(quote! { - #path::__substrate_genesis_config_check::is_genesis_config_defined!(#pallet_name); - #[cfg(feature = "std")] - #path::__substrate_genesis_config_check::is_std_enabled_for_genesis!(#pallet_name, #path_str); - }); - } - } - - quote! { - #( #query_genesis_config_part_macros )* - - #types - - use #scrate::__private::serde as __genesis_config_serde_import__; - #[derive(#scrate::__private::serde::Serialize, #scrate::__private::serde::Deserialize, Default)] - #[serde(rename_all = "camelCase")] - #[serde(deny_unknown_fields)] - #[serde(crate = "__genesis_config_serde_import__")] - pub struct RuntimeGenesisConfig { - #fields - } - - #[cfg(any(feature = "std", test))] - impl #scrate::sp_runtime::BuildStorage for RuntimeGenesisConfig { - fn assimilate_storage( - &self, - storage: &mut #scrate::sp_runtime::Storage, - ) -> std::result::Result<(), String> { - #scrate::__private::BasicExternalities::execute_with_storage(storage, || { - ::build(&self); - Ok(()) - }) - } - } - - impl #scrate::traits::BuildGenesisConfig for RuntimeGenesisConfig { - fn build(&self) { - #genesis_build_calls - ::on_genesis(); - } - } - - /// Test the `Default` derive impl of the `RuntimeGenesisConfig`. - #[cfg(test)] - #[test] - fn test_genesis_config_builds() { - #scrate::__private::sp_io::TestExternalities::default().execute_with(|| { - ::build( - &RuntimeGenesisConfig::default() - ); - }); - } - } -} - -fn expand_config_types( - attr: &TokenStream, - runtime: &Ident, - decl: &Pallet, - config: &Ident, - part_is_generic: bool, -) -> TokenStream { - let path = &decl.path; - - match (decl.instance.as_ref(), part_is_generic) { - (Some(inst), true) => quote! { - #attr - pub type #config = #path::GenesisConfig<#runtime, #path::#inst>; - }, - (None, true) => quote! { - #attr - pub type #config = #path::GenesisConfig<#runtime>; - }, - (_, false) => quote! { - #attr - pub type #config = #path::GenesisConfig; - }, - } -} - -fn expand_config_build_storage_call( - scrate: &TokenStream, - pallet_genesis_config: &Ident, - attr: &TokenStream, - field_name: &Ident, -) -> TokenStream { - quote! { - #attr - <#pallet_genesis_config as #scrate::traits::BuildGenesisConfig>::build(&self.#field_name); - } -} diff --git a/support/procedural-fork/src/construct_runtime/expand/freeze_reason.rs b/support/procedural-fork/src/construct_runtime/expand/freeze_reason.rs deleted file mode 100644 index 131c919ef0..0000000000 --- a/support/procedural-fork/src/construct_runtime/expand/freeze_reason.rs +++ /dev/null @@ -1,75 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License - -use super::composite_helper; -use crate::construct_runtime::Pallet; -use proc_macro2::TokenStream; -use quote::quote; - -pub fn expand_outer_freeze_reason(pallet_decls: &[Pallet], scrate: &TokenStream) -> TokenStream { - let mut conversion_fns = Vec::new(); - let mut freeze_reason_variants = Vec::new(); - let mut freeze_reason_variants_count = Vec::new(); - for decl in pallet_decls { - if let Some(_) = decl.find_part("FreezeReason") { - let variant_name = &decl.name; - let path = &decl.path; - let index = decl.index; - let instance = decl.instance.as_ref(); - - conversion_fns.push(composite_helper::expand_conversion_fn( - "FreezeReason", - path, - instance, - variant_name, - )); - - freeze_reason_variants.push(composite_helper::expand_variant( - "FreezeReason", - index, - path, - instance, - variant_name, - )); - - freeze_reason_variants_count.push(composite_helper::expand_variant_count( - "FreezeReason", - path, - instance, - )); - } - } - - quote! { - /// A reason for placing a freeze on funds. - #[derive( - Copy, Clone, Eq, PartialEq, - #scrate::__private::codec::Encode, #scrate::__private::codec::Decode, #scrate::__private::codec::MaxEncodedLen, - #scrate::__private::scale_info::TypeInfo, - #scrate::__private::RuntimeDebug, - )] - pub enum RuntimeFreezeReason { - #( #freeze_reason_variants )* - } - - impl #scrate::traits::VariantCount for RuntimeFreezeReason { - const VARIANT_COUNT: u32 = 0 #( + #freeze_reason_variants_count )*; - } - - #( #conversion_fns )* - } -} diff --git a/support/procedural-fork/src/construct_runtime/expand/hold_reason.rs b/support/procedural-fork/src/construct_runtime/expand/hold_reason.rs deleted file mode 100644 index 58870a3218..0000000000 --- a/support/procedural-fork/src/construct_runtime/expand/hold_reason.rs +++ /dev/null @@ -1,75 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License - -use super::composite_helper; -use crate::construct_runtime::Pallet; -use proc_macro2::TokenStream; -use quote::quote; - -pub fn expand_outer_hold_reason(pallet_decls: &[Pallet], scrate: &TokenStream) -> TokenStream { - let mut conversion_fns = Vec::new(); - let mut hold_reason_variants = Vec::new(); - let mut hold_reason_variants_count = Vec::new(); - for decl in pallet_decls { - if let Some(_) = decl.find_part("HoldReason") { - let variant_name = &decl.name; - let path = &decl.path; - let index = decl.index; - let instance = decl.instance.as_ref(); - - conversion_fns.push(composite_helper::expand_conversion_fn( - "HoldReason", - path, - instance, - variant_name, - )); - - hold_reason_variants.push(composite_helper::expand_variant( - "HoldReason", - index, - path, - instance, - variant_name, - )); - - hold_reason_variants_count.push(composite_helper::expand_variant_count( - "HoldReason", - path, - instance, - )); - } - } - - quote! { - /// A reason for placing a hold on funds. - #[derive( - Copy, Clone, Eq, PartialEq, - #scrate::__private::codec::Encode, #scrate::__private::codec::Decode, #scrate::__private::codec::MaxEncodedLen, - #scrate::__private::scale_info::TypeInfo, - #scrate::__private::RuntimeDebug, - )] - pub enum RuntimeHoldReason { - #( #hold_reason_variants )* - } - - impl #scrate::traits::VariantCount for RuntimeHoldReason { - const VARIANT_COUNT: u32 = 0 #( + #hold_reason_variants_count )*; - } - - #( #conversion_fns )* - } -} diff --git a/support/procedural-fork/src/construct_runtime/expand/inherent.rs b/support/procedural-fork/src/construct_runtime/expand/inherent.rs deleted file mode 100644 index 9705f97035..0000000000 --- a/support/procedural-fork/src/construct_runtime/expand/inherent.rs +++ /dev/null @@ -1,257 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License - -use crate::construct_runtime::Pallet; -use proc_macro2::TokenStream; -use quote::quote; -use std::str::FromStr; -use syn::Ident; - -pub fn expand_outer_inherent( - runtime: &Ident, - block: &TokenStream, - unchecked_extrinsic: &TokenStream, - pallet_decls: &[Pallet], - scrate: &TokenStream, -) -> TokenStream { - let mut pallet_names = Vec::new(); - let mut pallet_attrs = Vec::new(); - let mut query_inherent_part_macros = Vec::new(); - - for pallet_decl in pallet_decls { - if pallet_decl.exists_part("Inherent") { - let name = &pallet_decl.name; - let path = &pallet_decl.path; - let attr = pallet_decl - .cfg_pattern - .iter() - .fold(TokenStream::new(), |acc, pattern| { - let attr = TokenStream::from_str(&format!("#[cfg({})]", pattern.original())) - .expect("was successfully parsed before; qed"); - quote! { - #acc - #attr - } - }); - - pallet_names.push(name); - pallet_attrs.push(attr); - query_inherent_part_macros.push(quote! { - #path::__substrate_inherent_check::is_inherent_part_defined!(#name); - }); - } - } - - quote! { - #( #query_inherent_part_macros )* - - trait InherentDataExt { - fn create_extrinsics(&self) -> - #scrate::__private::Vec<<#block as #scrate::sp_runtime::traits::Block>::Extrinsic>; - fn check_extrinsics(&self, block: &#block) -> #scrate::inherent::CheckInherentsResult; - } - - impl InherentDataExt for #scrate::inherent::InherentData { - fn create_extrinsics(&self) -> - #scrate::__private::Vec<<#block as #scrate::sp_runtime::traits::Block>::Extrinsic> - { - use #scrate::inherent::ProvideInherent; - - let mut inherents = #scrate::__private::Vec::new(); - - #( - #pallet_attrs - if let Some(inherent) = #pallet_names::create_inherent(self) { - let inherent = <#unchecked_extrinsic as #scrate::sp_runtime::traits::Extrinsic>::new( - inherent.into(), - None, - ).expect("Runtime UncheckedExtrinsic is not Opaque, so it has to return \ - `Some`; qed"); - - inherents.push(inherent); - } - )* - - inherents - } - - fn check_extrinsics(&self, block: &#block) -> #scrate::inherent::CheckInherentsResult { - use #scrate::inherent::{ProvideInherent, IsFatalError}; - use #scrate::traits::{IsSubType, ExtrinsicCall}; - use #scrate::sp_runtime::traits::Block as _; - use #scrate::__private::{sp_inherents::Error, log}; - - let mut result = #scrate::inherent::CheckInherentsResult::new(); - - // This handle assume we abort on the first fatal error. - fn handle_put_error_result(res: Result<(), Error>) { - const LOG_TARGET: &str = "runtime::inherent"; - match res { - Ok(()) => (), - Err(Error::InherentDataExists(id)) => - log::debug!( - target: LOG_TARGET, - "Some error already reported for inherent {:?}, new non fatal \ - error is ignored", - id - ), - Err(Error::FatalErrorReported) => - log::error!( - target: LOG_TARGET, - "Fatal error already reported, unexpected considering there is \ - only one fatal error", - ), - Err(_) => - log::error!( - target: LOG_TARGET, - "Unexpected error from `put_error` operation", - ), - } - } - - for xt in block.extrinsics() { - // Inherents are before any other extrinsics. - // And signed extrinsics are not inherents. - if #scrate::sp_runtime::traits::Extrinsic::is_signed(xt).unwrap_or(false) { - break - } - - let mut is_inherent = false; - - #( - #pallet_attrs - { - let call = <#unchecked_extrinsic as ExtrinsicCall>::call(xt); - if let Some(call) = IsSubType::<_>::is_sub_type(call) { - if #pallet_names::is_inherent(call) { - is_inherent = true; - if let Err(e) = #pallet_names::check_inherent(call, self) { - handle_put_error_result(result.put_error( - #pallet_names::INHERENT_IDENTIFIER, &e - )); - if e.is_fatal_error() { - return result; - } - } - } - } - } - )* - - // Inherents are before any other extrinsics. - // No module marked it as inherent thus it is not. - if !is_inherent { - break - } - } - - #( - #pallet_attrs - match #pallet_names::is_inherent_required(self) { - Ok(Some(e)) => { - let found = block.extrinsics().iter().any(|xt| { - let is_signed = #scrate::sp_runtime::traits::Extrinsic::is_signed(xt) - .unwrap_or(false); - - if !is_signed { - let call = < - #unchecked_extrinsic as ExtrinsicCall - >::call(xt); - if let Some(call) = IsSubType::<_>::is_sub_type(call) { - #pallet_names::is_inherent(&call) - } else { - false - } - } else { - // Signed extrinsics are not inherents. - false - } - }); - - if !found { - handle_put_error_result(result.put_error( - #pallet_names::INHERENT_IDENTIFIER, &e - )); - if e.is_fatal_error() { - return result; - } - } - }, - Ok(None) => (), - Err(e) => { - handle_put_error_result(result.put_error( - #pallet_names::INHERENT_IDENTIFIER, &e - )); - if e.is_fatal_error() { - return result; - } - }, - } - )* - - result - } - } - - impl #scrate::traits::IsInherent<<#block as #scrate::sp_runtime::traits::Block>::Extrinsic> for #runtime { - fn is_inherent(ext: &<#block as #scrate::sp_runtime::traits::Block>::Extrinsic) -> bool { - use #scrate::inherent::ProvideInherent; - use #scrate::traits::{IsSubType, ExtrinsicCall}; - - if #scrate::sp_runtime::traits::Extrinsic::is_signed(ext).unwrap_or(false) { - // Signed extrinsics are never inherents. - return false - } - - #( - #pallet_attrs - { - let call = <#unchecked_extrinsic as ExtrinsicCall>::call(ext); - if let Some(call) = IsSubType::<_>::is_sub_type(call) { - if <#pallet_names as ProvideInherent>::is_inherent(&call) { - return true; - } - } - } - )* - false - } - } - - impl #scrate::traits::EnsureInherentsAreFirst<#block> for #runtime { - fn ensure_inherents_are_first(block: &#block) -> Result { - use #scrate::inherent::ProvideInherent; - use #scrate::traits::{IsSubType, ExtrinsicCall}; - use #scrate::sp_runtime::traits::Block as _; - - let mut num_inherents = 0u32; - - for (i, xt) in block.extrinsics().iter().enumerate() { - if >::is_inherent(xt) { - if num_inherents != i as u32 { - return Err(i as u32); - } - - num_inherents += 1; // Safe since we are in an `enumerate` loop. - } - } - - Ok(num_inherents) - } - } - } -} diff --git a/support/procedural-fork/src/construct_runtime/expand/lock_id.rs b/support/procedural-fork/src/construct_runtime/expand/lock_id.rs deleted file mode 100644 index 67c2fb9335..0000000000 --- a/support/procedural-fork/src/construct_runtime/expand/lock_id.rs +++ /dev/null @@ -1,64 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License - -use super::composite_helper; -use crate::construct_runtime::Pallet; -use proc_macro2::TokenStream; -use quote::quote; - -pub fn expand_outer_lock_id(pallet_decls: &[Pallet], scrate: &TokenStream) -> TokenStream { - let mut conversion_fns = Vec::new(); - let mut lock_id_variants = Vec::new(); - for decl in pallet_decls { - if let Some(_) = decl.find_part("LockId") { - let variant_name = &decl.name; - let path = &decl.path; - let index = decl.index; - let instance = decl.instance.as_ref(); - - conversion_fns.push(composite_helper::expand_conversion_fn( - "LockId", - path, - instance, - variant_name, - )); - - lock_id_variants.push(composite_helper::expand_variant( - "LockId", - index, - path, - instance, - variant_name, - )); - } - } - - quote! { - /// An identifier for each lock placed on funds. - #[derive( - Copy, Clone, Eq, PartialEq, - #scrate::__private::codec::Encode, #scrate::__private::codec::Decode, #scrate::__private::codec::MaxEncodedLen, - #scrate::__private::scale_info::TypeInfo, - #scrate::__private::RuntimeDebug, - )] - pub enum RuntimeLockId { - #( #lock_id_variants )* - } - - #( #conversion_fns )* - } -} diff --git a/support/procedural-fork/src/construct_runtime/expand/metadata.rs b/support/procedural-fork/src/construct_runtime/expand/metadata.rs deleted file mode 100644 index 4d338d7977..0000000000 --- a/support/procedural-fork/src/construct_runtime/expand/metadata.rs +++ /dev/null @@ -1,261 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License - -use crate::construct_runtime::{Pallet, parse::PalletPath}; -use proc_macro2::TokenStream; -use quote::quote; -use std::str::FromStr; -use syn::Ident; - -pub fn expand_runtime_metadata( - runtime: &Ident, - pallet_declarations: &[Pallet], - scrate: &TokenStream, - extrinsic: &TokenStream, - system_path: &PalletPath, -) -> TokenStream { - let pallets = pallet_declarations - .iter() - .filter_map(|pallet_declaration| { - pallet_declaration.find_part("Pallet").map(|_| { - let filtered_names: Vec<_> = pallet_declaration - .pallet_parts() - .iter() - .filter(|part| part.name() != "Pallet") - .map(|part| part.name()) - .collect(); - (pallet_declaration, filtered_names) - }) - }) - .map(|(decl, filtered_names)| { - let name = &decl.name; - let index = &decl.index; - let storage = expand_pallet_metadata_storage(&filtered_names, runtime, decl); - let calls = expand_pallet_metadata_calls(&filtered_names, runtime, decl); - let event = expand_pallet_metadata_events(&filtered_names, runtime, scrate, decl); - let constants = expand_pallet_metadata_constants(runtime, decl); - let errors = expand_pallet_metadata_errors(runtime, decl); - let docs = expand_pallet_metadata_docs(runtime, decl); - let attr = decl - .cfg_pattern - .iter() - .fold(TokenStream::new(), |acc, pattern| { - let attr = TokenStream::from_str(&format!("#[cfg({})]", pattern.original())) - .expect("was successfully parsed before; qed"); - quote! { - #acc - #attr - } - }); - - quote! { - #attr - #scrate::__private::metadata_ir::PalletMetadataIR { - name: stringify!(#name), - index: #index, - storage: #storage, - calls: #calls, - event: #event, - constants: #constants, - error: #errors, - docs: #docs, - } - } - }) - .collect::>(); - - quote! { - impl #runtime { - fn metadata_ir() -> #scrate::__private::metadata_ir::MetadataIR { - // Each runtime must expose the `runtime_metadata()` to fetch the runtime API metadata. - // The function is implemented by calling `impl_runtime_apis!`. - // - // However, the `construct_runtime!` may be called without calling `impl_runtime_apis!`. - // Rely on the `Deref` trait to differentiate between a runtime that implements - // APIs (by macro impl_runtime_apis!) and a runtime that is simply created (by macro construct_runtime!). - // - // Both `InternalConstructRuntime` and `InternalImplRuntimeApis` expose a `runtime_metadata()` function. - // `InternalConstructRuntime` is implemented by the `construct_runtime!` for Runtime references (`& Runtime`), - // while `InternalImplRuntimeApis` is implemented by the `impl_runtime_apis!` for Runtime (`Runtime`). - // - // Therefore, the `Deref` trait will resolve the `runtime_metadata` from `impl_runtime_apis!` - // when both macros are called; and will resolve an empty `runtime_metadata` when only the `construct_runtime!` - // is called. - // - // `Deref` needs a reference for resolving the function call. - let rt = #runtime; - - let ty = #scrate::__private::scale_info::meta_type::<#extrinsic>(); - let address_ty = #scrate::__private::scale_info::meta_type::< - <<#extrinsic as #scrate::sp_runtime::traits::Extrinsic>::SignaturePayload as #scrate::sp_runtime::traits::SignaturePayload>::SignatureAddress - >(); - let call_ty = #scrate::__private::scale_info::meta_type::< - <#extrinsic as #scrate::sp_runtime::traits::Extrinsic>::Call - >(); - let signature_ty = #scrate::__private::scale_info::meta_type::< - <<#extrinsic as #scrate::sp_runtime::traits::Extrinsic>::SignaturePayload as #scrate::sp_runtime::traits::SignaturePayload>::Signature - >(); - let extra_ty = #scrate::__private::scale_info::meta_type::< - <<#extrinsic as #scrate::sp_runtime::traits::Extrinsic>::SignaturePayload as #scrate::sp_runtime::traits::SignaturePayload>::SignatureExtra - >(); - - #scrate::__private::metadata_ir::MetadataIR { - pallets: #scrate::__private::vec![ #(#pallets),* ], - extrinsic: #scrate::__private::metadata_ir::ExtrinsicMetadataIR { - ty, - version: <#extrinsic as #scrate::sp_runtime::traits::ExtrinsicMetadata>::VERSION, - address_ty, - call_ty, - signature_ty, - extra_ty, - signed_extensions: < - < - #extrinsic as #scrate::sp_runtime::traits::ExtrinsicMetadata - >::SignedExtensions as #scrate::sp_runtime::traits::SignedExtension - >::metadata() - .into_iter() - .map(|meta| #scrate::__private::metadata_ir::SignedExtensionMetadataIR { - identifier: meta.identifier, - ty: meta.ty, - additional_signed: meta.additional_signed, - }) - .collect(), - }, - ty: #scrate::__private::scale_info::meta_type::<#runtime>(), - apis: (&rt).runtime_metadata(), - outer_enums: #scrate::__private::metadata_ir::OuterEnumsIR { - call_enum_ty: #scrate::__private::scale_info::meta_type::< - <#runtime as #system_path::Config>::RuntimeCall - >(), - event_enum_ty: #scrate::__private::scale_info::meta_type::(), - error_enum_ty: #scrate::__private::scale_info::meta_type::(), - } - } - } - - pub fn metadata() -> #scrate::__private::metadata::RuntimeMetadataPrefixed { - // Note: this always returns the V14 version. The runtime API function - // must be deprecated. - #scrate::__private::metadata_ir::into_v14(#runtime::metadata_ir()) - } - - pub fn metadata_at_version(version: u32) -> Option<#scrate::__private::OpaqueMetadata> { - #scrate::__private::metadata_ir::into_version(#runtime::metadata_ir(), version).map(|prefixed| { - #scrate::__private::OpaqueMetadata::new(prefixed.into()) - }) - } - - pub fn metadata_versions() -> #scrate::__private::Vec { - #scrate::__private::metadata_ir::supported_versions() - } - } - } -} - -fn expand_pallet_metadata_storage( - filtered_names: &[&'static str], - runtime: &Ident, - decl: &Pallet, -) -> TokenStream { - if filtered_names.contains(&"Storage") { - let instance = decl.instance.as_ref().into_iter(); - let path = &decl.path; - - quote! { - Some(#path::Pallet::<#runtime #(, #path::#instance)*>::storage_metadata()) - } - } else { - quote!(None) - } -} - -fn expand_pallet_metadata_calls( - filtered_names: &[&'static str], - runtime: &Ident, - decl: &Pallet, -) -> TokenStream { - if filtered_names.contains(&"Call") { - let instance = decl.instance.as_ref().into_iter(); - let path = &decl.path; - - quote! { - Some(#path::Pallet::<#runtime #(, #path::#instance)*>::call_functions()) - } - } else { - quote!(None) - } -} - -fn expand_pallet_metadata_events( - filtered_names: &[&'static str], - runtime: &Ident, - scrate: &TokenStream, - decl: &Pallet, -) -> TokenStream { - if filtered_names.contains(&"Event") { - let path = &decl.path; - let part_is_generic = !decl - .find_part("Event") - .expect("Event part exists; qed") - .generics - .params - .is_empty(); - let pallet_event = match (decl.instance.as_ref(), part_is_generic) { - (Some(inst), true) => quote!(#path::Event::<#runtime, #path::#inst>), - (Some(inst), false) => quote!(#path::Event::<#path::#inst>), - (None, true) => quote!(#path::Event::<#runtime>), - (None, false) => quote!(#path::Event), - }; - - quote! { - Some( - #scrate::__private::metadata_ir::PalletEventMetadataIR { - ty: #scrate::__private::scale_info::meta_type::<#pallet_event>() - } - ) - } - } else { - quote!(None) - } -} - -fn expand_pallet_metadata_constants(runtime: &Ident, decl: &Pallet) -> TokenStream { - let path = &decl.path; - let instance = decl.instance.as_ref().into_iter(); - - quote! { - #path::Pallet::<#runtime #(, #path::#instance)*>::pallet_constants_metadata() - } -} - -fn expand_pallet_metadata_errors(runtime: &Ident, decl: &Pallet) -> TokenStream { - let path = &decl.path; - let instance = decl.instance.as_ref().into_iter(); - - quote! { - #path::Pallet::<#runtime #(, #path::#instance)*>::error_metadata() - } -} - -fn expand_pallet_metadata_docs(runtime: &Ident, decl: &Pallet) -> TokenStream { - let path = &decl.path; - let instance = decl.instance.as_ref().into_iter(); - - quote! { - #path::Pallet::<#runtime #(, #path::#instance)*>::pallet_documentation_metadata() - } -} diff --git a/support/procedural-fork/src/construct_runtime/expand/mod.rs b/support/procedural-fork/src/construct_runtime/expand/mod.rs deleted file mode 100644 index 2d3538fcff..0000000000 --- a/support/procedural-fork/src/construct_runtime/expand/mod.rs +++ /dev/null @@ -1,43 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License - -mod call; -pub mod composite_helper; -mod config; -mod freeze_reason; -mod hold_reason; -mod inherent; -mod lock_id; -mod metadata; -mod origin; -mod outer_enums; -mod slash_reason; -mod task; -mod unsigned; - -pub use call::expand_outer_dispatch; -pub use config::expand_outer_config; -pub use freeze_reason::expand_outer_freeze_reason; -pub use hold_reason::expand_outer_hold_reason; -pub use inherent::expand_outer_inherent; -pub use lock_id::expand_outer_lock_id; -pub use metadata::expand_runtime_metadata; -pub use origin::expand_outer_origin; -pub use outer_enums::{OuterEnumType, expand_outer_enum}; -pub use slash_reason::expand_outer_slash_reason; -pub use task::expand_outer_task; -pub use unsigned::expand_outer_validate_unsigned; diff --git a/support/procedural-fork/src/construct_runtime/expand/origin.rs b/support/procedural-fork/src/construct_runtime/expand/origin.rs deleted file mode 100644 index 58c8adec51..0000000000 --- a/support/procedural-fork/src/construct_runtime/expand/origin.rs +++ /dev/null @@ -1,469 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License - -use crate::construct_runtime::{Pallet, SYSTEM_PALLET_NAME}; -use proc_macro2::TokenStream; -use quote::quote; -use std::str::FromStr; -use syn::{Generics, Ident}; - -pub fn expand_outer_origin( - runtime: &Ident, - system_pallet: &Pallet, - pallets: &[Pallet], - scrate: &TokenStream, -) -> syn::Result { - let mut caller_variants = TokenStream::new(); - let mut pallet_conversions = TokenStream::new(); - let mut query_origin_part_macros = Vec::new(); - - for pallet_decl in pallets - .iter() - .filter(|pallet| pallet.name != SYSTEM_PALLET_NAME) - { - if let Some(pallet_entry) = pallet_decl.find_part("Origin") { - let instance = pallet_decl.instance.as_ref(); - let index = pallet_decl.index; - let generics = &pallet_entry.generics; - let name = &pallet_decl.name; - let path = &pallet_decl.path; - - if instance.is_some() && generics.params.is_empty() { - let msg = format!( - "Instantiable pallet with no generic `Origin` cannot \ - be constructed: pallet `{}` must have generic `Origin`", - name - ); - return Err(syn::Error::new(name.span(), msg)); - } - - caller_variants.extend(expand_origin_caller_variant( - runtime, - pallet_decl, - index, - instance, - generics, - )); - pallet_conversions.extend(expand_origin_pallet_conversions( - scrate, - runtime, - pallet_decl, - instance, - generics, - )); - query_origin_part_macros.push(quote! { - #path::__substrate_origin_check::is_origin_part_defined!(#name); - }); - } - } - - let system_path = &system_pallet.path; - - let system_index = system_pallet.index; - - let system_path_name = system_path.module_name(); - - let doc_string = get_intra_doc_string( - "Origin is always created with the base filter configured in", - &system_path_name, - ); - - let doc_string_none_origin = - get_intra_doc_string("Create with system none origin and", &system_path_name); - - let doc_string_root_origin = - get_intra_doc_string("Create with system root origin and", &system_path_name); - - let doc_string_signed_origin = - get_intra_doc_string("Create with system signed origin and", &system_path_name); - - let doc_string_runtime_origin = get_intra_doc_string( - "Convert to runtime origin, using as filter:", - &system_path_name, - ); - - let doc_string_runtime_origin_with_caller = get_intra_doc_string( - "Convert to runtime origin with caller being system signed or none and use filter", - &system_path_name, - ); - - Ok(quote! { - #( #query_origin_part_macros )* - - /// The runtime origin type representing the origin of a call. - /// - #[doc = #doc_string] - #[derive(Clone)] - pub struct RuntimeOrigin { - pub caller: OriginCaller, - filter: #scrate::__private::Rc<#scrate::__private::Box::RuntimeCall) -> bool>>, - } - - #[cfg(not(feature = "std"))] - impl core::fmt::Debug for RuntimeOrigin { - fn fmt( - &self, - fmt: &mut core::fmt::Formatter, - ) -> core::result::Result<(), core::fmt::Error> { - fmt.write_str("") - } - } - - #[cfg(feature = "std")] - impl core::fmt::Debug for RuntimeOrigin { - fn fmt( - &self, - fmt: &mut core::fmt::Formatter, - ) -> core::result::Result<(), core::fmt::Error> { - fmt.debug_struct("Origin") - .field("caller", &self.caller) - .field("filter", &"[function ptr]") - .finish() - } - } - - impl #scrate::traits::OriginTrait for RuntimeOrigin { - type Call = <#runtime as #system_path::Config>::RuntimeCall; - type PalletsOrigin = OriginCaller; - type AccountId = <#runtime as #system_path::Config>::AccountId; - - fn add_filter(&mut self, filter: impl Fn(&Self::Call) -> bool + 'static) { - let f = self.filter.clone(); - - self.filter = #scrate::__private::Rc::new(#scrate::__private::Box::new(move |call| { - f(call) && filter(call) - })); - } - - fn reset_filter(&mut self) { - let filter = < - <#runtime as #system_path::Config>::BaseCallFilter - as #scrate::traits::Contains<<#runtime as #system_path::Config>::RuntimeCall> - >::contains; - - self.filter = #scrate::__private::Rc::new(#scrate::__private::Box::new(filter)); - } - - fn set_caller_from(&mut self, other: impl Into) { - self.caller = other.into().caller; - } - - fn filter_call(&self, call: &Self::Call) -> bool { - match self.caller { - // Root bypasses all filters - OriginCaller::system(#system_path::Origin::<#runtime>::Root) => true, - _ => (self.filter)(call), - } - } - - fn caller(&self) -> &Self::PalletsOrigin { - &self.caller - } - - fn into_caller(self) -> Self::PalletsOrigin { - self.caller - } - - fn try_with_caller( - mut self, - f: impl FnOnce(Self::PalletsOrigin) -> Result, - ) -> Result { - match f(self.caller) { - Ok(r) => Ok(r), - Err(caller) => { self.caller = caller; Err(self) } - } - } - - fn none() -> Self { - #system_path::RawOrigin::None.into() - } - - fn root() -> Self { - #system_path::RawOrigin::Root.into() - } - - fn signed(by: Self::AccountId) -> Self { - #system_path::RawOrigin::Signed(by).into() - } - } - - #[derive( - Clone, PartialEq, Eq, #scrate::__private::RuntimeDebug, #scrate::__private::codec::Encode, - #scrate::__private::codec::Decode, #scrate::__private::scale_info::TypeInfo, #scrate::__private::codec::MaxEncodedLen, - )] - #[allow(non_camel_case_types)] - pub enum OriginCaller { - #[codec(index = #system_index)] - system(#system_path::Origin<#runtime>), - #caller_variants - #[allow(dead_code)] - Void(#scrate::__private::Void) - } - - // For backwards compatibility and ease of accessing these functions. - #[allow(dead_code)] - impl RuntimeOrigin { - #[doc = #doc_string_none_origin] - pub fn none() -> Self { - ::none() - } - - #[doc = #doc_string_root_origin] - pub fn root() -> Self { - ::root() - } - - #[doc = #doc_string_signed_origin] - pub fn signed(by: <#runtime as #system_path::Config>::AccountId) -> Self { - ::signed(by) - } - } - - impl From<#system_path::Origin<#runtime>> for OriginCaller { - fn from(x: #system_path::Origin<#runtime>) -> Self { - OriginCaller::system(x) - } - } - - impl #scrate::traits::CallerTrait<<#runtime as #system_path::Config>::AccountId> for OriginCaller { - fn into_system(self) -> Option<#system_path::RawOrigin<<#runtime as #system_path::Config>::AccountId>> { - match self { - OriginCaller::system(x) => Some(x), - _ => None, - } - } - fn as_system_ref(&self) -> Option<&#system_path::RawOrigin<<#runtime as #system_path::Config>::AccountId>> { - match &self { - OriginCaller::system(o) => Some(o), - _ => None, - } - } - } - - impl TryFrom for #system_path::Origin<#runtime> { - type Error = OriginCaller; - fn try_from(x: OriginCaller) - -> core::result::Result<#system_path::Origin<#runtime>, OriginCaller> - { - if let OriginCaller::system(l) = x { - Ok(l) - } else { - Err(x) - } - } - } - - impl From<#system_path::Origin<#runtime>> for RuntimeOrigin { - - #[doc = #doc_string_runtime_origin] - fn from(x: #system_path::Origin<#runtime>) -> Self { - let o: OriginCaller = x.into(); - o.into() - } - } - - impl From for RuntimeOrigin { - fn from(x: OriginCaller) -> Self { - let mut o = RuntimeOrigin { - caller: x, - filter: #scrate::__private::Rc::new(#scrate::__private::Box::new(|_| true)), - }; - - #scrate::traits::OriginTrait::reset_filter(&mut o); - - o - } - } - - impl From for core::result::Result<#system_path::Origin<#runtime>, RuntimeOrigin> { - /// NOTE: converting to pallet origin loses the origin filter information. - fn from(val: RuntimeOrigin) -> Self { - if let OriginCaller::system(l) = val.caller { - Ok(l) - } else { - Err(val) - } - } - } - impl From::AccountId>> for RuntimeOrigin { - #[doc = #doc_string_runtime_origin_with_caller] - fn from(x: Option<<#runtime as #system_path::Config>::AccountId>) -> Self { - <#system_path::Origin<#runtime>>::from(x).into() - } - } - - #pallet_conversions - }) -} - -fn expand_origin_caller_variant( - runtime: &Ident, - pallet: &Pallet, - index: u8, - instance: Option<&Ident>, - generics: &Generics, -) -> TokenStream { - let part_is_generic = !generics.params.is_empty(); - let variant_name = &pallet.name; - let path = &pallet.path; - let attr = pallet - .cfg_pattern - .iter() - .fold(TokenStream::new(), |acc, pattern| { - let attr = TokenStream::from_str(&format!("#[cfg({})]", pattern.original())) - .expect("was successfully parsed before; qed"); - quote! { - #acc - #attr - } - }); - - match instance { - Some(inst) if part_is_generic => quote! { - #attr - #[codec(index = #index)] - #variant_name(#path::Origin<#runtime, #path::#inst>), - }, - Some(inst) => quote! { - #attr - #[codec(index = #index)] - #variant_name(#path::Origin<#path::#inst>), - }, - None if part_is_generic => quote! { - #attr - #[codec(index = #index)] - #variant_name(#path::Origin<#runtime>), - }, - None => quote! { - #attr - #[codec(index = #index)] - #variant_name(#path::Origin), - }, - } -} - -fn expand_origin_pallet_conversions( - _scrate: &TokenStream, - runtime: &Ident, - pallet: &Pallet, - instance: Option<&Ident>, - generics: &Generics, -) -> TokenStream { - let path = &pallet.path; - let variant_name = &pallet.name; - - let part_is_generic = !generics.params.is_empty(); - let pallet_origin = match instance { - Some(inst) if part_is_generic => quote!(#path::Origin<#runtime, #path::#inst>), - Some(inst) => quote!(#path::Origin<#path::#inst>), - None if part_is_generic => quote!(#path::Origin<#runtime>), - None => quote!(#path::Origin), - }; - - let doc_string = get_intra_doc_string(" Convert to runtime origin using", &path.module_name()); - let attr = pallet - .cfg_pattern - .iter() - .fold(TokenStream::new(), |acc, pattern| { - let attr = TokenStream::from_str(&format!("#[cfg({})]", pattern.original())) - .expect("was successfully parsed before; qed"); - quote! { - #acc - #attr - } - }); - - quote! { - #attr - impl From<#pallet_origin> for OriginCaller { - fn from(x: #pallet_origin) -> Self { - OriginCaller::#variant_name(x) - } - } - - #attr - impl From<#pallet_origin> for RuntimeOrigin { - #[doc = #doc_string] - fn from(x: #pallet_origin) -> Self { - let x: OriginCaller = x.into(); - x.into() - } - } - - #attr - impl From for core::result::Result<#pallet_origin, RuntimeOrigin> { - /// NOTE: converting to pallet origin loses the origin filter information. - fn from(val: RuntimeOrigin) -> Self { - if let OriginCaller::#variant_name(l) = val.caller { - Ok(l) - } else { - Err(val) - } - } - } - - #attr - impl TryFrom for #pallet_origin { - type Error = OriginCaller; - fn try_from( - x: OriginCaller, - ) -> core::result::Result<#pallet_origin, OriginCaller> { - if let OriginCaller::#variant_name(l) = x { - Ok(l) - } else { - Err(x) - } - } - } - - #attr - impl<'a> TryFrom<&'a OriginCaller> for &'a #pallet_origin { - type Error = (); - fn try_from( - x: &'a OriginCaller, - ) -> core::result::Result<&'a #pallet_origin, ()> { - if let OriginCaller::#variant_name(l) = x { - Ok(&l) - } else { - Err(()) - } - } - } - - #attr - impl<'a> TryFrom<&'a RuntimeOrigin> for &'a #pallet_origin { - type Error = (); - fn try_from( - x: &'a RuntimeOrigin, - ) -> core::result::Result<&'a #pallet_origin, ()> { - if let OriginCaller::#variant_name(l) = &x.caller { - Ok(&l) - } else { - Err(()) - } - } - } - } -} - -// Get the actual documentation using the doc information and system path name -fn get_intra_doc_string(doc_info: &str, system_path_name: &String) -> String { - format!( - " {} [`{}::Config::BaseCallFilter`].", - doc_info, system_path_name - ) -} diff --git a/support/procedural-fork/src/construct_runtime/expand/outer_enums.rs b/support/procedural-fork/src/construct_runtime/expand/outer_enums.rs deleted file mode 100644 index 3747cedea2..0000000000 --- a/support/procedural-fork/src/construct_runtime/expand/outer_enums.rs +++ /dev/null @@ -1,290 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License - -use crate::construct_runtime::Pallet; -use proc_macro2::{Span, TokenStream}; -use quote::{ToTokens, quote}; -use std::str::FromStr; -use syn::{Generics, Ident}; - -/// Represents the types supported for creating an outer enum. -#[derive(Clone, Copy, PartialEq)] -pub enum OuterEnumType { - /// Collects the Event enums from all pallets. - Event, - /// Collects the Error enums from all pallets. - Error, -} - -impl OuterEnumType { - /// The name of the structure this enum represents. - fn struct_name(&self) -> &str { - match self { - OuterEnumType::Event => "RuntimeEvent", - OuterEnumType::Error => "RuntimeError", - } - } - - /// The name of the variant (ie `Event` or `Error`). - fn variant_name(&self) -> &str { - match self { - OuterEnumType::Event => "Event", - OuterEnumType::Error => "Error", - } - } -} - -impl ToTokens for OuterEnumType { - fn to_tokens(&self, tokens: &mut TokenStream) { - match self { - OuterEnumType::Event => quote!(Event).to_tokens(tokens), - OuterEnumType::Error => quote!(Error).to_tokens(tokens), - } - } -} - -/// Create an outer enum that encapsulates all pallets as variants. -/// -/// Each variant represents a pallet and contains the corresponding type declared with either: -/// - #[pallet::event] for the [`OuterEnumType::Event`] variant -/// - #[pallet::error] for the [`OuterEnumType::Error`] variant -/// -/// The name of the outer enum is prefixed with Runtime, resulting in names like RuntimeEvent -/// or RuntimeError. -/// -/// This structure facilitates the decoding process by leveraging the metadata. -/// -/// # Example -/// -/// The code generate looks like the following for [`OuterEnumType::Event`]. -/// -/// ```ignore -/// enum RuntimeEvent { -/// #[codec(index = 0)] -/// System(pallet_system::Event), -/// -/// #[codec(index = 5)] -/// Balances(pallet_system::Event), -/// } -/// ``` -/// -/// Notice that the pallet index is preserved using the `#[codec(index = ..)]` attribute. -pub fn expand_outer_enum( - runtime: &Ident, - pallet_decls: &[Pallet], - scrate: &TokenStream, - enum_ty: OuterEnumType, -) -> syn::Result { - // Stores all pallet variants. - let mut enum_variants = TokenStream::new(); - // Generates the enum conversion between the `Runtime` outer enum and the pallet's enum. - let mut enum_conversions = TokenStream::new(); - // Specific for events to query via `is_event_part_defined!`. - let mut query_enum_part_macros = Vec::new(); - - let enum_name_str = enum_ty.variant_name(); - let enum_name_ident = Ident::new(enum_ty.struct_name(), Span::call_site()); - - for pallet_decl in pallet_decls { - let Some(pallet_entry) = pallet_decl.find_part(enum_name_str) else { - continue; - }; - - let path = &pallet_decl.path; - let pallet_name = &pallet_decl.name; - let index = pallet_decl.index; - let instance = pallet_decl.instance.as_ref(); - let generics = &pallet_entry.generics; - - if instance.is_some() && generics.params.is_empty() { - let msg = format!( - "Instantiable pallet with no generic `{}` cannot \ - be constructed: pallet `{}` must have generic `{}`", - enum_name_str, pallet_name, enum_name_str, - ); - return Err(syn::Error::new(pallet_name.span(), msg)); - } - - let part_is_generic = !generics.params.is_empty(); - let pallet_enum = match (instance, part_is_generic) { - (Some(inst), true) => quote!(#path::#enum_ty::<#runtime, #path::#inst>), - (Some(inst), false) => quote!(#path::#enum_ty::<#path::#inst>), - (None, true) => quote!(#path::#enum_ty::<#runtime>), - (None, false) => quote!(#path::#enum_ty), - }; - - enum_variants.extend(expand_enum_variant( - runtime, - pallet_decl, - index, - instance, - generics, - enum_ty, - )); - enum_conversions.extend(expand_enum_conversion( - pallet_decl, - &pallet_enum, - &enum_name_ident, - )); - - if enum_ty == OuterEnumType::Event { - query_enum_part_macros.push(quote! { - #path::__substrate_event_check::is_event_part_defined!(#pallet_name); - }); - } - } - - // Derives specific for the event. - let event_custom_derives = if enum_ty == OuterEnumType::Event { - quote!(Clone, PartialEq, Eq,) - } else { - quote!() - }; - - // Implementation specific for errors. - let error_custom_impl = generate_error_impl(scrate, enum_ty); - - Ok(quote! { - #( #query_enum_part_macros )* - - #[derive( - #event_custom_derives - #scrate::__private::codec::Encode, - #scrate::__private::codec::Decode, - #scrate::__private::scale_info::TypeInfo, - #scrate::__private::RuntimeDebug, - )] - #[allow(non_camel_case_types)] - pub enum #enum_name_ident { - #enum_variants - } - - #enum_conversions - - #error_custom_impl - }) -} - -fn expand_enum_variant( - runtime: &Ident, - pallet: &Pallet, - index: u8, - instance: Option<&Ident>, - generics: &Generics, - enum_ty: OuterEnumType, -) -> TokenStream { - let path = &pallet.path; - let variant_name = &pallet.name; - let part_is_generic = !generics.params.is_empty(); - let attr = pallet - .cfg_pattern - .iter() - .fold(TokenStream::new(), |acc, pattern| { - let attr = TokenStream::from_str(&format!("#[cfg({})]", pattern.original())) - .expect("was successfully parsed before; qed"); - quote! { - #acc - #attr - } - }); - - match instance { - Some(inst) if part_is_generic => quote! { - #attr - #[codec(index = #index)] - #variant_name(#path::#enum_ty<#runtime, #path::#inst>), - }, - Some(inst) => quote! { - #attr - #[codec(index = #index)] - #variant_name(#path::#enum_ty<#path::#inst>), - }, - None if part_is_generic => quote! { - #attr - #[codec(index = #index)] - #variant_name(#path::#enum_ty<#runtime>), - }, - None => quote! { - #attr - #[codec(index = #index)] - #variant_name(#path::#enum_ty), - }, - } -} - -fn expand_enum_conversion( - pallet: &Pallet, - pallet_enum: &TokenStream, - enum_name_ident: &Ident, -) -> TokenStream { - let variant_name = &pallet.name; - let attr = pallet - .cfg_pattern - .iter() - .fold(TokenStream::new(), |acc, pattern| { - let attr = TokenStream::from_str(&format!("#[cfg({})]", pattern.original())) - .expect("was successfully parsed before; qed"); - quote! { - #acc - #attr - } - }); - - quote! { - #attr - impl From<#pallet_enum> for #enum_name_ident { - fn from(x: #pallet_enum) -> Self { - #enum_name_ident - ::#variant_name(x) - } - } - #attr - impl TryInto<#pallet_enum> for #enum_name_ident { - type Error = (); - - fn try_into(self) -> ::core::result::Result<#pallet_enum, Self::Error> { - match self { - Self::#variant_name(evt) => Ok(evt), - _ => Err(()), - } - } - } - } -} - -fn generate_error_impl(scrate: &TokenStream, enum_ty: OuterEnumType) -> TokenStream { - // Implementation is specific to `Error`s. - if enum_ty == OuterEnumType::Event { - return quote! {}; - } - - let enum_name_ident = Ident::new(enum_ty.struct_name(), Span::call_site()); - - quote! { - impl #enum_name_ident { - /// Optionally convert the `DispatchError` into the `RuntimeError`. - /// - /// Returns `Some` if the error matches the `DispatchError::Module` variant, otherwise `None`. - pub fn from_dispatch_error(err: #scrate::sp_runtime::DispatchError) -> Option { - let #scrate::sp_runtime::DispatchError::Module(module_error) = err else { return None }; - - let bytes = #scrate::__private::codec::Encode::encode(&module_error); - #scrate::__private::codec::Decode::decode(&mut &bytes[..]).ok() - } - } - } -} diff --git a/support/procedural-fork/src/construct_runtime/expand/slash_reason.rs b/support/procedural-fork/src/construct_runtime/expand/slash_reason.rs deleted file mode 100644 index 0695d81020..0000000000 --- a/support/procedural-fork/src/construct_runtime/expand/slash_reason.rs +++ /dev/null @@ -1,64 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License - -use super::composite_helper; -use crate::construct_runtime::Pallet; -use proc_macro2::TokenStream; -use quote::quote; - -pub fn expand_outer_slash_reason(pallet_decls: &[Pallet], scrate: &TokenStream) -> TokenStream { - let mut conversion_fns = Vec::new(); - let mut slash_reason_variants = Vec::new(); - for decl in pallet_decls { - if let Some(_) = decl.find_part("SlashReason") { - let variant_name = &decl.name; - let path = &decl.path; - let index = decl.index; - let instance = decl.instance.as_ref(); - - conversion_fns.push(composite_helper::expand_conversion_fn( - "SlashReason", - path, - instance, - variant_name, - )); - - slash_reason_variants.push(composite_helper::expand_variant( - "SlashReason", - index, - path, - instance, - variant_name, - )); - } - } - - quote! { - /// A reason for slashing funds. - #[derive( - Copy, Clone, Eq, PartialEq, - #scrate::__private::codec::Encode, #scrate::__private::codec::Decode, #scrate::__private::codec::MaxEncodedLen, - #scrate::__private::scale_info::TypeInfo, - #scrate::__private::RuntimeDebug, - )] - pub enum RuntimeSlashReason { - #( #slash_reason_variants )* - } - - #( #conversion_fns )* - } -} diff --git a/support/procedural-fork/src/construct_runtime/expand/task.rs b/support/procedural-fork/src/construct_runtime/expand/task.rs deleted file mode 100644 index 94a5f52bb3..0000000000 --- a/support/procedural-fork/src/construct_runtime/expand/task.rs +++ /dev/null @@ -1,131 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License - -use crate::construct_runtime::Pallet; -use proc_macro2::{Ident, TokenStream as TokenStream2}; -use quote::quote; - -/// Expands aggregate `RuntimeTask` enum. -pub fn expand_outer_task( - runtime_name: &Ident, - pallet_decls: &[Pallet], - scrate: &TokenStream2, -) -> TokenStream2 { - let mut from_impls = Vec::new(); - let mut task_variants = Vec::new(); - let mut variant_names = Vec::new(); - let mut task_paths = Vec::new(); - for decl in pallet_decls { - if decl.find_part("Task").is_none() { - continue; - } - - let variant_name = &decl.name; - let path = &decl.path; - let index = decl.index; - - from_impls.push(quote! { - impl From<#path::Task<#runtime_name>> for RuntimeTask { - fn from(hr: #path::Task<#runtime_name>) -> Self { - RuntimeTask::#variant_name(hr) - } - } - - impl TryInto<#path::Task<#runtime_name>> for RuntimeTask { - type Error = (); - - fn try_into(self) -> Result<#path::Task<#runtime_name>, Self::Error> { - match self { - RuntimeTask::#variant_name(hr) => Ok(hr), - _ => Err(()), - } - } - } - }); - - task_variants.push(quote! { - #[codec(index = #index)] - #variant_name(#path::Task<#runtime_name>), - }); - - variant_names.push(quote!(#variant_name)); - - task_paths.push(quote!(#path::Task)); - } - - let prelude = quote!(#scrate::traits::tasks::__private); - - const INCOMPLETE_MATCH_QED: &'static str = - "cannot have an instantiated RuntimeTask without some Task variant in the runtime. QED"; - - let output = quote! { - /// An aggregation of all `Task` enums across all pallets included in the current runtime. - #[derive( - Clone, Eq, PartialEq, - #scrate::__private::codec::Encode, - #scrate::__private::codec::Decode, - #scrate::__private::scale_info::TypeInfo, - #scrate::__private::RuntimeDebug, - )] - pub enum RuntimeTask { - #( #task_variants )* - } - - #[automatically_derived] - impl #scrate::traits::Task for RuntimeTask { - type Enumeration = #prelude::IntoIter; - - fn is_valid(&self) -> bool { - match self { - #(RuntimeTask::#variant_names(val) => val.is_valid(),)* - _ => unreachable!(#INCOMPLETE_MATCH_QED), - } - } - - fn run(&self) -> Result<(), #scrate::traits::tasks::__private::DispatchError> { - match self { - #(RuntimeTask::#variant_names(val) => val.run(),)* - _ => unreachable!(#INCOMPLETE_MATCH_QED), - } - } - - fn weight(&self) -> #scrate::pallet_prelude::Weight { - match self { - #(RuntimeTask::#variant_names(val) => val.weight(),)* - _ => unreachable!(#INCOMPLETE_MATCH_QED), - } - } - - fn task_index(&self) -> u32 { - match self { - #(RuntimeTask::#variant_names(val) => val.task_index(),)* - _ => unreachable!(#INCOMPLETE_MATCH_QED), - } - } - - fn iter() -> Self::Enumeration { - let mut all_tasks = Vec::new(); - #(all_tasks.extend(#task_paths::iter().map(RuntimeTask::from).collect::>());)* - all_tasks.into_iter() - } - } - - #( #from_impls )* - }; - - output -} diff --git a/support/procedural-fork/src/construct_runtime/expand/unsigned.rs b/support/procedural-fork/src/construct_runtime/expand/unsigned.rs deleted file mode 100644 index 109f7081c1..0000000000 --- a/support/procedural-fork/src/construct_runtime/expand/unsigned.rs +++ /dev/null @@ -1,92 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License - -use crate::construct_runtime::Pallet; -use proc_macro2::TokenStream; -use quote::quote; -use std::str::FromStr; -use syn::Ident; - -pub fn expand_outer_validate_unsigned( - runtime: &Ident, - pallet_decls: &[Pallet], - scrate: &TokenStream, -) -> TokenStream { - let mut pallet_names = Vec::new(); - let mut pallet_attrs = Vec::new(); - let mut query_validate_unsigned_part_macros = Vec::new(); - - for pallet_decl in pallet_decls { - if pallet_decl.exists_part("ValidateUnsigned") { - let name = &pallet_decl.name; - let path = &pallet_decl.path; - let attr = pallet_decl - .cfg_pattern - .iter() - .fold(TokenStream::new(), |acc, pattern| { - let attr = TokenStream::from_str(&format!("#[cfg({})]", pattern.original())) - .expect("was successfully parsed before; qed"); - quote! { - #acc - #attr - } - }); - - pallet_names.push(name); - pallet_attrs.push(attr); - query_validate_unsigned_part_macros.push(quote! { - #path::__substrate_validate_unsigned_check::is_validate_unsigned_part_defined!(#name); - }); - } - } - - quote! { - #( #query_validate_unsigned_part_macros )* - - impl #scrate::unsigned::ValidateUnsigned for #runtime { - type Call = RuntimeCall; - - fn pre_dispatch(call: &Self::Call) -> Result<(), #scrate::unsigned::TransactionValidityError> { - #[allow(unreachable_patterns)] - match call { - #( - #pallet_attrs - RuntimeCall::#pallet_names(inner_call) => #pallet_names::pre_dispatch(inner_call), - )* - // pre-dispatch should not stop inherent extrinsics, validation should prevent - // including arbitrary (non-inherent) extrinsics to blocks. - _ => Ok(()), - } - } - - fn validate_unsigned( - #[allow(unused_variables)] - source: #scrate::unsigned::TransactionSource, - call: &Self::Call, - ) -> #scrate::unsigned::TransactionValidity { - #[allow(unreachable_patterns)] - match call { - #( - #pallet_attrs - RuntimeCall::#pallet_names(inner_call) => #pallet_names::validate_unsigned(source, inner_call), - )* - _ => #scrate::unsigned::UnknownTransaction::NoUnsignedValidator.into(), - } - } - } - } -} diff --git a/support/procedural-fork/src/construct_runtime/mod.rs b/support/procedural-fork/src/construct_runtime/mod.rs deleted file mode 100644 index cf39972461..0000000000 --- a/support/procedural-fork/src/construct_runtime/mod.rs +++ /dev/null @@ -1,847 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//! Implementation of `construct_runtime`. -//! -//! `construct_runtime` implementation is recursive and can generate code which will call itself in -//! order to get all the pallet parts for each pallet. -//! -//! Pallets can define their parts: -//! - Implicitly: `System: frame_system` -//! - Explicitly: `System: frame_system::{Pallet, Call}` -//! -//! The `construct_runtime` transitions from the implicit definition to the explicit one. -//! From the explicit state, Substrate expands the pallets with additional information -//! that is to be included in the runtime metadata. This expansion makes visible some extra -//! parts of the pallets, mainly the `Error` if defined. The expanded state looks like -//! `System: frame_system expanded::{Error} ::{Pallet, Call}` and concatenates the extra expanded -//! parts with the user-provided parts. For example, the `Pallet`, `Call` and `Error` parts are -//! collected. -//! -//! Pallets must provide the `tt_extra_parts` and `tt_default_parts` macros for these transitions. -//! These are automatically implemented by the `#[pallet::pallet]` macro. -//! -//! This macro also generates the following enums for ease of decoding: -//! - `enum RuntimeCall`: This type contains the information needed to decode extrinsics. -//! - `enum RuntimeEvent`: This type contains the information needed to decode events. -//! - `enum RuntimeError`: While this cannot be used directly to decode `sp_runtime::DispatchError` -//! from the chain, it contains the information needed to decode the -//! `sp_runtime::DispatchError::Module`. -//! -//! # State Transitions -//! -//! ```ignore -//! +----------+ -//! | Implicit | -----------+ -//! +----------+ | -//! | | -//! v v -//! +----------+ +------------------+ -//! | Explicit | --> | ExplicitExpanded | -//! +----------+ +------------------+ -//! ``` -//! -//! When all pallet parts are implicit, then the `construct_runtime!` macro expands to its final -//! state, the `ExplicitExpanded`. Otherwise, all implicit parts are converted to an explicit -//! expanded part allow the `construct_runtime!` to expand any remaining explicit parts to an -//! explicit expanded part. -//! -//! # Implicit to Explicit -//! -//! The `construct_runtime` macro transforms the implicit declaration of each pallet -//! `System: frame_system` to an explicit one `System: frame_system::{Pallet, Call}` using the -//! `tt_default_parts` macro. -//! -//! The `tt_default_parts` macro exposes a comma separated list of pallet parts. For example, the -//! `Event` part is exposed only if the pallet implements an event via `#[pallet::event]` macro. -//! The tokens generated by this macro are ` expanded :: { Pallet, Call }` for our example. -//! -//! The `match_and_insert` macro takes in 3 arguments: -//! - target: This is the `TokenStream` that contains the `construct_runtime!` macro. -//! - pattern: The pattern to match against in the target stream. -//! - tokens: The tokens to added after the pattern match. -//! -//! The `construct_runtime` macro uses the `tt_call` to get the default pallet parts via -//! the `tt_default_parts` macro defined by each pallet. The pallet parts are then returned as -//! input to the `match_and_replace` macro. -//! The `match_and_replace` then will modify the the `construct_runtime!` to expand the implicit -//! definition to the explicit one. -//! -//! For example, -//! -//! ```ignore -//! construct_runtime!( -//! //... -//! { -//! System: frame_system = 0, // Implicit definition of parts -//! Balances: pallet_balances = 1, // Implicit definition of parts -//! } -//! ); -//! ``` -//! This call has some implicit pallet parts, thus it will expand to: -//! ```ignore -//! frame_support::__private::tt_call! { -//! macro = [{ pallet_balances::tt_default_parts }] -//! ~~> frame_support::match_and_insert! { -//! target = [{ -//! frame_support::__private::tt_call! { -//! macro = [{ frame_system::tt_default_parts }] -//! ~~> frame_support::match_and_insert! { -//! target = [{ -//! construct_runtime!( -//! //... -//! { -//! System: frame_system = 0, -//! Balances: pallet_balances = 1, -//! } -//! ); -//! }] -//! pattern = [{ System: frame_system }] -//! } -//! } -//! }] -//! pattern = [{ Balances: pallet_balances }] -//! } -//! } -//! ``` -//! `tt_default_parts` must be defined. It returns the pallet parts inside some tokens, and -//! then `tt_call` will pipe the returned pallet parts into the input of `match_and_insert`. -//! Thus `match_and_insert` will initially receive the following inputs: -//! ```ignore -//! frame_support::match_and_insert! { -//! target = [{ -//! frame_support::match_and_insert! { -//! target = [{ -//! construct_runtime!( -//! //... -//! { -//! System: frame_system = 0, -//! Balances: pallet_balances = 1, -//! } -//! ) -//! }] -//! pattern = [{ System: frame_system }] -//! tokens = [{ ::{Pallet, Call} }] -//! } -//! }] -//! pattern = [{ Balances: pallet_balances }] -//! tokens = [{ ::{Pallet, Call} }] -//! } -//! ``` -//! After dealing with `pallet_balances`, the inner `match_and_insert` will expand to: -//! ```ignore -//! frame_support::match_and_insert! { -//! target = [{ -//! construct_runtime!( -//! //... -//! { -//! System: frame_system = 0, // Implicit definition of parts -//! Balances: pallet_balances::{Pallet, Call} = 1, // Explicit definition of parts -//! } -//! ) -//! }] -//! pattern = [{ System: frame_system }] -//! tokens = [{ ::{Pallet, Call} }] -//! } -//! ``` -//! -//! Which will then finally expand to the following: -//! ```ignore -//! construct_runtime!( -//! //... -//! { -//! System: frame_system::{Pallet, Call}, -//! Balances: pallet_balances::{Pallet, Call}, -//! } -//! ) -//! ``` -//! -//! This call has no implicit pallet parts, thus it will expand to the runtime construction: -//! ```ignore -//! pub enum Runtime { ... } -//! pub struct Call { ... } -//! impl Call ... -//! pub enum Origin { ... } -//! ... -//! ``` -//! -//! Visualizing the entire flow of `construct_runtime!`, it would look like the following: -//! -//! ```ignore -//! +--------------------+ +---------------------+ +-------------------+ -//! | | | (defined in pallet) | | | -//! | construct_runtime! | --> | tt_default_parts! | --> | match_and_insert! | -//! | w/ no pallet parts | | | | | -//! +--------------------+ +---------------------+ +-------------------+ -//! -//! +--------------------+ -//! | | -//! --> | construct_runtime! | -//! | w/ pallet parts | -//! +--------------------+ -//! ``` -//! -//! # Explicit to Explicit Expanded -//! -//! Users normally do not care about this transition. -//! -//! Similarly to the previous transition, the macro expansion transforms `System: -//! frame_system::{Pallet, Call}` into `System: frame_system expanded::{Error} ::{Pallet, Call}`. -//! The `expanded` section adds extra parts that the Substrate would like to expose for each pallet -//! by default. This is done to expose the appropriate types for metadata construction. -//! -//! This time, instead of calling `tt_default_parts` we are using the `tt_extra_parts` macro. -//! This macro returns the ` :: expanded { Error }` list of additional parts we would like to -//! expose. - -pub(crate) mod expand; -pub(crate) mod parse; - -use crate::pallet::parse::helper::two128_str; -use cfg_expr::Predicate; -use frame_support_procedural_tools::{ - generate_access_from_frame_or_crate, generate_crate_access, generate_hidden_includes, -}; -use itertools::Itertools; -use parse::{ExplicitRuntimeDeclaration, ImplicitRuntimeDeclaration, Pallet, RuntimeDeclaration}; -use proc_macro::TokenStream; -use proc_macro2::TokenStream as TokenStream2; -use quote::quote; -use std::{collections::HashSet, str::FromStr}; -use syn::{Ident, Result, spanned::Spanned}; - -/// The fixed name of the system pallet. -const SYSTEM_PALLET_NAME: &str = "System"; - -/// Implementation of `construct_runtime` macro. Either expand to some code which will call -/// `construct_runtime` again, or expand to the final runtime definition. -pub fn construct_runtime(input: TokenStream) -> TokenStream { - let input_copy = input.clone(); - let definition = syn::parse_macro_input!(input as RuntimeDeclaration); - - let (check_pallet_number_res, res) = match definition { - RuntimeDeclaration::Implicit(implicit_def) => ( - check_pallet_number(input_copy.clone().into(), implicit_def.pallets.len()), - construct_runtime_implicit_to_explicit(input_copy.into(), implicit_def), - ), - RuntimeDeclaration::Explicit(explicit_decl) => ( - check_pallet_number(input_copy.clone().into(), explicit_decl.pallets.len()), - construct_runtime_explicit_to_explicit_expanded(input_copy.into(), explicit_decl), - ), - RuntimeDeclaration::ExplicitExpanded(explicit_decl) => ( - check_pallet_number(input_copy.into(), explicit_decl.pallets.len()), - construct_runtime_final_expansion(explicit_decl), - ), - }; - - let res = res.unwrap_or_else(|e| e.to_compile_error()); - - // We want to provide better error messages to the user and thus, handle the error here - // separately. If there is an error, we print the error and still generate all of the code to - // get in overall less errors for the user. - let res = if let Err(error) = check_pallet_number_res { - let error = error.to_compile_error(); - - quote! { - #error - - #res - } - } else { - res - }; - - let res = expander::Expander::new("construct_runtime") - .dry(std::env::var("EXPAND_MACROS").is_err()) - .verbose(true) - .write_to_out_dir(res) - .expect("Does not fail because of IO in OUT_DIR; qed"); - - res.into() -} - -/// All pallets that have implicit pallet parts (ie `System: frame_system`) are -/// expanded with the default parts defined by the pallet's `tt_default_parts` macro. -/// -/// This function transforms the [`RuntimeDeclaration::Implicit`] into -/// [`RuntimeDeclaration::Explicit`] that is not yet fully expanded. -/// -/// For more details, please refer to the root documentation. -fn construct_runtime_implicit_to_explicit( - input: TokenStream2, - definition: ImplicitRuntimeDeclaration, -) -> Result { - let frame_support = generate_access_from_frame_or_crate("frame-support")?; - let mut expansion = quote::quote!( - #frame_support::construct_runtime! { #input } - ); - for pallet in definition - .pallets - .iter() - .filter(|pallet| pallet.pallet_parts.is_none()) - { - let pallet_path = &pallet.path; - let pallet_name = &pallet.name; - let pallet_instance = pallet - .instance - .as_ref() - .map(|instance| quote::quote!(::<#instance>)); - expansion = quote::quote!( - #frame_support::__private::tt_call! { - macro = [{ #pallet_path::tt_default_parts }] - your_tt_return = [{ #frame_support::__private::tt_return }] - ~~> #frame_support::match_and_insert! { - target = [{ #expansion }] - pattern = [{ #pallet_name: #pallet_path #pallet_instance }] - } - } - ); - } - - Ok(expansion) -} - -/// All pallets that have -/// (I): explicit pallet parts (ie `System: frame_system::{Pallet, Call}`) and -/// (II): are not fully expanded (ie do not include the `Error` expansion part) -/// are fully expanded by including the parts from the pallet's `tt_extra_parts` macro. -/// -/// This function transforms the [`RuntimeDeclaration::Explicit`] that is not yet fully expanded -/// into [`RuntimeDeclaration::ExplicitExpanded`] fully expanded. -/// -/// For more details, please refer to the root documentation. -fn construct_runtime_explicit_to_explicit_expanded( - input: TokenStream2, - definition: ExplicitRuntimeDeclaration, -) -> Result { - let frame_support = generate_access_from_frame_or_crate("frame-support")?; - let mut expansion = quote::quote!( - #frame_support::construct_runtime! { #input } - ); - for pallet in definition - .pallets - .iter() - .filter(|pallet| !pallet.is_expanded) - { - let pallet_path = &pallet.path; - let pallet_name = &pallet.name; - let pallet_instance = pallet - .instance - .as_ref() - .map(|instance| quote::quote!(::<#instance>)); - expansion = quote::quote!( - #frame_support::__private::tt_call! { - macro = [{ #pallet_path::tt_extra_parts }] - your_tt_return = [{ #frame_support::__private::tt_return }] - ~~> #frame_support::match_and_insert! { - target = [{ #expansion }] - pattern = [{ #pallet_name: #pallet_path #pallet_instance }] - } - } - ); - } - - Ok(expansion) -} - -/// All pallets have explicit definition of parts, this will expand to the runtime declaration. -fn construct_runtime_final_expansion( - definition: ExplicitRuntimeDeclaration, -) -> Result { - let ExplicitRuntimeDeclaration { - name, - pallets, - pallets_token, - where_section, - } = definition; - - let system_pallet = pallets - .iter() - .find(|decl| decl.name == SYSTEM_PALLET_NAME) - .ok_or_else(|| { - syn::Error::new( - pallets_token.span.join(), - "`System` pallet declaration is missing. \ - Please add this line: `System: frame_system,`", - ) - })?; - if !system_pallet.cfg_pattern.is_empty() { - return Err(syn::Error::new( - system_pallet.name.span(), - "`System` pallet declaration is feature gated, please remove any `#[cfg]` attributes", - )); - } - - let features = pallets - .iter() - .filter_map(|decl| { - (!decl.cfg_pattern.is_empty()).then(|| { - decl.cfg_pattern.iter().flat_map(|attr| { - attr.predicates().filter_map(|pred| match pred { - Predicate::Feature(feat) => Some(feat), - Predicate::Test => Some("test"), - _ => None, - }) - }) - }) - }) - .flatten() - .collect::>(); - - let hidden_crate_name = "construct_runtime"; - let scrate = generate_crate_access(hidden_crate_name, "frame-support"); - let scrate_decl = generate_hidden_includes(hidden_crate_name, "frame-support"); - - let frame_system = generate_access_from_frame_or_crate("frame-system")?; - let block = quote!(<#name as #frame_system::Config>::Block); - let unchecked_extrinsic = quote!(<#block as #scrate::sp_runtime::traits::Block>::Extrinsic); - - let outer_event = - expand::expand_outer_enum(&name, &pallets, &scrate, expand::OuterEnumType::Event)?; - let outer_error = - expand::expand_outer_enum(&name, &pallets, &scrate, expand::OuterEnumType::Error)?; - - let outer_origin = expand::expand_outer_origin(&name, system_pallet, &pallets, &scrate)?; - let all_pallets = decl_all_pallets(&name, pallets.iter(), &features); - let pallet_to_index = decl_pallet_runtime_setup(&name, &pallets, &scrate); - - let dispatch = expand::expand_outer_dispatch(&name, system_pallet, &pallets, &scrate); - let tasks = expand::expand_outer_task(&name, &pallets, &scrate); - let metadata = expand::expand_runtime_metadata( - &name, - &pallets, - &scrate, - &unchecked_extrinsic, - &system_pallet.path, - ); - let outer_config = expand::expand_outer_config(&name, &pallets, &scrate); - let inherent = - expand::expand_outer_inherent(&name, &block, &unchecked_extrinsic, &pallets, &scrate); - let validate_unsigned = expand::expand_outer_validate_unsigned(&name, &pallets, &scrate); - let freeze_reason = expand::expand_outer_freeze_reason(&pallets, &scrate); - let hold_reason = expand::expand_outer_hold_reason(&pallets, &scrate); - let lock_id = expand::expand_outer_lock_id(&pallets, &scrate); - let slash_reason = expand::expand_outer_slash_reason(&pallets, &scrate); - let integrity_test = decl_integrity_test(&scrate); - let static_assertions = decl_static_assertions(&name, &pallets, &scrate); - - let warning = where_section.map_or(None, |where_section| { - Some( - proc_macro_warning::Warning::new_deprecated("WhereSection") - .old("use a `where` clause in `construct_runtime`") - .new( - "use `frame_system::Config` to set the `Block` type and delete this clause. - It is planned to be removed in December 2023", - ) - .help_links(&["https://github.com/paritytech/substrate/pull/14437"]) - .span(where_section.span) - .build_or_panic(), - ) - }); - - let res = quote!( - #warning - - #scrate_decl - - // Prevent UncheckedExtrinsic to print unused warning. - const _: () = { - #[allow(unused)] - type __hidden_use_of_unchecked_extrinsic = #unchecked_extrinsic; - }; - - #[derive( - Clone, Copy, PartialEq, Eq, #scrate::sp_runtime::RuntimeDebug, - #scrate::__private::scale_info::TypeInfo - )] - pub struct #name; - impl #scrate::sp_runtime::traits::GetRuntimeBlockType for #name { - type RuntimeBlock = #block; - } - - // Each runtime must expose the `runtime_metadata()` to fetch the runtime API metadata. - // The function is implemented by calling `impl_runtime_apis!`. - // - // However, the `construct_runtime!` may be called without calling `impl_runtime_apis!`. - // Rely on the `Deref` trait to differentiate between a runtime that implements - // APIs (by macro impl_runtime_apis!) and a runtime that is simply created (by macro construct_runtime!). - // - // Both `InternalConstructRuntime` and `InternalImplRuntimeApis` expose a `runtime_metadata()` function. - // `InternalConstructRuntime` is implemented by the `construct_runtime!` for Runtime references (`& Runtime`), - // while `InternalImplRuntimeApis` is implemented by the `impl_runtime_apis!` for Runtime (`Runtime`). - // - // Therefore, the `Deref` trait will resolve the `runtime_metadata` from `impl_runtime_apis!` - // when both macros are called; and will resolve an empty `runtime_metadata` when only the `construct_runtime!` - // is called. - - #[doc(hidden)] - trait InternalConstructRuntime { - #[inline(always)] - fn runtime_metadata(&self) -> #scrate::__private::Vec<#scrate::__private::metadata_ir::RuntimeApiMetadataIR> { - Default::default() - } - } - #[doc(hidden)] - impl InternalConstructRuntime for &#name {} - - #outer_event - - #outer_error - - #outer_origin - - #all_pallets - - #pallet_to_index - - #dispatch - - #tasks - - #metadata - - #outer_config - - #inherent - - #validate_unsigned - - #freeze_reason - - #hold_reason - - #lock_id - - #slash_reason - - #integrity_test - - #static_assertions - ); - - Ok(res) -} - -pub(crate) fn decl_all_pallets<'a>( - runtime: &'a Ident, - pallet_declarations: impl Iterator, - features: &HashSet<&str>, -) -> TokenStream2 { - let mut types = TokenStream2::new(); - - // Every feature set to the pallet names that should be included by this feature set. - let mut features_to_names = features - .iter() - .map(|f| *f) - .powerset() - .map(|feat| (HashSet::from_iter(feat), Vec::new())) - .collect::, Vec<_>)>>(); - - for pallet_declaration in pallet_declarations { - let type_name = &pallet_declaration.name; - let pallet = &pallet_declaration.path; - let docs = &pallet_declaration.docs; - let mut generics = vec![quote!(#runtime)]; - generics.extend( - pallet_declaration - .instance - .iter() - .map(|name| quote!(#pallet::#name)), - ); - let mut attrs = Vec::new(); - for cfg in &pallet_declaration.cfg_pattern { - let feat = format!("#[cfg({})]\n", cfg.original()); - attrs.extend(TokenStream2::from_str(&feat).expect("was parsed successfully; qed")); - } - let type_decl = quote!( - #( #[doc = #docs] )* - #(#attrs)* - pub type #type_name = #pallet::Pallet <#(#generics),*>; - ); - types.extend(type_decl); - - if pallet_declaration.cfg_pattern.is_empty() { - for (_, names) in features_to_names.iter_mut() { - names.push(&pallet_declaration.name); - } - } else { - for (feature_set, names) in &mut features_to_names { - // Rust tidbit: if we have multiple `#[cfg]` feature on the same item, then the - // predicates listed in all `#[cfg]` attributes are effectively joined by `and()`, - // meaning that all of them must match in order to activate the item - let is_feature_active = pallet_declaration.cfg_pattern.iter().all(|expr| { - expr.eval(|pred| match pred { - Predicate::Feature(f) => feature_set.contains(f), - Predicate::Test => feature_set.contains(&"test"), - _ => false, - }) - }); - - if is_feature_active { - names.push(&pallet_declaration.name); - } - } - } - } - - // All possible features. This will be used below for the empty feature set. - let mut all_features = features_to_names - .iter() - .flat_map(|f| f.0.iter().cloned()) - .collect::>(); - let attribute_to_names = features_to_names - .into_iter() - .map(|(mut features, names)| { - // If this is the empty feature set, it needs to be changed to negate all available - // features. So, we ensure that there is some type declared when all features are not - // enabled. - if features.is_empty() { - let test_cfg = all_features.remove("test").then_some(quote!(test)).into_iter(); - let features = all_features.iter(); - let attr = quote!(#[cfg(all( #(not(#test_cfg)),* #(not(feature = #features)),* ))]); - - (attr, names) - } else { - let test_cfg = features.remove("test").then_some(quote!(test)).into_iter(); - let disabled_features = all_features.difference(&features); - let features = features.iter(); - let attr = quote!(#[cfg(all( #(#test_cfg,)* #(feature = #features,)* #(not(feature = #disabled_features)),* ))]); - - (attr, names) - } - }) - .collect::>(); - - let all_pallets_without_system = attribute_to_names.iter().map(|(attr, names)| { - let names = names.iter().filter(|n| **n != SYSTEM_PALLET_NAME); - quote! { - #attr - /// All pallets included in the runtime as a nested tuple of types. - /// Excludes the System pallet. - pub type AllPalletsWithoutSystem = ( #(#names,)* ); - } - }); - - let all_pallets_with_system = attribute_to_names.iter().map(|(attr, names)| { - quote! { - #attr - /// All pallets included in the runtime as a nested tuple of types. - pub type AllPalletsWithSystem = ( #(#names,)* ); - } - }); - - quote!( - #types - - #( #all_pallets_with_system )* - - #( #all_pallets_without_system )* - ) -} - -pub(crate) fn decl_pallet_runtime_setup( - runtime: &Ident, - pallet_declarations: &[Pallet], - scrate: &TokenStream2, -) -> TokenStream2 { - let names = pallet_declarations - .iter() - .map(|d| &d.name) - .collect::>(); - let name_strings = pallet_declarations.iter().map(|d| d.name.to_string()); - let name_hashes = pallet_declarations - .iter() - .map(|d| two128_str(&d.name.to_string())); - let module_names = pallet_declarations.iter().map(|d| d.path.module_name()); - let indices = pallet_declarations - .iter() - .map(|pallet| pallet.index as usize); - let pallet_structs = pallet_declarations - .iter() - .map(|pallet| { - let path = &pallet.path; - match pallet.instance.as_ref() { - Some(inst) => quote!(#path::Pallet<#runtime, #path::#inst>), - None => quote!(#path::Pallet<#runtime>), - } - }) - .collect::>(); - let pallet_attrs = pallet_declarations - .iter() - .map(|pallet| { - pallet - .cfg_pattern - .iter() - .fold(TokenStream2::new(), |acc, pattern| { - let attr = TokenStream2::from_str(&format!("#[cfg({})]", pattern.original())) - .expect("was successfully parsed before; qed"); - quote! { - #acc - #attr - } - }) - }) - .collect::>(); - - quote!( - /// Provides an implementation of `PalletInfo` to provide information - /// about the pallet setup in the runtime. - pub struct PalletInfo; - - impl #scrate::traits::PalletInfo for PalletInfo { - - fn index() -> Option { - let type_id = core::any::TypeId::of::

(); - #( - #pallet_attrs - if type_id == core::any::TypeId::of::<#names>() { - return Some(#indices) - } - )* - - None - } - - fn name() -> Option<&'static str> { - let type_id = core::any::TypeId::of::

(); - #( - #pallet_attrs - if type_id == core::any::TypeId::of::<#names>() { - return Some(#name_strings) - } - )* - - None - } - - fn name_hash() -> Option<[u8; 16]> { - let type_id = core::any::TypeId::of::

(); - #( - #pallet_attrs - if type_id == core::any::TypeId::of::<#names>() { - return Some(#name_hashes) - } - )* - - None - } - - fn module_name() -> Option<&'static str> { - let type_id = core::any::TypeId::of::

(); - #( - #pallet_attrs - if type_id == core::any::TypeId::of::<#names>() { - return Some(#module_names) - } - )* - - None - } - - fn crate_version() -> Option<#scrate::traits::CrateVersion> { - let type_id = core::any::TypeId::of::

(); - #( - #pallet_attrs - if type_id == core::any::TypeId::of::<#names>() { - return Some( - <#pallet_structs as #scrate::traits::PalletInfoAccess>::crate_version() - ) - } - )* - - None - } - } - ) -} - -pub(crate) fn decl_integrity_test(scrate: &TokenStream2) -> TokenStream2 { - quote!( - #[cfg(test)] - mod __construct_runtime_integrity_test { - use super::*; - - #[test] - pub fn runtime_integrity_tests() { - #scrate::__private::sp_tracing::try_init_simple(); - ::integrity_test(); - } - } - ) -} - -pub(crate) fn decl_static_assertions( - runtime: &Ident, - pallet_decls: &[Pallet], - scrate: &TokenStream2, -) -> TokenStream2 { - let error_encoded_size_check = pallet_decls.iter().map(|decl| { - let path = &decl.path; - let assert_message = format!( - "The maximum encoded size of the error type in the `{}` pallet exceeds \ - `MAX_MODULE_ERROR_ENCODED_SIZE`", - decl.name, - ); - - quote! { - #scrate::__private::tt_call! { - macro = [{ #path::tt_error_token }] - your_tt_return = [{ #scrate::__private::tt_return }] - ~~> #scrate::assert_error_encoded_size! { - path = [{ #path }] - runtime = [{ #runtime }] - assert_message = [{ #assert_message }] - } - } - } - }); - - quote! { - #(#error_encoded_size_check)* - } -} - -pub(crate) fn check_pallet_number(input: TokenStream2, pallet_num: usize) -> Result<()> { - let max_pallet_num = { - if cfg!(feature = "tuples-96") { - 96 - } else if cfg!(feature = "tuples-128") { - 128 - } else { - 64 - } - }; - - if pallet_num > max_pallet_num { - let no_feature = max_pallet_num == 128; - return Err(syn::Error::new( - input.span(), - format!( - "{} To increase this limit, enable the tuples-{} feature of [frame_support]. {}", - "The number of pallets exceeds the maximum number of tuple elements.", - max_pallet_num + 32, - if no_feature { - "If the feature does not exist - it needs to be implemented." - } else { - "" - }, - ), - )); - } - - Ok(()) -} diff --git a/support/procedural-fork/src/construct_runtime/parse.rs b/support/procedural-fork/src/construct_runtime/parse.rs deleted file mode 100644 index d2b2a4e4f6..0000000000 --- a/support/procedural-fork/src/construct_runtime/parse.rs +++ /dev/null @@ -1,823 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use frame_support_procedural_tools::syn_ext as ext; -use proc_macro2::{Span, TokenStream}; -use quote::ToTokens; -use std::collections::{HashMap, HashSet}; -use syn::{ - Attribute, Error, Ident, Path, Result, Token, - ext::IdentExt, - parse::{Parse, ParseStream}, - punctuated::Punctuated, - spanned::Spanned, - token, -}; - -mod keyword { - syn::custom_keyword!(Block); - syn::custom_keyword!(NodeBlock); - syn::custom_keyword!(UncheckedExtrinsic); - syn::custom_keyword!(Pallet); - syn::custom_keyword!(Call); - syn::custom_keyword!(Storage); - syn::custom_keyword!(Event); - syn::custom_keyword!(Error); - syn::custom_keyword!(Config); - syn::custom_keyword!(Origin); - syn::custom_keyword!(Inherent); - syn::custom_keyword!(ValidateUnsigned); - syn::custom_keyword!(FreezeReason); - syn::custom_keyword!(HoldReason); - syn::custom_keyword!(Task); - syn::custom_keyword!(LockId); - syn::custom_keyword!(SlashReason); - syn::custom_keyword!(exclude_parts); - syn::custom_keyword!(use_parts); - syn::custom_keyword!(expanded); -} - -/// Declaration of a runtime. -/// -/// Pallet declare their part either explicitly or implicitly (using no part declaration) -/// If all pallet have explicit parts then the runtime declaration is explicit, otherwise it is -/// implicit. -#[derive(Debug)] -pub enum RuntimeDeclaration { - Implicit(ImplicitRuntimeDeclaration), - Explicit(ExplicitRuntimeDeclaration), - ExplicitExpanded(ExplicitRuntimeDeclaration), -} - -/// Declaration of a runtime with some pallet with implicit declaration of parts. -#[derive(Debug)] -pub struct ImplicitRuntimeDeclaration { - pub pallets: Vec, -} - -/// Declaration of a runtime with all pallet having explicit declaration of parts. -#[derive(Debug)] -pub struct ExplicitRuntimeDeclaration { - pub name: Ident, - pub where_section: Option, - pub pallets: Vec, - pub pallets_token: token::Brace, -} - -impl Parse for RuntimeDeclaration { - fn parse(input: ParseStream) -> Result { - input.parse::()?; - - // Support either `enum` or `struct`. - if input.peek(Token![struct]) { - input.parse::()?; - } else { - input.parse::()?; - } - - let name = input.parse::()?; - let where_section = if input.peek(token::Where) { - Some(input.parse()?) - } else { - None - }; - let pallets = - input.parse::>>()?; - let pallets_token = pallets.token; - - match convert_pallets(pallets.content.inner.into_iter().collect())? { - PalletsConversion::Implicit(pallets) => { - Ok(RuntimeDeclaration::Implicit(ImplicitRuntimeDeclaration { - pallets, - })) - } - PalletsConversion::Explicit(pallets) => { - Ok(RuntimeDeclaration::Explicit(ExplicitRuntimeDeclaration { - name, - where_section, - pallets, - pallets_token, - })) - } - PalletsConversion::ExplicitExpanded(pallets) => Ok( - RuntimeDeclaration::ExplicitExpanded(ExplicitRuntimeDeclaration { - name, - where_section, - pallets, - pallets_token, - }), - ), - } - } -} - -#[derive(Debug)] -pub struct WhereSection { - pub span: Span, -} - -impl Parse for WhereSection { - fn parse(input: ParseStream) -> Result { - input.parse::()?; - - let mut definitions = Vec::new(); - while !input.peek(token::Brace) { - let definition: WhereDefinition = input.parse()?; - definitions.push(definition); - if !input.peek(Token![,]) { - if !input.peek(token::Brace) { - return Err(input.error("Expected `,` or `{`")); - } - break; - } - input.parse::()?; - } - remove_kind(input, WhereKind::Block, &mut definitions)?; - remove_kind(input, WhereKind::NodeBlock, &mut definitions)?; - remove_kind(input, WhereKind::UncheckedExtrinsic, &mut definitions)?; - if let Some(WhereDefinition { - kind_span, kind, .. - }) = definitions.first() - { - let msg = format!( - "`{:?}` was declared above. Please use exactly one declaration for `{:?}`.", - kind, kind - ); - return Err(Error::new(*kind_span, msg)); - } - Ok(Self { span: input.span() }) - } -} - -#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)] -pub enum WhereKind { - Block, - NodeBlock, - UncheckedExtrinsic, -} - -#[derive(Debug)] -pub struct WhereDefinition { - pub kind_span: Span, - pub kind: WhereKind, -} - -impl Parse for WhereDefinition { - fn parse(input: ParseStream) -> Result { - let lookahead = input.lookahead1(); - let (kind_span, kind) = if lookahead.peek(keyword::Block) { - (input.parse::()?.span(), WhereKind::Block) - } else if lookahead.peek(keyword::NodeBlock) { - ( - input.parse::()?.span(), - WhereKind::NodeBlock, - ) - } else if lookahead.peek(keyword::UncheckedExtrinsic) { - ( - input.parse::()?.span(), - WhereKind::UncheckedExtrinsic, - ) - } else { - return Err(lookahead.error()); - }; - - let _: Token![=] = input.parse()?; - let _: syn::TypePath = input.parse()?; - - Ok(Self { kind_span, kind }) - } -} - -/// The declaration of a pallet. -#[derive(Debug, Clone)] -pub struct PalletDeclaration { - /// Is this pallet fully expanded? - pub is_expanded: bool, - /// The name of the pallet, e.g.`System` in `System: frame_system`. - pub name: Ident, - /// Optional attributes tagged right above a pallet declaration. - pub attrs: Vec, - /// Optional fixed index, e.g. `MyPallet ... = 3,`. - pub index: Option, - /// The path of the pallet, e.g. `frame_system` in `System: frame_system`. - pub path: PalletPath, - /// The instance of the pallet, e.g. `Instance1` in `Council: pallet_collective::`. - pub instance: Option, - /// The declared pallet parts, - /// e.g. `Some([Pallet, Call])` for `System: system::{Pallet, Call}` - /// or `None` for `System: system`. - pub pallet_parts: Option>, - /// The specified parts, either use_parts or exclude_parts. - pub specified_parts: SpecifiedParts, -} - -/// The possible declaration of pallet parts to use. -#[derive(Debug, Clone)] -pub enum SpecifiedParts { - /// Use all the pallet parts except those specified. - Exclude(Vec), - /// Use only the specified pallet parts. - Use(Vec), - /// Use the all the pallet parts. - All, -} - -impl Parse for PalletDeclaration { - fn parse(input: ParseStream) -> Result { - let attrs = input.call(Attribute::parse_outer)?; - - let name = input.parse()?; - let _: Token![:] = input.parse()?; - let path = input.parse()?; - - // Parse for instance. - let instance = if input.peek(Token![::]) && input.peek3(Token![<]) { - let _: Token![::] = input.parse()?; - let _: Token![<] = input.parse()?; - let res = Some(input.parse()?); - let _: Token![>] = input.parse()?; - res - } else if !(input.peek(Token![::]) && input.peek3(token::Brace)) - && !input.peek(keyword::expanded) - && !input.peek(keyword::exclude_parts) - && !input.peek(keyword::use_parts) - && !input.peek(Token![=]) - && !input.peek(Token![,]) - && !input.is_empty() - { - return Err(input.error( - "Unexpected tokens, expected one of `::$ident` `::{`, `exclude_parts`, `use_parts`, `=`, `,`", - )); - } else { - None - }; - - // Check if the pallet is fully expanded. - let (is_expanded, extra_parts) = if input.peek(keyword::expanded) { - let _: keyword::expanded = input.parse()?; - let _: Token![::] = input.parse()?; - (true, parse_pallet_parts(input)?) - } else { - (false, vec![]) - }; - - // Parse for explicit parts - let pallet_parts = if input.peek(Token![::]) && input.peek3(token::Brace) { - let _: Token![::] = input.parse()?; - let mut parts = parse_pallet_parts(input)?; - parts.extend(extra_parts.into_iter()); - Some(parts) - } else if !input.peek(keyword::exclude_parts) - && !input.peek(keyword::use_parts) - && !input.peek(Token![=]) - && !input.peek(Token![,]) - && !input.is_empty() - { - return Err(input.error( - "Unexpected tokens, expected one of `::{`, `exclude_parts`, `use_parts`, `=`, `,`", - )); - } else { - is_expanded.then_some(extra_parts) - }; - - // Parse for specified parts - let specified_parts = if input.peek(keyword::exclude_parts) { - let _: keyword::exclude_parts = input.parse()?; - SpecifiedParts::Exclude(parse_pallet_parts_no_generic(input)?) - } else if input.peek(keyword::use_parts) { - let _: keyword::use_parts = input.parse()?; - SpecifiedParts::Use(parse_pallet_parts_no_generic(input)?) - } else if !input.peek(Token![=]) && !input.peek(Token![,]) && !input.is_empty() { - return Err(input.error("Unexpected tokens, expected one of `exclude_parts`, `=`, `,`")); - } else { - SpecifiedParts::All - }; - - // Parse for pallet index - let index = if input.peek(Token![=]) { - input.parse::()?; - let index = input.parse::()?; - let index = index.base10_parse::()?; - Some(index) - } else if !input.peek(Token![,]) && !input.is_empty() { - return Err(input.error("Unexpected tokens, expected one of `=`, `,`")); - } else { - None - }; - - Ok(Self { - is_expanded, - attrs, - name, - path, - instance, - pallet_parts, - specified_parts, - index, - }) - } -} - -/// A struct representing a path to a pallet. `PalletPath` is almost identical to the standard -/// Rust path with a few restrictions: -/// - No leading colons allowed -/// - Path segments can only consist of identifiers separated by colons -#[derive(Debug, Clone)] -pub struct PalletPath { - pub inner: Path, -} - -impl PalletPath { - pub fn module_name(&self) -> String { - self.inner - .segments - .iter() - .fold(String::new(), |mut acc, segment| { - if !acc.is_empty() { - acc.push_str("::"); - } - acc.push_str(&segment.ident.to_string()); - acc - }) - } -} - -impl Parse for PalletPath { - fn parse(input: ParseStream) -> Result { - let mut res = PalletPath { - inner: Path { - leading_colon: None, - segments: Punctuated::new(), - }, - }; - - let lookahead = input.lookahead1(); - if lookahead.peek(Token![crate]) - || lookahead.peek(Token![self]) - || lookahead.peek(Token![super]) - || lookahead.peek(Ident) - { - let ident = input.call(Ident::parse_any)?; - res.inner.segments.push(ident.into()); - } else { - return Err(lookahead.error()); - } - - while input.peek(Token![::]) && input.peek3(Ident) { - input.parse::()?; - let ident = input.parse::()?; - res.inner.segments.push(ident.into()); - } - Ok(res) - } -} - -impl quote::ToTokens for PalletPath { - fn to_tokens(&self, tokens: &mut TokenStream) { - self.inner.to_tokens(tokens); - } -} - -/// Parse [`PalletPart`]'s from a braces enclosed list that is split by commas, e.g. -/// -/// `{ Call, Event }` -fn parse_pallet_parts(input: ParseStream) -> Result> { - let pallet_parts: ext::Braces> = input.parse()?; - - let mut resolved = HashSet::new(); - for part in pallet_parts.content.inner.iter() { - if !resolved.insert(part.name()) { - let msg = format!( - "`{}` was already declared before. Please remove the duplicate declaration", - part.name(), - ); - return Err(Error::new(part.keyword.span(), msg)); - } - } - - Ok(pallet_parts.content.inner.into_iter().collect()) -} - -#[derive(Debug, Clone)] -pub enum PalletPartKeyword { - Pallet(keyword::Pallet), - Call(keyword::Call), - Storage(keyword::Storage), - Event(keyword::Event), - Error(keyword::Error), - Config(keyword::Config), - Origin(keyword::Origin), - Inherent(keyword::Inherent), - ValidateUnsigned(keyword::ValidateUnsigned), - FreezeReason(keyword::FreezeReason), - HoldReason(keyword::HoldReason), - Task(keyword::Task), - LockId(keyword::LockId), - SlashReason(keyword::SlashReason), -} - -impl Parse for PalletPartKeyword { - fn parse(input: ParseStream) -> Result { - let lookahead = input.lookahead1(); - - if lookahead.peek(keyword::Pallet) { - Ok(Self::Pallet(input.parse()?)) - } else if lookahead.peek(keyword::Call) { - Ok(Self::Call(input.parse()?)) - } else if lookahead.peek(keyword::Storage) { - Ok(Self::Storage(input.parse()?)) - } else if lookahead.peek(keyword::Event) { - Ok(Self::Event(input.parse()?)) - } else if lookahead.peek(keyword::Error) { - Ok(Self::Error(input.parse()?)) - } else if lookahead.peek(keyword::Config) { - Ok(Self::Config(input.parse()?)) - } else if lookahead.peek(keyword::Origin) { - Ok(Self::Origin(input.parse()?)) - } else if lookahead.peek(keyword::Inherent) { - Ok(Self::Inherent(input.parse()?)) - } else if lookahead.peek(keyword::ValidateUnsigned) { - Ok(Self::ValidateUnsigned(input.parse()?)) - } else if lookahead.peek(keyword::FreezeReason) { - Ok(Self::FreezeReason(input.parse()?)) - } else if lookahead.peek(keyword::HoldReason) { - Ok(Self::HoldReason(input.parse()?)) - } else if lookahead.peek(keyword::Task) { - Ok(Self::Task(input.parse()?)) - } else if lookahead.peek(keyword::LockId) { - Ok(Self::LockId(input.parse()?)) - } else if lookahead.peek(keyword::SlashReason) { - Ok(Self::SlashReason(input.parse()?)) - } else { - Err(lookahead.error()) - } - } -} - -impl PalletPartKeyword { - /// Returns the name of `Self`. - fn name(&self) -> &'static str { - match self { - Self::Pallet(_) => "Pallet", - Self::Call(_) => "Call", - Self::Storage(_) => "Storage", - Self::Event(_) => "Event", - Self::Error(_) => "Error", - Self::Config(_) => "Config", - Self::Origin(_) => "Origin", - Self::Inherent(_) => "Inherent", - Self::ValidateUnsigned(_) => "ValidateUnsigned", - Self::FreezeReason(_) => "FreezeReason", - Self::HoldReason(_) => "HoldReason", - Self::Task(_) => "Task", - Self::LockId(_) => "LockId", - Self::SlashReason(_) => "SlashReason", - } - } - - /// Returns `true` if this pallet part is allowed to have generic arguments. - fn allows_generic(&self) -> bool { - Self::all_generic_arg().iter().any(|n| *n == self.name()) - } - - /// Returns the names of all pallet parts that allow to have a generic argument. - fn all_generic_arg() -> &'static [&'static str] { - &["Event", "Error", "Origin", "Config", "Task"] - } -} - -impl ToTokens for PalletPartKeyword { - fn to_tokens(&self, tokens: &mut TokenStream) { - match self { - Self::Pallet(inner) => inner.to_tokens(tokens), - Self::Call(inner) => inner.to_tokens(tokens), - Self::Storage(inner) => inner.to_tokens(tokens), - Self::Event(inner) => inner.to_tokens(tokens), - Self::Error(inner) => inner.to_tokens(tokens), - Self::Config(inner) => inner.to_tokens(tokens), - Self::Origin(inner) => inner.to_tokens(tokens), - Self::Inherent(inner) => inner.to_tokens(tokens), - Self::ValidateUnsigned(inner) => inner.to_tokens(tokens), - Self::FreezeReason(inner) => inner.to_tokens(tokens), - Self::HoldReason(inner) => inner.to_tokens(tokens), - Self::Task(inner) => inner.to_tokens(tokens), - Self::LockId(inner) => inner.to_tokens(tokens), - Self::SlashReason(inner) => inner.to_tokens(tokens), - } - } -} - -#[derive(Debug, Clone)] -pub struct PalletPart { - pub keyword: PalletPartKeyword, - pub generics: syn::Generics, -} - -impl Parse for PalletPart { - fn parse(input: ParseStream) -> Result { - let keyword: PalletPartKeyword = input.parse()?; - - let generics: syn::Generics = input.parse()?; - if !generics.params.is_empty() && !keyword.allows_generic() { - let valid_generics = PalletPart::format_names(PalletPartKeyword::all_generic_arg()); - let msg = format!( - "`{}` is not allowed to have generics. \ - Only the following pallets are allowed to have generics: {}.", - keyword.name(), - valid_generics, - ); - return Err(syn::Error::new(keyword.span(), msg)); - } - - Ok(Self { keyword, generics }) - } -} - -impl PalletPart { - pub fn format_names(names: &[&'static str]) -> String { - let res: Vec<_> = names.iter().map(|s| format!("`{}`", s)).collect(); - res.join(", ") - } - - /// The name of this pallet part. - pub fn name(&self) -> &'static str { - self.keyword.name() - } -} - -fn remove_kind( - input: ParseStream, - kind: WhereKind, - definitions: &mut Vec, -) -> Result { - if let Some(pos) = definitions.iter().position(|d| d.kind == kind) { - Ok(definitions.remove(pos)) - } else { - let msg = format!( - "Missing associated type for `{:?}`. Add `{:?}` = ... to where section.", - kind, kind - ); - Err(input.error(msg)) - } -} - -/// The declaration of a part without its generics -#[derive(Debug, Clone)] -pub struct PalletPartNoGeneric { - keyword: PalletPartKeyword, -} - -impl Parse for PalletPartNoGeneric { - fn parse(input: ParseStream) -> Result { - Ok(Self { - keyword: input.parse()?, - }) - } -} - -/// Parse [`PalletPartNoGeneric`]'s from a braces enclosed list that is split by commas, e.g. -/// -/// `{ Call, Event }` -fn parse_pallet_parts_no_generic(input: ParseStream) -> Result> { - let pallet_parts: ext::Braces> = - input.parse()?; - - let mut resolved = HashSet::new(); - for part in pallet_parts.content.inner.iter() { - if !resolved.insert(part.keyword.name()) { - let msg = format!( - "`{}` was already declared before. Please remove the duplicate declaration", - part.keyword.name(), - ); - return Err(Error::new(part.keyword.span(), msg)); - } - } - - Ok(pallet_parts.content.inner.into_iter().collect()) -} - -/// The final definition of a pallet with the resulting fixed index and explicit parts. -#[derive(Debug, Clone)] -pub struct Pallet { - /// Is this pallet fully expanded? - pub is_expanded: bool, - /// The name of the pallet, e.g.`System` in `System: frame_system`. - pub name: Ident, - /// Either automatically inferred, or defined (e.g. `MyPallet ... = 3,`). - pub index: u8, - /// The path of the pallet, e.g. `frame_system` in `System: frame_system`. - pub path: PalletPath, - /// The instance of the pallet, e.g. `Instance1` in `Council: pallet_collective::`. - pub instance: Option, - /// The pallet parts to use for the pallet. - pub pallet_parts: Vec, - /// Expressions specified inside of a #[cfg] attribute. - pub cfg_pattern: Vec, - /// The doc literals - pub docs: Vec, -} - -impl Pallet { - /// Get resolved pallet parts - pub fn pallet_parts(&self) -> &[PalletPart] { - &self.pallet_parts - } - - /// Find matching parts - pub fn find_part(&self, name: &str) -> Option<&PalletPart> { - self.pallet_parts.iter().find(|part| part.name() == name) - } - - /// Return whether pallet contains part - pub fn exists_part(&self, name: &str) -> bool { - self.find_part(name).is_some() - } -} - -/// Result of a conversion of a declaration of pallets. -/// -/// # State Transitions -/// -/// ```ignore -/// +----------+ +----------+ +------------------+ -/// | Implicit | -> | Explicit | -> | ExplicitExpanded | -/// +----------+ +----------+ +------------------+ -/// ``` -enum PalletsConversion { - /// Pallets implicitly declare parts. - /// - /// `System: frame_system`. - Implicit(Vec), - /// Pallets explicitly declare parts. - /// - /// `System: frame_system::{Pallet, Call}` - /// - /// However, for backwards compatibility with Polkadot/Kusama - /// we must propagate some other parts to the pallet by default. - Explicit(Vec), - /// Pallets explicitly declare parts that are fully expanded. - /// - /// This is the end state that contains extra parts included by - /// default by Substrate. - /// - /// `System: frame_system expanded::{Error} ::{Pallet, Call}` - /// - /// For this example, the `Pallet`, `Call` and `Error` parts are collected. - ExplicitExpanded(Vec), -} - -/// Convert from the parsed pallet declaration to their final information. -/// -/// Check if all pallet have explicit declaration of their parts, if so then assign index to each -/// pallet using same rules as rust for fieldless enum. I.e. implicit are assigned number -/// incrementally from last explicit or 0. -fn convert_pallets(pallets: Vec) -> syn::Result { - if pallets.iter().any(|pallet| pallet.pallet_parts.is_none()) { - return Ok(PalletsConversion::Implicit(pallets)); - } - - let mut indices = HashMap::new(); - let mut last_index: Option = None; - let mut names = HashMap::new(); - let mut is_expanded = true; - - let pallets = pallets - .into_iter() - .map(|pallet| { - let final_index = match pallet.index { - Some(i) => i, - None => last_index - .map_or(Some(0), |i| i.checked_add(1)) - .ok_or_else(|| { - let msg = "Pallet index doesn't fit into u8, index is 256"; - syn::Error::new(pallet.name.span(), msg) - })?, - }; - - last_index = Some(final_index); - - if let Some(used_pallet) = indices.insert(final_index, pallet.name.clone()) { - let msg = format!( - "Pallet indices are conflicting: Both pallets {} and {} are at index {}", - used_pallet, pallet.name, final_index, - ); - let mut err = syn::Error::new(used_pallet.span(), &msg); - err.combine(syn::Error::new(pallet.name.span(), msg)); - return Err(err); - } - - if let Some(used_pallet) = names.insert(pallet.name.clone(), pallet.name.span()) { - let msg = "Two pallets with the same name!"; - - let mut err = syn::Error::new(used_pallet, &msg); - err.combine(syn::Error::new(pallet.name.span(), &msg)); - return Err(err); - } - - let mut pallet_parts = pallet.pallet_parts.expect("Checked above"); - - let available_parts = pallet_parts - .iter() - .map(|part| part.keyword.name()) - .collect::>(); - - // Check parts are correctly specified - match &pallet.specified_parts { - SpecifiedParts::Exclude(parts) | SpecifiedParts::Use(parts) => { - for part in parts { - if !available_parts.contains(part.keyword.name()) { - let msg = format!( - "Invalid pallet part specified, the pallet `{}` doesn't have the \ - `{}` part. Available parts are: {}.", - pallet.name, - part.keyword.name(), - pallet_parts.iter().fold(String::new(), |fold, part| { - if fold.is_empty() { - format!("`{}`", part.keyword.name()) - } else { - format!("{}, `{}`", fold, part.keyword.name()) - } - }) - ); - return Err(syn::Error::new(part.keyword.span(), msg)); - } - } - } - SpecifiedParts::All => (), - } - - // Set only specified parts. - match pallet.specified_parts { - SpecifiedParts::Exclude(excluded_parts) => pallet_parts.retain(|part| { - !excluded_parts - .iter() - .any(|excluded_part| excluded_part.keyword.name() == part.keyword.name()) - }), - SpecifiedParts::Use(used_parts) => pallet_parts.retain(|part| { - used_parts - .iter() - .any(|use_part| use_part.keyword.name() == part.keyword.name()) - }), - SpecifiedParts::All => (), - } - - let cfg_pattern = pallet - .attrs - .iter() - .map(|attr| { - if attr - .path() - .segments - .first() - .map_or(false, |s| s.ident != "cfg") - { - let msg = "Unsupported attribute, only #[cfg] is supported on pallet \ - declarations in `construct_runtime`"; - return Err(syn::Error::new(attr.span(), msg)); - } - - attr.parse_args_with(|input: syn::parse::ParseStream| { - // Required, otherwise the parse stream doesn't advance and will result in - // an error. - let input = input.parse::()?; - cfg_expr::Expression::parse(&input.to_string()) - .map_err(|e| syn::Error::new(attr.span(), e.to_string())) - }) - }) - .collect::>>()?; - - is_expanded &= pallet.is_expanded; - - Ok(Pallet { - is_expanded: pallet.is_expanded, - name: pallet.name, - index: final_index, - path: pallet.path, - instance: pallet.instance, - cfg_pattern, - pallet_parts, - docs: vec![], - }) - }) - .collect::>>()?; - - if is_expanded { - Ok(PalletsConversion::ExplicitExpanded(pallets)) - } else { - Ok(PalletsConversion::Explicit(pallets)) - } -} diff --git a/support/procedural-fork/src/crate_version.rs b/support/procedural-fork/src/crate_version.rs deleted file mode 100644 index 63e7c72796..0000000000 --- a/support/procedural-fork/src/crate_version.rs +++ /dev/null @@ -1,54 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//! Implementation of macros related to crate versioning. - -use super::get_cargo_env_var; -use frame_support_procedural_tools::generate_access_from_frame_or_crate; -use proc_macro2::{Span, TokenStream}; -use syn::{Error, Result}; - -/// Create an error that will be shown by rustc at the call site of the macro. -fn create_error(message: &str) -> Error { - Error::new(Span::call_site(), message) -} - -/// Implementation of the `crate_to_crate_version!` macro. -pub fn crate_to_crate_version(input: proc_macro::TokenStream) -> Result { - if !input.is_empty() { - return Err(create_error("No arguments expected!")); - } - - let major_version = get_cargo_env_var::("CARGO_PKG_VERSION_MAJOR") - .map_err(|_| create_error("Major version needs to fit into `u16`"))?; - - let minor_version = get_cargo_env_var::("CARGO_PKG_VERSION_MINOR") - .map_err(|_| create_error("Minor version needs to fit into `u8`"))?; - - let patch_version = get_cargo_env_var::("CARGO_PKG_VERSION_PATCH") - .map_err(|_| create_error("Patch version needs to fit into `u8`"))?; - - let crate_ = generate_access_from_frame_or_crate("frame-support")?; - - Ok(quote::quote! { - #crate_::traits::CrateVersion { - major: #major_version, - minor: #minor_version, - patch: #patch_version, - } - }) -} diff --git a/support/procedural-fork/src/derive_impl.rs b/support/procedural-fork/src/derive_impl.rs deleted file mode 100644 index 4320a8bf86..0000000000 --- a/support/procedural-fork/src/derive_impl.rs +++ /dev/null @@ -1,316 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//! Implementation of the `derive_impl` attribute macro. - -use derive_syn_parse::Parse; -use macro_magic::mm_core::ForeignPath; -use proc_macro2::TokenStream as TokenStream2; -use quote::{ToTokens, quote}; -use std::collections::HashSet; -use syn::{ - Ident, ImplItem, ItemImpl, Path, Result, Token, parse_quote, parse2, spanned::Spanned, token, -}; - -mod keyword { - syn::custom_keyword!(inject_runtime_type); - syn::custom_keyword!(no_aggregated_types); -} - -#[derive(derive_syn_parse::Parse, PartialEq, Eq)] -pub enum PalletAttrType { - #[peek(keyword::inject_runtime_type, name = "inject_runtime_type")] - RuntimeType(keyword::inject_runtime_type), -} - -#[derive(derive_syn_parse::Parse)] -pub struct PalletAttr { - _pound: Token![#], - #[bracket] - _bracket: token::Bracket, - #[inside(_bracket)] - typ: PalletAttrType, -} - -fn is_runtime_type(item: &syn::ImplItemType) -> bool { - item.attrs.iter().any(|attr| { - if let Ok(PalletAttr { - typ: PalletAttrType::RuntimeType(_), - .. - }) = parse2::(attr.into_token_stream()) - { - return true; - } - false - }) -} - -#[derive(Parse, Debug)] -pub struct DeriveImplAttrArgs { - pub default_impl_path: Path, - _as: Option, - #[parse_if(_as.is_some())] - pub disambiguation_path: Option, - _comma: Option, - #[parse_if(_comma.is_some())] - pub no_aggregated_types: Option, -} - -impl ForeignPath for DeriveImplAttrArgs { - fn foreign_path(&self) -> &Path { - &self.default_impl_path - } -} - -impl ToTokens for DeriveImplAttrArgs { - fn to_tokens(&self, tokens: &mut TokenStream2) { - tokens.extend(self.default_impl_path.to_token_stream()); - tokens.extend(self._as.to_token_stream()); - tokens.extend(self.disambiguation_path.to_token_stream()); - tokens.extend(self._comma.to_token_stream()); - tokens.extend(self.no_aggregated_types.to_token_stream()); - } -} - -/// Gets the [`Ident`] representation of the given [`ImplItem`], if one exists. Otherwise -/// returns [`None`]. -/// -/// Used by [`combine_impls`] to determine whether we can compare [`ImplItem`]s by [`Ident`] -/// or not. -fn impl_item_ident(impl_item: &ImplItem) -> Option<&Ident> { - match impl_item { - ImplItem::Const(item) => Some(&item.ident), - ImplItem::Fn(item) => Some(&item.sig.ident), - ImplItem::Type(item) => Some(&item.ident), - ImplItem::Macro(item) => item.mac.path.get_ident(), - _ => None, - } -} - -/// The real meat behind `derive_impl`. Takes in a `local_impl`, which is the impl for which we -/// want to implement defaults (i.e. the one the attribute macro is attached to), and a -/// `foreign_impl`, which is the impl containing the defaults we want to use, and returns an -/// [`ItemImpl`] containing the final generated impl. -/// -/// This process has the following caveats: -/// * Colliding items that have an ident are not copied into `local_impl` -/// * Uncolliding items that have an ident are copied into `local_impl` but are qualified as `type -/// #ident = <#default_impl_path as #disambiguation_path>::#ident;` -/// * Items that lack an ident are de-duplicated so only unique items that lack an ident are copied -/// into `local_impl`. Items that lack an ident and also exist verbatim in `local_impl` are not -/// copied over. -fn combine_impls( - local_impl: ItemImpl, - foreign_impl: ItemImpl, - default_impl_path: Path, - disambiguation_path: Path, - inject_runtime_types: bool, -) -> ItemImpl { - let (existing_local_keys, existing_unsupported_items): (HashSet, HashSet) = - local_impl - .items - .iter() - .cloned() - .partition(|impl_item| impl_item_ident(impl_item).is_some()); - let existing_local_keys: HashSet = existing_local_keys - .into_iter() - .filter_map(|item| impl_item_ident(&item).cloned()) - .collect(); - let mut final_impl = local_impl; - let extended_items = foreign_impl.items.into_iter().filter_map(|item| { - if let Some(ident) = impl_item_ident(&item) { - if existing_local_keys.contains(&ident) { - // do not copy colliding items that have an ident - return None; - } - if let ImplItem::Type(typ) = item.clone() { - let cfg_attrs = typ - .attrs - .iter() - .filter(|attr| { - attr.path() - .get_ident() - .map_or(false, |ident| ident == "cfg") - }) - .map(|attr| attr.to_token_stream()); - if is_runtime_type(&typ) { - let item: ImplItem = if inject_runtime_types { - parse_quote! { - #( #cfg_attrs )* - type #ident = #ident; - } - } else { - item - }; - return Some(item); - } - // modify and insert uncolliding type items - let modified_item: ImplItem = parse_quote! { - #( #cfg_attrs )* - type #ident = <#default_impl_path as #disambiguation_path>::#ident; - }; - return Some(modified_item); - } - // copy uncolliding non-type items that have an ident - Some(item) - } else { - // do not copy colliding items that lack an ident - (!existing_unsupported_items.contains(&item)) - // copy uncolliding items without an ident verbatim - .then_some(item) - } - }); - final_impl.items.extend(extended_items); - final_impl -} - -/// Computes the disambiguation path for the `derive_impl` attribute macro. -/// -/// When specified explicitly using `as [disambiguation_path]` in the macro attr, the -/// disambiguation is used as is. If not, we infer the disambiguation path from the -/// `foreign_impl_path` and the computed scope. -fn compute_disambiguation_path( - disambiguation_path: Option, - foreign_impl: ItemImpl, - default_impl_path: Path, -) -> Result { - match (disambiguation_path, foreign_impl.clone().trait_) { - (Some(disambiguation_path), _) => Ok(disambiguation_path), - (None, Some((_, foreign_impl_path, _))) => { - if default_impl_path.segments.len() > 1 { - let scope = default_impl_path.segments.first(); - Ok(parse_quote!(#scope :: #foreign_impl_path)) - } else { - Ok(foreign_impl_path) - } - } - _ => Err(syn::Error::new( - default_impl_path.span(), - "Impl statement must have a defined type being implemented \ - for a defined type such as `impl A for B`", - )), - } -} - -/// Internal implementation behind [`#[derive_impl(..)]`](`macro@crate::derive_impl`). -/// -/// `default_impl_path`: the module path of the external `impl` statement whose tokens we are -/// importing via `macro_magic` -/// -/// `foreign_tokens`: the tokens for the external `impl` statement -/// -/// `local_tokens`: the tokens for the local `impl` statement this attribute is attached to -/// -/// `disambiguation_path`: the module path of the external trait we will use to qualify -/// defaults imported from the external `impl` statement -pub fn derive_impl( - default_impl_path: TokenStream2, - foreign_tokens: TokenStream2, - local_tokens: TokenStream2, - disambiguation_path: Option, - no_aggregated_types: Option, -) -> Result { - let local_impl = parse2::(local_tokens)?; - let foreign_impl = parse2::(foreign_tokens)?; - let default_impl_path = parse2::(default_impl_path)?; - - let disambiguation_path = compute_disambiguation_path( - disambiguation_path, - foreign_impl.clone(), - default_impl_path.clone(), - )?; - - // generate the combined impl - let combined_impl = combine_impls( - local_impl, - foreign_impl, - default_impl_path, - disambiguation_path, - no_aggregated_types.is_none(), - ); - - Ok(quote!(#combined_impl)) -} - -#[test] -fn test_derive_impl_attr_args_parsing() { - parse2::(quote!( - some::path::TestDefaultConfig as some::path::DefaultConfig - )) - .unwrap(); - parse2::(quote!( - frame_system::prelude::testing::TestDefaultConfig as DefaultConfig - )) - .unwrap(); - parse2::(quote!(Something as some::path::DefaultConfig)).unwrap(); - parse2::(quote!(Something as DefaultConfig)).unwrap(); - parse2::(quote!(DefaultConfig)).unwrap(); - assert!(parse2::(quote!()).is_err()); - assert!(parse2::(quote!(Config Config)).is_err()); -} - -#[test] -fn test_runtime_type_with_doc() { - trait TestTrait { - type Test; - } - #[allow(unused)] - struct TestStruct; - let p = parse2::(quote!( - impl TestTrait for TestStruct { - /// Some doc - #[inject_runtime_type] - type Test = u32; - } - )) - .unwrap(); - for item in p.items { - if let ImplItem::Type(typ) = item { - assert_eq!(is_runtime_type(&typ), true); - } - } -} - -#[test] -fn test_disambiguation_path() { - let foreign_impl: ItemImpl = parse_quote!(impl SomeTrait for SomeType {}); - let default_impl_path: Path = parse_quote!(SomeScope::SomeType); - - // disambiguation path is specified - let disambiguation_path = compute_disambiguation_path( - Some(parse_quote!(SomeScope::SomePath)), - foreign_impl.clone(), - default_impl_path.clone(), - ); - assert_eq!( - disambiguation_path.unwrap(), - parse_quote!(SomeScope::SomePath) - ); - - // disambiguation path is not specified and the default_impl_path has more than one segment - let disambiguation_path = - compute_disambiguation_path(None, foreign_impl.clone(), default_impl_path.clone()); - assert_eq!( - disambiguation_path.unwrap(), - parse_quote!(SomeScope::SomeTrait) - ); - - // disambiguation path is not specified and the default_impl_path has only one segment - let disambiguation_path = - compute_disambiguation_path(None, foreign_impl.clone(), parse_quote!(SomeType)); - assert_eq!(disambiguation_path.unwrap(), parse_quote!(SomeTrait)); -} diff --git a/support/procedural-fork/src/dummy_part_checker.rs b/support/procedural-fork/src/dummy_part_checker.rs deleted file mode 100644 index 6bed541d16..0000000000 --- a/support/procedural-fork/src/dummy_part_checker.rs +++ /dev/null @@ -1,81 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use crate::COUNTER; -use proc_macro::TokenStream; - -pub fn generate_dummy_part_checker(input: TokenStream) -> TokenStream { - if !input.is_empty() { - return syn::Error::new(proc_macro2::Span::call_site(), "No arguments expected") - .to_compile_error() - .into(); - } - - let count = COUNTER.with(|counter| counter.borrow_mut().inc()); - - let no_op_macro_ident = syn::Ident::new( - &format!("__dummy_part_checker_{}", count), - proc_macro2::Span::call_site(), - ); - - quote::quote!( - #[macro_export] - #[doc(hidden)] - macro_rules! #no_op_macro_ident { - ( $( $tt:tt )* ) => {}; - } - - #[doc(hidden)] - pub mod __substrate_genesis_config_check { - #[doc(hidden)] - pub use #no_op_macro_ident as is_genesis_config_defined; - #[doc(hidden)] - pub use #no_op_macro_ident as is_std_enabled_for_genesis; - } - - #[doc(hidden)] - pub mod __substrate_event_check { - #[doc(hidden)] - pub use #no_op_macro_ident as is_event_part_defined; - } - - #[doc(hidden)] - pub mod __substrate_inherent_check { - #[doc(hidden)] - pub use #no_op_macro_ident as is_inherent_part_defined; - } - - #[doc(hidden)] - pub mod __substrate_validate_unsigned_check { - #[doc(hidden)] - pub use #no_op_macro_ident as is_validate_unsigned_part_defined; - } - - #[doc(hidden)] - pub mod __substrate_call_check { - #[doc(hidden)] - pub use #no_op_macro_ident as is_call_part_defined; - } - - #[doc(hidden)] - pub mod __substrate_origin_check { - #[doc(hidden)] - pub use #no_op_macro_ident as is_origin_part_defined; - } - ) - .into() -} diff --git a/support/procedural-fork/src/dynamic_params.rs b/support/procedural-fork/src/dynamic_params.rs deleted file mode 100644 index eeb7720798..0000000000 --- a/support/procedural-fork/src/dynamic_params.rs +++ /dev/null @@ -1,587 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//! Code for the `#[dynamic_params]`, `#[dynamic_pallet_params]` and -//! `#[dynamic_aggregated_params_internal]` macros. - -use frame_support_procedural_tools::generate_access_from_frame_or_crate; -use inflector::Inflector; -use proc_macro2::{Span, TokenStream}; -use quote::{ToTokens, format_ident, quote}; -use syn::{Result, Token, parse2, spanned::Spanned, visit_mut, visit_mut::VisitMut}; - -/// Parse and expand a `#[dynamic_params(..)]` module. -pub fn dynamic_params(attr: TokenStream, item: TokenStream) -> Result { - DynamicParamModAttr::parse(attr, item).map(ToTokens::into_token_stream) -} - -/// Parse and expand `#[dynamic_pallet_params(..)]` attribute. -pub fn dynamic_pallet_params(attr: TokenStream, item: TokenStream) -> Result { - DynamicPalletParamAttr::parse(attr, item).map(ToTokens::into_token_stream) -} - -/// Parse and expand `#[dynamic_aggregated_params_internal]` attribute. -pub fn dynamic_aggregated_params_internal( - _attr: TokenStream, - item: TokenStream, -) -> Result { - parse2::(item).map(ToTokens::into_token_stream) -} - -/// A top `#[dynamic_params(..)]` attribute together with a mod. -#[derive(derive_syn_parse::Parse)] -pub struct DynamicParamModAttr { - params_mod: syn::ItemMod, - meta: DynamicParamModAttrMeta, -} - -/// The inner meta of a `#[dynamic_params(..)]` attribute. -#[derive(derive_syn_parse::Parse)] -pub struct DynamicParamModAttrMeta { - name: syn::Ident, - _comma: Option, - #[parse_if(_comma.is_some())] - params_pallet: Option, -} - -impl DynamicParamModAttr { - pub fn parse(attr: TokenStream, item: TokenStream) -> Result { - let params_mod = parse2(item)?; - let meta = parse2(attr)?; - Ok(Self { params_mod, meta }) - } - - pub fn inner_mods(&self) -> Vec { - self.params_mod - .content - .as_ref() - .map_or(Vec::new(), |(_, items)| { - items - .iter() - .filter_map(|i| match i { - syn::Item::Mod(m) => Some(m), - _ => None, - }) - .cloned() - .collect() - }) - } -} - -impl ToTokens for DynamicParamModAttr { - fn to_tokens(&self, tokens: &mut TokenStream) { - let scrate = match crate_access() { - Ok(path) => path, - Err(err) => return tokens.extend(err), - }; - let (mut params_mod, name) = (self.params_mod.clone(), &self.meta.name); - let dynam_params_ident = ¶ms_mod.ident; - - let mut quoted_enum = quote! {}; - for m in self.inner_mods() { - let aggregate_name = - syn::Ident::new(&m.ident.to_string().to_pascal_case(), m.ident.span()); - let mod_name = &m.ident; - - let mut attrs = m.attrs.clone(); - attrs.retain(|attr| !attr.path().is_ident("dynamic_pallet_params")); - if let Err(err) = ensure_codec_index(&attrs, m.span()) { - tokens.extend(err.into_compile_error()); - return; - } - - quoted_enum.extend(quote! { - #(#attrs)* - #aggregate_name(#dynam_params_ident::#mod_name::Parameters), - }); - } - - // Inject the outer args into the inner `#[dynamic_pallet_params(..)]` attribute. - if let Some(params_pallet) = &self.meta.params_pallet { - MacroInjectArgs { - runtime_params: name.clone(), - params_pallet: params_pallet.clone(), - } - .visit_item_mod_mut(&mut params_mod); - } - - tokens.extend(quote! { - #params_mod - - #[#scrate::dynamic_params::dynamic_aggregated_params_internal] - pub enum #name { - #quoted_enum - } - }); - } -} - -/// Ensure there is a `#[codec(index = ..)]` attribute. -fn ensure_codec_index(attrs: &Vec, span: Span) -> Result<()> { - let mut found = false; - - for attr in attrs.iter() { - if attr.path().is_ident("codec") { - let meta: syn::ExprAssign = attr.parse_args()?; - if meta.left.to_token_stream().to_string() == "index" { - found = true; - break; - } - } - } - - if !found { - Err(syn::Error::new( - span, - "Missing explicit `#[codec(index = ..)]` attribute", - )) - } else { - Ok(()) - } -} - -/// Used to inject arguments into the inner `#[dynamic_pallet_params(..)]` attribute. -/// -/// This allows the outer `#[dynamic_params(..)]` attribute to specify some arguments that don't -/// need to be repeated every time. -struct MacroInjectArgs { - runtime_params: syn::Ident, - params_pallet: syn::Type, -} -impl VisitMut for MacroInjectArgs { - fn visit_item_mod_mut(&mut self, item: &mut syn::ItemMod) { - // Check if the mod has a `#[dynamic_pallet_params(..)]` attribute. - let attr = item - .attrs - .iter_mut() - .find(|attr| attr.path().is_ident("dynamic_pallet_params")); - - if let Some(attr) = attr { - match &attr.meta { - syn::Meta::Path(path) => { - assert_eq!(path.to_token_stream().to_string(), "dynamic_pallet_params") - } - _ => (), - } - - let runtime_params = &self.runtime_params; - let params_pallet = &self.params_pallet; - - attr.meta = syn::parse2::(quote! { - dynamic_pallet_params(#runtime_params, #params_pallet) - }) - .unwrap() - .into(); - } - - visit_mut::visit_item_mod_mut(self, item); - } -} -/// The helper attribute of a `#[dynamic_pallet_params(runtime_params, params_pallet)]` -/// attribute. -#[derive(derive_syn_parse::Parse)] -pub struct DynamicPalletParamAttr { - inner_mod: syn::ItemMod, - meta: DynamicPalletParamAttrMeta, -} - -/// The inner meta of a `#[dynamic_pallet_params(..)]` attribute. -#[derive(derive_syn_parse::Parse)] -pub struct DynamicPalletParamAttrMeta { - runtime_params: syn::Ident, - _comma: Token![,], - parameter_pallet: syn::Type, -} - -impl DynamicPalletParamAttr { - pub fn parse(attr: TokenStream, item: TokenStream) -> Result { - Ok(Self { - inner_mod: parse2(item)?, - meta: parse2(attr)?, - }) - } - - pub fn statics(&self) -> Vec { - self.inner_mod - .content - .as_ref() - .map_or(Vec::new(), |(_, items)| { - items - .iter() - .filter_map(|i| match i { - syn::Item::Static(s) => Some(s), - _ => None, - }) - .cloned() - .collect() - }) - } -} - -impl ToTokens for DynamicPalletParamAttr { - fn to_tokens(&self, tokens: &mut TokenStream) { - let scrate = match crate_access() { - Ok(path) => path, - Err(err) => return tokens.extend(err), - }; - let (params_mod, parameter_pallet, runtime_params) = ( - &self.inner_mod, - &self.meta.parameter_pallet, - &self.meta.runtime_params, - ); - - let aggregate_name = syn::Ident::new( - ¶ms_mod.ident.to_string().to_pascal_case(), - params_mod.ident.span(), - ); - let (mod_name, vis) = (¶ms_mod.ident, ¶ms_mod.vis); - let statics = self.statics(); - - let (mut key_names, mut key_values, mut defaults, mut attrs, mut value_types): ( - Vec<_>, - Vec<_>, - Vec<_>, - Vec<_>, - Vec<_>, - ) = Default::default(); - - for s in statics.iter() { - if let Err(err) = ensure_codec_index(&s.attrs, s.span()) { - tokens.extend(err.into_compile_error()); - return; - } - - key_names.push(&s.ident); - key_values.push(format_ident!("{}Value", &s.ident)); - defaults.push(&s.expr); - attrs.push(&s.attrs); - value_types.push(&s.ty); - } - - let key_ident = syn::Ident::new("ParametersKey", params_mod.ident.span()); - let value_ident = syn::Ident::new("ParametersValue", params_mod.ident.span()); - let runtime_key_ident = format_ident!("{}Key", runtime_params); - let runtime_value_ident = format_ident!("{}Value", runtime_params); - - tokens.extend(quote! { - pub mod #mod_name { - use super::*; - - #[doc(hidden)] - #[derive( - Clone, - PartialEq, - Eq, - #scrate::__private::codec::Encode, - #scrate::__private::codec::Decode, - #scrate::__private::codec::MaxEncodedLen, - #scrate::__private::RuntimeDebug, - #scrate::__private::scale_info::TypeInfo - )] - #vis enum Parameters { - #( - #(#attrs)* - #key_names(#key_names, Option<#value_types>), - )* - } - - #[doc(hidden)] - #[derive( - Clone, - PartialEq, - Eq, - #scrate::__private::codec::Encode, - #scrate::__private::codec::Decode, - #scrate::__private::codec::MaxEncodedLen, - #scrate::__private::RuntimeDebug, - #scrate::__private::scale_info::TypeInfo - )] - #vis enum #key_ident { - #( - #(#attrs)* - #key_names(#key_names), - )* - } - - #[doc(hidden)] - #[derive( - Clone, - PartialEq, - Eq, - #scrate::__private::codec::Encode, - #scrate::__private::codec::Decode, - #scrate::__private::codec::MaxEncodedLen, - #scrate::__private::RuntimeDebug, - #scrate::__private::scale_info::TypeInfo - )] - #vis enum #value_ident { - #( - #(#attrs)* - #key_names(#value_types), - )* - } - - impl #scrate::traits::dynamic_params::AggregatedKeyValue for Parameters { - type Key = #key_ident; - type Value = #value_ident; - - fn into_parts(self) -> (Self::Key, Option) { - match self { - #( - Parameters::#key_names(key, value) => { - (#key_ident::#key_names(key), value.map(#value_ident::#key_names)) - }, - )* - } - } - } - - #( - #[doc(hidden)] - #[derive( - Clone, - PartialEq, - Eq, - #scrate::__private::codec::Encode, - #scrate::__private::codec::Decode, - #scrate::__private::codec::MaxEncodedLen, - #scrate::__private::RuntimeDebug, - #scrate::__private::scale_info::TypeInfo - )] - #vis struct #key_names; - - impl #scrate::__private::Get<#value_types> for #key_names { - fn get() -> #value_types { - match - <#parameter_pallet as - #scrate::storage::StorageMap<#runtime_key_ident, #runtime_value_ident> - >::get(#runtime_key_ident::#aggregate_name(#key_ident::#key_names(#key_names))) - { - Some(#runtime_value_ident::#aggregate_name( - #value_ident::#key_names(inner))) => inner, - Some(_) => { - #scrate::defensive!("Unexpected value type at key - returning default"); - #defaults - }, - None => #defaults, - } - } - } - - impl #scrate::traits::dynamic_params::Key for #key_names { - type Value = #value_types; - type WrappedValue = #key_values; - } - - impl From<#key_names> for #key_ident { - fn from(key: #key_names) -> Self { - #key_ident::#key_names(key) - } - } - - impl TryFrom<#key_ident> for #key_names { - type Error = (); - - fn try_from(key: #key_ident) -> Result { - match key { - #key_ident::#key_names(key) => Ok(key), - _ => Err(()), - } - } - } - - #[doc(hidden)] - #[derive( - Clone, - PartialEq, - Eq, - #scrate::sp_runtime::RuntimeDebug, - )] - #vis struct #key_values(pub #value_types); - - impl From<#key_values> for #value_ident { - fn from(value: #key_values) -> Self { - #value_ident::#key_names(value.0) - } - } - - impl From<(#key_names, #value_types)> for Parameters { - fn from((key, value): (#key_names, #value_types)) -> Self { - Parameters::#key_names(key, Some(value)) - } - } - - impl From<#key_names> for Parameters { - fn from(key: #key_names) -> Self { - Parameters::#key_names(key, None) - } - } - - impl TryFrom<#value_ident> for #key_values { - type Error = (); - - fn try_from(value: #value_ident) -> Result { - match value { - #value_ident::#key_names(value) => Ok(#key_values(value)), - _ => Err(()), - } - } - } - - impl From<#key_values> for #value_types { - fn from(value: #key_values) -> Self { - value.0 - } - } - )* - } - }); - } -} - -#[derive(derive_syn_parse::Parse)] -pub struct DynamicParamAggregatedEnum { - aggregated_enum: syn::ItemEnum, -} - -impl ToTokens for DynamicParamAggregatedEnum { - fn to_tokens(&self, tokens: &mut TokenStream) { - let scrate = match crate_access() { - Ok(path) => path, - Err(err) => return tokens.extend(err), - }; - let params_enum = &self.aggregated_enum; - let (name, vis) = (¶ms_enum.ident, ¶ms_enum.vis); - - let (mut indices, mut param_names, mut param_types): (Vec<_>, Vec<_>, Vec<_>) = - Default::default(); - let mut attributes = Vec::new(); - for (i, variant) in params_enum.variants.iter().enumerate() { - indices.push(i); - param_names.push(&variant.ident); - attributes.push(&variant.attrs); - - param_types.push(match &variant.fields { - syn::Fields::Unnamed(fields) if fields.unnamed.len() == 1 => &fields.unnamed[0].ty, - _ => { - *tokens = quote! { compile_error!("Only unnamed enum variants with one inner item are supported") }; - return - }, - }); - } - - let params_key_ident = format_ident!("{}Key", params_enum.ident); - let params_value_ident = format_ident!("{}Value", params_enum.ident); - - tokens.extend(quote! { - #[doc(hidden)] - #[derive( - Clone, - PartialEq, - Eq, - #scrate::__private::codec::Encode, - #scrate::__private::codec::Decode, - #scrate::__private::codec::MaxEncodedLen, - #scrate::sp_runtime::RuntimeDebug, - #scrate::__private::scale_info::TypeInfo - )] - #vis enum #name { - #( - //#[codec(index = #indices)] - #(#attributes)* - #param_names(#param_types), - )* - } - - #[doc(hidden)] - #[derive( - Clone, - PartialEq, - Eq, - #scrate::__private::codec::Encode, - #scrate::__private::codec::Decode, - #scrate::__private::codec::MaxEncodedLen, - #scrate::sp_runtime::RuntimeDebug, - #scrate::__private::scale_info::TypeInfo - )] - #vis enum #params_key_ident { - #( - #(#attributes)* - #param_names(<#param_types as #scrate::traits::dynamic_params::AggregatedKeyValue>::Key), - )* - } - - #[doc(hidden)] - #[derive( - Clone, - PartialEq, - Eq, - #scrate::__private::codec::Encode, - #scrate::__private::codec::Decode, - #scrate::__private::codec::MaxEncodedLen, - #scrate::sp_runtime::RuntimeDebug, - #scrate::__private::scale_info::TypeInfo - )] - #vis enum #params_value_ident { - #( - #(#attributes)* - #param_names(<#param_types as #scrate::traits::dynamic_params::AggregatedKeyValue>::Value), - )* - } - - impl #scrate::traits::dynamic_params::AggregatedKeyValue for #name { - type Key = #params_key_ident; - type Value = #params_value_ident; - - fn into_parts(self) -> (Self::Key, Option) { - match self { - #( - #name::#param_names(parameter) => { - let (key, value) = parameter.into_parts(); - (#params_key_ident::#param_names(key), value.map(#params_value_ident::#param_names)) - }, - )* - } - } - } - - #( - impl ::core::convert::From<<#param_types as #scrate::traits::dynamic_params::AggregatedKeyValue>::Key> for #params_key_ident { - fn from(key: <#param_types as #scrate::traits::dynamic_params::AggregatedKeyValue>::Key) -> Self { - #params_key_ident::#param_names(key) - } - } - - impl ::core::convert::TryFrom<#params_value_ident> for <#param_types as #scrate::traits::dynamic_params::AggregatedKeyValue>::Value { - type Error = (); - - fn try_from(value: #params_value_ident) -> Result { - match value { - #params_value_ident::#param_names(value) => Ok(value), - _ => Err(()), - } - } - } - )* - }); - } -} - -/// Get access to the current crate and convert the error to a compile error. -fn crate_access() -> core::result::Result { - generate_access_from_frame_or_crate("frame-support").map_err(|e| e.to_compile_error()) -} diff --git a/support/procedural-fork/src/key_prefix.rs b/support/procedural-fork/src/key_prefix.rs deleted file mode 100644 index 6202d227a9..0000000000 --- a/support/procedural-fork/src/key_prefix.rs +++ /dev/null @@ -1,106 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use frame_support_procedural_tools::generate_access_from_frame_or_crate; -use proc_macro2::{Span, TokenStream}; -use quote::{ToTokens, format_ident, quote}; -use syn::{Ident, Result}; - -const MAX_IDENTS: usize = 18; - -pub fn impl_key_prefix_for_tuples(input: proc_macro::TokenStream) -> Result { - if !input.is_empty() { - return Err(syn::Error::new(Span::call_site(), "No arguments expected")); - } - - let mut all_trait_impls = TokenStream::new(); - let frame_support = generate_access_from_frame_or_crate("frame-support")?; - - for i in 2..=MAX_IDENTS { - let current_tuple = (0..i) - .map(|n| Ident::new(&format!("Tuple{}", n), Span::call_site())) - .collect::>(); - - for prefix_count in 1..i { - let (prefixes, suffixes) = current_tuple.split_at(prefix_count); - - let hashers = current_tuple - .iter() - .map(|ident| format_ident!("Hasher{}", ident)) - .collect::>(); - let kargs = prefixes - .iter() - .map(|ident| format_ident!("KArg{}", ident)) - .collect::>(); - let partial_keygen = generate_keygen(prefixes); - let suffix_keygen = generate_keygen(suffixes); - let suffix_tuple = generate_tuple(suffixes); - - let trait_impls = quote! { - impl< - #(#current_tuple: FullCodec + StaticTypeInfo,)* - #(#hashers: StorageHasher,)* - #(#kargs: EncodeLike<#prefixes>),* - > HasKeyPrefix<( #( #kargs, )* )> for ( #( Key<#hashers, #current_tuple>, )* ) { - type Suffix = #suffix_tuple; - - fn partial_key(prefix: ( #( #kargs, )* )) -> Vec { - <#partial_keygen>::final_key(prefix) - } - } - - impl< - #(#current_tuple: FullCodec + StaticTypeInfo,)* - #(#hashers: ReversibleStorageHasher,)* - #(#kargs: EncodeLike<#prefixes>),* - > HasReversibleKeyPrefix<( #( #kargs, )* )> for ( #( Key<#hashers, #current_tuple>, )* ) { - fn decode_partial_key(key_material: &[u8]) -> Result< - Self::Suffix, - #frame_support::__private::codec::Error, - > { - <#suffix_keygen>::decode_final_key(key_material).map(|k| k.0) - } - } - }; - - all_trait_impls.extend(trait_impls); - } - } - - Ok(all_trait_impls) -} - -fn generate_tuple(idents: &[Ident]) -> TokenStream { - if idents.len() == 1 { - idents[0].to_token_stream() - } else { - quote!((#(#idents),*)) - } -} - -fn generate_keygen(idents: &[Ident]) -> TokenStream { - if idents.len() == 1 { - let key = &idents[0]; - let hasher = format_ident!("Hasher{}", key); - - quote!(Key<#hasher, #key>) - } else { - let hashers = idents.iter().map(|ident| format_ident!("Hasher{}", ident)); - - quote!((#(Key<#hashers, #idents>),*)) - } -} diff --git a/support/procedural-fork/src/lib.rs b/support/procedural-fork/src/lib.rs deleted file mode 100644 index c7f1472b2a..0000000000 --- a/support/procedural-fork/src/lib.rs +++ /dev/null @@ -1,189 +0,0 @@ -//! This crate is a fork of the `frame-support-procedural` crate from -//! `substrate/frame/support/procedural` in `polkadot-sdk`. The purpose of this fork is to -//! re-export all parsing code from the original crate to make it accessible to other crates, -//! since the original crate is a `proc-macro` crate and therefore cannot have any non-macro -//! public exports. If Parity ever decides to move the parsing code to a separate crate, this -//! fork will no longer need to exist, but right now this is the only reliable way to get -//! access to the core parsing logic of substrate. -//! -//! Tags will be created for each major version of `polkadot-sdk` that `subtensor` relies on, -//! on an as-needed, ad-hoc basis, and versions will matched the corresponding `polkadot-sdk` -//! version/tag name. -#![recursion_limit = "512"] -#![allow(warnings)] -#![allow(clippy::all)] - -extern crate proc_macro; - -#[cfg(not(test))] -mod benchmark; -#[cfg(not(test))] -mod construct_runtime; -#[cfg(not(test))] -mod crate_version; -#[cfg(not(test))] -mod derive_impl; -#[cfg(not(test))] -mod dummy_part_checker; -#[cfg(not(test))] -mod dynamic_params; -#[cfg(not(test))] -mod key_prefix; -#[cfg(not(test))] -mod match_and_insert; -#[cfg(not(test))] -mod no_bound; -#[cfg(not(test))] -mod pallet; -#[cfg(not(test))] -mod pallet_error; -#[cfg(not(test))] -mod runtime; -#[cfg(not(test))] -mod storage_alias; -#[cfg(not(test))] -mod transactional; -#[cfg(not(test))] -mod tt_macro; -#[cfg(not(test))] -use std::{cell::RefCell, str::FromStr}; - -#[cfg(not(test))] -pub(crate) const INHERENT_INSTANCE_NAME: &str = "__InherentHiddenInstance"; - -/// The number of module instances supported by the runtime, starting at index 1, -/// and up to `NUMBER_OF_INSTANCE`. -#[cfg(not(test))] -pub(crate) const NUMBER_OF_INSTANCE: u8 = 16; - -thread_local! { - /// A global counter, can be used to generate a relatively unique identifier. - #[cfg(not(test))] - static COUNTER: RefCell = const { RefCell::new(Counter(0)) }; -} - -/// Counter to generate a relatively unique identifier for macros. This is necessary because -/// declarative macros gets hoisted to the crate root, which shares the namespace with other pallets -/// containing the very same macros. -#[cfg(not(test))] -struct Counter(u64); - -#[cfg(not(test))] -impl Counter { - fn inc(&mut self) -> u64 { - let ret = self.0; - self.0 += 1; - ret - } -} - -/// Get the value from the given environment variable set by cargo. -/// -/// The value is parsed into the requested destination type. -#[cfg(not(test))] -fn get_cargo_env_var(version_env: &str) -> std::result::Result { - let version = std::env::var(version_env) - .unwrap_or_else(|_| panic!("`{}` is always set by cargo; qed", version_env)); - - T::from_str(&version).map_err(drop) -} - -/// Generate the counter_prefix related to the storage. -/// counter_prefix is used by counted storage map. -#[cfg(not(test))] -fn counter_prefix(prefix: &str) -> String { - format!("CounterFor{}", prefix) -} - -#[cfg(not(test))] -pub mod exports { - pub mod benchmark { - pub use crate::benchmark::*; - } - - pub mod crate_version { - pub use crate::crate_version::*; - } - - pub mod derive_impl { - pub use crate::derive_impl::*; - } - - pub mod dummy_part_checker { - pub use crate::dummy_part_checker::*; - } - - pub mod dynamic_params { - pub use crate::dynamic_params::*; - } - - pub mod key_prefix { - pub use crate::key_prefix::*; - } - - pub mod match_and_insert { - pub use crate::match_and_insert::*; - } - - pub mod pallet_error { - pub use crate::pallet_error::*; - } - - pub mod storage_alias { - pub use crate::storage_alias::*; - } - - pub mod transactional { - pub use crate::transactional::*; - } - - pub mod tt_macro { - pub use crate::tt_macro::*; - } - - pub mod construct_runtime { - pub use crate::construct_runtime::*; - - pub mod parse { - pub use crate::construct_runtime::parse::*; - } - - pub mod expand { - pub use crate::construct_runtime::expand::*; - } - } - - pub mod no_bound { - pub mod clone { - pub use crate::no_bound::clone::*; - } - - pub mod debug { - pub use crate::no_bound::debug::*; - } - - pub mod default { - pub use crate::no_bound::default::*; - } - - pub mod ord { - pub use crate::no_bound::ord::*; - } - - pub mod partial_eq { - pub use crate::no_bound::partial_eq::*; - } - - pub mod partial_ord { - pub use crate::no_bound::partial_ord::*; - } - } - - pub mod pallet { - pub use crate::pallet::*; - - pub mod parse { - pub use crate::pallet::parse::*; - } - } -} diff --git a/support/procedural-fork/src/match_and_insert.rs b/support/procedural-fork/src/match_and_insert.rs deleted file mode 100644 index a80b6e95f8..0000000000 --- a/support/procedural-fork/src/match_and_insert.rs +++ /dev/null @@ -1,173 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//! Implementation of the `match_and_insert` macro. - -use proc_macro2::{Group, Span, TokenStream, TokenTree}; -use std::iter::once; -use syn::spanned::Spanned; - -mod keyword { - syn::custom_keyword!(target); - syn::custom_keyword!(pattern); - syn::custom_keyword!(tokens); -} - -pub fn match_and_insert(input: proc_macro::TokenStream) -> proc_macro::TokenStream { - let MatchAndInsertDef { - pattern, - tokens, - target, - } = syn::parse_macro_input!(input as MatchAndInsertDef); - - match expand_in_stream(&pattern, &mut Some(tokens), target) { - Ok(stream) => stream.into(), - Err(err) => err.to_compile_error().into(), - } -} - -struct MatchAndInsertDef { - // Token stream to search and insert tokens into. - target: TokenStream, - // Pattern to match against, this is ensured to have no TokenTree::Group nor TokenTree::Literal - // (i.e. contains only Punct or Ident), and not being empty. - pattern: Vec, - // Token stream to insert after the match pattern. - tokens: TokenStream, -} - -impl syn::parse::Parse for MatchAndInsertDef { - fn parse(input: syn::parse::ParseStream) -> syn::Result { - let mut target; - let _ = input.parse::()?; - let _ = input.parse::()?; - let _replace_with_bracket: syn::token::Bracket = syn::bracketed!(target in input); - let _replace_with_brace: syn::token::Brace = syn::braced!(target in target); - let target = target.parse()?; - - let mut pattern; - let _ = input.parse::()?; - let _ = input.parse::()?; - let _replace_with_bracket: syn::token::Bracket = syn::bracketed!(pattern in input); - let _replace_with_brace: syn::token::Brace = syn::braced!(pattern in pattern); - let pattern = pattern - .parse::()? - .into_iter() - .collect::>(); - - if let Some(t) = pattern.iter().find(|t| matches!(t, TokenTree::Group(_))) { - return Err(syn::Error::new(t.span(), "Unexpected group token tree")); - } - if let Some(t) = pattern.iter().find(|t| matches!(t, TokenTree::Literal(_))) { - return Err(syn::Error::new(t.span(), "Unexpected literal token tree")); - } - - if pattern.is_empty() { - return Err(syn::Error::new( - Span::call_site(), - "empty match pattern is invalid", - )); - } - - let mut tokens; - let _ = input.parse::()?; - let _ = input.parse::()?; - let _replace_with_bracket: syn::token::Bracket = syn::bracketed!(tokens in input); - let _replace_with_brace: syn::token::Brace = syn::braced!(tokens in tokens); - let tokens = tokens.parse()?; - - Ok(Self { - tokens, - pattern, - target, - }) - } -} - -// Insert `tokens` after the first matching `pattern`. -// `tokens` must be some (Option is used for internal simplification). -// `pattern` must not be empty and should only contain Ident or Punct. -fn expand_in_stream( - pattern: &[TokenTree], - tokens: &mut Option, - stream: TokenStream, -) -> syn::Result { - assert!( - tokens.is_some(), - "`tokens` must be some, Option is used because `tokens` is used only once" - ); - assert!( - !pattern.is_empty(), - "`pattern` must not be empty, otherwise there is nothing to match against" - ); - - let stream_span = stream.span(); - let mut stream = stream.into_iter(); - let mut extended = TokenStream::new(); - let mut match_cursor = 0; - - while let Some(token) = stream.next() { - match token { - TokenTree::Group(group) => { - match_cursor = 0; - let group_stream = group.stream(); - match expand_in_stream(pattern, tokens, group_stream) { - Ok(s) => { - extended.extend(once(TokenTree::Group(Group::new(group.delimiter(), s)))); - extended.extend(stream); - return Ok(extended); - } - Err(_) => { - extended.extend(once(TokenTree::Group(group))); - } - } - } - other => { - advance_match_cursor(&other, pattern, &mut match_cursor); - - extended.extend(once(other)); - - if match_cursor == pattern.len() { - extended.extend(once( - tokens.take().expect("tokens is used to replace only once"), - )); - extended.extend(stream); - return Ok(extended); - } - } - } - } - // if we reach this point, it means the stream is empty and we haven't found a matching pattern - let msg = format!("Cannot find pattern `{:?}` in given token stream", pattern); - Err(syn::Error::new(stream_span, msg)) -} - -fn advance_match_cursor(other: &TokenTree, pattern: &[TokenTree], match_cursor: &mut usize) { - use TokenTree::{Ident, Punct}; - - let does_match_other_pattern = match (other, &pattern[*match_cursor]) { - (Ident(i1), Ident(i2)) => i1 == i2, - (Punct(p1), Punct(p2)) => p1.as_char() == p2.as_char(), - _ => false, - }; - - if does_match_other_pattern { - *match_cursor += 1; - } else { - *match_cursor = 0; - } -} diff --git a/support/procedural-fork/src/no_bound/clone.rs b/support/procedural-fork/src/no_bound/clone.rs deleted file mode 100644 index 17039bdc87..0000000000 --- a/support/procedural-fork/src/no_bound/clone.rs +++ /dev/null @@ -1,111 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use syn::spanned::Spanned; - -/// Derive Clone but do not bound any generic. -pub fn derive_clone_no_bound(input: proc_macro::TokenStream) -> proc_macro::TokenStream { - let input = syn::parse_macro_input!(input as syn::DeriveInput); - - let name = &input.ident; - let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl(); - - let impl_ = match input.data { - syn::Data::Struct(struct_) => match struct_.fields { - syn::Fields::Named(named) => { - let fields = named.named.iter().map(|i| &i.ident).map(|i| { - quote::quote_spanned!(i.span() => - #i: ::core::clone::Clone::clone(&self.#i) - ) - }); - - quote::quote!( Self { #( #fields, )* } ) - } - syn::Fields::Unnamed(unnamed) => { - let fields = unnamed - .unnamed - .iter() - .enumerate() - .map(|(i, _)| syn::Index::from(i)) - .map(|i| { - quote::quote_spanned!(i.span() => - ::core::clone::Clone::clone(&self.#i) - ) - }); - - quote::quote!( Self ( #( #fields, )* ) ) - } - syn::Fields::Unit => { - quote::quote!(Self) - } - }, - syn::Data::Enum(enum_) => { - let variants = enum_.variants.iter().map(|variant| { - let ident = &variant.ident; - match &variant.fields { - syn::Fields::Named(named) => { - let captured = named.named.iter().map(|i| &i.ident); - let cloned = captured.clone().map(|i| { - ::quote::quote_spanned!(i.span() => - #i: ::core::clone::Clone::clone(#i) - ) - }); - quote::quote!( - Self::#ident { #( ref #captured, )* } => Self::#ident { #( #cloned, )*} - ) - } - syn::Fields::Unnamed(unnamed) => { - let captured = unnamed - .unnamed - .iter() - .enumerate() - .map(|(i, f)| syn::Ident::new(&format!("_{}", i), f.span())); - let cloned = captured.clone().map(|i| { - quote::quote_spanned!(i.span() => - ::core::clone::Clone::clone(#i) - ) - }); - quote::quote!( - Self::#ident ( #( ref #captured, )* ) => Self::#ident ( #( #cloned, )*) - ) - } - syn::Fields::Unit => quote::quote!( Self::#ident => Self::#ident ), - } - }); - - quote::quote!(match self { - #( #variants, )* - }) - } - syn::Data::Union(_) => { - let msg = "Union type not supported by `derive(CloneNoBound)`"; - return syn::Error::new(input.span(), msg).to_compile_error().into(); - } - }; - - quote::quote!( - const _: () = { - #[automatically_derived] - impl #impl_generics ::core::clone::Clone for #name #ty_generics #where_clause { - fn clone(&self) -> Self { - #impl_ - } - } - }; - ) - .into() -} diff --git a/support/procedural-fork/src/no_bound/debug.rs b/support/procedural-fork/src/no_bound/debug.rs deleted file mode 100644 index 8034bb5eca..0000000000 --- a/support/procedural-fork/src/no_bound/debug.rs +++ /dev/null @@ -1,121 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use syn::spanned::Spanned; - -/// Derive Debug but do not bound any generics. -pub fn derive_debug_no_bound(input: proc_macro::TokenStream) -> proc_macro::TokenStream { - let input = syn::parse_macro_input!(input as syn::DeriveInput); - - let input_ident = &input.ident; - let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl(); - - let impl_ = match input.data { - syn::Data::Struct(struct_) => match struct_.fields { - syn::Fields::Named(named) => { - let fields = - named.named.iter().map(|i| &i.ident).map( - |i| quote::quote_spanned!(i.span() => .field(stringify!(#i), &self.#i) ), - ); - - quote::quote!( - fmt.debug_struct(stringify!(#input_ident)) - #( #fields )* - .finish() - ) - } - syn::Fields::Unnamed(unnamed) => { - let fields = unnamed - .unnamed - .iter() - .enumerate() - .map(|(i, _)| syn::Index::from(i)) - .map(|i| quote::quote_spanned!(i.span() => .field(&self.#i) )); - - quote::quote!( - fmt.debug_tuple(stringify!(#input_ident)) - #( #fields )* - .finish() - ) - } - syn::Fields::Unit => quote::quote!(fmt.write_str(stringify!(#input_ident))), - }, - syn::Data::Enum(enum_) => { - let variants = enum_.variants.iter().map(|variant| { - let ident = &variant.ident; - let full_variant_str = format!("{}::{}", input_ident, ident); - match &variant.fields { - syn::Fields::Named(named) => { - let captured = named.named.iter().map(|i| &i.ident); - let debugged = captured.clone().map(|i| { - quote::quote_spanned!(i.span() => - .field(stringify!(#i), &#i) - ) - }); - quote::quote!( - Self::#ident { #( ref #captured, )* } => { - fmt.debug_struct(#full_variant_str) - #( #debugged )* - .finish() - } - ) - } - syn::Fields::Unnamed(unnamed) => { - let captured = unnamed - .unnamed - .iter() - .enumerate() - .map(|(i, f)| syn::Ident::new(&format!("_{}", i), f.span())); - let debugged = captured - .clone() - .map(|i| quote::quote_spanned!(i.span() => .field(&#i))); - quote::quote!( - Self::#ident ( #( ref #captured, )* ) => { - fmt.debug_tuple(#full_variant_str) - #( #debugged )* - .finish() - } - ) - } - syn::Fields::Unit => quote::quote!( - Self::#ident => fmt.write_str(#full_variant_str) - ), - } - }); - - quote::quote!(match *self { - #( #variants, )* - }) - } - syn::Data::Union(_) => { - let msg = "Union type not supported by `derive(DebugNoBound)`"; - return syn::Error::new(input.span(), msg).to_compile_error().into(); - } - }; - - quote::quote!( - const _: () = { - #[automatically_derived] - impl #impl_generics ::core::fmt::Debug for #input_ident #ty_generics #where_clause { - fn fmt(&self, fmt: &mut ::core::fmt::Formatter) -> ::core::fmt::Result { - #impl_ - } - } - }; - ) - .into() -} diff --git a/support/procedural-fork/src/no_bound/default.rs b/support/procedural-fork/src/no_bound/default.rs deleted file mode 100644 index 615268d7bd..0000000000 --- a/support/procedural-fork/src/no_bound/default.rs +++ /dev/null @@ -1,170 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use proc_macro2::Span; -use quote::{quote, quote_spanned}; -use syn::{Data, DeriveInput, Fields, spanned::Spanned}; - -/// Derive Default but do not bound any generic. -pub fn derive_default_no_bound(input: proc_macro::TokenStream) -> proc_macro::TokenStream { - let input = syn::parse_macro_input!(input as DeriveInput); - - let name = &input.ident; - - let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl(); - - let impl_ = match input.data { - Data::Struct(struct_) => match struct_.fields { - Fields::Named(named) => { - let fields = named.named.iter().map(|field| &field.ident).map(|ident| { - quote_spanned! {ident.span() => - #ident: ::core::default::Default::default() - } - }); - - quote!(Self { #( #fields, )* }) - } - Fields::Unnamed(unnamed) => { - let fields = unnamed.unnamed.iter().map(|field| { - quote_spanned! {field.span()=> - ::core::default::Default::default() - } - }); - - quote!(Self( #( #fields, )* )) - } - Fields::Unit => { - quote!(Self) - } - }, - Data::Enum(enum_) => { - if enum_.variants.is_empty() { - return syn::Error::new_spanned(name, "cannot derive Default for an empty enum") - .to_compile_error() - .into(); - } - - // all #[default] attrs with the variant they're on; i.e. a var - let default_variants = enum_ - .variants - .into_iter() - .filter(|variant| { - variant - .attrs - .iter() - .any(|attr| attr.path().is_ident("default")) - }) - .collect::>(); - - match &*default_variants { - [] => return syn::Error::new( - name.clone().span(), - "no default declared, make a variant default by placing `#[default]` above it", - ) - .into_compile_error() - .into(), - // only one variant with the #[default] attribute set - [default_variant] => { - let variant_attrs = default_variant - .attrs - .iter() - .filter(|a| a.path().is_ident("default")) - .collect::>(); - - // check that there is only one #[default] attribute on the variant - if let [first_attr, second_attr, additional_attrs @ ..] = &*variant_attrs { - let mut err = - syn::Error::new(Span::call_site(), "multiple `#[default]` attributes"); - - err.combine(syn::Error::new_spanned( - first_attr, - "`#[default]` used here", - )); - - err.extend([second_attr].into_iter().chain(additional_attrs).map( - |variant| { - syn::Error::new_spanned(variant, "`#[default]` used again here") - }, - )); - - return err.into_compile_error().into(); - } - - let variant_ident = &default_variant.ident; - - let fully_qualified_variant_path = quote!(Self::#variant_ident); - - match &default_variant.fields { - Fields::Named(named) => { - let fields = - named.named.iter().map(|field| &field.ident).map(|ident| { - quote_spanned! {ident.span()=> - #ident: ::core::default::Default::default() - } - }); - - quote!(#fully_qualified_variant_path { #( #fields, )* }) - } - Fields::Unnamed(unnamed) => { - let fields = unnamed.unnamed.iter().map(|field| { - quote_spanned! {field.span()=> - ::core::default::Default::default() - } - }); - - quote!(#fully_qualified_variant_path( #( #fields, )* )) - } - Fields::Unit => fully_qualified_variant_path, - } - } - [first, additional @ ..] => { - let mut err = syn::Error::new(Span::call_site(), "multiple declared defaults"); - - err.combine(syn::Error::new_spanned(first, "first default")); - - err.extend( - additional - .into_iter() - .map(|variant| syn::Error::new_spanned(variant, "additional default")), - ); - - return err.into_compile_error().into(); - } - } - } - Data::Union(union_) => { - return syn::Error::new_spanned( - union_.union_token, - "Union type not supported by `derive(DefaultNoBound)`", - ) - .to_compile_error() - .into(); - } - }; - - quote!( - const _: () = { - #[automatically_derived] - impl #impl_generics ::core::default::Default for #name #ty_generics #where_clause { - fn default() -> Self { - #impl_ - } - } - }; - ) - .into() -} diff --git a/support/procedural-fork/src/no_bound/mod.rs b/support/procedural-fork/src/no_bound/mod.rs deleted file mode 100644 index 9e0377ddaf..0000000000 --- a/support/procedural-fork/src/no_bound/mod.rs +++ /dev/null @@ -1,25 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//! Derive macros to derive traits without bounding generic parameters. - -pub mod clone; -pub mod debug; -pub mod default; -pub mod ord; -pub mod partial_eq; -pub mod partial_ord; diff --git a/support/procedural-fork/src/no_bound/ord.rs b/support/procedural-fork/src/no_bound/ord.rs deleted file mode 100644 index 20f30eb9d5..0000000000 --- a/support/procedural-fork/src/no_bound/ord.rs +++ /dev/null @@ -1,75 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use syn::spanned::Spanned; - -/// Derive Ord but do not bound any generic. -pub fn derive_ord_no_bound(input: proc_macro::TokenStream) -> proc_macro::TokenStream { - let input: syn::DeriveInput = match syn::parse(input) { - Ok(input) => input, - Err(e) => return e.to_compile_error().into(), - }; - - let name = &input.ident; - let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl(); - - let impl_ = match input.data { - syn::Data::Struct(struct_) => match struct_.fields { - syn::Fields::Named(named) => { - let fields = named - .named - .iter() - .map(|i| &i.ident) - .map(|i| quote::quote_spanned!(i.span() => self.#i.cmp(&other.#i) )); - - quote::quote!( core::cmp::Ordering::Equal #( .then_with(|| #fields) )* ) - } - syn::Fields::Unnamed(unnamed) => { - let fields = unnamed - .unnamed - .iter() - .enumerate() - .map(|(i, _)| syn::Index::from(i)) - .map(|i| quote::quote_spanned!(i.span() => self.#i.cmp(&other.#i) )); - - quote::quote!( core::cmp::Ordering::Equal #( .then_with(|| #fields) )* ) - } - syn::Fields::Unit => { - quote::quote!(core::cmp::Ordering::Equal) - } - }, - syn::Data::Enum(_) => { - let msg = "Enum type not supported by `derive(OrdNoBound)`"; - return syn::Error::new(input.span(), msg).to_compile_error().into(); - } - syn::Data::Union(_) => { - let msg = "Union type not supported by `derive(OrdNoBound)`"; - return syn::Error::new(input.span(), msg).to_compile_error().into(); - } - }; - - quote::quote!( - const _: () = { - impl #impl_generics core::cmp::Ord for #name #ty_generics #where_clause { - fn cmp(&self, other: &Self) -> core::cmp::Ordering { - #impl_ - } - } - }; - ) - .into() -} diff --git a/support/procedural-fork/src/no_bound/partial_eq.rs b/support/procedural-fork/src/no_bound/partial_eq.rs deleted file mode 100644 index 8833f6e5f7..0000000000 --- a/support/procedural-fork/src/no_bound/partial_eq.rs +++ /dev/null @@ -1,137 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use syn::spanned::Spanned; - -/// Derive PartialEq but do not bound any generic. -pub fn derive_partial_eq_no_bound(input: proc_macro::TokenStream) -> proc_macro::TokenStream { - let input = syn::parse_macro_input!(input as syn::DeriveInput); - - let name = &input.ident; - let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl(); - - let impl_ = match input.data { - syn::Data::Struct(struct_) => match struct_.fields { - syn::Fields::Named(named) => { - let fields = named - .named - .iter() - .map(|i| &i.ident) - .map(|i| quote::quote_spanned!(i.span() => self.#i == other.#i )); - - quote::quote!( true #( && #fields )* ) - } - syn::Fields::Unnamed(unnamed) => { - let fields = unnamed - .unnamed - .iter() - .enumerate() - .map(|(i, _)| syn::Index::from(i)) - .map(|i| quote::quote_spanned!(i.span() => self.#i == other.#i )); - - quote::quote!( true #( && #fields )* ) - } - syn::Fields::Unit => { - quote::quote!(true) - } - }, - syn::Data::Enum(enum_) => { - let variants = - enum_.variants.iter().map(|variant| { - let ident = &variant.ident; - match &variant.fields { - syn::Fields::Named(named) => { - let names = named.named.iter().map(|i| &i.ident); - let other_names = names.clone().enumerate().map(|(n, ident)| { - syn::Ident::new(&format!("_{}", n), ident.span()) - }); - - let capture = names.clone(); - let other_capture = names - .clone() - .zip(other_names.clone()) - .map(|(i, other_i)| quote::quote!(#i: #other_i)); - let eq = names.zip(other_names).map( - |(i, other_i)| quote::quote_spanned!(i.span() => #i == #other_i), - ); - quote::quote!( - ( - Self::#ident { #( #capture, )* }, - Self::#ident { #( #other_capture, )* }, - ) => true #( && #eq )* - ) - } - syn::Fields::Unnamed(unnamed) => { - let names = unnamed - .unnamed - .iter() - .enumerate() - .map(|(i, f)| syn::Ident::new(&format!("_{}", i), f.span())); - let other_names = - unnamed.unnamed.iter().enumerate().map(|(i, f)| { - syn::Ident::new(&format!("_{}_other", i), f.span()) - }); - let eq = names.clone().zip(other_names.clone()).map( - |(i, other_i)| quote::quote_spanned!(i.span() => #i == #other_i), - ); - quote::quote!( - ( - Self::#ident ( #( #names, )* ), - Self::#ident ( #( #other_names, )* ), - ) => true #( && #eq )* - ) - } - syn::Fields::Unit => quote::quote!( (Self::#ident, Self::#ident) => true ), - } - }); - - let mut different_variants = vec![]; - for (i, i_variant) in enum_.variants.iter().enumerate() { - for (j, j_variant) in enum_.variants.iter().enumerate() { - if i != j { - let i_ident = &i_variant.ident; - let j_ident = &j_variant.ident; - different_variants.push(quote::quote!( - (Self::#i_ident { .. }, Self::#j_ident { .. }) => false - )) - } - } - } - - quote::quote!( match (self, other) { - #( #variants, )* - #( #different_variants, )* - }) - } - syn::Data::Union(_) => { - let msg = "Union type not supported by `derive(PartialEqNoBound)`"; - return syn::Error::new(input.span(), msg).to_compile_error().into(); - } - }; - - quote::quote!( - const _: () = { - #[automatically_derived] - impl #impl_generics ::core::cmp::PartialEq for #name #ty_generics #where_clause { - fn eq(&self, other: &Self) -> bool { - #impl_ - } - } - }; - ) - .into() -} diff --git a/support/procedural-fork/src/no_bound/partial_ord.rs b/support/procedural-fork/src/no_bound/partial_ord.rs deleted file mode 100644 index c73199d4e7..0000000000 --- a/support/procedural-fork/src/no_bound/partial_ord.rs +++ /dev/null @@ -1,90 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use syn::spanned::Spanned; - -/// Derive PartialOrd but do not bound any generic. -pub fn derive_partial_ord_no_bound(input: proc_macro::TokenStream) -> proc_macro::TokenStream { - let input: syn::DeriveInput = match syn::parse(input) { - Ok(input) => input, - Err(e) => return e.to_compile_error().into(), - }; - - let name = &input.ident; - let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl(); - - let impl_ = - match input.data { - syn::Data::Struct(struct_) => { - match struct_.fields { - syn::Fields::Named(named) => { - let fields = named.named.iter().map(|i| &i.ident).map( - |i| quote::quote_spanned!(i.span() => self.#i.partial_cmp(&other.#i)), - ); - - quote::quote!( - Some(core::cmp::Ordering::Equal) - #( - .and_then(|order| { - let next_order = #fields?; - Some(order.then(next_order)) - }) - )* - ) - } - syn::Fields::Unnamed(unnamed) => { - let fields = - unnamed.unnamed.iter().enumerate().map(|(i, _)| syn::Index::from(i)).map( - |i| quote::quote_spanned!(i.span() => self.#i.partial_cmp(&other.#i)), - ); - - quote::quote!( - Some(core::cmp::Ordering::Equal) - #( - .and_then(|order| { - let next_order = #fields?; - Some(order.then(next_order)) - }) - )* - ) - } - syn::Fields::Unit => { - quote::quote!(Some(core::cmp::Ordering::Equal)) - } - } - } - syn::Data::Enum(_) => { - let msg = "Enum type not supported by `derive(PartialOrdNoBound)`"; - return syn::Error::new(input.span(), msg).to_compile_error().into(); - } - syn::Data::Union(_) => { - let msg = "Union type not supported by `derive(PartialOrdNoBound)`"; - return syn::Error::new(input.span(), msg).to_compile_error().into(); - } - }; - - quote::quote!( - const _: () = { - impl #impl_generics core::cmp::PartialOrd for #name #ty_generics #where_clause { - fn partial_cmp(&self, other: &Self) -> Option { - #impl_ - } - } - }; - ) - .into() -} diff --git a/support/procedural-fork/src/pallet/expand/call.rs b/support/procedural-fork/src/pallet/expand/call.rs deleted file mode 100644 index 189eabe4cd..0000000000 --- a/support/procedural-fork/src/pallet/expand/call.rs +++ /dev/null @@ -1,498 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use crate::{ - COUNTER, - pallet::{ - Def, - expand::warnings::{weight_constant_warning, weight_witness_warning}, - parse::call::CallWeightDef, - }, -}; -use proc_macro_warning::Warning; -use proc_macro2::TokenStream as TokenStream2; -use quote::{ToTokens, quote}; -use syn::spanned::Spanned; - -/// -/// * Generate enum call and implement various trait on it. -/// * Implement Callable and call_function on `Pallet` -pub fn expand_call(def: &mut Def) -> proc_macro2::TokenStream { - let (span, where_clause, methods, docs) = match def.call.as_ref() { - Some(call) => { - let span = call.attr_span; - let where_clause = call.where_clause.clone(); - let methods = call.methods.clone(); - let docs = call.docs.clone(); - - (span, where_clause, methods, docs) - } - None => ( - def.item.span(), - def.config.where_clause.clone(), - Vec::new(), - Vec::new(), - ), - }; - let frame_support = &def.frame_support; - let frame_system = &def.frame_system; - let type_impl_gen = &def.type_impl_generics(span); - let type_decl_bounded_gen = &def.type_decl_bounded_generics(span); - let type_use_gen = &def.type_use_generics(span); - let call_ident = syn::Ident::new("Call", span); - let pallet_ident = &def.pallet_struct.pallet; - - let fn_name = methods - .iter() - .map(|method| &method.name) - .collect::>(); - let call_index = methods - .iter() - .map(|method| method.call_index) - .collect::>(); - let new_call_variant_fn_name = fn_name - .iter() - .map(|fn_name| quote::format_ident!("new_call_variant_{}", fn_name)) - .collect::>(); - - let new_call_variant_doc = fn_name - .iter() - .map(|fn_name| format!("Create a call with the variant `{}`.", fn_name)) - .collect::>(); - - let mut call_index_warnings = Vec::new(); - // Emit a warning for each call that is missing `call_index` when not in dev-mode. - for method in &methods { - if method.explicit_call_index || def.dev_mode { - continue; - } - - let warning = Warning::new_deprecated("ImplicitCallIndex") - .index(call_index_warnings.len()) - .old("use implicit call indices") - .new("ensure that all calls have a `pallet::call_index` attribute or put the pallet into `dev` mode") - .help_links(&[ - "https://github.com/paritytech/substrate/pull/12891", - "https://github.com/paritytech/substrate/pull/11381" - ]) - .span(method.name.span()) - .build_or_panic(); - call_index_warnings.push(warning); - } - - let mut fn_weight = Vec::::new(); - let mut weight_warnings = Vec::new(); - for method in &methods { - match &method.weight { - CallWeightDef::DevModeDefault => fn_weight.push(syn::parse_quote!(0)), - CallWeightDef::Immediate(e) => { - weight_constant_warning(e, def.dev_mode, &mut weight_warnings); - weight_witness_warning(method, def.dev_mode, &mut weight_warnings); - - fn_weight.push(e.into_token_stream()); - } - CallWeightDef::Inherited => { - let pallet_weight = def - .call - .as_ref() - .expect("we have methods; we have calls; qed") - .inherited_call_weight - .as_ref() - .expect("the parser prevents this"); - - // Expand `<::WeightInfo>::call_name()`. - let t = &pallet_weight.typename; - let n = &method.name; - fn_weight.push(quote!({ < #t > :: #n () })); - } - } - } - debug_assert_eq!(fn_weight.len(), methods.len()); - - let fn_doc = methods - .iter() - .map(|method| &method.docs) - .collect::>(); - - let args_name = methods - .iter() - .map(|method| { - method - .args - .iter() - .map(|(_, name, _)| name.clone()) - .collect::>() - }) - .collect::>(); - - let args_name_stripped = methods - .iter() - .map(|method| { - method - .args - .iter() - .map(|(_, name, _)| { - syn::Ident::new(name.to_string().trim_start_matches('_'), name.span()) - }) - .collect::>() - }) - .collect::>(); - - let make_args_name_pattern = |ref_tok| { - args_name - .iter() - .zip(args_name_stripped.iter()) - .map(|(args_name, args_name_stripped)| { - args_name - .iter() - .zip(args_name_stripped) - .map(|(args_name, args_name_stripped)| { - if args_name == args_name_stripped { - quote::quote!( #ref_tok #args_name ) - } else { - quote::quote!( #args_name_stripped: #ref_tok #args_name ) - } - }) - .collect::>() - }) - .collect::>() - }; - - let args_name_pattern = make_args_name_pattern(None); - let args_name_pattern_ref = make_args_name_pattern(Some(quote::quote!(ref))); - - let args_type = methods - .iter() - .map(|method| { - method - .args - .iter() - .map(|(_, _, type_)| type_.clone()) - .collect::>() - }) - .collect::>(); - - let args_compact_attr = methods.iter().map(|method| { - method - .args - .iter() - .map(|(is_compact, _, type_)| { - if *is_compact { - quote::quote_spanned!(type_.span() => #[codec(compact)] ) - } else { - quote::quote!() - } - }) - .collect::>() - }); - - let default_docs = [syn::parse_quote!( - r"Contains a variant per dispatchable extrinsic that this pallet has." - )]; - let docs = if docs.is_empty() { - &default_docs[..] - } else { - &docs[..] - }; - - let maybe_compile_error = if def.call.is_none() { - quote::quote! { - compile_error!(concat!( - "`", - stringify!($pallet_name), - "` does not have #[pallet::call] defined, perhaps you should remove `Call` from \ - construct_runtime?", - )); - } - } else { - proc_macro2::TokenStream::new() - }; - - let count = COUNTER.with(|counter| counter.borrow_mut().inc()); - let macro_ident = syn::Ident::new(&format!("__is_call_part_defined_{}", count), span); - - let capture_docs = if cfg!(feature = "no-metadata-docs") { - "never" - } else { - "always" - }; - - // Wrap all calls inside of storage layers - if let Some(syn::Item::Impl(item_impl)) = def - .call - .as_ref() - .map(|c| &mut def.item.content.as_mut().expect("Checked by def parser").1[c.index]) - { - item_impl.items.iter_mut().for_each(|i| { - if let syn::ImplItem::Fn(method) = i { - let block = &method.block; - method.block = syn::parse_quote! {{ - // We execute all dispatchable in a new storage layer, allowing them - // to return an error at any point, and undoing any storage changes. - #frame_support::storage::with_storage_layer(|| #block) - }}; - } - }); - } - - // Extracts #[allow] attributes, necessary so that we don't run into compiler warnings - let maybe_allow_attrs = methods - .iter() - .map(|method| { - method - .attrs - .iter() - .find(|attr| attr.path().is_ident("allow")) - .map_or(proc_macro2::TokenStream::new(), |attr| { - attr.to_token_stream() - }) - }) - .collect::>(); - - let cfg_attrs = methods - .iter() - .map(|method| { - let attrs = method - .cfg_attrs - .iter() - .map(|attr| attr.to_token_stream()) - .collect::>(); - quote::quote!( #( #attrs )* ) - }) - .collect::>(); - - let feeless_check = methods - .iter() - .map(|method| &method.feeless_check) - .collect::>(); - let feeless_check_result = - feeless_check - .iter() - .zip(args_name.iter()) - .map(|(feeless_check, arg_name)| { - if let Some(feeless_check) = feeless_check { - quote::quote!(#feeless_check(origin, #( #arg_name, )*)) - } else { - quote::quote!(false) - } - }); - - quote::quote_spanned!(span => - #[doc(hidden)] - mod warnings { - #( - #call_index_warnings - )* - #( - #weight_warnings - )* - } - - #[allow(unused_imports)] - #[doc(hidden)] - pub mod __substrate_call_check { - #[macro_export] - #[doc(hidden)] - macro_rules! #macro_ident { - ($pallet_name:ident) => { - #maybe_compile_error - }; - } - - #[doc(hidden)] - pub use #macro_ident as is_call_part_defined; - } - - #( #[doc = #docs] )* - #[derive( - #frame_support::RuntimeDebugNoBound, - #frame_support::CloneNoBound, - #frame_support::EqNoBound, - #frame_support::PartialEqNoBound, - #frame_support::__private::codec::Encode, - #frame_support::__private::codec::Decode, - #frame_support::__private::scale_info::TypeInfo, - )] - #[codec(encode_bound())] - #[codec(decode_bound())] - #[scale_info(skip_type_params(#type_use_gen), capture_docs = #capture_docs)] - #[allow(non_camel_case_types)] - pub enum #call_ident<#type_decl_bounded_gen> #where_clause { - #[doc(hidden)] - #[codec(skip)] - __Ignore( - ::core::marker::PhantomData<(#type_use_gen,)>, - #frame_support::Never, - ), - #( - #cfg_attrs - #( #[doc = #fn_doc] )* - #[codec(index = #call_index)] - #fn_name { - #( - #[allow(missing_docs)] - #args_compact_attr #args_name_stripped: #args_type - ),* - }, - )* - } - - impl<#type_impl_gen> #call_ident<#type_use_gen> #where_clause { - #( - #cfg_attrs - #[doc = #new_call_variant_doc] - pub fn #new_call_variant_fn_name( - #( #args_name_stripped: #args_type ),* - ) -> Self { - Self::#fn_name { - #( #args_name_stripped ),* - } - } - )* - } - - impl<#type_impl_gen> #frame_support::dispatch::GetDispatchInfo - for #call_ident<#type_use_gen> - #where_clause - { - fn get_dispatch_info(&self) -> #frame_support::dispatch::DispatchInfo { - match *self { - #( - #cfg_attrs - Self::#fn_name { #( #args_name_pattern_ref, )* } => { - let __pallet_base_weight = #fn_weight; - - let __pallet_weight = < - dyn #frame_support::dispatch::WeighData<( #( & #args_type, )* )> - >::weigh_data(&__pallet_base_weight, ( #( #args_name, )* )); - - let __pallet_class = < - dyn #frame_support::dispatch::ClassifyDispatch< - ( #( & #args_type, )* ) - > - >::classify_dispatch(&__pallet_base_weight, ( #( #args_name, )* )); - - let __pallet_pays_fee = < - dyn #frame_support::dispatch::PaysFee<( #( & #args_type, )* )> - >::pays_fee(&__pallet_base_weight, ( #( #args_name, )* )); - - #frame_support::dispatch::DispatchInfo { - weight: __pallet_weight, - class: __pallet_class, - pays_fee: __pallet_pays_fee, - } - }, - )* - Self::__Ignore(_, _) => unreachable!("__Ignore cannot be used"), - } - } - } - - impl<#type_impl_gen> #frame_support::dispatch::CheckIfFeeless for #call_ident<#type_use_gen> - #where_clause - { - type Origin = #frame_system::pallet_prelude::OriginFor; - #[allow(unused_variables)] - fn is_feeless(&self, origin: &Self::Origin) -> bool { - match *self { - #( - #cfg_attrs - Self::#fn_name { #( #args_name_pattern_ref, )* } => { - #feeless_check_result - }, - )* - Self::__Ignore(_, _) => unreachable!("__Ignore cannot be used"), - } - } - } - - impl<#type_impl_gen> #frame_support::traits::GetCallName for #call_ident<#type_use_gen> - #where_clause - { - fn get_call_name(&self) -> &'static str { - match *self { - #( #cfg_attrs Self::#fn_name { .. } => stringify!(#fn_name), )* - Self::__Ignore(_, _) => unreachable!("__PhantomItem cannot be used."), - } - } - - fn get_call_names() -> &'static [&'static str] { - &[ #( #cfg_attrs stringify!(#fn_name), )* ] - } - } - - impl<#type_impl_gen> #frame_support::traits::GetCallIndex for #call_ident<#type_use_gen> - #where_clause - { - fn get_call_index(&self) -> u8 { - match *self { - #( #cfg_attrs Self::#fn_name { .. } => #call_index, )* - Self::__Ignore(_, _) => unreachable!("__PhantomItem cannot be used."), - } - } - - fn get_call_indices() -> &'static [u8] { - &[ #( #cfg_attrs #call_index, )* ] - } - } - - impl<#type_impl_gen> #frame_support::traits::UnfilteredDispatchable - for #call_ident<#type_use_gen> - #where_clause - { - type RuntimeOrigin = #frame_system::pallet_prelude::OriginFor; - fn dispatch_bypass_filter( - self, - origin: Self::RuntimeOrigin - ) -> #frame_support::dispatch::DispatchResultWithPostInfo { - #frame_support::dispatch_context::run_in_context(|| { - match self { - #( - #cfg_attrs - Self::#fn_name { #( #args_name_pattern, )* } => { - #frame_support::__private::sp_tracing::enter_span!( - #frame_support::__private::sp_tracing::trace_span!(stringify!(#fn_name)) - ); - #maybe_allow_attrs - <#pallet_ident<#type_use_gen>>::#fn_name(origin, #( #args_name, )* ) - .map(Into::into).map_err(Into::into) - }, - )* - Self::__Ignore(_, _) => { - let _ = origin; // Use origin for empty Call enum - unreachable!("__PhantomItem cannot be used."); - }, - } - }) - } - } - - impl<#type_impl_gen> #frame_support::dispatch::Callable for #pallet_ident<#type_use_gen> - #where_clause - { - type RuntimeCall = #call_ident<#type_use_gen>; - } - - impl<#type_impl_gen> #pallet_ident<#type_use_gen> #where_clause { - #[allow(dead_code)] - #[doc(hidden)] - pub fn call_functions() -> #frame_support::__private::metadata_ir::PalletCallMetadataIR { - #frame_support::__private::scale_info::meta_type::<#call_ident<#type_use_gen>>().into() - } - } - ) -} diff --git a/support/procedural-fork/src/pallet/expand/composite.rs b/support/procedural-fork/src/pallet/expand/composite.rs deleted file mode 100644 index 49c0ad6758..0000000000 --- a/support/procedural-fork/src/pallet/expand/composite.rs +++ /dev/null @@ -1,40 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use crate::pallet::Def; -use proc_macro2::TokenStream; - -/// Expands `composite_enum` and adds the `VariantCount` implementation for it. -pub fn expand_composites(def: &mut Def) -> TokenStream { - let mut expand = quote::quote!(); - let frame_support = &def.frame_support; - - for composite in &def.composites { - let name = &composite.ident; - let (impl_generics, ty_generics, where_clause) = composite.generics.split_for_impl(); - let variants_count = composite.variant_count; - - // add `VariantCount` implementation for `composite_enum` - expand.extend(quote::quote_spanned!(composite.attr_span => - impl #impl_generics #frame_support::traits::VariantCount for #name #ty_generics #where_clause { - const VARIANT_COUNT: u32 = #variants_count; - } - )); - } - - expand -} diff --git a/support/procedural-fork/src/pallet/expand/config.rs b/support/procedural-fork/src/pallet/expand/config.rs deleted file mode 100644 index dbaf709e88..0000000000 --- a/support/procedural-fork/src/pallet/expand/config.rs +++ /dev/null @@ -1,97 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use crate::pallet::Def; -use proc_macro2::TokenStream; -use quote::quote; -use syn::{Item, parse_quote}; - -/// -/// * Generate default rust doc -pub fn expand_config(def: &mut Def) -> TokenStream { - let config = &def.config; - let config_item = { - let item = &mut def.item.content.as_mut().expect("Checked by def parser").1[config.index]; - if let Item::Trait(item) = item { - item - } else { - unreachable!("Checked by config parser") - } - }; - - config_item.attrs.insert( - 0, - parse_quote!( - #[doc = r" -Configuration trait of this pallet. - -The main purpose of this trait is to act as an interface between this pallet and the runtime in -which it is embedded in. A type, function, or constant in this trait is essentially left to be -configured by the runtime that includes this pallet. - -Consequently, a runtime that wants to include this pallet must implement this trait." - ] - ), - ); - - // we only emit `DefaultConfig` if there are trait items, so an empty `DefaultConfig` is - // impossible consequently. - match &config.default_sub_trait { - Some(default_sub_trait) if default_sub_trait.items.len() > 0 => { - let trait_items = &default_sub_trait - .items - .iter() - .map(|item| { - if item.1 { - if let syn::TraitItem::Type(item) = item.0.clone() { - let mut item = item.clone(); - item.bounds.clear(); - syn::TraitItem::Type(item) - } else { - item.0.clone() - } - } else { - item.0.clone() - } - }) - .collect::>(); - - let type_param_bounds = if default_sub_trait.has_system { - let system = &def.frame_system; - quote::quote!(: #system::DefaultConfig) - } else { - quote::quote!() - }; - - quote!( - /// Based on [`Config`]. Auto-generated by - /// [`#[pallet::config(with_default)]`](`frame_support::pallet_macros::config`). - /// Can be used in tandem with - /// [`#[register_default_config]`](`frame_support::register_default_config`) and - /// [`#[derive_impl]`](`frame_support::derive_impl`) to derive test config traits - /// based on existing pallet config traits in a safe and developer-friendly way. - /// - /// See [here](`frame_support::pallet_macros::config`) for more information and caveats about - /// the auto-generated `DefaultConfig` trait and how it is generated. - pub trait DefaultConfig #type_param_bounds { - #(#trait_items)* - } - ) - } - _ => Default::default(), - } -} diff --git a/support/procedural-fork/src/pallet/expand/constants.rs b/support/procedural-fork/src/pallet/expand/constants.rs deleted file mode 100644 index 19862a8a6c..0000000000 --- a/support/procedural-fork/src/pallet/expand/constants.rs +++ /dev/null @@ -1,115 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use crate::pallet::Def; - -struct ConstDef { - /// Name of the associated type. - pub ident: syn::Ident, - /// The type in Get, e.g. `u32` in `type Foo: Get;`, but `Self` is replaced by `T` - pub type_: syn::Type, - /// The doc associated - pub doc: Vec, - /// default_byte implementation - pub default_byte_impl: proc_macro2::TokenStream, - /// Constant name for Metadata (optional) - pub metadata_name: Option, -} - -/// Implement the `pallet_constants_metadata` function for the pallet. -pub fn expand_constants(def: &mut Def) -> proc_macro2::TokenStream { - let frame_support = &def.frame_support; - let type_impl_gen = &def.type_impl_generics(proc_macro2::Span::call_site()); - let type_use_gen = &def.type_use_generics(proc_macro2::Span::call_site()); - let pallet_ident = &def.pallet_struct.pallet; - let trait_use_gen = &def.trait_use_generics(proc_macro2::Span::call_site()); - - let mut where_clauses = vec![&def.config.where_clause]; - where_clauses.extend(def.extra_constants.iter().map(|d| &d.where_clause)); - let completed_where_clause = super::merge_where_clauses(&where_clauses); - - let config_consts = def.config.consts_metadata.iter().map(|const_| { - let ident = &const_.ident; - let const_type = &const_.type_; - - ConstDef { - ident: const_.ident.clone(), - type_: const_.type_.clone(), - doc: const_.doc.clone(), - default_byte_impl: quote::quote!( - let value = <::#ident as - #frame_support::traits::Get<#const_type>>::get(); - #frame_support::__private::codec::Encode::encode(&value) - ), - metadata_name: None, - } - }); - - let extra_consts = def - .extra_constants - .iter() - .flat_map(|d| &d.extra_constants) - .map(|const_| { - let ident = &const_.ident; - - ConstDef { - ident: const_.ident.clone(), - type_: const_.type_.clone(), - doc: const_.doc.clone(), - default_byte_impl: quote::quote!( - let value = >::#ident(); - #frame_support::__private::codec::Encode::encode(&value) - ), - metadata_name: const_.metadata_name.clone(), - } - }); - - let consts = config_consts.chain(extra_consts).map(|const_| { - let const_type = &const_.type_; - let ident_str = format!("{}", const_.metadata_name.unwrap_or(const_.ident)); - - let no_docs = vec![]; - let doc = if cfg!(feature = "no-metadata-docs") { - &no_docs - } else { - &const_.doc - }; - - let default_byte_impl = &const_.default_byte_impl; - - quote::quote!({ - #frame_support::__private::metadata_ir::PalletConstantMetadataIR { - name: #ident_str, - ty: #frame_support::__private::scale_info::meta_type::<#const_type>(), - value: { #default_byte_impl }, - docs: #frame_support::__private::vec![ #( #doc ),* ], - } - }) - }); - - quote::quote!( - impl<#type_impl_gen> #pallet_ident<#type_use_gen> #completed_where_clause{ - - #[doc(hidden)] - pub fn pallet_constants_metadata() - -> #frame_support::__private::Vec<#frame_support::__private::metadata_ir::PalletConstantMetadataIR> - { - #frame_support::__private::vec![ #( #consts ),* ] - } - } - ) -} diff --git a/support/procedural-fork/src/pallet/expand/doc_only.rs b/support/procedural-fork/src/pallet/expand/doc_only.rs deleted file mode 100644 index 3e60e9a9b5..0000000000 --- a/support/procedural-fork/src/pallet/expand/doc_only.rs +++ /dev/null @@ -1,103 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use proc_macro2::Span; - -use crate::pallet::Def; - -pub fn expand_doc_only(def: &mut Def) -> proc_macro2::TokenStream { - let dispatchables = if let Some(call_def) = &def.call { - let type_impl_generics = def.type_impl_generics(Span::call_site()); - call_def - .methods - .iter() - .map(|method| { - let name = &method.name; - let args = &method - .args - .iter() - .map(|(_, arg_name, arg_type)| quote::quote!( #arg_name: #arg_type, )) - .collect::(); - let docs = &method.docs; - - let real = format!(" [`Pallet::{}`].", name); - quote::quote!( - #( #[doc = #docs] )* - /// - /// # Warning: Doc-Only - /// - /// This function is an automatically generated, and is doc-only, uncallable - /// stub. See the real version in - #[ doc = #real ] - pub fn #name<#type_impl_generics>(#args) { unreachable!(); } - ) - }) - .collect::() - } else { - quote::quote!() - }; - - let storage_types = def - .storages - .iter() - .map(|storage| { - let storage_name = &storage.ident; - let storage_type_docs = &storage.docs; - let real = format!("[`pallet::{}`].", storage_name); - quote::quote!( - #( #[doc = #storage_type_docs] )* - /// - /// # Warning: Doc-Only - /// - /// This type is automatically generated, and is doc-only. See the real version in - #[ doc = #real ] - pub struct #storage_name(); - ) - }) - .collect::(); - - quote::quote!( - /// Auto-generated docs-only module listing all (public and private) defined storage types - /// for this pallet. - /// - /// # Warning: Doc-Only - /// - /// Members of this module cannot be used directly and are only provided for documentation - /// purposes. - /// - /// To see the actual storage type, find a struct with the same name at the root of the - /// pallet, in the list of [*Type Definitions*](../index.html#types). - #[cfg(doc)] - pub mod storage_types { - use super::*; - #storage_types - } - - /// Auto-generated docs-only module listing all defined dispatchables for this pallet. - /// - /// # Warning: Doc-Only - /// - /// Members of this module cannot be used directly and are only provided for documentation - /// purposes. To see the real version of each dispatchable, look for them in [`Pallet`] or - /// [`Call`]. - #[cfg(doc)] - pub mod dispatchables { - use super::*; - #dispatchables - } - ) -} diff --git a/support/procedural-fork/src/pallet/expand/documentation.rs b/support/procedural-fork/src/pallet/expand/documentation.rs deleted file mode 100644 index f1b91c5f2a..0000000000 --- a/support/procedural-fork/src/pallet/expand/documentation.rs +++ /dev/null @@ -1,175 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use crate::pallet::Def; -use proc_macro2::TokenStream; -use quote::ToTokens; -use syn::{Attribute, Lit, LitStr, spanned::Spanned}; - -const DOC: &'static str = "doc"; -const PALLET_DOC: &'static str = "pallet_doc"; - -/// Get the documentation file path from the `pallet_doc` attribute. -/// -/// Supported format: -/// `#[pallet_doc(PATH)]`: The path of the file from which the documentation is loaded -fn parse_pallet_doc_value(attr: &Attribute) -> syn::Result { - let lit: syn::LitStr = attr.parse_args().map_err(|_| { - let msg = "The `pallet_doc` received an unsupported argument. Supported format: `pallet_doc(\"PATH\")`"; - syn::Error::new(attr.span(), msg) - })?; - - Ok(DocMetaValue::Path(lit)) -} - -/// Get the value from the `doc` comment attribute: -/// -/// Supported formats: -/// - `#[doc = "A doc string"]`: Documentation as a string literal -/// - `#[doc = include_str!(PATH)]`: Documentation obtained from a path -fn parse_doc_value(attr: &Attribute) -> syn::Result> { - if !attr.path().is_ident(DOC) { - return Ok(None); - } - - let meta = attr.meta.require_name_value()?; - - match &meta.value { - syn::Expr::Lit(lit) => Ok(Some(DocMetaValue::Lit(lit.lit.clone()))), - syn::Expr::Macro(mac) if mac.mac.path.is_ident("include_str") => { - Ok(Some(DocMetaValue::Path(mac.mac.parse_body()?))) - } - _ => Err(syn::Error::new( - attr.span(), - "Expected `= \"docs\"` or `= include_str!(\"PATH\")`", - )), - } -} - -/// Supported documentation tokens. -#[derive(Debug)] -enum DocMetaValue { - /// Documentation with string literals. - /// - /// `#[doc = "Lit"]` - Lit(Lit), - /// Documentation with `include_str!` macro. - /// - /// The string literal represents the file `PATH`. - /// - /// `#[doc = include_str!(PATH)]` - Path(LitStr), -} - -impl ToTokens for DocMetaValue { - fn to_tokens(&self, tokens: &mut TokenStream) { - match self { - DocMetaValue::Lit(lit) => lit.to_tokens(tokens), - DocMetaValue::Path(path_lit) => { - let decl = quote::quote!(include_str!(#path_lit)); - tokens.extend(decl) - } - } - } -} - -/// Extract the documentation from the given pallet definition -/// to include in the runtime metadata. -/// -/// Implement a `pallet_documentation_metadata` function to fetch the -/// documentation that is included in the metadata. -/// -/// The documentation is placed on the pallet similar to: -/// -/// ```ignore -/// #[pallet] -/// /// Documentation for pallet -/// #[doc = "Documentation for pallet"] -/// #[doc = include_str!("../README.md")] -/// #[pallet_doc("../documentation1.md")] -/// #[pallet_doc("../documentation2.md")] -/// pub mod pallet {} -/// ``` -/// -/// # pallet_doc -/// -/// The `pallet_doc` attribute can only be provided with one argument, -/// which is the file path that holds the documentation to be added to the metadata. -/// -/// Unlike the `doc` attribute, the documentation provided to the `proc_macro` attribute is -/// not added to the pallet. -pub fn expand_documentation(def: &mut Def) -> proc_macro2::TokenStream { - let frame_support = &def.frame_support; - let type_impl_gen = &def.type_impl_generics(proc_macro2::Span::call_site()); - let type_use_gen = &def.type_use_generics(proc_macro2::Span::call_site()); - let pallet_ident = &def.pallet_struct.pallet; - let where_clauses = &def.config.where_clause; - - // TODO: Use [drain_filter](https://doc.rust-lang.org/std/vec/struct.Vec.html#method.drain_filter) when it is stable. - - // The `pallet_doc` attributes are excluded from the generation of the pallet, - // but they are included in the runtime metadata. - let mut pallet_docs = Vec::with_capacity(def.item.attrs.len()); - let mut index = 0; - while index < def.item.attrs.len() { - let attr = &def.item.attrs[index]; - if attr.path().get_ident().map_or(false, |i| *i == PALLET_DOC) { - pallet_docs.push(def.item.attrs.remove(index)); - // Do not increment the index, we have just removed the - // element from the attributes. - continue; - } - - index += 1; - } - - // Capture the `#[doc = include_str!("../README.md")]` and `#[doc = "Documentation"]`. - let docs = match def - .item - .attrs - .iter() - .filter_map(|v| parse_doc_value(v).transpose()) - .collect::>>() - { - Ok(r) => r, - Err(err) => return err.into_compile_error(), - }; - - // Capture the `#[pallet_doc("../README.md")]`. - let pallet_docs = match pallet_docs - .into_iter() - .map(|attr| parse_pallet_doc_value(&attr)) - .collect::>>() - { - Ok(docs) => docs, - Err(err) => return err.into_compile_error(), - }; - - let docs = docs.iter().chain(pallet_docs.iter()); - - quote::quote!( - impl<#type_impl_gen> #pallet_ident<#type_use_gen> #where_clauses{ - - #[doc(hidden)] - pub fn pallet_documentation_metadata() - -> #frame_support::__private::Vec<&'static str> - { - #frame_support::__private::vec![ #( #docs ),* ] - } - } - ) -} diff --git a/support/procedural-fork/src/pallet/expand/error.rs b/support/procedural-fork/src/pallet/expand/error.rs deleted file mode 100644 index e68b8663f6..0000000000 --- a/support/procedural-fork/src/pallet/expand/error.rs +++ /dev/null @@ -1,197 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use crate::{ - COUNTER, - pallet::{ - Def, - parse::error::{VariantDef, VariantField}, - }, -}; -use frame_support_procedural_tools::get_doc_literals; -use quote::ToTokens; -use syn::spanned::Spanned; - -/// -/// * impl various trait on Error -pub fn expand_error(def: &mut Def) -> proc_macro2::TokenStream { - let count = COUNTER.with(|counter| counter.borrow_mut().inc()); - let error_token_unique_id = - syn::Ident::new(&format!("__tt_error_token_{}", count), def.item.span()); - - let frame_support = &def.frame_support; - let frame_system = &def.frame_system; - let config_where_clause = &def.config.where_clause; - - let error = if let Some(error) = &def.error { - error - } else { - return quote::quote! { - #[macro_export] - #[doc(hidden)] - macro_rules! #error_token_unique_id { - { - $caller:tt - your_tt_return = [{ $my_tt_return:path }] - } => { - $my_tt_return! { - $caller - } - }; - } - - pub use #error_token_unique_id as tt_error_token; - }; - }; - - let error_ident = &error.error; - let type_impl_gen = &def.type_impl_generics(error.attr_span); - let type_use_gen = &def.type_use_generics(error.attr_span); - - let phantom_variant: syn::Variant = syn::parse_quote!( - #[doc(hidden)] - #[codec(skip)] - __Ignore( - core::marker::PhantomData<(#type_use_gen)>, - #frame_support::Never, - ) - ); - - let as_str_matches = - error - .variants - .iter() - .map(|VariantDef { ident: variant, field: field_ty, cfg_attrs }| { - let variant_str = variant.to_string(); - let cfg_attrs = cfg_attrs.iter().map(|attr| attr.to_token_stream()); - match field_ty { - Some(VariantField { is_named: true }) => { - quote::quote_spanned!(error.attr_span => #( #cfg_attrs )* Self::#variant { .. } => #variant_str,) - }, - Some(VariantField { is_named: false }) => { - quote::quote_spanned!(error.attr_span => #( #cfg_attrs )* Self::#variant(..) => #variant_str,) - }, - None => { - quote::quote_spanned!(error.attr_span => #( #cfg_attrs )* Self::#variant => #variant_str,) - }, - } - }); - - let error_item = { - let item = &mut def.item.content.as_mut().expect("Checked by def parser").1[error.index]; - if let syn::Item::Enum(item) = item { - item - } else { - unreachable!("Checked by error parser") - } - }; - - error_item.variants.insert(0, phantom_variant); - - let capture_docs = if cfg!(feature = "no-metadata-docs") { - "never" - } else { - "always" - }; - - // derive TypeInfo for error metadata - error_item.attrs.push(syn::parse_quote! { - #[derive( - #frame_support::__private::codec::Encode, - #frame_support::__private::codec::Decode, - #frame_support::__private::scale_info::TypeInfo, - #frame_support::PalletError, - )] - }); - error_item.attrs.push(syn::parse_quote!( - #[scale_info(skip_type_params(#type_use_gen), capture_docs = #capture_docs)] - )); - - if get_doc_literals(&error_item.attrs).is_empty() { - error_item.attrs.push(syn::parse_quote!( - #[doc = "The `Error` enum of this pallet."] - )); - } - - quote::quote_spanned!(error.attr_span => - impl<#type_impl_gen> core::fmt::Debug for #error_ident<#type_use_gen> - #config_where_clause - { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) - -> core::fmt::Result - { - f.write_str(self.as_str()) - } - } - - impl<#type_impl_gen> #error_ident<#type_use_gen> #config_where_clause { - #[doc(hidden)] - pub fn as_str(&self) -> &'static str { - match &self { - Self::__Ignore(_, _) => unreachable!("`__Ignore` can never be constructed"), - #( #as_str_matches )* - } - } - } - - impl<#type_impl_gen> From<#error_ident<#type_use_gen>> for &'static str - #config_where_clause - { - fn from(err: #error_ident<#type_use_gen>) -> &'static str { - err.as_str() - } - } - - impl<#type_impl_gen> From<#error_ident<#type_use_gen>> - for #frame_support::sp_runtime::DispatchError - #config_where_clause - { - fn from(err: #error_ident<#type_use_gen>) -> Self { - use #frame_support::__private::codec::Encode; - let index = < - ::PalletInfo - as #frame_support::traits::PalletInfo - >::index::>() - .expect("Every active module has an index in the runtime; qed") as u8; - let mut encoded = err.encode(); - encoded.resize(#frame_support::MAX_MODULE_ERROR_ENCODED_SIZE, 0); - - #frame_support::sp_runtime::DispatchError::Module(#frame_support::sp_runtime::ModuleError { - index, - error: TryInto::try_into(encoded).expect("encoded error is resized to be equal to the maximum encoded error size; qed"), - message: Some(err.as_str()), - }) - } - } - - #[macro_export] - #[doc(hidden)] - macro_rules! #error_token_unique_id { - { - $caller:tt - your_tt_return = [{ $my_tt_return:path }] - } => { - $my_tt_return! { - $caller - error = [{ #error_ident }] - } - }; - } - - pub use #error_token_unique_id as tt_error_token; - ) -} diff --git a/support/procedural-fork/src/pallet/expand/event.rs b/support/procedural-fork/src/pallet/expand/event.rs deleted file mode 100644 index 8b75f2d45a..0000000000 --- a/support/procedural-fork/src/pallet/expand/event.rs +++ /dev/null @@ -1,185 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use crate::{ - COUNTER, - pallet::{Def, parse::event::PalletEventDepositAttr}, -}; -use frame_support_procedural_tools::get_doc_literals; -use syn::{Ident, spanned::Spanned}; - -/// -/// * Add __Ignore variant on Event -/// * Impl various trait on Event including metadata -/// * if deposit_event is defined, implement deposit_event on module. -pub fn expand_event(def: &mut Def) -> proc_macro2::TokenStream { - let count = COUNTER.with(|counter| counter.borrow_mut().inc()); - - let (event, macro_ident) = if let Some(event) = &def.event { - let ident = Ident::new( - &format!("__is_event_part_defined_{}", count), - event.attr_span, - ); - (event, ident) - } else { - let macro_ident = Ident::new( - &format!("__is_event_part_defined_{}", count), - def.item.span(), - ); - - return quote::quote! { - #[doc(hidden)] - pub mod __substrate_event_check { - #[macro_export] - #[doc(hidden)] - macro_rules! #macro_ident { - ($pallet_name:ident) => { - compile_error!(concat!( - "`", - stringify!($pallet_name), - "` does not have #[pallet::event] defined, perhaps you should \ - remove `Event` from construct_runtime?", - )); - } - } - - #[doc(hidden)] - pub use #macro_ident as is_event_part_defined; - } - }; - }; - - let event_where_clause = &event.where_clause; - - // NOTE: actually event where clause must be a subset of config where clause because of - // `type RuntimeEvent: From>`. But we merge either way for potential better error - // message - let completed_where_clause = - super::merge_where_clauses(&[&event.where_clause, &def.config.where_clause]); - - let event_ident = &event.event; - let frame_system = &def.frame_system; - let frame_support = &def.frame_support; - let event_use_gen = &event.gen_kind.type_use_gen(event.attr_span); - let event_impl_gen = &event.gen_kind.type_impl_gen(event.attr_span); - - let event_item = { - let item = &mut def.item.content.as_mut().expect("Checked by def parser").1[event.index]; - if let syn::Item::Enum(item) = item { - item - } else { - unreachable!("Checked by event parser") - } - }; - - // Phantom data is added for generic event. - if event.gen_kind.is_generic() { - let variant = syn::parse_quote!( - #[doc(hidden)] - #[codec(skip)] - __Ignore( - ::core::marker::PhantomData<(#event_use_gen)>, - #frame_support::Never, - ) - ); - - // Push ignore variant at the end. - event_item.variants.push(variant); - } - - if get_doc_literals(&event_item.attrs).is_empty() { - event_item - .attrs - .push(syn::parse_quote!(#[doc = "The `Event` enum of this pallet"])); - } - - // derive some traits because system event require Clone, FullCodec, Eq, PartialEq and Debug - event_item.attrs.push(syn::parse_quote!( - #[derive( - #frame_support::CloneNoBound, - #frame_support::EqNoBound, - #frame_support::PartialEqNoBound, - #frame_support::RuntimeDebugNoBound, - #frame_support::__private::codec::Encode, - #frame_support::__private::codec::Decode, - #frame_support::__private::scale_info::TypeInfo, - )] - )); - - let capture_docs = if cfg!(feature = "no-metadata-docs") { - "never" - } else { - "always" - }; - - // skip requirement for type params to implement `TypeInfo`, and set docs capture - event_item.attrs.push(syn::parse_quote!( - #[scale_info(skip_type_params(#event_use_gen), capture_docs = #capture_docs)] - )); - - let deposit_event = if let Some(deposit_event) = &event.deposit_event { - let event_use_gen = &event.gen_kind.type_use_gen(event.attr_span); - let trait_use_gen = &def.trait_use_generics(event.attr_span); - let type_impl_gen = &def.type_impl_generics(event.attr_span); - let type_use_gen = &def.type_use_generics(event.attr_span); - let pallet_ident = &def.pallet_struct.pallet; - - let PalletEventDepositAttr { - fn_vis, fn_span, .. - } = deposit_event; - - quote::quote_spanned!(*fn_span => - impl<#type_impl_gen> #pallet_ident<#type_use_gen> #completed_where_clause { - #fn_vis fn deposit_event(event: Event<#event_use_gen>) { - let event = < - ::RuntimeEvent as - From> - >::from(event); - - let event = < - ::RuntimeEvent as - Into<::RuntimeEvent> - >::into(event); - - <#frame_system::Pallet>::deposit_event(event) - } - } - ) - } else { - Default::default() - }; - - quote::quote_spanned!(event.attr_span => - #[doc(hidden)] - pub mod __substrate_event_check { - #[macro_export] - #[doc(hidden)] - macro_rules! #macro_ident { - ($pallet_name:ident) => {}; - } - - #[doc(hidden)] - pub use #macro_ident as is_event_part_defined; - } - - #deposit_event - - impl<#event_impl_gen> From<#event_ident<#event_use_gen>> for () #event_where_clause { - fn from(_: #event_ident<#event_use_gen>) {} - } - ) -} diff --git a/support/procedural-fork/src/pallet/expand/genesis_build.rs b/support/procedural-fork/src/pallet/expand/genesis_build.rs deleted file mode 100644 index c6089550de..0000000000 --- a/support/procedural-fork/src/pallet/expand/genesis_build.rs +++ /dev/null @@ -1,53 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use crate::pallet::Def; - -/// -/// * implement the trait `sp_runtime::BuildStorage` -pub fn expand_genesis_build(def: &mut Def) -> proc_macro2::TokenStream { - let genesis_config = if let Some(genesis_config) = &def.genesis_config { - genesis_config - } else { - return Default::default(); - }; - let genesis_build = def.genesis_build.as_ref().expect("Checked by def parser"); - - let frame_support = &def.frame_support; - let type_impl_gen = &genesis_config - .gen_kind - .type_impl_gen(genesis_build.attr_span); - let gen_cfg_ident = &genesis_config.genesis_config; - let gen_cfg_use_gen = &genesis_config - .gen_kind - .type_use_gen(genesis_build.attr_span); - - let where_clause = &genesis_build.where_clause; - - quote::quote_spanned!(genesis_build.attr_span => - #[cfg(feature = "std")] - impl<#type_impl_gen> #frame_support::sp_runtime::BuildStorage for #gen_cfg_ident<#gen_cfg_use_gen> #where_clause - { - fn assimilate_storage(&self, storage: &mut #frame_support::sp_runtime::Storage) -> std::result::Result<(), std::string::String> { - #frame_support::__private::BasicExternalities::execute_with_storage(storage, || { - self.build(); - Ok(()) - }) - } - } - ) -} diff --git a/support/procedural-fork/src/pallet/expand/genesis_config.rs b/support/procedural-fork/src/pallet/expand/genesis_config.rs deleted file mode 100644 index e98b410d02..0000000000 --- a/support/procedural-fork/src/pallet/expand/genesis_config.rs +++ /dev/null @@ -1,152 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use crate::{COUNTER, pallet::Def}; -use frame_support_procedural_tools::get_doc_literals; -use quote::ToTokens; -use syn::{Ident, spanned::Spanned}; - -/// -/// * add various derive trait on GenesisConfig struct. -pub fn expand_genesis_config(def: &mut Def) -> proc_macro2::TokenStream { - let count = COUNTER.with(|counter| counter.borrow_mut().inc()); - - let (genesis_config, def_macro_ident, std_macro_ident) = if let Some(genesis_config) = - &def.genesis_config - { - let def_macro_ident = Ident::new( - &format!("__is_genesis_config_defined_{}", count), - genesis_config.genesis_config.span(), - ); - - let std_macro_ident = Ident::new( - &format!("__is_std_macro_defined_for_genesis_{}", count), - genesis_config.genesis_config.span(), - ); - - (genesis_config, def_macro_ident, std_macro_ident) - } else { - let def_macro_ident = Ident::new( - &format!("__is_genesis_config_defined_{}", count), - def.item.span(), - ); - - let std_macro_ident = Ident::new( - &format!("__is_std_enabled_for_genesis_{}", count), - def.item.span(), - ); - - return quote::quote! { - #[doc(hidden)] - pub mod __substrate_genesis_config_check { - #[macro_export] - #[doc(hidden)] - macro_rules! #def_macro_ident { - ($pallet_name:ident) => { - compile_error!(concat!( - "`", - stringify!($pallet_name), - "` does not have #[pallet::genesis_config] defined, perhaps you should \ - remove `Config` from construct_runtime?", - )); - } - } - - #[macro_export] - #[doc(hidden)] - macro_rules! #std_macro_ident { - ($pallet_name:ident, $pallet_path:expr) => {}; - } - - #[doc(hidden)] - pub use #def_macro_ident as is_genesis_config_defined; - #[doc(hidden)] - pub use #std_macro_ident as is_std_enabled_for_genesis; - } - }; - }; - - let frame_support = &def.frame_support; - - let genesis_config_item = - &mut def.item.content.as_mut().expect("Checked by def parser").1[genesis_config.index]; - - let serde_crate = format!("{}::__private::serde", frame_support.to_token_stream()); - - match genesis_config_item { - syn::Item::Enum(syn::ItemEnum { attrs, .. }) - | syn::Item::Struct(syn::ItemStruct { attrs, .. }) - | syn::Item::Type(syn::ItemType { attrs, .. }) => { - if get_doc_literals(attrs).is_empty() { - attrs.push(syn::parse_quote!( - #[doc = r" - Can be used to configure the - [genesis state](https://docs.substrate.io/build/genesis-configuration/) - of this pallet. - "] - )); - } - attrs.push(syn::parse_quote!( - #[derive(#frame_support::Serialize, #frame_support::Deserialize)] - )); - attrs.push(syn::parse_quote!( #[serde(rename_all = "camelCase")] )); - attrs.push(syn::parse_quote!( #[serde(deny_unknown_fields)] )); - attrs.push(syn::parse_quote!( #[serde(bound(serialize = ""))] )); - attrs.push(syn::parse_quote!( #[serde(bound(deserialize = ""))] )); - attrs.push(syn::parse_quote!( #[serde(crate = #serde_crate)] )); - } - _ => unreachable!("Checked by genesis_config parser"), - } - - quote::quote! { - #[doc(hidden)] - pub mod __substrate_genesis_config_check { - #[macro_export] - #[doc(hidden)] - macro_rules! #def_macro_ident { - ($pallet_name:ident) => {}; - } - - #[cfg(not(feature = "std"))] - #[macro_export] - #[doc(hidden)] - macro_rules! #std_macro_ident { - ($pallet_name:ident, $pallet_path:expr) => { - compile_error!(concat!( - "`", - stringify!($pallet_name), - "` does not have the std feature enabled, this will cause the `", - $pallet_path, - "::GenesisConfig` type to not implement serde traits." - )); - }; - } - - #[cfg(feature = "std")] - #[macro_export] - #[doc(hidden)] - macro_rules! #std_macro_ident { - ($pallet_name:ident, $pallet_path:expr) => {}; - } - - #[doc(hidden)] - pub use #def_macro_ident as is_genesis_config_defined; - #[doc(hidden)] - pub use #std_macro_ident as is_std_enabled_for_genesis; - } - } -} diff --git a/support/procedural-fork/src/pallet/expand/hooks.rs b/support/procedural-fork/src/pallet/expand/hooks.rs deleted file mode 100644 index 8ff0e8f30f..0000000000 --- a/support/procedural-fork/src/pallet/expand/hooks.rs +++ /dev/null @@ -1,345 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use crate::pallet::Def; - -/// * implement the individual traits using the Hooks trait -pub fn expand_hooks(def: &mut Def) -> proc_macro2::TokenStream { - let (where_clause, span, has_runtime_upgrade) = match def.hooks.as_ref() { - Some(hooks) => { - let where_clause = hooks.where_clause.clone(); - let span = hooks.attr_span; - let has_runtime_upgrade = hooks.has_runtime_upgrade; - (where_clause, span, has_runtime_upgrade) - } - None => ( - def.config.where_clause.clone(), - def.pallet_struct.attr_span, - false, - ), - }; - - let frame_support = &def.frame_support; - let type_impl_gen = &def.type_impl_generics(span); - let type_use_gen = &def.type_use_generics(span); - let pallet_ident = &def.pallet_struct.pallet; - let frame_system = &def.frame_system; - let pallet_name = quote::quote! { - < - ::PalletInfo - as - #frame_support::traits::PalletInfo - >::name::().unwrap_or("") - }; - - let initialize_on_chain_storage_version = if let Some(in_code_version) = - &def.pallet_struct.storage_version - { - quote::quote! { - #frame_support::__private::log::info!( - target: #frame_support::LOG_TARGET, - "🐥 New pallet {:?} detected in the runtime. Initializing the on-chain storage version to match the storage version defined in the pallet: {:?}", - #pallet_name, - #in_code_version - ); - #in_code_version.put::(); - } - } else { - quote::quote! { - let default_version = #frame_support::traits::StorageVersion::new(0); - #frame_support::__private::log::info!( - target: #frame_support::LOG_TARGET, - "🐥 New pallet {:?} detected in the runtime. The pallet has no defined storage version, so the on-chain version is being initialized to {:?}.", - #pallet_name, - default_version - ); - default_version.put::(); - } - }; - - let log_runtime_upgrade = if has_runtime_upgrade { - // a migration is defined here. - quote::quote! { - #frame_support::__private::log::info!( - target: #frame_support::LOG_TARGET, - "⚠️ {} declares internal migrations (which *might* execute). \ - On-chain `{:?}` vs in-code storage version `{:?}`", - #pallet_name, - ::on_chain_storage_version(), - ::in_code_storage_version(), - ); - } - } else { - // default. - quote::quote! { - #frame_support::__private::log::debug!( - target: #frame_support::LOG_TARGET, - "✅ no migration for {}", - #pallet_name, - ); - } - }; - - let hooks_impl = if def.hooks.is_none() { - let frame_system = &def.frame_system; - quote::quote! { - impl<#type_impl_gen> - #frame_support::traits::Hooks<#frame_system::pallet_prelude::BlockNumberFor::> - for #pallet_ident<#type_use_gen> #where_clause {} - } - } else { - proc_macro2::TokenStream::new() - }; - - // If a storage version is set, we should ensure that the storage version on chain matches the - // in-code storage version. This assumes that `Executive` is running custom migrations before - // the pallets are called. - let post_storage_version_check = if def.pallet_struct.storage_version.is_some() { - quote::quote! { - let on_chain_version = ::on_chain_storage_version(); - let in_code_version = ::in_code_storage_version(); - - if on_chain_version != in_code_version { - #frame_support::__private::log::error!( - target: #frame_support::LOG_TARGET, - "{}: On chain storage version {:?} doesn't match in-code storage version {:?}.", - #pallet_name, - on_chain_version, - in_code_version, - ); - - return Err("On chain and in-code storage version do not match. Missing runtime upgrade?".into()); - } - } - } else { - quote::quote! { - let on_chain_version = ::on_chain_storage_version(); - - if on_chain_version != #frame_support::traits::StorageVersion::new(0) { - #frame_support::__private::log::error!( - target: #frame_support::LOG_TARGET, - "{}: On chain storage version {:?} is set to non zero, \ - while the pallet is missing the `#[pallet::storage_version(VERSION)]` attribute.", - #pallet_name, - on_chain_version, - ); - - return Err("On chain storage version set, while the pallet doesn't \ - have the `#[pallet::storage_version(VERSION)]` attribute.".into()); - } - } - }; - - quote::quote_spanned!(span => - #hooks_impl - - impl<#type_impl_gen> - #frame_support::traits::OnFinalize<#frame_system::pallet_prelude::BlockNumberFor::> - for #pallet_ident<#type_use_gen> #where_clause - { - fn on_finalize(n: #frame_system::pallet_prelude::BlockNumberFor::) { - #frame_support::__private::sp_tracing::enter_span!( - #frame_support::__private::sp_tracing::trace_span!("on_finalize") - ); - < - Self as #frame_support::traits::Hooks< - #frame_system::pallet_prelude::BlockNumberFor:: - > - >::on_finalize(n) - } - } - - impl<#type_impl_gen> - #frame_support::traits::OnIdle<#frame_system::pallet_prelude::BlockNumberFor::> - for #pallet_ident<#type_use_gen> #where_clause - { - fn on_idle( - n: #frame_system::pallet_prelude::BlockNumberFor::, - remaining_weight: #frame_support::weights::Weight - ) -> #frame_support::weights::Weight { - < - Self as #frame_support::traits::Hooks< - #frame_system::pallet_prelude::BlockNumberFor:: - > - >::on_idle(n, remaining_weight) - } - } - - impl<#type_impl_gen> - #frame_support::traits::OnPoll<#frame_system::pallet_prelude::BlockNumberFor::> - for #pallet_ident<#type_use_gen> #where_clause - { - fn on_poll( - n: #frame_system::pallet_prelude::BlockNumberFor::, - weight: &mut #frame_support::weights::WeightMeter - ) { - < - Self as #frame_support::traits::Hooks< - #frame_system::pallet_prelude::BlockNumberFor:: - > - >::on_poll(n, weight); - } - } - - impl<#type_impl_gen> - #frame_support::traits::OnInitialize<#frame_system::pallet_prelude::BlockNumberFor::> - for #pallet_ident<#type_use_gen> #where_clause - { - fn on_initialize( - n: #frame_system::pallet_prelude::BlockNumberFor:: - ) -> #frame_support::weights::Weight { - #frame_support::__private::sp_tracing::enter_span!( - #frame_support::__private::sp_tracing::trace_span!("on_initialize") - ); - < - Self as #frame_support::traits::Hooks< - #frame_system::pallet_prelude::BlockNumberFor:: - > - >::on_initialize(n) - } - } - - impl<#type_impl_gen> - #frame_support::traits::BeforeAllRuntimeMigrations - for #pallet_ident<#type_use_gen> #where_clause - { - fn before_all_runtime_migrations() -> #frame_support::weights::Weight { - use #frame_support::traits::{Get, PalletInfoAccess}; - use #frame_support::__private::hashing::twox_128; - use #frame_support::storage::unhashed::contains_prefixed_key; - #frame_support::__private::sp_tracing::enter_span!( - #frame_support::__private::sp_tracing::trace_span!("before_all") - ); - - // Check if the pallet has any keys set, including the storage version. If there are - // no keys set, the pallet was just added to the runtime and needs to have its - // version initialized. - let pallet_hashed_prefix = ::name_hash(); - let exists = contains_prefixed_key(&pallet_hashed_prefix); - if !exists { - #initialize_on_chain_storage_version - ::DbWeight::get().reads_writes(1, 1) - } else { - ::DbWeight::get().reads(1) - } - } - } - - impl<#type_impl_gen> - #frame_support::traits::OnRuntimeUpgrade - for #pallet_ident<#type_use_gen> #where_clause - { - fn on_runtime_upgrade() -> #frame_support::weights::Weight { - #frame_support::__private::sp_tracing::enter_span!( - #frame_support::__private::sp_tracing::trace_span!("on_runtime_update") - ); - - // log info about the upgrade. - #log_runtime_upgrade - - < - Self as #frame_support::traits::Hooks< - #frame_system::pallet_prelude::BlockNumberFor:: - > - >::on_runtime_upgrade() - } - - #frame_support::try_runtime_enabled! { - fn pre_upgrade() -> Result<#frame_support::__private::Vec, #frame_support::sp_runtime::TryRuntimeError> { - < - Self - as - #frame_support::traits::Hooks<#frame_system::pallet_prelude::BlockNumberFor::> - >::pre_upgrade() - } - - fn post_upgrade(state: #frame_support::__private::Vec) -> Result<(), #frame_support::sp_runtime::TryRuntimeError> { - #post_storage_version_check - - < - Self - as - #frame_support::traits::Hooks<#frame_system::pallet_prelude::BlockNumberFor::> - >::post_upgrade(state) - } - } - } - - impl<#type_impl_gen> - #frame_support::traits::OffchainWorker<#frame_system::pallet_prelude::BlockNumberFor::> - for #pallet_ident<#type_use_gen> #where_clause - { - fn offchain_worker(n: #frame_system::pallet_prelude::BlockNumberFor::) { - < - Self as #frame_support::traits::Hooks< - #frame_system::pallet_prelude::BlockNumberFor:: - > - >::offchain_worker(n) - } - } - - // Integrity tests are only required for when `std` is enabled. - #frame_support::std_enabled! { - impl<#type_impl_gen> - #frame_support::traits::IntegrityTest - for #pallet_ident<#type_use_gen> #where_clause - { - fn integrity_test() { - #frame_support::__private::sp_io::TestExternalities::default().execute_with(|| { - < - Self as #frame_support::traits::Hooks< - #frame_system::pallet_prelude::BlockNumberFor:: - > - >::integrity_test() - }); - } - } - } - - #frame_support::try_runtime_enabled! { - impl<#type_impl_gen> - #frame_support::traits::TryState<#frame_system::pallet_prelude::BlockNumberFor::> - for #pallet_ident<#type_use_gen> #where_clause - { - fn try_state( - n: #frame_system::pallet_prelude::BlockNumberFor::, - _s: #frame_support::traits::TryStateSelect - ) -> Result<(), #frame_support::sp_runtime::TryRuntimeError> { - #frame_support::__private::log::info!( - target: #frame_support::LOG_TARGET, - "🩺 Running {:?} try-state checks", - #pallet_name, - ); - < - Self as #frame_support::traits::Hooks< - #frame_system::pallet_prelude::BlockNumberFor:: - > - >::try_state(n).map_err(|err| { - #frame_support::__private::log::error!( - target: #frame_support::LOG_TARGET, - "❌ {:?} try_state checks failed: {:?}", - #pallet_name, - err - ); - - err - }) - } - } - } - ) -} diff --git a/support/procedural-fork/src/pallet/expand/inherent.rs b/support/procedural-fork/src/pallet/expand/inherent.rs deleted file mode 100644 index 832a755145..0000000000 --- a/support/procedural-fork/src/pallet/expand/inherent.rs +++ /dev/null @@ -1,58 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use crate::{COUNTER, pallet::Def}; -use proc_macro2::TokenStream; -use quote::quote; -use syn::{Ident, spanned::Spanned}; - -pub fn expand_inherents(def: &mut Def) -> TokenStream { - let count = COUNTER.with(|counter| counter.borrow_mut().inc()); - let macro_ident = Ident::new( - &format!("__is_inherent_part_defined_{}", count), - def.item.span(), - ); - - let maybe_compile_error = if def.inherent.is_none() { - quote! { - compile_error!(concat!( - "`", - stringify!($pallet_name), - "` does not have #[pallet::inherent] defined, perhaps you should \ - remove `Inherent` from construct_runtime?", - )); - } - } else { - TokenStream::new() - }; - - quote! { - #[doc(hidden)] - pub mod __substrate_inherent_check { - #[macro_export] - #[doc(hidden)] - macro_rules! #macro_ident { - ($pallet_name:ident) => { - #maybe_compile_error - } - } - - #[doc(hidden)] - pub use #macro_ident as is_inherent_part_defined; - } - } -} diff --git a/support/procedural-fork/src/pallet/expand/instances.rs b/support/procedural-fork/src/pallet/expand/instances.rs deleted file mode 100644 index d6d80854ae..0000000000 --- a/support/procedural-fork/src/pallet/expand/instances.rs +++ /dev/null @@ -1,43 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use crate::{NUMBER_OF_INSTANCE, pallet::Def}; -use proc_macro2::Span; - -/// -/// * Provide inherent instance to be used by construct_runtime -/// * Provide Instance1 ..= Instance16 for instantiable pallet -pub fn expand_instances(def: &mut Def) -> proc_macro2::TokenStream { - let frame_support = &def.frame_support; - let inherent_ident = syn::Ident::new(crate::INHERENT_INSTANCE_NAME, Span::call_site()); - let instances = if def.config.has_instance { - (1..=NUMBER_OF_INSTANCE) - .map(|i| syn::Ident::new(&format!("Instance{}", i), Span::call_site())) - .collect() - } else { - vec![] - }; - - quote::quote!( - /// Hidden instance generated to be internally used when module is used without - /// instance. - #[doc(hidden)] - pub type #inherent_ident = (); - - #( pub use #frame_support::instances::#instances; )* - ) -} diff --git a/support/procedural-fork/src/pallet/expand/mod.rs b/support/procedural-fork/src/pallet/expand/mod.rs deleted file mode 100644 index ff4423f859..0000000000 --- a/support/procedural-fork/src/pallet/expand/mod.rs +++ /dev/null @@ -1,130 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -mod call; -mod composite; -mod config; -mod constants; -mod doc_only; -mod documentation; -mod error; -mod event; -mod genesis_build; -mod genesis_config; -mod hooks; -mod inherent; -mod instances; -mod origin; -mod pallet_struct; -mod storage; -mod tasks; -mod tt_default_parts; -mod type_value; -mod validate_unsigned; -mod warnings; - -use crate::pallet::Def; -use quote::ToTokens; - -/// Merge where clause together, `where` token span is taken from the first not none one. -pub fn merge_where_clauses(clauses: &[&Option]) -> Option { - let mut clauses = clauses.iter().filter_map(|f| f.as_ref()); - let mut res = clauses.next()?.clone(); - for other in clauses { - res.predicates.extend(other.predicates.iter().cloned()) - } - Some(res) -} - -/// Expand definition, in particular: -/// * add some bounds and variants to type defined, -/// * create some new types, -/// * impl stuff on them. -pub fn expand(mut def: Def) -> proc_macro2::TokenStream { - // Remove the `pallet_doc` attribute first. - let metadata_docs = documentation::expand_documentation(&mut def); - let constants = constants::expand_constants(&mut def); - let pallet_struct = pallet_struct::expand_pallet_struct(&mut def); - let config = config::expand_config(&mut def); - let call = call::expand_call(&mut def); - let tasks = tasks::expand_tasks(&mut def); - let error = error::expand_error(&mut def); - let event = event::expand_event(&mut def); - let storages = storage::expand_storages(&mut def); - let inherents = inherent::expand_inherents(&mut def); - let instances = instances::expand_instances(&mut def); - let hooks = hooks::expand_hooks(&mut def); - let genesis_build = genesis_build::expand_genesis_build(&mut def); - let genesis_config = genesis_config::expand_genesis_config(&mut def); - let type_values = type_value::expand_type_values(&mut def); - let origins = origin::expand_origins(&mut def); - let validate_unsigned = validate_unsigned::expand_validate_unsigned(&mut def); - let tt_default_parts = tt_default_parts::expand_tt_default_parts(&mut def); - let doc_only = doc_only::expand_doc_only(&mut def); - let composites = composite::expand_composites(&mut def); - - def.item.attrs.insert( - 0, - syn::parse_quote!( - #[doc = r"The `pallet` module in each FRAME pallet hosts the most important items needed -to construct this pallet. - -The main components of this pallet are: -- [`Pallet`], which implements all of the dispatchable extrinsics of the pallet, among -other public functions. - - The subset of the functions that are dispatchable can be identified either in the - [`dispatchables`] module or in the [`Call`] enum. -- [`storage_types`], which contains the list of all types that are representing a -storage item. Otherwise, all storage items are listed among [*Type Definitions*](#types). -- [`Config`], which contains the configuration trait of this pallet. -- [`Event`] and [`Error`], which are listed among the [*Enums*](#enums). - "] - ), - ); - - let new_items = quote::quote!( - #metadata_docs - #constants - #pallet_struct - #config - #call - #tasks - #error - #event - #storages - #inherents - #instances - #hooks - #genesis_build - #genesis_config - #type_values - #origins - #validate_unsigned - #tt_default_parts - #doc_only - #composites - ); - - def.item - .content - .as_mut() - .expect("This is checked by parsing") - .1 - .push(syn::Item::Verbatim(new_items)); - - def.item.into_token_stream() -} diff --git a/support/procedural-fork/src/pallet/expand/origin.rs b/support/procedural-fork/src/pallet/expand/origin.rs deleted file mode 100644 index 3399143f04..0000000000 --- a/support/procedural-fork/src/pallet/expand/origin.rs +++ /dev/null @@ -1,58 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use crate::{COUNTER, pallet::Def}; -use proc_macro2::TokenStream; -use quote::quote; -use syn::{Ident, spanned::Spanned}; - -pub fn expand_origins(def: &mut Def) -> TokenStream { - let count = COUNTER.with(|counter| counter.borrow_mut().inc()); - let macro_ident = Ident::new( - &format!("__is_origin_part_defined_{}", count), - def.item.span(), - ); - - let maybe_compile_error = if def.origin.is_none() { - quote! { - compile_error!(concat!( - "`", - stringify!($pallet_name), - "` does not have #[pallet::origin] defined, perhaps you should \ - remove `Origin` from construct_runtime?", - )); - } - } else { - TokenStream::new() - }; - - quote! { - #[doc(hidden)] - pub mod __substrate_origin_check { - #[macro_export] - #[doc(hidden)] - macro_rules! #macro_ident { - ($pallet_name:ident) => { - #maybe_compile_error - } - } - - #[doc(hidden)] - pub use #macro_ident as is_origin_part_defined; - } - } -} diff --git a/support/procedural-fork/src/pallet/expand/pallet_struct.rs b/support/procedural-fork/src/pallet/expand/pallet_struct.rs deleted file mode 100644 index 8d2e198bc5..0000000000 --- a/support/procedural-fork/src/pallet/expand/pallet_struct.rs +++ /dev/null @@ -1,302 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use crate::pallet::{Def, expand::merge_where_clauses}; -use frame_support_procedural_tools::get_doc_literals; - -/// -/// * Add derive trait on Pallet -/// * Implement GetStorageVersion on Pallet -/// * Implement OnGenesis on Pallet -/// * Implement `fn error_metadata` on Pallet -/// * declare Module type alias for construct_runtime -/// * replace the first field type of `struct Pallet` with `PhantomData` if it is `_` -/// * implementation of `PalletInfoAccess` information -/// * implementation of `StorageInfoTrait` on Pallet -pub fn expand_pallet_struct(def: &mut Def) -> proc_macro2::TokenStream { - let frame_support = &def.frame_support; - let frame_system = &def.frame_system; - let type_impl_gen = &def.type_impl_generics(def.pallet_struct.attr_span); - let type_use_gen = &def.type_use_generics(def.pallet_struct.attr_span); - let type_decl_gen = &def.type_decl_generics(def.pallet_struct.attr_span); - let pallet_ident = &def.pallet_struct.pallet; - let config_where_clause = &def.config.where_clause; - - let mut storages_where_clauses = vec![&def.config.where_clause]; - storages_where_clauses.extend(def.storages.iter().map(|storage| &storage.where_clause)); - let storages_where_clauses = merge_where_clauses(&storages_where_clauses); - - let pallet_item = { - let pallet_module_items = &mut def.item.content.as_mut().expect("Checked by def").1; - let item = &mut pallet_module_items[def.pallet_struct.index]; - if let syn::Item::Struct(item) = item { - item - } else { - unreachable!("Checked by pallet struct parser") - } - }; - - // If the first field type is `_` then we replace with `PhantomData` - if let Some(field) = pallet_item.fields.iter_mut().next() { - if field.ty == syn::parse_quote!(_) { - field.ty = syn::parse_quote!( - core::marker::PhantomData<(#type_use_gen)> - ); - } - } - - if get_doc_literals(&pallet_item.attrs).is_empty() { - pallet_item.attrs.push(syn::parse_quote!( - #[doc = r" - The `Pallet` struct, the main type that implements traits and standalone - functions within the pallet. - "] - )); - } - - pallet_item.attrs.push(syn::parse_quote!( - #[derive( - #frame_support::CloneNoBound, - #frame_support::EqNoBound, - #frame_support::PartialEqNoBound, - #frame_support::RuntimeDebugNoBound, - )] - )); - - let pallet_error_metadata = if let Some(error_def) = &def.error { - let error_ident = &error_def.error; - quote::quote_spanned!(def.pallet_struct.attr_span => - impl<#type_impl_gen> #pallet_ident<#type_use_gen> #config_where_clause { - #[doc(hidden)] - pub fn error_metadata() -> Option<#frame_support::__private::metadata_ir::PalletErrorMetadataIR> { - Some(#frame_support::__private::metadata_ir::PalletErrorMetadataIR { - ty: #frame_support::__private::scale_info::meta_type::<#error_ident<#type_use_gen>>() - }) - } - } - ) - } else { - quote::quote_spanned!(def.pallet_struct.attr_span => - impl<#type_impl_gen> #pallet_ident<#type_use_gen> #config_where_clause { - #[doc(hidden)] - pub fn error_metadata() -> Option<#frame_support::__private::metadata_ir::PalletErrorMetadataIR> { - None - } - } - ) - }; - - let storage_info_span = def - .pallet_struct - .without_storage_info - .unwrap_or(def.pallet_struct.attr_span); - - let storage_names = &def - .storages - .iter() - .map(|storage| &storage.ident) - .collect::>(); - let storage_cfg_attrs = &def - .storages - .iter() - .map(|storage| &storage.cfg_attrs) - .collect::>(); - - // Depending on the flag `without_storage_info` and the storage attribute `unbounded`, we use - // partial or full storage info from storage. - let storage_info_traits = &def - .storages - .iter() - .map(|storage| { - if storage.unbounded || def.pallet_struct.without_storage_info.is_some() { - quote::quote_spanned!(storage_info_span => PartialStorageInfoTrait) - } else { - quote::quote_spanned!(storage_info_span => StorageInfoTrait) - } - }) - .collect::>(); - - let storage_info_methods = &def - .storages - .iter() - .map(|storage| { - if storage.unbounded || def.pallet_struct.without_storage_info.is_some() { - quote::quote_spanned!(storage_info_span => partial_storage_info) - } else { - quote::quote_spanned!(storage_info_span => storage_info) - } - }) - .collect::>(); - - let storage_info = quote::quote_spanned!(storage_info_span => - impl<#type_impl_gen> #frame_support::traits::StorageInfoTrait - for #pallet_ident<#type_use_gen> - #storages_where_clauses - { - fn storage_info() - -> #frame_support::__private::Vec<#frame_support::traits::StorageInfo> - { - #[allow(unused_mut)] - let mut res = #frame_support::__private::vec![]; - - #( - #(#storage_cfg_attrs)* - { - let mut storage_info = < - #storage_names<#type_use_gen> - as #frame_support::traits::#storage_info_traits - >::#storage_info_methods(); - res.append(&mut storage_info); - } - )* - - res - } - } - ); - - let (storage_version, in_code_storage_version_ty) = - if let Some(v) = def.pallet_struct.storage_version.as_ref() { - ( - quote::quote! { #v }, - quote::quote! { #frame_support::traits::StorageVersion }, - ) - } else { - ( - quote::quote! { core::default::Default::default() }, - quote::quote! { #frame_support::traits::NoStorageVersionSet }, - ) - }; - - let whitelisted_storage_idents: Vec = def - .storages - .iter() - .filter_map(|s| s.whitelisted.then_some(s.ident.clone())) - .collect(); - - let whitelisted_storage_keys_impl = quote::quote![ - use #frame_support::traits::{StorageInfoTrait, TrackedStorageKey, WhitelistedStorageKeys}; - impl<#type_impl_gen> WhitelistedStorageKeys for #pallet_ident<#type_use_gen> #storages_where_clauses { - fn whitelisted_storage_keys() -> #frame_support::__private::Vec { - use #frame_support::__private::vec; - vec![#( - TrackedStorageKey::new(#whitelisted_storage_idents::<#type_use_gen>::hashed_key().to_vec()) - ),*] - } - } - ]; - - quote::quote_spanned!(def.pallet_struct.attr_span => - #pallet_error_metadata - - /// Type alias to `Pallet`, to be used by `construct_runtime`. - /// - /// Generated by `pallet` attribute macro. - #[deprecated(note = "use `Pallet` instead")] - #[allow(dead_code)] - pub type Module<#type_decl_gen> = #pallet_ident<#type_use_gen>; - - // Implement `GetStorageVersion` for `Pallet` - impl<#type_impl_gen> #frame_support::traits::GetStorageVersion - for #pallet_ident<#type_use_gen> - #config_where_clause - { - type InCodeStorageVersion = #in_code_storage_version_ty; - - fn in_code_storage_version() -> Self::InCodeStorageVersion { - #storage_version - } - - fn on_chain_storage_version() -> #frame_support::traits::StorageVersion { - #frame_support::traits::StorageVersion::get::() - } - } - - // Implement `OnGenesis` for `Pallet` - impl<#type_impl_gen> #frame_support::traits::OnGenesis - for #pallet_ident<#type_use_gen> - #config_where_clause - { - fn on_genesis() { - let storage_version: #frame_support::traits::StorageVersion = #storage_version; - storage_version.put::(); - } - } - - // Implement `PalletInfoAccess` for `Pallet` - impl<#type_impl_gen> #frame_support::traits::PalletInfoAccess - for #pallet_ident<#type_use_gen> - #config_where_clause - { - fn index() -> usize { - < - ::PalletInfo as #frame_support::traits::PalletInfo - >::index::() - .expect("Pallet is part of the runtime because pallet `Config` trait is \ - implemented by the runtime") - } - - fn name() -> &'static str { - < - ::PalletInfo as #frame_support::traits::PalletInfo - >::name::() - .expect("Pallet is part of the runtime because pallet `Config` trait is \ - implemented by the runtime") - } - - fn name_hash() -> [u8; 16] { - < - ::PalletInfo as #frame_support::traits::PalletInfo - >::name_hash::() - .expect("Pallet is part of the runtime because pallet `Config` trait is \ - implemented by the runtime") - } - - fn module_name() -> &'static str { - < - ::PalletInfo as #frame_support::traits::PalletInfo - >::module_name::() - .expect("Pallet is part of the runtime because pallet `Config` trait is \ - implemented by the runtime") - } - - fn crate_version() -> #frame_support::traits::CrateVersion { - #frame_support::crate_to_crate_version!() - } - } - - impl<#type_impl_gen> #frame_support::traits::PalletsInfoAccess - for #pallet_ident<#type_use_gen> - #config_where_clause - { - fn count() -> usize { 1 } - fn infos() -> #frame_support::__private::Vec<#frame_support::traits::PalletInfoData> { - use #frame_support::traits::PalletInfoAccess; - let item = #frame_support::traits::PalletInfoData { - index: Self::index(), - name: Self::name(), - module_name: Self::module_name(), - crate_version: Self::crate_version(), - }; - #frame_support::__private::vec![item] - } - } - - #storage_info - #whitelisted_storage_keys_impl - ) -} diff --git a/support/procedural-fork/src/pallet/expand/storage.rs b/support/procedural-fork/src/pallet/expand/storage.rs deleted file mode 100644 index 51c9e8eb12..0000000000 --- a/support/procedural-fork/src/pallet/expand/storage.rs +++ /dev/null @@ -1,957 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use crate::{ - counter_prefix, - pallet::{ - Def, - parse::{ - helper::two128_str, - storage::{Metadata, QueryKind, StorageDef, StorageGenerics}, - }, - }, -}; -use quote::ToTokens; -use std::{collections::HashMap, ops::IndexMut}; -use syn::spanned::Spanned; - -/// Generate the prefix_ident related to the storage. -/// prefix_ident is used for the prefix struct to be given to storage as first generic param. -fn prefix_ident(storage: &StorageDef) -> syn::Ident { - let storage_ident = &storage.ident; - syn::Ident::new( - &format!("_GeneratedPrefixForStorage{}", storage_ident), - storage_ident.span(), - ) -} - -/// Generate the counter_prefix_ident related to the storage. -/// counter_prefix_ident is used for the prefix struct to be given to counted storage map. -fn counter_prefix_ident(storage_ident: &syn::Ident) -> syn::Ident { - syn::Ident::new( - &format!("_GeneratedCounterPrefixForStorage{}", storage_ident), - storage_ident.span(), - ) -} - -/// Check for duplicated storage prefixes. This step is necessary since users can specify an -/// alternative storage prefix using the #[pallet::storage_prefix] syntax, and we need to ensure -/// that the prefix specified by the user is not a duplicate of an existing one. -fn check_prefix_duplicates( - storage_def: &StorageDef, - // A hashmap of all already used prefix and their associated error if duplication - used_prefixes: &mut HashMap, -) -> syn::Result<()> { - let prefix = storage_def.prefix(); - let dup_err = syn::Error::new( - storage_def.prefix_span(), - format!("Duplicate storage prefixes found for `{}`", prefix), - ); - - if let Some(other_dup_err) = used_prefixes.insert(prefix.clone(), dup_err.clone()) { - let mut err = dup_err; - err.combine(other_dup_err); - return Err(err); - } - - if let Metadata::CountedMap { .. } = storage_def.metadata { - let counter_prefix = counter_prefix(&prefix); - let counter_dup_err = syn::Error::new( - storage_def.prefix_span(), - format!( - "Duplicate storage prefixes found for `{}`, used for counter associated to \ - counted storage map", - counter_prefix, - ), - ); - - if let Some(other_dup_err) = used_prefixes.insert(counter_prefix, counter_dup_err.clone()) { - let mut err = counter_dup_err; - err.combine(other_dup_err); - return Err(err); - } - } - - Ok(()) -} - -pub struct ResultOnEmptyStructMetadata { - /// The Rust ident that is going to be used as the name of the OnEmpty struct. - pub name: syn::Ident, - /// The path to the error type being returned by the ResultQuery. - pub error_path: syn::Path, - /// The visibility of the OnEmpty struct. - pub visibility: syn::Visibility, - /// The type of the storage item. - pub value_ty: syn::Type, - /// The name of the pallet error enum variant that is going to be returned. - pub variant_name: syn::Ident, - /// The span used to report compilation errors about the OnEmpty struct. - pub span: proc_macro2::Span, -} - -/// -/// * if generics are unnamed: replace the first generic `_` by the generated prefix structure -/// * if generics are named: reorder the generic, remove their name, and add the missing ones. -/// * Add `#[allow(type_alias_bounds)]` -pub fn process_generics(def: &mut Def) -> syn::Result> { - let frame_support = &def.frame_support; - let mut on_empty_struct_metadata = Vec::new(); - - for storage_def in def.storages.iter_mut() { - let item = &mut def.item.content.as_mut().expect("Checked by def").1[storage_def.index]; - - let typ_item = match item { - syn::Item::Type(t) => t, - _ => unreachable!("Checked by def"), - }; - - typ_item - .attrs - .push(syn::parse_quote!(#[allow(type_alias_bounds)])); - - let typ_path = match &mut *typ_item.ty { - syn::Type::Path(p) => p, - _ => unreachable!("Checked by def"), - }; - - let args = match &mut typ_path.path.segments[0].arguments { - syn::PathArguments::AngleBracketed(args) => args, - _ => unreachable!("Checked by def"), - }; - - let prefix_ident = prefix_ident(storage_def); - let type_use_gen = if def.config.has_instance { - quote::quote_spanned!(storage_def.attr_span => T, I) - } else { - quote::quote_spanned!(storage_def.attr_span => T) - }; - - let default_query_kind: syn::Type = - syn::parse_quote!(#frame_support::storage::types::OptionQuery); - let mut default_on_empty = |value_ty: syn::Type| -> syn::Type { - if let Some(QueryKind::ResultQuery(error_path, variant_name)) = - storage_def.query_kind.as_ref() - { - let on_empty_ident = - quote::format_ident!("__Frame_Internal_Get{}Result", storage_def.ident); - on_empty_struct_metadata.push(ResultOnEmptyStructMetadata { - name: on_empty_ident.clone(), - visibility: storage_def.vis.clone(), - value_ty, - error_path: error_path.clone(), - variant_name: variant_name.clone(), - span: storage_def.attr_span, - }); - return syn::parse_quote!(#on_empty_ident); - } - syn::parse_quote!(#frame_support::traits::GetDefault) - }; - let default_max_values: syn::Type = syn::parse_quote!(#frame_support::traits::GetDefault); - - let set_result_query_type_parameter = |query_type: &mut syn::Type| -> syn::Result<()> { - if let Some(QueryKind::ResultQuery(error_path, _)) = storage_def.query_kind.as_ref() { - if let syn::Type::Path(syn::TypePath { - path: syn::Path { segments, .. }, - .. - }) = query_type - { - if let Some(seg) = segments.last_mut() { - if let syn::PathArguments::AngleBracketed( - syn::AngleBracketedGenericArguments { args, .. }, - ) = &mut seg.arguments - { - args.clear(); - args.push(syn::GenericArgument::Type(syn::parse_quote!(#error_path))); - } - } - } else { - let msg = format!( - "Invalid pallet::storage, unexpected type for query, expected ResultQuery \ - with 1 type parameter, found `{}`", - query_type.to_token_stream().to_string() - ); - return Err(syn::Error::new(query_type.span(), msg)); - } - } - Ok(()) - }; - - if let Some(named_generics) = storage_def.named_generics.clone() { - args.args.clear(); - args.args - .push(syn::parse_quote!( #prefix_ident<#type_use_gen> )); - match named_generics { - StorageGenerics::Value { - value, - query_kind, - on_empty, - } => { - args.args.push(syn::GenericArgument::Type(value.clone())); - let mut query_kind = query_kind.unwrap_or_else(|| default_query_kind.clone()); - set_result_query_type_parameter(&mut query_kind)?; - args.args.push(syn::GenericArgument::Type(query_kind)); - let on_empty = on_empty.unwrap_or_else(|| default_on_empty(value)); - args.args.push(syn::GenericArgument::Type(on_empty)); - } - StorageGenerics::Map { - hasher, - key, - value, - query_kind, - on_empty, - max_values, - } - | StorageGenerics::CountedMap { - hasher, - key, - value, - query_kind, - on_empty, - max_values, - } => { - args.args.push(syn::GenericArgument::Type(hasher)); - args.args.push(syn::GenericArgument::Type(key)); - args.args.push(syn::GenericArgument::Type(value.clone())); - let mut query_kind = query_kind.unwrap_or_else(|| default_query_kind.clone()); - set_result_query_type_parameter(&mut query_kind)?; - args.args.push(syn::GenericArgument::Type(query_kind)); - let on_empty = on_empty.unwrap_or_else(|| default_on_empty(value)); - args.args.push(syn::GenericArgument::Type(on_empty)); - let max_values = max_values.unwrap_or_else(|| default_max_values.clone()); - args.args.push(syn::GenericArgument::Type(max_values)); - } - StorageGenerics::DoubleMap { - hasher1, - key1, - hasher2, - key2, - value, - query_kind, - on_empty, - max_values, - } => { - args.args.push(syn::GenericArgument::Type(hasher1)); - args.args.push(syn::GenericArgument::Type(key1)); - args.args.push(syn::GenericArgument::Type(hasher2)); - args.args.push(syn::GenericArgument::Type(key2)); - args.args.push(syn::GenericArgument::Type(value.clone())); - let mut query_kind = query_kind.unwrap_or_else(|| default_query_kind.clone()); - set_result_query_type_parameter(&mut query_kind)?; - args.args.push(syn::GenericArgument::Type(query_kind)); - let on_empty = on_empty.unwrap_or_else(|| default_on_empty(value)); - args.args.push(syn::GenericArgument::Type(on_empty)); - let max_values = max_values.unwrap_or_else(|| default_max_values.clone()); - args.args.push(syn::GenericArgument::Type(max_values)); - } - StorageGenerics::NMap { - keygen, - value, - query_kind, - on_empty, - max_values, - } - | StorageGenerics::CountedNMap { - keygen, - value, - query_kind, - on_empty, - max_values, - } => { - args.args.push(syn::GenericArgument::Type(keygen)); - args.args.push(syn::GenericArgument::Type(value.clone())); - let mut query_kind = query_kind.unwrap_or_else(|| default_query_kind.clone()); - set_result_query_type_parameter(&mut query_kind)?; - args.args.push(syn::GenericArgument::Type(query_kind)); - let on_empty = on_empty.unwrap_or_else(|| default_on_empty(value)); - args.args.push(syn::GenericArgument::Type(on_empty)); - let max_values = max_values.unwrap_or_else(|| default_max_values.clone()); - args.args.push(syn::GenericArgument::Type(max_values)); - } - } - } else { - args.args[0] = syn::parse_quote!( #prefix_ident<#type_use_gen> ); - - let (value_idx, query_idx, on_empty_idx) = match storage_def.metadata { - Metadata::Value { .. } => (1, 2, 3), - Metadata::NMap { .. } | Metadata::CountedNMap { .. } => (2, 3, 4), - Metadata::Map { .. } | Metadata::CountedMap { .. } => (3, 4, 5), - Metadata::DoubleMap { .. } => (5, 6, 7), - }; - - if storage_def.use_default_hasher { - let hasher_indices: Vec = match storage_def.metadata { - Metadata::Map { .. } | Metadata::CountedMap { .. } => vec![1], - Metadata::DoubleMap { .. } => vec![1, 3], - _ => vec![], - }; - for hasher_idx in hasher_indices { - args.args[hasher_idx] = syn::GenericArgument::Type( - syn::parse_quote!(#frame_support::Blake2_128Concat), - ); - } - } - - if query_idx < args.args.len() { - if let syn::GenericArgument::Type(query_kind) = args.args.index_mut(query_idx) { - set_result_query_type_parameter(query_kind)?; - } - } else if let Some(QueryKind::ResultQuery(error_path, _)) = - storage_def.query_kind.as_ref() - { - args.args - .push(syn::GenericArgument::Type(syn::parse_quote!(#error_path))) - } - - // Here, we only need to check if OnEmpty is *not* specified, and if so, then we have to - // generate a default OnEmpty struct for it. - if on_empty_idx >= args.args.len() - && matches!( - storage_def.query_kind.as_ref(), - Some(QueryKind::ResultQuery(_, _)) - ) - { - let value_ty = match args.args[value_idx].clone() { - syn::GenericArgument::Type(ty) => ty, - _ => unreachable!(), - }; - let on_empty = default_on_empty(value_ty); - args.args.push(syn::GenericArgument::Type(on_empty)); - } - } - } - - Ok(on_empty_struct_metadata) -} - -fn augment_final_docs(def: &mut Def) { - // expand the docs with a new line showing the storage type (value, map, double map, etc), and - // the key/value type(s). - let mut push_string_literal = |doc_line: &str, storage: &mut StorageDef| { - let item = &mut def.item.content.as_mut().expect("Checked by def").1[storage.index]; - let typ_item = match item { - syn::Item::Type(t) => t, - _ => unreachable!("Checked by def"), - }; - typ_item.attrs.push(syn::parse_quote!(#[doc = ""])); - typ_item.attrs.push(syn::parse_quote!(#[doc = #doc_line])); - }; - def.storages - .iter_mut() - .for_each(|storage| match &storage.metadata { - Metadata::Value { value } => { - let doc_line = format!( - "Storage type is [`StorageValue`] with value type `{}`.", - value.to_token_stream() - ); - push_string_literal(&doc_line, storage); - } - Metadata::Map { key, value } => { - let doc_line = format!( - "Storage type is [`StorageMap`] with key type `{}` and value type `{}`.", - key.to_token_stream(), - value.to_token_stream() - ); - push_string_literal(&doc_line, storage); - } - Metadata::DoubleMap { key1, key2, value } => { - let doc_line = format!( - "Storage type is [`StorageDoubleMap`] with key1 type {}, key2 type {} and value type {}.", - key1.to_token_stream(), - key2.to_token_stream(), - value.to_token_stream() - ); - push_string_literal(&doc_line, storage); - } - Metadata::NMap { keys, value, .. } => { - let doc_line = format!( - "Storage type is [`StorageNMap`] with keys type ({}) and value type {}.", - keys.iter() - .map(|k| k.to_token_stream().to_string()) - .collect::>() - .join(", "), - value.to_token_stream() - ); - push_string_literal(&doc_line, storage); - } - Metadata::CountedNMap { keys, value, .. } => { - let doc_line = format!( - "Storage type is [`CountedStorageNMap`] with keys type ({}) and value type {}.", - keys.iter() - .map(|k| k.to_token_stream().to_string()) - .collect::>() - .join(", "), - value.to_token_stream() - ); - push_string_literal(&doc_line, storage); - } - Metadata::CountedMap { key, value } => { - let doc_line = format!( - "Storage type is [`CountedStorageMap`] with key type {} and value type {}.", - key.to_token_stream(), - value.to_token_stream() - ); - push_string_literal(&doc_line, storage); - } - }); -} - -/// -/// * generate StoragePrefix structs (e.g. for a storage `MyStorage` a struct with the name -/// `_GeneratedPrefixForStorage$NameOfStorage` is generated) and implements StorageInstance trait. -/// * if generics are unnamed: replace the first generic `_` by the generated prefix structure -/// * if generics are named: reorder the generic, remove their name, and add the missing ones. -/// * Add `#[allow(type_alias_bounds)]` on storages type alias -/// * generate metadatas -pub fn expand_storages(def: &mut Def) -> proc_macro2::TokenStream { - let on_empty_struct_metadata = match process_generics(def) { - Ok(idents) => idents, - Err(e) => return e.into_compile_error(), - }; - - augment_final_docs(def); - - // Check for duplicate prefixes - let mut prefix_set = HashMap::new(); - let mut errors = def - .storages - .iter() - .filter_map(|storage_def| check_prefix_duplicates(storage_def, &mut prefix_set).err()); - if let Some(mut final_error) = errors.next() { - errors.for_each(|error| final_error.combine(error)); - return final_error.into_compile_error(); - } - - let frame_support = &def.frame_support; - let frame_system = &def.frame_system; - let pallet_ident = &def.pallet_struct.pallet; - - let entries_builder = def.storages.iter().map(|storage| { - let no_docs = vec![]; - let docs = if cfg!(feature = "no-metadata-docs") { &no_docs } else { &storage.docs }; - - let ident = &storage.ident; - let generics = &def.type_use_generics(storage.attr_span); - let full_ident = quote::quote_spanned!(storage.attr_span => #ident<#generics> ); - - let cfg_attrs = &storage.cfg_attrs; - - quote::quote_spanned!(storage.attr_span => - #(#cfg_attrs)* - { - <#full_ident as #frame_support::storage::StorageEntryMetadataBuilder>::build_metadata( - #frame_support::__private::vec![ - #( #docs, )* - ], - &mut entries, - ); - } - ) - }); - - let getters = def.storages.iter().map(|storage| { - if let Some(getter) = &storage.getter { - let completed_where_clause = - super::merge_where_clauses(&[&storage.where_clause, &def.config.where_clause]); - - let ident = &storage.ident; - let generics = &def.type_use_generics(storage.attr_span); - let type_impl_gen = &def.type_impl_generics(storage.attr_span); - let type_use_gen = &def.type_use_generics(storage.attr_span); - let full_ident = quote::quote_spanned!(storage.attr_span => #ident<#generics> ); - - let cfg_attrs = &storage.cfg_attrs; - - // If the storage item is public, link it and otherwise just mention it. - // - // We can not just copy the docs from a non-public type as it may links to internal - // types which makes the compiler very unhappy :( - let getter_doc_line = if matches!(storage.vis, syn::Visibility::Public(_)) { - format!("An auto-generated getter for [`{}`].", storage.ident) - } else { - format!("An auto-generated getter for `{}`.", storage.ident) - }; - - match &storage.metadata { - Metadata::Value { value } => { - let query = match storage.query_kind.as_ref().expect("Checked by def") { - QueryKind::OptionQuery => quote::quote_spanned!(storage.attr_span => - Option<#value> - ), - QueryKind::ResultQuery(error_path, _) => { - quote::quote_spanned!(storage.attr_span => - Result<#value, #error_path> - ) - } - QueryKind::ValueQuery => quote::quote!(#value), - }; - quote::quote_spanned!(storage.attr_span => - #(#cfg_attrs)* - impl<#type_impl_gen> #pallet_ident<#type_use_gen> #completed_where_clause { - #[doc = #getter_doc_line] - pub fn #getter() -> #query { - < - #full_ident as #frame_support::storage::StorageValue<#value> - >::get() - } - } - ) - } - Metadata::Map { key, value } => { - let query = match storage.query_kind.as_ref().expect("Checked by def") { - QueryKind::OptionQuery => quote::quote_spanned!(storage.attr_span => - Option<#value> - ), - QueryKind::ResultQuery(error_path, _) => { - quote::quote_spanned!(storage.attr_span => - Result<#value, #error_path> - ) - } - QueryKind::ValueQuery => quote::quote!(#value), - }; - quote::quote_spanned!(storage.attr_span => - #(#cfg_attrs)* - impl<#type_impl_gen> #pallet_ident<#type_use_gen> #completed_where_clause { - #[doc = #getter_doc_line] - pub fn #getter(k: KArg) -> #query where - KArg: #frame_support::__private::codec::EncodeLike<#key>, - { - < - #full_ident as #frame_support::storage::StorageMap<#key, #value> - >::get(k) - } - } - ) - } - Metadata::CountedMap { key, value } => { - let query = match storage.query_kind.as_ref().expect("Checked by def") { - QueryKind::OptionQuery => quote::quote_spanned!(storage.attr_span => - Option<#value> - ), - QueryKind::ResultQuery(error_path, _) => { - quote::quote_spanned!(storage.attr_span => - Result<#value, #error_path> - ) - } - QueryKind::ValueQuery => quote::quote!(#value), - }; - quote::quote_spanned!(storage.attr_span => - #(#cfg_attrs)* - impl<#type_impl_gen> #pallet_ident<#type_use_gen> #completed_where_clause { - #[doc = #getter_doc_line] - pub fn #getter(k: KArg) -> #query where - KArg: #frame_support::__private::codec::EncodeLike<#key>, - { - // NOTE: we can't use any trait here because CountedStorageMap - // doesn't implement any. - <#full_ident>::get(k) - } - } - ) - } - Metadata::DoubleMap { key1, key2, value } => { - let query = match storage.query_kind.as_ref().expect("Checked by def") { - QueryKind::OptionQuery => quote::quote_spanned!(storage.attr_span => - Option<#value> - ), - QueryKind::ResultQuery(error_path, _) => { - quote::quote_spanned!(storage.attr_span => - Result<#value, #error_path> - ) - } - QueryKind::ValueQuery => quote::quote!(#value), - }; - quote::quote_spanned!(storage.attr_span => - #(#cfg_attrs)* - impl<#type_impl_gen> #pallet_ident<#type_use_gen> #completed_where_clause { - #[doc = #getter_doc_line] - pub fn #getter(k1: KArg1, k2: KArg2) -> #query where - KArg1: #frame_support::__private::codec::EncodeLike<#key1>, - KArg2: #frame_support::__private::codec::EncodeLike<#key2>, - { - < - #full_ident as - #frame_support::storage::StorageDoubleMap<#key1, #key2, #value> - >::get(k1, k2) - } - } - ) - } - Metadata::NMap { keygen, value, .. } => { - let query = match storage.query_kind.as_ref().expect("Checked by def") { - QueryKind::OptionQuery => quote::quote_spanned!(storage.attr_span => - Option<#value> - ), - QueryKind::ResultQuery(error_path, _) => { - quote::quote_spanned!(storage.attr_span => - Result<#value, #error_path> - ) - } - QueryKind::ValueQuery => quote::quote!(#value), - }; - quote::quote_spanned!(storage.attr_span => - #(#cfg_attrs)* - impl<#type_impl_gen> #pallet_ident<#type_use_gen> #completed_where_clause { - #[doc = #getter_doc_line] - pub fn #getter(key: KArg) -> #query - where - KArg: #frame_support::storage::types::EncodeLikeTuple< - <#keygen as #frame_support::storage::types::KeyGenerator>::KArg - > - + #frame_support::storage::types::TupleToEncodedIter, - { - < - #full_ident as - #frame_support::storage::StorageNMap<#keygen, #value> - >::get(key) - } - } - ) - } - Metadata::CountedNMap { keygen, value, .. } => { - let query = match storage.query_kind.as_ref().expect("Checked by def") { - QueryKind::OptionQuery => quote::quote_spanned!(storage.attr_span => - Option<#value> - ), - QueryKind::ResultQuery(error_path, _) => { - quote::quote_spanned!(storage.attr_span => - Result<#value, #error_path> - ) - } - QueryKind::ValueQuery => quote::quote!(#value), - }; - quote::quote_spanned!(storage.attr_span => - #(#cfg_attrs)* - impl<#type_impl_gen> #pallet_ident<#type_use_gen> #completed_where_clause { - #[doc = #getter_doc_line] - pub fn #getter(key: KArg) -> #query - where - KArg: #frame_support::storage::types::EncodeLikeTuple< - <#keygen as #frame_support::storage::types::KeyGenerator>::KArg - > - + #frame_support::storage::types::TupleToEncodedIter, - { - // NOTE: we can't use any trait here because CountedStorageNMap - // doesn't implement any. - <#full_ident>::get(key) - } - } - ) - } - } - } else { - Default::default() - } - }); - - let prefix_structs = def.storages.iter().map(|storage_def| { - let type_impl_gen = &def.type_impl_generics(storage_def.attr_span); - let type_use_gen = &def.type_use_generics(storage_def.attr_span); - let prefix_struct_ident = prefix_ident(storage_def); - let prefix_struct_vis = &storage_def.vis; - let prefix_struct_const = storage_def.prefix(); - let config_where_clause = &def.config.where_clause; - - let cfg_attrs = &storage_def.cfg_attrs; - - let maybe_counter = match storage_def.metadata { - Metadata::CountedMap { .. } => { - let counter_prefix_struct_ident = counter_prefix_ident(&storage_def.ident); - let counter_prefix_struct_const = counter_prefix(&prefix_struct_const); - let storage_prefix_hash = two128_str(&counter_prefix_struct_const); - quote::quote_spanned!(storage_def.attr_span => - #(#cfg_attrs)* - #[doc(hidden)] - #prefix_struct_vis struct #counter_prefix_struct_ident<#type_use_gen>( - core::marker::PhantomData<(#type_use_gen,)> - ); - #(#cfg_attrs)* - impl<#type_impl_gen> #frame_support::traits::StorageInstance - for #counter_prefix_struct_ident<#type_use_gen> - #config_where_clause - { - fn pallet_prefix() -> &'static str { - < - ::PalletInfo - as #frame_support::traits::PalletInfo - >::name::>() - .expect("No name found for the pallet in the runtime! This usually means that the pallet wasn't added to `construct_runtime!`.") - } - - fn pallet_prefix_hash() -> [u8; 16] { - < - ::PalletInfo - as #frame_support::traits::PalletInfo - >::name_hash::>() - .expect("No name_hash found for the pallet in the runtime! This usually means that the pallet wasn't added to `construct_runtime!`.") - } - - const STORAGE_PREFIX: &'static str = #counter_prefix_struct_const; - fn storage_prefix_hash() -> [u8; 16] { - #storage_prefix_hash - } - } - #(#cfg_attrs)* - impl<#type_impl_gen> #frame_support::storage::types::CountedStorageMapInstance - for #prefix_struct_ident<#type_use_gen> - #config_where_clause - { - type CounterPrefix = #counter_prefix_struct_ident<#type_use_gen>; - } - ) - }, - Metadata::CountedNMap { .. } => { - let counter_prefix_struct_ident = counter_prefix_ident(&storage_def.ident); - let counter_prefix_struct_const = counter_prefix(&prefix_struct_const); - let storage_prefix_hash = two128_str(&counter_prefix_struct_const); - quote::quote_spanned!(storage_def.attr_span => - #(#cfg_attrs)* - #[doc(hidden)] - #prefix_struct_vis struct #counter_prefix_struct_ident<#type_use_gen>( - core::marker::PhantomData<(#type_use_gen,)> - ); - #(#cfg_attrs)* - impl<#type_impl_gen> #frame_support::traits::StorageInstance - for #counter_prefix_struct_ident<#type_use_gen> - #config_where_clause - { - fn pallet_prefix() -> &'static str { - < - ::PalletInfo - as #frame_support::traits::PalletInfo - >::name::>() - .expect("No name found for the pallet in the runtime! This usually means that the pallet wasn't added to `construct_runtime!`.") - } - fn pallet_prefix_hash() -> [u8; 16] { - < - ::PalletInfo - as #frame_support::traits::PalletInfo - >::name_hash::>() - .expect("No name_hash found for the pallet in the runtime! This usually means that the pallet wasn't added to `construct_runtime!`.") - } - const STORAGE_PREFIX: &'static str = #counter_prefix_struct_const; - fn storage_prefix_hash() -> [u8; 16] { - #storage_prefix_hash - } - } - #(#cfg_attrs)* - impl<#type_impl_gen> #frame_support::storage::types::CountedStorageNMapInstance - for #prefix_struct_ident<#type_use_gen> - #config_where_clause - { - type CounterPrefix = #counter_prefix_struct_ident<#type_use_gen>; - } - ) - }, - _ => proc_macro2::TokenStream::default(), - }; - - let storage_prefix_hash = two128_str(&prefix_struct_const); - quote::quote_spanned!(storage_def.attr_span => - #maybe_counter - - #(#cfg_attrs)* - #[doc(hidden)] - #prefix_struct_vis struct #prefix_struct_ident<#type_use_gen>( - core::marker::PhantomData<(#type_use_gen,)> - ); - #(#cfg_attrs)* - impl<#type_impl_gen> #frame_support::traits::StorageInstance - for #prefix_struct_ident<#type_use_gen> - #config_where_clause - { - fn pallet_prefix() -> &'static str { - < - ::PalletInfo - as #frame_support::traits::PalletInfo - >::name::>() - .expect("No name found for the pallet in the runtime! This usually means that the pallet wasn't added to `construct_runtime!`.") - } - - fn pallet_prefix_hash() -> [u8; 16] { - < - ::PalletInfo - as #frame_support::traits::PalletInfo - >::name_hash::>() - .expect("No name_hash found for the pallet in the runtime! This usually means that the pallet wasn't added to `construct_runtime!`.") - } - - const STORAGE_PREFIX: &'static str = #prefix_struct_const; - fn storage_prefix_hash() -> [u8; 16] { - #storage_prefix_hash - } - } - ) - }); - - let on_empty_structs = on_empty_struct_metadata.into_iter().map(|metadata| { - use crate::pallet::parse::GenericKind; - use syn::{GenericArgument, Path, PathArguments, PathSegment, Type, TypePath}; - - let ResultOnEmptyStructMetadata { - name, - visibility, - value_ty, - error_path, - variant_name, - span, - } = metadata; - - let generic_kind = match error_path.segments.last() { - Some(PathSegment { - arguments: PathArguments::AngleBracketed(args), - .. - }) => { - let (has_config, has_instance) = - args.args - .iter() - .fold( - (false, false), - |(has_config, has_instance), arg| match arg { - GenericArgument::Type(Type::Path(TypePath { - path: Path { segments, .. }, - .. - })) => { - let maybe_config = - segments.first().map_or(false, |seg| seg.ident == "T"); - let maybe_instance = - segments.first().map_or(false, |seg| seg.ident == "I"); - - (has_config || maybe_config, has_instance || maybe_instance) - } - _ => (has_config, has_instance), - }, - ); - GenericKind::from_gens(has_config, has_instance).unwrap_or(GenericKind::None) - } - _ => GenericKind::None, - }; - let type_impl_gen = generic_kind.type_impl_gen(proc_macro2::Span::call_site()); - let config_where_clause = &def.config.where_clause; - - quote::quote_spanned!(span => - #[doc(hidden)] - #[allow(non_camel_case_types)] - #visibility struct #name; - - impl<#type_impl_gen> #frame_support::traits::Get> - for #name - #config_where_clause - { - fn get() -> Result<#value_ty, #error_path> { - Err(<#error_path>::#variant_name) - } - } - ) - }); - - // aggregated where clause of all storage types and the whole pallet. - let mut where_clauses = vec![&def.config.where_clause]; - where_clauses.extend(def.storages.iter().map(|storage| &storage.where_clause)); - let completed_where_clause = super::merge_where_clauses(&where_clauses); - let type_impl_gen = &def.type_impl_generics(proc_macro2::Span::call_site()); - let type_use_gen = &def.type_use_generics(proc_macro2::Span::call_site()); - - let try_decode_entire_state = { - let mut storage_names = def - .storages - .iter() - .filter_map(|storage| { - // A little hacky; don't generate for cfg gated storages to not get compile errors - // when building "frame-feature-testing" gated storages in the "frame-support-test" - // crate. - if storage.try_decode && storage.cfg_attrs.is_empty() { - let ident = &storage.ident; - let generics = &def.type_use_generics(storage.attr_span); - Some(quote::quote_spanned!(storage.attr_span => #ident<#generics> )) - } else { - None - } - }) - .collect::>(); - storage_names.sort_by_cached_key(|ident| ident.to_string()); - - quote::quote!( - #frame_support::try_runtime_enabled! { - impl<#type_impl_gen> #frame_support::traits::TryDecodeEntireStorage - for #pallet_ident<#type_use_gen> #completed_where_clause - { - fn try_decode_entire_state() -> Result> { - let pallet_name = <::PalletInfo as #frame_support::traits::PalletInfo> - ::name::<#pallet_ident<#type_use_gen>>() - .expect("Every active pallet has a name in the runtime; qed"); - - #frame_support::__private::log::debug!(target: "runtime::try-decode-state", "trying to decode pallet: {pallet_name}"); - - // NOTE: for now, we have to exclude storage items that are feature gated. - let mut errors = #frame_support::__private::Vec::new(); - let mut decoded = 0usize; - - #( - #frame_support::__private::log::debug!(target: "runtime::try-decode-state", "trying to decode storage: \ - {pallet_name}::{}", stringify!(#storage_names)); - - match <#storage_names as #frame_support::traits::TryDecodeEntireStorage>::try_decode_entire_state() { - Ok(count) => { - decoded += count; - }, - Err(err) => { - errors.extend(err); - }, - } - )* - - if errors.is_empty() { - Ok(decoded) - } else { - Err(errors) - } - } - } - } - ) - }; - - quote::quote!( - impl<#type_impl_gen> #pallet_ident<#type_use_gen> - #completed_where_clause - { - #[doc(hidden)] - pub fn storage_metadata() -> #frame_support::__private::metadata_ir::PalletStorageMetadataIR { - #frame_support::__private::metadata_ir::PalletStorageMetadataIR { - prefix: < - ::PalletInfo as - #frame_support::traits::PalletInfo - >::name::<#pallet_ident<#type_use_gen>>() - .expect("No name found for the pallet in the runtime! This usually means that the pallet wasn't added to `construct_runtime!`."), - entries: { - #[allow(unused_mut)] - let mut entries = #frame_support::__private::vec![]; - #( #entries_builder )* - entries - }, - } - } - } - - #( #getters )* - #( #prefix_structs )* - #( #on_empty_structs )* - - #try_decode_entire_state - ) -} diff --git a/support/procedural-fork/src/pallet/expand/tasks.rs b/support/procedural-fork/src/pallet/expand/tasks.rs deleted file mode 100644 index 98496009b3..0000000000 --- a/support/procedural-fork/src/pallet/expand/tasks.rs +++ /dev/null @@ -1,280 +0,0 @@ -//! Contains logic for expanding task-related items. - -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//! Home of the expansion code for the Tasks API - -use crate::pallet::{Def, parse::tasks::*}; -use derive_syn_parse::Parse; -use inflector::Inflector; -use proc_macro2::TokenStream as TokenStream2; -use quote::{ToTokens, format_ident, quote}; -use syn::{ItemEnum, ItemImpl, parse_quote, spanned::Spanned}; - -impl TaskEnumDef { - /// Since we optionally allow users to manually specify a `#[pallet::task_enum]`, in the - /// event they _don't_ specify one (which is actually the most common behavior) we have to - /// generate one based on the existing [`TasksDef`]. This method performs that generation. - pub fn generate( - tasks: &TasksDef, - type_decl_bounded_generics: TokenStream2, - type_use_generics: TokenStream2, - ) -> Self { - let variants = if tasks.tasks_attr.is_some() { - tasks - .tasks - .iter() - .map(|task| { - let ident = &task.item.sig.ident; - let ident = - format_ident!("{}", ident.to_string().to_class_case(), span = ident.span()); - - let args = task.item.sig.inputs.iter().collect::>(); - - if args.is_empty() { - quote!(#ident) - } else { - quote!(#ident { - #(#args),* - }) - } - }) - .collect::>() - } else { - Vec::new() - }; - let mut task_enum_def: TaskEnumDef = parse_quote! { - /// Auto-generated enum that encapsulates all tasks defined by this pallet. - /// - /// Conceptually similar to the [`Call`] enum, but for tasks. This is only - /// generated if there are tasks present in this pallet. - #[pallet::task_enum] - pub enum Task<#type_decl_bounded_generics> { - #( - #variants, - )* - } - }; - task_enum_def.type_use_generics = type_use_generics; - task_enum_def - } -} - -impl ToTokens for TaskEnumDef { - fn to_tokens(&self, tokens: &mut TokenStream2) { - let item_enum = &self.item_enum; - let ident = &item_enum.ident; - let vis = &item_enum.vis; - let attrs = &item_enum.attrs; - let generics = &item_enum.generics; - let variants = &item_enum.variants; - let scrate = &self.scrate; - let type_use_generics = &self.type_use_generics; - if self.attr.is_some() { - // `item_enum` is short-hand / generated enum - tokens.extend(quote! { - #(#attrs)* - #[derive( - #scrate::CloneNoBound, - #scrate::EqNoBound, - #scrate::PartialEqNoBound, - #scrate::pallet_prelude::Encode, - #scrate::pallet_prelude::Decode, - #scrate::pallet_prelude::TypeInfo, - )] - #[codec(encode_bound())] - #[codec(decode_bound())] - #[scale_info(skip_type_params(#type_use_generics))] - #vis enum #ident #generics { - #variants - #[doc(hidden)] - #[codec(skip)] - __Ignore(core::marker::PhantomData, #scrate::Never), - } - - impl core::fmt::Debug for #ident<#type_use_generics> { - fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { - f.debug_struct(stringify!(#ident)).field("value", self).finish() - } - } - }); - } else { - // `item_enum` is a manually specified enum (no attribute) - tokens.extend(item_enum.to_token_stream()); - } - } -} - -/// Represents an already-expanded [`TasksDef`]. -#[derive(Parse)] -pub struct ExpandedTasksDef { - pub task_item_impl: ItemImpl, - pub task_trait_impl: ItemImpl, -} - -impl ToTokens for TasksDef { - fn to_tokens(&self, tokens: &mut TokenStream2) { - let scrate = &self.scrate; - let enum_ident = syn::Ident::new("Task", self.enum_ident.span()); - let enum_arguments = &self.enum_arguments; - let enum_use = quote!(#enum_ident #enum_arguments); - - let task_fn_idents = self - .tasks - .iter() - .map(|task| { - format_ident!( - "{}", - &task.item.sig.ident.to_string().to_class_case(), - span = task.item.sig.ident.span() - ) - }) - .collect::>(); - let task_indices = self.tasks.iter().map(|task| &task.index_attr.meta.index); - let task_conditions = self.tasks.iter().map(|task| &task.condition_attr.meta.expr); - let task_weights = self.tasks.iter().map(|task| &task.weight_attr.meta.expr); - let task_iters = self.tasks.iter().map(|task| &task.list_attr.meta.expr); - - let task_fn_impls = self.tasks.iter().map(|task| { - let mut task_fn_impl = task.item.clone(); - task_fn_impl.attrs = vec![]; - task_fn_impl - }); - - let task_fn_names = self.tasks.iter().map(|task| &task.item.sig.ident); - let task_arg_names = self - .tasks - .iter() - .map(|task| &task.arg_names) - .collect::>(); - - let impl_generics = &self.item_impl.generics; - tokens.extend(quote! { - impl #impl_generics #enum_use - { - #(#task_fn_impls)* - } - - impl #impl_generics #scrate::traits::Task for #enum_use - { - type Enumeration = #scrate::__private::IntoIter<#enum_use>; - - fn iter() -> Self::Enumeration { - let mut all_tasks = #scrate::__private::vec![]; - #(all_tasks - .extend(#task_iters.map(|(#(#task_arg_names),*)| #enum_ident::#task_fn_idents { #(#task_arg_names: #task_arg_names.clone()),* }) - .collect::<#scrate::__private::Vec<_>>()); - )* - all_tasks.into_iter() - } - - fn task_index(&self) -> u32 { - match self.clone() { - #(#enum_ident::#task_fn_idents { .. } => #task_indices,)* - Task::__Ignore(_, _) => unreachable!(), - } - } - - fn is_valid(&self) -> bool { - match self.clone() { - #(#enum_ident::#task_fn_idents { #(#task_arg_names),* } => (#task_conditions)(#(#task_arg_names),* ),)* - Task::__Ignore(_, _) => unreachable!(), - } - } - - fn run(&self) -> Result<(), #scrate::pallet_prelude::DispatchError> { - match self.clone() { - #(#enum_ident::#task_fn_idents { #(#task_arg_names),* } => { - <#enum_use>::#task_fn_names(#( #task_arg_names, )* ) - },)* - Task::__Ignore(_, _) => unreachable!(), - } - } - - #[allow(unused_variables)] - fn weight(&self) -> #scrate::pallet_prelude::Weight { - match self.clone() { - #(#enum_ident::#task_fn_idents { #(#task_arg_names),* } => #task_weights,)* - Task::__Ignore(_, _) => unreachable!(), - } - } - } - }); - } -} - -/// Expands the [`TasksDef`] in the enclosing [`Def`], if present, and returns its tokens. -/// -/// This modifies the underlying [`Def`] in addition to returning any tokens that were added. -pub fn expand_tasks_impl(def: &mut Def) -> TokenStream2 { - let Some(tasks) = &mut def.tasks else { - return quote!(); - }; - let ExpandedTasksDef { - task_item_impl, - task_trait_impl, - } = parse_quote!(#tasks); - quote! { - #task_item_impl - #task_trait_impl - } -} - -/// Represents a fully-expanded [`TaskEnumDef`]. -#[derive(Parse)] -pub struct ExpandedTaskEnum { - pub item_enum: ItemEnum, - pub debug_impl: ItemImpl, -} - -/// Modifies a [`Def`] to expand the underlying [`TaskEnumDef`] if present, and also returns -/// its tokens. A blank [`TokenStream2`] is returned if no [`TaskEnumDef`] has been generated -/// or defined. -pub fn expand_task_enum(def: &mut Def) -> TokenStream2 { - let Some(task_enum) = &mut def.task_enum else { - return quote!(); - }; - let ExpandedTaskEnum { - item_enum, - debug_impl, - } = parse_quote!(#task_enum); - quote! { - #item_enum - #debug_impl - } -} - -/// Modifies a [`Def`] to expand the underlying [`TasksDef`] and also generate a -/// [`TaskEnumDef`] if applicable. The tokens for these items are returned if they are created. -pub fn expand_tasks(def: &mut Def) -> TokenStream2 { - if let Some(tasks_def) = &def.tasks { - if def.task_enum.is_none() { - def.task_enum = Some(TaskEnumDef::generate( - &tasks_def, - def.type_decl_bounded_generics(tasks_def.item_impl.span()), - def.type_use_generics(tasks_def.item_impl.span()), - )); - } - } - let tasks_extra_output = expand_tasks_impl(def); - let task_enum_extra_output = expand_task_enum(def); - quote! { - #tasks_extra_output - #task_enum_extra_output - } -} diff --git a/support/procedural-fork/src/pallet/expand/tt_default_parts.rs b/support/procedural-fork/src/pallet/expand/tt_default_parts.rs deleted file mode 100644 index abd48aa21d..0000000000 --- a/support/procedural-fork/src/pallet/expand/tt_default_parts.rs +++ /dev/null @@ -1,226 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use crate::{ - COUNTER, - pallet::{CompositeKeyword, Def}, -}; -use syn::spanned::Spanned; - -/// Generate the `tt_default_parts` macro. -pub fn expand_tt_default_parts(def: &mut Def) -> proc_macro2::TokenStream { - let count = COUNTER.with(|counter| counter.borrow_mut().inc()); - let default_parts_unique_id = - syn::Ident::new(&format!("__tt_default_parts_{}", count), def.item.span()); - let extra_parts_unique_id = - syn::Ident::new(&format!("__tt_extra_parts_{}", count), def.item.span()); - let default_parts_unique_id_v2 = - syn::Ident::new(&format!("__tt_default_parts_v2_{}", count), def.item.span()); - - let call_part = def.call.as_ref().map(|_| quote::quote!(Call,)); - - let task_part = def.task_enum.as_ref().map(|_| quote::quote!(Task,)); - - let storage_part = (!def.storages.is_empty()).then(|| quote::quote!(Storage,)); - - let event_part = def.event.as_ref().map(|event| { - let generics = event.gen_kind.is_generic().then(|| quote::quote!( )); - quote::quote!( Event #generics , ) - }); - - let error_part = def.error.as_ref().map(|_| quote::quote!(Error,)); - - let origin_part = def.origin.as_ref().map(|origin| { - let generics = origin.is_generic.then(|| quote::quote!( )); - quote::quote!( Origin #generics , ) - }); - - let config_part = def.genesis_config.as_ref().map(|genesis_config| { - let generic = genesis_config - .gen_kind - .is_generic() - .then(|| quote::quote!( )); - quote::quote!( Config #generic , ) - }); - - let inherent_part = def.inherent.as_ref().map(|_| quote::quote!(Inherent,)); - - let validate_unsigned_part = def - .validate_unsigned - .as_ref() - .map(|_| quote::quote!(ValidateUnsigned,)); - - let freeze_reason_part = def - .composites - .iter() - .any(|c| matches!(c.composite_keyword, CompositeKeyword::FreezeReason(_))) - .then_some(quote::quote!(FreezeReason,)); - - let hold_reason_part = def - .composites - .iter() - .any(|c| matches!(c.composite_keyword, CompositeKeyword::HoldReason(_))) - .then_some(quote::quote!(HoldReason,)); - - let lock_id_part = def - .composites - .iter() - .any(|c| matches!(c.composite_keyword, CompositeKeyword::LockId(_))) - .then_some(quote::quote!(LockId,)); - - let slash_reason_part = def - .composites - .iter() - .any(|c| matches!(c.composite_keyword, CompositeKeyword::SlashReason(_))) - .then_some(quote::quote!(SlashReason,)); - - let call_part_v2 = def.call.as_ref().map(|_| quote::quote!(+ Call)); - - let task_part_v2 = def.task_enum.as_ref().map(|_| quote::quote!(+ Task)); - - let storage_part_v2 = (!def.storages.is_empty()).then(|| quote::quote!(+ Storage)); - - let event_part_v2 = def.event.as_ref().map(|event| { - let generic = event.gen_kind.is_generic().then(|| quote::quote!()); - quote::quote!(+ Event #generic) - }); - - let error_part_v2 = def.error.as_ref().map(|_| quote::quote!(+ Error)); - - let origin_part_v2 = def.origin.as_ref().map(|origin| { - let generic = origin.is_generic.then(|| quote::quote!()); - quote::quote!(+ Origin #generic) - }); - - let config_part_v2 = def.genesis_config.as_ref().map(|genesis_config| { - let generic = genesis_config - .gen_kind - .is_generic() - .then(|| quote::quote!()); - quote::quote!(+ Config #generic) - }); - - let inherent_part_v2 = def.inherent.as_ref().map(|_| quote::quote!(+ Inherent)); - - let validate_unsigned_part_v2 = def - .validate_unsigned - .as_ref() - .map(|_| quote::quote!(+ ValidateUnsigned)); - - let freeze_reason_part_v2 = def - .composites - .iter() - .any(|c| matches!(c.composite_keyword, CompositeKeyword::FreezeReason(_))) - .then_some(quote::quote!(+ FreezeReason)); - - let hold_reason_part_v2 = def - .composites - .iter() - .any(|c| matches!(c.composite_keyword, CompositeKeyword::HoldReason(_))) - .then_some(quote::quote!(+ HoldReason)); - - let lock_id_part_v2 = def - .composites - .iter() - .any(|c| matches!(c.composite_keyword, CompositeKeyword::LockId(_))) - .then_some(quote::quote!(+ LockId)); - - let slash_reason_part_v2 = def - .composites - .iter() - .any(|c| matches!(c.composite_keyword, CompositeKeyword::SlashReason(_))) - .then_some(quote::quote!(+ SlashReason)); - - quote::quote!( - // This macro follows the conventions as laid out by the `tt-call` crate. It does not - // accept any arguments and simply returns the pallet parts, separated by commas, then - // wrapped inside of braces and finally prepended with double colons, to the caller inside - // of a key named `tokens`. - // - // We need to accept a path argument here, because this macro gets expanded on the - // crate that called the `construct_runtime!` macro, and the actual path is unknown. - #[macro_export] - #[doc(hidden)] - macro_rules! #default_parts_unique_id { - { - $caller:tt - your_tt_return = [{ $my_tt_return:path }] - } => { - $my_tt_return! { - $caller - tokens = [{ - expanded::{ - Pallet, #call_part #storage_part #event_part #error_part #origin_part #config_part - #inherent_part #validate_unsigned_part #freeze_reason_part #task_part - #hold_reason_part #lock_id_part #slash_reason_part - } - }] - } - }; - } - - pub use #default_parts_unique_id as tt_default_parts; - - - // This macro is similar to the `tt_default_parts!`. It expands the pallets that are declared - // explicitly (`System: frame_system::{Pallet, Call}`) with extra parts. - // - // For example, after expansion an explicit pallet would look like: - // `System: expanded::{Error} ::{Pallet, Call}`. - // - // The `expanded` keyword is a marker of the final state of the `construct_runtime!`. - #[macro_export] - #[doc(hidden)] - macro_rules! #extra_parts_unique_id { - { - $caller:tt - your_tt_return = [{ $my_tt_return:path }] - } => { - $my_tt_return! { - $caller - tokens = [{ - expanded::{ - #error_part - } - }] - } - }; - } - - pub use #extra_parts_unique_id as tt_extra_parts; - - #[macro_export] - #[doc(hidden)] - macro_rules! #default_parts_unique_id_v2 { - { - $caller:tt - your_tt_return = [{ $my_tt_return:path }] - } => { - $my_tt_return! { - $caller - tokens = [{ - + Pallet #call_part_v2 #storage_part_v2 #event_part_v2 #error_part_v2 #origin_part_v2 #config_part_v2 - #inherent_part_v2 #validate_unsigned_part_v2 #freeze_reason_part_v2 #task_part_v2 - #hold_reason_part_v2 #lock_id_part_v2 #slash_reason_part_v2 - }] - } - }; - } - - pub use #default_parts_unique_id_v2 as tt_default_parts_v2; - ) -} diff --git a/support/procedural-fork/src/pallet/expand/type_value.rs b/support/procedural-fork/src/pallet/expand/type_value.rs deleted file mode 100644 index 84db3e4315..0000000000 --- a/support/procedural-fork/src/pallet/expand/type_value.rs +++ /dev/null @@ -1,77 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use crate::pallet::Def; - -/// -/// * Generate the struct -/// * implement the `Get<..>` on it -/// * Rename the name of the function to internal name -pub fn expand_type_values(def: &mut Def) -> proc_macro2::TokenStream { - let mut expand = quote::quote!(); - let frame_support = &def.frame_support; - - for type_value in &def.type_values { - let fn_name_str = &type_value.ident.to_string(); - let fn_name_snakecase = inflector::cases::snakecase::to_snake_case(fn_name_str); - let fn_ident_renamed = syn::Ident::new( - &format!("__type_value_for_{}", fn_name_snakecase), - type_value.ident.span(), - ); - - let type_value_item = { - let item = &mut def.item.content.as_mut().expect("Checked by def").1[type_value.index]; - if let syn::Item::Fn(item) = item { - item - } else { - unreachable!("Checked by error parser") - } - }; - - // Rename the type_value function name - type_value_item.sig.ident = fn_ident_renamed.clone(); - - let vis = &type_value.vis; - let ident = &type_value.ident; - let type_ = &type_value.type_; - let where_clause = &type_value.where_clause; - - let (struct_impl_gen, struct_use_gen) = if type_value.is_generic { - ( - def.type_impl_generics(type_value.attr_span), - def.type_use_generics(type_value.attr_span), - ) - } else { - (Default::default(), Default::default()) - }; - - let docs = &type_value.docs; - - expand.extend(quote::quote_spanned!(type_value.attr_span => - #( #[doc = #docs] )* - #vis struct #ident<#struct_use_gen>(core::marker::PhantomData<((), #struct_use_gen)>); - impl<#struct_impl_gen> #frame_support::traits::Get<#type_> for #ident<#struct_use_gen> - #where_clause - { - fn get() -> #type_ { - #fn_ident_renamed::<#struct_use_gen>() - } - } - )); - } - expand -} diff --git a/support/procedural-fork/src/pallet/expand/validate_unsigned.rs b/support/procedural-fork/src/pallet/expand/validate_unsigned.rs deleted file mode 100644 index a3a849704d..0000000000 --- a/support/procedural-fork/src/pallet/expand/validate_unsigned.rs +++ /dev/null @@ -1,58 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use crate::{COUNTER, pallet::Def}; -use proc_macro2::TokenStream; -use quote::quote; -use syn::{Ident, spanned::Spanned}; - -pub fn expand_validate_unsigned(def: &mut Def) -> TokenStream { - let count = COUNTER.with(|counter| counter.borrow_mut().inc()); - let macro_ident = Ident::new( - &format!("__is_validate_unsigned_part_defined_{}", count), - def.item.span(), - ); - - let maybe_compile_error = if def.validate_unsigned.is_none() { - quote! { - compile_error!(concat!( - "`", - stringify!($pallet_name), - "` does not have #[pallet::validate_unsigned] defined, perhaps you should \ - remove `ValidateUnsigned` from construct_runtime?", - )); - } - } else { - TokenStream::new() - }; - - quote! { - #[doc(hidden)] - pub mod __substrate_validate_unsigned_check { - #[macro_export] - #[doc(hidden)] - macro_rules! #macro_ident { - ($pallet_name:ident) => { - #maybe_compile_error - } - } - - #[doc(hidden)] - pub use #macro_ident as is_validate_unsigned_part_defined; - } - } -} diff --git a/support/procedural-fork/src/pallet/expand/warnings.rs b/support/procedural-fork/src/pallet/expand/warnings.rs deleted file mode 100644 index 3d71b83aff..0000000000 --- a/support/procedural-fork/src/pallet/expand/warnings.rs +++ /dev/null @@ -1,103 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//! Generates warnings for undesirable pallet code. - -use crate::pallet::parse::call::{CallVariantDef, CallWeightDef}; -use proc_macro_warning::Warning; -use syn::{ - spanned::Spanned, - visit::{self, Visit}, -}; - -/// Warn if any of the call arguments starts with a underscore and is used in a weight formula. -pub(crate) fn weight_witness_warning( - method: &CallVariantDef, - dev_mode: bool, - warnings: &mut Vec, -) { - if dev_mode { - return; - } - let CallWeightDef::Immediate(w) = &method.weight else { - return; - }; - - let partial_warning = Warning::new_deprecated("UncheckedWeightWitness") - .old("not check weight witness data") - .new("ensure that all witness data for weight calculation is checked before usage") - .help_link("https://github.com/paritytech/polkadot-sdk/pull/1818"); - - for (_, arg_ident, _) in method.args.iter() { - if !arg_ident.to_string().starts_with('_') || !contains_ident(w.clone(), &arg_ident) { - continue; - } - - let warning = partial_warning - .clone() - .index(warnings.len()) - .span(arg_ident.span()) - .build_or_panic(); - - warnings.push(warning); - } -} - -/// Warn if the weight is a constant and the pallet not in `dev_mode`. -pub(crate) fn weight_constant_warning( - weight: &syn::Expr, - dev_mode: bool, - warnings: &mut Vec, -) { - if dev_mode { - return; - } - let syn::Expr::Lit(lit) = weight else { return }; - - let warning = Warning::new_deprecated("ConstantWeight") - .index(warnings.len()) - .old("use hard-coded constant as call weight") - .new("benchmark all calls or put the pallet into `dev` mode") - .help_link("https://github.com/paritytech/substrate/pull/13798") - .span(lit.span()) - .build_or_panic(); - - warnings.push(warning); -} - -/// Returns whether `expr` contains `ident`. -fn contains_ident(mut expr: syn::Expr, ident: &syn::Ident) -> bool { - struct ContainsIdent { - ident: syn::Ident, - found: bool, - } - - impl<'a> Visit<'a> for ContainsIdent { - fn visit_ident(&mut self, i: &syn::Ident) { - if *i == self.ident { - self.found = true; - } - } - } - - let mut visitor = ContainsIdent { - ident: ident.clone(), - found: false, - }; - visit::visit_expr(&mut visitor, &mut expr); - visitor.found -} diff --git a/support/procedural-fork/src/pallet/mod.rs b/support/procedural-fork/src/pallet/mod.rs deleted file mode 100644 index 3636cc611b..0000000000 --- a/support/procedural-fork/src/pallet/mod.rs +++ /dev/null @@ -1,61 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//! Implementation for pallet attribute macro. -//! -//! General workflow: -//! 1 - parse all pallet attributes: -//! This step remove all attributes `#[pallet::*]` from the ItemMod and build the `Def` struct -//! which holds the ItemMod without `#[pallet::*]` and information given by those attributes -//! 2 - expand from the parsed information -//! This step will modify the ItemMod by adding some derive attributes or phantom data variants -//! to user defined types. And also crate new types and implement block. - -mod expand; -pub(crate) mod parse; - -pub use parse::{Def, composite::keyword::CompositeKeyword}; -use syn::spanned::Spanned; - -mod keyword { - syn::custom_keyword!(dev_mode); -} - -pub fn pallet( - attr: proc_macro::TokenStream, - item: proc_macro::TokenStream, -) -> proc_macro::TokenStream { - let mut dev_mode = false; - if !attr.is_empty() { - if let Ok(_) = syn::parse::(attr.clone()) { - dev_mode = true; - } else { - let msg = "Invalid pallet macro call: unexpected attribute. Macro call must be \ - bare, such as `#[frame_support::pallet]` or `#[pallet]`, or must specify the \ - `dev_mode` attribute, such as `#[frame_support::pallet(dev_mode)]` or \ - #[pallet(dev_mode)]."; - let span = proc_macro2::TokenStream::from(attr).span(); - return syn::Error::new(span, msg).to_compile_error().into(); - } - } - - let item = syn::parse_macro_input!(item as syn::ItemMod); - match parse::Def::try_from(item, dev_mode) { - Ok(def) => expand::expand(def).into(), - Err(e) => e.to_compile_error().into(), - } -} diff --git a/support/procedural-fork/src/pallet/parse/call.rs b/support/procedural-fork/src/pallet/parse/call.rs deleted file mode 100644 index 5555bfdc16..0000000000 --- a/support/procedural-fork/src/pallet/parse/call.rs +++ /dev/null @@ -1,471 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use super::{InheritedCallWeightAttr, helper}; -use frame_support_procedural_tools::get_doc_literals; -use proc_macro2::Span; -use quote::ToTokens; -use std::collections::HashMap; -use syn::{ExprClosure, spanned::Spanned}; - -/// List of additional token to be used for parsing. -mod keyword { - syn::custom_keyword!(Call); - syn::custom_keyword!(OriginFor); - syn::custom_keyword!(RuntimeOrigin); - syn::custom_keyword!(weight); - syn::custom_keyword!(call_index); - syn::custom_keyword!(compact); - syn::custom_keyword!(T); - syn::custom_keyword!(pallet); - syn::custom_keyword!(feeless_if); -} - -/// Definition of dispatchables typically `impl Pallet { ... }` -pub struct CallDef { - /// The where_clause used. - pub where_clause: Option, - /// A set of usage of instance, must be check for consistency with trait. - pub instances: Vec, - /// The index of call item in pallet module. - pub index: usize, - /// Information on methods (used for expansion). - pub methods: Vec, - /// The span of the pallet::call attribute. - pub attr_span: proc_macro2::Span, - /// Docs, specified on the impl Block. - pub docs: Vec, - /// The optional `weight` attribute on the `pallet::call`. - pub inherited_call_weight: Option, -} - -/// The weight of a call. -#[derive(Clone)] -pub enum CallWeightDef { - /// Explicitly set on the call itself with `#[pallet::weight(…)]`. This value is used. - Immediate(syn::Expr), - - /// The default value that should be set for dev-mode pallets. Usually zero. - DevModeDefault, - - /// Inherits whatever value is configured on the pallet level. - /// - /// The concrete value is not known at this point. - Inherited, -} - -/// Definition of dispatchable typically: `#[weight...] fn foo(origin .., param1: ...) -> ..` -#[derive(Clone)] -pub struct CallVariantDef { - /// Function name. - pub name: syn::Ident, - /// Information on args: `(is_compact, name, type)` - pub args: Vec<(bool, syn::Ident, Box)>, - /// Weight for the call. - pub weight: CallWeightDef, - /// Call index of the dispatchable. - pub call_index: u8, - /// Whether an explicit call index was specified. - pub explicit_call_index: bool, - /// Docs, used for metadata. - pub docs: Vec, - /// Attributes annotated at the top of the dispatchable function. - pub attrs: Vec, - /// The `cfg` attributes. - pub cfg_attrs: Vec, - /// The optional `feeless_if` attribute on the `pallet::call`. - pub feeless_check: Option, -} - -/// Attributes for functions in call impl block. -pub enum FunctionAttr { - /// Parse for `#[pallet::call_index(expr)]` - CallIndex(u8), - /// Parse for `#[pallet::weight(expr)]` - Weight(syn::Expr), - /// Parse for `#[pallet::feeless_if(expr)]` - FeelessIf(Span, syn::ExprClosure), -} - -impl syn::parse::Parse for FunctionAttr { - fn parse(input: syn::parse::ParseStream) -> syn::Result { - input.parse::()?; - let content; - syn::bracketed!(content in input); - content.parse::()?; - content.parse::()?; - - let lookahead = content.lookahead1(); - if lookahead.peek(keyword::weight) { - content.parse::()?; - let weight_content; - syn::parenthesized!(weight_content in content); - Ok(FunctionAttr::Weight(weight_content.parse::()?)) - } else if lookahead.peek(keyword::call_index) { - content.parse::()?; - let call_index_content; - syn::parenthesized!(call_index_content in content); - let index = call_index_content.parse::()?; - if !index.suffix().is_empty() { - let msg = "Number literal must not have a suffix"; - return Err(syn::Error::new(index.span(), msg)); - } - Ok(FunctionAttr::CallIndex(index.base10_parse()?)) - } else if lookahead.peek(keyword::feeless_if) { - content.parse::()?; - let closure_content; - syn::parenthesized!(closure_content in content); - Ok(FunctionAttr::FeelessIf( - closure_content.span(), - closure_content.parse::().map_err(|e| { - let msg = "Invalid feeless_if attribute: expected a closure"; - let mut err = syn::Error::new(closure_content.span(), msg); - err.combine(e); - err - })?, - )) - } else { - Err(lookahead.error()) - } - } -} - -/// Attribute for arguments in function in call impl block. -/// Parse for `#[pallet::compact]| -pub struct ArgAttrIsCompact; - -impl syn::parse::Parse for ArgAttrIsCompact { - fn parse(input: syn::parse::ParseStream) -> syn::Result { - input.parse::()?; - let content; - syn::bracketed!(content in input); - content.parse::()?; - content.parse::()?; - - content.parse::()?; - Ok(ArgAttrIsCompact) - } -} - -/// Check the syntax is `OriginFor`, `&OriginFor` or `T::RuntimeOrigin`. -pub fn check_dispatchable_first_arg_type(ty: &syn::Type, is_ref: bool) -> syn::Result<()> { - pub struct CheckOriginFor(bool); - impl syn::parse::Parse for CheckOriginFor { - fn parse(input: syn::parse::ParseStream) -> syn::Result { - let is_ref = input.parse::().is_ok(); - input.parse::()?; - input.parse::()?; - input.parse::()?; - input.parse::]>()?; - - Ok(Self(is_ref)) - } - } - - pub struct CheckRuntimeOrigin; - impl syn::parse::Parse for CheckRuntimeOrigin { - fn parse(input: syn::parse::ParseStream) -> syn::Result { - input.parse::()?; - input.parse::()?; - input.parse::()?; - - Ok(Self) - } - } - - let result_origin_for = syn::parse2::(ty.to_token_stream()); - let result_runtime_origin = syn::parse2::(ty.to_token_stream()); - return match (result_origin_for, result_runtime_origin) { - (Ok(CheckOriginFor(has_ref)), _) if is_ref == has_ref => Ok(()), - (_, Ok(_)) => Ok(()), - (_, _) => { - let msg = if is_ref { - "Invalid type: expected `&OriginFor`" - } else { - "Invalid type: expected `OriginFor` or `T::RuntimeOrigin`" - }; - return Err(syn::Error::new(ty.span(), msg)); - } - }; -} - -impl CallDef { - pub fn try_from( - attr_span: proc_macro2::Span, - index: usize, - item: &mut syn::Item, - dev_mode: bool, - inherited_call_weight: Option, - ) -> syn::Result { - let item_impl = if let syn::Item::Impl(item) = item { - item - } else { - return Err(syn::Error::new( - item.span(), - "Invalid pallet::call, expected item impl", - )); - }; - - let instances = vec![ - helper::check_impl_gen(&item_impl.generics, item_impl.impl_token.span())?, - helper::check_pallet_struct_usage(&item_impl.self_ty)?, - ]; - - if let Some((_, _, for_)) = item_impl.trait_ { - let msg = "Invalid pallet::call, expected no trait ident as in \ - `impl<..> Pallet<..> { .. }`"; - return Err(syn::Error::new(for_.span(), msg)); - } - - let mut methods = vec![]; - let mut indices = HashMap::new(); - let mut last_index: Option = None; - for item in &mut item_impl.items { - if let syn::ImplItem::Fn(method) = item { - if !matches!(method.vis, syn::Visibility::Public(_)) { - let msg = "Invalid pallet::call, dispatchable function must be public: \ - `pub fn`"; - - let span = match method.vis { - syn::Visibility::Inherited => method.sig.span(), - _ => method.vis.span(), - }; - - return Err(syn::Error::new(span, msg)); - } - - match method.sig.inputs.first() { - None => { - let msg = "Invalid pallet::call, must have at least origin arg"; - return Err(syn::Error::new(method.sig.span(), msg)); - } - Some(syn::FnArg::Receiver(_)) => { - let msg = "Invalid pallet::call, first argument must be a typed argument, \ - e.g. `origin: OriginFor`"; - return Err(syn::Error::new(method.sig.span(), msg)); - } - Some(syn::FnArg::Typed(arg)) => { - check_dispatchable_first_arg_type(&arg.ty, false)?; - } - } - - if let syn::ReturnType::Type(_, type_) = &method.sig.output { - helper::check_pallet_call_return_type(type_)?; - } else { - let msg = "Invalid pallet::call, require return type \ - DispatchResultWithPostInfo"; - return Err(syn::Error::new(method.sig.span(), msg)); - } - - let cfg_attrs: Vec = helper::get_item_cfg_attrs(&method.attrs); - let mut call_idx_attrs = vec![]; - let mut weight_attrs = vec![]; - let mut feeless_attrs = vec![]; - for attr in helper::take_item_pallet_attrs(&mut method.attrs)?.into_iter() { - match attr { - FunctionAttr::CallIndex(_) => { - call_idx_attrs.push(attr); - } - FunctionAttr::Weight(_) => { - weight_attrs.push(attr); - } - FunctionAttr::FeelessIf(span, _) => { - feeless_attrs.push((span, attr)); - } - } - } - - if weight_attrs.is_empty() && dev_mode { - // inject a default O(1) weight when dev mode is enabled and no weight has - // been specified on the call - let empty_weight: syn::Expr = syn::parse_quote!(0); - weight_attrs.push(FunctionAttr::Weight(empty_weight)); - } - - let weight = match weight_attrs.len() { - 0 if inherited_call_weight.is_some() => CallWeightDef::Inherited, - 0 if dev_mode => CallWeightDef::DevModeDefault, - 0 => return Err(syn::Error::new( - method.sig.span(), - "A pallet::call requires either a concrete `#[pallet::weight($expr)]` or an - inherited weight from the `#[pallet:call(weight($type))]` attribute, but - none were given.", - )), - 1 => match weight_attrs.pop().unwrap() { - FunctionAttr::Weight(w) => CallWeightDef::Immediate(w), - _ => unreachable!("checked during creation of the let binding"), - }, - _ => { - let msg = "Invalid pallet::call, too many weight attributes given"; - return Err(syn::Error::new(method.sig.span(), msg)); - } - }; - - if call_idx_attrs.len() > 1 { - let msg = "Invalid pallet::call, too many call_index attributes given"; - return Err(syn::Error::new(method.sig.span(), msg)); - } - let call_index = call_idx_attrs.pop().map(|attr| match attr { - FunctionAttr::CallIndex(idx) => idx, - _ => unreachable!("checked during creation of the let binding"), - }); - let explicit_call_index = call_index.is_some(); - - let final_index = match call_index { - Some(i) => i, - None => last_index - .map_or(Some(0), |idx| idx.checked_add(1)) - .ok_or_else(|| { - let msg = "Call index doesn't fit into u8, index is 256"; - syn::Error::new(method.sig.span(), msg) - })?, - }; - last_index = Some(final_index); - - if let Some(used_fn) = indices.insert(final_index, method.sig.ident.clone()) { - let msg = format!( - "Call indices are conflicting: Both functions {} and {} are at index {}", - used_fn, method.sig.ident, final_index, - ); - let mut err = syn::Error::new(used_fn.span(), &msg); - err.combine(syn::Error::new(method.sig.ident.span(), msg)); - return Err(err); - } - - let mut args = vec![]; - for arg in method.sig.inputs.iter_mut().skip(1) { - let arg = if let syn::FnArg::Typed(arg) = arg { - arg - } else { - unreachable!("Only first argument can be receiver"); - }; - - let arg_attrs: Vec = - helper::take_item_pallet_attrs(&mut arg.attrs)?; - - if arg_attrs.len() > 1 { - let msg = "Invalid pallet::call, argument has too many attributes"; - return Err(syn::Error::new(arg.span(), msg)); - } - - let arg_ident = if let syn::Pat::Ident(pat) = &*arg.pat { - pat.ident.clone() - } else { - let msg = "Invalid pallet::call, argument must be ident"; - return Err(syn::Error::new(arg.pat.span(), msg)); - }; - - args.push((!arg_attrs.is_empty(), arg_ident, arg.ty.clone())); - } - - let docs = get_doc_literals(&method.attrs); - - if feeless_attrs.len() > 1 { - let msg = "Invalid pallet::call, there can only be one feeless_if attribute"; - return Err(syn::Error::new(feeless_attrs[1].0, msg)); - } - let feeless_check: Option = - feeless_attrs.pop().map(|(_, attr)| match attr { - FunctionAttr::FeelessIf(_, closure) => closure, - _ => unreachable!("checked during creation of the let binding"), - }); - - if let Some(ref feeless_check) = feeless_check { - if feeless_check.inputs.len() != args.len() + 1 { - let msg = "Invalid pallet::call, feeless_if closure must have same \ - number of arguments as the dispatchable function"; - return Err(syn::Error::new(feeless_check.span(), msg)); - } - - match feeless_check.inputs.first() { - None => { - let msg = "Invalid pallet::call, feeless_if closure must have at least origin arg"; - return Err(syn::Error::new(feeless_check.span(), msg)); - } - Some(syn::Pat::Type(arg)) => { - check_dispatchable_first_arg_type(&arg.ty, true)?; - } - _ => { - let msg = "Invalid pallet::call, feeless_if closure first argument must be a typed argument, \ - e.g. `origin: OriginFor`"; - return Err(syn::Error::new(feeless_check.span(), msg)); - } - } - - for (feeless_arg, arg) in feeless_check.inputs.iter().skip(1).zip(args.iter()) { - let feeless_arg_type = if let syn::Pat::Type(syn::PatType { ty, .. }) = - feeless_arg.clone() - { - if let syn::Type::Reference(pat) = *ty { - pat.elem.clone() - } else { - let msg = "Invalid pallet::call, feeless_if closure argument must be a reference"; - return Err(syn::Error::new(ty.span(), msg)); - } - } else { - let msg = "Invalid pallet::call, feeless_if closure argument must be a type ascription pattern"; - return Err(syn::Error::new(feeless_arg.span(), msg)); - }; - - if feeless_arg_type != arg.2 { - let msg = "Invalid pallet::call, feeless_if closure argument must have \ - a reference to the same type as the dispatchable function argument"; - return Err(syn::Error::new(feeless_arg.span(), msg)); - } - } - - let valid_return = match &feeless_check.output { - syn::ReturnType::Type(_, type_) => match *(type_.clone()) { - syn::Type::Path(syn::TypePath { path, .. }) => path.is_ident("bool"), - _ => false, - }, - _ => false, - }; - if !valid_return { - let msg = "Invalid pallet::call, feeless_if closure must return `bool`"; - return Err(syn::Error::new(feeless_check.output.span(), msg)); - } - } - - methods.push(CallVariantDef { - name: method.sig.ident.clone(), - weight, - call_index: final_index, - explicit_call_index, - args, - docs, - attrs: method.attrs.clone(), - cfg_attrs, - feeless_check, - }); - } else { - let msg = "Invalid pallet::call, only method accepted"; - return Err(syn::Error::new(item.span(), msg)); - } - } - - Ok(Self { - index, - attr_span, - instances, - methods, - where_clause: item_impl.generics.where_clause.clone(), - docs: get_doc_literals(&item_impl.attrs), - inherited_call_weight, - }) - } -} diff --git a/support/procedural-fork/src/pallet/parse/composite.rs b/support/procedural-fork/src/pallet/parse/composite.rs deleted file mode 100644 index f679710b9a..0000000000 --- a/support/procedural-fork/src/pallet/parse/composite.rs +++ /dev/null @@ -1,193 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use super::helper; -use quote::ToTokens; -use syn::spanned::Spanned; - -pub mod keyword { - use super::*; - - syn::custom_keyword!(FreezeReason); - syn::custom_keyword!(HoldReason); - syn::custom_keyword!(LockId); - syn::custom_keyword!(SlashReason); - syn::custom_keyword!(Task); - - pub enum CompositeKeyword { - FreezeReason(FreezeReason), - HoldReason(HoldReason), - LockId(LockId), - SlashReason(SlashReason), - Task(Task), - } - - impl ToTokens for CompositeKeyword { - fn to_tokens(&self, tokens: &mut proc_macro2::TokenStream) { - use CompositeKeyword::*; - match self { - FreezeReason(inner) => inner.to_tokens(tokens), - HoldReason(inner) => inner.to_tokens(tokens), - LockId(inner) => inner.to_tokens(tokens), - SlashReason(inner) => inner.to_tokens(tokens), - Task(inner) => inner.to_tokens(tokens), - } - } - } - - impl syn::parse::Parse for CompositeKeyword { - fn parse(input: syn::parse::ParseStream) -> syn::Result { - let lookahead = input.lookahead1(); - if lookahead.peek(FreezeReason) { - Ok(Self::FreezeReason(input.parse()?)) - } else if lookahead.peek(HoldReason) { - Ok(Self::HoldReason(input.parse()?)) - } else if lookahead.peek(LockId) { - Ok(Self::LockId(input.parse()?)) - } else if lookahead.peek(SlashReason) { - Ok(Self::SlashReason(input.parse()?)) - } else if lookahead.peek(Task) { - Ok(Self::Task(input.parse()?)) - } else { - Err(lookahead.error()) - } - } - } - - impl std::fmt::Display for CompositeKeyword { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - use CompositeKeyword::*; - write!( - f, - "{}", - match self { - FreezeReason(_) => "FreezeReason", - HoldReason(_) => "HoldReason", - Task(_) => "Task", - LockId(_) => "LockId", - SlashReason(_) => "SlashReason", - } - ) - } - } -} - -pub struct CompositeDef { - /// The composite keyword used (contains span). - pub composite_keyword: keyword::CompositeKeyword, - /// Name of the associated type. - pub ident: syn::Ident, - /// Type parameters and where clause attached to a declaration of the pallet::composite_enum. - pub generics: syn::Generics, - /// The span of the pallet::composite_enum attribute. - pub attr_span: proc_macro2::Span, - /// Variant count of the pallet::composite_enum. - pub variant_count: u32, -} - -impl CompositeDef { - pub fn try_from( - attr_span: proc_macro2::Span, - scrate: &syn::Path, - item: &mut syn::Item, - ) -> syn::Result { - let item = if let syn::Item::Enum(item) = item { - // check variants: composite enums support only field-less enum variants. This is - // because fields can introduce too many possibilities, making it challenging to compute - // a fixed variant count. - for variant in &item.variants { - match variant.fields { - syn::Fields::Named(_) | syn::Fields::Unnamed(_) => { - return Err(syn::Error::new( - variant.ident.span(), - "The composite enum does not support variants with fields!", - )); - } - syn::Fields::Unit => (), - } - } - item - } else { - return Err(syn::Error::new( - item.span(), - "Invalid pallet::composite_enum, expected enum item", - )); - }; - - if !matches!(item.vis, syn::Visibility::Public(_)) { - let msg = format!( - "Invalid pallet::composite_enum, `{}` must be public", - item.ident - ); - return Err(syn::Error::new(item.span(), msg)); - } - - let has_instance = if item.generics.params.first().is_some() { - helper::check_config_def_gen(&item.generics, item.ident.span())?; - true - } else { - false - }; - - let has_derive_attr = item.attrs.iter().any(|attr| { - if let syn::Meta::List(syn::MetaList { path, .. }) = &attr.meta { - path.get_ident() - .map(|ident| ident == "derive") - .unwrap_or(false) - } else { - false - } - }); - - if !has_derive_attr { - let derive_attr: syn::Attribute = syn::parse_quote! { - #[derive( - Copy, Clone, Eq, PartialEq, - #scrate::__private::codec::Encode, #scrate::__private::codec::Decode, #scrate::__private::codec::MaxEncodedLen, - #scrate::__private::scale_info::TypeInfo, - #scrate::__private::RuntimeDebug, - )] - }; - item.attrs.push(derive_attr); - } - - if has_instance { - item.attrs.push(syn::parse_quote! { - #[scale_info(skip_type_params(I))] - }); - - item.variants.push(syn::parse_quote! { - #[doc(hidden)] - #[codec(skip)] - __Ignore( - ::core::marker::PhantomData, - ) - }); - } - - let composite_keyword = - syn::parse2::(item.ident.to_token_stream())?; - - Ok(CompositeDef { - composite_keyword, - attr_span, - generics: item.generics.clone(), - variant_count: item.variants.len() as u32, - ident: item.ident.clone(), - }) - } -} diff --git a/support/procedural-fork/src/pallet/parse/config.rs b/support/procedural-fork/src/pallet/parse/config.rs deleted file mode 100644 index a7b1f043b6..0000000000 --- a/support/procedural-fork/src/pallet/parse/config.rs +++ /dev/null @@ -1,637 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use super::helper; -use frame_support_procedural_tools::{get_doc_literals, is_using_frame_crate}; -use quote::ToTokens; -use syn::{Token, spanned::Spanned, token}; - -/// List of additional token to be used for parsing. -mod keyword { - syn::custom_keyword!(Config); - syn::custom_keyword!(From); - syn::custom_keyword!(T); - syn::custom_keyword!(I); - syn::custom_keyword!(config); - syn::custom_keyword!(pallet); - syn::custom_keyword!(IsType); - syn::custom_keyword!(RuntimeEvent); - syn::custom_keyword!(Event); - syn::custom_keyword!(frame_system); - syn::custom_keyword!(disable_frame_system_supertrait_check); - syn::custom_keyword!(no_default); - syn::custom_keyword!(no_default_bounds); - syn::custom_keyword!(constant); -} - -#[derive(Default)] -pub struct DefaultTrait { - /// A bool for each sub-trait item indicates whether the item has - /// `#[pallet::no_default_bounds]` attached to it. If true, the item will not have any bounds - /// in the generated default sub-trait. - pub items: Vec<(syn::TraitItem, bool)>, - pub has_system: bool, -} - -/// Input definition for the pallet config. -pub struct ConfigDef { - /// The index of item in pallet module. - pub index: usize, - /// Whether the trait has instance (i.e. define with `Config`) - pub has_instance: bool, - /// Const associated type. - pub consts_metadata: Vec, - /// Whether the trait has the associated type `Event`, note that those bounds are - /// checked: - /// * `IsType::RuntimeEvent` - /// * `From` or `From>` or `From>` - pub has_event_type: bool, - /// The where clause on trait definition but modified so `Self` is `T`. - pub where_clause: Option, - /// Whether a default sub-trait should be generated. - /// - /// Contains default sub-trait items (instantiated by `#[pallet::config(with_default)]`). - /// Vec will be empty if `#[pallet::config(with_default)]` is not specified or if there are - /// no trait items. - pub default_sub_trait: Option, -} - -/// Input definition for a constant in pallet config. -pub struct ConstMetadataDef { - /// Name of the associated type. - pub ident: syn::Ident, - /// The type in Get, e.g. `u32` in `type Foo: Get;`, but `Self` is replaced by `T` - pub type_: syn::Type, - /// The doc associated - pub doc: Vec, -} - -impl TryFrom<&syn::TraitItemType> for ConstMetadataDef { - type Error = syn::Error; - - fn try_from(trait_ty: &syn::TraitItemType) -> Result { - let err = |span, msg| { - syn::Error::new( - span, - format!("Invalid usage of `#[pallet::constant]`: {}", msg), - ) - }; - let doc = get_doc_literals(&trait_ty.attrs); - let ident = trait_ty.ident.clone(); - let bound = trait_ty - .bounds - .iter() - .find_map(|param_bound| { - let syn::TypeParamBound::Trait(trait_bound) = param_bound else { - return None; - }; - - trait_bound - .path - .segments - .last() - .and_then(|s| (s.ident == "Get").then(|| s)) - }) - .ok_or_else(|| err(trait_ty.span(), "`Get` trait bound not found"))?; - - let syn::PathArguments::AngleBracketed(ref ab) = bound.arguments else { - return Err(err(bound.span(), "Expected trait generic args")); - }; - - // Only one type argument is expected. - if ab.args.len() != 1 { - return Err(err(bound.span(), "Expected a single type argument")); - } - - let syn::GenericArgument::Type(ref type_arg) = ab.args[0] else { - return Err(err(ab.args[0].span(), "Expected a type argument")); - }; - - let type_ = syn::parse2::(replace_self_by_t(type_arg.to_token_stream())) - .expect("Internal error: replacing `Self` by `T` should result in valid type"); - - Ok(Self { ident, type_, doc }) - } -} - -/// Parse for `#[pallet::disable_frame_system_supertrait_check]` -pub struct DisableFrameSystemSupertraitCheck; - -impl syn::parse::Parse for DisableFrameSystemSupertraitCheck { - fn parse(input: syn::parse::ParseStream) -> syn::Result { - input.parse::()?; - let content; - syn::bracketed!(content in input); - content.parse::()?; - content.parse::()?; - - content.parse::()?; - Ok(Self) - } -} - -/// Parsing for the `typ` portion of `PalletAttr` -#[derive(derive_syn_parse::Parse, PartialEq, Eq)] -pub enum PalletAttrType { - #[peek(keyword::no_default, name = "no_default")] - NoDefault(keyword::no_default), - #[peek(keyword::no_default_bounds, name = "no_default_bounds")] - NoBounds(keyword::no_default_bounds), - #[peek(keyword::constant, name = "constant")] - Constant(keyword::constant), -} - -/// Parsing for `#[pallet::X]` -#[derive(derive_syn_parse::Parse)] -pub struct PalletAttr { - _pound: Token![#], - #[bracket] - _bracket: token::Bracket, - #[inside(_bracket)] - _pallet: keyword::pallet, - #[prefix(Token![::] in _bracket)] - #[inside(_bracket)] - typ: PalletAttrType, -} - -/// Parse for `IsType<::RuntimeEvent>` and retrieve `$path` -pub struct IsTypeBoundEventParse(syn::Path); - -impl syn::parse::Parse for IsTypeBoundEventParse { - fn parse(input: syn::parse::ParseStream) -> syn::Result { - input.parse::()?; - input.parse::()?; - input.parse::()?; - input.parse::()?; - input.parse::()?; - let config_path = input.parse::()?; - input.parse::]>()?; - input.parse::()?; - input.parse::()?; - input.parse::]>()?; - - Ok(Self(config_path)) - } -} - -/// Parse for `From` or `From>` or `From>` -pub struct FromEventParse { - is_generic: bool, - has_instance: bool, -} - -impl syn::parse::Parse for FromEventParse { - fn parse(input: syn::parse::ParseStream) -> syn::Result { - let mut is_generic = false; - let mut has_instance = false; - - input.parse::()?; - input.parse::()?; - input.parse::()?; - if input.peek(syn::Token![<]) { - is_generic = true; - input.parse::()?; - input.parse::()?; - if input.peek(syn::Token![,]) { - input.parse::()?; - input.parse::()?; - has_instance = true; - } - input.parse::]>()?; - } - input.parse::]>()?; - - Ok(Self { - is_generic, - has_instance, - }) - } -} - -/// Check if trait_item is `type RuntimeEvent`, if so checks its bounds are those expected. -/// (Event type is reserved type) -fn check_event_type( - frame_system: &syn::Path, - trait_item: &syn::TraitItem, - trait_has_instance: bool, -) -> syn::Result { - let syn::TraitItem::Type(type_) = trait_item else { - return Ok(false); - }; - - if type_.ident != "RuntimeEvent" { - return Ok(false); - } - - // Check event has no generics - if !type_.generics.params.is_empty() || type_.generics.where_clause.is_some() { - let msg = "Invalid `type RuntimeEvent`, associated type `RuntimeEvent` is reserved and must have\ - no generics nor where_clause"; - return Err(syn::Error::new(trait_item.span(), msg)); - } - - // Check bound contains IsType and From - let has_is_type_bound = type_.bounds.iter().any(|s| { - syn::parse2::(s.to_token_stream()) - .map_or(false, |b| has_expected_system_config(b.0, frame_system)) - }); - - if !has_is_type_bound { - let msg = - "Invalid `type RuntimeEvent`, associated type `RuntimeEvent` is reserved and must \ - bound: `IsType<::RuntimeEvent>`" - .to_string(); - return Err(syn::Error::new(type_.span(), msg)); - } - - let from_event_bound = type_ - .bounds - .iter() - .find_map(|s| syn::parse2::(s.to_token_stream()).ok()); - - let Some(from_event_bound) = from_event_bound else { - let msg = "Invalid `type RuntimeEvent`, associated type `RuntimeEvent` is reserved and must \ - bound: `From` or `From>` or `From>`"; - return Err(syn::Error::new(type_.span(), msg)); - }; - - if from_event_bound.is_generic && (from_event_bound.has_instance != trait_has_instance) { - let msg = "Invalid `type RuntimeEvent`, associated type `RuntimeEvent` bounds inconsistent \ - `From`. Config and generic Event must be both with instance or \ - without instance"; - return Err(syn::Error::new(type_.span(), msg)); - } - - Ok(true) -} - -/// Check that the path to `frame_system::Config` is valid, this is that the path is just -/// `frame_system::Config` or when using the `frame` crate it is -/// `polkadot_sdk_frame::xyz::frame_system::Config`. -fn has_expected_system_config(path: syn::Path, frame_system: &syn::Path) -> bool { - // Check if `frame_system` is actually 'frame_system'. - if path.segments.iter().all(|s| s.ident != "frame_system") { - return false; - } - - let mut expected_system_config = match ( - is_using_frame_crate(&path), - is_using_frame_crate(&frame_system), - ) { - (true, false) => - // We can't use the path to `frame_system` from `frame` if `frame_system` is not being - // in scope through `frame`. - { - return false; - } - (false, true) => - // We know that the only valid frame_system path is one that is `frame_system`, as - // `frame` re-exports it as such. - { - syn::parse2::(quote::quote!(frame_system)).expect("is a valid path; qed") - } - (_, _) => - // They are either both `frame_system` or both `polkadot_sdk_frame::xyz::frame_system`. - { - frame_system.clone() - } - }; - - expected_system_config - .segments - .push(syn::PathSegment::from(syn::Ident::new( - "Config", - path.span(), - ))); - - // the parse path might be something like `frame_system::Config<...>`, so we - // only compare the idents along the path. - expected_system_config - .segments - .into_iter() - .map(|ps| ps.ident) - .collect::>() - == path - .segments - .into_iter() - .map(|ps| ps.ident) - .collect::>() -} - -/// Replace ident `Self` by `T` -pub fn replace_self_by_t(input: proc_macro2::TokenStream) -> proc_macro2::TokenStream { - input - .into_iter() - .map(|token_tree| match token_tree { - proc_macro2::TokenTree::Group(group) => { - proc_macro2::Group::new(group.delimiter(), replace_self_by_t(group.stream())).into() - } - proc_macro2::TokenTree::Ident(ident) if ident == "Self" => { - proc_macro2::Ident::new("T", ident.span()).into() - } - other => other, - }) - .collect() -} - -impl ConfigDef { - pub fn try_from( - frame_system: &syn::Path, - index: usize, - item: &mut syn::Item, - enable_default: bool, - ) -> syn::Result { - let syn::Item::Trait(item) = item else { - let msg = "Invalid pallet::config, expected trait definition"; - return Err(syn::Error::new(item.span(), msg)); - }; - - if !matches!(item.vis, syn::Visibility::Public(_)) { - let msg = "Invalid pallet::config, trait must be public"; - return Err(syn::Error::new(item.span(), msg)); - } - - syn::parse2::(item.ident.to_token_stream())?; - - let where_clause = { - let stream = replace_self_by_t(item.generics.where_clause.to_token_stream()); - syn::parse2::>(stream).expect( - "Internal error: replacing `Self` by `T` should result in valid where - clause", - ) - }; - - if item.generics.params.len() > 1 { - let msg = "Invalid pallet::config, expected no more than one generic"; - return Err(syn::Error::new(item.generics.params[2].span(), msg)); - } - - let has_instance = if item.generics.params.first().is_some() { - helper::check_config_def_gen(&item.generics, item.ident.span())?; - true - } else { - false - }; - - let has_frame_system_supertrait = item.supertraits.iter().any(|s| { - syn::parse2::(s.to_token_stream()) - .map_or(false, |b| has_expected_system_config(b, frame_system)) - }); - - let mut has_event_type = false; - let mut consts_metadata = vec![]; - let mut default_sub_trait = if enable_default { - Some(DefaultTrait { - items: Default::default(), - has_system: has_frame_system_supertrait, - }) - } else { - None - }; - for trait_item in &mut item.items { - let is_event = check_event_type(frame_system, trait_item, has_instance)?; - has_event_type = has_event_type || is_event; - - let mut already_no_default = false; - let mut already_constant = false; - let mut already_no_default_bounds = false; - - while let Ok(Some(pallet_attr)) = - helper::take_first_item_pallet_attr::(trait_item) - { - match (pallet_attr.typ, &trait_item) { - (PalletAttrType::Constant(_), syn::TraitItem::Type(typ)) => { - if already_constant { - return Err(syn::Error::new( - pallet_attr._bracket.span.join(), - "Duplicate #[pallet::constant] attribute not allowed.", - )); - } - already_constant = true; - consts_metadata.push(ConstMetadataDef::try_from(typ)?); - } - (PalletAttrType::Constant(_), _) => { - return Err(syn::Error::new( - trait_item.span(), - "Invalid #[pallet::constant] in #[pallet::config], expected type item", - )); - } - (PalletAttrType::NoDefault(_), _) => { - if !enable_default { - return Err(syn::Error::new( - pallet_attr._bracket.span.join(), - "`#[pallet:no_default]` can only be used if `#[pallet::config(with_default)]` \ - has been specified", - )); - } - if already_no_default { - return Err(syn::Error::new( - pallet_attr._bracket.span.join(), - "Duplicate #[pallet::no_default] attribute not allowed.", - )); - } - - already_no_default = true; - } - (PalletAttrType::NoBounds(_), _) => { - if !enable_default { - return Err(syn::Error::new( - pallet_attr._bracket.span.join(), - "`#[pallet:no_default_bounds]` can only be used if `#[pallet::config(with_default)]` \ - has been specified", - )); - } - if already_no_default_bounds { - return Err(syn::Error::new( - pallet_attr._bracket.span.join(), - "Duplicate #[pallet::no_default_bounds] attribute not allowed.", - )); - } - already_no_default_bounds = true; - } - } - } - - if !already_no_default && enable_default { - default_sub_trait - .as_mut() - .expect("is 'Some(_)' if 'enable_default'; qed") - .items - .push((trait_item.clone(), already_no_default_bounds)); - } - } - - let attr: Option = - helper::take_first_item_pallet_attr(&mut item.attrs)?; - let disable_system_supertrait_check = attr.is_some(); - - if !has_frame_system_supertrait && !disable_system_supertrait_check { - let found = if item.supertraits.is_empty() { - "none".to_string() - } else { - let mut found = item.supertraits.iter().fold(String::new(), |acc, s| { - format!("{}`{}`, ", acc, quote::quote!(#s)) - }); - found.pop(); - found.pop(); - found - }; - - let msg = format!( - "Invalid pallet::trait, expected explicit `{}::Config` as supertrait, \ - found {}. \ - (try `pub trait Config: frame_system::Config {{ ...` or \ - `pub trait Config: frame_system::Config {{ ...`). \ - To disable this check, use `#[pallet::disable_frame_system_supertrait_check]`", - frame_system.to_token_stream(), - found, - ); - return Err(syn::Error::new(item.span(), msg)); - } - - Ok(Self { - index, - has_instance, - consts_metadata, - has_event_type, - where_clause, - default_sub_trait, - }) - } -} - -#[cfg(test)] -mod tests { - use super::*; - #[test] - fn has_expected_system_config_works() { - let frame_system = syn::parse2::(quote::quote!(frame_system)).unwrap(); - let path = syn::parse2::(quote::quote!(frame_system::Config)).unwrap(); - assert!(has_expected_system_config(path, &frame_system)); - } - - #[test] - fn has_expected_system_config_works_with_assoc_type() { - let frame_system = syn::parse2::(quote::quote!(frame_system)).unwrap(); - let path = - syn::parse2::(quote::quote!(frame_system::Config)) - .unwrap(); - assert!(has_expected_system_config(path, &frame_system)); - } - - #[test] - fn has_expected_system_config_works_with_frame() { - let path = syn::parse2::(quote::quote!(frame_system::Config)).unwrap(); - - let frame_system = - syn::parse2::(quote::quote!(polkadot_sdk_frame::deps::frame_system)) - .unwrap(); - assert!(has_expected_system_config(path.clone(), &frame_system)); - - let frame_system = - syn::parse2::(quote::quote!(frame::deps::frame_system)).unwrap(); - assert!(has_expected_system_config(path, &frame_system)); - } - - #[test] - fn has_expected_system_config_works_with_frame_full_path() { - let frame_system = - syn::parse2::(quote::quote!(polkadot_sdk_frame::deps::frame_system)) - .unwrap(); - let path = syn::parse2::(quote::quote!( - polkadot_sdk_frame::deps::frame_system::Config - )) - .unwrap(); - assert!(has_expected_system_config(path, &frame_system)); - - let frame_system = - syn::parse2::(quote::quote!(frame::deps::frame_system)).unwrap(); - let path = - syn::parse2::(quote::quote!(frame::deps::frame_system::Config)).unwrap(); - assert!(has_expected_system_config(path, &frame_system)); - } - - #[test] - fn has_expected_system_config_works_with_other_frame_full_path() { - let frame_system = - syn::parse2::(quote::quote!(polkadot_sdk_frame::xyz::frame_system)).unwrap(); - let path = - syn::parse2::(quote::quote!(polkadot_sdk_frame::xyz::frame_system::Config)) - .unwrap(); - assert!(has_expected_system_config(path, &frame_system)); - - let frame_system = - syn::parse2::(quote::quote!(frame::xyz::frame_system)).unwrap(); - let path = - syn::parse2::(quote::quote!(frame::xyz::frame_system::Config)).unwrap(); - assert!(has_expected_system_config(path, &frame_system)); - } - - #[test] - fn has_expected_system_config_does_not_works_with_mixed_frame_full_path() { - let frame_system = - syn::parse2::(quote::quote!(polkadot_sdk_frame::xyz::frame_system)).unwrap(); - let path = syn::parse2::(quote::quote!( - polkadot_sdk_frame::deps::frame_system::Config - )) - .unwrap(); - assert!(!has_expected_system_config(path, &frame_system)); - } - - #[test] - fn has_expected_system_config_does_not_works_with_other_mixed_frame_full_path() { - let frame_system = - syn::parse2::(quote::quote!(polkadot_sdk_frame::deps::frame_system)) - .unwrap(); - let path = - syn::parse2::(quote::quote!(polkadot_sdk_frame::xyz::frame_system::Config)) - .unwrap(); - assert!(!has_expected_system_config(path, &frame_system)); - } - - #[test] - fn has_expected_system_config_does_not_work_with_frame_full_path_if_not_frame_crate() { - let frame_system = syn::parse2::(quote::quote!(frame_system)).unwrap(); - let path = syn::parse2::(quote::quote!( - polkadot_sdk_frame::deps::frame_system::Config - )) - .unwrap(); - assert!(!has_expected_system_config(path, &frame_system)); - } - - #[test] - fn has_expected_system_config_unexpected_frame_system() { - let frame_system = - syn::parse2::(quote::quote!(framez::deps::frame_system)).unwrap(); - let path = syn::parse2::(quote::quote!(frame_system::Config)).unwrap(); - assert!(!has_expected_system_config(path, &frame_system)); - } - - #[test] - fn has_expected_system_config_unexpected_path() { - let frame_system = syn::parse2::(quote::quote!(frame_system)).unwrap(); - let path = syn::parse2::(quote::quote!(frame_system::ConfigSystem)).unwrap(); - assert!(!has_expected_system_config(path, &frame_system)); - } - - #[test] - fn has_expected_system_config_not_frame_system() { - let frame_system = syn::parse2::(quote::quote!(something)).unwrap(); - let path = syn::parse2::(quote::quote!(something::Config)).unwrap(); - assert!(!has_expected_system_config(path, &frame_system)); - } -} diff --git a/support/procedural-fork/src/pallet/parse/error.rs b/support/procedural-fork/src/pallet/parse/error.rs deleted file mode 100644 index 8bd2f438bd..0000000000 --- a/support/procedural-fork/src/pallet/parse/error.rs +++ /dev/null @@ -1,125 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use super::helper; -use quote::ToTokens; -use syn::{Fields, spanned::Spanned}; - -/// List of additional token to be used for parsing. -mod keyword { - syn::custom_keyword!(Error); -} - -/// Records information about the error enum variant field. -pub struct VariantField { - /// Whether or not the field is named, i.e. whether it is a tuple variant or struct variant. - pub is_named: bool, -} - -/// Records information about the error enum variants. -pub struct VariantDef { - /// The variant ident. - pub ident: syn::Ident, - /// The variant field, if any. - pub field: Option, - /// The `cfg` attributes. - pub cfg_attrs: Vec, -} - -/// This checks error declaration as a enum declaration with only variants without fields nor -/// discriminant. -pub struct ErrorDef { - /// The index of error item in pallet module. - pub index: usize, - /// Variant definitions. - pub variants: Vec, - /// A set of usage of instance, must be check for consistency with trait. - pub instances: Vec, - /// The keyword error used (contains span). - pub error: keyword::Error, - /// The span of the pallet::error attribute. - pub attr_span: proc_macro2::Span, -} - -impl ErrorDef { - pub fn try_from( - attr_span: proc_macro2::Span, - index: usize, - item: &mut syn::Item, - ) -> syn::Result { - let item = if let syn::Item::Enum(item) = item { - item - } else { - return Err(syn::Error::new( - item.span(), - "Invalid pallet::error, expected item enum", - )); - }; - if !matches!(item.vis, syn::Visibility::Public(_)) { - let msg = "Invalid pallet::error, `Error` must be public"; - return Err(syn::Error::new(item.span(), msg)); - } - - let instances = vec![helper::check_type_def_gen_no_bounds( - &item.generics, - item.ident.span(), - )?]; - - if item.generics.where_clause.is_some() { - let msg = "Invalid pallet::error, where clause is not allowed on pallet error item"; - return Err(syn::Error::new( - item.generics.where_clause.as_ref().unwrap().span(), - msg, - )); - } - - let error = syn::parse2::(item.ident.to_token_stream())?; - - let variants = item - .variants - .iter() - .map(|variant| { - let field_ty = match &variant.fields { - Fields::Unit => None, - Fields::Named(_) => Some(VariantField { is_named: true }), - Fields::Unnamed(_) => Some(VariantField { is_named: false }), - }; - if variant.discriminant.is_some() { - let msg = "Invalid pallet::error, unexpected discriminant, discriminants \ - are not supported"; - let span = variant.discriminant.as_ref().unwrap().0.span(); - return Err(syn::Error::new(span, msg)); - } - let cfg_attrs: Vec = helper::get_item_cfg_attrs(&variant.attrs); - - Ok(VariantDef { - ident: variant.ident.clone(), - field: field_ty, - cfg_attrs, - }) - }) - .collect::>()?; - - Ok(ErrorDef { - attr_span, - index, - variants, - instances, - error, - }) - } -} diff --git a/support/procedural-fork/src/pallet/parse/event.rs b/support/procedural-fork/src/pallet/parse/event.rs deleted file mode 100644 index 6102dd31f1..0000000000 --- a/support/procedural-fork/src/pallet/parse/event.rs +++ /dev/null @@ -1,159 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use super::helper; -use quote::ToTokens; -use syn::spanned::Spanned; - -/// List of additional token to be used for parsing. -mod keyword { - syn::custom_keyword!(Event); - syn::custom_keyword!(pallet); - syn::custom_keyword!(generate_deposit); - syn::custom_keyword!(deposit_event); -} - -/// Definition for pallet event enum. -pub struct EventDef { - /// The index of event item in pallet module. - pub index: usize, - /// The keyword Event used (contains span). - pub event: keyword::Event, - /// A set of usage of instance, must be check for consistency with trait. - pub instances: Vec, - /// The kind of generic the type `Event` has. - pub gen_kind: super::GenericKind, - /// Whether the function `deposit_event` must be generated. - pub deposit_event: Option, - /// Where clause used in event definition. - pub where_clause: Option, - /// The span of the pallet::event attribute. - pub attr_span: proc_macro2::Span, -} - -/// Attribute for a pallet's Event. -/// -/// Syntax is: -/// * `#[pallet::generate_deposit($vis fn deposit_event)]` -pub struct PalletEventDepositAttr { - pub fn_vis: syn::Visibility, - // Span for the keyword deposit_event - pub fn_span: proc_macro2::Span, - // Span of the attribute - pub span: proc_macro2::Span, -} - -impl syn::parse::Parse for PalletEventDepositAttr { - fn parse(input: syn::parse::ParseStream) -> syn::Result { - input.parse::()?; - let content; - syn::bracketed!(content in input); - content.parse::()?; - content.parse::()?; - - let span = content.parse::()?.span(); - let generate_content; - syn::parenthesized!(generate_content in content); - let fn_vis = generate_content.parse::()?; - generate_content.parse::()?; - let fn_span = generate_content.parse::()?.span(); - - Ok(PalletEventDepositAttr { - fn_vis, - span, - fn_span, - }) - } -} - -struct PalletEventAttrInfo { - deposit_event: Option, -} - -impl PalletEventAttrInfo { - fn from_attrs(attrs: Vec) -> syn::Result { - let mut deposit_event = None; - for attr in attrs { - if deposit_event.is_none() { - deposit_event = Some(attr) - } else { - return Err(syn::Error::new(attr.span, "Duplicate attribute")); - } - } - - Ok(PalletEventAttrInfo { deposit_event }) - } -} - -impl EventDef { - pub fn try_from( - attr_span: proc_macro2::Span, - index: usize, - item: &mut syn::Item, - ) -> syn::Result { - let item = if let syn::Item::Enum(item) = item { - item - } else { - return Err(syn::Error::new( - item.span(), - "Invalid pallet::event, expected enum item", - )); - }; - - let event_attrs: Vec = - helper::take_item_pallet_attrs(&mut item.attrs)?; - let attr_info = PalletEventAttrInfo::from_attrs(event_attrs)?; - let deposit_event = attr_info.deposit_event; - - if !matches!(item.vis, syn::Visibility::Public(_)) { - let msg = "Invalid pallet::event, `Event` must be public"; - return Err(syn::Error::new(item.span(), msg)); - } - - let where_clause = item.generics.where_clause.clone(); - - let mut instances = vec![]; - // NOTE: Event is not allowed to be only generic on I because it is not supported - // by construct_runtime. - if let Some(u) = helper::check_type_def_optional_gen(&item.generics, item.ident.span())? { - instances.push(u); - } else { - // construct_runtime only allow non generic event for non instantiable pallet. - instances.push(helper::InstanceUsage { - has_instance: false, - span: item.ident.span(), - }) - } - - let has_instance = item.generics.type_params().any(|t| t.ident == "I"); - let has_config = item.generics.type_params().any(|t| t.ident == "T"); - let gen_kind = super::GenericKind::from_gens(has_config, has_instance) - .expect("Checked by `helper::check_type_def_optional_gen` above"); - - let event = syn::parse2::(item.ident.to_token_stream())?; - - Ok(EventDef { - attr_span, - index, - instances, - deposit_event, - event, - gen_kind, - where_clause, - }) - } -} diff --git a/support/procedural-fork/src/pallet/parse/extra_constants.rs b/support/procedural-fork/src/pallet/parse/extra_constants.rs deleted file mode 100644 index 431fcf677e..0000000000 --- a/support/procedural-fork/src/pallet/parse/extra_constants.rs +++ /dev/null @@ -1,165 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use super::helper; -use frame_support_procedural_tools::get_doc_literals; -use syn::spanned::Spanned; - -/// List of additional token to be used for parsing. -mod keyword { - syn::custom_keyword!(DispatchResultWithPostInfo); - syn::custom_keyword!(Call); - syn::custom_keyword!(OriginFor); - syn::custom_keyword!(weight); - syn::custom_keyword!(compact); - syn::custom_keyword!(T); - syn::custom_keyword!(pallet); - syn::custom_keyword!(constant_name); -} - -/// Definition of extra constants typically `impl Pallet { ... }` -pub struct ExtraConstantsDef { - /// The where_clause used. - pub where_clause: Option, - /// A set of usage of instance, must be check for consistency with trait. - pub instances: Vec, - /// The extra constant defined. - pub extra_constants: Vec, -} - -/// Input definition for an constant in pallet. -pub struct ExtraConstantDef { - /// Name of the function - pub ident: syn::Ident, - /// The type returned by the function - pub type_: syn::Type, - /// The doc associated - pub doc: Vec, - /// Optional MetaData Name - pub metadata_name: Option, -} - -/// Attributes for functions in extra_constants impl block. -/// Parse for `#[pallet::constant_name(ConstantName)]` -pub struct ExtraConstAttr { - metadata_name: syn::Ident, -} - -impl syn::parse::Parse for ExtraConstAttr { - fn parse(input: syn::parse::ParseStream) -> syn::Result { - input.parse::()?; - let content; - syn::bracketed!(content in input); - content.parse::()?; - content.parse::()?; - content.parse::()?; - - let metadata_name; - syn::parenthesized!(metadata_name in content); - Ok(ExtraConstAttr { - metadata_name: metadata_name.parse::()?, - }) - } -} - -impl ExtraConstantsDef { - pub fn try_from(item: &mut syn::Item) -> syn::Result { - let item = if let syn::Item::Impl(item) = item { - item - } else { - return Err(syn::Error::new( - item.span(), - "Invalid pallet::extra_constants, expected item impl", - )); - }; - - let instances = vec![ - helper::check_impl_gen(&item.generics, item.impl_token.span())?, - helper::check_pallet_struct_usage(&item.self_ty)?, - ]; - - if let Some((_, _, for_)) = item.trait_ { - let msg = "Invalid pallet::call, expected no trait ident as in \ - `impl<..> Pallet<..> { .. }`"; - return Err(syn::Error::new(for_.span(), msg)); - } - - let mut extra_constants = vec![]; - for impl_item in &mut item.items { - let method = if let syn::ImplItem::Fn(method) = impl_item { - method - } else { - let msg = "Invalid pallet::call, only method accepted"; - return Err(syn::Error::new(impl_item.span(), msg)); - }; - - if !method.sig.inputs.is_empty() { - let msg = "Invalid pallet::extra_constants, method must have 0 args"; - return Err(syn::Error::new(method.sig.span(), msg)); - } - - if !method.sig.generics.params.is_empty() { - let msg = "Invalid pallet::extra_constants, method must have 0 generics"; - return Err(syn::Error::new(method.sig.generics.params[0].span(), msg)); - } - - if method.sig.generics.where_clause.is_some() { - let msg = "Invalid pallet::extra_constants, method must have no where clause"; - return Err(syn::Error::new( - method.sig.generics.where_clause.span(), - msg, - )); - } - - let type_ = match &method.sig.output { - syn::ReturnType::Default => { - let msg = "Invalid pallet::extra_constants, method must have a return type"; - return Err(syn::Error::new(method.span(), msg)); - } - syn::ReturnType::Type(_, type_) => *type_.clone(), - }; - - // parse metadata_name - let mut extra_constant_attrs: Vec = - helper::take_item_pallet_attrs(method)?; - - if extra_constant_attrs.len() > 1 { - let msg = - "Invalid attribute in pallet::constant_name, only one attribute is expected"; - return Err(syn::Error::new( - extra_constant_attrs[1].metadata_name.span(), - msg, - )); - } - - let metadata_name = extra_constant_attrs.pop().map(|attr| attr.metadata_name); - - extra_constants.push(ExtraConstantDef { - ident: method.sig.ident.clone(), - type_, - doc: get_doc_literals(&method.attrs), - metadata_name, - }); - } - - Ok(Self { - instances, - where_clause: item.generics.where_clause.clone(), - extra_constants, - }) - } -} diff --git a/support/procedural-fork/src/pallet/parse/genesis_build.rs b/support/procedural-fork/src/pallet/parse/genesis_build.rs deleted file mode 100644 index 936c929afc..0000000000 --- a/support/procedural-fork/src/pallet/parse/genesis_build.rs +++ /dev/null @@ -1,59 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use super::helper; -use syn::spanned::Spanned; - -/// Definition for pallet genesis build implementation. -pub struct GenesisBuildDef { - /// A set of usage of instance, must be check for consistency with trait. - pub instances: Option>, - /// The where_clause used. - pub where_clause: Option, - /// The span of the pallet::genesis_build attribute. - pub attr_span: proc_macro2::Span, -} - -impl GenesisBuildDef { - pub fn try_from(attr_span: proc_macro2::Span, item: &mut syn::Item) -> syn::Result { - let item = if let syn::Item::Impl(item) = item { - item - } else { - let msg = "Invalid pallet::genesis_build, expected item impl"; - return Err(syn::Error::new(item.span(), msg)); - }; - - let item_trait = &item - .trait_ - .as_ref() - .ok_or_else(|| { - let msg = "Invalid pallet::genesis_build, expected impl<..> GenesisBuild<..> \ - for GenesisConfig<..>"; - syn::Error::new(item.span(), msg) - })? - .1; - - let instances = - helper::check_genesis_builder_usage(item_trait)?.map(|instances| vec![instances]); - - Ok(Self { - attr_span, - instances, - where_clause: item.generics.where_clause.clone(), - }) - } -} diff --git a/support/procedural-fork/src/pallet/parse/genesis_config.rs b/support/procedural-fork/src/pallet/parse/genesis_config.rs deleted file mode 100644 index 1c52345eb2..0000000000 --- a/support/procedural-fork/src/pallet/parse/genesis_config.rs +++ /dev/null @@ -1,78 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use super::helper; -use syn::spanned::Spanned; - -/// Definition for pallet genesis config type. -/// -/// Either: -/// * `struct GenesisConfig` -/// * `enum GenesisConfig` -pub struct GenesisConfigDef { - /// The index of item in pallet module. - pub index: usize, - /// The kind of generic the type `GenesisConfig` has. - pub gen_kind: super::GenericKind, - /// A set of usage of instance, must be check for consistency with trait. - pub instances: Vec, - /// The ident of genesis_config, can be used for span. - pub genesis_config: syn::Ident, -} - -impl GenesisConfigDef { - pub fn try_from(index: usize, item: &mut syn::Item) -> syn::Result { - let item_span = item.span(); - let (vis, ident, generics) = match &item { - syn::Item::Enum(item) => (&item.vis, &item.ident, &item.generics), - syn::Item::Struct(item) => (&item.vis, &item.ident, &item.generics), - _ => { - let msg = "Invalid pallet::genesis_config, expected enum or struct"; - return Err(syn::Error::new(item.span(), msg)); - } - }; - - let mut instances = vec![]; - // NOTE: GenesisConfig is not allowed to be only generic on I because it is not supported - // by construct_runtime. - if let Some(u) = helper::check_type_def_optional_gen(generics, ident.span())? { - instances.push(u); - } - - let has_instance = generics.type_params().any(|t| t.ident == "I"); - let has_config = generics.type_params().any(|t| t.ident == "T"); - let gen_kind = super::GenericKind::from_gens(has_config, has_instance) - .expect("Checked by `helper::check_type_def_optional_gen` above"); - - if !matches!(vis, syn::Visibility::Public(_)) { - let msg = "Invalid pallet::genesis_config, GenesisConfig must be public"; - return Err(syn::Error::new(item_span, msg)); - } - - if ident != "GenesisConfig" { - let msg = "Invalid pallet::genesis_config, ident must `GenesisConfig`"; - return Err(syn::Error::new(ident.span(), msg)); - } - - Ok(GenesisConfigDef { - index, - genesis_config: ident.clone(), - instances, - gen_kind, - }) - } -} diff --git a/support/procedural-fork/src/pallet/parse/helper.rs b/support/procedural-fork/src/pallet/parse/helper.rs deleted file mode 100644 index e243dcbbfb..0000000000 --- a/support/procedural-fork/src/pallet/parse/helper.rs +++ /dev/null @@ -1,666 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use proc_macro2::TokenStream; -use quote::{ToTokens, quote}; -use syn::spanned::Spanned; - -/// List of additional token to be used for parsing. -mod keyword { - syn::custom_keyword!(I); - syn::custom_keyword!(compact); - syn::custom_keyword!(GenesisBuild); - syn::custom_keyword!(BuildGenesisConfig); - syn::custom_keyword!(Config); - syn::custom_keyword!(T); - syn::custom_keyword!(Pallet); - syn::custom_keyword!(origin); - syn::custom_keyword!(DispatchResult); - syn::custom_keyword!(DispatchResultWithPostInfo); -} - -/// A usage of instance, either the trait `Config` has been used with instance or without instance. -/// Used to check for consistency. -#[derive(Clone)] -pub struct InstanceUsage { - pub has_instance: bool, - pub span: proc_macro2::Span, -} - -/// Trait implemented for syn items to get mutable references on their attributes. -/// -/// NOTE: verbatim variants are not supported. -pub trait MutItemAttrs { - fn mut_item_attrs(&mut self) -> Option<&mut Vec>; -} - -/// Take the first pallet attribute (e.g. attribute like `#[pallet..]`) and decode it to `Attr` -pub(crate) fn take_first_item_pallet_attr( - item: &mut impl MutItemAttrs, -) -> syn::Result> -where - Attr: syn::parse::Parse, -{ - let Some(attrs) = item.mut_item_attrs() else { - return Ok(None); - }; - - let Some(index) = attrs.iter().position(|attr| { - attr.path() - .segments - .first() - .map_or(false, |segment| segment.ident == "pallet") - }) else { - return Ok(None); - }; - - let pallet_attr = attrs.remove(index); - Ok(Some(syn::parse2(pallet_attr.into_token_stream())?)) -} - -/// Take all the pallet attributes (e.g. attribute like `#[pallet..]`) and decode them to `Attr` -pub(crate) fn take_item_pallet_attrs(item: &mut impl MutItemAttrs) -> syn::Result> -where - Attr: syn::parse::Parse, -{ - let mut pallet_attrs = Vec::new(); - - while let Some(attr) = take_first_item_pallet_attr(item)? { - pallet_attrs.push(attr) - } - - Ok(pallet_attrs) -} - -/// Get all the cfg attributes (e.g. attribute like `#[cfg..]`) and decode them to `Attr` -pub fn get_item_cfg_attrs(attrs: &[syn::Attribute]) -> Vec { - attrs - .iter() - .filter_map(|attr| { - if attr - .path() - .segments - .first() - .map_or(false, |segment| segment.ident == "cfg") - { - Some(attr.clone()) - } else { - None - } - }) - .collect::>() -} - -impl MutItemAttrs for syn::Item { - fn mut_item_attrs(&mut self) -> Option<&mut Vec> { - match self { - Self::Const(item) => Some(item.attrs.as_mut()), - Self::Enum(item) => Some(item.attrs.as_mut()), - Self::ExternCrate(item) => Some(item.attrs.as_mut()), - Self::Fn(item) => Some(item.attrs.as_mut()), - Self::ForeignMod(item) => Some(item.attrs.as_mut()), - Self::Impl(item) => Some(item.attrs.as_mut()), - Self::Macro(item) => Some(item.attrs.as_mut()), - Self::Mod(item) => Some(item.attrs.as_mut()), - Self::Static(item) => Some(item.attrs.as_mut()), - Self::Struct(item) => Some(item.attrs.as_mut()), - Self::Trait(item) => Some(item.attrs.as_mut()), - Self::TraitAlias(item) => Some(item.attrs.as_mut()), - Self::Type(item) => Some(item.attrs.as_mut()), - Self::Union(item) => Some(item.attrs.as_mut()), - Self::Use(item) => Some(item.attrs.as_mut()), - _ => None, - } - } -} - -impl MutItemAttrs for syn::TraitItem { - fn mut_item_attrs(&mut self) -> Option<&mut Vec> { - match self { - Self::Const(item) => Some(item.attrs.as_mut()), - Self::Fn(item) => Some(item.attrs.as_mut()), - Self::Type(item) => Some(item.attrs.as_mut()), - Self::Macro(item) => Some(item.attrs.as_mut()), - _ => None, - } - } -} - -impl MutItemAttrs for Vec { - fn mut_item_attrs(&mut self) -> Option<&mut Vec> { - Some(self) - } -} - -impl MutItemAttrs for syn::ItemMod { - fn mut_item_attrs(&mut self) -> Option<&mut Vec> { - Some(&mut self.attrs) - } -} - -impl MutItemAttrs for syn::ImplItemFn { - fn mut_item_attrs(&mut self) -> Option<&mut Vec> { - Some(&mut self.attrs) - } -} - -impl MutItemAttrs for syn::ItemType { - fn mut_item_attrs(&mut self) -> Option<&mut Vec> { - Some(&mut self.attrs) - } -} - -/// Parse for `()` -struct Unit; -impl syn::parse::Parse for Unit { - fn parse(input: syn::parse::ParseStream) -> syn::Result { - let content; - syn::parenthesized!(content in input); - if !content.is_empty() { - let msg = "unexpected tokens, expected nothing inside parenthesis as `()`"; - return Err(syn::Error::new(content.span(), msg)); - } - Ok(Self) - } -} - -/// Parse for `'static` -struct StaticLifetime; -impl syn::parse::Parse for StaticLifetime { - fn parse(input: syn::parse::ParseStream) -> syn::Result { - let lifetime = input.parse::()?; - if lifetime.ident != "static" { - let msg = "unexpected tokens, expected `static`"; - return Err(syn::Error::new(lifetime.ident.span(), msg)); - } - Ok(Self) - } -} - -/// Check the syntax: `I: 'static = ()` -/// -/// `span` is used in case generics is empty (empty generics has span == call_site). -/// -/// return the instance if found. -pub fn check_config_def_gen(r#gen: &syn::Generics, span: proc_macro2::Span) -> syn::Result<()> { - let expected = "expected `I: 'static = ()`"; - pub struct CheckTraitDefGenerics; - impl syn::parse::Parse for CheckTraitDefGenerics { - fn parse(input: syn::parse::ParseStream) -> syn::Result { - input.parse::()?; - input.parse::()?; - input.parse::()?; - input.parse::()?; - input.parse::()?; - - Ok(Self) - } - } - - syn::parse2::(r#gen.params.to_token_stream()).map_err(|e| { - let msg = format!("Invalid generics: {}", expected); - let mut err = syn::Error::new(span, msg); - err.combine(e); - err - })?; - - Ok(()) -} - -/// Check the syntax: -/// * either `T` -/// * or `T, I = ()` -/// -/// `span` is used in case generics is empty (empty generics has span == call_site). -/// -/// return the instance if found. -pub fn check_type_def_gen_no_bounds( - r#gen: &syn::Generics, - span: proc_macro2::Span, -) -> syn::Result { - let expected = "expected `T` or `T, I = ()`"; - pub struct Checker(InstanceUsage); - impl syn::parse::Parse for Checker { - fn parse(input: syn::parse::ParseStream) -> syn::Result { - let mut instance_usage = InstanceUsage { - has_instance: false, - span: input.span(), - }; - - input.parse::()?; - if input.peek(syn::Token![,]) { - instance_usage.has_instance = true; - input.parse::()?; - input.parse::()?; - input.parse::()?; - input.parse::()?; - } - - Ok(Self(instance_usage)) - } - } - - let i = syn::parse2::(r#gen.params.to_token_stream()) - .map_err(|e| { - let msg = format!("Invalid type def generics: {}", expected); - let mut err = syn::Error::new(span, msg); - err.combine(e); - err - })? - .0; - - Ok(i) -} - -/// Check the syntax: -/// * either `` (no generics -/// * or `T` -/// * or `T: Config` -/// * or `T, I = ()` -/// * or `T: Config, I: 'static = ()` -/// -/// `span` is used in case generics is empty (empty generics has span == call_site). -/// -/// return some instance usage if there is some generic, or none otherwise. -pub fn check_type_def_optional_gen( - r#gen: &syn::Generics, - span: proc_macro2::Span, -) -> syn::Result> { - let expected = "expected `` or `T` or `T: Config` or `T, I = ()` or \ - `T: Config, I: 'static = ()`"; - pub struct Checker(Option); - impl syn::parse::Parse for Checker { - fn parse(input: syn::parse::ParseStream) -> syn::Result { - if input.is_empty() { - return Ok(Self(None)); - } - - let mut instance_usage = InstanceUsage { - span: input.span(), - has_instance: false, - }; - - input.parse::()?; - - if input.is_empty() { - return Ok(Self(Some(instance_usage))); - } - - let lookahead = input.lookahead1(); - if lookahead.peek(syn::Token![,]) { - instance_usage.has_instance = true; - input.parse::()?; - input.parse::()?; - input.parse::()?; - input.parse::()?; - - Ok(Self(Some(instance_usage))) - } else if lookahead.peek(syn::Token![:]) { - input.parse::()?; - input.parse::()?; - - if input.is_empty() { - return Ok(Self(Some(instance_usage))); - } - - instance_usage.has_instance = true; - input.parse::()?; - input.parse::()?; - input.parse::]>()?; - input.parse::()?; - input.parse::()?; - input.parse::()?; - input.parse::()?; - input.parse::()?; - input.parse::()?; - - Ok(Self(Some(instance_usage))) - } else { - Err(lookahead.error()) - } - } - } - - let i = syn::parse2::(r#gen.params.to_token_stream()) - .map_err(|e| { - let msg = format!("Invalid type def generics: {}", expected); - let mut err = syn::Error::new(span, msg); - err.combine(e); - err - })? - .0 - // Span can be call_site if generic is empty. Thus we replace it. - .map(|mut i| { - i.span = span; - i - }); - - Ok(i) -} - -/// Check the syntax: -/// * either `Pallet` -/// * or `Pallet` -/// -/// return the instance if found. -pub fn check_pallet_struct_usage(type_: &Box) -> syn::Result { - let expected = "expected `Pallet` or `Pallet`"; - pub struct Checker(InstanceUsage); - impl syn::parse::Parse for Checker { - fn parse(input: syn::parse::ParseStream) -> syn::Result { - let mut instance_usage = InstanceUsage { - span: input.span(), - has_instance: false, - }; - - input.parse::()?; - input.parse::()?; - input.parse::()?; - if input.peek(syn::Token![,]) { - instance_usage.has_instance = true; - input.parse::()?; - input.parse::()?; - } - input.parse::]>()?; - - Ok(Self(instance_usage)) - } - } - - let i = syn::parse2::(type_.to_token_stream()) - .map_err(|e| { - let msg = format!("Invalid pallet struct: {}", expected); - let mut err = syn::Error::new(type_.span(), msg); - err.combine(e); - err - })? - .0; - - Ok(i) -} - -/// Check the generic is: -/// * either `T: Config` -/// * or `T: Config, I: 'static` -/// -/// `span` is used in case generics is empty (empty generics has span == call_site). -/// -/// return whether it contains instance. -pub fn check_impl_gen( - r#gen: &syn::Generics, - span: proc_macro2::Span, -) -> syn::Result { - let expected = "expected `impl` or `impl, I: 'static>`"; - pub struct Checker(InstanceUsage); - impl syn::parse::Parse for Checker { - fn parse(input: syn::parse::ParseStream) -> syn::Result { - let mut instance_usage = InstanceUsage { - span: input.span(), - has_instance: false, - }; - - input.parse::()?; - input.parse::()?; - input.parse::()?; - if input.peek(syn::Token![<]) { - instance_usage.has_instance = true; - input.parse::()?; - input.parse::()?; - input.parse::]>()?; - input.parse::()?; - input.parse::()?; - input.parse::()?; - input.parse::()?; - } - - Ok(Self(instance_usage)) - } - } - - let i = syn::parse2::(r#gen.params.to_token_stream()) - .map_err(|e| { - let mut err = syn::Error::new(span, format!("Invalid generics: {}", expected)); - err.combine(e); - err - })? - .0; - - Ok(i) -} - -/// Check the syntax: -/// * or `T` -/// * or `T: Config` -/// * or `T, I = ()` -/// * or `T: Config, I: 'static = ()` -/// -/// `span` is used in case generics is empty (empty generics has span == call_site). -/// -/// return the instance if found. -pub fn check_type_def_gen( - r#gen: &syn::Generics, - span: proc_macro2::Span, -) -> syn::Result { - let expected = "expected `T` or `T: Config` or `T, I = ()` or \ - `T: Config, I: 'static = ()`"; - pub struct Checker(InstanceUsage); - impl syn::parse::Parse for Checker { - fn parse(input: syn::parse::ParseStream) -> syn::Result { - let mut instance_usage = InstanceUsage { - span: input.span(), - has_instance: false, - }; - - input.parse::()?; - - if input.is_empty() { - return Ok(Self(instance_usage)); - } - - let lookahead = input.lookahead1(); - if lookahead.peek(syn::Token![,]) { - instance_usage.has_instance = true; - input.parse::()?; - input.parse::()?; - input.parse::()?; - input.parse::()?; - - Ok(Self(instance_usage)) - } else if lookahead.peek(syn::Token![:]) { - input.parse::()?; - input.parse::()?; - - if input.is_empty() { - return Ok(Self(instance_usage)); - } - - instance_usage.has_instance = true; - input.parse::()?; - input.parse::()?; - input.parse::]>()?; - input.parse::()?; - input.parse::()?; - input.parse::()?; - input.parse::()?; - input.parse::()?; - input.parse::()?; - - Ok(Self(instance_usage)) - } else { - Err(lookahead.error()) - } - } - } - - let mut i = syn::parse2::(r#gen.params.to_token_stream()) - .map_err(|e| { - let msg = format!("Invalid type def generics: {}", expected); - let mut err = syn::Error::new(span, msg); - err.combine(e); - err - })? - .0; - - // Span can be call_site if generic is empty. Thus we replace it. - i.span = span; - - Ok(i) -} - -/// Check the syntax: -/// * either `GenesisBuild` -/// * or `GenesisBuild` -/// * or `BuildGenesisConfig` -/// -/// return the instance if found for `GenesisBuild` -/// return None for BuildGenesisConfig -pub fn check_genesis_builder_usage(type_: &syn::Path) -> syn::Result> { - let expected = "expected `BuildGenesisConfig` (or the deprecated `GenesisBuild` or `GenesisBuild`)"; - pub struct Checker(Option); - impl syn::parse::Parse for Checker { - fn parse(input: syn::parse::ParseStream) -> syn::Result { - let mut instance_usage = InstanceUsage { - span: input.span(), - has_instance: false, - }; - - if input.peek(keyword::GenesisBuild) { - input.parse::()?; - input.parse::()?; - input.parse::()?; - if input.peek(syn::Token![,]) { - instance_usage.has_instance = true; - input.parse::()?; - input.parse::()?; - } - input.parse::]>()?; - return Ok(Self(Some(instance_usage))); - } else { - input.parse::()?; - return Ok(Self(None)); - } - } - } - - let i = syn::parse2::(type_.to_token_stream()) - .map_err(|e| { - let msg = format!("Invalid genesis builder: {}", expected); - let mut err = syn::Error::new(type_.span(), msg); - err.combine(e); - err - })? - .0; - - Ok(i) -} - -/// Check the syntax: -/// * either `` (no generics) -/// * or `T: Config` -/// * or `T: Config, I: 'static` -/// -/// `span` is used in case generics is empty (empty generics has span == call_site). -/// -/// return the instance if found. -pub fn check_type_value_gen( - r#gen: &syn::Generics, - span: proc_macro2::Span, -) -> syn::Result> { - let expected = "expected `` or `T: Config` or `T: Config, I: 'static`"; - pub struct Checker(Option); - impl syn::parse::Parse for Checker { - fn parse(input: syn::parse::ParseStream) -> syn::Result { - if input.is_empty() { - return Ok(Self(None)); - } - - input.parse::()?; - input.parse::()?; - input.parse::()?; - - let mut instance_usage = InstanceUsage { - span: input.span(), - has_instance: false, - }; - - if input.is_empty() { - return Ok(Self(Some(instance_usage))); - } - - instance_usage.has_instance = true; - input.parse::()?; - input.parse::()?; - input.parse::]>()?; - input.parse::()?; - input.parse::()?; - input.parse::()?; - input.parse::()?; - - Ok(Self(Some(instance_usage))) - } - } - - let i = syn::parse2::(r#gen.params.to_token_stream()) - .map_err(|e| { - let msg = format!("Invalid type def generics: {}", expected); - let mut err = syn::Error::new(span, msg); - err.combine(e); - err - })? - .0 - // Span can be call_site if generic is empty. Thus we replace it. - .map(|mut i| { - i.span = span; - i - }); - - Ok(i) -} - -/// Check the keyword `DispatchResultWithPostInfo` or `DispatchResult`. -pub fn check_pallet_call_return_type(type_: &syn::Type) -> syn::Result<()> { - pub struct Checker; - impl syn::parse::Parse for Checker { - fn parse(input: syn::parse::ParseStream) -> syn::Result { - let lookahead = input.lookahead1(); - if lookahead.peek(keyword::DispatchResultWithPostInfo) { - input.parse::()?; - Ok(Self) - } else if lookahead.peek(keyword::DispatchResult) { - input.parse::()?; - Ok(Self) - } else { - Err(lookahead.error()) - } - } - } - - syn::parse2::(type_.to_token_stream()).map(|_| ()) -} - -pub(crate) fn two128_str(s: &str) -> TokenStream { - bytes_to_array(sp_crypto_hashing::twox_128(s.as_bytes()).into_iter()) -} - -pub(crate) fn bytes_to_array(bytes: impl IntoIterator) -> TokenStream { - let bytes = bytes.into_iter(); - - quote!( - [ #( #bytes ),* ] - ) - .into() -} diff --git a/support/procedural-fork/src/pallet/parse/hooks.rs b/support/procedural-fork/src/pallet/parse/hooks.rs deleted file mode 100644 index bca1a33833..0000000000 --- a/support/procedural-fork/src/pallet/parse/hooks.rs +++ /dev/null @@ -1,79 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use super::helper; -use syn::spanned::Spanned; - -/// Implementation of the pallet hooks. -pub struct HooksDef { - /// A set of usage of instance, must be check for consistency with trait. - pub instances: Vec, - /// The where_clause used. - pub where_clause: Option, - /// The span of the pallet::hooks attribute. - pub attr_span: proc_macro2::Span, - /// Boolean flag, set to true if the `on_runtime_upgrade` method of hooks was implemented. - pub has_runtime_upgrade: bool, -} - -impl HooksDef { - pub fn try_from(attr_span: proc_macro2::Span, item: &mut syn::Item) -> syn::Result { - let item = if let syn::Item::Impl(item) = item { - item - } else { - let msg = "Invalid pallet::hooks, expected item impl"; - return Err(syn::Error::new(item.span(), msg)); - }; - - let instances = vec![ - helper::check_pallet_struct_usage(&item.self_ty)?, - helper::check_impl_gen(&item.generics, item.impl_token.span())?, - ]; - - let item_trait = &item - .trait_ - .as_ref() - .ok_or_else(|| { - let msg = "Invalid pallet::hooks, expected impl<..> Hooks \ - for Pallet<..>"; - syn::Error::new(item.span(), msg) - })? - .1; - - if item_trait.segments.len() != 1 || item_trait.segments[0].ident != "Hooks" { - let msg = format!( - "Invalid pallet::hooks, expected trait to be `Hooks` found `{}`\ - , you can import from `frame_support::pallet_prelude`", - quote::quote!(#item_trait) - ); - - return Err(syn::Error::new(item_trait.span(), msg)); - } - - let has_runtime_upgrade = item.items.iter().any(|i| match i { - syn::ImplItem::Fn(method) => method.sig.ident == "on_runtime_upgrade", - _ => false, - }); - - Ok(Self { - attr_span, - instances, - has_runtime_upgrade, - where_clause: item.generics.where_clause.clone(), - }) - } -} diff --git a/support/procedural-fork/src/pallet/parse/inherent.rs b/support/procedural-fork/src/pallet/parse/inherent.rs deleted file mode 100644 index 911de2ffed..0000000000 --- a/support/procedural-fork/src/pallet/parse/inherent.rs +++ /dev/null @@ -1,58 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use super::helper; -use syn::spanned::Spanned; - -/// The definition of the pallet inherent implementation. -pub struct InherentDef { - /// A set of usage of instance, must be check for consistency with trait. - pub instances: Vec, -} - -impl InherentDef { - pub fn try_from(item: &mut syn::Item) -> syn::Result { - let item = if let syn::Item::Impl(item) = item { - item - } else { - let msg = "Invalid pallet::inherent, expected item impl"; - return Err(syn::Error::new(item.span(), msg)); - }; - - if item.trait_.is_none() { - let msg = "Invalid pallet::inherent, expected impl<..> ProvideInherent for Pallet<..>"; - return Err(syn::Error::new(item.span(), msg)); - } - - if let Some(last) = item.trait_.as_ref().unwrap().1.segments.last() { - if last.ident != "ProvideInherent" { - let msg = "Invalid pallet::inherent, expected trait ProvideInherent"; - return Err(syn::Error::new(last.span(), msg)); - } - } else { - let msg = "Invalid pallet::inherent, expected impl<..> ProvideInherent for Pallet<..>"; - return Err(syn::Error::new(item.span(), msg)); - } - - let instances = vec![ - helper::check_pallet_struct_usage(&item.self_ty)?, - helper::check_impl_gen(&item.generics, item.impl_token.span())?, - ]; - - Ok(InherentDef { instances }) - } -} diff --git a/support/procedural-fork/src/pallet/parse/mod.rs b/support/procedural-fork/src/pallet/parse/mod.rs deleted file mode 100644 index 05eacd1449..0000000000 --- a/support/procedural-fork/src/pallet/parse/mod.rs +++ /dev/null @@ -1,818 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//! Parse for pallet macro. -//! -//! Parse the module into `Def` struct through `Def::try_from` function. - -pub mod call; -pub mod composite; -pub mod config; -pub mod error; -pub mod event; -pub mod extra_constants; -pub mod genesis_build; -pub mod genesis_config; -pub mod helper; -pub mod hooks; -pub mod inherent; -pub mod origin; -pub mod pallet_struct; -pub mod storage; -pub mod tasks; -pub mod type_value; -pub mod validate_unsigned; - -#[cfg(test)] -pub mod tests; - -use composite::{CompositeDef, keyword::CompositeKeyword}; -use frame_support_procedural_tools::generate_access_from_frame_or_crate; -use quote::ToTokens; -use syn::spanned::Spanned; - -/// Parsed definition of a pallet. -pub struct Def { - /// The module items. - /// (their order must not be modified because they are registered in individual definitions). - pub item: syn::ItemMod, - pub config: config::ConfigDef, - pub pallet_struct: pallet_struct::PalletStructDef, - pub hooks: Option, - pub call: Option, - pub tasks: Option, - pub task_enum: Option, - pub storages: Vec, - pub error: Option, - pub event: Option, - pub origin: Option, - pub inherent: Option, - pub genesis_config: Option, - pub genesis_build: Option, - pub validate_unsigned: Option, - pub extra_constants: Option, - pub composites: Vec, - pub type_values: Vec, - pub frame_system: syn::Path, - pub frame_support: syn::Path, - pub dev_mode: bool, -} - -impl Def { - pub fn try_from(mut item: syn::ItemMod, dev_mode: bool) -> syn::Result { - let frame_system = generate_access_from_frame_or_crate("frame-system")?; - let frame_support = generate_access_from_frame_or_crate("frame-support")?; - - let item_span = item.span(); - let items = &mut item - .content - .as_mut() - .ok_or_else(|| { - let msg = "Invalid pallet definition, expected mod to be inlined."; - syn::Error::new(item_span, msg) - })? - .1; - - let mut config = None; - let mut pallet_struct = None; - let mut hooks = None; - let mut call = None; - let mut tasks = None; - let mut task_enum = None; - let mut error = None; - let mut event = None; - let mut origin = None; - let mut inherent = None; - let mut genesis_config = None; - let mut genesis_build = None; - let mut validate_unsigned = None; - let mut extra_constants = None; - let mut storages = vec![]; - let mut type_values = vec![]; - let mut composites: Vec = vec![]; - - for (index, item) in items.iter_mut().enumerate() { - let pallet_attr: Option = helper::take_first_item_pallet_attr(item)?; - - match pallet_attr { - Some(PalletAttr::Config(_, with_default)) if config.is_none() => { - config = Some(config::ConfigDef::try_from( - &frame_system, - index, - item, - with_default, - )?) - } - Some(PalletAttr::Pallet(span)) if pallet_struct.is_none() => { - let p = pallet_struct::PalletStructDef::try_from(span, index, item)?; - pallet_struct = Some(p); - } - Some(PalletAttr::Hooks(span)) if hooks.is_none() => { - let m = hooks::HooksDef::try_from(span, item)?; - hooks = Some(m); - } - Some(PalletAttr::RuntimeCall(cw, span)) if call.is_none() => { - call = Some(call::CallDef::try_from(span, index, item, dev_mode, cw)?) - } - Some(PalletAttr::Tasks(_)) if tasks.is_none() => { - let item_tokens = item.to_token_stream(); - // `TasksDef::parse` needs to know if attr was provided so we artificially - // re-insert it here - tasks = Some(syn::parse2::(quote::quote! { - #[pallet::tasks_experimental] - #item_tokens - })?); - - // replace item with a no-op because it will be handled by the expansion of tasks - *item = syn::Item::Verbatim(quote::quote!()); - } - Some(PalletAttr::TaskCondition(span)) => { - return Err(syn::Error::new( - span, - "`#[pallet::task_condition]` can only be used on items within an `impl` statement.", - )); - } - Some(PalletAttr::TaskIndex(span)) => { - return Err(syn::Error::new( - span, - "`#[pallet::task_index]` can only be used on items within an `impl` statement.", - )); - } - Some(PalletAttr::TaskList(span)) => { - return Err(syn::Error::new( - span, - "`#[pallet::task_list]` can only be used on items within an `impl` statement.", - )); - } - Some(PalletAttr::RuntimeTask(_)) if task_enum.is_none() => { - task_enum = Some(syn::parse2::(item.to_token_stream())?) - } - Some(PalletAttr::Error(span)) if error.is_none() => { - error = Some(error::ErrorDef::try_from(span, index, item)?) - } - Some(PalletAttr::RuntimeEvent(span)) if event.is_none() => { - event = Some(event::EventDef::try_from(span, index, item)?) - } - Some(PalletAttr::GenesisConfig(_)) if genesis_config.is_none() => { - let g = genesis_config::GenesisConfigDef::try_from(index, item)?; - genesis_config = Some(g); - } - Some(PalletAttr::GenesisBuild(span)) if genesis_build.is_none() => { - let g = genesis_build::GenesisBuildDef::try_from(span, item)?; - genesis_build = Some(g); - } - Some(PalletAttr::RuntimeOrigin(_)) if origin.is_none() => { - origin = Some(origin::OriginDef::try_from(item)?) - } - Some(PalletAttr::Inherent(_)) if inherent.is_none() => { - inherent = Some(inherent::InherentDef::try_from(item)?) - } - Some(PalletAttr::Storage(span)) => { - storages.push(storage::StorageDef::try_from(span, index, item, dev_mode)?) - } - Some(PalletAttr::ValidateUnsigned(_)) if validate_unsigned.is_none() => { - let v = validate_unsigned::ValidateUnsignedDef::try_from(item)?; - validate_unsigned = Some(v); - } - Some(PalletAttr::TypeValue(span)) => { - type_values.push(type_value::TypeValueDef::try_from(span, index, item)?) - } - Some(PalletAttr::ExtraConstants(_)) => { - extra_constants = Some(extra_constants::ExtraConstantsDef::try_from(item)?) - } - Some(PalletAttr::Composite(span)) => { - let composite = composite::CompositeDef::try_from(span, &frame_support, item)?; - if composites.iter().any(|def| { - match (&def.composite_keyword, &composite.composite_keyword) { - ( - CompositeKeyword::FreezeReason(_), - CompositeKeyword::FreezeReason(_), - ) - | (CompositeKeyword::HoldReason(_), CompositeKeyword::HoldReason(_)) - | (CompositeKeyword::LockId(_), CompositeKeyword::LockId(_)) - | ( - CompositeKeyword::SlashReason(_), - CompositeKeyword::SlashReason(_), - ) => true, - _ => false, - } - }) { - let msg = format!( - "Invalid duplicated `{}` definition", - composite.composite_keyword - ); - return Err(syn::Error::new(composite.composite_keyword.span(), &msg)); - } - composites.push(composite); - } - Some(attr) => { - let msg = "Invalid duplicated attribute"; - return Err(syn::Error::new(attr.span(), msg)); - } - None => (), - } - } - - if genesis_config.is_some() != genesis_build.is_some() { - let msg = format!( - "`#[pallet::genesis_config]` and `#[pallet::genesis_build]` attributes must be \ - either both used or both not used, instead genesis_config is {} and genesis_build \ - is {}", - genesis_config.as_ref().map_or("unused", |_| "used"), - genesis_build.as_ref().map_or("unused", |_| "used"), - ); - return Err(syn::Error::new(item_span, msg)); - } - - Self::resolve_tasks(&item_span, &mut tasks, &mut task_enum, items)?; - - let def = Def { - item, - config: config - .ok_or_else(|| syn::Error::new(item_span, "Missing `#[pallet::config]`"))?, - pallet_struct: pallet_struct - .ok_or_else(|| syn::Error::new(item_span, "Missing `#[pallet::pallet]`"))?, - hooks, - call, - tasks, - task_enum, - extra_constants, - genesis_config, - genesis_build, - validate_unsigned, - error, - event, - origin, - inherent, - storages, - composites, - type_values, - frame_system, - frame_support, - dev_mode, - }; - - def.check_instance_usage()?; - def.check_event_usage()?; - - Ok(def) - } - - /// Performs extra logic checks necessary for the `#[pallet::tasks_experimental]` feature. - fn resolve_tasks( - item_span: &proc_macro2::Span, - tasks: &mut Option, - task_enum: &mut Option, - items: &mut Vec, - ) -> syn::Result<()> { - // fallback for manual (without macros) definition of tasks impl - Self::resolve_manual_tasks_impl(tasks, task_enum, items)?; - - // fallback for manual (without macros) definition of task enum - Self::resolve_manual_task_enum(tasks, task_enum, items)?; - - // ensure that if `task_enum` is specified, `tasks` is also specified - match (&task_enum, &tasks) { - (Some(_), None) => { - return Err(syn::Error::new( - *item_span, - "Missing `#[pallet::tasks_experimental]` impl", - )); - } - (None, Some(tasks)) => { - if tasks.tasks_attr.is_none() { - return Err(syn::Error::new( - tasks.item_impl.impl_token.span(), - "A `#[pallet::tasks_experimental]` attribute must be attached to your `Task` impl if the \ - task enum has been omitted", - )); - } else { - } - } - _ => (), - } - - Ok(()) - } - - /// Tries to locate task enum based on the tasks impl target if attribute is not specified - /// but impl is present. If one is found, `task_enum` is set appropriately. - fn resolve_manual_task_enum( - tasks: &Option, - task_enum: &mut Option, - items: &mut Vec, - ) -> syn::Result<()> { - let (None, Some(tasks)) = (&task_enum, &tasks) else { - return Ok(()); - }; - let syn::Type::Path(type_path) = &*tasks.item_impl.self_ty else { - return Ok(()); - }; - let type_path = type_path.path.segments.iter().collect::>(); - let (Some(seg), None) = (type_path.get(0), type_path.get(1)) else { - return Ok(()); - }; - let mut result = None; - for item in items { - let syn::Item::Enum(item_enum) = item else { - continue; - }; - if item_enum.ident == seg.ident { - result = Some(syn::parse2::( - item_enum.to_token_stream(), - )?); - // replace item with a no-op because it will be handled by the expansion of - // `task_enum`. We use a no-op instead of simply removing it from the vec - // so that any indices collected by `Def::try_from` remain accurate - *item = syn::Item::Verbatim(quote::quote!()); - break; - } - } - *task_enum = result; - Ok(()) - } - - /// Tries to locate a manual tasks impl (an impl implementing a trait whose last path segment is - /// `Task`) in the event that one has not been found already via the attribute macro - pub fn resolve_manual_tasks_impl( - tasks: &mut Option, - task_enum: &Option, - items: &Vec, - ) -> syn::Result<()> { - let None = tasks else { return Ok(()) }; - let mut result = None; - for item in items { - let syn::Item::Impl(item_impl) = item else { - continue; - }; - let Some((_, path, _)) = &item_impl.trait_ else { - continue; - }; - let Some(trait_last_seg) = path.segments.last() else { - continue; - }; - let syn::Type::Path(target_path) = &*item_impl.self_ty else { - continue; - }; - let target_path = target_path.path.segments.iter().collect::>(); - let (Some(target_ident), None) = (target_path.get(0), target_path.get(1)) else { - continue; - }; - let matches_task_enum = match task_enum { - Some(task_enum) => task_enum.item_enum.ident == target_ident.ident, - None => true, - }; - if trait_last_seg.ident == "Task" && matches_task_enum { - result = Some(syn::parse2::(item_impl.to_token_stream())?); - break; - } - } - *tasks = result; - Ok(()) - } - - /// Check that usage of trait `Event` is consistent with the definition, i.e. it is declared - /// and trait defines type RuntimeEvent, or not declared and no trait associated type. - fn check_event_usage(&self) -> syn::Result<()> { - match (self.config.has_event_type, self.event.is_some()) { - (true, false) => { - let msg = "Invalid usage of RuntimeEvent, `Config` contains associated type `RuntimeEvent`, \ - but enum `Event` is not declared (i.e. no use of `#[pallet::event]`). \ - Note that type `RuntimeEvent` in trait is reserved to work alongside pallet event."; - Err(syn::Error::new(proc_macro2::Span::call_site(), msg)) - } - (false, true) => { - let msg = "Invalid usage of RuntimeEvent, `Config` contains no associated type \ - `RuntimeEvent`, but enum `Event` is declared (in use of `#[pallet::event]`). \ - An RuntimeEvent associated type must be declare on trait `Config`."; - Err(syn::Error::new(proc_macro2::Span::call_site(), msg)) - } - _ => Ok(()), - } - } - - /// Check that usage of trait `Config` is consistent with the definition, i.e. it is used with - /// instance iff it is defined with instance. - fn check_instance_usage(&self) -> syn::Result<()> { - let mut instances = vec![]; - instances.extend_from_slice(&self.pallet_struct.instances[..]); - instances.extend(&mut self.storages.iter().flat_map(|s| s.instances.clone())); - if let Some(call) = &self.call { - instances.extend_from_slice(&call.instances[..]); - } - if let Some(hooks) = &self.hooks { - instances.extend_from_slice(&hooks.instances[..]); - } - if let Some(event) = &self.event { - instances.extend_from_slice(&event.instances[..]); - } - if let Some(error) = &self.error { - instances.extend_from_slice(&error.instances[..]); - } - if let Some(inherent) = &self.inherent { - instances.extend_from_slice(&inherent.instances[..]); - } - if let Some(origin) = &self.origin { - instances.extend_from_slice(&origin.instances[..]); - } - if let Some(genesis_config) = &self.genesis_config { - instances.extend_from_slice(&genesis_config.instances[..]); - } - if let Some(genesis_build) = &self.genesis_build { - genesis_build - .instances - .as_ref() - .map(|i| instances.extend_from_slice(&i)); - } - if let Some(extra_constants) = &self.extra_constants { - instances.extend_from_slice(&extra_constants.instances[..]); - } - - let mut errors = instances.into_iter().filter_map(|instances| { - if instances.has_instance == self.config.has_instance { - return None; - } - let msg = if self.config.has_instance { - "Invalid generic declaration, trait is defined with instance but generic use none" - } else { - "Invalid generic declaration, trait is defined without instance but generic use \ - some" - }; - Some(syn::Error::new(instances.span, msg)) - }); - - if let Some(mut first_error) = errors.next() { - for error in errors { - first_error.combine(error) - } - Err(first_error) - } else { - Ok(()) - } - } - - /// Depending on if pallet is instantiable: - /// * either `T: Config` - /// * or `T: Config, I: 'static` - pub fn type_impl_generics(&self, span: proc_macro2::Span) -> proc_macro2::TokenStream { - if self.config.has_instance { - quote::quote_spanned!(span => T: Config, I: 'static) - } else { - quote::quote_spanned!(span => T: Config) - } - } - - /// Depending on if pallet is instantiable: - /// * either `T: Config` - /// * or `T: Config, I: 'static = ()` - pub fn type_decl_bounded_generics(&self, span: proc_macro2::Span) -> proc_macro2::TokenStream { - if self.config.has_instance { - quote::quote_spanned!(span => T: Config, I: 'static = ()) - } else { - quote::quote_spanned!(span => T: Config) - } - } - - /// Depending on if pallet is instantiable: - /// * either `T` - /// * or `T, I = ()` - pub fn type_decl_generics(&self, span: proc_macro2::Span) -> proc_macro2::TokenStream { - if self.config.has_instance { - quote::quote_spanned!(span => T, I = ()) - } else { - quote::quote_spanned!(span => T) - } - } - - /// Depending on if pallet is instantiable: - /// * either `` - /// * or `` - /// to be used when using pallet trait `Config` - pub fn trait_use_generics(&self, span: proc_macro2::Span) -> proc_macro2::TokenStream { - if self.config.has_instance { - quote::quote_spanned!(span => ) - } else { - quote::quote_spanned!(span => ) - } - } - - /// Depending on if pallet is instantiable: - /// * either `T` - /// * or `T, I` - pub fn type_use_generics(&self, span: proc_macro2::Span) -> proc_macro2::TokenStream { - if self.config.has_instance { - quote::quote_spanned!(span => T, I) - } else { - quote::quote_spanned!(span => T) - } - } -} - -/// Some generic kind for type which can be not generic, or generic over config, -/// or generic over config and instance, but not generic only over instance. -pub enum GenericKind { - None, - Config, - ConfigAndInstance, -} - -impl GenericKind { - /// Return Err if it is only generics over instance but not over config. - pub fn from_gens(has_config: bool, has_instance: bool) -> Result { - match (has_config, has_instance) { - (false, false) => Ok(GenericKind::None), - (true, false) => Ok(GenericKind::Config), - (true, true) => Ok(GenericKind::ConfigAndInstance), - (false, true) => Err(()), - } - } - - /// Return the generic to be used when using the type. - /// - /// Depending on its definition it can be: ``, `T` or `T, I` - pub fn type_use_gen(&self, span: proc_macro2::Span) -> proc_macro2::TokenStream { - match self { - GenericKind::None => quote::quote!(), - GenericKind::Config => quote::quote_spanned!(span => T), - GenericKind::ConfigAndInstance => quote::quote_spanned!(span => T, I), - } - } - - /// Return the generic to be used in `impl<..>` when implementing on the type. - pub fn type_impl_gen(&self, span: proc_macro2::Span) -> proc_macro2::TokenStream { - match self { - GenericKind::None => quote::quote!(), - GenericKind::Config => quote::quote_spanned!(span => T: Config), - GenericKind::ConfigAndInstance => { - quote::quote_spanned!(span => T: Config, I: 'static) - } - } - } - - /// Return whereas the type has some generic. - pub fn is_generic(&self) -> bool { - match self { - GenericKind::None => false, - GenericKind::Config | GenericKind::ConfigAndInstance => true, - } - } -} - -/// List of additional token to be used for parsing. -mod keyword { - syn::custom_keyword!(origin); - syn::custom_keyword!(call); - syn::custom_keyword!(tasks_experimental); - syn::custom_keyword!(task_enum); - syn::custom_keyword!(task_list); - syn::custom_keyword!(task_condition); - syn::custom_keyword!(task_index); - syn::custom_keyword!(weight); - syn::custom_keyword!(event); - syn::custom_keyword!(config); - syn::custom_keyword!(with_default); - syn::custom_keyword!(hooks); - syn::custom_keyword!(inherent); - syn::custom_keyword!(error); - syn::custom_keyword!(storage); - syn::custom_keyword!(genesis_build); - syn::custom_keyword!(genesis_config); - syn::custom_keyword!(validate_unsigned); - syn::custom_keyword!(type_value); - syn::custom_keyword!(pallet); - syn::custom_keyword!(extra_constants); - syn::custom_keyword!(composite_enum); -} - -/// Parse attributes for item in pallet module -/// syntax must be `pallet::` (e.g. `#[pallet::config]`) -enum PalletAttr { - Config(proc_macro2::Span, bool), - Pallet(proc_macro2::Span), - Hooks(proc_macro2::Span), - /// A `#[pallet::call]` with optional attributes to specialize the behaviour. - /// - /// # Attributes - /// - /// Each attribute `attr` can take the form of `#[pallet::call(attr = …)]` or - /// `#[pallet::call(attr(…))]`. The possible attributes are: - /// - /// ## `weight` - /// - /// Can be used to reduce the repetitive weight annotation in the trivial case. It accepts one - /// argument that is expected to be an implementation of the `WeightInfo` or something that - /// behaves syntactically equivalent. This allows to annotate a `WeightInfo` for all the calls. - /// Now each call does not need to specify its own `#[pallet::weight]` but can instead use the - /// one from the `#[pallet::call]` definition. So instead of having to write it on each call: - /// - /// ```ignore - /// #[pallet::call] - /// impl Pallet { - /// #[pallet::weight(T::WeightInfo::create())] - /// pub fn create( - /// ``` - /// you can now omit it on the call itself, if the name of the weigh function matches the call: - /// - /// ```ignore - /// #[pallet::call(weight = ::WeightInfo)] - /// impl Pallet { - /// pub fn create( - /// ``` - /// - /// It is possible to use this syntax together with instantiated pallets by using `Config` - /// instead. - /// - /// ### Dev Mode - /// - /// Normally the `dev_mode` sets all weights of calls without a `#[pallet::weight]` annotation - /// to zero. Now when there is a `weight` attribute on the `#[pallet::call]`, then that is used - /// instead of the zero weight. So to say: it works together with `dev_mode`. - RuntimeCall(Option, proc_macro2::Span), - Error(proc_macro2::Span), - Tasks(proc_macro2::Span), - TaskList(proc_macro2::Span), - TaskCondition(proc_macro2::Span), - TaskIndex(proc_macro2::Span), - RuntimeTask(proc_macro2::Span), - RuntimeEvent(proc_macro2::Span), - RuntimeOrigin(proc_macro2::Span), - Inherent(proc_macro2::Span), - Storage(proc_macro2::Span), - GenesisConfig(proc_macro2::Span), - GenesisBuild(proc_macro2::Span), - ValidateUnsigned(proc_macro2::Span), - TypeValue(proc_macro2::Span), - ExtraConstants(proc_macro2::Span), - Composite(proc_macro2::Span), -} - -impl PalletAttr { - fn span(&self) -> proc_macro2::Span { - match self { - Self::Config(span, _) => *span, - Self::Pallet(span) => *span, - Self::Hooks(span) => *span, - Self::Tasks(span) => *span, - Self::TaskCondition(span) => *span, - Self::TaskIndex(span) => *span, - Self::TaskList(span) => *span, - Self::Error(span) => *span, - Self::RuntimeTask(span) => *span, - Self::RuntimeCall(_, span) => *span, - Self::RuntimeEvent(span) => *span, - Self::RuntimeOrigin(span) => *span, - Self::Inherent(span) => *span, - Self::Storage(span) => *span, - Self::GenesisConfig(span) => *span, - Self::GenesisBuild(span) => *span, - Self::ValidateUnsigned(span) => *span, - Self::TypeValue(span) => *span, - Self::ExtraConstants(span) => *span, - Self::Composite(span) => *span, - } - } -} - -impl syn::parse::Parse for PalletAttr { - fn parse(input: syn::parse::ParseStream) -> syn::Result { - input.parse::()?; - let content; - syn::bracketed!(content in input); - content.parse::()?; - content.parse::()?; - - let lookahead = content.lookahead1(); - if lookahead.peek(keyword::config) { - let span = content.parse::()?.span(); - let with_default = content.peek(syn::token::Paren); - if with_default { - let inside_config; - let _paren = syn::parenthesized!(inside_config in content); - inside_config.parse::()?; - } - Ok(PalletAttr::Config(span, with_default)) - } else if lookahead.peek(keyword::pallet) { - Ok(PalletAttr::Pallet( - content.parse::()?.span(), - )) - } else if lookahead.peek(keyword::hooks) { - Ok(PalletAttr::Hooks(content.parse::()?.span())) - } else if lookahead.peek(keyword::call) { - let span = content.parse::().expect("peeked").span(); - let attr = match content.is_empty() { - true => None, - false => Some(InheritedCallWeightAttr::parse(&content)?), - }; - Ok(PalletAttr::RuntimeCall(attr, span)) - } else if lookahead.peek(keyword::tasks_experimental) { - Ok(PalletAttr::Tasks( - content.parse::()?.span(), - )) - } else if lookahead.peek(keyword::task_enum) { - Ok(PalletAttr::RuntimeTask( - content.parse::()?.span(), - )) - } else if lookahead.peek(keyword::task_condition) { - Ok(PalletAttr::TaskCondition( - content.parse::()?.span(), - )) - } else if lookahead.peek(keyword::task_index) { - Ok(PalletAttr::TaskIndex( - content.parse::()?.span(), - )) - } else if lookahead.peek(keyword::task_list) { - Ok(PalletAttr::TaskList( - content.parse::()?.span(), - )) - } else if lookahead.peek(keyword::error) { - Ok(PalletAttr::Error(content.parse::()?.span())) - } else if lookahead.peek(keyword::event) { - Ok(PalletAttr::RuntimeEvent( - content.parse::()?.span(), - )) - } else if lookahead.peek(keyword::origin) { - Ok(PalletAttr::RuntimeOrigin( - content.parse::()?.span(), - )) - } else if lookahead.peek(keyword::inherent) { - Ok(PalletAttr::Inherent( - content.parse::()?.span(), - )) - } else if lookahead.peek(keyword::storage) { - Ok(PalletAttr::Storage( - content.parse::()?.span(), - )) - } else if lookahead.peek(keyword::genesis_config) { - Ok(PalletAttr::GenesisConfig( - content.parse::()?.span(), - )) - } else if lookahead.peek(keyword::genesis_build) { - Ok(PalletAttr::GenesisBuild( - content.parse::()?.span(), - )) - } else if lookahead.peek(keyword::validate_unsigned) { - Ok(PalletAttr::ValidateUnsigned( - content.parse::()?.span(), - )) - } else if lookahead.peek(keyword::type_value) { - Ok(PalletAttr::TypeValue( - content.parse::()?.span(), - )) - } else if lookahead.peek(keyword::extra_constants) { - Ok(PalletAttr::ExtraConstants( - content.parse::()?.span(), - )) - } else if lookahead.peek(keyword::composite_enum) { - Ok(PalletAttr::Composite( - content.parse::()?.span(), - )) - } else { - Err(lookahead.error()) - } - } -} - -/// The optional weight annotation on a `#[pallet::call]` like `#[pallet::call(weight($type))]`. -#[derive(Clone)] -pub struct InheritedCallWeightAttr { - pub typename: syn::Type, -} - -impl syn::parse::Parse for InheritedCallWeightAttr { - // Parses `(weight($type))` or `(weight = $type)`. - fn parse(input: syn::parse::ParseStream) -> syn::Result { - let content; - syn::parenthesized!(content in input); - content.parse::()?; - let lookahead = content.lookahead1(); - - let buffer = if lookahead.peek(syn::token::Paren) { - let inner; - syn::parenthesized!(inner in content); - inner - } else if lookahead.peek(syn::Token![=]) { - content.parse::().expect("peeked"); - content - } else { - return Err(lookahead.error()); - }; - - Ok(Self { - typename: buffer.parse()?, - }) - } -} diff --git a/support/procedural-fork/src/pallet/parse/origin.rs b/support/procedural-fork/src/pallet/parse/origin.rs deleted file mode 100644 index 8232719d66..0000000000 --- a/support/procedural-fork/src/pallet/parse/origin.rs +++ /dev/null @@ -1,74 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use super::helper; -use syn::spanned::Spanned; - -/// Definition of the pallet origin type. -/// -/// Either: -/// * `type Origin` -/// * `struct Origin` -/// * `enum Origin` -pub struct OriginDef { - pub is_generic: bool, - /// A set of usage of instance, must be check for consistency with trait. - pub instances: Vec, -} - -impl OriginDef { - pub fn try_from(item: &mut syn::Item) -> syn::Result { - let item_span = item.span(); - let (vis, ident, generics) = match &item { - syn::Item::Enum(item) => (&item.vis, &item.ident, &item.generics), - syn::Item::Struct(item) => (&item.vis, &item.ident, &item.generics), - syn::Item::Type(item) => (&item.vis, &item.ident, &item.generics), - _ => { - let msg = "Invalid pallet::origin, expected enum or struct or type"; - return Err(syn::Error::new(item.span(), msg)); - } - }; - - let is_generic = !generics.params.is_empty(); - - let mut instances = vec![]; - if let Some(u) = helper::check_type_def_optional_gen(generics, item.span())? { - instances.push(u); - } else { - // construct_runtime only allow generic event for instantiable pallet. - instances.push(helper::InstanceUsage { - has_instance: false, - span: ident.span(), - }) - } - - if !matches!(vis, syn::Visibility::Public(_)) { - let msg = "Invalid pallet::origin, Origin must be public"; - return Err(syn::Error::new(item_span, msg)); - } - - if ident != "Origin" { - let msg = "Invalid pallet::origin, ident must `Origin`"; - return Err(syn::Error::new(ident.span(), msg)); - } - - Ok(OriginDef { - is_generic, - instances, - }) - } -} diff --git a/support/procedural-fork/src/pallet/parse/pallet_struct.rs b/support/procedural-fork/src/pallet/parse/pallet_struct.rs deleted file mode 100644 index 320cf01faf..0000000000 --- a/support/procedural-fork/src/pallet/parse/pallet_struct.rs +++ /dev/null @@ -1,157 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use super::helper; -use quote::ToTokens; -use syn::spanned::Spanned; - -/// List of additional token to be used for parsing. -mod keyword { - syn::custom_keyword!(pallet); - syn::custom_keyword!(Pallet); - syn::custom_keyword!(without_storage_info); - syn::custom_keyword!(storage_version); -} - -/// Definition of the pallet pallet. -pub struct PalletStructDef { - /// The index of item in pallet pallet. - pub index: usize, - /// A set of usage of instance, must be check for consistency with config trait. - pub instances: Vec, - /// The keyword Pallet used (contains span). - pub pallet: keyword::Pallet, - /// The span of the pallet::pallet attribute. - pub attr_span: proc_macro2::Span, - /// Whether to specify the storages max encoded len when implementing `StorageInfoTrait`. - /// Contains the span of the attribute. - pub without_storage_info: Option, - /// The in-code storage version of the pallet. - pub storage_version: Option, -} - -/// Parse for one variant of: -/// * `#[pallet::without_storage_info]` -/// * `#[pallet::storage_version(STORAGE_VERSION)]` -pub enum PalletStructAttr { - WithoutStorageInfoTrait(proc_macro2::Span), - StorageVersion { - storage_version: syn::Path, - span: proc_macro2::Span, - }, -} - -impl PalletStructAttr { - fn span(&self) -> proc_macro2::Span { - match self { - Self::WithoutStorageInfoTrait(span) | Self::StorageVersion { span, .. } => *span, - } - } -} - -impl syn::parse::Parse for PalletStructAttr { - fn parse(input: syn::parse::ParseStream) -> syn::Result { - input.parse::()?; - let content; - syn::bracketed!(content in input); - content.parse::()?; - content.parse::()?; - - let lookahead = content.lookahead1(); - if lookahead.peek(keyword::without_storage_info) { - let span = content.parse::()?.span(); - Ok(Self::WithoutStorageInfoTrait(span)) - } else if lookahead.peek(keyword::storage_version) { - let span = content.parse::()?.span(); - - let version_content; - syn::parenthesized!(version_content in content); - let storage_version = version_content.parse::()?; - - Ok(Self::StorageVersion { - storage_version, - span, - }) - } else { - Err(lookahead.error()) - } - } -} - -impl PalletStructDef { - pub fn try_from( - attr_span: proc_macro2::Span, - index: usize, - item: &mut syn::Item, - ) -> syn::Result { - let item = if let syn::Item::Struct(item) = item { - item - } else { - let msg = "Invalid pallet::pallet, expected struct definition"; - return Err(syn::Error::new(item.span(), msg)); - }; - - let mut without_storage_info = None; - let mut storage_version_found = None; - - let struct_attrs: Vec = helper::take_item_pallet_attrs(&mut item.attrs)?; - for attr in struct_attrs { - match attr { - PalletStructAttr::WithoutStorageInfoTrait(span) - if without_storage_info.is_none() => - { - without_storage_info = Some(span); - } - PalletStructAttr::StorageVersion { - storage_version, .. - } if storage_version_found.is_none() => { - storage_version_found = Some(storage_version); - } - attr => { - let msg = "Unexpected duplicated attribute"; - return Err(syn::Error::new(attr.span(), msg)); - } - } - } - - let pallet = syn::parse2::(item.ident.to_token_stream())?; - - if !matches!(item.vis, syn::Visibility::Public(_)) { - let msg = "Invalid pallet::pallet, Pallet must be public"; - return Err(syn::Error::new(item.span(), msg)); - } - - if item.generics.where_clause.is_some() { - let msg = "Invalid pallet::pallet, where clause not supported on Pallet declaration"; - return Err(syn::Error::new(item.generics.where_clause.span(), msg)); - } - - let instances = vec![helper::check_type_def_gen_no_bounds( - &item.generics, - item.ident.span(), - )?]; - - Ok(Self { - index, - instances, - pallet, - attr_span, - without_storage_info, - storage_version: storage_version_found, - }) - } -} diff --git a/support/procedural-fork/src/pallet/parse/storage.rs b/support/procedural-fork/src/pallet/parse/storage.rs deleted file mode 100644 index 00f0f6e141..0000000000 --- a/support/procedural-fork/src/pallet/parse/storage.rs +++ /dev/null @@ -1,1044 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use super::helper; -use frame_support_procedural_tools::get_doc_literals; -use quote::ToTokens; -use std::collections::HashMap; -use syn::spanned::Spanned; - -/// List of additional token to be used for parsing. -mod keyword { - syn::custom_keyword!(Error); - syn::custom_keyword!(pallet); - syn::custom_keyword!(getter); - syn::custom_keyword!(storage_prefix); - syn::custom_keyword!(unbounded); - syn::custom_keyword!(whitelist_storage); - syn::custom_keyword!(disable_try_decode_storage); - syn::custom_keyword!(OptionQuery); - syn::custom_keyword!(ResultQuery); - syn::custom_keyword!(ValueQuery); -} - -/// Parse for one of the following: -/// * `#[pallet::getter(fn dummy)]` -/// * `#[pallet::storage_prefix = "CustomName"]` -/// * `#[pallet::unbounded]` -/// * `#[pallet::whitelist_storage] -/// * `#[pallet::disable_try_decode_storage]` -pub enum PalletStorageAttr { - Getter(syn::Ident, proc_macro2::Span), - StorageName(syn::LitStr, proc_macro2::Span), - Unbounded(proc_macro2::Span), - WhitelistStorage(proc_macro2::Span), - DisableTryDecodeStorage(proc_macro2::Span), -} - -impl PalletStorageAttr { - fn attr_span(&self) -> proc_macro2::Span { - match self { - Self::Getter(_, span) - | Self::StorageName(_, span) - | Self::Unbounded(span) - | Self::WhitelistStorage(span) => *span, - Self::DisableTryDecodeStorage(span) => *span, - } - } -} - -impl syn::parse::Parse for PalletStorageAttr { - fn parse(input: syn::parse::ParseStream) -> syn::Result { - input.parse::()?; - let attr_span = input.span(); - let content; - syn::bracketed!(content in input); - content.parse::()?; - content.parse::()?; - - let lookahead = content.lookahead1(); - if lookahead.peek(keyword::getter) { - content.parse::()?; - - let generate_content; - syn::parenthesized!(generate_content in content); - generate_content.parse::()?; - Ok(Self::Getter( - generate_content.parse::()?, - attr_span, - )) - } else if lookahead.peek(keyword::storage_prefix) { - content.parse::()?; - content.parse::()?; - - let renamed_prefix = content.parse::()?; - // Ensure the renamed prefix is a proper Rust identifier - syn::parse_str::(&renamed_prefix.value()).map_err(|_| { - let msg = format!("`{}` is not a valid identifier", renamed_prefix.value()); - syn::Error::new(renamed_prefix.span(), msg) - })?; - - Ok(Self::StorageName(renamed_prefix, attr_span)) - } else if lookahead.peek(keyword::unbounded) { - content.parse::()?; - - Ok(Self::Unbounded(attr_span)) - } else if lookahead.peek(keyword::whitelist_storage) { - content.parse::()?; - Ok(Self::WhitelistStorage(attr_span)) - } else if lookahead.peek(keyword::disable_try_decode_storage) { - content.parse::()?; - Ok(Self::DisableTryDecodeStorage(attr_span)) - } else { - Err(lookahead.error()) - } - } -} - -struct PalletStorageAttrInfo { - getter: Option, - rename_as: Option, - unbounded: bool, - whitelisted: bool, - try_decode: bool, -} - -impl PalletStorageAttrInfo { - fn from_attrs(attrs: Vec) -> syn::Result { - let mut getter = None; - let mut rename_as = None; - let mut unbounded = false; - let mut whitelisted = false; - let mut disable_try_decode_storage = false; - for attr in attrs { - match attr { - PalletStorageAttr::Getter(ident, ..) if getter.is_none() => getter = Some(ident), - PalletStorageAttr::StorageName(name, ..) if rename_as.is_none() => { - rename_as = Some(name) - } - PalletStorageAttr::Unbounded(..) if !unbounded => unbounded = true, - PalletStorageAttr::WhitelistStorage(..) if !whitelisted => whitelisted = true, - PalletStorageAttr::DisableTryDecodeStorage(..) if !disable_try_decode_storage => { - disable_try_decode_storage = true - } - attr => { - return Err(syn::Error::new( - attr.attr_span(), - "Invalid attribute: Duplicate attribute", - )); - } - } - } - - Ok(PalletStorageAttrInfo { - getter, - rename_as, - unbounded, - whitelisted, - try_decode: !disable_try_decode_storage, - }) - } -} - -/// The value and key types used by storages. Needed to expand metadata. -pub enum Metadata { - Value { - value: syn::Type, - }, - Map { - value: syn::Type, - key: syn::Type, - }, - CountedMap { - value: syn::Type, - key: syn::Type, - }, - DoubleMap { - value: syn::Type, - key1: syn::Type, - key2: syn::Type, - }, - NMap { - keys: Vec, - keygen: syn::Type, - value: syn::Type, - }, - CountedNMap { - keys: Vec, - keygen: syn::Type, - value: syn::Type, - }, -} - -pub enum QueryKind { - OptionQuery, - ResultQuery(syn::Path, syn::Ident), - ValueQuery, -} - -/// Definition of a storage, storage is a storage type like -/// `type MyStorage = StorageValue` -/// The keys and values types are parsed in order to get metadata -pub struct StorageDef { - /// The index of storage item in pallet module. - pub index: usize, - /// Visibility of the storage type. - pub vis: syn::Visibility, - /// The type ident, to generate the StoragePrefix for. - pub ident: syn::Ident, - /// The keys and value metadata of the storage. - pub metadata: Metadata, - /// The doc associated to the storage. - pub docs: Vec, - /// A set of usage of instance, must be check for consistency with config. - pub instances: Vec, - /// Optional getter to generate. If some then query_kind is ensured to be some as well. - pub getter: Option, - /// Optional expression that evaluates to a type that can be used as StoragePrefix instead of - /// ident. - pub rename_as: Option, - /// Whereas the querytype of the storage is OptionQuery, ResultQuery or ValueQuery. - /// Note that this is best effort as it can't be determined when QueryKind is generic, and - /// result can be false if user do some unexpected type alias. - pub query_kind: Option, - /// Where clause of type definition. - pub where_clause: Option, - /// The span of the pallet::storage attribute. - pub attr_span: proc_macro2::Span, - /// The `cfg` attributes. - pub cfg_attrs: Vec, - /// If generics are named (e.g. `StorageValue`) then this contains all the - /// generics of the storage. - /// If generics are not named, this is none. - pub named_generics: Option, - /// If the value stored in this storage is unbounded. - pub unbounded: bool, - /// Whether or not reads to this storage key will be ignored by benchmarking - pub whitelisted: bool, - /// Whether or not to try to decode the storage key when running try-runtime checks. - pub try_decode: bool, - /// Whether or not a default hasher is allowed to replace `_` - pub use_default_hasher: bool, -} - -/// The parsed generic from the -#[derive(Clone)] -pub enum StorageGenerics { - DoubleMap { - hasher1: syn::Type, - key1: syn::Type, - hasher2: syn::Type, - key2: syn::Type, - value: syn::Type, - query_kind: Option, - on_empty: Option, - max_values: Option, - }, - Map { - hasher: syn::Type, - key: syn::Type, - value: syn::Type, - query_kind: Option, - on_empty: Option, - max_values: Option, - }, - CountedMap { - hasher: syn::Type, - key: syn::Type, - value: syn::Type, - query_kind: Option, - on_empty: Option, - max_values: Option, - }, - Value { - value: syn::Type, - query_kind: Option, - on_empty: Option, - }, - NMap { - keygen: syn::Type, - value: syn::Type, - query_kind: Option, - on_empty: Option, - max_values: Option, - }, - CountedNMap { - keygen: syn::Type, - value: syn::Type, - query_kind: Option, - on_empty: Option, - max_values: Option, - }, -} - -impl StorageGenerics { - /// Return the metadata from the defined generics - fn metadata(&self) -> syn::Result { - let res = match self.clone() { - Self::DoubleMap { - value, key1, key2, .. - } => Metadata::DoubleMap { value, key1, key2 }, - Self::Map { value, key, .. } => Metadata::Map { value, key }, - Self::CountedMap { value, key, .. } => Metadata::CountedMap { value, key }, - Self::Value { value, .. } => Metadata::Value { value }, - Self::NMap { keygen, value, .. } => Metadata::NMap { - keys: collect_keys(&keygen)?, - keygen, - value, - }, - Self::CountedNMap { keygen, value, .. } => Metadata::CountedNMap { - keys: collect_keys(&keygen)?, - keygen, - value, - }, - }; - - Ok(res) - } - - /// Return the query kind from the defined generics - fn query_kind(&self) -> Option { - match &self { - Self::DoubleMap { query_kind, .. } - | Self::Map { query_kind, .. } - | Self::CountedMap { query_kind, .. } - | Self::Value { query_kind, .. } - | Self::NMap { query_kind, .. } - | Self::CountedNMap { query_kind, .. } => query_kind.clone(), - } - } -} - -enum StorageKind { - Value, - Map, - CountedMap, - DoubleMap, - NMap, - CountedNMap, -} - -/// Check the generics in the `map` contains the generics in `gen` may contains generics in -/// `optional_gen`, and doesn't contains any other. -fn check_generics( - map: &HashMap, - mandatory_generics: &[&str], - optional_generics: &[&str], - storage_type_name: &str, - args_span: proc_macro2::Span, -) -> syn::Result<()> { - let mut errors = vec![]; - - let expectation = { - let mut e = format!( - "`{}` expect generics {}and optional generics {}", - storage_type_name, - mandatory_generics - .iter() - .map(|name| format!("`{}`, ", name)) - .collect::(), - &optional_generics - .iter() - .map(|name| format!("`{}`, ", name)) - .collect::(), - ); - e.pop(); - e.pop(); - e.push('.'); - e - }; - - for (gen_name, gen_binding) in map { - if !mandatory_generics.contains(&gen_name.as_str()) - && !optional_generics.contains(&gen_name.as_str()) - { - let msg = format!( - "Invalid pallet::storage, Unexpected generic `{}` for `{}`. {}", - gen_name, storage_type_name, expectation, - ); - errors.push(syn::Error::new(gen_binding.span(), msg)); - } - } - - for mandatory_generic in mandatory_generics { - if !map.contains_key(&mandatory_generic.to_string()) { - let msg = format!( - "Invalid pallet::storage, cannot find `{}` generic, required for `{}`.", - mandatory_generic, storage_type_name - ); - errors.push(syn::Error::new(args_span, msg)); - } - } - - let mut errors = errors.drain(..); - if let Some(mut error) = errors.next() { - for other_error in errors { - error.combine(other_error); - } - Err(error) - } else { - Ok(()) - } -} - -/// Returns `(named generics, metadata, query kind, use_default_hasher)` -fn process_named_generics( - storage: &StorageKind, - args_span: proc_macro2::Span, - args: &[syn::AssocType], - dev_mode: bool, -) -> syn::Result<(Option, Metadata, Option, bool)> { - let mut parsed = HashMap::::new(); - - // Ensure no duplicate. - for arg in args { - if let Some(other) = parsed.get(&arg.ident.to_string()) { - let msg = "Invalid pallet::storage, Duplicated named generic"; - let mut err = syn::Error::new(arg.ident.span(), msg); - err.combine(syn::Error::new(other.ident.span(), msg)); - return Err(err); - } - parsed.insert(arg.ident.to_string(), arg.clone()); - } - - let mut map_mandatory_generics = vec!["Key", "Value"]; - let mut map_optional_generics = vec!["QueryKind", "OnEmpty", "MaxValues"]; - if dev_mode { - map_optional_generics.push("Hasher"); - } else { - map_mandatory_generics.push("Hasher"); - } - - let generics = match storage { - StorageKind::Value => { - check_generics( - &parsed, - &["Value"], - &["QueryKind", "OnEmpty"], - "StorageValue", - args_span, - )?; - - StorageGenerics::Value { - value: parsed - .remove("Value") - .map(|binding| binding.ty) - .expect("checked above as mandatory generic"), - query_kind: parsed.remove("QueryKind").map(|binding| binding.ty), - on_empty: parsed.remove("OnEmpty").map(|binding| binding.ty), - } - } - StorageKind::Map => { - check_generics( - &parsed, - &map_mandatory_generics, - &map_optional_generics, - "StorageMap", - args_span, - )?; - - StorageGenerics::Map { - hasher: parsed - .remove("Hasher") - .map(|binding| binding.ty) - .unwrap_or(syn::parse_quote!(Blake2_128Concat)), - key: parsed - .remove("Key") - .map(|binding| binding.ty) - .expect("checked above as mandatory generic"), - value: parsed - .remove("Value") - .map(|binding| binding.ty) - .expect("checked above as mandatory generic"), - query_kind: parsed.remove("QueryKind").map(|binding| binding.ty), - on_empty: parsed.remove("OnEmpty").map(|binding| binding.ty), - max_values: parsed.remove("MaxValues").map(|binding| binding.ty), - } - } - StorageKind::CountedMap => { - check_generics( - &parsed, - &map_mandatory_generics, - &map_optional_generics, - "CountedStorageMap", - args_span, - )?; - - StorageGenerics::CountedMap { - hasher: parsed - .remove("Hasher") - .map(|binding| binding.ty) - .unwrap_or(syn::Type::Verbatim(quote::quote! { Blake2_128Concat })), - key: parsed - .remove("Key") - .map(|binding| binding.ty) - .expect("checked above as mandatory generic"), - value: parsed - .remove("Value") - .map(|binding| binding.ty) - .expect("checked above as mandatory generic"), - query_kind: parsed.remove("QueryKind").map(|binding| binding.ty), - on_empty: parsed.remove("OnEmpty").map(|binding| binding.ty), - max_values: parsed.remove("MaxValues").map(|binding| binding.ty), - } - } - StorageKind::DoubleMap => { - let mut double_map_mandatory_generics = vec!["Key1", "Key2", "Value"]; - if dev_mode { - map_optional_generics.extend(["Hasher1", "Hasher2"]); - } else { - double_map_mandatory_generics.extend(["Hasher1", "Hasher2"]); - } - - check_generics( - &parsed, - &double_map_mandatory_generics, - &map_optional_generics, - "StorageDoubleMap", - args_span, - )?; - - StorageGenerics::DoubleMap { - hasher1: parsed - .remove("Hasher1") - .map(|binding| binding.ty) - .unwrap_or(syn::parse_quote!(Blake2_128Concat)), - key1: parsed - .remove("Key1") - .map(|binding| binding.ty) - .expect("checked above as mandatory generic"), - hasher2: parsed - .remove("Hasher2") - .map(|binding| binding.ty) - .unwrap_or(syn::parse_quote!(Blake2_128Concat)), - key2: parsed - .remove("Key2") - .map(|binding| binding.ty) - .expect("checked above as mandatory generic"), - value: parsed - .remove("Value") - .map(|binding| binding.ty) - .expect("checked above as mandatory generic"), - query_kind: parsed.remove("QueryKind").map(|binding| binding.ty), - on_empty: parsed.remove("OnEmpty").map(|binding| binding.ty), - max_values: parsed.remove("MaxValues").map(|binding| binding.ty), - } - } - StorageKind::NMap => { - check_generics( - &parsed, - &["Key", "Value"], - &["QueryKind", "OnEmpty", "MaxValues"], - "StorageNMap", - args_span, - )?; - - StorageGenerics::NMap { - keygen: parsed - .remove("Key") - .map(|binding| binding.ty) - .expect("checked above as mandatory generic"), - value: parsed - .remove("Value") - .map(|binding| binding.ty) - .expect("checked above as mandatory generic"), - query_kind: parsed.remove("QueryKind").map(|binding| binding.ty), - on_empty: parsed.remove("OnEmpty").map(|binding| binding.ty), - max_values: parsed.remove("MaxValues").map(|binding| binding.ty), - } - } - StorageKind::CountedNMap => { - check_generics( - &parsed, - &["Key", "Value"], - &["QueryKind", "OnEmpty", "MaxValues"], - "CountedStorageNMap", - args_span, - )?; - - StorageGenerics::CountedNMap { - keygen: parsed - .remove("Key") - .map(|binding| binding.ty) - .expect("checked above as mandatory generic"), - value: parsed - .remove("Value") - .map(|binding| binding.ty) - .expect("checked above as mandatory generic"), - query_kind: parsed.remove("QueryKind").map(|binding| binding.ty), - on_empty: parsed.remove("OnEmpty").map(|binding| binding.ty), - max_values: parsed.remove("MaxValues").map(|binding| binding.ty), - } - } - }; - - let metadata = generics.metadata()?; - let query_kind = generics.query_kind(); - - Ok((Some(generics), metadata, query_kind, false)) -} - -/// Returns `(named generics, metadata, query kind, use_default_hasher)` -fn process_unnamed_generics( - storage: &StorageKind, - args_span: proc_macro2::Span, - args: &[syn::Type], - dev_mode: bool, -) -> syn::Result<(Option, Metadata, Option, bool)> { - let retrieve_arg = |arg_pos| { - args.get(arg_pos).cloned().ok_or_else(|| { - let msg = format!( - "Invalid pallet::storage, unexpected number of generic argument, \ - expect at least {} args, found {}.", - arg_pos + 1, - args.len(), - ); - syn::Error::new(args_span, msg) - }) - }; - - let prefix_arg = retrieve_arg(0)?; - syn::parse2::(prefix_arg.to_token_stream()).map_err(|e| { - let msg = "Invalid pallet::storage, for unnamed generic arguments the type \ - first generic argument must be `_`, the argument is then replaced by macro."; - let mut err = syn::Error::new(prefix_arg.span(), msg); - err.combine(e); - err - })?; - - let use_default_hasher = |arg_pos| { - let arg = retrieve_arg(arg_pos)?; - if syn::parse2::(arg.to_token_stream()).is_ok() { - if dev_mode { - Ok(true) - } else { - let msg = "`_` can only be used in dev_mode. Please specify an appropriate hasher."; - Err(syn::Error::new(arg.span(), msg)) - } - } else { - Ok(false) - } - }; - - let res = match storage { - StorageKind::Value => ( - None, - Metadata::Value { - value: retrieve_arg(1)?, - }, - retrieve_arg(2).ok(), - false, - ), - StorageKind::Map => ( - None, - Metadata::Map { - key: retrieve_arg(2)?, - value: retrieve_arg(3)?, - }, - retrieve_arg(4).ok(), - use_default_hasher(1)?, - ), - StorageKind::CountedMap => ( - None, - Metadata::CountedMap { - key: retrieve_arg(2)?, - value: retrieve_arg(3)?, - }, - retrieve_arg(4).ok(), - use_default_hasher(1)?, - ), - StorageKind::DoubleMap => ( - None, - Metadata::DoubleMap { - key1: retrieve_arg(2)?, - key2: retrieve_arg(4)?, - value: retrieve_arg(5)?, - }, - retrieve_arg(6).ok(), - use_default_hasher(1)? && use_default_hasher(3)?, - ), - StorageKind::NMap => { - let keygen = retrieve_arg(1)?; - let keys = collect_keys(&keygen)?; - ( - None, - Metadata::NMap { - keys, - keygen, - value: retrieve_arg(2)?, - }, - retrieve_arg(3).ok(), - false, - ) - } - StorageKind::CountedNMap => { - let keygen = retrieve_arg(1)?; - let keys = collect_keys(&keygen)?; - ( - None, - Metadata::CountedNMap { - keys, - keygen, - value: retrieve_arg(2)?, - }, - retrieve_arg(3).ok(), - false, - ) - } - }; - - Ok(res) -} - -/// Returns `(named generics, metadata, query kind, use_default_hasher)` -fn process_generics( - segment: &syn::PathSegment, - dev_mode: bool, -) -> syn::Result<(Option, Metadata, Option, bool)> { - let storage_kind = match &*segment.ident.to_string() { - "StorageValue" => StorageKind::Value, - "StorageMap" => StorageKind::Map, - "CountedStorageMap" => StorageKind::CountedMap, - "StorageDoubleMap" => StorageKind::DoubleMap, - "StorageNMap" => StorageKind::NMap, - "CountedStorageNMap" => StorageKind::CountedNMap, - found => { - let msg = format!( - "Invalid pallet::storage, expected ident: `StorageValue` or \ - `StorageMap` or `CountedStorageMap` or `StorageDoubleMap` or `StorageNMap` or `CountedStorageNMap` \ - in order to expand metadata, found `{}`.", - found, - ); - return Err(syn::Error::new(segment.ident.span(), msg)); - } - }; - - let args_span = segment.arguments.span(); - - let args = match &segment.arguments { - syn::PathArguments::AngleBracketed(args) if !args.args.is_empty() => args, - _ => { - let msg = "Invalid pallet::storage, invalid number of generic generic arguments, \ - expect more that 0 generic arguments."; - return Err(syn::Error::new(segment.span(), msg)); - } - }; - - if args - .args - .iter() - .all(|r#gen| matches!(r#gen, syn::GenericArgument::Type(_))) - { - let args = args - .args - .iter() - .map(|r#gen| match r#gen { - syn::GenericArgument::Type(r#gen) => r#gen.clone(), - _ => unreachable!("It is asserted above that all generics are types"), - }) - .collect::>(); - process_unnamed_generics(&storage_kind, args_span, &args, dev_mode) - } else if args - .args - .iter() - .all(|r#gen| matches!(r#gen, syn::GenericArgument::AssocType(_))) - { - let args = args - .args - .iter() - .map(|r#gen| match r#gen { - syn::GenericArgument::AssocType(r#gen) => r#gen.clone(), - _ => unreachable!("It is asserted above that all generics are bindings"), - }) - .collect::>(); - process_named_generics(&storage_kind, args_span, &args, dev_mode) - } else { - let msg = "Invalid pallet::storage, invalid generic declaration for storage. Expect only \ - type generics or binding generics, e.g. `` or \ - ``."; - Err(syn::Error::new(segment.span(), msg)) - } -} - -/// Parse the 2nd type argument to `StorageNMap` and return its keys. -fn collect_keys(keygen: &syn::Type) -> syn::Result> { - if let syn::Type::Tuple(tup) = keygen { - tup.elems - .iter() - .map(extract_key) - .collect::>>() - } else { - Ok(vec![extract_key(keygen)?]) - } -} - -/// In `Key`, extract K and return it. -fn extract_key(ty: &syn::Type) -> syn::Result { - let typ = if let syn::Type::Path(typ) = ty { - typ - } else { - let msg = "Invalid pallet::storage, expected type path"; - return Err(syn::Error::new(ty.span(), msg)); - }; - - let key_struct = typ.path.segments.last().ok_or_else(|| { - let msg = "Invalid pallet::storage, expected type path with at least one segment"; - syn::Error::new(typ.path.span(), msg) - })?; - if key_struct.ident != "Key" && key_struct.ident != "NMapKey" { - let msg = "Invalid pallet::storage, expected Key or NMapKey struct"; - return Err(syn::Error::new(key_struct.ident.span(), msg)); - } - - let ty_params = if let syn::PathArguments::AngleBracketed(args) = &key_struct.arguments { - args - } else { - let msg = "Invalid pallet::storage, expected angle bracketed arguments"; - return Err(syn::Error::new(key_struct.arguments.span(), msg)); - }; - - if ty_params.args.len() != 2 { - let msg = format!( - "Invalid pallet::storage, unexpected number of generic arguments \ - for Key struct, expected 2 args, found {}", - ty_params.args.len() - ); - return Err(syn::Error::new(ty_params.span(), msg)); - } - - let key = match &ty_params.args[1] { - syn::GenericArgument::Type(key_ty) => key_ty.clone(), - _ => { - let msg = "Invalid pallet::storage, expected type"; - return Err(syn::Error::new(ty_params.args[1].span(), msg)); - } - }; - - Ok(key) -} - -impl StorageDef { - /// Return the storage prefix for this storage item - pub fn prefix(&self) -> String { - self.rename_as - .as_ref() - .map(syn::LitStr::value) - .unwrap_or_else(|| self.ident.to_string()) - } - - /// Return either the span of the ident or the span of the literal in the - /// #[storage_prefix] attribute - pub fn prefix_span(&self) -> proc_macro2::Span { - self.rename_as - .as_ref() - .map(syn::LitStr::span) - .unwrap_or_else(|| self.ident.span()) - } - - pub fn try_from( - attr_span: proc_macro2::Span, - index: usize, - item: &mut syn::Item, - dev_mode: bool, - ) -> syn::Result { - let item = if let syn::Item::Type(item) = item { - item - } else { - return Err(syn::Error::new( - item.span(), - "Invalid pallet::storage, expect item type.", - )); - }; - - let attrs: Vec = helper::take_item_pallet_attrs(&mut item.attrs)?; - let PalletStorageAttrInfo { - getter, - rename_as, - mut unbounded, - whitelisted, - try_decode, - } = PalletStorageAttrInfo::from_attrs(attrs)?; - - // set all storages to be unbounded if dev_mode is enabled - unbounded |= dev_mode; - let cfg_attrs = helper::get_item_cfg_attrs(&item.attrs); - - let instances = vec![helper::check_type_def_gen( - &item.generics, - item.ident.span(), - )?]; - - let where_clause = item.generics.where_clause.clone(); - let docs = get_doc_literals(&item.attrs); - - let typ = if let syn::Type::Path(typ) = &*item.ty { - typ - } else { - let msg = "Invalid pallet::storage, expected type path"; - return Err(syn::Error::new(item.ty.span(), msg)); - }; - - if typ.path.segments.len() != 1 { - let msg = "Invalid pallet::storage, expected type path with one segment"; - return Err(syn::Error::new(item.ty.span(), msg)); - } - - let (named_generics, metadata, query_kind, use_default_hasher) = - process_generics(&typ.path.segments[0], dev_mode)?; - - let query_kind = query_kind - .map(|query_kind| { - use syn::{ - AngleBracketedGenericArguments, GenericArgument, Path, PathArguments, Type, - TypePath, - }; - - let result_query = match query_kind { - Type::Path(path) - if path - .path - .segments - .last() - .map_or(false, |s| s.ident == "OptionQuery") => - { - return Ok(Some(QueryKind::OptionQuery)); - } - Type::Path(TypePath { - path: Path { segments, .. }, - .. - }) if segments.last().map_or(false, |s| s.ident == "ResultQuery") => segments - .last() - .expect("segments is checked to have the last value; qed") - .clone(), - Type::Path(path) - if path - .path - .segments - .last() - .map_or(false, |s| s.ident == "ValueQuery") => - { - return Ok(Some(QueryKind::ValueQuery)); - } - _ => return Ok(None), - }; - - let error_type = match result_query.arguments { - PathArguments::AngleBracketed(AngleBracketedGenericArguments { - args, .. - }) => { - if args.len() != 1 { - let msg = format!( - "Invalid pallet::storage, unexpected number of generic arguments \ - for ResultQuery, expected 1 type argument, found {}", - args.len(), - ); - return Err(syn::Error::new(args.span(), msg)); - } - - args[0].clone() - } - args => { - let msg = format!( - "Invalid pallet::storage, unexpected generic args for ResultQuery, \ - expected angle-bracketed arguments, found `{}`", - args.to_token_stream().to_string() - ); - return Err(syn::Error::new(args.span(), msg)); - } - }; - - match error_type { - GenericArgument::Type(Type::Path(TypePath { - path: - Path { - segments: err_variant, - leading_colon, - }, - .. - })) => { - if err_variant.len() < 2 { - let msg = format!( - "Invalid pallet::storage, unexpected number of path segments for \ - the generics in ResultQuery, expected a path with at least 2 \ - segments, found {}", - err_variant.len(), - ); - return Err(syn::Error::new(err_variant.span(), msg)); - } - let mut error = err_variant.clone(); - let err_variant = error - .pop() - .expect("Checked to have at least 2; qed") - .into_value() - .ident; - - // Necessary here to eliminate the last double colon - let last = error - .pop() - .expect("Checked to have at least 2; qed") - .into_value(); - error.push_value(last); - - Ok(Some(QueryKind::ResultQuery( - syn::Path { - leading_colon, - segments: error, - }, - err_variant, - ))) - } - gen_arg => { - let msg = format!( - "Invalid pallet::storage, unexpected generic argument kind, expected a \ - type path to a `PalletError` enum variant, found `{}`", - gen_arg.to_token_stream().to_string(), - ); - Err(syn::Error::new(gen_arg.span(), msg)) - } - } - }) - .transpose()? - .unwrap_or(Some(QueryKind::OptionQuery)); - - if let (None, Some(getter)) = (query_kind.as_ref(), getter.as_ref()) { - let msg = "Invalid pallet::storage, cannot generate getter because QueryKind is not \ - identifiable. QueryKind must be `OptionQuery`, `ResultQuery`, `ValueQuery`, or default \ - one to be identifiable."; - return Err(syn::Error::new(getter.span(), msg)); - } - - Ok(StorageDef { - attr_span, - index, - vis: item.vis.clone(), - ident: item.ident.clone(), - instances, - metadata, - docs, - getter, - rename_as, - query_kind, - where_clause, - cfg_attrs, - named_generics, - unbounded, - whitelisted, - try_decode, - use_default_hasher, - }) - } -} diff --git a/support/procedural-fork/src/pallet/parse/tasks.rs b/support/procedural-fork/src/pallet/parse/tasks.rs deleted file mode 100644 index 8da1fa8823..0000000000 --- a/support/procedural-fork/src/pallet/parse/tasks.rs +++ /dev/null @@ -1,1003 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//! Home of the parsing code for the Tasks API - -use std::collections::HashSet; - -#[cfg(test)] -use crate::assert_parse_error_matches; - -#[cfg(test)] -use crate::pallet::parse::tests::simulate_manifest_dir; - -use derive_syn_parse::Parse; -use frame_support_procedural_tools::generate_access_from_frame_or_crate; -use proc_macro2::TokenStream as TokenStream2; -use quote::{ToTokens, quote}; -use syn::{ - Error, Expr, Ident, ImplItem, ImplItemFn, ItemEnum, ItemImpl, LitInt, Path, PathArguments, - Result, TypePath, - parse::ParseStream, - parse2, - spanned::Spanned, - token::{Bracket, Paren, PathSep, Pound}, -}; - -pub mod keywords { - use syn::custom_keyword; - - custom_keyword!(tasks_experimental); - custom_keyword!(task_enum); - custom_keyword!(task_list); - custom_keyword!(task_condition); - custom_keyword!(task_index); - custom_keyword!(task_weight); - custom_keyword!(pallet); -} - -/// Represents the `#[pallet::tasks_experimental]` attribute and its attached item. Also includes -/// metadata about the linked [`TaskEnumDef`] if applicable. -#[derive(Clone, Debug)] -pub struct TasksDef { - pub tasks_attr: Option, - pub tasks: Vec, - pub item_impl: ItemImpl, - /// Path to `frame_support` - pub scrate: Path, - pub enum_ident: Ident, - pub enum_arguments: PathArguments, -} - -impl syn::parse::Parse for TasksDef { - fn parse(input: ParseStream) -> Result { - let item_impl: ItemImpl = input.parse()?; - let (tasks_attrs, normal_attrs) = partition_tasks_attrs(&item_impl); - let tasks_attr = match tasks_attrs.first() { - Some(attr) => Some(parse2::(attr.to_token_stream())?), - None => None, - }; - if let Some(extra_tasks_attr) = tasks_attrs.get(1) { - return Err(Error::new( - extra_tasks_attr.span(), - "unexpected extra `#[pallet::tasks_experimental]` attribute", - )); - } - let tasks: Vec = if tasks_attr.is_some() { - item_impl - .items - .clone() - .into_iter() - .filter(|impl_item| matches!(impl_item, ImplItem::Fn(_))) - .map(|item| parse2::(item.to_token_stream())) - .collect::>()? - } else { - Vec::new() - }; - let mut task_indices = HashSet::::new(); - for task in tasks.iter() { - let task_index = &task.index_attr.meta.index; - if !task_indices.insert(task_index.clone()) { - return Err(Error::new( - task_index.span(), - format!("duplicate task index `{}`", task_index), - )); - } - } - let mut item_impl = item_impl; - item_impl.attrs = normal_attrs; - - // we require the path on the impl to be a TypePath - let enum_path = parse2::(item_impl.self_ty.to_token_stream())?; - let segments = enum_path.path.segments.iter().collect::>(); - let (Some(last_seg), None) = (segments.get(0), segments.get(1)) else { - return Err(Error::new( - enum_path.span(), - "if specified manually, the task enum must be defined locally in this \ - pallet and cannot be a re-export", - )); - }; - let enum_ident = last_seg.ident.clone(); - let enum_arguments = last_seg.arguments.clone(); - - // We do this here because it would be improper to do something fallible like this at - // the expansion phase. Fallible stuff should happen during parsing. - let scrate = generate_access_from_frame_or_crate("frame-support")?; - - Ok(TasksDef { - tasks_attr, - item_impl, - tasks, - scrate, - enum_ident, - enum_arguments, - }) - } -} - -/// Parsing for a `#[pallet::tasks_experimental]` attr. -pub type PalletTasksAttr = PalletTaskAttr; - -/// Parsing for any of the attributes that can be used within a `#[pallet::tasks_experimental]` -/// [`ItemImpl`]. -pub type TaskAttr = PalletTaskAttr; - -/// Parsing for a `#[pallet::task_index]` attr. -pub type TaskIndexAttr = PalletTaskAttr; - -/// Parsing for a `#[pallet::task_condition]` attr. -pub type TaskConditionAttr = PalletTaskAttr; - -/// Parsing for a `#[pallet::task_list]` attr. -pub type TaskListAttr = PalletTaskAttr; - -/// Parsing for a `#[pallet::task_weight]` attr. -pub type TaskWeightAttr = PalletTaskAttr; - -/// Parsing for a `#[pallet:task_enum]` attr. -pub type PalletTaskEnumAttr = PalletTaskAttr; - -/// Parsing for a manually-specified (or auto-generated) task enum, optionally including the -/// attached `#[pallet::task_enum]` attribute. -#[derive(Clone, Debug)] -pub struct TaskEnumDef { - pub attr: Option, - pub item_enum: ItemEnum, - pub scrate: Path, - pub type_use_generics: TokenStream2, -} - -impl syn::parse::Parse for TaskEnumDef { - fn parse(input: ParseStream) -> Result { - let mut item_enum = input.parse::()?; - let attr = extract_pallet_attr(&mut item_enum)?; - let attr = match attr { - Some(attr) => Some(parse2(attr)?), - None => None, - }; - - // We do this here because it would be improper to do something fallible like this at - // the expansion phase. Fallible stuff should happen during parsing. - let scrate = generate_access_from_frame_or_crate("frame-support")?; - - let type_use_generics = quote!(T); - - Ok(TaskEnumDef { - attr, - item_enum, - scrate, - type_use_generics, - }) - } -} - -/// Represents an individual tasks within a [`TasksDef`]. -#[derive(Debug, Clone)] -pub struct TaskDef { - pub index_attr: TaskIndexAttr, - pub condition_attr: TaskConditionAttr, - pub list_attr: TaskListAttr, - pub weight_attr: TaskWeightAttr, - pub item: ImplItemFn, - pub arg_names: Vec, -} - -impl syn::parse::Parse for TaskDef { - fn parse(input: ParseStream) -> Result { - let item = input.parse::()?; - // we only want to activate TaskAttrType parsing errors for tasks-related attributes, - // so we filter them here - let task_attrs = partition_task_attrs(&item).0; - - let task_attrs: Vec = task_attrs - .into_iter() - .map(|attr| parse2(attr.to_token_stream())) - .collect::>()?; - - let Some(index_attr) = task_attrs - .iter() - .find(|attr| matches!(attr.meta, TaskAttrMeta::TaskIndex(_))) - .cloned() - else { - return Err(Error::new( - item.sig.ident.span(), - "missing `#[pallet::task_index(..)]` attribute", - )); - }; - - let Some(condition_attr) = task_attrs - .iter() - .find(|attr| matches!(attr.meta, TaskAttrMeta::TaskCondition(_))) - .cloned() - else { - return Err(Error::new( - item.sig.ident.span(), - "missing `#[pallet::task_condition(..)]` attribute", - )); - }; - - let Some(list_attr) = task_attrs - .iter() - .find(|attr| matches!(attr.meta, TaskAttrMeta::TaskList(_))) - .cloned() - else { - return Err(Error::new( - item.sig.ident.span(), - "missing `#[pallet::task_list(..)]` attribute", - )); - }; - - let Some(weight_attr) = task_attrs - .iter() - .find(|attr| matches!(attr.meta, TaskAttrMeta::TaskWeight(_))) - .cloned() - else { - return Err(Error::new( - item.sig.ident.span(), - "missing `#[pallet::task_weight(..)]` attribute", - )); - }; - - if let Some(duplicate) = task_attrs - .iter() - .filter(|attr| matches!(attr.meta, TaskAttrMeta::TaskCondition(_))) - .collect::>() - .get(1) - { - return Err(Error::new( - duplicate.span(), - "unexpected extra `#[pallet::task_condition(..)]` attribute", - )); - } - - if let Some(duplicate) = task_attrs - .iter() - .filter(|attr| matches!(attr.meta, TaskAttrMeta::TaskList(_))) - .collect::>() - .get(1) - { - return Err(Error::new( - duplicate.span(), - "unexpected extra `#[pallet::task_list(..)]` attribute", - )); - } - - if let Some(duplicate) = task_attrs - .iter() - .filter(|attr| matches!(attr.meta, TaskAttrMeta::TaskIndex(_))) - .collect::>() - .get(1) - { - return Err(Error::new( - duplicate.span(), - "unexpected extra `#[pallet::task_index(..)]` attribute", - )); - } - - let mut arg_names = vec![]; - for input in item.sig.inputs.iter() { - match input { - syn::FnArg::Typed(pat_type) => match &*pat_type.pat { - syn::Pat::Ident(ident) => arg_names.push(ident.ident.clone()), - _ => return Err(Error::new(input.span(), "unexpected pattern type")), - }, - _ => { - return Err(Error::new( - input.span(), - "unexpected function argument type", - )); - } - } - } - - let index_attr = index_attr.try_into().expect("we check the type above; QED"); - let condition_attr = condition_attr - .try_into() - .expect("we check the type above; QED"); - let list_attr = list_attr.try_into().expect("we check the type above; QED"); - let weight_attr = weight_attr - .try_into() - .expect("we check the type above; QED"); - - Ok(TaskDef { - index_attr, - condition_attr, - list_attr, - weight_attr, - item, - arg_names, - }) - } -} - -/// The contents of a [`TasksDef`]-related attribute. -#[derive(Parse, Debug, Clone)] -pub enum TaskAttrMeta { - #[peek(keywords::task_list, name = "#[pallet::task_list(..)]")] - TaskList(TaskListAttrMeta), - #[peek(keywords::task_index, name = "#[pallet::task_index(..)")] - TaskIndex(TaskIndexAttrMeta), - #[peek(keywords::task_condition, name = "#[pallet::task_condition(..)")] - TaskCondition(TaskConditionAttrMeta), - #[peek(keywords::task_weight, name = "#[pallet::task_weight(..)")] - TaskWeight(TaskWeightAttrMeta), -} - -/// The contents of a `#[pallet::task_list]` attribute. -#[derive(Parse, Debug, Clone)] -pub struct TaskListAttrMeta { - pub task_list: keywords::task_list, - #[paren] - _paren: Paren, - #[inside(_paren)] - pub expr: Expr, -} - -/// The contents of a `#[pallet::task_index]` attribute. -#[derive(Parse, Debug, Clone)] -pub struct TaskIndexAttrMeta { - pub task_index: keywords::task_index, - #[paren] - _paren: Paren, - #[inside(_paren)] - pub index: LitInt, -} - -/// The contents of a `#[pallet::task_condition]` attribute. -#[derive(Parse, Debug, Clone)] -pub struct TaskConditionAttrMeta { - pub task_condition: keywords::task_condition, - #[paren] - _paren: Paren, - #[inside(_paren)] - pub expr: Expr, -} - -/// The contents of a `#[pallet::task_weight]` attribute. -#[derive(Parse, Debug, Clone)] -pub struct TaskWeightAttrMeta { - pub task_weight: keywords::task_weight, - #[paren] - _paren: Paren, - #[inside(_paren)] - pub expr: Expr, -} - -/// The contents of a `#[pallet::task]` attribute. -#[derive(Parse, Debug, Clone)] -pub struct PalletTaskAttr { - pub pound: Pound, - #[bracket] - _bracket: Bracket, - #[inside(_bracket)] - pub pallet: keywords::pallet, - #[inside(_bracket)] - pub colons: PathSep, - #[inside(_bracket)] - pub meta: T, -} - -impl ToTokens for TaskListAttrMeta { - fn to_tokens(&self, tokens: &mut TokenStream2) { - let task_list = self.task_list; - let expr = &self.expr; - tokens.extend(quote!(#task_list(#expr))); - } -} - -impl ToTokens for TaskConditionAttrMeta { - fn to_tokens(&self, tokens: &mut TokenStream2) { - let task_condition = self.task_condition; - let expr = &self.expr; - tokens.extend(quote!(#task_condition(#expr))); - } -} - -impl ToTokens for TaskWeightAttrMeta { - fn to_tokens(&self, tokens: &mut TokenStream2) { - let task_weight = self.task_weight; - let expr = &self.expr; - tokens.extend(quote!(#task_weight(#expr))); - } -} - -impl ToTokens for TaskIndexAttrMeta { - fn to_tokens(&self, tokens: &mut TokenStream2) { - let task_index = self.task_index; - let index = &self.index; - tokens.extend(quote!(#task_index(#index))) - } -} - -impl ToTokens for TaskAttrMeta { - fn to_tokens(&self, tokens: &mut TokenStream2) { - match self { - TaskAttrMeta::TaskList(list) => tokens.extend(list.to_token_stream()), - TaskAttrMeta::TaskIndex(index) => tokens.extend(index.to_token_stream()), - TaskAttrMeta::TaskCondition(condition) => tokens.extend(condition.to_token_stream()), - TaskAttrMeta::TaskWeight(weight) => tokens.extend(weight.to_token_stream()), - } - } -} - -impl ToTokens for PalletTaskAttr { - fn to_tokens(&self, tokens: &mut TokenStream2) { - let pound = self.pound; - let pallet = self.pallet; - let colons = self.colons; - let meta = &self.meta; - tokens.extend(quote!(#pound[#pallet #colons #meta])); - } -} - -impl TryFrom> for TaskIndexAttr { - type Error = syn::Error; - - fn try_from(value: PalletTaskAttr) -> Result { - let pound = value.pound; - let pallet = value.pallet; - let colons = value.colons; - match value.meta { - TaskAttrMeta::TaskIndex(meta) => parse2(quote!(#pound[#pallet #colons #meta])), - _ => { - return Err(Error::new( - value.span(), - format!( - "`{:?}` cannot be converted to a `TaskIndexAttr`", - value.meta - ), - )); - } - } - } -} - -impl TryFrom> for TaskConditionAttr { - type Error = syn::Error; - - fn try_from(value: PalletTaskAttr) -> Result { - let pound = value.pound; - let pallet = value.pallet; - let colons = value.colons; - match value.meta { - TaskAttrMeta::TaskCondition(meta) => parse2(quote!(#pound[#pallet #colons #meta])), - _ => { - return Err(Error::new( - value.span(), - format!( - "`{:?}` cannot be converted to a `TaskConditionAttr`", - value.meta - ), - )); - } - } - } -} - -impl TryFrom> for TaskWeightAttr { - type Error = syn::Error; - - fn try_from(value: PalletTaskAttr) -> Result { - let pound = value.pound; - let pallet = value.pallet; - let colons = value.colons; - match value.meta { - TaskAttrMeta::TaskWeight(meta) => parse2(quote!(#pound[#pallet #colons #meta])), - _ => { - return Err(Error::new( - value.span(), - format!( - "`{:?}` cannot be converted to a `TaskWeightAttr`", - value.meta - ), - )); - } - } - } -} - -impl TryFrom> for TaskListAttr { - type Error = syn::Error; - - fn try_from(value: PalletTaskAttr) -> Result { - let pound = value.pound; - let pallet = value.pallet; - let colons = value.colons; - match value.meta { - TaskAttrMeta::TaskList(meta) => parse2(quote!(#pound[#pallet #colons #meta])), - _ => { - return Err(Error::new( - value.span(), - format!("`{:?}` cannot be converted to a `TaskListAttr`", value.meta), - )); - } - } - } -} - -fn extract_pallet_attr(item_enum: &mut ItemEnum) -> Result> { - let mut duplicate = None; - let mut attr = None; - item_enum.attrs = item_enum - .attrs - .iter() - .filter(|found_attr| { - let segs = found_attr - .path() - .segments - .iter() - .map(|seg| seg.ident.clone()) - .collect::>(); - let (Some(seg1), Some(_), None) = (segs.get(0), segs.get(1), segs.get(2)) else { - return true; - }; - if seg1 != "pallet" { - return true; - } - if attr.is_some() { - duplicate = Some(found_attr.span()); - } - attr = Some(found_attr.to_token_stream()); - false - }) - .cloned() - .collect(); - if let Some(span) = duplicate { - return Err(Error::new( - span, - "only one `#[pallet::_]` attribute is supported on this item", - )); - } - Ok(attr) -} - -fn partition_tasks_attrs(item_impl: &ItemImpl) -> (Vec, Vec) { - item_impl.attrs.clone().into_iter().partition(|attr| { - let mut path_segs = attr.path().segments.iter(); - let (Some(prefix), Some(suffix), None) = - (path_segs.next(), path_segs.next(), path_segs.next()) - else { - return false; - }; - prefix.ident == "pallet" && suffix.ident == "tasks_experimental" - }) -} - -fn partition_task_attrs(item: &ImplItemFn) -> (Vec, Vec) { - item.attrs.clone().into_iter().partition(|attr| { - let mut path_segs = attr.path().segments.iter(); - let (Some(prefix), Some(suffix)) = (path_segs.next(), path_segs.next()) else { - return false; - }; - // N.B: the `PartialEq` impl between `Ident` and `&str` is more efficient than - // parsing and makes no stack or heap allocations - prefix.ident == "pallet" - && (suffix.ident == "tasks_experimental" - || suffix.ident == "task_list" - || suffix.ident == "task_condition" - || suffix.ident == "task_weight" - || suffix.ident == "task_index") - }) -} - -#[test] -fn test_parse_task_list_() { - parse2::(quote!(#[pallet::task_list(Something::iter())])).unwrap(); - parse2::(quote!(#[pallet::task_list(Numbers::::iter_keys())])).unwrap(); - parse2::(quote!(#[pallet::task_list(iter())])).unwrap(); - assert_parse_error_matches!( - parse2::(quote!(#[pallet::task_list()])), - "expected an expression" - ); - assert_parse_error_matches!( - parse2::(quote!(#[pallet::task_list])), - "expected parentheses" - ); -} - -#[test] -fn test_parse_task_index() { - parse2::(quote!(#[pallet::task_index(3)])).unwrap(); - parse2::(quote!(#[pallet::task_index(0)])).unwrap(); - parse2::(quote!(#[pallet::task_index(17)])).unwrap(); - assert_parse_error_matches!( - parse2::(quote!(#[pallet::task_index])), - "expected parentheses" - ); - assert_parse_error_matches!( - parse2::(quote!(#[pallet::task_index("hey")])), - "expected integer literal" - ); - assert_parse_error_matches!( - parse2::(quote!(#[pallet::task_index(0.3)])), - "expected integer literal" - ); -} - -#[test] -fn test_parse_task_condition() { - parse2::(quote!(#[pallet::task_condition(|x| x.is_some())])).unwrap(); - parse2::(quote!(#[pallet::task_condition(|_x| some_expr())])).unwrap(); - parse2::(quote!(#[pallet::task_condition(|| some_expr())])).unwrap(); - parse2::(quote!(#[pallet::task_condition(some_expr())])).unwrap(); -} - -#[test] -fn test_parse_tasks_attr() { - parse2::(quote!(#[pallet::tasks_experimental])).unwrap(); - assert_parse_error_matches!( - parse2::(quote!(#[pallet::taskss])), - "expected `tasks_experimental`" - ); - assert_parse_error_matches!( - parse2::(quote!(#[pallet::tasks_])), - "expected `tasks_experimental`" - ); - assert_parse_error_matches!( - parse2::(quote!(#[pal::tasks])), - "expected `pallet`" - ); - assert_parse_error_matches!( - parse2::(quote!(#[pallet::tasks_experimental()])), - "unexpected token" - ); -} - -#[test] -fn test_parse_tasks_def_basic() { - simulate_manifest_dir("../../examples/basic", || { - let parsed = parse2::(quote! { - #[pallet::tasks_experimental] - impl, I: 'static> Pallet { - /// Add a pair of numbers into the totals and remove them. - #[pallet::task_list(Numbers::::iter_keys())] - #[pallet::task_condition(|i| Numbers::::contains_key(i))] - #[pallet::task_index(0)] - #[pallet::task_weight(0)] - pub fn add_number_into_total(i: u32) -> DispatchResult { - let v = Numbers::::take(i).ok_or(Error::::NotFound)?; - Total::::mutate(|(total_keys, total_values)| { - *total_keys += i; - *total_values += v; - }); - Ok(()) - } - } - }) - .unwrap(); - assert_eq!(parsed.tasks.len(), 1); - }); -} - -#[test] -fn test_parse_tasks_def_basic_increment_decrement() { - simulate_manifest_dir("../../examples/basic", || { - let parsed = parse2::(quote! { - #[pallet::tasks_experimental] - impl, I: 'static> Pallet { - /// Get the value and check if it can be incremented - #[pallet::task_index(0)] - #[pallet::task_condition(|| { - let value = Value::::get().unwrap(); - value < 255 - })] - #[pallet::task_list(Vec::>::new())] - #[pallet::task_weight(0)] - fn increment() -> DispatchResult { - let value = Value::::get().unwrap_or_default(); - if value >= 255 { - Err(Error::::ValueOverflow.into()) - } else { - let new_val = value.checked_add(1).ok_or(Error::::ValueOverflow)?; - Value::::put(new_val); - Pallet::::deposit_event(Event::Incremented { new_val }); - Ok(()) - } - } - - // Get the value and check if it can be decremented - #[pallet::task_index(1)] - #[pallet::task_condition(|| { - let value = Value::::get().unwrap(); - value > 0 - })] - #[pallet::task_list(Vec::>::new())] - #[pallet::task_weight(0)] - fn decrement() -> DispatchResult { - let value = Value::::get().unwrap_or_default(); - if value == 0 { - Err(Error::::ValueUnderflow.into()) - } else { - let new_val = value.checked_sub(1).ok_or(Error::::ValueUnderflow)?; - Value::::put(new_val); - Pallet::::deposit_event(Event::Decremented { new_val }); - Ok(()) - } - } - } - }) - .unwrap(); - assert_eq!(parsed.tasks.len(), 2); - }); -} - -#[test] -fn test_parse_tasks_def_duplicate_index() { - simulate_manifest_dir("../../examples/basic", || { - assert_parse_error_matches!( - parse2::(quote! { - #[pallet::tasks_experimental] - impl, I: 'static> Pallet { - #[pallet::task_list(Something::iter())] - #[pallet::task_condition(|i| i % 2 == 0)] - #[pallet::task_index(0)] - #[pallet::task_weight(0)] - pub fn foo(i: u32) -> DispatchResult { - Ok(()) - } - - #[pallet::task_list(Numbers::::iter_keys())] - #[pallet::task_condition(|i| Numbers::::contains_key(i))] - #[pallet::task_index(0)] - #[pallet::task_weight(0)] - pub fn bar(i: u32) -> DispatchResult { - Ok(()) - } - } - }), - "duplicate task index `0`" - ); - }); -} - -#[test] -fn test_parse_tasks_def_missing_task_list() { - simulate_manifest_dir("../../examples/basic", || { - assert_parse_error_matches!( - parse2::(quote! { - #[pallet::tasks_experimental] - impl, I: 'static> Pallet { - #[pallet::task_condition(|i| i % 2 == 0)] - #[pallet::task_index(0)] - pub fn foo(i: u32) -> DispatchResult { - Ok(()) - } - } - }), - r"missing `#\[pallet::task_list\(\.\.\)\]`" - ); - }); -} - -#[test] -fn test_parse_tasks_def_missing_task_condition() { - simulate_manifest_dir("../../examples/basic", || { - assert_parse_error_matches!( - parse2::(quote! { - #[pallet::tasks_experimental] - impl, I: 'static> Pallet { - #[pallet::task_list(Something::iter())] - #[pallet::task_index(0)] - pub fn foo(i: u32) -> DispatchResult { - Ok(()) - } - } - }), - r"missing `#\[pallet::task_condition\(\.\.\)\]`" - ); - }); -} - -#[test] -fn test_parse_tasks_def_missing_task_index() { - simulate_manifest_dir("../../examples/basic", || { - assert_parse_error_matches!( - parse2::(quote! { - #[pallet::tasks_experimental] - impl, I: 'static> Pallet { - #[pallet::task_condition(|i| i % 2 == 0)] - #[pallet::task_list(Something::iter())] - pub fn foo(i: u32) -> DispatchResult { - Ok(()) - } - } - }), - r"missing `#\[pallet::task_index\(\.\.\)\]`" - ); - }); -} - -#[test] -fn test_parse_tasks_def_missing_task_weight() { - simulate_manifest_dir("../../examples/basic", || { - assert_parse_error_matches!( - parse2::(quote! { - #[pallet::tasks_experimental] - impl, I: 'static> Pallet { - #[pallet::task_condition(|i| i % 2 == 0)] - #[pallet::task_list(Something::iter())] - #[pallet::task_index(0)] - pub fn foo(i: u32) -> DispatchResult { - Ok(()) - } - } - }), - r"missing `#\[pallet::task_weight\(\.\.\)\]`" - ); - }); -} - -#[test] -fn test_parse_tasks_def_unexpected_extra_task_list_attr() { - simulate_manifest_dir("../../examples/basic", || { - assert_parse_error_matches!( - parse2::(quote! { - #[pallet::tasks_experimental] - impl, I: 'static> Pallet { - #[pallet::task_condition(|i| i % 2 == 0)] - #[pallet::task_index(0)] - #[pallet::task_weight(0)] - #[pallet::task_list(Something::iter())] - #[pallet::task_list(SomethingElse::iter())] - pub fn foo(i: u32) -> DispatchResult { - Ok(()) - } - } - }), - r"unexpected extra `#\[pallet::task_list\(\.\.\)\]`" - ); - }); -} - -#[test] -fn test_parse_tasks_def_unexpected_extra_task_condition_attr() { - simulate_manifest_dir("../../examples/basic", || { - assert_parse_error_matches!( - parse2::(quote! { - #[pallet::tasks_experimental] - impl, I: 'static> Pallet { - #[pallet::task_condition(|i| i % 2 == 0)] - #[pallet::task_condition(|i| i % 4 == 0)] - #[pallet::task_index(0)] - #[pallet::task_list(Something::iter())] - #[pallet::task_weight(0)] - pub fn foo(i: u32) -> DispatchResult { - Ok(()) - } - } - }), - r"unexpected extra `#\[pallet::task_condition\(\.\.\)\]`" - ); - }); -} - -#[test] -fn test_parse_tasks_def_unexpected_extra_task_index_attr() { - simulate_manifest_dir("../../examples/basic", || { - assert_parse_error_matches!( - parse2::(quote! { - #[pallet::tasks_experimental] - impl, I: 'static> Pallet { - #[pallet::task_condition(|i| i % 2 == 0)] - #[pallet::task_index(0)] - #[pallet::task_index(0)] - #[pallet::task_list(Something::iter())] - #[pallet::task_weight(0)] - pub fn foo(i: u32) -> DispatchResult { - Ok(()) - } - } - }), - r"unexpected extra `#\[pallet::task_index\(\.\.\)\]`" - ); - }); -} - -#[test] -fn test_parse_tasks_def_extra_tasks_attribute() { - simulate_manifest_dir("../../examples/basic", || { - assert_parse_error_matches!( - parse2::(quote! { - #[pallet::tasks_experimental] - #[pallet::tasks_experimental] - impl, I: 'static> Pallet {} - }), - r"unexpected extra `#\[pallet::tasks_experimental\]` attribute" - ); - }); -} - -#[test] -fn test_parse_task_enum_def_basic() { - simulate_manifest_dir("../../examples/basic", || { - parse2::(quote! { - #[pallet::task_enum] - pub enum Task { - Increment, - Decrement, - } - }) - .unwrap(); - }); -} - -#[test] -fn test_parse_task_enum_def_non_task_name() { - simulate_manifest_dir("../../examples/basic", || { - parse2::(quote! { - #[pallet::task_enum] - pub enum Something { - Foo - } - }) - .unwrap(); - }); -} - -#[test] -fn test_parse_task_enum_def_missing_attr_allowed() { - simulate_manifest_dir("../../examples/basic", || { - parse2::(quote! { - pub enum Task { - Increment, - Decrement, - } - }) - .unwrap(); - }); -} - -#[test] -fn test_parse_task_enum_def_missing_attr_alternate_name_allowed() { - simulate_manifest_dir("../../examples/basic", || { - parse2::(quote! { - pub enum Foo { - Red, - } - }) - .unwrap(); - }); -} - -#[test] -fn test_parse_task_enum_def_wrong_attr() { - simulate_manifest_dir("../../examples/basic", || { - assert_parse_error_matches!( - parse2::(quote! { - #[pallet::something] - pub enum Task { - Increment, - Decrement, - } - }), - "expected `task_enum`" - ); - }); -} - -#[test] -fn test_parse_task_enum_def_wrong_item() { - simulate_manifest_dir("../../examples/basic", || { - assert_parse_error_matches!( - parse2::(quote! { - #[pallet::task_enum] - pub struct Something; - }), - "expected `enum`" - ); - }); -} diff --git a/support/procedural-fork/src/pallet/parse/tests/mod.rs b/support/procedural-fork/src/pallet/parse/tests/mod.rs deleted file mode 100644 index fd7dc2dbe0..0000000000 --- a/support/procedural-fork/src/pallet/parse/tests/mod.rs +++ /dev/null @@ -1,264 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use std::{panic, sync::Mutex}; -use syn::parse_quote; - -#[doc(hidden)] -pub mod __private { - pub use regex; -} - -/// Allows you to assert that the input expression resolves to an error whose string -/// representation matches the specified regex literal. -/// -/// ## Example: -/// -/// ``` -/// use super::tasks::*; -/// -/// assert_parse_error_matches!( -/// parse2::(quote! { -/// #[pallet::task_enum] -/// pub struct Something; -/// }), -/// "expected `enum`" -/// ); -/// ``` -/// -/// More complex regular expressions are also possible (anything that could pass as a regex for -/// use with the [`regex`] crate.): -/// -/// ```ignore -/// assert_parse_error_matches!( -/// parse2::(quote! { -/// #[pallet::tasks_experimental] -/// impl, I: 'static> Pallet { -/// #[pallet::task_condition(|i| i % 2 == 0)] -/// #[pallet::task_index(0)] -/// pub fn foo(i: u32) -> DispatchResult { -/// Ok(()) -/// } -/// } -/// }), -/// r"missing `#\[pallet::task_list\(\.\.\)\]`" -/// ); -/// ``` -/// -/// Although this is primarily intended to be used with parsing errors, this macro is general -/// enough that it will work with any error with a reasonable [`core::fmt::Display`] impl. -#[macro_export] -macro_rules! assert_parse_error_matches { - ($expr:expr, $reg:literal) => { - match $expr { - Ok(_) => panic!("Expected an `Error(..)`, but got Ok(..)"), - Err(e) => { - let error_message = e.to_string(); - let re = $crate::pallet::parse::tests::__private::regex::Regex::new($reg) - .expect("Invalid regex pattern"); - assert!( - re.is_match(&error_message), - "Error message \"{}\" does not match the pattern \"{}\"", - error_message, - $reg - ); - } - } - }; -} - -/// Allows you to assert that an entire pallet parses successfully. A custom syntax is used for -/// specifying arguments so please pay attention to the docs below. -/// -/// The general syntax is: -/// -/// ```ignore -/// assert_pallet_parses! { -/// #[manifest_dir("../../examples/basic")] -/// #[frame_support::pallet] -/// pub mod pallet { -/// #[pallet::config] -/// pub trait Config: frame_system::Config {} -/// -/// #[pallet::pallet] -/// pub struct Pallet(_); -/// } -/// }; -/// ``` -/// -/// The `#[manifest_dir(..)]` attribute _must_ be specified as the _first_ attribute on the -/// pallet module, and should reference the relative (to your current directory) path of a -/// directory containing containing the `Cargo.toml` of a valid pallet. Typically you will only -/// ever need to use the `examples/basic` pallet, but sometimes it might be advantageous to -/// specify a different one that has additional dependencies. -/// -/// The reason this must be specified is that our underlying parsing of pallets depends on -/// reaching out into the file system to look for particular `Cargo.toml` dependencies via the -/// [`generate_access_from_frame_or_crate`] method, so to simulate this properly in a proc -/// macro crate, we need to temporarily convince this function that we are running from the -/// directory of a valid pallet. -#[macro_export] -macro_rules! assert_pallet_parses { - ( - #[manifest_dir($manifest_dir:literal)] - $($tokens:tt)* - ) => { - { - let mut pallet: Option<$crate::pallet::parse::Def> = None; - $crate::pallet::parse::tests::simulate_manifest_dir($manifest_dir, core::panic::AssertUnwindSafe(|| { - pallet = Some($crate::pallet::parse::Def::try_from(syn::parse_quote! { - $($tokens)* - }, false).unwrap()); - })); - pallet.unwrap() - } - } -} - -/// Similar to [`assert_pallet_parses`], except this instead expects the pallet not to parse, -/// and allows you to specify a regex matching the expected parse error. -/// -/// This is identical syntactically to [`assert_pallet_parses`] in every way except there is a -/// second attribute that must be specified immediately after `#[manifest_dir(..)]` which is -/// `#[error_regex(..)]` which should contain a string/regex literal designed to match what you -/// consider to be the correct parsing error we should see when we try to parse this particular -/// pallet. -/// -/// ## Example: -/// -/// ``` -/// assert_pallet_parse_error! { -/// #[manifest_dir("../../examples/basic")] -/// #[error_regex("Missing `\\#\\[pallet::pallet\\]`")] -/// #[frame_support::pallet] -/// pub mod pallet { -/// #[pallet::config] -/// pub trait Config: frame_system::Config {} -/// } -/// } -/// ``` -#[macro_export] -macro_rules! assert_pallet_parse_error { - ( - #[manifest_dir($manifest_dir:literal)] - #[error_regex($reg:literal)] - $($tokens:tt)* - ) => { - $crate::pallet::parse::tests::simulate_manifest_dir($manifest_dir, || { - $crate::assert_parse_error_matches!( - $crate::pallet::parse::Def::try_from( - parse_quote! { - $($tokens)* - }, - false - ), - $reg - ); - }); - } -} - -/// Safely runs the specified `closure` while simulating an alternative `CARGO_MANIFEST_DIR`, -/// restoring `CARGO_MANIFEST_DIR` to its original value upon completion regardless of whether -/// the closure panics. -/// -/// This is useful in tests of `Def::try_from` and other pallet-related methods that internally -/// make use of [`generate_access_from_frame_or_crate`], which is sensitive to entries in the -/// "current" `Cargo.toml` files. -/// -/// This function uses a [`Mutex`] to avoid a race condition created when multiple tests try to -/// modify and then restore the `CARGO_MANIFEST_DIR` ENV var in an overlapping way. -pub fn simulate_manifest_dir, F: FnOnce() + std::panic::UnwindSafe>( - path: P, - closure: F, -) { - use std::{env::*, path::*}; - - /// Ensures that only one thread can modify/restore the `CARGO_MANIFEST_DIR` ENV var at a time, - /// avoiding a race condition because `cargo test` runs tests in parallel. - /// - /// Although this forces all tests that use [`simulate_manifest_dir`] to run sequentially with - /// respect to each other, this is still several orders of magnitude faster than using UI - /// tests, even if they are run in parallel. - static MANIFEST_DIR_LOCK: Mutex<()> = Mutex::new(()); - - // avoid race condition when swapping out `CARGO_MANIFEST_DIR` - let guard = MANIFEST_DIR_LOCK.lock().unwrap(); - - // obtain the current/original `CARGO_MANIFEST_DIR` - let orig = PathBuf::from( - var("CARGO_MANIFEST_DIR").expect("failed to read ENV var `CARGO_MANIFEST_DIR`"), - ); - - // set `CARGO_MANIFEST_DIR` to the provided path, relative to current working dir - set_var("CARGO_MANIFEST_DIR", orig.join(path.as_ref())); - - // safely run closure catching any panics - let result = panic::catch_unwind(closure); - - // restore original `CARGO_MANIFEST_DIR` before unwinding - set_var("CARGO_MANIFEST_DIR", &orig); - - // unlock the mutex so we don't poison it if there is a panic - drop(guard); - - // unwind any panics originally encountered when running closure - result.unwrap(); -} - -mod tasks; - -#[test] -fn test_parse_minimal_pallet() { - assert_pallet_parses! { - #[manifest_dir("../../examples/basic")] - #[frame_support::pallet] - pub mod pallet { - #[pallet::config] - pub trait Config: frame_system::Config {} - - #[pallet::pallet] - pub struct Pallet(_); - } - }; -} - -#[test] -fn test_parse_pallet_missing_pallet() { - assert_pallet_parse_error! { - #[manifest_dir("../../examples/basic")] - #[error_regex("Missing `\\#\\[pallet::pallet\\]`")] - #[frame_support::pallet] - pub mod pallet { - #[pallet::config] - pub trait Config: frame_system::Config {} - } - } -} - -#[test] -fn test_parse_pallet_missing_config() { - assert_pallet_parse_error! { - #[manifest_dir("../../examples/basic")] - #[error_regex("Missing `\\#\\[pallet::config\\]`")] - #[frame_support::pallet] - pub mod pallet { - #[pallet::pallet] - pub struct Pallet(_); - } - } -} diff --git a/support/procedural-fork/src/pallet/parse/tests/tasks.rs b/support/procedural-fork/src/pallet/parse/tests/tasks.rs deleted file mode 100644 index 0097ed0471..0000000000 --- a/support/procedural-fork/src/pallet/parse/tests/tasks.rs +++ /dev/null @@ -1,240 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use syn::parse_quote; - -#[test] -fn test_parse_pallet_with_task_enum_missing_impl() { - assert_pallet_parse_error! { - #[manifest_dir("../../examples/basic")] - #[error_regex("Missing `\\#\\[pallet::tasks_experimental\\]` impl")] - #[frame_support::pallet] - pub mod pallet { - #[pallet::task_enum] - pub enum Task { - Something, - } - - #[pallet::config] - pub trait Config: frame_system::Config {} - - #[pallet::pallet] - pub struct Pallet(_); - } - } -} - -#[test] -fn test_parse_pallet_with_task_enum_wrong_attribute() { - assert_pallet_parse_error! { - #[manifest_dir("../../examples/basic")] - #[error_regex("expected one of")] - #[frame_support::pallet] - pub mod pallet { - #[pallet::wrong_attribute] - pub enum Task { - Something, - } - - #[pallet::task_list] - impl frame_support::traits::Task for Task - where - T: TypeInfo, - {} - - #[pallet::config] - pub trait Config: frame_system::Config {} - - #[pallet::pallet] - pub struct Pallet(_); - } - } -} - -#[test] -fn test_parse_pallet_missing_task_enum() { - assert_pallet_parses! { - #[manifest_dir("../../examples/basic")] - #[frame_support::pallet] - pub mod pallet { - #[pallet::tasks_experimental] - #[cfg(test)] // aha, this means it's being eaten - impl frame_support::traits::Task for Task - where - T: TypeInfo, - {} - - #[pallet::config] - pub trait Config: frame_system::Config {} - - #[pallet::pallet] - pub struct Pallet(_); - } - }; -} - -#[test] -fn test_parse_pallet_task_list_in_wrong_place() { - assert_pallet_parse_error! { - #[manifest_dir("../../examples/basic")] - #[error_regex("can only be used on items within an `impl` statement.")] - #[frame_support::pallet] - pub mod pallet { - pub enum MyCustomTaskEnum { - Something, - } - - #[pallet::task_list] - pub fn something() { - println!("hey"); - } - - #[pallet::config] - pub trait Config: frame_system::Config {} - - #[pallet::pallet] - pub struct Pallet(_); - } - } -} - -#[test] -fn test_parse_pallet_manual_tasks_impl_without_manual_tasks_enum() { - assert_pallet_parse_error! { - #[manifest_dir("../../examples/basic")] - #[error_regex(".*attribute must be attached to your.*")] - #[frame_support::pallet] - pub mod pallet { - - impl frame_support::traits::Task for Task - where - T: TypeInfo, - { - type Enumeration = alloc::vec::IntoIter>; - - fn iter() -> Self::Enumeration { - alloc::vec![Task::increment, Task::decrement].into_iter() - } - } - - #[pallet::config] - pub trait Config: frame_system::Config {} - - #[pallet::pallet] - pub struct Pallet(_); - } - } -} - -#[test] -fn test_parse_pallet_manual_task_enum_non_manual_impl() { - assert_pallet_parses! { - #[manifest_dir("../../examples/basic")] - #[frame_support::pallet] - pub mod pallet { - pub enum MyCustomTaskEnum { - Something, - } - - #[pallet::tasks_experimental] - impl frame_support::traits::Task for MyCustomTaskEnum - where - T: TypeInfo, - {} - - #[pallet::config] - pub trait Config: frame_system::Config {} - - #[pallet::pallet] - pub struct Pallet(_); - } - }; -} - -#[test] -fn test_parse_pallet_non_manual_task_enum_manual_impl() { - assert_pallet_parses! { - #[manifest_dir("../../examples/basic")] - #[frame_support::pallet] - pub mod pallet { - #[pallet::task_enum] - pub enum MyCustomTaskEnum { - Something, - } - - impl frame_support::traits::Task for MyCustomTaskEnum - where - T: TypeInfo, - {} - - #[pallet::config] - pub trait Config: frame_system::Config {} - - #[pallet::pallet] - pub struct Pallet(_); - } - }; -} - -#[test] -fn test_parse_pallet_manual_task_enum_manual_impl() { - assert_pallet_parses! { - #[manifest_dir("../../examples/basic")] - #[frame_support::pallet] - pub mod pallet { - pub enum MyCustomTaskEnum { - Something, - } - - impl frame_support::traits::Task for MyCustomTaskEnum - where - T: TypeInfo, - {} - - #[pallet::config] - pub trait Config: frame_system::Config {} - - #[pallet::pallet] - pub struct Pallet(_); - } - }; -} - -#[test] -fn test_parse_pallet_manual_task_enum_mismatch_ident() { - assert_pallet_parses! { - #[manifest_dir("../../examples/basic")] - #[frame_support::pallet] - pub mod pallet { - pub enum WrongIdent { - Something, - } - - #[pallet::tasks_experimental] - impl frame_support::traits::Task for MyCustomTaskEnum - where - T: TypeInfo, - {} - - #[pallet::config] - pub trait Config: frame_system::Config {} - - #[pallet::pallet] - pub struct Pallet(_); - } - }; -} diff --git a/support/procedural-fork/src/pallet/parse/type_value.rs b/support/procedural-fork/src/pallet/parse/type_value.rs deleted file mode 100644 index 1054fd74cc..0000000000 --- a/support/procedural-fork/src/pallet/parse/type_value.rs +++ /dev/null @@ -1,113 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use super::helper; -use syn::spanned::Spanned; - -/// Definition of type value. Just a function which is expanded to a struct implementing `Get`. -pub struct TypeValueDef { - /// The index of error item in pallet module. - pub index: usize, - /// Visibility of the struct to generate. - pub vis: syn::Visibility, - /// Ident of the struct to generate. - pub ident: syn::Ident, - /// The type return by Get. - pub type_: Box, - /// If type value is generic over `T` (or `T` and `I` for instantiable pallet) - pub is_generic: bool, - /// The where clause of the function. - pub where_clause: Option, - /// The span of the pallet::type_value attribute. - pub attr_span: proc_macro2::Span, - /// Docs on the item. - pub docs: Vec, -} - -impl TypeValueDef { - pub fn try_from( - attr_span: proc_macro2::Span, - index: usize, - item: &mut syn::Item, - ) -> syn::Result { - let item = if let syn::Item::Fn(item) = item { - item - } else { - let msg = "Invalid pallet::type_value, expected item fn"; - return Err(syn::Error::new(item.span(), msg)); - }; - - let mut docs = vec![]; - for attr in &item.attrs { - if let syn::Meta::NameValue(meta) = &attr.meta { - if meta.path.get_ident().map_or(false, |ident| ident == "doc") { - docs.push(meta.value.clone()); - continue; - } - } - - let msg = "Invalid pallet::type_value, unexpected attribute, only doc attribute are \ - allowed"; - return Err(syn::Error::new(attr.span(), msg)); - } - - if let Some(span) = item - .sig - .constness - .as_ref() - .map(|t| t.span()) - .or_else(|| item.sig.asyncness.as_ref().map(|t| t.span())) - .or_else(|| item.sig.unsafety.as_ref().map(|t| t.span())) - .or_else(|| item.sig.abi.as_ref().map(|t| t.span())) - .or_else(|| item.sig.variadic.as_ref().map(|t| t.span())) - { - let msg = "Invalid pallet::type_value, unexpected token"; - return Err(syn::Error::new(span, msg)); - } - - if !item.sig.inputs.is_empty() { - let msg = "Invalid pallet::type_value, unexpected argument"; - return Err(syn::Error::new(item.sig.inputs[0].span(), msg)); - } - - let vis = item.vis.clone(); - let ident = item.sig.ident.clone(); - let type_ = match item.sig.output.clone() { - syn::ReturnType::Type(_, type_) => type_, - syn::ReturnType::Default => { - let msg = "Invalid pallet::type_value, expected return type"; - return Err(syn::Error::new(item.sig.span(), msg)); - } - }; - - helper::check_type_value_gen(&item.sig.generics, item.sig.span())?; - - let is_generic = item.sig.generics.type_params().count() > 0; - let where_clause = item.sig.generics.where_clause.clone(); - - Ok(TypeValueDef { - attr_span, - index, - is_generic, - vis, - ident, - type_, - where_clause, - docs, - }) - } -} diff --git a/support/procedural-fork/src/pallet/parse/validate_unsigned.rs b/support/procedural-fork/src/pallet/parse/validate_unsigned.rs deleted file mode 100644 index 3fcbe09e8d..0000000000 --- a/support/procedural-fork/src/pallet/parse/validate_unsigned.rs +++ /dev/null @@ -1,55 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use super::helper; -use syn::spanned::Spanned; - -/// The definition of the pallet validate unsigned implementation. -pub struct ValidateUnsignedDef {} - -impl ValidateUnsignedDef { - pub fn try_from(item: &mut syn::Item) -> syn::Result { - let item = if let syn::Item::Impl(item) = item { - item - } else { - let msg = "Invalid pallet::validate_unsigned, expected item impl"; - return Err(syn::Error::new(item.span(), msg)); - }; - - if item.trait_.is_none() { - let msg = "Invalid pallet::validate_unsigned, expected impl<..> ValidateUnsigned for \ - Pallet<..>"; - return Err(syn::Error::new(item.span(), msg)); - } - - if let Some(last) = item.trait_.as_ref().unwrap().1.segments.last() { - if last.ident != "ValidateUnsigned" { - let msg = "Invalid pallet::validate_unsigned, expected trait ValidateUnsigned"; - return Err(syn::Error::new(last.span(), msg)); - } - } else { - let msg = "Invalid pallet::validate_unsigned, expected impl<..> ValidateUnsigned for \ - Pallet<..>"; - return Err(syn::Error::new(item.span(), msg)); - } - - helper::check_pallet_struct_usage(&item.self_ty)?; - helper::check_impl_gen(&item.generics, item.impl_token.span())?; - - Ok(ValidateUnsignedDef {}) - } -} diff --git a/support/procedural-fork/src/pallet_error.rs b/support/procedural-fork/src/pallet_error.rs deleted file mode 100644 index bdf8330cd7..0000000000 --- a/support/procedural-fork/src/pallet_error.rs +++ /dev/null @@ -1,191 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use frame_support_procedural_tools::generate_access_from_frame_or_crate; -use quote::ToTokens; - -// Derive `PalletError` -pub fn derive_pallet_error(input: proc_macro::TokenStream) -> proc_macro::TokenStream { - let syn::DeriveInput { - ident: name, - generics, - data, - .. - } = match syn::parse(input) { - Ok(input) => input, - Err(e) => return e.to_compile_error().into(), - }; - - let frame_support = match generate_access_from_frame_or_crate("frame-support") { - Ok(c) => c, - Err(e) => return e.into_compile_error().into(), - }; - let frame_support = &frame_support; - let (impl_generics, ty_generics, where_clause) = generics.split_for_impl(); - - let max_encoded_size = match data { - syn::Data::Struct(syn::DataStruct { fields, .. }) => match fields { - syn::Fields::Named(syn::FieldsNamed { named: fields, .. }) - | syn::Fields::Unnamed(syn::FieldsUnnamed { - unnamed: fields, .. - }) => { - let maybe_field_tys = fields - .iter() - .map(|f| generate_field_types(f, &frame_support)) - .collect::>>(); - let field_tys = match maybe_field_tys { - Ok(tys) => tys.into_iter().flatten(), - Err(e) => return e.into_compile_error().into(), - }; - quote::quote! { - 0_usize - #( - .saturating_add(< - #field_tys as #frame_support::traits::PalletError - >::MAX_ENCODED_SIZE) - )* - } - } - syn::Fields::Unit => quote::quote!(0), - }, - syn::Data::Enum(syn::DataEnum { variants, .. }) => { - let field_tys = variants - .iter() - .map(|variant| generate_variant_field_types(variant, &frame_support)) - .collect::>>, syn::Error>>(); - - let field_tys = match field_tys { - Ok(tys) => tys.into_iter().flatten().collect::>(), - Err(e) => return e.to_compile_error().into(), - }; - - // We start with `1`, because the discriminant of an enum is stored as u8 - if field_tys.is_empty() { - quote::quote!(1) - } else { - let variant_sizes = field_tys.into_iter().map(|variant_field_tys| { - quote::quote! { - 1_usize - #(.saturating_add(< - #variant_field_tys as #frame_support::traits::PalletError - >::MAX_ENCODED_SIZE))* - } - }); - - quote::quote! {{ - let mut size = 1_usize; - let mut tmp = 0_usize; - #( - tmp = #variant_sizes; - size = if tmp > size { tmp } else { size }; - tmp = 0_usize; - )* - size - }} - } - } - syn::Data::Union(syn::DataUnion { union_token, .. }) => { - let msg = "Cannot derive `PalletError` for union; please implement it directly"; - return syn::Error::new(union_token.span, msg) - .into_compile_error() - .into(); - } - }; - - quote::quote!( - const _: () = { - impl #impl_generics #frame_support::traits::PalletError - for #name #ty_generics #where_clause - { - const MAX_ENCODED_SIZE: usize = #max_encoded_size; - } - }; - ) - .into() -} - -fn generate_field_types( - field: &syn::Field, - scrate: &syn::Path, -) -> syn::Result> { - let attrs = &field.attrs; - - for attr in attrs { - if attr.path().is_ident("codec") { - let mut res = None; - - attr.parse_nested_meta(|meta| { - if meta.path.is_ident("skip") { - res = Some(None); - } else if meta.path.is_ident("compact") { - let field_ty = &field.ty; - res = Some(Some( - quote::quote!(#scrate::__private::codec::Compact<#field_ty>), - )); - } else if meta.path.is_ident("compact") { - res = Some(Some(meta.value()?.parse()?)); - } - - Ok(()) - })?; - - if let Some(v) = res { - return Ok(v); - } - } - } - - Ok(Some(field.ty.to_token_stream())) -} - -fn generate_variant_field_types( - variant: &syn::Variant, - scrate: &syn::Path, -) -> syn::Result>> { - let attrs = &variant.attrs; - - for attr in attrs { - if attr.path().is_ident("codec") { - let mut skip = false; - - // We ignore the error intentionally as this isn't `codec(skip)` when - // `parse_nested_meta` fails. - let _ = attr.parse_nested_meta(|meta| { - skip = meta.path.is_ident("skip"); - Ok(()) - }); - - if skip { - return Ok(None); - } - } - } - - match &variant.fields { - syn::Fields::Named(syn::FieldsNamed { named: fields, .. }) - | syn::Fields::Unnamed(syn::FieldsUnnamed { - unnamed: fields, .. - }) => { - let field_tys = fields - .iter() - .map(|field| generate_field_types(field, scrate)) - .collect::>>()?; - Ok(Some(field_tys.into_iter().flatten().collect())) - } - syn::Fields::Unit => Ok(None), - } -} diff --git a/support/procedural-fork/src/runtime/expand/mod.rs b/support/procedural-fork/src/runtime/expand/mod.rs deleted file mode 100644 index b51012541b..0000000000 --- a/support/procedural-fork/src/runtime/expand/mod.rs +++ /dev/null @@ -1,343 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use super::parse::runtime_types::RuntimeType; -use crate::{ - construct_runtime::{ - check_pallet_number, decl_all_pallets, decl_integrity_test, decl_pallet_runtime_setup, - decl_static_assertions, expand, - }, - runtime::{ - Def, - parse::{ - AllPalletsDeclaration, ExplicitAllPalletsDeclaration, ImplicitAllPalletsDeclaration, - }, - }, -}; -use cfg_expr::Predicate; -use frame_support_procedural_tools::{ - generate_access_from_frame_or_crate, generate_crate_access, generate_hidden_includes, -}; -use proc_macro2::TokenStream as TokenStream2; -use quote::quote; -use std::collections::HashSet; -use syn::{Ident, Result}; - -/// The fixed name of the system pallet. -const SYSTEM_PALLET_NAME: &str = "System"; - -pub fn expand(def: Def, legacy_ordering: bool) -> TokenStream2 { - let input = def.input; - - let (check_pallet_number_res, res) = match def.pallets { - AllPalletsDeclaration::Implicit(ref decl) => ( - check_pallet_number(input.clone(), decl.pallet_count), - construct_runtime_implicit_to_explicit(input.into(), decl.clone(), legacy_ordering), - ), - AllPalletsDeclaration::Explicit(ref decl) => ( - check_pallet_number(input, decl.pallets.len()), - construct_runtime_final_expansion( - def.runtime_struct.ident.clone(), - decl.clone(), - def.runtime_types.clone(), - legacy_ordering, - ), - ), - }; - - let res = res.unwrap_or_else(|e| e.to_compile_error()); - - // We want to provide better error messages to the user and thus, handle the error here - // separately. If there is an error, we print the error and still generate all of the code to - // get in overall less errors for the user. - let res = if let Err(error) = check_pallet_number_res { - let error = error.to_compile_error(); - - quote! { - #error - - #res - } - } else { - res - }; - - let res = expander::Expander::new("construct_runtime") - .dry(std::env::var("FRAME_EXPAND").is_err()) - .verbose(true) - .write_to_out_dir(res) - .expect("Does not fail because of IO in OUT_DIR; qed"); - - res.into() -} - -fn construct_runtime_implicit_to_explicit( - input: TokenStream2, - definition: ImplicitAllPalletsDeclaration, - legacy_ordering: bool, -) -> Result { - let frame_support = generate_access_from_frame_or_crate("frame-support")?; - let attr = if legacy_ordering { - quote!((legacy_ordering)) - } else { - quote!() - }; - let mut expansion = quote::quote!( - #[#frame_support::runtime #attr] - #input - ); - for pallet in definition.pallet_decls.iter() { - let pallet_path = &pallet.path; - let pallet_name = &pallet.name; - let runtime_param = &pallet.runtime_param; - let pallet_segment_and_instance = match (&pallet.pallet_segment, &pallet.instance) { - (Some(segment), Some(instance)) => quote::quote!(::#segment<#runtime_param, #instance>), - (Some(segment), None) => quote::quote!(::#segment<#runtime_param>), - (None, Some(instance)) => quote::quote!(<#instance>), - (None, None) => quote::quote!(), - }; - expansion = quote::quote!( - #frame_support::__private::tt_call! { - macro = [{ #pallet_path::tt_default_parts_v2 }] - your_tt_return = [{ #frame_support::__private::tt_return }] - ~~> #frame_support::match_and_insert! { - target = [{ #expansion }] - pattern = [{ #pallet_name = #pallet_path #pallet_segment_and_instance }] - } - } - ); - } - - Ok(expansion) -} - -fn construct_runtime_final_expansion( - name: Ident, - definition: ExplicitAllPalletsDeclaration, - runtime_types: Vec, - legacy_ordering: bool, -) -> Result { - let ExplicitAllPalletsDeclaration { - mut pallets, - name: pallets_name, - } = definition; - - if !legacy_ordering { - // Ensure that order of hooks is based on the pallet index - pallets.sort_by_key(|p| p.index); - } - - let system_pallet = pallets - .iter() - .find(|decl| decl.name == SYSTEM_PALLET_NAME) - .ok_or_else(|| { - syn::Error::new( - pallets_name.span(), - "`System` pallet declaration is missing. \ - Please add this line: `pub type System = frame_system;`", - ) - })?; - if !system_pallet.cfg_pattern.is_empty() { - return Err(syn::Error::new( - system_pallet.name.span(), - "`System` pallet declaration is feature gated, please remove any `#[cfg]` attributes", - )); - } - - let features = pallets - .iter() - .filter_map(|decl| { - (!decl.cfg_pattern.is_empty()).then(|| { - decl.cfg_pattern.iter().flat_map(|attr| { - attr.predicates().filter_map(|pred| match pred { - Predicate::Feature(feat) => Some(feat), - Predicate::Test => Some("test"), - _ => None, - }) - }) - }) - }) - .flatten() - .collect::>(); - - let hidden_crate_name = "construct_runtime"; - let scrate = generate_crate_access(hidden_crate_name, "frame-support"); - let scrate_decl = generate_hidden_includes(hidden_crate_name, "frame-support"); - - let frame_system = generate_access_from_frame_or_crate("frame-system")?; - let block = quote!(<#name as #frame_system::Config>::Block); - let unchecked_extrinsic = quote!(<#block as #scrate::sp_runtime::traits::Block>::Extrinsic); - - let mut dispatch = None; - let mut outer_event = None; - let mut outer_error = None; - let mut outer_origin = None; - let mut freeze_reason = None; - let mut hold_reason = None; - let mut slash_reason = None; - let mut lock_id = None; - let mut task = None; - - for runtime_type in runtime_types.iter() { - match runtime_type { - RuntimeType::RuntimeCall(_) => { - dispatch = Some(expand::expand_outer_dispatch( - &name, - system_pallet, - &pallets, - &scrate, - )); - } - RuntimeType::RuntimeEvent(_) => { - outer_event = Some(expand::expand_outer_enum( - &name, - &pallets, - &scrate, - expand::OuterEnumType::Event, - )?); - } - RuntimeType::RuntimeError(_) => { - outer_error = Some(expand::expand_outer_enum( - &name, - &pallets, - &scrate, - expand::OuterEnumType::Error, - )?); - } - RuntimeType::RuntimeOrigin(_) => { - outer_origin = Some(expand::expand_outer_origin( - &name, - system_pallet, - &pallets, - &scrate, - )?); - } - RuntimeType::RuntimeFreezeReason(_) => { - freeze_reason = Some(expand::expand_outer_freeze_reason(&pallets, &scrate)); - } - RuntimeType::RuntimeHoldReason(_) => { - hold_reason = Some(expand::expand_outer_hold_reason(&pallets, &scrate)); - } - RuntimeType::RuntimeSlashReason(_) => { - slash_reason = Some(expand::expand_outer_slash_reason(&pallets, &scrate)); - } - RuntimeType::RuntimeLockId(_) => { - lock_id = Some(expand::expand_outer_lock_id(&pallets, &scrate)); - } - RuntimeType::RuntimeTask(_) => { - task = Some(expand::expand_outer_task(&name, &pallets, &scrate)); - } - } - } - - let all_pallets = decl_all_pallets(&name, pallets.iter(), &features); - let pallet_to_index = decl_pallet_runtime_setup(&name, &pallets, &scrate); - - let metadata = expand::expand_runtime_metadata( - &name, - &pallets, - &scrate, - &unchecked_extrinsic, - &system_pallet.path, - ); - let outer_config = expand::expand_outer_config(&name, &pallets, &scrate); - let inherent = - expand::expand_outer_inherent(&name, &block, &unchecked_extrinsic, &pallets, &scrate); - let validate_unsigned = expand::expand_outer_validate_unsigned(&name, &pallets, &scrate); - let integrity_test = decl_integrity_test(&scrate); - let static_assertions = decl_static_assertions(&name, &pallets, &scrate); - - let res = quote!( - #scrate_decl - - // Prevent UncheckedExtrinsic to print unused warning. - const _: () = { - #[allow(unused)] - type __HiddenUseOfUncheckedExtrinsic = #unchecked_extrinsic; - }; - - #[derive( - Clone, Copy, PartialEq, Eq, #scrate::sp_runtime::RuntimeDebug, - #scrate::__private::scale_info::TypeInfo - )] - pub struct #name; - impl #scrate::sp_runtime::traits::GetRuntimeBlockType for #name { - type RuntimeBlock = #block; - } - - // Each runtime must expose the `runtime_metadata()` to fetch the runtime API metadata. - // The function is implemented by calling `impl_runtime_apis!`. - // - // However, the `runtime` may be used without calling `impl_runtime_apis!`. - // Rely on the `Deref` trait to differentiate between a runtime that implements - // APIs (by macro impl_runtime_apis!) and a runtime that is simply created (by macro runtime). - // - // Both `InternalConstructRuntime` and `InternalImplRuntimeApis` expose a `runtime_metadata()` function. - // `InternalConstructRuntime` is implemented by the `runtime` for Runtime references (`& Runtime`), - // while `InternalImplRuntimeApis` is implemented by the `impl_runtime_apis!` for Runtime (`Runtime`). - // - // Therefore, the `Deref` trait will resolve the `runtime_metadata` from `impl_runtime_apis!` - // when both macros are called; and will resolve an empty `runtime_metadata` when only the `runtime` - // is used. - - #[doc(hidden)] - trait InternalConstructRuntime { - #[inline(always)] - fn runtime_metadata(&self) -> #scrate::__private::Vec<#scrate::__private::metadata_ir::RuntimeApiMetadataIR> { - Default::default() - } - } - #[doc(hidden)] - impl InternalConstructRuntime for &#name {} - - #outer_event - - #outer_error - - #outer_origin - - #all_pallets - - #pallet_to_index - - #dispatch - - #task - - #metadata - - #outer_config - - #inherent - - #validate_unsigned - - #freeze_reason - - #hold_reason - - #lock_id - - #slash_reason - - #integrity_test - - #static_assertions - ); - - Ok(res) -} diff --git a/support/procedural-fork/src/runtime/mod.rs b/support/procedural-fork/src/runtime/mod.rs deleted file mode 100644 index a96b21cd19..0000000000 --- a/support/procedural-fork/src/runtime/mod.rs +++ /dev/null @@ -1,234 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//! Implementation of `runtime`. -//! -//! `runtime` implementation is recursive and can generate code which will call itself -//! in order to get all the pallet parts for each pallet. -//! -//! Pallets can define their parts: -//! - Implicitly: `pub type System = frame_system;` -//! - Explicitly: `pub type System = frame_system + Pallet + Call;` -//! -//! The `runtime` transitions from the implicit definition to the explicit one. -//! From the explicit state, Substrate expands the pallets with additional information -//! that is to be included in the runtime metadata. -//! -//! Pallets must provide the `tt_default_parts_v2` macro for these transitions. -//! These are automatically implemented by the `#[pallet::pallet]` macro. -//! -//! This macro also generates the following enums for ease of decoding if the respective type -//! is defined inside `#[runtime::derive]`: -//! - `enum RuntimeCall`: This type contains the information needed to decode extrinsics. -//! - `enum RuntimeEvent`: This type contains the information needed to decode events. -//! - `enum RuntimeError`: While this cannot be used directly to decode `sp_runtime::DispatchError` -//! from the chain, it contains the information needed to decode the -//! `sp_runtime::DispatchError::Module`. -//! -//! # State Transitions -//! -//! ```ignore -//! +----------+ -//! | Implicit | -//! +----------+ -//! | -//! v -//! +----------+ -//! | Explicit | -//! +----------+ -//! ``` -//! -//! The `runtime` macro transforms the implicit declaration of each pallet -//! `System: frame_system` to an explicit one `System: frame_system + Pallet + Call` using the -//! `tt_default_parts_v2` macro. -//! -//! The `tt_default_parts_v2` macro exposes a plus separated list of pallet parts. For example, the -//! `Event` part is exposed only if the pallet implements an event via `#[pallet::event]` macro. -//! The tokens generated by this macro are `+ Pallet + Call` for our example. -//! -//! The `match_and_insert` macro takes in 3 arguments: -//! - target: This is the `TokenStream` that contains the `runtime` macro. -//! - pattern: The pattern to match against in the target stream. -//! - tokens: The tokens to added after the pattern match. -//! -//! The `runtime` macro uses the `tt_call` to get the default pallet parts via -//! the `tt_default_parts_v2` macro defined by each pallet. The pallet parts are then returned as -//! input to the `match_and_replace` macro. -//! The `match_and_replace` then will modify the `runtime` to expand the implicit -//! definition to the explicit one. -//! -//! For example, -//! -//! ```ignore -//! #[frame_support::runtime] -//! mod runtime { -//! //... -//! -//! #[runtime::pallet_index(0)] -//! pub type System = frame_system; // Implicit definition of parts -//! -//! #[runtime::pallet_index(1)] -//! pub type Balances = pallet_balances; // Implicit definition of parts -//! } -//! ``` -//! This call has some implicit pallet parts, thus it will expand to: -//! ```ignore -//! frame_support::__private::tt_call! { -//! macro = [{ pallet_balances::tt_default_parts_v2 }] -//! ~~> frame_support::match_and_insert! { -//! target = [{ -//! frame_support::__private::tt_call! { -//! macro = [{ frame_system::tt_default_parts_v2 }] -//! ~~> frame_support::match_and_insert! { -//! target = [{ -//! #[frame_support::runtime] -//! mod runtime { -//! //... -//! -//! #[runtime::pallet_index(0)] -//! pub type System = frame_system; -//! -//! #[runtime::pallet_index(1)] -//! pub type Balances = pallet_balances; -//! } -//! }] -//! pattern = [{ System = frame_system }] -//! } -//! } -//! }] -//! pattern = [{ Balances = pallet_balances }] -//! } -//! } -//! ``` -//! `tt_default_parts_v2` must be defined. It returns the pallet parts inside some tokens, and -//! then `tt_call` will pipe the returned pallet parts into the input of `match_and_insert`. -//! Thus `match_and_insert` will initially receive the following inputs: -//! ```ignore -//! frame_support::match_and_insert! { -//! target = [{ -//! frame_support::match_and_insert! { -//! target = [{ -//! #[frame_support::runtime] -//! mod runtime { -//! //... -//! -//! #[runtime::pallet_index(0)] -//! pub type System = frame_system; -//! -//! #[runtime::pallet_index(1)] -//! pub type Balances = pallet_balances; -//! } -//! }] -//! pattern = [{ System = frame_system }] -//! tokens = [{ ::{+ Pallet + Call} }] -//! } -//! }] -//! pattern = [{ Balances = pallet_balances }] -//! tokens = [{ ::{+ Pallet + Call} }] -//! } -//! ``` -//! After dealing with `pallet_balances`, the inner `match_and_insert` will expand to: -//! ```ignore -//! frame_support::match_and_insert! { -//! target = [{ -//! #[frame_support::runtime] -//! mod runtime { -//! //... -//! -//! #[runtime::pallet_index(0)] -//! pub type System = frame_system; // Implicit definition of parts -//! -//! #[runtime::pallet_index(1)] -//! pub type Balances = pallet_balances + Pallet + Call; // Explicit definition of parts -//! } -//! }] -//! pattern = [{ System = frame_system }] -//! tokens = [{ ::{+ Pallet + Call} }] -//! } -//! ``` -//! -//! Which will then finally expand to the following: -//! ```ignore -//! #[frame_support::runtime] -//! mod runtime { -//! //... -//! -//! #[runtime::pallet_index(0)] -//! pub type System = frame_system + Pallet + Call; -//! -//! #[runtime::pallet_index(1)] -//! pub type Balances = pallet_balances + Pallet + Call; -//! } -//! ``` -//! -//! This call has no implicit pallet parts, thus it will expand to the runtime construction: -//! ```ignore -//! pub struct Runtime { ... } -//! pub struct Call { ... } -//! impl Call ... -//! pub enum Origin { ... } -//! ... -//! ``` -//! -//! Visualizing the entire flow of `#[frame_support::runtime]`, it would look like the following: -//! -//! ```ignore -//! +----------------------+ +------------------------+ +-------------------+ -//! | | | (defined in pallet) | | | -//! | runtime | --> | tt_default_parts_v2! | --> | match_and_insert! | -//! | w/ no pallet parts | | | | | -//! +----------------------+ +------------------------+ +-------------------+ -//! -//! +----------------------+ -//! | | -//! --> | runtime | -//! | w/ pallet parts | -//! +----------------------+ -//! ``` - -pub use parse::Def; -use proc_macro::TokenStream; -use syn::spanned::Spanned; - -mod expand; -mod parse; - -mod keyword { - syn::custom_keyword!(legacy_ordering); -} - -pub fn runtime(attr: TokenStream, tokens: TokenStream) -> TokenStream { - let mut legacy_ordering = false; - if !attr.is_empty() { - if let Ok(_) = syn::parse::(attr.clone()) { - legacy_ordering = true; - } else { - let msg = "Invalid runtime macro call: unexpected attribute. Macro call must be \ - bare, such as `#[frame_support::runtime]` or `#[runtime]`, or must specify the \ - `legacy_ordering` attribute, such as `#[frame_support::runtime(legacy_ordering)]` or \ - #[runtime(legacy_ordering)]."; - let span = proc_macro2::TokenStream::from(attr).span(); - return syn::Error::new(span, msg).to_compile_error().into(); - } - } - - let item = syn::parse_macro_input!(tokens as syn::ItemMod); - match parse::Def::try_from(item) { - Ok(def) => expand::expand(def, legacy_ordering).into(), - Err(e) => e.to_compile_error().into(), - } -} diff --git a/support/procedural-fork/src/runtime/parse/helper.rs b/support/procedural-fork/src/runtime/parse/helper.rs deleted file mode 100644 index 17e362410d..0000000000 --- a/support/procedural-fork/src/runtime/parse/helper.rs +++ /dev/null @@ -1,44 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use crate::pallet::parse::helper::MutItemAttrs; -use quote::ToTokens; - -pub(crate) fn take_first_item_runtime_attr( - item: &mut impl MutItemAttrs, -) -> syn::Result> -where - Attr: syn::parse::Parse, -{ - let attrs = if let Some(attrs) = item.mut_item_attrs() { - attrs - } else { - return Ok(None); - }; - - if let Some(index) = attrs.iter().position(|attr| { - attr.path() - .segments - .first() - .map_or(false, |segment| segment.ident == "runtime") - }) { - let runtime_attr = attrs.remove(index); - Ok(Some(syn::parse2(runtime_attr.into_token_stream())?)) - } else { - Ok(None) - } -} diff --git a/support/procedural-fork/src/runtime/parse/mod.rs b/support/procedural-fork/src/runtime/parse/mod.rs deleted file mode 100644 index 67fc03c59f..0000000000 --- a/support/procedural-fork/src/runtime/parse/mod.rs +++ /dev/null @@ -1,295 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -pub mod helper; -pub mod pallet; -pub mod pallet_decl; -pub mod runtime_struct; -pub mod runtime_types; - -use crate::construct_runtime::parse::Pallet; -use pallet_decl::PalletDeclaration; -use proc_macro2::TokenStream as TokenStream2; -use quote::ToTokens; -use std::collections::HashMap; -use syn::{Ident, Token, spanned::Spanned}; - -use frame_support_procedural_tools::syn_ext as ext; -use runtime_types::RuntimeType; - -mod keyword { - use syn::custom_keyword; - - custom_keyword!(runtime); - custom_keyword!(derive); - custom_keyword!(pallet_index); - custom_keyword!(disable_call); - custom_keyword!(disable_unsigned); -} - -enum RuntimeAttr { - Runtime(proc_macro2::Span), - Derive(proc_macro2::Span, Vec), - PalletIndex(proc_macro2::Span, u8), - DisableCall(proc_macro2::Span), - DisableUnsigned(proc_macro2::Span), -} - -impl RuntimeAttr { - fn span(&self) -> proc_macro2::Span { - match self { - Self::Runtime(span) => *span, - Self::Derive(span, _) => *span, - Self::PalletIndex(span, _) => *span, - Self::DisableCall(span) => *span, - Self::DisableUnsigned(span) => *span, - } - } -} - -impl syn::parse::Parse for RuntimeAttr { - fn parse(input: syn::parse::ParseStream) -> syn::Result { - input.parse::()?; - let content; - syn::bracketed!(content in input); - content.parse::()?; - content.parse::()?; - - let lookahead = content.lookahead1(); - if lookahead.peek(keyword::runtime) { - Ok(RuntimeAttr::Runtime( - content.parse::()?.span(), - )) - } else if lookahead.peek(keyword::derive) { - let _ = content.parse::(); - let derive_content; - syn::parenthesized!(derive_content in content); - let runtime_types = - derive_content.parse::>()?; - let runtime_types = runtime_types.inner.into_iter().collect(); - Ok(RuntimeAttr::Derive(derive_content.span(), runtime_types)) - } else if lookahead.peek(keyword::pallet_index) { - let _ = content.parse::(); - let pallet_index_content; - syn::parenthesized!(pallet_index_content in content); - let pallet_index = pallet_index_content.parse::()?; - if !pallet_index.suffix().is_empty() { - let msg = "Number literal must not have a suffix"; - return Err(syn::Error::new(pallet_index.span(), msg)); - } - Ok(RuntimeAttr::PalletIndex( - pallet_index.span(), - pallet_index.base10_parse()?, - )) - } else if lookahead.peek(keyword::disable_call) { - Ok(RuntimeAttr::DisableCall( - content.parse::()?.span(), - )) - } else if lookahead.peek(keyword::disable_unsigned) { - Ok(RuntimeAttr::DisableUnsigned( - content.parse::()?.span(), - )) - } else { - Err(lookahead.error()) - } - } -} - -#[derive(Debug, Clone)] -pub enum AllPalletsDeclaration { - Implicit(ImplicitAllPalletsDeclaration), - Explicit(ExplicitAllPalletsDeclaration), -} - -/// Declaration of a runtime with some pallet with implicit declaration of parts. -#[derive(Debug, Clone)] -pub struct ImplicitAllPalletsDeclaration { - pub pallet_decls: Vec, - pub pallet_count: usize, -} - -/// Declaration of a runtime with all pallet having explicit declaration of parts. -#[derive(Debug, Clone)] -pub struct ExplicitAllPalletsDeclaration { - pub name: Ident, - pub pallets: Vec, -} - -pub struct Def { - pub input: TokenStream2, - pub runtime_struct: runtime_struct::RuntimeStructDef, - pub pallets: AllPalletsDeclaration, - pub runtime_types: Vec, -} - -impl Def { - pub fn try_from(mut item: syn::ItemMod) -> syn::Result { - let input: TokenStream2 = item.to_token_stream().into(); - let item_span = item.span(); - let items = &mut item - .content - .as_mut() - .ok_or_else(|| { - let msg = "Invalid runtime definition, expected mod to be inlined."; - syn::Error::new(item_span, msg) - })? - .1; - - let mut runtime_struct = None; - let mut runtime_types = None; - - let mut indices = HashMap::new(); - let mut names = HashMap::new(); - - let mut pallet_decls = vec![]; - let mut pallets = vec![]; - - for item in items.iter_mut() { - let mut pallet_index_and_item = None; - - let mut disable_call = false; - let mut disable_unsigned = false; - - while let Some(runtime_attr) = - helper::take_first_item_runtime_attr::(item)? - { - match runtime_attr { - RuntimeAttr::Runtime(_) if runtime_struct.is_none() => { - let p = runtime_struct::RuntimeStructDef::try_from(item)?; - runtime_struct = Some(p); - } - RuntimeAttr::Derive(_, types) if runtime_types.is_none() => { - runtime_types = Some(types); - } - RuntimeAttr::PalletIndex(span, index) => { - pallet_index_and_item = if let syn::Item::Type(item) = item { - Some((index, item.clone())) - } else { - let msg = "Invalid runtime::pallet_index, expected type definition"; - return Err(syn::Error::new(span, msg)); - }; - } - RuntimeAttr::DisableCall(_) => disable_call = true, - RuntimeAttr::DisableUnsigned(_) => disable_unsigned = true, - attr => { - let msg = "Invalid duplicated attribute"; - return Err(syn::Error::new(attr.span(), msg)); - } - } - } - - if let Some((pallet_index, pallet_item)) = pallet_index_and_item { - match *pallet_item.ty.clone() { - syn::Type::Path(ref path) => { - let pallet_decl = - PalletDeclaration::try_from(item.span(), &pallet_item, &path.path)?; - - if let Some(used_pallet) = - names.insert(pallet_decl.name.clone(), pallet_decl.name.span()) - { - let msg = "Two pallets with the same name!"; - - let mut err = syn::Error::new(used_pallet, &msg); - err.combine(syn::Error::new(pallet_decl.name.span(), &msg)); - return Err(err); - } - - pallet_decls.push(pallet_decl); - } - syn::Type::TraitObject(syn::TypeTraitObject { bounds, .. }) => { - let pallet = Pallet::try_from( - item.span(), - &pallet_item, - pallet_index, - disable_call, - disable_unsigned, - &bounds, - )?; - - if let Some(used_pallet) = indices.insert(pallet.index, pallet.name.clone()) - { - let msg = format!( - "Pallet indices are conflicting: Both pallets {} and {} are at index {}", - used_pallet, pallet.name, pallet.index, - ); - let mut err = syn::Error::new(used_pallet.span(), &msg); - err.combine(syn::Error::new(pallet.name.span(), msg)); - return Err(err); - } - - pallets.push(pallet); - } - _ => continue, - } - } else { - if let syn::Item::Type(item) = item { - let msg = "Missing pallet index for pallet declaration. Please add `#[runtime::pallet_index(...)]`"; - return Err(syn::Error::new(item.span(), &msg)); - } - } - } - - let name = item.ident.clone(); - let decl_count = pallet_decls.len(); - let pallets = if decl_count > 0 { - AllPalletsDeclaration::Implicit(ImplicitAllPalletsDeclaration { - pallet_decls, - pallet_count: decl_count.saturating_add(pallets.len()), - }) - } else { - AllPalletsDeclaration::Explicit(ExplicitAllPalletsDeclaration { name, pallets }) - }; - - let def = Def { - input, - runtime_struct: runtime_struct.ok_or_else(|| { - syn::Error::new(item_span, - "Missing Runtime. Please add a struct inside the module and annotate it with `#[runtime::runtime]`" - ) - })?, - pallets, - runtime_types: runtime_types.ok_or_else(|| { - syn::Error::new(item_span, - "Missing Runtime Types. Please annotate the runtime struct with `#[runtime::derive]`" - ) - })?, - }; - - Ok(def) - } -} - -#[test] -fn runtime_parsing_works() { - let def = Def::try_from(syn::parse_quote! { - #[runtime::runtime] - mod runtime { - #[runtime::derive(RuntimeCall, RuntimeEvent)] - #[runtime::runtime] - pub struct Runtime; - - #[runtime::pallet_index(0)] - pub type System = frame_system::Pallet; - - #[runtime::pallet_index(1)] - pub type Pallet1 = pallet1; - } - }) - .expect("Failed to parse runtime definition"); - - assert_eq!(def.runtime_struct.ident, "Runtime"); -} diff --git a/support/procedural-fork/src/runtime/parse/pallet.rs b/support/procedural-fork/src/runtime/parse/pallet.rs deleted file mode 100644 index 460818e4d5..0000000000 --- a/support/procedural-fork/src/runtime/parse/pallet.rs +++ /dev/null @@ -1,217 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use crate::{ - construct_runtime::parse::{Pallet, PalletPart, PalletPartKeyword, PalletPath}, - runtime::parse::PalletDeclaration, -}; -use frame_support_procedural_tools::get_doc_literals; -use quote::ToTokens; -use syn::{Error, punctuated::Punctuated, token}; - -impl Pallet { - pub fn try_from( - attr_span: proc_macro2::Span, - item: &syn::ItemType, - pallet_index: u8, - disable_call: bool, - disable_unsigned: bool, - bounds: &Punctuated, - ) -> syn::Result { - let name = item.ident.clone(); - - let mut pallet_path = None; - let mut pallet_parts = vec![]; - - for (index, bound) in bounds.into_iter().enumerate() { - if let syn::TypeParamBound::Trait(syn::TraitBound { path, .. }) = bound { - if index == 0 { - pallet_path = Some(PalletPath { - inner: path.clone(), - }); - } else { - let pallet_part = syn::parse2::(bound.into_token_stream())?; - pallet_parts.push(pallet_part); - } - } else { - return Err(Error::new( - attr_span, - "Invalid pallet declaration, expected a path or a trait object", - )); - }; - } - - let mut path = pallet_path.ok_or(Error::new( - attr_span, - "Invalid pallet declaration, expected a path or a trait object", - ))?; - - let PalletDeclaration { - path: inner, - instance, - .. - } = PalletDeclaration::try_from(attr_span, item, &path.inner)?; - - path = PalletPath { inner }; - - pallet_parts = pallet_parts - .into_iter() - .filter(|part| { - if let (true, &PalletPartKeyword::Call(_)) = (disable_call, &part.keyword) { - false - } else if let (true, &PalletPartKeyword::ValidateUnsigned(_)) = - (disable_unsigned, &part.keyword) - { - false - } else { - true - } - }) - .collect(); - - let cfg_pattern = vec![]; - - let docs = get_doc_literals(&item.attrs); - - Ok(Pallet { - is_expanded: true, - name, - index: pallet_index, - path, - instance, - cfg_pattern, - pallet_parts, - docs, - }) - } -} - -#[test] -fn pallet_parsing_works() { - use syn::{ItemType, parse_quote}; - - let item: ItemType = parse_quote! { - pub type System = frame_system + Call; - }; - let ItemType { ty, .. } = item.clone(); - let syn::Type::TraitObject(syn::TypeTraitObject { bounds, .. }) = *ty else { - panic!("Expected a trait object"); - }; - - let index = 0; - let pallet = Pallet::try_from( - proc_macro2::Span::call_site(), - &item, - index, - false, - false, - &bounds, - ) - .unwrap(); - - assert_eq!(pallet.name.to_string(), "System"); - assert_eq!(pallet.index, index); - assert_eq!(pallet.path.to_token_stream().to_string(), "frame_system"); - assert_eq!(pallet.instance, None); -} - -#[test] -fn pallet_parsing_works_with_instance() { - use syn::{ItemType, parse_quote}; - - let item: ItemType = parse_quote! { - pub type System = frame_system + Call; - }; - let ItemType { ty, .. } = item.clone(); - let syn::Type::TraitObject(syn::TypeTraitObject { bounds, .. }) = *ty else { - panic!("Expected a trait object"); - }; - - let index = 0; - let pallet = Pallet::try_from( - proc_macro2::Span::call_site(), - &item, - index, - false, - false, - &bounds, - ) - .unwrap(); - - assert_eq!(pallet.name.to_string(), "System"); - assert_eq!(pallet.index, index); - assert_eq!(pallet.path.to_token_stream().to_string(), "frame_system"); - assert_eq!(pallet.instance, Some(parse_quote! { Instance1 })); -} - -#[test] -fn pallet_parsing_works_with_pallet() { - use syn::{ItemType, parse_quote}; - - let item: ItemType = parse_quote! { - pub type System = frame_system::Pallet + Call; - }; - let ItemType { ty, .. } = item.clone(); - let syn::Type::TraitObject(syn::TypeTraitObject { bounds, .. }) = *ty else { - panic!("Expected a trait object"); - }; - - let index = 0; - let pallet = Pallet::try_from( - proc_macro2::Span::call_site(), - &item, - index, - false, - false, - &bounds, - ) - .unwrap(); - - assert_eq!(pallet.name.to_string(), "System"); - assert_eq!(pallet.index, index); - assert_eq!(pallet.path.to_token_stream().to_string(), "frame_system"); - assert_eq!(pallet.instance, None); -} - -#[test] -fn pallet_parsing_works_with_instance_and_pallet() { - use syn::{ItemType, parse_quote}; - - let item: ItemType = parse_quote! { - pub type System = frame_system::Pallet + Call; - }; - let ItemType { ty, .. } = item.clone(); - let syn::Type::TraitObject(syn::TypeTraitObject { bounds, .. }) = *ty else { - panic!("Expected a trait object"); - }; - - let index = 0; - let pallet = Pallet::try_from( - proc_macro2::Span::call_site(), - &item, - index, - false, - false, - &bounds, - ) - .unwrap(); - - assert_eq!(pallet.name.to_string(), "System"); - assert_eq!(pallet.index, index); - assert_eq!(pallet.path.to_token_stream().to_string(), "frame_system"); - assert_eq!(pallet.instance, Some(parse_quote! { Instance1 })); -} diff --git a/support/procedural-fork/src/runtime/parse/pallet_decl.rs b/support/procedural-fork/src/runtime/parse/pallet_decl.rs deleted file mode 100644 index ddc9a7ffe7..0000000000 --- a/support/procedural-fork/src/runtime/parse/pallet_decl.rs +++ /dev/null @@ -1,185 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use syn::{Ident, PathArguments}; - -/// The declaration of a pallet. -#[derive(Debug, Clone)] -pub struct PalletDeclaration { - /// The name of the pallet, e.g.`System` in `pub type System = frame_system`. - pub name: Ident, - /// The path of the pallet, e.g. `frame_system` in `pub type System = frame_system`. - pub path: syn::Path, - /// The segment of the pallet, e.g. `Pallet` in `pub type System = frame_system::Pallet`. - pub pallet_segment: Option, - /// The runtime parameter of the pallet, e.g. `Runtime` in - /// `pub type System = frame_system::Pallet`. - pub runtime_param: Option, - /// The instance of the pallet, e.g. `Instance1` in `pub type Council = pallet_collective`. - pub instance: Option, -} - -impl PalletDeclaration { - pub fn try_from( - _attr_span: proc_macro2::Span, - item: &syn::ItemType, - path: &syn::Path, - ) -> syn::Result { - let name = item.ident.clone(); - - let mut path = path.clone(); - - let mut pallet_segment = None; - let mut runtime_param = None; - let mut instance = None; - if let Some(segment) = path - .segments - .iter_mut() - .find(|seg| !seg.arguments.is_empty()) - { - if let PathArguments::AngleBracketed(syn::AngleBracketedGenericArguments { - args, .. - }) = segment.arguments.clone() - { - if segment.ident == "Pallet" { - let mut segment = segment.clone(); - segment.arguments = PathArguments::None; - pallet_segment = Some(segment.clone()); - } - let mut args_iter = args.iter(); - if let Some(syn::GenericArgument::Type(syn::Type::Path(arg_path))) = - args_iter.next() - { - let ident = arg_path.path.require_ident()?.clone(); - if segment.ident == "Pallet" { - runtime_param = Some(ident); - if let Some(syn::GenericArgument::Type(syn::Type::Path(arg_path))) = - args_iter.next() - { - instance = Some(arg_path.path.require_ident()?.clone()); - } - } else { - instance = Some(ident); - segment.arguments = PathArguments::None; - } - } - } - } - - if pallet_segment.is_some() { - path = syn::Path { - leading_colon: None, - segments: path - .segments - .iter() - .filter(|seg| seg.arguments.is_empty()) - .cloned() - .collect(), - }; - } - - Ok(Self { - name, - path, - pallet_segment, - runtime_param, - instance, - }) - } -} - -#[test] -fn declaration_works() { - use syn::parse_quote; - - let decl: PalletDeclaration = PalletDeclaration::try_from( - proc_macro2::Span::call_site(), - &parse_quote! { pub type System = frame_system; }, - &parse_quote! { frame_system }, - ) - .expect("Failed to parse pallet declaration"); - - assert_eq!(decl.name, "System"); - assert_eq!(decl.path, parse_quote! { frame_system }); - assert_eq!(decl.pallet_segment, None); - assert_eq!(decl.runtime_param, None); - assert_eq!(decl.instance, None); -} - -#[test] -fn declaration_works_with_instance() { - use syn::parse_quote; - - let decl: PalletDeclaration = PalletDeclaration::try_from( - proc_macro2::Span::call_site(), - &parse_quote! { pub type System = frame_system; }, - &parse_quote! { frame_system }, - ) - .expect("Failed to parse pallet declaration"); - - assert_eq!(decl.name, "System"); - assert_eq!(decl.path, parse_quote! { frame_system }); - assert_eq!(decl.pallet_segment, None); - assert_eq!(decl.runtime_param, None); - assert_eq!(decl.instance, Some(parse_quote! { Instance1 })); -} - -#[test] -fn declaration_works_with_pallet() { - use syn::parse_quote; - - let decl: PalletDeclaration = PalletDeclaration::try_from( - proc_macro2::Span::call_site(), - &parse_quote! { pub type System = frame_system::Pallet; }, - &parse_quote! { frame_system::Pallet }, - ) - .expect("Failed to parse pallet declaration"); - - assert_eq!(decl.name, "System"); - assert_eq!(decl.path, parse_quote! { frame_system }); - - let segment: syn::PathSegment = syn::PathSegment { - ident: parse_quote! { Pallet }, - arguments: PathArguments::None, - }; - assert_eq!(decl.pallet_segment, Some(segment)); - assert_eq!(decl.runtime_param, Some(parse_quote! { Runtime })); - assert_eq!(decl.instance, None); -} - -#[test] -fn declaration_works_with_pallet_and_instance() { - use syn::parse_quote; - - let decl: PalletDeclaration = PalletDeclaration::try_from( - proc_macro2::Span::call_site(), - &parse_quote! { pub type System = frame_system::Pallet; }, - &parse_quote! { frame_system::Pallet }, - ) - .expect("Failed to parse pallet declaration"); - - assert_eq!(decl.name, "System"); - assert_eq!(decl.path, parse_quote! { frame_system }); - - let segment: syn::PathSegment = syn::PathSegment { - ident: parse_quote! { Pallet }, - arguments: PathArguments::None, - }; - assert_eq!(decl.pallet_segment, Some(segment)); - assert_eq!(decl.runtime_param, Some(parse_quote! { Runtime })); - assert_eq!(decl.instance, Some(parse_quote! { Instance1 })); -} diff --git a/support/procedural-fork/src/runtime/parse/runtime_struct.rs b/support/procedural-fork/src/runtime/parse/runtime_struct.rs deleted file mode 100644 index 82c6470d7d..0000000000 --- a/support/procedural-fork/src/runtime/parse/runtime_struct.rs +++ /dev/null @@ -1,36 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use syn::spanned::Spanned; -pub struct RuntimeStructDef { - pub ident: syn::Ident, -} - -impl RuntimeStructDef { - pub fn try_from(item: &mut syn::Item) -> syn::Result { - let item = if let syn::Item::Struct(item) = item { - item - } else { - let msg = "Invalid runtime::runtime, expected struct definition"; - return Err(syn::Error::new(item.span(), msg)); - }; - - Ok(Self { - ident: item.ident.clone(), - }) - } -} diff --git a/support/procedural-fork/src/runtime/parse/runtime_types.rs b/support/procedural-fork/src/runtime/parse/runtime_types.rs deleted file mode 100644 index 56c765d04e..0000000000 --- a/support/procedural-fork/src/runtime/parse/runtime_types.rs +++ /dev/null @@ -1,76 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use syn::{ - Result, - parse::{Parse, ParseStream}, -}; - -mod keyword { - use syn::custom_keyword; - - custom_keyword!(RuntimeCall); - custom_keyword!(RuntimeEvent); - custom_keyword!(RuntimeError); - custom_keyword!(RuntimeOrigin); - custom_keyword!(RuntimeFreezeReason); - custom_keyword!(RuntimeHoldReason); - custom_keyword!(RuntimeSlashReason); - custom_keyword!(RuntimeLockId); - custom_keyword!(RuntimeTask); -} - -#[derive(Debug, Clone, PartialEq)] -pub enum RuntimeType { - RuntimeCall(keyword::RuntimeCall), - RuntimeEvent(keyword::RuntimeEvent), - RuntimeError(keyword::RuntimeError), - RuntimeOrigin(keyword::RuntimeOrigin), - RuntimeFreezeReason(keyword::RuntimeFreezeReason), - RuntimeHoldReason(keyword::RuntimeHoldReason), - RuntimeSlashReason(keyword::RuntimeSlashReason), - RuntimeLockId(keyword::RuntimeLockId), - RuntimeTask(keyword::RuntimeTask), -} - -impl Parse for RuntimeType { - fn parse(input: ParseStream) -> Result { - let lookahead = input.lookahead1(); - - if lookahead.peek(keyword::RuntimeCall) { - Ok(Self::RuntimeCall(input.parse()?)) - } else if lookahead.peek(keyword::RuntimeEvent) { - Ok(Self::RuntimeEvent(input.parse()?)) - } else if lookahead.peek(keyword::RuntimeError) { - Ok(Self::RuntimeError(input.parse()?)) - } else if lookahead.peek(keyword::RuntimeOrigin) { - Ok(Self::RuntimeOrigin(input.parse()?)) - } else if lookahead.peek(keyword::RuntimeFreezeReason) { - Ok(Self::RuntimeFreezeReason(input.parse()?)) - } else if lookahead.peek(keyword::RuntimeHoldReason) { - Ok(Self::RuntimeHoldReason(input.parse()?)) - } else if lookahead.peek(keyword::RuntimeSlashReason) { - Ok(Self::RuntimeSlashReason(input.parse()?)) - } else if lookahead.peek(keyword::RuntimeLockId) { - Ok(Self::RuntimeLockId(input.parse()?)) - } else if lookahead.peek(keyword::RuntimeTask) { - Ok(Self::RuntimeTask(input.parse()?)) - } else { - Err(lookahead.error()) - } - } -} diff --git a/support/procedural-fork/src/storage_alias.rs b/support/procedural-fork/src/storage_alias.rs deleted file mode 100644 index 018105053e..0000000000 --- a/support/procedural-fork/src/storage_alias.rs +++ /dev/null @@ -1,709 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//! Implementation of the `storage_alias` attribute macro. - -use crate::{counter_prefix, pallet::parse::helper}; -use frame_support_procedural_tools::generate_access_from_frame_or_crate; -use proc_macro2::{Span, TokenStream}; -use quote::{ToTokens, quote}; -use syn::{ - Attribute, Error, Ident, Result, Token, Type, TypeParam, Visibility, WhereClause, - parenthesized, - parse::{Parse, ParseStream}, - punctuated::Punctuated, - spanned::Spanned, - token, - visit::Visit, -}; - -/// Extension trait for [`Type`]. -trait TypeExt { - fn get_ident(&self) -> Option<&Ident>; - fn contains_ident(&self, ident: &Ident) -> bool; -} - -impl TypeExt for Type { - fn get_ident(&self) -> Option<&Ident> { - match self { - Type::Path(p) => match &p.qself { - Some(qself) => qself.ty.get_ident(), - None => p.path.get_ident(), - }, - _ => None, - } - } - - fn contains_ident(&self, ident: &Ident) -> bool { - struct ContainsIdent<'a> { - ident: &'a Ident, - found: bool, - } - impl<'a, 'ast> Visit<'ast> for ContainsIdent<'a> { - fn visit_ident(&mut self, i: &'ast Ident) { - if i == self.ident { - self.found = true; - } - } - } - - let mut visitor = ContainsIdent { - ident, - found: false, - }; - syn::visit::visit_type(&mut visitor, self); - visitor.found - } -} - -/// Represents generics which only support [`TypeParam`] separated by commas. -struct SimpleGenerics { - lt_token: Token![<], - params: Punctuated, - gt_token: Token![>], -} - -impl SimpleGenerics { - /// Returns the generics for types declarations etc. - fn type_generics(&self) -> impl Iterator { - self.params.iter().map(|p| &p.ident) - } - - /// Returns the generics for the `impl` block. - fn impl_generics(&self) -> impl Iterator { - self.params.iter() - } -} - -impl Parse for SimpleGenerics { - fn parse(input: ParseStream<'_>) -> Result { - Ok(Self { - lt_token: input.parse()?, - params: Punctuated::parse_separated_nonempty(input)?, - gt_token: input.parse()?, - }) - } -} - -impl ToTokens for SimpleGenerics { - fn to_tokens(&self, tokens: &mut TokenStream) { - self.lt_token.to_tokens(tokens); - self.params.to_tokens(tokens); - self.gt_token.to_tokens(tokens); - } -} - -mod storage_types { - syn::custom_keyword!(StorageValue); - syn::custom_keyword!(StorageMap); - syn::custom_keyword!(CountedStorageMap); - syn::custom_keyword!(StorageDoubleMap); - syn::custom_keyword!(StorageNMap); -} - -/// The types of prefixes the storage alias macro supports. -mod prefix_types { - // Use the verbatim/unmodified input name as the prefix. - syn::custom_keyword!(verbatim); - // The input type is a pallet and its pallet name should be used as the prefix. - syn::custom_keyword!(pallet_name); - // The input type implements `Get<'static str>` and this `str` should be used as the prefix. - syn::custom_keyword!(dynamic); -} - -/// The supported storage types -enum StorageType { - Value { - _kw: storage_types::StorageValue, - _lt_token: Token![<], - prefix: Type, - _value_comma: Token![,], - value_ty: Type, - query_type: Option<(Token![,], Type)>, - _trailing_comma: Option, - _gt_token: Token![>], - }, - Map { - _kw: storage_types::StorageMap, - _lt_token: Token![<], - prefix: Type, - _hasher_comma: Token![,], - hasher_ty: Type, - _key_comma: Token![,], - key_ty: Type, - _value_comma: Token![,], - value_ty: Type, - query_type: Option<(Token![,], Type)>, - _trailing_comma: Option, - _gt_token: Token![>], - }, - CountedMap { - _kw: storage_types::CountedStorageMap, - _lt_token: Token![<], - prefix: Type, - _hasher_comma: Token![,], - hasher_ty: Type, - _key_comma: Token![,], - key_ty: Type, - _value_comma: Token![,], - value_ty: Type, - query_type: Option<(Token![,], Type)>, - _trailing_comma: Option, - _gt_token: Token![>], - }, - DoubleMap { - _kw: storage_types::StorageDoubleMap, - _lt_token: Token![<], - prefix: Type, - _hasher1_comma: Token![,], - hasher1_ty: Type, - _key1_comma: Token![,], - key1_ty: Type, - _hasher2_comma: Token![,], - hasher2_ty: Type, - _key2_comma: Token![,], - key2_ty: Type, - _value_comma: Token![,], - value_ty: Type, - query_type: Option<(Token![,], Type)>, - _trailing_comma: Option, - _gt_token: Token![>], - }, - NMap { - _kw: storage_types::StorageNMap, - _lt_token: Token![<], - prefix: Type, - _paren_comma: Token![,], - _paren_token: token::Paren, - key_types: Punctuated, - _value_comma: Token![,], - value_ty: Type, - query_type: Option<(Token![,], Type)>, - _trailing_comma: Option, - _gt_token: Token![>], - }, -} - -impl StorageType { - /// Generate the actual type declaration. - fn generate_type_declaration( - &self, - crate_: &syn::Path, - storage_instance: &StorageInstance, - storage_name: &Ident, - storage_generics: Option<&SimpleGenerics>, - visibility: &Visibility, - attributes: &[Attribute], - ) -> TokenStream { - let storage_instance_generics = &storage_instance.generics; - let storage_instance = &storage_instance.name; - let attributes = attributes.iter(); - let storage_generics = storage_generics.map(|g| { - let generics = g.type_generics(); - - quote!( < #( #generics ),* > ) - }); - - match self { - Self::Value { - value_ty, - query_type, - .. - } => { - let query_type = query_type.as_ref().map(|(c, t)| quote!(#c #t)); - - quote! { - #( #attributes )* - #visibility type #storage_name #storage_generics = #crate_::storage::types::StorageValue< - #storage_instance #storage_instance_generics, - #value_ty - #query_type - >; - } - } - Self::CountedMap { - value_ty, - query_type, - hasher_ty, - key_ty, - .. - } - | Self::Map { - value_ty, - query_type, - hasher_ty, - key_ty, - .. - } => { - let query_type = query_type.as_ref().map(|(c, t)| quote!(#c #t)); - let map_type = Ident::new( - match self { - Self::Map { .. } => "StorageMap", - _ => "CountedStorageMap", - }, - Span::call_site(), - ); - - quote! { - #( #attributes )* - #visibility type #storage_name #storage_generics = #crate_::storage::types::#map_type< - #storage_instance #storage_instance_generics, - #hasher_ty, - #key_ty, - #value_ty - #query_type - >; - } - } - Self::DoubleMap { - value_ty, - query_type, - hasher1_ty, - key1_ty, - hasher2_ty, - key2_ty, - .. - } => { - let query_type = query_type.as_ref().map(|(c, t)| quote!(#c #t)); - - quote! { - #( #attributes )* - #visibility type #storage_name #storage_generics = #crate_::storage::types::StorageDoubleMap< - #storage_instance #storage_instance_generics, - #hasher1_ty, - #key1_ty, - #hasher2_ty, - #key2_ty, - #value_ty - #query_type - >; - } - } - Self::NMap { - value_ty, - query_type, - key_types, - .. - } => { - let query_type = query_type.as_ref().map(|(c, t)| quote!(#c #t)); - let key_types = key_types.iter(); - - quote! { - #( #attributes )* - #visibility type #storage_name #storage_generics = #crate_::storage::types::StorageNMap< - #storage_instance #storage_instance_generics, - ( #( #key_types ),* ), - #value_ty - #query_type - >; - } - } - } - } - - /// The prefix for this storage type. - fn prefix(&self) -> &Type { - match self { - Self::Value { prefix, .. } - | Self::Map { prefix, .. } - | Self::CountedMap { prefix, .. } - | Self::NMap { prefix, .. } - | Self::DoubleMap { prefix, .. } => prefix, - } - } -} - -impl Parse for StorageType { - fn parse(input: ParseStream<'_>) -> Result { - let lookahead = input.lookahead1(); - - let parse_query_type = |input: ParseStream<'_>| -> Result> { - if input.peek(Token![,]) && !input.peek2(Token![>]) { - Ok(Some((input.parse()?, input.parse()?))) - } else { - Ok(None) - } - }; - - if lookahead.peek(storage_types::StorageValue) { - Ok(Self::Value { - _kw: input.parse()?, - _lt_token: input.parse()?, - prefix: input.parse()?, - _value_comma: input.parse()?, - value_ty: input.parse()?, - query_type: parse_query_type(input)?, - _trailing_comma: input.peek(Token![,]).then(|| input.parse()).transpose()?, - _gt_token: input.parse()?, - }) - } else if lookahead.peek(storage_types::StorageMap) { - Ok(Self::Map { - _kw: input.parse()?, - _lt_token: input.parse()?, - prefix: input.parse()?, - _hasher_comma: input.parse()?, - hasher_ty: input.parse()?, - _key_comma: input.parse()?, - key_ty: input.parse()?, - _value_comma: input.parse()?, - value_ty: input.parse()?, - query_type: parse_query_type(input)?, - _trailing_comma: input.peek(Token![,]).then(|| input.parse()).transpose()?, - _gt_token: input.parse()?, - }) - } else if lookahead.peek(storage_types::CountedStorageMap) { - Ok(Self::CountedMap { - _kw: input.parse()?, - _lt_token: input.parse()?, - prefix: input.parse()?, - _hasher_comma: input.parse()?, - hasher_ty: input.parse()?, - _key_comma: input.parse()?, - key_ty: input.parse()?, - _value_comma: input.parse()?, - value_ty: input.parse()?, - query_type: parse_query_type(input)?, - _trailing_comma: input.peek(Token![,]).then(|| input.parse()).transpose()?, - _gt_token: input.parse()?, - }) - } else if lookahead.peek(storage_types::StorageDoubleMap) { - Ok(Self::DoubleMap { - _kw: input.parse()?, - _lt_token: input.parse()?, - prefix: input.parse()?, - _hasher1_comma: input.parse()?, - hasher1_ty: input.parse()?, - _key1_comma: input.parse()?, - key1_ty: input.parse()?, - _hasher2_comma: input.parse()?, - hasher2_ty: input.parse()?, - _key2_comma: input.parse()?, - key2_ty: input.parse()?, - _value_comma: input.parse()?, - value_ty: input.parse()?, - query_type: parse_query_type(input)?, - _trailing_comma: input.peek(Token![,]).then(|| input.parse()).transpose()?, - _gt_token: input.parse()?, - }) - } else if lookahead.peek(storage_types::StorageNMap) { - let content; - Ok(Self::NMap { - _kw: input.parse()?, - _lt_token: input.parse()?, - prefix: input.parse()?, - _paren_comma: input.parse()?, - _paren_token: parenthesized!(content in input), - key_types: Punctuated::parse_terminated(&content)?, - _value_comma: input.parse()?, - value_ty: input.parse()?, - query_type: parse_query_type(input)?, - _trailing_comma: input.peek(Token![,]).then(|| input.parse()).transpose()?, - _gt_token: input.parse()?, - }) - } else { - Err(lookahead.error()) - } - } -} - -/// The input expected by this macro. -struct Input { - attributes: Vec, - visibility: Visibility, - _type: Token![type], - storage_name: Ident, - storage_generics: Option, - where_clause: Option, - _equal: Token![=], - storage_type: StorageType, - _semicolon: Token![;], -} - -impl Parse for Input { - fn parse(input: ParseStream<'_>) -> Result { - let attributes = input.call(Attribute::parse_outer)?; - let visibility = input.parse()?; - let _type = input.parse()?; - let storage_name = input.parse()?; - - let lookahead = input.lookahead1(); - let storage_generics = if lookahead.peek(Token![<]) { - Some(input.parse()?) - } else if lookahead.peek(Token![=]) { - None - } else { - return Err(lookahead.error()); - }; - - let lookahead = input.lookahead1(); - let where_clause = if lookahead.peek(Token![where]) { - Some(input.parse()?) - } else if lookahead.peek(Token![=]) { - None - } else { - return Err(lookahead.error()); - }; - - let _equal = input.parse()?; - - let storage_type = input.parse()?; - - let _semicolon = input.parse()?; - - Ok(Self { - attributes, - visibility, - _type, - storage_name, - storage_generics, - _equal, - storage_type, - where_clause, - _semicolon, - }) - } -} - -/// Defines which type of prefix the storage alias is using. -#[derive(Clone, Copy)] -enum PrefixType { - /// An appropriate prefix will be determined automatically. - /// - /// If generics are passed, this is assumed to be a pallet and the pallet name should be used. - /// Otherwise use the verbatim passed name as prefix. - Compatibility, - /// The provided ident/name will be used as the prefix. - Verbatim, - /// The provided type will be used to determine the prefix. This type must - /// implement `PalletInfoAccess` which specifies the proper name. This - /// name is then used as the prefix. - PalletName, - /// Uses the provided type implementing `Get<'static str>` to determine the prefix. - Dynamic, -} - -/// Implementation of the `storage_alias` attribute macro. -pub fn storage_alias(attributes: TokenStream, input: TokenStream) -> Result { - let input = syn::parse2::(input)?; - let crate_ = generate_access_from_frame_or_crate("frame-support")?; - - let prefix_type = if attributes.is_empty() { - PrefixType::Compatibility - } else if syn::parse2::(attributes.clone()).is_ok() { - PrefixType::Verbatim - } else if syn::parse2::(attributes.clone()).is_ok() { - PrefixType::PalletName - } else if syn::parse2::(attributes.clone()).is_ok() { - PrefixType::Dynamic - } else { - return Err(Error::new(attributes.span(), "Unknown attributes")); - }; - - let storage_instance = generate_storage_instance( - &crate_, - &input.storage_name, - input.storage_generics.as_ref(), - input.where_clause.as_ref(), - input.storage_type.prefix(), - &input.visibility, - matches!(input.storage_type, StorageType::CountedMap { .. }), - prefix_type, - )?; - - let definition = input.storage_type.generate_type_declaration( - &crate_, - &storage_instance, - &input.storage_name, - input.storage_generics.as_ref(), - &input.visibility, - &input.attributes, - ); - - let storage_instance_code = storage_instance.code; - - Ok(quote! { - #storage_instance_code - - #definition - }) -} - -/// The storage instance to use for the storage alias. -struct StorageInstance { - name: Ident, - generics: TokenStream, - code: TokenStream, -} - -/// Generate the [`StorageInstance`] for the storage alias. -fn generate_storage_instance( - crate_: &syn::Path, - storage_name: &Ident, - storage_generics: Option<&SimpleGenerics>, - storage_where_clause: Option<&WhereClause>, - prefix: &Type, - visibility: &Visibility, - is_counted_map: bool, - prefix_type: PrefixType, -) -> Result { - if let Type::Infer(_) = prefix { - return Err(Error::new( - prefix.span(), - "`_` is not allowed as prefix by `storage_alias`.", - )); - } - - let impl_generics_used_by_prefix = storage_generics - .as_ref() - .map(|g| { - g.impl_generics() - .filter(|g| prefix.contains_ident(&g.ident)) - .collect::>() - }) - .unwrap_or_default(); - - let (pallet_prefix, impl_generics, type_generics) = match prefix_type { - PrefixType::Compatibility => { - if !impl_generics_used_by_prefix.is_empty() { - let type_generics = impl_generics_used_by_prefix.iter().map(|g| &g.ident); - let impl_generics = impl_generics_used_by_prefix.iter(); - - ( - quote! { - < #prefix as #crate_::traits::PalletInfoAccess>::name() - }, - quote!( #( #impl_generics ),* ), - quote!( #( #type_generics ),* ), - ) - } else if let Some(prefix) = prefix.get_ident() { - let prefix_str = prefix.to_string(); - - (quote!(#prefix_str), quote!(), quote!()) - } else { - return Err(Error::new_spanned( - prefix, - "If there are no generics, the prefix is only allowed to be an identifier.", - )); - } - } - PrefixType::Verbatim => { - let prefix_str = match prefix.get_ident() { - Some(p) => p.to_string(), - None => { - return Err(Error::new_spanned( - prefix, - "Prefix type `verbatim` requires that the prefix is an ident.", - )); - } - }; - - (quote!(#prefix_str), quote!(), quote!()) - } - PrefixType::PalletName => { - let type_generics = impl_generics_used_by_prefix.iter().map(|g| &g.ident); - let impl_generics = impl_generics_used_by_prefix.iter(); - - ( - quote! { - <#prefix as #crate_::traits::PalletInfoAccess>::name() - }, - quote!( #( #impl_generics ),* ), - quote!( #( #type_generics ),* ), - ) - } - PrefixType::Dynamic => { - let type_generics = impl_generics_used_by_prefix.iter().map(|g| &g.ident); - let impl_generics = impl_generics_used_by_prefix.iter(); - - ( - quote! { - <#prefix as #crate_::traits::Get<_>>::get() - }, - quote!( #( #impl_generics ),* ), - quote!( #( #type_generics ),* ), - ) - } - }; - - let where_clause = storage_where_clause.map(|w| quote!(#w)).unwrap_or_default(); - - let name_str = format!("{}_Storage_Instance", storage_name); - let name = Ident::new(&name_str, Span::call_site()); - let storage_name_str = storage_name.to_string(); - - let counter_code = is_counted_map.then(|| { - let counter_name = Ident::new(&counter_prefix(&name_str), Span::call_site()); - let counter_storage_name_str = counter_prefix(&storage_name_str); - let storage_prefix_hash = helper::two128_str(&counter_storage_name_str); - - quote! { - #visibility struct #counter_name< #impl_generics >( - ::core::marker::PhantomData<(#type_generics)> - ) #where_clause; - - impl<#impl_generics> #crate_::traits::StorageInstance - for #counter_name< #type_generics > #where_clause - { - fn pallet_prefix() -> &'static str { - #pallet_prefix - } - - const STORAGE_PREFIX: &'static str = #counter_storage_name_str; - fn storage_prefix_hash() -> [u8; 16] { - #storage_prefix_hash - } - } - - impl<#impl_generics> #crate_::storage::types::CountedStorageMapInstance - for #name< #type_generics > #where_clause - { - type CounterPrefix = #counter_name < #type_generics >; - } - } - }); - - let storage_prefix_hash = helper::two128_str(&storage_name_str); - - // Implement `StorageInstance` trait. - let code = quote! { - #[allow(non_camel_case_types)] - #visibility struct #name< #impl_generics >( - ::core::marker::PhantomData<(#type_generics)> - ) #where_clause; - - impl<#impl_generics> #crate_::traits::StorageInstance - for #name< #type_generics > #where_clause - { - fn pallet_prefix() -> &'static str { - #pallet_prefix - } - - const STORAGE_PREFIX: &'static str = #storage_name_str; - fn storage_prefix_hash() -> [u8; 16] { - #storage_prefix_hash - } - } - - #counter_code - }; - - Ok(StorageInstance { - name, - code, - generics: quote!( < #type_generics > ), - }) -} diff --git a/support/procedural-fork/src/transactional.rs b/support/procedural-fork/src/transactional.rs deleted file mode 100644 index 73a841d9be..0000000000 --- a/support/procedural-fork/src/transactional.rs +++ /dev/null @@ -1,70 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -use frame_support_procedural_tools::generate_access_from_frame_or_crate; -use proc_macro::TokenStream; -use quote::quote; -use syn::{ItemFn, Result}; - -pub fn transactional(_attr: TokenStream, input: TokenStream) -> Result { - let ItemFn { - attrs, - vis, - sig, - block, - } = syn::parse(input)?; - - let crate_ = generate_access_from_frame_or_crate("frame-support")?; - let output = quote! { - #(#attrs)* - #vis #sig { - use #crate_::storage::{with_transaction, TransactionOutcome}; - with_transaction(|| { - let r = (|| { #block })(); - if r.is_ok() { - TransactionOutcome::Commit(r) - } else { - TransactionOutcome::Rollback(r) - } - }) - } - }; - - Ok(output.into()) -} - -pub fn require_transactional(_attr: TokenStream, input: TokenStream) -> Result { - let ItemFn { - attrs, - vis, - sig, - block, - } = syn::parse(input)?; - - let crate_ = generate_access_from_frame_or_crate("frame-support")?; - let output = quote! { - #(#attrs)* - #vis #sig { - if !#crate_::storage::transactional::is_transactional() { - return Err(#crate_::sp_runtime::TransactionalError::NoLayer.into()); - } - #block - } - }; - - Ok(output.into()) -} diff --git a/support/procedural-fork/src/tt_macro.rs b/support/procedural-fork/src/tt_macro.rs deleted file mode 100644 index 3f280013f6..0000000000 --- a/support/procedural-fork/src/tt_macro.rs +++ /dev/null @@ -1,105 +0,0 @@ -// This file is part of Substrate. - -// Copyright (C) Parity Technologies (UK) Ltd. -// SPDX-License-Identifier: Apache-2.0 - -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -//! Implementation of the `create_tt_return_macro` macro - -use crate::COUNTER; -use proc_macro2::{Ident, TokenStream}; -use quote::format_ident; - -struct CreateTtReturnMacroDef { - name: Ident, - args: Vec<(Ident, TokenStream)>, -} - -impl syn::parse::Parse for CreateTtReturnMacroDef { - fn parse(input: syn::parse::ParseStream) -> syn::Result { - let name = input.parse()?; - let _ = input.parse::()?; - - let mut args = Vec::new(); - while !input.is_empty() { - let mut value; - let key: Ident = input.parse()?; - let _ = input.parse::()?; - let _: syn::token::Bracket = syn::bracketed!(value in input); - let _: syn::token::Brace = syn::braced!(value in value); - let value: TokenStream = value.parse()?; - - args.push((key, value)) - } - - Ok(Self { name, args }) - } -} - -/// A proc macro that accepts a name and any number of key-value pairs, to be used to create a -/// declarative macro that follows tt-call conventions and simply calls -/// [`tt_call::tt_return`], accepting an optional `frame-support` argument and returning -/// the key-value pairs that were supplied to the proc macro. -/// -/// # Example -/// ```ignore -/// __create_tt_macro! { -/// my_tt_macro, -/// foo = [{ bar }] -/// } -/// -/// // Creates the following declarative macro: -/// -/// macro_rules! my_tt_macro { -/// { -/// $caller:tt -/// $(your_tt_return = [{ $my_tt_return:path }])? -/// } => { -/// $my_tt_return! { -/// $caller -/// foo = [{ bar }] -/// } -/// } -/// } -/// ``` -pub fn create_tt_return_macro(input: proc_macro::TokenStream) -> proc_macro::TokenStream { - let CreateTtReturnMacroDef { name, args } = - syn::parse_macro_input!(input as CreateTtReturnMacroDef); - - let (keys, values): (Vec<_>, Vec<_>) = args.into_iter().unzip(); - let count = COUNTER.with(|counter| counter.borrow_mut().inc()); - let unique_name = format_ident!("{}_{}", name, count); - - let decl_macro = quote::quote! { - #[macro_export] - #[doc(hidden)] - macro_rules! #unique_name { - { - $caller:tt - $(your_tt_return = [{ $my_tt_macro:path }])? - } => { - $my_tt_return! { - $caller - #( - #keys = [{ #values }] - )* - } - } - } - - pub use #unique_name as #name; - }; - - decl_macro.into() -} diff --git a/support/procedural-fork/update.sh b/support/procedural-fork/update.sh deleted file mode 100755 index 0cb933b331..0000000000 --- a/support/procedural-fork/update.sh +++ /dev/null @@ -1,46 +0,0 @@ -#!/bin/sh - -# Enable error handling -set -e - -# Set the repository and tag -REPO_URL="git@github.com:paritytech/polkadot-sdk.git" -POLKADOT_SDK_TAG="v1.16.0-rc1" - -# Create a temporary directory for cloning -TMP_DIR=$(mktemp -d) - -# Define source and destination directories -SRC_DIR="substrate/frame/support/procedural/src" -DEST_DIR="$(pwd)/src" # Absolute path to `src` directory of procedural-fork - -# Check if DEST_DIR exists -if [ ! -d "$DEST_DIR" ]; then - echo "Error: Destination directory $DEST_DIR does not exist." - rm -rf "$TMP_DIR" - exit 1 -fi - -# Clone only the required directory from the repository -echo "Cloning $REPO_URL at tag $POLKADOT_SDK_TAG ..." -git clone --depth 1 --branch "$POLKADOT_SDK_TAG" --filter=blob:none --sparse "$REPO_URL" "$TMP_DIR" - -# Navigate to the cloned directory -cd "$TMP_DIR" - -# Initialize sparse-checkout and set the correct directory -git sparse-checkout init --cone -git sparse-checkout set "$SRC_DIR" - -# Debugging: List the contents of the sparse-checked-out directory -echo "Contents of $TMP_DIR/$SRC_DIR after sparse-checkout:" -ls -l "$TMP_DIR/$SRC_DIR" || { echo "Error: Sparse checkout failed, $SRC_DIR not found."; rm -rf "$TMP_DIR"; exit 1; } - -# Copy all files from `src` except `lib.rs` to the destination folder -echo "Copying files to $DEST_DIR ..." -rsync -a --exclude='lib.rs' "$TMP_DIR/$SRC_DIR/" "$DEST_DIR/" - -# Clean up the temporary directory -rm -rf "$TMP_DIR" - -echo "Update completed successfully."