mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-22 19:40:37 +00:00
0eff83cb9d
* Use a cache of one entry to build attestation * Gazelle * Enforce on RPC side * Rm unused var * Potuz feedback, dont use pointer * Fix tests * Init fetcher * Add in-progress * Add back missing lock * Potuz feedback * Update beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go Co-authored-by: Potuz <potuz@prysmaticlabs.com> --------- Co-authored-by: Potuz <potuz@prysmaticlabs.com>
42 lines
1.0 KiB
Go
42 lines
1.0 KiB
Go
package cache
|
|
|
|
import (
|
|
"errors"
|
|
"sync"
|
|
|
|
forkchoicetypes "github.com/prysmaticlabs/prysm/v4/beacon-chain/forkchoice/types"
|
|
"github.com/prysmaticlabs/prysm/v4/consensus-types/primitives"
|
|
)
|
|
|
|
type AttestationConsensusData struct {
|
|
Slot primitives.Slot
|
|
HeadRoot []byte
|
|
Target forkchoicetypes.Checkpoint
|
|
Source forkchoicetypes.Checkpoint
|
|
}
|
|
|
|
// AttestationCache stores cached results of AttestationData requests.
|
|
type AttestationCache struct {
|
|
a *AttestationConsensusData
|
|
sync.RWMutex
|
|
}
|
|
|
|
// NewAttestationCache creates a new instance of AttestationCache.
|
|
func NewAttestationCache() *AttestationCache {
|
|
return &AttestationCache{}
|
|
}
|
|
|
|
// Get retrieves cached attestation data, recording a cache hit or miss. This method is lock free.
|
|
func (c *AttestationCache) Get() *AttestationConsensusData {
|
|
return c.a
|
|
}
|
|
|
|
// Put adds a response to the cache. This method is lock free.
|
|
func (c *AttestationCache) Put(a *AttestationConsensusData) error {
|
|
if a == nil {
|
|
return errors.New("attestation cannot be nil")
|
|
}
|
|
c.a = a
|
|
return nil
|
|
}
|