refactor(networks): store feeder and gateway URLs as *url.URL#3769
Conversation
The Network type kept its feeder and gateway URLs as plain strings, so every consumer that needed an actual URL had to re-parse them. Since NethermindEth#3749 the feeder client takes a *url.URL, which meant node startup parsed the string only to hand it straight back. Store the URLs as *url.URL on the Network itself and drop the redundant conversions. Predefined networks build their URLs up front, and custom network URLs are parsed and validated once during config load. Closes NethermindEth#3761
There was a problem hiding this comment.
Pull request overview
Refactors the networks.Network configuration to store feeder/gateway endpoints as parsed *url.URL values instead of raw strings, eliminating repeated parsing and simplifying client construction across the node and CLI config flow.
Changes:
- Change
networks.Network.FeederURL/GatewayURLfromstringto*url.URL, building predefined network URLs up-front. - Parse and validate custom-network URLs once during CLI/config load (
validateHTTPURL→parseHTTPURLreturning*url.URL). - Remove redundant feeder URL parsing in
node.New, and adapt gateway client initialization to useGatewayURL.String().
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
node/node.go |
Stops re-parsing feeder URL; uses stored *url.URL for feeder client and .String() for gateway client. |
cmd/juno/juno.go |
Parses custom network URLs once and stores them as *url.URL in config. |
cmd/juno/juno_test.go |
Updates tests to construct/compare URLs using *url.URL and .String(). |
blockchain/networks/network.go |
Updates Network URL fields to *url.URL and introduces mustParseURL for predefined networks. |
blockchain/networks/network_test.go |
Updates assertions to compare URL string representations. |
Comments suppressed due to low confidence (1)
node/node.go:368
- cfg.Network.FeederURL / GatewayURL are now pointers; if a user selects a network without URLs (e.g. "sequencer") while running with seq-enable=false, this code will panic (GatewayURL.String() and feeder client URL usage). Add an explicit nil check here and return a configuration error instead of crashing.
client = feeder.NewClient(cfg.Network.FeederURL).
WithUserAgent(ua).
WithLogger(logger).
WithTimeouts(timeouts, fixed).
WithAPIKey(cfg.GatewayAPIKey)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Use url.ParseRequestURI in mustParseURL so a malformed or scheme-less hardcoded network URL panics at startup instead of silently producing a broken URL, and include the offending value in the panic message.
The gateway client still took a string, so node had to call GatewayURL.String() — keeping the url->string round trip NethermindEth#3761 aimed to remove. Make gateway.NewClient take *url.URL, mirroring the feeder client. Also guard against nil feeder/gateway URLs in sync mode: the sequencer network leaves them unset, so `--network sequencer` without --seq would nil-panic on GatewayURL.String(). Return a clear error instead.
d9962f7 to
86e0dec
Compare
|
Thanks for your PR! I left a few comments to tighten the refactor so the tests, URL handling and validation all consistently follow the new |
Store Client.url as *url.URL and build the add_transaction path with JoinPath, compare URLs as *url.URL in tests, and make mustParseURL enforce the same http/https scheme and non-empty host checks as custom networks.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3769 +/- ##
==========================================
- Coverage 75.03% 75.00% -0.04%
==========================================
Files 433 433
Lines 38594 38606 +12
==========================================
- Hits 28960 28955 -5
- Misses 7632 7645 +13
- Partials 2002 2006 +4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Signed-off-by: ongyimeng <73429081+ongyimeng@users.noreply.github.com>
Co-authored-by: Rodrigo <rodrodpino@gmail.com> Signed-off-by: ongyimeng <73429081+ongyimeng@users.noreply.github.com>
01a8301 to
fd6a8e5
Compare
What
The
Networktype stored its feeder and gateway URLs as plainstrings. Every consumer that needed an actual URL had to re-parse them, and since #3749 the feeder client takes a*url.URL, node startup parsed the string only to hand it straight back.This changes
Network.FeederURLandNetwork.GatewayURLto*url.URLand drops the redundant conversions:mustParseURLhelper).validateHTTPURL->parseHTTPURL, returning the parsed URL).nodeno longer re-parses the feeder URL before constructing the client.No behavioural change.
Testing
go build ./cmd/juno/go test ./blockchain/networks/... ./cmd/juno/... ./node/... ./clients/...Closes #3761