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

Fix round changes #867

Merged
merged 2 commits into from
Oct 22, 2022
Merged
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
31 changes: 27 additions & 4 deletions runtime/calamari/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1023,10 +1023,33 @@ impl_runtime_apis! {

impl nimbus_primitives::NimbusApi<Block> for Runtime {
fn can_author(author: NimbusId, relay_parent: u32, parent_header: &<Block as BlockT>::Header) -> bool {
System::initialize(&(parent_header.number + 1), &parent_header.hash(), &parent_header.digest);

// And now the actual prediction call
<AuthorInherent as nimbus_primitives::CanAuthor<_>>::can_author(&author, &relay_parent)
let next_block_number = parent_header.number + 1;
let slot = relay_parent;
// 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 is to compute the selection during prediction.
// NOTE: This logic must manually be kept in sync with the nimbus filter pipeline
if pallet_parachain_staking::Pallet::<Self>::round().should_update(next_block_number)
{
// lookup account from nimbusId
// mirrors logic in `pallet_author_inherent`
use nimbus_primitives::AccountLookup;
let account = match manta_collator_selection::Pallet::<Self>::lookup_account(&author) {
Some(account) => account,
// Authors whose account lookups fail will not be eligible
None => {
return false;
}
};
// manually check aura eligibility (in the new round)
// mirrors logic in `aura_style_filter`
let truncated_half_slot = (slot >> 1) as usize;
let active: Vec<AccountId> = pallet_parachain_staking::Pallet::<Self>::compute_top_candidates();
zqhxuyuan marked this conversation as resolved.
Show resolved Hide resolved
account == active[truncated_half_slot % active.len()]
} else {
// We're not changing rounds, `PotentialAuthors` is not changing, just use can_author
<AuthorInherent as nimbus_primitives::CanAuthor<_>>::can_author(&author, &relay_parent)
}
}
}

Expand Down