Skip to content

Commit

Permalink
Merge #6061: backport: Merge bitcoin#(partial) 24355, 24797
Browse files Browse the repository at this point in the history
e5e0b00 Merge bitcoin#24797: test: compare `/chaininfo` response with `getblockchaininfo` RPC (MarcoFalke)
39bca40 (partial) Merge bitcoin#24355: util, refactor: Add UNIQUE_NAME helper macro (laanwj)

Pull request description:

  bitcoin backports

ACKs for top commit:
  PastaPastaPasta:
    utACK e5e0b00

Tree-SHA512: 82d68090935b47b63c1f09ffcc660277b3054e60b96b455fb81dfd4b6180ec272df943bd4c1691a2cdbc76da668f362cd42653fa67a8fd2d44197ab316bbd36f
  • Loading branch information
PastaPastaPasta committed Sep 3, 2024
2 parents 7a9e475 + e5e0b00 commit 0472a07
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/logging/timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ class Timer


#define LOG_TIME_MICROS_WITH_CATEGORY(end_msg, log_category) \
BCLog::Timer<std::chrono::microseconds> PASTE2(logging_timer, __COUNTER__)(__func__, end_msg, log_category)
BCLog::Timer<std::chrono::microseconds> UNIQUE_NAME(logging_timer)(__func__, end_msg, log_category)
#define LOG_TIME_MILLIS_WITH_CATEGORY(end_msg, log_category) \
BCLog::Timer<std::chrono::milliseconds> PASTE2(logging_timer, __COUNTER__)(__func__, end_msg, log_category)
BCLog::Timer<std::chrono::milliseconds> UNIQUE_NAME(logging_timer)(__func__, end_msg, log_category)
#define LOG_TIME_SECONDS(end_msg) \
BCLog::Timer<std::chrono::seconds> PASTE2(logging_timer, __COUNTER__)(__func__, end_msg)
BCLog::Timer<std::chrono::seconds> UNIQUE_NAME(logging_timer)(__func__, end_msg)


#endif // BITCOIN_LOGGING_TIMER_H
6 changes: 3 additions & 3 deletions src/sync.h
Original file line number Diff line number Diff line change
Expand Up @@ -298,15 +298,15 @@ class SCOPED_LOCKABLE SharedLock : public Base
}
};

#define REVERSE_LOCK(g) typename std::decay<decltype(g)>::type::reverse_lock PASTE2(revlock, __COUNTER__)(g, #g, __FILE__, __LINE__)
#define REVERSE_LOCK(g) typename std::decay<decltype(g)>::type::reverse_lock UNIQUE_NAME(revlock)(g, #g, __FILE__, __LINE__)

template<typename MutexArg>
using DebugLock = UniqueLock<typename std::remove_reference<typename std::remove_pointer<MutexArg>::type>::type>;
template<typename MutexArg>
using ReadLock = SharedLock<typename std::remove_reference<typename std::remove_pointer<MutexArg>::type>::type>;

#define LOCK(cs) DebugLock<decltype(cs)> PASTE2(criticalblock, __COUNTER__)(cs, #cs, __FILE__, __LINE__)
#define READ_LOCK(cs) ReadLock<decltype(cs)> PASTE2(criticalblock, __COUNTER__)(cs, #cs, __FILE__, __LINE__)
#define LOCK(cs) DebugLock<decltype(cs)> UNIQUE_NAME(criticalblock)(cs, #cs, __FILE__, __LINE__)
#define READ_LOCK(cs) ReadLock<decltype(cs)> UNIQUE_NAME(criticalblock)(cs, #cs, __FILE__, __LINE__)
#define LOCK2(cs1, cs2) \
DebugLock<decltype(cs1)> criticalblock1(cs1, #cs1, __FILE__, __LINE__); \
DebugLock<decltype(cs2)> criticalblock2(cs2, #cs2, __FILE__, __LINE__);
Expand Down
2 changes: 1 addition & 1 deletion src/test/util/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion src/util/epochguard.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#define BITCOIN_UTIL_EPOCHGUARD_H

#include <threadsafety.h>
#include <util/macros.h>

#include <cassert>

Expand Down Expand Up @@ -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
2 changes: 2 additions & 0 deletions src/util/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down
4 changes: 4 additions & 0 deletions test/functional/interface_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 0472a07

Please sign in to comment.