Skip to content

Commit

Permalink
Better naming for constructor funcs (prysmaticlabs#7316)
Browse files Browse the repository at this point in the history
* sync/initial-sync
* NewBeaconClientService -> NewService
* NewSlashingProtectionService -> NewService
* NewPrometheusService -> NewService
* NewColdStartService -> NewService
* NewRegularSync -> NewService
* NewDetectionService -> NewService
* NewWallet -> New
* NewKeystore -> New
* Merge branch 'master' into better-naming
* Merge branch 'master' into better-naming
* NewDepositCache -> New
  • Loading branch information
farazdagi authored Sep 23, 2020
1 parent 49ae42c commit 3621b2f
Show file tree
Hide file tree
Showing 35 changed files with 127 additions and 127 deletions.
2 changes: 1 addition & 1 deletion beacon-chain/blockchain/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func setupBeaconChain(t *testing.T, beaconDB db.Database, sc *cache.StateSummary
opsService, err := attestations.NewService(ctx, &attestations.Config{Pool: attestations.NewPool()})
require.NoError(t, err)

depositCache, err := depositcache.NewDepositCache()
depositCache, err := depositcache.New()
require.NoError(t, err)

cfg := &Config{
Expand Down
4 changes: 2 additions & 2 deletions beacon-chain/cache/depositcache/deposits_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ type DepositCache struct {
chainStartPubkeys map[string]bool
}

// NewDepositCache instantiates a new deposit cache
func NewDepositCache() (*DepositCache, error) {
// New instantiates a new deposit cache
func New() (*DepositCache, error) {
finalizedDepositsTrie, err := trieutil.NewTrie(int(params.BeaconConfig().DepositContractTreeDepth))
if err != nil {
return nil, err
Expand Down
24 changes: 12 additions & 12 deletions beacon-chain/cache/depositcache/deposits_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var _ = DepositFetcher(&DepositCache{})

func TestInsertDeposit_LogsOnNilDepositInsertion(t *testing.T) {
hook := logTest.NewGlobal()
dc, err := NewDepositCache()
dc, err := New()
require.NoError(t, err)

dc.InsertDeposit(context.Background(), nil, 1, 0, [32]byte{})
Expand All @@ -33,7 +33,7 @@ func TestInsertDeposit_LogsOnNilDepositInsertion(t *testing.T) {
}

func TestInsertDeposit_MaintainsSortedOrderByIndex(t *testing.T) {
dc, err := NewDepositCache()
dc, err := New()
require.NoError(t, err)

insertions := []struct {
Expand Down Expand Up @@ -75,7 +75,7 @@ func TestInsertDeposit_MaintainsSortedOrderByIndex(t *testing.T) {
}

func TestAllDeposits_ReturnsAllDeposits(t *testing.T) {
dc, err := NewDepositCache()
dc, err := New()
require.NoError(t, err)

deposits := []*dbpb.DepositContainer{
Expand Down Expand Up @@ -115,7 +115,7 @@ func TestAllDeposits_ReturnsAllDeposits(t *testing.T) {
}

func TestAllDeposits_FiltersDepositUpToAndIncludingBlockNumber(t *testing.T) {
dc, err := NewDepositCache()
dc, err := New()
require.NoError(t, err)

deposits := []*dbpb.DepositContainer{
Expand Down Expand Up @@ -155,7 +155,7 @@ func TestAllDeposits_FiltersDepositUpToAndIncludingBlockNumber(t *testing.T) {
}

func TestDepositsNumberAndRootAtHeight_ReturnsAppropriateCountAndRoot(t *testing.T) {
dc, err := NewDepositCache()
dc, err := New()
require.NoError(t, err)

dc.deposits = []*dbpb.DepositContainer{
Expand Down Expand Up @@ -238,7 +238,7 @@ func TestDepositsNumberAndRootAtHeight_ReturnsAppropriateCountAndRoot(t *testing
}

func TestDepositsNumberAndRootAtHeight_ReturnsEmptyTrieIfBlockHeightLessThanOldestDeposit(t *testing.T) {
dc, err := NewDepositCache()
dc, err := New()
require.NoError(t, err)

dc.deposits = []*dbpb.DepositContainer{
Expand Down Expand Up @@ -272,7 +272,7 @@ func TestDepositsNumberAndRootAtHeight_ReturnsEmptyTrieIfBlockHeightLessThanOlde
}

func TestDepositByPubkey_ReturnsFirstMatchingDeposit(t *testing.T) {
dc, err := NewDepositCache()
dc, err := New()
require.NoError(t, err)

dc.deposits = []*dbpb.DepositContainer{
Expand Down Expand Up @@ -329,7 +329,7 @@ func TestDepositByPubkey_ReturnsFirstMatchingDeposit(t *testing.T) {
}

func TestFinalizedDeposits_DepositsCachedCorrectly(t *testing.T) {
dc, err := NewDepositCache()
dc, err := New()
require.NoError(t, err)

finalizedDeposits := []*dbpb.DepositContainer{
Expand Down Expand Up @@ -393,7 +393,7 @@ func TestFinalizedDeposits_DepositsCachedCorrectly(t *testing.T) {
}

func TestFinalizedDeposits_UtilizesPreviouslyCachedDeposits(t *testing.T) {
dc, err := NewDepositCache()
dc, err := New()
require.NoError(t, err)

oldFinalizedDeposits := []*dbpb.DepositContainer{
Expand Down Expand Up @@ -451,7 +451,7 @@ func TestFinalizedDeposits_UtilizesPreviouslyCachedDeposits(t *testing.T) {
}

func TestFinalizedDeposits_InitializedCorrectly(t *testing.T) {
dc, err := NewDepositCache()
dc, err := New()
require.NoError(t, err)

finalizedDeposits := dc.finalizedDeposits
Expand All @@ -461,7 +461,7 @@ func TestFinalizedDeposits_InitializedCorrectly(t *testing.T) {
}

func TestNonFinalizedDeposits_ReturnsAllNonFinalizedDeposits(t *testing.T) {
dc, err := NewDepositCache()
dc, err := New()
require.NoError(t, err)

finalizedDeposits := []*dbpb.DepositContainer{
Expand Down Expand Up @@ -518,7 +518,7 @@ func TestNonFinalizedDeposits_ReturnsAllNonFinalizedDeposits(t *testing.T) {
}

func TestNonFinalizedDeposits_ReturnsNonFinalizedDepositsUpToBlockNumber(t *testing.T) {
dc, err := NewDepositCache()
dc, err := New()
require.NoError(t, err)

finalizedDeposits := []*dbpb.DepositContainer{
Expand Down
4 changes: 2 additions & 2 deletions beacon-chain/interop-cold-start/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ type Config struct {
GenesisPath string
}

// NewColdStartService is an interoperability testing service to inject a deterministically generated genesis state
// NewService is an interoperability testing service to inject a deterministically generated genesis state
// into the beacon chain database and running services at start up. This service should not be used in production
// as it does not have any value other than ease of use for testing purposes.
func NewColdStartService(ctx context.Context, cfg *Config) *Service {
func NewService(ctx context.Context, cfg *Config) *Service {
log.Warn("Saving generated genesis state in database for interop testing")
ctx, cancel := context.WithCancel(ctx)

Expand Down
12 changes: 6 additions & 6 deletions beacon-chain/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
"github.com/prysmaticlabs/prysm/beacon-chain/powchain"
"github.com/prysmaticlabs/prysm/beacon-chain/rpc"
"github.com/prysmaticlabs/prysm/beacon-chain/state/stategen"
prysmsync "github.com/prysmaticlabs/prysm/beacon-chain/sync"
regularsync "github.com/prysmaticlabs/prysm/beacon-chain/sync"
initialsync "github.com/prysmaticlabs/prysm/beacon-chain/sync/initial-sync"
"github.com/prysmaticlabs/prysm/shared"
"github.com/prysmaticlabs/prysm/shared/cmd"
Expand Down Expand Up @@ -327,7 +327,7 @@ func (b *BeaconNode) startDB(cliCtx *cli.Context) error {

b.db = d

depositCache, err := depositcache.NewDepositCache()
depositCache, err := depositcache.New()
if err != nil {
return errors.Wrap(err, "could not create deposit cache")
}
Expand Down Expand Up @@ -516,7 +516,7 @@ func (b *BeaconNode) registerSyncService() error {
return err
}

rs := prysmsync.NewRegularSync(b.ctx, &prysmsync.Config{
rs := regularsync.NewService(b.ctx, &regularsync.Config{
DB: b.db,
P2P: b.fetchP2P(),
Chain: chainService,
Expand Down Expand Up @@ -546,7 +546,7 @@ func (b *BeaconNode) registerInitialSyncService() error {
return err
}

is := initialsync.NewInitialSync(b.ctx, &initialsync.Config{
is := initialsync.NewService(b.ctx, &initialsync.Config{
DB: b.db,
Chain: chainService,
P2P: b.fetchP2P(),
Expand Down Expand Up @@ -651,7 +651,7 @@ func (b *BeaconNode) registerPrometheusService() error {

additionalHandlers = append(additionalHandlers, prometheus.Handler{Path: "/tree", Handler: c.TreeHandler})

service := prometheus.NewPrometheusService(
service := prometheus.NewService(
fmt.Sprintf("%s:%d", b.cliCtx.String(cmd.MonitoringHostFlag.Name), b.cliCtx.Int(flags.MonitoringPortFlag.Name)),
b.services,
additionalHandlers...,
Expand Down Expand Up @@ -691,7 +691,7 @@ func (b *BeaconNode) registerInteropServices() error {
genesisStatePath := b.cliCtx.String(flags.InteropGenesisStateFlag.Name)

if genesisValidators > 0 || genesisStatePath != "" {
svc := interopcoldstart.NewColdStartService(b.ctx, &interopcoldstart.Config{
svc := interopcoldstart.NewService(b.ctx, &interopcoldstart.Config{
GenesisTime: genesisTime,
NumValidators: genesisValidators,
BeaconDB: b.db,
Expand Down
14 changes: 7 additions & 7 deletions beacon-chain/powchain/log_processing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestProcessDepositLog_OK(t *testing.T) {
require.NoError(t, err, "Unable to set up simulated backend")

beaconDB, _ := testDB.SetupDB(t)
depositCache, err := depositcache.NewDepositCache()
depositCache, err := depositcache.New()
require.NoError(t, err)

web3Service, err := NewService(context.Background(), &Web3ServiceConfig{
Expand Down Expand Up @@ -107,7 +107,7 @@ func TestProcessDepositLog_InsertsPendingDeposit(t *testing.T) {
testAcc, err := contracts.Setup()
require.NoError(t, err, "Unable to set up simulated backend")
beaconDB, _ := testDB.SetupDB(t)
depositCache, err := depositcache.NewDepositCache()
depositCache, err := depositcache.New()
require.NoError(t, err)

web3Service, err := NewService(context.Background(), &Web3ServiceConfig{
Expand Down Expand Up @@ -217,7 +217,7 @@ func TestProcessETH2GenesisLog_8DuplicatePubkeys(t *testing.T) {
testAcc, err := contracts.Setup()
require.NoError(t, err, "Unable to set up simulated backend")
beaconDB, _ := testDB.SetupDB(t)
depositCache, err := depositcache.NewDepositCache()
depositCache, err := depositcache.New()
require.NoError(t, err)

web3Service, err := NewService(context.Background(), &Web3ServiceConfig{
Expand Down Expand Up @@ -288,7 +288,7 @@ func TestProcessETH2GenesisLog(t *testing.T) {
testAcc, err := contracts.Setup()
require.NoError(t, err, "Unable to set up simulated backend")
beaconDB, _ := testDB.SetupDB(t)
depositCache, err := depositcache.NewDepositCache()
depositCache, err := depositcache.New()
require.NoError(t, err)

web3Service, err := NewService(context.Background(), &Web3ServiceConfig{
Expand Down Expand Up @@ -377,7 +377,7 @@ func TestProcessETH2GenesisLog_CorrectNumOfDeposits(t *testing.T) {
testAcc, err := contracts.Setup()
require.NoError(t, err, "Unable to set up simulated backend")
kvStore, _ := testDB.SetupDB(t)
depositCache, err := depositcache.NewDepositCache()
depositCache, err := depositcache.New()
require.NoError(t, err)

web3Service, err := NewService(context.Background(), &Web3ServiceConfig{
Expand Down Expand Up @@ -472,7 +472,7 @@ func TestWeb3ServiceProcessDepositLog_RequestMissedDeposits(t *testing.T) {
testAcc, err := contracts.Setup()
require.NoError(t, err, "Unable to set up simulated backend")
beaconDB, _ := testDB.SetupDB(t)
depositCache, err := depositcache.NewDepositCache()
depositCache, err := depositcache.New()
require.NoError(t, err)

web3Service, err := NewService(context.Background(), &Web3ServiceConfig{
Expand Down Expand Up @@ -624,7 +624,7 @@ func TestCheckForChainstart_NoValidator(t *testing.T) {
}

func newPowchainService(t *testing.T, eth1Backend *contracts.TestAccount, beaconDB db.Database) *Service {
depositCache, err := depositcache.NewDepositCache()
depositCache, err := depositcache.New()
require.NoError(t, err)

web3Service, err := NewService(context.Background(), &Web3ServiceConfig{
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/rpc/validator/assignments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestGetDuties_NextEpoch_CantFindValidatorIdx(t *testing.T) {
chain := &mockChain.ChainService{
State: beaconState, Root: genesisRoot[:], Genesis: time.Now(),
}
depositCache, err := depositcache.NewDepositCache()
depositCache, err := depositcache.New()
require.NoError(t, err)

vs := &Server{
Expand Down
26 changes: 13 additions & 13 deletions beacon-chain/rpc/validator/proposer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ func TestProposer_PendingDeposits_OutsideEth1FollowWindow(t *testing.T) {
},
}

depositCache, err := depositcache.NewDepositCache()
depositCache, err := depositcache.New()
require.NoError(t, err)

depositTrie, err := trieutil.NewTrie(int(params.BeaconConfig().DepositContractTreeDepth))
Expand Down Expand Up @@ -573,7 +573,7 @@ func TestProposer_PendingDeposits_FollowsCorrectEth1Block(t *testing.T) {
},
}

depositCache, err := depositcache.NewDepositCache()
depositCache, err := depositcache.New()
require.NoError(t, err)

depositTrie, err := trieutil.NewTrie(int(params.BeaconConfig().DepositContractTreeDepth))
Expand Down Expand Up @@ -673,7 +673,7 @@ func TestProposer_PendingDeposits_CantReturnBelowStateEth1DepositIndex(t *testin
depositTrie, err := trieutil.NewTrie(int(params.BeaconConfig().DepositContractTreeDepth))
require.NoError(t, err, "Could not setup deposit trie")

depositCache, err := depositcache.NewDepositCache()
depositCache, err := depositcache.New()
require.NoError(t, err)

for _, dp := range append(readyDeposits, recentDeposits...) {
Expand Down Expand Up @@ -769,7 +769,7 @@ func TestProposer_PendingDeposits_CantReturnMoreThanMax(t *testing.T) {
depositTrie, err := trieutil.NewTrie(int(params.BeaconConfig().DepositContractTreeDepth))
require.NoError(t, err, "Could not setup deposit trie")

depositCache, err := depositcache.NewDepositCache()
depositCache, err := depositcache.New()
require.NoError(t, err)

for _, dp := range append(readyDeposits, recentDeposits...) {
Expand Down Expand Up @@ -863,7 +863,7 @@ func TestProposer_PendingDeposits_CantReturnMoreThanDepositCount(t *testing.T) {
depositTrie, err := trieutil.NewTrie(int(params.BeaconConfig().DepositContractTreeDepth))
require.NoError(t, err, "Could not setup deposit trie")

depositCache, err := depositcache.NewDepositCache()
depositCache, err := depositcache.New()
require.NoError(t, err)

for _, dp := range append(readyDeposits, recentDeposits...) {
Expand Down Expand Up @@ -972,7 +972,7 @@ func TestProposer_DepositTrie_UtilizesCachedFinalizedDeposits(t *testing.T) {
},
}

depositCache, err := depositcache.NewDepositCache()
depositCache, err := depositcache.New()
require.NoError(t, err)

depositTrie, err := trieutil.NewTrie(int(params.BeaconConfig().DepositContractTreeDepth))
Expand Down Expand Up @@ -1058,7 +1058,7 @@ func TestProposer_Eth1Data_NoBlockExists(t *testing.T) {
depositTrie, err := trieutil.NewTrie(int(params.BeaconConfig().DepositContractTreeDepth))
require.NoError(t, err, "Could not setup deposit trie")

depositCache, err := depositcache.NewDepositCache()
depositCache, err := depositcache.New()
require.NoError(t, err)

for _, dp := range deps {
Expand Down Expand Up @@ -1113,7 +1113,7 @@ func TestProposer_Eth1Data(t *testing.T) {

headState := testutil.NewBeaconState()
require.NoError(t, headState.SetEth1Data(&ethpb.Eth1Data{DepositCount: 55}))
depositCache, err := depositcache.NewDepositCache()
depositCache, err := depositcache.New()
require.NoError(t, err)

ps := &Server{
Expand Down Expand Up @@ -1157,7 +1157,7 @@ func TestProposer_Eth1Data_SmallerDepositCount(t *testing.T) {
depositTrie, err := trieutil.NewTrie(int(params.BeaconConfig().DepositContractTreeDepth))
require.NoError(t, err, "Could not setup deposit trie")

depositCache, err := depositcache.NewDepositCache()
depositCache, err := depositcache.New()
require.NoError(t, err)

for _, dp := range deps {
Expand Down Expand Up @@ -1250,7 +1250,7 @@ func TestProposer_Eth1Data_MajorityVote(t *testing.T) {
}
depositTrie, err := trieutil.NewTrie(int(params.BeaconConfig().DepositContractTreeDepth))
require.NoError(t, err)
depositCache, err := depositcache.NewDepositCache()
depositCache, err := depositcache.New()
require.NoError(t, err)
depositCache.InsertDeposit(context.Background(), dc.Deposit, dc.Eth1BlockHeight, dc.Index, depositTrie.Root())

Expand Down Expand Up @@ -1767,7 +1767,7 @@ func TestProposer_Eth1Data_MajorityVote(t *testing.T) {
BlockHash: []byte("eth1data"),
}

depositCache, err := depositcache.NewDepositCache()
depositCache, err := depositcache.New()
require.NoError(t, err)

beaconState, err := beaconstate.InitializeFromProto(&pbp2p.BeaconState{
Expand Down Expand Up @@ -1952,7 +1952,7 @@ func Benchmark_Eth1Data(b *testing.B) {
},
}

depositCache, err := depositcache.NewDepositCache()
depositCache, err := depositcache.New()
require.NoError(b, err)

for i, dp := range deposits {
Expand Down Expand Up @@ -2063,7 +2063,7 @@ func TestProposer_Deposits_ReturnsEmptyList_IfLatestEth1DataEqGenesisEth1Block(t
depositTrie, err := trieutil.NewTrie(int(params.BeaconConfig().DepositContractTreeDepth))
require.NoError(t, err, "Could not setup deposit trie")

depositCache, err := depositcache.NewDepositCache()
depositCache, err := depositcache.New()
require.NoError(t, err)

for _, dp := range append(readyDeposits, recentDeposits...) {
Expand Down
Loading

0 comments on commit 3621b2f

Please sign in to comment.