Skip to content
Merged
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
6 changes: 6 additions & 0 deletions src/interfaces/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,18 @@ class Node
//! Get mempool dynamic usage.
virtual size_t getMempoolDynamicUsage() = 0;

//! Get mempool maximum memory usage.
virtual size_t getMempoolMaxUsage() = 0;

//! Get header tip height and time.
virtual bool getHeaderTip(int& height, int64_t& block_time) = 0;

//! Get num blocks.
virtual int getNumBlocks() = 0;

//! Get network local addresses.
virtual std::map<CNetAddr, LocalServiceInfo> getNetLocalAddresses() = 0;

//! Get best block hash.
virtual uint256 getBestBlockHash() = 0;

Expand Down
7 changes: 7 additions & 0 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4449,10 +4449,17 @@ size_t CConnman::GetNodeCount(ConnectionDirection flags) const
return nNum;
}

std::map<CNetAddr, LocalServiceInfo> CConnman::getNetLocalAddresses() const
{
LOCK(g_maplocalhost_mutex);
return mapLocalHost;
}

size_t CConnman::GetMaxOutboundNodeCount()
{
return m_max_outbound;
}

size_t CConnman::GetMaxOutboundOnionNodeCount()
{
return m_max_outbound_onion;
Expand Down
1 change: 1 addition & 0 deletions src/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -1489,6 +1489,7 @@ friend class CNode;
void AddPendingProbeConnections(const std::set<uint256>& proTxHashes);

size_t GetNodeCount(ConnectionDirection) const;
std::map<CNetAddr, LocalServiceInfo> getNetLocalAddresses() const;
Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Align method name with project style (PascalCase) and add noexcept/[[nodiscard]].

CConnman methods use PascalCase (e.g., GetNodeCount). Rename for consistency and add noexcept/[[nodiscard]] since this is a const accessor returning a copy.

Apply this diff:

-    std::map<CNetAddr, LocalServiceInfo> getNetLocalAddresses() const;
+    [[nodiscard]] std::map<CNetAddr, LocalServiceInfo> GetNetLocalAddresses() const noexcept;

Then update definition and call sites. To locate them:


🏁 Script executed:

#!/bin/bash
# Update/verify implementation and uses
rg -n 'getNetLocalAddresses\s*\(' -g 'src/**'
rg -n 'GetNetLocalAddresses\s*\(' -g 'src/**'

Length of output: 952


Rename getNetLocalAddresses to GetNetLocalAddresses and add [[nodiscard]] noexcept
Aligns with CConnman’s PascalCase convention and marks the accessor as non-throwing and its return value as used.

  • Update declaration in src/net.h (l. 1492):
    -    std::map<CNetAddr, LocalServiceInfo> getNetLocalAddresses() const;
    +    [[nodiscard]] std::map<CNetAddr, LocalServiceInfo> GetNetLocalAddresses() const noexcept;
  • Update definition in src/net.cpp (l. 4452): rename to CConnman::GetNetLocalAddresses() and add noexcept.
  • Update override in src/node/interfaces.cpp (ll. 534–537) and virtual declaration in src/interfaces/node.h (l. 246).
  • Update ClientModel in src/qt/clientmodel.h (l. 75) and src/qt/clientmodel.cpp (ll. 160–162).
  • Update call site in src/qt/rpcconsole.cpp (l. 1050).
  • Rename all remaining calls from getNetLocalAddresses() to GetNetLocalAddresses().
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
std::map<CNetAddr, LocalServiceInfo> getNetLocalAddresses() const;
[[nodiscard]] std::map<CNetAddr, LocalServiceInfo> GetNetLocalAddresses() const noexcept;
🤖 Prompt for AI Agents
In src/net.h around line 1492, rename the accessor declaration from
getNetLocalAddresses to GetNetLocalAddresses and annotate it with [[nodiscard]]
and noexcept; then update the corresponding definition in src/net.cpp around
line 4452 to CConnman::GetNetLocalAddresses() and add noexcept, update the
virtual declaration in src/interfaces/node.h at line 246 and the override in
src/node/interfaces.cpp (lines ~534–537) to match the new name and noexcept,
update ClientModel declaration/definition in src/qt/clientmodel.h (line ~75) and
src/qt/clientmodel.cpp (lines ~160–162), update the call site in
src/qt/rpcconsole.cpp (line ~1050), and perform a project-wide replacement of
all remaining calls from getNetLocalAddresses() to GetNetLocalAddresses();
ensure signatures (including const, return type) remain identical except for the
name and added [[nodiscard]] noexcept, and rebuild to catch any missed
references.

size_t GetMaxOutboundNodeCount();
size_t GetMaxOutboundOnionNodeCount();
void GetNodeStats(std::vector<CNodeStats>& vstats) const;
Expand Down
8 changes: 8 additions & 0 deletions src/node/interfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,7 @@ class NodeImpl : public Node
int64_t getTotalBytesSent() override { return m_context->connman ? m_context->connman->GetTotalBytesSent() : 0; }
size_t getMempoolSize() override { return m_context->mempool ? m_context->mempool->size() : 0; }
size_t getMempoolDynamicUsage() override { return m_context->mempool ? m_context->mempool->DynamicMemoryUsage() : 0; }
size_t getMempoolMaxUsage() override { return gArgs.GetIntArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000; }
bool getHeaderTip(int& height, int64_t& block_time) override
{
LOCK(::cs_main);
Expand All @@ -530,6 +531,13 @@ class NodeImpl : public Node
}
return false;
}
std::map<CNetAddr, LocalServiceInfo> getNetLocalAddresses() override
{
if (m_context->connman)
return m_context->connman->getNetLocalAddresses();
else
return {};
}
int getNumBlocks() override
{
LOCK(::cs_main);
Expand Down
33 changes: 17 additions & 16 deletions src/qt/bitcoingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include <qt/walletview.h>
#endif // ENABLE_WALLET

#ifdef Q_OS_MAC
#ifdef Q_OS_MACOS
#include <qt/macdockiconhandler.h>
#endif

Expand Down Expand Up @@ -74,7 +74,7 @@


const std::string BitcoinGUI::DEFAULT_UIPLATFORM =
#if defined(Q_OS_MAC)
#if defined(Q_OS_MACOS)
"macosx"
#elif defined(Q_OS_WIN)
"windows"
Expand Down Expand Up @@ -228,7 +228,7 @@ BitcoinGUI::BitcoinGUI(interfaces::Node& node, const NetworkStyle* networkStyle,
connect(labelBlocksIcon, &GUIUtil::ClickableLabel::clicked, this, &BitcoinGUI::showModalOverlay);
connect(progressBar, &GUIUtil::ClickableProgressBar::clicked, this, &BitcoinGUI::showModalOverlay);

#ifdef Q_OS_MAC
#ifdef Q_OS_MACOS
m_app_nap_inhibitor = new CAppNapInhibitor;
#endif

Expand Down Expand Up @@ -261,7 +261,7 @@ BitcoinGUI::~BitcoinGUI()
settings.setValue("MainWindowGeometry", saveGeometry());
if(trayIcon) // Hide tray icon, as deleting will let it linger until quit (on Ubuntu)
trayIcon->hide();
#ifdef Q_OS_MAC
#ifdef Q_OS_MACOS
delete m_app_nap_inhibitor;
MacDockIconHandler::cleanup();
#endif
Expand Down Expand Up @@ -643,7 +643,7 @@ void BitcoinGUI::createMenuBar()
minimize_action->setEnabled(window != nullptr && (window->flags() & Qt::Dialog) != Qt::Dialog && window->windowState() != Qt::WindowMinimized);
});

#ifdef Q_OS_MAC
#ifdef Q_OS_MACOS
QAction* zoom_action = window_menu->addAction(tr("Zoom"));
connect(zoom_action, &QAction::triggered, [] {
QWindow* window = qApp->focusWindow();
Expand All @@ -660,7 +660,7 @@ void BitcoinGUI::createMenuBar()
#endif

if (walletFrame) {
#ifdef Q_OS_MAC
#ifdef Q_OS_MACOS
window_menu->addSeparator();
QAction* main_window_action = window_menu->addAction(tr("Main Window"));
connect(main_window_action, &QAction::triggered, [this] {
Expand Down Expand Up @@ -818,7 +818,7 @@ void BitcoinGUI::setClientModel(ClientModel *_clientModel, interfaces::BlockAndH
trayIcon->setContextMenu(trayIconMenu.get());
createIconMenu(trayIconMenu.get());

#ifndef Q_OS_MAC
#ifndef Q_OS_MACOS
// Show main window on tray icon click
// Note: ignore this on Mac - this is not the way tray should work there
connect(trayIcon, &QSystemTrayIcon::activated, [this](QSystemTrayIcon::ActivationReason reason) {
Expand Down Expand Up @@ -904,7 +904,7 @@ void BitcoinGUI::setClientModel(ClientModel *_clientModel, interfaces::BlockAndH
#endif // ENABLE_WALLET
unitDisplayControl->setOptionsModel(nullptr);

#ifdef Q_OS_MAC
#ifdef Q_OS_MACOS
if(dockIconMenu)
{
// Disable context menu on dock icon
Expand Down Expand Up @@ -1070,11 +1070,11 @@ void BitcoinGUI::createIconMenu(QMenu *pmenu)
{
// Configuration of the tray icon (or dock icon) icon menu
QAction* show_hide_action{nullptr};
#ifndef Q_OS_MAC
#ifndef Q_OS_MACOS
// Note: On macOS, the Dock icon is used to provide the tray's functionality.
show_hide_action = pmenu->addAction(QString(), this, &BitcoinGUI::toggleHidden);
pmenu->addSeparator();
#endif // Q_OS_MAC
#endif // Q_OS_MACOS

QAction* send_action{nullptr};
QAction* cj_send_action{nullptr};
Expand Down Expand Up @@ -1107,11 +1107,11 @@ void BitcoinGUI::createIconMenu(QMenu *pmenu)
backups_action = pmenu->addAction(showBackupsAction->text(), showBackupsAction, &QAction::trigger);
}
QAction* quit_action{nullptr};
#ifndef Q_OS_MAC
#ifndef Q_OS_MACOS
// Note: On macOS, the Dock icon's menu already has Quit action.
pmenu->addSeparator();
quit_action = pmenu->addAction(quitAction->text(), quitAction, &QAction::trigger);
#endif // Q_OS_MAC
#endif // Q_OS_MACOS

connect(
// Using QSystemTrayIcon::Context is not reliable.
Expand Down Expand Up @@ -1416,6 +1416,7 @@ void BitcoinGUI::openOptionsDialogWithTab(OptionsDialog::Tab tab)
auto dlg = new OptionsDialog(this, enableWallet);
connect(dlg, &OptionsDialog::quitOnReset, this, &BitcoinGUI::quitRequested);
dlg->setCurrentTab(tab);
dlg->setClientModel(clientModel);
dlg->setModel(clientModel->getOptionsModel());
connect(dlg, &OptionsDialog::appearanceChanged, [this]() {
updateWidth();
Expand Down Expand Up @@ -1489,7 +1490,7 @@ void BitcoinGUI::updateWidth()

void BitcoinGUI::setNumBlocks(int count, const QDateTime& blockDate, const QString& blockHash, double nVerificationProgress, bool header, SynchronizationState sync_state)
{
#ifdef Q_OS_MAC
#ifdef Q_OS_MACOS
// Disabling macOS App Nap on initial sync, disk, reindex operations and mixing.
bool disableAppNap = !m_node.masternodeSync().isSynced() || sync_state != SynchronizationState::POST_INIT;
#ifdef ENABLE_WALLET
Expand All @@ -1504,7 +1505,7 @@ void BitcoinGUI::setNumBlocks(int count, const QDateTime& blockDate, const QStri
} else {
m_app_nap_inhibitor->enableAppNap();
}
#endif // Q_OS_MAC
#endif // Q_OS_MACOS

if (modalOverlay)
{
Expand Down Expand Up @@ -1719,7 +1720,7 @@ void BitcoinGUI::message(const QString& title, QString message, unsigned int sty
void BitcoinGUI::changeEvent(QEvent *e)
{
QMainWindow::changeEvent(e);
#ifndef Q_OS_MAC // Ignored on macOS
#ifndef Q_OS_MACOS // Ignored on macOS
if(e->type() == QEvent::WindowStateChange)
{
if(clientModel && clientModel->getOptionsModel() && clientModel->getOptionsModel()->getMinimizeToTray())
Expand Down Expand Up @@ -1753,7 +1754,7 @@ void BitcoinGUI::changeEvent(QEvent *e)

void BitcoinGUI::closeEvent(QCloseEvent *event)
{
#ifndef Q_OS_MAC // Ignored on macOS
#ifndef Q_OS_MACOS // Ignored on macOS
if(clientModel && clientModel->getOptionsModel())
{
if(!clientModel->getOptionsModel()->getMinimizeOnClose())
Expand Down
4 changes: 2 additions & 2 deletions src/qt/bitcoingui.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

#include <memory>

#ifdef Q_OS_MAC
#ifdef Q_OS_MACOS
#include <qt/macos_appnap.h>
#endif

Expand Down Expand Up @@ -193,7 +193,7 @@ class BitcoinGUI : public QMainWindow

QMenu* m_network_context_menu = new QMenu(this);

#ifdef Q_OS_MAC
#ifdef Q_OS_MACOS
CAppNapInhibitor* m_app_nap_inhibitor = nullptr;
#endif

Expand Down
7 changes: 6 additions & 1 deletion src/qt/clientmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ ClientModel::ClientModel(interfaces::Node& node, OptionsModel *_optionsModel, QO
connect(timer, &QTimer::timeout, [this] {
// no locking required at this point
// the following calls will acquire the required lock
Q_EMIT mempoolSizeChanged(m_node.getMempoolSize(), m_node.getMempoolDynamicUsage());
Q_EMIT mempoolSizeChanged(m_node.getMempoolSize(), m_node.getMempoolDynamicUsage(), m_node.getMempoolMaxUsage());
Q_EMIT islockCountChanged(m_node.llmq().getInstantSentLockCount());
});
connect(m_thread, &QThread::finished, timer, &QObject::deleteLater);
Expand Down Expand Up @@ -157,6 +157,11 @@ void ClientModel::getAllGovernanceObjects(std::vector<CGovernanceObject> &obj)
m_node.gov().getAllNewerThan(obj, 0);
}

std::map<CNetAddr, LocalServiceInfo> ClientModel::getNetLocalAddresses() const
{
return m_node.getNetLocalAddresses();
}

int ClientModel::getNumBlocks() const
{
if (m_cached_num_blocks == -1) {
Expand Down
6 changes: 5 additions & 1 deletion src/qt/clientmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@
#include <memory>
#include <uint256.h>

#include <netaddress.h>

class BanTableModel;
class CBlockIndex;
class OptionsModel;
class PeerTableModel;
class PeerTableSortProxy;
enum class SynchronizationState;
struct LocalServiceInfo;

namespace interfaces {
struct BlockTip;
Expand Down Expand Up @@ -69,6 +72,7 @@ class ClientModel : public QObject

//! Return number of connections, default is in- and outbound (total)
int getNumConnections(unsigned int flags = CONNECTIONS_ALL) const;
std::map<CNetAddr, LocalServiceInfo> getNetLocalAddresses() const;
int getNumBlocks() const;
uint256 getBestBlockHash() EXCLUSIVE_LOCKS_REQUIRED(!m_cached_tip_mutex);
int getHeaderTipHeight() const;
Expand Down Expand Up @@ -130,7 +134,7 @@ class ClientModel : public QObject
void chainLockChanged(const QString& bestChainLockHash, int bestChainLockHeight);
void numBlocksChanged(int count, const QDateTime& blockDate, const QString& blockHash, double nVerificationProgress, bool header, SynchronizationState sync_state);
void additionalDataSyncProgressChanged(double nSyncProgress);
void mempoolSizeChanged(long count, size_t mempoolSizeInBytes);
void mempoolSizeChanged(long count, size_t mempoolSizeInBytes, size_t mempoolMaxSizeInBytes);
void islockCountChanged(size_t count);
void networkActiveChanged(bool networkActive);
void alertsChanged(const QString &warnings);
Expand Down
Loading
Loading