mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-02-03 22:03:01 +01:00
add waitfornewblock/waitforblock/waitforblockheight rpcs and use them for tests
waitfornewblock waits until a new block is received, or the timeout expires, then returns the current block height/hash. waitforblock waits for a specific blockhash, or until the timeout expires, then returns the current block height/hash. If the target blockhash is the current tip, it will return immediately. waitforblockheight waits until the tip has reached a certain height or higher, then returns the current height and hash. waitforblockheight is used to avoid polling in the rpc tests.
This commit is contained in:
@@ -280,9 +280,15 @@ bool static Bind(const CService &addr, unsigned int flags) {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
void OnRPCStarted()
|
||||
{
|
||||
uiInterface.NotifyBlockTip.connect(&RPCNotifyBlockChange);
|
||||
}
|
||||
|
||||
void OnRPCStopped()
|
||||
{
|
||||
uiInterface.NotifyBlockTip.disconnect(&RPCNotifyBlockChange);
|
||||
RPCNotifyBlockChange(false, nullptr);
|
||||
cvBlockChange.notify_all();
|
||||
LogPrint("rpc", "RPC stopped.\n");
|
||||
}
|
||||
@@ -666,6 +672,7 @@ bool InitSanityCheck(void)
|
||||
|
||||
bool AppInitServers(boost::thread_group& threadGroup)
|
||||
{
|
||||
RPCServer::OnStarted(&OnRPCStarted);
|
||||
RPCServer::OnStopped(&OnRPCStopped);
|
||||
RPCServer::OnPreCommand(&OnRPCPreCommand);
|
||||
if (!InitHTTPServer())
|
||||
@@ -1357,6 +1364,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
|
||||
{
|
||||
LOCK(cs_main);
|
||||
CBlockIndex* tip = chainActive.Tip();
|
||||
RPCNotifyBlockChange(true, tip);
|
||||
if (tip && tip->nTime > GetAdjustedTime() + 2 * 60 * 60) {
|
||||
strLoadError = _("The block database contains a block which appears to be from the future. "
|
||||
"This may be due to your computer's date and time being set incorrectly. "
|
||||
|
||||
Reference in New Issue
Block a user