mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 15:37:56 -05:00
* config values * block protos * get_committee_indices * proto and ssz * attestation interface * Revert "Auxiliary commit to revert individual files from deadb2183723511721b3288c7168808a4fa97c64" This reverts commit 32ad5009537bc5ec0e6caf9f52143d380d00be85. * todos * get_attesting_indices * Revert "Auxiliary commit to revert individual files from dd2789723f90b15eb1f874b561d88d11dcc9c0bf" This reverts commit f39644ed3cb6f3964fc6c86fdf4bd5de2a9668c8. * beacon spec changes * Fix pending attestation. Build ok * Electra: add electra version * Electra: consensus types * gocognit exclusion * @potuz's suggestion * build fix * interfaces for indexed att and slashing * indexed att usage * BuildSignedBeaconBlockFromExecutionPayload * slashing usage * grpc stubs * remove unused methods * Electra attestation interfaces * cleanup * tests * make linter happy * simple casting * test fixes * Fix spectest failures * Regen pb and ssz files * Handle "not ok" type assertion cases * Setters that check version should always return an error. SetAttesterSlashings and SetAttestations * gofmt * Fix TestMinSpanChunksSlice_CheckSlashable --------- Co-authored-by: terence tsao <terence@prysmaticlabs.com> Co-authored-by: Preston Van Loon <preston@pvl.dev>
64 lines
1.5 KiB
Go
64 lines
1.5 KiB
Go
package kv
|
|
|
|
import (
|
|
"github.com/patrickmn/go-cache"
|
|
"github.com/pkg/errors"
|
|
"github.com/prysmaticlabs/go-bitfield"
|
|
"github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces"
|
|
)
|
|
|
|
func (c *AttCaches) insertSeenBit(att interfaces.Attestation) error {
|
|
r, err := hashFn(att.GetData())
|
|
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.GetAggregationBits()); err != nil {
|
|
return err
|
|
} else if c {
|
|
alreadyExists = true
|
|
break
|
|
}
|
|
}
|
|
if !alreadyExists {
|
|
seenBits = append(seenBits, att.GetAggregationBits())
|
|
}
|
|
c.seenAtt.Set(string(r[:]), seenBits, cache.DefaultExpiration /* one epoch */)
|
|
return nil
|
|
}
|
|
|
|
c.seenAtt.Set(string(r[:]), []bitfield.Bitlist{att.GetAggregationBits()}, cache.DefaultExpiration /* one epoch */)
|
|
return nil
|
|
}
|
|
|
|
func (c *AttCaches) hasSeenBit(att interfaces.Attestation) (bool, error) {
|
|
r, err := hashFn(att.GetData())
|
|
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.GetAggregationBits()); err != nil {
|
|
return false, err
|
|
} else if c {
|
|
return true, nil
|
|
}
|
|
}
|
|
}
|
|
return false, nil
|
|
}
|