From 0fb91437fc84265bea51fe24a1d3eb6e28285bea Mon Sep 17 00:00:00 2001 From: Raul Jordan Date: Tue, 9 Nov 2021 11:49:28 -0500 Subject: [PATCH] Group Slashing Protection History Packages Idiomatically (#9873) * rename * gaz * gaz * Gaz * rename * edit * gaz * gaz * build * fix * build * fix up * fix * gaz * cli import export * gaz * flag * rev * comm * package renames * radek --- cmd/validator/slashing-protection/BUILD.bazel | 33 ++++- .../validator/slashing-protection/export.go | 12 +- .../validator/slashing-protection/import.go | 10 +- .../slashing-protection/import_export_test.go | 12 +- cmd/validator/slashing-protection/log.go | 5 + .../slashing-protection.go | 11 +- config/features/flags.go | 2 +- validator/accounts/userprompt/BUILD.bazel | 5 +- validator/client/BUILD.bazel | 2 +- .../slashing_protection_interchange_test.go | 16 +-- validator/db/kv/BUILD.bazel | 5 +- validator/db/testing/BUILD.bazel | 5 +- validator/rpc/BUILD.bazel | 4 +- validator/rpc/slashing.go | 2 +- validator/rpc/slashing_test.go | 2 +- .../BUILD.bazel | 12 +- validator/slashing-protection-history/doc.go | 4 + .../export.go | 4 +- .../export_test.go | 4 +- .../format/BUILD.bazel | 4 +- .../format/format.go | 3 - .../helpers.go | 2 +- .../helpers_test.go | 2 +- .../import.go | 4 +- .../import_test.go | 4 +- validator/slashing-protection-history/log.go | 5 + .../round_trip_test.go | 20 +-- validator/slashing-protection/BUILD.bazel | 64 --------- validator/slashing-protection/external.go | 35 ----- .../slashing-protection/external_test.go | 50 ------- .../slashing-protection/iface/BUILD.bazel | 9 -- .../slashing-protection/iface/protector.go | 14 -- .../local/standard-protection-format/log.go | 5 - validator/slashing-protection/log.go | 5 - .../slashing-protection/slasher_client.go | 129 ------------------ .../slasher_client_test.go | 23 ---- validator/testing/BUILD.bazel | 7 +- validator/testing/protection_history.go | 2 +- 38 files changed, 128 insertions(+), 409 deletions(-) rename validator/slashing-protection/cli_export.go => cmd/validator/slashing-protection/export.go (88%) rename validator/slashing-protection/cli_import.go => cmd/validator/slashing-protection/import.go (88%) rename validator/slashing-protection/cli_import_export_test.go => cmd/validator/slashing-protection/import_export_test.go (95%) create mode 100644 cmd/validator/slashing-protection/log.go rename validator/{slashing-protection/local/standard-protection-format => slashing-protection-history}/BUILD.bazel (84%) create mode 100644 validator/slashing-protection-history/doc.go rename validator/{slashing-protection/local/standard-protection-format => slashing-protection-history}/export.go (98%) rename validator/{slashing-protection/local/standard-protection-format => slashing-protection-history}/export_test.go (98%) rename validator/{slashing-protection/local/standard-protection-format => slashing-protection-history}/format/BUILD.bazel (63%) rename validator/{slashing-protection/local/standard-protection-format => slashing-protection-history}/format/format.go (83%) rename validator/{slashing-protection/local/standard-protection-format => slashing-protection-history}/helpers.go (99%) rename validator/{slashing-protection/local/standard-protection-format => slashing-protection-history}/helpers_test.go (99%) rename validator/{slashing-protection/local/standard-protection-format => slashing-protection-history}/import.go (99%) rename validator/{slashing-protection/local/standard-protection-format => slashing-protection-history}/import_test.go (99%) create mode 100644 validator/slashing-protection-history/log.go rename validator/{slashing-protection/local/standard-protection-format => slashing-protection-history}/round_trip_test.go (93%) delete mode 100644 validator/slashing-protection/BUILD.bazel delete mode 100644 validator/slashing-protection/external.go delete mode 100644 validator/slashing-protection/external_test.go delete mode 100644 validator/slashing-protection/iface/BUILD.bazel delete mode 100644 validator/slashing-protection/iface/protector.go delete mode 100644 validator/slashing-protection/local/standard-protection-format/log.go delete mode 100644 validator/slashing-protection/log.go delete mode 100644 validator/slashing-protection/slasher_client.go delete mode 100644 validator/slashing-protection/slasher_client_test.go diff --git a/cmd/validator/slashing-protection/BUILD.bazel b/cmd/validator/slashing-protection/BUILD.bazel index 47d9bbd4a7..8b859746b5 100644 --- a/cmd/validator/slashing-protection/BUILD.bazel +++ b/cmd/validator/slashing-protection/BUILD.bazel @@ -1,17 +1,44 @@ -load("@prysm//tools/go:def.bzl", "go_library") +load("@prysm//tools/go:def.bzl", "go_library", "go_test") go_library( name = "go_default_library", - srcs = ["slashing-protection.go"], + srcs = [ + "export.go", + "import.go", + "log.go", + "slashing-protection.go", + ], importpath = "github.com/prysmaticlabs/prysm/cmd/validator/slashing-protection", visibility = ["//visibility:public"], deps = [ "//cmd:go_default_library", "//cmd/validator/flags:go_default_library", "//config/features:go_default_library", + "//io/file:go_default_library", "//runtime/tos:go_default_library", - "//validator/slashing-protection:go_default_library", + "//validator/accounts/userprompt:go_default_library", + "//validator/db/kv:go_default_library", + "//validator/slashing-protection-history:go_default_library", + "@com_github_pkg_errors//:go_default_library", "@com_github_sirupsen_logrus//:go_default_library", "@com_github_urfave_cli_v2//:go_default_library", ], ) + +go_test( + name = "go_default_test", + srcs = ["import_export_test.go"], + embed = [":go_default_library"], + deps = [ + "//cmd:go_default_library", + "//cmd/validator/flags:go_default_library", + "//io/file:go_default_library", + "//testing/assert:go_default_library", + "//testing/require:go_default_library", + "//validator/db/kv:go_default_library", + "//validator/db/testing:go_default_library", + "//validator/slashing-protection-history/format:go_default_library", + "//validator/testing:go_default_library", + "@com_github_urfave_cli_v2//:go_default_library", + ], +) diff --git a/validator/slashing-protection/cli_export.go b/cmd/validator/slashing-protection/export.go similarity index 88% rename from validator/slashing-protection/cli_export.go rename to cmd/validator/slashing-protection/export.go index b5ee39967e..fb999e278a 100644 --- a/validator/slashing-protection/cli_export.go +++ b/cmd/validator/slashing-protection/export.go @@ -1,4 +1,4 @@ -package slashingprotection +package historycmd import ( "encoding/json" @@ -11,7 +11,7 @@ import ( "github.com/prysmaticlabs/prysm/io/file" "github.com/prysmaticlabs/prysm/validator/accounts/userprompt" "github.com/prysmaticlabs/prysm/validator/db/kv" - export "github.com/prysmaticlabs/prysm/validator/slashing-protection/local/standard-protection-format" + slashingprotection "github.com/prysmaticlabs/prysm/validator/slashing-protection-history" "github.com/urfave/cli/v2" ) @@ -19,7 +19,7 @@ const ( jsonExportFileName = "slashing_protection.json" ) -// ExportSlashingProtectionJSONCli extracts a validator's slashing protection +// Extracts a validator's slashing protection // history from their database and formats it into an EIP-3076 standard JSON // file via a CLI entrypoint to make it easy to migrate machines or Ethereum consensus clients. // @@ -29,7 +29,7 @@ const ( // 3. Call the function which actually exports the data from // from the validator's db into an EIP standard slashing protection format // 4. Format and save the JSON file to a user's specified output directory. -func ExportSlashingProtectionJSONCli(cliCtx *cli.Context) error { +func exportSlashingProtectionJSON(cliCtx *cli.Context) error { log.Info( "This command exports your validator's attestation and proposal history into " + "a file that can then be imported into any other Prysm setup across computers", @@ -63,7 +63,7 @@ func ExportSlashingProtectionJSONCli(cliCtx *cli.Context) error { log.WithError(err).Errorf("Could not close validator DB") } }() - eipJSON, err := export.ExportStandardProtectionJSON(cliCtx.Context, validatorDB) + eipJSON, err := slashingprotection.ExportStandardProtectionJSON(cliCtx.Context, validatorDB) if err != nil { return errors.Wrap(err, "could not export slashing protection history") } @@ -98,7 +98,7 @@ func ExportSlashingProtectionJSONCli(cliCtx *cli.Context) error { } log.Infof( "Successfully wrote %s. You can import this file using Prysm's "+ - "validator slashing-protection import command in another machine", + "validator slashing-protection-history import command in another machine", outputFilePath, ) return nil diff --git a/validator/slashing-protection/cli_import.go b/cmd/validator/slashing-protection/import.go similarity index 88% rename from validator/slashing-protection/cli_import.go rename to cmd/validator/slashing-protection/import.go index 824ac21e17..26cd8daee0 100644 --- a/validator/slashing-protection/cli_import.go +++ b/cmd/validator/slashing-protection/import.go @@ -1,4 +1,4 @@ -package slashingprotection +package historycmd import ( "bytes" @@ -10,11 +10,11 @@ import ( "github.com/prysmaticlabs/prysm/io/file" "github.com/prysmaticlabs/prysm/validator/accounts/userprompt" "github.com/prysmaticlabs/prysm/validator/db/kv" - slashingProtectionFormat "github.com/prysmaticlabs/prysm/validator/slashing-protection/local/standard-protection-format" + slashingprotection "github.com/prysmaticlabs/prysm/validator/slashing-protection-history" "github.com/urfave/cli/v2" ) -// ImportSlashingProtectionCLI reads an input slashing protection EIP-3076 +// Reads an input slashing protection EIP-3076 // standard JSON file and attempts to insert its data into our validator DB. // // Steps: @@ -23,7 +23,7 @@ import ( // 3. Read the JSON file from user input. // 4. Call the function which actually imports the data from // from the standard slashing protection JSON file into our database. -func ImportSlashingProtectionCLI(cliCtx *cli.Context) error { +func importSlashingProtectionJSON(cliCtx *cli.Context) error { var err error dataDir := cliCtx.String(cmd.DataDirFlag.Name) if !cliCtx.IsSet(cmd.DataDirFlag.Name) { @@ -71,7 +71,7 @@ func ImportSlashingProtectionCLI(cliCtx *cli.Context) error { } log.Infof("Starting import of slashing protection file %s", protectionFilePath) buf := bytes.NewBuffer(enc) - if err := slashingProtectionFormat.ImportStandardProtectionJSON( + if err := slashingprotection.ImportStandardProtectionJSON( cliCtx.Context, valDB, buf, ); err != nil { return err diff --git a/validator/slashing-protection/cli_import_export_test.go b/cmd/validator/slashing-protection/import_export_test.go similarity index 95% rename from validator/slashing-protection/cli_import_export_test.go rename to cmd/validator/slashing-protection/import_export_test.go index 34b312e2a3..147230f7e0 100644 --- a/validator/slashing-protection/cli_import_export_test.go +++ b/cmd/validator/slashing-protection/import_export_test.go @@ -1,4 +1,4 @@ -package slashingprotection +package historycmd import ( "encoding/json" @@ -14,7 +14,7 @@ import ( "github.com/prysmaticlabs/prysm/testing/require" "github.com/prysmaticlabs/prysm/validator/db/kv" dbTest "github.com/prysmaticlabs/prysm/validator/db/testing" - "github.com/prysmaticlabs/prysm/validator/slashing-protection/local/standard-protection-format/format" + "github.com/prysmaticlabs/prysm/validator/slashing-protection-history/format" mocks "github.com/prysmaticlabs/prysm/validator/testing" "github.com/urfave/cli/v2" ) @@ -66,11 +66,11 @@ func TestImportExportSlashingProtectionCli_RoundTrip(t *testing.T) { cliCtx := setupCliCtx(t, dbPath, protectionFilePath, outputPath) // We import the slashing protection history file via CLI. - err = ImportSlashingProtectionCLI(cliCtx) + err = importSlashingProtectionJSON(cliCtx) require.NoError(t, err) // We export the slashing protection history file via CLI. - err = ExportSlashingProtectionJSONCli(cliCtx) + err = exportSlashingProtectionJSON(cliCtx) require.NoError(t, err) // Attempt to read the exported file from the output directory. @@ -142,11 +142,11 @@ func TestImportExportSlashingProtectionCli_EmptyData(t *testing.T) { cliCtx := setupCliCtx(t, dbPath, protectionFilePath, outputPath) // We import the slashing protection history file via CLI. - err = ImportSlashingProtectionCLI(cliCtx) + err = importSlashingProtectionJSON(cliCtx) require.NoError(t, err) // We export the slashing protection history file via CLI. - err = ExportSlashingProtectionJSONCli(cliCtx) + err = exportSlashingProtectionJSON(cliCtx) require.NoError(t, err) // Attempt to read the exported file from the output directory. diff --git a/cmd/validator/slashing-protection/log.go b/cmd/validator/slashing-protection/log.go new file mode 100644 index 0000000000..f105763424 --- /dev/null +++ b/cmd/validator/slashing-protection/log.go @@ -0,0 +1,5 @@ +package historycmd + +import "github.com/sirupsen/logrus" + +var log = logrus.WithField("prefix", "historycmd") diff --git a/cmd/validator/slashing-protection/slashing-protection.go b/cmd/validator/slashing-protection/slashing-protection.go index 7e5e0a1eca..e47ae5e532 100644 --- a/cmd/validator/slashing-protection/slashing-protection.go +++ b/cmd/validator/slashing-protection/slashing-protection.go @@ -1,19 +1,18 @@ -package slashing_protection +package historycmd import ( "github.com/prysmaticlabs/prysm/cmd" "github.com/prysmaticlabs/prysm/cmd/validator/flags" "github.com/prysmaticlabs/prysm/config/features" "github.com/prysmaticlabs/prysm/runtime/tos" - slashingprotection "github.com/prysmaticlabs/prysm/validator/slashing-protection" "github.com/sirupsen/logrus" "github.com/urfave/cli/v2" ) // Commands for slashing protection. var Commands = &cli.Command{ - Name: "slashing-protection", - Category: "slashing-protection", + Name: "slashing-protection-history", + Category: "slashing-protection-history", Usage: "defines commands for interacting your validator's slashing protection history", Subcommands: []*cli.Command{ { @@ -31,7 +30,7 @@ var Commands = &cli.Command{ }, Action: func(cliCtx *cli.Context) error { features.ConfigureValidator(cliCtx) - if err := slashingprotection.ExportSlashingProtectionJSONCli(cliCtx); err != nil { + if err := exportSlashingProtectionJSON(cliCtx); err != nil { logrus.Fatalf("Could not export slashing protection file: %v", err) } return nil @@ -56,7 +55,7 @@ var Commands = &cli.Command{ }, Action: func(cliCtx *cli.Context) error { features.ConfigureValidator(cliCtx) - err := slashingprotection.ImportSlashingProtectionCLI(cliCtx) + err := importSlashingProtectionJSON(cliCtx) if err != nil { logrus.Fatalf("Could not import slashing protection cli: %v", err) } diff --git a/config/features/flags.go b/config/features/flags.go index 7f4703ab15..5cd136a303 100644 --- a/config/features/flags.go +++ b/config/features/flags.go @@ -98,7 +98,7 @@ var ( Usage: "Disable max-cover algorithm when selecting attestations for proposer", } enableSlashingProtectionPruning = &cli.BoolFlag{ - Name: "enable-slashing-protection-pruning", + Name: "enable-slashing-protection-history-pruning", Usage: "Enables the pruning of the validator client's slashing protection database", } disableOptimizedBalanceUpdate = &cli.BoolFlag{ diff --git a/validator/accounts/userprompt/BUILD.bazel b/validator/accounts/userprompt/BUILD.bazel index caf7ef5242..e0d27b0623 100644 --- a/validator/accounts/userprompt/BUILD.bazel +++ b/validator/accounts/userprompt/BUILD.bazel @@ -7,7 +7,10 @@ go_library( "prompt.go", ], importpath = "github.com/prysmaticlabs/prysm/validator/accounts/userprompt", - visibility = ["//validator:__subpackages__"], + visibility = [ + "//cmd:__subpackages__", + "//validator:__subpackages__", + ], deps = [ "//cmd/validator/flags:go_default_library", "//io/file:go_default_library", diff --git a/validator/client/BUILD.bazel b/validator/client/BUILD.bazel index f637aa2b1b..a44cd92438 100644 --- a/validator/client/BUILD.bazel +++ b/validator/client/BUILD.bazel @@ -128,7 +128,7 @@ go_test( "//validator/graffiti:go_default_library", "//validator/keymanager/derived:go_default_library", "//validator/keymanager/remote:go_default_library", - "//validator/slashing-protection/local/standard-protection-format:go_default_library", + "//validator/slashing-protection-history:go_default_library", "//validator/testing:go_default_library", "@com_github_golang_mock//gomock:go_default_library", "@com_github_pkg_errors//:go_default_library", diff --git a/validator/client/slashing_protection_interchange_test.go b/validator/client/slashing_protection_interchange_test.go index 58fa905dcb..05ab2bd306 100644 --- a/validator/client/slashing_protection_interchange_test.go +++ b/validator/client/slashing_protection_interchange_test.go @@ -15,7 +15,7 @@ import ( "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/wrapper" "github.com/prysmaticlabs/prysm/testing/require" "github.com/prysmaticlabs/prysm/testing/util" - interchangeformat "github.com/prysmaticlabs/prysm/validator/slashing-protection/local/standard-protection-format" + "github.com/prysmaticlabs/prysm/validator/slashing-protection-history" ) type eip3076TestCase struct { @@ -88,7 +88,7 @@ func TestEIP3076SpecTests(t *testing.T) { validator, _, _, _ := setup(t) if tt.GenesisValidatorsRoot != "" { - r, err := interchangeformat.RootFromHex(tt.GenesisValidatorsRoot) + r, err := history.RootFromHex(tt.GenesisValidatorsRoot) require.NoError(t, validator.db.SaveGenesisValidatorsRoot(context.Background(), r[:])) require.NoError(t, err) } @@ -100,7 +100,7 @@ func TestEIP3076SpecTests(t *testing.T) { t.Fatal(err) } b := bytes.NewBuffer(interchangeBytes) - if err := interchangeformat.ImportStandardProtectionJSON(context.Background(), validator.db, b); err != nil { + if err := history.ImportStandardProtectionJSON(context.Background(), validator.db, b); err != nil { if step.ShouldSucceed { t.Fatal(err) } @@ -110,9 +110,9 @@ func TestEIP3076SpecTests(t *testing.T) { // This loops through a list of block signings to attempt after importing the interchange data above. for _, sb := range step.Blocks { - bSlot, err := interchangeformat.SlotFromString(sb.Slot) + bSlot, err := history.SlotFromString(sb.Slot) require.NoError(t, err) - pk, err := interchangeformat.PubKeyFromHex(sb.Pubkey) + pk, err := history.PubKeyFromHex(sb.Pubkey) require.NoError(t, err) b := util.NewBeaconBlock() b.Block.Slot = bSlot @@ -134,11 +134,11 @@ func TestEIP3076SpecTests(t *testing.T) { // This loops through a list of attestation signings to attempt after importing the interchange data above. for _, sa := range step.Attestations { - target, err := interchangeformat.EpochFromString(sa.TargetEpoch) + target, err := history.EpochFromString(sa.TargetEpoch) require.NoError(t, err) - source, err := interchangeformat.EpochFromString(sa.SourceEpoch) + source, err := history.EpochFromString(sa.SourceEpoch) require.NoError(t, err) - pk, err := interchangeformat.PubKeyFromHex(sa.Pubkey) + pk, err := history.PubKeyFromHex(sa.Pubkey) require.NoError(t, err) ia := ðpb.IndexedAttestation{ Data: ðpb.AttestationData{ diff --git a/validator/db/kv/BUILD.bazel b/validator/db/kv/BUILD.bazel index e904a9650f..092312ab2b 100644 --- a/validator/db/kv/BUILD.bazel +++ b/validator/db/kv/BUILD.bazel @@ -19,7 +19,10 @@ go_library( "schema.go", ], importpath = "github.com/prysmaticlabs/prysm/validator/db/kv", - visibility = ["//validator:__subpackages__"], + visibility = [ + "//cmd:__subpackages__", + "//validator:__subpackages__", + ], deps = [ "//async/abool:go_default_library", "//async/event:go_default_library", diff --git a/validator/db/testing/BUILD.bazel b/validator/db/testing/BUILD.bazel index 4a236a0b7e..11a845e744 100644 --- a/validator/db/testing/BUILD.bazel +++ b/validator/db/testing/BUILD.bazel @@ -4,7 +4,10 @@ go_library( name = "go_default_library", srcs = ["setup_db.go"], importpath = "github.com/prysmaticlabs/prysm/validator/db/testing", - visibility = ["//validator:__subpackages__"], + visibility = [ + "//cmd:__subpackages__", + "//validator:__subpackages__", + ], deps = [ "//validator/db/iface:go_default_library", "//validator/db/kv:go_default_library", diff --git a/validator/rpc/BUILD.bazel b/validator/rpc/BUILD.bazel index d7b8583376..7480a7c684 100644 --- a/validator/rpc/BUILD.bazel +++ b/validator/rpc/BUILD.bazel @@ -44,7 +44,7 @@ go_library( "//validator/keymanager:go_default_library", "//validator/keymanager/derived:go_default_library", "//validator/keymanager/imported:go_default_library", - "//validator/slashing-protection/local/standard-protection-format:go_default_library", + "//validator/slashing-protection-history:go_default_library", "@com_github_fsnotify_fsnotify//:go_default_library", "@com_github_golang_jwt_jwt//:go_default_library", "@com_github_grpc_ecosystem_go_grpc_middleware//:go_default_library", @@ -104,7 +104,7 @@ go_test( "//validator/keymanager:go_default_library", "//validator/keymanager/derived:go_default_library", "//validator/keymanager/imported:go_default_library", - "//validator/slashing-protection/local/standard-protection-format/format:go_default_library", + "//validator/slashing-protection-history/format:go_default_library", "//validator/testing:go_default_library", "@com_github_golang_jwt_jwt//:go_default_library", "@com_github_golang_mock//gomock:go_default_library", diff --git a/validator/rpc/slashing.go b/validator/rpc/slashing.go index 8616e75a98..59e13ab02b 100644 --- a/validator/rpc/slashing.go +++ b/validator/rpc/slashing.go @@ -8,7 +8,7 @@ import ( "github.com/golang/protobuf/ptypes/empty" "github.com/pkg/errors" pb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/validator-client" - slashing "github.com/prysmaticlabs/prysm/validator/slashing-protection/local/standard-protection-format" + slashing "github.com/prysmaticlabs/prysm/validator/slashing-protection-history" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" "google.golang.org/protobuf/types/known/emptypb" diff --git a/validator/rpc/slashing_test.go b/validator/rpc/slashing_test.go index 6cb91448a0..38bb428edd 100644 --- a/validator/rpc/slashing_test.go +++ b/validator/rpc/slashing_test.go @@ -12,7 +12,7 @@ import ( "github.com/prysmaticlabs/prysm/validator/accounts/wallet" "github.com/prysmaticlabs/prysm/validator/db/kv" "github.com/prysmaticlabs/prysm/validator/keymanager" - "github.com/prysmaticlabs/prysm/validator/slashing-protection/local/standard-protection-format/format" + "github.com/prysmaticlabs/prysm/validator/slashing-protection-history/format" mocks "github.com/prysmaticlabs/prysm/validator/testing" ) diff --git a/validator/slashing-protection/local/standard-protection-format/BUILD.bazel b/validator/slashing-protection-history/BUILD.bazel similarity index 84% rename from validator/slashing-protection/local/standard-protection-format/BUILD.bazel rename to validator/slashing-protection-history/BUILD.bazel index 84946a4aef..7626d33e93 100644 --- a/validator/slashing-protection/local/standard-protection-format/BUILD.bazel +++ b/validator/slashing-protection-history/BUILD.bazel @@ -3,13 +3,17 @@ load("@prysm//tools/go:def.bzl", "go_library", "go_test") go_library( name = "go_default_library", srcs = [ + "doc.go", "export.go", "helpers.go", "import.go", "log.go", ], - importpath = "github.com/prysmaticlabs/prysm/validator/slashing-protection/local/standard-protection-format", - visibility = ["//validator:__subpackages__"], + importpath = "github.com/prysmaticlabs/prysm/validator/slashing-protection-history", + visibility = [ + "//cmd:__subpackages__", + "//validator:__subpackages__", + ], deps = [ "//config/params:go_default_library", "//encoding/bytesutil:go_default_library", @@ -18,7 +22,7 @@ go_library( "//proto/prysm/v1alpha1/slashings:go_default_library", "//validator/db:go_default_library", "//validator/db/kv:go_default_library", - "//validator/slashing-protection/local/standard-protection-format/format:go_default_library", + "//validator/slashing-protection-history/format:go_default_library", "@com_github_k0kubun_go_ansi//:go_default_library", "@com_github_pkg_errors//:go_default_library", "@com_github_prysmaticlabs_eth2_types//:go_default_library", @@ -42,7 +46,7 @@ go_test( "//testing/require:go_default_library", "//validator/db/kv:go_default_library", "//validator/db/testing:go_default_library", - "//validator/slashing-protection/local/standard-protection-format/format:go_default_library", + "//validator/slashing-protection-history/format:go_default_library", "//validator/testing:go_default_library", "@com_github_prysmaticlabs_eth2_types//:go_default_library", "@com_github_sirupsen_logrus//hooks/test:go_default_library", diff --git a/validator/slashing-protection-history/doc.go b/validator/slashing-protection-history/doc.go new file mode 100644 index 0000000000..ff16bb1cfb --- /dev/null +++ b/validator/slashing-protection-history/doc.go @@ -0,0 +1,4 @@ +// Package history defines methods to parse, import, and export slashing protection data +// from a standard JSON file according to EIP-3076 https://eips.ethereum.org/EIPS/eip-3076. This format +// is critical to allow safe interoperability between Ethereum consensus clients. +package history diff --git a/validator/slashing-protection/local/standard-protection-format/export.go b/validator/slashing-protection-history/export.go similarity index 98% rename from validator/slashing-protection/local/standard-protection-format/export.go rename to validator/slashing-protection-history/export.go index 5b23a2b08b..0f37245385 100644 --- a/validator/slashing-protection/local/standard-protection-format/export.go +++ b/validator/slashing-protection-history/export.go @@ -1,4 +1,4 @@ -package interchangeformat +package history import ( "bytes" @@ -11,7 +11,7 @@ import ( "github.com/prysmaticlabs/prysm/config/params" "github.com/prysmaticlabs/prysm/monitoring/progress" "github.com/prysmaticlabs/prysm/validator/db" - "github.com/prysmaticlabs/prysm/validator/slashing-protection/local/standard-protection-format/format" + "github.com/prysmaticlabs/prysm/validator/slashing-protection-history/format" ) // ExportStandardProtectionJSON extracts all slashing protection data from a validator database diff --git a/validator/slashing-protection/local/standard-protection-format/export_test.go b/validator/slashing-protection-history/export_test.go similarity index 98% rename from validator/slashing-protection/local/standard-protection-format/export_test.go rename to validator/slashing-protection-history/export_test.go index 105bb27b3e..75aee396d8 100644 --- a/validator/slashing-protection/local/standard-protection-format/export_test.go +++ b/validator/slashing-protection-history/export_test.go @@ -1,4 +1,4 @@ -package interchangeformat +package history import ( "context" @@ -9,7 +9,7 @@ import ( "github.com/prysmaticlabs/prysm/testing/assert" "github.com/prysmaticlabs/prysm/testing/require" dbtest "github.com/prysmaticlabs/prysm/validator/db/testing" - "github.com/prysmaticlabs/prysm/validator/slashing-protection/local/standard-protection-format/format" + "github.com/prysmaticlabs/prysm/validator/slashing-protection-history/format" ) func TestExportStandardProtectionJSON_EmptyGenesisRoot(t *testing.T) { diff --git a/validator/slashing-protection/local/standard-protection-format/format/BUILD.bazel b/validator/slashing-protection-history/format/BUILD.bazel similarity index 63% rename from validator/slashing-protection/local/standard-protection-format/format/BUILD.bazel rename to validator/slashing-protection-history/format/BUILD.bazel index 6bb4d2ba1f..42c4a58ce9 100644 --- a/validator/slashing-protection/local/standard-protection-format/format/BUILD.bazel +++ b/validator/slashing-protection-history/format/BUILD.bazel @@ -3,6 +3,6 @@ load("@prysm//tools/go:def.bzl", "go_library") go_library( name = "go_default_library", srcs = ["format.go"], - importpath = "github.com/prysmaticlabs/prysm/validator/slashing-protection/local/standard-protection-format/format", - visibility = ["//validator:__subpackages__"], + importpath = "github.com/prysmaticlabs/prysm/validator/slashing-protection-history/format", + visibility = ["//visibility:public"], ) diff --git a/validator/slashing-protection/local/standard-protection-format/format/format.go b/validator/slashing-protection-history/format/format.go similarity index 83% rename from validator/slashing-protection/local/standard-protection-format/format/format.go rename to validator/slashing-protection-history/format/format.go index 19fe64bacb..49e7d53ee9 100644 --- a/validator/slashing-protection/local/standard-protection-format/format/format.go +++ b/validator/slashing-protection-history/format/format.go @@ -1,6 +1,3 @@ -// Package format defines methods to parse, import, and export slashing protection data -// from a standard JSON file according to EIP-3076 https://eips.ethereum.org/EIPS/eip-3076. This format -// is critical to allow safe interoperability between Ethereum consensus clients. package format // InterchangeFormatVersion specified by https://eips.ethereum.org/EIPS/eip-3076. diff --git a/validator/slashing-protection/local/standard-protection-format/helpers.go b/validator/slashing-protection-history/helpers.go similarity index 99% rename from validator/slashing-protection/local/standard-protection-format/helpers.go rename to validator/slashing-protection-history/helpers.go index cee1b9b1fc..0a36ac9c15 100644 --- a/validator/slashing-protection/local/standard-protection-format/helpers.go +++ b/validator/slashing-protection-history/helpers.go @@ -1,4 +1,4 @@ -package interchangeformat +package history import ( "encoding/hex" diff --git a/validator/slashing-protection/local/standard-protection-format/helpers_test.go b/validator/slashing-protection-history/helpers_test.go similarity index 99% rename from validator/slashing-protection/local/standard-protection-format/helpers_test.go rename to validator/slashing-protection-history/helpers_test.go index 13fe49518b..291affc76c 100644 --- a/validator/slashing-protection/local/standard-protection-format/helpers_test.go +++ b/validator/slashing-protection-history/helpers_test.go @@ -1,4 +1,4 @@ -package interchangeformat +package history import ( "fmt" diff --git a/validator/slashing-protection/local/standard-protection-format/import.go b/validator/slashing-protection-history/import.go similarity index 99% rename from validator/slashing-protection/local/standard-protection-format/import.go rename to validator/slashing-protection-history/import.go index 1a610967ad..8caa0f01a0 100644 --- a/validator/slashing-protection/local/standard-protection-format/import.go +++ b/validator/slashing-protection-history/import.go @@ -1,4 +1,4 @@ -package interchangeformat +package history import ( "bytes" @@ -15,7 +15,7 @@ import ( "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1/slashings" "github.com/prysmaticlabs/prysm/validator/db" "github.com/prysmaticlabs/prysm/validator/db/kv" - "github.com/prysmaticlabs/prysm/validator/slashing-protection/local/standard-protection-format/format" + "github.com/prysmaticlabs/prysm/validator/slashing-protection-history/format" ) // ImportStandardProtectionJSON takes in EIP-3076 compliant JSON file used for slashing protection diff --git a/validator/slashing-protection/local/standard-protection-format/import_test.go b/validator/slashing-protection-history/import_test.go similarity index 99% rename from validator/slashing-protection/local/standard-protection-format/import_test.go rename to validator/slashing-protection-history/import_test.go index 45458e8297..4e4240fc1d 100644 --- a/validator/slashing-protection/local/standard-protection-format/import_test.go +++ b/validator/slashing-protection-history/import_test.go @@ -1,4 +1,4 @@ -package interchangeformat +package history import ( "bytes" @@ -15,7 +15,7 @@ import ( "github.com/prysmaticlabs/prysm/testing/require" "github.com/prysmaticlabs/prysm/validator/db/kv" dbtest "github.com/prysmaticlabs/prysm/validator/db/testing" - "github.com/prysmaticlabs/prysm/validator/slashing-protection/local/standard-protection-format/format" + "github.com/prysmaticlabs/prysm/validator/slashing-protection-history/format" valtest "github.com/prysmaticlabs/prysm/validator/testing" logTest "github.com/sirupsen/logrus/hooks/test" ) diff --git a/validator/slashing-protection-history/log.go b/validator/slashing-protection-history/log.go new file mode 100644 index 0000000000..e743f28f4d --- /dev/null +++ b/validator/slashing-protection-history/log.go @@ -0,0 +1,5 @@ +package history + +import "github.com/sirupsen/logrus" + +var log = logrus.WithField("prefix", "slashing-protection-history") diff --git a/validator/slashing-protection/local/standard-protection-format/round_trip_test.go b/validator/slashing-protection-history/round_trip_test.go similarity index 93% rename from validator/slashing-protection/local/standard-protection-format/round_trip_test.go rename to validator/slashing-protection-history/round_trip_test.go index 85ee42731c..a5f2513370 100644 --- a/validator/slashing-protection/local/standard-protection-format/round_trip_test.go +++ b/validator/slashing-protection-history/round_trip_test.go @@ -1,4 +1,4 @@ -package interchangeformat_test +package history_test import ( "bytes" @@ -12,8 +12,8 @@ import ( "github.com/prysmaticlabs/prysm/testing/require" "github.com/prysmaticlabs/prysm/validator/db/kv" dbtest "github.com/prysmaticlabs/prysm/validator/db/testing" - protectionFormat "github.com/prysmaticlabs/prysm/validator/slashing-protection/local/standard-protection-format" - "github.com/prysmaticlabs/prysm/validator/slashing-protection/local/standard-protection-format/format" + "github.com/prysmaticlabs/prysm/validator/slashing-protection-history" + "github.com/prysmaticlabs/prysm/validator/slashing-protection-history/format" slashtest "github.com/prysmaticlabs/prysm/validator/testing" ) @@ -37,12 +37,12 @@ func TestImportExport_RoundTrip(t *testing.T) { buf := bytes.NewBuffer(blob) // Next, we attempt to import it into our validator database. - err = protectionFormat.ImportStandardProtectionJSON(ctx, validatorDB, buf) + err = history.ImportStandardProtectionJSON(ctx, validatorDB, buf) require.NoError(t, err) // Next up, we export our slashing protection database into the EIP standard file. // Next, we attempt to import it into our validator database. - eipStandard, err := protectionFormat.ExportStandardProtectionJSON(ctx, validatorDB) + eipStandard, err := history.ExportStandardProtectionJSON(ctx, validatorDB) require.NoError(t, err) // We compare the metadata fields from import to export. @@ -111,12 +111,12 @@ func TestImportExport_RoundTrip_SkippedAttestationEpochs(t *testing.T) { buf := bytes.NewBuffer(blob) // Next, we attempt to import it into our validator database. - err = protectionFormat.ImportStandardProtectionJSON(ctx, validatorDB, buf) + err = history.ImportStandardProtectionJSON(ctx, validatorDB, buf) require.NoError(t, err) // Next up, we export our slashing protection database into the EIP standard file. // Next, we attempt to import it into our validator database. - eipStandard, err := protectionFormat.ExportStandardProtectionJSON(ctx, validatorDB) + eipStandard, err := history.ExportStandardProtectionJSON(ctx, validatorDB) require.NoError(t, err) // We compare the metadata fields from import to export. @@ -148,7 +148,7 @@ func TestImportInterchangeData_OK(t *testing.T) { buf := bytes.NewBuffer(blob) // Next, we attempt to import it into our validator database. - err = protectionFormat.ImportStandardProtectionJSON(ctx, validatorDB, buf) + err = history.ImportStandardProtectionJSON(ctx, validatorDB, buf) require.NoError(t, err) // Next, we attempt to retrieve the attesting and proposals histories from our database and @@ -256,7 +256,7 @@ func TestImportInterchangeData_OK_SavesBlacklistedPublicKeys(t *testing.T) { buf := bytes.NewBuffer(blob) // Next, we attempt to import it into our validator database. - err = protectionFormat.ImportStandardProtectionJSON(ctx, validatorDB, buf) + err = history.ImportStandardProtectionJSON(ctx, validatorDB, buf) require.NoError(t, err) // Assert the three slashable keys in the imported JSON were saved to the database. @@ -299,7 +299,7 @@ func TestStore_ImportInterchangeData_BadFormat_PreventsDBWrites(t *testing.T) { // Next, we attempt to import it into our validator database and check that // we obtain an error during the import process. - err = protectionFormat.ImportStandardProtectionJSON(ctx, validatorDB, buf) + err = history.ImportStandardProtectionJSON(ctx, validatorDB, buf) assert.NotNil(t, err) // Next, we attempt to retrieve the attesting and proposals histories from our database and diff --git a/validator/slashing-protection/BUILD.bazel b/validator/slashing-protection/BUILD.bazel deleted file mode 100644 index 91e3e492d0..0000000000 --- a/validator/slashing-protection/BUILD.bazel +++ /dev/null @@ -1,64 +0,0 @@ -load("@prysm//tools/go:def.bzl", "go_library", "go_test") - -go_library( - name = "go_default_library", - srcs = [ - "cli_export.go", - "cli_import.go", - "external.go", - "log.go", - "slasher_client.go", - ], - importpath = "github.com/prysmaticlabs/prysm/validator/slashing-protection", - visibility = [ - "//cmd/validator:__subpackages__", - "//validator:__subpackages__", - ], - deps = [ - "//api/grpc:go_default_library", - "//cmd:go_default_library", - "//cmd/validator/flags:go_default_library", - "//io/file:go_default_library", - "//proto/prysm/v1alpha1:go_default_library", - "//validator/accounts/userprompt:go_default_library", - "//validator/db/kv:go_default_library", - "//validator/slashing-protection/local/standard-protection-format:go_default_library", - "@com_github_grpc_ecosystem_go_grpc_middleware//:go_default_library", - "@com_github_grpc_ecosystem_go_grpc_middleware//retry:go_default_library", - "@com_github_grpc_ecosystem_go_grpc_middleware//tracing/opentracing:go_default_library", - "@com_github_grpc_ecosystem_go_grpc_prometheus//:go_default_library", - "@com_github_pkg_errors//:go_default_library", - "@com_github_sirupsen_logrus//:go_default_library", - "@com_github_urfave_cli_v2//:go_default_library", - "@io_opencensus_go//plugin/ocgrpc:go_default_library", - "@org_golang_google_grpc//:go_default_library", - "@org_golang_google_grpc//connectivity:go_default_library", - "@org_golang_google_grpc//credentials:go_default_library", - ], -) - -go_test( - name = "go_default_test", - srcs = [ - "cli_import_export_test.go", - "external_test.go", - "slasher_client_test.go", - ], - embed = [":go_default_library"], - deps = [ - "//cmd:go_default_library", - "//cmd/validator/flags:go_default_library", - "//config/params:go_default_library", - "//encoding/bytesutil:go_default_library", - "//io/file:go_default_library", - "//proto/prysm/v1alpha1:go_default_library", - "//testing/assert:go_default_library", - "//testing/require:go_default_library", - "//validator/db/kv:go_default_library", - "//validator/db/testing:go_default_library", - "//validator/slashing-protection/local/standard-protection-format/format:go_default_library", - "//validator/testing:go_default_library", - "@com_github_urfave_cli_v2//:go_default_library", - "@org_golang_google_grpc//metadata:go_default_library", - ], -) diff --git a/validator/slashing-protection/external.go b/validator/slashing-protection/external.go deleted file mode 100644 index 053a890cc4..0000000000 --- a/validator/slashing-protection/external.go +++ /dev/null @@ -1,35 +0,0 @@ -package slashingprotection - -import ( - "context" - - ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" -) - -// CheckBlockSafety for blocks before submitting them to the node. -func (s *Service) CheckBlockSafety(ctx context.Context, blockHeader *ethpb.SignedBeaconBlockHeader) bool { - ps, err := s.slasherClient.IsSlashableBlock(ctx, blockHeader) - if err != nil { - log.Errorf("External slashing block protection returned an error: %v", err) - return false - } - if ps != nil && len(ps.ProposerSlashings) != 0 { - log.Warn("External slashing proposal protection found the block to be slashable") - return false - } - return true -} - -// CheckAttestationSafety for attestations before submitting them to the node. -func (s *Service) CheckAttestationSafety(ctx context.Context, attestation *ethpb.IndexedAttestation) bool { - as, err := s.slasherClient.IsSlashableAttestation(ctx, attestation) - if err != nil { - log.Errorf("External slashing attestation protection returned an error: %v", err) - return false - } - if as != nil && len(as.AttesterSlashings) != 0 { - log.Warnf("External slashing attestation protection found the attestation to be slashable: %v", as) - return false - } - return true -} diff --git a/validator/slashing-protection/external_test.go b/validator/slashing-protection/external_test.go deleted file mode 100644 index d8ee72d2cd..0000000000 --- a/validator/slashing-protection/external_test.go +++ /dev/null @@ -1,50 +0,0 @@ -package slashingprotection - -import ( - "context" - "testing" - - "github.com/prysmaticlabs/prysm/config/params" - "github.com/prysmaticlabs/prysm/encoding/bytesutil" - eth "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" - "github.com/prysmaticlabs/prysm/testing/assert" - mockSlasher "github.com/prysmaticlabs/prysm/validator/testing" -) - -func TestService_VerifyAttestation(t *testing.T) { - s := &Service{slasherClient: mockSlasher.MockSlasher{SlashAttestation: true}} - att := ð.IndexedAttestation{ - AttestingIndices: []uint64{1, 2}, - Data: ð.AttestationData{ - Slot: 5, - CommitteeIndex: 2, - BeaconBlockRoot: []byte("great block"), - Source: ð.Checkpoint{ - Epoch: 4, - Root: []byte("good source"), - }, - Target: ð.Checkpoint{ - Epoch: 10, - Root: []byte("good target"), - }, - }, - } - assert.Equal(t, false, s.CheckAttestationSafety(context.Background(), att), "Expected verify attestation to fail verification") - s = &Service{slasherClient: mockSlasher.MockSlasher{SlashAttestation: false}} - assert.Equal(t, true, s.CheckAttestationSafety(context.Background(), att), "Expected verify attestation to pass verification") -} - -func TestService_VerifyBlock(t *testing.T) { - s := &Service{slasherClient: mockSlasher.MockSlasher{SlashBlock: true}} - blk := ð.BeaconBlockHeader{ - Slot: 0, - ProposerIndex: 0, - ParentRoot: bytesutil.PadTo([]byte("parent"), 32), - StateRoot: bytesutil.PadTo([]byte("state"), 32), - BodyRoot: bytesutil.PadTo([]byte("body"), 32), - } - sblk := ð.SignedBeaconBlockHeader{Header: blk, Signature: params.BeaconConfig().EmptySignature[:]} - assert.Equal(t, false, s.CheckBlockSafety(context.Background(), sblk), "Expected verify block to fail verification") - s = &Service{slasherClient: mockSlasher.MockSlasher{SlashBlock: false}} - assert.Equal(t, true, s.CheckBlockSafety(context.Background(), sblk), "Expected verify block to pass verification") -} diff --git a/validator/slashing-protection/iface/BUILD.bazel b/validator/slashing-protection/iface/BUILD.bazel deleted file mode 100644 index 6272a7f1de..0000000000 --- a/validator/slashing-protection/iface/BUILD.bazel +++ /dev/null @@ -1,9 +0,0 @@ -load("@prysm//tools/go:def.bzl", "go_library") - -go_library( - name = "go_default_library", - srcs = ["protector.go"], - importpath = "github.com/prysmaticlabs/prysm/validator/slashing-protection/iface", - visibility = ["//validator:__subpackages__"], - deps = ["//proto/prysm/v1alpha1:go_default_library"], -) diff --git a/validator/slashing-protection/iface/protector.go b/validator/slashing-protection/iface/protector.go deleted file mode 100644 index 9c9844cd4d..0000000000 --- a/validator/slashing-protection/iface/protector.go +++ /dev/null @@ -1,14 +0,0 @@ -package iface - -import ( - "context" - - eth "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" -) - -// Protector interface defines the methods of the service that provides slashing protection. -type Protector interface { - CheckAttestationSafety(ctx context.Context, attestation *eth.IndexedAttestation) bool - CheckBlockSafety(ctx context.Context, blockHeader *eth.SignedBeaconBlockHeader) bool - Status() error -} diff --git a/validator/slashing-protection/local/standard-protection-format/log.go b/validator/slashing-protection/local/standard-protection-format/log.go deleted file mode 100644 index ec6567d6a8..0000000000 --- a/validator/slashing-protection/local/standard-protection-format/log.go +++ /dev/null @@ -1,5 +0,0 @@ -package interchangeformat - -import "github.com/sirupsen/logrus" - -var log = logrus.WithField("prefix", "slashing-protection-format") diff --git a/validator/slashing-protection/log.go b/validator/slashing-protection/log.go deleted file mode 100644 index 7802e7a3e5..0000000000 --- a/validator/slashing-protection/log.go +++ /dev/null @@ -1,5 +0,0 @@ -package slashingprotection - -import "github.com/sirupsen/logrus" - -var log = logrus.WithField("prefix", "slashingprotection") diff --git a/validator/slashing-protection/slasher_client.go b/validator/slashing-protection/slasher_client.go deleted file mode 100644 index 907fca66c7..0000000000 --- a/validator/slashing-protection/slasher_client.go +++ /dev/null @@ -1,129 +0,0 @@ -package slashingprotection - -import ( - "context" - "errors" - "fmt" - "strings" - "time" - - middleware "github.com/grpc-ecosystem/go-grpc-middleware" - grpc_retry "github.com/grpc-ecosystem/go-grpc-middleware/retry" - grpc_opentracing "github.com/grpc-ecosystem/go-grpc-middleware/tracing/opentracing" - grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus" - grpcutil "github.com/prysmaticlabs/prysm/api/grpc" - ethsl "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1" - "go.opencensus.io/plugin/ocgrpc" - "google.golang.org/grpc" - "google.golang.org/grpc/connectivity" - "google.golang.org/grpc/credentials" -) - -// Service represents a service to manage the validator -// ￿slashing protection. -type Service struct { - cfg *Config - ctx context.Context - cancel context.CancelFunc - conn *grpc.ClientConn - grpcHeaders []string - slasherClient ethsl.SlasherClient -} - -// Config for the validator service. -type Config struct { - Endpoint string - CertFlag string - GrpcMaxCallRecvMsgSizeFlag int - GrpcRetriesFlag uint - GrpcRetryDelay time.Duration - GrpcHeadersFlag string -} - -// NewService creates a new validator service for the service -// registry. -func NewService(ctx context.Context, cfg *Config) (*Service, error) { - ctx, cancel := context.WithCancel(ctx) - return &Service{ - cfg: cfg, - ctx: ctx, - cancel: cancel, - grpcHeaders: strings.Split(cfg.GrpcHeadersFlag, ","), - }, nil -} - -// Start the slasher protection service and grpc client. -func (s *Service) Start() { - if s.cfg.Endpoint != "" { - s.slasherClient = s.startSlasherClient() - } -} - -func (s *Service) startSlasherClient() ethsl.SlasherClient { - var dialOpt grpc.DialOption - - if s.cfg.CertFlag != "" { - creds, err := credentials.NewClientTLSFromFile(s.cfg.CertFlag, "") - if err != nil { - log.Errorf("Could not get valid slasher credentials: %v", err) - return nil - } - dialOpt = grpc.WithTransportCredentials(creds) - } else { - dialOpt = grpc.WithInsecure() - log.Warn("You are using an insecure slasher gRPC connection! Please provide a certificate and key to use a secure connection.") - } - - s.ctx = grpcutil.AppendHeaders(s.ctx, s.grpcHeaders) - - opts := []grpc.DialOption{ - dialOpt, - grpc.WithDefaultCallOptions( - grpc_retry.WithMax(s.cfg.GrpcRetriesFlag), - grpc_retry.WithBackoff(grpc_retry.BackoffLinear(s.cfg.GrpcRetryDelay)), - ), - grpc.WithStatsHandler(&ocgrpc.ClientHandler{}), - grpc.WithStreamInterceptor(middleware.ChainStreamClient( - grpc_opentracing.StreamClientInterceptor(), - grpc_prometheus.StreamClientInterceptor, - grpc_retry.StreamClientInterceptor(), - )), - grpc.WithUnaryInterceptor(middleware.ChainUnaryClient( - grpc_opentracing.UnaryClientInterceptor(), - grpc_prometheus.UnaryClientInterceptor, - grpc_retry.UnaryClientInterceptor(), - grpcutil.LogRequests, - )), - } - conn, err := grpc.DialContext(s.ctx, s.cfg.Endpoint, opts...) - if err != nil { - log.Errorf("Could not dial slasher endpoint: %s, %v", s.cfg.Endpoint, err) - return nil - } - log.Debug("Successfully started slasher gRPC connection") - s.conn = conn - return ethsl.NewSlasherClient(s.conn) - -} - -// Stop the validator service. -func (s *Service) Stop() error { - s.cancel() - log.Info("Stopping slashing protection service") - if s.conn != nil { - return s.conn.Close() - } - return nil -} - -// Status checks if the connection to slasher server is ready, -// returns error otherwise. -func (s *Service) Status() error { - if s.conn == nil { - return errors.New("no connection to slasher RPC") - } - if s.conn.GetState() != connectivity.Ready { - return fmt.Errorf("can`t connect to slasher server at: %v connection status: %v ", s.cfg.Endpoint, s.conn.GetState()) - } - return nil -} diff --git a/validator/slashing-protection/slasher_client_test.go b/validator/slashing-protection/slasher_client_test.go deleted file mode 100644 index de9c755e78..0000000000 --- a/validator/slashing-protection/slasher_client_test.go +++ /dev/null @@ -1,23 +0,0 @@ -package slashingprotection - -import ( - "context" - "testing" - - "github.com/prysmaticlabs/prysm/testing/assert" - "github.com/prysmaticlabs/prysm/testing/require" - "google.golang.org/grpc/metadata" -) - -func TestGrpcHeaders(t *testing.T) { - s := &Service{ - cfg: &Config{}, - ctx: context.Background(), - grpcHeaders: []string{"first=value1", "second=value2"}, - } - s.startSlasherClient() - md, _ := metadata.FromOutgoingContext(s.ctx) - require.Equal(t, 2, md.Len(), "MetadataV0 contains wrong number of values") - assert.Equal(t, "value1", md.Get("first")[0]) - assert.Equal(t, "value2", md.Get("second")[0]) -} diff --git a/validator/testing/BUILD.bazel b/validator/testing/BUILD.bazel index f49dab410e..38b29b99b5 100644 --- a/validator/testing/BUILD.bazel +++ b/validator/testing/BUILD.bazel @@ -10,7 +10,10 @@ go_library( "protection_history.go", ], importpath = "github.com/prysmaticlabs/prysm/validator/testing", - visibility = ["//validator:__subpackages__"], + visibility = [ + "//cmd:__subpackages__", + "//validator:__subpackages__", + ], deps = [ "//config/params:go_default_library", "//crypto/bls:go_default_library", @@ -18,7 +21,7 @@ go_library( "//encoding/bytesutil:go_default_library", "//proto/prysm/v1alpha1:go_default_library", "//validator/db/kv:go_default_library", - "//validator/slashing-protection/local/standard-protection-format/format:go_default_library", + "//validator/slashing-protection-history/format:go_default_library", "@com_github_prysmaticlabs_eth2_types//:go_default_library", "@org_golang_google_grpc//:go_default_library", "@org_golang_google_protobuf//proto:go_default_library", diff --git a/validator/testing/protection_history.go b/validator/testing/protection_history.go index 3de1a39b47..27e813e22f 100644 --- a/validator/testing/protection_history.go +++ b/validator/testing/protection_history.go @@ -9,7 +9,7 @@ import ( "github.com/prysmaticlabs/prysm/crypto/rand" "github.com/prysmaticlabs/prysm/encoding/bytesutil" "github.com/prysmaticlabs/prysm/validator/db/kv" - "github.com/prysmaticlabs/prysm/validator/slashing-protection/local/standard-protection-format/format" + "github.com/prysmaticlabs/prysm/validator/slashing-protection-history/format" ) // MockSlashingProtectionJSON creates a mock, full slashing protection JSON struct