Skip to content

Commit

Permalink
Rename getter functions to be idiomatic (#8320)
Browse files Browse the repository at this point in the history
* Rename getter functions

* Rename new

* Radek's feedback

Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
  • Loading branch information
terencechain and prylabs-bulldozer[bot] committed Jan 25, 2021
1 parent b2d6012 commit d5ec248
Show file tree
Hide file tree
Showing 59 changed files with 143 additions and 143 deletions.
2 changes: 1 addition & 1 deletion beacon-chain/blockchain/receive_attestation.go
Expand Up @@ -118,7 +118,7 @@ func (s *Service) processAttestationsRoutine(subscribedToStateEvents chan struct
log.Warn("Genesis time received, now available to process attestations")
}

st := slotutil.GetSlotTicker(s.genesisTime, params.BeaconConfig().SecondsPerSlot)
st := slotutil.NewSlotTicker(s.genesisTime, params.BeaconConfig().SecondsPerSlot)
for {
select {
case <-s.ctx.Done():
Expand Down
8 changes: 4 additions & 4 deletions beacon-chain/core/blocks/signature.go
Expand Up @@ -15,7 +15,7 @@ import (
)

// retrieves the signature set from the raw data, public key,signature and domain provided.
func retrieveSignatureSet(signedData, pub, signature, domain []byte) (*bls.SignatureSet, error) {
func signatureSet(signedData, pub, signature, domain []byte) (*bls.SignatureSet, error) {
publicKey, err := bls.PublicKeyFromBytes(pub)
if err != nil {
return nil, errors.Wrap(err, "could not convert bytes to public key")
Expand All @@ -37,7 +37,7 @@ func retrieveSignatureSet(signedData, pub, signature, domain []byte) (*bls.Signa

// verifies the signature from the raw data, public key and domain provided.
func verifySignature(signedData, pub, signature, domain []byte) error {
set, err := retrieveSignatureSet(signedData, pub, signature, domain)
set, err := signatureSet(signedData, pub, signature, domain)
if err != nil {
return err
}
Expand Down Expand Up @@ -85,7 +85,7 @@ func BlockSignatureSet(beaconState *stateTrie.BeaconState, block *ethpb.SignedBe
return nil, err
}
proposerPubKey := proposer.PublicKey
return helpers.RetrieveBlockSignatureSet(block.Block, proposerPubKey, block.Signature, domain)
return helpers.BlockSignatureSet(block.Block, proposerPubKey, block.Signature, domain)
}

// RandaoSignatureSet retrieves the relevant randao specific signature set object
Expand All @@ -97,7 +97,7 @@ func RandaoSignatureSet(beaconState *stateTrie.BeaconState,
if err != nil {
return nil, err
}
set, err := retrieveSignatureSet(buf, proposerPub, body.RandaoReveal, domain)
set, err := signatureSet(buf, proposerPub, body.RandaoReveal, domain)
if err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions beacon-chain/core/helpers/signing_root.go
Expand Up @@ -98,7 +98,7 @@ func VerifySigningRoot(obj fssz.HashRoot, pub, signature, domain []byte) error {

// VerifyBlockSigningRoot verifies the signing root of a block given it's public key, signature and domain.
func VerifyBlockSigningRoot(blk *ethpb.BeaconBlock, pub, signature, domain []byte) error {
set, err := RetrieveBlockSignatureSet(blk, pub, signature, domain)
set, err := BlockSignatureSet(blk, pub, signature, domain)
if err != nil {
return err
}
Expand All @@ -117,9 +117,9 @@ func VerifyBlockSigningRoot(blk *ethpb.BeaconBlock, pub, signature, domain []byt
return nil
}

// RetrieveBlockSignatureSet retrieves the relevant signature, message and pubkey data from a block and collating it
// BlockSignatureSet retrieves the relevant signature, message and pubkey data from a block and collating it
// into a signature set object.
func RetrieveBlockSignatureSet(blk *ethpb.BeaconBlock, pub, signature, domain []byte) (*bls.SignatureSet, error) {
func BlockSignatureSet(blk *ethpb.BeaconBlock, pub, signature, domain []byte) (*bls.SignatureSet, error) {
publicKey, err := bls.PublicKeyFromBytes(pub)
if err != nil {
return nil, errors.Wrap(err, "could not convert bytes to public key")
Expand Down
28 changes: 14 additions & 14 deletions beacon-chain/db/kv/blocks.go
Expand Up @@ -71,7 +71,7 @@ func (s *Store) Blocks(ctx context.Context, f *filters.QueryFilter) ([]*ethpb.Si
err := s.db.View(func(tx *bolt.Tx) error {
bkt := tx.Bucket(blocksBucket)

keys, err := getBlockRootsByFilter(ctx, tx, f)
keys, err := blockRootsByFilter(ctx, tx, f)
if err != nil {
return err
}
Expand Down Expand Up @@ -100,7 +100,7 @@ func (s *Store) BlockRoots(ctx context.Context, f *filters.QueryFilter) ([][32]b
defer span.End()
blockRoots := make([][32]byte, 0)
err := s.db.View(func(tx *bolt.Tx) error {
keys, err := getBlockRootsByFilter(ctx, tx, f)
keys, err := blockRootsByFilter(ctx, tx, f)
if err != nil {
return err
}
Expand Down Expand Up @@ -143,7 +143,7 @@ func (s *Store) BlocksBySlot(ctx context.Context, slot uint64) (bool, []*ethpb.S
err := s.db.View(func(tx *bolt.Tx) error {
bkt := tx.Bucket(blocksBucket)

keys, err := getBlockRootsBySlot(ctx, tx, slot)
keys, err := blockRootsBySlot(ctx, tx, slot)
if err != nil {
return err
}
Expand All @@ -167,7 +167,7 @@ func (s *Store) BlockRootsBySlot(ctx context.Context, slot uint64) (bool, [][32]
defer span.End()
blockRoots := make([][32]byte, 0)
err := s.db.View(func(tx *bolt.Tx) error {
keys, err := getBlockRootsBySlot(ctx, tx, slot)
keys, err := blockRootsBySlot(ctx, tx, slot)
if err != nil {
return err
}
Expand Down Expand Up @@ -374,9 +374,9 @@ func (s *Store) HighestSlotBlocksBelow(ctx context.Context, slot uint64) ([]*eth
return []*ethpb.SignedBeaconBlock{blk}, nil
}

// getBlockRootsByFilter retrieves the block roots given the filter criteria.
func getBlockRootsByFilter(ctx context.Context, tx *bolt.Tx, f *filters.QueryFilter) ([][]byte, error) {
ctx, span := trace.StartSpan(ctx, "BeaconDB.getBlockRootsByFilter")
// blockRootsByFilter retrieves the block roots given the filter criteria.
func blockRootsByFilter(ctx context.Context, tx *bolt.Tx, f *filters.QueryFilter) ([][]byte, error) {
ctx, span := trace.StartSpan(ctx, "BeaconDB.blockRootsByFilter")
defer span.End()

// If no filter criteria are specified, return an error.
Expand All @@ -394,7 +394,7 @@ func getBlockRootsByFilter(ctx context.Context, tx *bolt.Tx, f *filters.QueryFil

// We retrieve block roots that match a filter criteria of slot ranges, if specified.
filtersMap := f.Filters()
rootsBySlotRange, err := fetchBlockRootsBySlotRange(
rootsBySlotRange, err := blockRootsBySlotRange(
ctx,
tx.Bucket(blockSlotIndicesBucket),
filtersMap[filters.StartSlot],
Expand Down Expand Up @@ -431,15 +431,15 @@ func getBlockRootsByFilter(ctx context.Context, tx *bolt.Tx, f *filters.QueryFil
return keys, nil
}

// fetchBlockRootsBySlotRange looks into a boltDB bucket and performs a binary search
// blockRootsBySlotRange looks into a boltDB bucket and performs a binary search
// range scan using sorted left-padded byte keys using a start slot and an end slot.
// However, if step is one, the implemented logic won’t skip half of the slots in the range.
func fetchBlockRootsBySlotRange(
func blockRootsBySlotRange(
ctx context.Context,
bkt *bolt.Bucket,
startSlotEncoded, endSlotEncoded, startEpochEncoded, endEpochEncoded, slotStepEncoded interface{},
) ([][]byte, error) {
ctx, span := trace.StartSpan(ctx, "BeaconDB.fetchBlockRootsBySlotRange")
ctx, span := trace.StartSpan(ctx, "BeaconDB.blockRootsBySlotRange")
defer span.End()

// Return nothing when all slot parameters are missing
Expand Down Expand Up @@ -501,9 +501,9 @@ func fetchBlockRootsBySlotRange(
return roots, nil
}

// getBlockRootsByFilter retrieves the block roots by slot
func getBlockRootsBySlot(ctx context.Context, tx *bolt.Tx, slot uint64) ([][]byte, error) {
ctx, span := trace.StartSpan(ctx, "BeaconDB.getBlockRootsBySlot")
// blockRootsBySlot retrieves the block roots by slot
func blockRootsBySlot(ctx context.Context, tx *bolt.Tx, slot uint64) ([][]byte, error) {
ctx, span := trace.StartSpan(ctx, "BeaconDB.blockRootsBySlot")
defer span.End()

roots := make([][]byte, 0)
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/main.go
Expand Up @@ -117,7 +117,7 @@ func main() {
app.Name = "beacon-chain"
app.Usage = "this is a beacon chain implementation for Ethereum 2.0"
app.Action = startNode
app.Version = version.GetVersion()
app.Version = version.Version()
app.Commands = []*cli.Command{
db.DatabaseCommands,
}
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/node/node.go
Expand Up @@ -242,7 +242,7 @@ func (b *BeaconNode) Start() {
b.lock.Lock()

log.WithFields(logrus.Fields{
"version": version.GetVersion(),
"version": version.Version(),
}).Info("Starting beacon node")

b.services.StartAll()
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/p2p/discovery.go
Expand Up @@ -44,7 +44,7 @@ func (s *Service) RefreshENR() {
for _, idx := range committees {
bitV.SetBitAt(idx, true)
}
currentBitV, err := retrieveBitvector(s.dv5Listener.Self().Record())
currentBitV, err := bitvector(s.dv5Listener.Self().Record())
if err != nil {
log.Errorf("Could not retrieve bitfield: %v", err)
return
Expand Down
6 changes: 3 additions & 3 deletions beacon-chain/p2p/fork.go
Expand Up @@ -36,11 +36,11 @@ func (s *Service) forkDigest() ([4]byte, error) {
// local record values for current and next fork version/epoch.
func (s *Service) compareForkENR(record *enr.Record) error {
currentRecord := s.dv5Listener.LocalNode().Node().Record()
peerForkENR, err := retrieveForkEntry(record)
peerForkENR, err := forkEntry(record)
if err != nil {
return err
}
currentForkENR, err := retrieveForkEntry(currentRecord)
currentForkENR, err := forkEntry(currentRecord)
if err != nil {
return err
}
Expand Down Expand Up @@ -124,7 +124,7 @@ func addForkEntry(

// Retrieves an enrForkID from an ENR record by key lookup
// under the eth2EnrKey.
func retrieveForkEntry(record *enr.Record) (*pb.ENRForkID, error) {
func forkEntry(record *enr.Record) (*pb.ENRForkID, error) {
sszEncodedForkEntry := make([]byte, 16)
entry := enr.WithEntry(eth2ENRKey, &sszEncodedForkEntry)
err := record.Load(entry)
Expand Down
8 changes: 4 additions & 4 deletions beacon-chain/p2p/fork_test.go
Expand Up @@ -229,7 +229,7 @@ func TestDiscv5_AddRetrieveForkEntryENR(t *testing.T) {
}
enc, err := enrForkID.MarshalSSZ()
require.NoError(t, err)
forkEntry := enr.WithEntry(eth2ENRKey, enc)
entry := enr.WithEntry(eth2ENRKey, enc)
// In epoch 1 of current time, the fork version should be
// {0, 0, 0, 1} according to the configuration override above.
temp := t.TempDir()
Expand All @@ -241,12 +241,12 @@ func TestDiscv5_AddRetrieveForkEntryENR(t *testing.T) {
db, err := enode.OpenDB("")
require.NoError(t, err)
localNode := enode.NewLocalNode(db, pkey)
localNode.Set(forkEntry)
localNode.Set(entry)

want, err := helpers.ComputeForkDigest([]byte{0, 0, 0, 0}, genesisValidatorsRoot)
require.NoError(t, err)

resp, err := retrieveForkEntry(localNode.Node().Record())
resp, err := forkEntry(localNode.Node().Record())
require.NoError(t, err)
assert.DeepEqual(t, want[:], resp.CurrentForkDigest)
assert.DeepEqual(t, nextForkVersion, resp.NextForkVersion)
Expand All @@ -266,7 +266,7 @@ func TestAddForkEntry_Genesis(t *testing.T) {
localNode := enode.NewLocalNode(db, pkey)
localNode, err = addForkEntry(localNode, time.Now().Add(10*time.Second), bytesutil.PadTo([]byte{'A', 'B', 'C', 'D'}, 32))
require.NoError(t, err)
forkEntry, err := retrieveForkEntry(localNode.Node().Record())
forkEntry, err := forkEntry(localNode.Node().Record())
require.NoError(t, err)
assert.DeepEqual(t,
params.BeaconConfig().GenesisForkVersion, forkEntry.NextForkVersion,
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/p2p/options.go
Expand Up @@ -32,7 +32,7 @@ func (s *Service) buildOptions(ip net.IP, priKey *ecdsa.PrivateKey) []libp2p.Opt
options := []libp2p.Option{
privKeyOption(priKey),
libp2p.ListenAddrs(listen),
libp2p.UserAgent(version.GetBuildData()),
libp2p.UserAgent(version.BuildData()),
libp2p.ConnectionGater(s),
}

Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/p2p/peers/benchmark_test.go
Expand Up @@ -13,6 +13,6 @@ func Benchmark_retrieveIndicesFromBitfield(b *testing.B) {
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
retrieveIndicesFromBitfield(bv)
indicesFromBitfield(bv)
}
}
6 changes: 3 additions & 3 deletions beacon-chain/p2p/peers/status.go
Expand Up @@ -237,7 +237,7 @@ func (p *Status) CommitteeIndices(pid peer.ID) ([]uint64, error) {
if peerData.Enr == nil || peerData.MetaData == nil {
return []uint64{}, nil
}
return retrieveIndicesFromBitfield(peerData.MetaData.Attnets), nil
return indicesFromBitfield(peerData.MetaData.Attnets), nil
}
return nil, peerdata.ErrPeerUnknown
}
Expand All @@ -253,7 +253,7 @@ func (p *Status) SubscribedToSubnet(index uint64) []peer.ID {
// look at active peers
connectedStatus := peerData.ConnState == PeerConnecting || peerData.ConnState == PeerConnected
if connectedStatus && peerData.MetaData != nil && peerData.MetaData.Attnets != nil {
indices := retrieveIndicesFromBitfield(peerData.MetaData.Attnets)
indices := indicesFromBitfield(peerData.MetaData.Attnets)
for _, idx := range indices {
if idx == index {
peers = append(peers, pid)
Expand Down Expand Up @@ -796,7 +796,7 @@ func sameIP(firstAddr, secondAddr ma.Multiaddr) bool {
return firstIP.Equal(secondIP)
}

func retrieveIndicesFromBitfield(bitV bitfield.Bitvector64) []uint64 {
func indicesFromBitfield(bitV bitfield.Bitvector64) []uint64 {
committeeIdxs := make([]uint64, 0, bitV.Count())
for i := uint64(0); i < 64; i++ {
if bitV.BitAt(i) {
Expand Down
8 changes: 4 additions & 4 deletions beacon-chain/p2p/subnets.go
Expand Up @@ -73,7 +73,7 @@ func (s *Service) filterPeerForSubnet(index uint64) func(node *enode.Node) bool
if !s.filterPeer(node) {
return false
}
subnets, err := retrieveAttSubnets(node.Record())
subnets, err := attSubnets(node.Record())
if err != nil {
return false
}
Expand Down Expand Up @@ -119,8 +119,8 @@ func intializeAttSubnets(node *enode.LocalNode) *enode.LocalNode {

// Reads the attestation subnets entry from a node's ENR and determines
// the committee indices of the attestation subnets the node is subscribed to.
func retrieveAttSubnets(record *enr.Record) ([]uint64, error) {
bitV, err := retrieveBitvector(record)
func attSubnets(record *enr.Record) ([]uint64, error) {
bitV, err := bitvector(record)
if err != nil {
return nil, err
}
Expand All @@ -135,7 +135,7 @@ func retrieveAttSubnets(record *enr.Record) ([]uint64, error) {

// Parses the attestation subnets ENR entry in a node and extracts its value
// as a bitvector for further manipulation.
func retrieveBitvector(record *enr.Record) (bitfield.Bitvector64, error) {
func bitvector(record *enr.Record) (bitfield.Bitvector64, error) {
bitV := bitfield.NewBitvector64()
entry := enr.WithEntry(attSubnetEnrKey, &bitV)
err := record.Load(entry)
Expand Down
4 changes: 2 additions & 2 deletions beacon-chain/p2p/utils.go
Expand Up @@ -87,11 +87,11 @@ func privKey(cfg *Config) (*ecdsa.PrivateKey, error) {
if defaultKeysExist && privateKeyPath == "" {
privateKeyPath = defaultKeyPath
}
return retrievePrivKeyFromFile(privateKeyPath)
return privKeyFromFile(privateKeyPath)
}

// Retrieves a p2p networking private key from a file path.
func retrievePrivKeyFromFile(path string) (*ecdsa.PrivateKey, error) {
func privKeyFromFile(path string) (*ecdsa.PrivateKey, error) {
src, err := ioutil.ReadFile(path)
if err != nil {
log.WithError(err).Error("Error reading private key from file")
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/rpc/beacon/attestations.go
Expand Up @@ -334,7 +334,7 @@ func (bs *Server) StreamIndexedAttestations(
func (bs *Server) collectReceivedAttestations(ctx context.Context) {
attsByRoot := make(map[[32]byte][]*ethpb.Attestation)
twoThirdsASlot := 2 * slotutil.DivideSlotBy(3) /* 2/3 slot duration */
ticker := slotutil.GetSlotTickerWithOffset(bs.GenesisTimeFetcher.GenesisTime(), twoThirdsASlot, params.BeaconConfig().SecondsPerSlot)
ticker := slotutil.NewSlotTickerWithOffset(bs.GenesisTimeFetcher.GenesisTime(), twoThirdsASlot, params.BeaconConfig().SecondsPerSlot)
for {
select {
case <-ticker.C():
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/rpc/node/server.go
Expand Up @@ -79,7 +79,7 @@ func (ns *Server) GetGenesis(ctx context.Context, _ *ptypes.Empty) (*ethpb.Genes
// GetVersion checks the version information of the beacon node.
func (ns *Server) GetVersion(_ context.Context, _ *ptypes.Empty) (*ethpb.Version, error) {
return &ethpb.Version{
Version: version.GetVersion(),
Version: version.Version(),
}, nil
}

Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/rpc/node/server_test.go
Expand Up @@ -71,7 +71,7 @@ func TestNodeServer_GetGenesis(t *testing.T) {
}

func TestNodeServer_GetVersion(t *testing.T) {
v := version.GetVersion()
v := version.Version()
ns := &Server{}
res, err := ns.GetVersion(context.Background(), &ptypes.Empty{})
require.NoError(t, err)
Expand Down
4 changes: 2 additions & 2 deletions beacon-chain/rpc/nodev1/node.go
Expand Up @@ -226,10 +226,10 @@ func (ns *Server) PeerCount(ctx context.Context, _ *ptypes.Empty) (*ethpb.PeerCo
// GetVersion requests that the beacon node identify information about its implementation in a
// format similar to a HTTP User-Agent field.
func (ns *Server) GetVersion(ctx context.Context, _ *ptypes.Empty) (*ethpb.VersionResponse, error) {
ctx, span := trace.StartSpan(ctx, "nodev1.GetVersion")
ctx, span := trace.StartSpan(ctx, "nodev1.Version")
defer span.End()

v := fmt.Sprintf("Prysm/%s (%s %s)", version.GetSemanticVersion(), runtime.GOOS, runtime.GOARCH)
v := fmt.Sprintf("Prysm/%s (%s %s)", version.SemanticVersion(), runtime.GOOS, runtime.GOARCH)
return &ethpb.VersionResponse{
Data: &ethpb.Version{
Version: v,
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/rpc/nodev1/node_test.go
Expand Up @@ -35,7 +35,7 @@ func (id dummyIdentity) Verify(_ *enr.Record, _ []byte) error { return nil }
func (id dummyIdentity) NodeAddr(_ *enr.Record) []byte { return id[:] }

func TestGetVersion(t *testing.T) {
semVer := version.GetSemanticVersion()
semVer := version.SemanticVersion()
os := runtime.GOOS
arch := runtime.GOARCH
res, err := (&Server{}).GetVersion(context.Background(), &ptypes.Empty{})
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/rpc/validator/assignments.go
Expand Up @@ -61,7 +61,7 @@ func (vs *Server) StreamDuties(req *ethpb.DutiesRequest, stream ethpb.BeaconNode
defer stateSub.Unsubscribe()

secondsPerEpoch := params.BeaconConfig().SecondsPerSlot * params.BeaconConfig().SlotsPerEpoch
epochTicker := slotutil.GetSlotTicker(vs.TimeFetcher.GenesisTime(), secondsPerEpoch)
epochTicker := slotutil.NewSlotTicker(vs.TimeFetcher.GenesisTime(), secondsPerEpoch)
for {
select {
// Ticks every epoch to submit assignments to connected validator clients.
Expand Down

0 comments on commit d5ec248

Please sign in to comment.