Qt: Network Watch tool #9849

pull luke-jr wants to merge 2 commits into bitcoin:master from luke-jr:gui_netwatch changing 9 files +1109 −0
  1. luke-jr commented at 4:01 AM on February 24, 2017: member

    Simple realtime log of p2p network activity (blocks and transactions only)

    • Doesn't begin logging until opened; limited to 0x400 entries (outputs)
    • Automatically scrolls if left at the bottom of the log; maintains position if left elsewhere
    • Memory-efficient circular buffer; CTransaction references become weak after they're 0x200 entries back in the log
    • Search function that selects all matching log entries, including ongoing
  2. fanquake added the label GUI on Feb 24, 2017
  3. luke-jr force-pushed on Feb 24, 2017
  4. in src/qt/netwatch.cpp:None in 563ec9e947 outdated
     547 | +        assert(!logpos);
     548 | +        log.push_back(le);
     549 | +    }
     550 | +    ++rows_used;
     551 | +    if (rows_used > max_nonweak_txouts) {
     552 | +        LogEntry& le = getLogEntryRow(rows_used - max_nonweak_txouts - 1);
    


    paveljanik commented at 7:19 AM on February 24, 2017:

    le is the same name as the first argument here, it will bring shadow warning.

  5. paveljanik commented at 7:24 AM on February 24, 2017: contributor

    This is how it looks like here on testnet:

    <img width="1167" alt="screen shot 2017-02-24 at 08 22 39" src="https://cloud.githubusercontent.com/assets/6848764/23294190/86f5186e-fa6a-11e6-83bd-dfa5811b8b68.png">

  6. jonasschnelli commented at 7:30 AM on February 24, 2017: contributor

    Thanks. Will review. I just played a bit with it and had massive locking issues on mainnet during catch-up of 2-3 weeks.

  7. luke-jr force-pushed on Feb 24, 2017
  8. luke-jr force-pushed on Feb 24, 2017
  9. jonasschnelli commented at 3:26 PM on March 17, 2017: contributor

    Running this PR (built over gitian: https://bitcoin.jonasschnelli.ch/build/54) makes Bitcoin-Qt and also the rest of my apps almost unusable. Had to force kill the process.

  10. in src/qt/netwatch.cpp:649 in 9019229f08 outdated
     614 | +}
     615 | +
     616 | +void NetWatchLogModel::LogBlock(const CBlockIndex* pblockindex)
     617 | +{
     618 | +    CBlock block;
     619 | +    if (!ReadBlockFromDisk(block, pblockindex, Params().GetConsensus())) {
    


    jonasschnelli commented at 3:29 PM on March 17, 2017:

    IMO reading each block will cause a massive slow down during IBD / catchup.


    luke-jr commented at 10:49 PM on March 17, 2017:

    The OS should have the data cached already?

  11. in src/qt/netwatch.cpp:653 in 9019229f08 outdated
     618 | +    CBlock block;
     619 | +    if (!ReadBlockFromDisk(block, pblockindex, Params().GetConsensus())) {
     620 | +        // Indicate error somehow?
     621 | +        return;
     622 | +    }
     623 | +    assert(block.vtx.size());
    


    jonasschnelli commented at 3:30 PM on March 17, 2017:

    What we probably should do is adding each blocks size and vtx.size() to CBlockIndex* (would require to alter the block index, migration, etc. yes).


    luke-jr commented at 10:50 PM on March 17, 2017:

    That wouldn't change anything here...?

  12. luke-jr force-pushed on Aug 25, 2017
  13. luke-jr force-pushed on Aug 25, 2017
  14. luke-jr force-pushed on Mar 6, 2018
  15. laanwj commented at 10:54 PM on March 6, 2018: member

    Concept ACK, I like having this, though we have to be sure that there is no performance impact when the monitor is not running, and as little as possible when it is.

  16. luke-jr commented at 2:46 AM on March 7, 2018: member

    The code is (already) disabled until the first time it is opened.

  17. MarcoFalke added the label Needs rebase on Jun 6, 2018
  18. luke-jr force-pushed on Oct 30, 2018
  19. MarcoFalke removed the label Needs rebase on Oct 30, 2018
  20. DrahtBot added the label Needs rebase on Oct 30, 2018
  21. luke-jr force-pushed on Oct 30, 2018
  22. luke-jr commented at 8:13 PM on October 30, 2018: member

    Oops, had rebased onto 0.17 instead of master. Rebased for real this time.

  23. in src/qt/netwatch.cpp:681 in ae96c0d678 outdated
     676 | +    if (clientModel) {
     677 | +        disconnect(clientModel->getOptionsModel(), SIGNAL(displayUnitChanged(int)), this, SLOT(updateDisplayUnit()));
     678 | +    }
     679 | +    clientModel = model;
     680 | +    if (model) {
     681 | +        connect(model->getOptionsModel(), SIGNAL(displayUnitChanged(int)), this, SLOT(updateDisplayUnit()));
    


    MarcoFalke commented at 8:35 PM on October 30, 2018:

    Might want to use the new connect syntax in this file?


    luke-jr commented at 10:28 PM on October 30, 2018:

    Let me know if I got it right...

  24. DrahtBot removed the label Needs rebase on Oct 30, 2018
  25. luke-jr force-pushed on Oct 30, 2018
  26. in src/qt/bitcoingui.cpp:767 in e8ca94c4dc outdated
     683 | +        NetWatch->setClientModel(clientModel);
     684 | +    }
     685 | +    NetWatch->showNormal();
     686 | +    NetWatch->show();
     687 | +    NetWatch->raise();
     688 | +    NetWatch->activateWindow();
    


    promag commented at 11:27 PM on October 30, 2018:

    Could rebase with #14123 to replace these calls with GUIUtil::bringToFront.

  27. in src/qt/bitcoingui.cpp:78 in e8ca94c4dc outdated
      73 | @@ -73,7 +74,8 @@ const std::string BitcoinGUI::DEFAULT_UIPLATFORM =
      74 |  BitcoinGUI::BitcoinGUI(interfaces::Node& node, const PlatformStyle *_platformStyle, const NetworkStyle *networkStyle, QWidget *parent) :
      75 |      QMainWindow(parent),
      76 |      m_node(node),
      77 | -    platformStyle(_platformStyle)
      78 | +    platformStyle(_platformStyle),
      79 | +    netStyle(networkStyle)
    


    promag commented at 11:30 PM on October 30, 2018:

    Remove.


    luke-jr commented at 12:11 AM on October 31, 2018:

    It's needed...


    promag commented at 1:32 PM on October 31, 2018:

    Sorry, forgot to delete this comment while reviewing..

  28. in src/qt/netwatch.h:1 in e8ca94c4dc outdated
       0 | @@ -0,0 +1,228 @@
       1 | +// Copyright (c) 2017 The Bitcoin Core developers
    


    promag commented at 11:31 PM on October 30, 2018:

    nit 2018.


    luke-jr commented at 12:11 AM on October 31, 2018:

    2018 is wrong. This code hasn't been substantially changed since 2017.

  29. in src/qt/netwatch.h:25 in e8ca94c4dc outdated
      21 | +class CBlock;
      22 | +class CBlockIndex;
      23 | +class ClientModel;
      24 | +class LogEntry;
      25 | +class PlatformStyle;
      26 | +class NetworkStyle;
    


    promag commented at 11:32 PM on October 30, 2018:

    nit, sort.

  30. in src/qt/netwatch.h:28 in e8ca94c4dc outdated
      23 | +class ClientModel;
      24 | +class LogEntry;
      25 | +class PlatformStyle;
      26 | +class NetworkStyle;
      27 | +
      28 | +static const int nLongestAddress = 35;
    


    promag commented at 11:33 PM on October 30, 2018:

    move to .cpp? nit, follow code convention.

  31. in src/qt/bitcoingui.cpp:407 in e8ca94c4dc outdated
     403 | @@ -397,6 +404,7 @@ void BitcoinGUI::createMenuBar()
     404 |      settings->addAction(optionsAction);
     405 |  
     406 |      QMenu *help = appMenuBar->addMenu(tr("&Help"));
     407 | +    help->addAction(NetWatchAction);
    


    promag commented at 11:37 PM on October 30, 2018:

    FYI in #14573 I'm proposing a Window menu.

  32. in src/qt/bitcoingui.h:131 in e8ca94c4dc outdated
     127 | @@ -127,6 +128,7 @@ class BitcoinGUI : public QMainWindow
     128 |      QAction* backupWalletAction = nullptr;
     129 |      QAction* changePassphraseAction = nullptr;
     130 |      QAction* aboutQtAction = nullptr;
     131 | +    QAction* NetWatchAction = nullptr;
    


    promag commented at 11:45 PM on October 30, 2018:

    nit, m_show_netwatch_action.

  33. in src/qt/netwatch.cpp:76 in e8ca94c4dc outdated
      71 | +        ++count;
      72 | +    }
      73 | +    return NULL;
      74 | +}
      75 | +
      76 | +}
    


    promag commented at 11:46 PM on October 30, 2018:

    nit, } // namespace

  34. in src/qt/netwatch.cpp:78 in e8ca94c4dc outdated
      73 | +    return NULL;
      74 | +}
      75 | +
      76 | +}
      77 | +
      78 | +const QString LogEntry::LogEntryTypeAbbreviation(const LogEntryType LET)
    


    promag commented at 11:48 PM on October 30, 2018:

    nit, s/LET/log_entry_type.

  35. in src/qt/netwatch.cpp:52 in e8ca94c4dc outdated
      47 | +}
      48 | +
      49 | +size_t CountNonDatacarrierOutputs(const CTransactionRef& tx)
      50 | +{
      51 | +    size_t count = 0;
      52 | +    for (auto& txout : tx->vout) {
    


    promag commented at 11:48 PM on October 30, 2018:

    const?

  36. in src/qt/netwatch.cpp:53 in e8ca94c4dc outdated
      48 | +
      49 | +size_t CountNonDatacarrierOutputs(const CTransactionRef& tx)
      50 | +{
      51 | +    size_t count = 0;
      52 | +    for (auto& txout : tx->vout) {
      53 | +        if (IsDatacarrier(txout)) {
    


    promag commented at 11:48 PM on October 30, 2018:

    nit, one line if (...) continue;

  37. in src/qt/netwatch.cpp:65 in e8ca94c4dc outdated
      60 | +
      61 | +const CTxOut* GetNonDatacarrierOutput(const CTransactionRef& tx, const size_t txout_index)
      62 | +{
      63 | +    size_t count = 0;
      64 | +    for (auto& txout : tx->vout) {
      65 | +        if (IsDatacarrier(txout)) {
    


    promag commented at 11:49 PM on October 30, 2018:

    Same as above.

  38. in src/qt/netwatch.cpp:64 in e8ca94c4dc outdated
      63 | +    size_t count = 0;
      64 | +    for (auto& txout : tx->vout) {
      65 | +        if (IsDatacarrier(txout)) {
      66 | +            continue;
      67 | +        }
      68 | +        if (count == txout_index) {
    


    promag commented at 11:49 PM on October 30, 2018:

    Same as above.


    luke-jr commented at 3:38 AM on October 31, 2018:

    IMO this one is clearer split out.

  39. in src/qt/netwatch.cpp:73 in e8ca94c4dc outdated
      68 | +        if (count == txout_index) {
      69 | +            return &txout;
      70 | +        }
      71 | +        ++count;
      72 | +    }
      73 | +    return NULL;
    


    promag commented at 11:50 PM on October 30, 2018:

    nullptr.

  40. in src/qt/netwatch.cpp:1 in e8ca94c4dc outdated
       0 | @@ -0,0 +1,838 @@
       1 | +// Copyright (c) 2017 The Bitcoin Core developers
    


    promag commented at 11:50 PM on October 30, 2018:

    nit, 2018

  41. promag commented at 11:59 PM on October 30, 2018: member

    Concept ACK.

    Code style is a bit outdated.

  42. in src/qt/netwatch.cpp:261 in e8ca94c4dc outdated
     260 | +    CTransactionWeakref * const ptx_new = get<CTransactionWeakref>();
     261 | +    new (ptx_new) CTransactionWeakref(tx);
     262 | +    *((meta_t*)data) |= (3 << 30);
     263 | +}
     264 | +
     265 | +class NetWatchValidationInterface final : public CValidationInterface {
    


    promag commented at 12:00 AM on October 31, 2018:

    Should use/extend interfaces::Node instead?

  43. luke-jr force-pushed on Oct 31, 2018
  44. DrahtBot commented at 3:44 AM on October 31, 2018: member

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #16612 (qt: Remove menu icons by laanwj)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  45. in src/qt/netwatch.h:80 in 56bd9fdfc0 outdated
      75 | +        LET_TX,
      76 | +    };
      77 | +    static const QString LogEntryTypeAbbreviation(LogEntryType);
      78 | +
      79 | +    LogEntry(const LogEntry&);
      80 | +    LogEntry() : data(NULL) { }
    


    practicalswift commented at 11:39 AM on October 31, 2018:

    Use nullptr instead of NULL. Applies throughout this PR :-)

  46. in src/qt/netwatch.cpp:17 in 56bd9fdfc0 outdated
      12 | +#include <qt/clientmodel.h>
      13 | +#include <qt/guiconstants.h>
      14 | +#include <qt/guiutil.h>
      15 | +#include <qt/optionsmodel.h>
      16 | +#include <qt/platformstyle.h>
      17 | +#include <qt/networkstyle.h>
    


    practicalswift commented at 2:07 PM on October 31, 2018:

    Nit: Sort includes :-)

  47. in src/qt/netwatch.h:119 in 56bd9fdfc0 outdated
     114 | +    bool fCheckType;
     115 | +    bool fCheckId;
     116 | +    bool fCheckAddr;
     117 | +    bool fCheckValue;
     118 | +
     119 | +    NetWatchLogSearch(const QString& query, int displayunit);
    


    practicalswift commented at 2:08 PM on October 31, 2018:

    Nit: Make parameter names match between declaration and definition.

  48. in src/qt/netwatch.cpp:266 in 56bd9fdfc0 outdated
     261 | +class NetWatchValidationInterface final : public CValidationInterface {
     262 | +private:
     263 | +    NetWatchLogModel& model;
     264 | +
     265 | +public:
     266 | +    NetWatchValidationInterface(NetWatchLogModel& model_in) : model(model_in) {}
    


    practicalswift commented at 2:10 PM on October 31, 2018:

    Should be explicit? :-)

  49. in src/qt/netwatch.cpp:343 in 56bd9fdfc0 outdated
     338 | +            CBlock block;
     339 | +            if (!ReadBlockFromDisk(block, &blockindex, Params().GetConsensus())) {
     340 | +                // Indicate error somehow?
     341 | +                return QVariant();
     342 | +            }
     343 | +            assert(block.vtx.size());
    


    practicalswift commented at 2:13 PM on October 31, 2018:

    Nit: !block.vtx.empty() communicates intention more clearly than block.vtx.size()?


    luke-jr commented at 7:08 PM on October 31, 2018:

    Not sure. The intent is only to make sure vtx[0] below is an acceptable dereference.

    The actual check for block data is above, with if (blockindex.nTx == 0 || !(blockindex.nStatus & BLOCK_HAVE_DATA))


    practicalswift commented at 7:31 PM on October 31, 2018:

    I see -- makes sense :-)

  50. in src/qt/netwatch.cpp:546 in 56bd9fdfc0 outdated
     541 | +void NetWatchLogModel::searchRows(const QString& query, QList<int>& results)
     542 | +{
     543 | +    const auto currentUnit = clientModel->getOptionsModel()->getDisplayUnit();
     544 | +    NetWatchLogSearch *newsearch = new NetWatchLogSearch(query, currentUnit);
     545 | +    LOCK(cs);
     546 | +    if (currentSearch) {
    


    practicalswift commented at 2:16 PM on October 31, 2018:

    This if statement is unnecessary. Deleting a null pointer is a noop.

  51. in src/qt/netwatch.h:160 in 56bd9fdfc0 outdated
     155 | +        NWLMH_ID,
     156 | +        NWLMH_ADDR,
     157 | +        NWLMH_VALUE,
     158 | +    };
     159 | +
     160 | +    NetWatchLogModel(QWidget *parent);
    


    practicalswift commented at 2:18 PM on October 31, 2018:

    Should be made explicit?

  52. in src/qt/netwatch.cpp:278 in 56bd9fdfc0 outdated
     273 | +void NetWatchValidationInterface::ValidationInterfaceUnregistering()
     274 | +{
     275 | +    model.OrphanedValidationInterface();
     276 | +}
     277 | +
     278 | +void NetWatchValidationInterface::UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload)
    


    practicalswift commented at 2:19 PM on October 31, 2018:

    Should be marked override?


    luke-jr commented at 7:26 PM on October 31, 2018:
    qt/netwatch.cpp:273:70: error: virt-specifiers in ‘ValidationInterfaceUnregistering’ not allowed outside a class definition
    

    Adding it to only the class def instead...


    practicalswift commented at 7:33 PM on October 31, 2018:

    Sounds good. I commented on the wrong line :-)

  53. in src/qt/netwatch.h:56 in 56bd9fdfc0 outdated
      51 | +        offset = size_t(p);
      52 | +        return offset + sizeof(T);
      53 | +    }
      54 | +
      55 | +    // std::align (missing in at least GCC 4.9) substitute from c-plus
      56 | +    static inline void *align( std::size_t alignment, std::size_t size, void *&ptr, std::size_t &space ) {
    


    practicalswift commented at 2:21 PM on October 31, 2018:

    Remove extra spaces after ( and before ) :-)

  54. in src/qt/netwatch.cpp:577 in 654f66d9e0 outdated
     572 | +        // Replace a deleted row
     573 | +        getLogEntryRow(rows_used) = le;
     574 | +        --m_logskip;
     575 | +    } else {
     576 | +        // Haven't filled up yet, so just push_back
     577 | +        assert(!m_logpos);
    


    ken2812221 commented at 1:17 PM on November 3, 2018:

    I see this assertion on Windows in testing, haven't take a look at the code.

    image


    luke-jr commented at 5:51 PM on February 12, 2019:

    Any idea how?>

  55. in src/qt/bitcoingui.cpp:407 in 654f66d9e0 outdated
     403 | @@ -397,6 +404,7 @@ void BitcoinGUI::createMenuBar()
     404 |      settings->addAction(optionsAction);
     405 |  
     406 |      QMenu *help = appMenuBar->addMenu(tr("&Help"));
     407 | +    help->addAction(m_show_netwatch_action);
    


    promag commented at 11:23 PM on November 30, 2018:

    This could go to window menu, which is added in #14573.

  56. DrahtBot added the label Needs rebase on Dec 16, 2018
  57. CValidationInterface: ValidationInterfaceUnregistering, called when being unregistered 9800d9d761
  58. luke-jr force-pushed on Feb 12, 2019
  59. Qt: Network Watch tool
    Simple realtime log of p2p network activity (blocks and transactions only)
    
    - Doesn't begin logging until opened; limited to 0x400 entries (outputs)
    - Automatically scrolls if left at the bottom of the log; maintains position if left elsewhere
    - Memory-efficient circular buffer; CTransaction references become weak after they're 0x200 entries back in the log
    - Search function that selects all matching log entries, including ongoing
    ba6074b561
  60. luke-jr force-pushed on Feb 12, 2019
  61. DrahtBot removed the label Needs rebase on Feb 12, 2019
  62. in src/qt/netwatch.cpp:258 in ba6074b561
     253 | +    CTransactionRef * const ptx_old = get<CTransactionRef>();
     254 | +    CTransactionRef tx = *ptx_old;  // save a copy
     255 | +    ptx_old->~CTransactionRef();
     256 | +    CTransactionWeakref * const ptx_new = get<CTransactionWeakref>();
     257 | +    new (ptx_new) CTransactionWeakref(tx);
     258 | +    *((meta_t*)m_data) |= (3 << 30);
    


    practicalswift commented at 11:00 AM on February 13, 2019:

    Shift overflow?

  63. DrahtBot commented at 7:41 AM on August 16, 2019: member

    <!--cf906140f33d8803c4a75a2196329ecb-->Needs rebase

  64. DrahtBot added the label Needs rebase on Aug 16, 2019
  65. laanwj commented at 11:53 AM on September 30, 2019: member

    As this PR has been inactive for a long time, I'm closing this (but marking "up for grabs").

  66. laanwj added the label Up for grabs on Sep 30, 2019
  67. laanwj removed the label Needs rebase on Sep 30, 2019
  68. laanwj closed this on Sep 30, 2019

  69. MarcoFalke removed the label Up for grabs on Oct 5, 2021
  70. MarcoFalke commented at 2:30 PM on October 5, 2021: member
  71. DrahtBot locked this on Oct 30, 2022

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-14 15:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me