Skip to content

Commit

Permalink
fix(taiko-client): fix an url path issue in BeaconClient (#17417)
Browse files Browse the repository at this point in the history
Co-authored-by: gavin <[email protected]>
  • Loading branch information
davidtaikocha and YoGhurt111 authored May 29, 2024
1 parent 23104e9 commit 012d532
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 9 deletions.
1 change: 0 additions & 1 deletion packages/taiko-client/cmd/flags/prover.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ var (
// ProverFlags All prover flags.
var ProverFlags = MergeFlags(CommonFlags, []cli.Flag{
L1HTTPEndpoint,
L1BeaconEndpoint,
L2WSEndpoint,
L2HTTPEndpoint,
ProverSetAddress,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (s *BeaconSyncProgressTrackerTestSuite) TestClearMeta() {
func (s *BeaconSyncProgressTrackerTestSuite) TestHeadChanged() {
s.True(s.t.NeedReSync(common.Big256))
s.t.triggered = true
s.False(s.t.NeedReSync(common.Big256))
s.True(s.t.NeedReSync(common.Big256))
}

func (s *BeaconSyncProgressTrackerTestSuite) TestOutOfSync() {
Expand Down
30 changes: 24 additions & 6 deletions packages/taiko-client/pkg/rpc/beaconclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,22 @@ import (
"encoding/json"
"fmt"
"strconv"
"strings"
"time"

"github.com/ethereum/go-ethereum/log"
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/v4/api/client"
"github.com/prysmaticlabs/prysm/v4/api/client/beacon"
"github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/eth/blob"
"github.com/prysmaticlabs/prysm/v4/beacon-chain/rpc/eth/config"
)

var (
// Request urls.
sidecarsRequestURL = "eth/v1/beacon/blob_sidecars/%d"
genesisRequestURL = "eth/v1/beacon/genesis"
sidecarsRequestURL = "/eth/v1/beacon/blob_sidecars/%d"
genesisRequestURL = "/eth/v1/beacon/genesis"
getConfigSpecPath = "/eth/v1/config/spec"
)

type ConfigSpec struct {
Expand All @@ -39,7 +43,7 @@ type BeaconClient struct {

// NewBeaconClient returns a new beacon client.
func NewBeaconClient(endpoint string, timeout time.Duration) (*BeaconClient, error) {
cli, err := beacon.NewClient(endpoint, client.WithTimeout(timeout))
cli, err := beacon.NewClient(strings.TrimSuffix(endpoint, "/"), client.WithTimeout(timeout))
if err != nil {
return nil, err
}
Expand All @@ -49,7 +53,7 @@ func NewBeaconClient(endpoint string, timeout time.Duration) (*BeaconClient, err

// Get the genesis time.
var genesisDetail *GenesisResponse
resBytes, err := cli.Get(ctx, genesisRequestURL)
resBytes, err := cli.Get(ctx, cli.BaseURL().Path+genesisRequestURL)
if err != nil {
return nil, err
}
Expand All @@ -66,7 +70,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 All @@ -92,7 +96,7 @@ func (c *BeaconClient) GetBlobs(ctx context.Context, time uint64) ([]*blob.Sidec
}

var sidecars *blob.SidecarsResponse
resBytes, err := c.Get(ctxWithTimeout, fmt.Sprintf(sidecarsRequestURL, slot))
resBytes, err := c.Get(ctxWithTimeout, c.BaseURL().Path+fmt.Sprintf(sidecarsRequestURL, slot))
if err != nil {
return nil, err
}
Expand All @@ -107,3 +111,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) (*config.GetSpecResponse, error) {
body, err := c.Get(ctx, c.BaseURL().Path+getConfigSpecPath)
if err != nil {
return nil, errors.Wrap(err, "error requesting configSpecPath")
}
fsr := &config.GetSpecResponse{}
err = json.Unmarshal(body, fsr)
if err != nil {
return nil, err
}
return fsr, nil
}
2 changes: 1 addition & 1 deletion packages/taiko-client/pkg/rpc/blob_datasource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/require"

"github.com/taikoxyz/taiko-mono/packages/taiko-client/bindings"
)

Expand Down

0 comments on commit 012d532

Please sign in to comment.