mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-02-11 09:42:17 +01:00
Merge bitcoin/bitcoin#30409: Introduce waitTipChanged() mining interface, replace RPCNotifyBlockChange, drop CRPCSignals & g_best_block
7942951e3fRemove unused g_best_block (Ryan Ofsky)e3a560ca68rpc: use waitTipChanged for longpoll (Ryan Ofsky)460687a09cRemove unused CRPCSignals (Sjors Provoost)dca923150eReplace RPCNotifyBlockChange with waitTipChanged() (Sjors Provoost)2a40ee1121rpc: check for negative timeout arg in waitfor* (Sjors Provoost)de7c855b3arpc: recommend -rpcclienttimeout=0 for waitfor* (Sjors Provoost)77ec072925rpc: fix waitfornewblock description (Sjors Provoost)285fe9fb51rpc: add test for waitforblock and waitfornewblock (Sjors Provoost)b94b27cf05Add waitTipChanged to Mining interface (Sjors Provoost)7eccdaf160node: Track last block that received a blockTip notification (Sjors Provoost)ebb8215f23Rename getTipHash() to getTip() and return BlockRef (Sjors Provoost)89a8f74bbbrefactor: rename BlockKey to BlockRef (Sjors Provoost) Pull request description: This continues the work in #30200 so that a future Stratum v2 Template Provider (see #29432) can avoid accessing node internals. It needs to know when a new block arrives in order to push new templates to connected clients. `waitTipChanged()` uses a new kernel notification `notifications().m_tip_block_mutex`, which this PR also introduces (a previous version used `g_best_block`). In order to ensure the new method works as intended, the `waitfornewblock`, `waitforblock` and `waitforblockheight` RPC methods are refactored to use it. This allows removing `RPCNotifyBlockChange`. There's a commit to add (direct) tests for the methods that are about to be refactored: - `waitfornewblock` was already implicitly tested by `feature_shutdown.py`. - `waitforblockheight` by `feature_coinstatsindex.py` and `example_test.py` This PR renames `getTipHash()` to `getTip()` and returns a `BlockRef` (renamed from `BlockKey`) so that callers can use either the height or hash. The later commits make trivial improvements to the `waitfor*` RPC calls (not needed for this PR). The `waitTipChanged()` method could probably also be used for the longpoll functionality in `getblocktemplate`, but I'm a bit reluctant to touch that. `RPCServer::OnStarted` no longer does anything and `RPCServer::OnStopped` merely prints a log statement. They were added in #5711 as a refactor. This PR drops them entirely. Finally `g_best_block` is also dropped. ACKs for top commit: achow101: ACK7942951e3fryanofsky: Code review ACK7942951e3f. Just rebased since last review TheCharlatan: Re-ACK7942951e3fTree-SHA512: a5559446b4000c95e07aad33284b7ee2e57aafd87e1ae778b3825d59689566d047a8047e47a10f76e6e341e7dc72fd265a65afbc0a9c011d17c4cafd55031837
This commit is contained in:
23
src/init.cpp
23
src/init.cpp
@@ -284,7 +284,7 @@ void Shutdown(NodeContext& node)
|
||||
|
||||
StopHTTPRPC();
|
||||
StopREST();
|
||||
StopRPC();
|
||||
StopRPC(&node);
|
||||
StopHTTPServer();
|
||||
for (const auto& client : node.chain_clients) {
|
||||
client->flush();
|
||||
@@ -429,20 +429,6 @@ static void registerSignalHandler(int signal, void(*handler)(int))
|
||||
}
|
||||
#endif
|
||||
|
||||
static boost::signals2::connection rpc_notify_block_change_connection;
|
||||
static void OnRPCStarted()
|
||||
{
|
||||
rpc_notify_block_change_connection = uiInterface.NotifyBlockTip_connect(std::bind(RPCNotifyBlockChange, std::placeholders::_2));
|
||||
}
|
||||
|
||||
static void OnRPCStopped()
|
||||
{
|
||||
rpc_notify_block_change_connection.disconnect();
|
||||
RPCNotifyBlockChange(nullptr);
|
||||
g_best_block_cv.notify_all();
|
||||
LogDebug(BCLog::RPC, "RPC stopped.\n");
|
||||
}
|
||||
|
||||
void SetupServerArgs(ArgsManager& argsman, bool can_listen_ipc)
|
||||
{
|
||||
SetupHelpOptions(argsman);
|
||||
@@ -723,8 +709,6 @@ static void StartupNotify(const ArgsManager& args)
|
||||
static bool AppInitServers(NodeContext& node)
|
||||
{
|
||||
const ArgsManager& args = *Assert(node.args);
|
||||
RPCServer::OnStarted(&OnRPCStarted);
|
||||
RPCServer::OnStopped(&OnRPCStopped);
|
||||
if (!InitHTTPServer(*Assert(node.shutdown))) {
|
||||
return false;
|
||||
}
|
||||
@@ -2017,11 +2001,6 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
|
||||
// cannot yet be called. Before we make it callable, we need to make sure
|
||||
// that the RPC's view of the best block is valid and consistent with
|
||||
// ChainstateManager's active tip.
|
||||
//
|
||||
// If we do not do this, RPC's view of the best block will be height=0 and
|
||||
// hash=0x0. This will lead to erroroneous responses for things like
|
||||
// waitforblockheight.
|
||||
RPCNotifyBlockChange(WITH_LOCK(chainman.GetMutex(), return chainman.ActiveTip()));
|
||||
SetRPCWarmupFinished();
|
||||
|
||||
uiInterface.InitMessage(_("Done loading").translated);
|
||||
|
||||
Reference in New Issue
Block a user