mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 15:37:56 -05:00
Use fieldparams for BLS public key (#10042)
* Use fieldparams for pubkey length * Fix validator tests * fix more tests * fix mock validator * Fix typo * bunch of typos * Update bytes.go * Update BUILD.bazel Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
This commit is contained in:
@@ -7,6 +7,7 @@ go_library(
|
||||
# Other packages must use github.com/prysmaticlabs/prysm/validator/db.Database alias.
|
||||
visibility = ["//validator/db:__subpackages__"],
|
||||
deps = [
|
||||
"//config/fieldparams:go_default_library",
|
||||
"//monitoring/backup:go_default_library",
|
||||
"//proto/prysm/v1alpha1:go_default_library",
|
||||
"//validator/db/kv:go_default_library",
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"io"
|
||||
|
||||
types "github.com/prysmaticlabs/eth2-types"
|
||||
fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams"
|
||||
"github.com/prysmaticlabs/prysm/monitoring/backup"
|
||||
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/validator/db/kv"
|
||||
@@ -22,40 +23,40 @@ type ValidatorDB interface {
|
||||
ClearDB() error
|
||||
RunUpMigrations(ctx context.Context) error
|
||||
RunDownMigrations(ctx context.Context) error
|
||||
UpdatePublicKeysBuckets(publicKeys [][48]byte) error
|
||||
UpdatePublicKeysBuckets(publicKeys [][fieldparams.BLSPubkeyLength]byte) error
|
||||
|
||||
// Genesis information related methods.
|
||||
GenesisValidatorsRoot(ctx context.Context) ([]byte, error)
|
||||
SaveGenesisValidatorsRoot(ctx context.Context, genValRoot []byte) error
|
||||
|
||||
// Proposer protection related methods.
|
||||
HighestSignedProposal(ctx context.Context, publicKey [48]byte) (types.Slot, bool, error)
|
||||
LowestSignedProposal(ctx context.Context, publicKey [48]byte) (types.Slot, bool, error)
|
||||
ProposalHistoryForPubKey(ctx context.Context, publicKey [48]byte) ([]*kv.Proposal, error)
|
||||
ProposalHistoryForSlot(ctx context.Context, publicKey [48]byte, slot types.Slot) ([32]byte, bool, error)
|
||||
SaveProposalHistoryForSlot(ctx context.Context, pubKey [48]byte, slot types.Slot, signingRoot []byte) error
|
||||
ProposedPublicKeys(ctx context.Context) ([][48]byte, error)
|
||||
HighestSignedProposal(ctx context.Context, publicKey [fieldparams.BLSPubkeyLength]byte) (types.Slot, bool, error)
|
||||
LowestSignedProposal(ctx context.Context, publicKey [fieldparams.BLSPubkeyLength]byte) (types.Slot, bool, error)
|
||||
ProposalHistoryForPubKey(ctx context.Context, publicKey [fieldparams.BLSPubkeyLength]byte) ([]*kv.Proposal, error)
|
||||
ProposalHistoryForSlot(ctx context.Context, publicKey [fieldparams.BLSPubkeyLength]byte, slot types.Slot) ([32]byte, bool, error)
|
||||
SaveProposalHistoryForSlot(ctx context.Context, pubKey [fieldparams.BLSPubkeyLength]byte, slot types.Slot, signingRoot []byte) error
|
||||
ProposedPublicKeys(ctx context.Context) ([][fieldparams.BLSPubkeyLength]byte, error)
|
||||
|
||||
// Attester protection related methods.
|
||||
// Methods to store and read blacklisted public keys from EIP-3076
|
||||
// slashing protection imports.
|
||||
EIPImportBlacklistedPublicKeys(ctx context.Context) ([][48]byte, error)
|
||||
SaveEIPImportBlacklistedPublicKeys(ctx context.Context, publicKeys [][48]byte) error
|
||||
SigningRootAtTargetEpoch(ctx context.Context, publicKey [48]byte, target types.Epoch) ([32]byte, error)
|
||||
LowestSignedTargetEpoch(ctx context.Context, publicKey [48]byte) (types.Epoch, bool, error)
|
||||
LowestSignedSourceEpoch(ctx context.Context, publicKey [48]byte) (types.Epoch, bool, error)
|
||||
AttestedPublicKeys(ctx context.Context) ([][48]byte, error)
|
||||
EIPImportBlacklistedPublicKeys(ctx context.Context) ([][fieldparams.BLSPubkeyLength]byte, error)
|
||||
SaveEIPImportBlacklistedPublicKeys(ctx context.Context, publicKeys [][fieldparams.BLSPubkeyLength]byte) error
|
||||
SigningRootAtTargetEpoch(ctx context.Context, publicKey [fieldparams.BLSPubkeyLength]byte, target types.Epoch) ([32]byte, error)
|
||||
LowestSignedTargetEpoch(ctx context.Context, publicKey [fieldparams.BLSPubkeyLength]byte) (types.Epoch, bool, error)
|
||||
LowestSignedSourceEpoch(ctx context.Context, publicKey [fieldparams.BLSPubkeyLength]byte) (types.Epoch, bool, error)
|
||||
AttestedPublicKeys(ctx context.Context) ([][fieldparams.BLSPubkeyLength]byte, error)
|
||||
CheckSlashableAttestation(
|
||||
ctx context.Context, pubKey [48]byte, signingRoot [32]byte, att *ethpb.IndexedAttestation,
|
||||
ctx context.Context, pubKey [fieldparams.BLSPubkeyLength]byte, signingRoot [32]byte, att *ethpb.IndexedAttestation,
|
||||
) (kv.SlashingKind, error)
|
||||
SaveAttestationForPubKey(
|
||||
ctx context.Context, pubKey [48]byte, signingRoot [32]byte, att *ethpb.IndexedAttestation,
|
||||
ctx context.Context, pubKey [fieldparams.BLSPubkeyLength]byte, signingRoot [32]byte, att *ethpb.IndexedAttestation,
|
||||
) error
|
||||
SaveAttestationsForPubKey(
|
||||
ctx context.Context, pubKey [48]byte, signingRoots [][32]byte, atts []*ethpb.IndexedAttestation,
|
||||
ctx context.Context, pubKey [fieldparams.BLSPubkeyLength]byte, signingRoots [][32]byte, atts []*ethpb.IndexedAttestation,
|
||||
) error
|
||||
AttestationHistoryForPubKey(
|
||||
ctx context.Context, pubKey [48]byte,
|
||||
ctx context.Context, pubKey [fieldparams.BLSPubkeyLength]byte,
|
||||
) ([]*kv.AttestationRecord, error)
|
||||
|
||||
// Graffiti ordered index related methods
|
||||
|
||||
@@ -63,6 +63,7 @@ go_test(
|
||||
],
|
||||
embed = [":go_default_library"],
|
||||
deps = [
|
||||
"//config/fieldparams:go_default_library",
|
||||
"//config/params:go_default_library",
|
||||
"//crypto/hash:go_default_library",
|
||||
"//encoding/bytesutil:go_default_library",
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
|
||||
"github.com/pkg/errors"
|
||||
types "github.com/prysmaticlabs/eth2-types"
|
||||
fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams"
|
||||
"github.com/prysmaticlabs/prysm/encoding/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/monitoring/tracing"
|
||||
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||
@@ -22,7 +23,7 @@ type SlashingKind int
|
||||
// AttestationRecord which can be represented by these simple values
|
||||
// for manipulation by database methods.
|
||||
type AttestationRecord struct {
|
||||
PubKey [48]byte
|
||||
PubKey [fieldparams.BLSPubkeyLength]byte
|
||||
Source types.Epoch
|
||||
Target types.Epoch
|
||||
SigningRoot [32]byte
|
||||
@@ -92,7 +93,7 @@ var (
|
||||
|
||||
// AttestationHistoryForPubKey retrieves a list of attestation records for data
|
||||
// we have stored in the database for the given validator public key.
|
||||
func (s *Store) AttestationHistoryForPubKey(ctx context.Context, pubKey [48]byte) ([]*AttestationRecord, error) {
|
||||
func (s *Store) AttestationHistoryForPubKey(ctx context.Context, pubKey [fieldparams.BLSPubkeyLength]byte) ([]*AttestationRecord, error) {
|
||||
records := make([]*AttestationRecord, 0)
|
||||
_, span := trace.StartSpan(ctx, "Validator.AttestationHistoryForPubKey")
|
||||
defer span.End()
|
||||
@@ -133,7 +134,7 @@ func (s *Store) AttestationHistoryForPubKey(ctx context.Context, pubKey [48]byte
|
||||
// CheckSlashableAttestation verifies an incoming attestation is
|
||||
// not a double vote for a validator public key nor a surround vote.
|
||||
func (s *Store) CheckSlashableAttestation(
|
||||
ctx context.Context, pubKey [48]byte, signingRoot [32]byte, att *ethpb.IndexedAttestation,
|
||||
ctx context.Context, pubKey [fieldparams.BLSPubkeyLength]byte, signingRoot [32]byte, att *ethpb.IndexedAttestation,
|
||||
) (SlashingKind, error) {
|
||||
ctx, span := trace.StartSpan(ctx, "Validator.CheckSlashableAttestation")
|
||||
defer span.End()
|
||||
@@ -273,7 +274,7 @@ func (_ *Store) checkSurroundingVote(
|
||||
|
||||
// SaveAttestationsForPubKey stores a batch of attestations all at once.
|
||||
func (s *Store) SaveAttestationsForPubKey(
|
||||
ctx context.Context, pubKey [48]byte, signingRoots [][32]byte, atts []*ethpb.IndexedAttestation,
|
||||
ctx context.Context, pubKey [fieldparams.BLSPubkeyLength]byte, signingRoots [][32]byte, atts []*ethpb.IndexedAttestation,
|
||||
) error {
|
||||
ctx, span := trace.StartSpan(ctx, "Validator.SaveAttestationsForPubKey")
|
||||
defer span.End()
|
||||
@@ -299,7 +300,7 @@ func (s *Store) SaveAttestationsForPubKey(
|
||||
// SaveAttestationForPubKey saves an attestation for a validator public
|
||||
// key for local validator slashing protection.
|
||||
func (s *Store) SaveAttestationForPubKey(
|
||||
ctx context.Context, pubKey [48]byte, signingRoot [32]byte, att *ethpb.IndexedAttestation,
|
||||
ctx context.Context, pubKey [fieldparams.BLSPubkeyLength]byte, signingRoot [32]byte, att *ethpb.IndexedAttestation,
|
||||
) error {
|
||||
_, span := trace.StartSpan(ctx, "Validator.SaveAttestationForPubKey")
|
||||
defer span.End()
|
||||
@@ -491,15 +492,15 @@ func (s *Store) saveAttestationRecords(ctx context.Context, atts []*AttestationR
|
||||
}
|
||||
|
||||
// AttestedPublicKeys retrieves all public keys that have attested.
|
||||
func (s *Store) AttestedPublicKeys(ctx context.Context) ([][48]byte, error) {
|
||||
func (s *Store) AttestedPublicKeys(ctx context.Context) ([][fieldparams.BLSPubkeyLength]byte, error) {
|
||||
_, span := trace.StartSpan(ctx, "Validator.AttestedPublicKeys")
|
||||
defer span.End()
|
||||
var err error
|
||||
attestedPublicKeys := make([][48]byte, 0)
|
||||
attestedPublicKeys := make([][fieldparams.BLSPubkeyLength]byte, 0)
|
||||
err = s.view(func(tx *bolt.Tx) error {
|
||||
bucket := tx.Bucket(pubKeysBucket)
|
||||
return bucket.ForEach(func(pubKey []byte, _ []byte) error {
|
||||
var pk [48]byte
|
||||
var pk [fieldparams.BLSPubkeyLength]byte
|
||||
copy(pk[:], pubKey)
|
||||
attestedPublicKeys = append(attestedPublicKeys, pk)
|
||||
return nil
|
||||
@@ -510,7 +511,7 @@ func (s *Store) AttestedPublicKeys(ctx context.Context) ([][48]byte, error) {
|
||||
|
||||
// SigningRootAtTargetEpoch checks for an existing signing root at a specified
|
||||
// target epoch for a given validator public key.
|
||||
func (s *Store) SigningRootAtTargetEpoch(ctx context.Context, pubKey [48]byte, target types.Epoch) ([32]byte, error) {
|
||||
func (s *Store) SigningRootAtTargetEpoch(ctx context.Context, pubKey [fieldparams.BLSPubkeyLength]byte, target types.Epoch) ([32]byte, error) {
|
||||
_, span := trace.StartSpan(ctx, "Validator.SigningRootAtTargetEpoch")
|
||||
defer span.End()
|
||||
var signingRoot [32]byte
|
||||
@@ -533,7 +534,7 @@ func (s *Store) SigningRootAtTargetEpoch(ctx context.Context, pubKey [48]byte, t
|
||||
|
||||
// LowestSignedSourceEpoch returns the lowest signed source epoch for a validator public key.
|
||||
// If no data exists, returning 0 is a sensible default.
|
||||
func (s *Store) LowestSignedSourceEpoch(ctx context.Context, publicKey [48]byte) (types.Epoch, bool, error) {
|
||||
func (s *Store) LowestSignedSourceEpoch(ctx context.Context, publicKey [fieldparams.BLSPubkeyLength]byte) (types.Epoch, bool, error) {
|
||||
_, span := trace.StartSpan(ctx, "Validator.LowestSignedSourceEpoch")
|
||||
defer span.End()
|
||||
|
||||
@@ -556,7 +557,7 @@ func (s *Store) LowestSignedSourceEpoch(ctx context.Context, publicKey [48]byte)
|
||||
|
||||
// LowestSignedTargetEpoch returns the lowest signed target epoch for a validator public key.
|
||||
// If no data exists, returning 0 is a sensible default.
|
||||
func (s *Store) LowestSignedTargetEpoch(ctx context.Context, publicKey [48]byte) (types.Epoch, bool, error) {
|
||||
func (s *Store) LowestSignedTargetEpoch(ctx context.Context, publicKey [fieldparams.BLSPubkeyLength]byte) (types.Epoch, bool, error) {
|
||||
_, span := trace.StartSpan(ctx, "Validator.LowestSignedTargetEpoch")
|
||||
defer span.End()
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"testing"
|
||||
|
||||
types "github.com/prysmaticlabs/eth2-types"
|
||||
fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams"
|
||||
"github.com/prysmaticlabs/prysm/encoding/bytesutil"
|
||||
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/testing/assert"
|
||||
@@ -45,7 +46,7 @@ func TestPendingAttestationRecords_Len(t *testing.T) {
|
||||
func TestStore_CheckSlashableAttestation_DoubleVote(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
numValidators := 1
|
||||
pubKeys := make([][48]byte, numValidators)
|
||||
pubKeys := make([][fieldparams.BLSPubkeyLength]byte, numValidators)
|
||||
validatorDB := setupDB(t, pubKeys)
|
||||
tests := []struct {
|
||||
name string
|
||||
@@ -116,7 +117,7 @@ func TestStore_CheckSlashableAttestation_DoubleVote(t *testing.T) {
|
||||
func TestStore_CheckSlashableAttestation_SurroundVote_MultipleTargetsPerSource(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
numValidators := 1
|
||||
pubKeys := make([][48]byte, numValidators)
|
||||
pubKeys := make([][fieldparams.BLSPubkeyLength]byte, numValidators)
|
||||
validatorDB := setupDB(t, pubKeys)
|
||||
|
||||
// Create an attestation with source 1 and target 50, save it.
|
||||
@@ -142,7 +143,7 @@ func TestStore_CheckSlashableAttestation_SurroundVote_54kEpochs(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
numValidators := 1
|
||||
numEpochs := types.Epoch(54000)
|
||||
pubKeys := make([][48]byte, numValidators)
|
||||
pubKeys := make([][fieldparams.BLSPubkeyLength]byte, numValidators)
|
||||
validatorDB := setupDB(t, pubKeys)
|
||||
|
||||
// Attest to every (source = epoch, target = epoch + 1) sequential pair
|
||||
@@ -219,8 +220,8 @@ func TestLowestSignedSourceEpoch_SaveRetrieve(t *testing.T) {
|
||||
require.NoError(t, validatorDB.Close(), "Failed to close database")
|
||||
require.NoError(t, validatorDB.ClearDB(), "Failed to clear database")
|
||||
})
|
||||
p0 := [48]byte{0}
|
||||
p1 := [48]byte{1}
|
||||
p0 := [fieldparams.BLSPubkeyLength]byte{0}
|
||||
p1 := [fieldparams.BLSPubkeyLength]byte{1}
|
||||
// Can save.
|
||||
require.NoError(
|
||||
t,
|
||||
@@ -278,8 +279,8 @@ func TestLowestSignedTargetEpoch_SaveRetrieveReplace(t *testing.T) {
|
||||
require.NoError(t, validatorDB.Close(), "Failed to close database")
|
||||
require.NoError(t, validatorDB.ClearDB(), "Failed to clear database")
|
||||
})
|
||||
p0 := [48]byte{0}
|
||||
p1 := [48]byte{1}
|
||||
p0 := [fieldparams.BLSPubkeyLength]byte{0}
|
||||
p1 := [fieldparams.BLSPubkeyLength]byte{1}
|
||||
// Can save.
|
||||
require.NoError(
|
||||
t,
|
||||
@@ -332,7 +333,7 @@ func TestLowestSignedTargetEpoch_SaveRetrieveReplace(t *testing.T) {
|
||||
func TestStore_SaveAttestationsForPubKey(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
numValidators := 1
|
||||
pubKeys := make([][48]byte, numValidators)
|
||||
pubKeys := make([][fieldparams.BLSPubkeyLength]byte, numValidators)
|
||||
validatorDB := setupDB(t, pubKeys)
|
||||
atts := make([]*ethpb.IndexedAttestation, 0)
|
||||
signingRoots := make([][32]byte, 0)
|
||||
@@ -374,14 +375,14 @@ func TestSaveAttestationForPubKey_BatchWrites_FullCapacity(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
numValidators := attestationBatchCapacity
|
||||
pubKeys := make([][48]byte, numValidators)
|
||||
pubKeys := make([][fieldparams.BLSPubkeyLength]byte, numValidators)
|
||||
validatorDB := setupDB(t, pubKeys)
|
||||
|
||||
// For each public key, we attempt to save an attestation with signing root.
|
||||
var wg sync.WaitGroup
|
||||
for i, pubKey := range pubKeys {
|
||||
wg.Add(1)
|
||||
go func(j types.Epoch, pk [48]byte, w *sync.WaitGroup) {
|
||||
go func(j types.Epoch, pk [fieldparams.BLSPubkeyLength]byte, w *sync.WaitGroup) {
|
||||
defer w.Done()
|
||||
var signingRoot [32]byte
|
||||
copy(signingRoot[:], fmt.Sprintf("%d", j))
|
||||
@@ -431,14 +432,14 @@ func TestSaveAttestationForPubKey_BatchWrites_LowCapacity_TimerReached(t *testin
|
||||
// test force flushing to the DB based on a timer instead
|
||||
// of the max capacity being reached.
|
||||
numValidators := attestationBatchCapacity / 2
|
||||
pubKeys := make([][48]byte, numValidators)
|
||||
pubKeys := make([][fieldparams.BLSPubkeyLength]byte, numValidators)
|
||||
validatorDB := setupDB(t, pubKeys)
|
||||
|
||||
// For each public key, we attempt to save an attestation with signing root.
|
||||
var wg sync.WaitGroup
|
||||
for i, pubKey := range pubKeys {
|
||||
wg.Add(1)
|
||||
go func(j types.Epoch, pk [48]byte, w *sync.WaitGroup) {
|
||||
go func(j types.Epoch, pk [fieldparams.BLSPubkeyLength]byte, w *sync.WaitGroup) {
|
||||
defer w.Done()
|
||||
var signingRoot [32]byte
|
||||
copy(signingRoot[:], fmt.Sprintf("%d", j))
|
||||
@@ -482,20 +483,20 @@ func TestSaveAttestationForPubKey_BatchWrites_LowCapacity_TimerReached(t *testin
|
||||
func BenchmarkStore_CheckSlashableAttestation_Surround_SafeAttestation_54kEpochs(b *testing.B) {
|
||||
numValidators := 1
|
||||
numEpochs := types.Epoch(54000)
|
||||
pubKeys := make([][48]byte, numValidators)
|
||||
pubKeys := make([][fieldparams.BLSPubkeyLength]byte, numValidators)
|
||||
benchCheckSurroundVote(b, pubKeys, numEpochs, false /* surround */)
|
||||
}
|
||||
|
||||
func BenchmarkStore_CheckSurroundVote_Surround_Slashable_54kEpochs(b *testing.B) {
|
||||
numValidators := 1
|
||||
numEpochs := types.Epoch(54000)
|
||||
pubKeys := make([][48]byte, numValidators)
|
||||
pubKeys := make([][fieldparams.BLSPubkeyLength]byte, numValidators)
|
||||
benchCheckSurroundVote(b, pubKeys, numEpochs, true /* surround */)
|
||||
}
|
||||
|
||||
func benchCheckSurroundVote(
|
||||
b *testing.B,
|
||||
pubKeys [][48]byte,
|
||||
pubKeys [][fieldparams.BLSPubkeyLength]byte,
|
||||
numEpochs types.Epoch,
|
||||
shouldSurround bool,
|
||||
) {
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams"
|
||||
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/testing/require"
|
||||
)
|
||||
@@ -41,7 +42,7 @@ func TestStore_Backup(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestStore_NestedBackup(t *testing.T) {
|
||||
keys := [][48]byte{{'A'}, {'B'}}
|
||||
keys := [][fieldparams.BLSPubkeyLength]byte{{'A'}, {'B'}}
|
||||
db := setupDB(t, keys)
|
||||
ctx := context.Background()
|
||||
root := [32]byte{1}
|
||||
|
||||
@@ -13,6 +13,7 @@ import (
|
||||
"github.com/prysmaticlabs/prysm/async/abool"
|
||||
"github.com/prysmaticlabs/prysm/async/event"
|
||||
"github.com/prysmaticlabs/prysm/config/features"
|
||||
fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams"
|
||||
"github.com/prysmaticlabs/prysm/config/params"
|
||||
"github.com/prysmaticlabs/prysm/io/file"
|
||||
bolt "go.etcd.io/bbolt"
|
||||
@@ -52,7 +53,7 @@ var blockedBuckets = [][]byte{
|
||||
|
||||
// Config represents store's config object.
|
||||
type Config struct {
|
||||
PubKeys [][48]byte
|
||||
PubKeys [][fieldparams.BLSPubkeyLength]byte
|
||||
InitialMMapSize int
|
||||
}
|
||||
|
||||
@@ -177,7 +178,7 @@ func NewKVStore(ctx context.Context, dirPath string, config *Config) (*Store, er
|
||||
}
|
||||
|
||||
// UpdatePublicKeysBuckets for a specified list of keys.
|
||||
func (s *Store) UpdatePublicKeysBuckets(pubKeys [][48]byte) error {
|
||||
func (s *Store) UpdatePublicKeysBuckets(pubKeys [][fieldparams.BLSPubkeyLength]byte) error {
|
||||
return s.update(func(tx *bolt.Tx) error {
|
||||
bucket := tx.Bucket(historicProposalsBucket)
|
||||
for _, pubKey := range pubKeys {
|
||||
|
||||
@@ -3,22 +3,23 @@ package kv
|
||||
import (
|
||||
"context"
|
||||
|
||||
fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams"
|
||||
bolt "go.etcd.io/bbolt"
|
||||
"go.opencensus.io/trace"
|
||||
)
|
||||
|
||||
// EIPImportBlacklistedPublicKeys returns keys that were marked as blacklisted during EIP-3076 slashing
|
||||
// protection imports, ensuring that we can prevent these keys from having duties at runtime.
|
||||
func (s *Store) EIPImportBlacklistedPublicKeys(ctx context.Context) ([][48]byte, error) {
|
||||
func (s *Store) EIPImportBlacklistedPublicKeys(ctx context.Context) ([][fieldparams.BLSPubkeyLength]byte, error) {
|
||||
_, span := trace.StartSpan(ctx, "Validator.EIPImportBlacklistedPublicKeys")
|
||||
defer span.End()
|
||||
var err error
|
||||
publicKeys := make([][48]byte, 0)
|
||||
publicKeys := make([][fieldparams.BLSPubkeyLength]byte, 0)
|
||||
err = s.db.View(func(tx *bolt.Tx) error {
|
||||
bucket := tx.Bucket(slashablePublicKeysBucket)
|
||||
return bucket.ForEach(func(key []byte, _ []byte) error {
|
||||
if key != nil {
|
||||
pubKeyBytes := [48]byte{}
|
||||
pubKeyBytes := [fieldparams.BLSPubkeyLength]byte{}
|
||||
copy(pubKeyBytes[:], key)
|
||||
publicKeys = append(publicKeys, pubKeyBytes)
|
||||
}
|
||||
@@ -30,7 +31,7 @@ func (s *Store) EIPImportBlacklistedPublicKeys(ctx context.Context) ([][48]byte,
|
||||
|
||||
// SaveEIPImportBlacklistedPublicKeys stores a list of blacklisted public keys that
|
||||
// were determined during EIP-3076 slashing protection imports.
|
||||
func (s *Store) SaveEIPImportBlacklistedPublicKeys(ctx context.Context, publicKeys [][48]byte) error {
|
||||
func (s *Store) SaveEIPImportBlacklistedPublicKeys(ctx context.Context, publicKeys [][fieldparams.BLSPubkeyLength]byte) error {
|
||||
_, span := trace.StartSpan(ctx, "Validator.SaveEIPImportBlacklistedPublicKeys")
|
||||
defer span.End()
|
||||
return s.db.Update(func(tx *bolt.Tx) error {
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams"
|
||||
"github.com/prysmaticlabs/prysm/testing/assert"
|
||||
"github.com/prysmaticlabs/prysm/testing/require"
|
||||
)
|
||||
@@ -12,9 +13,9 @@ import (
|
||||
func TestStore_EIPBlacklistedPublicKeys(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
numValidators := 100
|
||||
publicKeys := make([][48]byte, numValidators)
|
||||
publicKeys := make([][fieldparams.BLSPubkeyLength]byte, numValidators)
|
||||
for i := 0; i < numValidators; i++ {
|
||||
key := [48]byte{}
|
||||
key := [fieldparams.BLSPubkeyLength]byte{}
|
||||
copy(key[:], fmt.Sprintf("%d", i))
|
||||
publicKeys[i] = key
|
||||
}
|
||||
@@ -32,7 +33,7 @@ func TestStore_EIPBlacklistedPublicKeys(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// Keys are not guaranteed to be ordered, so we create a map for comparisons.
|
||||
want := make(map[[48]byte]bool)
|
||||
want := make(map[[fieldparams.BLSPubkeyLength]byte]bool)
|
||||
for _, pubKey := range publicKeys[:50] {
|
||||
want[pubKey] = true
|
||||
}
|
||||
|
||||
@@ -4,13 +4,14 @@ import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams"
|
||||
"github.com/prysmaticlabs/prysm/config/params"
|
||||
"github.com/prysmaticlabs/prysm/testing/require"
|
||||
)
|
||||
|
||||
func TestStore_GenesisValidatorsRoot_ReadAndWrite(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db := setupDB(t, [][48]byte{})
|
||||
db := setupDB(t, [][fieldparams.BLSPubkeyLength]byte{})
|
||||
tests := []struct {
|
||||
name string
|
||||
want []byte
|
||||
|
||||
@@ -4,13 +4,14 @@ import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams"
|
||||
"github.com/prysmaticlabs/prysm/crypto/hash"
|
||||
"github.com/prysmaticlabs/prysm/testing/require"
|
||||
)
|
||||
|
||||
func TestStore_GraffitiOrderedIndex_ReadAndWrite(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
db := setupDB(t, [][48]byte{})
|
||||
db := setupDB(t, [][fieldparams.BLSPubkeyLength]byte{})
|
||||
tests := []struct {
|
||||
name string
|
||||
want uint64
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"io/ioutil"
|
||||
"testing"
|
||||
|
||||
fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams"
|
||||
"github.com/prysmaticlabs/prysm/testing/require"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
@@ -17,7 +18,7 @@ func TestMain(m *testing.M) {
|
||||
}
|
||||
|
||||
// setupDB instantiates and returns a DB instance for the validator client.
|
||||
func setupDB(t testing.TB, pubkeys [][48]byte) *Store {
|
||||
func setupDB(t testing.TB, pubkeys [][fieldparams.BLSPubkeyLength]byte) *Store {
|
||||
db, err := NewKVStore(context.Background(), t.TempDir(), &Config{
|
||||
PubKeys: pubkeys,
|
||||
})
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"context"
|
||||
|
||||
types "github.com/prysmaticlabs/eth2-types"
|
||||
fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams"
|
||||
"github.com/prysmaticlabs/prysm/config/params"
|
||||
"github.com/prysmaticlabs/prysm/encoding/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/monitoring/progress"
|
||||
@@ -114,7 +115,7 @@ func (s *Store) migrateOptimalAttesterProtectionUp(ctx context.Context) error {
|
||||
// Migrate attester protection from the more optimal format to the old format in the DB.
|
||||
func (s *Store) migrateOptimalAttesterProtectionDown(ctx context.Context) error {
|
||||
// First we extract the public keys we are migrating down for.
|
||||
pubKeys := make([][48]byte, 0)
|
||||
pubKeys := make([][fieldparams.BLSPubkeyLength]byte, 0)
|
||||
err := s.view(func(tx *bolt.Tx) error {
|
||||
mb := tx.Bucket(migrationsBucket)
|
||||
if b := mb.Get(migrationOptimalAttesterProtectionKey); b == nil {
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"testing"
|
||||
|
||||
types "github.com/prysmaticlabs/eth2-types"
|
||||
fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams"
|
||||
"github.com/prysmaticlabs/prysm/encoding/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/testing/require"
|
||||
bolt "go.etcd.io/bbolt"
|
||||
@@ -38,7 +39,7 @@ func Test_migrateOptimalAttesterProtectionUp(t *testing.T) {
|
||||
name: "populates optimized schema buckets",
|
||||
setup: func(t *testing.T, validatorDB *Store) {
|
||||
ctx := context.Background()
|
||||
pubKey := [48]byte{1}
|
||||
pubKey := [fieldparams.BLSPubkeyLength]byte{1}
|
||||
history := newDeprecatedAttestingHistory(0)
|
||||
// Attest all epochs from genesis to 50.
|
||||
numEpochs := types.Epoch(50)
|
||||
@@ -65,7 +66,7 @@ func Test_migrateOptimalAttesterProtectionUp(t *testing.T) {
|
||||
// Verify we indeed have the data for all epochs
|
||||
// since genesis to epoch 50 under the new schema.
|
||||
err := validatorDB.view(func(tx *bolt.Tx) error {
|
||||
pubKey := [48]byte{1}
|
||||
pubKey := [fieldparams.BLSPubkeyLength]byte{1}
|
||||
bucket := tx.Bucket(pubKeysBucket)
|
||||
pkBucket := bucket.Bucket(pubKey[:])
|
||||
signingRootsBucket := pkBucket.Bucket(attestationSigningRootsBucket)
|
||||
@@ -97,7 +98,7 @@ func Test_migrateOptimalAttesterProtectionUp(t *testing.T) {
|
||||
name: "partial data saved for both types still completes the migration successfully",
|
||||
setup: func(t *testing.T, validatorDB *Store) {
|
||||
ctx := context.Background()
|
||||
pubKey := [48]byte{1}
|
||||
pubKey := [fieldparams.BLSPubkeyLength]byte{1}
|
||||
history := newDeprecatedAttestingHistory(0)
|
||||
// Attest all epochs from genesis to 50.
|
||||
numEpochs := types.Epoch(50)
|
||||
@@ -151,7 +152,7 @@ func Test_migrateOptimalAttesterProtectionUp(t *testing.T) {
|
||||
// Verify we indeed have the data for all epochs
|
||||
// since genesis to epoch 50+1 under the new schema.
|
||||
err := validatorDB.view(func(tx *bolt.Tx) error {
|
||||
pubKey := [48]byte{1}
|
||||
pubKey := [fieldparams.BLSPubkeyLength]byte{1}
|
||||
bucket := tx.Bucket(pubKeysBucket)
|
||||
pkBucket := bucket.Bucket(pubKey[:])
|
||||
signingRootsBucket := pkBucket.Bucket(attestationSigningRootsBucket)
|
||||
@@ -229,7 +230,7 @@ func Test_migrateOptimalAttesterProtectionDown(t *testing.T) {
|
||||
{
|
||||
name: "populates old format from data using the new schema",
|
||||
setup: func(t *testing.T, validatorDB *Store) {
|
||||
pubKeys := [][48]byte{{1}, {2}}
|
||||
pubKeys := [][fieldparams.BLSPubkeyLength]byte{{1}, {2}}
|
||||
// Create attesting history for two public keys
|
||||
err := validatorDB.update(func(tx *bolt.Tx) error {
|
||||
bkt := tx.Bucket(pubKeysBucket)
|
||||
@@ -270,7 +271,7 @@ func Test_migrateOptimalAttesterProtectionDown(t *testing.T) {
|
||||
},
|
||||
eval: func(t *testing.T, validatorDB *Store) {
|
||||
ctx := context.Background()
|
||||
pubKeys := [][48]byte{{1}, {2}}
|
||||
pubKeys := [][fieldparams.BLSPubkeyLength]byte{{1}, {2}}
|
||||
// Next up, we validate that we have indeed rolled back our data
|
||||
// into the old format for attesting history.
|
||||
err := validatorDB.view(func(tx *bolt.Tx) error {
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams"
|
||||
"github.com/prysmaticlabs/prysm/encoding/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/testing/require"
|
||||
bolt "go.etcd.io/bbolt"
|
||||
@@ -17,9 +18,9 @@ func TestStore_migrateSourceTargetEpochsBucketUp(t *testing.T) {
|
||||
// numKeys should be more than batch size for testing.
|
||||
// See: https://github.com/prysmaticlabs/prysm/issues/8509
|
||||
numKeys := 2*publicKeyMigrationBatchSize + 1
|
||||
pubKeys := make([][48]byte, numKeys)
|
||||
pubKeys := make([][fieldparams.BLSPubkeyLength]byte, numKeys)
|
||||
for i := 0; i < numKeys; i++ {
|
||||
var pk [48]byte
|
||||
var pk [fieldparams.BLSPubkeyLength]byte
|
||||
copy(pk[:], fmt.Sprintf("%d", i))
|
||||
pubKeys[i] = pk
|
||||
}
|
||||
@@ -118,9 +119,9 @@ func TestStore_migrateSourceTargetEpochsBucketDown(t *testing.T) {
|
||||
// numKeys should be more than batch size for testing.
|
||||
// See: https://github.com/prysmaticlabs/prysm/issues/8509
|
||||
numKeys := 2*publicKeyMigrationBatchSize + 1
|
||||
pubKeys := make([][48]byte, numKeys)
|
||||
pubKeys := make([][fieldparams.BLSPubkeyLength]byte, numKeys)
|
||||
for i := 0; i < numKeys; i++ {
|
||||
var pk [48]byte
|
||||
var pk [fieldparams.BLSPubkeyLength]byte
|
||||
copy(pk[:], fmt.Sprintf("%d", i))
|
||||
pubKeys[i] = pk
|
||||
}
|
||||
|
||||
@@ -26,15 +26,15 @@ type Proposal struct {
|
||||
}
|
||||
|
||||
// ProposedPublicKeys retrieves all public keys in our proposals history bucket.
|
||||
func (s *Store) ProposedPublicKeys(ctx context.Context) ([][48]byte, error) {
|
||||
func (s *Store) ProposedPublicKeys(ctx context.Context) ([][fieldparams.BLSPubkeyLength]byte, error) {
|
||||
_, span := trace.StartSpan(ctx, "Validator.ProposedPublicKeys")
|
||||
defer span.End()
|
||||
var err error
|
||||
proposedPublicKeys := make([][48]byte, 0)
|
||||
proposedPublicKeys := make([][fieldparams.BLSPubkeyLength]byte, 0)
|
||||
err = s.view(func(tx *bolt.Tx) error {
|
||||
bucket := tx.Bucket(historicProposalsBucket)
|
||||
return bucket.ForEach(func(key []byte, _ []byte) error {
|
||||
pubKeyBytes := [48]byte{}
|
||||
pubKeyBytes := [fieldparams.BLSPubkeyLength]byte{}
|
||||
copy(pubKeyBytes[:], key)
|
||||
proposedPublicKeys = append(proposedPublicKeys, pubKeyBytes)
|
||||
return nil
|
||||
@@ -46,7 +46,7 @@ func (s *Store) ProposedPublicKeys(ctx context.Context) ([][48]byte, error) {
|
||||
// ProposalHistoryForSlot accepts a validator public key and returns the corresponding signing root as well
|
||||
// as a boolean that tells us if we have a proposal history stored at the slot. It is possible we have proposed
|
||||
// a slot but stored a nil signing root, so the boolean helps give full information.
|
||||
func (s *Store) ProposalHistoryForSlot(ctx context.Context, publicKey [48]byte, slot types.Slot) ([32]byte, bool, error) {
|
||||
func (s *Store) ProposalHistoryForSlot(ctx context.Context, publicKey [fieldparams.BLSPubkeyLength]byte, slot types.Slot) ([32]byte, bool, error) {
|
||||
_, span := trace.StartSpan(ctx, "Validator.ProposalHistoryForSlot")
|
||||
defer span.End()
|
||||
|
||||
@@ -71,7 +71,7 @@ func (s *Store) ProposalHistoryForSlot(ctx context.Context, publicKey [48]byte,
|
||||
}
|
||||
|
||||
// ProposalHistoryForPubKey returns the entire proposal history for a given public key.
|
||||
func (s *Store) ProposalHistoryForPubKey(ctx context.Context, publicKey [48]byte) ([]*Proposal, error) {
|
||||
func (s *Store) ProposalHistoryForPubKey(ctx context.Context, publicKey [fieldparams.BLSPubkeyLength]byte) ([]*Proposal, error) {
|
||||
ctx, span := trace.StartSpan(ctx, "Validator.ProposalHistoryForPubKey")
|
||||
defer span.End()
|
||||
|
||||
@@ -99,7 +99,7 @@ func (s *Store) ProposalHistoryForPubKey(ctx context.Context, publicKey [48]byte
|
||||
// SaveProposalHistoryForSlot saves the proposal history for the requested validator public key.
|
||||
// We also check if the incoming proposal slot is lower than the lowest signed proposal slot
|
||||
// for the validator and override its value on disk.
|
||||
func (s *Store) SaveProposalHistoryForSlot(ctx context.Context, pubKey [48]byte, slot types.Slot, signingRoot []byte) error {
|
||||
func (s *Store) SaveProposalHistoryForSlot(ctx context.Context, pubKey [fieldparams.BLSPubkeyLength]byte, slot types.Slot, signingRoot []byte) error {
|
||||
_, span := trace.StartSpan(ctx, "Validator.SaveProposalHistoryForEpoch")
|
||||
defer span.End()
|
||||
|
||||
@@ -146,7 +146,7 @@ func (s *Store) SaveProposalHistoryForSlot(ctx context.Context, pubKey [48]byte,
|
||||
|
||||
// LowestSignedProposal returns the lowest signed proposal slot for a validator public key.
|
||||
// If no data exists, a boolean of value false is returned.
|
||||
func (s *Store) LowestSignedProposal(ctx context.Context, publicKey [48]byte) (types.Slot, bool, error) {
|
||||
func (s *Store) LowestSignedProposal(ctx context.Context, publicKey [fieldparams.BLSPubkeyLength]byte) (types.Slot, bool, error) {
|
||||
_, span := trace.StartSpan(ctx, "Validator.LowestSignedProposal")
|
||||
defer span.End()
|
||||
|
||||
@@ -169,7 +169,7 @@ func (s *Store) LowestSignedProposal(ctx context.Context, publicKey [48]byte) (t
|
||||
|
||||
// HighestSignedProposal returns the highest signed proposal slot for a validator public key.
|
||||
// If no data exists, a boolean of value false is returned.
|
||||
func (s *Store) HighestSignedProposal(ctx context.Context, publicKey [48]byte) (types.Slot, bool, error) {
|
||||
func (s *Store) HighestSignedProposal(ctx context.Context, publicKey [fieldparams.BLSPubkeyLength]byte) (types.Slot, bool, error) {
|
||||
_, span := trace.StartSpan(ctx, "Validator.HighestSignedProposal")
|
||||
defer span.End()
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"testing"
|
||||
|
||||
types "github.com/prysmaticlabs/eth2-types"
|
||||
fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams"
|
||||
"github.com/prysmaticlabs/prysm/config/params"
|
||||
"github.com/prysmaticlabs/prysm/encoding/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/testing/assert"
|
||||
@@ -12,7 +13,7 @@ import (
|
||||
)
|
||||
|
||||
func TestProposalHistoryForSlot_InitializesNewPubKeys(t *testing.T) {
|
||||
pubkeys := [][48]byte{{30}, {25}, {20}}
|
||||
pubkeys := [][fieldparams.BLSPubkeyLength]byte{{30}, {25}, {20}}
|
||||
db := setupDB(t, pubkeys)
|
||||
|
||||
for _, pub := range pubkeys {
|
||||
@@ -24,8 +25,8 @@ func TestProposalHistoryForSlot_InitializesNewPubKeys(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNewProposalHistoryForSlot_ReturnsNilIfNoHistory(t *testing.T) {
|
||||
valPubkey := [48]byte{1, 2, 3}
|
||||
db := setupDB(t, [][48]byte{})
|
||||
valPubkey := [fieldparams.BLSPubkeyLength]byte{1, 2, 3}
|
||||
db := setupDB(t, [][fieldparams.BLSPubkeyLength]byte{})
|
||||
|
||||
_, proposalExists, err := db.ProposalHistoryForSlot(context.Background(), valPubkey, 0)
|
||||
require.NoError(t, err)
|
||||
@@ -33,8 +34,8 @@ func TestNewProposalHistoryForSlot_ReturnsNilIfNoHistory(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSaveProposalHistoryForSlot_OK(t *testing.T) {
|
||||
pubkey := [48]byte{3}
|
||||
db := setupDB(t, [][48]byte{pubkey})
|
||||
pubkey := [fieldparams.BLSPubkeyLength]byte{3}
|
||||
db := setupDB(t, [][fieldparams.BLSPubkeyLength]byte{pubkey})
|
||||
|
||||
slot := types.Slot(2)
|
||||
|
||||
@@ -48,8 +49,8 @@ func TestSaveProposalHistoryForSlot_OK(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestNewProposalHistoryForPubKey_ReturnsEmptyIfNoHistory(t *testing.T) {
|
||||
valPubkey := [48]byte{1, 2, 3}
|
||||
db := setupDB(t, [][48]byte{})
|
||||
valPubkey := [fieldparams.BLSPubkeyLength]byte{1, 2, 3}
|
||||
db := setupDB(t, [][fieldparams.BLSPubkeyLength]byte{})
|
||||
|
||||
proposalHistory, err := db.ProposalHistoryForPubKey(context.Background(), valPubkey)
|
||||
require.NoError(t, err)
|
||||
@@ -57,8 +58,8 @@ func TestNewProposalHistoryForPubKey_ReturnsEmptyIfNoHistory(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSaveProposalHistoryForPubKey_OK(t *testing.T) {
|
||||
pubkey := [48]byte{3}
|
||||
db := setupDB(t, [][48]byte{pubkey})
|
||||
pubkey := [fieldparams.BLSPubkeyLength]byte{3}
|
||||
db := setupDB(t, [][fieldparams.BLSPubkeyLength]byte{pubkey})
|
||||
|
||||
slot := types.Slot(2)
|
||||
|
||||
@@ -79,7 +80,7 @@ func TestSaveProposalHistoryForPubKey_OK(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSaveProposalHistoryForSlot_Overwrites(t *testing.T) {
|
||||
pubkey := [48]byte{0}
|
||||
pubkey := [fieldparams.BLSPubkeyLength]byte{0}
|
||||
tests := []struct {
|
||||
signingRoot []byte
|
||||
}{
|
||||
@@ -95,7 +96,7 @@ func TestSaveProposalHistoryForSlot_Overwrites(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
db := setupDB(t, [][48]byte{pubkey})
|
||||
db := setupDB(t, [][fieldparams.BLSPubkeyLength]byte{pubkey})
|
||||
err := db.SaveProposalHistoryForSlot(context.Background(), pubkey, 0, tt.signingRoot)
|
||||
require.NoError(t, err, "Saving proposal history failed")
|
||||
proposalHistory, err := db.ProposalHistoryForPubKey(context.Background(), pubkey)
|
||||
@@ -110,7 +111,7 @@ func TestSaveProposalHistoryForSlot_Overwrites(t *testing.T) {
|
||||
func TestPruneProposalHistoryBySlot_OK(t *testing.T) {
|
||||
slotsPerEpoch := params.BeaconConfig().SlotsPerEpoch
|
||||
wsPeriod := params.BeaconConfig().WeakSubjectivityPeriod
|
||||
pubKey := [48]byte{0}
|
||||
pubKey := [fieldparams.BLSPubkeyLength]byte{0}
|
||||
tests := []struct {
|
||||
slots []types.Slot
|
||||
storedSlots []types.Slot
|
||||
@@ -150,7 +151,7 @@ func TestPruneProposalHistoryBySlot_OK(t *testing.T) {
|
||||
signedRoot := bytesutil.PadTo([]byte{1}, 32)
|
||||
|
||||
for _, tt := range tests {
|
||||
db := setupDB(t, [][48]byte{pubKey})
|
||||
db := setupDB(t, [][fieldparams.BLSPubkeyLength]byte{pubKey})
|
||||
for _, slot := range tt.slots {
|
||||
err := db.SaveProposalHistoryForSlot(context.Background(), pubKey, slot, signedRoot)
|
||||
require.NoError(t, err, "Saving proposal history failed")
|
||||
@@ -188,23 +189,23 @@ func TestStore_ProposedPublicKeys(t *testing.T) {
|
||||
|
||||
keys, err := validatorDB.ProposedPublicKeys(ctx)
|
||||
require.NoError(t, err)
|
||||
assert.DeepEqual(t, make([][48]byte, 0), keys)
|
||||
assert.DeepEqual(t, make([][fieldparams.BLSPubkeyLength]byte, 0), keys)
|
||||
|
||||
pubKey := [48]byte{1}
|
||||
pubKey := [fieldparams.BLSPubkeyLength]byte{1}
|
||||
dummyRoot := [32]byte{}
|
||||
err = validatorDB.SaveProposalHistoryForSlot(ctx, pubKey, 1, dummyRoot[:])
|
||||
require.NoError(t, err)
|
||||
|
||||
keys, err = validatorDB.ProposedPublicKeys(ctx)
|
||||
require.NoError(t, err)
|
||||
assert.DeepEqual(t, [][48]byte{pubKey}, keys)
|
||||
assert.DeepEqual(t, [][fieldparams.BLSPubkeyLength]byte{pubKey}, keys)
|
||||
}
|
||||
|
||||
func TestStore_LowestSignedProposal(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
pubkey := [48]byte{3}
|
||||
pubkey := [fieldparams.BLSPubkeyLength]byte{3}
|
||||
dummySigningRoot := [32]byte{}
|
||||
validatorDB := setupDB(t, [][48]byte{pubkey})
|
||||
validatorDB := setupDB(t, [][fieldparams.BLSPubkeyLength]byte{pubkey})
|
||||
|
||||
_, exists, err := validatorDB.LowestSignedProposal(ctx, pubkey)
|
||||
require.NoError(t, err)
|
||||
@@ -243,9 +244,9 @@ func TestStore_LowestSignedProposal(t *testing.T) {
|
||||
|
||||
func TestStore_HighestSignedProposal(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
pubkey := [48]byte{3}
|
||||
pubkey := [fieldparams.BLSPubkeyLength]byte{3}
|
||||
dummySigningRoot := [32]byte{}
|
||||
validatorDB := setupDB(t, [][48]byte{pubkey})
|
||||
validatorDB := setupDB(t, [][fieldparams.BLSPubkeyLength]byte{pubkey})
|
||||
|
||||
_, exists, err := validatorDB.HighestSignedProposal(ctx, pubkey)
|
||||
require.NoError(t, err)
|
||||
|
||||
@@ -6,6 +6,7 @@ import (
|
||||
"testing"
|
||||
|
||||
types "github.com/prysmaticlabs/eth2-types"
|
||||
fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams"
|
||||
"github.com/prysmaticlabs/prysm/config/params"
|
||||
"github.com/prysmaticlabs/prysm/encoding/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/testing/require"
|
||||
@@ -13,8 +14,8 @@ import (
|
||||
)
|
||||
|
||||
func TestPruneAttestations_NoPruning(t *testing.T) {
|
||||
pubKey := [48]byte{1}
|
||||
validatorDB := setupDB(t, [][48]byte{pubKey})
|
||||
pubKey := [fieldparams.BLSPubkeyLength]byte{1}
|
||||
validatorDB := setupDB(t, [][fieldparams.BLSPubkeyLength]byte{pubKey})
|
||||
|
||||
// Write attesting history for every single epoch
|
||||
// since genesis to a specified number of epochs.
|
||||
@@ -40,7 +41,7 @@ func TestPruneAttestations_NoPruning(t *testing.T) {
|
||||
|
||||
func TestPruneAttestations_OK(t *testing.T) {
|
||||
numKeys := uint64(64)
|
||||
pks := make([][48]byte, 0, numKeys)
|
||||
pks := make([][fieldparams.BLSPubkeyLength]byte, 0, numKeys)
|
||||
for i := uint64(0); i < numKeys; i++ {
|
||||
pks = append(pks, bytesutil.ToBytes48(bytesutil.ToBytes(i, 48)))
|
||||
}
|
||||
@@ -89,7 +90,7 @@ func TestPruneAttestations_OK(t *testing.T) {
|
||||
|
||||
func BenchmarkPruneAttestations(b *testing.B) {
|
||||
numKeys := uint64(8)
|
||||
pks := make([][48]byte, 0, numKeys)
|
||||
pks := make([][fieldparams.BLSPubkeyLength]byte, 0, numKeys)
|
||||
for i := uint64(0); i < numKeys; i++ {
|
||||
pks = append(pks, bytesutil.ToBytes48(bytesutil.ToBytes(i, 48)))
|
||||
}
|
||||
@@ -113,7 +114,7 @@ func BenchmarkPruneAttestations(b *testing.B) {
|
||||
|
||||
// Saves attesting history for every (source, target = source + 1) pairs since genesis
|
||||
// up to a given number of epochs for a validator public key.
|
||||
func setupAttestationsForEveryEpoch(t testing.TB, validatorDB *Store, pubKey [48]byte, numEpochs types.Epoch) error {
|
||||
func setupAttestationsForEveryEpoch(t testing.TB, validatorDB *Store, pubKey [fieldparams.BLSPubkeyLength]byte, numEpochs types.Epoch) error {
|
||||
return validatorDB.update(func(tx *bolt.Tx) error {
|
||||
bucket := tx.Bucket(pubKeysBucket)
|
||||
pkBucket, err := bucket.CreateBucketIfNotExists(pubKey[:])
|
||||
@@ -152,7 +153,7 @@ func setupAttestationsForEveryEpoch(t testing.TB, validatorDB *Store, pubKey [48
|
||||
func checkAttestingHistoryAfterPruning(
|
||||
t testing.TB,
|
||||
validatorDB *Store,
|
||||
pubKey [48]byte,
|
||||
pubKey [fieldparams.BLSPubkeyLength]byte,
|
||||
startEpoch,
|
||||
numEpochs types.Epoch,
|
||||
shouldBePruned bool,
|
||||
|
||||
@@ -9,6 +9,7 @@ go_library(
|
||||
"//validator:__subpackages__",
|
||||
],
|
||||
deps = [
|
||||
"//config/fieldparams:go_default_library",
|
||||
"//validator/db/iface:go_default_library",
|
||||
"//validator/db/kv:go_default_library",
|
||||
],
|
||||
|
||||
@@ -4,12 +4,13 @@ import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams"
|
||||
"github.com/prysmaticlabs/prysm/validator/db/iface"
|
||||
"github.com/prysmaticlabs/prysm/validator/db/kv"
|
||||
)
|
||||
|
||||
// SetupDB instantiates and returns a DB instance for the validator client.
|
||||
func SetupDB(t testing.TB, pubkeys [][48]byte) iface.ValidatorDB {
|
||||
func SetupDB(t testing.TB, pubkeys [][fieldparams.BLSPubkeyLength]byte) iface.ValidatorDB {
|
||||
db, err := kv.NewKVStore(context.Background(), t.TempDir(), &kv.Config{
|
||||
PubKeys: pubkeys,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user