Merge #6046: backport: trivial 2024 06 04

a62e17027f Merge bitcoin/bitcoin#23458: ci: Do not print `git log` for empty COMMIT_RANGE (MarcoFalke)
eec305b4b3 Merge bitcoin/bitcoin#22904: sync, log: inline lock contention logging macro to fix duration, improve BCLog::LogMsg() (merge-script)
54e6449d09 Merge bitcoin-core/gui#250: scripted-diff: Drop redundant QString calls (MarcoFalke)
d2032dd03f Merge #20845: net: Log to net debug in MaybeDiscourageAndDisconnect except for noban and manual peers (MarcoFalke)
a2f3ba0054 Merge bitcoin-core/gui#202: peers-tab: bug fix right panel toggle (MarcoFalke)
a5e7b029f2 Merge #21124: test: remove unnecessary assignment in bdb (MarcoFalke)
53f9d2ce2c Merge bitcoin-core/gui#161: Add PeerTableModel::StatsRole to prevent data layer violation (Jonas Schnelli)

Pull request description:

  ## Issue being fixed or feature implemented
  Batch of trivial backports

  ## What was done?
  Trivial backports

  ## How Has This Been Tested?
  Built; haven't ran tests

  ## Breaking Changes
  Didn't see any

  ## Checklist:
    _Go over all the following points, and put an `x` in all the boxes that apply._
  - [ ] I have performed a self-review of my own code
  - [ ] I have commented my code, particularly in hard-to-understand areas
  - [ ] I have added or updated relevant unit/integration/functional/e2e tests
  - [ ] I have made corresponding changes to the documentation
  - [x] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_

ACKs for top commit:
  knst:
    utACK a62e17027f

Tree-SHA512: d14fb153e256ec7e2c5562e6c9361e0a890376092cbe78b59e88a1462bf2c32fc169f9bd0e00493ac68cdf47870c07023f52e3be7da807e2886b33dba7a8816a
This commit is contained in:
pasta 2024-06-05 08:34:06 -05:00
commit d23ecf8c94
No known key found for this signature in database
GPG Key ID: 52527BEDABE87984
14 changed files with 65 additions and 76 deletions

View File

@ -8,8 +8,8 @@ export LC_ALL=C
GIT_HEAD=$(git rev-parse HEAD)
if [ -n "$CIRRUS_PR" ]; then
COMMIT_RANGE="$CIRRUS_BASE_SHA..$GIT_HEAD"
test/lint/commit-script-check.sh $COMMIT_RANGE
COMMIT_RANGE="${CIRRUS_BASE_SHA}..$GIT_HEAD"
test/lint/commit-script-check.sh "$COMMIT_RANGE"
fi
export COMMIT_RANGE
@ -29,5 +29,7 @@ if [ "$CIRRUS_REPO_FULL_NAME" = "dashpay/dash" ] && [ -n "$CIRRUS_CRON" ]; then
./contrib/verify-commits/verify-commits.py --clean-merge=2;
fi
echo
git log --no-merges --oneline $COMMIT_RANGE
if [ -n "$COMMIT_RANGE" ]; then
echo
git log --no-merges --oneline "$COMMIT_RANGE"
fi

View File

@ -360,6 +360,7 @@ BITCOIN_CORE_H = \
util/tokenpipe.h \
util/trace.h \
util/translation.h \
util/types.h \
util/ui_change_type.h \
util/url.h \
util/vector.h \

View File

@ -9,6 +9,7 @@
#include <logging.h>
#include <util/macros.h>
#include <util/time.h>
#include <util/types.h>
#include <chrono>
#include <string>
@ -58,23 +59,15 @@ public:
return strprintf("%s: %s", m_prefix, msg);
}
if (std::is_same<TimeType, std::chrono::microseconds>::value) {
if constexpr (std::is_same<TimeType, std::chrono::microseconds>::value) {
return strprintf("%s: %s (%iμs)", m_prefix, msg, end_time.count());
} else if constexpr (std::is_same<TimeType, std::chrono::milliseconds>::value) {
return strprintf("%s: %s (%.2fms)", m_prefix, msg, end_time.count() * 0.001);
} else if constexpr (std::is_same<TimeType, std::chrono::seconds>::value) {
return strprintf("%s: %s (%.2fs)", m_prefix, msg, end_time.count() * 0.000001);
} else {
static_assert(ALWAYS_FALSE<TimeType>, "Error: unexpected time type");
}
std::string units;
float divisor = 1;
if (std::is_same<TimeType, std::chrono::milliseconds>::value) {
units = "ms";
divisor = 1000.;
} else if (std::is_same<TimeType, std::chrono::seconds>::value) {
units = "s";
divisor = 1000. * 1000.;
}
const float time_ms = end_time.count() / divisor;
return strprintf("%s: %s (%.2f%s)", m_prefix, msg, time_ms, units);
}
private:
@ -89,7 +82,6 @@ private:
//! Forwarded on to LogPrint if specified - has the effect of only
//! outputting the timing log when a particular debug= category is specified.
const BCLog::LogFlags m_log_category{};
};
} // namespace BCLog

View File

@ -4914,7 +4914,8 @@ bool PeerManagerImpl::MaybeDiscourageAndDisconnect(CNode& pnode, Peer& peer)
if (pnode.addr.IsLocal()) {
// We disconnect local peers for bad behavior but don't discourage (since that would discourage
// all peers on the same local address)
LogPrintf("Warning: disconnecting but not discouraging local peer %d!\n", peer.m_id);
LogPrint(BCLog::NET, "Warning: disconnecting but not discouraging %s peer %d!\n",
pnode.m_inbound_onion ? "inbound onion" : "local", peer.m_id);
pnode.fDisconnect = true;
return true;
}

View File

@ -870,7 +870,7 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="widget_2" native="true">
<widget class="QWidget" name="peersTabRightPanel" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
<horstretch>0</horstretch>

View File

@ -1684,13 +1684,13 @@ QString formatDurationStr(std::chrono::seconds dur)
int seconds = secs % 60;
if (days)
strList.append(QString(QObject::tr("%1 d")).arg(days));
strList.append(QObject::tr("%1 d").arg(days));
if (hours)
strList.append(QString(QObject::tr("%1 h")).arg(hours));
strList.append(QObject::tr("%1 h").arg(hours));
if (mins)
strList.append(QString(QObject::tr("%1 m")).arg(mins));
strList.append(QObject::tr("%1 m").arg(mins));
if (seconds || (!days && !hours && !mins))
strList.append(QString(QObject::tr("%1 s")).arg(seconds));
strList.append(QObject::tr("%1 s").arg(seconds));
return strList.join(" ");
}
@ -1713,12 +1713,12 @@ QString formatPingTime(std::chrono::microseconds ping_time)
{
return (ping_time == std::chrono::microseconds::max() || ping_time == 0us) ?
QObject::tr("N/A") :
QString(QObject::tr("%1 ms")).arg(QString::number((int)(count_microseconds(ping_time) / 1000), 10));
QObject::tr("%1 ms").arg(QString::number((int)(count_microseconds(ping_time) / 1000), 10));
}
QString formatTimeOffset(int64_t nTimeOffset)
{
return QString(QObject::tr("%1 s")).arg(QString::number((int)nTimeOffset, 10));
return QObject::tr("%1 s").arg(QString::number((int)nTimeOffset, 10));
}
QString formatNiceTimeOffset(qint64 secs)
@ -1761,13 +1761,13 @@ QString formatNiceTimeOffset(qint64 secs)
QString formatBytes(uint64_t bytes)
{
if(bytes < 1024)
return QString(QObject::tr("%1 B")).arg(bytes);
return QObject::tr("%1 B").arg(bytes);
if(bytes < 1024 * 1024)
return QString(QObject::tr("%1 KB")).arg(bytes / 1024);
return QObject::tr("%1 KB").arg(bytes / 1024);
if(bytes < 1024 * 1024 * 1024)
return QString(QObject::tr("%1 MB")).arg(bytes / 1024 / 1024);
return QObject::tr("%1 MB").arg(bytes / 1024 / 1024);
return QString(QObject::tr("%1 GB")).arg(bytes / 1024 / 1024 / 1024);
return QObject::tr("%1 GB").arg(bytes / 1024 / 1024 / 1024);
}
qreal calculateIdealFontSize(int width, const QString& text, QFont font, qreal minPointSize, qreal font_size) {

View File

@ -186,6 +186,11 @@ QVariant PeerTableModel::data(const QModelIndex &index, int role) const
default:
return QVariant();
}
} else if (role == StatsRole) {
switch (index.column()) {
case NetNodeId: return QVariant::fromValue(rec);
default: return QVariant();
}
}
return QVariant();
@ -221,11 +226,6 @@ QModelIndex PeerTableModel::index(int row, int column, const QModelIndex &parent
return QModelIndex();
}
const CNodeCombinedStats *PeerTableModel::getNodeStats(int idx)
{
return priv->index(idx);
}
void PeerTableModel::refresh()
{
Q_EMIT layoutAboutToBeChanged();

View File

@ -28,6 +28,7 @@ struct CNodeCombinedStats {
CNodeStateStats nodeStateStats;
bool fNodeStateStatsAvailable;
};
Q_DECLARE_METATYPE(CNodeCombinedStats*)
class NodeLessThan
{
@ -52,7 +53,6 @@ class PeerTableModel : public QAbstractTableModel
public:
explicit PeerTableModel(interfaces::Node& node, QObject* parent);
~PeerTableModel();
const CNodeCombinedStats *getNodeStats(int idx);
int getRowByNodeId(NodeId nodeid);
void startAutoRefresh();
void stopAutoRefresh();
@ -67,6 +67,10 @@ public:
Subversion = 6
};
enum {
StatsRole = Qt::UserRole,
};
/** @name Methods overridden from QAbstractTableModel
@{*/
int rowCount(const QModelIndex &parent) const override;

View File

@ -1153,11 +1153,9 @@ void RPCConsole::setTrafficGraphRange(TrafficGraphData::GraphRange range)
void RPCConsole::peerLayoutAboutToChange()
{
QModelIndexList selected = ui->peerWidget->selectionModel()->selectedIndexes();
cachedNodeids.clear();
for(int i = 0; i < selected.size(); i++)
{
const CNodeCombinedStats *stats = clientModel->getPeerTableModel()->getNodeStats(selected.at(i).row());
for (const QModelIndex& peer : GUIUtil::getEntryData(ui->peerWidget, PeerTableModel::NetNodeId)) {
const auto stats = peer.data(PeerTableModel::StatsRole).value<CNodeCombinedStats*>();
cachedNodeids.append(stats->nodeStats.nodeid);
}
}
@ -1216,15 +1214,13 @@ void RPCConsole::peerLayoutChanged()
void RPCConsole::updateDetailWidget()
{
QModelIndexList selected_rows;
auto selection_model = ui->peerWidget->selectionModel();
if (selection_model) selected_rows = selection_model->selectedRows();
if (!clientModel || !clientModel->getPeerTableModel() || selected_rows.size() != 1) {
ui->detailWidget->hide();
const QList<QModelIndex> selected_peers = GUIUtil::getEntryData(ui->peerWidget, PeerTableModel::NetNodeId);
if (!clientModel || !clientModel->getPeerTableModel() || selected_peers.size() != 1) {
ui->peersTabRightPanel->hide();
ui->peerHeading->setText(tr("Select a peer to view detailed information."));
return;
}
const CNodeCombinedStats *stats = clientModel->getPeerTableModel()->getNodeStats(selected_rows.first().row());
const auto stats = selected_peers.first().data(PeerTableModel::StatsRole).value<CNodeCombinedStats*>();
// update the detail ui with latest node information
QString peerAddrDetails(QString::fromStdString(stats->nodeStats.m_addr_name) + " ");
peerAddrDetails += tr("(peer: %1)").arg(QString::number(stats->nodeStats.nodeid));
@ -1293,7 +1289,7 @@ void RPCConsole::updateDetailWidget()
ui->peerRelayTxes->setText(stats->nodeStateStats.m_relay_txs ? "Yes" : "No");
}
ui->detailWidget->show();
ui->peersTabRightPanel->show();
}
void RPCConsole::setButtonIcons()
@ -1383,19 +1379,9 @@ void RPCConsole::banSelectedNode(int bantime)
if (!clientModel)
return;
// Get selected peer addresses
QList<QModelIndex> nodes = GUIUtil::getEntryData(ui->peerWidget, PeerTableModel::NetNodeId);
for(int i = 0; i < nodes.count(); i++)
{
// Get currently selected peer address
NodeId id = nodes.at(i).data().toLongLong();
// Get currently selected peer address
int detailNodeRow = clientModel->getPeerTableModel()->getRowByNodeId(id);
if (detailNodeRow < 0) return;
for (const QModelIndex& peer : GUIUtil::getEntryData(ui->peerWidget, PeerTableModel::NetNodeId)) {
// Find possible nodes, ban it and clear the selected node
const CNodeCombinedStats *stats = clientModel->getPeerTableModel()->getNodeStats(detailNodeRow);
const auto stats = peer.data(PeerTableModel::StatsRole).value<CNodeCombinedStats*>();
if (stats) {
m_node.ban(stats->nodeStats.addr, bantime);
m_node.disconnectByAddress(stats->nodeStats.addr);

View File

@ -9,7 +9,6 @@
#include <sync.h>
#include <logging.h>
#include <logging/timer.h>
#include <tinyformat.h>
#include <util/strencodings.h>
#include <util/threadnames.h>
@ -24,11 +23,6 @@
#include <utility>
#include <vector>
void LockContention(const char* pszName, const char* pszFile, int nLine)
{
LOG_TIME_MICROS_WITH_CATEGORY(strprintf("%s, %s:%d", pszName, pszFile, nLine), BCLog::LOCK);
}
#ifdef DEBUG_LOCKORDER
//
// Early deadlock detection.

View File

@ -6,6 +6,8 @@
#ifndef BITCOIN_SYNC_H
#define BITCOIN_SYNC_H
#include <logging.h>
#include <logging/timer.h>
#include <threadsafety.h>
#include <util/macros.h>
@ -149,9 +151,6 @@ inline void AssertLockNotHeldInline(const char* name, const char* file, int line
inline void AssertLockNotHeldInline(const char* name, const char* file, int line, SharedMutex* cs) LOCKS_EXCLUDED(cs) { AssertLockNotHeldInternal(name, file, line, cs); }
#define AssertLockNotHeld(cs) AssertLockNotHeldInline(#cs, __FILE__, __LINE__, &cs)
/** Prints a lock contention to the log */
void LockContention(const char* pszName, const char* pszFile, int nLine);
/** Wrapper around std::unique_lock style lock for Mutex. */
template <typename Mutex, typename Base = typename Mutex::UniqueLock>
class SCOPED_LOCKABLE UniqueLock : public Base
@ -161,7 +160,7 @@ private:
{
EnterCritical(pszName, pszFile, nLine, Base::mutex());
if (Base::try_lock()) return;
LockContention(pszName, pszFile, nLine); // log the contention
LOG_TIME_MICROS_WITH_CATEGORY(strprintf("lock contention %s, %s:%d", pszName, pszFile, nLine), BCLog::LOCK);
Base::lock();
}

View File

@ -15,9 +15,9 @@ BOOST_FIXTURE_TEST_SUITE(logging_tests, BasicTestingSetup)
BOOST_AUTO_TEST_CASE(logging_timer)
{
SetMockTime(1);
auto sec_timer = BCLog::Timer<std::chrono::seconds>("tests", "end_msg");
auto micro_timer = BCLog::Timer<std::chrono::microseconds>("tests", "end_msg");
SetMockTime(2);
BOOST_CHECK_EQUAL(sec_timer.LogMsg("test secs"), "tests: test secs (1.00s)");
BOOST_CHECK_EQUAL(micro_timer.LogMsg("test micros"), "tests: test micros (1000000μs)");
SetMockTime(1);
auto ms_timer = BCLog::Timer<std::chrono::milliseconds>("tests", "end_msg");
@ -25,9 +25,9 @@ BOOST_AUTO_TEST_CASE(logging_timer)
BOOST_CHECK_EQUAL(ms_timer.LogMsg("test ms"), "tests: test ms (1000.00ms)");
SetMockTime(1);
auto micro_timer = BCLog::Timer<std::chrono::microseconds>("tests", "end_msg");
auto sec_timer = BCLog::Timer<std::chrono::seconds>("tests", "end_msg");
SetMockTime(2);
BOOST_CHECK_EQUAL(micro_timer.LogMsg("test micros"), "tests: test micros (1000000μs)");
BOOST_CHECK_EQUAL(sec_timer.LogMsg("test secs"), "tests: test secs (1.00s)");
}
BOOST_AUTO_TEST_SUITE_END()

11
src/util/types.h Normal file
View File

@ -0,0 +1,11 @@
// Copyright (c) 2021 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_UTIL_TYPES_H
#define BITCOIN_UTIL_TYPES_H
template <class>
inline constexpr bool ALWAYS_FALSE{false};
#endif // BITCOIN_UTIL_TYPES_H

View File

@ -51,7 +51,6 @@ def dump_leaf_page(data):
page_info['pgno'] = pgno
page_info['prev_pgno'] = prev_pgno
page_info['next_pgno'] = next_pgno
page_info['entries'] = entries
page_info['hf_offset'] = hf_offset
page_info['level'] = level
page_info['pg_type'] = pg_type