-
Notifications
You must be signed in to change notification settings - Fork 38.7k
Return more specific errors about invalid descriptors #16542
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
Conversation
|
Descriptors are hard to parse, they should be hard to write also. Eh, I mean, big concept ACK. |
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, 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. |
|
Concept ACK
|
1 similar comment
|
Concept ACK |
promag
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concept ACK, nice to have a detailed error.
|
Concept ACK. |
Sjors
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK dae2590
This introduces a fun little trick if you're too lazy to call getdescriptorinfo to obtain the checkum: you can instead set the checksum to 00000000.
$ bitcoin-cli importmulti '[{"desc": "sh(wpkh(03fff97bd5755eeea420453a14355235d382f6472f8568a18b2f057a1460297556))#00000000", "timestamp": "now"}]'
[
{
"success": false,
"error": {
"code": -5,
"message": "Descriptor is invalid, Provided checksum '00000000' does not match computed checksum 'qkrrc7je'"
}
}
]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: make descriptor errors start with lower case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nah.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree with @Sjors, is there a reason to not do so? I was going to suggest to drop "Descriptor is invalid, " prefix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've just removed the prefixes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They're back
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They're back
No??
dae2590 to
0d55f50
Compare
src/test/descriptor_tests.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: expected_error could be const ref?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
promag
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I've bookmarked all errors without a test - not saying you should add them here, I'm happy to improve in a follow up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree with @Sjors, is there a reason to not do so? I was going to suggest to drop "Descriptor is invalid, " prefix.
0d55f50 to
a1b4795
Compare
|
I've added more tests and also cleaned up a few typos in error messages. |
|
reACK a1b47955838f1151fc1904d0ff3bc7751b9fa7ca |
|
Code Review ACK a1b47955838f1151fc1904d0ff3bc7751b9fa7ca |
instagibbs
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tACK
the errors I encountered during initial usage of descriptors are all caught here, and enough information to quickly figure out what I did wrong.
f.e.
getdescriptorinfo "multi(1, 03a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd,04a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd5b8dec5235a0fa8722476c7709c02559e3aa73aa03918ba2d492eea75abea235)"
error code: -5
error message:
key ' 03a34b99f22c790c4e36b2b3c2c35a36db06226e41c692fc82b8b56ac1c540c5bd' is not valid
^ space after comma
src/script/descriptor.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where would this case be hit previously?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would fail below at the extkey decoding stuff.
src/script/descriptor.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where would this case be hit previously?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would just get to the end of the function and hit return nullptr.
src/script/descriptor.cpp
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I'd prefer it also checks for !Func explicitly, since there are a number of combinations, and a generic error is preferable to a specific error that's an implementation mistake.
There was a problem hiding this comment.
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 can check that there is no function.
|
If you need to make any changes, I suggest rebasing due to #14934 to be on the safe side. It still compiles and tests pass for me when I do that rebase locally though. |
| Needs rebase |
|
Sorry about the rebase again due to #15986 Once this is rebased I'll review and merge |
Some failure conditions implicitly fail by failing some other check. But the error messages are more helpful if they say explicitly what actually caused the failure, so add those as failure conditions and errors.
|
Rebased |
a1b4795 to
787c9ec
Compare
Sjors
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only the first commit changed in this rebase, but you lost a few of your recent fixes in the process.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They're back
No??? Are you sure you're looking at the right commits? The latest diff includes everything that was commented on earlier. |
meshcollider
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code review ACK 787c9ec
This is a nice change, one tiny nit but it is pretty insignificant so I'll merge this tomorrow if you don't have time to fix it now
| if (origin_split.size() == 1) return ParsePubkeyInner(origin_split[0], permit_uncompressed, out, error); | ||
| if (origin_split[0].size() < 1 || origin_split[0][0] != '[') { | ||
| error = strprintf("Key origin expected but not found, got '%s' instead", std::string(origin_split[0].begin(), origin_split[0].end())); | ||
| error = strprintf("Key origin start '[ character expected but not found, got '%c' instead", origin_split[0][0]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mismatched ' (also in the corresponding test case)
787c9ec Additional tests for other failure cases (Andrew Chow) 6e1ae58 Check error messages in descriptor tests (Andrew Chow) 625534d Give more errors for specific failure conditions (Andrew Chow) c325f61 Return an error from descriptor Parse that gives more information about what failed (Andrew Chow) Pull request description: Because it's nigh impossible to figure out what is wrong with a descriptor otherwise. ACKs for top commit: Sjors: ACK 787c9ec meshcollider: Code review ACK 787c9ec Tree-SHA512: 07c5deff127fd65507b96df2e4608b4f918e0cbd20b3b45b9ab5a05c2985a6efa9832079cf1e7f504305bfbb861019e93b96cc1574dd63b2ff0756b5928ece20
…ptors 787c9ec Additional tests for other failure cases (Andrew Chow) 6e1ae58 Check error messages in descriptor tests (Andrew Chow) 625534d Give more errors for specific failure conditions (Andrew Chow) c325f61 Return an error from descriptor Parse that gives more information about what failed (Andrew Chow) Pull request description: Because it's nigh impossible to figure out what is wrong with a descriptor otherwise. ACKs for top commit: Sjors: ACK 787c9ec meshcollider: Code review ACK 787c9ec Tree-SHA512: 07c5deff127fd65507b96df2e4608b4f918e0cbd20b3b45b9ab5a05c2985a6efa9832079cf1e7f504305bfbb861019e93b96cc1574dd63b2ff0756b5928ece20
… more information about what failed Summary: bitcoin/bitcoin@c325f61 --- Depends on D6641 Partial backport of Core [[bitcoin/bitcoin#16542 | PR16542]] Test Plan: ninja check ninja test_runner.py wallet_importmulti Reviewers: #bitcoin_abc, deadalnix Reviewed By: #bitcoin_abc, deadalnix Differential Revision: https://reviews.bitcoinabc.org/D6642
Summary: Some failure conditions implicitly fail by failing some other check. But the error messages are more helpful if they say explicitly what actually caused the failure, so add those as failure conditions and errors. bitcoin/bitcoin@625534d --- Depends on D6642 Partial backport of Core [[bitcoin/bitcoin#16542 | PR16542]] Test Plan: ninja check-all Reviewers: #bitcoin_abc, deadalnix Reviewed By: #bitcoin_abc, deadalnix Differential Revision: https://reviews.bitcoinabc.org/D6643
Summary: bitcoin/bitcoin@6e1ae58 --- Depends on D6643 Partial backport of Core [[bitcoin/bitcoin#16542 | PR16542]] Test Plan: ninja check Reviewers: #bitcoin_abc, deadalnix Reviewed By: #bitcoin_abc, deadalnix Subscribers: deadalnix Differential Revision: https://reviews.bitcoinabc.org/D6648
Summary: bitcoin/bitcoin@787c9ec --- Depends on D6648 Concludes backport of Core [[bitcoin/bitcoin#16542 | PR16542]] Test Plan: ninja check Reviewers: #bitcoin_abc, deadalnix Reviewed By: #bitcoin_abc, deadalnix Subscribers: deadalnix Differential Revision: https://reviews.bitcoinabc.org/D6649
Because it's nigh impossible to figure out what is wrong with a descriptor otherwise.