mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-14 10:22:38 +00:00
Persistent PubkeyCache on the state
This commit is contained in:
@@ -1,16 +1,15 @@
|
||||
use crate::*;
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
use std::collections::HashMap;
|
||||
use rpds::HashTrieMapSync as HashTrieMap;
|
||||
|
||||
type ValidatorIndex = usize;
|
||||
|
||||
#[derive(Debug, PartialEq, Clone, Default, Serialize, Deserialize)]
|
||||
#[derive(Debug, PartialEq, Clone, Default)]
|
||||
pub struct PubkeyCache {
|
||||
/// Maintain the number of keys added to the map. It is not sufficient to just use the HashMap
|
||||
/// len, as it does not increase when duplicate keys are added. Duplicate keys are used during
|
||||
/// testing.
|
||||
/// Maintain the number of keys added to the map. It is not sufficient to just use the
|
||||
/// HashTrieMap len, as it does not increase when duplicate keys are added. Duplicate keys are
|
||||
/// used during testing.
|
||||
len: usize,
|
||||
map: HashMap<PublicKeyBytes, ValidatorIndex>,
|
||||
map: HashTrieMap<PublicKeyBytes, ValidatorIndex>,
|
||||
}
|
||||
|
||||
impl PubkeyCache {
|
||||
@@ -25,7 +24,7 @@ impl PubkeyCache {
|
||||
/// that an index is never skipped.
|
||||
pub fn insert(&mut self, pubkey: PublicKeyBytes, index: ValidatorIndex) -> bool {
|
||||
if index == self.len {
|
||||
self.map.insert(pubkey, index);
|
||||
self.map.insert_mut(pubkey, index);
|
||||
self.len = self
|
||||
.len
|
||||
.checked_add(1)
|
||||
|
||||
Reference in New Issue
Block a user