Skip to content
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

Merged
merged 8 commits into from
Feb 23, 2020

Conversation

austinabell
Copy link
Contributor

@austinabell austinabell commented Feb 19, 2020

Summary of changes
Changes introduced in this pull request:

  • Allows ability to set Address network specifically (Can be chained to use when specifically printing)
    • Was going to leave it to some configuration within Forest, but I can see the need for it to be specified explicitly (as it was by someone using this crate)
  • Removed unnecessary heap allocation in tests I noticed
  • Updated function signature for generating secp and actor addresses to only require reference to bytes since address is generated from hashing bytes and does not require the move

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

@austinabell austinabell changed the title Austin/networkprint Allow Address network prefix to be overriden for printing Feb 19, 2020
@ansermino
Copy link
Member

ansermino commented Feb 20, 2020

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.

@austinabell
Copy link
Contributor Author

austinabell commented Feb 20, 2020

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

}

/// Sets the network for the address and returns a mutable reference to it
pub fn with_network(&mut self, network: Network) -> &mut Self {
Copy link
Contributor

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

Copy link
Contributor Author

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

Copy link
Member

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

Copy link
Contributor Author

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

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

Successfully merging this pull request may close these issues.

4 participants