mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 15:37:56 -05:00
42 lines
1.0 KiB
Go
42 lines
1.0 KiB
Go
package cache
|
|
|
|
import (
|
|
"errors"
|
|
"sync"
|
|
|
|
forkchoicetypes "github.com/OffchainLabs/prysm/v7/beacon-chain/forkchoice/types"
|
|
"github.com/OffchainLabs/prysm/v7/consensus-types/primitives"
|
|
)
|
|
|
|
type AttestationConsensusData struct {
|
|
Slot primitives.Slot
|
|
HeadRoot []byte
|
|
Target forkchoicetypes.Checkpoint
|
|
Source forkchoicetypes.Checkpoint
|
|
}
|
|
|
|
// AttestationDataCache stores cached results of AttestationData requests.
|
|
type AttestationDataCache struct {
|
|
a *AttestationConsensusData
|
|
sync.RWMutex
|
|
}
|
|
|
|
// NewAttestationDataCache creates a new instance of AttestationDataCache.
|
|
func NewAttestationDataCache() *AttestationDataCache {
|
|
return &AttestationDataCache{}
|
|
}
|
|
|
|
// Get retrieves cached attestation data, recording a cache hit or miss. This method is lock free.
|
|
func (c *AttestationDataCache) Get() *AttestationConsensusData {
|
|
return c.a
|
|
}
|
|
|
|
// Put adds a response to the cache. This method is lock free.
|
|
func (c *AttestationDataCache) Put(a *AttestationConsensusData) error {
|
|
if a == nil {
|
|
return errors.New("attestation cannot be nil")
|
|
}
|
|
c.a = a
|
|
return nil
|
|
}
|