-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Adds validate_node_url() and refactors boot node check (#6907) #6970
Conversation
util/network/src/node_table.rs
Outdated
@@ -368,6 +368,15 @@ pub fn is_valid_node_url(url: &str) -> bool { | |||
Node::from_str(url).is_ok() | |||
} | |||
|
|||
/// Same as `is_valid_node_url` but returns detailed `NetworkError` | |||
pub fn validate_node_url(url: &str) -> Option<NetworkError> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why introduce another method then?
Wouldn't it be better to just do is_valid_node_url().is_ok()
in places that don't care about the error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about it and it was my first intention, however, in that case, method name would conflict with it's semantics.
Also I'm a bit confused why we validate nodes by effectively doing all the work needed to construct Node
just to throw it away and use the raw string value. Wouldn't it be better to return Reusult<Vec<Node>, NetworkError>
from init_reserved_nodes
? Anyway, I thought, that would cause substantial refactoring and is out of the scope.
For now I think it would be better to stick with the new function and refactor existing calls to is_valid_node_url
.
d6b5798
to
851401d
Compare
Removed obsolete variant @tomusdrw, currently Actually, we may go even further, and return |
this one is probably addressed by #6979 |
This PR fixes #6907 by propagating error value instead of a
bool
flag.IMO, full solution should return the actual reason of failure including underlying error message. However, there are some issues with it:
Display
forNetworkError
should handle error detailsFromStr
forNode
andNodeEndpoint
returnNetworkError::AddressResolve
even on incorrectly formatted addresses, likefoo
,enode://foo@bar
and even on an empty string (Node::from_str()
reports errors incorrectly #6972).