-
Notifications
You must be signed in to change notification settings - Fork 1k
track authorities from aura digests #9272
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
Conversation
All GitHub workflows were cancelled due to failure one of the required jobs. |
/cmd prdoc --audience node_dev --audience node_operator --bump patch |
…e_dev --audience node_operator --bump patch'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need the same changes also for
impl<P, Client, Block, CIDP> VerifierT<Block> for Verifier<P, Client, Block, CIDP> |
Are you planning to do this in a follow up? Also It would be really cool to have some tests introduced for this.
Yes and no - the follow up will be moving the authorities tracking code (and related equivocation checks and the inherents checks) into the import queue. At that point the code you linked will not need any changes (other than removing code). So I decided to not change that verifier at all in this PR. Let me know if you disagree - it's possible I'm missing something. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks nice!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! 🚀
Maybe we could add a few tiny tests to ensure we captured the authorities in the tracker, but offhand that seems quite involved
Have a question, can't say that I am 100% on top of the full picture, but saw this comment from Basti in the associated issue:
Was this done? I can't remember. If no, should it be still done (maybe in this PR if yes)? |
I think this update will be relevant for parachain-template too (besides omni-node). Might be worth verifying both at the time it is done. |
Yes sir - this was done way before. (This predates me 😄). |
Seems that I misread the comment then. I think this corresponds to babe equivalent Basti linked: polkadot-sdk/substrate/frame/aura/src/lib.rs Line 197 in 7ecf3f7
|
Also, here's a test for this: 251544c. I think this is a nice solution, it's simple because it doesn't add a new zombienet test (CI is slow enough as it is 😄) but it does check that 1) authorities are fetched from the runtime exactly once and 2) they are fetched from the cache many times, and since the sync proceeds without errors this proves that we must be tracking authorities correctly. |
Test lgtm! Looks like we're a check-semver fix away from merging this :D. Please do that before |
None => { | ||
// Authorities are missing from the cache. Fetch them from the runtime and cache | ||
// them. | ||
log::debug!( | ||
target: LOG_TARGET, | ||
"Authorities for block {:?} at number {} not found in cache, fetching from runtime", | ||
hash, | ||
number | ||
); | ||
let authorities = fetch_authorities_from_runtime( | ||
&*self.client, | ||
parent_hash, | ||
number, | ||
compatibility_mode, | ||
) | ||
.map_err(|e| format!("Could not fetch authorities at {:?}: {}", parent_hash, e))?; | ||
let is_descendent_of = sc_client_api::utils::is_descendent_of(&*self.client, None); | ||
let mut authorities_cache = self.authorities.write(); | ||
authorities_cache | ||
.import( | ||
parent_hash, | ||
number - 1u32.into(), | ||
authorities.clone(), | ||
&is_descendent_of, | ||
) | ||
.map_err(|e| { | ||
format!("Could not import authorities for block {parent_hash:?} at number {}: {e}", number - 1u32.into()) | ||
})?; | ||
Ok(authorities) | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code path should not exist in this function. We should warm up the cache at startup and fetch the authorities for all blocks from the leaves back to the finalized block.
for log in header.digest().logs() { | ||
log::trace!(target: LOG_TARGET, "Checking log {:?}, looking for authorities change digest.", log); | ||
let log = log | ||
.try_to::<ConsensusLog<AuthorityId<P>>>(OpaqueDigestItemId::Consensus(&AURA_ENGINE_ID)); | ||
if let Some(ConsensusLog::AuthoritiesChange(authorities)) = log { | ||
return Some(authorities); | ||
} | ||
} | ||
None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for log in header.digest().logs() { | |
log::trace!(target: LOG_TARGET, "Checking log {:?}, looking for authorities change digest.", log); | |
let log = log | |
.try_to::<ConsensusLog<AuthorityId<P>>>(OpaqueDigestItemId::Consensus(&AURA_ENGINE_ID)); | |
if let Some(ConsensusLog::AuthoritiesChange(authorities)) = log { | |
return Some(authorities); | |
} | |
} | |
None | |
header.digest().convert_first(|log| | |
log::trace!(target: LOG_TARGET, "Checking log {:?}, looking for authorities change digest.", log); | |
let (engine, log) = log.as_consensus()? | |
if engine != AURA_ENGINE_ID { return None; } | |
if let Some(ConsensusLog::AuthoritiesChange(authorities)) = ConsensusLog<AuthorityId<P>>>::decode_all(&mut &log[..] { | |
return Some(authorities); | |
} | |
} | |
None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as_consensus
is very important here. You could also extend
pub trait CompatibleDigestItem<Signature>: Sized { |
Closes #9064. Tracks AURA authorities in a `ForkTree`. The fork tree is updated whenever there is an authorities change log in the digest. If the fork tree doesn't contain the authorities, they are fetched for the runtime (should only happen at startup, or if something weird is going on with forks maybe). --------- Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Closes #9064.
Tracks AURA authorities in a
ForkTree
. The fork tree is updated whenever there is an authorities change log in the digest. If the fork tree doesn't contain the authorities, they are fetched for the runtime (should only happen at startup, or if something weird is going on with forks maybe).