mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 12:02:48 +01:00
merge bitcoin#16839: Replace Connman and BanMan globals with NodeContext local
Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
This commit is contained in:
parent
f90cd9fe37
commit
b3b636463e
@ -246,6 +246,7 @@ BITCOIN_CORE_H = \
|
||||
netmessagemaker.h \
|
||||
node/coin.h \
|
||||
node/coinstats.h \
|
||||
node/context.h \
|
||||
node/transaction.h \
|
||||
noui.h \
|
||||
optional.h \
|
||||
@ -423,6 +424,7 @@ libdash_server_a_SOURCES = \
|
||||
net_processing.cpp \
|
||||
node/coin.cpp \
|
||||
node/coinstats.cpp \
|
||||
node/context.cpp \
|
||||
node/transaction.cpp \
|
||||
noui.cpp \
|
||||
policy/fees.cpp \
|
||||
|
@ -67,5 +67,4 @@ private:
|
||||
const int64_t m_default_ban_time;
|
||||
};
|
||||
|
||||
extern std::unique_ptr<BanMan> g_banman;
|
||||
#endif
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#include <bench/bench.h>
|
||||
#include <interfaces/chain.h>
|
||||
#include <node/context.h>
|
||||
#include <wallet/coinselection.h>
|
||||
#include <wallet/wallet.h>
|
||||
|
||||
@ -28,7 +29,8 @@ static void addCoin(const CAmount& nValue, const CWallet& wallet, std::vector<st
|
||||
// (https://github.com/bitcoin/bitcoin/issues/7883#issuecomment-224807484)
|
||||
static void CoinSelection(benchmark::Bench& bench)
|
||||
{
|
||||
auto chain = interfaces::MakeChain();
|
||||
NodeContext node;
|
||||
auto chain = interfaces::MakeChain(node);
|
||||
const CWallet wallet(chain.get(), WalletLocation(), CreateDummyWalletDatabase());
|
||||
std::vector<std::unique_ptr<CWalletTx>> wtxs;
|
||||
LOCK(wallet.cs_wallet);
|
||||
@ -59,7 +61,8 @@ static void CoinSelection(benchmark::Bench& bench)
|
||||
}
|
||||
|
||||
typedef std::set<CInputCoin> CoinSet;
|
||||
static auto testChain = interfaces::MakeChain();
|
||||
static NodeContext testNode;
|
||||
static auto testChain = interfaces::MakeChain(testNode);
|
||||
static const CWallet testWallet(testChain.get(), WalletLocation(), CreateDummyWalletDatabase());
|
||||
std::vector<std::unique_ptr<CWalletTx>> wtxn;
|
||||
|
||||
|
@ -4,6 +4,7 @@
|
||||
|
||||
#include <bench/bench.h>
|
||||
#include <interfaces/chain.h>
|
||||
#include <node/context.h>
|
||||
#include <test/util.h>
|
||||
#include <validationinterface.h>
|
||||
#include <wallet/wallet.h>
|
||||
@ -14,7 +15,8 @@ static void WalletBalance(benchmark::Bench& bench, const bool set_dirty, const b
|
||||
{
|
||||
const auto& ADDRESS_WATCHONLY = ADDRESS_B58T_UNSPENDABLE;
|
||||
|
||||
std::unique_ptr<interfaces::Chain> chain = interfaces::MakeChain();
|
||||
NodeContext node;
|
||||
std::unique_ptr<interfaces::Chain> chain = interfaces::MakeChain(node);
|
||||
CWallet wallet{chain.get(), WalletLocation(), CreateMockWalletDatabase()};
|
||||
{
|
||||
bool first_run;
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include <compat.h>
|
||||
#include <init.h>
|
||||
#include <interfaces/chain.h>
|
||||
#include <node/context.h>
|
||||
#include <noui.h>
|
||||
#include <shutdown.h>
|
||||
#include <ui_interface.h>
|
||||
@ -27,13 +28,13 @@
|
||||
|
||||
const std::function<std::string(const char*)> G_TRANSLATION_FUN = nullptr;
|
||||
|
||||
static void WaitForShutdown()
|
||||
static void WaitForShutdown(NodeContext& node)
|
||||
{
|
||||
while (!ShutdownRequested())
|
||||
{
|
||||
UninterruptibleSleep(std::chrono::milliseconds{200});
|
||||
}
|
||||
Interrupt();
|
||||
Interrupt(node);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
@ -42,8 +43,8 @@ static void WaitForShutdown()
|
||||
//
|
||||
static bool AppInit(int argc, char* argv[])
|
||||
{
|
||||
InitInterfaces interfaces;
|
||||
interfaces.chain = interfaces::MakeChain();
|
||||
NodeContext node;
|
||||
node.chain = interfaces::MakeChain(node);
|
||||
|
||||
bool fRet = false;
|
||||
|
||||
@ -157,18 +158,18 @@ static bool AppInit(int argc, char* argv[])
|
||||
// If locking the data directory failed, exit immediately
|
||||
return false;
|
||||
}
|
||||
fRet = AppInitMain(interfaces);
|
||||
fRet = AppInitMain(node);
|
||||
} catch (...) {
|
||||
PrintExceptionContinue(std::current_exception(), "AppInit()");
|
||||
}
|
||||
|
||||
if (!fRet)
|
||||
{
|
||||
Interrupt();
|
||||
Interrupt(node);
|
||||
} else {
|
||||
WaitForShutdown();
|
||||
WaitForShutdown(node);
|
||||
}
|
||||
Shutdown(interfaces);
|
||||
Shutdown(node);
|
||||
|
||||
return fRet;
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ public:
|
||||
bool HasWalletSupport() const override {return false;}
|
||||
void AddWalletOptions() const override;
|
||||
bool ParameterInteraction() const override {return true;}
|
||||
void Construct(InitInterfaces& interfaces) const override {LogPrintf("No wallet support compiled in!\n");}
|
||||
void Construct(NodeContext& node) const override {LogPrintf("No wallet support compiled in!\n");}
|
||||
|
||||
// Dash Specific WalletInitInterface InitCoinJoinSettings
|
||||
void AutoLockMasternodeCollaterals() const override {}
|
||||
|
89
src/init.cpp
89
src/init.cpp
@ -34,6 +34,7 @@
|
||||
#include <net_permissions.h>
|
||||
#include <net_processing.h>
|
||||
#include <netbase.h>
|
||||
#include <node/context.h>
|
||||
#include <policy/feerate.h>
|
||||
#include <policy/fees.h>
|
||||
#include <policy/policy.h>
|
||||
@ -121,9 +122,6 @@ static const bool DEFAULT_STOPAFTERBLOCKIMPORT = false;
|
||||
// Dump addresses to banlist.dat every 15 minutes (900s)
|
||||
static constexpr int DUMP_BANS_INTERVAL = 60 * 15;
|
||||
|
||||
std::unique_ptr<CConnman> g_connman;
|
||||
std::unique_ptr<PeerLogicValidation> peerLogic;
|
||||
std::unique_ptr<BanMan> g_banman;
|
||||
|
||||
static CDSNotificationInterface* pdsNotificationInterface = nullptr;
|
||||
|
||||
@ -192,7 +190,7 @@ static std::unique_ptr<ECCVerifyHandle> globalVerifyHandle;
|
||||
static boost::thread_group threadGroup;
|
||||
static CScheduler scheduler;
|
||||
|
||||
void Interrupt()
|
||||
void Interrupt(NodeContext& node)
|
||||
{
|
||||
InterruptHTTPServer();
|
||||
InterruptHTTPRPC();
|
||||
@ -201,8 +199,8 @@ void Interrupt()
|
||||
InterruptTorControl();
|
||||
llmq::InterruptLLMQSystem();
|
||||
InterruptMapPort();
|
||||
if (g_connman)
|
||||
g_connman->Interrupt();
|
||||
if (node.connman)
|
||||
node.connman->Interrupt();
|
||||
if (g_txindex) {
|
||||
g_txindex->Interrupt();
|
||||
}
|
||||
@ -210,7 +208,7 @@ void Interrupt()
|
||||
}
|
||||
|
||||
/** Preparing steps before shutting down or restarting the wallet */
|
||||
void PrepareShutdown(InitInterfaces& interfaces)
|
||||
void PrepareShutdown(NodeContext& node)
|
||||
{
|
||||
LogPrintf("%s: In progress...\n", __func__);
|
||||
static CCriticalSection cs_Shutdown;
|
||||
@ -235,15 +233,15 @@ void PrepareShutdown(InitInterfaces& interfaces)
|
||||
std::string statusmessage;
|
||||
bool fRPCInWarmup = RPCIsInWarmup(&statusmessage);
|
||||
|
||||
for (const auto& client : interfaces.chain_clients) {
|
||||
for (const auto& client : node.chain_clients) {
|
||||
client->flush();
|
||||
}
|
||||
StopMapPort();
|
||||
|
||||
// Because these depend on each-other, we make sure that neither can be
|
||||
// using the other before destroying them.
|
||||
if (peerLogic) UnregisterValidationInterface(peerLogic.get());
|
||||
if (g_connman) g_connman->Stop();
|
||||
if (node.peer_logic) UnregisterValidationInterface(node.peer_logic.get());
|
||||
if (node.connman) node.connman->Stop();
|
||||
if (g_txindex) g_txindex->Stop();
|
||||
ForEachBlockFilterIndex([](BlockFilterIndex& index) { index.Stop(); });
|
||||
|
||||
@ -276,9 +274,9 @@ void PrepareShutdown(InitInterfaces& interfaces)
|
||||
|
||||
// After the threads that potentially access these pointers have been stopped,
|
||||
// destruct and reset all to nullptr.
|
||||
peerLogic.reset();
|
||||
g_connman.reset();
|
||||
g_banman.reset();
|
||||
node.peer_logic.reset();
|
||||
node.connman.reset();
|
||||
node.banman.reset();
|
||||
g_txindex.reset();
|
||||
DestroyAllBlockFilterIndexes();
|
||||
|
||||
@ -331,7 +329,7 @@ void PrepareShutdown(InitInterfaces& interfaces)
|
||||
deterministicMNManager.reset();
|
||||
evoDb.reset();
|
||||
}
|
||||
for (const auto& client : interfaces.chain_clients) {
|
||||
for (const auto& client : node.chain_clients) {
|
||||
client->stop();
|
||||
}
|
||||
|
||||
@ -368,7 +366,7 @@ void PrepareShutdown(InitInterfaces& interfaces)
|
||||
LogPrintf("%s: Unable to remove PID file: %s\n", __func__, e.what());
|
||||
}
|
||||
#endif
|
||||
interfaces.chain_clients.clear();
|
||||
node.chain_clients.clear();
|
||||
UnregisterAllValidationInterfaces();
|
||||
GetMainSignals().UnregisterBackgroundSignalScheduler();
|
||||
GetMainSignals().UnregisterWithMempoolSignals(mempool);
|
||||
@ -383,11 +381,11 @@ void PrepareShutdown(InitInterfaces& interfaces)
|
||||
* called implicitly when the parent object is deleted. In this case we have to skip the
|
||||
* PrepareShutdown() part because it was already executed and just delete the wallet instance.
|
||||
*/
|
||||
void Shutdown(InitInterfaces& interfaces)
|
||||
void Shutdown(NodeContext& node)
|
||||
{
|
||||
// Shutdown part 1: prepare shutdown
|
||||
if(!RestartRequested()) {
|
||||
PrepareShutdown(interfaces);
|
||||
PrepareShutdown(node);
|
||||
}
|
||||
// Shutdown part 2: delete wallet instance
|
||||
globalVerifyHandle.reset();
|
||||
@ -1610,7 +1608,7 @@ bool AppInitLockDataDirectory()
|
||||
return true;
|
||||
}
|
||||
|
||||
bool AppInitMain(InitInterfaces& interfaces)
|
||||
bool AppInitMain(NodeContext& node)
|
||||
{
|
||||
const CChainParams& chainparams = Params();
|
||||
// ********************************************************* Step 4a: application initialization
|
||||
@ -1719,16 +1717,16 @@ bool AppInitMain(InitInterfaces& interfaces)
|
||||
// according to -wallet and -disablewallet options. This only constructs
|
||||
// the interfaces, it doesn't load wallet data. Wallets actually get loaded
|
||||
// when load() and start() interface methods are called below.
|
||||
g_wallet_init_interface.Construct(interfaces);
|
||||
g_wallet_init_interface.Construct(node);
|
||||
|
||||
/* Register RPC commands regardless of -server setting so they will be
|
||||
* available in the GUI RPC console even if external calls are disabled.
|
||||
*/
|
||||
RegisterAllCoreRPCCommands(tableRPC);
|
||||
for (const auto& client : interfaces.chain_clients) {
|
||||
for (const auto& client : node.chain_clients) {
|
||||
client->registerRpcs();
|
||||
}
|
||||
g_rpc_interfaces = &interfaces;
|
||||
g_rpc_node = &node;
|
||||
#if ENABLE_ZMQ
|
||||
RegisterZMQRPCCommands(tableRPC);
|
||||
#endif
|
||||
@ -1748,7 +1746,7 @@ bool AppInitMain(InitInterfaces& interfaces)
|
||||
// ********************************************************* Step 5: verify wallet database integrity
|
||||
|
||||
if (!g_wallet_init_interface.InitAutoBackup()) return false;
|
||||
for (const auto& client : interfaces.chain_clients) {
|
||||
for (const auto& client : node.chain_clients) {
|
||||
if (!client->verify()) {
|
||||
return false;
|
||||
}
|
||||
@ -1760,13 +1758,13 @@ bool AppInitMain(InitInterfaces& interfaces)
|
||||
// is not yet setup and may end up being set up twice if we
|
||||
// need to reindex later.
|
||||
|
||||
assert(!g_banman);
|
||||
g_banman = MakeUnique<BanMan>(GetDataDir() / "banlist.dat", &uiInterface, gArgs.GetArg("-bantime", DEFAULT_MISBEHAVING_BANTIME));
|
||||
assert(!g_connman);
|
||||
g_connman = std::make_unique<CConnman>(GetRand(std::numeric_limits<uint64_t>::max()), GetRand(std::numeric_limits<uint64_t>::max()));
|
||||
assert(!node.banman);
|
||||
node.banman = MakeUnique<BanMan>(GetDataDir() / "banlist.dat", &uiInterface, gArgs.GetArg("-bantime", DEFAULT_MISBEHAVING_BANTIME));
|
||||
assert(!node.connman);
|
||||
node.connman = std::make_unique<CConnman>(GetRand(std::numeric_limits<uint64_t>::max()), GetRand(std::numeric_limits<uint64_t>::max()));
|
||||
|
||||
peerLogic.reset(new PeerLogicValidation(g_connman.get(), g_banman.get(), scheduler, gArgs.GetBoolArg("-enablebip61", DEFAULT_ENABLE_BIP61)));
|
||||
RegisterValidationInterface(peerLogic.get());
|
||||
node.peer_logic.reset(new PeerLogicValidation(node.connman.get(), node.banman.get(), scheduler, gArgs.GetBoolArg("-enablebip61", DEFAULT_ENABLE_BIP61)));
|
||||
RegisterValidationInterface(node.peer_logic.get());
|
||||
|
||||
// sanitize comments per BIP-0014, format user agent and check total size
|
||||
std::vector<std::string> uacomments;
|
||||
@ -1879,7 +1877,7 @@ bool AppInitMain(InitInterfaces& interfaces)
|
||||
return false;
|
||||
}
|
||||
const uint256 asmap_version = SerializeHash(asmap);
|
||||
g_connman->SetAsmap(std::move(asmap));
|
||||
node.connman->SetAsmap(std::move(asmap));
|
||||
LogPrintf("Using asmap version %s for IP bucketing\n", asmap_version.ToString());
|
||||
} else {
|
||||
LogPrintf("Using /16 prefix for IP bucketing\n");
|
||||
@ -1893,7 +1891,7 @@ bool AppInitMain(InitInterfaces& interfaces)
|
||||
}
|
||||
#endif
|
||||
|
||||
pdsNotificationInterface = new CDSNotificationInterface(*g_connman);
|
||||
pdsNotificationInterface = new CDSNotificationInterface(*node.connman);
|
||||
RegisterValidationInterface(pdsNotificationInterface);
|
||||
|
||||
uint64_t nMaxOutboundLimit = 0; //unlimited unless -maxuploadtarget is set
|
||||
@ -1975,11 +1973,11 @@ bool AppInitMain(InitInterfaces& interfaces)
|
||||
evoDb.reset();
|
||||
evoDb.reset(new CEvoDB(nEvoDbCache, false, fReset || fReindexChainState));
|
||||
deterministicMNManager.reset();
|
||||
deterministicMNManager.reset(new CDeterministicMNManager(*evoDb, *g_connman));
|
||||
deterministicMNManager.reset(new CDeterministicMNManager(*evoDb, *node.connman));
|
||||
llmq::quorumSnapshotManager.reset();
|
||||
llmq::quorumSnapshotManager.reset(new llmq::CQuorumSnapshotManager(*evoDb));
|
||||
|
||||
llmq::InitLLMQSystem(*evoDb, *g_connman, false, fReset || fReindexChainState);
|
||||
llmq::InitLLMQSystem(*evoDb, *node.connman, false, fReset || fReindexChainState);
|
||||
|
||||
if (fReset) {
|
||||
pblocktree->WriteReindexing(true);
|
||||
@ -2191,7 +2189,7 @@ bool AppInitMain(InitInterfaces& interfaces)
|
||||
}
|
||||
|
||||
// ********************************************************* Step 9: load wallet
|
||||
for (const auto& client : interfaces.chain_clients) {
|
||||
for (const auto& client : node.chain_clients) {
|
||||
if (!client->load()) {
|
||||
return false;
|
||||
}
|
||||
@ -2248,7 +2246,7 @@ bool AppInitMain(InitInterfaces& interfaces)
|
||||
|
||||
if(fMasternodeMode) {
|
||||
// Create and register activeMasternodeManager, will init later in ThreadImport
|
||||
activeMasternodeManager = new CActiveMasternodeManager(*g_connman);
|
||||
activeMasternodeManager = new CActiveMasternodeManager(*node.connman);
|
||||
RegisterValidationInterface(activeMasternodeManager);
|
||||
}
|
||||
|
||||
@ -2327,20 +2325,20 @@ bool AppInitMain(InitInterfaces& interfaces)
|
||||
// ********************************************************* Step 10c: schedule Dash-specific tasks
|
||||
|
||||
scheduler.scheduleEvery(std::bind(&CNetFulfilledRequestManager::DoMaintenance, std::ref(netfulfilledman)), 60 * 1000);
|
||||
scheduler.scheduleEvery(std::bind(&CMasternodeSync::DoMaintenance, std::ref(masternodeSync), std::ref(*g_connman)), 1 * 1000);
|
||||
scheduler.scheduleEvery(std::bind(&CMasternodeUtils::DoMaintenance, std::ref(*g_connman)), 1 * 1000);
|
||||
scheduler.scheduleEvery(std::bind(&CMasternodeSync::DoMaintenance, std::ref(masternodeSync), std::ref(*node.connman)), 1 * 1000);
|
||||
scheduler.scheduleEvery(std::bind(&CMasternodeUtils::DoMaintenance, std::ref(*node.connman)), 1 * 1000);
|
||||
scheduler.scheduleEvery(std::bind(&CDeterministicMNManager::DoMaintenance, std::ref(*deterministicMNManager)), 10 * 1000);
|
||||
|
||||
if (!fDisableGovernance) {
|
||||
scheduler.scheduleEvery(std::bind(&CGovernanceManager::DoMaintenance, std::ref(governance), std::ref(*g_connman)), 60 * 5 * 1000);
|
||||
scheduler.scheduleEvery(std::bind(&CGovernanceManager::DoMaintenance, std::ref(governance), std::ref(*node.connman)), 60 * 5 * 1000);
|
||||
}
|
||||
|
||||
if (fMasternodeMode) {
|
||||
scheduler.scheduleEvery(std::bind(&CCoinJoinServer::DoMaintenance, std::ref(coinJoinServer), std::ref(*g_connman)), 1 * 1000);
|
||||
scheduler.scheduleEvery(std::bind(&CCoinJoinServer::DoMaintenance, std::ref(coinJoinServer), std::ref(*node.connman)), 1 * 1000);
|
||||
scheduler.scheduleEvery(std::bind(&llmq::CDKGSessionManager::CleanupOldContributions, std::ref(*llmq::quorumDKGSessionManager)), 60 * 60 * 1000);
|
||||
#ifdef ENABLE_WALLET
|
||||
} else if(CCoinJoinClientOptions::IsEnabled()) {
|
||||
scheduler.scheduleEvery(std::bind(&DoCoinJoinMaintenance, std::ref(*g_connman)), 1 * 1000);
|
||||
scheduler.scheduleEvery(std::bind(&DoCoinJoinMaintenance, std::ref(*node.connman)), 1 * 1000);
|
||||
#endif // ENABLE_WALLET
|
||||
}
|
||||
|
||||
@ -2427,8 +2425,8 @@ bool AppInitMain(InitInterfaces& interfaces)
|
||||
connOptions.nMaxFeeler = 1;
|
||||
connOptions.nBestHeight = chain_active_height;
|
||||
connOptions.uiInterface = &uiInterface;
|
||||
connOptions.m_banman = g_banman.get();
|
||||
connOptions.m_msgproc = peerLogic.get();
|
||||
connOptions.m_banman = node.banman.get();
|
||||
connOptions.m_msgproc = node.peer_logic.get();
|
||||
connOptions.nSendBufferMaxSize = 1000*gArgs.GetArg("-maxsendbuffer", DEFAULT_MAXSENDBUFFER);
|
||||
connOptions.nReceiveFloodSize = 1000*gArgs.GetArg("-maxreceivebuffer", DEFAULT_MAXRECEIVEBUFFER);
|
||||
connOptions.m_added_nodes = gArgs.GetArgs("-addnode");
|
||||
@ -2488,7 +2486,7 @@ bool AppInitMain(InitInterfaces& interfaces)
|
||||
return InitError(strprintf(_("Invalid -socketevents ('%s') specified. Only these modes are supported: %s"), strSocketEventsMode, GetSupportedSocketEventsStr()));
|
||||
}
|
||||
|
||||
if (!g_connman->Start(scheduler, connOptions)) {
|
||||
if (!node.connman->Start(scheduler, connOptions)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -2497,12 +2495,13 @@ bool AppInitMain(InitInterfaces& interfaces)
|
||||
SetRPCWarmupFinished();
|
||||
uiInterface.InitMessage(_("Done loading").translated);
|
||||
|
||||
for (const auto& client : interfaces.chain_clients) {
|
||||
for (const auto& client : node.chain_clients) {
|
||||
client->start(scheduler);
|
||||
}
|
||||
|
||||
scheduler.scheduleEvery([]{
|
||||
g_banman->DumpBanlist();
|
||||
BanMan* banman = node.banman.get();
|
||||
scheduler.scheduleEvery([banman]{
|
||||
banman->DumpBanlist();
|
||||
}, DUMP_BANS_INTERVAL * 1000);
|
||||
|
||||
return true;
|
||||
|
24
src/init.h
24
src/init.h
@ -10,26 +10,14 @@
|
||||
#include <string>
|
||||
#include <util/system.h>
|
||||
|
||||
namespace interfaces {
|
||||
class Chain;
|
||||
class ChainClient;
|
||||
} // namespace interfaces
|
||||
|
||||
//! Pointers to interfaces used during init and destroyed on shutdown.
|
||||
struct InitInterfaces
|
||||
{
|
||||
std::unique_ptr<interfaces::Chain> chain;
|
||||
std::vector<std::unique_ptr<interfaces::ChainClient>> chain_clients;
|
||||
};
|
||||
|
||||
namespace boost
|
||||
{
|
||||
struct NodeContext;
|
||||
namespace boost {
|
||||
class thread_group;
|
||||
} // namespace boost
|
||||
|
||||
/** Interrupt threads */
|
||||
void Interrupt();
|
||||
void Shutdown(InitInterfaces& interfaces);
|
||||
void Interrupt(NodeContext& node);
|
||||
void Shutdown(NodeContext& node);
|
||||
//!Initialize the logging infrastructure
|
||||
void InitLogging();
|
||||
//!Parameter interaction: change current parameters depending on various rules
|
||||
@ -63,8 +51,8 @@ bool AppInitLockDataDirectory();
|
||||
* @note This should only be done after daemonization. Call Shutdown() if this function fails.
|
||||
* @pre Parameters should be parsed and config file should be read, AppInitLockDataDirectory should have been called.
|
||||
*/
|
||||
bool AppInitMain(InitInterfaces& interfaces);
|
||||
void PrepareShutdown(InitInterfaces& interfaces);
|
||||
bool AppInitMain(NodeContext& node);
|
||||
void PrepareShutdown(NodeContext& node);
|
||||
|
||||
/**
|
||||
* Setup the arguments for gArgs
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include <interfaces/wallet.h>
|
||||
#include <net.h>
|
||||
#include <node/coin.h>
|
||||
#include <node/context.h>
|
||||
#include <node/transaction.h>
|
||||
#include <policy/fees.h>
|
||||
#include <policy/policy.h>
|
||||
@ -239,6 +240,7 @@ public:
|
||||
class ChainImpl : public Chain
|
||||
{
|
||||
public:
|
||||
explicit ChainImpl(NodeContext& node) : m_node(node) {}
|
||||
std::unique_ptr<Chain::Lock> lock(bool try_lock) override
|
||||
{
|
||||
auto lock = MakeUnique<LockImpl>(::cs_main, "cs_main", __FILE__, __LINE__, try_lock);
|
||||
@ -281,7 +283,7 @@ public:
|
||||
}
|
||||
bool broadcastTransaction(const CTransactionRef& tx, std::string& err_string, const CAmount& max_tx_fee, bool relay) override
|
||||
{
|
||||
const TransactionError err = BroadcastTransaction(tx, err_string, max_tx_fee, relay, /*wait_callback*/ false);
|
||||
const TransactionError err = BroadcastTransaction(m_node, tx, err_string, max_tx_fee, relay, /*wait_callback*/ false);
|
||||
// Chain clients only care about failures to accept the tx to the mempool. Disregard non-mempool related failures.
|
||||
// Note: this will need to be updated if BroadcastTransactions() is updated to return other non-mempool failures
|
||||
// that Chain clients do not need to know about.
|
||||
@ -325,7 +327,7 @@ public:
|
||||
LOCK(cs_main);
|
||||
return ::fHavePruned;
|
||||
}
|
||||
bool p2pEnabled() override { return g_connman != nullptr; }
|
||||
bool p2pEnabled() override { return m_node.connman != nullptr; }
|
||||
bool isReadyToBroadcast() override { return !::fImporting && !::fReindex && !::ChainstateActive().IsInitialBlockDownload(); }
|
||||
bool isInitialBlockDownload() override { return ::ChainstateActive().IsInitialBlockDownload(); }
|
||||
bool shutdownRequested() override { return ShutdownRequested(); }
|
||||
@ -366,9 +368,10 @@ public:
|
||||
notifications.TransactionAddedToMempool(entry.GetSharedTx(), 0);
|
||||
}
|
||||
}
|
||||
NodeContext& m_node;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
std::unique_ptr<Chain> MakeChain() { return MakeUnique<ChainImpl>(); }
|
||||
std::unique_ptr<Chain> MakeChain(NodeContext& node) { return MakeUnique<ChainImpl>(node); }
|
||||
|
||||
} // namespace interfaces
|
||||
|
@ -27,6 +27,7 @@ class uint256;
|
||||
struct bilingual_str;
|
||||
struct CBlockLocator;
|
||||
struct FeeCalculation;
|
||||
struct NodeContext;
|
||||
enum class MemPoolRemovalReason;
|
||||
|
||||
namespace llmq {
|
||||
@ -291,7 +292,7 @@ public:
|
||||
};
|
||||
|
||||
//! Return implementation of Chain interface.
|
||||
std::unique_ptr<Chain> MakeChain();
|
||||
std::unique_ptr<Chain> MakeChain(NodeContext& node);
|
||||
|
||||
//! Return implementation of ChainClient interface for a wallet client. This
|
||||
//! function will be undefined in builds where ENABLE_WALLET is false.
|
||||
|
@ -22,6 +22,7 @@
|
||||
#include <net_processing.h>
|
||||
#include <netaddress.h>
|
||||
#include <netbase.h>
|
||||
#include <node/context.h>
|
||||
#include <policy/feerate.h>
|
||||
#include <policy/fees.h>
|
||||
#include <policy/settings.h>
|
||||
@ -170,8 +171,6 @@ public:
|
||||
class NodeImpl : public Node
|
||||
{
|
||||
public:
|
||||
NodeImpl() { m_interfaces.chain = MakeChain(); }
|
||||
|
||||
EVOImpl m_evo;
|
||||
GOVImpl m_gov;
|
||||
LLMQImpl m_llmq;
|
||||
@ -199,17 +198,21 @@ public:
|
||||
return AppInitBasicSetup() && AppInitParameterInteraction() && AppInitSanityChecks() &&
|
||||
AppInitLockDataDirectory();
|
||||
}
|
||||
bool appInitMain() override { return AppInitMain(m_interfaces); }
|
||||
bool appInitMain() override
|
||||
{
|
||||
m_context.chain = MakeChain(m_context);
|
||||
return AppInitMain(m_context);
|
||||
}
|
||||
void appShutdown() override
|
||||
{
|
||||
Interrupt();
|
||||
Shutdown(m_interfaces);
|
||||
Interrupt(m_context);
|
||||
Shutdown(m_context);
|
||||
}
|
||||
void appPrepareShutdown() override
|
||||
{
|
||||
Interrupt();
|
||||
Interrupt(m_context);
|
||||
StartRestart();
|
||||
PrepareShutdown(m_interfaces);
|
||||
PrepareShutdown(m_context);
|
||||
}
|
||||
void startShutdown() override { StartShutdown(); }
|
||||
bool shutdownRequested() override { return ShutdownRequested(); }
|
||||
@ -218,15 +221,15 @@ public:
|
||||
bool getProxy(Network net, proxyType& proxy_info) override { return GetProxy(net, proxy_info); }
|
||||
size_t getNodeCount(CConnman::NumConnections flags) override
|
||||
{
|
||||
return g_connman ? g_connman->GetNodeCount(flags) : 0;
|
||||
return m_context.connman ? m_context.connman->GetNodeCount(flags) : 0;
|
||||
}
|
||||
bool getNodesStats(NodesStats& stats) override
|
||||
{
|
||||
stats.clear();
|
||||
|
||||
if (g_connman) {
|
||||
if (m_context.connman) {
|
||||
std::vector<CNodeStats> stats_temp;
|
||||
g_connman->GetNodeStats(stats_temp);
|
||||
m_context.connman->GetNodeStats(stats_temp);
|
||||
|
||||
stats.reserve(stats_temp.size());
|
||||
for (auto& node_stats_temp : stats_temp) {
|
||||
@ -247,44 +250,44 @@ public:
|
||||
}
|
||||
bool getBanned(banmap_t& banmap) override
|
||||
{
|
||||
if (g_banman) {
|
||||
g_banman->GetBanned(banmap);
|
||||
if (m_context.banman) {
|
||||
m_context.banman->GetBanned(banmap);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool ban(const CNetAddr& net_addr, BanReason reason, int64_t ban_time_offset) override
|
||||
{
|
||||
if (g_banman) {
|
||||
g_banman->Ban(net_addr, reason, ban_time_offset);
|
||||
if (m_context.banman) {
|
||||
m_context.banman->Ban(net_addr, reason, ban_time_offset);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool unban(const CSubNet& ip) override
|
||||
{
|
||||
if (g_banman) {
|
||||
g_banman->Unban(ip);
|
||||
if (m_context.banman) {
|
||||
m_context.banman->Unban(ip);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool disconnect(const CNetAddr& net_addr) override
|
||||
{
|
||||
if (g_connman) {
|
||||
return g_connman->DisconnectNode(net_addr);
|
||||
if (m_context.connman) {
|
||||
return m_context.connman->DisconnectNode(net_addr);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool disconnect(NodeId id) override
|
||||
{
|
||||
if (g_connman) {
|
||||
return g_connman->DisconnectNode(id);
|
||||
if (m_context.connman) {
|
||||
return m_context.connman->DisconnectNode(id);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
int64_t getTotalBytesRecv() override { return g_connman ? g_connman->GetTotalBytesRecv() : 0; }
|
||||
int64_t getTotalBytesSent() override { return g_connman ? g_connman->GetTotalBytesSent() : 0; }
|
||||
int64_t getTotalBytesRecv() override { return m_context.connman ? m_context.connman->GetTotalBytesRecv() : 0; }
|
||||
int64_t getTotalBytesSent() override { return m_context.connman ? m_context.connman->GetTotalBytesSent() : 0; }
|
||||
size_t getMempoolSize() override { return ::mempool.size(); }
|
||||
size_t getMempoolDynamicUsage() override { return ::mempool.DynamicMemoryUsage(); }
|
||||
bool getHeaderTip(int& height, int64_t& block_time) override
|
||||
@ -332,11 +335,11 @@ public:
|
||||
bool getImporting() override { return ::fImporting; }
|
||||
void setNetworkActive(bool active) override
|
||||
{
|
||||
if (g_connman) {
|
||||
g_connman->SetNetworkActive(active);
|
||||
if (m_context.connman) {
|
||||
m_context.connman->SetNetworkActive(active);
|
||||
}
|
||||
}
|
||||
bool getNetworkActive() override { return g_connman && g_connman->GetNetworkActive(); }
|
||||
bool getNetworkActive() override { return m_context.connman && m_context.connman->GetNetworkActive(); }
|
||||
CFeeRate estimateSmartFee(int num_blocks, bool conservative, int* returned_target = nullptr) override
|
||||
{
|
||||
FeeCalculation fee_calc;
|
||||
@ -385,7 +388,7 @@ public:
|
||||
}
|
||||
std::unique_ptr<Wallet> loadWallet(const std::string& name, bilingual_str& error, std::vector<bilingual_str>& warnings) override
|
||||
{
|
||||
return MakeWallet(LoadWallet(*m_interfaces.chain, name, error, warnings));
|
||||
return MakeWallet(LoadWallet(*m_context.chain, name, error, warnings));
|
||||
}
|
||||
|
||||
EVO& evo() override { return m_evo; }
|
||||
@ -397,7 +400,7 @@ public:
|
||||
WalletCreationStatus createWallet(const SecureString& passphrase, uint64_t wallet_creation_flags, const std::string& name, bilingual_str& error, std::vector<bilingual_str>& warnings, std::unique_ptr<Wallet>& result) override
|
||||
{
|
||||
std::shared_ptr<CWallet> wallet;
|
||||
WalletCreationStatus status = CreateWallet(*m_interfaces.chain, passphrase, wallet_creation_flags, name, error, warnings, wallet);
|
||||
WalletCreationStatus status = CreateWallet(*m_context.chain, passphrase, wallet_creation_flags, name, error, warnings, wallet);
|
||||
result = MakeWallet(wallet);
|
||||
return status;
|
||||
}
|
||||
@ -472,7 +475,8 @@ public:
|
||||
fn(nSyncProgress);
|
||||
}));
|
||||
}
|
||||
InitInterfaces m_interfaces;
|
||||
NodeContext* context() override { return &m_context; }
|
||||
NodeContext m_context;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
@ -32,6 +32,7 @@ class proxyType;
|
||||
struct bilingual_str;
|
||||
struct CNodeStateStats;
|
||||
enum class WalletCreationStatus;
|
||||
struct NodeContext;
|
||||
|
||||
namespace interfaces {
|
||||
class Handler;
|
||||
@ -352,6 +353,9 @@ public:
|
||||
using NotifyAdditionalDataSyncProgressChangedFn =
|
||||
std::function<void(double nSyncProgress)>;
|
||||
virtual std::unique_ptr<Handler> handleNotifyAdditionalDataSyncProgressChanged(NotifyAdditionalDataSyncProgressChangedFn fn) = 0;
|
||||
|
||||
//! Return pointer to internal chain interface, useful for testing.
|
||||
virtual NodeContext* context() { return nullptr; }
|
||||
};
|
||||
|
||||
//! Return implementation of Node interface.
|
||||
|
@ -575,7 +575,11 @@ public:
|
||||
: m_chain(chain), m_wallet_filenames(std::move(wallet_filenames))
|
||||
{
|
||||
}
|
||||
void registerRpcs() override { return RegisterWalletRPCCommands(m_chain, m_rpc_handlers); }
|
||||
void registerRpcs() override
|
||||
{
|
||||
g_rpc_chain = &m_chain;
|
||||
return RegisterWalletRPCCommands(m_chain, m_rpc_handlers);
|
||||
}
|
||||
bool verify() override { return VerifyWallets(m_chain, m_wallet_filenames); }
|
||||
bool load() override { return LoadWallets(m_chain, m_wallet_filenames); }
|
||||
void start(CScheduler& scheduler) override { return StartWallets(scheduler); }
|
||||
|
@ -660,8 +660,6 @@ private:
|
||||
|
||||
friend struct CConnmanTest;
|
||||
};
|
||||
extern std::unique_ptr<CConnman> g_connman;
|
||||
extern std::unique_ptr<BanMan> g_banman;
|
||||
void Discover();
|
||||
unsigned short GetListenPort();
|
||||
|
||||
|
@ -1220,7 +1220,7 @@ void PeerLogicValidation::BlockConnected(const std::shared_ptr<const CBlock>& pb
|
||||
|
||||
while (!orphanWorkSet.empty()) {
|
||||
LogPrint(BCLog::MEMPOOL, "Trying to process %d orphans\n", orphanWorkSet.size());
|
||||
ProcessOrphanTx(g_connman.get(), orphanWorkSet);
|
||||
ProcessOrphanTx(connman, orphanWorkSet);
|
||||
}
|
||||
|
||||
g_last_tip_update = GetTime();
|
||||
@ -2411,7 +2411,7 @@ std::pair<bool /*ret*/, bool /*do_return*/> static ValidateDSTX(CCoinJoinBroadca
|
||||
return {true, false};
|
||||
}
|
||||
|
||||
bool static ProcessMessage(CNode* pfrom, const std::string& msg_type, CDataStream& vRecv, int64_t nTimeReceived, const CChainParams& chainparams, CConnman* connman, const std::atomic<bool>& interruptMsgProc, bool enable_bip61)
|
||||
bool static ProcessMessage(CNode* pfrom, const std::string& msg_type, CDataStream& vRecv, int64_t nTimeReceived, const CChainParams& chainparams, CConnman* connman, BanMan* banman, const std::atomic<bool>& interruptMsgProc, bool enable_bip61)
|
||||
{
|
||||
LogPrint(BCLog::NET, "received: %s (%u bytes) peer=%d\n", SanitizeString(msg_type), vRecv.size(), pfrom->GetId());
|
||||
statsClient.inc("message.received." + SanitizeString(msg_type), 1.0f);
|
||||
@ -2782,7 +2782,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& msg_type, CDataStrea
|
||||
if (addr.nTime <= 100000000 || addr.nTime > nNow + 10 * 60)
|
||||
addr.nTime = nNow - 5 * 24 * 60 * 60;
|
||||
pfrom->AddAddressKnown(addr);
|
||||
if (g_banman->IsBanned(addr)) continue; // Do not process banned addresses beyond remembering we received them
|
||||
if (banman->IsBanned(addr)) continue; // Do not process banned addresses beyond remembering we received them
|
||||
bool fReachable = IsReachable(addr);
|
||||
if (addr.nTime > nSince && !pfrom->fGetAddr && vAddr.size() <= 10 && addr.IsRoutable())
|
||||
{
|
||||
@ -3509,7 +3509,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& msg_type, CDataStrea
|
||||
} // cs_main
|
||||
|
||||
if (fProcessBLOCKTXN)
|
||||
return ProcessMessage(pfrom, NetMsgType::BLOCKTXN, blockTxnMsg, nTimeReceived, chainparams, connman, interruptMsgProc, enable_bip61);
|
||||
return ProcessMessage(pfrom, NetMsgType::BLOCKTXN, blockTxnMsg, nTimeReceived, chainparams, connman, banman, interruptMsgProc, enable_bip61);
|
||||
|
||||
if (fRevertToHeaderProcessing) {
|
||||
// Headers received from HB compact block peers are permitted to be
|
||||
@ -3736,7 +3736,7 @@ bool static ProcessMessage(CNode* pfrom, const std::string& msg_type, CDataStrea
|
||||
std::vector<CAddress> vAddr = connman->GetAddresses();
|
||||
FastRandomContext insecure_rand;
|
||||
for (const CAddress &addr : vAddr) {
|
||||
if (!g_banman->IsBanned(addr)) {
|
||||
if (!banman->IsBanned(addr)) {
|
||||
pfrom->PushAddress(addr, insecure_rand);
|
||||
}
|
||||
}
|
||||
@ -4137,7 +4137,7 @@ bool PeerLogicValidation::ProcessMessages(CNode* pfrom, std::atomic<bool>& inter
|
||||
bool fRet = false;
|
||||
try
|
||||
{
|
||||
fRet = ProcessMessage(pfrom, msg_type, vRecv, msg.m_time, chainparams, connman, interruptMsgProc, m_enable_bip61);
|
||||
fRet = ProcessMessage(pfrom, msg_type, vRecv, msg.m_time, chainparams, connman, m_banman, interruptMsgProc, m_enable_bip61);
|
||||
if (interruptMsgProc)
|
||||
return false;
|
||||
if (!pfrom->vRecvGetData.empty())
|
||||
|
13
src/node/context.cpp
Normal file
13
src/node/context.cpp
Normal file
@ -0,0 +1,13 @@
|
||||
// Copyright (c) 2019 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <node/context.h>
|
||||
|
||||
#include <banman.h>
|
||||
#include <interfaces/chain.h>
|
||||
#include <net.h>
|
||||
#include <net_processing.h>
|
||||
|
||||
NodeContext::NodeContext() {}
|
||||
NodeContext::~NodeContext() {}
|
44
src/node/context.h
Normal file
44
src/node/context.h
Normal file
@ -0,0 +1,44 @@
|
||||
// Copyright (c) 2019 The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#ifndef BITCOIN_NODE_CONTEXT_H
|
||||
#define BITCOIN_NODE_CONTEXT_H
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
class BanMan;
|
||||
class CConnman;
|
||||
class PeerLogicValidation;
|
||||
namespace interfaces {
|
||||
class Chain;
|
||||
class ChainClient;
|
||||
} // namespace interfaces
|
||||
|
||||
//! NodeContext struct containing references to chain state and connection
|
||||
//! state.
|
||||
//!
|
||||
//! This is used by init, rpc, and test code to pass object references around
|
||||
//! without needing to declare the same variables and parameters repeatedly, or
|
||||
//! to use globals. More variables could be added to this struct (particularly
|
||||
//! references to validation and mempool objects) to eliminate use of globals
|
||||
//! and make code more modular and testable. The struct isn't intended to have
|
||||
//! any member functions. It should just be a collection of references that can
|
||||
//! be used without pulling in unwanted dependencies or functionality.
|
||||
struct NodeContext
|
||||
{
|
||||
std::unique_ptr<CConnman> connman;
|
||||
std::unique_ptr<PeerLogicValidation> peer_logic;
|
||||
std::unique_ptr<BanMan> banman;
|
||||
std::unique_ptr<interfaces::Chain> chain;
|
||||
std::vector<std::unique_ptr<interfaces::ChainClient>> chain_clients;
|
||||
|
||||
//! Declare default constructor and destructor that are not inline, so code
|
||||
//! instantiating the NodeContext struct doesn't need to #include class
|
||||
//! definitions for all the unique_ptr members.
|
||||
NodeContext();
|
||||
~NodeContext();
|
||||
};
|
||||
|
||||
#endif // BITCOIN_NODE_CONTEXT_H
|
@ -10,13 +10,14 @@
|
||||
#include <util/validation.h>
|
||||
#include <validation.h>
|
||||
#include <validationinterface.h>
|
||||
#include <node/context.h>
|
||||
#include <node/transaction.h>
|
||||
|
||||
#include <future>
|
||||
|
||||
TransactionError BroadcastTransaction(const CTransactionRef tx, std::string& err_string, const CAmount& max_tx_fee, bool relay, bool wait_callback, bool bypass_limits)
|
||||
TransactionError BroadcastTransaction(NodeContext& node, const CTransactionRef tx, std::string& err_string, const CAmount& max_tx_fee, bool relay, bool wait_callback, bool bypass_limits)
|
||||
{
|
||||
assert(g_connman);
|
||||
assert(node.connman);
|
||||
std::promise<void> promise;
|
||||
uint256 hashTx = tx->GetHash();
|
||||
bool callback_set = false;
|
||||
@ -77,7 +78,7 @@ TransactionError BroadcastTransaction(const CTransactionRef tx, std::string& err
|
||||
}
|
||||
|
||||
if (relay) {
|
||||
RelayTransaction(hashTx, *g_connman);
|
||||
RelayTransaction(hashTx, *node.connman);
|
||||
}
|
||||
|
||||
return TransactionError::OK;
|
||||
|
@ -9,6 +9,8 @@
|
||||
#include <primitives/transaction.h>
|
||||
#include <util/error.h>
|
||||
|
||||
struct NodeContext;
|
||||
|
||||
/**
|
||||
* Submit a transaction to the mempool and (optionally) relay it to all P2P peers.
|
||||
*
|
||||
@ -18,6 +20,7 @@
|
||||
* NOT be set while cs_main, cs_mempool or cs_wallet are held to avoid
|
||||
* deadlock.
|
||||
*
|
||||
* @param[in] node reference to node context
|
||||
* @param[in] tx the transaction to broadcast
|
||||
* @param[out] &err_string reference to std::string to fill with error string if available
|
||||
* @param[in] max_tx_fee reject txs with fees higher than this (if 0, accept any fee)
|
||||
@ -25,6 +28,6 @@
|
||||
* @param[in] wait_callback, wait until callbacks have been processed to avoid stale result due to a sequentially RPC.
|
||||
* return error
|
||||
*/
|
||||
[[nodiscard]] TransactionError BroadcastTransaction(CTransactionRef tx, std::string& err_string, const CAmount& highfee, bool relay, bool wait_callback, bool bypass_limits = false);
|
||||
[[nodiscard]] TransactionError BroadcastTransaction(NodeContext& node, CTransactionRef tx, std::string& err_string, const CAmount& highfee, bool relay, bool wait_callback, bool bypass_limits = false);
|
||||
|
||||
#endif // BITCOIN_NODE_TRANSACTION_H
|
||||
|
@ -54,11 +54,10 @@ void EditAddressAndSubmit(
|
||||
* In each case, verify the resulting state of the address book and optionally
|
||||
* the warning message presented to the user.
|
||||
*/
|
||||
void TestAddAddressesToSendBook()
|
||||
void TestAddAddressesToSendBook(interfaces::Node& node)
|
||||
{
|
||||
TestChain100Setup test;
|
||||
auto chain = interfaces::MakeChain();
|
||||
std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(chain.get(), WalletLocation(), CreateMockWalletDatabase());
|
||||
std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(node.context()->chain.get(), WalletLocation(), CreateMockWalletDatabase());
|
||||
bool firstRun;
|
||||
wallet->LoadWallet(firstRun);
|
||||
|
||||
@ -102,10 +101,9 @@ void TestAddAddressesToSendBook()
|
||||
check_addbook_size(2);
|
||||
|
||||
// Initialize relevant QT models.
|
||||
auto node = interfaces::MakeNode();
|
||||
OptionsModel optionsModel(*node);
|
||||
OptionsModel optionsModel(node);
|
||||
AddWallet(wallet);
|
||||
WalletModel walletModel(std::move(node->getWallets()[0]), *node, &optionsModel);
|
||||
WalletModel walletModel(interfaces::MakeWallet(wallet), node, &optionsModel);
|
||||
RemoveWallet(wallet);
|
||||
EditAddressDialog editAddressDialog(EditAddressDialog::NewSendingAddress);
|
||||
editAddressDialog.setModel(walletModel.getAddressTableModel());
|
||||
@ -151,5 +149,5 @@ void AddressBookTests::addressBookTests()
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
TestAddAddressesToSendBook();
|
||||
TestAddAddressesToSendBook(m_node);
|
||||
}
|
||||
|
@ -8,8 +8,16 @@
|
||||
#include <QObject>
|
||||
#include <QTest>
|
||||
|
||||
namespace interfaces {
|
||||
class Node;
|
||||
} // namespace interfaces
|
||||
|
||||
class AddressBookTests : public QObject
|
||||
{
|
||||
public:
|
||||
AddressBookTests(interfaces::Node& node) : m_node(node) {}
|
||||
interfaces::Node& m_node;
|
||||
|
||||
Q_OBJECT
|
||||
|
||||
private Q_SLOTS:
|
||||
|
@ -43,7 +43,7 @@ void RPCNestedTests::rpcNestedTests()
|
||||
std::string result;
|
||||
std::string result2;
|
||||
std::string filtered;
|
||||
auto node = interfaces::MakeNode();
|
||||
interfaces::Node* node = &m_node;
|
||||
RPCConsole::RPCExecuteCommandLine(*node, result, "getblockchaininfo()[chain]", &filtered); //simple result filtering with path
|
||||
QVERIFY(result=="main");
|
||||
QVERIFY(filtered == "getblockchaininfo()[chain]");
|
||||
|
@ -8,8 +8,16 @@
|
||||
#include <QObject>
|
||||
#include <QTest>
|
||||
|
||||
namespace interfaces {
|
||||
class Node;
|
||||
} // namespace interfaces
|
||||
|
||||
class RPCNestedTests : public QObject
|
||||
{
|
||||
public:
|
||||
RPCNestedTests(interfaces::Node& node) : m_node(node) {}
|
||||
interfaces::Node& m_node;
|
||||
|
||||
Q_OBJECT
|
||||
|
||||
private Q_SLOTS:
|
||||
|
@ -61,7 +61,7 @@ int main(int argc, char *argv[])
|
||||
BasicTestingSetup dummy{CBaseChainParams::REGTEST};
|
||||
}
|
||||
|
||||
auto node = interfaces::MakeNode();
|
||||
std::unique_ptr<interfaces::Node> node = interfaces::MakeNode();
|
||||
|
||||
bool fInvalid = false;
|
||||
|
||||
@ -97,7 +97,7 @@ int main(int argc, char *argv[])
|
||||
fInvalid = true;
|
||||
}
|
||||
#endif
|
||||
RPCNestedTests test3;
|
||||
RPCNestedTests test3(*node);
|
||||
if (QTest::qExec(&test3) != 0) {
|
||||
fInvalid = true;
|
||||
}
|
||||
@ -106,11 +106,11 @@ int main(int argc, char *argv[])
|
||||
fInvalid = true;
|
||||
}
|
||||
#ifdef ENABLE_WALLET
|
||||
WalletTests test5;
|
||||
WalletTests test5(*node);
|
||||
if (QTest::qExec(&test5) != 0) {
|
||||
fInvalid = true;
|
||||
}
|
||||
AddressBookTests test6;
|
||||
AddressBookTests test6(*node);
|
||||
if (QTest::qExec(&test6) != 0) {
|
||||
fInvalid = true;
|
||||
}
|
||||
|
@ -101,15 +101,15 @@ QModelIndex FindTx(const QAbstractItemModel& model, const uint256& txid)
|
||||
// QT_QPA_PLATFORM=xcb src/qt/test/test_dash-qt # Linux
|
||||
// QT_QPA_PLATFORM=windows src/qt/test/test_dash-qt # Windows
|
||||
// QT_QPA_PLATFORM=cocoa src/qt/test/test_dash-qt # macOS
|
||||
void TestGUI()
|
||||
void TestGUI(interfaces::Node& node)
|
||||
{
|
||||
// Set up wallet and chain with 105 blocks (5 mature blocks for spending).
|
||||
TestChain100Setup test;
|
||||
for (int i = 0; i < 5; ++i) {
|
||||
test.CreateAndProcessBlock({}, GetScriptForRawPubKey(test.coinbaseKey.GetPubKey()));
|
||||
}
|
||||
auto chain = interfaces::MakeChain();
|
||||
std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(chain.get(), WalletLocation(), CreateMockWalletDatabase());
|
||||
node.context()->connman = std::move(test.m_node.connman);
|
||||
std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(node.context()->chain.get(), WalletLocation(), CreateMockWalletDatabase());
|
||||
AddWallet(wallet);
|
||||
bool firstRun;
|
||||
wallet->LoadWallet(firstRun);
|
||||
@ -136,10 +136,9 @@ void TestGUI()
|
||||
// Create widgets for sending coins and listing transactions.
|
||||
SendCoinsDialog sendCoinsDialog;
|
||||
TransactionView transactionView;
|
||||
auto node = interfaces::MakeNode();
|
||||
OptionsModel optionsModel(*node);
|
||||
ClientModel clientModel(*node, &optionsModel);
|
||||
WalletModel walletModel(std::move(node->getWallets()[0]), *node, &optionsModel);;
|
||||
OptionsModel optionsModel(node);
|
||||
ClientModel clientModel(node, &optionsModel);
|
||||
WalletModel walletModel(interfaces::MakeWallet(wallet), node, &optionsModel);;
|
||||
sendCoinsDialog.setModel(&walletModel);
|
||||
transactionView.setModel(&walletModel);
|
||||
|
||||
@ -232,5 +231,5 @@ void WalletTests::walletTests()
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
TestGUI();
|
||||
TestGUI(m_node);
|
||||
}
|
||||
|
@ -8,8 +8,16 @@
|
||||
#include <QObject>
|
||||
#include <QTest>
|
||||
|
||||
namespace interfaces {
|
||||
class Node;
|
||||
} // namespace interfaces
|
||||
|
||||
class WalletTests : public QObject
|
||||
{
|
||||
public:
|
||||
WalletTests(interfaces::Node& node) : m_node(node) {}
|
||||
interfaces::Node& m_node;
|
||||
|
||||
Q_OBJECT
|
||||
|
||||
private Q_SLOTS:
|
||||
|
@ -2769,3 +2769,5 @@ void RegisterBlockchainRPCCommands(CRPCTable &t)
|
||||
for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++)
|
||||
t.appendCommand(commands[vcidx].name, &commands[vcidx]);
|
||||
}
|
||||
|
||||
NodeContext* g_rpc_node = nullptr;
|
||||
|
@ -13,6 +13,7 @@ class CBlock;
|
||||
class CBlockIndex;
|
||||
class CTxMemPool;
|
||||
class UniValue;
|
||||
struct NodeContext;
|
||||
|
||||
static constexpr int NUM_GETBLOCKSTATS_PERCENTILES = 5;
|
||||
|
||||
@ -42,4 +43,9 @@ UniValue blockheaderToJSON(const CBlockIndex* tip, const CBlockIndex* blockindex
|
||||
/** Used by getblockstats to get feerates at different percentiles by weight */
|
||||
void CalculatePercentilesBySize(CAmount result[NUM_GETBLOCKSTATS_PERCENTILES], std::vector<std::pair<CAmount, int64_t>>& scores, int64_t total_size);
|
||||
|
||||
//! Pointer to node state that needs to be declared as a global to be accessible
|
||||
//! RPC methods. Due to limitations of the RPC framework, there's currently no
|
||||
//! direct way to pass in state to RPC methods without globals.
|
||||
extern NodeContext* g_rpc_node;
|
||||
|
||||
#endif
|
||||
|
@ -2,6 +2,7 @@
|
||||
// Distributed under the MIT/X11 software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <node/context.h>
|
||||
#include <validation.h>
|
||||
#ifdef ENABLE_WALLET
|
||||
#include <coinjoin/client.h>
|
||||
@ -9,6 +10,7 @@
|
||||
#include <wallet/rpcwallet.h>
|
||||
#endif // ENABLE_WALLET
|
||||
#include <coinjoin/server.h>
|
||||
#include <rpc/blockchain.h>
|
||||
#include <rpc/server.h>
|
||||
#include <rpc/util.h>
|
||||
#include <util/strencodings.h>
|
||||
@ -63,7 +65,7 @@ static UniValue coinjoin(const JSONRPCRequest& request)
|
||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "Mixing has been started already.");
|
||||
}
|
||||
|
||||
bool result = it->second->DoAutomaticDenominating(*g_connman);
|
||||
bool result = it->second->DoAutomaticDenominating(*g_rpc_node->connman);
|
||||
return "Mixing " + (result ? "started successfully" : ("start failed: " + it->second->GetStatuses().original + ", will retry"));
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,9 @@
|
||||
#include <masternode/node.h>
|
||||
#include <masternode/sync.h>
|
||||
#include <messagesigner.h>
|
||||
#include <node/context.h>
|
||||
#include <net.h>
|
||||
#include <rpc/blockchain.h>
|
||||
#include <rpc/server.h>
|
||||
#include <rpc/util.h>
|
||||
#include <util/system.h>
|
||||
@ -410,9 +412,9 @@ static UniValue gobject_submit(const JSONRPCRequest& request)
|
||||
|
||||
if (fMissingConfirmations) {
|
||||
governance.AddPostponedObject(govobj);
|
||||
govobj.Relay(*g_connman);
|
||||
govobj.Relay(*g_rpc_node->connman);
|
||||
} else {
|
||||
governance.AddGovernanceObject(govobj, *g_connman);
|
||||
governance.AddGovernanceObject(govobj, *g_rpc_node->connman);
|
||||
}
|
||||
|
||||
return govobj.GetHash().ToString();
|
||||
@ -510,7 +512,7 @@ static UniValue gobject_vote_conf(const JSONRPCRequest& request)
|
||||
}
|
||||
|
||||
CGovernanceException exception;
|
||||
if (governance.ProcessVoteAndRelay(vote, exception, *g_connman)) {
|
||||
if (governance.ProcessVoteAndRelay(vote, exception, *g_rpc_node->connman)) {
|
||||
nSuccessful++;
|
||||
statusObj.pushKV("result", "success");
|
||||
} else {
|
||||
@ -571,7 +573,7 @@ static UniValue VoteWithMasternodes(const std::map<uint256, CKey>& keys,
|
||||
}
|
||||
|
||||
CGovernanceException exception;
|
||||
if (governance.ProcessVoteAndRelay(vote, exception, *g_connman)) {
|
||||
if (governance.ProcessVoteAndRelay(vote, exception, *g_rpc_node->connman)) {
|
||||
nSuccessful++;
|
||||
statusObj.pushKV("result", "success");
|
||||
} else {
|
||||
@ -1143,7 +1145,7 @@ static UniValue voteraw(const JSONRPCRequest& request)
|
||||
}
|
||||
|
||||
CGovernanceException exception;
|
||||
if (governance.ProcessVoteAndRelay(vote, exception, *g_connman)) {
|
||||
if (governance.ProcessVoteAndRelay(vote, exception, *g_rpc_node->connman)) {
|
||||
return "Voted successfully";
|
||||
} else {
|
||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "Error voting : " + exception.GetMessage());
|
||||
|
@ -6,10 +6,12 @@
|
||||
#include <evo/deterministicmns.h>
|
||||
#include <governance/classes.h>
|
||||
#include <index/txindex.h>
|
||||
#include <node/context.h>
|
||||
#include <masternode/node.h>
|
||||
#include <masternode/payments.h>
|
||||
#include <net.h>
|
||||
#include <netbase.h>
|
||||
#include <rpc/blockchain.h>
|
||||
#include <rpc/server.h>
|
||||
#include <rpc/util.h>
|
||||
#include <univalue.h>
|
||||
@ -91,8 +93,8 @@ static UniValue masternode_connect(const JSONRPCRequest& request)
|
||||
throw JSONRPCError(RPC_INTERNAL_ERROR, strprintf("Incorrect masternode address %s", strAddress));
|
||||
|
||||
// TODO: Pass CConnman instance somehow and don't use global variable.
|
||||
g_connman->OpenMasternodeConnection(CAddress(addr, NODE_NETWORK));
|
||||
if (!g_connman->IsConnected(CAddress(addr, NODE_NETWORK), CConnman::AllNodes))
|
||||
g_rpc_node->connman->OpenMasternodeConnection(CAddress(addr, NODE_NETWORK));
|
||||
if (!g_rpc_node->connman->IsConnected(CAddress(addr, NODE_NETWORK), CConnman::AllNodes))
|
||||
throw JSONRPCError(RPC_INTERNAL_ERROR, strprintf("Couldn't connect to masternode %s", strAddress));
|
||||
|
||||
return "successfully connected";
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include <key_io.h>
|
||||
#include <miner.h>
|
||||
#include <net.h>
|
||||
#include <node/context.h>
|
||||
#include <policy/fees.h>
|
||||
#include <pow.h>
|
||||
#include <rpc/blockchain.h>
|
||||
@ -462,10 +463,10 @@ static UniValue getblocktemplate(const JSONRPCRequest& request)
|
||||
if (strMode != "template")
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid mode");
|
||||
|
||||
if(!g_connman)
|
||||
if(!g_rpc_node->connman)
|
||||
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
|
||||
|
||||
if (g_connman->GetNodeCount(CConnman::CONNECTIONS_ALL) == 0)
|
||||
if (g_rpc_node->connman->GetNodeCount(CConnman::CONNECTIONS_ALL) == 0)
|
||||
throw JSONRPCError(RPC_CLIENT_NOT_CONNECTED, PACKAGE_NAME " is not connected!");
|
||||
|
||||
if (::ChainstateActive().IsInitialBlockDownload())
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include <httpserver.h>
|
||||
#include <key_io.h>
|
||||
#include <net.h>
|
||||
#include <node/context.h>
|
||||
#include <rpc/blockchain.h>
|
||||
#include <rpc/server.h>
|
||||
#include <rpc/util.h>
|
||||
@ -101,7 +102,7 @@ static UniValue mnsync(const JSONRPCRequest& request)
|
||||
|
||||
if(strMode == "next")
|
||||
{
|
||||
masternodeSync.SwitchToNextAsset(*g_connman);
|
||||
masternodeSync.SwitchToNextAsset(*g_rpc_node->connman);
|
||||
return "sync updated to " + masternodeSync.GetAssetName();
|
||||
}
|
||||
|
||||
@ -166,14 +167,14 @@ static UniValue spork(const JSONRPCRequest& request)
|
||||
if(nSporkID == SPORK_INVALID)
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid spork name");
|
||||
|
||||
if (!g_connman)
|
||||
if (!g_rpc_node->connman)
|
||||
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
|
||||
|
||||
// SPORK VALUE
|
||||
int64_t nValue = request.params[1].get_int64();
|
||||
|
||||
//broadcast new spork
|
||||
if(sporkManager.UpdateSpork(nSporkID, nValue, *g_connman)){
|
||||
if(sporkManager.UpdateSpork(nSporkID, nValue, *g_rpc_node->connman)){
|
||||
return "success";
|
||||
} else {
|
||||
throw std::runtime_error(
|
||||
@ -580,7 +581,7 @@ static UniValue mnauth(const JSONRPCRequest& request)
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "publicKey invalid");
|
||||
}
|
||||
|
||||
bool fSuccess = g_connman->ForNode(nodeId, CConnman::AllNodes, [&](CNode* pNode){
|
||||
bool fSuccess = g_rpc_node->connman->ForNode(nodeId, CConnman::AllNodes, [&](CNode* pNode){
|
||||
pNode->SetVerifiedProRegTxHash(proTxHash);
|
||||
pNode->SetVerifiedPubKeyHash(publicKey.GetHash());
|
||||
return true;
|
||||
|
@ -13,7 +13,9 @@
|
||||
#include <net_processing.h>
|
||||
#include <net_types.h> // For banmap_t
|
||||
#include <netbase.h>
|
||||
#include <node/context.h>
|
||||
#include <policy/settings.h>
|
||||
#include <rpc/blockchain.h>
|
||||
#include <rpc/protocol.h>
|
||||
#include <rpc/util.h>
|
||||
#include <sync.h>
|
||||
@ -42,10 +44,10 @@ static UniValue getconnectioncount(const JSONRPCRequest& request)
|
||||
},
|
||||
}.ToString());
|
||||
|
||||
if(!g_connman)
|
||||
if(!g_rpc_node->connman)
|
||||
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
|
||||
|
||||
return (int)g_connman->GetNodeCount(CConnman::CONNECTIONS_ALL);
|
||||
return (int)g_rpc_node->connman->GetNodeCount(CConnman::CONNECTIONS_ALL);
|
||||
}
|
||||
|
||||
static UniValue ping(const JSONRPCRequest& request)
|
||||
@ -64,11 +66,11 @@ static UniValue ping(const JSONRPCRequest& request)
|
||||
},
|
||||
}.ToString());
|
||||
|
||||
if(!g_connman)
|
||||
if(!g_rpc_node->connman)
|
||||
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
|
||||
|
||||
// Request that each node send a ping during next message processing pass
|
||||
g_connman->ForEachNode([](CNode* pnode) {
|
||||
g_rpc_node->connman->ForEachNode([](CNode* pnode) {
|
||||
pnode->fPingQueued = true;
|
||||
});
|
||||
return NullUniValue;
|
||||
@ -146,11 +148,11 @@ static UniValue getpeerinfo(const JSONRPCRequest& request)
|
||||
},
|
||||
}.ToString());
|
||||
|
||||
if(!g_connman)
|
||||
if(!g_rpc_node->connman)
|
||||
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
|
||||
|
||||
std::vector<CNodeStats> vstats;
|
||||
g_connman->GetNodeStats(vstats);
|
||||
g_rpc_node->connman->GetNodeStats(vstats);
|
||||
|
||||
UniValue ret(UniValue::VARR);
|
||||
|
||||
@ -261,7 +263,7 @@ static UniValue addnode(const JSONRPCRequest& request)
|
||||
},
|
||||
}.ToString());
|
||||
|
||||
if(!g_connman)
|
||||
if(!g_rpc_node->connman)
|
||||
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
|
||||
|
||||
std::string strNode = request.params[0].get_str();
|
||||
@ -269,18 +271,18 @@ static UniValue addnode(const JSONRPCRequest& request)
|
||||
if (strCommand == "onetry")
|
||||
{
|
||||
CAddress addr;
|
||||
g_connman->OpenNetworkConnection(addr, false, nullptr, strNode.c_str(), false, false, true);
|
||||
g_rpc_node->connman->OpenNetworkConnection(addr, false, nullptr, strNode.c_str(), false, false, true);
|
||||
return NullUniValue;
|
||||
}
|
||||
|
||||
if (strCommand == "add")
|
||||
{
|
||||
if(!g_connman->AddNode(strNode))
|
||||
if(!g_rpc_node->connman->AddNode(strNode))
|
||||
throw JSONRPCError(RPC_CLIENT_NODE_ALREADY_ADDED, "Error: Node already added");
|
||||
}
|
||||
else if(strCommand == "remove")
|
||||
{
|
||||
if(!g_connman->RemoveAddedNode(strNode))
|
||||
if(!g_rpc_node->connman->RemoveAddedNode(strNode))
|
||||
throw JSONRPCError(RPC_CLIENT_NODE_NOT_ADDED, "Error: Node has not been added.");
|
||||
}
|
||||
|
||||
@ -308,7 +310,7 @@ static UniValue disconnectnode(const JSONRPCRequest& request)
|
||||
},
|
||||
}.ToString());
|
||||
|
||||
if(!g_connman)
|
||||
if(!g_rpc_node->connman)
|
||||
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
|
||||
|
||||
bool success;
|
||||
@ -317,11 +319,11 @@ static UniValue disconnectnode(const JSONRPCRequest& request)
|
||||
|
||||
if (!address_arg.isNull() && id_arg.isNull()) {
|
||||
/* handle disconnect-by-address */
|
||||
success = g_connman->DisconnectNode(address_arg.get_str());
|
||||
success = g_rpc_node->connman->DisconnectNode(address_arg.get_str());
|
||||
} else if (!id_arg.isNull() && (address_arg.isNull() || (address_arg.isStr() && address_arg.get_str().empty()))) {
|
||||
/* handle disconnect-by-id */
|
||||
NodeId nodeid = (NodeId) id_arg.get_int64();
|
||||
success = g_connman->DisconnectNode(nodeid);
|
||||
success = g_rpc_node->connman->DisconnectNode(nodeid);
|
||||
} else {
|
||||
throw JSONRPCError(RPC_INVALID_PARAMS, "Only one of address and nodeid should be provided.");
|
||||
}
|
||||
@ -365,10 +367,10 @@ static UniValue getaddednodeinfo(const JSONRPCRequest& request)
|
||||
},
|
||||
}.ToString());
|
||||
|
||||
if(!g_connman)
|
||||
if(!g_rpc_node->connman)
|
||||
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
|
||||
|
||||
std::vector<AddedNodeInfo> vInfo = g_connman->GetAddedNodeInfo();
|
||||
std::vector<AddedNodeInfo> vInfo = g_rpc_node->connman->GetAddedNodeInfo();
|
||||
|
||||
if (!request.params[0].isNull()) {
|
||||
bool found = false;
|
||||
@ -434,21 +436,21 @@ static UniValue getnettotals(const JSONRPCRequest& request)
|
||||
+ HelpExampleRpc("getnettotals", "")
|
||||
},
|
||||
}.ToString());
|
||||
if(!g_connman)
|
||||
if(!g_rpc_node->connman)
|
||||
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
|
||||
|
||||
UniValue obj(UniValue::VOBJ);
|
||||
obj.pushKV("totalbytesrecv", g_connman->GetTotalBytesRecv());
|
||||
obj.pushKV("totalbytessent", g_connman->GetTotalBytesSent());
|
||||
obj.pushKV("totalbytesrecv", g_rpc_node->connman->GetTotalBytesRecv());
|
||||
obj.pushKV("totalbytessent", g_rpc_node->connman->GetTotalBytesSent());
|
||||
obj.pushKV("timemillis", GetTimeMillis());
|
||||
|
||||
UniValue outboundLimit(UniValue::VOBJ);
|
||||
outboundLimit.pushKV("timeframe", g_connman->GetMaxOutboundTimeframe());
|
||||
outboundLimit.pushKV("target", g_connman->GetMaxOutboundTarget());
|
||||
outboundLimit.pushKV("target_reached", g_connman->OutboundTargetReached(false));
|
||||
outboundLimit.pushKV("serve_historical_blocks", !g_connman->OutboundTargetReached(true));
|
||||
outboundLimit.pushKV("bytes_left_in_cycle", g_connman->GetOutboundTargetBytesLeft());
|
||||
outboundLimit.pushKV("time_left_in_cycle", g_connman->GetMaxOutboundTimeLeftInCycle());
|
||||
outboundLimit.pushKV("timeframe", g_rpc_node->connman->GetMaxOutboundTimeframe());
|
||||
outboundLimit.pushKV("target", g_rpc_node->connman->GetMaxOutboundTarget());
|
||||
outboundLimit.pushKV("target_reached", g_rpc_node->connman->OutboundTargetReached(false));
|
||||
outboundLimit.pushKV("serve_historical_blocks", !g_rpc_node->connman->OutboundTargetReached(true));
|
||||
outboundLimit.pushKV("bytes_left_in_cycle", g_rpc_node->connman->GetOutboundTargetBytesLeft());
|
||||
outboundLimit.pushKV("time_left_in_cycle", g_rpc_node->connman->GetMaxOutboundTimeLeftInCycle());
|
||||
obj.pushKV("uploadtarget", outboundLimit);
|
||||
return obj;
|
||||
}
|
||||
@ -532,18 +534,18 @@ static UniValue getnetworkinfo(const JSONRPCRequest& request)
|
||||
obj.pushKV("buildversion", FormatFullVersion());
|
||||
obj.pushKV("subversion", strSubVersion);
|
||||
obj.pushKV("protocolversion",PROTOCOL_VERSION);
|
||||
if (g_connman) {
|
||||
ServiceFlags services = g_connman->GetLocalServices();
|
||||
if (g_rpc_node->connman) {
|
||||
ServiceFlags services = g_rpc_node->connman->GetLocalServices();
|
||||
obj.pushKV("localservices", strprintf("%016x", services));
|
||||
obj.pushKV("localservicesnames", GetServicesNames(services));
|
||||
}
|
||||
obj.pushKV("localrelay", g_relay_txes);
|
||||
obj.pushKV("timeoffset", GetTimeOffset());
|
||||
if (g_connman) {
|
||||
obj.pushKV("networkactive", g_connman->GetNetworkActive());
|
||||
obj.pushKV("connections", (int)g_connman->GetNodeCount(CConnman::CONNECTIONS_ALL));
|
||||
if (g_rpc_node->connman) {
|
||||
obj.pushKV("networkactive", g_rpc_node->connman->GetNetworkActive());
|
||||
obj.pushKV("connections", (int)g_rpc_node->connman->GetNodeCount(CConnman::CONNECTIONS_ALL));
|
||||
std::string strSocketEvents;
|
||||
switch (g_connman->GetSocketEventsMode()) {
|
||||
switch (g_rpc_node->connman->GetSocketEventsMode()) {
|
||||
case CConnman::SOCKETEVENTS_SELECT:
|
||||
strSocketEvents = "select";
|
||||
break;
|
||||
@ -604,7 +606,7 @@ static UniValue setban(const JSONRPCRequest& request)
|
||||
if (request.fHelp || !help.IsValidNumArgs(request.params.size()) || (strCommand != "add" && strCommand != "remove")) {
|
||||
throw std::runtime_error(help.ToString());
|
||||
}
|
||||
if (!g_banman) {
|
||||
if (!g_rpc_node->banman) {
|
||||
throw JSONRPCError(RPC_DATABASE_ERROR, "Error: Ban database not loaded");
|
||||
}
|
||||
|
||||
@ -628,7 +630,7 @@ static UniValue setban(const JSONRPCRequest& request)
|
||||
|
||||
if (strCommand == "add")
|
||||
{
|
||||
if (isSubnet ? g_banman->IsBanned(subNet) : g_banman->IsBanned(netAddr)) {
|
||||
if (isSubnet ? g_rpc_node->banman->IsBanned(subNet) : g_rpc_node->banman->IsBanned(netAddr)) {
|
||||
throw JSONRPCError(RPC_CLIENT_NODE_ALREADY_ADDED, "Error: IP/Subnet already banned");
|
||||
}
|
||||
|
||||
@ -641,20 +643,20 @@ static UniValue setban(const JSONRPCRequest& request)
|
||||
absolute = true;
|
||||
|
||||
if (isSubnet) {
|
||||
g_banman->Ban(subNet, BanReasonManuallyAdded, banTime, absolute);
|
||||
if (g_connman) {
|
||||
g_connman->DisconnectNode(subNet);
|
||||
g_rpc_node->banman->Ban(subNet, BanReasonManuallyAdded, banTime, absolute);
|
||||
if (g_rpc_node->connman) {
|
||||
g_rpc_node->connman->DisconnectNode(subNet);
|
||||
}
|
||||
} else {
|
||||
g_banman->Ban(netAddr, BanReasonManuallyAdded, banTime, absolute);
|
||||
if (g_connman) {
|
||||
g_connman->DisconnectNode(netAddr);
|
||||
g_rpc_node->banman->Ban(netAddr, BanReasonManuallyAdded, banTime, absolute);
|
||||
if (g_rpc_node->connman) {
|
||||
g_rpc_node->connman->DisconnectNode(netAddr);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(strCommand == "remove")
|
||||
{
|
||||
if (!( isSubnet ? g_banman->Unban(subNet) : g_banman->Unban(netAddr) )) {
|
||||
if (!( isSubnet ? g_rpc_node->banman->Unban(subNet) : g_rpc_node->banman->Unban(netAddr) )) {
|
||||
throw JSONRPCError(RPC_CLIENT_INVALID_IP_OR_SUBNET, "Error: Unban failed. Requested address/subnet was not previously banned.");
|
||||
}
|
||||
}
|
||||
@ -684,12 +686,12 @@ static UniValue listbanned(const JSONRPCRequest& request)
|
||||
},
|
||||
}.ToString());
|
||||
|
||||
if(!g_banman) {
|
||||
if(!g_rpc_node->banman) {
|
||||
throw JSONRPCError(RPC_DATABASE_ERROR, "Error: Ban database not loaded");
|
||||
}
|
||||
|
||||
banmap_t banMap;
|
||||
g_banman->GetBanned(banMap);
|
||||
g_rpc_node->banman->GetBanned(banMap);
|
||||
|
||||
UniValue bannedAddresses(UniValue::VARR);
|
||||
for (const auto& entry : banMap)
|
||||
@ -720,11 +722,11 @@ static UniValue clearbanned(const JSONRPCRequest& request)
|
||||
+ HelpExampleRpc("clearbanned", "")
|
||||
},
|
||||
}.ToString());
|
||||
if (!g_banman) {
|
||||
if (!g_rpc_node->banman) {
|
||||
throw JSONRPCError(RPC_DATABASE_ERROR, "Error: Ban database not loaded");
|
||||
}
|
||||
|
||||
g_banman->ClearBanned();
|
||||
g_rpc_node->banman->ClearBanned();
|
||||
|
||||
return NullUniValue;
|
||||
}
|
||||
@ -744,13 +746,13 @@ static UniValue setnetworkactive(const JSONRPCRequest& request)
|
||||
);
|
||||
}
|
||||
|
||||
if (!g_connman) {
|
||||
if (!g_rpc_node->connman) {
|
||||
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
|
||||
}
|
||||
|
||||
g_connman->SetNetworkActive(request.params[0].get_bool());
|
||||
g_rpc_node->connman->SetNetworkActive(request.params[0].get_bool());
|
||||
|
||||
return g_connman->GetNetworkActive();
|
||||
return g_rpc_node->connman->GetNetworkActive();
|
||||
}
|
||||
|
||||
static UniValue getnodeaddresses(const JSONRPCRequest& request)
|
||||
@ -779,7 +781,7 @@ static UniValue getnodeaddresses(const JSONRPCRequest& request)
|
||||
},
|
||||
}.ToString());
|
||||
}
|
||||
if (!g_connman) {
|
||||
if (!g_rpc_node->connman) {
|
||||
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
|
||||
}
|
||||
|
||||
@ -791,7 +793,7 @@ static UniValue getnodeaddresses(const JSONRPCRequest& request)
|
||||
}
|
||||
}
|
||||
// returns a shuffled list of CAddress
|
||||
std::vector<CAddress> vAddr = g_connman->GetAddresses();
|
||||
std::vector<CAddress> vAddr = g_rpc_node->connman->GetAddresses();
|
||||
UniValue ret(UniValue::VARR);
|
||||
|
||||
int address_return_count = std::min<int>(count, vAddr.size());
|
||||
|
@ -16,11 +16,13 @@
|
||||
#include <keystore.h>
|
||||
#include <merkleblock.h>
|
||||
#include <node/coin.h>
|
||||
#include <node/context.h>
|
||||
#include <node/transaction.h>
|
||||
#include <policy/policy.h>
|
||||
#include <policy/settings.h>
|
||||
#include <primitives/transaction.h>
|
||||
#include <psbt.h>
|
||||
#include <rpc/blockchain.h>
|
||||
#include <rpc/rawtransaction_util.h>
|
||||
#include <rpc/server.h>
|
||||
#include <rpc/util.h>
|
||||
@ -839,7 +841,7 @@ UniValue sendrawtransaction(const JSONRPCRequest& request)
|
||||
if (!request.params[3].isNull()) bypass_limits = request.params[3].get_bool();
|
||||
std::string err_string;
|
||||
AssertLockNotHeld(cs_main);
|
||||
const TransactionError err = BroadcastTransaction(tx, err_string, max_raw_tx_fee, /* relay */ true, /* wait_callback */ true, bypass_limits);
|
||||
const TransactionError err = BroadcastTransaction(*g_rpc_node, tx, err_string, max_raw_tx_fee, /* relay */ true, /* wait_callback */ true, bypass_limits);
|
||||
if (TransactionError::OK != err) {
|
||||
throw JSONRPCTransactionError(err, err_string);
|
||||
}
|
||||
|
@ -4,6 +4,8 @@
|
||||
|
||||
#include <chainparams.h>
|
||||
#include <index/txindex.h>
|
||||
#include <node/context.h>
|
||||
#include <rpc/blockchain.h>
|
||||
#include <rpc/server.h>
|
||||
#include <rpc/util.h>
|
||||
#include <validation.h>
|
||||
@ -218,7 +220,7 @@ static UniValue quorum_dkgstatus(const JSONRPCRequest& request)
|
||||
pQuorumBaseBlockIndex, proTxHash,
|
||||
true);
|
||||
std::map<uint256, CAddress> foundConnections;
|
||||
g_connman->ForEachNode([&](const CNode* pnode) {
|
||||
g_rpc_node->connman->ForEachNode([&](const CNode* pnode) {
|
||||
auto verifiedProRegTxHash = pnode->GetVerifiedProRegTxHash();
|
||||
if (!verifiedProRegTxHash.IsNull() && allConnections.count(verifiedProRegTxHash)) {
|
||||
foundConnections.emplace(verifiedProRegTxHash, pnode->addr);
|
||||
@ -642,7 +644,7 @@ static UniValue quorum_getdata(const JSONRPCRequest& request)
|
||||
}
|
||||
|
||||
const CBlockIndex* pQuorumBaseBlockIndex = WITH_LOCK(cs_main, return LookupBlockIndex(quorumHash));
|
||||
return g_connman->ForNode(nodeId, [&](CNode* pNode) {
|
||||
return g_rpc_node->connman->ForNode(nodeId, [&](CNode* pNode) {
|
||||
return llmq::quorumManager->RequestQuorumData(pNode, llmqType, pQuorumBaseBlockIndex, nDataMask, proTxHash);
|
||||
});
|
||||
}
|
||||
|
@ -17,8 +17,6 @@
|
||||
#include <boost/algorithm/string/classification.hpp>
|
||||
#include <boost/algorithm/string/split.hpp>
|
||||
|
||||
InitInterfaces* g_rpc_interfaces = nullptr;
|
||||
|
||||
void RPCTypeCheck(const UniValue& params,
|
||||
const std::list<UniValueType>& typesExpected,
|
||||
bool fAllowNull)
|
||||
|
@ -24,12 +24,6 @@ class CKeyStore;
|
||||
class CPubKey;
|
||||
class CScript;
|
||||
struct Sections;
|
||||
struct InitInterfaces;
|
||||
|
||||
//! Pointers to interfaces that need to be accessible from RPC methods. Due to
|
||||
//! limitations of the RPC framework, there's currently no direct way to pass in
|
||||
//! state to RPC method implementations.
|
||||
extern InitInterfaces* g_rpc_interfaces;
|
||||
|
||||
/** Wrapper for UniValue::VType, which includes typeAny:
|
||||
* Used to denote don't care type. */
|
||||
|
@ -7,8 +7,8 @@
|
||||
#include <rpc/util.h>
|
||||
|
||||
#include <core_io.h>
|
||||
#include <init.h>
|
||||
#include <interfaces/chain.h>
|
||||
#include <node/context.h>
|
||||
#include <test/util/setup_common.h>
|
||||
#include <util/time.h>
|
||||
|
||||
@ -110,14 +110,14 @@ BOOST_AUTO_TEST_CASE(rpc_rawsign)
|
||||
std::string notsigned = r.get_str();
|
||||
std::string privkey1 = "\"XEwTRsCX3CiWSQf8YmKMTeb84KyTbibkUv9mDTZHQ5MwuKG2ZzES\"";
|
||||
std::string privkey2 = "\"XDmZ7LjGd94Q81eUBjb2h6uV5Y14s7fmeXWEGYabfBJP8RVpprBu\"";
|
||||
InitInterfaces interfaces;
|
||||
interfaces.chain = interfaces::MakeChain();
|
||||
g_rpc_interfaces = &interfaces;
|
||||
NodeContext node;
|
||||
node.chain = interfaces::MakeChain(node);
|
||||
g_rpc_node = &node;
|
||||
r = CallRPC(std::string("signrawtransactionwithkey ")+notsigned+" [] "+prevout);
|
||||
BOOST_CHECK(find_value(r.get_obj(), "complete").get_bool() == false);
|
||||
r = CallRPC(std::string("signrawtransactionwithkey ")+notsigned+" ["+privkey1+","+privkey2+"] "+prevout);
|
||||
BOOST_CHECK(find_value(r.get_obj(), "complete").get_bool() == true);
|
||||
g_rpc_interfaces = nullptr;
|
||||
g_rpc_node = nullptr;
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(rpc_createraw_op_return)
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include <net.h>
|
||||
#include <noui.h>
|
||||
#include <pow.h>
|
||||
#include <rpc/blockchain.h>
|
||||
#include <rpc/register.h>
|
||||
#include <rpc/server.h>
|
||||
#include <script/sigcache.h>
|
||||
@ -91,7 +92,8 @@ BasicTestingSetup::BasicTestingSetup(const std::string& chainName)
|
||||
InitScriptExecutionCache();
|
||||
fCheckBlockIndex = true;
|
||||
evoDb.reset(new CEvoDB(1 << 20, true, true));
|
||||
deterministicMNManager.reset(new CDeterministicMNManager(*evoDb, *g_connman));
|
||||
connman = MakeUnique<CConnman>(0x1337, 0x1337);
|
||||
deterministicMNManager.reset(new CDeterministicMNManager(*evoDb, *connman));
|
||||
llmq::quorumSnapshotManager.reset(new llmq::CQuorumSnapshotManager(*evoDb));
|
||||
static bool noui_connected = false;
|
||||
if (!noui_connected) {
|
||||
@ -102,6 +104,7 @@ BasicTestingSetup::BasicTestingSetup(const std::string& chainName)
|
||||
|
||||
BasicTestingSetup::~BasicTestingSetup()
|
||||
{
|
||||
connman.reset();
|
||||
llmq::quorumSnapshotManager.reset();
|
||||
deterministicMNManager.reset();
|
||||
evoDb.reset();
|
||||
@ -116,6 +119,7 @@ TestingSetup::TestingSetup(const std::string& chainName) : BasicTestingSetup(cha
|
||||
const CChainParams& chainparams = Params();
|
||||
// Ideally we'd move all the RPC tests to the functional testing framework
|
||||
// instead of unit tests, but for now we need these here.
|
||||
g_rpc_node = &m_node;
|
||||
RegisterAllCoreRPCCommands(tableRPC);
|
||||
|
||||
// We have to run a scheduler thread to prevent ActivateBestChain
|
||||
@ -123,8 +127,8 @@ TestingSetup::TestingSetup(const std::string& chainName) : BasicTestingSetup(cha
|
||||
threadGroup.create_thread(std::bind(&CScheduler::serviceQueue, &scheduler));
|
||||
GetMainSignals().RegisterBackgroundSignalScheduler(scheduler);
|
||||
mempool.setSanityCheck(1.0);
|
||||
g_banman = MakeUnique<BanMan>(GetDataDir() / "banlist.dat", nullptr, DEFAULT_MISBEHAVING_BANTIME);
|
||||
g_connman = MakeUnique<CConnman>(0x1337, 0x1337); // Deterministic randomness for tests.
|
||||
m_node.banman = MakeUnique<BanMan>(GetDataDir() / "banlist.dat", nullptr, DEFAULT_MISBEHAVING_BANTIME);
|
||||
m_node.connman = MakeUnique<CConnman>(0x1337, 0x1337); // Deterministic randomness for tests.
|
||||
pblocktree.reset(new CBlockTreeDB(1 << 20, true));
|
||||
g_chainstate = MakeUnique<CChainState>();
|
||||
::ChainstateActive().InitCoinsDB(
|
||||
@ -132,7 +136,8 @@ TestingSetup::TestingSetup(const std::string& chainName) : BasicTestingSetup(cha
|
||||
assert(!::ChainstateActive().CanFlushToDisk());
|
||||
g_txindex = MakeUnique<TxIndex>(1 << 20, true);
|
||||
g_txindex->Start();
|
||||
llmq::InitLLMQSystem(*evoDb, *g_connman, true);
|
||||
deterministicMNManager.reset(new CDeterministicMNManager(*evoDb, *m_node.connman));
|
||||
llmq::InitLLMQSystem(*evoDb, *m_node.connman, true);
|
||||
::ChainstateActive().InitCoinsCache();
|
||||
assert(::ChainstateActive().CanFlushToDisk());
|
||||
if (!LoadGenesisBlock(chainparams)) {
|
||||
@ -153,6 +158,7 @@ TestingSetup::TestingSetup(const std::string& chainName) : BasicTestingSetup(cha
|
||||
TestingSetup::~TestingSetup()
|
||||
{
|
||||
scheduler.stop();
|
||||
deterministicMNManager.reset();
|
||||
llmq::InterruptLLMQSystem();
|
||||
llmq::StopLLMQSystem();
|
||||
g_txindex->Interrupt();
|
||||
@ -163,8 +169,9 @@ TestingSetup::~TestingSetup()
|
||||
StopScriptCheckWorkerThreads();
|
||||
GetMainSignals().FlushBackgroundCallbacks();
|
||||
GetMainSignals().UnregisterBackgroundSignalScheduler();
|
||||
g_connman.reset();
|
||||
g_banman.reset();
|
||||
g_rpc_node = nullptr;
|
||||
m_node.connman.reset();
|
||||
m_node.banman.reset();
|
||||
UnloadBlockIndex();
|
||||
g_chainstate.reset();
|
||||
llmq::DestroyLLMQSystem();
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include <chainparamsbase.h>
|
||||
#include <fs.h>
|
||||
#include <key.h>
|
||||
#include <node/context.h>
|
||||
#include <pubkey.h>
|
||||
#include <random.h>
|
||||
#include <scheduler.h>
|
||||
@ -76,6 +77,7 @@ struct BasicTestingSetup {
|
||||
explicit BasicTestingSetup(const std::string& chainName = CBaseChainParams::MAIN);
|
||||
~BasicTestingSetup();
|
||||
private:
|
||||
std::unique_ptr<CConnman> connman;
|
||||
const fs::path m_path_root;
|
||||
};
|
||||
|
||||
@ -83,6 +85,7 @@ private:
|
||||
* Included are coins database, script check threads setup.
|
||||
*/
|
||||
struct TestingSetup : public BasicTestingSetup {
|
||||
NodeContext m_node;
|
||||
boost::thread_group threadGroup;
|
||||
CScheduler scheduler;
|
||||
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <init.h>
|
||||
#include <interfaces/chain.h>
|
||||
#include <net.h>
|
||||
#include <node/context.h>
|
||||
#include <util/error.h>
|
||||
#include <util/system.h>
|
||||
#include <util/moneystr.h>
|
||||
@ -30,8 +31,8 @@ public:
|
||||
//! Wallets parameter interaction
|
||||
bool ParameterInteraction() const override;
|
||||
|
||||
//! Add wallets that should be opened to list of init interfaces.
|
||||
void Construct(InitInterfaces& interfaces) const override;
|
||||
//! Add wallets that should be opened to list of chain clients.
|
||||
void Construct(NodeContext& node) const override;
|
||||
|
||||
// Dash Specific Wallet Init
|
||||
void AutoLockMasternodeCollaterals() const override;
|
||||
@ -165,14 +166,14 @@ bool WalletInit::ParameterInteraction() const
|
||||
return true;
|
||||
}
|
||||
|
||||
void WalletInit::Construct(InitInterfaces& interfaces) const
|
||||
void WalletInit::Construct(NodeContext& node) const
|
||||
{
|
||||
if (gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) {
|
||||
LogPrintf("Wallet disabled!\n");
|
||||
return;
|
||||
}
|
||||
gArgs.SoftSetArg("-wallet", "");
|
||||
interfaces.chain_clients.emplace_back(interfaces::MakeWalletClient(*interfaces.chain, gArgs.GetArgs("-wallet")));
|
||||
node.chain_clients.emplace_back(interfaces::MakeWalletClient(*node.chain, gArgs.GetArgs("-wallet")));
|
||||
}
|
||||
|
||||
|
||||
|
@ -8,10 +8,11 @@
|
||||
#include <chainparams.h>
|
||||
#include <core_io.h>
|
||||
#include <httpserver.h>
|
||||
#include <init.h>
|
||||
#include <interfaces/chain.h>
|
||||
#include <node/context.h>
|
||||
#include <policy/feerate.h>
|
||||
#include <policy/fees.h>
|
||||
#include <rpc/blockchain.h>
|
||||
#include <rpc/mining.h>
|
||||
#include <rpc/rawtransaction_util.h>
|
||||
#include <rpc/server.h>
|
||||
@ -2728,7 +2729,7 @@ static UniValue loadwallet(const JSONRPCRequest& request)
|
||||
|
||||
bilingual_str error;
|
||||
std::vector<bilingual_str> warnings;
|
||||
std::shared_ptr<CWallet> const wallet = LoadWallet(*g_rpc_interfaces->chain, location, error, warnings);
|
||||
std::shared_ptr<CWallet> const wallet = LoadWallet(*g_rpc_chain, location, error, warnings);
|
||||
if (!wallet) throw JSONRPCError(RPC_WALLET_ERROR, error.original);
|
||||
|
||||
UniValue obj(UniValue::VOBJ);
|
||||
@ -2787,7 +2788,7 @@ static UniValue createwallet(const JSONRPCRequest& request)
|
||||
|
||||
bilingual_str error;
|
||||
std::shared_ptr<CWallet> wallet;
|
||||
WalletCreationStatus status = CreateWallet(*g_rpc_interfaces->chain, passphrase, flags, request.params[0].get_str(), error, warnings, wallet);
|
||||
WalletCreationStatus status = CreateWallet(*g_rpc_chain, passphrase, flags, request.params[0].get_str(), error, warnings, wallet);
|
||||
switch (status) {
|
||||
case WalletCreationStatus::CREATION_FAILED:
|
||||
throw JSONRPCError(RPC_WALLET_ERROR, error.original);
|
||||
@ -4053,3 +4054,5 @@ void RegisterWalletRPCCommands(interfaces::Chain& chain, std::vector<std::unique
|
||||
for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++)
|
||||
handlers.emplace_back(chain.handleRpc(commands[vcidx]));
|
||||
}
|
||||
|
||||
interfaces::Chain* g_rpc_chain = nullptr;
|
||||
|
@ -21,6 +21,12 @@ class Chain;
|
||||
class Handler;
|
||||
}
|
||||
|
||||
//! Pointer to chain interface that needs to be declared as a global to be
|
||||
//! accessible loadwallet and createwallet methods. Due to limitations of the
|
||||
//! RPC framework, there's currently no direct way to pass in state to RPC
|
||||
//! methods without globals.
|
||||
extern interfaces::Chain* g_rpc_chain;
|
||||
|
||||
void RegisterWalletRPCCommands(interfaces::Chain& chain, std::vector<std::unique_ptr<interfaces::Handler>>& handlers);
|
||||
|
||||
/**
|
||||
|
@ -4,6 +4,7 @@
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <fs.h>
|
||||
#include <node/context.h>
|
||||
#include <streams.h>
|
||||
#include <util/translation.h>
|
||||
#include <wallet/salvage.h>
|
||||
@ -122,7 +123,8 @@ bool RecoverDatabaseFile(const fs::path& file_path)
|
||||
return false;
|
||||
}
|
||||
|
||||
auto chain = interfaces::MakeChain();
|
||||
NodeContext node;
|
||||
auto chain = interfaces::MakeChain(node);
|
||||
DbTxn* ptxn = env->TxnBegin();
|
||||
CWallet dummyWallet(chain.get(), WalletLocation(), CreateDummyWalletDatabase());
|
||||
for (KeyValPair& row : salvagedData)
|
||||
|
@ -66,7 +66,8 @@ public:
|
||||
CTransactionBuilderTestSetup()
|
||||
{
|
||||
CreateAndProcessBlock({}, GetScriptForRawPubKey(coinbaseKey.GetPubKey()));
|
||||
chain = interfaces::MakeChain();
|
||||
NodeContext node;
|
||||
chain = interfaces::MakeChain(node);
|
||||
wallet = MakeUnique<CWallet>(chain.get(), WalletLocation(), CreateMockWalletDatabase());
|
||||
bool firstRun;
|
||||
wallet->LoadWallet(firstRun);
|
||||
|
@ -2,6 +2,7 @@
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <node/context.h>
|
||||
#include <wallet/wallet.h>
|
||||
#include <wallet/coinselection.h>
|
||||
#include <wallet/coincontrol.h>
|
||||
@ -29,7 +30,8 @@ std::vector<std::unique_ptr<CWalletTx>> wtxn;
|
||||
typedef std::set<CInputCoin> CoinSet;
|
||||
|
||||
static std::vector<COutput> vCoins;
|
||||
static auto testChain = interfaces::MakeChain();
|
||||
static NodeContext testNode;
|
||||
static auto testChain = interfaces::MakeChain(testNode);
|
||||
static CWallet testWallet(testChain.get(), WalletLocation(), CreateDummyWalletDatabase());
|
||||
static CAmount balance = 0;
|
||||
|
||||
|
@ -2,7 +2,6 @@
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <net.h>
|
||||
#include <fs.h>
|
||||
#include <util/system.h>
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
#define BITCOIN_WALLET_TEST_INIT_TEST_FIXTURE_H
|
||||
|
||||
#include <interfaces/chain.h>
|
||||
#include <node/context.h>
|
||||
#include <test/util/setup_common.h>
|
||||
|
||||
|
||||
@ -17,7 +18,8 @@ struct InitWalletDirTestingSetup: public BasicTestingSetup {
|
||||
fs::path m_datadir;
|
||||
fs::path m_cwd;
|
||||
std::map<std::string, fs::path> m_walletdir_path_cases;
|
||||
std::unique_ptr<interfaces::Chain> m_chain = interfaces::MakeChain();
|
||||
NodeContext m_node;
|
||||
std::unique_ptr<interfaces::Chain> m_chain = interfaces::MakeChain(m_node);
|
||||
std::unique_ptr<interfaces::ChainClient> m_chain_client;
|
||||
};
|
||||
|
||||
|
@ -27,7 +27,8 @@ BOOST_AUTO_TEST_CASE(ismine_standard)
|
||||
CKey uncompressedKey;
|
||||
uncompressedKey.MakeNewKey(false);
|
||||
CPubKey uncompressedPubkey = uncompressedKey.GetPubKey();
|
||||
auto chain = interfaces::MakeChain();
|
||||
NodeContext node;
|
||||
auto chain = interfaces::MakeChain(node);
|
||||
|
||||
CScript scriptPubKey;
|
||||
isminetype result;
|
||||
|
@ -7,9 +7,9 @@
|
||||
|
||||
#include <test/util/setup_common.h>
|
||||
|
||||
#include <net.h>
|
||||
#include <interfaces/chain.h>
|
||||
#include <interfaces/wallet.h>
|
||||
#include <node/context.h>
|
||||
#include <wallet/wallet.h>
|
||||
|
||||
#include <memory>
|
||||
@ -19,7 +19,8 @@
|
||||
struct WalletTestingSetup: public TestingSetup {
|
||||
explicit WalletTestingSetup(const std::string& chainName = CBaseChainParams::MAIN);
|
||||
|
||||
std::unique_ptr<interfaces::Chain> m_chain = interfaces::MakeChain();
|
||||
NodeContext m_node;
|
||||
std::unique_ptr<interfaces::Chain> m_chain = interfaces::MakeChain(m_node);
|
||||
std::unique_ptr<interfaces::ChainClient> m_chain_client = interfaces::MakeWalletClient(*m_chain, {});
|
||||
CWallet m_wallet;
|
||||
};
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
#include <interfaces/chain.h>
|
||||
#include <key_io.h>
|
||||
#include <node/context.h>
|
||||
#include <policy/policy.h>
|
||||
#include <rpc/server.h>
|
||||
#include <test/util/setup_common.h>
|
||||
@ -43,7 +44,8 @@ BOOST_FIXTURE_TEST_CASE(scan_for_wallet_transactions, TestChain100Setup)
|
||||
CreateAndProcessBlock({}, GetScriptForRawPubKey(coinbaseKey.GetPubKey()));
|
||||
CBlockIndex* newTip = ::ChainActive().Tip();
|
||||
|
||||
auto chain = interfaces::MakeChain();
|
||||
NodeContext node;
|
||||
auto chain = interfaces::MakeChain(node);
|
||||
auto locked_chain = chain->lock();
|
||||
LockAnnotation lock(::cs_main);
|
||||
|
||||
@ -138,7 +140,8 @@ BOOST_FIXTURE_TEST_CASE(importmulti_rescan, TestChain100Setup)
|
||||
CreateAndProcessBlock({}, GetScriptForRawPubKey(coinbaseKey.GetPubKey()));
|
||||
CBlockIndex* newTip = ::ChainActive().Tip();
|
||||
|
||||
auto chain = interfaces::MakeChain();
|
||||
NodeContext node;
|
||||
auto chain = interfaces::MakeChain(node);
|
||||
auto locked_chain = chain->lock();
|
||||
LockAnnotation lock(::cs_main);
|
||||
|
||||
@ -205,7 +208,8 @@ BOOST_FIXTURE_TEST_CASE(importwallet_rescan, TestChain100Setup)
|
||||
SetMockTime(KEY_TIME);
|
||||
m_coinbase_txns.emplace_back(CreateAndProcessBlock({}, GetScriptForRawPubKey(coinbaseKey.GetPubKey())).vtx[0]);
|
||||
|
||||
auto chain = interfaces::MakeChain();
|
||||
NodeContext node;
|
||||
auto chain = interfaces::MakeChain(node);
|
||||
auto locked_chain = chain->lock();
|
||||
LockAnnotation lock(::cs_main);
|
||||
|
||||
@ -259,7 +263,9 @@ BOOST_FIXTURE_TEST_CASE(importwallet_rescan, TestChain100Setup)
|
||||
// debit functions.
|
||||
BOOST_FIXTURE_TEST_CASE(coin_mark_dirty_immature_credit, TestChain100Setup)
|
||||
{
|
||||
auto chain = interfaces::MakeChain();
|
||||
NodeContext node;
|
||||
auto chain = interfaces::MakeChain(node);
|
||||
|
||||
CWallet wallet(chain.get(), WalletLocation(), CreateDummyWalletDatabase());
|
||||
CWalletTx wtx(&wallet, m_coinbase_txns.back());
|
||||
|
||||
@ -416,7 +422,8 @@ public:
|
||||
return it->second;
|
||||
}
|
||||
|
||||
std::unique_ptr<interfaces::Chain> m_chain = interfaces::MakeChain();
|
||||
NodeContext m_node;
|
||||
std::unique_ptr<interfaces::Chain> m_chain = interfaces::MakeChain(m_node);
|
||||
std::unique_ptr<CWallet> wallet;
|
||||
};
|
||||
|
||||
@ -527,7 +534,8 @@ public:
|
||||
BOOST_CHECK_EQUAL(result.status, CWallet::ScanResult::SUCCESS);
|
||||
}
|
||||
|
||||
std::unique_ptr<interfaces::Chain> m_chain = interfaces::MakeChain();
|
||||
NodeContext m_node;
|
||||
std::unique_ptr<interfaces::Chain> m_chain = interfaces::MakeChain(m_node);
|
||||
|
||||
~CreateTransactionTestSetup()
|
||||
{
|
||||
@ -993,7 +1001,8 @@ BOOST_FIXTURE_TEST_CASE(select_coins_grouped_by_addresses, ListCoinsTestingSetup
|
||||
|
||||
BOOST_FIXTURE_TEST_CASE(wallet_disableprivkeys, TestChain100Setup)
|
||||
{
|
||||
auto chain = interfaces::MakeChain();
|
||||
NodeContext node;
|
||||
auto chain = interfaces::MakeChain(node);
|
||||
std::shared_ptr<CWallet> wallet = std::make_shared<CWallet>(chain.get(), WalletLocation(), CreateDummyWalletDatabase());
|
||||
wallet->SetMinVersion(FEATURE_LATEST);
|
||||
wallet->SetWalletFlag(WALLET_FLAG_DISABLE_PRIVATE_KEYS);
|
||||
|
@ -5,7 +5,7 @@
|
||||
#ifndef BITCOIN_WALLETINITINTERFACE_H
|
||||
#define BITCOIN_WALLETINITINTERFACE_H
|
||||
|
||||
struct InitInterfaces;
|
||||
struct NodeContext;
|
||||
|
||||
class WalletInitInterface {
|
||||
public:
|
||||
@ -15,8 +15,8 @@ public:
|
||||
virtual void AddWalletOptions() const = 0;
|
||||
/** Check wallet parameter interaction */
|
||||
virtual bool ParameterInteraction() const = 0;
|
||||
/** Add wallets that should be opened to list of init interfaces. */
|
||||
virtual void Construct(InitInterfaces& interfaces) const = 0;
|
||||
/** Add wallets that should be opened to list of chain clients. */
|
||||
virtual void Construct(NodeContext& node) const = 0;
|
||||
|
||||
// Dash Specific WalletInitInterface
|
||||
virtual void AutoLockMasternodeCollaterals() const = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user