Skip to content

Commit 4978754

Browse files
committed
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.
1 parent 924327e commit 4978754

File tree

6 files changed

+19
-5
lines changed

6 files changed

+19
-5
lines changed

src/interfaces/chain.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,9 @@ class ChainClient
395395

396396
//! Set mock time.
397397
virtual void setMockTime(int64_t time) = 0;
398+
399+
//! Mock the scheduler to fast forward in time.
400+
virtual void schedulerMockForward(std::chrono::seconds delta_seconds) = 0;
398401
};
399402

400403
//! Return implementation of Chain interface.

src/rpc/node.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ static RPCHelpMan mockscheduler()
9191
const NodeContext& node_context{EnsureAnyNodeContext(request.context)};
9292
CHECK_NONFATAL(node_context.scheduler)->MockForward(std::chrono::seconds{delta_seconds});
9393
SyncWithValidationInterfaceQueue();
94+
for (const auto& chain_client : node_context.chain_clients) {
95+
chain_client->schedulerMockForward(std::chrono::seconds(delta_seconds));
96+
}
9497

9598
return UniValue::VNULL;
9699
},

src/wallet/context.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <vector>
1414

1515
class ArgsManager;
16+
class CScheduler;
1617
namespace interfaces {
1718
class Chain;
1819
class Wallet;
@@ -34,6 +35,7 @@ using LoadWalletFn = std::function<void(std::unique_ptr<interfaces::Wallet> wall
3435
//! behavior.
3536
struct WalletContext {
3637
interfaces::Chain* chain{nullptr};
38+
CScheduler* scheduler{nullptr};
3739
ArgsManager* args{nullptr}; // Currently a raw pointer because the memory is not managed by this struct
3840
// It is unsafe to lock this after locking a CWallet::cs_wallet mutex because
3941
// this could introduce inconsistent lock ordering and cause deadlocks.

src/wallet/interfaces.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <policy/fees.h>
1212
#include <primitives/transaction.h>
1313
#include <rpc/server.h>
14+
#include <scheduler.h>
1415
#include <support/allocators/secure.h>
1516
#include <sync.h>
1617
#include <uint256.h>
@@ -585,10 +586,15 @@ class WalletLoaderImpl : public WalletLoader
585586
}
586587
bool verify() override { return VerifyWallets(m_context); }
587588
bool load() override { return LoadWallets(m_context); }
588-
void start(CScheduler& scheduler) override { return StartWallets(m_context, scheduler); }
589+
void start(CScheduler& scheduler) override
590+
{
591+
m_context.scheduler = &scheduler;
592+
return StartWallets(m_context);
593+
}
589594
void flush() override { return FlushWallets(m_context); }
590595
void stop() override { return StopWallets(m_context); }
591596
void setMockTime(int64_t time) override { return SetMockTime(time); }
597+
void schedulerMockForward(std::chrono::seconds delta) override { Assert(m_context.scheduler)->MockForward(delta); }
592598

593599
//! WalletLoader methods
594600
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

src/wallet/load.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,17 +141,17 @@ bool LoadWallets(WalletContext& context)
141141
}
142142
}
143143

144-
void StartWallets(WalletContext& context, CScheduler& scheduler)
144+
void StartWallets(WalletContext& context)
145145
{
146146
for (const std::shared_ptr<CWallet>& pwallet : GetWallets(context)) {
147147
pwallet->postInitProcess();
148148
}
149149

150150
// Schedule periodic wallet flushes and tx rebroadcasts
151151
if (context.args->GetBoolArg("-flushwallet", DEFAULT_FLUSHWALLET)) {
152-
scheduler.scheduleEvery([&context] { MaybeCompactWalletDB(context); }, std::chrono::milliseconds{500});
152+
context.scheduler->scheduleEvery([&context] { MaybeCompactWalletDB(context); }, 500ms);
153153
}
154-
scheduler.scheduleEvery([&context] { MaybeResendWalletTxs(context); }, 1min);
154+
context.scheduler->scheduleEvery([&context] { MaybeResendWalletTxs(context); }, 1min);
155155
}
156156

157157
void FlushWallets(WalletContext& context)

src/wallet/load.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ bool VerifyWallets(WalletContext& context);
2626
bool LoadWallets(WalletContext& context);
2727

2828
//! Complete startup of wallets.
29-
void StartWallets(WalletContext& context, CScheduler& scheduler);
29+
void StartWallets(WalletContext& context);
3030

3131
//! Flush all wallets in preparation for shutdown.
3232
void FlushWallets(WalletContext& context);

0 commit comments

Comments
 (0)