Skip to content

util/address: make address encoding more modular#643

Merged
sanket1729 merged 3 commits intorust-bitcoin:masterfrom
benma:address_params
Dec 15, 2021
Merged

util/address: make address encoding more modular#643
sanket1729 merged 3 commits intorust-bitcoin:masterfrom
benma:address_params

Conversation

@benma
Copy link
Copy Markdown
Contributor

@benma benma commented Aug 29, 2021

This allow library clients to plug their own encoding parameters in a
backwards compatible manner.

Copy link
Copy Markdown
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.

concept ACK. I don't see any reason not to support this. There is a CI failure on 1.29 MSRV

@apoelstra
Copy link
Copy Markdown
Member

concept ACK.

I'd like the bech32 hrp to be &'static and to also have an AddressEncodingOwned type (maybe even this should be called Address?) which does not have any lifetimes and directly holds the payload.

@benma
Copy link
Copy Markdown
Contributor Author

benma commented Sep 10, 2021

concept ACK.

I'd like the bech32 hrp to be &'static and to also have an AddressEncodingOwned type (maybe even this should be called Address?) which does not have any lifetimes and directly holds the payload.

Imho it would be better to defer AddressEncodingOwned to another PR or issue. Since Address already exists and owns the payload, the goal is not quite clear.

I added a separate lifetime for bech32_hrp, see the other comment above.

Copy link
Copy Markdown
Collaborator

@dr-orlovsky dr-orlovsky left a comment

Choose a reason for hiding this comment

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

Concept ACK. Unfortunatelly will need a refactor once taproot addresses will get merged from #563

@dr-orlovsky
Copy link
Copy Markdown
Collaborator

Needs rebase & editing since we've got P2TR into master

@benma
Copy link
Copy Markdown
Contributor Author

benma commented Nov 14, 2021

Needs rebase & editing since we've got P2TR into master

@dr-orlovsky Sorry for the delay. I finally rebased this PR. I also snuck in another small fix here which I extracted into another PR: #698

Copy link
Copy Markdown
Collaborator

@dr-orlovsky dr-orlovsky left a comment

Choose a reason for hiding this comment

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

Found several ways of improving the code. This is not related to the PR and rather affects the code we had before, but since we are moving/touching that code anyway I propose also to improve its readibility

@benma benma force-pushed the address_params branch 2 times, most recently from 37d1ec4 to f01e7f6 Compare November 16, 2021 22:35
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Could this be represented in type?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I couldn't work out a way, did you have a concrete idea?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I do: pls see my commend below

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I meant taking struct CompressedPublicKey(secp256k1::PublicKey) which guarantees the key being compressed. We could then push checking to the boundary and also have a helpful compress(self) -> CompressedPublicKey method. (Might make sense to implement in secp256k1.)

@benma
Copy link
Copy Markdown
Contributor Author

benma commented Nov 22, 2021

I think this is ready to be merged. @sanket1729

Copy link
Copy Markdown
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.

Left a few comments. I think rest is good to go

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This should be a reference to Secp256k1<C>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The other part is being resolved here: #707

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Rebased this PR, should be good to go now!

@dr-orlovsky
Copy link
Copy Markdown
Collaborator

LGTM. Agree with @sanket1729 on having Secp by ref

@benma benma force-pushed the address_params branch 2 times, most recently from fa9a8ef to ec776ff Compare November 30, 2021 23:17
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: There is a to_bytes() method for doing this. I don't like using psbt specific utilities for this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done!

Copy link
Copy Markdown
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 one more small thing.

@tcharding
Copy link
Copy Markdown
Member

Thanks for your continued contributions @benma.

I'd like the bech32 hrp to be &'static

Could you address this suggestion please, either by implementing it or by commenting on why you think it should not be implemented.

If you want to implement it as suggested its just a quick fix

    /// hrp used in bech32 addresss (e.g. "bc" for "bc1..." addresses).
    pub bech32_hrp: &'static str,

Legend,
Cheers.

@benma
Copy link
Copy Markdown
Contributor Author

benma commented Dec 2, 2021

I'd like the bech32 hrp to be &'static

Could you address this suggestion please, either by implementing it or by commenting on why you think it should not be implemented.

This was addressed here already:

#643 (comment)

@tcharding
Copy link
Copy Markdown
Member

Thanks @benma, I'll try to be more careful next time and look through all the comments before messaging :)

@tcharding
Copy link
Copy Markdown
Member

GitHub is weird these days

Did you mean to suggest we should move rust-bitcoin off GitHub and start using patches to a mailing list - sir, I concur!

Copy link
Copy Markdown
Collaborator

@dr-orlovsky dr-orlovsky left a comment

Choose a reason for hiding this comment

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

I just recalled that we should use existing functions PublicKey::(w)pubkey_hash() and Script::(w)script_hash() everywhere and get rid of the most of this code duplicating business logic which is already present there (BTW, unlike this code, it does no allocations)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I do: pls see my commend below

@benma
Copy link
Copy Markdown
Contributor Author

benma commented Dec 10, 2021

@dr-orlovsky

I just recalled that we should use existing functions PublicKey::(w)pubkey_hash() and Script::(w)script_hash() everywhere and get rid of the most of this code duplicating business logic which is already present there (BTW, unlike this code, it does no allocations)

I did this in all places I could find, and put it into a new commit for easier review. Please check it out.

dr-orlovsky
dr-orlovsky previously approved these changes Dec 11, 2021
Copy link
Copy Markdown
Collaborator

@dr-orlovsky dr-orlovsky left a comment

Choose a reason for hiding this comment

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

utACK f53c9b7b956a94eef47d4c929fa896577cf140ab

@sanket1729
Copy link
Copy Markdown
Member

ACK f53c9b7

sanket1729
sanket1729 previously approved these changes Dec 12, 2021
Copy link
Copy Markdown
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 f53c9b7

@dr-orlovsky
Copy link
Copy Markdown
Collaborator

Oh, now it requires rebase :(

@benma benma dismissed stale reviews from sanket1729 and dr-orlovsky via 87a75d2 December 12, 2021 10:20
@benma
Copy link
Copy Markdown
Contributor Author

benma commented Dec 12, 2021

Oh, now it requires rebase :(

Rebased

@dr-orlovsky
Copy link
Copy Markdown
Collaborator

First commit fails to build, pls check & fix the history with

git rebase -x 'AS_DEPENDENCY=true TOOLCHAIN=stable ./contrib/test.sh' master &&
  PIN_VERSIONS=true AS_DEPENDENCY=true TOOLCHAIN="${BITCOIN_MSRV:-1.29.0}" ./contrib/test.sh &&
  AS_DEPENDENCY=true DO_FUZZ=true TOOLCHAIN=nightly ./contrib/test.sh

@Kixunil Kixunil added the waiting for author This can only progress if the author responds to a request. label Dec 12, 2021
This allow library clients to plug their own encoding parameters in a
backwards compatible manner.
@benma
Copy link
Copy Markdown
Contributor Author

benma commented Dec 12, 2021

@dr-orlovsky good catch - fixed

Copy link
Copy Markdown
Collaborator

@dr-orlovsky dr-orlovsky left a comment

Choose a reason for hiding this comment

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

tACK f53c9b7b956a94eef47d4c929fa896577cf140ab

All tests are passing for each of the commits in the history

@benma
Copy link
Copy Markdown
Contributor Author

benma commented Dec 15, 2021

Please merge.

Copy link
Copy Markdown
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 f53c9b7

@sanket1729 sanket1729 merged commit 36f3d23 into rust-bitcoin:master Dec 15, 2021
@sanket1729
Copy link
Copy Markdown
Member

Sorry, it took this long. Merging this since this has been open for quite some time. If there are other comments from other reviewers we can address those in follow-up PRs.

@Kixunil Kixunil removed the waiting for author This can only progress if the author responds to a request. label Dec 15, 2021
@benma benma deleted the address_params branch December 15, 2021 16:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants