From dac1a42fa8390dad156c23cb1f1e78ff60bde9ee Mon Sep 17 00:00:00 2001 From: PeaStew <34198053+PeaStew@users.noreply.github.com> Date: Mon, 15 Jan 2024 09:46:15 +0100 Subject: [PATCH] Update client.go to allow the use of paths with the heimdall url (#1126) * Update client.go to allow the use of paths with the heimdall url As reported to the polygon team 2 months ago in the Ankr polygon slack, the current code prevents the use of a path with the heimdall url, this was fixed in erigon ledgerwatch/erigon@a3a6170 in response to my request by Mark Holt, and it seems this code was just copied from bor where it is incorrect too. This patch fixes that. * Add reference to path library * Fix reversed order of values in unit tests and test removal of setting u.path to rawPath (otherwise why do we need rawPath at all) seems like there were work arounds done here in bioth the unit tests AND the makeURL but logic needs to be examined --- consensus/bor/heimdall/client.go | 3 ++- consensus/bor/heimdall/client_test.go | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/consensus/bor/heimdall/client.go b/consensus/bor/heimdall/client.go index d69f5ead3c..5c65721574 100644 --- a/consensus/bor/heimdall/client.go +++ b/consensus/bor/heimdall/client.go @@ -8,6 +8,7 @@ import ( "io" "net/http" "net/url" + "path" "sort" "time" @@ -420,7 +421,7 @@ func makeURL(urlString, rawPath, rawQuery string) (*url.URL, error) { return nil, err } - u.Path = rawPath + u.Path = path.Join(u.Path, rawPath) u.RawQuery = rawQuery return u, err diff --git a/consensus/bor/heimdall/client_test.go b/consensus/bor/heimdall/client_test.go index 5023b847a5..737875028c 100644 --- a/consensus/bor/heimdall/client_test.go +++ b/consensus/bor/heimdall/client_test.go @@ -399,7 +399,7 @@ func TestSpanURL(t *testing.T) { const expected = "http://bor0/bor/span/1" if url.String() != expected { - t.Fatalf("expected URL %q, got %q", url.String(), expected) + t.Fatalf("expected URL %q, got %q", expected, url.String()) } } @@ -414,6 +414,6 @@ func TestStateSyncURL(t *testing.T) { const expected = "http://bor0/clerk/event-record/list?from-id=10&to-time=100&limit=50" if url.String() != expected { - t.Fatalf("expected URL %q, got %q", url.String(), expected) + t.Fatalf("expected URL %q, got %q", expected, url.String()) } }