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

Add a way to fetch the relay state proof #4612

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions cumulus/pallets/parachain-system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1694,12 +1694,23 @@ pub trait RelaychainStateProvider {
/// **NOTE**: This is not guaranteed to return monotonically increasing relay parents.
fn current_relay_chain_state() -> RelayChainState;

/// May be called by any runtime module to obtain the current state proof for well known keys.
///
fn current_relay_state_proof() -> Option<sp_trie::StorageProof>;

/// Utility function only to be used in benchmarking scenarios, to be implemented optionally,
/// else a noop.
///
/// It allows for setting a custom RelayChainState.
#[cfg(feature = "runtime-benchmarks")]
fn set_current_relay_chain_state(_state: RelayChainState) {}

/// Utility function only to be used in benchmarking scenarios, to be implemented optionally,
/// else a noop.
///
/// It allows for setting a custom StorageProof.
#[cfg(feature = "runtime-benchmarks")]
fn set_current_relay_state_proof(_proof: sp_trie::StorageProof) {}
}

/// Implements [`BlockNumberProvider`] that returns relay chain block number fetched from validation
Expand Down Expand Up @@ -1757,6 +1768,10 @@ impl<T: Config> RelaychainStateProvider for RelaychainDataProvider<T> {
.unwrap_or_default()
}

fn current_relay_state_proof() -> Option<sp_trie::StorageProof> {
RelayStateProof::<T>::get()
}

#[cfg(feature = "runtime-benchmarks")]
fn set_current_relay_chain_state(state: RelayChainState) {
let mut validation_data = ValidationData::<T>::get().unwrap_or_else(||
Expand All @@ -1771,4 +1786,9 @@ impl<T: Config> RelaychainStateProvider for RelaychainDataProvider<T> {
validation_data.relay_parent_storage_root = state.state_root;
ValidationData::<T>::put(validation_data)
}

#[cfg(feature = "runtime-benchmarks")]
fn set_current_relay_state_proof(proof: sp_trie::StorageProof) {
RelayStateProof::<T>::put(proof)
}
}
Loading