mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 04:47:18 +00:00
Lock Only When Needed When Fetching Attesting History (#8140)
* lock when needed in attesting history * rw
This commit is contained in:
parent
a7cf77fc26
commit
d650034734
@ -34,11 +34,12 @@ func (store *Store) AttestationHistoryForPubKeyV2(ctx context.Context, publicKey
|
||||
ctx, span := trace.StartSpan(ctx, "Validator.AttestationHistoryForPubKeyV2")
|
||||
defer span.End()
|
||||
if !featureconfig.Get().DisableAttestingHistoryDBCache {
|
||||
store.lock.Lock()
|
||||
defer store.lock.Unlock()
|
||||
store.lock.RLock()
|
||||
if history, ok := store.attestingHistoriesByPubKey[publicKey]; ok {
|
||||
store.lock.RUnlock()
|
||||
return history, nil
|
||||
}
|
||||
store.lock.RUnlock()
|
||||
}
|
||||
var err error
|
||||
var attestationHistory EncHistoryData
|
||||
@ -57,7 +58,9 @@ func (store *Store) AttestationHistoryForPubKeyV2(ctx context.Context, publicKey
|
||||
return nil
|
||||
})
|
||||
if !featureconfig.Get().DisableAttestingHistoryDBCache {
|
||||
store.lock.Lock()
|
||||
store.attestingHistoriesByPubKey[publicKey] = attestationHistory
|
||||
store.lock.Unlock()
|
||||
}
|
||||
return attestationHistory, err
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ var ProtectionDbFileName = "validator.db"
|
||||
type Store struct {
|
||||
db *bolt.DB
|
||||
databasePath string
|
||||
lock sync.Mutex
|
||||
lock sync.RWMutex
|
||||
attestingHistoriesByPubKey map[[48]byte]EncHistoryData
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user