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

add authorities_len for aura #2040

Merged
merged 3 commits into from
Oct 26, 2023
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
7 changes: 6 additions & 1 deletion substrate/frame/aura/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,11 @@ impl<T: Config> Pallet<T> {
}
}

/// Return current authorities length.
pub fn authorities_len() -> usize {
Authorities::<T>::decode_len().unwrap_or(0)
georgepisaltu marked this conversation as resolved.
Show resolved Hide resolved
}

/// Get the current slot from the pre-runtime digests.
fn current_slot_from_digests() -> Option<Slot> {
let digest = frame_system::Pallet::<T>::digest();
Expand Down Expand Up @@ -363,7 +368,7 @@ impl<T: Config> FindAuthor<u32> for Pallet<T> {
for (id, mut data) in digests.into_iter() {
if id == AURA_ENGINE_ID {
let slot = Slot::decode(&mut data).ok()?;
let author_index = *slot % Self::authorities().len() as u64;
let author_index = *slot % Self::authorities_len() as u64;
georgepisaltu marked this conversation as resolved.
Show resolved Hide resolved
return Some(author_index as u32)
}
}
Expand Down
3 changes: 2 additions & 1 deletion substrate/frame/aura/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ use sp_runtime::{Digest, DigestItem};
fn initial_values() {
build_ext_and_execute_test(vec![0, 1, 2, 3], || {
assert_eq!(Aura::current_slot(), 0u64);
assert_eq!(Aura::authorities().len(), 4);
assert_eq!(Aura::authorities().len(), Aura::authorities_len());
assert_eq!(Aura::authorities_len(), 4);
});
}

Expand Down