Skip to content

Commit

Permalink
merge bitcoin#23104: Avoid breaking single log lines over multiple li…
Browse files Browse the repository at this point in the history
…nes in the log file
  • Loading branch information
kwvg committed Nov 20, 2024
1 parent 479ae82 commit d9cc2ea
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
24 changes: 13 additions & 11 deletions src/sync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,34 +94,36 @@ LockData& GetLockData() {

static void potential_deadlock_detected(const LockPair& mismatch, const LockStack& s1, const LockStack& s2)
{
std::string strOutput = "";
strOutput += "POTENTIAL DEADLOCK DETECTED\n";
strOutput += "Previous lock order was:\n";
std::string log_message{};
log_message += "POTENTIAL DEADLOCK DETECTED\n";
log_message += "Previous lock order was:\n";
for (const LockStackItem& i : s1) {
std::string prefix{};
if (i.first == mismatch.first) {
strOutput += " (1)";
prefix = " (1)";
}
if (i.first == mismatch.second) {
strOutput += " (2)";
prefix = " (2)";
}
strOutput += strprintf(" %s\n", i.second.ToString());
log_message += strprintf("%s %s\n", prefix, i.second.ToString());
}

std::string mutex_a, mutex_b;
strOutput += "Current lock order is:\n";
log_message += "Current lock order is:\n";
for (const LockStackItem& i : s2) {
std::string prefix{};
if (i.first == mismatch.first) {
strOutput += " (1)";
prefix = " (1)";
mutex_a = i.second.Name();
}
if (i.first == mismatch.second) {
strOutput += " (2)";
prefix = " (2)";
mutex_b = i.second.Name();
}
strOutput += strprintf(" %s\n", i.second.ToString());
log_message += strprintf("%s %s\n", prefix, i.second.ToString());
}

LogPrintf("%s\n", strOutput);
LogPrintf("%s\n", log_message);

if (g_debug_lockorder_abort) {
tfm::format(std::cerr, "Assertion failed: detected inconsistent lock order for %s, details in debug log.\n", s2.back().second.ToString());
Expand Down
6 changes: 3 additions & 3 deletions src/wallet/coinselection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,15 +340,15 @@ bool KnapsackSolver(const CAmount& nTargetValue, std::vector<OutputGroup>& group
util::insert(setCoinsRet, lowest_larger->m_outputs);
nValueRet += lowest_larger->m_value;
} else {
std::string s = "CWallet::SelectCoinsMinConf best subset: ";
std::string log_message{"Coin selection best subset: "};
for (unsigned int i = 0; i < applicable_groups.size(); i++) {
if (vfBest[i]) {
util::insert(setCoinsRet, applicable_groups[i].m_outputs);
nValueRet += applicable_groups[i].m_value;
s += FormatMoney(applicable_groups[i].m_value) + " ";
log_message += strprintf("%s ", FormatMoney(applicable_groups[i].m_value));
}
}
LogPrint(BCLog::SELECTCOINS, "%s - total %s\n", s, FormatMoney(nBest));
LogPrint(BCLog::SELECTCOINS, "%stotal %s\n", log_message, FormatMoney(nBest));
}

// There is no change in PS, so we know the fee beforehand,
Expand Down

0 comments on commit d9cc2ea

Please sign in to comment.