diff options
author | Ava Chow <github@achow101.com> | 2024-05-06 12:24:09 -0400 |
---|---|---|
committer | Ava Chow <github@achow101.com> | 2024-05-06 12:24:09 -0400 |
commit | 63d0b930f821132badd804822a46232a5f98bbef (patch) | |
tree | c54b865fbe9e8eebed5595b4453a765fd2b7e390 /src/warnings.cpp | |
parent | fdb41e08c4a4fb2743f8ca7c4b8dac52a460e864 (diff) | |
parent | 42fb5311b19582361409d65c6fddeadbee14bb97 (diff) | |
download | bitcoin-63d0b930f821132badd804822a46232a5f98bbef.tar.xz |
Merge bitcoin/bitcoin#29845: rpc: return warnings as an array instead of just a single one
42fb5311b19582361409d65c6fddeadbee14bb97 rpc: return warnings as an array instead of just a single one (stickies-v)
Pull request description:
The RPC documentation for `getblockchaininfo`, `getmininginfo` and `getnetworkinfo` 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:
- when `GetWarnings` was introduced in 401926283a200994ecd7df8eae8ced8e0b067c46, it was used in the `getinfo` RPC, where only a [single error/warning was returned](https://github.com/bitcoin/bitcoin/commit/401926283a200994ecd7df8eae8ced8e0b067c46#diff-7442c48d42cd5455a79915a0f00cce5e13359db46437a32b812876edb0a5ccddR250) (similar to how it is now).
- later on, "warnings" RPC response fields were introduced, e.g. in ef2a3de25c882396e1776b554878d2784b6b7391, with the description [stating](https://github.com/bitcoin/bitcoin/commit/ef2a3de25c882396e1776b554878d2784b6b7391#diff-1021bd3c74415ad9719bd764ad6ca35af5dfb33b1cd863c0be49bdf52518af54R411) that it returned "any network warnings" but in practice still only a single warning was returned
ACKs for top commit:
achow101:
re-ACK 42fb5311b19582361409d65c6fddeadbee14bb97
tdb3:
Re ACK for 42fb5311b19582361409d65c6fddeadbee14bb97
TheCharlatan:
ACK 42fb5311b19582361409d65c6fddeadbee14bb97
maflcko:
ACK 42fb5311b19582361409d65c6fddeadbee14bb97 🔺
Tree-SHA512: 4225ed8979cd5f030dec785a80e7452a041ad5703445da79d2906ada983ed0bbe7b15889d663d75aae4a77d92e302c93e93eca185c7bd47c9cce29e12f752bd3
Diffstat (limited to 'src/warnings.cpp')
-rw-r--r-- | src/warnings.cpp | 24 |
1 files changed, 8 insertions, 16 deletions
diff --git a/src/warnings.cpp b/src/warnings.cpp index d55eecc48d..0b1af9b9f0 100644 --- a/src/warnings.cpp +++ b/src/warnings.cpp @@ -11,7 +11,6 @@ #include <common/system.h> #include <sync.h> -#include <util/string.h> #include <util/translation.h> #include <optional> @@ -39,37 +38,30 @@ void SetMedianTimeOffsetWarning(std::optional<bilingual_str> warning) LOCK(g_warnings_mutex); g_timeoffset_warning = warning; } -bilingual_str GetWarnings(bool verbose) + +std::vector<bilingual_str> GetWarnings() { - bilingual_str warnings_concise; - std::vector<bilingual_str> warnings_verbose; + std::vector<bilingual_str> warnings; LOCK(g_warnings_mutex); // Pre-release build warning if (!CLIENT_VERSION_IS_RELEASE) { - warnings_concise = _("This is a pre-release test build - use at your own risk - do not use for mining or merchant applications"); - warnings_verbose.emplace_back(warnings_concise); + warnings.emplace_back(_("This is a pre-release test build - use at your own risk - do not use for mining or merchant applications")); } // Misc warnings like out of disk space and clock is wrong if (!g_misc_warnings.empty()) { - warnings_concise = g_misc_warnings; - warnings_verbose.emplace_back(warnings_concise); + warnings.emplace_back(g_misc_warnings); } if (fLargeWorkInvalidChainFound) { - warnings_concise = _("Warning: We do not appear to fully agree with our peers! You may need to upgrade, or other nodes may need to upgrade."); - warnings_verbose.emplace_back(warnings_concise); + warnings.emplace_back(_("Warning: We do not appear to fully agree with our peers! You may need to upgrade, or other nodes may need to upgrade.")); } if (g_timeoffset_warning) { - warnings_verbose.emplace_back(g_timeoffset_warning.value()); - } - - if (verbose) { - return Join(warnings_verbose, Untranslated("<hr />")); + warnings.emplace_back(g_timeoffset_warning.value()); } - return warnings_concise; + return warnings; } |