34 lines
1.4 KiB
Diff
34 lines
1.4 KiB
Diff
--- a/substrate/frame/aura/src/lib.rs
|
|
+++ b/substrate/frame/aura/src/lib.rs
|
|
@@ -441,6 +441,8 @@ impl<T: Config> IsMember<T::AuthorityId> for Pallet<T> {
|
|
fn is_member(authority_id: &T::AuthorityId) -> bool {
|
|
- Authorities::<T>::get().iter().any(|id| id == authority_id)
|
|
+ // Authorities is stored sorted (invariant maintained by set_authorities).
|
|
+ // Binary search replaces O(A) linear scan with O(log A).
|
|
+ Authorities::<T>::get().binary_search(authority_id).is_ok()
|
|
}
|
|
}
|
|
|
|
Note: Requires Authorities BoundedVec to be kept sorted. The set_authorities
|
|
call site must sort before storing. Aura already processes authorities in
|
|
session index order which is stable — sorting once on write is correct.
|
|
|
|
--- a/substrate/frame/babe/src/lib.rs
|
|
+++ b/substrate/frame/babe/src/lib.rs
|
|
@@ -508,5 +508,6 @@ impl<T: Config> IsMember<AuthorityId> for Pallet<T> {
|
|
fn is_member(authority_id: &AuthorityId) -> bool {
|
|
- Authorities::<T>::get().iter().any(|id| &id.0 == authority_id)
|
|
+ Authorities::<T>::get()
|
|
+ .binary_search_by(|id| id.0.cmp(authority_id))
|
|
+ .is_ok()
|
|
}
|
|
}
|
|
|
|
--- a/substrate/frame/beefy/src/lib.rs
|
|
+++ b/substrate/frame/beefy/src/lib.rs
|
|
@@ -737,5 +737,6 @@ impl<T: Config> IsMember<T::BeefyId> for Pallet<T> {
|
|
fn is_member(authority_id: &T::BeefyId) -> bool {
|
|
- Authorities::<T>::get().iter().any(|id| id == authority_id)
|
|
+ Authorities::<T>::get().binary_search(authority_id).is_ok()
|
|
}
|
|
}
|