Reduce the number of global symbols used #15612

issue practicalswift openend this issue on March 17, 2019
  1. practicalswift commented at 4:05 pm on March 17, 2019: contributor

    The bitcoind binary contains more than 79 global symbols as reported by nm (in the BSS data section and initialized data section, somewhat filtered - see oneliner below):

     0$ for SYMBOL in $(nm src/bitcoind | grep -E ' [BD] ' | c++filt | cut -f3- -d' ' | grep -v @ | grep -v : | sort | grep '[a-z]' | sort -u | grep -vE '^_'); do
     1     REFERENCES=$(git grep -lE "([^a-zA-Z]|^)${SYMBOL}([^a-zA-Z]|\$)" -- "*.cpp" "*.h")
     2     N_REFERENCES=$(wc -l <<< "${REFERENCES}")
     3     echo -n "Found ${N_REFERENCES} use(s) of ${SYMBOL}: "
     4     sort -u <<< "${REFERENCES}" | tr "\n" " "
     5     echo
     6  done
     7Found 1 use(s) of boundSockets: src/httpserver.cpp
     8Found 25 use(s) of chainActive: src/bench/block_assemble.cpp src/bench/duplicate_inputs.cpp src/index/base.cpp src/index/txindex.cpp src/init.cpp src/interfaces/chain.cpp src/interfaces/node.cpp src/miner.cpp src/net_processing.cpp src/policy/fees.cpp src/qt/test/wallettests.cpp src/rest.cpp src/rpc/blockchain.cpp src/rpc/mining.cpp src/rpc/rawtransaction.cpp src/test/denialofservice_tests.cpp src/test/miner_tests.cpp src/test/test_bitcoin.cpp src/test/txvalidationcache_tests.cpp src/test/validation_block_tests.cpp src/txmempool.h src/validation.cpp src/validation.h src/wallet/test/wallet_tests.cpp src/wallet/wallet.cpp
     9Found 43 use(s) of cs_main: src/bench/block_assemble.cpp src/bench/duplicate_inputs.cpp src/bench/mempool_eviction.cpp src/bench/rpc_mempool.cpp src/index/base.cpp src/index/txindex.cpp src/init.cpp src/interfaces/chain.cpp src/interfaces/node.cpp src/interfaces/wallet.cpp src/miner.cpp src/net.h src/net_processing.cpp src/net_processing.h src/node/transaction.cpp src/qt/clientmodel.cpp src/qt/peertablemodel.cpp src/rest.cpp src/rpc/blockchain.cpp src/rpc/mining.cpp src/rpc/misc.cpp src/rpc/net.cpp src/rpc/rawtransaction.cpp src/test/blockencodings_tests.cpp src/test/denialofservice_tests.cpp src/test/mempool_tests.cpp src/test/miner_tests.cpp src/test/policyestimator_tests.cpp src/test/script_p2sh_tests.cpp src/test/test_bitcoin.cpp src/test/transaction_tests.cpp src/test/txvalidationcache_tests.cpp src/test/txvalidation_tests.cpp src/test/validation_block_tests.cpp src/txmempool.h src/validation.cpp src/validation.h src/validationinterface.cpp src/validationinterface.h src/wallet/test/wallet_tests.cpp src/wallet/wallet.cpp src/wallet/wallet.h src/zmq/zmqpublishnotifier.cpp
    10Found 4 use(s) of cs_mapLocalHost: src/net.cpp src/net.h src/rpc/net.cpp src/test/net_tests.cpp
    11Found 1 use(s) of cs_warnings: src/warnings.cpp
    12Found 7 use(s) of dustRelayFee: src/init.cpp src/interfaces/node.cpp src/policy/policy.cpp src/policy/policy.h src/test/transaction_tests.cpp src/wallet/fees.cpp src/wallet/wallet.cpp
    13Found 1 use(s) of eventHTTP: src/httpserver.cpp
    14Found 4 use(s) of fAcceptDatacarrier: src/init.cpp src/policy/policy.cpp src/script/standard.cpp src/script/standard.h
    15Found 4 use(s) of fCheckBlockIndex: src/init.cpp src/test/test_bitcoin.cpp src/validation.cpp src/validation.h
    16Found 4 use(s) of fCheckpointsEnabled: src/init.cpp src/test/miner_tests.cpp src/validation.cpp src/validation.h
    17Found 3 use(s) of fDiscover: src/init.cpp src/net.cpp src/net.h
    18Found 6 use(s) of feeEstimator: src/init.cpp src/interfaces/chain.cpp src/interfaces/node.cpp src/rpc/mining.cpp src/validation.cpp src/validation.h
    19Found 3 use(s) of fEnableReplacement: src/init.cpp src/validation.cpp src/validation.h
    20Found 1 use(s) of fFeeEstimatesInitialized: src/init.cpp
    21Found 3 use(s) of fHavePruned: src/init.cpp src/validation.cpp src/validation.h
    22Found 5 use(s) of fImporting: src/init.cpp src/interfaces/node.cpp src/net_processing.cpp src/validation.cpp src/validation.h
    23Found 4 use(s) of fIsBareMultisigStd: src/init.cpp src/policy/policy.cpp src/validation.cpp src/validation.h
    24Found 1 use(s) of fLargeWorkForkFound: src/warnings.cpp
    25Found 1 use(s) of fLargeWorkInvalidChainFound: src/warnings.cpp
    26Found 5 use(s) of fListen: src/init.cpp src/net.cpp src/net.h src/net_processing.cpp src/qt/optionsmodel.cpp
    27Found 6 use(s) of fLogIPs: src/init.cpp src/logging.cpp src/logging.h src/net.cpp src/net_processing.cpp src/rpc/server.cpp
    28Found 4 use(s) of fNameLookup: src/init.cpp src/netbase.cpp src/netbase.h src/net.cpp
    29Found 6 use(s) of fPruneMode: src/init.cpp src/interfaces/chain.cpp src/net_processing.cpp src/rpc/blockchain.cpp src/validation.cpp src/validation.h
    30Found 5 use(s) of fReindex: src/init.cpp src/interfaces/node.cpp src/net_processing.cpp src/validation.cpp src/validation.h
    31Found 5 use(s) of fRelayTxes: src/init.cpp src/net.cpp src/net.h src/net_processing.cpp src/rpc/net.cpp
    32Found 5 use(s) of fRequireStandard: src/chainparams.cpp src/chainparams.h src/init.cpp src/validation.cpp src/validation.h
    33Found 51 use(s) of gArgs: src/bench/bench_bitcoin.cpp src/bitcoin-cli.cpp src/bitcoind.cpp src/bitcoin-tx.cpp src/bitcoin-wallet.cpp src/chainparamsbase.cpp src/chainparams.cpp src/dbwrapper.cpp src/dummywallet.cpp src/httprpc.cpp src/httpserver.cpp src/init.cpp src/init.h src/interfaces/chain.cpp src/interfaces/node.cpp src/miner.cpp src/net.cpp src/net_processing.cpp src/qt/bitcoin.cpp src/qt/guiutil.cpp src/qt/intro.cpp src/qt/optionsmodel.cpp src/qt/paymentrequestplus.cpp src/qt/paymentserver.cpp src/qt/test/test_main.cpp src/qt/utilitydialog.cpp src/qt/walletmodel.cpp src/rpc/blockchain.cpp src/rpc/protocol.cpp src/rpc/server.cpp src/script/sigcache.cpp src/test/denialofservice_tests.cpp src/test/getarg_tests.cpp src/test/net_tests.cpp src/test/test_bitcoin.cpp src/timedata.cpp src/torcontrol.cpp src/txdb.cpp src/util/system.cpp src/util/system.h src/validation.cpp src/wallet/coincontrol.cpp src/wallet/db.cpp src/wallet/feebumper.cpp src/wallet/init.cpp src/wallet/test/init_test_fixture.cpp src/wallet/test/init_tests.cpp src/wallet/wallet.cpp src/wallet/walletdb.cpp src/wallet/walletutil.cpp src/zmq/zmqnotificationinterface.cpp
    34Found 6 use(s) of g_banman: src/banman.h src/init.cpp src/interfaces/node.cpp src/net.h src/rpc/net.cpp src/test/test_bitcoin.cpp
    35Found 4 use(s) of g_best_block: src/init.cpp src/rpc/mining.cpp src/validation.cpp src/validation.h
    36Found 4 use(s) of g_best_block_cv: src/init.cpp src/rpc/mining.cpp src/validation.cpp src/validation.h
    37Found 3 use(s) of g_best_block_mutex: src/rpc/mining.cpp src/validation.cpp src/validation.h
    38Found 1 use(s) of g_chainstate: src/validation.cpp
    39Found 8 use(s) of g_connman: src/init.cpp src/interfaces/chain.cpp src/interfaces/node.cpp src/net.h src/node/transaction.cpp src/rpc/mining.cpp src/rpc/net.cpp src/test/test_bitcoin.cpp
    40Found 3 use(s) of g_cs_orphans: src/net.h src/net_processing.cpp src/test/denialofservice_tests.cpp
    41Found 4 use(s) of g_is_mempool_loaded: src/init.cpp src/rpc/blockchain.cpp src/validation.cpp src/validation.h
    42Found 4 use(s) of g_mock_deterministic_tests: src/random.cpp src/test/bloom_tests.cpp src/test/random_tests.cpp src/test/test_bitcoin.h
    43Found 6 use(s) of g_rpc_interfaces: src/init.cpp src/rpc/rawtransaction.cpp src/rpc/util.cpp src/rpc/util.h src/test/rpc_tests.cpp src/wallet/rpcwallet.cpp
    44Found 7 use(s) of g_txindex: src/index/txindex.cpp src/index/txindex.h src/init.cpp src/rest.cpp src/rpc/blockchain.cpp src/rpc/rawtransaction.cpp src/validation.cpp
    45Found 1 use(s) of g_ui_signals: src/ui_interface.cpp
    46Found 5 use(s) of g_wallet_init_interface: src/dummywallet.cpp src/httprpc.cpp src/init.cpp src/wallet/init.cpp src/walletinitinterface.h
    47Found 4 use(s) of g_zmq_notification_interface: src/init.cpp src/zmq/zmqnotificationinterface.cpp src/zmq/zmqnotificationinterface.h src/zmq/zmqrpc.cpp
    48Found 3 use(s) of hashAssumeValid: src/init.cpp src/validation.cpp src/validation.h
    49Found 8 use(s) of incrementalRelayFee: src/init.cpp src/policy/policy.cpp src/policy/policy.h src/rpc/net.cpp src/txmempool.cpp src/txmempool.h src/validation.cpp src/wallet/feebumper.cpp
    50Found 1 use(s) of instance_of_cmaincleanup: src/validation.cpp
    51Found 1 use(s) of instance_of_cnetcleanup: src/net.cpp
    52Found 1 use(s) of instance_of_cnetprocessingcleanup: src/net_processing.cpp
    53Found 8 use(s) of mapBlockIndex: src/init.cpp src/interfaces/wallet.cpp src/net_processing.cpp src/rpc/blockchain.cpp src/txdb.cpp src/validation.cpp src/validation.h src/wallet/test/wallet_tests.cpp
    54Found 4 use(s) of mapLocalHost: src/net.cpp src/net.h src/rpc/net.cpp src/test/net_tests.cpp
    55Found 2 use(s) of mapOrphanTransactions: src/net_processing.cpp src/test/denialofservice_tests.cpp
    56Found 11 use(s) of maxTxFee: src/init.cpp src/interfaces/chain.cpp src/interfaces/chain.h src/interfaces/node.cpp src/qt/walletmodel.cpp src/rpc/rawtransaction.cpp src/validation.cpp src/validation.h src/wallet/feebumper.cpp src/wallet/fees.cpp src/wallet/wallet.cpp
    57Found 55 use(s) of mempool: src/bench/block_assemble.cpp src/bench/mempool_eviction.cpp src/blockencodings.cpp src/blockencodings.h src/init.cpp src/interfaces/chain.cpp src/interfaces/chain.h src/interfaces/node.cpp src/interfaces/node.h src/interfaces/wallet.cpp src/interfaces/wallet.h src/logging.cpp src/miner.cpp src/miner.h src/net.h src/net_processing.cpp src/node/transaction.cpp src/policy/fees.cpp src/policy/fees.h src/policy/policy.h src/policy/rbf.cpp src/policy/rbf.h src/protocol.cpp src/protocol.h src/qt/bitcoinstrings.cpp src/qt/coincontroldialog.cpp src/qt/rpcconsole.h src/qt/test/rpcnestedtests.cpp src/qt/transactionrecord.h src/rest.cpp src/rpc/blockchain.cpp src/rpc/client.cpp src/rpc/mining.cpp src/rpc/misc.cpp src/rpc/net.cpp src/rpc/rawtransaction.cpp src/test/blockencodings_tests.cpp src/test/mempool_tests.cpp src/test/miner_tests.cpp src/test/policyestimator_tests.cpp src/test/test_bitcoin.cpp src/test/txvalidationcache_tests.cpp src/test/txvalidation_tests.cpp src/txmempool.cpp src/txmempool.h src/validation.cpp src/validation.h src/validationinterface.h src/wallet/feebumper.cpp src/wallet/feebumper.h src/wallet/fees.cpp src/wallet/init.cpp src/wallet/rpcwallet.cpp src/wallet/wallet.cpp src/wallet/wallet.h
    58Found 11 use(s) of minRelayTxFee: src/init.cpp src/net_processing.cpp src/policy/policy.h src/rpc/blockchain.cpp src/rpc/net.cpp src/validation.cpp src/validation.h src/wallet/fees.cpp src/wallet/init.cpp src/wallet/rpcwallet.cpp src/wallet/wallet.cpp
    59Found 3 use(s) of nBytesPerSigOp: src/init.cpp src/policy/policy.cpp src/policy/policy.h
    60Found 3 use(s) of nCoinCacheUsage: src/init.cpp src/validation.cpp src/validation.h
    61Found 4 use(s) of nConnectTimeout: src/init.cpp src/netbase.cpp src/netbase.h src/net.cpp
    62Found 4 use(s) of nMaxDatacarrierBytes: src/init.cpp src/policy/policy.cpp src/script/standard.cpp src/script/standard.h
    63Found 3 use(s) of nMaxTipAge: src/init.cpp src/validation.cpp src/validation.h
    64Found 6 use(s) of nMinimumChainWork: src/chainparams.cpp src/consensus/params.h src/init.cpp src/net_processing.cpp src/validation.cpp src/validation.h
    65Found 4 use(s) of nPruneTarget: src/init.cpp src/rpc/blockchain.cpp src/validation.cpp src/validation.h
    66Found 5 use(s) of nScriptCheckThreads: src/init.cpp src/test/checkqueue_tests.cpp src/test/test_bitcoin.cpp src/validation.cpp src/validation.h
    67Found 13 use(s) of NullUniValue: src/bitcoin-cli.cpp src/httprpc.cpp src/rpc/blockchain.cpp src/rpc/mining.cpp src/rpc/misc.cpp src/rpc/net.cpp src/rpc/protocol.cpp src/rpc/server.cpp src/rpc/server.h src/univalue/include/univalue.h src/univalue/lib/univalue.cpp src/wallet/rpcdump.cpp src/wallet/rpcwallet.cpp
    68Found 1 use(s) of pathHandlers: src/httpserver.cpp
    69Found 7 use(s) of pblocktree: src/bench/block_assemble.cpp src/bench/duplicate_inputs.cpp src/index/txindex.cpp src/init.cpp src/test/test_bitcoin.cpp src/validation.cpp src/validation.h
    70Found 7 use(s) of pcoinsdbview: src/bench/block_assemble.cpp src/bench/duplicate_inputs.cpp src/init.cpp src/rpc/blockchain.cpp src/test/test_bitcoin.cpp src/validation.cpp src/validation.h
    71Found 15 use(s) of pcoinsTip: src/bench/block_assemble.cpp src/bench/duplicate_inputs.cpp src/init.cpp src/interfaces/node.cpp src/net_processing.cpp src/node/transaction.cpp src/rest.cpp src/rpc/blockchain.cpp src/rpc/rawtransaction.cpp src/test/miner_tests.cpp src/test/test_bitcoin.cpp src/test/txvalidationcache_tests.cpp src/txmempool.h src/validation.cpp src/validation.h
    72Found 2 use(s) of peerLogic: src/init.cpp src/test/denialofservice_tests.cpp
    73Found 1 use(s) of pindexBestForkBase: src/validation.cpp
    74Found 1 use(s) of pindexBestForkTip: src/validation.cpp
    75Found 5 use(s) of pindexBestHeader: src/interfaces/node.cpp src/net_processing.cpp src/rpc/blockchain.cpp src/validation.cpp src/validation.h
    76Found 3 use(s) of secp256k1_nonce_function_default: src/secp256k1/include/secp256k1.h src/secp256k1/include/secp256k1_recovery.h src/secp256k1/src/modules/recovery/main_impl.h
    77Found 2 use(s) of secp256k1_nonce_function_rfc6979: src/key.cpp src/secp256k1/include/secp256k1.h
    78Found 11 use(s) of tableRPC: src/httprpc.cpp src/init.cpp src/interfaces/node.cpp src/interfaces/wallet.cpp src/qt/test/rpcnestedtests.cpp src/rpc/register.h src/rpc/server.cpp src/rpc/server.h src/test/rpc_tests.cpp src/test/test_bitcoin.cpp src/wallet/test/wallet_test_fixture.cpp
    79Found 1 use(s) of threadHTTP: src/httpserver.cpp
    80Found 17 use(s) of uiInterface: src/httprpc.cpp src/httpserver.cpp src/index/base.cpp src/index/txindex.cpp src/init.cpp src/interfaces/chain.cpp src/interfaces/node.cpp src/net.cpp src/net.h src/noui.cpp src/timedata.cpp src/txdb.cpp src/ui_interface.cpp src/ui_interface.h src/validation.cpp src/wallet/init.cpp src/wallet/rpcdump.cpp
    81Found 3 use(s) of versionbitscache: src/rpc/mining.cpp src/validation.cpp src/validation.h
    82Found 6 use(s) of VersionBitsDeploymentInfo: src/chainparams.cpp src/consensus/params.h src/rpc/blockchain.cpp src/rpc/mining.cpp src/versionbitsinfo.cpp src/versionbitsinfo.h
    83$ for SYMBOL in $(nm src/bitcoind | c++filt | grep -E ' B .*[a-z]\[abi:cxx11\]' | cut -f3- -d' ' | cut -f1 -d'[' | sort -u); do
    84       REFERENCES=$(git grep -lE "([^a-zA-Z]|^)${SYMBOL}([^a-zA-Z]|\$)" -- "*.cpp" "*.h")
    85       N_REFERENCES=$(wc -l <<< "${REFERENCES}")
    86       echo -n "Found ${N_REFERENCES} use(s) of ${SYMBOL}: "
    87       sort -u <<< "${REFERENCES}" | tr "\n" " "
    88       echo
    89  done
    90Found 5 use(s) of strMessageMagic: src/qt/signverifymessagedialog.cpp src/rpc/misc.cpp src/validation.cpp src/validation.h src/wallet/rpcwallet.cpp
    91Found 1 use(s) of strMiscWarning: src/warnings.cpp
    92Found 6 use(s) of strSubVersion: src/init.cpp src/net.cpp src/net.h src/net_processing.cpp src/qt/clientmodel.cpp src/rpc/net.cpp
    

    Most of these symbols are global (external) for good reasons.

    However, judging from the output above the following 16 symbols do not have to be global (external):

     0Found 1 use(s) of boundSockets: src/httpserver.cpp
     1Found 1 use(s) of cs_warnings: src/warnings.cpp
     2Found 1 use(s) of eventHTTP: src/httpserver.cpp
     3Found 1 use(s) of fFeeEstimatesInitialized: src/init.cpp
     4Found 1 use(s) of fLargeWorkForkFound: src/warnings.cpp
     5Found 1 use(s) of fLargeWorkInvalidChainFound: src/warnings.cpp
     6Found 1 use(s) of g_chainstate: src/validation.cpp
     7Found 1 use(s) of g_ui_signals: src/ui_interface.cpp
     8Found 1 use(s) of instance_of_cmaincleanup: src/validation.cpp
     9Found 1 use(s) of instance_of_cnetcleanup: src/net.cpp
    10Found 1 use(s) of instance_of_cnetprocessingcleanup: src/net_processing.cpp
    11Found 1 use(s) of pathHandlers: src/httpserver.cpp
    12Found 1 use(s) of pindexBestForkBase: src/validation.cpp
    13Found 1 use(s) of pindexBestForkTip: src/validation.cpp
    14Found 1 use(s) of strMiscWarning: src/warnings.cpp
    15Found 1 use(s) of threadHTTP: src/httpserver.cpp
    
  2. MarcoFalke added the label Brainstorming on Mar 17, 2019
  3. MarcoFalke added the label Refactoring on Mar 17, 2019
  4. practicalswift renamed this:
    Reduce the number of globals used
    Reduce the number of global symbols used
    on Apr 16, 2019
  5. MarcoFalke closed this on May 25, 2019

  6. MarcoFalke referenced this in commit 8ab4f282c0 on May 25, 2019
  7. PastaPastaPasta referenced this in commit 9936bfe112 on Jun 27, 2021
  8. PastaPastaPasta referenced this in commit 2184ba19ed on Jun 28, 2021
  9. PastaPastaPasta referenced this in commit 51c46d0edb on Jun 29, 2021
  10. PastaPastaPasta referenced this in commit 225c8690ba on Sep 11, 2021
  11. PastaPastaPasta referenced this in commit 3f346d2fa9 on Sep 11, 2021
  12. PastaPastaPasta referenced this in commit 74a2557245 on Sep 12, 2021
  13. DrahtBot locked this on Dec 16, 2021

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: 2024-12-18 21:12 UTC

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