Skip to content

Commit

Permalink
implemented logic to restore disable-runtime-api to test runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
bolajahmad committed Apr 30, 2024
1 parent c973fe8 commit c494b17
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 28 deletions.
15 changes: 12 additions & 3 deletions polkadot/runtime/rococo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@ license.workspace = true
workspace = true

[dependencies]
parity-scale-codec = { version = "3.6.1", default-features = false, features = ["derive", "max-encoded-len"] }
scale-info = { version = "2.11.1", default-features = false, features = ["derive"] }
parity-scale-codec = { version = "3.6.1", default-features = false, features = [
"derive",
"max-encoded-len",
] }
scale-info = { version = "2.11.1", default-features = false, features = [
"derive",
] }
log = { workspace = true }
serde = { workspace = true }
serde_derive = { optional = true, workspace = true }
Expand Down Expand Up @@ -80,7 +85,9 @@ pallet-scheduler = { path = "../../../substrate/frame/scheduler", default-featur
pallet-session = { path = "../../../substrate/frame/session", default-features = false }
pallet-society = { path = "../../../substrate/frame/society", default-features = false }
pallet-sudo = { path = "../../../substrate/frame/sudo", default-features = false }
frame-support = { path = "../../../substrate/frame/support", default-features = false, features = ["tuples-96"] }
frame-support = { path = "../../../substrate/frame/support", default-features = false, features = [
"tuples-96",
] }
pallet-staking = { path = "../../../substrate/frame/staking", default-features = false }
frame-system = { path = "../../../substrate/frame/system", default-features = false }
frame-system-rpc-runtime-api = { path = "../../../substrate/frame/system/rpc/runtime-api", default-features = false }
Expand Down Expand Up @@ -323,6 +330,8 @@ try-runtime = [
"sp-runtime/try-runtime",
]

disable-runtime-api = []

# Set timing constants (e.g. session period) to faster versions to speed up testing.
fast-runtime = ["rococo-runtime-constants/fast-runtime"]

Expand Down
32 changes: 25 additions & 7 deletions polkadot/runtime/rococo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ use beefy_primitives::{
};
use frame_support::{
dynamic_params::{dynamic_pallet_params, dynamic_params},
migrations::MultiStepMigrator,
traits::FromContains,
};
use pallet_nis::WithMaximumOf;
Expand Down Expand Up @@ -163,6 +164,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
authoring_version: 0,
spec_version: 1_010_000,
impl_version: 0,
#[cfg(not(feature = "disable-runtime-api"))]
apis: RUNTIME_API_VERSIONS,
transaction_version: 24,
state_version: 1,
Expand Down Expand Up @@ -199,6 +201,21 @@ parameter_types! {

#[derive_impl(frame_system::config_preludes::RelayChainDefaultConfig)]
impl frame_system::Config for Runtime {
type RuntimeOrigin = RuntimeOrigin;
type RuntimeEvent = RuntimeEvent;
type RuntimeCall = RuntimeCall;
type Hashing = BlakeTwo256;
type Lookup = AccountIdLookup<AccountId, ()>;
type RuntimeTask = RuntimeTask;
type PalletInfo = PalletInfo;
type OnNewAccount = ();
type OnKilledAccount = ();
type OnSetCode = ();
type SingleBlockMigrations = SingleBlockMigration;
type MultiBlockMigrator = MultiStepMigrator;
type PreInherents = ();
type PostInherents = ();
type PostTransactions = ();
type BaseCallFilter = EverythingBut<IsIdentityCall>;
type BlockWeights = BlockWeights;
type BlockLength = BlockLength;
Expand Down Expand Up @@ -893,19 +910,19 @@ impl InstanceFilter<RuntimeCall> for ProxyType {
),
ProxyType::IdentityJudgement => matches!(
c,
RuntimeCall::Identity(pallet_identity::Call::provide_judgement { .. }) |
RuntimeCall::Utility(..)
RuntimeCall::Identity(pallet_identity::Call::provide_judgement { .. })
| RuntimeCall::Utility(..)
),
ProxyType::CancelProxy => {
matches!(c, RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. }))
},
ProxyType::Auction => matches!(
c,
RuntimeCall::Auctions { .. } |
RuntimeCall::Crowdloan { .. } |
RuntimeCall::Registrar { .. } |
RuntimeCall::Multisig(..) |
RuntimeCall::Slots { .. }
RuntimeCall::Auctions { .. }
| RuntimeCall::Crowdloan { .. }
| RuntimeCall::Registrar { .. }
| RuntimeCall::Multisig(..)
| RuntimeCall::Slots { .. }
),
ProxyType::Society => matches!(c, RuntimeCall::Society(..)),
ProxyType::OnDemandOrdering => matches!(c, RuntimeCall::OnDemandAssignmentProvider(..)),
Expand Down Expand Up @@ -1744,6 +1761,7 @@ mod benches {
);
}

#[cfg(not(feature = "disable-runtime-api"))]
sp_api::impl_runtime_apis! {
impl sp_api::Core<Block> for Runtime {
fn version() -> RuntimeVersion {
Expand Down
16 changes: 13 additions & 3 deletions polkadot/runtime/westend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@ workspace = true

[dependencies]
bitvec = { version = "1.0.0", default-features = false, features = ["alloc"] }
parity-scale-codec = { version = "3.6.1", default-features = false, features = ["derive", "max-encoded-len"] }
scale-info = { version = "2.11.1", default-features = false, features = ["derive"] }
parity-scale-codec = { version = "3.6.1", default-features = false, features = [
"derive",
"max-encoded-len",
] }
scale-info = { version = "2.11.1", default-features = false, features = [
"derive",
] }
log = { workspace = true }
rustc-hex = { version = "2.1.0", default-features = false }
serde = { workspace = true }
Expand Down Expand Up @@ -45,7 +50,10 @@ sp-npos-elections = { path = "../../../substrate/primitives/npos-elections", def

frame-election-provider-support = { path = "../../../substrate/frame/election-provider-support", default-features = false }
frame-executive = { path = "../../../substrate/frame/executive", default-features = false }
frame-support = { path = "../../../substrate/frame/support", default-features = false, features = ["experimental", "tuples-96"] }
frame-support = { path = "../../../substrate/frame/support", default-features = false, features = [
"experimental",
"tuples-96",
] }
frame-system = { path = "../../../substrate/frame/system", default-features = false }
frame-system-rpc-runtime-api = { path = "../../../substrate/frame/system/rpc/runtime-api", default-features = false }
westend-runtime-constants = { package = "westend-runtime-constants", path = "constants", default-features = false }
Expand Down Expand Up @@ -337,6 +345,8 @@ try-runtime = [
"sp-runtime/try-runtime",
]

disable-runtime-api = []

# Set timing constants (e.g. session period) to faster versions to speed up testing.
fast-runtime = []

Expand Down
48 changes: 33 additions & 15 deletions polkadot/runtime/westend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
authoring_version: 2,
spec_version: 1_010_000,
impl_version: 0,
#[cfg(not(feature = "disable-runtime-api"))]
apis: RUNTIME_API_VERSIONS,
transaction_version: 24,
state_version: 1,
Expand Down Expand Up @@ -191,15 +192,30 @@ parameter_types! {

#[derive_impl(frame_system::config_preludes::RelayChainDefaultConfig)]
impl frame_system::Config for Runtime {
type RuntimeOrigin = RuntimeOrigin;
type RuntimeEvent = RuntimeEvent;
type RuntimeCall = RuntimeCall;
type Hashing = BlakeTwo256;
type Lookup = AccountIdLookup<AccountId, ()>;
type RuntimeTask = RuntimeTask;
type PalletInfo = PalletInfo;
type OnNewAccount = ();
type OnKilledAccount = ();
type OnSetCode = ();
type SingleBlockMigrations = SingleBlockMigration;
type MultiBlockMigrator = MultiStepMigrator;
type PreInherents = ();
type PostInherents = ();
type PostTransactions = ();
type BaseCallFilter = EverythingBut<IsIdentityCall>;
type BlockWeights = BlockWeights;
type BlockLength = BlockLength;
type DbWeight = RocksDbWeight;
type Nonce = Nonce;
type Hash = Hash;
type AccountId = AccountId;
type Block = Block;
type BlockHashCount = BlockHashCount;
type DbWeight = RocksDbWeight;
type Version = Version;
type AccountData = pallet_balances::AccountData<Balance>;
type SystemWeightInfo = weights::frame_system::WeightInfo<Runtime>;
Expand Down Expand Up @@ -1007,11 +1023,12 @@ impl InstanceFilter<RuntimeCall> for ProxyType {
ProxyType::Staking => {
matches!(
c,
RuntimeCall::Staking(..) |
RuntimeCall::Session(..) | RuntimeCall::Utility(..) |
RuntimeCall::FastUnstake(..) |
RuntimeCall::VoterList(..) |
RuntimeCall::NominationPools(..)
RuntimeCall::Staking(..)
| RuntimeCall::Session(..)
| RuntimeCall::Utility(..)
| RuntimeCall::FastUnstake(..)
| RuntimeCall::VoterList(..)
| RuntimeCall::NominationPools(..)
)
},
ProxyType::NominationPools => {
Expand All @@ -1027,24 +1044,24 @@ impl InstanceFilter<RuntimeCall> for ProxyType {
ProxyType::Governance => matches!(
c,
// OpenGov calls
RuntimeCall::ConvictionVoting(..) |
RuntimeCall::Referenda(..) |
RuntimeCall::Whitelist(..)
RuntimeCall::ConvictionVoting(..)
| RuntimeCall::Referenda(..)
| RuntimeCall::Whitelist(..)
),
ProxyType::IdentityJudgement => matches!(
c,
RuntimeCall::Identity(pallet_identity::Call::provide_judgement { .. }) |
RuntimeCall::Utility(..)
RuntimeCall::Identity(pallet_identity::Call::provide_judgement { .. })
| RuntimeCall::Utility(..)
),
ProxyType::CancelProxy => {
matches!(c, RuntimeCall::Proxy(pallet_proxy::Call::reject_announcement { .. }))
},
ProxyType::Auction => matches!(
c,
RuntimeCall::Auctions(..) |
RuntimeCall::Crowdloan(..) |
RuntimeCall::Registrar(..) |
RuntimeCall::Slots(..)
RuntimeCall::Auctions(..)
| RuntimeCall::Crowdloan(..)
| RuntimeCall::Registrar(..)
| RuntimeCall::Slots(..)
),
}
}
Expand Down Expand Up @@ -1724,6 +1741,7 @@ mod benches {
);
}

#[cfg(not(feature = "disable-runtime-api"))]
sp_api::impl_runtime_apis! {
impl sp_api::Core<Block> for Runtime {
fn version() -> RuntimeVersion {
Expand Down

0 comments on commit c494b17

Please sign in to comment.