@@ -32,8 +32,11 @@ const BLST_DST: &[u8] = b"BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_POP_";
3232type ValidatorCache = LruMap < BlockHash , ( Vec < Address > , Vec < VoteAddress > ) , ByLength > ;
3333type TurnLengthCache = LruMap < BlockHash , u8 , ByLength > ;
3434type AttestationCache = LruMap < B256 , ( ) , ByLength > ;
35- type SnapshotFingerprintCache = HashMap < BlockHash , B256 > ;
36- type BlsPublicKeyCache = HashMap < VoteAddress , Arc < PublicKey > > ;
35+ type SnapshotFingerprintCache = LruMap < BlockHash , B256 , ByLength > ;
36+ type BlsPublicKeyCache = LruMap < VoteAddress , Arc < PublicKey > , ByLength > ;
37+
38+ const DEFAULT_FINGERPRINT_CACHE_SIZE : u32 = 4096 ;
39+ const DEFAULT_BLS_PUBKEY_CACHE_SIZE : u32 = 256 ;
3740
3841pub static VALIDATOR_CACHE : LazyLock < Mutex < ValidatorCache > > = LazyLock :: new ( || {
3942 Mutex :: new ( LruMap :: new ( ByLength :: new ( 1024 ) ) )
@@ -48,10 +51,10 @@ static ATTESTATION_VERIFY_CACHE: LazyLock<Mutex<AttestationCache>> = LazyLock::n
4851} ) ;
4952
5053static SNAPSHOT_FINGERPRINT_CACHE : LazyLock < Mutex < SnapshotFingerprintCache > > =
51- LazyLock :: new ( || Mutex :: new ( HashMap :: new ( ) ) ) ;
54+ LazyLock :: new ( || Mutex :: new ( LruMap :: new ( ByLength :: new ( DEFAULT_FINGERPRINT_CACHE_SIZE ) ) ) ) ;
5255
5356static BLS_PUBKEY_CACHE : LazyLock < Mutex < BlsPublicKeyCache > > =
54- LazyLock :: new ( || Mutex :: new ( HashMap :: new ( ) ) ) ;
57+ LazyLock :: new ( || Mutex :: new ( LruMap :: new ( ByLength :: new ( DEFAULT_BLS_PUBKEY_CACHE_SIZE ) ) ) ) ;
5558
5659#[ cfg( test) ]
5760fn reset_attestation_caches ( ) {
@@ -62,7 +65,7 @@ fn reset_attestation_caches() {
6265
6366fn snapshot_fingerprint ( snap : & Snapshot ) -> B256 {
6467 {
65- let cache = SNAPSHOT_FINGERPRINT_CACHE . lock ( ) . unwrap ( ) ;
68+ let mut cache = SNAPSHOT_FINGERPRINT_CACHE . lock ( ) . unwrap ( ) ;
6669 if let Some ( fingerprint) = cache. get ( & snap. block_hash ) {
6770 return * fingerprint;
6871 }
@@ -682,7 +685,7 @@ mod tests {
682685 {
683686 let cache = SNAPSHOT_FINGERPRINT_CACHE . lock ( ) . unwrap ( ) ;
684687 assert_eq ! ( cache. len( ) , 1 ) ;
685- assert_eq ! ( cache. get ( & snap. block_hash) , Some ( & fp1) ) ;
688+ assert_eq ! ( cache. peek ( & snap. block_hash) , Some ( & fp1) ) ;
686689 }
687690
688691 let fp2 = snapshot_fingerprint ( & snap) ;
0 commit comments