Skip to content

Commit

Permalink
Ran code inspect (#8387)
Browse files Browse the repository at this point in the history
  • Loading branch information
terencechain committed Feb 3, 2021
1 parent 842bafb commit 616081f
Show file tree
Hide file tree
Showing 16 changed files with 31 additions and 30 deletions.
4 changes: 2 additions & 2 deletions fuzz/common.go
Expand Up @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion shared/bls/blst/stub.go
Expand Up @@ -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)
}

Expand Down
6 changes: 3 additions & 3 deletions tools/analyzers/slicedirect/testdata/slice.go
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions validator/accounts/accounts.go
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions validator/accounts/accounts_delete.go
Expand Up @@ -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,
Expand All @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions validator/accounts/wallet/wallet.go
Expand Up @@ -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
Expand Down Expand Up @@ -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,
)
Expand Down
8 changes: 4 additions & 4 deletions validator/db/kv/attester_protection.go
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions validator/keymanager/derived/keymanager.go
Expand Up @@ -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)
}
2 changes: 1 addition & 1 deletion validator/keymanager/remote/keymanager.go
Expand Up @@ -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
})
Expand Down
3 changes: 2 additions & 1 deletion validator/slashing-protection/cli_export.go
Expand Up @@ -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"
Expand All @@ -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 (
Expand Down
Expand Up @@ -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)
Expand Down
Expand Up @@ -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.
Expand Down
Expand Up @@ -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,
)
}

Expand Down
Expand Up @@ -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),
},
},
Expand Down Expand Up @@ -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),
},
},
Expand All @@ -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),
},
},
Expand Down
Expand Up @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion validator/testing/protection_history.go
Expand Up @@ -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]),
Expand Down

0 comments on commit 616081f

Please sign in to comment.