mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-29 14:59:39 -04: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.
|
//! Set mock time.
|
||||||
virtual void setMockTime(int64_t time) = 0;
|
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.
|
//! Return implementation of Chain interface.
|
||||||
|
|
|
@ -91,6 +91,9 @@ static RPCHelpMan mockscheduler()
|
||||||
const NodeContext& node_context{EnsureAnyNodeContext(request.context)};
|
const NodeContext& node_context{EnsureAnyNodeContext(request.context)};
|
||||||
CHECK_NONFATAL(node_context.scheduler)->MockForward(std::chrono::seconds{delta_seconds});
|
CHECK_NONFATAL(node_context.scheduler)->MockForward(std::chrono::seconds{delta_seconds});
|
||||||
SyncWithValidationInterfaceQueue();
|
SyncWithValidationInterfaceQueue();
|
||||||
|
for (const auto& chain_client : node_context.chain_clients) {
|
||||||
|
chain_client->schedulerMockForward(std::chrono::seconds(delta_seconds));
|
||||||
|
}
|
||||||
|
|
||||||
return UniValue::VNULL;
|
return UniValue::VNULL;
|
||||||
},
|
},
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
class ArgsManager;
|
class ArgsManager;
|
||||||
|
class CScheduler;
|
||||||
namespace interfaces {
|
namespace interfaces {
|
||||||
class Chain;
|
class Chain;
|
||||||
class Wallet;
|
class Wallet;
|
||||||
|
@ -34,6 +35,7 @@ using LoadWalletFn = std::function<void(std::unique_ptr<interfaces::Wallet> wall
|
||||||
//! behavior.
|
//! behavior.
|
||||||
struct WalletContext {
|
struct WalletContext {
|
||||||
interfaces::Chain* chain{nullptr};
|
interfaces::Chain* chain{nullptr};
|
||||||
|
CScheduler* scheduler{nullptr};
|
||||||
ArgsManager* args{nullptr}; // Currently a raw pointer because the memory is not managed by this struct
|
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
|
// It is unsafe to lock this after locking a CWallet::cs_wallet mutex because
|
||||||
// this could introduce inconsistent lock ordering and cause deadlocks.
|
// this could introduce inconsistent lock ordering and cause deadlocks.
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include <policy/fees.h>
|
#include <policy/fees.h>
|
||||||
#include <primitives/transaction.h>
|
#include <primitives/transaction.h>
|
||||||
#include <rpc/server.h>
|
#include <rpc/server.h>
|
||||||
|
#include <scheduler.h>
|
||||||
#include <support/allocators/secure.h>
|
#include <support/allocators/secure.h>
|
||||||
#include <sync.h>
|
#include <sync.h>
|
||||||
#include <uint256.h>
|
#include <uint256.h>
|
||||||
|
@ -585,10 +586,15 @@ public:
|
||||||
}
|
}
|
||||||
bool verify() override { return VerifyWallets(m_context); }
|
bool verify() override { return VerifyWallets(m_context); }
|
||||||
bool load() override { return LoadWallets(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 flush() override { return FlushWallets(m_context); }
|
||||||
void stop() override { return StopWallets(m_context); }
|
void stop() override { return StopWallets(m_context); }
|
||||||
void setMockTime(int64_t time) override { return SetMockTime(time); }
|
void setMockTime(int64_t time) override { return SetMockTime(time); }
|
||||||
|
void schedulerMockForward(std::chrono::seconds delta) override { Assert(m_context.scheduler)->MockForward(delta); }
|
||||||
|
|
||||||
//! WalletLoader methods
|
//! 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
|
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)) {
|
for (const std::shared_ptr<CWallet>& pwallet : GetWallets(context)) {
|
||||||
pwallet->postInitProcess();
|
pwallet->postInitProcess();
|
||||||
|
@ -149,9 +149,9 @@ void StartWallets(WalletContext& context, CScheduler& scheduler)
|
||||||
|
|
||||||
// Schedule periodic wallet flushes and tx rebroadcasts
|
// Schedule periodic wallet flushes and tx rebroadcasts
|
||||||
if (context.args->GetBoolArg("-flushwallet", DEFAULT_FLUSHWALLET)) {
|
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)
|
void FlushWallets(WalletContext& context)
|
||||||
|
|
|
@ -26,7 +26,7 @@ bool VerifyWallets(WalletContext& context);
|
||||||
bool LoadWallets(WalletContext& context);
|
bool LoadWallets(WalletContext& context);
|
||||||
|
|
||||||
//! Complete startup of wallets.
|
//! Complete startup of wallets.
|
||||||
void StartWallets(WalletContext& context, CScheduler& scheduler);
|
void StartWallets(WalletContext& context);
|
||||||
|
|
||||||
//! Flush all wallets in preparation for shutdown.
|
//! Flush all wallets in preparation for shutdown.
|
||||||
void FlushWallets(WalletContext& context);
|
void FlushWallets(WalletContext& context);
|
||||||
|
|
Loading…
Add table
Reference in a new issue