Skip to content

Commit

Permalink
added option to disable fetching validator set from specific endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
pk910 committed Aug 31, 2023
1 parent 1c064dc commit d64b870
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 11 deletions.
4 changes: 3 additions & 1 deletion indexer/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type IndexerClient struct {
clientIdx uint8
clientName string
rpcClient *rpc.BeaconClient
skipValidators bool
archive bool
priority int
versionStr string
Expand All @@ -32,11 +33,12 @@ type IndexerClient struct {
lastFinalizedRoot []byte
}

func newIndexerClient(clientIdx uint8, clientName string, rpcClient *rpc.BeaconClient, indexerCache *indexerCache, archive bool, priority int) *IndexerClient {
func newIndexerClient(clientIdx uint8, clientName string, rpcClient *rpc.BeaconClient, indexerCache *indexerCache, archive bool, priority int, skipValidators bool) *IndexerClient {
client := IndexerClient{
clientIdx: clientIdx,
clientName: clientName,
rpcClient: rpcClient,
skipValidators: skipValidators,
archive: archive,
priority: priority,
indexerCache: indexerCache,
Expand Down
3 changes: 3 additions & 0 deletions indexer/epoch_stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,9 @@ func (epochStats *EpochStats) ensureEpochStatsLazy(client *IndexerClient, propos

func (epochStats *EpochStats) ensureValidatorStatsLazy(client *IndexerClient, stateRef string) {
defer utils.HandleSubroutinePanic("ensureValidatorStatsLazy")
if client.skipValidators {
return
}
epochStats.loadValidatorStats(client, stateRef)
}

Expand Down
9 changes: 5 additions & 4 deletions indexer/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/pk910/light-beaconchain-explorer/dbtypes"
"github.com/pk910/light-beaconchain-explorer/rpc"
"github.com/pk910/light-beaconchain-explorer/rpctypes"
"github.com/pk910/light-beaconchain-explorer/types"
"github.com/pk910/light-beaconchain-explorer/utils"
)

Expand Down Expand Up @@ -43,13 +44,13 @@ func NewIndexer() (*Indexer, error) {
return indexer, nil
}

func (indexer *Indexer) AddClient(index uint8, name string, endpoint string, archive bool, priority int, headers map[string]string) *IndexerClient {
rpcClient, err := rpc.NewBeaconClient(endpoint, name, headers)
func (indexer *Indexer) AddClient(index uint8, endpoint *types.EndpointConfig) *IndexerClient {
rpcClient, err := rpc.NewBeaconClient(endpoint.Url, endpoint.Name, endpoint.Headers)
if err != nil {
logger.Errorf("error while adding client %v to indexer: %v", name, err)
logger.Errorf("error while adding client %v to indexer: %v", endpoint.Name, err)
return nil
}
client := newIndexerClient(index, name, rpcClient, indexer.indexerCache, archive, priority)
client := newIndexerClient(index, endpoint.Name, rpcClient, indexer.indexerCache, endpoint.Archive, endpoint.Priority, endpoint.SkipValidators)
indexer.indexerClients = append(indexer.indexerClients, client)
return client
}
Expand Down
2 changes: 1 addition & 1 deletion services/beaconservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func StartBeaconService() error {
}

for idx, endpoint := range utils.Config.BeaconApi.Endpoints {
indexer.AddClient(uint8(idx), endpoint.Name, endpoint.Url, endpoint.Archive, endpoint.Priority, endpoint.Headers)
indexer.AddClient(uint8(idx), &endpoint)
}

validatorNames := &ValidatorNames{}
Expand Down
11 changes: 6 additions & 5 deletions types/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,12 @@ type Config struct {
}

type EndpointConfig struct {
Url string `yaml:"url"`
Name string `yaml:"name"`
Archive bool `yaml:"archive"`
Priority int `yaml:"priority"`
Headers map[string]string `yaml:"headers"`
Url string `yaml:"url"`
Name string `yaml:"name"`
Archive bool `yaml:"archive"`
SkipValidators bool `yaml:"skipValidators"`
Priority int `yaml:"priority"`
Headers map[string]string `yaml:"headers"`
}

type SqliteDatabaseConfig struct {
Expand Down

0 comments on commit d64b870

Please sign in to comment.