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

Prepare for using new bech32 release #1975

Merged
merged 8 commits into from
Sep 20, 2023

Conversation

tcharding
Copy link
Member

@tcharding tcharding commented Aug 4, 2023

In preparation for depending on the recently released version of rust-bech32 do a bunch of preparatory fixes.

  1. Improve address module error handling as we are doing else where at the moment
  2. Remove bip 173 and 350 test vector tests, these are fully covered in bech32
  3. Trim down the docs on WitnessVersion

This PR is the first 8 patches of #1951

apoelstra
apoelstra previously approved these changes Aug 4, 2023
Copy link
Member

@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

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

ACK f641cd4

Copy link
Member

@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

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

ACK fb8cb50

@tcharding tcharding added P-high High priority one ack PRs that have one ACK, so one more can progress them labels Aug 21, 2023
Copy link
Member

@sanket1729 sanket1729 left a comment

Choose a reason for hiding this comment

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

Just left one comment. Will do another round later

}
}

impl From<base58::Error> for ParseError {
Copy link
Member

Choose a reason for hiding this comment

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

I don't think it is approriate to create From<base58::Error> for ParseError. Can we wrap this in a struct struct AddrBase58Error(base58::Error). And then in the enum we would have variant as Base58(AddrBase58Error) instead of Base58(base58::Error).
Finally, we can implement From<AddrBase58Error> for ParseError.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for the review. I don't understand your concern, can you elaborate please? Why can't we put the base58::Error directly in a variant, this is "standard" error handling boilerplate?

Copy link
Member

Choose a reason for hiding this comment

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

Consider the following code.

fn foo() -> ParseError {
     let sender_name = base58::decode(...)?; // Some other usage of base58 completely unrelated to address module
     let addr_parsed = Address::from_str(&base58_str)?; // Error related to base58 in address module.
}

In the current implementation, the above code would compile both of them will go into address::ParseError().
But sender name is really not related to address.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fair point but this same applies for every error we have, right? Just to clarify foo in your example is a function in downstream code that is returning an error from our code? Or are you saying that we might add foo in rust-bitcoin at some later stage and inadvertently create the situation you describe?

Said another way, I don't think the From imples are the problem, I think the foo() -> ParseError function is buggy because it returns the wrong error type. Am I understanding you correctly?

Copy link
Member

Choose a reason for hiding this comment

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

Fair point but this same applies for every error we have, right?

Agreed. I no longer have the above concern. Will do a detailed review later.

Copy link
Member Author

Choose a reason for hiding this comment

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

No worries, thanks man.

apoelstra
apoelstra previously approved these changes Sep 3, 2023
Copy link
Member

@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

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

ACK 4451b9b

@tcharding
Copy link
Member Author

Rebase only, no other changes.

Copy link
Member

@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

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

ACK dd1dbb9

In preparation for splitting out the error code move `address.rs` to
`address/mod.rs`.

File move only, no other changes.
Split the error code out of `address/mod.rs` and into
`address/error.rs`. Code move only, no changes other than to
imports/exports etc. to make it build.
`Error` is in this file, no need for `self::Error`.
In an effort to reduce the number of lines of code import the error
variants locally within the `Display` impl on `Error`.

Refactor only, no logic changes.
There is no need to use the general `address::Error` when parsing an
address type, there is only one error path.
The `address::Error` is module level general, we can make the code
easier to maintain and easier to stabalize by splitting the parse error
out of the general error.

Create a `ParseError` that is returned by `FromStr for Address`. Remove
the now unused variants from the general `address::Error`.
The BIP-173 and BIP-350 test vectors are implemented in `rust-bech32`,
no need to duplicate those tests here.
These docs do not add that much value, we do not typically bother
documenting `From` and `TryFrom` implementations because they are super
well known and its obvious from the function signature what is going on.
@tcharding
Copy link
Member Author

Rebased to pick up recent pinning fix, no other changes.

@tcharding
Copy link
Member Author

This PR is basically just refactoring and a some improvements to error handling. It has been open for over a month with an ack from @apoelstra. Other activity was partial review by @sanket1729 and all his concerns were explicitly ok'ed by him above.

As such it is a candidate for the "refactor carve-out" and may be merged at any time.

Copy link
Member

@sanket1729 sanket1729 left a comment

Choose a reason for hiding this comment

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

ACK 52f2332

Copy link
Member

@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

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

ACK 52f2332

@apoelstra apoelstra merged commit a2a4efb into rust-bitcoin:master Sep 20, 2023
29 checks passed
@tcharding tcharding deleted the 08-04-address-prep branch September 21, 2023 03:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
one ack PRs that have one ACK, so one more can progress them P-high High priority
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants