Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[xcm-emulator] Add on_initialize and on_finalize hooks #1384

Open
Tracked by #50
NachoPal opened this issue Sep 4, 2023 · 4 comments · May be fixed by #2007
Open
Tracked by #50

[xcm-emulator] Add on_initialize and on_finalize hooks #1384

NachoPal opened this issue Sep 4, 2023 · 4 comments · May be fixed by #2007
Assignees
Labels
T6-XCM This PR/Issue is related to XCM.

Comments

@NachoPal
Copy link
Contributor

NachoPal commented Sep 4, 2023

More info here: paritytech/cumulus#2734

@0xmovses 0xmovses self-assigned this Oct 24, 2023
@0xmovses
Copy link
Contributor

Picking this up

@NachoPal
Copy link
Contributor Author

NachoPal commented Oct 24, 2023

@0xmovses Ok, I had something in mind already.

The idea is to expand decl_test_relay_chains and decl_test_parachains adding on_initialize and on_finalize attributes. And probably to rename on_init to on_genesis as it could now be confused with on_initialize. Something like this:

decl_test_parachains! {
	pub struct AssetHub {
		genesis = genesis(),
		on_genesis = {
			asset_hub_kusama_runtime::AuraExt::on_initialize(1);
		},
		runtime = asset_hub_kusama_runtime,
		core = {
			XcmpMessageHandler: asset_hub_kusama_runtime::XcmpQueue,
			DmpMessageHandler: asset_hub_kusama_runtime::DmpQueue,
			LocationToAccountId: asset_hub_kusama_runtime::xcm_config::LocationToAccountId,
			ParachainInfo: asset_hub_kusama_runtime::ParachainInfo,
		},
		pallets = {
			PolkadotXcm: asset_hub_kusama_runtime::PolkadotXcm,
			Assets: asset_hub_kusama_runtime::Assets,
			ForeignAssets: asset_hub_kusama_runtime::ForeignAssets,
			PoolAssets: asset_hub_kusama_runtime::PoolAssets,
			AssetConversion: asset_hub_kusama_runtime::AssetConversion,
			Balances: asset_hub_kusama_runtime::Balances,
		},
		on_initialize = // Accepts a function that is expecting `BlockNumber` as argument
		on_finalize = // Accepts a function that is expecting `BlockNumber` as argument,
	},
}

Maybe just init instead of on_genesis. I am not fully convinced about the naming.

@NachoPal
Copy link
Contributor Author

NachoPal commented Oct 24, 2023

Actually on_initialize and on_finalize should be a function that is expecting a BlockNumber only an argument.

Inside the function, individual calls to each selected pallets on_initialize/on_finalize calls would be added.

For Parachains BlockNumber is coming from:

  • parachains_common::BlockNumber;
    For RelayChains BlockNumber is coming from:
  • cumulus_primitives_core::relay_chain::{BlockNumber as RelayBlockNumber}

The block numbers can be queried in xcm-emulator. It would be something like:

  • <Self as $crate::Chain>::System::block_number(); (for Parachain)
  • N::relay_block_number() (for RelayChain)

@franciscoaguirre franciscoaguirre added the T6-XCM This PR/Issue is related to XCM. label Mar 25, 2024
@ntn-x2
Copy link

ntn-x2 commented May 10, 2024

Hey, I would like to pick up on this issue for a reason:

For Parachains BlockNumber is coming from:
parachains_common::BlockNumber;

as done in

<<Self as Parachain>::ParachainSystem as Hooks<$crate::BlockNumber>>::on_initialize(block_number);

This represents a problem for parachains that use a different type for block numbers, e.g. a u64. We cannot update to Polkadot SDK 1.1 because of this issue that leads to compilation errors for XCM Emulator. BlockNumber should be taken from the implementation of the frame_system pallet rather. Should I open a different issue for it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T6-XCM This PR/Issue is related to XCM.
Projects
None yet
4 participants