erigon-pulse/cl/phase1/cache/attestation_indicies_cache.go
Giulio rebuffo d62ef03cad
Added states/fork and states/root to beacon API (#8293)
Added /eth/v1/beacon/states/{state_id}/root and
/eth/v1/beacon/states/{state_id}/fork
2023-09-27 11:15:51 +02:00

31 lines
932 B
Go

package cache
import (
"github.com/ledgerwatch/erigon-lib/common"
"github.com/ledgerwatch/erigon/cl/cltypes/solid"
"github.com/ledgerwatch/erigon/cl/phase1/core/state/lru"
"github.com/ledgerwatch/erigon/cl/utils"
)
var attestationIndiciesCache *lru.Cache[common.Hash, []uint64]
const attestationIndiciesCacheSize = 1024
func LoadAttestatingIndicies(attestation *solid.AttestationData, aggregationBits []byte) ([]uint64, bool) {
bitsHash := utils.Keccak256(aggregationBits)
hash, err := attestation.HashSSZ()
if err != nil {
return nil, false
}
return attestationIndiciesCache.Get(utils.Keccak256(hash[:], bitsHash[:]))
}
func StoreAttestation(attestation *solid.AttestationData, aggregationBits []byte, indicies []uint64) {
bitsHash := utils.Keccak256(aggregationBits)
hash, err := attestation.HashSSZ()
if err != nil {
return
}
attestationIndiciesCache.Add(utils.Keccak256(hash[:], bitsHash[:]), indicies)
}