From 6633c80fbcabb6f06ce5467501da4207bc84be84 Mon Sep 17 00:00:00 2001 From: Gavin Yu Date: Thu, 24 Oct 2024 20:33:27 +0800 Subject: [PATCH] fix(taiko-client): fix path parsing in `/eth/v1/config/spec` (#18295) --- packages/taiko-client/pkg/rpc/beaconclient.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/packages/taiko-client/pkg/rpc/beaconclient.go b/packages/taiko-client/pkg/rpc/beaconclient.go index e907acf460..acf70c86b7 100644 --- a/packages/taiko-client/pkg/rpc/beaconclient.go +++ b/packages/taiko-client/pkg/rpc/beaconclient.go @@ -9,6 +9,7 @@ import ( "time" "github.com/ethereum/go-ethereum/log" + "github.com/pkg/errors" "github.com/prysmaticlabs/prysm/v5/api/client" "github.com/prysmaticlabs/prysm/v5/api/client/beacon" "github.com/prysmaticlabs/prysm/v5/api/server/structs" @@ -18,6 +19,7 @@ var ( // Request urls. sidecarsRequestURL = "/eth/v1/beacon/blob_sidecars/%d" genesisRequestURL = "/eth/v1/beacon/genesis" + getConfigSpecPath = "/eth/v1/config/spec" ) type ConfigSpec struct { @@ -67,7 +69,7 @@ func NewBeaconClient(endpoint string, timeout time.Duration) (*BeaconClient, err log.Info("L1 genesis time", "time", genesisTime) // Get the seconds per slot. - spec, err := cli.GetConfigSpec(ctx) + spec, err := getConfigSpec(ctx, cli) if err != nil { return nil, err } @@ -111,3 +113,17 @@ func (c *BeaconClient) timeToSlot(timestamp uint64) (uint64, error) { } return (timestamp - c.genesisTime) / c.secondsPerSlot, nil } + +// getConfigSpec retrieve the current configs of the network used by the beacon node. +func getConfigSpec(ctx context.Context, c *beacon.Client) (*structs.GetSpecResponse, error) { + body, err := c.Get(ctx, c.BaseURL().Path+getConfigSpecPath) + if err != nil { + return nil, errors.Wrap(err, "error requesting configSpecPath") + } + fsr := &structs.GetSpecResponse{} + err = json.Unmarshal(body, fsr) + if err != nil { + return nil, err + } + return fsr, nil +}