Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(taiko-client): fix an url path issue in BeaconClient #17417

Merged
merged 2 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading