Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

Ensure slot number is strictly increasing #41

Conversation

JoshOrndorff
Copy link
Contributor

This PR adds a simple storage item and validation check that ensures the slot number associated with each block is always strictly greater than the previous highest slot number in this chain.

Nimbus has always assumed this invariant to be true, but has not enforced it. In the parachain context, we are guaranteed increasing slot numbers because we use the relay chain parent number which is always strictly increasing. But in other contexts, nimbus will need to ensure this manually. (Plus nimbus should ensure it manually anyways in case the design of cumulus ever changes without warning.)

This works toward #1 and #3

@4meta5
Copy link
Contributor

4meta5 commented Apr 4, 2022

we are guaranteed increasing slot numbers because we use the relay chain parent number which is always strictly increasing

asynchronous backing will remove this guarantee such that there may be multiple parachain blocks for a single relay chain parent block

Copy link
Contributor

@4meta5 4meta5 left a comment

Choose a reason for hiding this comment

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

We can change > to >= when asynchronous backing is included

@4meta5 4meta5 merged commit fc2209b into moonbeam-foundation:main Apr 7, 2022
@4meta5
Copy link
Contributor

4meta5 commented Apr 7, 2022

Thanks @JoshOrndorff !

let author = <Author<T>>::get()
.expect("Block invalid, no authorship information supplied in preruntime digest.");

assert!(
T::CanAuthor::can_author(&author, &T::SlotBeacon::slot()),
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
T::CanAuthor::can_author(&author, &T::SlotBeacon::slot()),
T::CanAuthor::can_author(&author, &slot),

Copy link
Contributor

Choose a reason for hiding this comment

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

just missed this, not sure how much better it is

@notlesh
Copy link
Contributor

notlesh commented Apr 7, 2022

We should bump the weight returned by on_initialize() to reflect the extra read/write here.

@4meta5 4meta5 mentioned this pull request Apr 7, 2022
1 task
@JoshOrndorff
Copy link
Contributor Author

JoshOrndorff commented Apr 8, 2022

Rob gives some options for how to address asynchronous backing in paritytech/polkadot#3779 (comment)

I had also considered a notion of slot that is derived from both the relay block number and parachain block number, maybe k * relay_height + para_height % k

Maybe that's similar to his idea # 3

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants