Skip to content

Conversation

sistemd
Copy link
Contributor

@sistemd sistemd commented Jul 21, 2025

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).

@paritytech-workflow-stopper
Copy link

All GitHub workflows were cancelled due to failure one of the required jobs.
Failed workflow url: https://github.com/paritytech/polkadot-sdk/actions/runs/16405762024
Failed job name: fmt

@sistemd sistemd requested review from bkchr, iulianbarbu and skunert July 21, 2025 00:37
@sistemd
Copy link
Contributor Author

sistemd commented Jul 21, 2025

/cmd prdoc --audience node_dev --audience node_operator --bump patch

@sistemd sistemd added the T9-cumulus This PR/Issue is related to cumulus. label Jul 21, 2025
Copy link
Contributor

@skunert skunert left a 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.

@sistemd
Copy link
Contributor Author

sistemd commented Jul 28, 2025

@skunert

Are you planning to do this in a follow up?

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.

@sistemd sistemd requested a review from skunert July 31, 2025 23:11
Copy link
Contributor

@skunert skunert left a comment

Choose a reason for hiding this comment

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

Looks nice!

Copy link
Contributor

@lexnv lexnv left a 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

@iulianbarbu
Copy link
Contributor

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:

The idea is that we change the aura pallet to also announce the new authority set via a digest,

Was this done? I can't remember. If no, should it be still done (maybe in this PR if yes)?

@iulianbarbu
Copy link
Contributor

iulianbarbu commented Aug 22, 2025

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.

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.

@sistemd
Copy link
Contributor Author

sistemd commented Aug 25, 2025

Was this done? I can't remember. If no, should it be still done (maybe in this PR if yes)?

Yes sir - this was done way before. (This predates me 😄).

@iulianbarbu
Copy link
Contributor

Was this done? I can't remember. If no, should it be still done (maybe in this PR if yes)?

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:

pub fn change_authorities(new: BoundedVec<T::AuthorityId, T::MaxAuthorities>) {
.

@sistemd
Copy link
Contributor Author

sistemd commented Aug 25, 2025

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.

@iulianbarbu
Copy link
Contributor

Also, here's a test for this: 251544c

Test lgtm! Looks like we're a check-semver fix away from merging this :D. Please do that before

@sistemd sistemd added this pull request to the merge queue Aug 26, 2025
Merged via the queue into master with commit dcd9cac Aug 26, 2025
285 of 292 checks passed
@sistemd sistemd deleted the sistemd/aura-authorities-in-digest branch August 26, 2025 17:55
Comment on lines +95 to +124
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)
},
Copy link
Member

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.

Comment on lines +171 to +179
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
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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

Copy link
Member

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 {
to support the consensuslog.

alvicsam pushed a commit that referenced this pull request Oct 17, 2025
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T9-cumulus This PR/Issue is related to cumulus.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Aura: Track authorities in digests

5 participants