From 0393ddf0cab41a798d88d70a0badaba68eed97f6 Mon Sep 17 00:00:00 2001 From: pk910 Date: Sun, 31 Mar 2024 04:21:18 +0200 Subject: [PATCH] populate spec cache in go-eth2-client --- indexer/client.go | 6 ++++++ rpc/beaconapi.go | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/indexer/client.go b/indexer/client.go index 9f1875dd..929dab0c 100644 --- a/indexer/client.go +++ b/indexer/client.go @@ -209,6 +209,12 @@ func (client *IndexerClient) checkIndexerClient() error { } func (client *IndexerClient) runIndexerClient() error { + // get specs + _, err := client.rpcClient.GetSpecs() + if err != nil { + return fmt.Errorf("could not get specs: %v", err) + } + // get latest header latestHeader, err := client.rpcClient.GetLatestBlockHead() if err != nil { diff --git a/rpc/beaconapi.go b/rpc/beaconapi.go index 41b1cccd..c3cdb34d 100644 --- a/rpc/beaconapi.go +++ b/rpc/beaconapi.go @@ -180,6 +180,24 @@ func (bc *BeaconClient) Initialize() error { return nil } +func (bc *BeaconClient) GetSpecs() (map[string]any, error) { + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + provider, isProvider := bc.clientSvc.(eth2client.SpecProvider) + if !isProvider { + return nil, fmt.Errorf("get spec not supported") + } + result, err := provider.Spec(ctx, &api.SpecOpts{ + Common: api.CommonOpts{ + Timeout: 0, + }, + }) + if err != nil { + return nil, err + } + return result.Data, nil +} + func (bc *BeaconClient) GetGenesis() (*v1.Genesis, error) { ctx, cancel := context.WithCancel(context.Background()) defer cancel()