prysm-pulse/validator/rpc/slashing.go

70 lines
2.6 KiB
Go
Raw Normal View History

Slashing Protection RPC Endpoints for Web Backend (#8723) * added the removed RPC delete account to accounts.go and the rpc in proto * reverted the 3 unit tests namely the failed derived delete, no pub keys provided and the successful imported account with provided public keys; also brought back the createImportedWalletWithAccounts back in wallet_test.go * strong password defined elsewhere- removed * Update validator/rpc/accounts_test.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * added PublicKeys Nil test case * changed ss to s. ss was a bad name inthe first place * goimports -w root * fixed the goimports before running the proto scripts, also changed the deleterequest variable to PublicKeysToDelete * removed unneeded comment * added test case for derived, changed delete account to be for both imported and derived * gofmt * unrelated files * unrelated files * unrelatedfiles restored * revert unrelated files * changed the last ss * adding slashign endpoints * adding the rpc export and import funcs, still need more testing and add unit tests * added import slashing unit test * clean up * remove less * Update proto/validator/accounts/v2/web_api.proto Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> * Update proto/validator/accounts/v2/web_api.proto Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> * Update proto/validator/accounts/v2/web_api.proto Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> * Update proto/validator/accounts/v2/web_api.proto Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> * camelCase Proto * update slashing_protection_json * update proto * register in validator/rpc/gateway * removed the server db creation, the validator cannot begin with a null db * round trip test * gofmt * Update validator/rpc/slashing.go * Update validator/rpc/slashing.go * Update validator/rpc/slashing.go * Update validator/rpc/slashing.go * Update validator/rpc/slashing.go * Update validator/rpc/slashing.go * Update validator/rpc/slashing.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> Co-authored-by: terence tsao <terence@prysmaticlabs.com>
2021-04-09 19:13:59 +00:00
package rpc
import (
"bytes"
"context"
"encoding/json"
"github.com/golang/protobuf/ptypes/empty"
"github.com/pkg/errors"
pb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1/validator-client"
slashing "github.com/prysmaticlabs/prysm/v4/validator/slashing-protection-history"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/types/known/emptypb"
Slashing Protection RPC Endpoints for Web Backend (#8723) * added the removed RPC delete account to accounts.go and the rpc in proto * reverted the 3 unit tests namely the failed derived delete, no pub keys provided and the successful imported account with provided public keys; also brought back the createImportedWalletWithAccounts back in wallet_test.go * strong password defined elsewhere- removed * Update validator/rpc/accounts_test.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * added PublicKeys Nil test case * changed ss to s. ss was a bad name inthe first place * goimports -w root * fixed the goimports before running the proto scripts, also changed the deleterequest variable to PublicKeysToDelete * removed unneeded comment * added test case for derived, changed delete account to be for both imported and derived * gofmt * unrelated files * unrelated files * unrelatedfiles restored * revert unrelated files * changed the last ss * adding slashign endpoints * adding the rpc export and import funcs, still need more testing and add unit tests * added import slashing unit test * clean up * remove less * Update proto/validator/accounts/v2/web_api.proto Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> * Update proto/validator/accounts/v2/web_api.proto Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> * Update proto/validator/accounts/v2/web_api.proto Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> * Update proto/validator/accounts/v2/web_api.proto Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> * camelCase Proto * update slashing_protection_json * update proto * register in validator/rpc/gateway * removed the server db creation, the validator cannot begin with a null db * round trip test * gofmt * Update validator/rpc/slashing.go * Update validator/rpc/slashing.go * Update validator/rpc/slashing.go * Update validator/rpc/slashing.go * Update validator/rpc/slashing.go * Update validator/rpc/slashing.go * Update validator/rpc/slashing.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> Co-authored-by: terence tsao <terence@prysmaticlabs.com>
2021-04-09 19:13:59 +00:00
)
// ExportSlashingProtection handles the rpc call returning the json slashing history.
// The format of the export follows the EIP-3076 standard which makes it
// easy to migrate machines or Ethereum consensus clients.
Slashing Protection RPC Endpoints for Web Backend (#8723) * added the removed RPC delete account to accounts.go and the rpc in proto * reverted the 3 unit tests namely the failed derived delete, no pub keys provided and the successful imported account with provided public keys; also brought back the createImportedWalletWithAccounts back in wallet_test.go * strong password defined elsewhere- removed * Update validator/rpc/accounts_test.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * added PublicKeys Nil test case * changed ss to s. ss was a bad name inthe first place * goimports -w root * fixed the goimports before running the proto scripts, also changed the deleterequest variable to PublicKeysToDelete * removed unneeded comment * added test case for derived, changed delete account to be for both imported and derived * gofmt * unrelated files * unrelated files * unrelatedfiles restored * revert unrelated files * changed the last ss * adding slashign endpoints * adding the rpc export and import funcs, still need more testing and add unit tests * added import slashing unit test * clean up * remove less * Update proto/validator/accounts/v2/web_api.proto Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> * Update proto/validator/accounts/v2/web_api.proto Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> * Update proto/validator/accounts/v2/web_api.proto Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> * Update proto/validator/accounts/v2/web_api.proto Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> * camelCase Proto * update slashing_protection_json * update proto * register in validator/rpc/gateway * removed the server db creation, the validator cannot begin with a null db * round trip test * gofmt * Update validator/rpc/slashing.go * Update validator/rpc/slashing.go * Update validator/rpc/slashing.go * Update validator/rpc/slashing.go * Update validator/rpc/slashing.go * Update validator/rpc/slashing.go * Update validator/rpc/slashing.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> Co-authored-by: terence tsao <terence@prysmaticlabs.com>
2021-04-09 19:13:59 +00:00
//
// Steps:
// 1. Call the function which exports the data from
// the validator's db into an EIP standard slashing protection format.
// 2. Format and send JSON in the response.
//
// DEPRECATED: Prysm Web UI and associated endpoints will be fully removed in a future hard fork. Use the Keymanager APIs if an API is required.
Slashing Protection RPC Endpoints for Web Backend (#8723) * added the removed RPC delete account to accounts.go and the rpc in proto * reverted the 3 unit tests namely the failed derived delete, no pub keys provided and the successful imported account with provided public keys; also brought back the createImportedWalletWithAccounts back in wallet_test.go * strong password defined elsewhere- removed * Update validator/rpc/accounts_test.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * added PublicKeys Nil test case * changed ss to s. ss was a bad name inthe first place * goimports -w root * fixed the goimports before running the proto scripts, also changed the deleterequest variable to PublicKeysToDelete * removed unneeded comment * added test case for derived, changed delete account to be for both imported and derived * gofmt * unrelated files * unrelated files * unrelatedfiles restored * revert unrelated files * changed the last ss * adding slashign endpoints * adding the rpc export and import funcs, still need more testing and add unit tests * added import slashing unit test * clean up * remove less * Update proto/validator/accounts/v2/web_api.proto Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> * Update proto/validator/accounts/v2/web_api.proto Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> * Update proto/validator/accounts/v2/web_api.proto Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> * Update proto/validator/accounts/v2/web_api.proto Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> * camelCase Proto * update slashing_protection_json * update proto * register in validator/rpc/gateway * removed the server db creation, the validator cannot begin with a null db * round trip test * gofmt * Update validator/rpc/slashing.go * Update validator/rpc/slashing.go * Update validator/rpc/slashing.go * Update validator/rpc/slashing.go * Update validator/rpc/slashing.go * Update validator/rpc/slashing.go * Update validator/rpc/slashing.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> Co-authored-by: terence tsao <terence@prysmaticlabs.com>
2021-04-09 19:13:59 +00:00
func (s *Server) ExportSlashingProtection(ctx context.Context, _ *empty.Empty) (*pb.ExportSlashingProtectionResponse, error) {
if s.valDB == nil {
return nil, errors.New("err finding validator database at path")
}
eipJSON, err := slashing.ExportStandardProtectionJSON(ctx, s.valDB)
if err != nil {
return nil, errors.Wrap(err, "could not export slashing protection history")
}
encoded, err := json.MarshalIndent(eipJSON, "", "\t")
if err != nil {
return nil, errors.Wrap(err, "could not JSON marshal slashing protection history")
}
return &pb.ExportSlashingProtectionResponse{
File: string(encoded),
}, nil
}
// ImportSlashingProtection reads an input slashing protection EIP-3076
// standard JSON string and inserts the data into validator DB.
//
// Read the JSON string passed through rpc, then call the func
// which actually imports the data from the JSON file into our database. Use the Keymanager APIs if an API is required.
// DEPRECATED: Prysm Web UI and associated endpoints will be fully removed in a future hard fork.
Slashing Protection RPC Endpoints for Web Backend (#8723) * added the removed RPC delete account to accounts.go and the rpc in proto * reverted the 3 unit tests namely the failed derived delete, no pub keys provided and the successful imported account with provided public keys; also brought back the createImportedWalletWithAccounts back in wallet_test.go * strong password defined elsewhere- removed * Update validator/rpc/accounts_test.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> * added PublicKeys Nil test case * changed ss to s. ss was a bad name inthe first place * goimports -w root * fixed the goimports before running the proto scripts, also changed the deleterequest variable to PublicKeysToDelete * removed unneeded comment * added test case for derived, changed delete account to be for both imported and derived * gofmt * unrelated files * unrelated files * unrelatedfiles restored * revert unrelated files * changed the last ss * adding slashign endpoints * adding the rpc export and import funcs, still need more testing and add unit tests * added import slashing unit test * clean up * remove less * Update proto/validator/accounts/v2/web_api.proto Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> * Update proto/validator/accounts/v2/web_api.proto Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> * Update proto/validator/accounts/v2/web_api.proto Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> * Update proto/validator/accounts/v2/web_api.proto Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> * camelCase Proto * update slashing_protection_json * update proto * register in validator/rpc/gateway * removed the server db creation, the validator cannot begin with a null db * round trip test * gofmt * Update validator/rpc/slashing.go * Update validator/rpc/slashing.go * Update validator/rpc/slashing.go * Update validator/rpc/slashing.go * Update validator/rpc/slashing.go * Update validator/rpc/slashing.go * Update validator/rpc/slashing.go Co-authored-by: Radosław Kapka <rkapka@wp.pl> Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> Co-authored-by: terence tsao <terence@prysmaticlabs.com>
2021-04-09 19:13:59 +00:00
func (s *Server) ImportSlashingProtection(ctx context.Context, req *pb.ImportSlashingProtectionRequest) (*emptypb.Empty, error) {
if s.valDB == nil {
return nil, errors.New("err finding validator database at path")
}
if req.SlashingProtectionJson == "" {
return nil, status.Errorf(codes.InvalidArgument, "empty slashing_protection json specified")
}
enc := []byte(req.SlashingProtectionJson)
buf := bytes.NewBuffer(enc)
if err := slashing.ImportStandardProtectionJSON(ctx, s.valDB, buf); err != nil {
return nil, err
}
log.Info("Slashing protection JSON successfully imported")
return &empty.Empty{}, nil
}