Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ if test "x$enable_werror" = "xyes"; then
AC_MSG_ERROR("enable-werror set but -Werror is not usable")
fi
AX_CHECK_COMPILE_FLAG([-Werror=vla],[ERROR_CXXFLAGS="$ERROR_CXXFLAGS -Werror=vla"],,[[$CXXFLAG_WERROR]])
AX_CHECK_COMPILE_FLAG([-Werror=shadow-field],[ERROR_CXXFLAGS="$ERROR_CXXFLAGS -Werror=shadow-field"],,[[$CXXFLAG_WERROR]])
AX_CHECK_COMPILE_FLAG([-Werror=switch],[ERROR_CXXFLAGS="$ERROR_CXXFLAGS -Werror=switch"],,[[$CXXFLAG_WERROR]])
AX_CHECK_COMPILE_FLAG([-Werror=thread-safety],[ERROR_CXXFLAGS="$ERROR_CXXFLAGS -Werror=thread-safety"],,[[$CXXFLAG_WERROR]])
AX_CHECK_COMPILE_FLAG([-Werror=unused-variable],[ERROR_CXXFLAGS="$ERROR_CXXFLAGS -Werror=unused-variable"],,[[$CXXFLAG_WERROR]])
Expand All @@ -416,6 +417,7 @@ if test "x$CXXFLAGS_overridden" = "xno"; then
AX_CHECK_COMPILE_FLAG([-Wextra],[WARN_CXXFLAGS="$WARN_CXXFLAGS -Wextra"],,[[$CXXFLAG_WERROR]])
AX_CHECK_COMPILE_FLAG([-Wformat],[WARN_CXXFLAGS="$WARN_CXXFLAGS -Wformat"],,[[$CXXFLAG_WERROR]])
AX_CHECK_COMPILE_FLAG([-Wvla],[WARN_CXXFLAGS="$WARN_CXXFLAGS -Wvla"],,[[$CXXFLAG_WERROR]])
AX_CHECK_COMPILE_FLAG([-Wshadow-field],[WARN_CXXFLAGS="$WARN_CXXFLAGS -Wshadow-field"],,[[$CXXFLAG_WERROR]])
AX_CHECK_COMPILE_FLAG([-Wswitch],[WARN_CXXFLAGS="$WARN_CXXFLAGS -Wswitch"],,[[$CXXFLAG_WERROR]])
AX_CHECK_COMPILE_FLAG([-Wformat-security],[WARN_CXXFLAGS="$WARN_CXXFLAGS -Wformat-security"],,[[$CXXFLAG_WERROR]])
AX_CHECK_COMPILE_FLAG([-Wthread-safety],[WARN_CXXFLAGS="$WARN_CXXFLAGS -Wthread-safety"],,[[$CXXFLAG_WERROR]])
Expand Down
1 change: 1 addition & 0 deletions src/Makefile.test.include
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ BITCOIN_TESTS =\
test/script_standard_tests.cpp \
test/scriptnum_tests.cpp \
test/serialize_tests.cpp \
test/settings_tests.cpp \
test/sighash_tests.cpp \
test/sigopcount_tests.cpp \
test/skiplist_tests.cpp \
Expand Down
5 changes: 0 additions & 5 deletions src/bench/bench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,6 @@ void benchmark::BenchRunner::RunAll(const Args& args)

std::vector<ankerl::nanobench::Result> benchmarkResults;
for (const auto& p : benchmarks()) {
RegTestingSetup test{};
{
assert(::ChainActive().Height() == 0);
}

if (!std::regex_match(p.first, baseMatch, reFilter)) {
continue;
}
Expand Down
2 changes: 2 additions & 0 deletions src/bench/bench_dash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ int main(int argc, char** argv)
args.output_csv = gArgs.GetArg("-output_csv", "");
args.output_json = gArgs.GetArg("-output_json", "");

gArgs.ClearArgs(); // gArgs no longer needed. Clear it here to avoid interactions with the testing setup in the benches

benchmark::BenchRunner::RunAll(args);

return EXIT_SUCCESS;
Expand Down
2 changes: 1 addition & 1 deletion src/bench/block_assemble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ static void AssembleBlock(benchmark::Bench& bench)

for (const auto& txr : txs) {
CValidationState state;
bool ret{::AcceptToMemoryPool(::mempool, state, txr, nullptr /* pfMissingInputs */, false /* bypass_limits */, /* nAbsurdFee */ 0)};
bool ret{::AcceptToMemoryPool(*test_setup.m_node.mempool, state, txr, nullptr /* pfMissingInputs */, false /* bypass_limits */, /* nAbsurdFee */ 0)};
assert(ret);
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/bench/wallet_balance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@ static void WalletBalance(benchmark::Bench& bench, const bool set_dirty, const b
{
bool first_run;
if (wallet.LoadWallet(first_run) != DBErrors::LOAD_OK) assert(false);
wallet.handleNotifications();
}

auto handler = chain->handleNotifications({ &wallet, [](CWallet*) {} });

const std::optional<std::string> address_mine{add_mine ? std::optional<std::string>{getnewaddress(wallet)} : std::nullopt};
if (add_watchonly) importaddress(wallet, ADDRESS_WATCHONLY);
Expand Down
7 changes: 1 addition & 6 deletions src/dash-cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,19 +138,14 @@ static int AppInitRPC(int argc, char* argv[])
}
return EXIT_SUCCESS;
}
bool datadirFromCmdLine = gArgs.IsArgSet("-datadir");
if (datadirFromCmdLine && !fs::is_directory(GetDataDir(false))) {
if (!CheckDataDirOption()) {
tfm::format(std::cerr, "Error: Specified data directory \"%s\" does not exist.\n", gArgs.GetArg("-datadir", ""));
return EXIT_FAILURE;
}
if (!gArgs.ReadConfigFiles(error, true)) {
tfm::format(std::cerr, "Error reading configuration file: %s\n", error);
return EXIT_FAILURE;
}
if (!datadirFromCmdLine && !fs::is_directory(GetDataDir(false))) {
tfm::format(std::cerr, "Error: Specified data directory \"%s\" from config file does not exist.\n", gArgs.GetArg("-datadir", ""));
return EXIT_FAILURE;
}
// Check for -testnet or -regtest parameter (BaseParams() calls are only valid after this clause)
try {
SelectBaseParams(gArgs.GetChainName());
Expand Down
2 changes: 1 addition & 1 deletion src/dash-wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ static bool WalletAppInit(int argc, char* argv[])
// check for printtoconsole, allow -debug
LogInstance().m_print_to_console = gArgs.GetBoolArg("-printtoconsole", gArgs.GetBoolArg("-debug", false));

if (!fs::is_directory(GetDataDir(false))) {
if (!CheckDataDirOption()) {
tfm::format(std::cerr, "Error: Specified data directory \"%s\" does not exist.\n", gArgs.GetArg("-datadir", ""));
return false;
}
Expand Down
11 changes: 2 additions & 9 deletions src/dashd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ static bool AppInit(int argc, char* argv[])
// Parameters
//
// If Qt is used, parameters/dash.conf are parsed in qt/dash.cpp's main()
SetupServerArgs();
SetupServerArgs(node);
std::string error;
if (!gArgs.ParseParameters(argc, argv, error)) {
return InitError(Untranslated(strprintf("Error parsing command line arguments: %s\n", error)));
Expand Down Expand Up @@ -87,19 +87,12 @@ static bool AppInit(int argc, char* argv[])
util::Ref context{node};
try
{
bool datadirFromCmdLine = gArgs.IsArgSet("-datadir");
if (datadirFromCmdLine && !fs::is_directory(GetDataDir(false)))
{
if (!CheckDataDirOption()) {
return InitError(Untranslated(strprintf("Specified data directory \"%s\" does not exist.\n", gArgs.GetArg("-datadir", ""))));
}
if (!gArgs.ReadConfigFiles(error, true)) {
return InitError(Untranslated(strprintf("Error reading configuration file: %s\n", error)));
}
if (!datadirFromCmdLine && !fs::is_directory(GetDataDir(false)))
{
tfm::format(std::cerr, "Error: Specified data directory \"%s\" from config file does not exist.\n", gArgs.GetArg("-datadir", ""));
return EXIT_FAILURE;
}
// Check for -testnet or -regtest parameter (Params() calls are only valid after this clause)
try {
SelectParams(gArgs.GetChainName());
Expand Down
22 changes: 14 additions & 8 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ void Shutdown(NodeContext& node)
// Shutdown part 2: delete wallet instance
globalVerifyHandle.reset();
ECC_Stop();
node.args = nullptr;
node.mempool = nullptr;
node.chainman = nullptr;
node.scheduler.reset();
Expand Down Expand Up @@ -465,8 +466,11 @@ std::string GetSupportedSocketEventsStr()
return strSupportedModes;
}

void SetupServerArgs()
void SetupServerArgs(NodeContext& node)
{
assert(!node.args);
node.args = &gArgs;

const auto defaultBaseParams = CreateBaseChainParams(CBaseChainParams::MAIN);
const auto testnetBaseParams = CreateBaseChainParams(CBaseChainParams::TESTNET);
const auto regtestBaseParams = CreateBaseChainParams(CBaseChainParams::REGTEST);
Expand Down Expand Up @@ -2023,13 +2027,15 @@ bool AppInitMain(const util::Ref& context, NodeContext& node, interfaces::BlockA

// If the loaded chain has a wrong genesis, bail out immediately
// (we're likely using a testnet datadir, or the other way around).
if (!::BlockIndex().empty() &&
if (!chainman.BlockIndex().empty() &&
!LookupBlockIndex(chainparams.GetConsensus().hashGenesisBlock)) {
return InitError(_("Incorrect or no genesis block found. Wrong datadir for network?"));
}

if (!chainparams.GetConsensus().hashDevnetGenesisBlock.IsNull() && !::BlockIndex().empty() && ::BlockIndex().count(chainparams.GetConsensus().hashDevnetGenesisBlock) == 0)
if (!chainparams.GetConsensus().hashDevnetGenesisBlock.IsNull() && !chainman.BlockIndex().empty() &&
!LookupBlockIndex(chainparams.GetConsensus().hashDevnetGenesisBlock)) {
return InitError(_("Incorrect or no devnet genesis block found. Wrong datadir for devnet specified?"));
}

// Check for changed -addressindex state
if (fAddressIndex != gArgs.GetBoolArg("-addressindex", DEFAULT_ADDRESSINDEX)) {
Expand Down Expand Up @@ -2448,13 +2454,13 @@ bool AppInitMain(const util::Ref& context, NodeContext& node, interfaces::BlockA
//// debug print
{
LOCK(cs_main);
LogPrintf("block tree size = %u\n", ::BlockIndex().size());
chain_active_height = ::ChainActive().Height();
LogPrintf("block tree size = %u\n", chainman.BlockIndex().size());
chain_active_height = chainman.ActiveChain().Height();
if (tip_info) {
tip_info->block_height = chain_active_height;
tip_info->block_time = ::ChainActive().Tip() ? ::ChainActive().Tip()->GetBlockTime() : Params().GenesisBlock().GetBlockTime();
tip_info->block_hash = ::ChainActive().Tip() ? ::ChainActive().Tip()->GetBlockHash() : Params().GenesisBlock().GetHash();
tip_info->verification_progress = GuessVerificationProgress(Params().TxData(), ::ChainActive().Tip());
tip_info->block_time = chainman.ActiveChain().Tip() ? chainman.ActiveChain().Tip()->GetBlockTime() : Params().GenesisBlock().GetBlockTime();
tip_info->block_hash = chainman.ActiveChain().Tip() ? chainman.ActiveChain().Tip()->GetBlockHash() : Params().GenesisBlock().GetHash();
tip_info->verification_progress = GuessVerificationProgress(Params().TxData(), chainman.ActiveChain().Tip());
}
if (tip_info && ::pindexBestHeader) {
tip_info->header_height = ::pindexBestHeader->nHeight;
Expand Down
4 changes: 2 additions & 2 deletions src/init.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ bool AppInitMain(const util::Ref& context, NodeContext& node, interfaces::BlockA
void PrepareShutdown(NodeContext& node);

/**
* Setup the arguments for gArgs
* Register all arguments with the ArgsManager
*/
void SetupServerArgs();
void SetupServerArgs(NodeContext& node);

/** Returns licensing information (for -version) */
std::string LicenseInfo();
Expand Down
45 changes: 27 additions & 18 deletions src/interfaces/chain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,12 @@

namespace interfaces {
namespace {
class NotificationsHandlerImpl : public Handler, CValidationInterface
class NotificationsProxy : public CValidationInterface
{
public:
explicit NotificationsHandlerImpl(Chain& chain, Chain::Notifications& notifications)
: m_chain(chain), m_notifications(&notifications)
{
RegisterValidationInterface(this);
}
~NotificationsHandlerImpl() override { disconnect(); }
void disconnect() override
{
if (m_notifications) {
m_notifications = nullptr;
UnregisterValidationInterface(this);
}
}
explicit NotificationsProxy(std::shared_ptr<Chain::Notifications> notifications)
: m_notifications(std::move(notifications)) {}
virtual ~NotificationsProxy() = default;
void TransactionAddedToMempool(const CTransactionRef& tx, int64_t nAcceptTime) override
{
m_notifications->TransactionAddedToMempool(tx, nAcceptTime);
Expand Down Expand Up @@ -83,8 +73,27 @@ class NotificationsHandlerImpl : public Handler, CValidationInterface
{
m_notifications->NotifyTransactionLock(tx, islock);
}
Chain& m_chain;
Chain::Notifications* m_notifications;
std::shared_ptr<Chain::Notifications> m_notifications;
};


class NotificationsHandlerImpl : public Handler
{
public:
explicit NotificationsHandlerImpl(std::shared_ptr<Chain::Notifications> notifications)
: m_proxy(std::make_shared<NotificationsProxy>(std::move(notifications)))
{
RegisterSharedValidationInterface(m_proxy);
}
~NotificationsHandlerImpl() override { disconnect(); }
void disconnect() override
{
if (m_proxy) {
UnregisterSharedValidationInterface(m_proxy);
m_proxy.reset();
}
}
std::shared_ptr<NotificationsProxy> m_proxy;
};

class RpcHandlerImpl : public Handler
Expand Down Expand Up @@ -325,9 +334,9 @@ class ChainImpl : public Chain
{
::uiInterface.ShowProgress(title, progress, resume_possible);
}
std::unique_ptr<Handler> handleNotifications(Notifications& notifications) override
std::unique_ptr<Handler> handleNotifications(std::shared_ptr<Notifications> notifications) override
{
return MakeUnique<NotificationsHandlerImpl>(*this, notifications);
return MakeUnique<NotificationsHandlerImpl>(std::move(notifications));
}
void waitForNotificationsIfTipChanged(const uint256& old_tip) override
{
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ class Chain
};

//! Register handler for notifications.
virtual std::unique_ptr<Handler> handleNotifications(Notifications& notifications) = 0;
virtual std::unique_ptr<Handler> handleNotifications(std::shared_ptr<Notifications> notifications) = 0;

//! Wait for pending notifications to be processed unless block hash points to the current
//! chain tip.
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ class NodeImpl : public Node
void startShutdown() override { StartShutdown(); }
bool shutdownRequested() override { return ShutdownRequested(); }
void mapPort(bool use_upnp, bool use_natpmp) override { StartMapPort(use_upnp, use_natpmp); }
void setupServerArgs() override { return SetupServerArgs(); }
void setupServerArgs() override { return SetupServerArgs(m_context); }
bool getProxy(Network net, proxyType& proxy_info) override { return GetProxy(net, proxy_info); }
size_t getNodeCount(CConnman::NumConnections flags) override
{
Expand Down
14 changes: 7 additions & 7 deletions src/llmq/signing_shares.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ class CSigShare : virtual public CSigBase
return quorumMember;
}

CSigShare(Consensus::LLMQType llmqType, const uint256 &quorumHash, const uint256 &id, const uint256 &msgHash,
uint16_t quorumMember, const CBLSLazySignature &sigShare) :
CSigBase(llmqType, quorumHash, id, msgHash),
quorumMember(quorumMember),
sigShare(sigShare) {};
CSigShare(Consensus::LLMQType _llmqType, const uint256& _quorumHash, const uint256& _id, const uint256& _msgHash,
uint16_t _quorumMember, const CBLSLazySignature& _sigShare) :
CSigBase(_llmqType, _quorumHash, _id, _msgHash),
quorumMember(_quorumMember),
sigShare(_sigShare) {};

// This should only be used for serialization
CSigShare() = default;
Expand Down Expand Up @@ -83,8 +83,8 @@ class CSigSesAnn : virtual public CSigBase
uint32_t sessionId{UNINITIALIZED_SESSION_ID};

public:
CSigSesAnn(uint32_t sessionId, Consensus::LLMQType llmqType, const uint256& quorumHash, const uint256& id,
const uint256& msgHash) : CSigBase(llmqType, quorumHash, id, msgHash), sessionId(sessionId) {};
CSigSesAnn(uint32_t _sessionId, Consensus::LLMQType _llmqType, const uint256& _quorumHash, const uint256& _id,
const uint256& _msgHash) : CSigBase(_llmqType, _quorumHash, _id, _msgHash), sessionId(_sessionId) {};
// ONLY FOR SERIALIZATION
CSigSesAnn() = default;

Expand Down
2 changes: 2 additions & 0 deletions src/node/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <memory>
#include <vector>

class ArgsManager;
class BanMan;
class CConnman;
class CScheduler;
Expand Down Expand Up @@ -37,6 +38,7 @@ struct NodeContext {
std::unique_ptr<PeerLogicValidation> peer_logic;
ChainstateManager* chainman{nullptr}; // Currently a raw pointer because the memory is not managed by this struct
std::unique_ptr<BanMan> banman;
ArgsManager* args{nullptr}; // Currently a raw pointer because the memory is not managed by this struct
std::unique_ptr<interfaces::Chain> chain;
std::vector<std::unique_ptr<interfaces::ChainClient>> chain_clients;
std::unique_ptr<CScheduler> scheduler;
Expand Down
5 changes: 2 additions & 3 deletions src/qt/dash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,10 +516,9 @@ int GuiMain(int argc, char* argv[])
if (!Intro::pickDataDirectory(*node))
return EXIT_SUCCESS;

/// 6. Determine availability of data and blocks directory and parse dash.conf
/// 6. Determine availability of data directory and parse dash.conf
/// - Do not call GetDataDir(true) before this step finishes
if (!fs::is_directory(GetDataDir(false)))
{
if (!CheckDataDirOption()) {
node->initError(strprintf(Untranslated("Specified data directory \"%s\" does not exist.\n"), gArgs.GetArg("-datadir", "")));
QMessageBox::critical(nullptr, PACKAGE_NAME,
QObject::tr("Error: Specified data directory \"%1\" does not exist.").arg(QString::fromStdString(gArgs.GetArg("-datadir", ""))));
Expand Down
6 changes: 3 additions & 3 deletions src/qt/rpcconsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -824,10 +824,10 @@ void RPCConsole::buildParameterlist(QString arg)

for (const auto& [key, values] : gArgs.GetCommandLineArgs()) {
for (const auto& value : values) {
if (value.empty()) {
args << QString::fromStdString(key);
if (value.getValStr().empty()) {
args << QString::fromStdString("-" + key);
} else {
args << QString::fromStdString(key + "=" + value);
args << QString::fromStdString("-" + key + "=" + value.getValStr());
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/qt/walletcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ WalletModel* WalletController::getOrCreateWallet(std::unique_ptr<interfaces::Wal
const bool called = QMetaObject::invokeMethod(wallet_model, "startPollBalance");
assert(called);

connect(wallet_model, &WalletModel::unload, [this, wallet_model] {
connect(wallet_model, &WalletModel::unload, this, [this, wallet_model] {
// Defer removeAndDeleteWallet when no modal widget is active.
// TODO: remove this workaround by removing usage of QDiallog::exec.
if (QApplication::activeModalWidget()) {
Expand All @@ -127,7 +127,7 @@ WalletModel* WalletController::getOrCreateWallet(std::unique_ptr<interfaces::Wal
} else {
removeAndDeleteWallet(wallet_model);
}
});
}, Qt::QueuedConnection);

// Re-emit coinsSent signal from wallet model.
connect(wallet_model, &WalletModel::coinsSent, this, &WalletController::coinsSent);
Expand Down
Loading