Skip to content

Commit

Permalink
Merge pull request #95 from ethpandaops/pk910/default-validator-names
Browse files Browse the repository at this point in the history
load default validator names based on network name from specs
  • Loading branch information
pk910 authored Aug 16, 2024
2 parents 3e3296b + 580161d commit c484ad7
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 23 deletions.
15 changes: 8 additions & 7 deletions services/chainservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,7 @@ func StartChainService(ctx context.Context, logger logrus.FieldLogger) error {
}

// init validator names & load inventory
validatorNames := NewValidatorNames(beaconIndexer)
validatorNamesLoading := validatorNames.LoadValidatorNames()
validatorNames := NewValidatorNames(beaconIndexer, consensusPool.GetChainState())

// reset sync state if configured
if utils.Config.Indexer.ResyncFromEpoch != nil {
Expand All @@ -120,8 +119,7 @@ func StartChainService(ctx context.Context, logger logrus.FieldLogger) error {
logger.Warnf("Reset explorer synchronization status to epoch %v as configured! Please remove this setting again.", *utils.Config.Indexer.ResyncFromEpoch)
}

// await validator names & beacon pool readiness
<-validatorNamesLoading
// await beacon pool readiness
lastLog := time.Now()
for {
specs := consensusPool.GetChainState().GetSpecs()
Expand All @@ -136,15 +134,18 @@ func StartChainService(ctx context.Context, logger logrus.FieldLogger) error {
time.Sleep(1 * time.Second)
}

// start chain indexer
beaconIndexer.StartIndexer()

// start validator names updater
validatorNamesLoading := validatorNames.LoadValidatorNames()
<-validatorNamesLoading

go func() {
validatorNames.UpdateDb()
validatorNames.StartUpdater()
}()

// start chain indexer
beaconIndexer.StartIndexer()

// add execution indexers
execindexer.NewDepositIndexer(executionIndexerCtx)

Expand Down
36 changes: 31 additions & 5 deletions services/validatornames.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
v1 "github.com/attestantio/go-eth2-client/api/v1"
"github.com/attestantio/go-eth2-client/spec/phase0"
"github.com/ethereum/go-ethereum/common"
"github.com/ethpandaops/dora/clients/consensus"
"github.com/ethpandaops/dora/config"
"github.com/ethpandaops/dora/db"
"github.com/ethpandaops/dora/dbtypes"
Expand All @@ -30,6 +31,7 @@ var logger_vn = logrus.StandardLogger().WithField("module", "validator_names")

type ValidatorNames struct {
beaconIndexer *beacon.Indexer
chainState *consensus.ChainState
loadingMutex sync.Mutex
loading chan bool
lastResolvedMapUpdate time.Time
Expand All @@ -47,9 +49,10 @@ type validatorNameEntry struct {
name string
}

func NewValidatorNames(beaconIndexer *beacon.Indexer) *ValidatorNames {
func NewValidatorNames(beaconIndexer *beacon.Indexer, chainState *consensus.ChainState) *ValidatorNames {
validatorNames := &ValidatorNames{
beaconIndexer: beaconIndexer,
chainState: chainState,
}
return validatorNames
}
Expand Down Expand Up @@ -111,6 +114,24 @@ func (vn *ValidatorNames) runUpdater() error {
return nil
}

func (vn *ValidatorNames) getDefaultValidatorNames() string {
specs := vn.chainState.GetSpecs()
chainName := ""
if specs != nil {
chainName = specs.ConfigName
}

// default validator names
switch chainName {
case "sepolia":
return "~internal/sepolia.names.yml"
case "holesky":
return "~internal/holesky.names.yml"
}

return ""
}

func (vn *ValidatorNames) resolveNames() (bool, error) {
validatorSet := vn.beaconIndexer.GetCanonicalValidatorSet(nil)
if validatorSet == nil {
Expand Down Expand Up @@ -277,14 +298,19 @@ func (vn *ValidatorNames) LoadValidatorNames() chan bool {
vn.namesByDepositTarget = make(map[common.Address]*validatorNameEntry)
vn.namesMutex.Unlock()

validatorNamesYaml := utils.Config.Frontend.ValidatorNamesYaml
if validatorNamesYaml == "" {
validatorNamesYaml = vn.getDefaultValidatorNames()
}

// load names
if strings.HasPrefix(utils.Config.Frontend.ValidatorNamesYaml, "~internal/") {
err := vn.loadFromInternalYaml(utils.Config.Frontend.ValidatorNamesYaml[10:])
if strings.HasPrefix(validatorNamesYaml, "~internal/") {
err := vn.loadFromInternalYaml(validatorNamesYaml[10:])
if err != nil {
logger_vn.WithError(err).Errorf("error while loading validator names from internal yaml")
}
} else if utils.Config.Frontend.ValidatorNamesYaml != "" {
err := vn.loadFromYaml(utils.Config.Frontend.ValidatorNamesYaml)
} else if validatorNamesYaml != "" {
err := vn.loadFromYaml(validatorNamesYaml)
if err != nil {
logger_vn.WithError(err).Errorf("error while loading validator names from yaml")
}
Expand Down
1 change: 0 additions & 1 deletion types/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ type Config struct {
} `yaml:"server"`

Chain struct {
Name string `yaml:"name" envconfig:"CHAIN_NAME"`
DisplayName string `yaml:"displayName" envconfig:"CHAIN_DISPLAY_NAME"`

// optional features
Expand Down
10 changes: 0 additions & 10 deletions utils/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,6 @@ func ReadConfig(cfg *types.Config, path string) error {

readConfigEnv(cfg)

// default validator names
if cfg.Frontend.ValidatorNamesYaml == "" && cfg.Frontend.ValidatorNamesInventory == "" {
switch cfg.Chain.Name {
case "sepolia":
cfg.Frontend.ValidatorNamesYaml = "~internal/sepolia.names.yml"
case "holesky":
cfg.Frontend.ValidatorNamesYaml = "~internal/holesky.names.yml"
}
}

// endpoints
if cfg.BeaconApi.Endpoints == nil && cfg.BeaconApi.Endpoint != "" {
cfg.BeaconApi.Endpoints = []types.EndpointConfig{
Expand Down

0 comments on commit c484ad7

Please sign in to comment.