Skip to content

Commit

Permalink
fix: improve net_listening implementation (#13387)
Browse files Browse the repository at this point in the history
Replace hardcoded value with actual network state check.
**The method now properly reflects network connectivity status by
checking if the node can communicate with the network.**
  • Loading branch information
crStiv authored Jan 31, 2025
1 parent 6e26052 commit 8227e4c
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions turbo/jsonrpc/net_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,17 @@ func NewNetAPIImpl(eth rpchelper.ApiBackend) *NetAPIImpl {
}

// Listening implements net_listening. Returns true if client is actively listening for network connections.
// TODO: Remove hard coded value
func (api *NetAPIImpl) Listening(_ context.Context) (bool, error) {
func (api *NetAPIImpl) Listening(ctx context.Context) (bool, error) {
if api.ethBackend == nil {
// We're running in --datadir mode or otherwise cannot get the backend
return false, fmt.Errorf(NotAvailableChainData, "net_listening")
}

// If we can get peers info, it means the network interface is up and listening
_, err := api.ethBackend.Peers(ctx)
if err != nil {
return false, nil
}
return true, nil
}

Expand Down

0 comments on commit 8227e4c

Please sign in to comment.