diff --git a/packages/taiko-client/cmd/flags/prover.go b/packages/taiko-client/cmd/flags/prover.go index b1766659b44..9ec65dfa1bf 100644 --- a/packages/taiko-client/cmd/flags/prover.go +++ b/packages/taiko-client/cmd/flags/prover.go @@ -213,7 +213,6 @@ var ( // ProverFlags All prover flags. var ProverFlags = MergeFlags(CommonFlags, []cli.Flag{ L1HTTPEndpoint, - L1BeaconEndpoint, L2WSEndpoint, L2HTTPEndpoint, ProverSetAddress, diff --git a/packages/taiko-client/driver/chain_syncer/beaconsync/progress_tracker_test.go b/packages/taiko-client/driver/chain_syncer/beaconsync/progress_tracker_test.go index 9ea1a3f443a..dd5bb47f1a5 100644 --- a/packages/taiko-client/driver/chain_syncer/beaconsync/progress_tracker_test.go +++ b/packages/taiko-client/driver/chain_syncer/beaconsync/progress_tracker_test.go @@ -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() { diff --git a/packages/taiko-client/pkg/rpc/beaconclient.go b/packages/taiko-client/pkg/rpc/beaconclient.go index 06e3b5ac600..91e67cf1a5f 100644 --- a/packages/taiko-client/pkg/rpc/beaconclient.go +++ b/packages/taiko-client/pkg/rpc/beaconclient.go @@ -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 { @@ -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 } @@ -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 } @@ -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 } @@ -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 } @@ -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 +} diff --git a/packages/taiko-client/pkg/rpc/blob_datasource_test.go b/packages/taiko-client/pkg/rpc/blob_datasource_test.go new file mode 100644 index 00000000000..59802910167 --- /dev/null +++ b/packages/taiko-client/pkg/rpc/blob_datasource_test.go @@ -0,0 +1,56 @@ +package rpc + +import ( + "context" + "net/url" + "testing" + + "github.com/ethereum/go-ethereum/common" + "github.com/stretchr/testify/require" + + "github.com/taikoxyz/taiko-mono/packages/taiko-client/bindings" +) + +func TestGetBlobsFromSocialScan(t *testing.T) { + socialScanEndpoint, err := url.Parse("https://api.socialscan.io/blob-archive/v1/holesky-testnet") + require.Nil(t, err) + require.NotNil(t, socialScanEndpoint) + ds := NewBlobDataSource( + context.Background(), + &Client{}, + nil, + socialScanEndpoint, + ) + sidecars, err := ds.GetBlobs( + context.Background(), + &bindings.TaikoDataBlockMetadata{ + BlobHash: common.HexToHash("0x0145185449c57dee4e6c921b702e5d572fbeb026f96c220a6a17b79d157d921b"), + BlobUsed: true, + }, + ) + require.Nil(t, err) + require.NotNil(t, sidecars) + require.NotNil(t, sidecars[0].Blob) +} + +func TestGetBlobsFromBlobScan(t *testing.T) { + blobScanEndpoint, err := url.Parse("https://api.holesky.blobscan.com") + require.Nil(t, err) + require.NotNil(t, blobScanEndpoint) + ds := NewBlobDataSource( + context.Background(), + &Client{}, + blobScanEndpoint, + nil, + ) + sidecars, err := ds.GetBlobs( + context.Background(), + &bindings.TaikoDataBlockMetadata{ + BlobHash: common.HexToHash("0x0145185449c57dee4e6c921b702e5d572fbeb026f96c220a6a17b79d157d921b"), + BlobUsed: true, + }, + ) + require.Nil(t, err) + require.NotNil(t, sidecars) + require.NotNil(t, sidecars[0].Blob) +}