mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-08 02:31:19 +00:00
d077483577
* v3 import renamings * tidy * fmt * rev * Update beacon-chain/core/epoch/precompute/reward_penalty_test.go * Update beacon-chain/core/helpers/validators_test.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/alias.go * Update beacon-chain/db/iface/BUILD.bazel * Update beacon-chain/db/kv/kv.go * Update beacon-chain/db/kv/state.go * Update beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go * Update beacon-chain/rpc/prysm/v1alpha1/validator/attester_test.go * Update beacon-chain/sync/initial-sync/service.go * fix deps * fix bad replacements * fix bad replacements * change back * gohashtree version * fix deps Co-authored-by: Nishant Das <nishdas93@gmail.com> Co-authored-by: Potuz <potuz@prysmaticlabs.com>
79 lines
1.8 KiB
Go
79 lines
1.8 KiB
Go
package kv
|
|
|
|
import (
|
|
"github.com/pkg/errors"
|
|
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
|
)
|
|
|
|
// SaveBlockAttestation saves an block attestation in cache.
|
|
func (c *AttCaches) SaveBlockAttestation(att *ethpb.Attestation) error {
|
|
if att == nil {
|
|
return nil
|
|
}
|
|
r, err := hashFn(att.Data)
|
|
if err != nil {
|
|
return errors.Wrap(err, "could not tree hash attestation")
|
|
}
|
|
|
|
c.blockAttLock.Lock()
|
|
defer c.blockAttLock.Unlock()
|
|
atts, ok := c.blockAtt[r]
|
|
if !ok {
|
|
atts = make([]*ethpb.Attestation, 0, 1)
|
|
}
|
|
|
|
// Ensure that this attestation is not already fully contained in an existing attestation.
|
|
for _, a := range atts {
|
|
if c, err := a.AggregationBits.Contains(att.AggregationBits); err != nil {
|
|
return err
|
|
} else if c {
|
|
return nil
|
|
}
|
|
}
|
|
|
|
c.blockAtt[r] = append(atts, ethpb.CopyAttestation(att))
|
|
|
|
return nil
|
|
}
|
|
|
|
// SaveBlockAttestations saves a list of block attestations in cache.
|
|
func (c *AttCaches) SaveBlockAttestations(atts []*ethpb.Attestation) error {
|
|
for _, att := range atts {
|
|
if err := c.SaveBlockAttestation(att); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// BlockAttestations returns the block attestations in cache.
|
|
func (c *AttCaches) BlockAttestations() []*ethpb.Attestation {
|
|
atts := make([]*ethpb.Attestation, 0)
|
|
|
|
c.blockAttLock.RLock()
|
|
defer c.blockAttLock.RUnlock()
|
|
for _, att := range c.blockAtt {
|
|
atts = append(atts, att...)
|
|
}
|
|
|
|
return atts
|
|
}
|
|
|
|
// DeleteBlockAttestation deletes a block attestation in cache.
|
|
func (c *AttCaches) DeleteBlockAttestation(att *ethpb.Attestation) error {
|
|
if att == nil {
|
|
return nil
|
|
}
|
|
r, err := hashFn(att.Data)
|
|
if err != nil {
|
|
return errors.Wrap(err, "could not tree hash attestation")
|
|
}
|
|
|
|
c.blockAttLock.Lock()
|
|
defer c.blockAttLock.Unlock()
|
|
delete(c.blockAtt, r)
|
|
|
|
return nil
|
|
}
|