mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 21:38:05 -05:00
4
beacon-chain/cache/active_balance.go
vendored
4
beacon-chain/cache/active_balance.go
vendored
@@ -13,7 +13,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state"
|
||||
lruwrpr "github.com/prysmaticlabs/prysm/v3/cache/lru"
|
||||
"github.com/prysmaticlabs/prysm/v3/config/params"
|
||||
ethTypes "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
"github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -90,7 +90,7 @@ func balanceCacheKey(st state.ReadOnlyBeaconState) (string, error) {
|
||||
// impossible condition due to early division
|
||||
return "", errors.Errorf("start slot calculation overflows: %v", err)
|
||||
}
|
||||
prevSlot := ethTypes.Slot(0)
|
||||
prevSlot := primitives.Slot(0)
|
||||
if epochStartSlot > 1 {
|
||||
prevSlot = epochStartSlot - 1
|
||||
}
|
||||
|
||||
4
beacon-chain/cache/active_balance_test.go
vendored
4
beacon-chain/cache/active_balance_test.go
vendored
@@ -9,7 +9,7 @@ import (
|
||||
|
||||
state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native"
|
||||
"github.com/prysmaticlabs/prysm/v3/config/params"
|
||||
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
"github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
||||
)
|
||||
@@ -70,7 +70,7 @@ func TestBalanceCache_BalanceKey(t *testing.T) {
|
||||
}
|
||||
st, err := state_native.InitializeFromProtoPhase0(raw)
|
||||
require.NoError(t, err)
|
||||
require.NoError(t, st.SetSlot(types.Slot(math.MaxUint64)))
|
||||
require.NoError(t, st.SetSlot(primitives.Slot(math.MaxUint64)))
|
||||
|
||||
_, err = balanceCacheKey(st)
|
||||
require.NoError(t, err)
|
||||
|
||||
6
beacon-chain/cache/checkpoint_state_test.go
vendored
6
beacon-chain/cache/checkpoint_state_test.go
vendored
@@ -6,7 +6,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state"
|
||||
state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native"
|
||||
"github.com/prysmaticlabs/prysm/v3/config/params"
|
||||
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
"github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
"github.com/prysmaticlabs/prysm/v3/encoding/bytesutil"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/assert"
|
||||
@@ -65,8 +65,8 @@ func TestCheckpointStateCache_MaxSize(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
for i := uint64(0); i < uint64(maxCheckpointStateSize+100); i++ {
|
||||
require.NoError(t, st.SetSlot(types.Slot(i)))
|
||||
require.NoError(t, c.AddCheckpointState(ðpb.Checkpoint{Epoch: types.Epoch(i), Root: make([]byte, 32)}, st))
|
||||
require.NoError(t, st.SetSlot(primitives.Slot(i)))
|
||||
require.NoError(t, c.AddCheckpointState(ðpb.Checkpoint{Epoch: primitives.Epoch(i), Root: make([]byte, 32)}, st))
|
||||
}
|
||||
|
||||
assert.Equal(t, maxCheckpointStateSize, len(c.cache.Keys()))
|
||||
|
||||
6
beacon-chain/cache/committee.go
vendored
6
beacon-chain/cache/committee.go
vendored
@@ -14,7 +14,7 @@ import (
|
||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||
lruwrpr "github.com/prysmaticlabs/prysm/v3/cache/lru"
|
||||
"github.com/prysmaticlabs/prysm/v3/config/params"
|
||||
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
"github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
"github.com/prysmaticlabs/prysm/v3/container/slice"
|
||||
mathutil "github.com/prysmaticlabs/prysm/v3/math"
|
||||
)
|
||||
@@ -64,7 +64,7 @@ func NewCommitteesCache() *CommitteeCache {
|
||||
|
||||
// Committee fetches the shuffled indices by slot and committee index. Every list of indices
|
||||
// represent one committee. Returns true if the list exists with slot and committee index. Otherwise returns false, nil.
|
||||
func (c *CommitteeCache) Committee(ctx context.Context, slot types.Slot, seed [32]byte, index types.CommitteeIndex) ([]types.ValidatorIndex, error) {
|
||||
func (c *CommitteeCache) Committee(ctx context.Context, slot primitives.Slot, seed [32]byte, index primitives.CommitteeIndex) ([]primitives.ValidatorIndex, error) {
|
||||
if err := c.checkInProgress(ctx, seed); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -117,7 +117,7 @@ func (c *CommitteeCache) AddCommitteeShuffledList(ctx context.Context, committee
|
||||
}
|
||||
|
||||
// ActiveIndices returns the active indices of a given seed stored in cache.
|
||||
func (c *CommitteeCache) ActiveIndices(ctx context.Context, seed [32]byte) ([]types.ValidatorIndex, error) {
|
||||
func (c *CommitteeCache) ActiveIndices(ctx context.Context, seed [32]byte) ([]primitives.ValidatorIndex, error) {
|
||||
if err := c.checkInProgress(ctx, seed); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
10
beacon-chain/cache/committee_disabled.go
vendored
10
beacon-chain/cache/committee_disabled.go
vendored
@@ -6,7 +6,7 @@ package cache
|
||||
import (
|
||||
"context"
|
||||
|
||||
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
"github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
)
|
||||
|
||||
// FakeCommitteeCache is a struct with 1 queue for looking up shuffled indices list by seed.
|
||||
@@ -20,7 +20,7 @@ func NewCommitteesCache() *FakeCommitteeCache {
|
||||
|
||||
// Committee fetches the shuffled indices by slot and committee index. Every list of indices
|
||||
// represent one committee. Returns true if the list exists with slot and committee index. Otherwise returns false, nil.
|
||||
func (c *FakeCommitteeCache) Committee(ctx context.Context, slot types.Slot, seed [32]byte, index types.CommitteeIndex) ([]types.ValidatorIndex, error) {
|
||||
func (c *FakeCommitteeCache) Committee(ctx context.Context, slot primitives.Slot, seed [32]byte, index primitives.CommitteeIndex) ([]primitives.ValidatorIndex, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
@@ -31,12 +31,12 @@ func (c *FakeCommitteeCache) AddCommitteeShuffledList(ctx context.Context, commi
|
||||
}
|
||||
|
||||
// AddProposerIndicesList updates the committee shuffled list with proposer indices.
|
||||
func (c *FakeCommitteeCache) AddProposerIndicesList(seed [32]byte, indices []types.ValidatorIndex) error {
|
||||
func (c *FakeCommitteeCache) AddProposerIndicesList(seed [32]byte, indices []primitives.ValidatorIndex) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// ActiveIndices returns the active indices of a given seed stored in cache.
|
||||
func (c *FakeCommitteeCache) ActiveIndices(ctx context.Context, seed [32]byte) ([]types.ValidatorIndex, error) {
|
||||
func (c *FakeCommitteeCache) ActiveIndices(ctx context.Context, seed [32]byte) ([]primitives.ValidatorIndex, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ func (c *FakeCommitteeCache) ActiveBalance(seed [32]byte) (uint64, error) {
|
||||
}
|
||||
|
||||
// ProposerIndices returns the proposer indices of a given seed.
|
||||
func (c *FakeCommitteeCache) ProposerIndices(seed [32]byte) ([]types.ValidatorIndex, error) {
|
||||
func (c *FakeCommitteeCache) ProposerIndices(seed [32]byte) ([]primitives.ValidatorIndex, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
|
||||
20
beacon-chain/cache/committee_test.go
vendored
20
beacon-chain/cache/committee_test.go
vendored
@@ -10,7 +10,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/v3/config/params"
|
||||
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
"github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
"github.com/prysmaticlabs/prysm/v3/encoding/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/assert"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
||||
@@ -20,7 +20,7 @@ func TestCommitteeKeyFn_OK(t *testing.T) {
|
||||
item := &Committees{
|
||||
CommitteeCount: 1,
|
||||
Seed: [32]byte{'A'},
|
||||
ShuffledIndices: []types.ValidatorIndex{1, 2, 3, 4, 5},
|
||||
ShuffledIndices: []primitives.ValidatorIndex{1, 2, 3, 4, 5},
|
||||
}
|
||||
|
||||
k, err := committeeKeyFn(item)
|
||||
@@ -37,13 +37,13 @@ func TestCommitteeCache_CommitteesByEpoch(t *testing.T) {
|
||||
cache := NewCommitteesCache()
|
||||
|
||||
item := &Committees{
|
||||
ShuffledIndices: []types.ValidatorIndex{1, 2, 3, 4, 5, 6},
|
||||
ShuffledIndices: []primitives.ValidatorIndex{1, 2, 3, 4, 5, 6},
|
||||
Seed: [32]byte{'A'},
|
||||
CommitteeCount: 3,
|
||||
}
|
||||
|
||||
slot := params.BeaconConfig().SlotsPerEpoch
|
||||
committeeIndex := types.CommitteeIndex(1)
|
||||
committeeIndex := primitives.CommitteeIndex(1)
|
||||
indices, err := cache.Committee(context.Background(), slot, item.Seed, committeeIndex)
|
||||
require.NoError(t, err)
|
||||
if indices != nil {
|
||||
@@ -51,7 +51,7 @@ func TestCommitteeCache_CommitteesByEpoch(t *testing.T) {
|
||||
}
|
||||
require.NoError(t, cache.AddCommitteeShuffledList(context.Background(), item))
|
||||
|
||||
wantedIndex := types.CommitteeIndex(0)
|
||||
wantedIndex := primitives.CommitteeIndex(0)
|
||||
indices, err = cache.Committee(context.Background(), slot, item.Seed, wantedIndex)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -62,7 +62,7 @@ func TestCommitteeCache_CommitteesByEpoch(t *testing.T) {
|
||||
func TestCommitteeCache_ActiveIndices(t *testing.T) {
|
||||
cache := NewCommitteesCache()
|
||||
|
||||
item := &Committees{Seed: [32]byte{'A'}, SortedIndices: []types.ValidatorIndex{1, 2, 3, 4, 5, 6}}
|
||||
item := &Committees{Seed: [32]byte{'A'}, SortedIndices: []primitives.ValidatorIndex{1, 2, 3, 4, 5, 6}}
|
||||
indices, err := cache.ActiveIndices(context.Background(), item.Seed)
|
||||
require.NoError(t, err)
|
||||
if indices != nil {
|
||||
@@ -79,7 +79,7 @@ func TestCommitteeCache_ActiveIndices(t *testing.T) {
|
||||
func TestCommitteeCache_ActiveCount(t *testing.T) {
|
||||
cache := NewCommitteesCache()
|
||||
|
||||
item := &Committees{Seed: [32]byte{'A'}, SortedIndices: []types.ValidatorIndex{1, 2, 3, 4, 5, 6}}
|
||||
item := &Committees{Seed: [32]byte{'A'}, SortedIndices: []primitives.ValidatorIndex{1, 2, 3, 4, 5, 6}}
|
||||
count, err := cache.ActiveIndicesCount(context.Background(), item.Seed)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, 0, count, "Expected active count not to exist in empty cache")
|
||||
@@ -123,8 +123,8 @@ func TestCommitteeCacheOutOfRange(t *testing.T) {
|
||||
comms := &Committees{
|
||||
CommitteeCount: 1,
|
||||
Seed: seed,
|
||||
ShuffledIndices: []types.ValidatorIndex{0},
|
||||
SortedIndices: []types.ValidatorIndex{},
|
||||
ShuffledIndices: []primitives.ValidatorIndex{0},
|
||||
SortedIndices: []primitives.ValidatorIndex{},
|
||||
}
|
||||
key, err := committeeKeyFn(comms)
|
||||
assert.NoError(t, err)
|
||||
@@ -137,7 +137,7 @@ func TestCommitteeCacheOutOfRange(t *testing.T) {
|
||||
func TestCommitteeCache_DoesNothingWhenCancelledContext(t *testing.T) {
|
||||
cache := NewCommitteesCache()
|
||||
|
||||
item := &Committees{Seed: [32]byte{'A'}, SortedIndices: []types.ValidatorIndex{1, 2, 3, 4, 5, 6}}
|
||||
item := &Committees{Seed: [32]byte{'A'}, SortedIndices: []primitives.ValidatorIndex{1, 2, 3, 4, 5, 6}}
|
||||
count, err := cache.ActiveIndicesCount(context.Background(), item.Seed)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, 0, count, "Expected active count not to exist in empty cache")
|
||||
|
||||
6
beacon-chain/cache/committees.go
vendored
6
beacon-chain/cache/committees.go
vendored
@@ -3,7 +3,7 @@ package cache
|
||||
import (
|
||||
"errors"
|
||||
|
||||
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
"github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
)
|
||||
|
||||
// ErrNotCommittee will be returned when a cache object is not a pointer to
|
||||
@@ -14,6 +14,6 @@ var ErrNotCommittee = errors.New("object is not a committee struct")
|
||||
type Committees struct {
|
||||
CommitteeCount uint64
|
||||
Seed [32]byte
|
||||
ShuffledIndices []types.ValidatorIndex
|
||||
SortedIndices []types.ValidatorIndex
|
||||
ShuffledIndices []primitives.ValidatorIndex
|
||||
SortedIndices []primitives.ValidatorIndex
|
||||
}
|
||||
|
||||
14
beacon-chain/cache/payload_id.go
vendored
14
beacon-chain/cache/payload_id.go
vendored
@@ -4,7 +4,7 @@ import (
|
||||
"bytes"
|
||||
"sync"
|
||||
|
||||
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
"github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
"github.com/prysmaticlabs/prysm/v3/encoding/bytesutil"
|
||||
)
|
||||
|
||||
@@ -27,7 +27,7 @@ func NewProposerPayloadIDsCache() *ProposerPayloadIDsCache {
|
||||
}
|
||||
|
||||
// GetProposerPayloadIDs returns the proposer and payload IDs for the given slot.
|
||||
func (f *ProposerPayloadIDsCache) GetProposerPayloadIDs(slot types.Slot, r [32]byte) (types.ValidatorIndex, [8]byte, bool) {
|
||||
func (f *ProposerPayloadIDsCache) GetProposerPayloadIDs(slot primitives.Slot, r [32]byte) (primitives.ValidatorIndex, [8]byte, bool) {
|
||||
f.RLock()
|
||||
defer f.RUnlock()
|
||||
ids, ok := f.slotToProposerAndPayloadIDs[idKey(slot, r)]
|
||||
@@ -40,11 +40,11 @@ func (f *ProposerPayloadIDsCache) GetProposerPayloadIDs(slot types.Slot, r [32]b
|
||||
var pId [pIdLength]byte
|
||||
copy(pId[:], b)
|
||||
|
||||
return types.ValidatorIndex(bytesutil.BytesToUint64BigEndian(vId)), pId, true
|
||||
return primitives.ValidatorIndex(bytesutil.BytesToUint64BigEndian(vId)), pId, true
|
||||
}
|
||||
|
||||
// SetProposerAndPayloadIDs sets the proposer and payload IDs for the given slot.
|
||||
func (f *ProposerPayloadIDsCache) SetProposerAndPayloadIDs(slot types.Slot, vId types.ValidatorIndex, pId [8]byte, r [32]byte) {
|
||||
func (f *ProposerPayloadIDsCache) SetProposerAndPayloadIDs(slot primitives.Slot, vId primitives.ValidatorIndex, pId [8]byte, r [32]byte) {
|
||||
f.Lock()
|
||||
defer f.Unlock()
|
||||
var vIdBytes [vIdLength]byte
|
||||
@@ -64,19 +64,19 @@ func (f *ProposerPayloadIDsCache) SetProposerAndPayloadIDs(slot types.Slot, vId
|
||||
}
|
||||
|
||||
// PrunePayloadIDs removes the payload id entries that's current than input slot.
|
||||
func (f *ProposerPayloadIDsCache) PrunePayloadIDs(slot types.Slot) {
|
||||
func (f *ProposerPayloadIDsCache) PrunePayloadIDs(slot primitives.Slot) {
|
||||
f.Lock()
|
||||
defer f.Unlock()
|
||||
|
||||
for k := range f.slotToProposerAndPayloadIDs {
|
||||
s := types.Slot(bytesutil.BytesToUint64BigEndian(k[:8]))
|
||||
s := primitives.Slot(bytesutil.BytesToUint64BigEndian(k[:8]))
|
||||
if slot > s {
|
||||
delete(f.slotToProposerAndPayloadIDs, k)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func idKey(slot types.Slot, r [32]byte) [40]byte {
|
||||
func idKey(slot primitives.Slot, r [32]byte) [40]byte {
|
||||
var k [40]byte
|
||||
copy(k[:], append(bytesutil.Uint64ToBytesBigEndian(uint64(slot)), r[:]...))
|
||||
return k
|
||||
|
||||
24
beacon-chain/cache/payload_id_test.go
vendored
24
beacon-chain/cache/payload_id_test.go
vendored
@@ -3,7 +3,7 @@ package cache
|
||||
import (
|
||||
"testing"
|
||||
|
||||
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
"github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
||||
)
|
||||
|
||||
@@ -12,11 +12,11 @@ func TestValidatorPayloadIDsCache_GetAndSaveValidatorPayloadIDs(t *testing.T) {
|
||||
var r [32]byte
|
||||
i, p, ok := cache.GetProposerPayloadIDs(0, r)
|
||||
require.Equal(t, false, ok)
|
||||
require.Equal(t, types.ValidatorIndex(0), i)
|
||||
require.Equal(t, primitives.ValidatorIndex(0), i)
|
||||
require.Equal(t, [pIdLength]byte{}, p)
|
||||
|
||||
slot := types.Slot(1234)
|
||||
vid := types.ValidatorIndex(34234324)
|
||||
slot := primitives.Slot(1234)
|
||||
vid := primitives.ValidatorIndex(34234324)
|
||||
pid := [8]byte{1, 2, 3, 3, 7, 8, 7, 8}
|
||||
r = [32]byte{1, 2, 3}
|
||||
cache.SetProposerAndPayloadIDs(slot, vid, pid, r)
|
||||
@@ -25,8 +25,8 @@ func TestValidatorPayloadIDsCache_GetAndSaveValidatorPayloadIDs(t *testing.T) {
|
||||
require.Equal(t, vid, i)
|
||||
require.Equal(t, pid, p)
|
||||
|
||||
slot = types.Slot(9456456)
|
||||
vid = types.ValidatorIndex(6786745)
|
||||
slot = primitives.Slot(9456456)
|
||||
vid = primitives.ValidatorIndex(6786745)
|
||||
r = [32]byte{4, 5, 6}
|
||||
cache.SetProposerAndPayloadIDs(slot, vid, [pIdLength]byte{}, r)
|
||||
i, p, ok = cache.GetProposerPayloadIDs(slot, r)
|
||||
@@ -35,8 +35,8 @@ func TestValidatorPayloadIDsCache_GetAndSaveValidatorPayloadIDs(t *testing.T) {
|
||||
require.Equal(t, [pIdLength]byte{}, p)
|
||||
|
||||
// reset cache without pid
|
||||
slot = types.Slot(9456456)
|
||||
vid = types.ValidatorIndex(11111)
|
||||
slot = primitives.Slot(9456456)
|
||||
vid = primitives.ValidatorIndex(11111)
|
||||
r = [32]byte{7, 8, 9}
|
||||
pid = [8]byte{3, 2, 3, 33, 72, 8, 7, 8}
|
||||
cache.SetProposerAndPayloadIDs(slot, vid, pid, r)
|
||||
@@ -49,12 +49,12 @@ func TestValidatorPayloadIDsCache_GetAndSaveValidatorPayloadIDs(t *testing.T) {
|
||||
r = [32]byte{1, 2, 3}
|
||||
i, p, ok = cache.GetProposerPayloadIDs(slot, r)
|
||||
require.Equal(t, false, ok)
|
||||
require.Equal(t, types.ValidatorIndex(0), i)
|
||||
require.Equal(t, primitives.ValidatorIndex(0), i)
|
||||
require.Equal(t, [pIdLength]byte{}, p)
|
||||
|
||||
// existing pid - no change in cache
|
||||
slot = types.Slot(9456456)
|
||||
vid = types.ValidatorIndex(11111)
|
||||
slot = primitives.Slot(9456456)
|
||||
vid = primitives.ValidatorIndex(11111)
|
||||
r = [32]byte{7, 8, 9}
|
||||
newPid := [8]byte{1, 2, 3, 33, 72, 8, 7, 1}
|
||||
cache.SetProposerAndPayloadIDs(slot, vid, newPid, r)
|
||||
@@ -67,6 +67,6 @@ func TestValidatorPayloadIDsCache_GetAndSaveValidatorPayloadIDs(t *testing.T) {
|
||||
cache.PrunePayloadIDs(slot + 1)
|
||||
i, p, ok = cache.GetProposerPayloadIDs(slot, r)
|
||||
require.Equal(t, false, ok)
|
||||
require.Equal(t, types.ValidatorIndex(0), i)
|
||||
require.Equal(t, primitives.ValidatorIndex(0), i)
|
||||
require.Equal(t, [pIdLength]byte{}, p)
|
||||
}
|
||||
|
||||
4
beacon-chain/cache/proposer_indices.go
vendored
4
beacon-chain/cache/proposer_indices.go
vendored
@@ -7,7 +7,7 @@ import (
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
"github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
"k8s.io/client-go/tools/cache"
|
||||
)
|
||||
|
||||
@@ -76,7 +76,7 @@ func (c *ProposerIndicesCache) HasProposerIndices(r [32]byte) (bool, error) {
|
||||
}
|
||||
|
||||
// ProposerIndices returns the proposer indices of a block root seed.
|
||||
func (c *ProposerIndicesCache) ProposerIndices(r [32]byte) ([]types.ValidatorIndex, error) {
|
||||
func (c *ProposerIndicesCache) ProposerIndices(r [32]byte) ([]primitives.ValidatorIndex, error) {
|
||||
c.lock.RLock()
|
||||
defer c.lock.RUnlock()
|
||||
obj, exists, err := c.proposerIndicesCache.GetByKey(key(r))
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// This file is used in fuzzer builds to bypass proposer indices caches.
|
||||
package cache
|
||||
|
||||
import types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
import "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
|
||||
// FakeProposerIndicesCache is a struct with 1 queue for looking up proposer indices by root.
|
||||
type FakeProposerIndicesCache struct {
|
||||
@@ -21,7 +21,7 @@ func (c *FakeProposerIndicesCache) AddProposerIndices(p *ProposerIndices) error
|
||||
}
|
||||
|
||||
// ProposerIndices returns the proposer indices of a block root seed.
|
||||
func (c *FakeProposerIndicesCache) ProposerIndices(r [32]byte) ([]types.ValidatorIndex, error) {
|
||||
func (c *FakeProposerIndicesCache) ProposerIndices(r [32]byte) ([]primitives.ValidatorIndex, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
|
||||
6
beacon-chain/cache/proposer_indices_test.go
vendored
6
beacon-chain/cache/proposer_indices_test.go
vendored
@@ -6,7 +6,7 @@ import (
|
||||
"strconv"
|
||||
"testing"
|
||||
|
||||
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
"github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
"github.com/prysmaticlabs/prysm/v3/encoding/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/assert"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
func TestProposerKeyFn_OK(t *testing.T) {
|
||||
item := &ProposerIndices{
|
||||
BlockRoot: [32]byte{'A'},
|
||||
ProposerIndices: []types.ValidatorIndex{1, 2, 3, 4, 5},
|
||||
ProposerIndices: []primitives.ValidatorIndex{1, 2, 3, 4, 5},
|
||||
}
|
||||
|
||||
k, err := proposerIndicesKeyFn(item)
|
||||
@@ -51,7 +51,7 @@ func TestProposerCache_AddProposerIndicesList(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, true, has)
|
||||
|
||||
item := &ProposerIndices{BlockRoot: [32]byte{'B'}, ProposerIndices: []types.ValidatorIndex{1, 2, 3, 4, 5, 6}}
|
||||
item := &ProposerIndices{BlockRoot: [32]byte{'B'}, ProposerIndices: []primitives.ValidatorIndex{1, 2, 3, 4, 5, 6}}
|
||||
require.NoError(t, cache.AddProposerIndices(item))
|
||||
|
||||
received, err = cache.ProposerIndices(item.BlockRoot)
|
||||
|
||||
4
beacon-chain/cache/proposer_indices_type.go
vendored
4
beacon-chain/cache/proposer_indices_type.go
vendored
@@ -3,7 +3,7 @@ package cache
|
||||
import (
|
||||
"errors"
|
||||
|
||||
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
"github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
)
|
||||
|
||||
// ErrNotProposerIndices will be returned when a cache object is not a pointer to
|
||||
@@ -13,5 +13,5 @@ var ErrNotProposerIndices = errors.New("object is not a proposer indices struct"
|
||||
// ProposerIndices defines the cached struct for proposer indices.
|
||||
type ProposerIndices struct {
|
||||
BlockRoot [32]byte
|
||||
ProposerIndices []types.ValidatorIndex
|
||||
ProposerIndices []primitives.ValidatorIndex
|
||||
}
|
||||
|
||||
10
beacon-chain/cache/subnet_ids.go
vendored
10
beacon-chain/cache/subnet_ids.go
vendored
@@ -8,7 +8,7 @@ import (
|
||||
"github.com/patrickmn/go-cache"
|
||||
lruwrpr "github.com/prysmaticlabs/prysm/v3/cache/lru"
|
||||
"github.com/prysmaticlabs/prysm/v3/config/params"
|
||||
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
"github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
"github.com/prysmaticlabs/prysm/v3/container/slice"
|
||||
)
|
||||
|
||||
@@ -37,7 +37,7 @@ func newSubnetIDs() *subnetIDs {
|
||||
}
|
||||
|
||||
// AddAttesterSubnetID adds the subnet index for subscribing subnet for the attester of a given slot.
|
||||
func (s *subnetIDs) AddAttesterSubnetID(slot types.Slot, subnetID uint64) {
|
||||
func (s *subnetIDs) AddAttesterSubnetID(slot primitives.Slot, subnetID uint64) {
|
||||
s.attesterLock.Lock()
|
||||
defer s.attesterLock.Unlock()
|
||||
|
||||
@@ -50,7 +50,7 @@ func (s *subnetIDs) AddAttesterSubnetID(slot types.Slot, subnetID uint64) {
|
||||
}
|
||||
|
||||
// GetAttesterSubnetIDs gets the subnet IDs for subscribed subnets for attesters of the slot.
|
||||
func (s *subnetIDs) GetAttesterSubnetIDs(slot types.Slot) []uint64 {
|
||||
func (s *subnetIDs) GetAttesterSubnetIDs(slot primitives.Slot) []uint64 {
|
||||
s.attesterLock.RLock()
|
||||
defer s.attesterLock.RUnlock()
|
||||
|
||||
@@ -65,7 +65,7 @@ func (s *subnetIDs) GetAttesterSubnetIDs(slot types.Slot) []uint64 {
|
||||
}
|
||||
|
||||
// AddAggregatorSubnetID adds the subnet ID for subscribing subnet for the aggregator of a given slot.
|
||||
func (s *subnetIDs) AddAggregatorSubnetID(slot types.Slot, subnetID uint64) {
|
||||
func (s *subnetIDs) AddAggregatorSubnetID(slot primitives.Slot, subnetID uint64) {
|
||||
s.aggregatorLock.Lock()
|
||||
defer s.aggregatorLock.Unlock()
|
||||
|
||||
@@ -78,7 +78,7 @@ func (s *subnetIDs) AddAggregatorSubnetID(slot types.Slot, subnetID uint64) {
|
||||
}
|
||||
|
||||
// GetAggregatorSubnetIDs gets the subnet IDs for subscribing subnet for aggregator of the slot.
|
||||
func (s *subnetIDs) GetAggregatorSubnetIDs(slot types.Slot) []uint64 {
|
||||
func (s *subnetIDs) GetAggregatorSubnetIDs(slot primitives.Slot) []uint64 {
|
||||
s.aggregatorLock.RLock()
|
||||
defer s.aggregatorLock.RUnlock()
|
||||
|
||||
|
||||
4
beacon-chain/cache/subnet_ids_test.go
vendored
4
beacon-chain/cache/subnet_ids_test.go
vendored
@@ -4,14 +4,14 @@ import (
|
||||
"testing"
|
||||
|
||||
fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams"
|
||||
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
"github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/assert"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
||||
)
|
||||
|
||||
func TestSubnetIDsCache_RoundTrip(t *testing.T) {
|
||||
c := newSubnetIDs()
|
||||
slot := types.Slot(100)
|
||||
slot := primitives.Slot(100)
|
||||
committeeIDs := c.GetAggregatorSubnetIDs(slot)
|
||||
assert.Equal(t, 0, len(committeeIDs), "Empty cache returned an object")
|
||||
|
||||
|
||||
28
beacon-chain/cache/sync_committee.go
vendored
28
beacon-chain/cache/sync_committee.go
vendored
@@ -8,7 +8,7 @@ import (
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state"
|
||||
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
"github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
"github.com/prysmaticlabs/prysm/v3/encoding/bytesutil"
|
||||
"k8s.io/client-go/tools/cache"
|
||||
)
|
||||
@@ -40,13 +40,13 @@ type SyncCommitteeCache struct {
|
||||
// are cached where key is the validator index and the value is the `positionInCommittee` struct.
|
||||
type syncCommitteeIndexPosition struct {
|
||||
currentSyncCommitteeRoot [32]byte
|
||||
vIndexToPositionMap map[types.ValidatorIndex]*positionInCommittee
|
||||
vIndexToPositionMap map[primitives.ValidatorIndex]*positionInCommittee
|
||||
}
|
||||
|
||||
// Index position of individual validator of current period and next period sync committee.
|
||||
type positionInCommittee struct {
|
||||
currentPeriod []types.CommitteeIndex
|
||||
nextPeriod []types.CommitteeIndex
|
||||
currentPeriod []primitives.CommitteeIndex
|
||||
nextPeriod []primitives.CommitteeIndex
|
||||
}
|
||||
|
||||
// NewSyncCommittee initializes and returns a new SyncCommitteeCache.
|
||||
@@ -60,7 +60,7 @@ func NewSyncCommittee() *SyncCommitteeCache {
|
||||
// sync committee. If the input validator index has no assignment, an empty list will be returned.
|
||||
// If the input root does not exist in cache, `ErrNonExistingSyncCommitteeKey` is returned.
|
||||
// Manual checking of state for index position in state is recommended when `ErrNonExistingSyncCommitteeKey` is returned.
|
||||
func (s *SyncCommitteeCache) CurrentPeriodIndexPosition(root [32]byte, valIdx types.ValidatorIndex) ([]types.CommitteeIndex, error) {
|
||||
func (s *SyncCommitteeCache) CurrentPeriodIndexPosition(root [32]byte, valIdx primitives.ValidatorIndex) ([]primitives.CommitteeIndex, error) {
|
||||
s.lock.RLock()
|
||||
defer s.lock.RUnlock()
|
||||
|
||||
@@ -69,7 +69,7 @@ func (s *SyncCommitteeCache) CurrentPeriodIndexPosition(root [32]byte, valIdx ty
|
||||
return nil, err
|
||||
}
|
||||
if pos == nil {
|
||||
return []types.CommitteeIndex{}, nil
|
||||
return []primitives.CommitteeIndex{}, nil
|
||||
}
|
||||
|
||||
return pos.currentPeriod, nil
|
||||
@@ -79,7 +79,7 @@ func (s *SyncCommitteeCache) CurrentPeriodIndexPosition(root [32]byte, valIdx ty
|
||||
// If the input validator index has no assignment, an empty list will be returned.
|
||||
// If the input root does not exist in cache, `ErrNonExistingSyncCommitteeKey` is returned.
|
||||
// Manual checking of state for index position in state is recommended when `ErrNonExistingSyncCommitteeKey` is returned.
|
||||
func (s *SyncCommitteeCache) NextPeriodIndexPosition(root [32]byte, valIdx types.ValidatorIndex) ([]types.CommitteeIndex, error) {
|
||||
func (s *SyncCommitteeCache) NextPeriodIndexPosition(root [32]byte, valIdx primitives.ValidatorIndex) ([]primitives.CommitteeIndex, error) {
|
||||
s.lock.RLock()
|
||||
defer s.lock.RUnlock()
|
||||
|
||||
@@ -88,7 +88,7 @@ func (s *SyncCommitteeCache) NextPeriodIndexPosition(root [32]byte, valIdx types
|
||||
return nil, err
|
||||
}
|
||||
if pos == nil {
|
||||
return []types.CommitteeIndex{}, nil
|
||||
return []primitives.CommitteeIndex{}, nil
|
||||
}
|
||||
return pos.nextPeriod, nil
|
||||
}
|
||||
@@ -96,7 +96,7 @@ func (s *SyncCommitteeCache) NextPeriodIndexPosition(root [32]byte, valIdx types
|
||||
// Helper function for `CurrentPeriodIndexPosition` and `NextPeriodIndexPosition` to return a mapping
|
||||
// of validator index to its index(s) position in the sync committee.
|
||||
func (s *SyncCommitteeCache) idxPositionInCommittee(
|
||||
root [32]byte, valIdx types.ValidatorIndex,
|
||||
root [32]byte, valIdx primitives.ValidatorIndex,
|
||||
) (*positionInCommittee, error) {
|
||||
obj, exists, err := s.cache.GetByKey(key(root))
|
||||
if err != nil {
|
||||
@@ -127,7 +127,7 @@ func (s *SyncCommitteeCache) UpdatePositionsInCommittee(syncCommitteeBoundaryRoo
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
positionsMap := make(map[types.ValidatorIndex]*positionInCommittee)
|
||||
positionsMap := make(map[primitives.ValidatorIndex]*positionInCommittee)
|
||||
for i, pubkey := range csc.Pubkeys {
|
||||
p := bytesutil.ToBytes48(pubkey)
|
||||
validatorIndex, ok := st.ValidatorIndexByPubkey(p)
|
||||
@@ -135,10 +135,10 @@ func (s *SyncCommitteeCache) UpdatePositionsInCommittee(syncCommitteeBoundaryRoo
|
||||
continue
|
||||
}
|
||||
if _, ok := positionsMap[validatorIndex]; !ok {
|
||||
m := &positionInCommittee{currentPeriod: []types.CommitteeIndex{types.CommitteeIndex(i)}, nextPeriod: []types.CommitteeIndex{}}
|
||||
m := &positionInCommittee{currentPeriod: []primitives.CommitteeIndex{primitives.CommitteeIndex(i)}, nextPeriod: []primitives.CommitteeIndex{}}
|
||||
positionsMap[validatorIndex] = m
|
||||
} else {
|
||||
positionsMap[validatorIndex].currentPeriod = append(positionsMap[validatorIndex].currentPeriod, types.CommitteeIndex(i))
|
||||
positionsMap[validatorIndex].currentPeriod = append(positionsMap[validatorIndex].currentPeriod, primitives.CommitteeIndex(i))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,10 +153,10 @@ func (s *SyncCommitteeCache) UpdatePositionsInCommittee(syncCommitteeBoundaryRoo
|
||||
continue
|
||||
}
|
||||
if _, ok := positionsMap[validatorIndex]; !ok {
|
||||
m := &positionInCommittee{nextPeriod: []types.CommitteeIndex{types.CommitteeIndex(i)}, currentPeriod: []types.CommitteeIndex{}}
|
||||
m := &positionInCommittee{nextPeriod: []primitives.CommitteeIndex{primitives.CommitteeIndex(i)}, currentPeriod: []primitives.CommitteeIndex{}}
|
||||
positionsMap[validatorIndex] = m
|
||||
} else {
|
||||
positionsMap[validatorIndex].nextPeriod = append(positionsMap[validatorIndex].nextPeriod, types.CommitteeIndex(i))
|
||||
positionsMap[validatorIndex].nextPeriod = append(positionsMap[validatorIndex].nextPeriod, primitives.CommitteeIndex(i))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ package cache
|
||||
|
||||
import (
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state"
|
||||
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
"github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
)
|
||||
|
||||
// FakeSyncCommitteeCache is a fake `SyncCommitteeCache` to satisfy fuzzing.
|
||||
@@ -17,12 +17,12 @@ func NewSyncCommittee() *FakeSyncCommitteeCache {
|
||||
}
|
||||
|
||||
// CurrentEpochIndexPosition -- fake.
|
||||
func (s *FakeSyncCommitteeCache) CurrentPeriodIndexPosition(root [32]byte, valIdx types.ValidatorIndex) ([]types.CommitteeIndex, error) {
|
||||
func (s *FakeSyncCommitteeCache) CurrentPeriodIndexPosition(root [32]byte, valIdx primitives.ValidatorIndex) ([]primitives.CommitteeIndex, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// NextEpochIndexPosition -- fake.
|
||||
func (s *FakeSyncCommitteeCache) NextPeriodIndexPosition(root [32]byte, valIdx types.ValidatorIndex) ([]types.CommitteeIndex, error) {
|
||||
func (s *FakeSyncCommitteeCache) NextPeriodIndexPosition(root [32]byte, valIdx primitives.ValidatorIndex) ([]primitives.CommitteeIndex, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
lru "github.com/hashicorp/golang-lru"
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state"
|
||||
lruwrpr "github.com/prysmaticlabs/prysm/v3/cache/lru"
|
||||
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
"github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
"github.com/prysmaticlabs/prysm/v3/runtime/version"
|
||||
)
|
||||
|
||||
@@ -23,7 +23,7 @@ func NewSyncCommitteeHeadState() *SyncCommitteeHeadStateCache {
|
||||
}
|
||||
|
||||
// Put `slot` as key and `state` as value onto the cache.
|
||||
func (c *SyncCommitteeHeadStateCache) Put(slot types.Slot, st state.BeaconState) error {
|
||||
func (c *SyncCommitteeHeadStateCache) Put(slot primitives.Slot, st state.BeaconState) error {
|
||||
c.lock.Lock()
|
||||
defer c.lock.Unlock()
|
||||
// Make sure that the provided state is non nil
|
||||
@@ -41,7 +41,7 @@ func (c *SyncCommitteeHeadStateCache) Put(slot types.Slot, st state.BeaconState)
|
||||
}
|
||||
|
||||
// Get `state` using `slot` as key. Return nil if nothing is found.
|
||||
func (c *SyncCommitteeHeadStateCache) Get(slot types.Slot) (state.BeaconState, error) {
|
||||
func (c *SyncCommitteeHeadStateCache) Get(slot primitives.Slot) (state.BeaconState, error) {
|
||||
c.lock.RLock()
|
||||
defer c.lock.RUnlock()
|
||||
val, exists := c.cache.Get(slot)
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/state"
|
||||
state_native "github.com/prysmaticlabs/prysm/v3/beacon-chain/state/state-native"
|
||||
"github.com/prysmaticlabs/prysm/v3/config/params"
|
||||
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
"github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
||||
)
|
||||
@@ -41,12 +41,12 @@ func TestSyncCommitteeHeadState(t *testing.T) {
|
||||
})
|
||||
require.NoError(t, err)
|
||||
type put struct {
|
||||
slot types.Slot
|
||||
slot primitives.Slot
|
||||
state state.BeaconState
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
key types.Slot
|
||||
key primitives.Slot
|
||||
put *put
|
||||
want state.BeaconState
|
||||
wantErr bool
|
||||
@@ -54,9 +54,9 @@ func TestSyncCommitteeHeadState(t *testing.T) {
|
||||
}{
|
||||
{
|
||||
name: "putting error in",
|
||||
key: types.Slot(1),
|
||||
key: primitives.Slot(1),
|
||||
put: &put{
|
||||
slot: types.Slot(1),
|
||||
slot: primitives.Slot(1),
|
||||
state: nil,
|
||||
},
|
||||
wantPutErr: true,
|
||||
@@ -64,9 +64,9 @@ func TestSyncCommitteeHeadState(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "putting invalid state in",
|
||||
key: types.Slot(1),
|
||||
key: primitives.Slot(1),
|
||||
put: &put{
|
||||
slot: types.Slot(1),
|
||||
slot: primitives.Slot(1),
|
||||
state: phase0State,
|
||||
},
|
||||
wantPutErr: true,
|
||||
@@ -74,50 +74,50 @@ func TestSyncCommitteeHeadState(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "not found when empty cache",
|
||||
key: types.Slot(1),
|
||||
key: primitives.Slot(1),
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "not found when non-existent key in non-empty cache",
|
||||
key: types.Slot(2),
|
||||
key: primitives.Slot(2),
|
||||
put: &put{
|
||||
slot: types.Slot(1),
|
||||
slot: primitives.Slot(1),
|
||||
state: beaconState,
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "found with key",
|
||||
key: types.Slot(1),
|
||||
key: primitives.Slot(1),
|
||||
put: &put{
|
||||
slot: types.Slot(1),
|
||||
slot: primitives.Slot(1),
|
||||
state: beaconState,
|
||||
},
|
||||
want: beaconState,
|
||||
},
|
||||
{
|
||||
name: "not found when non-existent key in non-empty cache (bellatrix state)",
|
||||
key: types.Slot(2),
|
||||
key: primitives.Slot(2),
|
||||
put: &put{
|
||||
slot: types.Slot(1),
|
||||
slot: primitives.Slot(1),
|
||||
state: bellatrixState,
|
||||
},
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "found with key (bellatrix state)",
|
||||
key: types.Slot(100),
|
||||
key: primitives.Slot(100),
|
||||
put: &put{
|
||||
slot: types.Slot(100),
|
||||
slot: primitives.Slot(100),
|
||||
state: bellatrixState,
|
||||
},
|
||||
want: bellatrixState,
|
||||
},
|
||||
{
|
||||
name: "found with key (capella state)",
|
||||
key: types.Slot(200),
|
||||
key: primitives.Slot(200),
|
||||
put: &put{
|
||||
slot: types.Slot(200),
|
||||
slot: primitives.Slot(200),
|
||||
state: capellaState,
|
||||
},
|
||||
want: capellaState,
|
||||
|
||||
30
beacon-chain/cache/sync_committee_test.go
vendored
30
beacon-chain/cache/sync_committee_test.go
vendored
@@ -4,7 +4,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/prysmaticlabs/prysm/v3/beacon-chain/cache"
|
||||
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
"github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/require"
|
||||
"github.com/prysmaticlabs/prysm/v3/testing/util"
|
||||
@@ -21,8 +21,8 @@ func TestSyncCommitteeCache_CanUpdateAndRetrieve(t *testing.T) {
|
||||
name string
|
||||
currentSyncCommittee *ethpb.SyncCommittee
|
||||
nextSyncCommittee *ethpb.SyncCommittee
|
||||
currentSyncMap map[types.ValidatorIndex][]types.CommitteeIndex
|
||||
nextSyncMap map[types.ValidatorIndex][]types.CommitteeIndex
|
||||
currentSyncMap map[primitives.ValidatorIndex][]primitives.CommitteeIndex
|
||||
nextSyncMap map[primitives.ValidatorIndex][]primitives.CommitteeIndex
|
||||
}{
|
||||
{
|
||||
name: "only current epoch",
|
||||
@@ -30,12 +30,12 @@ func TestSyncCommitteeCache_CanUpdateAndRetrieve(t *testing.T) {
|
||||
pubKeys[1], pubKeys[2], pubKeys[3], pubKeys[2], pubKeys[2],
|
||||
}),
|
||||
nextSyncCommittee: util.ConvertToCommittee([][]byte{}),
|
||||
currentSyncMap: map[types.ValidatorIndex][]types.CommitteeIndex{
|
||||
currentSyncMap: map[primitives.ValidatorIndex][]primitives.CommitteeIndex{
|
||||
1: {0},
|
||||
2: {1, 3, 4},
|
||||
3: {2},
|
||||
},
|
||||
nextSyncMap: map[types.ValidatorIndex][]types.CommitteeIndex{
|
||||
nextSyncMap: map[primitives.ValidatorIndex][]primitives.CommitteeIndex{
|
||||
1: {},
|
||||
2: {},
|
||||
3: {},
|
||||
@@ -47,12 +47,12 @@ func TestSyncCommitteeCache_CanUpdateAndRetrieve(t *testing.T) {
|
||||
nextSyncCommittee: util.ConvertToCommittee([][]byte{
|
||||
pubKeys[1], pubKeys[2], pubKeys[3], pubKeys[2], pubKeys[2],
|
||||
}),
|
||||
currentSyncMap: map[types.ValidatorIndex][]types.CommitteeIndex{
|
||||
currentSyncMap: map[primitives.ValidatorIndex][]primitives.CommitteeIndex{
|
||||
1: {},
|
||||
2: {},
|
||||
3: {},
|
||||
},
|
||||
nextSyncMap: map[types.ValidatorIndex][]types.CommitteeIndex{
|
||||
nextSyncMap: map[primitives.ValidatorIndex][]primitives.CommitteeIndex{
|
||||
1: {0},
|
||||
2: {1, 3, 4},
|
||||
3: {2},
|
||||
@@ -74,12 +74,12 @@ func TestSyncCommitteeCache_CanUpdateAndRetrieve(t *testing.T) {
|
||||
pubKeys[4],
|
||||
pubKeys[7],
|
||||
}),
|
||||
currentSyncMap: map[types.ValidatorIndex][]types.CommitteeIndex{
|
||||
currentSyncMap: map[primitives.ValidatorIndex][]primitives.CommitteeIndex{
|
||||
1: {0},
|
||||
2: {1, 3, 4},
|
||||
3: {2},
|
||||
},
|
||||
nextSyncMap: map[types.ValidatorIndex][]types.CommitteeIndex{
|
||||
nextSyncMap: map[primitives.ValidatorIndex][]primitives.CommitteeIndex{
|
||||
7: {0, 4},
|
||||
6: {1},
|
||||
5: {2},
|
||||
@@ -102,12 +102,12 @@ func TestSyncCommitteeCache_CanUpdateAndRetrieve(t *testing.T) {
|
||||
pubKeys[2],
|
||||
pubKeys[1],
|
||||
}),
|
||||
currentSyncMap: map[types.ValidatorIndex][]types.CommitteeIndex{
|
||||
currentSyncMap: map[primitives.ValidatorIndex][]primitives.CommitteeIndex{
|
||||
1: {0},
|
||||
2: {1, 3, 4},
|
||||
3: {2},
|
||||
},
|
||||
nextSyncMap: map[types.ValidatorIndex][]types.CommitteeIndex{
|
||||
nextSyncMap: map[primitives.ValidatorIndex][]primitives.CommitteeIndex{
|
||||
1: {1, 4},
|
||||
2: {0, 3},
|
||||
3: {2},
|
||||
@@ -127,10 +127,10 @@ func TestSyncCommitteeCache_CanUpdateAndRetrieve(t *testing.T) {
|
||||
pubKeys[100],
|
||||
pubKeys[100],
|
||||
}),
|
||||
currentSyncMap: map[types.ValidatorIndex][]types.CommitteeIndex{
|
||||
currentSyncMap: map[primitives.ValidatorIndex][]primitives.CommitteeIndex{
|
||||
100: {0, 1, 2, 3},
|
||||
},
|
||||
nextSyncMap: map[types.ValidatorIndex][]types.CommitteeIndex{
|
||||
nextSyncMap: map[primitives.ValidatorIndex][]primitives.CommitteeIndex{
|
||||
100: {0, 1, 2, 3},
|
||||
},
|
||||
},
|
||||
@@ -148,10 +148,10 @@ func TestSyncCommitteeCache_CanUpdateAndRetrieve(t *testing.T) {
|
||||
pubKeys[100],
|
||||
pubKeys[100],
|
||||
}),
|
||||
currentSyncMap: map[types.ValidatorIndex][]types.CommitteeIndex{
|
||||
currentSyncMap: map[primitives.ValidatorIndex][]primitives.CommitteeIndex{
|
||||
1: {},
|
||||
},
|
||||
nextSyncMap: map[types.ValidatorIndex][]types.CommitteeIndex{
|
||||
nextSyncMap: map[primitives.ValidatorIndex][]primitives.CommitteeIndex{
|
||||
1: {},
|
||||
},
|
||||
},
|
||||
|
||||
14
beacon-chain/cache/sync_subnet_ids.go
vendored
14
beacon-chain/cache/sync_subnet_ids.go
vendored
@@ -6,7 +6,7 @@ import (
|
||||
|
||||
"github.com/patrickmn/go-cache"
|
||||
"github.com/prysmaticlabs/prysm/v3/config/params"
|
||||
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
"github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
|
||||
"github.com/prysmaticlabs/prysm/v3/container/slice"
|
||||
"github.com/prysmaticlabs/prysm/v3/crypto/rand"
|
||||
"github.com/prysmaticlabs/prysm/v3/encoding/bytesutil"
|
||||
@@ -29,7 +29,7 @@ func newSyncSubnetIDs() *syncSubnetIDs {
|
||||
}
|
||||
|
||||
// GetSyncCommitteeSubnets retrieves the sync committee subnet and expiration time of that validator's subscription.
|
||||
func (s *syncSubnetIDs) GetSyncCommitteeSubnets(pubkey []byte, epoch types.Epoch) ([]uint64, types.Epoch, bool, time.Time) {
|
||||
func (s *syncSubnetIDs) GetSyncCommitteeSubnets(pubkey []byte, epoch primitives.Epoch) ([]uint64, primitives.Epoch, bool, time.Time) {
|
||||
s.sCommiteeLock.RLock()
|
||||
defer s.sCommiteeLock.RUnlock()
|
||||
|
||||
@@ -50,13 +50,13 @@ func (s *syncSubnetIDs) GetSyncCommitteeSubnets(pubkey []byte, epoch types.Epoch
|
||||
// Index 0 was used to store validator's join epoch. We do not
|
||||
// return it to the caller.
|
||||
// Index 1 and beyond were used to store subnets.
|
||||
return idxs[1:], types.Epoch(idxs[0]), ok, duration
|
||||
return idxs[1:], primitives.Epoch(idxs[0]), ok, duration
|
||||
}
|
||||
|
||||
// GetAllSubnets retrieves all the non-expired subscribed subnets of all the validators
|
||||
// in the cache. This method also takes the epoch as an argument to only retrieve
|
||||
// assignments for epochs that have happened.
|
||||
func (s *syncSubnetIDs) GetAllSubnets(currEpoch types.Epoch) []uint64 {
|
||||
func (s *syncSubnetIDs) GetAllSubnets(currEpoch primitives.Epoch) []uint64 {
|
||||
s.sCommiteeLock.RLock()
|
||||
defer s.sCommiteeLock.RUnlock()
|
||||
|
||||
@@ -79,7 +79,7 @@ func (s *syncSubnetIDs) GetAllSubnets(currEpoch types.Epoch) []uint64 {
|
||||
// Check if the subnet is valid in the current epoch. If our
|
||||
// join epoch is still in the future we skip retrieving the
|
||||
// relevant committee index.
|
||||
if types.Epoch(idxs[0]) > currEpoch {
|
||||
if primitives.Epoch(idxs[0]) > currEpoch {
|
||||
continue
|
||||
}
|
||||
// Ignore the first index as that represents the
|
||||
@@ -92,7 +92,7 @@ func (s *syncSubnetIDs) GetAllSubnets(currEpoch types.Epoch) []uint64 {
|
||||
// AddSyncCommitteeSubnets adds the relevant committee for that particular validator along with its
|
||||
// expiration period. An Epoch argument here denotes the epoch from which the sync committee subnets
|
||||
// will be active.
|
||||
func (s *syncSubnetIDs) AddSyncCommitteeSubnets(pubkey []byte, epoch types.Epoch, comIndex []uint64, duration time.Duration) {
|
||||
func (s *syncSubnetIDs) AddSyncCommitteeSubnets(pubkey []byte, epoch primitives.Epoch, comIndex []uint64, duration time.Duration) {
|
||||
s.sCommiteeLock.Lock()
|
||||
defer s.sCommiteeLock.Unlock()
|
||||
subComCount := params.BeaconConfig().SyncCommitteeSubnetCount
|
||||
@@ -125,7 +125,7 @@ func (s *syncSubnetIDs) EmptyAllCaches() {
|
||||
|
||||
// build a key composed of both the pubkey and epoch here. The epoch
|
||||
// here would be the 1st epoch of the sync committee period.
|
||||
func keyBuilder(pubkey []byte, epoch types.Epoch) string {
|
||||
func keyBuilder(pubkey []byte, epoch primitives.Epoch) string {
|
||||
epochBytes := bytesutil.Bytes8(uint64(epoch))
|
||||
return string(append(pubkey, epochBytes...))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user