mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-04 13:55:23 -05:00
node: Track last block that received a blockTip notification
Also signal m_tip_block_cv when StopRPC is called, for consistency with g_best_block_cv. This is handled in StopRPC instead of OnRPCStopped() because the latter is deleted in a later commit. Co-authored-by: TheCharlatan <seb.kung@gmail.com> Co-authored-by: Ryan Ofsky <ryan@ofsky.org>
This commit is contained in:
parent
ebb8215f23
commit
7eccdaf160
6 changed files with 27 additions and 6 deletions
|
@ -284,7 +284,7 @@ void Shutdown(NodeContext& node)
|
||||||
|
|
||||||
StopHTTPRPC();
|
StopHTTPRPC();
|
||||||
StopREST();
|
StopREST();
|
||||||
StopRPC();
|
StopRPC(&node);
|
||||||
StopHTTPServer();
|
StopHTTPServer();
|
||||||
for (const auto& client : node.chain_clients) {
|
for (const auto& client : node.chain_clients) {
|
||||||
client->flush();
|
client->flush();
|
||||||
|
|
|
@ -139,7 +139,7 @@ public:
|
||||||
// Stop RPC for clean shutdown if any of waitfor* commands is executed.
|
// Stop RPC for clean shutdown if any of waitfor* commands is executed.
|
||||||
if (args().GetBoolArg("-server", false)) {
|
if (args().GetBoolArg("-server", false)) {
|
||||||
InterruptRPC();
|
InterruptRPC();
|
||||||
StopRPC();
|
StopRPC(m_context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bool shutdownRequested() override { return ShutdownRequested(*Assert(m_context)); };
|
bool shutdownRequested() override { return ShutdownRequested(*Assert(m_context)); };
|
||||||
|
|
|
@ -50,6 +50,12 @@ namespace node {
|
||||||
|
|
||||||
kernel::InterruptResult KernelNotifications::blockTip(SynchronizationState state, CBlockIndex& index)
|
kernel::InterruptResult KernelNotifications::blockTip(SynchronizationState state, CBlockIndex& index)
|
||||||
{
|
{
|
||||||
|
{
|
||||||
|
LOCK(m_tip_block_mutex);
|
||||||
|
m_tip_block = index.GetBlockHash();
|
||||||
|
m_tip_block_cv.notify_all();
|
||||||
|
}
|
||||||
|
|
||||||
uiInterface.NotifyBlockTip(state, &index);
|
uiInterface.NotifyBlockTip(state, &index);
|
||||||
if (m_stop_at_height && index.nHeight >= m_stop_at_height) {
|
if (m_stop_at_height && index.nHeight >= m_stop_at_height) {
|
||||||
if (!m_shutdown()) {
|
if (!m_shutdown()) {
|
||||||
|
|
|
@ -7,6 +7,10 @@
|
||||||
|
|
||||||
#include <kernel/notifications_interface.h>
|
#include <kernel/notifications_interface.h>
|
||||||
|
|
||||||
|
#include <sync.h>
|
||||||
|
#include <threadsafety.h>
|
||||||
|
#include <uint256.h>
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
|
@ -34,7 +38,7 @@ public:
|
||||||
KernelNotifications(util::SignalInterrupt& shutdown, std::atomic<int>& exit_status, node::Warnings& warnings)
|
KernelNotifications(util::SignalInterrupt& shutdown, std::atomic<int>& exit_status, node::Warnings& warnings)
|
||||||
: m_shutdown(shutdown), m_exit_status{exit_status}, m_warnings{warnings} {}
|
: m_shutdown(shutdown), m_exit_status{exit_status}, m_warnings{warnings} {}
|
||||||
|
|
||||||
[[nodiscard]] kernel::InterruptResult blockTip(SynchronizationState state, CBlockIndex& index) override;
|
[[nodiscard]] kernel::InterruptResult blockTip(SynchronizationState state, CBlockIndex& index) override EXCLUSIVE_LOCKS_REQUIRED(!m_tip_block_mutex);
|
||||||
|
|
||||||
void headerTip(SynchronizationState state, int64_t height, int64_t timestamp, bool presync) override;
|
void headerTip(SynchronizationState state, int64_t height, int64_t timestamp, bool presync) override;
|
||||||
|
|
||||||
|
@ -52,6 +56,12 @@ public:
|
||||||
int m_stop_at_height{DEFAULT_STOPATHEIGHT};
|
int m_stop_at_height{DEFAULT_STOPATHEIGHT};
|
||||||
//! Useful for tests, can be set to false to avoid shutdown on fatal error.
|
//! Useful for tests, can be set to false to avoid shutdown on fatal error.
|
||||||
bool m_shutdown_on_fatal_error{true};
|
bool m_shutdown_on_fatal_error{true};
|
||||||
|
|
||||||
|
Mutex m_tip_block_mutex;
|
||||||
|
std::condition_variable m_tip_block_cv;
|
||||||
|
//! The block for which the last blockTip notification was received for.
|
||||||
|
uint256 m_tip_block;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
util::SignalInterrupt& m_shutdown;
|
util::SignalInterrupt& m_shutdown;
|
||||||
std::atomic<int>& m_exit_status;
|
std::atomic<int>& m_exit_status;
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include <common/system.h>
|
#include <common/system.h>
|
||||||
#include <logging.h>
|
#include <logging.h>
|
||||||
#include <node/context.h>
|
#include <node/context.h>
|
||||||
|
#include <node/kernel_notifications.h>
|
||||||
#include <rpc/server_util.h>
|
#include <rpc/server_util.h>
|
||||||
#include <rpc/util.h>
|
#include <rpc/util.h>
|
||||||
#include <sync.h>
|
#include <sync.h>
|
||||||
|
@ -311,16 +312,19 @@ void InterruptRPC()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void StopRPC()
|
void StopRPC(const std::any& context)
|
||||||
{
|
{
|
||||||
static std::once_flag g_rpc_stop_flag;
|
static std::once_flag g_rpc_stop_flag;
|
||||||
// This function could be called twice if the GUI has been started with -server=1.
|
// This function could be called twice if the GUI has been started with -server=1.
|
||||||
assert(!g_rpc_running);
|
assert(!g_rpc_running);
|
||||||
std::call_once(g_rpc_stop_flag, []() {
|
std::call_once(g_rpc_stop_flag, [&]() {
|
||||||
LogDebug(BCLog::RPC, "Stopping RPC\n");
|
LogDebug(BCLog::RPC, "Stopping RPC\n");
|
||||||
WITH_LOCK(g_deadline_timers_mutex, deadlineTimers.clear());
|
WITH_LOCK(g_deadline_timers_mutex, deadlineTimers.clear());
|
||||||
DeleteAuthCookie();
|
DeleteAuthCookie();
|
||||||
g_rpcSignals.Stopped();
|
g_rpcSignals.Stopped();
|
||||||
|
node::NodeContext& node = EnsureAnyNodeContext(context);
|
||||||
|
// The notifications interface doesn't exist between initialization step 4a and 7.
|
||||||
|
if (node.notifications) node.notifications->m_tip_block_cv.notify_all();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include <rpc/request.h>
|
#include <rpc/request.h>
|
||||||
#include <rpc/util.h>
|
#include <rpc/util.h>
|
||||||
|
|
||||||
|
#include <any>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
@ -178,7 +179,7 @@ extern CRPCTable tableRPC;
|
||||||
|
|
||||||
void StartRPC();
|
void StartRPC();
|
||||||
void InterruptRPC();
|
void InterruptRPC();
|
||||||
void StopRPC();
|
void StopRPC(const std::any& context);
|
||||||
UniValue JSONRPCExec(const JSONRPCRequest& jreq, bool catch_errors);
|
UniValue JSONRPCExec(const JSONRPCRequest& jreq, bool catch_errors);
|
||||||
|
|
||||||
#endif // BITCOIN_RPC_SERVER_H
|
#endif // BITCOIN_RPC_SERVER_H
|
||||||
|
|
Loading…
Add table
Reference in a new issue