Skip to content

Commit 1bee33e

Browse files
zsfelfoldistevemilk
authored andcommitted
beacon/light/api: fixed blsync update query (#30421)
This PR fixes what ethereum/go-ethereum#30306 broke. Escaping the `?` in the event sub query was fixed in that PR but it was still escaped in the `updates` request. This PR adds a URL params argument to `httpGet` and fixes `updates` query formatting.
1 parent 0ae29ea commit 1bee33e

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

beacon/light/api/light_api.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"io"
2525
"net/http"
2626
"net/url"
27+
"strconv"
2728
"sync"
2829
"time"
2930

@@ -121,8 +122,8 @@ func NewBeaconLightApi(url string, customHeaders map[string]string) *BeaconLight
121122
}
122123
}
123124

124-
func (api *BeaconLightApi) httpGet(path string) ([]byte, error) {
125-
uri, err := api.buildURL(path, nil)
125+
func (api *BeaconLightApi) httpGet(path string, params url.Values) ([]byte, error) {
126+
uri, err := api.buildURL(path, params)
126127
if err != nil {
127128
return nil, err
128129
}
@@ -150,17 +151,16 @@ func (api *BeaconLightApi) httpGet(path string) ([]byte, error) {
150151
}
151152
}
152153

153-
func (api *BeaconLightApi) httpGetf(format string, params ...any) ([]byte, error) {
154-
return api.httpGet(fmt.Sprintf(format, params...))
155-
}
156-
157154
// GetBestUpdatesAndCommittees fetches and validates LightClientUpdate for given
158155
// period and full serialized committee for the next period (committee root hash
159156
// equals update.NextSyncCommitteeRoot).
160157
// Note that the results are validated but the update signature should be verified
161158
// by the caller as its validity depends on the update chain.
162159
func (api *BeaconLightApi) GetBestUpdatesAndCommittees(firstPeriod, count uint64) ([]*types.LightClientUpdate, []*types.SerializedSyncCommittee, error) {
163-
resp, err := api.httpGetf("/eth/v1/beacon/light_client/updates?start_period=%d&count=%d", firstPeriod, count)
160+
resp, err := api.httpGet("/eth/v1/beacon/light_client/updates", map[string][]string{
161+
"start_period": {strconv.FormatUint(firstPeriod, 10)},
162+
"count": {strconv.FormatUint(count, 10)},
163+
})
164164
if err != nil {
165165
return nil, nil, err
166166
}
@@ -197,7 +197,7 @@ func (api *BeaconLightApi) GetBestUpdatesAndCommittees(firstPeriod, count uint64
197197
// See data structure definition here:
198198
// https://github.com/ethereum/consensus-specs/blob/dev/specs/altair/light-client/sync-protocol.md#lightclientoptimisticupdate
199199
func (api *BeaconLightApi) GetOptimisticUpdate() (types.OptimisticUpdate, error) {
200-
resp, err := api.httpGet("/eth/v1/beacon/light_client/optimistic_update")
200+
resp, err := api.httpGet("/eth/v1/beacon/light_client/optimistic_update", nil)
201201
if err != nil {
202202
return types.OptimisticUpdate{}, err
203203
}
@@ -250,7 +250,7 @@ func decodeOptimisticUpdate(enc []byte) (types.OptimisticUpdate, error) {
250250
// See data structure definition here:
251251
// https://github.com/ethereum/consensus-specs/blob/dev/specs/altair/light-client/sync-protocol.md#lightclientfinalityupdate
252252
func (api *BeaconLightApi) GetFinalityUpdate() (types.FinalityUpdate, error) {
253-
resp, err := api.httpGet("/eth/v1/beacon/light_client/finality_update")
253+
resp, err := api.httpGet("/eth/v1/beacon/light_client/finality_update", nil)
254254
if err != nil {
255255
return types.FinalityUpdate{}, err
256256
}
@@ -316,7 +316,7 @@ func (api *BeaconLightApi) GetHeader(blockRoot common.Hash) (types.Header, bool,
316316
} else {
317317
blockId = blockRoot.Hex()
318318
}
319-
resp, err := api.httpGetf("/eth/v1/beacon/headers/%s", blockId)
319+
resp, err := api.httpGet(fmt.Sprintf("/eth/v1/beacon/headers/%s", blockId), nil)
320320
if err != nil {
321321
return types.Header{}, false, false, err
322322
}
@@ -347,7 +347,7 @@ func (api *BeaconLightApi) GetHeader(blockRoot common.Hash) (types.Header, bool,
347347

348348
// GetCheckpointData fetches and validates bootstrap data belonging to the given checkpoint.
349349
func (api *BeaconLightApi) GetCheckpointData(checkpointHash common.Hash) (*types.BootstrapData, error) {
350-
resp, err := api.httpGetf("/eth/v1/beacon/light_client/bootstrap/0x%x", checkpointHash[:])
350+
resp, err := api.httpGet(fmt.Sprintf("/eth/v1/beacon/light_client/bootstrap/0x%x", checkpointHash[:]), nil)
351351
if err != nil {
352352
return nil, err
353353
}
@@ -389,7 +389,7 @@ func (api *BeaconLightApi) GetCheckpointData(checkpointHash common.Hash) (*types
389389
}
390390

391391
func (api *BeaconLightApi) GetBeaconBlock(blockRoot common.Hash) (*types.BeaconBlock, error) {
392-
resp, err := api.httpGetf("/eth/v2/beacon/blocks/0x%x", blockRoot)
392+
resp, err := api.httpGet(fmt.Sprintf("/eth/v2/beacon/blocks/0x%x", blockRoot), nil)
393393
if err != nil {
394394
return nil, err
395395
}

0 commit comments

Comments
 (0)