dash/test/lint/lint-circular-dependencies.sh
MarcoFalke 436a5783c7
Merge bitcoin/bitcoin#22736: log, sync: change lock contention from preprocessor directive to log category
7e698732836121912f179b7c743a72dd6fdffa72 sync: remove DEBUG_LOCKCONTENTION preprocessor directives (Jon Atack)
9b08006bc502e67956d6ab518388fad6397cac8d log, sync: improve lock contention logging and add time duration (Jon Atack)
3f4c6b87f1098436693c4990f2082515ec0ece26 log, timer: add timing macro in usec LOG_TIME_MICROS_WITH_CATEGORY (Jon Atack)
b7a17444e0746c562ae97b26eba431577947b06a log, sync: add LOCK logging category, apply it to lock contention (Jon Atack)

Pull request description:

  To enable lock contention logging, `DEBUG_LOCKCONTENTION` has to be defined at compilation. Once built, the logging is not limited to a category and is high frequency, verbose and in all-caps. With these factors combined, it seems likely to be rarely used.

  This patch:
  - adds a `lock` logging category
  - adds a timing macro in microseconds, `LOG_TIME_MICROS_WITH_CATEGORY`
  - updates `BCLog::LogMsg()` to omit irrelevant decimals for microseconds and skip unneeded code and math
  - improves the lock contention logging, drops the all-caps, and displays the duration in microseconds
  - removes the conditional compilation directives
  - allows lock contentions to be logged on startup with `-debug=lock` or at run time with `bitcoin-cli logging '["lock"]'`

  ```
  $ bitcoind -signet -debug=lock
  2021-09-01T12:40:01Z LockContention: cs_vNodes, net.cpp:1920 started
  2021-09-01T12:40:01Z LockContention: cs_vNodes, net.cpp:1920 completed (4μs)
  2021-09-01T12:40:01Z LockContention: cs_vNodes, net.cpp:1302 started
  2021-09-01T12:40:01Z LockContention: cs_vNodes, net.cpp:1302 completed (4μs)
  2021-09-01T12:40:02Z LockContention: cs_vNodes, net.cpp:2242 started
  2021-09-01T12:40:02Z LockContention: cs_vNodes, net.cpp:2242 completed (20μs)
  2021-09-01T12:43:04Z LockContention: ::cs_main, validation.cpp:4980 started
  2021-09-01T12:43:04Z LockContention: ::cs_main, validation.cpp:4980 completed (3μs)

  $ bitcoin-cli -signet logging
    "lock": true,

  $ bitcoin-cli -signet logging [] '["lock"]'
    "lock": false,

  $ bitcoin-cli -signet logging '["lock"]'
    "lock": true,
  ```

  I've tested this with Clang 13 and GCC 10.2.1, on Debian, with and without `--enable-debug`.

ACKs for top commit:
  hebasto:
    re-ACK 7e698732836121912f179b7c743a72dd6fdffa72, added a contention duration to the log message since my [previous](https://github.com/bitcoin/bitcoin/pull/22736#pullrequestreview-743764606) review.
  theStack:
    re-ACK 7e698732836121912f179b7c743a72dd6fdffa72 🔏 ⏲️

Tree-SHA512: c4b5eb88d3a2c051acaa842b3055ce30efde1f114f61da6e55fcaa27476c1c33a60bc419f7f5ccda532e1bdbe70815222ec2b2b6d9226f29c8e94e598aacfee7
2024-04-02 12:09:35 -05:00

144 lines
7.6 KiB
Bash
Executable File

#!/usr/bin/env bash
#
# Copyright (c) 2018-2020 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
#
# Check for circular dependencies
export LC_ALL=C
EXPECTED_CIRCULAR_DEPENDENCIES=(
"chainparamsbase -> util/system -> chainparamsbase"
"node/blockstorage -> validation -> node/blockstorage"
"index/blockfilterindex -> node/blockstorage -> validation -> index/blockfilterindex"
"index/base -> validation -> index/blockfilterindex -> index/base"
"index/coinstatsindex -> node/coinstats -> index/coinstatsindex"
"policy/fees -> txmempool -> policy/fees"
"qt/addresstablemodel -> qt/walletmodel -> qt/addresstablemodel"
"qt/bitcoingui -> qt/walletframe -> qt/bitcoingui"
"qt/recentrequeststablemodel -> qt/walletmodel -> qt/recentrequeststablemodel"
"qt/transactiontablemodel -> qt/walletmodel -> qt/transactiontablemodel"
"txmempool -> validation -> txmempool"
"wallet/fees -> wallet/wallet -> wallet/fees"
"wallet/wallet -> wallet/walletdb -> wallet/wallet"
"node/coinstats -> validation -> node/coinstats"
# Dash
"coinjoin/server -> core_io -> evo/assetlocktx -> llmq/signing -> net_processing -> coinjoin/server"
"coinjoin/coinjoin -> llmq/instantsend -> net_processing -> coinjoin/server -> coinjoin/coinjoin"
"dsnotificationinterface -> llmq/chainlocks -> node/blockstorage -> dsnotificationinterface"
"evo/cbtx -> evo/simplifiedmns -> evo/cbtx"
"evo/deterministicmns -> llmq/commitment -> evo/deterministicmns"
"evo/deterministicmns -> llmq/utils -> evo/deterministicmns"
"governance/classes -> governance/governance -> governance/classes"
"governance/governance -> governance/object -> governance/governance"
"governance/governance -> masternode/sync -> governance/governance"
"llmq/chainlocks -> llmq/instantsend -> llmq/chainlocks"
"llmq/chainlocks -> llmq/instantsend -> net_processing -> llmq/chainlocks"
"llmq/dkgsessionhandler -> net_processing -> llmq/dkgsessionmgr -> llmq/dkgsessionhandler"
"llmq/instantsend -> net_processing -> llmq/instantsend"
"llmq/instantsend -> txmempool -> llmq/instantsend"
"llmq/instantsend -> validation -> llmq/instantsend"
"llmq/signing -> llmq/signing_shares -> llmq/signing"
"llmq/signing -> net_processing -> llmq/signing"
"llmq/signing_shares -> net_processing -> llmq/signing_shares"
"logging -> util/system -> logging"
"masternode/payments -> validation -> masternode/payments"
"masternode/sync -> validation -> masternode/sync"
"net -> netmessagemaker -> net"
"netaddress -> netbase -> netaddress"
"qt/appearancewidget -> qt/guiutil -> qt/appearancewidget"
"qt/bitcoinaddressvalidator -> qt/guiutil -> qt/bitcoinaddressvalidator"
"qt/bitcoingui -> qt/guiutil -> qt/bitcoingui"
"qt/guiutil -> qt/optionsdialog -> qt/guiutil"
"qt/guiutil -> qt/qvalidatedlineedit -> qt/guiutil"
"core_io -> evo/cbtx -> evo/simplifiedmns -> core_io"
"core_io -> evo/assetlocktx -> llmq/signing -> net_processing -> governance/governance -> governance/object -> core_io"
"llmq/dkgsession -> llmq/dkgsessionmgr -> llmq/dkgsessionhandler -> llmq/dkgsession"
"logging -> util/system -> sync -> logging"
"logging -> util/system -> stacktraces -> logging"
"logging -> util/system -> util/getuniquepath -> random -> logging"
"coinjoin/context -> coinjoin/server -> core_io -> evo/assetlocktx -> llmq/signing -> net_processing -> coinjoin/context"
"qt/appearancewidget -> qt/guiutil -> qt/optionsdialog -> qt/appearancewidget"
"qt/guiutil -> qt/optionsdialog -> qt/optionsmodel -> qt/guiutil"
"bloom -> evo/assetlocktx -> llmq/quorums -> net -> bloom"
"bloom -> evo/assetlocktx -> llmq/signing -> net_processing -> governance/governance -> bloom"
"bloom -> evo/assetlocktx -> llmq/signing -> net_processing -> merkleblock -> bloom"
"banman -> bloom -> evo/assetlocktx -> llmq/quorums -> net -> banman"
"banman -> bloom -> evo/assetlocktx -> llmq/signing -> net_processing -> banman"
"coinjoin/client -> coinjoin/coinjoin -> llmq/instantsend -> net_processing -> coinjoin/client"
"coinjoin/client -> coinjoin/coinjoin -> llmq/instantsend -> net_processing -> coinjoin/context -> coinjoin/client"
"llmq/dkgsession -> llmq/dkgsessionmgr -> llmq/dkgsession"
"llmq/chainlocks -> validation -> llmq/chainlocks"
"coinjoin/coinjoin -> llmq/chainlocks -> net -> coinjoin/coinjoin"
"evo/deterministicmns -> llmq/utils -> llmq/snapshot -> evo/simplifiedmns -> evo/deterministicmns"
"evo/deterministicmns -> llmq/utils -> net -> evo/deterministicmns"
"policy/policy -> policy/settings -> policy/policy"
"evo/assetlocktx -> validation -> evo/specialtxman -> evo/assetlocktx"
"evo/cbtx -> validation -> evo/specialtxman -> evo/cbtx"
"evo/creditpool -> validation -> evo/specialtxman -> evo/creditpool"
"evo/deterministicmns -> validation -> evo/specialtxman -> evo/deterministicmns"
"evo/mnhftx -> validation -> evo/specialtxman -> evo/mnhftx"
"evo/specialtxman -> llmq/blockprocessor -> validation -> evo/specialtxman"
"consensus/tx_verify -> evo/assetlocktx -> validation -> consensus/tx_verify"
"consensus/tx_verify -> evo/assetlocktx -> llmq/signing -> net_processing -> txmempool -> consensus/tx_verify"
"evo/assetlocktx -> llmq/signing -> net_processing -> txmempool -> evo/assetlocktx"
"evo/simplifiedmns -> llmq/blockprocessor -> llmq/utils -> llmq/snapshot -> evo/simplifiedmns"
"llmq/blockprocessor -> llmq/utils -> llmq/snapshot -> llmq/blockprocessor"
"llmq/context -> llmq/instantsend -> net_processing -> llmq/context"
"llmq/commitment -> llmq/utils -> llmq/snapshot -> llmq/commitment"
"spork -> validation -> spork"
"governance/governance -> validation -> governance/governance"
"evo/deterministicmns -> validationinterface -> governance/vote -> evo/deterministicmns"
"governance/vote -> masternode/node -> validationinterface -> governance/vote"
"llmq/signing -> masternode/node -> validationinterface -> llmq/signing"
"evo/mnhftx -> validation -> evo/mnhftx"
"evo/deterministicmns -> validation -> evo/deterministicmns"
"evo/chainhelper -> masternode/payments -> validation -> evo/chainhelper"
"evo/deterministicmns -> validationinterface -> evo/deterministicmns"
"logging -> util/system -> sync -> logging/timer -> logging"
)
EXIT_CODE=0
CIRCULAR_DEPENDENCIES=()
IFS=$'\n'
for CIRC in $(cd src && ../contrib/devtools/circular-dependencies.py {*,*/*,*/*/*}.{h,cpp} | sed -e 's/^Circular dependency: //'); do
CIRCULAR_DEPENDENCIES+=( "$CIRC" )
IS_EXPECTED_CIRC=0
for EXPECTED_CIRC in "${EXPECTED_CIRCULAR_DEPENDENCIES[@]}"; do
if [[ "${CIRC}" == "${EXPECTED_CIRC}" ]]; then
IS_EXPECTED_CIRC=1
break
fi
done
if [[ ${IS_EXPECTED_CIRC} == 0 ]]; then
echo "A new circular dependency in the form of \"${CIRC}\" appears to have been introduced."
echo
EXIT_CODE=1
fi
done
for EXPECTED_CIRC in "${EXPECTED_CIRCULAR_DEPENDENCIES[@]}"; do
IS_PRESENT_EXPECTED_CIRC=0
for CIRC in "${CIRCULAR_DEPENDENCIES[@]}"; do
if [[ "${CIRC}" == "${EXPECTED_CIRC}" ]]; then
IS_PRESENT_EXPECTED_CIRC=1
break
fi
done
if [[ ${IS_PRESENT_EXPECTED_CIRC} == 0 ]]; then
echo "Good job! The circular dependency \"${EXPECTED_CIRC}\" is no longer present."
echo "Please remove it from EXPECTED_CIRCULAR_DEPENDENCIES in $0"
echo "to make sure this circular dependency is not accidentally reintroduced."
echo
EXIT_CODE=1
fi
done
exit ${EXIT_CODE}