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>
64 lines
1.4 KiB
Go
64 lines
1.4 KiB
Go
package kv
|
|
|
|
import (
|
|
"github.com/patrickmn/go-cache"
|
|
"github.com/pkg/errors"
|
|
"github.com/prysmaticlabs/go-bitfield"
|
|
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
|
)
|
|
|
|
func (c *AttCaches) insertSeenBit(att *ethpb.Attestation) error {
|
|
r, err := hashFn(att.Data)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
v, ok := c.seenAtt.Get(string(r[:]))
|
|
if ok {
|
|
seenBits, ok := v.([]bitfield.Bitlist)
|
|
if !ok {
|
|
return errors.New("could not convert to bitlist type")
|
|
}
|
|
alreadyExists := false
|
|
for _, bit := range seenBits {
|
|
if c, err := bit.Contains(att.AggregationBits); err != nil {
|
|
return err
|
|
} else if c {
|
|
alreadyExists = true
|
|
break
|
|
}
|
|
}
|
|
if !alreadyExists {
|
|
seenBits = append(seenBits, att.AggregationBits)
|
|
}
|
|
c.seenAtt.Set(string(r[:]), seenBits, cache.DefaultExpiration /* one epoch */)
|
|
return nil
|
|
}
|
|
|
|
c.seenAtt.Set(string(r[:]), []bitfield.Bitlist{att.AggregationBits}, cache.DefaultExpiration /* one epoch */)
|
|
return nil
|
|
}
|
|
|
|
func (c *AttCaches) hasSeenBit(att *ethpb.Attestation) (bool, error) {
|
|
r, err := hashFn(att.Data)
|
|
if err != nil {
|
|
return false, err
|
|
}
|
|
|
|
v, ok := c.seenAtt.Get(string(r[:]))
|
|
if ok {
|
|
seenBits, ok := v.([]bitfield.Bitlist)
|
|
if !ok {
|
|
return false, errors.New("could not convert to bitlist type")
|
|
}
|
|
for _, bit := range seenBits {
|
|
if c, err := bit.Contains(att.AggregationBits); err != nil {
|
|
return false, err
|
|
} else if c {
|
|
return true, nil
|
|
}
|
|
}
|
|
}
|
|
return false, nil
|
|
}
|