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

beacon/light/api: fixed blsync update query #30421

Merged
merged 2 commits into from
Sep 12, 2024

Conversation

zsfelfoldi
Copy link
Contributor

@zsfelfoldi zsfelfoldi commented Sep 11, 2024

This PR fixes what #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.

@holiman
Copy link
Contributor

holiman commented Sep 12, 2024

Even after looking at this fix, and the previous fix, and playing with it in my IDE, I fail to spot the error. Please point it out to me...

@holiman
Copy link
Contributor

holiman commented Sep 12, 2024

Ok, I got an explanation now, I'll post it here for visibility. There's this method

func (api *BeaconLightApi) httpGet(path string) ([]byte, error) 

Which @s1na fixed to escape the path.
However, it's called by

func (api *BeaconLightApi) httpGetf(format string, params ...any) ([]byte, error) {
	return api.httpGet(fmt.Sprintf(format, params...))
}

called by

func (api *BeaconLightApi) GetBestUpdatesAndCommittees(firstPeriod, count uint64) ([]*types.LightClientUpdate, []*types.SerializedSyncCommittee, error) {
	resp, err := api.httpGetf("/eth/v1/beacon/light_client/updates?start_period=%d&count=%d", firstPeriod, count)

So, the httpGetf accepts params, but passes the full path + params as path to httpGet -- which now escapes the already escaped param-string.

So it's a semantic mixup, IMO the httpGetf must not use httpGet, because what it's passing is not path, but a full query.

@zsfelfoldi
Copy link
Contributor Author

zsfelfoldi commented Sep 12, 2024

Now it's fixed in a nice way. httpGet makes a full query (which is required for updates) while httpGetf makes a request to a formatted string path with no additional query params (which is required for most of the other requests where parameters are actually a part of the path).

@@ -151,7 +152,7 @@ func (api *BeaconLightApi) httpGet(path string) ([]byte, error) {
}

func (api *BeaconLightApi) httpGetf(format string, params ...any) ([]byte, error) {
return api.httpGet(fmt.Sprintf(format, params...))
return api.httpGet(fmt.Sprintf(format, params...), nil)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This httpGetf method is a bit useless, IMO. It's now used in three places, so they can write e.g

	resp, err := api.httpGetf("/eth/v1/beacon/headers/%s", blockId)

instead of

	resp, err := api.httpGet(fmt.Sprintf("/eth/v1/beacon/headers/%s", blockId))

I approve of this patch, but I also wouldn't mind dropping that method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, httpGetf removed.

@zsfelfoldi zsfelfoldi merged commit a01e974 into ethereum:master Sep 12, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants