mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-10 03:47:29 -03:00
interfaces: Add schedulerMockForward method so mockscheduler RPC can work across processes
Needed to fix new wallet_groups.py and wallet_resendwallettransactions.py tests with multiprocess bitcoin-node executable.
This commit is contained in:
parent
924327eaf3
commit
4978754c00
6 changed files with 19 additions and 5 deletions
|
@ -395,6 +395,9 @@ public:
|
|||
|
||||
//! Set mock time.
|
||||
virtual void setMockTime(int64_t time) = 0;
|
||||
|
||||
//! Mock the scheduler to fast forward in time.
|
||||
virtual void schedulerMockForward(std::chrono::seconds delta_seconds) = 0;
|
||||
};
|
||||
|
||||
//! Return implementation of Chain interface.
|
||||
|
|
|
@ -91,6 +91,9 @@ static RPCHelpMan mockscheduler()
|
|||
const NodeContext& node_context{EnsureAnyNodeContext(request.context)};
|
||||
CHECK_NONFATAL(node_context.scheduler)->MockForward(std::chrono::seconds{delta_seconds});
|
||||
SyncWithValidationInterfaceQueue();
|
||||
for (const auto& chain_client : node_context.chain_clients) {
|
||||
chain_client->schedulerMockForward(std::chrono::seconds(delta_seconds));
|
||||
}
|
||||
|
||||
return UniValue::VNULL;
|
||||
},
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include <vector>
|
||||
|
||||
class ArgsManager;
|
||||
class CScheduler;
|
||||
namespace interfaces {
|
||||
class Chain;
|
||||
class Wallet;
|
||||
|
@ -34,6 +35,7 @@ using LoadWalletFn = std::function<void(std::unique_ptr<interfaces::Wallet> wall
|
|||
//! behavior.
|
||||
struct WalletContext {
|
||||
interfaces::Chain* chain{nullptr};
|
||||
CScheduler* scheduler{nullptr};
|
||||
ArgsManager* args{nullptr}; // Currently a raw pointer because the memory is not managed by this struct
|
||||
// It is unsafe to lock this after locking a CWallet::cs_wallet mutex because
|
||||
// this could introduce inconsistent lock ordering and cause deadlocks.
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include <policy/fees.h>
|
||||
#include <primitives/transaction.h>
|
||||
#include <rpc/server.h>
|
||||
#include <scheduler.h>
|
||||
#include <support/allocators/secure.h>
|
||||
#include <sync.h>
|
||||
#include <uint256.h>
|
||||
|
@ -585,10 +586,15 @@ public:
|
|||
}
|
||||
bool verify() override { return VerifyWallets(m_context); }
|
||||
bool load() override { return LoadWallets(m_context); }
|
||||
void start(CScheduler& scheduler) override { return StartWallets(m_context, scheduler); }
|
||||
void start(CScheduler& scheduler) override
|
||||
{
|
||||
m_context.scheduler = &scheduler;
|
||||
return StartWallets(m_context);
|
||||
}
|
||||
void flush() override { return FlushWallets(m_context); }
|
||||
void stop() override { return StopWallets(m_context); }
|
||||
void setMockTime(int64_t time) override { return SetMockTime(time); }
|
||||
void schedulerMockForward(std::chrono::seconds delta) override { Assert(m_context.scheduler)->MockForward(delta); }
|
||||
|
||||
//! WalletLoader methods
|
||||
util::Result<std::unique_ptr<Wallet>> createWallet(const std::string& name, const SecureString& passphrase, uint64_t wallet_creation_flags, std::vector<bilingual_str>& warnings) override
|
||||
|
|
|
@ -141,7 +141,7 @@ bool LoadWallets(WalletContext& context)
|
|||
}
|
||||
}
|
||||
|
||||
void StartWallets(WalletContext& context, CScheduler& scheduler)
|
||||
void StartWallets(WalletContext& context)
|
||||
{
|
||||
for (const std::shared_ptr<CWallet>& pwallet : GetWallets(context)) {
|
||||
pwallet->postInitProcess();
|
||||
|
@ -149,9 +149,9 @@ void StartWallets(WalletContext& context, CScheduler& scheduler)
|
|||
|
||||
// Schedule periodic wallet flushes and tx rebroadcasts
|
||||
if (context.args->GetBoolArg("-flushwallet", DEFAULT_FLUSHWALLET)) {
|
||||
scheduler.scheduleEvery([&context] { MaybeCompactWalletDB(context); }, std::chrono::milliseconds{500});
|
||||
context.scheduler->scheduleEvery([&context] { MaybeCompactWalletDB(context); }, 500ms);
|
||||
}
|
||||
scheduler.scheduleEvery([&context] { MaybeResendWalletTxs(context); }, 1min);
|
||||
context.scheduler->scheduleEvery([&context] { MaybeResendWalletTxs(context); }, 1min);
|
||||
}
|
||||
|
||||
void FlushWallets(WalletContext& context)
|
||||
|
|
|
@ -26,7 +26,7 @@ bool VerifyWallets(WalletContext& context);
|
|||
bool LoadWallets(WalletContext& context);
|
||||
|
||||
//! Complete startup of wallets.
|
||||
void StartWallets(WalletContext& context, CScheduler& scheduler);
|
||||
void StartWallets(WalletContext& context);
|
||||
|
||||
//! Flush all wallets in preparation for shutdown.
|
||||
void FlushWallets(WalletContext& context);
|
||||
|
|
Loading…
Reference in a new issue