Adding a virtual sync method that's no-op for all but one of its implementations doesn't seem ideal. Would adding a Chain::waitForNotifications method be a workable alternative? E.g.:
<details>
<summary>git diff on 563ec53d54</summary>
diff --git a/src/common/interfaces.cpp b/src/common/interfaces.cpp
index 1c1a6f3203..ffd85e6131 100644
--- a/src/common/interfaces.cpp
+++ b/src/common/interfaces.cpp
@@ -17,7 +17,6 @@ public:
explicit CleanupHandler(std::function<void()> cleanup) : m_cleanup(std::move(cleanup)) {}
~CleanupHandler() override { if (!m_cleanup) return; m_cleanup(); m_cleanup = nullptr; }
void disconnect() override { if (!m_cleanup) return; m_cleanup(); m_cleanup = nullptr; }
- void sync() override {}
std::function<void()> m_cleanup;
};
@@ -27,7 +26,6 @@ public:
explicit SignalHandler(boost::signals2::connection connection) : m_connection(std::move(connection)) {}
void disconnect() override { m_connection.disconnect(); }
- void sync() override {}
boost::signals2::scoped_connection m_connection;
};
diff --git a/src/interfaces/chain.h b/src/interfaces/chain.h
index e6847b9b16..a0f288aee6 100644
--- a/src/interfaces/chain.h
+++ b/src/interfaces/chain.h
@@ -332,6 +332,9 @@ public:
//! chain tip.
virtual void waitForNotificationsIfTipChanged(const uint256& old_tip) = 0;
+ //! Wait for all pending notifications to be processed.
+ virtual void waitForNotifications() = 0;
+
//! Register handler for RPC. Command is not copied, so reference
//! needs to remain valid until Handler is disconnected.
virtual std::unique_ptr<Handler> handleRpc(const CRPCCommand& command) = 0;
diff --git a/src/interfaces/handler.h b/src/interfaces/handler.h
index 6b8484f80f..b3aebf7e14 100644
--- a/src/interfaces/handler.h
+++ b/src/interfaces/handler.h
@@ -26,9 +26,6 @@ public:
//! Disconnect the handler.
virtual void disconnect() = 0;
-
- //! Block until all notifications have been handled
- virtual void sync() = 0;
};
//! Return handler wrapping a boost signal connection.
diff --git a/src/node/interfaces.cpp b/src/node/interfaces.cpp
index 3b2a726d10..2cc30ff519 100644
--- a/src/node/interfaces.cpp
+++ b/src/node/interfaces.cpp
@@ -499,10 +499,6 @@ public:
m_proxy.reset();
}
}
- void sync() override
- {
- m_signals.SyncWithValidationInterfaceQueue();
- }
ValidationSignals& m_signals;
std::shared_ptr<NotificationsProxy> m_proxy;
};
@@ -539,8 +535,6 @@ public:
::tableRPC.removeCommand(m_command.name, &m_command);
}
}
- void sync() final {}
-
~RpcHandlerImpl() override { disconnect(); }
CRPCCommand m_command;
@@ -790,6 +784,10 @@ public:
if (!old_tip.IsNull() && old_tip == WITH_LOCK(::cs_main, return chainman().ActiveChain().Tip()->GetBlockHash())) return;
validation_signals().SyncWithValidationInterfaceQueue();
}
+ void waitForNotifications() override
+ {
+ validation_signals().SyncWithValidationInterfaceQueue();
+ }
std::unique_ptr<Handler> handleRpc(const CRPCCommand& command) override
{
return std::make_unique<RpcHandlerImpl>(command);
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp
index 9e918599d5..1e7ad3fc6b 100644
--- a/src/wallet/wallet.cpp
+++ b/src/wallet/wallet.cpp
@@ -4582,7 +4582,7 @@ void CWallet::DisconnectChainNotifications()
{
if (m_chain_notifications_handler) {
m_chain_notifications_handler->disconnect();
- m_chain_notifications_handler->sync();
+ chain().waitForNotifications();
m_chain_notifications_handler.reset();
}
}
diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h
index b90668e64c..e6823c2441 100644
--- a/src/wallet/wallet.h
+++ b/src/wallet/wallet.h
@@ -1073,7 +1073,7 @@ public:
//! Returns nullopt when no descriptor has the key or if the wallet is locked.
std::optional<CKey> GetKey(const CKeyID& keyid) const;
- //! Disconnect chain notifications and wait for validation interfrace queue to drain
+ //! Disconnect chain notifications and wait for validation interface queue to drain
void DisconnectChainNotifications();
};
</details>