Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

beacon node: renaming functions and services to better reflect what they do #14643

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion beacon-chain/blockchain/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ type config struct {
StateGen *stategen.State
SlasherAttestationsFeed *event.Feed
WeakSubjectivityCheckpt *ethpb.Checkpoint
BlockFetcher execution.POWBlockFetcher
ExecutionBlockFetcher execution.BlockFetcher
FinalizedStateAtStartUp state.BeaconState
ExecutionEngineCaller execution.EngineCaller
SyncChecker Checker
Expand Down
22 changes: 12 additions & 10 deletions beacon-chain/execution/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ type ChainInfoFetcher interface {
ExecutionClientConnectionErr() error
}

// POWBlockFetcher defines a struct that can retrieve mainchain blocks.
type POWBlockFetcher interface {
// BlockFetcher defines a struct that can retrieve mainchain blocks.
type BlockFetcher interface {
BlockTimeByHeight(ctx context.Context, height *big.Int) (uint64, error)
BlockByTimestamp(ctx context.Context, time uint64) (*types.HeaderInfo, error)
BlockHashByHeight(ctx context.Context, height *big.Int) (common.Hash, error)
Expand All @@ -95,7 +95,7 @@ type POWBlockFetcher interface {
type Chain interface {
ChainStartFetcher
ChainInfoFetcher
POWBlockFetcher
BlockFetcher
}

// RPCClient defines the rpc methods required to interact with the eth1 node.
Expand Down Expand Up @@ -206,7 +206,7 @@ func NewService(ctx context.Context, opts ...Option) (*Service, error) {
}
}

eth1Data, err := s.validPowchainData(ctx)
eth1Data, err := s.validExecutionChainData(ctx)
if err != nil {
return nil, errors.Wrap(err, "unable to validate powchain data")
}
Expand Down Expand Up @@ -316,6 +316,7 @@ func (s *Service) updateConnectedETH1(state bool) {
s.updateBeaconNodeStats()
}

// TODO: deprecate sometime after Electra
// refers to the latest eth1 block which follows the condition: eth1_timestamp +
// SECONDS_PER_ETH1_BLOCK * ETH1_FOLLOW_DISTANCE <= current_unix_time
func (s *Service) followedBlockHeight(ctx context.Context) (uint64, error) {
Expand Down Expand Up @@ -460,6 +461,7 @@ func safelyHandlePanic() {
}
}

// TODO: deprecate sometime after Electra
func (s *Service) handleETH1FollowDistance() {
defer safelyHandlePanic()
ctx := s.ctx
Expand Down Expand Up @@ -498,7 +500,7 @@ func (s *Service) handleETH1FollowDistance() {
}
}

func (s *Service) initPOWService() {
func (s *Service) initExecutionChainService() {
// Use a custom logger to only log errors
logCounter := 0
errorLogger := func(err error, msg string) {
Expand Down Expand Up @@ -584,7 +586,7 @@ func (s *Service) initPOWService() {
func (s *Service) run(done <-chan struct{}) {
s.runError = nil

s.initPOWService()
s.initExecutionChainService()
// Do not keep storing the finalized state as it is
// no longer of use.
s.removeStartupState()
Expand Down Expand Up @@ -810,9 +812,9 @@ func validateDepositContainers(ctrs []*ethpb.DepositContainer) bool {
return true
}

// Validates the current powchain data is saved and makes sure that any
// Validates the current execution chain data is saved and makes sure that any
// embedded genesis state is correctly accounted for.
func (s *Service) validPowchainData(ctx context.Context) (*ethpb.ETH1ChainData, error) {
func (s *Service) validExecutionChainData(ctx context.Context) (*ethpb.ETH1ChainData, error) {
genState, err := s.cfg.beaconDB.GenesisState(ctx)
if err != nil {
return nil, err
Expand Down Expand Up @@ -842,11 +844,11 @@ func (s *Service) validPowchainData(ctx context.Context) (*ethpb.ETH1ChainData,
BeaconState: pbState,
DepositContainers: s.cfg.depositCache.AllDepositContainers(ctx),
}
trie, ok := s.depositTrie.(*depositsnapshot.DepositTree)
depositTrie, ok := s.depositTrie.(*depositsnapshot.DepositTree)
if !ok {
return nil, errors.New("deposit trie was not EIP4881 DepositTree")
}
eth1Data.DepositSnapshot, err = trie.ToProto()
eth1Data.DepositSnapshot, err = depositTrie.ToProto()
if err != nil {
return nil, err
}
Expand Down
8 changes: 4 additions & 4 deletions beacon-chain/execution/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import (

var _ ChainStartFetcher = (*Service)(nil)
var _ ChainInfoFetcher = (*Service)(nil)
var _ POWBlockFetcher = (*Service)(nil)
var _ BlockFetcher = (*Service)(nil)
var _ Chain = (*Service)(nil)

type goodLogger struct {
Expand Down Expand Up @@ -580,7 +580,7 @@ func TestService_EnsureConsistentPowchainData(t *testing.T) {
assert.NoError(t, genState.SetSlot(1000))

require.NoError(t, s1.cfg.beaconDB.SaveGenesisData(context.Background(), genState))
_, err = s1.validPowchainData(context.Background())
_, err = s1.validExecutionChainData(context.Background())
require.NoError(t, err)

eth1Data, err := s1.cfg.beaconDB.ExecutionChainData(context.Background())
Expand Down Expand Up @@ -611,7 +611,7 @@ func TestService_InitializeCorrectly(t *testing.T) {
assert.NoError(t, genState.SetSlot(1000))

require.NoError(t, s1.cfg.beaconDB.SaveGenesisData(context.Background(), genState))
_, err = s1.validPowchainData(context.Background())
_, err = s1.validExecutionChainData(context.Background())
require.NoError(t, err)

eth1Data, err := s1.cfg.beaconDB.ExecutionChainData(context.Background())
Expand Down Expand Up @@ -647,7 +647,7 @@ func TestService_EnsureValidPowchainData(t *testing.T) {
DepositContainers: []*ethpb.DepositContainer{{Index: 1}},
})
require.NoError(t, err)
_, err = s1.validPowchainData(context.Background())
_, err = s1.validExecutionChainData(context.Background())
require.NoError(t, err)

eth1Data, err := s1.cfg.beaconDB.ExecutionChainData(context.Background())
Expand Down
41 changes: 21 additions & 20 deletions beacon-chain/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,8 @@ func registerServices(cliCtx *cli.Context, beacon *BeaconNode, synchronizer *sta
return errors.Wrap(err, "could not register backfill service")
}

log.Debugln("Registering POW Chain Service")
if err := beacon.registerPOWChainService(); err != nil {
log.Debugln("Registering Execution Chain Service")
if err := beacon.registerExecutionChainService(); err != nil {
return errors.Wrap(err, "could not register POW chain service")
}

Expand Down Expand Up @@ -729,8 +729,8 @@ func (b *BeaconNode) registerAttestationPool() error {
}

func (b *BeaconNode) registerBlockchainService(fc forkchoice.ForkChoicer, gs *startup.ClockSynchronizer, syncComplete chan struct{}) error {
var web3Service *execution.Service
if err := b.services.FetchService(&web3Service); err != nil {
var executionChainService *execution.Service
if err := b.services.FetchService(&executionChainService); err != nil {
return err
}

Expand All @@ -745,8 +745,8 @@ func (b *BeaconNode) registerBlockchainService(fc forkchoice.ForkChoicer, gs *st
blockchain.WithForkChoiceStore(fc),
blockchain.WithDatabase(b.db),
blockchain.WithDepositCache(b.depositCache),
blockchain.WithChainStartFetcher(web3Service),
blockchain.WithExecutionEngineCaller(web3Service),
blockchain.WithChainStartFetcher(executionChainService),
blockchain.WithExecutionEngineCaller(executionChainService),
blockchain.WithAttestationPool(b.attestationPool),
blockchain.WithExitPool(b.exitPool),
blockchain.WithSlashingPool(b.slashingsPool),
Expand All @@ -772,10 +772,11 @@ func (b *BeaconNode) registerBlockchainService(fc forkchoice.ForkChoicer, gs *st
return b.services.RegisterService(blockchainService)
}

func (b *BeaconNode) registerPOWChainService() error {
func (b *BeaconNode) registerExecutionChainService() error {
if b.cliCtx.Bool(testSkipPowFlag) {
return b.services.RegisterService(&execution.Service{})
}
// TODO: rename POW to execution
bs, err := execution.NewPowchainCollector(b.ctx)
if err != nil {
return err
Expand All @@ -798,17 +799,17 @@ func (b *BeaconNode) registerPOWChainService() error {
execution.WithJwtId(b.cliCtx.String(flags.JwtId.Name)),
execution.WithVerifierWaiter(b.verifyInitWaiter),
)
web3Service, err := execution.NewService(b.ctx, opts...)
executionChainService, err := execution.NewService(b.ctx, opts...)
if err != nil {
return errors.Wrap(err, "could not register proof-of-work chain web3Service")
return errors.Wrap(err, "could not register execution chain service")
}

return b.services.RegisterService(web3Service)
return b.services.RegisterService(executionChainService)
}

func (b *BeaconNode) registerSyncService(initialSyncComplete chan struct{}, bFillStore *backfill.Store) error {
var web3Service *execution.Service
if err := b.services.FetchService(&web3Service); err != nil {
var executionChainService *execution.Service
if err := b.services.FetchService(&executionChainService); err != nil {
return err
}

Expand Down Expand Up @@ -839,7 +840,7 @@ func (b *BeaconNode) registerSyncService(initialSyncComplete chan struct{}, bFil
regularsync.WithStateGen(b.stateGen),
regularsync.WithSlasherAttestationsFeed(b.slasherAttestationsFeed),
regularsync.WithSlasherBlockHeadersFeed(b.slasherBlockHeadersFeed),
regularsync.WithReconstructor(web3Service),
regularsync.WithReconstructor(executionChainService),
regularsync.WithClockWaiter(b.clockWaiter),
regularsync.WithInitialSyncComplete(initialSyncComplete),
regularsync.WithStateNotifier(b),
Expand Down Expand Up @@ -910,8 +911,8 @@ func (b *BeaconNode) registerRPCService(router *http.ServeMux) error {
return err
}

var web3Service *execution.Service
if err := b.services.FetchService(&web3Service); err != nil {
var executionChainService *execution.Service
if err := b.services.FetchService(&executionChainService); err != nil {
return err
}

Expand Down Expand Up @@ -939,7 +940,7 @@ func (b *BeaconNode) registerRPCService(router *http.ServeMux) error {
chainStartFetcher = interopService
} else {
depositFetcher = b.depositCache
chainStartFetcher = web3Service
chainStartFetcher = executionChainService
}

host := b.cliCtx.String(flags.RPCHost.Name)
Expand All @@ -954,8 +955,8 @@ func (b *BeaconNode) registerRPCService(router *http.ServeMux) error {

p2pService := b.fetchP2P()
rpcService := rpc.NewService(b.ctx, &rpc.Config{
ExecutionEngineCaller: web3Service,
ExecutionReconstructor: web3Service,
ExecutionEngineCaller: executionChainService,
ExecutionReconstructor: executionChainService,
Host: host,
Port: port,
BeaconMonitoringHost: beaconMonitoringHost,
Expand Down Expand Up @@ -984,8 +985,8 @@ func (b *BeaconNode) registerRPCService(router *http.ServeMux) error {
SlashingsPool: b.slashingsPool,
BLSChangesPool: b.blsToExecPool,
SyncCommitteeObjectPool: b.syncCommitteePool,
ExecutionChainService: web3Service,
ExecutionChainInfoFetcher: web3Service,
ExecutionChainService: executionChainService,
ExecutionChainInfoFetcher: executionChainService,
ChainStartFetcher: chainStartFetcher,
MockEth1Votes: mockEth1DataVotes,
SyncService: syncService,
Expand Down
2 changes: 1 addition & 1 deletion beacon-chain/rpc/prysm/v1alpha1/beacon/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type Server struct {
CanonicalFetcher blockchain.CanonicalFetcher
FinalizationFetcher blockchain.FinalizationFetcher
DepositFetcher cache.DepositFetcher
BlockFetcher execution.POWBlockFetcher
ExecutionBlockFetcher execution.BlockFetcher
GenesisTimeFetcher blockchain.TimeFetcher
StateNotifier statefeed.Notifier
BlockNotifier blockfeed.Notifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func TestProposer_PendingDeposits_Electra(t *testing.T) {
bs := &Server{
ChainStartFetcher: p,
Eth1InfoFetcher: p,
Eth1BlockFetcher: p,
ExecutionBlockFetcher: p,
DepositFetcher: depositCache,
PendingDepositsFetcher: depositCache,
BlockReceiver: &mock.ChainService{State: beaconState, Root: blkRoot[:]},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (vs *Server) eth1DataMajorityVote(ctx context.Context, beaconState state.Be
return vs.HeadFetcher.HeadETH1Data(), nil
}

lastBlockByLatestValidTime, err := vs.Eth1BlockFetcher.BlockByTimestamp(ctx, latestValidTime)
lastBlockByLatestValidTime, err := vs.ExecutionBlockFetcher.BlockByTimestamp(ctx, latestValidTime)
if err != nil {
log.WithError(err).Error("Could not get last block by latest valid time")
return vs.randomETH1DataVote(ctx)
Expand All @@ -73,7 +73,7 @@ func (vs *Server) eth1DataMajorityVote(ctx context.Context, beaconState state.Be
}

if lastBlockDepositCount >= vs.HeadFetcher.HeadETH1Data().DepositCount {
h, err := vs.Eth1BlockFetcher.BlockHashByHeight(ctx, lastBlockByLatestValidTime.Number)
h, err := vs.ExecutionBlockFetcher.BlockHashByHeight(ctx, lastBlockByLatestValidTime.Number)
if err != nil {
log.WithError(err).Error("Could not get hash of last block by latest valid time")
return vs.randomETH1DataVote(ctx)
Expand Down Expand Up @@ -118,7 +118,7 @@ func (vs *Server) canonicalEth1Data(
if features.Get().DisableStakinContractCheck && eth1BlockHash == [32]byte{} {
return canonicalEth1Data, new(big.Int).SetInt64(0), nil
}
_, canonicalEth1DataHeight, err := vs.Eth1BlockFetcher.BlockExists(ctx, eth1BlockHash)
_, canonicalEth1DataHeight, err := vs.ExecutionBlockFetcher.BlockExists(ctx, eth1BlockHash)
if err != nil {
return nil, nil, errors.Wrap(err, "could not fetch eth1data height")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ func (vs *Server) getTerminalBlockHashIfExists(ctx context.Context, transitionTi
terminalBlockHash := params.BeaconConfig().TerminalBlockHash
// Terminal block hash override takes precedence over terminal total difficulty.
if params.BeaconConfig().TerminalBlockHash != params.BeaconConfig().ZeroHash {
exists, _, err := vs.Eth1BlockFetcher.BlockExists(ctx, terminalBlockHash)
exists, _, err := vs.ExecutionBlockFetcher.BlockExists(ctx, terminalBlockHash)
if err != nil {
return nil, false, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ func TestServer_getTerminalBlockHashIfExists(t *testing.T) {
c := powtesting.New()
c.HashesByHeight[0] = tt.wantTerminalBlockHash
vs := &Server{
Eth1BlockFetcher: c,
ExecutionBlockFetcher: c,
ExecutionEngineCaller: &powtesting.EngineClient{
ExecutionBlock: tt.currentPowBlock,
BlockByHashMap: m,
Expand Down
Loading
Loading