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

Always author in first slot of new round #704

Merged
merged 3 commits into from
Aug 19, 2021
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions runtime/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@ version = '0.8.0-dev'
authors = ["PureStake"]
edition = '2018'

[dependencies]
log = "0.4"

[features]
std = []
27 changes: 23 additions & 4 deletions runtime/common/src/apis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,20 +351,39 @@ macro_rules! impl_runtime_apis_plus_common {
slot: u32,
parent_header: &<Block as BlockT>::Header
) -> bool {
let block_number = parent_header.number + 1;

// The Moonbeam runtimes use an entropy source that needs to do some accounting
// work during block initialization. Therefore we initialize it here to match
// the state it will be in when the next block is being executed.
use frame_support::traits::OnInitialize;
System::initialize(
&(parent_header.number + 1),
&block_number,
&parent_header.hash(),
&parent_header.digest,
frame_system::InitKind::Inspection
);
RandomnessCollectiveFlip::on_initialize(System::block_number());
RandomnessCollectiveFlip::on_initialize(block_number);

// Because the staking solution calculates the next staking set at the beginning
// of the first block in the new round, the only way to accurately predict the
// authors would be to run the staking election while predicting. However this
// election is heavy and will take too long during prediction. So instead we
// work around it by always authoring the first slot in a new round. A longer-
// term solution will be to calculate the staking election result in the last
// block of the ending round.
if parachain_staking::Pallet::<Self>::round().should_update(block_number) {
log::info!(target: "nimbus-staking-workaround", "A new round is starting.\
Moonbeam will author during this slot without predicting eligibility first.\
You may see a `CannotBeAuthor` error soon. This is expected and harmless.\
It will be resolved soon.");

true
}
else {
AuthorInherent::can_author(&author, &slot)
JoshOrndorff marked this conversation as resolved.
Show resolved Hide resolved

// And now the actual prediction call
AuthorInherent::can_author(&author, &slot)
}
}
}

Expand Down