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

WitnessVersion type #617

Merged
merged 2 commits into from Sep 8, 2021
Merged

WitnessVersion type #617

merged 2 commits into from Sep 8, 2021

Conversation

dr-orlovsky
Copy link
Collaborator

Reopening as a new PR to #562 (github does not allow to re-open force-pushed branches) since there might be changes during the review at this level unrelated to #563 (which will be in draft mode until this is merged - and rebased after the merge)

@dr-orlovsky dr-orlovsky added the API break This PR requires a version bump for the next release label Jun 13, 2021
@dr-orlovsky dr-orlovsky added this to the 0.27.0 milestone Jun 13, 2021
This was referenced Jun 13, 2021
sgeisler
sgeisler previously approved these changes Jun 13, 2021
Copy link
Contributor

@sgeisler sgeisler left a comment

Choose a reason for hiding this comment

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

utACK 3645c63

Looks pretty good. I really like the function documentation describing all error cases applicable to the function (especially when it's only a subset of the error enum).

src/util/address.rs Outdated Show resolved Hide resolved
src/util/address.rs Outdated Show resolved Hide resolved
src/util/address.rs Show resolved Hide resolved
src/util/address.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@jrawsthorne jrawsthorne left a comment

Choose a reason for hiding this comment

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

You mentioned here about using WitnessVersion in the is_* methods on Script. Don't know if you want to do that here.

src/util/address.rs Outdated Show resolved Hide resolved
src/util/address.rs Outdated Show resolved Hide resolved
@dr-orlovsky
Copy link
Collaborator Author

@jrawsthorne well, tried that and it looks like it adds a lot more code instead of simplifying functions. So just made it for only is_witness_program and not the rest of is_* methods (which will require error testing instead of simple opcode equivalence test used now)

Copy link
Member

@clarkmoody clarkmoody left a comment

Choose a reason for hiding this comment

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

I prefer this approach, since it "makes impossible states impossible." I've just got a couple preference nits.

/// # Errors
/// If the integer does not corresponds to any witness version, errors with
/// [`Error::InvalidWitnessVersion`]
pub fn from_no(no: u8) -> Result<Self, Error> {
Copy link
Member

Choose a reason for hiding this comment

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

Nit: use num instead of no for a number variable? Also, this function would probably be better named from_u8

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It was originally named from_u8, but later I decided it is a bad name, since there are two different u8-based representations for witness version: by script byte (0, 0x51-0x60) and as version number (incremental from 0 to 16). So while I'm fine with using from_num instead of from_no, it will be confusing to use from_u8.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Possibly raw_num or raw_u8?

Copy link
Member

Choose a reason for hiding this comment

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

+1 for num instead of no

/// NB: this is not the same as an integer representation of the opcode signifying witness
/// version in bitcoin script. Thus, there is no function to directly convert witness version
/// into a byte since the conversion requires context (bitcoin script or just a version number)
pub fn into_no(self) -> u8 {
Copy link
Member

Choose a reason for hiding this comment

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

Nit: I would prefer into_u8

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Commented above: the same reason for the naming here

Kixunil
Kixunil previously approved these changes Jun 14, 2021
Copy link
Collaborator

@Kixunil Kixunil left a comment

Choose a reason for hiding this comment

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

Just a few doc suggestions.

///
/// Structure helps to limit possible version of the witness according to the
/// specification; if a plain `u8` type will be used instead it will mean that
/// version > 16, which is incorrect.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Did you mean to say "if a plain u8 type was used instead it would mean that version may be > 16, which is incorrect"?

src/util/address.rs Show resolved Hide resolved
type Err = Error;

fn from_str(s: &str) -> Result<Self, Self::Err> {
let version = u8::from_str(s).map_err(|err| Error::UnparsableWitnessVersion(err))?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe s.parse::<u8>() is considered idiomatic.

src/util/address.rs Show resolved Hide resolved
@@ -329,7 +499,7 @@ impl Address {
}

/// Check whether or not the address is following Bitcoin
/// standardness rules.
/// standard rules.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not a native speaker but the original seemed correct. The rules check if the address is standard.

Copy link
Member

Choose a reason for hiding this comment

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

Agreed.

src/util/address.rs Show resolved Hide resolved
src/blockdata/script.rs Show resolved Hide resolved
@dr-orlovsky
Copy link
Collaborator Author

Addressed all suggestions with a separate commit

@@ -159,8 +159,8 @@ impl FromStr for AddressType {
/// to 16 (inclusive).
///
/// Structure helps to limit possible version of the witness according to the
/// specification; if a plain `u8` type will be used instead it will mean that
/// version > 16, which is incorrect.
/// specification; if a plain `u8` type was be used instead it would mean that
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: "was be"

@dr-orlovsky dr-orlovsky added this to In review in Taproot Jun 16, 2021
sanket1729
sanket1729 previously approved these changes Jun 16, 2021
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 4ecfd68

@dr-orlovsky
Copy link
Collaborator Author

Needed rebase, merged master into this branch so the review will not require to go through all commits again. Also fixed @Kixunil nit in docs.

Ned re-ACK from @sanket1729 and review from @apoelstra before the merge since this is intrusive and important change

sgeisler
sgeisler previously approved these changes Jun 27, 2021
Copy link
Contributor

@sgeisler sgeisler left a comment

Choose a reason for hiding this comment

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

utACK 409cb91

src/util/address.rs Show resolved Hide resolved
sgeisler
sgeisler previously approved these changes Jun 27, 2021
Copy link
Contributor

@sgeisler sgeisler left a comment

Choose a reason for hiding this comment

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

utACK 8a99a3f

@apoelstra
Copy link
Member

Can you clean up the history by removing the merge commit and rebasing on top of master?

@apoelstra
Copy link
Member

ack 8a99a3f aside from history

@dr-orlovsky
Copy link
Collaborator Author

@apoelstra done

sanket1729
sanket1729 previously approved these changes Aug 1, 2021
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 a8571f2

@dr-orlovsky
Copy link
Collaborator Author

@sanket1729 @sgeisler had to force-push due to conflicts with recent merges. Re-ACK will be highly appreciated

Copy link
Contributor

@sgeisler sgeisler left a comment

Choose a reason for hiding this comment

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

re-ACK ecc4008

Just looked at the diff-diff using git range-diff 8a99a3f...ecc400826c5eebf4c8bf3f28219af348a1ba0191

@apoelstra
Copy link
Member

re-utACK ecc4008

Taproot automation moved this from In review to Ready for merge Aug 30, 2021
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 ecc4008

@apoelstra apoelstra merged commit 2a655f4 into rust-bitcoin:master Sep 8, 2021
Taproot automation moved this from Ready for merge to Done Sep 8, 2021
@dr-orlovsky dr-orlovsky mentioned this pull request Sep 29, 2021
20 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API break This PR requires a version bump for the next release
Projects
Development

Successfully merging this pull request may close these issues.

None yet

7 participants