1

The title is quite self-explanatory, how can i get the blocknumber of the relay chain I'm connected to (Kusama) instead of my local blocknumber ?

All of this in a substrate/cumulus environment

Nathan
  • 493
  • 1
  • 3
  • 13
  • From https://github.com/paritytech/cumulus/pull/279 and https://github.com/paritytech/cumulus/issues/320 my guess is that this is not currently possible and you can only read specific keys from the relay-chain into the parachain, as noted in https://paritytech.github.io/cumulus/cumulus_primitives_core/relay_chain/v2/well_known_keys/index.html – kianenigma Jul 07 '22 at 09:47
  • Just a tip: https://substrate.stackexchange.com/ is far more active for questions like this – Nuke Jul 21 '22 at 13:21

1 Answers1

4

I assume that you mean not Substrate, but Cumulus, to be specific, since you are talking about parachains.

Cumulus parachains' runtimes receive the so called PersistedValidationData from the collators. It has several pieces of information passed by the relay-chain. It does include relay_parent_number. That is the relay chain block number from which the parachain block in question was created.

In a cumulus parachain runtime, PersistedValidationData can be accessed through the validation_data getter.

Be advised, this data is submitted by a collator in an inherent. That means, among other things, this data is not available in the on_initialize hooks.

pepyakin
  • 2,217
  • 19
  • 31
  • Okay, i see, so the solution would be to either do what i want in `on_finalize()` (i do a lot of transactions), or save the blocknumber when `on_finalize()` and read it in `on_initialize()` to do what i have to.. What do you think ? – Nathan Jul 07 '22 at 12:43
  • There are several things you can do. One of them is to set the callback OnSystemEvent https://paritytech.github.io/cumulus/cumulus_pallet_parachain_system/pallet/trait.Config.html . That would allow you to execute some code just right after the validation data is set – pepyakin Jul 08 '22 at 09:59
  • Another option is to introduce your own inherent that executes after the parachain-system’s one. – pepyakin Jul 08 '22 at 10:01