From 39bca402a07c1875d104325846ec8292134d31f0 Mon Sep 17 00:00:00 2001 From: laanwj <126646+laanwj@users.noreply.github.com> Date: Wed, 13 Apr 2022 22:32:45 +0200 Subject: [PATCH 1/2] (partial) Merge bitcoin/bitcoin#24355: util, refactor: Add UNIQUE_NAME helper macro 1633f5ec8846408182cceb60dc88f022635f4002 util, refactor: Add UNIQUE_NAME helper macro (Hennadii Stepanov) Pull request description: This PR replaces repetitive code with a helper macro. ACKs for top commit: laanwj: Tested ACK 1633f5ec8846408182cceb60dc88f022635f4002 Tree-SHA512: 5f04e472c5f3184c0a9df75395377c6744bfb2cd8f95f8427c1c5e20daa7d6a9b29e45424b88391fc6326d365907a750ab50fda534b49d1df80dccf0e18467a4 Signed-off-by: Vijay --- src/logging/timer.h | 6 +++--- src/sync.h | 6 +++--- src/test/util/logging.h | 2 +- src/util/epochguard.h | 3 ++- src/util/macros.h | 2 ++ 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/logging/timer.h b/src/logging/timer.h index 79627b1fe31a2..80835af5e22d2 100644 --- a/src/logging/timer.h +++ b/src/logging/timer.h @@ -88,11 +88,11 @@ class Timer #define LOG_TIME_MICROS_WITH_CATEGORY(end_msg, log_category) \ - BCLog::Timer PASTE2(logging_timer, __COUNTER__)(__func__, end_msg, log_category) + BCLog::Timer UNIQUE_NAME(logging_timer)(__func__, end_msg, log_category) #define LOG_TIME_MILLIS_WITH_CATEGORY(end_msg, log_category) \ - BCLog::Timer PASTE2(logging_timer, __COUNTER__)(__func__, end_msg, log_category) + BCLog::Timer UNIQUE_NAME(logging_timer)(__func__, end_msg, log_category) #define LOG_TIME_SECONDS(end_msg) \ - BCLog::Timer PASTE2(logging_timer, __COUNTER__)(__func__, end_msg) + BCLog::Timer UNIQUE_NAME(logging_timer)(__func__, end_msg) #endif // BITCOIN_LOGGING_TIMER_H diff --git a/src/sync.h b/src/sync.h index 6a0b87a2c85cd..3712bd9824e5f 100644 --- a/src/sync.h +++ b/src/sync.h @@ -298,15 +298,15 @@ class SCOPED_LOCKABLE SharedLock : public Base } }; -#define REVERSE_LOCK(g) typename std::decay::type::reverse_lock PASTE2(revlock, __COUNTER__)(g, #g, __FILE__, __LINE__) +#define REVERSE_LOCK(g) typename std::decay::type::reverse_lock UNIQUE_NAME(revlock)(g, #g, __FILE__, __LINE__) template using DebugLock = UniqueLock::type>::type>; template using ReadLock = SharedLock::type>::type>; -#define LOCK(cs) DebugLock PASTE2(criticalblock, __COUNTER__)(cs, #cs, __FILE__, __LINE__) -#define READ_LOCK(cs) ReadLock PASTE2(criticalblock, __COUNTER__)(cs, #cs, __FILE__, __LINE__) +#define LOCK(cs) DebugLock UNIQUE_NAME(criticalblock)(cs, #cs, __FILE__, __LINE__) +#define READ_LOCK(cs) ReadLock UNIQUE_NAME(criticalblock)(cs, #cs, __FILE__, __LINE__) #define LOCK2(cs1, cs2) \ DebugLock criticalblock1(cs1, #cs1, __FILE__, __LINE__); \ DebugLock criticalblock2(cs2, #cs2, __FILE__, __LINE__); diff --git a/src/test/util/logging.h b/src/test/util/logging.h index ebe0ecf62331b..f47708839217a 100644 --- a/src/test/util/logging.h +++ b/src/test/util/logging.h @@ -36,6 +36,6 @@ class DebugLogHelper ~DebugLogHelper() { check_found(); } }; -#define ASSERT_DEBUG_LOG(message) DebugLogHelper PASTE2(debugloghelper, __COUNTER__)(message) +#define ASSERT_DEBUG_LOG(message) DebugLogHelper UNIQUE_NAME(debugloghelper)(message) #endif // BITCOIN_TEST_UTIL_LOGGING_H diff --git a/src/util/epochguard.h b/src/util/epochguard.h index 3e63e093daa19..a447f6dbf8d31 100644 --- a/src/util/epochguard.h +++ b/src/util/epochguard.h @@ -7,6 +7,7 @@ #define BITCOIN_UTIL_EPOCHGUARD_H #include +#include #include @@ -96,6 +97,6 @@ class LOCKABLE Epoch } }; -#define WITH_FRESH_EPOCH(epoch) const Epoch::Guard PASTE2(epoch_guard_, __COUNTER__)(epoch) +#define WITH_FRESH_EPOCH(epoch) const Epoch::Guard UNIQUE_NAME(epoch_guard_)(epoch) #endif // BITCOIN_UTIL_EPOCHGUARD_H diff --git a/src/util/macros.h b/src/util/macros.h index 0887c80fd7f1d..3b40a0767e89d 100644 --- a/src/util/macros.h +++ b/src/util/macros.h @@ -8,6 +8,8 @@ #define PASTE(x, y) x ## y #define PASTE2(x, y) PASTE(x, y) +#define UNIQUE_NAME(name) PASTE2(name, __COUNTER__) + /** * Converts the parameter X to a string after macro replacement on X has been performed. * Don't merge these into one macro! From e5e0b00e1e6909054137ef6656df743c82010ed3 Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Mon, 11 Apr 2022 11:04:17 +0200 Subject: [PATCH 2/2] Merge bitcoin/bitcoin#24797: test: compare `/chaininfo` response with `getblockchaininfo` RPC 0f7dc893ea1776515173dcd0bfe6826e963c90f3 test: compare `/chaininfo` response with `getblockchaininfo` RPC (brunoerg) Pull request description: The `/chaininfo` REST endpoint gets its infos from `getblockchaininfo` RPC, so this PR adds an `assert_equal` (in `interface_rest`) to ensure both responses are the same. Obs: other endpoints do the same for their respective RPC. ACKs for top commit: 0xB10C: Concept and Code Review ACK 0f7dc893ea1776515173dcd0bfe6826e963c90f3. Belts-and-spenders. Tree-SHA512: 51cbcf988090272e406a47dc869710740b74e2222af29c05ddcbf53bd49765cdc59efb525e970867f091b3d2efec4fb13371a342d9e484e51144b760265bc5b8 Signed-off-by: Vijay --- test/functional/interface_rest.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/functional/interface_rest.py b/test/functional/interface_rest.py index faa92e6675937..809134e72d86b 100755 --- a/test/functional/interface_rest.py +++ b/test/functional/interface_rest.py @@ -340,5 +340,9 @@ def run_test(self): json_obj = self.test_rest_request("/chaininfo") assert_equal(json_obj['bestblockhash'], bb_hash) + # Compare with normal RPC getblockchaininfo response + blockchain_info = self.nodes[0].getblockchaininfo() + assert_equal(blockchain_info, json_obj) + if __name__ == '__main__': RESTTest().main()