Ran code inspect (#8387)

This commit is contained in:
terence tsao
2021-02-03 08:59:17 -08:00
committed by GitHub
parent 842bafb002
commit 616081fbdd
16 changed files with 31 additions and 30 deletions

View File

@@ -6,11 +6,11 @@ import (
"github.com/prysmaticlabs/prysm/shared/featureconfig"
)
const ENV_BLS = "BLS_ENABLED"
const EnvBls = "BLS_ENABLED"
func init() {
var blsEnabled bool
if value, exists := os.LookupEnv(ENV_BLS); exists {
if value, exists := os.LookupEnv(EnvBls); exists {
blsEnabled = value == "1"
}
featureconfig.Init(&featureconfig.Flags{

View File

@@ -51,7 +51,7 @@ func (p PublicKey) Aggregate(_ common.PublicKey) common.PublicKey {
}
// IsInfinite -- stub
func (s PublicKey) IsInfinite() bool {
func (p PublicKey) IsInfinite() bool {
panic(err)
}

View File

@@ -7,21 +7,21 @@ func NoIndexProvided() {
}
}
func StartIndexProvided_NoDiagnostic() {
func StartindexprovidedNodiagnostic() {
x := []byte{'f', 'o', 'o'}
y := x[1:]
if len(y) == 3 {
}
}
func EndIndexProvided_NoDiagnostic() {
func EndindexprovidedNodiagnostic() {
x := []byte{'f', 'o', 'o'}
y := x[:2]
if len(y) == 3 {
}
}
func BothIndicesProvided_NoDiagnostic() {
func BothindicesprovidedNodiagnostic() {
x := []byte{'f', 'o', 'o'}
y := x[1:2]
if len(y) == 3 {

View File

@@ -11,8 +11,8 @@ var (
ErrCouldNotInitializeKeymanager = "could not initialize keymanager"
)
// AccountsConfig specifies parameters to run to delete, enable, disable accounts.
type AccountsConfig struct {
// Config specifies parameters to run to delete, enable, disable accounts.
type Config struct {
Wallet *wallet.Wallet
Keymanager keymanager.IKeymanager
DisablePublicKeys [][]byte

View File

@@ -85,7 +85,7 @@ func DeleteAccountCli(cliCtx *cli.Context) error {
}
}
}
if err := DeleteAccount(cliCtx.Context, &AccountsConfig{
if err := DeleteAccount(cliCtx.Context, &Config{
Wallet: w,
Keymanager: keymanager,
DeletePublicKeys: rawPublicKeys,
@@ -100,7 +100,7 @@ func DeleteAccountCli(cliCtx *cli.Context) error {
}
// DeleteAccount deletes the accounts that the user requests to be deleted from the wallet.
func DeleteAccount(ctx context.Context, cfg *AccountsConfig) error {
func DeleteAccount(ctx context.Context, cfg *Config) error {
switch cfg.Wallet.KeymanagerKind() {
case keymanager.Remote:
return errors.New("cannot delete accounts for a remote keymanager")

View File

@@ -28,7 +28,7 @@ const (
// NewWalletPasswordPromptText for wallet creation.
NewWalletPasswordPromptText = "New wallet password"
// WalletPasswordPromptText for wallet unlocking.
WalletPasswordPromptText = "Wallet password"
PasswordPromptText = "Wallet password"
// ConfirmPasswordPromptText for confirming a wallet password.
ConfirmPasswordPromptText = "Confirm password"
// DefaultWalletPasswordFile used to store a wallet password with appropriate permissions
@@ -179,7 +179,7 @@ func OpenWalletOrElseCli(cliCtx *cli.Context, otherwise func(cliCtx *cli.Context
walletPassword, err := inputPassword(
cliCtx,
flags.WalletPasswordFileFlag,
WalletPasswordPromptText,
PasswordPromptText,
false, /* Do not confirm password */
ValidateExistingPass,
)

View File

@@ -50,9 +50,9 @@ var (
// AttestationHistoryForPubKey retrieves a list of attestation records for data
// we have stored in the database for the given validator public key.
func (store *Store) AttestationHistoryForPubKey(ctx context.Context, pubKey [48]byte) ([]*AttestationRecord, error) {
func (s *Store) AttestationHistoryForPubKey(ctx context.Context, pubKey [48]byte) ([]*AttestationRecord, error) {
records := make([]*AttestationRecord, 0)
err := store.view(func(tx *bolt.Tx) error {
err := s.view(func(tx *bolt.Tx) error {
bucket := tx.Bucket(pubKeysBucket)
pkBucket := bucket.Bucket(pubKey[:])
if pkBucket == nil {
@@ -367,11 +367,11 @@ 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 (store *Store) SigningRootAtTargetEpoch(ctx context.Context, pubKey [48]byte, target uint64) ([32]byte, error) {
func (s *Store) SigningRootAtTargetEpoch(ctx context.Context, pubKey [48]byte, target uint64) ([32]byte, error) {
ctx, span := trace.StartSpan(ctx, "Validator.SigningRootAtTargetEpoch")
defer span.End()
var signingRoot [32]byte
err := store.view(func(tx *bolt.Tx) error {
err := s.view(func(tx *bolt.Tx) error {
bucket := tx.Bucket(pubKeysBucket)
pkBucket := bucket.Bucket(pubKey[:])
if pkBucket == nil {

View File

@@ -117,6 +117,6 @@ func (km *Keymanager) DeleteAccounts(ctx context.Context, publicKeys [][]byte) e
// SubscribeAccountChanges creates an event subscription for a channel
// to listen for public key changes at runtime, such as when new validator accounts
// are imported into the keymanager while the validator process is running.
func (dr *Keymanager) SubscribeAccountChanges(pubKeysChan chan [][48]byte) event.Subscription {
return dr.importedKM.SubscribeAccountChanges(pubKeysChan)
func (km *Keymanager) SubscribeAccountChanges(pubKeysChan chan [][48]byte) event.Subscription {
return km.importedKM.SubscribeAccountChanges(pubKeysChan)
}

View File

@@ -231,7 +231,7 @@ func (km *Keymanager) Sign(ctx context.Context, req *validatorpb.SignRequest) (b
// SubscribeAccountChanges is currently NOT IMPLEMENTED for the remote keymanager.
// INVOKING THIS FUNCTION HAS NO EFFECT!
func (k *Keymanager) SubscribeAccountChanges(_ chan [][48]byte) event.Subscription {
func (km *Keymanager) SubscribeAccountChanges(_ chan [][48]byte) event.Subscription {
return event.NewSubscription(func(i <-chan struct{}) error {
return nil
})

View File

@@ -2,6 +2,8 @@ package slashingprotection
import (
"encoding/json"
"path/filepath"
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/shared/cmd"
"github.com/prysmaticlabs/prysm/shared/fileutil"
@@ -10,7 +12,6 @@ import (
"github.com/prysmaticlabs/prysm/validator/flags"
export "github.com/prysmaticlabs/prysm/validator/slashing-protection/local/standard-protection-format"
"github.com/urfave/cli/v2"
"path/filepath"
)
const (

View File

@@ -27,7 +27,7 @@ func ExportStandardProtectionJSON(ctx context.Context, validatorDB db.Database)
return nil, err
}
interchangeJSON.Metadata.GenesisValidatorsRoot = genesisRootHex
interchangeJSON.Metadata.InterchangeFormatVersion = format.INTERCHANGE_FORMAT_VERSION
interchangeJSON.Metadata.InterchangeFormatVersion = format.InterchangeFormatVersion
// Extract the existing public keys in our database.
proposedPublicKeys, err := validatorDB.ProposedPublicKeys(ctx)

View File

@@ -3,9 +3,9 @@
// is critical to allow safe interoperability between eth2 clients.
package format
// INTERCHANGE_FORMAT_VERSION specified by https://eips.ethereum.org/EIPS/eip-3076.
// InterchangeFormatVersion specified by https://eips.ethereum.org/EIPS/eip-3076.
// The version Prysm supports is version 5.
const INTERCHANGE_FORMAT_VERSION = "5"
const InterchangeFormatVersion = "5"
// EIPSlashingProtectionFormat string representation of a standard
// format for representing validator slashing protection db data.

View File

@@ -139,11 +139,11 @@ func ImportStandardProtectionJSON(ctx context.Context, validatorDB db.Database,
func validateMetadata(ctx context.Context, validatorDB db.Database, interchangeJSON *format.EIPSlashingProtectionFormat) error {
// We need to ensure the version in the metadata field matches the one we support.
version := interchangeJSON.Metadata.InterchangeFormatVersion
if version != format.INTERCHANGE_FORMAT_VERSION {
if version != format.InterchangeFormatVersion {
return fmt.Errorf(
"slashing protection JSON version '%s' is not supported, wanted '%s'",
version,
format.INTERCHANGE_FORMAT_VERSION,
format.InterchangeFormatVersion,
)
}

View File

@@ -210,7 +210,7 @@ func Test_validateMetadata(t *testing.T) {
InterchangeFormatVersion string `json:"interchange_format_version"`
GenesisValidatorsRoot string `json:"genesis_validators_root"`
}{
InterchangeFormatVersion: format.INTERCHANGE_FORMAT_VERSION,
InterchangeFormatVersion: format.InterchangeFormatVersion,
GenesisValidatorsRoot: string(goodStr),
},
},
@@ -250,7 +250,7 @@ func Test_validateMetadataGenesisValidatorRoot(t *testing.T) {
InterchangeFormatVersion string `json:"interchange_format_version"`
GenesisValidatorsRoot string `json:"genesis_validators_root"`
}{
InterchangeFormatVersion: format.INTERCHANGE_FORMAT_VERSION,
InterchangeFormatVersion: format.InterchangeFormatVersion,
GenesisValidatorsRoot: string(goodStr),
},
},
@@ -264,7 +264,7 @@ func Test_validateMetadataGenesisValidatorRoot(t *testing.T) {
InterchangeFormatVersion string `json:"interchange_format_version"`
GenesisValidatorsRoot string `json:"genesis_validators_root"`
}{
InterchangeFormatVersion: format.INTERCHANGE_FORMAT_VERSION,
InterchangeFormatVersion: format.InterchangeFormatVersion,
GenesisValidatorsRoot: string(secondStr),
},
},

View File

@@ -84,7 +84,7 @@ func TestImportExport_RoundTrip_SkippedAttestationEpochs(t *testing.T) {
InterchangeFormatVersion string `json:"interchange_format_version"`
GenesisValidatorsRoot string `json:"genesis_validators_root"`
}{
InterchangeFormatVersion: format.INTERCHANGE_FORMAT_VERSION,
InterchangeFormatVersion: format.InterchangeFormatVersion,
GenesisValidatorsRoot: fmt.Sprintf("%#x", [32]byte{}),
},
Data: []*format.ProtectionData{

View File

@@ -20,7 +20,7 @@ func MockSlashingProtectionJSON(
) (*format.EIPSlashingProtectionFormat, error) {
standardProtectionFormat := &format.EIPSlashingProtectionFormat{}
standardProtectionFormat.Metadata.GenesisValidatorsRoot = fmt.Sprintf("%#x", bytesutil.PadTo([]byte{32}, 32))
standardProtectionFormat.Metadata.InterchangeFormatVersion = format.INTERCHANGE_FORMAT_VERSION
standardProtectionFormat.Metadata.InterchangeFormatVersion = format.InterchangeFormatVersion
for i := 0; i < len(publicKeys); i++ {
data := &format.ProtectionData{
Pubkey: fmt.Sprintf("%#x", publicKeys[i]),