mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 04:47:18 +00:00
Do not save duplicated indices (#4118)
* Added a duplication test * Refactor * Updated test * Do not save dups for indices bucket
This commit is contained in:
parent
c1c48a8af5
commit
b872f74fd3
@ -265,6 +265,74 @@ func TestStore_Attestations_FiltersCorrectly(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestStore_DuplicatedAttestations_FiltersCorrectly(t *testing.T) {
|
||||
db := setupDB(t)
|
||||
defer teardownDB(t, db)
|
||||
someRoot := [32]byte{1, 2, 3}
|
||||
att := ðpb.Attestation{
|
||||
Data: ðpb.AttestationData{
|
||||
BeaconBlockRoot: someRoot[:],
|
||||
Source: ðpb.Checkpoint{
|
||||
Root: someRoot[:],
|
||||
Epoch: 5,
|
||||
},
|
||||
Target: ðpb.Checkpoint{
|
||||
Root: someRoot[:],
|
||||
Epoch: 7,
|
||||
},
|
||||
},
|
||||
AggregationBits: bitfield.Bitlist{0b11},
|
||||
}
|
||||
atts := []*ethpb.Attestation{att, att, att}
|
||||
ctx := context.Background()
|
||||
if err := db.SaveAttestations(ctx, atts); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
retrievedAtts, err := db.Attestations(ctx, filters.NewFilter().
|
||||
SetHeadBlockRoot(someRoot[:]))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(retrievedAtts) != 1 {
|
||||
t.Errorf("Expected %d attestations, received %d", 1, len(retrievedAtts))
|
||||
}
|
||||
|
||||
att1 := proto.Clone(att).(*ethpb.Attestation)
|
||||
att1.Data.Source.Epoch = 6
|
||||
atts = []*ethpb.Attestation{att, att, att, att1, att1, att1}
|
||||
if err := db.SaveAttestations(ctx, atts); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
retrievedAtts, err = db.Attestations(ctx, filters.NewFilter().
|
||||
SetHeadBlockRoot(someRoot[:]))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(retrievedAtts) != 2 {
|
||||
t.Errorf("Expected %d attestations, received %d", 1, len(retrievedAtts))
|
||||
}
|
||||
|
||||
retrievedAtts, err = db.Attestations(ctx, filters.NewFilter().
|
||||
SetHeadBlockRoot(someRoot[:]).SetSourceEpoch(5))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(retrievedAtts) != 1 {
|
||||
t.Errorf("Expected %d attestations, received %d", 1, len(retrievedAtts))
|
||||
}
|
||||
|
||||
retrievedAtts, err = db.Attestations(ctx, filters.NewFilter().
|
||||
SetHeadBlockRoot(someRoot[:]).SetSourceEpoch(6))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(retrievedAtts) != 1 {
|
||||
t.Errorf("Expected %d attestations, received %d", 1, len(retrievedAtts))
|
||||
}
|
||||
}
|
||||
|
||||
func TestStore_Attestations_BitfieldLogic(t *testing.T) {
|
||||
commonData := ðpb.AttestationData{Slot: 10}
|
||||
|
||||
|
@ -39,6 +39,12 @@ func updateValueForIndices(indicesByBucket map[string][]byte, root []byte, tx *b
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
// Do not save duplication in indices bucket
|
||||
for i := 0; i < len(valuesAtIndex); i += 32 {
|
||||
if bytes.Equal(valuesAtIndex[i:i+32], root) {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
if err := bkt.Put(idx, append(valuesAtIndex, root...)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ func buildOptions(cfg *Config, ip net.IP, priKey *ecdsa.PrivateKey) []libp2p.Opt
|
||||
libp2p.EnableRelay(),
|
||||
libp2p.ListenAddrs(listen),
|
||||
whitelistSubnet(cfg.WhitelistCIDR),
|
||||
libp2p.ConnectionManager(connmgr.NewConnManager(int(cfg.MaxPeers), int(cfg.MaxPeers), 1 * time.Second)),
|
||||
libp2p.ConnectionManager(connmgr.NewConnManager(int(cfg.MaxPeers), int(cfg.MaxPeers), 1*time.Second)),
|
||||
}
|
||||
if cfg.EnableUPnP {
|
||||
options = append(options, libp2p.NATPortMap()) //Allow to use UPnP
|
||||
|
Loading…
Reference in New Issue
Block a user