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

rpc: Better error messages for invalid addresses #20832

Merged
merged 1 commit into from Jan 26, 2021

Conversation

eilx2
Copy link

@eilx2 eilx2 commented Jan 3, 2021

This PR addresses #20809.

We add more detailed error messages in case an invalid address is provided inside the 'validateaddress' and 'getaddressinfo' RPC calls. This also covers the case when a user provides an address from a wrong network.

We also add a functional test to test the new error messages.

@eilx2
Copy link
Author

eilx2 commented Jan 3, 2021

Tagging @instagibbs as requested.

Copy link
Contributor

@jonatack jonatack 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, builds cleanly and works. A few suggestions follow.

src/key_io.cpp Outdated Show resolved Hide resolved
src/wallet/rpcwallet.cpp Outdated Show resolved Hide resolved
src/rpc/misc.cpp Outdated Show resolved Hide resolved
src/rpc/misc.cpp Outdated Show resolved Hide resolved
src/rpc/misc.cpp Outdated Show resolved Hide resolved
src/key_io.cpp Outdated Show resolved Hide resolved
src/key_io.cpp Outdated Show resolved Hide resolved
src/key_io.cpp Outdated Show resolved Hide resolved
src/key_io.cpp Outdated Show resolved Hide resolved
src/key_io.cpp Outdated Show resolved Hide resolved
@eilx2 eilx2 force-pushed the master branch 4 times, most recently from 0f8f334 to f1c7aea Compare January 3, 2021 22:15
@eilx2
Copy link
Author

eilx2 commented Jan 3, 2021

Thanks a lot for the review! I've made the proposed changes.

In addition, I've realized that DecodeDestination is used in other places too which return a generic 'invalid address' error message in case if fails. Should we also handle those places as part of this PR?

src/rpc/misc.cpp Outdated Show resolved Hide resolved
Copy link
Member

@instagibbs instagibbs left a comment

Choose a reason for hiding this comment

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

ACK

Take or leave the suggested changes, test coverage of various paths is nice.

test/functional/rpc_invalid_address_message.py Outdated Show resolved Hide resolved
src/key_io.cpp Outdated Show resolved Hide resolved
Copy link
Contributor

@jonasschnelli jonasschnelli left a comment

Choose a reason for hiding this comment

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

code review ACK f1c7aea (modulo nitpicks).

src/key_io.cpp Outdated Show resolved Hide resolved
src/wallet/rpcwallet.cpp Show resolved Hide resolved
@eilx2 eilx2 force-pushed the master branch 2 times, most recently from 65ca93d to 11de868 Compare January 4, 2021 12:25
@eilx2
Copy link
Author

eilx2 commented Jan 4, 2021

Thanks again for the comments.

I think for now I'll let this PR cover only 'getaddressinfo' and 'validateaddress' just to keep it small enough. In the future I will work on the other code paths.

Copy link
Contributor

@jonatack jonatack left a comment

Choose a reason for hiding this comment

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

Almost-ACK 11de868

The new test file test/functional/rpc_invalid_address_message.py has the wrong file permissions.

src/key_io.h Outdated Show resolved Hide resolved
@jonatack
Copy link
Contributor

jonatack commented Jan 4, 2021

ACK f58a4ed

@DrahtBot
Copy link
Contributor

DrahtBot commented Jan 4, 2021

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@instagibbs
Copy link
Member

reACK f58a4ed

Copy link
Member

@luke-jr luke-jr left a comment

Choose a reason for hiding this comment

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

utACK, w/ a few nits

src/key_io.cpp Outdated Show resolved Hide resolved
@@ -39,13 +39,14 @@ static RPCHelpMan validateaddress()
RPCResult{
RPCResult::Type::OBJ, "", "",
{
{RPCResult::Type::BOOL, "isvalid", "If the address is valid or not. If not, this is the only property returned."},
{RPCResult::Type::BOOL, "isvalid", "If the address is valid or not"},
Copy link
Member

Choose a reason for hiding this comment

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

Maybe split up the two possible return cases like getrawmempool does?

Copy link
Author

Choose a reason for hiding this comment

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

Good idea, I will try to do this in a future commit where I address the other places where you need to return an error message for invalid address as they probably all require a similar change

Copy link

@felipsoarez felipsoarez left a comment

Choose a reason for hiding this comment

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

ACK f58a4ed
I have reviewed it and it looks OK

@instagibbs
Copy link
Member

4 ACKs, RFM imo

Copy link
Contributor

@kristapsk kristapsk left a comment

Choose a reason for hiding this comment

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

ACK f58a4ed (I agree with @luke-jr comment about WITNESS_PROG_MAX_LEN constant name, but don't think that's too important). Apart from reviewing code and running test suite, made sure this does not break JoinMarket which uses getaddressinfo RPC.

This commit addresses bitcoin#20809.

We add an additional 'error' property in the result of 'validateaddress' in case the address is not valid that gives a short description of why the address in invalid. We also change the error message returned by 'getaddressinfo' in case the address is invalid.
@eilx2
Copy link
Author

eilx2 commented Jan 24, 2021

Thanks everyone for the review! I've rebased on the latest master so there are no more merge conflicts.

Copy link
Contributor

@kristapsk kristapsk left a comment

Choose a reason for hiding this comment

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

ACK 8f0b64f

Copy link
Contributor

@meshcollider meshcollider left a comment

Choose a reason for hiding this comment

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

Code review ACK 8f0b64f

@meshcollider meshcollider merged commit 4b15ffe into bitcoin:master Jan 26, 2021
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jan 26, 2021
@ghost ghost mentioned this pull request Apr 21, 2021
maflcko pushed a commit to maflcko/bitcoin-core that referenced this pull request May 22, 2021
+ Detailed error messages for invalid address
+ Used `IsValidDestination` instead of `IsValidDestinationString`
+ Referred to bitcoin#20832 for solution

Github-Pull: bitcoin-core/gui#280
Rebased-From: 3bad0b3
maflcko pushed a commit to maflcko/bitcoin-core that referenced this pull request May 22, 2021
+ Detailed error messages for invalid address
+ Used `IsValidDestination` instead of `IsValidDestinationString`
+ Referred to bitcoin#20832 for solution

Github-Pull: bitcoin-core/gui#280
Rebased-From: 3bad0b3
luke-jr pushed a commit to bitcoinknots/bitcoin that referenced this pull request Jun 27, 2021
This commit addresses bitcoin#20809.

We add an additional 'error' property in the result of 'validateaddress' in case the address is not valid that gives a short description of why the address in invalid. We also change the error message returned by 'getaddressinfo' in case the address is invalid.

Github-Pull: bitcoin#20832
Rebased-From: 8f0b64f
apoelstra pushed a commit to apoelstra/elements that referenced this pull request Aug 5, 2021
This commit addresses #20809.

We add an additional 'error' property in the result of 'validateaddress' in case the address is not valid that gives a short description of why the address in invalid. We also change the error message returned by 'getaddressinfo' in case the address is invalid.

bitcoin/bitcoin#20832 (1/1)

ELEMENTS: Merge conflicts resolved based on d6c85c5 (from 22.0 rebase)
apoelstra pushed a commit to apoelstra/elements that referenced this pull request Aug 18, 2021
This commit addresses #20809.

We add an additional 'error' property in the result of 'validateaddress' in case the address is not valid that gives a short description of why the address in invalid. We also change the error message returned by 'getaddressinfo' in case the address is invalid.

bitcoin/bitcoin#20832 (1/1)

ELEMENTS: Merge conflicts resolved based on d6c85c5 (from 22.0 rebase)
apoelstra added a commit to ElementsProject/elements that referenced this pull request Aug 30, 2021
c72c949 blech32: copy ubsan suppression for bech32 to blech32 (Andrew Poelstra)
d13fb49 blech32: add test vectors for blech32 and blech32m (Andrew Poelstra)
15a826e blech32: add functional tests for blech32m (Andrew Poelstra)
c01e09e blech32: add blech32m format and use it to decode witness v1+ addresses (Andrew Poelstra)
18fcec8 naming nits (Fabian Jahr)
8515f40 Add signet support to gen_key_io_test_vectors.py (Pieter Wuille)
b3df66f Use Bech32m encoding for v1+ segwit addresses (Pieter Wuille)
42f43a1 Add Bech32m test vectors (Pieter Wuille)
b1d1d94 Implement Bech32m encoding/decoding (Pieter Wuille)
c607835 Better error messages for invalid addresses (Bezdrighin)

Pull request description:

  Includes backports of bitcoin/bitcoin#20832 (1 commit) and bitcoin/bitcoin#20861 (5 commits)

ACKs for top commit:
  gwillen:
    utACK c72c949.

Tree-SHA512: af96a6ef31b1cab72b0350197dcb34761e9ffb2ec43685084408b5fafcda0adee1945045003194600372652f7cca65d721bda3ed9b6be7e9543d3199e2cbe145
janus pushed a commit to BitgesellOfficial/bitgesell that referenced this pull request Oct 24, 2021
+ Detailed error messages for invalid address
+ Used `IsValidDestination` instead of `IsValidDestinationString`
+ Referred to bitcoin/bitcoin#20832 for solution
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Aug 18, 2022
@fanquake
Copy link
Member

This change was part of 22.0, removing "Needs release note".

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

Successfully merging this pull request may close these issues.

None yet