difftreelog
fix relay can't do root ops
in: master
4 files changed
js-packages/tests/xcm/lowLevelXcmQuartz.test.tsdiffbeforeafterboth299 });299 });300});300});301302describeXCM('[XCMLL] Integration test: The relay can do some root ops', () => {303 let sudoer: IKeyringPair;304305 before(async function () {306 await usingRelayPlaygrounds(relayUrl, async (_, privateKey) => {307 sudoer = await privateKey('//Alice');308 });309 });310311 // At the moment there is no reliable way312 // to establish the correspondence between the `ExecutedDownward` event313 // and the relay's sent message due to `SetTopic` instruction314 // containing an unpredictable topic silently added by the relay's messages on the router level.315 // This changes the message hash on arrival to our chain.316 //317 // See:318 // * The relay's router: https://github.com/paritytech/polkadot-sdk/blob/f60318f68687e601c47de5ad5ca88e2c3f8139a7/polkadot/runtime/westend/src/xcm_config.rs#L83319 // * The `WithUniqueTopic` helper: https://github.com/paritytech/polkadot-sdk/blob/945ebbbcf66646be13d5b1d1bc26c8b0d3296d9e/polkadot/xcm/xcm-builder/src/routing.rs#L36320 //321 // Because of this, we insert time gaps between tests so322 // different `ExecutedDownward` events won't interfere with each other.323 afterEach(async () => {324 await usingPlaygrounds(async (helper) => {325 await helper.wait.newBlocks(3);326 });327 });328329 itSub('The relay can set storage', async () => {330 await testHelper.relayIsPermittedToSetStorage(sudoer, 'plain');331 });332333 itSub('The relay can batch set storage', async () => {334 await testHelper.relayIsPermittedToSetStorage(sudoer, 'batch');335 });336337 itSub('The relay can batchAll set storage', async () => {338 await testHelper.relayIsPermittedToSetStorage(sudoer, 'batchAll');339 });340341 itSub('The relay can forceBatch set storage', async () => {342 await testHelper.relayIsPermittedToSetStorage(sudoer, 'forceBatch');343 });344345 itSub('[negative] The relay cannot set balance', async () => {346 await testHelper.relayIsNotPermittedToSetBalance(sudoer, 'plain');347 });348349 itSub('[negative] The relay cannot set balance via batch', async () => {350 await testHelper.relayIsNotPermittedToSetBalance(sudoer, 'batch');351 });352353 itSub('[negative] The relay cannot set balance via batchAll', async () => {354 await testHelper.relayIsNotPermittedToSetBalance(sudoer, 'batchAll');355 });356357 itSub('[negative] The relay cannot set balance via forceBatch', async () => {358 await testHelper.relayIsNotPermittedToSetBalance(sudoer, 'forceBatch');359 });360361 itSub('[negative] The relay cannot set balance via dispatchAs', async () => {362 await testHelper.relayIsNotPermittedToSetBalance(sudoer, 'dispatchAs');363 });364});365301js-packages/tests/xcm/lowLevelXcmUnique.test.tsdiffbeforeafterboth365 });365 });366});366});367368describeXCM('[XCMLL] Integration test: The relay can do some root ops', () => {369 let sudoer: IKeyringPair;370371 before(async function () {372 await usingRelayPlaygrounds(relayUrl, async (_, privateKey) => {373 sudoer = await privateKey('//Alice');374 });375 });376377 // At the moment there is no reliable way378 // to establish the correspondence between the `ExecutedDownward` event379 // and the relay's sent message due to `SetTopic` instruction380 // containing an unpredictable topic silently added by the relay's messages on the router level.381 // This changes the message hash on arrival to our chain.382 //383 // See:384 // * The relay's router: https://github.com/paritytech/polkadot-sdk/blob/f60318f68687e601c47de5ad5ca88e2c3f8139a7/polkadot/runtime/westend/src/xcm_config.rs#L83385 // * The `WithUniqueTopic` helper: https://github.com/paritytech/polkadot-sdk/blob/945ebbbcf66646be13d5b1d1bc26c8b0d3296d9e/polkadot/xcm/xcm-builder/src/routing.rs#L36386 //387 // Because of this, we insert time gaps between tests so388 // different `ExecutedDownward` events won't interfere with each other.389 afterEach(async () => {390 await usingPlaygrounds(async (helper) => {391 await helper.wait.newBlocks(3);392 });393 });394395 itSub('The relay can set storage', async () => {396 await testHelper.relayIsPermittedToSetStorage(sudoer, 'plain');397 });398399 itSub('The relay can batch set storage', async () => {400 await testHelper.relayIsPermittedToSetStorage(sudoer, 'batch');401 });402403 itSub('The relay can batchAll set storage', async () => {404 await testHelper.relayIsPermittedToSetStorage(sudoer, 'batchAll');405 });406407 itSub('The relay can forceBatch set storage', async () => {408 await testHelper.relayIsPermittedToSetStorage(sudoer, 'forceBatch');409 });410411 itSub('[negative] The relay cannot set balance', async () => {412 await testHelper.relayIsNotPermittedToSetBalance(sudoer, 'plain');413 });414415 itSub('[negative] The relay cannot set balance via batch', async () => {416 await testHelper.relayIsNotPermittedToSetBalance(sudoer, 'batch');417 });418419 itSub('[negative] The relay cannot set balance via batchAll', async () => {420 await testHelper.relayIsNotPermittedToSetBalance(sudoer, 'batchAll');421 });422423 itSub('[negative] The relay cannot set balance via forceBatch', async () => {424 await testHelper.relayIsNotPermittedToSetBalance(sudoer, 'forceBatch');425 });426427 itSub('[negative] The relay cannot set balance via dispatchAs', async () => {428 await testHelper.relayIsNotPermittedToSetBalance(sudoer, 'dispatchAs');429 });430});431367js-packages/tests/xcm/xcm.types.tsdiffbeforeafterboth506 });506 });507 }507 }508509 private async _relayXcmTransactSetStorage(variant: 'plain' | 'batch' | 'batchAll' | 'forceBatch') {510 // eslint-disable-next-line require-await511 return await usingPlaygrounds(async (helper) => {512 const relayForceKV = () => {513 const random = Math.random();514 const key = `relay-forced-key (instance: ${random})`;515 const val = `relay-forced-value (instance: ${random})`;516 const call = helper.constructApiCall('api.tx.system.setStorage', [[[key, val]]]).method.toHex();517518 return {519 call,520 key,521 val,522 };523 };524525 if(variant == 'plain') {526 const kv = relayForceKV();527 return {528 program: helper.arrange.makeUnpaidSudoTransactProgram({529 weightMultiplier: 1,530 call: kv.call,531 }),532 kvs: [kv],533 };534 } else {535 const kv0 = relayForceKV();536 const kv1 = relayForceKV();537538 const batchCall = helper.constructApiCall(`api.tx.utility.${variant}`, [[kv0.call, kv1.call]]).method.toHex();539 return {540 program: helper.arrange.makeUnpaidSudoTransactProgram({541 weightMultiplier: 2,542 call: batchCall,543 }),544 kvs: [kv0, kv1],545 };546 }547 });548 }549550 async relayIsPermittedToSetStorage(relaySudoer: IKeyringPair, variant: 'plain' | 'batch' | 'batchAll' | 'forceBatch') {551 const {program, kvs} = await this._relayXcmTransactSetStorage(variant);552553 await usingRelayPlaygrounds(relayUrl, async (helper) => {554 await helper.getSudo().executeExtrinsic(relaySudoer, 'api.tx.xcmPallet.send', [555 this._uniqueChainMultilocationForRelay(),556 program,557 ]);558 });559560 await usingPlaygrounds(async (helper) => {561 await expectDownwardXcmComplete(helper);562563 for(const kv of kvs) {564 const forcedValue = await helper.callRpc('api.rpc.state.getStorage', [kv.key]);565 expect(hexToString(forcedValue.toHex())).to.be.equal(kv.val);566 }567 });568 }569570 private async _relayXcmTransactSetBalance(variant: 'plain' | 'batch' | 'batchAll' | 'forceBatch' | 'dispatchAs') {571 // eslint-disable-next-line require-await572 return await usingPlaygrounds(async (helper) => {573 const emptyAccount = helper.arrange.createEmptyAccount().address;574575 const forceSetBalanceCall = helper.constructApiCall('api.tx.balances.forceSetBalance', [emptyAccount, 10_000n]).method.toHex();576577 let call;578579 if(variant == 'plain') {580 call = forceSetBalanceCall;581582 } else if(variant == 'dispatchAs') {583 call = helper.constructApiCall('api.tx.utility.dispatchAs', [584 {585 system: 'Root',586 },587 forceSetBalanceCall,588 ]).method.toHex();589 } else {590 call = helper.constructApiCall(`api.tx.utility.${variant}`, [[forceSetBalanceCall]]).method.toHex();591 }592593 return {594 program: helper.arrange.makeUnpaidSudoTransactProgram({595 weightMultiplier: 1,596 call,597 }),598 emptyAccount,599 };600 });601 }602603 async relayIsNotPermittedToSetBalance(604 relaySudoer: IKeyringPair,605 variant: 'plain' | 'batch' | 'batchAll' | 'forceBatch' | 'dispatchAs',606 ) {607 const {program, emptyAccount} = await this._relayXcmTransactSetBalance(variant);608609 await usingRelayPlaygrounds(relayUrl, async (helper) => {610 await helper.getSudo().executeExtrinsic(relaySudoer, 'api.tx.xcmPallet.send', [611 this._uniqueChainMultilocationForRelay(),612 program,613 ]);614 });615616 await usingPlaygrounds(async (helper) => {617 await expectDownwardXcmNoPermission(helper);618 expect(await helper.balance.getSubstrate(emptyAccount)).to.be.equal(0n);619 });620 }621}508}622509runtime/common/config/xcm/mod.rsdiffbeforeafterboth17use cumulus_primitives_core::ParaId;17use cumulus_primitives_core::ParaId;18use frame_support::{18use frame_support::{19 parameter_types,19 parameter_types,20 traits::{ConstU32, Contains, Everything, Get, Nothing, ProcessMessageError},20 traits::{ConstU32, Everything, Get, Nothing, ProcessMessageError},21};21};22use frame_system::EnsureRoot;22use frame_system::EnsureRoot;23use pallet_xcm::XcmPassthrough;23use pallet_xcm::XcmPassthrough;29 v3::Instruction,29 v3::Instruction,30};30};31use staging_xcm_builder::{31use staging_xcm_builder::{32 AccountId32Aliases, EnsureXcmOrigin, FixedWeightBounds, ParentAsSuperuser, ParentIsPreset,32 AccountId32Aliases, EnsureXcmOrigin, FixedWeightBounds, ParentIsPreset, RelayChainAsNative,33 RelayChainAsNative, SiblingParachainAsNative, SiblingParachainConvertsVia,33 SiblingParachainAsNative, SiblingParachainConvertsVia, SignedAccountId32AsNative,34 SignedAccountId32AsNative, SignedToAccountId32, SovereignSignedViaLocation,34 SignedToAccountId32, SovereignSignedViaLocation,35};35};111 // Native converter for sibling Parachains; will convert to a `SiblingPara` origin when111 // Native converter for sibling Parachains; will convert to a `SiblingPara` origin when112 // recognised.112 // recognised.113 SiblingParachainAsNative<cumulus_pallet_xcm::Origin, RuntimeOrigin>,113 SiblingParachainAsNative<cumulus_pallet_xcm::Origin, RuntimeOrigin>,114 // Superuser converter for the Relay-chain (Parent) location. This will allow it to issue a115 // transaction from the Root origin.116 ParentAsSuperuser<RuntimeOrigin>,117 // Native signed account converter; this just converts an `AccountId32` origin into a normal114 // Native signed account converter; this just converts an `AccountId32` origin into a normal118 // `Origin::Signed` origin of the same 32-byte value.115 // `Origin::Signed` origin of the same 32-byte value.119 SignedAccountId32AsNative<RelayNetwork, RuntimeOrigin>,116 SignedAccountId32AsNative<RelayNetwork, RuntimeOrigin>,167164168pub type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;165pub type Weigher = FixedWeightBounds<UnitWeightCost, RuntimeCall, MaxInstructions>;169170pub struct XcmCallFilter;171impl XcmCallFilter {172 fn allow_gov_and_sys_call(call: &RuntimeCall) -> bool {173 match call {174 RuntimeCall::System(..) => true,175176 #[cfg(feature = "governance")]177 RuntimeCall::Identity(..)178 | RuntimeCall::Preimage(..)179 | RuntimeCall::Democracy(..)180 | RuntimeCall::Council(..)181 | RuntimeCall::TechnicalCommittee(..)182 | RuntimeCall::CouncilMembership(..)183 | RuntimeCall::TechnicalCommitteeMembership(..)184 | RuntimeCall::FellowshipCollective(..)185 | RuntimeCall::FellowshipReferenda(..) => true,186 _ => false,187 }188 }189190 fn allow_utility_call(call: &RuntimeCall) -> bool {191 match call {192 RuntimeCall::Utility(pallet_utility::Call::batch { calls, .. }) => {193 calls.iter().all(Self::allow_gov_and_sys_call)194 }195 RuntimeCall::Utility(pallet_utility::Call::batch_all { calls, .. }) => {196 calls.iter().all(Self::allow_gov_and_sys_call)197 }198 RuntimeCall::Utility(pallet_utility::Call::as_derivative { call, .. }) => {199 Self::allow_gov_and_sys_call(call)200 }201 RuntimeCall::Utility(pallet_utility::Call::dispatch_as { call, .. }) => {202 Self::allow_gov_and_sys_call(call)203 }204 RuntimeCall::Utility(pallet_utility::Call::force_batch { calls, .. }) => {205 calls.iter().all(Self::allow_gov_and_sys_call)206 }207 _ => false,208 }209 }210}211212impl Contains<RuntimeCall> for XcmCallFilter {213 fn contains(call: &RuntimeCall) -> bool {214 Self::allow_gov_and_sys_call(call) || Self::allow_utility_call(call)215 }216}217166218pub struct XcmExecutorConfig<T>(PhantomData<T>);167pub struct XcmExecutorConfig<T>(PhantomData<T>);219impl<T> staging_xcm_executor::Config for XcmExecutorConfig<T>168impl<T> staging_xcm_executor::Config for XcmExecutorConfig<T>244 type MessageExporter = ();193 type MessageExporter = ();245 type UniversalAliases = Nothing;194 type UniversalAliases = Nothing;246 type CallDispatcher = RuntimeCall;195 type CallDispatcher = RuntimeCall;247 type SafeCallFilter = XcmCallFilter;196 type SafeCallFilter = Nothing;248 type Aliasers = Nothing;197 type Aliasers = Nothing;249}198}250199