Skip to content

Commit

Permalink
fix(taiko-client): fix path parsing in /eth/v1/config/spec (#18295)
Browse files Browse the repository at this point in the history
  • Loading branch information
YoGhurt111 authored Oct 24, 2024
1 parent 63ba863 commit 6633c80
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion packages/taiko-client/pkg/rpc/beaconclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}

0 comments on commit 6633c80

Please sign in to comment.