Skip to content

Commit

Permalink
Fix typos and inconsistencies (#4453)
Browse files Browse the repository at this point in the history
* Fix typos and inconsistencies

* igoimports

* Gazelle
  • Loading branch information
0xKiwi authored and rauljordan committed Jan 8, 2020
1 parent 0d400fa commit b30a7d1
Show file tree
Hide file tree
Showing 40 changed files with 84 additions and 150 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -23,7 +23,7 @@ Participation is now open to the public for our Ethereum 2.0 phase 0 testnet rel
- [Running via Docker](#running-via-docker)
- [Running via Bazel](#running-via-bazel)
- [Staking ETH: running a validator client](#staking-eth-running-a-validator-client)
- [Activating your validator: depositing 3.2 Goerli ETH](#activating-your-validator-depositing-32-göerli-eth)
- [Activating your validator: depositing 3.2 Goerli ETH](#activating-your-validator-depositing-32-gerli-eth)
- [Starting the validator with Bazel](#starting-the-validator-with-bazel)
- [Setting up a local ETH2 development chain](#setting-up-a-local-eth2-development-chain)
- [Installation and dependencies](#installation-and-dependencies)
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/blockchain/forkchoice/service_test.go
Expand Up @@ -329,7 +329,7 @@ func TestStore_GetHead(t *testing.T) {
// 18 validators switches vote to B1 to gain 51%, enough to switch head
for i := 0; i < 18; i++ {
idx := 50 + uint64(i)
store.latestVoteMap[uint64(idx)] = &pb.ValidatorLatestVote{Root: roots[1]}
store.latestVoteMap[idx] = &pb.ValidatorLatestVote{Root: roots[1]}
}
head, err = store.Head(ctx)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/cache/eth1_data_test.go
Expand Up @@ -91,7 +91,7 @@ func TestEth1Data_MaxSize(t *testing.T) {

for i := 0; i < maxEth1DataVoteSize+1; i++ {
var hash [32]byte
copy(hash[:], []byte(strconv.Itoa(i)))
copy(hash[:], strconv.Itoa(i))
eInfo := &Eth1DataVote{
Eth1DataHash: hash,
}
Expand Down
24 changes: 12 additions & 12 deletions beacon-chain/core/epoch/epoch_processing_test.go
Expand Up @@ -323,8 +323,8 @@ func TestProcessRegistryUpdates_NoRotation(t *testing.T) {
state := &pb.BeaconState{
Slot: 5 * params.BeaconConfig().SlotsPerEpoch,
Validators: []*ethpb.Validator{
{ExitEpoch: params.BeaconConfig().MaxSeedLookhead},
{ExitEpoch: params.BeaconConfig().MaxSeedLookhead},
{ExitEpoch: params.BeaconConfig().MaxSeedLookahead},
{ExitEpoch: params.BeaconConfig().MaxSeedLookahead},
},
Balances: []uint64{
params.BeaconConfig().MaxEffectiveBalance,
Expand All @@ -337,9 +337,9 @@ func TestProcessRegistryUpdates_NoRotation(t *testing.T) {
t.Fatal(err)
}
for i, validator := range newState.Validators {
if validator.ExitEpoch != params.BeaconConfig().MaxSeedLookhead {
if validator.ExitEpoch != params.BeaconConfig().MaxSeedLookahead {
t.Errorf("Could not update registry %d, wanted exit slot %d got %d",
i, params.BeaconConfig().MaxSeedLookhead, validator.ExitEpoch)
i, params.BeaconConfig().MaxSeedLookahead, validator.ExitEpoch)
}
}
}
Expand Down Expand Up @@ -385,10 +385,10 @@ func TestProcessRegistryUpdates_ActivationCompletes(t *testing.T) {
state := &pb.BeaconState{
Slot: 5 * params.BeaconConfig().SlotsPerEpoch,
Validators: []*ethpb.Validator{
{ExitEpoch: params.BeaconConfig().MaxSeedLookhead,
ActivationEpoch: 5 + params.BeaconConfig().MaxSeedLookhead + 1},
{ExitEpoch: params.BeaconConfig().MaxSeedLookhead,
ActivationEpoch: 5 + params.BeaconConfig().MaxSeedLookhead + 1},
{ExitEpoch: params.BeaconConfig().MaxSeedLookahead,
ActivationEpoch: 5 + params.BeaconConfig().MaxSeedLookahead + 1},
{ExitEpoch: params.BeaconConfig().MaxSeedLookahead,
ActivationEpoch: 5 + params.BeaconConfig().MaxSeedLookahead + 1},
},
FinalizedCheckpoint: &ethpb.Checkpoint{},
}
Expand All @@ -397,9 +397,9 @@ func TestProcessRegistryUpdates_ActivationCompletes(t *testing.T) {
t.Error(err)
}
for i, validator := range newState.Validators {
if validator.ExitEpoch != params.BeaconConfig().MaxSeedLookhead {
if validator.ExitEpoch != params.BeaconConfig().MaxSeedLookahead {
t.Errorf("Could not update registry %d, wanted exit slot %d got %d",
i, params.BeaconConfig().MaxSeedLookhead, validator.ExitEpoch)
i, params.BeaconConfig().MaxSeedLookahead, validator.ExitEpoch)
}
}
}
Expand All @@ -424,9 +424,9 @@ func TestProcessRegistryUpdates_ValidatorsEjected(t *testing.T) {
t.Error(err)
}
for i, validator := range newState.Validators {
if validator.ExitEpoch != params.BeaconConfig().MaxSeedLookhead+1 {
if validator.ExitEpoch != params.BeaconConfig().MaxSeedLookahead+1 {
t.Errorf("Could not update registry %d, wanted exit slot %d got %d",
i, params.BeaconConfig().MaxSeedLookhead+1, validator.ExitEpoch)
i, params.BeaconConfig().MaxSeedLookahead+1, validator.ExitEpoch)
}
}
}
Expand Down
5 changes: 0 additions & 5 deletions beacon-chain/core/helpers/randao.go
@@ -1,17 +1,12 @@
package helpers

import (
"github.com/pkg/errors"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/hashutil"
"github.com/prysmaticlabs/prysm/shared/params"
)

// ErrInvalidStateLatestActiveIndexRoots is returned when the state active
// index root count does not match the expected EpochsPerHistoricalVector.
var ErrInvalidStateLatestActiveIndexRoots = errors.New("state does not have correct number of latest active index roots")

// Seed returns the randao seed used for shuffling of a given epoch.
//
// Spec pseudocode definition:
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/core/helpers/validators.go
Expand Up @@ -110,7 +110,7 @@ func ActiveValidatorCount(state *pb.BeaconState, epoch uint64) (uint64, error) {
// """
// return Epoch(epoch + 1 + ACTIVATION_EXIT_DELAY)
func DelayedActivationExitEpoch(epoch uint64) uint64 {
return epoch + 1 + params.BeaconConfig().MaxSeedLookhead
return epoch + 1 + params.BeaconConfig().MaxSeedLookahead
}

// ValidatorChurnLimit returns the number of validators that are allowed to
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/core/helpers/validators_test.go
Expand Up @@ -178,7 +178,7 @@ func TestBeaconProposerIndex_OK(t *testing.T) {
func TestDelayedActivationExitEpoch_OK(t *testing.T) {
epoch := uint64(9999)
got := DelayedActivationExitEpoch(epoch)
wanted := epoch + 1 + params.BeaconConfig().MaxSeedLookhead
wanted := epoch + 1 + params.BeaconConfig().MaxSeedLookahead
if wanted != got {
t.Errorf("Wanted: %d, received: %d", wanted, got)
}
Expand Down
18 changes: 9 additions & 9 deletions beacon-chain/db/kv/finalized_block_roots.go
Expand Up @@ -37,7 +37,7 @@ var containerFinalizedButNotCanonical = []byte("recent block needs reindexing to
//
// This method ensures that all blocks from the current finalized epoch are considered "final" while
// maintaining only canonical and finalized blocks older than the current finalized epoch.
func (kv *Store) updateFinalizedBlockRoots(ctx context.Context, tx *bolt.Tx, checkpoint *ethpb.Checkpoint) error {
func (k *Store) updateFinalizedBlockRoots(ctx context.Context, tx *bolt.Tx, checkpoint *ethpb.Checkpoint) error {
ctx, span := trace.StartSpan(ctx, "BeaconDB.updateFinalizedBlockRoots")
defer span.End()

Expand All @@ -48,15 +48,15 @@ func (kv *Store) updateFinalizedBlockRoots(ctx context.Context, tx *bolt.Tx, che
genesisRoot := tx.Bucket(blocksBucket).Get(genesisBlockRootKey)

// De-index recent finalized block roots, to be re-indexed.
prevousFinalizedCheckpoint := &ethpb.Checkpoint{}
previousFinalizedCheckpoint := &ethpb.Checkpoint{}
if b := bkt.Get(previousFinalizedCheckpointKey); b != nil {
if err := decode(b, prevousFinalizedCheckpoint); err != nil {
if err := decode(b, previousFinalizedCheckpoint); err != nil {
traceutil.AnnotateError(span, err)
return err
}
}
blockRoots, err := kv.BlockRoots(ctx, filters.NewFilter().
SetStartEpoch(prevousFinalizedCheckpoint.Epoch).
blockRoots, err := k.BlockRoots(ctx, filters.NewFilter().
SetStartEpoch(previousFinalizedCheckpoint.Epoch).
SetEndEpoch(checkpoint.Epoch+1),
)
if err != nil {
Expand All @@ -77,7 +77,7 @@ func (kv *Store) updateFinalizedBlockRoots(ctx context.Context, tx *bolt.Tx, che
break
}

signedBlock, err := kv.Block(ctx, bytesutil.ToBytes32(root))
signedBlock, err := k.Block(ctx, bytesutil.ToBytes32(root))
if err != nil {
traceutil.AnnotateError(span, err)
return err
Expand Down Expand Up @@ -128,7 +128,7 @@ func (kv *Store) updateFinalizedBlockRoots(ctx context.Context, tx *bolt.Tx, che
}

// Upsert blocks from the current finalized epoch.
roots, err := kv.BlockRoots(ctx, filters.NewFilter().SetStartEpoch(checkpoint.Epoch).SetEndEpoch(checkpoint.Epoch+1))
roots, err := k.BlockRoots(ctx, filters.NewFilter().SetStartEpoch(checkpoint.Epoch).SetEndEpoch(checkpoint.Epoch+1))
if err != nil {
traceutil.AnnotateError(span, err)
return err
Expand Down Expand Up @@ -158,12 +158,12 @@ func (kv *Store) updateFinalizedBlockRoots(ctx context.Context, tx *bolt.Tx, che
// A beacon block root contained exists in this index if it is considered finalized and canonical.
// Note: beacon blocks from the latest finalized epoch return true, whether or not they are
// considered canonical in the "head view" of the beacon node.
func (kv *Store) IsFinalizedBlock(ctx context.Context, blockRoot [32]byte) bool {
func (k *Store) IsFinalizedBlock(ctx context.Context, blockRoot [32]byte) bool {
ctx, span := trace.StartSpan(ctx, "BeaconDB.IsFinalizedBlock")
defer span.End()

var exists bool
err := kv.db.View(func(tx *bolt.Tx) error {
err := k.db.View(func(tx *bolt.Tx) error {
exists = tx.Bucket(finalizedBlockRootsIndexBucket).Get(blockRoot[:]) != nil
return nil
})
Expand Down
16 changes: 8 additions & 8 deletions beacon-chain/db/kv/prune_states.go
Expand Up @@ -12,10 +12,10 @@ import (

var pruneStatesKey = []byte("prune-states")

func (kv *Store) pruneStates(ctx context.Context) error {
func (k *Store) pruneStates(ctx context.Context) error {
var pruned bool

kv.db.View(func(tx *bolt.Tx) error {
k.db.View(func(tx *bolt.Tx) error {
bkt := tx.Bucket(migrationBucket)
v := bkt.Get(pruneStatesKey)
pruned = len(v) == 1 && v[0] == 0x01
Expand All @@ -29,16 +29,16 @@ func (kv *Store) pruneStates(ctx context.Context) error {
log := logrus.WithField("prefix", "kv")
log.Info("Pruning states before last finalized check point. This might take a while...")

roots, err := kv.rootsToPrune(ctx)
roots, err := k.rootsToPrune(ctx)
if err != nil {
return err
}

if err := kv.DeleteStates(ctx, roots); err != nil {
if err := k.DeleteStates(ctx, roots); err != nil {
return err
}

return kv.db.Update(func(tx *bolt.Tx) error {
return k.db.Update(func(tx *bolt.Tx) error {
bkt := tx.Bucket(migrationBucket)
return bkt.Put(pruneStatesKey, []byte{0x01})
})
Expand All @@ -48,13 +48,13 @@ func (kv *Store) pruneStates(ctx context.Context) error {
// * Get last finalized check point
// * Rewind end slot until it's not finalized root
// * return roots between slot 1 and end slot
func (kv *Store) rootsToPrune(ctx context.Context) ([][32]byte, error) {
cp, err := kv.FinalizedCheckpoint(ctx)
func (k *Store) rootsToPrune(ctx context.Context) ([][32]byte, error) {
cp, err := k.FinalizedCheckpoint(ctx)
if err != nil {
return nil, err
}
f := filters.NewFilter().SetStartSlot(1).SetEndSlot(helpers.StartSlot(cp.Epoch))
roots, err := kv.BlockRoots(ctx, f)
roots, err := k.BlockRoots(ctx, f)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/p2p/connmgr/connmgr.go
Expand Up @@ -84,7 +84,7 @@ type segment struct {
type segments [256]*segment

func (ss *segments) get(p peer.ID) *segment {
return ss[byte(p[len(p)-1])]
return ss[p[len(p)-1]]
}

func (ss *segments) countPeers() (count int) {
Expand Down
16 changes: 8 additions & 8 deletions beacon-chain/p2p/connmgr/connmgr_test.go
Expand Up @@ -103,7 +103,7 @@ func TestConnsToClose(t *testing.T) {
t.Fatal("expected no connections")
}

cm = NewConnManager(1, 1, time.Duration(10*time.Minute))
cm = NewConnManager(1, 1, 10*time.Minute)
not := cm.Notifee()
for i := 0; i < 5; i++ {
conn := randConn(t, nil)
Expand All @@ -117,7 +117,7 @@ func TestConnsToClose(t *testing.T) {

func TestGetTagInfo(t *testing.T) {
start := time.Now()
cm := NewConnManager(1, 1, time.Duration(10*time.Minute))
cm := NewConnManager(1, 1, 10*time.Minute)
not := cm.Notifee()
conn := randConn(t, nil)
not.Connected(nil, conn)
Expand Down Expand Up @@ -187,7 +187,7 @@ func TestGetTagInfo(t *testing.T) {
}

func TestTagPeerNonExistant(t *testing.T) {
cm := NewConnManager(1, 1, time.Duration(10*time.Minute))
cm := NewConnManager(1, 1, 10*time.Minute)

id := tu.RandPeerIDFatal(t)
cm.TagPeer(id, "test", 1)
Expand All @@ -198,7 +198,7 @@ func TestTagPeerNonExistant(t *testing.T) {
}

func TestUntagPeer(t *testing.T) {
cm := NewConnManager(1, 1, time.Duration(10*time.Minute))
cm := NewConnManager(1, 1, 10*time.Minute)
not := cm.Notifee()
conn := randConn(t, nil)
not.Connected(nil, conn)
Expand Down Expand Up @@ -228,7 +228,7 @@ func TestUntagPeer(t *testing.T) {

func TestGetInfo(t *testing.T) {
start := time.Now()
gp := time.Duration(10 * time.Minute)
gp := 10 * time.Minute
cm := NewConnManager(1, 5, gp)
not := cm.Notifee()
conn := randConn(t, nil)
Expand All @@ -255,7 +255,7 @@ func TestGetInfo(t *testing.T) {
}

func TestDoubleConnection(t *testing.T) {
gp := time.Duration(10 * time.Minute)
gp := 10 * time.Minute
cm := NewConnManager(1, 5, gp)
not := cm.Notifee()
conn := randConn(t, nil)
Expand All @@ -271,7 +271,7 @@ func TestDoubleConnection(t *testing.T) {
}

func TestDisconnected(t *testing.T) {
gp := time.Duration(10 * time.Minute)
gp := 10 * time.Minute
cm := NewConnManager(1, 5, gp)
not := cm.Notifee()
conn := randConn(t, nil)
Expand Down Expand Up @@ -605,7 +605,7 @@ func TestPeerProtectionIdempotent(t *testing.T) {
}

func TestUpsertTag(t *testing.T) {
cm := NewConnManager(1, 1, time.Duration(10*time.Minute))
cm := NewConnManager(1, 1, 10*time.Minute)
not := cm.Notifee()
conn := randConn(t, nil)
rp := conn.RemotePeer()
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/p2p/discovery_test.go
Expand Up @@ -55,7 +55,7 @@ func TestCreateListener(t *testing.T) {
t.Errorf("Ip address is not the expected type, wanted %s but got %s", ipAddr.String(), listener.Self().IP().String())
}

if port != int(listener.Self().UDP()) {
if port != listener.Self().UDP() {
t.Errorf("In correct port number, wanted %d but got %d", port, listener.Self().UDP())
}
pubkey := listener.Self().Pubkey()
Expand Down
5 changes: 2 additions & 3 deletions beacon-chain/p2p/service.go
Expand Up @@ -30,7 +30,6 @@ import (
var _ = shared.Service(&Service{})

var pollingPeriod = 1 * time.Second
var ttl = 1 * time.Hour

const prysmProtocolPrefix = "/prysm/0.0.0"

Expand Down Expand Up @@ -94,7 +93,7 @@ func NewService(cfg *Config) (*Service, error) {
dopts := []dhtopts.Option{
dhtopts.Datastore(dsync.MutexWrap(ds.NewMapDatastore())),
dhtopts.Protocols(
protocol.ID(prysmProtocolPrefix + "/dht"),
prysmProtocolPrefix + "/dht",
),
}

Expand Down Expand Up @@ -189,7 +188,7 @@ func (s *Service) Start() {
s.host.ConnManager().Protect(peer.ID, "bootnode")
}
bcfg := kaddht.DefaultBootstrapConfig
bcfg.Period = time.Duration(30 * time.Second)
bcfg.Period = 30 * time.Second
if err := s.dht.BootstrapWithConfig(s.ctx, bcfg); err != nil {
log.WithError(err).Error("Failed to bootstrap DHT")
}
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/powchain/deposit_test.go
Expand Up @@ -108,7 +108,7 @@ func TestProcessDeposit_InvalidPublicKey(t *testing.T) {
if err != nil {
log.Error(err)
}
deposits[0].Proof, err = trie.MerkleProof((0))
deposits[0].Proof, err = trie.MerkleProof(0)
if err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/rpc/beacon/validators.go
Expand Up @@ -591,6 +591,6 @@ func (bs *Server) GetValidatorPerformance(
AverageActiveValidatorBalance: avgBalance,
MissingValidators: missingValidators,
TotalValidators: uint64(len(headState.Validators)),
TotalActiveValidators: uint64(activeCount),
TotalActiveValidators: activeCount,
}, nil
}
2 changes: 1 addition & 1 deletion beacon-chain/rpc/validator/proposer.go
Expand Up @@ -64,7 +64,7 @@ func (vs *Server) GetBlock(ctx context.Context, req *ethpb.BlockRequest) (*ethpb
// Use zero hash as stub for state root to compute later.
stateRoot := params.BeaconConfig().ZeroHash[:]

graffiti := bytesutil.ToBytes32([]byte(req.Graffiti))
graffiti := bytesutil.ToBytes32(req.Graffiti)

blk := &ethpb.BeaconBlock{
Slot: req.Slot,
Expand Down
1 change: 0 additions & 1 deletion beacon-chain/sync/BUILD.bazel
Expand Up @@ -117,7 +117,6 @@ go_test(
"@com_github_gogo_protobuf//proto:go_default_library",
"@com_github_libp2p_go_libp2p_core//:go_default_library",
"@com_github_libp2p_go_libp2p_core//network:go_default_library",
"@com_github_libp2p_go_libp2p_core//peer:go_default_library",
"@com_github_libp2p_go_libp2p_core//protocol:go_default_library",
"@com_github_libp2p_go_libp2p_pubsub//:go_default_library",
"@com_github_libp2p_go_libp2p_pubsub//pb:go_default_library",
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/sync/error.go
Expand Up @@ -43,5 +43,5 @@ func ReadStatusCode(stream io.Reader, encoding encoder.NetworkEncoding) (uint8,
return 0, "", err
}

return uint8(b[0]), string(msg), nil
return b[0], string(msg), nil
}

0 comments on commit b30a7d1

Please sign in to comment.