Skip to content

Fix for 'debug/blacklist' HTTP API method.#2121

Open
nickeskov wants to merge 4 commits into
determenistic-finality-featurefrom
fix-http-api-debug-blacklist
Open

Fix for 'debug/blacklist' HTTP API method.#2121
nickeskov wants to merge 4 commits into
determenistic-finality-featurefrom
fix-http-api-debug-blacklist

Conversation

@nickeskov

Copy link
Copy Markdown
Collaborator

Fix for #2119.

This pull request refactors the peer blacklisting logic to improve IP resolution, standardize method naming, and enhance test coverage. The main change is to always resolve and blacklist by IPv4 address (ignoring port), simplifying and unifying how peers are blacklisted. Several method and mock names are updated for clarity and consistency, and tests are expanded to cover more scenarios.

Peer blacklisting improvements:

  • The blacklisting logic in App.PeersBlackList now resolves the provided address (IP or IP:port) to one or more IPv4 addresses and blacklists each resolved IP, ignoring the port. This ensures consistent blacklisting regardless of input format. (pkg/api/peers.go, pkg/proto/proto.go) [1] [2] [3]
  • The helper function resolveAddrToIPsV4 is introduced to handle address parsing and resolution. (pkg/api/peers.go)

API and handler updates:

  • The NodeApi.PeersBlackList handler now writes a 200 OK response on success and wraps errors with context for better debugging. (pkg/api/node_api.go)

Peer manager interface and implementation:

  • The peer manager method for blacklisting is renamed from AddToBlackListByAddr to AddToBlackListByIP in the interface and implementation, and all usages are updated accordingly. (pkg/node/peers/peer_manager.go) [1] [2]

Testing improvements:

  • Tests for peer blacklisting are updated to use the new method names and logic, and are expanded to cover both IP and IP:port inputs, as well as leading slashes. Mock expectations are updated to match the new method signature. (pkg/api/node_api_test.go, pkg/api/peers_test.go, pkg/node/peers/mock_peer_manager.go) [1] [2] [3] [4] [5] [6] [7] [8] [9]

Proto utility function:

  • The internal resolveHostToIPsv4 is made public as ResolveHostToIPsv4 for use in the new address resolution logic. (pkg/proto/proto.go)

These changes collectively make peer blacklisting more robust, consistent, and easier to maintain.

Adds reponse text and fixes request input format.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes and refactors the debug/blacklist HTTP endpoint by standardizing peer blacklisting around resolved IPv4 addresses (ignoring ports), renaming the peer manager method to reflect the new behavior, and expanding tests to cover additional input formats.

Changes:

  • Exported proto.ResolveHostToIPsv4() and updated proto parsing to use it.
  • Updated App.PeersBlackList to resolve an input host / host:port into one or more IPv4s and blacklist each resolved IP (port ignored).
  • Updated the HTTP handler to return a success body ("OK") and expanded tests for IP, IP:port, and leading-slash inputs; renamed peer manager blacklisting method to AddToBlackListByIP.

Reviewed changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
pkg/proto/proto.go Exports host→IPv4 resolver and updates internal call site to use the exported name.
pkg/node/peers/peer_manager.go Renames peer manager API to AddToBlackListByIP and keeps blacklist behavior IP-based.
pkg/node/peers/mock_peer_manager.go Updates generated mock to match the renamed peer manager method.
pkg/api/peers.go Refactors blacklist logic to resolve and blacklist by IPv4(s), ignoring ports.
pkg/api/peers_test.go Updates and expands app-level blacklist tests for IP and IP:port inputs.
pkg/api/node_api.go Updates blacklist handler to wrap errors with context and write a 200 OK response body on success.
pkg/api/node_api_test.go Expands handler tests to verify "OK" response body for multiple success cases.
Files not reviewed (1)
  • pkg/node/peers/mock_peer_manager.go: Generated file

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/api/peers.go
Comment thread pkg/api/node_api_test.go Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 7 changed files in this pull request and generated 1 comment.

Files not reviewed (1)
  • pkg/node/peers/mock_peer_manager.go: Generated file

Comment thread pkg/api/peers.go

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 7 changed files in this pull request and generated 1 comment.

Files not reviewed (1)
  • pkg/node/peers/mock_peer_manager.go: Generated file

Comment thread pkg/api/peers.go

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 7 changed files in this pull request and generated no new comments.

Files not reviewed (1)
  • pkg/node/peers/mock_peer_manager.go: Generated file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants