Skip to content

Commit c66dc16

Browse files
committed
Implement validator deduplication based on account id and the first-in order
1 parent 15cc8b3 commit c66dc16

File tree

1 file changed

+20
-0
lines changed
  • crates/pallet-humanode-session/src

1 file changed

+20
-0
lines changed

crates/pallet-humanode-session/src/lib.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ mod mock;
2525
mod tests;
2626
mod utils;
2727

28+
use self::utils::DedupeIteratorExt as _;
29+
2830
/// The type representing the session index in our chain.
2931
type SessionIndex = u32;
3032

@@ -278,6 +280,7 @@ impl<T: Config> Pallet<T> {
278280
bootnodes
279281
.chain(bioauth_active_authentications)
280282
.chain(fixed_validators)
283+
.dedupe(AccountIdDedupeKey::<T>::default())
281284
}
282285

283286
/// Clears and re-populates the [`SessionIdentities`] for a given session with the entries.
@@ -355,3 +358,20 @@ impl<T: Config> sp_runtime::traits::Convert<T::AccountId, Option<IdentificationF
355358
<SessionIdentities<T>>::get(session_index, account_id)
356359
}
357360
}
361+
362+
/// The dedupe key extractor that provides Account Ids from Identification Tuples.
363+
struct AccountIdDedupeKey<T>(core::marker::PhantomData<T>);
364+
365+
impl<T: Config> utils::DedupeKeyExtractor<IdentificationTupleFor<T>> for AccountIdDedupeKey<T> {
366+
type Output = <T as frame_system::Config>::AccountId;
367+
368+
fn extract_key(&self, value: &IdentificationTupleFor<T>) -> Self::Output {
369+
value.0.clone()
370+
}
371+
}
372+
373+
impl<T> Default for AccountIdDedupeKey<T> {
374+
fn default() -> Self {
375+
Self(core::marker::PhantomData)
376+
}
377+
}

0 commit comments

Comments
 (0)