From c86f697b88b5179851bd756eec49bf95545ff553 Mon Sep 17 00:00:00 2001 From: Marc Brinkmann Date: Thu, 11 Apr 2024 14:22:18 +0200 Subject: [PATCH] Re-add `is_active_or_upcoming_validator` --- node/src/types/validator_matrix.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/node/src/types/validator_matrix.rs b/node/src/types/validator_matrix.rs index d9b138a1cc..21fdad24e0 100644 --- a/node/src/types/validator_matrix.rs +++ b/node/src/types/validator_matrix.rs @@ -236,6 +236,20 @@ impl ValidatorMatrix { } } + /// Determine if the active validator is in a current or upcoming set of active validators. + /// + /// This function may produce false positives, as it works backwards from the highest known era. + /// Depending on the current network state, this may be an upcoming or active era, at least the + /// previous era validators may be positively identified by this function. + #[inline] + pub(crate) fn is_active_or_upcoming_validator(&self, public_key: &PublicKey) -> bool { + self.read_inner() + .values() + .rev() + .take(self.auction_delay as usize + 1) + .any(|validator_weights| validator_weights.is_validator(public_key)) + } + /// Returns the public keys of all validators in a given era. /// /// Will return `None` if the era is not known.