Skip to content

Commit

Permalink
Add a way to fetch the relay state proof
Browse files Browse the repository at this point in the history
  • Loading branch information
girazoki committed May 30, 2024
1 parent c4c5012 commit e9d3cc3
Showing 1 changed file with 28 additions and 8 deletions.
36 changes: 28 additions & 8 deletions cumulus/pallets/parachain-system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ pub mod pallet {
false,
"host configuration is promised to set until `on_finalize`; qed",
);
return
return;
},
};

Expand All @@ -289,7 +289,7 @@ pub mod pallet {
"relevant messaging state is promised to be set until `on_finalize`; \
qed",
);
return
return;
},
};

Expand All @@ -310,7 +310,7 @@ pub mod pallet {
"relevant messaging state is promised to be set until `on_finalize`; \
qed",
);
return (0, 0)
return (0, 0);
},
};

Expand Down Expand Up @@ -971,11 +971,11 @@ pub mod pallet {
provides: vec![hash.as_ref().to_vec()],
longevity: TransactionLongevity::max_value(),
propagate: true,
})
});
}
}
if let Call::set_validation_data { .. } = call {
return Ok(Default::default())
return Ok(Default::default());
}
Err(InvalidTransaction::Call.into())
}
Expand Down Expand Up @@ -1040,7 +1040,7 @@ impl<T: Config> GetChannelInfo for Pallet<T> {
let channels = match RelevantMessagingState::<T>::get() {
None => {
log::warn!("calling `get_channel_status` with no RelevantMessagingState?!");
return ChannelStatus::Closed
return ChannelStatus::Closed;
},
Some(d) => d.egress_channels,
};
Expand All @@ -1057,7 +1057,7 @@ impl<T: Config> GetChannelInfo for Pallet<T> {
let meta = &channels[index].1;
if meta.msg_count + 1 > meta.max_capacity {
// The channel is at its capacity. Skip it for now.
return ChannelStatus::Full
return ChannelStatus::Full;
}
let max_size_now = meta.max_total_size - meta.total_size;
let max_size_ever = meta.max_message_size;
Expand Down Expand Up @@ -1560,7 +1560,7 @@ impl<T: Config> Pallet<T> {
// However, changing this setting is expected to be rare.
if let Some(cfg) = HostConfiguration::<T>::get() {
if message_len > cfg.max_upward_message_size as usize {
return Err(MessageSendError::TooBig)
return Err(MessageSendError::TooBig);
}
let threshold =
cfg.max_upward_queue_size.saturating_div(ump_constants::THRESHOLD_FACTOR);
Expand Down Expand Up @@ -1681,12 +1681,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 @@ -1744,6 +1755,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 @@ -1758,4 +1773,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)
}
}

0 comments on commit e9d3cc3

Please sign in to comment.