-
Notifications
You must be signed in to change notification settings - Fork 371
Practical crosschain interaction #206
Description
Not sure if this is the best place for this, but post here anyway.
I am currently designing how to make a parachain act as a staking pool, which will have the requirement of sending upward message, and query relaychain storages.
Sending upward message is mostly working now so that's good.
We don't have much light currently on how the reading storages is going to work.
To implement the staking liquidity protocol, we need to query many different storages from relaychain, includes
- account balances
- we will have handful of staking accounts and only interest about balances for those accounts
- pallet-staking storages
- validator list
- staking ledger
- slashes
- era information
- pallet-democracy storages
- ongoing referendum indices
- maybe bunch more like pallet-collectives etc
AFAIK, there won't be any direct cross-chain storage read ability, instead we need a relayer (possible implemented with offchain-worker) to relay relaychain storage to parachain using extrinsic, which will include a storage proof to allow parachian runtime to verify storage.
So the extrinsic will be something like
fn update_relaychain_state(origin, values: Vec<(StorageKey, StorageValue)>, proof: StroageProof)
But in practice, this is really hard to use. We need to reimplement something decl_storage does to parse and decode the key, decode the value, generate a suitable Rust interface for consumption. It is definitely doable, but a lot of work.
I would like to explorer if it is possible to reuse decl_storage to handle the decoding & type generation.
So basically in update_relaychain_state, after verification, it directly write the key value pairs into a child storage, or replace / rehash the prefix and write to storage directly.
Next step is basically redeclare the storages / import storages from relaychain runtime and we will be able to access them normally.
But there are still few more questions:
- How to ensure relayer don't relay unnecessary information?
- I guess a prefix whitelist combined with custom checker can do
- How to ensure the data is not outdated?
- The easy way is storage last updated block, and make transactions depending on relaychain fail if last updated was too long ago. People can them relayer the information themself and continue transact. But we probably wants a better way.
- How to efficiently relay the state?
- Is it possible to generate a change trie for a subset of prefix so only the change needs to be relayed?
- How to handle storage migration on relaychain runtime?