Skip to content

Commit 898f560

Browse files
committed
Merge #12206: qa: Sync with validationinterface queue in sync_mempools
fa1e69e qa: Sync with validationinterface queue in sync_mempools (MarcoFalke) Pull request description: Commit e545ded moved `TransactionAddedToMempool` to the background scheduler thread. Thus, adding a transaction to the mempool will no longer add it to the wallet immediately. Functional tests, that `sync_mempools` and then call into wallet rpcs will race against the scheduler thread. Fix that race by flushing the scheduler queue. Fixes #12205; Fixes #12171; References #9584; Tree-SHA512: 14d99cff9c4756de9fad412f04e6d8e25bb9a0938f24ed8348de79df5b4ee67763dac5214b1a69e77e60787d81ee642976d1482b1b5637edfc4892a238ed22af
2 parents 17180fa + fa1e69e commit 898f560

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/rpc/blockchain.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <util.h>
2525
#include <utilstrencodings.h>
2626
#include <hash.h>
27+
#include <validationinterface.h>
2728
#include <warnings.h>
2829

2930
#include <stdint.h>
@@ -323,6 +324,21 @@ UniValue waitforblockheight(const JSONRPCRequest& request)
323324
return ret;
324325
}
325326

327+
UniValue syncwithvalidationinterfacequeue(const JSONRPCRequest& request)
328+
{
329+
if (request.fHelp || request.params.size() > 0) {
330+
throw std::runtime_error(
331+
"syncwithvalidationinterfacequeue\n"
332+
"\nWaits for the validation interface queue to catch up on everything that was there when we entered this function.\n"
333+
"\nExamples:\n"
334+
+ HelpExampleCli("syncwithvalidationinterfacequeue","")
335+
+ HelpExampleRpc("syncwithvalidationinterfacequeue","")
336+
);
337+
}
338+
SyncWithValidationInterfaceQueue();
339+
return NullUniValue;
340+
}
341+
326342
UniValue getdifficulty(const JSONRPCRequest& request)
327343
{
328344
if (request.fHelp || request.params.size() != 0)
@@ -1628,6 +1644,7 @@ static const CRPCCommand commands[] =
16281644
{ "hidden", "waitfornewblock", &waitfornewblock, {"timeout"} },
16291645
{ "hidden", "waitforblock", &waitforblock, {"blockhash","timeout"} },
16301646
{ "hidden", "waitforblockheight", &waitforblockheight, {"height","timeout"} },
1647+
{ "hidden", "syncwithvalidationinterfacequeue", &syncwithvalidationinterfacequeue, {} },
16311648
};
16321649

16331650
void RegisterBlockchainRPCCommands(CRPCTable &t)

test/functional/test_framework/util.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ def sync_chain(rpc_connections, *, wait=1, timeout=60):
390390
timeout -= wait
391391
raise AssertionError("Chain sync failed: Best block hashes don't match")
392392

393-
def sync_mempools(rpc_connections, *, wait=1, timeout=60):
393+
def sync_mempools(rpc_connections, *, wait=1, timeout=60, flush_scheduler=True):
394394
"""
395395
Wait until everybody has the same transactions in their memory
396396
pools
@@ -402,6 +402,9 @@ def sync_mempools(rpc_connections, *, wait=1, timeout=60):
402402
if set(rpc_connections[i].getrawmempool()) == pool:
403403
num_match = num_match + 1
404404
if num_match == len(rpc_connections):
405+
if flush_scheduler:
406+
for r in rpc_connections:
407+
r.syncwithvalidationinterfacequeue()
405408
return
406409
time.sleep(wait)
407410
timeout -= wait

0 commit comments

Comments
 (0)