-
Notifications
You must be signed in to change notification settings - Fork 35.5k
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: return warnings as an array instead of just a single one #29845
Conversation
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code CoverageFor detailed information about the code coverage, see the test coverage report. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. ConflictsNo conflicts as of last run. |
🚧 At least one of the CI tasks failed. Make sure to run all tests locally, according to the Possibly this is due to a silent merge conflict (the changes in this pull request being Leave a comment here, if you need help tracking down a confusing failure. |
7b40542
to
4b82191
Compare
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 for 4b82191
Nice addition and great opportunistic cleanup of GetWarnings()
.
Built and ran all unit and functional tests (all passed).
On signet, tested by running getblockchaininfo
with
- no warnings, by supressing the pre-release warning with
if (false && !CLIENT_VERSION_IS_RELEASE)
and rebuilding, - one warning (the pre-release warning)
- two warnings, the pre-release warning and date/time warning by manually setting the system clock back two days before starting bitcoind
All three cases seemed to work without issue.
The only difference observed vs master is that when no warnings are present, master returns an empty string of warnings vs this PR returning an empty array. This was touched on in the description of the PR. I agree that adding a -deprecatedrpc
option does seem like a bit of overkill. IMHO the release notes addition should help inform users.
Left one minor nit.
No warnings:
dev@bdev01:~/bitcoin$ src/bitcoin-cli -signet getblockchaininfo
{
"chain": "signet",
"blocks": 0,
"headers": 20634,
"bestblockhash": "00000008819873e925422c1ff0f99f7cc9bbb232af63a077a480a3633bee1ef6",
"difficulty": 0.001126515290698186,
"time": 1598918400,
"mediantime": 1598918400,
"verificationprogress": 4.029370408440712e-07,
"initialblockdownload": true,
"chainwork": "000000000000000000000000000000000000000000000000000000000049d414",
"size_on_disk": 7872875,
"pruned": false,
"warnings": [
]
}
One warning:
dev@bdev01:~/bitcoin$ src/bitcoin-cli -signet getblockchaininfo
{
"chain": "signet",
"blocks": 0,
"headers": 7358,
"bestblockhash": "00000008819873e925422c1ff0f99f7cc9bbb232af63a077a480a3633bee1ef6",
"difficulty": 0.001126515290698186,
"time": 1598918400,
"mediantime": 1598918400,
"verificationprogress": 4.029367626439888e-07,
"initialblockdownload": true,
"chainwork": "000000000000000000000000000000000000000000000000000000000049d414",
"size_on_disk": 2890410,
"pruned": false,
"warnings": [
"This is a pre-release test build - use at your own risk - do not use for mining or merchant applications"
]
}
Two warnings:
dev@bdev01:~/bitcoin$ src/bitcoin-cli -signet getblockchaininfo
{
"chain": "signet",
"blocks": 0,
"headers": 30645,
"bestblockhash": "00000008819873e925422c1ff0f99f7cc9bbb232af63a077a480a3633bee1ef6",
"difficulty": 0.001126515290698186,
"time": 1598918400,
"mediantime": 1598918400,
"verificationprogress": 4.032686769779725e-07,
"initialblockdownload": true,
"chainwork": "000000000000000000000000000000000000000000000000000000000049d414",
"size_on_disk": 12258274,
"pruned": false,
"warnings": [
"This is a pre-release test build - use at your own risk - do not use for mining or merchant applications",
"Please check that your computer's date and time are correct! If your clock is wrong, Bitcoin Core will not work properly."
]
}
* @returns the warning string | ||
*/ | ||
bilingual_str GetWarnings(bool verbose); | ||
/** Return potential problems detected by the node. */ |
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: Looks like the old function comment header used Doxygen syntax. Would recommend keeping this style, but feel free to disregard this nit since the return type seems straightforward, and the function is small/digestible.
diff --git a/src/warnings.h b/src/warnings.h
index 0b8eb2c9a1..4ae05d4862 100644
--- a/src/warnings.h
+++ b/src/warnings.h
@@ -12,7 +12,10 @@ struct bilingual_str;
void SetMiscWarning(const bilingual_str& warning);
void SetfLargeWorkInvalidChainFound(bool flag);
-/** Return potential problems detected by the node. */
+/** Return potential problems detected by the node.
+ *
+ * @returns each warning string as a vector element.
+ */
std::vector<bilingual_str> GetWarnings();
#endif // BITCOIN_WARNINGS_H
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 generally tend to prefer to doxygen-ify documentation, but in this case I'm not sure the extra line adds anything over the return type and function name, so then is it just unnecessary boilerplate that makes the documentation less instead of more clear? No strong view either way, so will leave this open.
This is something that we should have done a long time ago imo. I wouldn't be surprised if I have an ancient PR doing just this. |
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.
Left some stupid style nits. Leave a comment if you want to ignore them or address them.
very nice. Thanks for fixing this. ACK 4b82191 🛏
Show signature
Signature:
untrusted comment: signature from minisign secret key on empty file; verify via: minisign -Vm "${path_to_any_empty_file}" -P RWTRmVTMeKV5noAMqVlsMugDDCyyTSbA3Re5AkUrhvLVln0tSaFWglOw -x "${path_to_this_whole_four_line_signature_blob}"
RUTRmVTMeKV5npGrKx1nqXCw5zeVHdtdYURB/KlyA/LMFgpNCs+SkW9a8N95d+U4AP1RJMi+krxU1A3Yux4bpwZNLvVBKy0wLgM=
trusted comment: very nice. Thanks for fixing this. ACK 4b821915bf92082043d6cf60efb1a5faea0151db 🛏
2C4/MGb7Zt2VKd0SexvYcgZQplu/bak1Sxc/jU7RHsNG2P6rqMRriRgrMxJ5xP/EzEPad6wnaHJycRWZEhfyDA==
*/ | ||
bilingual_str GetWarnings(bool verbose); | ||
/** Return potential problems detected by the node. */ | ||
std::vector<bilingual_str> GetWarnings(); | ||
|
||
#endif // BITCOIN_WARNINGS_H |
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.
unrelated follow-up idea: It seems wrong to have the warnings module in the common
library, when it is using globals to keep track of the warnings.
I guess it would be nice to actually move it to the node
library, and node
namespace?
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.
Agreed, that looks like a nice follow-up. Happy to have a go after this gets merged.
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.
Happy to have a go after this gets merged.
Implemented in master...stickies-v:bitcoin:2024-04/move-warnings-node
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 it is better off in the kernel library eventually: https://github.com/bitcoin/bitcoin/pull/28690/files#diff-4cb884d03ebb901069e4ee5de5d02538c40dd9b39919c615d8eaa9d364bbbd77R735
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.
kernel
I guess it is a bit odd to have g_timeoffset_warning
in the kernel, but happy to review either approach.
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 guess it would be nice to actually move it to the node library, and node namespace?
Done in #30058
4b82191
to
7cad21a
Compare
Thanks for the reviews everyone. Force-pushed to address maflcko's style nits. Otherwise no changes so should be a quick re-review. CI failure unrelated: #29831 |
scanblocks CI failure is known, unrelated, and can be ignored. re-ACK 7cad21a 🛵 Show signatureSignature:
|
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.
ltgm.
cr re ACK for 7cad21a
7cad21a
to
60b4334
Compare
Force pushed to add |
60b4334
to
7b64820
Compare
🚧 At least one of the CI tasks failed. Make sure to run all tests locally, according to the Possibly this is due to a silent merge conflict (the changes in this pull request being Leave a comment here, if you need help tracking down a confusing failure. |
ACK 7b64820 |
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.
Approach ACK.
Re-ran the sanity checks in #29845 (review)
All were successful.
Tried testing out the -deprecatedrpc=warnings
functionality. I'm guessing I'm missing something simple/trivial (or improperly using -deprecatedrpc
). When running src/bitcoind -deprecatedrpc=warnings
, both curl and bitcoin-cli returned an error:
curl:
$ curl --user __cookie__ --data-binary '{"id": "curltest", "method": "getblockchaininfo", "params": []}' -H 'content-type: text/plain;' http://127.0.0.1:38332/
Enter host password for user '__cookie__':
{"result":null,"error":{"code":-1,"message":"Internal bug detected: RPC call \"getblockchaininfo\" returned incorrect type:\n{\n \"warnings\": \"returned type is string, but declared as array in doc\"\n}\nBitcoin Core v27.99.0-7b64820da65d-dirty\nPlease report this issue here: https://github.com/bitcoin/bitcoin/issues\n"},"id":"curltest"}
bitcoin-cli:
$ src/bitcoin-cli -signet getblockchaininfo
error code: -1
error message:
Internal bug detected: RPC call "getblockchaininfo" returned incorrect type:
{
"warnings": "returned type is string, but declared as array in doc"
}
Bitcoin Core v27.99.0-7b64820da65d-dirty
Please report this issue here: https://github.com/bitcoin/bitcoin/issues
I did some quick searching and also checked for -help
output for "deprecatedrpc" for usage (both bitcoind and bitcoin-cli), but didn't see anything indicating appropriate usage.
7b64820
to
07cb2ca
Compare
I suspect you're running with Thanks for your diligent re-review! |
ACK for 07cb2ca I hadn't explicitly been running with
|
07cb2ca
to
b716e02
Compare
The RPC documentation for `getblockchaininfo`, `getmininginfo` and `getnetworkinfo` states that "warnings" returns "any network and blockchain warnings". In practice, only a single warning is returned. Fix that by returning all warnings as an array. As a side benefit, cleans up the GetWarnings() logic.
b716e02
to
42fb531
Compare
re-ACK 42fb531 |
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.
Re ACK for 42fb531
Ran the tests in #29845 (comment) and #29845 (review) again (no warnings, one warning, two warnings, and with -deprecatedrpc
with one warning). All behaved as expected.
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 42fb531
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 42fb531 🔺
Show signature
Signature:
untrusted comment: signature from minisign secret key on empty file; verify via: minisign -Vm "${path_to_any_empty_file}" -P RWTRmVTMeKV5noAMqVlsMugDDCyyTSbA3Re5AkUrhvLVln0tSaFWglOw -x "${path_to_this_whole_four_line_signature_blob}"
RUTRmVTMeKV5npGrKx1nqXCw5zeVHdtdYURB/KlyA/LMFgpNCs+SkW9a8N95d+U4AP1RJMi+krxU1A3Yux4bpwZNLvVBKy0wLgM=
trusted comment: ACK 42fb5311b19582361409d65c6fddeadbee14bb97 🔺
DkZcGaegmeNqao4OyqKkZvPK1NSWofgTqWxVDrmqPuY4EZlSajPN8iz8kpunlYESlSl31ykCX/U9HS/4bHoUCQ==
- the `warnings` field in `getblockchaininfo`, `getmininginfo` and | ||
`getnetworkinfo` now returns all the active node warnings as an array | ||
of strings, instead of just a single warning. The current behaviour | ||
can temporarily be restored by running bitcoind with configuration |
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.
can temporarily be restored by running bitcoind with configuration | |
can temporarily be restored by running with configuration |
nit (only if you re-touch): Could remove the executable name, as it can be bitcoin-qt
as well, or a different name.
The RPC documentation for
getblockchaininfo
,getmininginfo
andgetnetworkinfo
states that "warnings" returns "any network and blockchain warnings". In practice, only a single warning (i.e. the latest one that is set) is returned, the other ones are ignored.Fix that by returning all warnings as an array.
As a side benefit, clean up the GetWarnings() logic.
Since this PR changes the RPC result schema, I've added release notes. Users can temporarily revert to the old results by using
-deprecatedrpc=warnings
, until it's removed in a future version.Some historical context from git log:
GetWarnings
was introduced in 4019262, it was used in thegetinfo
RPC, where only a single error/warning was returned (similar to how it is now).