Merge pull request #3618 from PastaPastaPasta/backports-0.17-pr16

Backports 0.17 pr16
This commit is contained in:
UdjinM6 2020-07-20 18:03:11 +03:00 committed by GitHub
commit 6e592cc691
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
80 changed files with 862 additions and 686 deletions

View File

@ -186,3 +186,14 @@ It will do the following automatically:
- add missing translations to the build system (TODO) - add missing translations to the build system (TODO)
See doc/translation-process.md for more information. See doc/translation-process.md for more information.
circular-dependencies.py
========================
Run this script from the root of the source tree (`src/`) to find circular dependencies in the source code.
This looks only at which files include other files, treating the `.cpp` and `.h` file as one unit.
Example usage:
cd .../src
../contrib/devtools/circular-dependencies.py {*,*/*,*/*/*}.{h,cpp}

View File

@ -0,0 +1,79 @@
#!/usr/bin/env python3
import sys
import re
MAPPING = {
'core_read.cpp': 'core_io.cpp',
'core_write.cpp': 'core_io.cpp',
}
def module_name(path):
if path in MAPPING:
path = MAPPING[path]
if path.endswith(".h"):
return path[:-2]
if path.endswith(".c"):
return path[:-2]
if path.endswith(".cpp"):
return path[:-4]
return None
files = dict()
deps = dict()
RE = re.compile("^#include <(.*)>")
# Iterate over files, and create list of modules
for arg in sys.argv[1:]:
module = module_name(arg)
if module is None:
print("Ignoring file %s (does not constitute module)\n" % arg)
else:
files[arg] = module
deps[module] = set()
# Iterate again, and build list of direct dependencies for each module
# TODO: implement support for multiple include directories
for arg in sorted(files.keys()):
module = files[arg]
with open(arg, 'r') as f:
for line in f:
match = RE.match(line)
if match:
include = match.group(1)
included_module = module_name(include)
if included_module is not None and included_module in deps and included_module != module:
deps[module].add(included_module)
# Loop to find the shortest (remaining) circular dependency
have_cycle = False
while True:
shortest_cycle = None
for module in sorted(deps.keys()):
# Build the transitive closure of dependencies of module
closure = dict()
for dep in deps[module]:
closure[dep] = []
while True:
old_size = len(closure)
old_closure_keys = sorted(closure.keys())
for src in old_closure_keys:
for dep in deps[src]:
if dep not in closure:
closure[dep] = closure[src] + [src]
if len(closure) == old_size:
break
# If module is in its own transitive closure, it's a circular dependency; check if it is the shortest
if module in closure and (shortest_cycle is None or len(closure[module]) + 1 < len(shortest_cycle)):
shortest_cycle = [module] + closure[module]
if shortest_cycle is None:
break
# We have the shortest circular dependency; report it
module = shortest_cycle[0]
print("Circular dependency: %s" % (" -> ".join(shortest_cycle + [module])))
# And then break the dependency to avoid repeating in other cycles
deps[shortest_cycle[-1]] = deps[shortest_cycle[-1]] - set([module])
have_cycle = True
sys.exit(1 if have_cycle else 0)

View File

@ -0,0 +1,29 @@
#!/bin/bash
#
# Copyright (c) 2018 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 include guards.
HEADER_ID_PREFIX="BITCOIN_"
HEADER_ID_SUFFIX="_H"
REGEXP_EXCLUDE_FILES_WITH_PREFIX="src/(crypto/ctaes/|leveldb/|secp256k1/|tinyformat.h|univalue/|ctpl.h|bls/|crypto/sph)"
EXIT_CODE=0
for HEADER_FILE in $(git ls-files -- "*.h" | grep -vE "^${REGEXP_EXCLUDE_FILES_WITH_PREFIX}")
do
HEADER_ID_BASE=$(cut -f2- -d/ <<< "${HEADER_FILE}" | sed "s/\.h$//g" | tr / _ | tr "[:lower:]" "[:upper:]" | tr - _)
HEADER_ID="${HEADER_ID_PREFIX}${HEADER_ID_BASE}${HEADER_ID_SUFFIX}"
if [[ $(grep -cE "^#(ifndef|define) ${HEADER_ID}" "${HEADER_FILE}") != 2 ]]; then
echo "${HEADER_FILE} seems to be missing the expected include guard:"
echo " #ifndef ${HEADER_ID}"
echo " #define ${HEADER_ID}"
echo " ..."
echo " #endif // ${HEADER_ID}"
echo
EXIT_CODE=1
fi
done
exit ${EXIT_CODE}

View File

@ -564,6 +564,16 @@ namespace {
source file into account. This allows quoted includes to stand out more when source file into account. This allows quoted includes to stand out more when
the location of the source file actually is relevant. the location of the source file actually is relevant.
- Use include guards to avoid the problem of double inclusion. The header file
`foo/bar.h` should use the include guard identifier `BITCOIN_FOO_BAR_H`, e.g.
```c++
#ifndef BITCOIN_FOO_BAR_H
#define BITCOIN_FOO_BAR_H
...
#endif // BITCOIN_FOO_BAR_H
```
GUI GUI
----- -----

View File

@ -187,6 +187,7 @@ BITCOIN_CORE_H = \
llmq/quorums_signing.h \ llmq/quorums_signing.h \
llmq/quorums_signing_shares.h \ llmq/quorums_signing_shares.h \
llmq/quorums_utils.h \ llmq/quorums_utils.h \
logging.h \
masternode/activemasternode.h \ masternode/activemasternode.h \
masternode/masternode-meta.h \ masternode/masternode-meta.h \
masternode/masternode-payments.h \ masternode/masternode-payments.h \
@ -546,6 +547,7 @@ libdash_util_a_SOURCES = \
compat/glibcxx_sanity.cpp \ compat/glibcxx_sanity.cpp \
compat/strnlen.cpp \ compat/strnlen.cpp \
fs.cpp \ fs.cpp \
logging.cpp \
random.cpp \ random.cpp \
rpc/protocol.cpp \ rpc/protocol.cpp \
stacktraces.cpp \ stacktraces.cpp \

View File

@ -2,8 +2,8 @@
// Distributed under the MIT/X11 software license, see the accompanying // Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef DASH_BATCHEDLOGGER_H #ifndef BITCOIN_BATCHEDLOGGER_H
#define DASH_BATCHEDLOGGER_H #define BITCOIN_BATCHEDLOGGER_H
#include <tinyformat.h> #include <tinyformat.h>
@ -29,4 +29,4 @@ public:
void Flush(); void Flush();
}; };
#endif//DASH_BATCHEDLOGGER_H #endif//BITCOIN_BATCHEDLOGGER_H

View File

@ -3,8 +3,8 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
/** Functions for measurement of CPU cycles */ /** Functions for measurement of CPU cycles */
#ifndef H_PERF #ifndef BITCOIN_BENCH_PERF_H
#define H_PERF #define BITCOIN_BENCH_PERF_H
#include <stdint.h> #include <stdint.h>
@ -34,4 +34,4 @@ uint64_t perf_cpucycles(void);
void perf_init(void); void perf_init(void);
void perf_fini(void); void perf_fini(void);
#endif // H_PERF #endif // BITCOIN_BENCH_PERF_H

View File

@ -21,8 +21,8 @@
* OTHER DEALINGS IN THE SOFTWARE. * OTHER DEALINGS IN THE SOFTWARE.
*/ */
#ifndef DASH_BIP39_H #ifndef BITCOIN_BIP39_H
#define DASH_BIP39_H #define BITCOIN_BIP39_H
#include <support/allocators/secure.h> #include <support/allocators/secure.h>
@ -36,4 +36,4 @@ public:
static void ToSeed(SecureString mnemonic, SecureString passphrase, SecureVector& seedRet); static void ToSeed(SecureString mnemonic, SecureString passphrase, SecureVector& seedRet);
}; };
#endif #endif // BITCOIN_BIP39_H

View File

@ -21,6 +21,9 @@
* OTHER DEALINGS IN THE SOFTWARE. * OTHER DEALINGS IN THE SOFTWARE.
*/ */
#ifndef BITCOIN_BIP39_ENGLISH_H
#define BITCOIN_BIP39_ENGLISH_H
const char * const wordlist[] = { const char * const wordlist[] = {
"abandon", "abandon",
"ability", "ability",
@ -2072,3 +2075,5 @@ const char * const wordlist[] = {
"zoo", "zoo",
0, 0,
}; };
#endif // BITCOIN_BIP39_ENGLISH_H

View File

@ -2,8 +2,8 @@
// Distributed under the MIT software license, see the accompanying // Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_BLOCK_ENCODINGS_H #ifndef BITCOIN_BLOCKENCODINGS_H
#define BITCOIN_BLOCK_ENCODINGS_H #define BITCOIN_BLOCKENCODINGS_H
#include <primitives/block.h> #include <primitives/block.h>
@ -209,4 +209,4 @@ public:
ReadStatus FillBlock(CBlock& block, const std::vector<CTransactionRef>& vtx_missing); ReadStatus FillBlock(CBlock& block, const std::vector<CTransactionRef>& vtx_missing);
}; };
#endif #endif // BITCOIN_BLOCKENCODINGS_H

View File

@ -2,8 +2,8 @@
// Distributed under the MIT/X11 software license, see the accompanying // Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef CACHEMAP_H_ #ifndef BITCOIN_CACHEMAP_H
#define CACHEMAP_H_ #define BITCOIN_CACHEMAP_H
#include <map> #include <map>
#include <list> #include <list>
@ -186,4 +186,4 @@ private:
} }
}; };
#endif /* CACHEMAP_H_ */ #endif // BITCOIN_CACHEMAP_H

View File

@ -2,8 +2,8 @@
// Distributed under the MIT/X11 software license, see the accompanying // Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef CACHEMULTIMAP_H_ #ifndef BITCOIN_CACHEMULTIMAP_H
#define CACHEMULTIMAP_H_ #define BITCOIN_CACHEMULTIMAP_H
#include <cstddef> #include <cstddef>
#include <map> #include <map>
@ -245,4 +245,4 @@ private:
} }
}; };
#endif /* CACHEMULTIMAP_H_ */ #endif // BITCOIN_CACHEMULTIMAP_H

View File

@ -1,5 +1,5 @@
#ifndef DASH_CHAINPARAMSSEEDS_H #ifndef BITCOIN_CHAINPARAMSSEEDS_H
#define DASH_CHAINPARAMSSEEDS_H #define BITCOIN_CHAINPARAMSSEEDS_H
/** /**
* List of fixed seed nodes for the dash network * List of fixed seed nodes for the dash network
* AUTOGENERATED by contrib/seeds/generate-seeds.py * AUTOGENERATED by contrib/seeds/generate-seeds.py
@ -283,4 +283,4 @@ static SeedSpec6 pnSeed6_test[] = {
{{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xb9,0xd5,0x25,0x01}, 19999}, {{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xb9,0xd5,0x25,0x01}, 19999},
{{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xb9,0xd5,0x25,0x02}, 19999} {{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff,0xb9,0xd5,0x25,0x02}, 19999}
}; };
#endif // DASH_CHAINPARAMSSEEDS_H #endif // BITCOIN_CHAINPARAMSSEEDS_H

View File

@ -2,8 +2,8 @@
// Distributed under the MIT software license, see the accompanying // Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_MERKLE #ifndef BITCOIN_CONSENSUS_MERKLE_H
#define BITCOIN_MERKLE #define BITCOIN_CONSENSUS_MERKLE_H
#include <stdint.h> #include <stdint.h>
#include <vector> #include <vector>
@ -20,4 +20,4 @@ uint256 ComputeMerkleRoot(std::vector<uint256> hashes, bool* mutated = nullptr);
*/ */
uint256 BlockMerkleRoot(const CBlock& block, bool* mutated = nullptr); uint256 BlockMerkleRoot(const CBlock& block, bool* mutated = nullptr);
#endif #endif // BITCOIN_CONSENSUS_MERKLE_H

View File

@ -2,8 +2,8 @@
// Distributed under the MIT software license, see the accompanying // Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef DASH_CBTX_H #ifndef BITCOIN_EVO_CBTX_H
#define DASH_CBTX_H #define BITCOIN_EVO_CBTX_H
#include <consensus/validation.h> #include <consensus/validation.h>
#include <primitives/transaction.h> #include <primitives/transaction.h>
@ -60,4 +60,4 @@ bool CheckCbTxMerkleRoots(const CBlock& block, const CBlockIndex* pindex, CValid
bool CalcCbTxMerkleRootMNList(const CBlock& block, const CBlockIndex* pindexPrev, uint256& merkleRootRet, CValidationState& state); bool CalcCbTxMerkleRootMNList(const CBlock& block, const CBlockIndex* pindexPrev, uint256& merkleRootRet, CValidationState& state);
bool CalcCbTxMerkleRootQuorums(const CBlock& block, const CBlockIndex* pindexPrev, uint256& merkleRootRet, CValidationState& state); bool CalcCbTxMerkleRootQuorums(const CBlock& block, const CBlockIndex* pindexPrev, uint256& merkleRootRet, CValidationState& state);
#endif //DASH_CBTX_H #endif // BITCOIN_EVO_CBTX_H

View File

@ -2,8 +2,8 @@
// Distributed under the MIT software license, see the accompanying // Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef DASH_DETERMINISTICMNS_H #ifndef BITCOIN_EVO_DETERMINISTICMNS_H
#define DASH_DETERMINISTICMNS_H #define BITCOIN_EVO_DETERMINISTICMNS_H
#include <arith_uint256.h> #include <arith_uint256.h>
#include <bls/bls.h> #include <bls/bls.h>
@ -682,4 +682,4 @@ private:
extern std::unique_ptr<CDeterministicMNManager> deterministicMNManager; extern std::unique_ptr<CDeterministicMNManager> deterministicMNManager;
#endif //DASH_DETERMINISTICMNS_H #endif // BITCOIN_EVO_DETERMINISTICMNS_H

View File

@ -2,8 +2,8 @@
// Distributed under the MIT software license, see the accompanying // Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef DASH_EVODB_H #ifndef BITCOIN_EVO_EVODB_H
#define DASH_EVODB_H #define BITCOIN_EVO_EVODB_H
#include <dbwrapper.h> #include <dbwrapper.h>
#include <sync.h> #include <sync.h>
@ -110,4 +110,4 @@ private:
extern std::unique_ptr<CEvoDB> evoDb; extern std::unique_ptr<CEvoDB> evoDb;
#endif //DASH_EVODB_H #endif // BITCOIN_EVO_EVODB_H

View File

@ -2,8 +2,8 @@
// Distributed under the MIT software license, see the accompanying // Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef DASH_MNAUTH_H #ifndef BITCOIN_EVO_MNAUTH_H
#define DASH_MNAUTH_H #define BITCOIN_EVO_MNAUTH_H
#include <bls/bls.h> #include <bls/bls.h>
#include <serialize.h> #include <serialize.h>
@ -55,4 +55,4 @@ public:
}; };
#endif //DASH_MNAUTH_H #endif // BITCOIN_EVO_MNAUTH_H

View File

@ -2,8 +2,8 @@
// Distributed under the MIT software license, see the accompanying // Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef DASH_PROVIDERTX_H #ifndef BITCOIN_EVO_PROVIDERTX_H
#define DASH_PROVIDERTX_H #define BITCOIN_EVO_PROVIDERTX_H
#include <bls/bls.h> #include <bls/bls.h>
#include <consensus/validation.h> #include <consensus/validation.h>
@ -240,4 +240,4 @@ bool CheckProUpServTx(const CTransaction& tx, const CBlockIndex* pindexPrev, CVa
bool CheckProUpRegTx(const CTransaction& tx, const CBlockIndex* pindexPrev, CValidationState& state); bool CheckProUpRegTx(const CTransaction& tx, const CBlockIndex* pindexPrev, CValidationState& state);
bool CheckProUpRevTx(const CTransaction& tx, const CBlockIndex* pindexPrev, CValidationState& state); bool CheckProUpRevTx(const CTransaction& tx, const CBlockIndex* pindexPrev, CValidationState& state);
#endif //DASH_PROVIDERTX_H #endif // BITCOIN_EVO_PROVIDERTX_H

View File

@ -2,8 +2,8 @@
// Distributed under the MIT software license, see the accompanying // Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef DASH_SIMPLIFIEDMNS_H #ifndef BITCOIN_EVO_SIMPLIFIEDMNS_H
#define DASH_SIMPLIFIEDMNS_H #define BITCOIN_EVO_SIMPLIFIEDMNS_H
#include <bls/bls.h> #include <bls/bls.h>
#include <merkleblock.h> #include <merkleblock.h>
@ -147,4 +147,4 @@ public:
bool BuildSimplifiedMNListDiff(const uint256& baseBlockHash, const uint256& blockHash, CSimplifiedMNListDiff& mnListDiffRet, std::string& errorRet); bool BuildSimplifiedMNListDiff(const uint256& baseBlockHash, const uint256& blockHash, CSimplifiedMNListDiff& mnListDiffRet, std::string& errorRet);
#endif //DASH_SIMPLIFIEDMNS_H #endif // BITCOIN_EVO_SIMPLIFIEDMNS_H

View File

@ -2,8 +2,8 @@
// Distributed under the MIT software license, see the accompanying // Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef DASH_SPECIALTX_H #ifndef BITCOIN_EVO_SPECIALTX_H
#define DASH_SPECIALTX_H #define BITCOIN_EVO_SPECIALTX_H
#include <primitives/transaction.h> #include <primitives/transaction.h>
#include <streams.h> #include <streams.h>
@ -49,4 +49,4 @@ void SetTxPayload(CMutableTransaction& tx, const T& payload)
uint256 CalcTxInputsHash(const CTransaction& tx); uint256 CalcTxInputsHash(const CTransaction& tx);
#endif //DASH_SPECIALTX_H #endif // BITCOIN_EVO_SPECIALTX_H

View File

@ -2,8 +2,8 @@
// Distributed under the MIT/X11 software license, see the accompanying // Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef FLAT_DATABASE_H #ifndef BITCOIN_FLAT_DATABASE_H
#define FLAT_DATABASE_H #define BITCOIN_FLAT_DATABASE_H
#include <chainparams.h> #include <chainparams.h>
#include <clientversion.h> #include <clientversion.h>
@ -225,4 +225,4 @@ public:
}; };
#endif #endif // BITCOIN_FLAT_DATABASE_H

View File

@ -1,8 +1,8 @@
// Copyright (c) 2014-2020 The Dash Core developers // Copyright (c) 2014-2020 The Dash Core developers
// Distributed under the MIT/X11 software license, see the accompanying // Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef GOVERNANCE_CLASSES_H #ifndef BITCOIN_GOVERNANCE_GOVERNANCE_CLASSES_H
#define GOVERNANCE_CLASSES_H #define BITCOIN_GOVERNANCE_GOVERNANCE_CLASSES_H
#include <base58.h> #include <base58.h>
#include <governance/governance.h> #include <governance/governance.h>
@ -173,4 +173,4 @@ public:
bool IsExpired() const; bool IsExpired() const;
}; };
#endif #endif // BITCOIN_GOVERNANCE_GOVERNANCE_CLASSES_H

View File

@ -2,8 +2,8 @@
// Distributed under the MIT/X11 software license, see the accompanying // Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef GOVERNANCE_EXCEPTIONS_H #ifndef BITCOIN_GOVERNANCE_GOVERNANCE_EXCEPTIONS_H
#define GOVERNANCE_EXCEPTIONS_H #define BITCOIN_GOVERNANCE_GOVERNANCE_EXCEPTIONS_H
#include <exception> #include <exception>
#include <iostream> #include <iostream>
@ -97,4 +97,4 @@ public:
} }
}; };
#endif #endif // BITCOIN_GOVERNANCE_GOVERNANCE_EXCEPTIONS_H

View File

@ -2,8 +2,8 @@
// Distributed under the MIT/X11 software license, see the accompanying // Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef GOVERNANCE_OBJECT_H #ifndef BITCOIN_GOVERNANCE_GOVERNANCE_OBJECT_H
#define GOVERNANCE_OBJECT_H #define BITCOIN_GOVERNANCE_GOVERNANCE_OBJECT_H
#include <cachemultimap.h> #include <cachemultimap.h>
#include <governance/governance-exceptions.h> #include <governance/governance-exceptions.h>
@ -356,4 +356,4 @@ public:
}; };
#endif #endif // BITCOIN_GOVERNANCE_GOVERNANCE_OBJECT_H

View File

@ -2,8 +2,8 @@
// Distributed under the MIT/X11 software license, see the accompanying // Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef GOVERNANCE_VALIDATORS_H #ifndef BITCOIN_GOVERNANCE_GOVERNANCE_VALIDATORS_H
#define GOVERNANCE_VALIDATORS_H #define BITCOIN_GOVERNANCE_GOVERNANCE_VALIDATORS_H
#include <string> #include <string>
@ -44,4 +44,4 @@ private:
bool CheckURL(const std::string& strURLIn); bool CheckURL(const std::string& strURLIn);
}; };
#endif #endif // BITCOIN_GOVERNANCE_GOVERNANCE_VALIDATORS_H

View File

@ -2,8 +2,8 @@
// Distributed under the MIT/X11 software license, see the accompanying // Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef GOVERNANCE_VOTE_H #ifndef BITCOIN_GOVERNANCE_GOVERNANCE_VOTE_H
#define GOVERNANCE_VOTE_H #define BITCOIN_GOVERNANCE_GOVERNANCE_VOTE_H
#include <key.h> #include <key.h>
#include <primitives/transaction.h> #include <primitives/transaction.h>
@ -133,4 +133,4 @@ public:
} }
}; };
#endif #endif // BITCOIN_GOVERNANCE_GOVERNANCE_VOTE_H

View File

@ -2,8 +2,8 @@
// Distributed under the MIT/X11 software license, see the accompanying // Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef GOVERNANCE_VOTEDB_H #ifndef BITCOIN_GOVERNANCE_GOVERNANCE_VOTEDB_H
#define GOVERNANCE_VOTEDB_H #define BITCOIN_GOVERNANCE_GOVERNANCE_VOTEDB_H
#include <list> #include <list>
#include <map> #include <map>
@ -92,4 +92,4 @@ private:
void RebuildIndex(); void RebuildIndex();
}; };
#endif #endif // BITCOIN_GOVERNANCE_GOVERNANCE_VOTEDB_H

View File

@ -2,8 +2,8 @@
// Distributed under the MIT/X11 software license, see the accompanying // Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef GOVERNANCE_H #ifndef BITCOIN_GOVERNANCE_GOVERNANCE_H
#define GOVERNANCE_H #define BITCOIN_GOVERNANCE_GOVERNANCE_H
#include <bloom.h> #include <bloom.h>
#include <cachemap.h> #include <cachemap.h>
@ -432,4 +432,4 @@ private:
}; };
#endif #endif // BITCOIN_GOVERNANCE_GOVERNANCE_H

View File

@ -1,7 +1,7 @@
// Copyright (c) 2014-2019 The Dash Core developers // Copyright (c) 2014-2019 The Dash Core developers
// Distributed under the MIT software license, see the accompanying // Distributed under the MIT software license, see the accompanying
#ifndef DASH_HDCHAIN_H #ifndef BITCOIN_HDCHAIN_H
#define DASH_HDCHAIN_H #define BITCOIN_HDCHAIN_H
#include <key.h> #include <key.h>
#include <sync.h> #include <sync.h>
@ -147,4 +147,4 @@ public:
std::string GetKeyPath() const; std::string GetKeyPath() const;
}; };
#endif // DASH_HDCHAIN_H #endif // BITCOIN_HDCHAIN_H

View File

@ -2,8 +2,8 @@
// Distributed under the MIT/X11 software license, see the accompanying // Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef _KEEPASS_H_ #ifndef BITCOIN_KEEPASS_H
#define _KEEPASS_H_ #define BITCOIN_KEEPASS_H
#include <support/allocators/secure.h> #include <support/allocators/secure.h>
@ -130,4 +130,4 @@ public:
}; };
#endif #endif // BITCOIN_KEEPASS_H

View File

@ -2,8 +2,8 @@
// Distributed under the MIT/X11 software license, see the accompanying // Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef DASH_QUORUMS_H #ifndef BITCOIN_LLMQ_QUORUMS_H
#define DASH_QUORUMS_H #define BITCOIN_LLMQ_QUORUMS_H
#include <evo/evodb.h> #include <evo/evodb.h>
#include <evo/deterministicmns.h> #include <evo/deterministicmns.h>
@ -117,4 +117,4 @@ extern CQuorumManager* quorumManager;
} // namespace llmq } // namespace llmq
#endif //DASH_QUORUMS_H #endif // BITCOIN_LLMQ_QUORUMS_H

View File

@ -2,8 +2,8 @@
// Distributed under the MIT/X11 software license, see the accompanying // Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef DASH_QUORUMS_BLOCKPROCESSOR_H #ifndef BITCOIN_LLMQ_QUORUMS_BLOCKPROCESSOR_H
#define DASH_QUORUMS_BLOCKPROCESSOR_H #define BITCOIN_LLMQ_QUORUMS_BLOCKPROCESSOR_H
#include <llmq/quorums_commitment.h> #include <llmq/quorums_commitment.h>
#include <llmq/quorums_utils.h> #include <llmq/quorums_utils.h>
@ -68,4 +68,4 @@ extern CQuorumBlockProcessor* quorumBlockProcessor;
} // namespace llmq } // namespace llmq
#endif//DASH_QUORUMS_BLOCKPROCESSOR_H #endif // BITCOIN_LLMQ_QUORUMS_BLOCKPROCESSOR_H

View File

@ -2,8 +2,8 @@
// Distributed under the MIT/X11 software license, see the accompanying // Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef DASH_QUORUMS_CHAINLOCKS_H #ifndef BITCOIN_LLMQ_QUORUMS_CHAINLOCKS_H
#define DASH_QUORUMS_CHAINLOCKS_H #define BITCOIN_LLMQ_QUORUMS_CHAINLOCKS_H
#include <llmq/quorums.h> #include <llmq/quorums.h>
#include <llmq/quorums_signing.h> #include <llmq/quorums_signing.h>
@ -125,4 +125,4 @@ extern CChainLocksHandler* chainLocksHandler;
} // namespace llmq } // namespace llmq
#endif //DASH_QUORUMS_CHAINLOCKS_H #endif // BITCOIN_LLMQ_QUORUMS_CHAINLOCKS_H

View File

@ -2,8 +2,8 @@
// Distributed under the MIT/X11 software license, see the accompanying // Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef DASH_QUORUMS_COMMITMENT_H #ifndef BITCOIN_LLMQ_QUORUMS_COMMITMENT_H
#define DASH_QUORUMS_COMMITMENT_H #define BITCOIN_LLMQ_QUORUMS_COMMITMENT_H
#include <llmq/quorums_utils.h> #include <llmq/quorums_utils.h>
@ -143,4 +143,4 @@ bool CheckLLMQCommitment(const CTransaction& tx, const CBlockIndex* pindexPrev,
} // namespace llmq } // namespace llmq
#endif //DASH_QUORUMS_COMMITMENT_H #endif // BITCOIN_LLMQ_QUORUMS_COMMITMENT_H

View File

@ -2,8 +2,8 @@
// Distributed under the MIT/X11 software license, see the accompanying // Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef DASH_QUORUMS_DEBUG_H #ifndef BITCOIN_LLMQ_QUORUMS_DEBUG_H
#define DASH_QUORUMS_DEBUG_H #define BITCOIN_LLMQ_QUORUMS_DEBUG_H
#include <consensus/params.h> #include <consensus/params.h>
#include <sync.h> #include <sync.h>
@ -108,4 +108,4 @@ extern CDKGDebugManager* quorumDKGDebugManager;
} // namespace llmq } // namespace llmq
#endif //DASH_QUORUMS_DEBUG_H #endif // BITCOIN_LLMQ_QUORUMS_DEBUG_H

View File

@ -2,8 +2,8 @@
// Distributed under the MIT/X11 software license, see the accompanying // Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef DASH_QUORUMS_DKGSESSION_H #ifndef BITCOIN_LLMQ_QUORUMS_DKGSESSION_H
#define DASH_QUORUMS_DKGSESSION_H #define BITCOIN_LLMQ_QUORUMS_DKGSESSION_H
#include <consensus/params.h> #include <consensus/params.h>
#include <net.h> #include <net.h>
@ -345,4 +345,4 @@ void SetSimulatedDKGErrorRate(const std::string& type, double rate);
} // namespace llmq } // namespace llmq
#endif //DASH_QUORUMS_DKGSESSION_H #endif // BITCOIN_LLMQ_QUORUMS_DKGSESSION_H

View File

@ -2,8 +2,8 @@
// Distributed under the MIT/X11 software license, see the accompanying // Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef DASH_QUORUMS_DKGSESSIONHANDLER_H #ifndef BITCOIN_LLMQ_QUORUMS_DKGSESSIONHANDLER_H
#define DASH_QUORUMS_DKGSESSIONHANDLER_H #define BITCOIN_LLMQ_QUORUMS_DKGSESSIONHANDLER_H
#include <llmq/quorums_dkgsession.h> #include <llmq/quorums_dkgsession.h>
@ -145,4 +145,4 @@ private:
} // namespace llmq } // namespace llmq
#endif //DASH_QUORUMS_DKGSESSIONHANDLER_H #endif // BITCOIN_LLMQ_QUORUMS_DKGSESSIONHANDLER_H

View File

@ -2,8 +2,8 @@
// Distributed under the MIT/X11 software license, see the accompanying // Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef DASH_QUORUMS_DKGSESSIONMGR_H #ifndef BITCOIN_LLMQ_QUORUMS_DKGSESSIONMGR_H
#define DASH_QUORUMS_DKGSESSIONMGR_H #define BITCOIN_LLMQ_QUORUMS_DKGSESSIONMGR_H
#include <llmq/quorums_dkgsessionhandler.h> #include <llmq/quorums_dkgsessionhandler.h>
@ -75,4 +75,4 @@ extern CDKGSessionManager* quorumDKGSessionManager;
} // namespace llmq } // namespace llmq
#endif //DASH_QUORUMS_DKGSESSIONMGR_H #endif // BITCOIN_LLMQ_QUORUMS_DKGSESSIONMGR_H

View File

@ -2,8 +2,8 @@
// Distributed under the MIT/X11 software license, see the accompanying // Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef DASH_QUORUMS_INIT_H #ifndef BITCOIN_LLMQ_QUORUMS_INIT_H
#define DASH_QUORUMS_INIT_H #define BITCOIN_LLMQ_QUORUMS_INIT_H
class CDBWrapper; class CDBWrapper;
class CEvoDB; class CEvoDB;
@ -24,4 +24,4 @@ void StopLLMQSystem();
void InterruptLLMQSystem(); void InterruptLLMQSystem();
} // namespace llmq } // namespace llmq
#endif //DASH_QUORUMS_INIT_H #endif // BITCOIN_LLMQ_QUORUMS_INIT_H

View File

@ -2,8 +2,8 @@
// Distributed under the MIT software license, see the accompanying // Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef DASH_QUORUMS_INSTANTSEND_H #ifndef BITCOIN_LLMQ_QUORUMS_INSTANTSEND_H
#define DASH_QUORUMS_INSTANTSEND_H #define BITCOIN_LLMQ_QUORUMS_INSTANTSEND_H
#include <llmq/quorums_signing.h> #include <llmq/quorums_signing.h>
@ -177,4 +177,4 @@ bool IsInstantSendEnabled();
} // namespace llmq } // namespace llmq
#endif//DASH_QUORUMS_INSTANTSEND_H #endif // BITCOIN_LLMQ_QUORUMS_INSTANTSEND_H

View File

@ -2,8 +2,8 @@
// Distributed under the MIT/X11 software license, see the accompanying // Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef DASH_QUORUMS_SIGNING_H #ifndef BITCOIN_LLMQ_QUORUMS_SIGNING_H
#define DASH_QUORUMS_SIGNING_H #define BITCOIN_LLMQ_QUORUMS_SIGNING_H
#include <llmq/quorums.h> #include <llmq/quorums.h>
@ -191,4 +191,4 @@ extern CSigningManager* quorumSigningManager;
} // namespace llmq } // namespace llmq
#endif //DASH_QUORUMS_SIGNING_H #endif // BITCOIN_LLMQ_QUORUMS_SIGNING_H

View File

@ -2,8 +2,8 @@
// Distributed under the MIT/X11 software license, see the accompanying // Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef DASH_QUORUMS_SIGNING_SHARES_H #ifndef BITCOIN_LLMQ_QUORUMS_SIGNING_SHARES_H
#define DASH_QUORUMS_SIGNING_SHARES_H #define BITCOIN_LLMQ_QUORUMS_SIGNING_SHARES_H
#include <bls/bls.h> #include <bls/bls.h>
#include <chainparams.h> #include <chainparams.h>
@ -460,4 +460,4 @@ extern CSigSharesManager* quorumSigSharesManager;
} // namespace llmq } // namespace llmq
#endif //DASH_QUORUMS_SIGNING_SHARES_H #endif // BITCOIN_LLMQ_QUORUMS_SIGNING_SHARES_H

View File

@ -2,8 +2,8 @@
// Distributed under the MIT software license, see the accompanying // Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef DASH_QUORUMS_UTILS_H #ifndef BITCOIN_LLMQ_QUORUMS_UTILS_H
#define DASH_QUORUMS_UTILS_H #define BITCOIN_LLMQ_QUORUMS_UTILS_H
#include <consensus/params.h> #include <consensus/params.h>
#include <net.h> #include <net.h>
@ -83,4 +83,4 @@ public:
} // namespace llmq } // namespace llmq
#endif//DASH_QUORUMS_UTILS_H #endif // BITCOIN_LLMQ_QUORUMS_UTILS_H

349
src/logging.cpp Normal file
View File

@ -0,0 +1,349 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2018 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <logging.h>
#include <util.h>
#include <utilstrencodings.h>
#include <list>
#include <mutex>
const char * const DEFAULT_DEBUGLOGFILE = "debug.log";
bool fPrintToConsole = false;
bool fPrintToDebugLog = true;
bool fLogTimestamps = DEFAULT_LOGTIMESTAMPS;
bool fLogTimeMicros = DEFAULT_LOGTIMEMICROS;
bool fLogThreadNames = DEFAULT_LOGTHREADNAMES;
bool fLogIPs = DEFAULT_LOGIPS;
std::atomic<bool> fReopenDebugLog(false);
/** Log categories bitfield. */
std::atomic<uint64_t> logCategories(0);
/**
* LogPrintf() has been broken a couple of times now
* by well-meaning people adding mutexes in the most straightforward way.
* It breaks because it may be called by global destructors during shutdown.
* Since the order of destruction of static/global objects is undefined,
* defining a mutex as a global object doesn't work (the mutex gets
* destroyed, and then some later destructor calls OutputDebugStringF,
* maybe indirectly, and you get a core dump at shutdown trying to lock
* the mutex).
*/
static std::once_flag debugPrintInitFlag;
/**
* We use std::call_once() to make sure mutexDebugLog and
* vMsgsBeforeOpenLog are initialized in a thread-safe manner.
*
* NOTE: fileout, mutexDebugLog and sometimes vMsgsBeforeOpenLog
* are leaked on exit. This is ugly, but will be cleaned up by
* the OS/libc. When the shutdown sequence is fully audited and
* tested, explicit destruction of these objects can be implemented.
*/
static FILE* fileout = nullptr;
static std::mutex* mutexDebugLog = nullptr;
static std::list<std::string>* vMsgsBeforeOpenLog;
static int FileWriteStr(const std::string &str, FILE *fp)
{
return fwrite(str.data(), 1, str.size(), fp);
}
static void DebugPrintInit()
{
assert(mutexDebugLog == nullptr);
mutexDebugLog = new std::mutex();
vMsgsBeforeOpenLog = new std::list<std::string>;
}
fs::path GetDebugLogPath()
{
fs::path logfile(gArgs.GetArg("-debuglogfile", DEFAULT_DEBUGLOGFILE));
return AbsPathForConfigVal(logfile);
}
bool OpenDebugLog()
{
std::call_once(debugPrintInitFlag, &DebugPrintInit);
std::lock_guard<std::mutex> scoped_lock(*mutexDebugLog);
assert(fileout == nullptr);
assert(vMsgsBeforeOpenLog);
fs::path pathDebug = GetDebugLogPath();
fileout = fsbridge::fopen(pathDebug, "a");
if (!fileout) {
return false;
}
setbuf(fileout, nullptr); // unbuffered
// dump buffered messages from before we opened the log
while (!vMsgsBeforeOpenLog->empty()) {
FileWriteStr(vMsgsBeforeOpenLog->front(), fileout);
vMsgsBeforeOpenLog->pop_front();
}
delete vMsgsBeforeOpenLog;
vMsgsBeforeOpenLog = nullptr;
return true;
}
struct CLogCategoryDesc
{
uint64_t flag;
std::string category;
};
const CLogCategoryDesc LogCategories[] =
{
{BCLog::NONE, "0"},
{BCLog::NONE, "none"},
{BCLog::NET, "net"},
{BCLog::TOR, "tor"},
{BCLog::MEMPOOL, "mempool"},
{BCLog::HTTP, "http"},
{BCLog::BENCHMARK, "bench"},
{BCLog::ZMQ, "zmq"},
{BCLog::DB, "db"},
{BCLog::RPC, "rpc"},
{BCLog::ESTIMATEFEE, "estimatefee"},
{BCLog::ADDRMAN, "addrman"},
{BCLog::SELECTCOINS, "selectcoins"},
{BCLog::REINDEX, "reindex"},
{BCLog::CMPCTBLOCK, "cmpctblock"},
{BCLog::RANDOM, "rand"},
{BCLog::PRUNE, "prune"},
{BCLog::PROXY, "proxy"},
{BCLog::MEMPOOLREJ, "mempoolrej"},
{BCLog::LIBEVENT, "libevent"},
{BCLog::COINDB, "coindb"},
{BCLog::QT, "qt"},
{BCLog::LEVELDB, "leveldb"},
{BCLog::ALL, "1"},
{BCLog::ALL, "all"},
//Start Dash
{BCLog::CHAINLOCKS, "chainlocks"},
{BCLog::GOBJECT, "gobject"},
{BCLog::INSTANTSEND, "instantsend"},
{BCLog::KEEPASS, "keepass"},
{BCLog::LLMQ, "llmq"},
{BCLog::LLMQ_DKG, "llmq-dkg"},
{BCLog::LLMQ_SIGS, "llmq-sigs"},
{BCLog::MNPAYMENTS, "mnpayments"},
{BCLog::MNSYNC, "mnsync"},
{BCLog::PRIVATESEND, "privatesend"},
{BCLog::SPORK, "spork"},
{BCLog::NETCONN, "netconn"},
//End Dash
};
bool GetLogCategory(uint64_t *f, const std::string *str)
{
if (f && str) {
if (*str == "") {
*f = BCLog::ALL;
return true;
}
if (*str == "dash") {
*f = BCLog::CHAINLOCKS
| BCLog::GOBJECT
| BCLog::INSTANTSEND
| BCLog::KEEPASS
| BCLog::LLMQ
| BCLog::LLMQ_DKG
| BCLog::LLMQ_SIGS
| BCLog::MNPAYMENTS
| BCLog::MNSYNC
| BCLog::PRIVATESEND
| BCLog::SPORK;
return true;
}
for (unsigned int i = 0; i < ARRAYLEN(LogCategories); i++) {
if (LogCategories[i].category == *str) {
*f = LogCategories[i].flag;
return true;
}
}
}
return false;
}
std::string ListLogCategories()
{
std::string ret;
int outcount = 0;
for (unsigned int i = 0; i < ARRAYLEN(LogCategories); i++) {
// Omit the special cases.
if (LogCategories[i].flag != BCLog::NONE && LogCategories[i].flag != BCLog::ALL) {
if (outcount != 0) ret += ", ";
ret += LogCategories[i].category;
outcount++;
}
}
return ret;
}
std::vector<CLogCategoryActive> ListActiveLogCategories()
{
std::vector<CLogCategoryActive> ret;
for (unsigned int i = 0; i < ARRAYLEN(LogCategories); i++) {
// Omit the special cases.
if (LogCategories[i].flag != BCLog::NONE && LogCategories[i].flag != BCLog::ALL) {
CLogCategoryActive catActive;
catActive.category = LogCategories[i].category;
catActive.active = LogAcceptCategory(LogCategories[i].flag);
ret.push_back(catActive);
}
}
return ret;
}
std::string ListActiveLogCategoriesString()
{
if (logCategories == BCLog::NONE)
return "0";
if (logCategories == BCLog::ALL)
return "1";
std::string ret;
int outcount = 0;
for (unsigned int i = 0; i < ARRAYLEN(LogCategories); i++) {
// Omit the special cases.
if (LogCategories[i].flag != BCLog::NONE && LogCategories[i].flag != BCLog::ALL && LogAcceptCategory(LogCategories[i].flag)) {
if (outcount != 0) ret += ", ";
ret += LogCategories[i].category;
outcount++;
}
}
return ret;
}
/**
* fStartedNewLine is a state variable held by the calling context that will
* suppress printing of the timestamp when multiple calls are made that don't
* end in a newline. Initialize it to true, and hold it, in the calling context.
*/
static std::string LogTimestampStr(const std::string &str, std::atomic_bool *fStartedNewLine)
{
std::string strStamped;
if (!fLogTimestamps)
return str;
if (*fStartedNewLine) {
int64_t nTimeMicros = GetTimeMicros();
strStamped = DateTimeStrFormat("%Y-%m-%d %H:%M:%S", nTimeMicros/1000000);
if (fLogTimeMicros)
strStamped += strprintf(".%06d", nTimeMicros%1000000);
int64_t mocktime = GetMockTime();
if (mocktime) {
strStamped += " (mocktime: " + DateTimeStrFormat("%Y-%m-%d %H:%M:%S", mocktime) + ")";
}
strStamped += ' ' + str;
} else
strStamped = str;
return strStamped;
}
/**
* fStartedNewLine is a state variable held by the calling context that will
* suppress printing of the thread name when multiple calls are made that don't
* end in a newline. Initialize it to true, and hold/manage it, in the calling context.
*/
static std::string LogThreadNameStr(const std::string &str, std::atomic_bool *fStartedNewLine)
{
std::string strThreadLogged;
if (!fLogThreadNames)
return str;
std::string strThreadName = GetThreadName();
if (*fStartedNewLine)
strThreadLogged = strprintf("%16s | %s", strThreadName.c_str(), str.c_str());
else
strThreadLogged = str;
return strThreadLogged;
}
int LogPrintStr(const std::string &str)
{
int ret = 0; // Returns total number of characters written
static std::atomic_bool fStartedNewLine(true);
std::string strThreadLogged = LogThreadNameStr(str, &fStartedNewLine);
std::string strTimestamped = LogTimestampStr(strThreadLogged, &fStartedNewLine);
if (!str.empty() && str[str.size()-1] == '\n')
fStartedNewLine = true;
else
fStartedNewLine = false;
if (fPrintToConsole)
{
// print to console
ret = fwrite(strTimestamped.data(), 1, strTimestamped.size(), stdout);
fflush(stdout);
}
else if (fPrintToDebugLog)
{
std::call_once(debugPrintInitFlag, &DebugPrintInit);
std::lock_guard<std::mutex> scoped_lock(*mutexDebugLog);
// buffer if we haven't opened the log yet
if (fileout == nullptr) {
assert(vMsgsBeforeOpenLog);
ret = strTimestamped.length();
vMsgsBeforeOpenLog->push_back(strTimestamped);
}
else
{
// reopen the log file, if requested
if (fReopenDebugLog) {
fReopenDebugLog = false;
fs::path pathDebug = GetDebugLogPath();
if (fsbridge::freopen(pathDebug,"a",fileout) != nullptr)
setbuf(fileout, nullptr); // unbuffered
}
ret = FileWriteStr(strTimestamped, fileout);
}
}
return ret;
}
void ShrinkDebugFile()
{
// Amount of debug.log to save at end when shrinking (must fit in memory)
constexpr size_t RECENT_DEBUG_HISTORY_SIZE = 10 * 1000000;
// Scroll debug.log if it's getting too big
fs::path pathLog = GetDebugLogPath();
FILE* file = fsbridge::fopen(pathLog, "r");
// If debug.log file is more than 10% bigger the RECENT_DEBUG_HISTORY_SIZE
// trim it down by saving only the last RECENT_DEBUG_HISTORY_SIZE bytes
if (file && fs::file_size(pathLog) > 11 * (RECENT_DEBUG_HISTORY_SIZE / 10))
{
// Restart the file with some of the end
std::vector<char> vch(RECENT_DEBUG_HISTORY_SIZE, 0);
fseek(file, -((long)vch.size()), SEEK_END);
int nBytes = fread(vch.data(), 1, vch.size(), file);
fclose(file);
file = fsbridge::fopen(pathLog, "w");
if (file)
{
fwrite(vch.data(), 1, nBytes, file);
fclose(file);
}
}
else if (file != nullptr)
fclose(file);
}

161
src/logging.h Normal file
View File

@ -0,0 +1,161 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2018 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_LOGGING_H
#define BITCOIN_LOGGING_H
#include <fs.h>
#include <tinyformat.h>
#include <atomic>
#include <cstdint>
#include <string>
#include <vector>
static const bool DEFAULT_LOGTIMEMICROS = false;
static const bool DEFAULT_LOGIPS = false;
static const bool DEFAULT_LOGTIMESTAMPS = true;
static const bool DEFAULT_LOGTHREADNAMES = false;
extern const char * const DEFAULT_DEBUGLOGFILE;
extern bool fPrintToConsole;
extern bool fPrintToDebugLog;
extern bool fLogTimestamps;
extern bool fLogTimeMicros;
extern bool fLogThreadNames;
extern bool fLogIPs;
extern std::atomic<bool> fReopenDebugLog;
extern std::atomic<uint64_t> logCategories;
struct CLogCategoryActive
{
std::string category;
bool active;
};
namespace BCLog {
enum LogFlags : uint64_t {
NONE = 0,
NET = (1 << 0),
TOR = (1 << 1),
MEMPOOL = (1 << 2),
HTTP = (1 << 3),
BENCHMARK = (1 << 4),
ZMQ = (1 << 5),
DB = (1 << 6),
RPC = (1 << 7),
ESTIMATEFEE = (1 << 8),
ADDRMAN = (1 << 9),
SELECTCOINS = (1 << 10),
REINDEX = (1 << 11),
CMPCTBLOCK = (1 << 12),
RANDOM = (1 << 13),
PRUNE = (1 << 14),
PROXY = (1 << 15),
MEMPOOLREJ = (1 << 16),
LIBEVENT = (1 << 17),
COINDB = (1 << 18),
QT = (1 << 19),
LEVELDB = (1 << 20),
//Start Dash
CHAINLOCKS = ((uint64_t)1 << 32),
GOBJECT = ((uint64_t)1 << 33),
INSTANTSEND = ((uint64_t)1 << 34),
KEEPASS = ((uint64_t)1 << 35),
LLMQ = ((uint64_t)1 << 36),
LLMQ_DKG = ((uint64_t)1 << 37),
LLMQ_SIGS = ((uint64_t)1 << 38),
MNPAYMENTS = ((uint64_t)1 << 39),
MNSYNC = ((uint64_t)1 << 40),
PRIVATESEND = ((uint64_t)1 << 41),
SPORK = ((uint64_t)1 << 42),
NETCONN = ((uint64_t)1 << 43),
//End Dash
NET_NETCONN = NET | NETCONN, // use this to have something logged in NET and NETCONN as well
ALL = ~(uint64_t)0,
};
}
/** Return true if log accepts specified category */
static inline bool LogAcceptCategory(uint64_t category)
{
return (logCategories.load(std::memory_order_relaxed) & category) != 0;
}
/** Returns a string with the log categories. */
std::string ListLogCategories();
/** Returns a string with the list of active log categories */
std::string ListActiveLogCategoriesString();
/** Returns a vector of the active log categories. */
std::vector<CLogCategoryActive> ListActiveLogCategories();
/** Return true if str parses as a log category and set the flags in f */
bool GetLogCategory(uint64_t *f, const std::string *str);
/** Send a string to the log output */
int LogPrintStr(const std::string &str);
/** Formats a string without throwing exceptions. Instead, it'll return an error string instead of formatted string. */
template<typename... Args>
std::string SafeStringFormat(const std::string& fmt, const Args&... args)
{
try {
return tinyformat::format(fmt, args...);
} catch (std::runtime_error& fmterr) {
std::string message = tinyformat::format("\n****TINYFORMAT ERROR****\n err=\"%s\"\n fmt=\"%s\"\n", fmterr.what(), fmt);
fprintf(stderr, "%s", message.c_str());
return message;
}
}
/** Get format string from VA_ARGS for error reporting */
template<typename... Args> std::string FormatStringFromLogArgs(const char *fmt, const Args&... args) { return fmt; }
static inline void MarkUsed() {}
template<typename T, typename... Args> static inline void MarkUsed(const T& t, const Args&... args)
{
(void)t;
MarkUsed(args...);
}
// Be conservative when using LogPrintf/error or other things which
// unconditionally log to debug.log! It should not be the case that an inbound
// peer can fill up a user's disk with debug.log entries.
#ifdef USE_COVERAGE
#define LogPrintf(...) do { MarkUsed(__VA_ARGS__); } while(0)
#define LogPrint(category, ...) do { MarkUsed(__VA_ARGS__); } while(0)
#else
#define LogPrintf(...) do { \
if (fPrintToConsole || fPrintToDebugLog) { \
std::string _log_msg_; /* Unlikely name to avoid shadowing variables */ \
try { \
_log_msg_ = tfm::format(__VA_ARGS__); \
} catch (tinyformat::format_error &e) { \
/* Original format string will have newline so don't add one here */ \
_log_msg_ = "Error \"" + std::string(e.what()) + "\" while formatting log message: " + FormatStringFromLogArgs(__VA_ARGS__); \
} \
LogPrintStr(_log_msg_); \
} \
} while(0)
#define LogPrint(category, ...) do { \
if (LogAcceptCategory((category))) { \
LogPrintf(__VA_ARGS__); \
} \
} while(0)
#endif // USE_COVERAGE
fs::path GetDebugLogPath();
bool OpenDebugLog();
void ShrinkDebugFile();
#endif // BITCOIN_LOGGING_H

View File

@ -2,8 +2,8 @@
// Distributed under the MIT/X11 software license, see the accompanying // Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef ACTIVEMASTERNODE_H #ifndef BITCOIN_MASTERNODE_ACTIVEMASTERNODE_H
#define ACTIVEMASTERNODE_H #define BITCOIN_MASTERNODE_ACTIVEMASTERNODE_H
#include <chainparams.h> #include <chainparams.h>
#include <key.h> #include <key.h>
@ -63,4 +63,4 @@ private:
bool GetLocalAddress(CService& addrRet); bool GetLocalAddress(CService& addrRet);
}; };
#endif #endif // BITCOIN_MASTERNODE_ACTIVEMASTERNODE_H

View File

@ -2,8 +2,8 @@
// Distributed under the MIT/X11 software license, see the accompanying // Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef MASTERNODE_META_H #ifndef BITCOIN_MASTERNODE_MASTERNODE_META_H
#define MASTERNODE_META_H #define BITCOIN_MASTERNODE_MASTERNODE_META_H
#include <serialize.h> #include <serialize.h>
@ -158,4 +158,4 @@ public:
extern CMasternodeMetaMan mmetaman; extern CMasternodeMetaMan mmetaman;
#endif//MASTERNODE_META_H #endif // BITCOIN_MASTERNODE_MASTERNODE_META_H

View File

@ -2,8 +2,8 @@
// Distributed under the MIT/X11 software license, see the accompanying // Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef MASTERNODE_PAYMENTS_H #ifndef BITCOIN_MASTERNODE_MASTERNODE_PAYMENTS_H
#define MASTERNODE_PAYMENTS_H #define BITCOIN_MASTERNODE_MASTERNODE_PAYMENTS_H
#include <util.h> #include <util.h>
#include <core_io.h> #include <core_io.h>
@ -37,4 +37,4 @@ public:
bool GetMasternodeTxOuts(int nBlockHeight, CAmount blockReward, std::vector<CTxOut>& voutMasternodePaymentsRet) const; bool GetMasternodeTxOuts(int nBlockHeight, CAmount blockReward, std::vector<CTxOut>& voutMasternodePaymentsRet) const;
}; };
#endif #endif // BITCOIN_MASTERNODE_MASTERNODE_PAYMENTS_H

View File

@ -1,8 +1,8 @@
// Copyright (c) 2014-2019 The Dash Core developers // Copyright (c) 2014-2019 The Dash Core developers
// Distributed under the MIT/X11 software license, see the accompanying // Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef MASTERNODE_SYNC_H #ifndef BITCOIN_MASTERNODE_MASTERNODE_SYNC_H
#define MASTERNODE_SYNC_H #define BITCOIN_MASTERNODE_MASTERNODE_SYNC_H
#include <chain.h> #include <chain.h>
#include <net.h> #include <net.h>
@ -71,4 +71,4 @@ public:
void DoMaintenance(CConnman &connman); void DoMaintenance(CConnman &connman);
}; };
#endif #endif // BITCOIN_MASTERNODE_MASTERNODE_SYNC_H

View File

@ -2,8 +2,8 @@
// Distributed under the MIT/X11 software license, see the accompanying // Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef MASTERNODE_UTILS_H #ifndef BITCOIN_MASTERNODE_MASTERNODE_UTILS_H
#define MASTERNODE_UTILS_H #define BITCOIN_MASTERNODE_MASTERNODE_UTILS_H
#include <evo/deterministicmns.h> #include <evo/deterministicmns.h>
@ -16,4 +16,4 @@ public:
static void DoMaintenance(CConnman &connman); static void DoMaintenance(CConnman &connman);
}; };
#endif//MASTERNODE_UTILS_H #endif // BITCOIN_MASTERNODE_MASTERNODE_UTILS_H

View File

@ -2,8 +2,8 @@
// Distributed under the MIT/X11 software license, see the accompanying // Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef MESSAGESIGNER_H #ifndef BITCOIN_MESSAGESIGNER_H
#define MESSAGESIGNER_H #define BITCOIN_MESSAGESIGNER_H
#include <key.h> #include <key.h>
@ -35,4 +35,4 @@ public:
static bool VerifyHash(const uint256& hash, const CKeyID& keyID, const std::vector<unsigned char>& vchSig, std::string& strErrorRet); static bool VerifyHash(const uint256& hash, const CKeyID& keyID, const std::vector<unsigned char>& vchSig, std::string& strErrorRet);
}; };
#endif #endif // BITCOIN_MESSAGESIGNER_H

View File

@ -2,8 +2,8 @@
// Distributed under the MIT/X11 software license, see the accompanying // Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef NETFULFILLEDMAN_H #ifndef BITCOIN_NETFULFILLEDMAN_H
#define NETFULFILLEDMAN_H #define BITCOIN_NETFULFILLEDMAN_H
#include <netaddress.h> #include <netaddress.h>
#include <serialize.h> #include <serialize.h>
@ -50,4 +50,4 @@ public:
void DoMaintenance(); void DoMaintenance();
}; };
#endif #endif // BITCOIN_NETFULFILLEDMAN_H

View File

@ -2,8 +2,8 @@
// Copyright (c) 2009-2015 The Bitcoin Core developers // Copyright (c) 2009-2015 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying // Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_POLICYESTIMATOR_H #ifndef BITCOIN_POLICY_FEES_H
#define BITCOIN_POLICYESTIMATOR_H #define BITCOIN_POLICY_FEES_H
#include <amount.h> #include <amount.h>
#include <policy/feerate.h> #include <policy/feerate.h>
@ -273,4 +273,4 @@ private:
unsigned int MaxUsableEstimate() const; unsigned int MaxUsableEstimate() const;
}; };
#endif /*BITCOIN_POLICYESTIMATOR_H */ #endif // BITCOIN_POLICY_FEES_H

View File

@ -2,8 +2,8 @@
// Distributed under the MIT/X11 software license, see the accompanying // Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef PRIVATESENDCLIENT_H #ifndef BITCOIN_PRIVATESEND_PRIVATESEND_CLIENT_H
#define PRIVATESENDCLIENT_H #define BITCOIN_PRIVATESEND_PRIVATESEND_CLIENT_H
#include <privatesend/privatesend-util.h> #include <privatesend/privatesend-util.h>
#include <privatesend/privatesend.h> #include <privatesend/privatesend.h>
@ -261,4 +261,4 @@ public:
void GetJsonInfo(UniValue& obj) const; void GetJsonInfo(UniValue& obj) const;
}; };
#endif #endif // BITCOIN_PRIVATESEND_PRIVATESEND_CLIENT_H

View File

@ -2,8 +2,8 @@
// Distributed under the MIT/X11 software license, see the accompanying // Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef PRIVATESENDSERVER_H #ifndef BITCOIN_PRIVATESEND_PRIVATESEND_SERVER_H
#define PRIVATESENDSERVER_H #define BITCOIN_PRIVATESEND_PRIVATESEND_SERVER_H
#include <net.h> #include <net.h>
#include <privatesend/privatesend.h> #include <privatesend/privatesend.h>
@ -82,4 +82,4 @@ public:
void GetJsonInfo(UniValue& obj) const; void GetJsonInfo(UniValue& obj) const;
}; };
#endif #endif // BITCOIN_PRIVATESEND_PRIVATESEND_SERVER_H

View File

@ -2,8 +2,8 @@
// Distributed under the MIT/X11 software license, see the accompanying // Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef PRIVATESENDUTIL_H #ifndef BITCOIN_PRIVATESEND_PRIVATESEND_UTIL_H
#define PRIVATESENDUTIL_H #define BITCOIN_PRIVATESEND_PRIVATESEND_UTIL_H
#include <wallet/wallet.h> #include <wallet/wallet.h>
@ -34,4 +34,4 @@ public:
void KeepAll(); void KeepAll();
void ReturnAll(); void ReturnAll();
}; };
#endif //PRIVATESENDUTIL_H #endif // BITCOIN_PRIVATESEND_PRIVATESEND_UTIL_H

View File

@ -2,8 +2,8 @@
// Distributed under the MIT/X11 software license, see the accompanying // Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef PRIVATESEND_H #ifndef BITCOIN_PRIVATESEND_PRIVATESEND_H
#define PRIVATESEND_H #define BITCOIN_PRIVATESEND_PRIVATESEND_H
#include <bls/bls.h> #include <bls/bls.h>
#include <chain.h> #include <chain.h>
@ -475,4 +475,4 @@ public:
}; };
#endif #endif // BITCOIN_PRIVATESEND_PRIVATESEND_H

View File

@ -1,5 +1,5 @@
#ifndef MASTERNODELIST_H #ifndef BITCOIN_QT_MASTERNODELIST_H
#define MASTERNODELIST_H #define BITCOIN_QT_MASTERNODELIST_H
#include <qt/platformstyle.h> #include <qt/platformstyle.h>
#include <primitives/transaction.h> #include <primitives/transaction.h>
@ -76,4 +76,4 @@ private Q_SLOTS:
void handleMasternodeListChanged(); void handleMasternodeListChanged();
void updateDIP3ListScheduled(); void updateDIP3ListScheduled();
}; };
#endif // MASTERNODELIST_H #endif // BITCOIN_QT_MASTERNODELIST_H

View File

@ -2,6 +2,9 @@
// Distributed under the MIT software license, see the accompanying // Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_QT_TEST_PAYMENTREQUESTDATA_H
#define BITCOIN_QT_TEST_PAYMENTREQUESTDATA_H
// //
// Data for paymentservertests.cpp // Data for paymentservertests.cpp
// //
@ -458,3 +461,5 @@ iEBFUrBDJZU+UEezGwr7/zoECjo5ZY3PmtZcM2sILNjyweJF6XVzGqTxUw6pN6sW\
XR2T3Gy2LzRvhVA25QgGqpz0/juS2BtmNbsZPkN9gMMwKimgzc+PuCzmEKwPK9cQ\ XR2T3Gy2LzRvhVA25QgGqpz0/juS2BtmNbsZPkN9gMMwKimgzc+PuCzmEKwPK9cQ\
YQ==\ YQ==\
"; ";
#endif // BITCOIN_QT_TEST_PAYMENTREQUESTDATA_H

View File

@ -2,8 +2,8 @@
// Distributed under the MIT software license, see the accompanying // Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_QT_TEST_RPC_NESTED_TESTS_H #ifndef BITCOIN_QT_TEST_RPCNESTEDTESTS_H
#define BITCOIN_QT_TEST_RPC_NESTED_TESTS_H #define BITCOIN_QT_TEST_RPCNESTEDTESTS_H
#include <QObject> #include <QObject>
#include <QTest> #include <QTest>
@ -19,4 +19,4 @@ class RPCNestedTests : public QObject
void rpcNestedTests(); void rpcNestedTests();
}; };
#endif // BITCOIN_QT_TEST_RPC_NESTED_TESTS_H #endif // BITCOIN_QT_TEST_RPCNESTEDTESTS_H

View File

@ -1,5 +1,5 @@
#ifndef TRAFFICGRAPHDATATESTS_H #ifndef BITCOIN_QT_TEST_TRAFFICGRAPHDATATESTS_H
#define TRAFFICGRAPHDATATESTS_H #define BITCOIN_QT_TEST_TRAFFICGRAPHDATATESTS_H
#include <QObject> #include <QObject>
#include <QTest> #include <QTest>
@ -20,4 +20,4 @@ private Q_SLOTS:
}; };
#endif // TRAFFICGRAPHDATATESTS_H #endif // BITCOIN_QT_TEST_TRAFFICGRAPHDATATESTS_H

View File

@ -1,5 +1,5 @@
#ifndef TRAFFICGRAPHDATA_H #ifndef BITCOIN_QT_TRAFFICGRAPHDATA_H
#define TRAFFICGRAPHDATA_H #define BITCOIN_QT_TRAFFICGRAPHDATA_H
#include <QHash> #include <QHash>
#include <QQueue> #include <QQueue>
@ -88,4 +88,4 @@ private:
TrafficGraphData& operator=(TrafficGraphData const&); TrafficGraphData& operator=(TrafficGraphData const&);
}; };
#endif // TRAFFICGRAPHDATA_H #endif // BITCOIN_QT_TRAFFICGRAPHDATA_H

View File

@ -11,14 +11,15 @@
#include <compat.h> // for Windows API #include <compat.h> // for Windows API
#include <wincrypt.h> #include <wincrypt.h>
#endif #endif
#include <util.h> // for LogPrint() #include <logging.h> // for LogPrint()
#include <utilstrencodings.h> // for GetTime() #include <utiltime.h> // for GetTime()
#include <stdlib.h> #include <stdlib.h>
#include <chrono> #include <chrono>
#include <thread> #include <thread>
#ifndef WIN32 #ifndef WIN32
#include <fcntl.h>
#include <sys/time.h> #include <sys/time.h>
#endif #endif

View File

@ -3,8 +3,8 @@
// Distributed under the MIT software license, see the accompanying // Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_RPCCLIENT_H #ifndef BITCOIN_RPC_CLIENT_H
#define BITCOIN_RPCCLIENT_H #define BITCOIN_RPC_CLIENT_H
#include <univalue.h> #include <univalue.h>
@ -19,4 +19,4 @@ UniValue RPCConvertNamedValues(const std::string& strMethod, const std::vector<s
*/ */
UniValue ParseNonRFCJSONValue(const std::string& strVal); UniValue ParseNonRFCJSONValue(const std::string& strVal);
#endif // BITCOIN_RPCCLIENT_H #endif // BITCOIN_RPC_CLIENT_H

View File

@ -3,8 +3,8 @@
// Distributed under the MIT software license, see the accompanying // Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_RPCPROTOCOL_H #ifndef BITCOIN_RPC_PROTOCOL_H
#define BITCOIN_RPCPROTOCOL_H #define BITCOIN_RPC_PROTOCOL_H
#include <fs.h> #include <fs.h>
@ -104,4 +104,4 @@ void DeleteAuthCookie();
/** Parse JSON-RPC batch reply into a vector */ /** Parse JSON-RPC batch reply into a vector */
std::vector<UniValue> JSONRPCProcessBatchReply(const UniValue &in, size_t num); std::vector<UniValue> JSONRPCProcessBatchReply(const UniValue &in, size_t num);
#endif // BITCOIN_RPCPROTOCOL_H #endif // BITCOIN_RPC_PROTOCOL_H

View File

@ -2,8 +2,8 @@
// Distributed under the MIT software license, see the accompanying // Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_RPCREGISTER_H #ifndef BITCOIN_RPC_REGISTER_H
#define BITCOIN_RPCREGISTER_H #define BITCOIN_RPC_REGISTER_H
/** These are in one header file to avoid creating tons of single-function /** These are in one header file to avoid creating tons of single-function
* headers for everything under src/rpc/ */ * headers for everything under src/rpc/ */
@ -44,4 +44,4 @@ static inline void RegisterAllCoreRPCCommands(CRPCTable &t)
RegisterQuorumsRPCCommands(t); RegisterQuorumsRPCCommands(t);
} }
#endif #endif // BITCOIN_RPC_REGISTER_H

View File

@ -3,8 +3,8 @@
// Distributed under the MIT software license, see the accompanying // Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_RPCSERVER_H #ifndef BITCOIN_RPC_SERVER_H
#define BITCOIN_RPCSERVER_H #define BITCOIN_RPC_SERVER_H
#include <amount.h> #include <amount.h>
#include <rpc/protocol.h> #include <rpc/protocol.h>
@ -204,4 +204,4 @@ void InterruptRPC();
void StopRPC(); void StopRPC();
std::string JSONRPCExecBatch(const JSONRPCRequest& jreq, const UniValue& vReq); std::string JSONRPCExecBatch(const JSONRPCRequest& jreq, const UniValue& vReq);
#endif // BITCOIN_RPCSERVER_H #endif // BITCOIN_RPC_SERVER_H

View File

@ -2,8 +2,8 @@
// Distributed under the MIT software license, see the accompanying // Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef SALTEDHASHER_H #ifndef BITCOIN_SALTEDHASHER_H
#define SALTEDHASHER_H #define BITCOIN_SALTEDHASHER_H
#include <hash.h> #include <hash.h>
#include <uint256.h> #include <uint256.h>
@ -72,4 +72,4 @@ struct StaticSaltedHasher
} }
}; };
#endif//SALTEDHASHER_H #endif // BITCOIN_SALTEDHASHER_H

View File

@ -3,8 +3,8 @@
// Distributed under the MIT software license, see the accompanying // Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_BITCOINCONSENSUS_H #ifndef BITCOIN_SCRIPT_DASHCONSENSUS_H
#define BITCOIN_BITCOINCONSENSUS_H #define BITCOIN_SCRIPT_DASHCONSENSUS_H
#include <stdint.h> #include <stdint.h>
@ -74,4 +74,4 @@ EXPORT_SYMBOL unsigned int dashconsensus_version();
#undef EXPORT_SYMBOL #undef EXPORT_SYMBOL
#endif // BITCOIN_BITCOINCONSENSUS_H #endif // BITCOIN_SCRIPT_DASHCONSENSUS_H

View File

@ -2,8 +2,8 @@
// Distributed under the MIT/X11 software license, see the accompanying // Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef SPORK_H #ifndef BITCOIN_SPORK_H
#define SPORK_H #define BITCOIN_SPORK_H
#include <hash.h> #include <hash.h>
#include <net.h> #include <net.h>
@ -300,4 +300,4 @@ public:
std::string ToString() const; std::string ToString() const;
}; };
#endif #endif // BITCOIN_SPORK_H

View File

@ -2,8 +2,8 @@
// Distributed under the MIT/X11 software license, see the accompanying // Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef DASH_STACKTRACES_H #ifndef BITCOIN_STACKTRACES_H
#define DASH_STACKTRACES_H #define BITCOIN_STACKTRACES_H
#include <string> #include <string>
#include <sstream> #include <sstream>
@ -39,4 +39,4 @@ inline std::string GetExceptionWhat(const T& e)
void RegisterPrettyTerminateHander(); void RegisterPrettyTerminateHander();
void RegisterPrettySignalHandlers(); void RegisterPrettySignalHandlers();
#endif//DASH_STACKTRACES_H #endif//BITCOIN_STACKTRACES_H

View File

@ -4,13 +4,15 @@
#include <sync.h> #include <sync.h>
#include <memory> #include <logging.h>
#include <set>
#include <util.h>
#include <utilstrencodings.h> #include <utilstrencodings.h>
#include <stdio.h> #include <stdio.h>
#include <map>
#include <memory>
#include <set>
#ifdef DEBUG_LOCKCONTENTION #ifdef DEBUG_LOCKCONTENTION
#if !defined(HAVE_THREAD_LOCAL) #if !defined(HAVE_THREAD_LOCAL)
static_assert(false, "thread_local is not supported"); static_assert(false, "thread_local is not supported");

View File

@ -2,8 +2,8 @@
// Distributed under the MIT software license, see the accompanying // Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef DASH_UNORDERED_LRU_CACHE_H #ifndef BITCOIN_UNORDERED_LRU_CACHE_H
#define DASH_UNORDERED_LRU_CACHE_H #define BITCOIN_UNORDERED_LRU_CACHE_H
#include <unordered_map> #include <unordered_map>
@ -107,4 +107,4 @@ private:
} }
}; };
#endif // DASH_UNORDERED_LRU_CACHE_H #endif // BITCOIN_UNORDERED_LRU_CACHE_H

View File

@ -103,22 +103,11 @@ int nWalletBackups = 10;
const char * const BITCOIN_CONF_FILENAME = "dash.conf"; const char * const BITCOIN_CONF_FILENAME = "dash.conf";
const char * const BITCOIN_PID_FILENAME = "dashd.pid"; const char * const BITCOIN_PID_FILENAME = "dashd.pid";
const char * const DEFAULT_DEBUGLOGFILE = "debug.log";
ArgsManager gArgs; ArgsManager gArgs;
bool fPrintToConsole = false;
bool fPrintToDebugLog = true;
bool fLogTimestamps = DEFAULT_LOGTIMESTAMPS;
bool fLogTimeMicros = DEFAULT_LOGTIMEMICROS;
bool fLogThreadNames = DEFAULT_LOGTHREADNAMES;
bool fLogIPs = DEFAULT_LOGIPS;
std::atomic<bool> fReopenDebugLog(false);
CTranslationInterface translationInterface; CTranslationInterface translationInterface;
/** Log categories bitfield. */
std::atomic<uint64_t> logCategories(0);
/** Init OpenSSL library multithreading support */ /** Init OpenSSL library multithreading support */
static std::unique_ptr<CCriticalSection[]> ppmutexOpenSSL; static std::unique_ptr<CCriticalSection[]> ppmutexOpenSSL;
void locking_callback(int mode, int i, const char* file, int line) NO_THREAD_SAFETY_ANALYSIS void locking_callback(int mode, int i, const char* file, int line) NO_THREAD_SAFETY_ANALYSIS
@ -167,304 +156,6 @@ public:
} }
instance_of_cinit; instance_of_cinit;
/**
* LogPrintf() has been broken a couple of times now
* by well-meaning people adding mutexes in the most straightforward way.
* It breaks because it may be called by global destructors during shutdown.
* Since the order of destruction of static/global objects is undefined,
* defining a mutex as a global object doesn't work (the mutex gets
* destroyed, and then some later destructor calls OutputDebugStringF,
* maybe indirectly, and you get a core dump at shutdown trying to lock
* the mutex).
*/
static std::once_flag debugPrintInitFlag;
/**
* We use std::call_once() to make sure mutexDebugLog and
* vMsgsBeforeOpenLog are initialized in a thread-safe manner.
*
* NOTE: fileout, mutexDebugLog and sometimes vMsgsBeforeOpenLog
* are leaked on exit. This is ugly, but will be cleaned up by
* the OS/libc. When the shutdown sequence is fully audited and
* tested, explicit destruction of these objects can be implemented.
*/
static FILE* fileout = nullptr;
static std::mutex* mutexDebugLog = nullptr;
static std::list<std::string>* vMsgsBeforeOpenLog;
static int FileWriteStr(const std::string &str, FILE *fp)
{
return fwrite(str.data(), 1, str.size(), fp);
}
static void DebugPrintInit()
{
assert(mutexDebugLog == nullptr);
mutexDebugLog = new std::mutex();
vMsgsBeforeOpenLog = new std::list<std::string>;
}
fs::path GetDebugLogPath()
{
fs::path logfile(gArgs.GetArg("-debuglogfile", DEFAULT_DEBUGLOGFILE));
return AbsPathForConfigVal(logfile);
}
bool OpenDebugLog()
{
std::call_once(debugPrintInitFlag, &DebugPrintInit);
std::lock_guard<std::mutex> scoped_lock(*mutexDebugLog);
assert(fileout == nullptr);
assert(vMsgsBeforeOpenLog);
fs::path pathDebug = GetDebugLogPath();
fileout = fsbridge::fopen(pathDebug, "a");
if (!fileout) {
return false;
}
setbuf(fileout, nullptr); // unbuffered
// dump buffered messages from before we opened the log
while (!vMsgsBeforeOpenLog->empty()) {
FileWriteStr(vMsgsBeforeOpenLog->front(), fileout);
vMsgsBeforeOpenLog->pop_front();
}
delete vMsgsBeforeOpenLog;
vMsgsBeforeOpenLog = nullptr;
return true;
}
struct CLogCategoryDesc
{
uint64_t flag;
std::string category;
};
const CLogCategoryDesc LogCategories[] =
{
{BCLog::NONE, "0"},
{BCLog::NONE, "none"},
{BCLog::NET, "net"},
{BCLog::TOR, "tor"},
{BCLog::MEMPOOL, "mempool"},
{BCLog::HTTP, "http"},
{BCLog::BENCHMARK, "bench"},
{BCLog::ZMQ, "zmq"},
{BCLog::DB, "db"},
{BCLog::RPC, "rpc"},
{BCLog::ESTIMATEFEE, "estimatefee"},
{BCLog::ADDRMAN, "addrman"},
{BCLog::SELECTCOINS, "selectcoins"},
{BCLog::REINDEX, "reindex"},
{BCLog::CMPCTBLOCK, "cmpctblock"},
{BCLog::RANDOM, "rand"},
{BCLog::PRUNE, "prune"},
{BCLog::PROXY, "proxy"},
{BCLog::MEMPOOLREJ, "mempoolrej"},
{BCLog::LIBEVENT, "libevent"},
{BCLog::COINDB, "coindb"},
{BCLog::QT, "qt"},
{BCLog::LEVELDB, "leveldb"},
{BCLog::ALL, "1"},
{BCLog::ALL, "all"},
//Start Dash
{BCLog::CHAINLOCKS, "chainlocks"},
{BCLog::GOBJECT, "gobject"},
{BCLog::INSTANTSEND, "instantsend"},
{BCLog::KEEPASS, "keepass"},
{BCLog::LLMQ, "llmq"},
{BCLog::LLMQ_DKG, "llmq-dkg"},
{BCLog::LLMQ_SIGS, "llmq-sigs"},
{BCLog::MNPAYMENTS, "mnpayments"},
{BCLog::MNSYNC, "mnsync"},
{BCLog::PRIVATESEND, "privatesend"},
{BCLog::SPORK, "spork"},
{BCLog::NETCONN, "netconn"},
//End Dash
};
bool GetLogCategory(uint64_t *f, const std::string *str)
{
if (f && str) {
if (*str == "") {
*f = BCLog::ALL;
return true;
}
if (*str == "dash") {
*f = BCLog::CHAINLOCKS
| BCLog::GOBJECT
| BCLog::INSTANTSEND
| BCLog::KEEPASS
| BCLog::LLMQ
| BCLog::LLMQ_DKG
| BCLog::LLMQ_SIGS
| BCLog::MNPAYMENTS
| BCLog::MNSYNC
| BCLog::PRIVATESEND
| BCLog::SPORK;
return true;
}
for (unsigned int i = 0; i < ARRAYLEN(LogCategories); i++) {
if (LogCategories[i].category == *str) {
*f = LogCategories[i].flag;
return true;
}
}
}
return false;
}
std::string ListLogCategories()
{
std::string ret;
int outcount = 0;
for (unsigned int i = 0; i < ARRAYLEN(LogCategories); i++) {
// Omit the special cases.
if (LogCategories[i].flag != BCLog::NONE && LogCategories[i].flag != BCLog::ALL) {
if (outcount != 0) ret += ", ";
ret += LogCategories[i].category;
outcount++;
}
}
return ret;
}
std::vector<CLogCategoryActive> ListActiveLogCategories()
{
std::vector<CLogCategoryActive> ret;
for (unsigned int i = 0; i < ARRAYLEN(LogCategories); i++) {
// Omit the special cases.
if (LogCategories[i].flag != BCLog::NONE && LogCategories[i].flag != BCLog::ALL) {
CLogCategoryActive catActive;
catActive.category = LogCategories[i].category;
catActive.active = LogAcceptCategory(LogCategories[i].flag);
ret.push_back(catActive);
}
}
return ret;
}
std::string ListActiveLogCategoriesString()
{
if (logCategories == BCLog::NONE)
return "0";
if (logCategories == BCLog::ALL)
return "1";
std::string ret;
int outcount = 0;
for (unsigned int i = 0; i < ARRAYLEN(LogCategories); i++) {
// Omit the special cases.
if (LogCategories[i].flag != BCLog::NONE && LogCategories[i].flag != BCLog::ALL && LogAcceptCategory(LogCategories[i].flag)) {
if (outcount != 0) ret += ", ";
ret += LogCategories[i].category;
outcount++;
}
}
return ret;
}
/**
* fStartedNewLine is a state variable held by the calling context that will
* suppress printing of the timestamp when multiple calls are made that don't
* end in a newline. Initialize it to true, and hold/manage it, in the calling context.
*/
static std::string LogTimestampStr(const std::string &str, std::atomic_bool *fStartedNewLine)
{
std::string strStamped;
if (!fLogTimestamps)
return str;
if (*fStartedNewLine) {
int64_t nTimeMicros = GetTimeMicros();
strStamped = DateTimeStrFormat("%Y-%m-%d %H:%M:%S", nTimeMicros/1000000);
if (fLogTimeMicros)
strStamped += strprintf(".%06d", nTimeMicros%1000000);
int64_t mocktime = GetMockTime();
if (mocktime) {
strStamped += " (mocktime: " + DateTimeStrFormat("%Y-%m-%d %H:%M:%S", mocktime) + ")";
}
strStamped += ' ' + str;
} else
strStamped = str;
return strStamped;
}
/**
* fStartedNewLine is a state variable held by the calling context that will
* suppress printing of the thread name when multiple calls are made that don't
* end in a newline. Initialize it to true, and hold/manage it, in the calling context.
*/
static std::string LogThreadNameStr(const std::string &str, std::atomic_bool *fStartedNewLine)
{
std::string strThreadLogged;
if (!fLogThreadNames)
return str;
std::string strThreadName = GetThreadName();
if (*fStartedNewLine)
strThreadLogged = strprintf("%16s | %s", strThreadName.c_str(), str.c_str());
else
strThreadLogged = str;
return strThreadLogged;
}
int LogPrintStr(const std::string &str)
{
int ret = 0; // Returns total number of characters written
static std::atomic_bool fStartedNewLine(true);
std::string strThreadLogged = LogThreadNameStr(str, &fStartedNewLine);
std::string strTimestamped = LogTimestampStr(strThreadLogged, &fStartedNewLine);
if (!str.empty() && str[str.size()-1] == '\n')
fStartedNewLine = true;
else
fStartedNewLine = false;
if (fPrintToConsole)
{
// print to console
ret = fwrite(strTimestamped.data(), 1, strTimestamped.size(), stdout);
fflush(stdout);
}
else if (fPrintToDebugLog)
{
std::call_once(debugPrintInitFlag, &DebugPrintInit);
std::lock_guard<std::mutex> scoped_lock(*mutexDebugLog);
// buffer if we haven't opened the log yet
if (fileout == nullptr) {
assert(vMsgsBeforeOpenLog);
ret = strTimestamped.length();
vMsgsBeforeOpenLog->push_back(strTimestamped);
}
else
{
// reopen the log file, if requested
if (fReopenDebugLog) {
fReopenDebugLog = false;
fs::path pathDebug = GetDebugLogPath();
if (fsbridge::freopen(pathDebug,"a",fileout) != nullptr)
setbuf(fileout, nullptr); // unbuffered
}
ret = FileWriteStr(strTimestamped, fileout);
}
}
return ret;
}
/** A map that contains all the currently held directory locks. After /** A map that contains all the currently held directory locks. After
* successful locking, these will be held here until the global destructor * successful locking, these will be held here until the global destructor
* cleans them up and thus automatically unlocks them, or ReleaseDirectoryLocks * cleans them up and thus automatically unlocks them, or ReleaseDirectoryLocks
@ -1195,34 +886,6 @@ void AllocateFileRange(FILE *file, unsigned int offset, unsigned int length) {
#endif #endif
} }
void ShrinkDebugFile()
{
// Amount of debug.log to save at end when shrinking (must fit in memory)
constexpr size_t RECENT_DEBUG_HISTORY_SIZE = 10 * 1000000;
// Scroll debug.log if it's getting too big
fs::path pathLog = GetDebugLogPath();
FILE* file = fsbridge::fopen(pathLog, "r");
// If debug.log file is more than 10% bigger the RECENT_DEBUG_HISTORY_SIZE
// trim it down by saving only the last RECENT_DEBUG_HISTORY_SIZE bytes
if (file && fs::file_size(pathLog) > 11 * (RECENT_DEBUG_HISTORY_SIZE / 10))
{
// Restart the file with some of the end
std::vector<char> vch(RECENT_DEBUG_HISTORY_SIZE, 0);
fseek(file, -((long)vch.size()), SEEK_END);
int nBytes = fread(vch.data(), 1, vch.size(), file);
fclose(file);
file = fsbridge::fopen(pathLog, "w");
if (file)
{
fwrite(vch.data(), 1, nBytes, file);
fclose(file);
}
}
else if (file != nullptr)
fclose(file);
}
#ifdef WIN32 #ifdef WIN32
fs::path GetSpecialFolderPath(int nFolder, bool fCreate) fs::path GetSpecialFolderPath(int nFolder, bool fCreate)
{ {

View File

@ -6,7 +6,7 @@
/** /**
* Server/client environment: argument handling, config file parsing, * Server/client environment: argument handling, config file parsing,
* logging, thread wrappers, startup time * thread wrappers, startup time
*/ */
#ifndef BITCOIN_UTIL_H #ifndef BITCOIN_UTIL_H
#define BITCOIN_UTIL_H #define BITCOIN_UTIL_H
@ -17,6 +17,7 @@
#include <compat.h> #include <compat.h>
#include <fs.h> #include <fs.h>
#include <logging.h>
#include <sync.h> #include <sync.h>
#include <tinyformat.h> #include <tinyformat.h>
#include <utiltime.h> #include <utiltime.h>
@ -56,12 +57,6 @@ extern int nWalletBackups;
// Application startup time (used for uptime calculation) // Application startup time (used for uptime calculation)
int64_t GetStartupTime(); int64_t GetStartupTime();
static const bool DEFAULT_LOGTIMEMICROS = false;
static const bool DEFAULT_LOGIPS = false;
static const bool DEFAULT_LOGTIMESTAMPS = true;
static const bool DEFAULT_LOGTHREADNAMES = false;
extern const char * const DEFAULT_DEBUGLOGFILE;
/** Signals for translation. */ /** Signals for translation. */
class CTranslationInterface class CTranslationInterface
{ {
@ -70,21 +65,11 @@ public:
boost::signals2::signal<std::string (const char* psz)> Translate; boost::signals2::signal<std::string (const char* psz)> Translate;
}; };
extern bool fPrintToConsole;
extern bool fPrintToDebugLog;
extern bool fLogTimestamps;
extern bool fLogTimeMicros;
extern bool fLogThreadNames;
extern bool fLogIPs;
extern std::atomic<bool> fReopenDebugLog;
extern CTranslationInterface translationInterface; extern CTranslationInterface translationInterface;
extern const char * const BITCOIN_CONF_FILENAME; extern const char * const BITCOIN_CONF_FILENAME;
extern const char * const BITCOIN_PID_FILENAME; extern const char * const BITCOIN_PID_FILENAME;
extern std::atomic<uint64_t> logCategories;
/** /**
* Translation function: Call Translate signal on UI interface, which returns a boost::optional result. * Translation function: Call Translate signal on UI interface, which returns a boost::optional result.
* If no translation slot is registered, nothing is returned, and simply return the input. * If no translation slot is registered, nothing is returned, and simply return the input.
@ -98,128 +83,6 @@ inline std::string _(const char* psz)
void SetupEnvironment(); void SetupEnvironment();
bool SetupNetworking(); bool SetupNetworking();
struct CLogCategoryActive
{
std::string category;
bool active;
};
namespace BCLog {
enum LogFlags : uint64_t {
NONE = 0,
NET = (1 << 0),
TOR = (1 << 1),
MEMPOOL = (1 << 2),
HTTP = (1 << 3),
BENCHMARK = (1 << 4),
ZMQ = (1 << 5),
DB = (1 << 6),
RPC = (1 << 7),
ESTIMATEFEE = (1 << 8),
ADDRMAN = (1 << 9),
SELECTCOINS = (1 << 10),
REINDEX = (1 << 11),
CMPCTBLOCK = (1 << 12),
RANDOM = (1 << 13),
PRUNE = (1 << 14),
PROXY = (1 << 15),
MEMPOOLREJ = (1 << 16),
LIBEVENT = (1 << 17),
COINDB = (1 << 18),
QT = (1 << 19),
LEVELDB = (1 << 20),
//Start Dash
CHAINLOCKS = ((uint64_t)1 << 32),
GOBJECT = ((uint64_t)1 << 33),
INSTANTSEND = ((uint64_t)1 << 34),
KEEPASS = ((uint64_t)1 << 35),
LLMQ = ((uint64_t)1 << 36),
LLMQ_DKG = ((uint64_t)1 << 37),
LLMQ_SIGS = ((uint64_t)1 << 38),
MNPAYMENTS = ((uint64_t)1 << 39),
MNSYNC = ((uint64_t)1 << 40),
PRIVATESEND = ((uint64_t)1 << 41),
SPORK = ((uint64_t)1 << 42),
NETCONN = ((uint64_t)1 << 43),
//End Dash
NET_NETCONN = NET | NETCONN, // use this to have something logged in NET and NETCONN as well
ALL = ~(uint64_t)0,
};
}
static inline bool LogAcceptCategory(uint64_t category)
{
return (logCategories.load(std::memory_order_relaxed) & category) != 0;
}
/** Returns a string with the log categories. */
std::string ListLogCategories();
/** Returns a string with the list of active log categories */
std::string ListActiveLogCategoriesString();
/** Returns a vector of the active log categories. */
std::vector<CLogCategoryActive> ListActiveLogCategories();
/** Return true if str parses as a log category and set the flags in f */
bool GetLogCategory(uint64_t *f, const std::string *str);
/** Send a string to the log output */
int LogPrintStr(const std::string &str);
/** Formats a string without throwing exceptions. Instead, it'll return an error string instead of formatted string. */
template<typename... Args>
std::string SafeStringFormat(const std::string& fmt, const Args&... args)
{
try {
return tinyformat::format(fmt, args...);
} catch (std::runtime_error& fmterr) {
std::string message = tinyformat::format("\n****TINYFORMAT ERROR****\n err=\"%s\"\n fmt=\"%s\"\n", fmterr.what(), fmt);
fprintf(stderr, "%s", message.c_str());
return message;
}
}
/** Get format string from VA_ARGS for error reporting */
template<typename... Args> std::string FormatStringFromLogArgs(const char *fmt, const Args&... args) { return fmt; }
static inline void MarkUsed() {}
template<typename T, typename... Args> static inline void MarkUsed(const T& t, const Args&... args)
{
(void)t;
MarkUsed(args...);
}
// Be conservative when using LogPrintf/error or other things which
// unconditionally log to debug.log! It should not be the case that an inbound
// peer can fill up a user's disk with debug.log entries.
#ifdef USE_COVERAGE
#define LogPrintf(...) do { MarkUsed(__VA_ARGS__); } while(0)
#define LogPrint(category, ...) do { MarkUsed(__VA_ARGS__); } while(0)
#else
#define LogPrintf(...) do { \
if (fPrintToConsole || fPrintToDebugLog) { \
std::string _log_msg_; /* Unlikely name to avoid shadowing variables */ \
try { \
_log_msg_ = tfm::format(__VA_ARGS__); \
} catch (tinyformat::format_error &e) { \
/* Original format string will have newline so don't add one here */ \
_log_msg_ = "Error \"" + std::string(e.what()) + "\" while formatting log message: " + FormatStringFromLogArgs(__VA_ARGS__); \
} \
LogPrintStr(_log_msg_); \
} \
} while(0)
#define LogPrint(category, ...) do { \
if (LogAcceptCategory((category))) { \
LogPrintf(__VA_ARGS__); \
} \
} while(0)
#endif
template<typename... Args> template<typename... Args>
bool error(const char* fmt, const Args&... args) bool error(const char* fmt, const Args&... args)
{ {
@ -253,9 +116,6 @@ void CreatePidFile(const fs::path &path, pid_t pid);
#ifdef WIN32 #ifdef WIN32
fs::path GetSpecialFolderPath(int nFolder, bool fCreate = true); fs::path GetSpecialFolderPath(int nFolder, bool fCreate = true);
#endif #endif
fs::path GetDebugLogPath();
bool OpenDebugLog();
void ShrinkDebugFile();
void runCommand(const std::string& strCommand); void runCommand(const std::string& strCommand);
/** /**

View File

@ -2,8 +2,8 @@
// Distributed under the MIT software license, see the accompanying // Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_CONSENSUS_VERSIONBITS #ifndef BITCOIN_VERSIONBITS_H
#define BITCOIN_CONSENSUS_VERSIONBITS #define BITCOIN_VERSIONBITS_H
#include <chain.h> #include <chain.h>
#include <map> #include <map>
@ -79,4 +79,4 @@ BIP9Stats VersionBitsStatistics(const CBlockIndex* pindexPrev, const Consensus::
int VersionBitsStateSinceHeight(const CBlockIndex* pindexPrev, const Consensus::Params& params, Consensus::DeploymentPos pos, VersionBitsCache& cache); int VersionBitsStateSinceHeight(const CBlockIndex* pindexPrev, const Consensus::Params& params, Consensus::DeploymentPos pos, VersionBitsCache& cache);
uint32_t VersionBitsMask(const Consensus::Params& params, Consensus::DeploymentPos pos); uint32_t VersionBitsMask(const Consensus::Params& params, Consensus::DeploymentPos pos);
#endif #endif // BITCOIN_VERSIONBITS_H

View File

@ -2,8 +2,8 @@
// Distributed under the MIT software license, see the accompanying // Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_WALLET_TEST_FIXTURE_H #ifndef BITCOIN_WALLET_TEST_WALLET_TEST_FIXTURE_H
#define BITCOIN_WALLET_TEST_FIXTURE_H #define BITCOIN_WALLET_TEST_WALLET_TEST_FIXTURE_H
#include <test/test_dash.h> #include <test/test_dash.h>
@ -20,5 +20,4 @@ struct WalletTestingSetup: public TestingSetup {
CWallet m_wallet; CWallet m_wallet;
}; };
#endif #endif // BITCOIN_WALLET_TEST_WALLET_TEST_FIXTURE_H

View File

@ -2,8 +2,8 @@
// Distributed under the MIT software license, see the accompanying // Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef BITCOIN_WALLET_UTIL_H #ifndef BITCOIN_WALLET_WALLETUTIL_H
#define BITCOIN_WALLET_UTIL_H #define BITCOIN_WALLET_WALLETUTIL_H
#include <chainparamsbase.h> #include <chainparamsbase.h>
#include <util.h> #include <util.h>
@ -11,4 +11,4 @@
//! Get the path of the wallet directory. //! Get the path of the wallet directory.
fs::path GetWalletDir(); fs::path GetWalletDir();
#endif // BITCOIN_WALLET_UTIL_H #endif // BITCOIN_WALLET_WALLETUTIL_H

View File

@ -2,8 +2,8 @@
// Distributed under the MIT software license, see the accompanying // Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef WALLETINITINTERFACE_H #ifndef BITCOIN_WALLETINITINTERFACE_H
#define WALLETINITINTERFACE_H #define BITCOIN_WALLETINITINTERFACE_H
#include <string> #include <string>
@ -40,4 +40,4 @@ public:
virtual ~WalletInitInterface() {} virtual ~WalletInitInterface() {}
}; };
#endif // WALLETINITINTERFACE_H #endif // BITCOIN_WALLETINITINTERFACE_H