-
Notifications
You must be signed in to change notification settings - Fork 379
introduce a method for fetching relay chain header to RelayChainInterface
#2794
introduce a method for fetching relay chain header to RelayChainInterface
#2794
Conversation
Yeah my use case requires block numbers |
@@ -110,6 +111,9 @@ pub trait RelayChainInterface: Send + Sync { | |||
/// Get the hash of the current best block. | |||
async fn best_block_hash(&self) -> RelayChainResult<PHash>; | |||
|
|||
/// Fetch the block header of a given height | |||
async fn header(&self, block_id: BlockId) -> RelayChainResult<Option<PHeader>>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use PHash
. No new BlockId
in public interfaces anymore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But i specifically need to query using BlockNumber
, any reason for this?
No new BlockId in public interfaces anymore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Block numbers should only be used in places where there is no other way around them. Block numbers are not ambiguous. Some interfaces (like RPC/CLI) still require block numbers, but most "internal code" can be rewritten in a way to use hashes. E.g. get the header of block X and then go back using parent_hash()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But i specifically need to query using BlockNumber, any reason for this?
The use case here is on-chain code which wishes to read the relay chain, they signal a request given a specific relay chain height (parachains don't have access to the relay chain blockhashes). So hence the BlockId
here.
Doesn't seem like there's any alternatives here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And how does the parachain validates the relay chain headers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't need the header, it has the state_root
from PersistedValidationData
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The use case here is on-chain code which wishes to read the relay chain, they signal a request given a specific relay chain height (parachains don't have access to the relay chain blockhashes).
You say it signals which relay chain header it wants to read. So you are just wanting to get the header to get the storage root?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, when we got: https://github.com/paritytech/cumulus/issues/303
This can be changed.
@@ -110,6 +111,9 @@ pub trait RelayChainInterface: Send + Sync { | |||
/// Get the hash of the current best block. | |||
async fn best_block_hash(&self) -> RelayChainResult<PHash>; | |||
|
|||
/// Fetch the block header of a given height | |||
async fn header(&self, block_id: BlockId) -> RelayChainResult<Option<PHeader>>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, when we got: https://github.com/paritytech/cumulus/issues/303
This can be changed.
This shouldn't have been merged as-is - the interface was changed to |
By "opaque error" you mean that it is a string error? |
Will do a follow up |
follow up: #2830 |
This is particularly useful for fetching arbitrary relay chain headers within inherents.