Skip to content

Commit 6438f2c

Browse files
authored
Merge branch 'develop' into broadcast-equivocating-blocks
2 parents b333d36 + 96f1ebf commit 6438f2c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1006
-180
lines changed

WORKSPACE

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ filegroup(
255255
url = "https://github.com/ethereum/EIPs/archive/5480440fe51742ed23342b68cf106cefd427e39d.tar.gz",
256256
)
257257

258-
consensus_spec_version = "v1.5.0-beta.3"
258+
consensus_spec_version = "v1.5.0-beta.4"
259259

260260
bls_test_version = "v0.1.1"
261261

@@ -271,7 +271,7 @@ filegroup(
271271
visibility = ["//visibility:public"],
272272
)
273273
""",
274-
integrity = "sha256-z+j0BEJuXMBKbGL+7jq35zddzZMW1je8/uvTz5+wboQ=",
274+
integrity = "sha256-QG0NUqaCvP5lKaKKwF/fmeICZVjONMlb7EE+MtYl0C0=",
275275
url = "https://github.com/ethereum/consensus-spec-tests/releases/download/%s/general.tar.gz" % consensus_spec_version,
276276
)
277277

@@ -287,7 +287,7 @@ filegroup(
287287
visibility = ["//visibility:public"],
288288
)
289289
""",
290-
integrity = "sha256-5/YUOXH65CmM1plZ8twJ3BQxwM51jgSpOB8/VSBI19k=",
290+
integrity = "sha256-8NQngTSSqzW/j3tOUi3r5h+94ChRbLNWTt7BOGqr4+E=",
291291
url = "https://github.com/ethereum/consensus-spec-tests/releases/download/%s/minimal.tar.gz" % consensus_spec_version,
292292
)
293293

@@ -303,7 +303,7 @@ filegroup(
303303
visibility = ["//visibility:public"],
304304
)
305305
""",
306-
integrity = "sha256-iZ2eNhwRnbxrjR+5gMBUYakaCXicvPChwFUkZtQUbbI=",
306+
integrity = "sha256-gFqxbaBnJ7dtdoj0zFbVrtlHv/bLNuWjrTHkyCAjFjI=",
307307
url = "https://github.com/ethereum/consensus-spec-tests/releases/download/%s/mainnet.tar.gz" % consensus_spec_version,
308308
)
309309

@@ -318,7 +318,7 @@ filegroup(
318318
visibility = ["//visibility:public"],
319319
)
320320
""",
321-
integrity = "sha256-inAXV7xNM5J1aUdP7JNXFO2iFFZ7dth38Ji+mJW50Ts=",
321+
integrity = "sha256-9paalF0POULpP2ga+4ouHSETKYrWNCUCZoJHPuFw06E=",
322322
strip_prefix = "consensus-specs-" + consensus_spec_version[1:],
323323
url = "https://github.com/ethereum/consensus-specs/archive/refs/tags/%s.tar.gz" % consensus_spec_version,
324324
)

beacon-chain/core/helpers/attestation.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives"
1111
"github.com/prysmaticlabs/prysm/v5/crypto/hash"
1212
ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
13-
"github.com/prysmaticlabs/prysm/v5/runtime/version"
1413
prysmTime "github.com/prysmaticlabs/prysm/v5/time"
1514
"github.com/prysmaticlabs/prysm/v5/time/slots"
1615
)
@@ -86,15 +85,7 @@ func IsAggregator(committeeCount uint64, slotSig []byte) (bool, error) {
8685
//
8786
// return uint64((committees_since_epoch_start + committee_index) % ATTESTATION_SUBNET_COUNT)
8887
func ComputeSubnetForAttestation(activeValCount uint64, att ethpb.Att) uint64 {
89-
if att.Version() >= version.Electra {
90-
committeeIndex := 0
91-
committeeIndices := att.CommitteeBitsVal().BitIndices()
92-
if len(committeeIndices) > 0 {
93-
committeeIndex = committeeIndices[0]
94-
}
95-
return ComputeSubnetFromCommitteeAndSlot(activeValCount, primitives.CommitteeIndex(committeeIndex), att.GetData().Slot)
96-
}
97-
return ComputeSubnetFromCommitteeAndSlot(activeValCount, att.GetData().CommitteeIndex, att.GetData().Slot)
88+
return ComputeSubnetFromCommitteeAndSlot(activeValCount, att.GetCommitteeIndex(), att.GetData().Slot)
9889
}
9990

10091
// ComputeSubnetFromCommitteeAndSlot is a flattened version of ComputeSubnetForAttestation where we only pass in

beacon-chain/db/filters/BUILD.bazel

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,19 @@ load("@prysm//tools/go:def.bzl", "go_library", "go_test")
22

33
go_library(
44
name = "go_default_library",
5-
srcs = ["filter.go"],
5+
srcs = [
6+
"errors.go",
7+
"filter.go",
8+
],
69
importpath = "github.com/prysmaticlabs/prysm/v5/beacon-chain/db/filters",
710
visibility = [
811
"//beacon-chain:__subpackages__",
912
"//tools:__subpackages__",
1013
],
11-
deps = ["//consensus-types/primitives:go_default_library"],
14+
deps = [
15+
"//consensus-types/primitives:go_default_library",
16+
"@com_github_pkg_errors//:go_default_library",
17+
],
1218
)
1319

1420
go_test(
@@ -18,5 +24,6 @@ go_test(
1824
deps = [
1925
"//consensus-types/primitives:go_default_library",
2026
"//testing/assert:go_default_library",
27+
"//testing/require:go_default_library",
2128
],
2229
)

beacon-chain/db/filters/errors.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package filters
2+
3+
import "errors"
4+
5+
var (
6+
ErrIncompatibleFilters = errors.New("combination of filters is not valid")
7+
ErrNotSet = errors.New("filter was not set")
8+
ErrInvalidQuery = errors.New("invalid query")
9+
)

beacon-chain/db/filters/filter.go

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414
// }
1515
package filters
1616

17-
import primitives "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives"
17+
import (
18+
"github.com/pkg/errors"
19+
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives"
20+
)
1821

1922
// FilterType defines an enum which is used as the keys in a map that tracks
2023
// set attribute filters for data as part of the `FilterQuery` struct type.
@@ -45,10 +48,34 @@ const (
4548
SlotStep
4649
)
4750

51+
// SlotRoot is the slot and root of a single block.
52+
type SlotRoot struct {
53+
Slot primitives.Slot
54+
Root [32]byte
55+
}
56+
57+
// AncestryQuery is a special query that describes a chain of blocks that satisfies the invariant of:
58+
// blocks[n].parent_root == blocks[n-1].root.
59+
type AncestryQuery struct {
60+
// Slot of oldest to return.
61+
Earliest primitives.Slot
62+
// Descendent that all ancestors in chain must descend from.
63+
Descendent SlotRoot
64+
set bool
65+
}
66+
67+
func (aq AncestryQuery) Span() primitives.Slot {
68+
if aq.Earliest > aq.Descendent.Slot {
69+
return 0
70+
}
71+
return (aq.Descendent.Slot - aq.Earliest) + 1 // +1 to include upper bound
72+
}
73+
4874
// QueryFilter defines a generic interface for type-asserting
4975
// specific filters to use in querying DB objects.
5076
type QueryFilter struct {
51-
queries map[FilterType]interface{}
77+
queries map[FilterType]interface{}
78+
ancestry AncestryQuery
5279
}
5380

5481
// NewFilter instantiates a new QueryFilter type used to build filters for
@@ -132,3 +159,42 @@ func (q *QueryFilter) SetSlotStep(val uint64) *QueryFilter {
132159
q.queries[SlotStep] = val
133160
return q
134161
}
162+
163+
// SimpleSlotRange returns the start and end slot of a query filter if it is a simple slot range query.
164+
// A simple slot range query is one where the filter only contains a start slot and an end slot.
165+
// If the query is not a simple slot range query, the bool return value will be false.
166+
func (q *QueryFilter) SimpleSlotRange() (primitives.Slot, primitives.Slot, bool) {
167+
if len(q.queries) != 2 || q.queries[StartSlot] == nil || q.queries[EndSlot] == nil {
168+
return 0, 0, false
169+
}
170+
start, ok := q.queries[StartSlot].(primitives.Slot)
171+
if !ok {
172+
return 0, 0, false
173+
}
174+
end, ok := q.queries[EndSlot].(primitives.Slot)
175+
if !ok {
176+
return 0, 0, false
177+
}
178+
return start, end, true
179+
}
180+
181+
// SetAncestryQuery sets the filter to be an ancestryQuery. Note that this filter type is exclusive with
182+
// other filters, so call ing GetAncestryQuery will return an error if other values are set.
183+
func (q *QueryFilter) SetAncestryQuery(aq AncestryQuery) *QueryFilter {
184+
aq.set = true
185+
q.ancestry = aq
186+
return q
187+
}
188+
189+
func (q *QueryFilter) GetAncestryQuery() (AncestryQuery, error) {
190+
if !q.ancestry.set {
191+
return q.ancestry, ErrNotSet
192+
}
193+
if len(q.queries) > 0 {
194+
return q.ancestry, errors.Wrap(ErrIncompatibleFilters, "AncestryQuery cannot be combined with other filters")
195+
}
196+
if q.ancestry.Earliest > q.ancestry.Descendent.Slot {
197+
return q.ancestry, errors.Wrap(ErrInvalidQuery, "descendent slot must come after earliest slot")
198+
}
199+
return q.ancestry, nil
200+
}

beacon-chain/db/filters/filter_test.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55

66
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives"
77
"github.com/prysmaticlabs/prysm/v5/testing/assert"
8+
"github.com/prysmaticlabs/prysm/v5/testing/require"
89
)
910

1011
func TestQueryFilter_ChainsCorrectly(t *testing.T) {
@@ -28,3 +29,64 @@ func TestQueryFilter_ChainsCorrectly(t *testing.T) {
2829
}
2930
}
3031
}
32+
33+
func TestSimpleSlotRange(t *testing.T) {
34+
type tc struct {
35+
name string
36+
applFilters []func(*QueryFilter) *QueryFilter
37+
isSimple bool
38+
start primitives.Slot
39+
end primitives.Slot
40+
}
41+
cases := []tc{
42+
{
43+
name: "no filters",
44+
applFilters: []func(*QueryFilter) *QueryFilter{},
45+
isSimple: false,
46+
},
47+
{
48+
name: "start slot",
49+
applFilters: []func(*QueryFilter) *QueryFilter{
50+
func(f *QueryFilter) *QueryFilter {
51+
return f.SetStartSlot(3)
52+
},
53+
},
54+
isSimple: false,
55+
},
56+
{
57+
name: "end slot",
58+
applFilters: []func(*QueryFilter) *QueryFilter{
59+
func(f *QueryFilter) *QueryFilter {
60+
return f.SetEndSlot(3)
61+
},
62+
},
63+
isSimple: false,
64+
},
65+
{
66+
name: "end slot",
67+
applFilters: []func(*QueryFilter) *QueryFilter{
68+
func(f *QueryFilter) *QueryFilter {
69+
return f.SetStartSlot(3)
70+
},
71+
func(f *QueryFilter) *QueryFilter {
72+
return f.SetEndSlot(7)
73+
},
74+
},
75+
start: 3,
76+
end: 7,
77+
isSimple: true,
78+
},
79+
}
80+
for _, c := range cases {
81+
t.Run(c.name, func(t *testing.T) {
82+
f := NewFilter()
83+
for _, filt := range c.applFilters {
84+
f = filt(f)
85+
}
86+
start, end, isSimple := f.SimpleSlotRange()
87+
require.Equal(t, c.isSimple, isSimple)
88+
require.Equal(t, c.start, start)
89+
require.Equal(t, c.end, end)
90+
})
91+
}
92+
}

0 commit comments

Comments
 (0)