Fix validator export failing when validator.db is in nested directory (#15351)

* files changed

* added changelog file

* added tests and formatting changes

* fixed bugs

* fixed formatting
This commit is contained in:
Rose Jethani
2025-05-30 20:23:19 +05:30
committed by GitHub
parent 711984d942
commit 3300866572
12 changed files with 162 additions and 115 deletions

View File

@@ -0,0 +1,3 @@
### Fixed
- Fix `slashing-protection-history export` failing when `validator.db` is in a nested folder like `data/direct/`. (#14954)

View File

@@ -58,10 +58,11 @@ func exportSlashingProtectionJSON(cliCtx *cli.Context) error {
}
// Ensure that the database is found under the specified dir or its subdirectories
var matchPath string
if isDatabaseMinimal {
found, _, err = file.RecursiveDirFind(filesystem.DatabaseDirName, dataDir)
found, matchPath, err = file.RecursiveDirFind(filesystem.DatabaseDirName, dataDir)
} else {
found, _, err = file.RecursiveFileFind(kv.ProtectionDbFileName, dataDir)
found, matchPath, err = file.RecursiveFileFind(kv.ProtectionDbFileName, dataDir)
}
if err != nil {
@@ -74,6 +75,12 @@ func exportSlashingProtectionJSON(cliCtx *cli.Context) error {
databaseFileDir = filesystem.DatabaseDirName
}
return fmt.Errorf("%s (validator database) was not found at path %s, so nothing to export", databaseFileDir, dataDir)
} else {
if !isDatabaseMinimal {
matchPath = filepath.Dir(matchPath) // strip the file name
}
dataDir = matchPath
log.Infof("Found validator database at path %s", dataDir)
}
// Open the validator database.

View File

@@ -3,6 +3,7 @@ package historycmd
import (
"bytes"
"fmt"
"path/filepath"
"github.com/OffchainLabs/prysm/v6/cmd"
"github.com/OffchainLabs/prysm/v6/cmd/validator/flags"
@@ -45,16 +46,29 @@ func importSlashingProtectionJSON(cliCtx *cli.Context) error {
}
// Ensure that the database is found under the specified directory or its subdirectories
var matchPath string
if isDatabaseMinimal {
found, _, err = file.RecursiveDirFind(filesystem.DatabaseDirName, dataDir)
found, matchPath, err = file.RecursiveDirFind(filesystem.DatabaseDirName, dataDir)
} else {
found, _, err = file.RecursiveFileFind(kv.ProtectionDbFileName, dataDir)
found, matchPath, err = file.RecursiveFileFind(kv.ProtectionDbFileName, dataDir)
}
if err != nil {
return errors.Wrapf(err, "error finding validator database at path %s", dataDir)
}
if !found {
databaseFileDir := kv.ProtectionDbFileName
if isDatabaseMinimal {
databaseFileDir = filesystem.DatabaseDirName
}
return fmt.Errorf("%s (validator database) was not found at path %s, so nothing to export", databaseFileDir, dataDir)
} else {
if !isDatabaseMinimal {
matchPath = filepath.Dir(matchPath) // strip the file name
}
dataDir = matchPath
log.Infof("Found validator database at path %s", dataDir)
}
message := "Found existing database inside of %s"
if !found {
message = "Did not find existing database inside of %s, creating a new one"

View File

@@ -3,9 +3,6 @@ package historycmd
import (
"encoding/json"
"flag"
"path/filepath"
"testing"
"github.com/OffchainLabs/prysm/v6/cmd"
"github.com/OffchainLabs/prysm/v6/cmd/validator/flags"
"github.com/OffchainLabs/prysm/v6/io/file"
@@ -16,6 +13,8 @@ import (
"github.com/OffchainLabs/prysm/v6/validator/slashing-protection-history/format"
mocks "github.com/OffchainLabs/prysm/v6/validator/testing"
"github.com/urfave/cli/v2"
"path/filepath"
"testing"
)
func setupCliCtx(
@@ -41,6 +40,28 @@ func setupCliCtx(
// slashing protection history database will keep only the latest signed block slot / attestations,
// and thus will not be able to export the same data as the original file.
func TestImportExportSlashingProtectionCli_RoundTrip(t *testing.T) {
layouts := []struct {
name string
mutate func(t *testing.T) (string, string)
}{
{
name: "flat",
mutate: func(t *testing.T) (string, string) {
dbPath := t.TempDir()
return dbPath, dbPath
},
},
{
name: "nested",
mutate: func(t *testing.T) (string, string) {
dbPath := t.TempDir()
nestedDir := filepath.Join(dbPath, "data", "direct")
return dbPath, nestedDir
},
},
}
for _, tc := range layouts {
t.Run(tc.name, func(t *testing.T) {
numValidators := 10
outputPath := filepath.Join(t.TempDir(), "slashing-exports")
err := file.MkdirAll(outputPath)
@@ -65,10 +86,10 @@ func TestImportExportSlashingProtectionCli_RoundTrip(t *testing.T) {
// We create a CLI context with the required values, such as the database datadir and output directory.
isSlashingProtectionMinimal := false
validatorDB := dbTest.SetupDB(t, pubKeys, isSlashingProtectionMinimal)
dbPath := validatorDB.DatabasePath()
dataDir, dataPath := tc.mutate(t)
validatorDB := dbTest.SetupDB(t, dataPath, pubKeys, isSlashingProtectionMinimal)
require.NoError(t, validatorDB.Close())
cliCtx := setupCliCtx(t, dbPath, protectionFilePath, outputPath)
cliCtx := setupCliCtx(t, dataDir, protectionFilePath, outputPath)
// We import the slashing protection history file via CLI.
err = importSlashingProtectionJSON(cliCtx)
@@ -112,6 +133,8 @@ func TestImportExportSlashingProtectionCli_RoundTrip(t *testing.T) {
require.Equal(t, len(wanted.SignedBlocks), len(item.SignedBlocks))
require.DeepEqual(t, wanted.SignedBlocks, item.SignedBlocks)
}
})
}
}
// TestImportExportSlashingProtectionCli_EmptyData imports a EIP-3076 interchange format JSON file,
@@ -147,7 +170,7 @@ func TestImportExportSlashingProtectionCli_EmptyData(t *testing.T) {
// We create a CLI context with the required values, such as the database datadir and output directory.
isSlashingProtectionMinimal := false
validatorDB := dbTest.SetupDB(t, pubKeys, isSlashingProtectionMinimal)
validatorDB := dbTest.SetupDB(t, t.TempDir(), pubKeys, isSlashingProtectionMinimal)
dbPath := validatorDB.DatabasePath()
require.NoError(t, validatorDB.Close())
cliCtx := setupCliCtx(t, dbPath, protectionFilePath, outputPath)

View File

@@ -930,7 +930,7 @@ func TestProposerSettingsLoader(t *testing.T) {
set.Bool(flags.EnableBuilderFlag.Name, true, "")
}
cliCtx := cli.NewContext(&app, set, nil)
validatorDB := dbTest.SetupDB(t, [][fieldparams.BLSPubkeyLength]byte{}, isSlashingProtectionMinimal)
validatorDB := dbTest.SetupDB(t, t.TempDir(), [][fieldparams.BLSPubkeyLength]byte{}, isSlashingProtectionMinimal)
if tt.withdb != nil {
err := tt.withdb(validatorDB)
require.NoError(t, err)
@@ -978,7 +978,7 @@ func Test_ProposerSettingsLoaderWithOnlyBuilder_DoesNotSaveInDB(t *testing.T) {
set := flag.NewFlagSet("test", 0)
set.Bool(flags.EnableBuilderFlag.Name, true, "")
cliCtx := cli.NewContext(&app, set, nil)
validatorDB := dbTest.SetupDB(t, [][fieldparams.BLSPubkeyLength]byte{}, isSlashingProtectionMinimal)
validatorDB := dbTest.SetupDB(t, t.TempDir(), [][fieldparams.BLSPubkeyLength]byte{}, isSlashingProtectionMinimal)
loader, err := NewProposerSettingsLoader(
cliCtx,
validatorDB,

View File

@@ -81,7 +81,7 @@ func setup(t *testing.T, isSlashingProtectionMinimal bool) (*validator, *mocks,
func setupWithKey(t *testing.T, validatorKey bls.SecretKey, isSlashingProtectionMinimal bool) (*validator, *mocks, bls.SecretKey, func()) {
var pubKey [fieldparams.BLSPubkeyLength]byte
copy(pubKey[:], validatorKey.PublicKey().Marshal())
valDB := testing2.SetupDB(t, [][fieldparams.BLSPubkeyLength]byte{pubKey}, isSlashingProtectionMinimal)
valDB := testing2.SetupDB(t, t.TempDir(), [][fieldparams.BLSPubkeyLength]byte{pubKey}, isSlashingProtectionMinimal)
ctrl := gomock.NewController(t)
m := &mocks{
validatorClient: validatormock.NewMockValidatorClient(ctrl),
@@ -1105,7 +1105,7 @@ func TestGetGraffitiOrdered_Ok(t *testing.T) {
for _, isSlashingProtectionMinimal := range [...]bool{false, true} {
t.Run(fmt.Sprintf("SlashingProtectionMinimal:%v", isSlashingProtectionMinimal), func(t *testing.T) {
pubKey := [fieldparams.BLSPubkeyLength]byte{'a'}
valDB := testing2.SetupDB(t, [][fieldparams.BLSPubkeyLength]byte{pubKey}, isSlashingProtectionMinimal)
valDB := testing2.SetupDB(t, t.TempDir(), [][fieldparams.BLSPubkeyLength]byte{pubKey}, isSlashingProtectionMinimal)
ctrl := gomock.NewController(t)
m := &mocks{
validatorClient: validatormock.NewMockValidatorClient(ctrl),
@@ -1188,7 +1188,7 @@ func Test_validator_DeleteGraffiti(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
v := &validator{
db: testing2.SetupDB(t, [][fieldparams.BLSPubkeyLength]byte{pubKey}, false),
db: testing2.SetupDB(t, t.TempDir(), [][fieldparams.BLSPubkeyLength]byte{pubKey}, false),
proposerSettings: tt.proposerSettings,
}
err := v.DeleteGraffiti(context.Background(), pubKey)
@@ -1268,7 +1268,7 @@ func Test_validator_SetGraffiti(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
v := &validator{
db: testing2.SetupDB(t, [][fieldparams.BLSPubkeyLength]byte{pubKey}, false),
db: testing2.SetupDB(t, t.TempDir(), [][fieldparams.BLSPubkeyLength]byte{pubKey}, false),
proposerSettings: tt.proposerSettings,
}
err := v.SetGraffiti(context.Background(), pubKey, []byte(tt.graffiti))

View File

@@ -165,7 +165,7 @@ func TestWaitForChainStart_SetsGenesisInfo(t *testing.T) {
defer ctrl.Finish()
client := validatormock.NewMockValidatorClient(ctrl)
db := dbTest.SetupDB(t, [][fieldparams.BLSPubkeyLength]byte{}, isSlashingProtectionMinimal)
db := dbTest.SetupDB(t, t.TempDir(), [][fieldparams.BLSPubkeyLength]byte{}, isSlashingProtectionMinimal)
v := validator{
validatorClient: client,
db: db,
@@ -215,7 +215,7 @@ func TestWaitForChainStart_SetsGenesisInfo_IncorrectSecondTry(t *testing.T) {
defer ctrl.Finish()
client := validatormock.NewMockValidatorClient(ctrl)
db := dbTest.SetupDB(t, [][fieldparams.BLSPubkeyLength]byte{}, isSlashingProtectionMinimal)
db := dbTest.SetupDB(t, t.TempDir(), [][fieldparams.BLSPubkeyLength]byte{}, isSlashingProtectionMinimal)
v := validator{
validatorClient: client,
db: db,
@@ -925,7 +925,7 @@ func TestValidator_CheckDoppelGanger(t *testing.T) {
km := genMockKeymanager(t, 10)
keys, err := km.FetchValidatingPublicKeys(context.Background())
assert.NoError(t, err)
db := dbTest.SetupDB(t, keys, isSlashingProtectionMinimal)
db := dbTest.SetupDB(t, t.TempDir(), keys, isSlashingProtectionMinimal)
req := &ethpb.DoppelGangerRequest{ValidatorRequests: []*ethpb.DoppelGangerRequest_ValidatorRequest{}}
for _, k := range keys {
pkey := k
@@ -959,7 +959,7 @@ func TestValidator_CheckDoppelGanger(t *testing.T) {
km := genMockKeymanager(t, 10)
keys, err := km.FetchValidatingPublicKeys(context.Background())
assert.NoError(t, err)
db := dbTest.SetupDB(t, keys, isSlashingProtectionMinimal)
db := dbTest.SetupDB(t, t.TempDir(), keys, isSlashingProtectionMinimal)
req := &ethpb.DoppelGangerRequest{ValidatorRequests: []*ethpb.DoppelGangerRequest_ValidatorRequest{}}
resp := &ethpb.DoppelGangerResponse{Responses: []*ethpb.DoppelGangerResponse_ValidatorResponse{}}
for i, k := range keys {
@@ -1000,7 +1000,7 @@ func TestValidator_CheckDoppelGanger(t *testing.T) {
km := genMockKeymanager(t, 10)
keys, err := km.FetchValidatingPublicKeys(context.Background())
assert.NoError(t, err)
db := dbTest.SetupDB(t, keys, isSlashingProtectionMinimal)
db := dbTest.SetupDB(t, t.TempDir(), keys, isSlashingProtectionMinimal)
req := &ethpb.DoppelGangerRequest{ValidatorRequests: []*ethpb.DoppelGangerRequest_ValidatorRequest{}}
resp := &ethpb.DoppelGangerResponse{Responses: []*ethpb.DoppelGangerResponse_ValidatorResponse{}}
for i, k := range keys {
@@ -1039,7 +1039,7 @@ func TestValidator_CheckDoppelGanger(t *testing.T) {
km := genMockKeymanager(t, 10)
keys, err := km.FetchValidatingPublicKeys(context.Background())
assert.NoError(t, err)
db := dbTest.SetupDB(t, keys, isSlashingProtectionMinimal)
db := dbTest.SetupDB(t, t.TempDir(), keys, isSlashingProtectionMinimal)
req := &ethpb.DoppelGangerRequest{ValidatorRequests: []*ethpb.DoppelGangerRequest_ValidatorRequest{}}
resp := &ethpb.DoppelGangerResponse{Responses: []*ethpb.DoppelGangerResponse_ValidatorResponse{}}
attLimit := 5
@@ -1085,7 +1085,7 @@ func TestValidator_CheckDoppelGanger(t *testing.T) {
km := genMockKeymanager(t, 1)
keys, err := km.FetchValidatingPublicKeys(context.Background())
assert.NoError(t, err)
db := dbTest.SetupDB(t, keys, isSlashingProtectionMinimal)
db := dbTest.SetupDB(t, t.TempDir(), keys, isSlashingProtectionMinimal)
resp := &ethpb.DoppelGangerResponse{Responses: []*ethpb.DoppelGangerResponse_ValidatorResponse{}}
req := &ethpb.DoppelGangerRequest{ValidatorRequests: []*ethpb.DoppelGangerRequest_ValidatorRequest{}}
for _, k := range keys {
@@ -1123,7 +1123,7 @@ func TestValidatorAttestationsAreOrdered(t *testing.T) {
km := genMockKeymanager(t, 10)
keys, err := km.FetchValidatingPublicKeys(context.Background())
assert.NoError(t, err)
db := dbTest.SetupDB(t, keys, isSlashingProtectionMinimal)
db := dbTest.SetupDB(t, t.TempDir(), keys, isSlashingProtectionMinimal)
k := keys[0]
att := createAttestation(10, 14)
@@ -1303,7 +1303,7 @@ func TestValidator_WaitForKeymanagerInitialization_web3Signer(t *testing.T) {
for _, isSlashingProtectionMinimal := range [...]bool{false, true} {
t.Run(fmt.Sprintf("SlashingProtectionMinimal:%v", isSlashingProtectionMinimal), func(t *testing.T) {
ctx := context.Background()
db := dbTest.SetupDB(t, [][fieldparams.BLSPubkeyLength]byte{}, isSlashingProtectionMinimal)
db := dbTest.SetupDB(t, t.TempDir(), [][fieldparams.BLSPubkeyLength]byte{}, isSlashingProtectionMinimal)
root := make([]byte, 32)
copy(root[2:], "a")
err := db.SaveGenesisValidatorsRoot(ctx, root)
@@ -1336,7 +1336,7 @@ func TestValidator_WaitForKeymanagerInitialization_Web(t *testing.T) {
for _, isSlashingProtectionMinimal := range [...]bool{false, true} {
t.Run(fmt.Sprintf("SlashingProtectionMinimal:%v", isSlashingProtectionMinimal), func(t *testing.T) {
ctx := context.Background()
db := dbTest.SetupDB(t, [][fieldparams.BLSPubkeyLength]byte{}, isSlashingProtectionMinimal)
db := dbTest.SetupDB(t, t.TempDir(), [][fieldparams.BLSPubkeyLength]byte{}, isSlashingProtectionMinimal)
root := make([]byte, 32)
copy(root[2:], "a")
err := db.SaveGenesisValidatorsRoot(ctx, root)
@@ -1370,7 +1370,7 @@ func TestValidator_WaitForKeymanagerInitialization_Interop(t *testing.T) {
for _, isSlashingProtectionMinimal := range [...]bool{false, true} {
t.Run(fmt.Sprintf("SlashingProtectionMinimal:%v", isSlashingProtectionMinimal), func(t *testing.T) {
ctx := context.Background()
db := dbTest.SetupDB(t, [][fieldparams.BLSPubkeyLength]byte{}, isSlashingProtectionMinimal)
db := dbTest.SetupDB(t, t.TempDir(), [][fieldparams.BLSPubkeyLength]byte{}, isSlashingProtectionMinimal)
root := make([]byte, 32)
copy(root[2:], "a")
err := db.SaveGenesisValidatorsRoot(ctx, root)
@@ -1430,7 +1430,7 @@ func TestValidator_PushSettings(t *testing.T) {
for _, isSlashingProtectionMinimal := range [...]bool{false, true} {
ctrl := gomock.NewController(t)
ctx := context.Background()
db := dbTest.SetupDB(t, [][fieldparams.BLSPubkeyLength]byte{}, isSlashingProtectionMinimal)
db := dbTest.SetupDB(t, t.TempDir(), [][fieldparams.BLSPubkeyLength]byte{}, isSlashingProtectionMinimal)
client := validatormock.NewMockValidatorClient(ctrl)
nodeClient := validatormock.NewMockNodeClient(ctrl)
defaultFeeHex := "0x046Fb65722E7b2455043BFEBf6177F1D2e9738D9"

View File

@@ -26,7 +26,7 @@ func TestMigrateUp_NoDBFound(t *testing.T) {
// This, it is tested only for complete slashing protection database.
func TestMigrateUp_OK(t *testing.T) {
isSlashingProtectionMinimal := false
validatorDB := dbtest.SetupDB(t, nil, isSlashingProtectionMinimal)
validatorDB := dbtest.SetupDB(t, t.TempDir(), nil, isSlashingProtectionMinimal)
dbPath := validatorDB.DatabasePath()
require.NoError(t, validatorDB.Close())
app := cli.App{}
@@ -52,7 +52,7 @@ func TestMigrateDown_NoDBFound(t *testing.T) {
// This, it is tested only for complete slashing protection database.
func TestMigrateDown_OK(t *testing.T) {
isSlashingProtectionMinimal := false
validatorDB := dbtest.SetupDB(t, nil, isSlashingProtectionMinimal)
validatorDB := dbtest.SetupDB(t, t.TempDir(), nil, isSlashingProtectionMinimal)
dbPath := validatorDB.DatabasePath()
require.NoError(t, validatorDB.Close())
app := cli.App{}

View File

@@ -13,7 +13,7 @@ import (
// SetupDB instantiates and returns a DB instance for the validator client.
// The `minimal` flag indicates whether the DB should be instantiated with minimal, filesystem
// slashing protection database.
func SetupDB(t testing.TB, pubkeys [][fieldparams.BLSPubkeyLength]byte, minimal bool) iface.ValidatorDB {
func SetupDB(t testing.TB, dataPath string, pubkeys [][fieldparams.BLSPubkeyLength]byte, minimal bool) iface.ValidatorDB {
var (
db iface.ValidatorDB
err error
@@ -22,10 +22,10 @@ func SetupDB(t testing.TB, pubkeys [][fieldparams.BLSPubkeyLength]byte, minimal
// Create a new DB instance.
if minimal {
config := &filesystem.Config{PubKeys: pubkeys}
db, err = filesystem.NewStore(t.TempDir(), config)
db, err = filesystem.NewStore(dataPath, config)
} else {
config := &kv.Config{PubKeys: pubkeys}
db, err = kv.NewKVStore(context.Background(), t.TempDir(), config)
db, err = kv.NewKVStore(context.Background(), dataPath, config)
}
if err != nil {

View File

@@ -1110,7 +1110,7 @@ func TestServer_SetGasLimit(t *testing.T) {
m := &testutil.FakeValidator{}
err := m.SetProposerSettings(ctx, tt.proposerSettings)
require.NoError(t, err)
validatorDB := dbtest.SetupDB(t, [][fieldparams.BLSPubkeyLength]byte{}, isSlashingProtectionMinimal)
validatorDB := dbtest.SetupDB(t, t.TempDir(), [][fieldparams.BLSPubkeyLength]byte{}, isSlashingProtectionMinimal)
vs, err := client.NewValidatorService(ctx, &client.Config{
Validator: m,
DB: validatorDB,
@@ -1299,7 +1299,7 @@ func TestServer_DeleteGasLimit(t *testing.T) {
m := &testutil.FakeValidator{}
err := m.SetProposerSettings(ctx, tt.proposerSettings)
require.NoError(t, err)
validatorDB := dbtest.SetupDB(t, [][fieldparams.BLSPubkeyLength]byte{}, isSlashingProtectionMinimal)
validatorDB := dbtest.SetupDB(t, t.TempDir(), [][fieldparams.BLSPubkeyLength]byte{}, isSlashingProtectionMinimal)
vs, err := client.NewValidatorService(ctx, &client.Config{
Validator: m,
DB: validatorDB,
@@ -1777,7 +1777,7 @@ func TestServer_FeeRecipientByPubkey(t *testing.T) {
m := &testutil.FakeValidator{}
err := m.SetProposerSettings(ctx, tt.proposerSettings)
require.NoError(t, err)
validatorDB := dbtest.SetupDB(t, [][fieldparams.BLSPubkeyLength]byte{}, isSlashingProtectionMinimal)
validatorDB := dbtest.SetupDB(t, t.TempDir(), [][fieldparams.BLSPubkeyLength]byte{}, isSlashingProtectionMinimal)
// save a default here
vs, err := client.NewValidatorService(ctx, &client.Config{
@@ -1889,7 +1889,7 @@ func TestServer_DeleteFeeRecipientByPubkey(t *testing.T) {
m := &testutil.FakeValidator{}
err := m.SetProposerSettings(ctx, tt.proposerSettings)
require.NoError(t, err)
validatorDB := dbtest.SetupDB(t, [][fieldparams.BLSPubkeyLength]byte{}, isSlashingProtectionMinimal)
validatorDB := dbtest.SetupDB(t, t.TempDir(), [][fieldparams.BLSPubkeyLength]byte{}, isSlashingProtectionMinimal)
vs, err := client.NewValidatorService(ctx, &client.Config{
Validator: m,
DB: validatorDB,

View File

@@ -21,7 +21,7 @@ func TestExportStandardProtectionJSON_EmptyGenesisRoot(t *testing.T) {
pubKeys := [][fieldparams.BLSPubkeyLength]byte{
{1},
}
validatorDB := dbtest.SetupDB(t, pubKeys, isSlashingProtectionMinimal)
validatorDB := dbtest.SetupDB(t, t.TempDir(), pubKeys, isSlashingProtectionMinimal)
_, err := ExportStandardProtectionJSON(ctx, validatorDB)
require.ErrorContains(t, "genesis validators root is empty", err)
genesisValidatorsRoot := [32]byte{1}
@@ -40,7 +40,7 @@ func Test_getSignedAttestationsByPubKey(t *testing.T) {
{1},
}
ctx := context.Background()
validatorDB := dbtest.SetupDB(t, pubKeys, isSlashingProtectionMinimal)
validatorDB := dbtest.SetupDB(t, t.TempDir(), pubKeys, isSlashingProtectionMinimal)
// No attestation history stored should return empty.
signedAttestations, err := signedAttestationsByPubKey(ctx, validatorDB, pubKeys[0])
@@ -98,7 +98,7 @@ func Test_getSignedAttestationsByPubKey(t *testing.T) {
ctx := context.Background()
isSlashingProtectionMinimal := false
validatorDB := dbtest.SetupDB(t, pubKeys, isSlashingProtectionMinimal)
validatorDB := dbtest.SetupDB(t, t.TempDir(), pubKeys, isSlashingProtectionMinimal)
// No attestation history stored should return empty.
signedAttestations, err := signedAttestationsByPubKey(ctx, validatorDB, pubKeys[0])
@@ -145,7 +145,7 @@ func Test_getSignedAttestationsByPubKey(t *testing.T) {
ctx := context.Background()
isSlashingProtectionMinimal := false
validatorDB := dbtest.SetupDB(t, pubKeys, isSlashingProtectionMinimal)
validatorDB := dbtest.SetupDB(t, t.TempDir(), pubKeys, isSlashingProtectionMinimal)
// No attestation history stored should return empty.
signedAttestations, err := signedAttestationsByPubKey(ctx, validatorDB, pubKeys[0])
@@ -196,7 +196,7 @@ func Test_getSignedBlocksByPubKey(t *testing.T) {
{1},
}
ctx := context.Background()
validatorDB := dbtest.SetupDB(t, pubKeys, isSlashingProtectionMinimal)
validatorDB := dbtest.SetupDB(t, t.TempDir(), pubKeys, isSlashingProtectionMinimal)
// No highest and/or lowest signed blocks will return empty.
signedBlocks, err := signedBlocksByPubKey(ctx, validatorDB, pubKeys[0])

View File

@@ -29,7 +29,7 @@ func TestImportExport_RoundTrip(t *testing.T) {
require.NoError(t, err)
isSlashingProtectionMinimal := false
validatorDB := dbtest.SetupDB(t, publicKeys, isSlashingProtectionMinimal)
validatorDB := dbtest.SetupDB(t, t.TempDir(), publicKeys, isSlashingProtectionMinimal)
// First we setup some mock attesting and proposal histories and create a mock
// standard slashing protection format JSON struct.
@@ -98,7 +98,7 @@ func TestImportExport_RoundTrip_SkippedAttestationEpochs(t *testing.T) {
require.NoError(t, err)
isSlashingProtectionMinimal := false
validatorDB := dbtest.SetupDB(t, pubKeys, isSlashingProtectionMinimal)
validatorDB := dbtest.SetupDB(t, t.TempDir(), pubKeys, isSlashingProtectionMinimal)
wanted := &format.EIPSlashingProtectionFormat{
Metadata: struct {
InterchangeFormatVersion string `json:"interchange_format_version"`
@@ -164,7 +164,7 @@ func TestImportExport_FilterKeys(t *testing.T) {
require.NoError(t, err)
isSlashingProtectionMinimal := false
validatorDB := dbtest.SetupDB(t, publicKeys, isSlashingProtectionMinimal)
validatorDB := dbtest.SetupDB(t, t.TempDir(), publicKeys, isSlashingProtectionMinimal)
// First we setup some mock attesting and proposal histories and create a mock
// standard slashing protection format JSON struct.
@@ -209,7 +209,7 @@ func TestImportInterchangeData_OK(t *testing.T) {
require.NoError(t, err)
isSlashingProtectionMinimal := false
validatorDB := dbtest.SetupDB(t, publicKeys, isSlashingProtectionMinimal)
validatorDB := dbtest.SetupDB(t, t.TempDir(), publicKeys, isSlashingProtectionMinimal)
// First we setup some mock attesting and proposal histories and create a mock
// standard slashing protection format JSON struct.
@@ -279,7 +279,7 @@ func TestImportInterchangeData_OK_SavesBlacklistedPublicKeys(t *testing.T) {
require.NoError(t, err)
isSlashingProtectionMinimal := false
validatorDB := dbtest.SetupDB(t, publicKeys, isSlashingProtectionMinimal)
validatorDB := dbtest.SetupDB(t, t.TempDir(), publicKeys, isSlashingProtectionMinimal)
// First we setup some mock attesting and proposal histories and create a mock
// standard slashing protection format JSON struct.
@@ -374,7 +374,7 @@ func TestStore_ImportInterchangeData_BadFormat_PreventsDBWrites(t *testing.T) {
require.NoError(t, err)
isSlashingProtectionMinimal := false
validatorDB := dbtest.SetupDB(t, publicKeys, isSlashingProtectionMinimal)
validatorDB := dbtest.SetupDB(t, t.TempDir(), publicKeys, isSlashingProtectionMinimal)
// First we setup some mock attesting and proposal histories and create a mock
// standard slashing protection format JSON struct.