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

expose the last relay chain block number as an API from parachain-system #1761

Merged
merged 3 commits into from
Oct 3, 2023
Merged
Changes from 2 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
18 changes: 11 additions & 7 deletions cumulus/pallets/parachain-system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,10 @@ pub mod pallet {
<UpgradeRestrictionSignal<T>>::kill();
let relay_upgrade_go_ahead = <UpgradeGoAhead<T>>::take();

assert!(
<ValidationData<T>>::exists(),
"set_validation_data inherent needs to be present in every block!"
);
let vfp = <ValidationData<T>>::get()
.expect("set_validation_data inherent needs to be present in every block!");

LastRelayChainBlockNumber::<T>::put(vfp.relay_parent_number);

let host_config = match Self::host_configuration() {
Some(ok) => ok,
Expand Down Expand Up @@ -380,8 +380,7 @@ pub mod pallet {
let ancestor = Ancestor::new_unchecked(used_bandwidth, consumed_go_ahead_signal);

let watermark = HrmpWatermark::<T>::get();
let watermark_update =
HrmpWatermarkUpdate::new(watermark, LastRelayChainBlockNumber::<T>::get());
let watermark_update = HrmpWatermarkUpdate::new(watermark, vfp.relay_parent_number);

aggregated_segment
.append(&ancestor, watermark_update, &total_bandwidth_out)
Expand Down Expand Up @@ -460,6 +459,9 @@ pub mod pallet {
4 + hrmp_max_message_num_per_candidate as u64,
);

// Weight for updating the last relay chain block number in `on_finalize`.
weight += T::DbWeight::get().reads_writes(1, 1);

// Weight for adjusting the unincluded segment in `on_finalize`.
weight += T::DbWeight::get().reads_writes(6, 3);

Expand Down Expand Up @@ -515,7 +517,6 @@ pub mod pallet {
vfp.relay_parent_number,
LastRelayChainBlockNumber::<T>::get(),
);
LastRelayChainBlockNumber::<T>::put(vfp.relay_parent_number);

let relay_state_proof = RelayChainStateProof::new(
T::SelfParaId::get(),
Expand Down Expand Up @@ -756,7 +757,10 @@ pub mod pallet {
pub(super) type DidSetValidationCode<T: Config> = StorageValue<_, bool, ValueQuery>;

/// The relay chain block number associated with the last parachain block.
///
/// This is updated in `on_finalize`.
KiChjang marked this conversation as resolved.
Show resolved Hide resolved
#[pallet::storage]
#[pallet::getter(fn last_relay_block_number)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given this, we probably should implement a dedicated function.

pub(super) type LastRelayChainBlockNumber<T: Config> =
StorageValue<_, RelayChainBlockNumber, ValueQuery>;

Expand Down
Loading