Skip to content

Commit

Permalink
beacon/light/api: fixed blsync update query
Browse files Browse the repository at this point in the history
  • Loading branch information
zsfelfoldi committed Sep 11, 2024
1 parent ec69830 commit 7457d92
Showing 1 changed file with 6 additions and 24 deletions.
30 changes: 6 additions & 24 deletions beacon/light/api/light_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"fmt"
"io"
"net/http"
"net/url"
"sync"
"time"

Expand Down Expand Up @@ -112,6 +111,9 @@ type BeaconLightApi struct {
}

func NewBeaconLightApi(url string, customHeaders map[string]string) *BeaconLightApi {
if len(url) > 0 && url[len(url)-1] == '/' {
url = url[:len(url)-1]
}
return &BeaconLightApi{
url: url,
client: &http.Client{
Expand All @@ -122,11 +124,7 @@ func NewBeaconLightApi(url string, customHeaders map[string]string) *BeaconLight
}

func (api *BeaconLightApi) httpGet(path string) ([]byte, error) {
uri, err := api.buildURL(path, nil)
if err != nil {
return nil, err
}
req, err := http.NewRequest("GET", uri, nil)
req, err := http.NewRequest("GET", api.url+path, nil)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -551,12 +549,8 @@ func (api *BeaconLightApi) StartHeadListener(listener HeadEventListener) func()
func (api *BeaconLightApi) startEventStream(ctx context.Context, listener *HeadEventListener) *eventsource.Stream {
for retry := true; retry; retry = ctxSleep(ctx, 5*time.Second) {
log.Trace("Sending event subscription request")
uri, err := api.buildURL("/eth/v1/events", map[string][]string{"topics": {"head", "light_client_finality_update", "light_client_optimistic_update"}})
if err != nil {
listener.OnError(fmt.Errorf("error creating event subscription URL: %v", err))
continue
}
req, err := http.NewRequestWithContext(ctx, "GET", uri, nil)
path := "/eth/v1/events?topics=head&topics=light_client_finality_update&topics=light_client_optimistic_update"
req, err := http.NewRequestWithContext(ctx, "GET", api.url+path, nil)
if err != nil {
listener.OnError(fmt.Errorf("error creating event subscription request: %v", err))
continue
Expand Down Expand Up @@ -585,15 +579,3 @@ func ctxSleep(ctx context.Context, timeout time.Duration) (ok bool) {
return false
}
}

func (api *BeaconLightApi) buildURL(path string, params url.Values) (string, error) {
uri, err := url.Parse(api.url)
if err != nil {
return "", err
}
uri = uri.JoinPath(path)
if params != nil {
uri.RawQuery = params.Encode()
}
return uri.String(), nil
}

0 comments on commit 7457d92

Please sign in to comment.