Skip to content
1 change: 0 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,6 @@ add_library(bitcoin_node STATIC EXCLUDE_FROM_ALL
rpc/signmessage.cpp
rpc/txoutproof.cpp
script/sigcache.cpp
shutdown.cpp
spork.cpp
stats/client.cpp
stats/rawsender.cpp
Expand Down
11 changes: 7 additions & 4 deletions src/addresstype.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,25 @@
#ifndef BITCOIN_ADDRESSTYPE_H
#define BITCOIN_ADDRESSTYPE_H

#include <attributes.h>
#include <pubkey.h>
#include <script/script.h>
#include <uint256.h>
#include <util/hash_type.h>

#include <variant>
#include <vector>

class CNoDestination {
class CNoDestination
{
private:
CScript m_script;

public:
CNoDestination() = default;
CNoDestination(const CScript& script) : m_script(script) {}
explicit CNoDestination(const CScript& script) : m_script(script) {}

const CScript& GetScript() const { return m_script; }
const CScript& GetScript() const LIFETIMEBOUND { return m_script; }

friend bool operator==(const CNoDestination& a, const CNoDestination& b) { return a.GetScript() == b.GetScript(); }
friend bool operator<(const CNoDestination& a, const CNoDestination& b) { return a.GetScript() < b.GetScript(); }
Expand All @@ -31,7 +34,7 @@ struct PubKeyDestination {
CPubKey m_pubkey;

public:
PubKeyDestination(const CPubKey& pubkey) : m_pubkey(pubkey) {}
explicit PubKeyDestination(const CPubKey& pubkey) : m_pubkey(pubkey) {}

const CPubKey& GetPubKey() const LIFETIMEBOUND { return m_pubkey; }

Expand Down
2 changes: 1 addition & 1 deletion src/bench/blockfilter_index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class BlockFilterIndexBenchSetup
if (!m_filter_index->Init() || !m_filter_index->StartBackgroundSync()) {
throw std::runtime_error("failed to start block filter benchmark index");
}
IndexWaitSynced(*m_filter_index);
IndexWaitSynced(*m_filter_index, *Assert(m_testing_setup->m_node.shutdown));

LOCK(cs_main);
m_stop_index = m_testing_setup->m_node.chainman->ActiveChain().Tip();
Expand Down
5 changes: 3 additions & 2 deletions src/bench/wallet_create_tx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,14 @@ static void WalletCreateTx(benchmark::Bench& bench, const OutputType output_type
}

// Generate destinations
CScript dest = GetScriptForDestination(getNewDestination(wallet, output_type));
const auto dest{getNewDestination(wallet, output_type)};

// Generate chain; each coinbase will have two outputs to fill-up the wallet
const auto& params = Params();
const CScript coinbase_out{GetScriptForDestination(dest)};
unsigned int chain_size = 5000; // 5k blocks means 10k UTXO for the wallet (minus 200 due COINBASE_MATURITY)
for (unsigned int i = 0; i < chain_size; ++i) {
generateFakeBlock(params, test_setup->m_node, wallet, dest);
generateFakeBlock(params, test_setup->m_node, wallet, coinbase_out);
}

// Check available balance
Expand Down
4 changes: 2 additions & 2 deletions src/bitcoin-chainstate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ int main(int argc, char* argv[])
.blocks_dir = abs_datadir / "blocks",
.notifications = chainman_opts.notifications,
};
ChainstateManager chainman{kernel_context.interrupt, chainman_opts, blockman_opts};
util::SignalInterrupt interrupt;
ChainstateManager chainman{interrupt, chainman_opts, blockman_opts};

CMasternodeMetaMan metaman{abs_datadir};
CEvoDB evodb{util::DbWrapperParams{.path = abs_datadir, .memory = false, .wipe = false}};
Expand All @@ -161,7 +162,6 @@ int main(int argc, char* argv[])
node::ChainstateLoadOptions options;
options.chainlocks = &chainlocks;
options.data_dir = abs_datadir;
options.check_interrupt = [] { return false; };
options.coins_error_cb = [] {};
auto [status, error] = node::LoadChainstate(chainman, cache_sizes, options, evodb, dmnman, *special_tx);
if (status != node::ChainstateLoadStatus::SUCCESS) {
Expand Down
5 changes: 1 addition & 4 deletions src/bitcoind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include <node/context.h>
#include <node/interface_ui.h>
#include <noui.h>
#include <shutdown.h>
#include <util/check.h>
#include <util/exception.h>
#include <util/syserror.h>
Expand Down Expand Up @@ -279,9 +278,7 @@ MAIN_FUNCTION
if (ProcessInitCommands(args)) return EXIT_SUCCESS;

// Start application
if (AppInit(node)) {
WaitForShutdown();
} else {
if (!AppInit(node) || !Assert(node.shutdown)->wait()) {
node.exit_status = EXIT_FAILURE;
}
Interrupt(node);
Expand Down
4 changes: 2 additions & 2 deletions src/chainlock/clsig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
#include <llmq/quorumsman.h>
#include <node/blockstorage.h>
#include <saltedhasher.h>
#include <shutdown.h>
#include <streams.h>
#include <sync.h>
#include <unordered_lru_cache.h>
#include <util/signalinterrupt.h>

#include <algorithm>
#include <stdexcept>
Expand Down Expand Up @@ -175,7 +175,7 @@ std::optional<CoinbaseChainLock> CoinbaseChainLockReader::Read(int carrier_heigh
const auto* carrier = m_tip ? m_tip->GetAncestor(carrier_height) : nullptr;
if (!carrier || carrier_height < Params().GetConsensus().V20Height) return std::nullopt;
if (const auto it = m_cache.find(carrier_height); it != m_cache.end()) return it->second;
if (ShutdownRequested()) throw std::runtime_error("ChainLock lookup interrupted");
if (m_blockman.m_interrupt) throw std::runtime_error("ChainLock lookup interrupted");
if (m_cache.size() >= MAX_HISTORICAL_CARRIER_LOOKUPS) throw std::runtime_error("ChainLock lookup budget exhausted");
const uint256 carrier_hash = carrier->GetBlockHash();
CarrierEntry entry;
Expand Down
4 changes: 2 additions & 2 deletions src/coinjoin/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
#include <net.h>
#include <netmessagemaker.h>
#include <node/protocol_version.h>
#include <shutdown.h>
#include <txmempool.h>
#include <util/check.h>
#include <util/fs_helpers.h>
#include <util/moneystr.h>
#include <util/signalinterrupt.h>
#include <util/translation.h>
#include <validation.h>
#include <wallet/coincontrol.h>
Expand Down Expand Up @@ -2440,7 +2440,7 @@ void CCoinJoinClientManager::DoMaintenance(ChainstateManager& chainman, CConnman
{
if (!CCoinJoinClientOptions::IsEnabled()) return;

if (!m_mn_sync.IsBlockchainSynced() || ShutdownRequested()) return;
if (!m_mn_sync.IsBlockchainSynced() || chainman.m_interrupt) return;

m_tick++;
CheckTimeout();
Expand Down
4 changes: 2 additions & 2 deletions src/coinjoin/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
#include <scheduler.h>
#include <script/interpreter.h>
#include <serialize.h>
#include <shutdown.h>
#include <streams.h>
#include <txmempool.h>
#include <util/moneystr.h>
#include <util/signalinterrupt.h>
#include <validation.h>

#include <univalue.h>
Expand Down Expand Up @@ -1359,7 +1359,7 @@ void CCoinJoinServer::Schedule(CScheduler& scheduler)
scheduler.scheduleEvery(
[this]() -> void {
if (!m_mn_sync.IsBlockchainSynced()) return;
if (ShutdownRequested()) return;
if (m_chainman.m_interrupt) return;

CheckForCompleteQueue();
CheckPool();
Expand Down
2 changes: 1 addition & 1 deletion src/coinjoin/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ bool CTransactionBuilder::Commit(bilingual_str& strResult)
LOCK(cs_outputs);
vecSend.reserve(vecOutputs.size());
for (const auto& out : vecOutputs) {
vecSend.push_back((CRecipient){out->GetScript(), out->GetAmount(), false});
vecSend.push_back((CRecipient){CNoDestination{out->GetScript()}, out->GetAmount(), false});
}
}

Expand Down
7 changes: 4 additions & 3 deletions src/coinjoin/walletman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
#include <net.h>
#include <protocol.h>
#include <scheduler.h>
#include <shutdown.h>
#include <streams.h>
#include <util/signalinterrupt.h>
#include <validation.h>

#ifdef ENABLE_WALLET
#include <coinjoin/client.h>
Expand Down Expand Up @@ -209,7 +210,7 @@ void CJWalletManagerImpl::removeWallet(const std::string& name)

void CJWalletManagerImpl::DoMaintenance(CConnman& connman)
{
if (m_queueman && m_mn_sync.IsBlockchainSynced() && !ShutdownRequested()) {
if (m_queueman && m_mn_sync.IsBlockchainSynced() && !m_chainman.m_interrupt) {
m_queueman->CheckQueue();
}
LOCK(cs_wallet_manager_map);
Expand All @@ -220,7 +221,7 @@ void CJWalletManagerImpl::DoMaintenance(CConnman& connman)

void CJWalletManagerImpl::CheckPendingObservations()
{
if (ShutdownRequested()) return;
if (m_chainman.m_interrupt) return;
LOCK(cs_wallet_manager_map);
for (auto& [_, clientman] : m_wallet_manager_map) {
clientman->CheckPendingObservations(m_mempool);
Expand Down
2 changes: 2 additions & 0 deletions src/consensus/validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ enum class TxValidationResult {
TX_CONFLICT_LOCK, //!< conflicts with InstantSend lock
TX_MEMPOOL_POLICY, //!< violated mempool's fee/size/descendant/etc limits
TX_NO_MEMPOOL, //!< this node does not have a mempool so can't validate the transaction
TX_RECONSIDERABLE, //!< fails some policy, but might be acceptable if submitted in a (different) package
TX_UNKNOWN, //!< transaction was not validated because package failed
};

/** A "reason" why a block was invalid, suitable for determining whether the
Expand Down
13 changes: 7 additions & 6 deletions src/httpserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
#include <netbase.h>
#include <node/interface_ui.h>
#include <rpc/protocol.h> // For HTTP status codes
#include <shutdown.h>
#include <sync.h>
#include <util/check.h>
#include <util/signalinterrupt.h>
#include <util/strencodings.h>
#include <util/threadnames.h>
#include <util/translation.h>
Expand Down Expand Up @@ -296,7 +296,7 @@ static void http_request_cb(struct evhttp_request* req, void* arg)
}
}
}
auto hreq{std::make_unique<HTTPRequest>(req)};
auto hreq{std::make_unique<HTTPRequest>(req, *static_cast<const util::SignalInterrupt*>(arg))};

// Early address-based allow check
if (!ClientAllowed(hreq->GetPeer())) {
Expand Down Expand Up @@ -462,7 +462,7 @@ static void libevent_log_cb(int severity, const char *msg)
LogPrintLevel(BCLog::LIBEVENT, level, "%s\n", msg);
}

bool InitHTTPServer()
bool InitHTTPServer(const util::SignalInterrupt& interrupt)
{
if (!InitHTTPAllowList())
return false;
Expand Down Expand Up @@ -491,7 +491,7 @@ bool InitHTTPServer()
evhttp_set_timeout(http, gArgs.GetIntArg("-rpcservertimeout", DEFAULT_HTTP_SERVER_TIMEOUT));
evhttp_set_max_headers_size(http, MAX_HEADERS_SIZE);
evhttp_set_max_body_size(http, MAX_SIZE);
evhttp_set_gencb(http, http_request_cb, nullptr);
evhttp_set_gencb(http, http_request_cb, (void*)&interrupt);

if (!HTTPBindAddresses(http)) {
LogPrintf("Unable to bind any endpoint for RPC server\n");
Expand Down Expand Up @@ -619,7 +619,8 @@ void HTTPEvent::trigger(struct timeval* tv)
else
evtimer_add(ev, tv); // trigger after timeval passed
}
HTTPRequest::HTTPRequest(struct evhttp_request* _req, bool _replySent) : req(_req), replySent(_replySent)
HTTPRequest::HTTPRequest(struct evhttp_request* _req, const util::SignalInterrupt& interrupt, bool _replySent)
: req(_req), m_interrupt(interrupt), replySent(_replySent)
{
}

Expand Down Expand Up @@ -679,7 +680,7 @@ void HTTPRequest::WriteHeader(const std::string& hdr, const std::string& value)
void HTTPRequest::WriteReply(int nStatus, const std::string& strReply)
{
assert(!replySent && req);
if (ShutdownRequested()) {
if (m_interrupt) {
WriteHeader("Connection", "close");
}
// Send event to main http thread to send reply message
Expand Down
9 changes: 7 additions & 2 deletions src/httpserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
#include <optional>
#include <string>

namespace util {
class SignalInterrupt;
} // namespace util

static const int DEFAULT_HTTP_THREADS=4;
static const int DEFAULT_HTTP_WORKQUEUE=16;
static const int DEFAULT_HTTP_SERVER_TIMEOUT=30;
Expand All @@ -21,7 +25,7 @@ class HTTPRequest;
/** Initialize HTTP server.
* Call this before RegisterHTTPHandler or EventBase().
*/
bool InitHTTPServer();
bool InitHTTPServer(const util::SignalInterrupt& interrupt);
/** Start HTTP server.
* This is separate from InitHTTPServer to give users race-condition-free time
* to register their handlers between InitHTTPServer and StartHTTPServer.
Expand Down Expand Up @@ -57,10 +61,11 @@ class HTTPRequest
{
private:
struct evhttp_request* req;
const util::SignalInterrupt& m_interrupt;
bool replySent;

public:
explicit HTTPRequest(struct evhttp_request* req, bool replySent = false);
explicit HTTPRequest(struct evhttp_request* req, const util::SignalInterrupt& interrupt, bool replySent = false);
~HTTPRequest();

enum RequestMethod {
Expand Down
2 changes: 1 addition & 1 deletion src/index/base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ template <typename... Args>
void BaseIndex::FatalErrorf(const char* fmt, const Args&... args)
{
auto message = tfm::format(fmt, args...);
node::AbortNode(m_chain->context()->exit_status, message);
node::AbortNode(m_chain->context()->shutdown, m_chain->context()->exit_status, message);
}

CBlockLocator GetLocator(interfaces::Chain& chain, const uint256& block_hash)
Expand Down
Loading
Loading