-
Notifications
You must be signed in to change notification settings - Fork 161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow Address network prefix to be overriden for printing #233
Conversation
I'm not sure this functionality is the best course of action. In most protocols we associate network IDs with addresses to prevent replay attacks, what the exact purpose is in FIL? My thought is that this functionality should only exist as a constructor, not as a method to modify (a copy of) an existing address instance. We should not be associating different network IDs with existing address instances, rather only creating instances with the current ID and discarding any we receive that don't match that ID. |
I would agree, but defined in the protocol the network prefix is not serialized to bytes, so it's not used in any consensus but just for printing. When deserializing bytes on another network, we may have a way to pass through the config to set the network but for some cases we will need the ability to modify the network of an Address. But aside from that this couldn't introduce any vulnerabilities, someone with external code could still swap out the network prefix without this change, no external code could affect how our client operates, I fail to see how this is a concern. Edit: The use case is that if you deserialize from bytes, there is no way to set what the network actually is, because there is no data indicating this, this is the primary reason for the change |
vm/address/src/lib.rs
Outdated
} | ||
|
||
/// Sets the network for the address and returns a mutable reference to it | ||
pub fn with_network(&mut self, network: Network) -> &mut Self { |
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.
As per your question, I think it makes more sense to name this set_network
given its functionality. Just my opinion tho
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.
ya, I didn't like that the name didn't indicate self is mutated, with set_network
it doesn't indicate that it can be chained and returns a mutable self ref. I'll think about this later and see if any examples in std lib for naming
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.
with kinda feels like its a temporary change. set feels more permanent
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.
yeah I agree this is better, I didn't like that it didn't indicate that it could be chained, but that is definitely less of a problem than it being worded as not being mutated and instead being copied
Summary of changes
Changes introduced in this pull request:
I tried to find the naming guideline for this kind of functionality but this makes sense to me, does
with_network
make sense to you?Reference issue to close (if applicable)
Closes
Other information and links