Skip to content
Open
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
11 changes: 7 additions & 4 deletions src/blockencodings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ uint64_t CBlockHeaderAndShortTxIDs::GetShortID(const uint256& txhash) const {



ReadStatus PartiallyDownloadedBlock::InitData(const CBlockHeaderAndShortTxIDs& cmpctblock, const std::vector<std::pair<uint256, CTransactionRef>>& extra_txn) {
ReadStatus PartiallyDownloadedBlock::InitData(const CBlockHeaderAndShortTxIDs& cmpctblock, const std::vector<CTransactionRef>& extra_txn) {
if (cmpctblock.header.IsNull() || (cmpctblock.shorttxids.empty() && cmpctblock.prefilledtxn.empty()))
return READ_STATUS_INVALID;
if (cmpctblock.shorttxids.size() + cmpctblock.prefilledtxn.size() > MaxBlockSize() / MIN_TRANSACTION_SIZE)
Expand Down Expand Up @@ -140,11 +140,14 @@ ReadStatus PartiallyDownloadedBlock::InitData(const CBlockHeaderAndShortTxIDs& c
}

for (size_t i = 0; i < extra_txn.size(); i++) {
uint64_t shortid = cmpctblock.GetShortID(extra_txn[i].first);
if (extra_txn[i] == nullptr) {
continue;
}
uint64_t shortid = cmpctblock.GetShortID(extra_txn[i]->GetInstanceHash());
std::unordered_map<uint64_t, uint16_t>::iterator idit = shorttxids.find(shortid);
if (idit != shorttxids.end()) {
if (!have_txn[idit->second]) {
txn_available[idit->second] = extra_txn[i].second;
txn_available[idit->second] = extra_txn[i];
have_txn[idit->second] = true;
mempool_count++;
extra_count++;
Expand All @@ -156,7 +159,7 @@ ReadStatus PartiallyDownloadedBlock::InitData(const CBlockHeaderAndShortTxIDs& c
// Note that we don't want duplication between extra_txn and mempool to
// trigger this case, so we compare hashes first
if (txn_available[idit->second] &&
txn_available[idit->second]->GetHash() != extra_txn[i].second->GetHash()) {
txn_available[idit->second]->GetHash() != extra_txn[i]->GetHash()) {
txn_available[idit->second].reset();
mempool_count--;
extra_count--;
Expand Down
2 changes: 1 addition & 1 deletion src/blockencodings.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class PartiallyDownloadedBlock {
explicit PartiallyDownloadedBlock(CTxMemPool* poolIn) : pool(poolIn) {}

// extra_txn is a list of extra transactions to look at, in <hash, reference> form

@thepastaclaw thepastaclaw Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Withdrawn at e3594251; see the replies below.

💬 Nitpick: Stale extra-transaction API comment remains

InitData now accepts std::vector<CTransactionRef>, and the implementation computes the instance hash from each transaction. The comment still describes the argument as being in <hash, reference> form, which is no longer accurate and can mislead callers about the required input. Update it to describe a list of transaction references.

Suggested change
// extra_txn is a list of extra transactions to look at, in <hash, reference> form
// extra_txn is a list of extra transactions to look at

source: muse-spark-1.3-contributor (phase1-reviewer: general); gpt-6.1-sol (phase2-reviewer: general, backport-reviewer, dash-core-commit-history)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The backport matches upstream: bitcoin#29752 changed only the InitData signature and left this comment as it was (upstream's merge 7cc9a08 still says "in <witness hash, reference> form"). Rewording it would be a cleanup upstream never made, so it belongs in a separate upstream or Dash change, not this backport.


🤖 backportsys, on behalf of the Dash backport pipeline.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked the parent diff and agree that this is an unchanged upstream comment carried through the faithful backport, rather than a Dash-specific adaptation error. The wording is stale relative to the upstream API change, but updating it here would be a separate documentation cleanup, so I withdraw this nitpick for this backport.

Withdrawing this finding.

ReadStatus InitData(const CBlockHeaderAndShortTxIDs& cmpctblock, const std::vector<std::pair<uint256, CTransactionRef>>& extra_txn);
ReadStatus InitData(const CBlockHeaderAndShortTxIDs& cmpctblock, const std::vector<CTransactionRef>& extra_txn);
bool IsTxAvailable(size_t index) const;
ReadStatus FillBlock(CBlock& block, const std::vector<CTransactionRef>& vtx_missing);
};
Expand Down
4 changes: 2 additions & 2 deletions src/init/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ void AddLoggingArgs(ArgsManager& argsman)
{
argsman.AddArg("-debuglogfile=<file>", strprintf("Specify location of debug log file (default: %s). Relative paths will be prefixed by a net-specific datadir location. Pass -nodebuglogfile to disable writing the log to a file.", DEFAULT_DEBUGLOGFILE), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-debug=<category>", "Output debug and trace logging (default: -nodebug, supplying <category> is optional). "
"If <category> is not supplied or if <category> = 1, output all debug and trace logging. <category> can be: " + LogInstance().LogCategoriesString() + ". This option can be specified multiple times to output multiple categories.",
"If <category> is not supplied or if <category> is 1 or \"all\", output all debug logging. If <category> is 0 or \"none\", any other categories are ignored. Other valid values for <category> are: " + LogInstance().LogCategoriesString() + ". This option can be specified multiple times to output multiple categories.",
ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
argsman.AddArg("-debugexclude=<category>", "Exclude debug and trace logging for a category. Can be used in conjunction with -debug=1 to output debug and trace logging for all categories except the specified category. This option can be specified multiple times to exclude multiple categories.", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
argsman.AddArg("-debugexclude=<category>", "Exclude debug and trace logging for a category. Can be used in conjunction with -debug=1 to output debug and trace logging for all categories except the specified category. This option can be specified multiple times to exclude multiple categories. This takes priority over \"-debug\"", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
argsman.AddArg("-logips", strprintf("Include IP addresses in debug output (default: %u)", DEFAULT_LOGIPS), ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
argsman.AddArg("-loglevel=<level>|<category>:<level>", strprintf("Set the global or per-category severity level for logging categories enabled with the -debug configuration option or the logging RPC. Possible values are %s (default=%s). The following levels are always logged: error, warning, info. If <category>:<level> is supplied, the setting will override the global one and may be specified multiple times to set multiple category-specific levels. <category> can be: %s.", LogInstance().LogLevelsString(), LogInstance().LogLevelToStr(BCLog::DEFAULT_LOG_LEVEL), LogInstance().LogCategoriesString()), ArgsManager::DISALLOW_NEGATION | ArgsManager::DISALLOW_ELISION | ArgsManager::DEBUG_ONLY, OptionsCategory::DEBUG_TEST);
argsman.AddArg("-logtimestamps", strprintf("Prepend debug output with timestamp (default: %u)", DEFAULT_LOGTIMESTAMPS), ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
Expand Down
249 changes: 77 additions & 172 deletions src/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#include <util/threadnames.h>
#include <util/time.h>

#include <algorithm>
#include <array>
#include <map>
#include <optional>

const char * const DEFAULT_DEBUGLOGFILE = "debug.log";
Expand Down Expand Up @@ -141,78 +141,82 @@ bool BCLog::Logger::DefaultShrinkDebugFile() const
return m_categories == BCLog::NONE;
}

struct CLogCategoryDesc {
BCLog::LogFlags flag;
std::string category;
};

const CLogCategoryDesc LogCategories[] =
{
{BCLog::NONE, "0"},
{BCLog::NONE, ""},
{BCLog::NET, "net"},
{BCLog::TOR, "tor"},
{BCLog::MEMPOOL, "mempool"},
{BCLog::HTTP, "http"},
{BCLog::BENCHMARK, "bench"},
{BCLog::ZMQ, "zmq"},
{BCLog::WALLETDB, "walletdb"},
{BCLog::RPC, "rpc"},
{BCLog::ESTIMATEFEE, "estimatefee"},
{BCLog::ADDRMAN, "addrman"},
{BCLog::SELECTCOINS, "selectcoins"},
{BCLog::REINDEX, "reindex"},
{BCLog::CMPCTBLOCK, "cmpctblock"},
{BCLog::RANDOM, "rand"},
{BCLog::PRUNE, "prune"},
{BCLog::PROXY, "proxy"},
{BCLog::MEMPOOLREJ, "mempoolrej"},
{BCLog::LIBEVENT, "libevent"},
{BCLog::COINDB, "coindb"},
{BCLog::QT, "qt"},
{BCLog::LEVELDB, "leveldb"},
{BCLog::VALIDATION, "validation"},
{BCLog::I2P, "i2p"},
{BCLog::IPC, "ipc"},
static const std::map<std::string, BCLog::LogFlags> LOG_CATEGORIES_BY_STR{
{"net", BCLog::NET},
{"tor", BCLog::TOR},
{"mempool", BCLog::MEMPOOL},
{"http", BCLog::HTTP},
{"bench", BCLog::BENCHMARK},
{"zmq", BCLog::ZMQ},
{"walletdb", BCLog::WALLETDB},
{"rpc", BCLog::RPC},
{"estimatefee", BCLog::ESTIMATEFEE},
{"addrman", BCLog::ADDRMAN},
{"selectcoins", BCLog::SELECTCOINS},
{"reindex", BCLog::REINDEX},
{"cmpctblock", BCLog::CMPCTBLOCK},
{"rand", BCLog::RANDOM},
{"prune", BCLog::PRUNE},
{"proxy", BCLog::PROXY},
{"mempoolrej", BCLog::MEMPOOLREJ},
{"libevent", BCLog::LIBEVENT},
{"coindb", BCLog::COINDB},
{"qt", BCLog::QT},
{"leveldb", BCLog::LEVELDB},
{"validation", BCLog::VALIDATION},
{"i2p", BCLog::I2P},
{"ipc", BCLog::IPC},
#ifdef DEBUG_LOCKCONTENTION
{BCLog::LOCK, "lock"},
{"lock", BCLog::LOCK},
#endif
{BCLog::BLOCKSTORAGE, "blockstorage"},
{BCLog::TXRECONCILIATION, "txreconciliation"},
{BCLog::SCAN, "scan"},
{BCLog::TXPACKAGES, "txpackages"},
{BCLog::ALL, "1"},
{BCLog::ALL, "all"},
{"blockstorage", BCLog::BLOCKSTORAGE},
{"txreconciliation", BCLog::TXRECONCILIATION},
{"scan", BCLog::SCAN},
{"txpackages", BCLog::TXPACKAGES},

//Start Dash
{BCLog::CHAINLOCKS, "chainlocks"},
{BCLog::GOBJECT, "gobject"},
{BCLog::INSTANTSEND, "instantsend"},
{BCLog::LLMQ, "llmq"},
{BCLog::LLMQ_DKG, "llmq-dkg"},
{BCLog::LLMQ_SIGS, "llmq-sigs"},
{BCLog::MNPAYMENTS, "mnpayments"},
{BCLog::MNSYNC, "mnsync"},
{BCLog::COINJOIN, "coinjoin"},
{BCLog::SPORK, "spork"},
{BCLog::NETCONN, "netconn"},
{BCLog::CREDITPOOL, "creditpool"},
{BCLog::EHF, "ehf"},
{BCLog::DASH, "dash"},
{"chainlocks", BCLog::CHAINLOCKS},
{"gobject", BCLog::GOBJECT},
{"instantsend", BCLog::INSTANTSEND},
{"llmq", BCLog::LLMQ},
{"llmq-dkg", BCLog::LLMQ_DKG},
{"llmq-sigs", BCLog::LLMQ_SIGS},
{"mnpayments", BCLog::MNPAYMENTS},
{"mnsync", BCLog::MNSYNC},
{"coinjoin", BCLog::COINJOIN},
{"spork", BCLog::SPORK},
{"netconn", BCLog::NETCONN},
{"creditpool", BCLog::CREDITPOOL},
{"ehf", BCLog::EHF},
{"dash", BCLog::DASH},
//End Dash
};

static const std::unordered_map<BCLog::LogFlags, std::string> LOG_CATEGORIES_BY_FLAG{
// Swap keys and values from LOG_CATEGORIES_BY_STR.
[](const std::map<std::string, BCLog::LogFlags>& in) {
std::unordered_map<BCLog::LogFlags, std::string> out;
for (const auto& [k, v] : in) {
const bool inserted{out.emplace(v, k).second};
assert(inserted);
}
/* Start Dash */
out.emplace(BCLog::NET_NETCONN, "net|netconn");
/* End Dash */
return out;
}(LOG_CATEGORIES_BY_STR)
};

bool GetLogCategory(BCLog::LogFlags& flag, const std::string& str)
{
if (str.empty()) {
if (str.empty() || str == "1" || str == "all") {
flag = BCLog::ALL;
return true;
}
for (const CLogCategoryDesc& category_desc : LogCategories) {
if (category_desc.category == str) {
flag = category_desc.flag;
return true;
}
auto it = LOG_CATEGORIES_BY_STR.find(str);
if (it != LOG_CATEGORIES_BY_STR.end()) {
flag = it->second;
return true;
}
return false;
}
Expand All @@ -234,108 +238,14 @@ std::string BCLog::Logger::LogLevelToStr(BCLog::Level level)
assert(false);
}

std::string LogCategoryToStr(BCLog::LogFlags category)
static std::string LogCategoryToStr(BCLog::LogFlags category)
{
// Each log category string representation should sync with LogCategories
switch (category) {
case BCLog::LogFlags::NONE:
return "";
case BCLog::LogFlags::NET:
return "net";
case BCLog::LogFlags::TOR:
return "tor";
case BCLog::LogFlags::MEMPOOL:
return "mempool";
case BCLog::LogFlags::HTTP:
return "http";
case BCLog::LogFlags::BENCHMARK:
return "bench";
case BCLog::LogFlags::ZMQ:
return "zmq";
case BCLog::LogFlags::WALLETDB:
return "walletdb";
case BCLog::LogFlags::RPC:
return "rpc";
case BCLog::LogFlags::ESTIMATEFEE:
return "estimatefee";
case BCLog::LogFlags::ADDRMAN:
return "addrman";
case BCLog::LogFlags::SELECTCOINS:
return "selectcoins";
case BCLog::LogFlags::REINDEX:
return "reindex";
case BCLog::LogFlags::CMPCTBLOCK:
return "cmpctblock";
case BCLog::LogFlags::RANDOM:
return "rand";
case BCLog::LogFlags::PRUNE:
return "prune";
case BCLog::LogFlags::PROXY:
return "proxy";
case BCLog::LogFlags::MEMPOOLREJ:
return "mempoolrej";
case BCLog::LogFlags::LIBEVENT:
return "libevent";
case BCLog::LogFlags::COINDB:
return "coindb";
case BCLog::LogFlags::QT:
return "qt";
case BCLog::LogFlags::LEVELDB:
return "leveldb";
case BCLog::LogFlags::VALIDATION:
return "validation";
case BCLog::LogFlags::I2P:
return "i2p";
case BCLog::LogFlags::IPC:
return "ipc";
#ifdef DEBUG_LOCKCONTENTION
case BCLog::LogFlags::LOCK:
return "lock";
#endif
case BCLog::LogFlags::BLOCKSTORAGE:
return "blockstorage";
case BCLog::LogFlags::TXRECONCILIATION:
return "txreconciliation";
case BCLog::LogFlags::SCAN:
return "scan";
case BCLog::LogFlags::TXPACKAGES:
return "txpackages";
/* Start Dash */
case BCLog::LogFlags::CHAINLOCKS:
return "chainlocks";
case BCLog::LogFlags::GOBJECT:
return "gobject";
case BCLog::LogFlags::INSTANTSEND:
return "instantsend";
case BCLog::LogFlags::LLMQ:
return "llmq";
case BCLog::LogFlags::LLMQ_DKG:
return "llmq-dkg";
case BCLog::LogFlags::LLMQ_SIGS:
return "llmq-sigs";
case BCLog::LogFlags::MNPAYMENTS:
return "mnpayments";
case BCLog::LogFlags::MNSYNC:
return "mnsync";
case BCLog::LogFlags::COINJOIN:
return "coinjoin";
case BCLog::LogFlags::SPORK:
return "spork";
case BCLog::LogFlags::NETCONN:
return "netconn";
case BCLog::LogFlags::CREDITPOOL:
return "creditpool";
case BCLog::LogFlags::EHF:
return "ehf";
case BCLog::LogFlags::DASH:
return "dash";
case BCLog::LogFlags::NET_NETCONN:
return "net|netconn";
/* End Dash */
case BCLog::LogFlags::ALL:
if (category == BCLog::ALL) {
return "all";
}
assert(false);
auto it = LOG_CATEGORIES_BY_FLAG.find(category);
assert(it != LOG_CATEGORIES_BY_FLAG.end());
return it->second;
}

static std::optional<BCLog::Level> GetLogLevel(const std::string& level_str)
Expand All @@ -357,19 +267,14 @@ static std::optional<BCLog::Level> GetLogLevel(const std::string& level_str)

std::vector<LogCategory> BCLog::Logger::LogCategoriesList(bool enabled_only) const
{
// Sort log categories by alphabetical order.
std::array<CLogCategoryDesc, std::size(LogCategories)> categories;
std::copy(std::begin(LogCategories), std::end(LogCategories), categories.begin());
std::sort(categories.begin(), categories.end(), [](auto a, auto b) { return a.category < b.category; });

std::vector<LogCategory> ret;
for (const CLogCategoryDesc& category_desc : categories) {
if (category_desc.flag == BCLog::NONE || category_desc.flag == BCLog::ALL || category_desc.flag == BCLog::DASH) continue;
LogCategory catActive;
catActive.category = category_desc.category;
catActive.active = WillLogCategory(category_desc.flag);
if (!enabled_only || catActive.active) {
ret.push_back(catActive);
ret.reserve(LOG_CATEGORIES_BY_STR.size());
for (const auto& [category, flag] : LOG_CATEGORIES_BY_STR) {
if (flag != BCLog::DASH) {
LogCategory catActive{.category = category, .active = WillLogCategory(flag)};
if (!enabled_only || catActive.active) {
ret.push_back(catActive);
}
}
}
return ret;
Expand Down
14 changes: 7 additions & 7 deletions src/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ namespace BCLog {
#ifdef DEBUG_LOCKCONTENTION
LOCK = (1 << 24),
#endif
BLOCKSTORAGE = (1 << 26),
TXRECONCILIATION = (1 << 27),
SCAN = (1 << 28),
TXPACKAGES = (1 << 29),
BLOCKSTORAGE = (1 << 25),
TXRECONCILIATION = (1 << 26),
SCAN = (1 << 27),
TXPACKAGES = (1 << 28),

//Start Dash
CHAINLOCKS = ((uint64_t)1 << 32),
Expand Down Expand Up @@ -128,14 +128,16 @@ namespace BCLog {
std::atomic<Level> m_log_level{DEFAULT_LOG_LEVEL};

/** Log categories bitfield. */
std::atomic<uint64_t> m_categories{0};
std::atomic<uint64_t> m_categories{BCLog::NONE};

std::string LogTimestampStr(const std::string& str);
std::string LogThreadNameStr(const std::string &str);

/** Slots that connect to the print signal */
std::list<std::function<void(const std::string&)>> m_print_callbacks /* GUARDED_BY(m_cs) */ {};

std::string GetLogPrefix(LogFlags category, Level level) const;

public:
bool m_print_to_console = false;
bool m_print_to_file = false;
Expand All @@ -149,8 +151,6 @@ namespace BCLog {
fs::path m_file_path;
std::atomic<bool> m_reopen_file{false};

std::string GetLogPrefix(LogFlags category, Level level) const;

/** Send a string to the log output */
void LogPrintStr(const std::string& str, const std::string& logging_function, const std::string& source_file, int source_line, BCLog::LogFlags category, BCLog::Level level);

Expand Down
Loading
Loading