Skip to content

Commit d23ecf8

Browse files
Merge dashpay#6046: backport: trivial 2024 06 04
a62e170 Merge bitcoin#23458: ci: Do not print `git log` for empty COMMIT_RANGE (MarcoFalke) eec305b Merge bitcoin#22904: sync, log: inline lock contention logging macro to fix duration, improve BCLog::LogMsg() (merge-script) 54e6449 Merge bitcoin-core/gui#250: scripted-diff: Drop redundant QString calls (MarcoFalke) d2032dd Merge bitcoin#20845: net: Log to net debug in MaybeDiscourageAndDisconnect except for noban and manual peers (MarcoFalke) a2f3ba0 Merge bitcoin-core/gui#202: peers-tab: bug fix right panel toggle (MarcoFalke) a5e7b02 Merge bitcoin#21124: test: remove unnecessary assignment in bdb (MarcoFalke) 53f9d2c 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 a62e170 Tree-SHA512: d14fb153e256ec7e2c5562e6c9361e0a890376092cbe78b59e88a1462bf2c32fc169f9bd0e00493ac68cdf47870c07023f52e3be7da807e2886b33dba7a8816a
2 parents 44f237a + a62e170 commit d23ecf8

File tree

14 files changed

+65
-76
lines changed

14 files changed

+65
-76
lines changed

ci/lint/06_script.sh

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ export LC_ALL=C
88

99
GIT_HEAD=$(git rev-parse HEAD)
1010
if [ -n "$CIRRUS_PR" ]; then
11-
COMMIT_RANGE="$CIRRUS_BASE_SHA..$GIT_HEAD"
12-
test/lint/commit-script-check.sh $COMMIT_RANGE
11+
COMMIT_RANGE="${CIRRUS_BASE_SHA}..$GIT_HEAD"
12+
test/lint/commit-script-check.sh "$COMMIT_RANGE"
1313
fi
1414
export COMMIT_RANGE
1515

@@ -29,5 +29,7 @@ if [ "$CIRRUS_REPO_FULL_NAME" = "dashpay/dash" ] && [ -n "$CIRRUS_CRON" ]; then
2929
./contrib/verify-commits/verify-commits.py --clean-merge=2;
3030
fi
3131

32-
echo
33-
git log --no-merges --oneline $COMMIT_RANGE
32+
if [ -n "$COMMIT_RANGE" ]; then
33+
echo
34+
git log --no-merges --oneline "$COMMIT_RANGE"
35+
fi

src/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ BITCOIN_CORE_H = \
360360
util/tokenpipe.h \
361361
util/trace.h \
362362
util/translation.h \
363+
util/types.h \
363364
util/ui_change_type.h \
364365
util/url.h \
365366
util/vector.h \

src/logging/timer.h

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <logging.h>
1010
#include <util/macros.h>
1111
#include <util/time.h>
12+
#include <util/types.h>
1213

1314
#include <chrono>
1415
#include <string>
@@ -58,23 +59,15 @@ class Timer
5859
return strprintf("%s: %s", m_prefix, msg);
5960
}
6061

61-
if (std::is_same<TimeType, std::chrono::microseconds>::value) {
62+
if constexpr (std::is_same<TimeType, std::chrono::microseconds>::value) {
6263
return strprintf("%s: %s (%iμs)", m_prefix, msg, end_time.count());
64+
} else if constexpr (std::is_same<TimeType, std::chrono::milliseconds>::value) {
65+
return strprintf("%s: %s (%.2fms)", m_prefix, msg, end_time.count() * 0.001);
66+
} else if constexpr (std::is_same<TimeType, std::chrono::seconds>::value) {
67+
return strprintf("%s: %s (%.2fs)", m_prefix, msg, end_time.count() * 0.000001);
68+
} else {
69+
static_assert(ALWAYS_FALSE<TimeType>, "Error: unexpected time type");
6370
}
64-
65-
std::string units;
66-
float divisor = 1;
67-
68-
if (std::is_same<TimeType, std::chrono::milliseconds>::value) {
69-
units = "ms";
70-
divisor = 1000.;
71-
} else if (std::is_same<TimeType, std::chrono::seconds>::value) {
72-
units = "s";
73-
divisor = 1000. * 1000.;
74-
}
75-
76-
const float time_ms = end_time.count() / divisor;
77-
return strprintf("%s: %s (%.2f%s)", m_prefix, msg, time_ms, units);
7871
}
7972

8073
private:
@@ -89,7 +82,6 @@ class Timer
8982
//! Forwarded on to LogPrint if specified - has the effect of only
9083
//! outputting the timing log when a particular debug= category is specified.
9184
const BCLog::LogFlags m_log_category{};
92-
9385
};
9486

9587
} // namespace BCLog

src/net_processing.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4914,7 +4914,8 @@ bool PeerManagerImpl::MaybeDiscourageAndDisconnect(CNode& pnode, Peer& peer)
49144914
if (pnode.addr.IsLocal()) {
49154915
// We disconnect local peers for bad behavior but don't discourage (since that would discourage
49164916
// all peers on the same local address)
4917-
LogPrintf("Warning: disconnecting but not discouraging local peer %d!\n", peer.m_id);
4917+
LogPrint(BCLog::NET, "Warning: disconnecting but not discouraging %s peer %d!\n",
4918+
pnode.m_inbound_onion ? "inbound onion" : "local", peer.m_id);
49184919
pnode.fDisconnect = true;
49194920
return true;
49204921
}

src/qt/forms/debugwindow.ui

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,7 @@
870870
</item>
871871
</layout>
872872
</widget>
873-
<widget class="QWidget" name="widget_2" native="true">
873+
<widget class="QWidget" name="peersTabRightPanel" native="true">
874874
<property name="sizePolicy">
875875
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
876876
<horstretch>0</horstretch>

src/qt/guiutil.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,13 +1684,13 @@ QString formatDurationStr(std::chrono::seconds dur)
16841684
int seconds = secs % 60;
16851685

16861686
if (days)
1687-
strList.append(QString(QObject::tr("%1 d")).arg(days));
1687+
strList.append(QObject::tr("%1 d").arg(days));
16881688
if (hours)
1689-
strList.append(QString(QObject::tr("%1 h")).arg(hours));
1689+
strList.append(QObject::tr("%1 h").arg(hours));
16901690
if (mins)
1691-
strList.append(QString(QObject::tr("%1 m")).arg(mins));
1691+
strList.append(QObject::tr("%1 m").arg(mins));
16921692
if (seconds || (!days && !hours && !mins))
1693-
strList.append(QString(QObject::tr("%1 s")).arg(seconds));
1693+
strList.append(QObject::tr("%1 s").arg(seconds));
16941694

16951695
return strList.join(" ");
16961696
}
@@ -1713,12 +1713,12 @@ QString formatPingTime(std::chrono::microseconds ping_time)
17131713
{
17141714
return (ping_time == std::chrono::microseconds::max() || ping_time == 0us) ?
17151715
QObject::tr("N/A") :
1716-
QString(QObject::tr("%1 ms")).arg(QString::number((int)(count_microseconds(ping_time) / 1000), 10));
1716+
QObject::tr("%1 ms").arg(QString::number((int)(count_microseconds(ping_time) / 1000), 10));
17171717
}
17181718

17191719
QString formatTimeOffset(int64_t nTimeOffset)
17201720
{
1721-
return QString(QObject::tr("%1 s")).arg(QString::number((int)nTimeOffset, 10));
1721+
return QObject::tr("%1 s").arg(QString::number((int)nTimeOffset, 10));
17221722
}
17231723

17241724
QString formatNiceTimeOffset(qint64 secs)
@@ -1761,13 +1761,13 @@ QString formatNiceTimeOffset(qint64 secs)
17611761
QString formatBytes(uint64_t bytes)
17621762
{
17631763
if(bytes < 1024)
1764-
return QString(QObject::tr("%1 B")).arg(bytes);
1764+
return QObject::tr("%1 B").arg(bytes);
17651765
if(bytes < 1024 * 1024)
1766-
return QString(QObject::tr("%1 KB")).arg(bytes / 1024);
1766+
return QObject::tr("%1 KB").arg(bytes / 1024);
17671767
if(bytes < 1024 * 1024 * 1024)
1768-
return QString(QObject::tr("%1 MB")).arg(bytes / 1024 / 1024);
1768+
return QObject::tr("%1 MB").arg(bytes / 1024 / 1024);
17691769

1770-
return QString(QObject::tr("%1 GB")).arg(bytes / 1024 / 1024 / 1024);
1770+
return QObject::tr("%1 GB").arg(bytes / 1024 / 1024 / 1024);
17711771
}
17721772

17731773
qreal calculateIdealFontSize(int width, const QString& text, QFont font, qreal minPointSize, qreal font_size) {

src/qt/peertablemodel.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,11 @@ QVariant PeerTableModel::data(const QModelIndex &index, int role) const
186186
default:
187187
return QVariant();
188188
}
189+
} else if (role == StatsRole) {
190+
switch (index.column()) {
191+
case NetNodeId: return QVariant::fromValue(rec);
192+
default: return QVariant();
193+
}
189194
}
190195

191196
return QVariant();
@@ -221,11 +226,6 @@ QModelIndex PeerTableModel::index(int row, int column, const QModelIndex &parent
221226
return QModelIndex();
222227
}
223228

224-
const CNodeCombinedStats *PeerTableModel::getNodeStats(int idx)
225-
{
226-
return priv->index(idx);
227-
}
228-
229229
void PeerTableModel::refresh()
230230
{
231231
Q_EMIT layoutAboutToBeChanged();

src/qt/peertablemodel.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ struct CNodeCombinedStats {
2828
CNodeStateStats nodeStateStats;
2929
bool fNodeStateStatsAvailable;
3030
};
31+
Q_DECLARE_METATYPE(CNodeCombinedStats*)
3132

3233
class NodeLessThan
3334
{
@@ -52,7 +53,6 @@ class PeerTableModel : public QAbstractTableModel
5253
public:
5354
explicit PeerTableModel(interfaces::Node& node, QObject* parent);
5455
~PeerTableModel();
55-
const CNodeCombinedStats *getNodeStats(int idx);
5656
int getRowByNodeId(NodeId nodeid);
5757
void startAutoRefresh();
5858
void stopAutoRefresh();
@@ -67,6 +67,10 @@ class PeerTableModel : public QAbstractTableModel
6767
Subversion = 6
6868
};
6969

70+
enum {
71+
StatsRole = Qt::UserRole,
72+
};
73+
7074
/** @name Methods overridden from QAbstractTableModel
7175
@{*/
7276
int rowCount(const QModelIndex &parent) const override;

src/qt/rpcconsole.cpp

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,11 +1153,9 @@ void RPCConsole::setTrafficGraphRange(TrafficGraphData::GraphRange range)
11531153

11541154
void RPCConsole::peerLayoutAboutToChange()
11551155
{
1156-
QModelIndexList selected = ui->peerWidget->selectionModel()->selectedIndexes();
11571156
cachedNodeids.clear();
1158-
for(int i = 0; i < selected.size(); i++)
1159-
{
1160-
const CNodeCombinedStats *stats = clientModel->getPeerTableModel()->getNodeStats(selected.at(i).row());
1157+
for (const QModelIndex& peer : GUIUtil::getEntryData(ui->peerWidget, PeerTableModel::NetNodeId)) {
1158+
const auto stats = peer.data(PeerTableModel::StatsRole).value<CNodeCombinedStats*>();
11611159
cachedNodeids.append(stats->nodeStats.nodeid);
11621160
}
11631161
}
@@ -1216,15 +1214,13 @@ void RPCConsole::peerLayoutChanged()
12161214

12171215
void RPCConsole::updateDetailWidget()
12181216
{
1219-
QModelIndexList selected_rows;
1220-
auto selection_model = ui->peerWidget->selectionModel();
1221-
if (selection_model) selected_rows = selection_model->selectedRows();
1222-
if (!clientModel || !clientModel->getPeerTableModel() || selected_rows.size() != 1) {
1223-
ui->detailWidget->hide();
1217+
const QList<QModelIndex> selected_peers = GUIUtil::getEntryData(ui->peerWidget, PeerTableModel::NetNodeId);
1218+
if (!clientModel || !clientModel->getPeerTableModel() || selected_peers.size() != 1) {
1219+
ui->peersTabRightPanel->hide();
12241220
ui->peerHeading->setText(tr("Select a peer to view detailed information."));
12251221
return;
12261222
}
1227-
const CNodeCombinedStats *stats = clientModel->getPeerTableModel()->getNodeStats(selected_rows.first().row());
1223+
const auto stats = selected_peers.first().data(PeerTableModel::StatsRole).value<CNodeCombinedStats*>();
12281224
// update the detail ui with latest node information
12291225
QString peerAddrDetails(QString::fromStdString(stats->nodeStats.m_addr_name) + " ");
12301226
peerAddrDetails += tr("(peer: %1)").arg(QString::number(stats->nodeStats.nodeid));
@@ -1293,7 +1289,7 @@ void RPCConsole::updateDetailWidget()
12931289
ui->peerRelayTxes->setText(stats->nodeStateStats.m_relay_txs ? "Yes" : "No");
12941290
}
12951291

1296-
ui->detailWidget->show();
1292+
ui->peersTabRightPanel->show();
12971293
}
12981294

12991295
void RPCConsole::setButtonIcons()
@@ -1383,19 +1379,9 @@ void RPCConsole::banSelectedNode(int bantime)
13831379
if (!clientModel)
13841380
return;
13851381

1386-
// Get selected peer addresses
1387-
QList<QModelIndex> nodes = GUIUtil::getEntryData(ui->peerWidget, PeerTableModel::NetNodeId);
1388-
for(int i = 0; i < nodes.count(); i++)
1389-
{
1390-
// Get currently selected peer address
1391-
NodeId id = nodes.at(i).data().toLongLong();
1392-
1393-
// Get currently selected peer address
1394-
int detailNodeRow = clientModel->getPeerTableModel()->getRowByNodeId(id);
1395-
if (detailNodeRow < 0) return;
1396-
1382+
for (const QModelIndex& peer : GUIUtil::getEntryData(ui->peerWidget, PeerTableModel::NetNodeId)) {
13971383
// Find possible nodes, ban it and clear the selected node
1398-
const CNodeCombinedStats *stats = clientModel->getPeerTableModel()->getNodeStats(detailNodeRow);
1384+
const auto stats = peer.data(PeerTableModel::StatsRole).value<CNodeCombinedStats*>();
13991385
if (stats) {
14001386
m_node.ban(stats->nodeStats.addr, bantime);
14011387
m_node.disconnectByAddress(stats->nodeStats.addr);

src/sync.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#include <sync.h>
1010

1111
#include <logging.h>
12-
#include <logging/timer.h>
1312
#include <tinyformat.h>
1413
#include <util/strencodings.h>
1514
#include <util/threadnames.h>
@@ -24,11 +23,6 @@
2423
#include <utility>
2524
#include <vector>
2625

27-
void LockContention(const char* pszName, const char* pszFile, int nLine)
28-
{
29-
LOG_TIME_MICROS_WITH_CATEGORY(strprintf("%s, %s:%d", pszName, pszFile, nLine), BCLog::LOCK);
30-
}
31-
3226
#ifdef DEBUG_LOCKORDER
3327
//
3428
// Early deadlock detection.

0 commit comments

Comments
 (0)