Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
61129e6483 |
No files matched your search
@@ -12,7 +12,7 @@ function HELP {
|
||||
echo "-q: compile the QT GUI (not working at present)"
|
||||
echo "-d: force a rebuild of dependencies"
|
||||
echo "-u: run the unit tests when done"
|
||||
echo "-g: compile in debug mode"
|
||||
echo "-g: include debug symbols"
|
||||
echo "-h: show help"
|
||||
exit 1
|
||||
}
|
||||
@@ -56,18 +56,16 @@ done
|
||||
|
||||
echo "Compiling with ${PARALLEL_JOBS} jobs in parallel."
|
||||
|
||||
BUILD_FLAGS=(CXXFLAGS="-O3 -march=native -g")
|
||||
DEBUG_DEPENDS=""
|
||||
BUILD_FLAGS=(CXXFLAGS="-O3 -march=native")
|
||||
if test "$COMPILE_WITH_DEBUG" = true; then
|
||||
BUILD_FLAGS=(--with-debug CXXFLAGS="-O0 -g")
|
||||
DEBUG_DEPENDS="DEBUG=1"
|
||||
BUILD_FLAGS=(--with-debug CXXFLAGS="-Og -g")
|
||||
fi
|
||||
|
||||
cd depends
|
||||
if test "$REBUILD_DEPENDENCIES" = true; then
|
||||
make clean
|
||||
fi
|
||||
make -j${PARALLEL_JOBS} ${DO_NOT_COMPILE_THE_GUI} ${DEBUG_DEPENDS} V=1
|
||||
make -j${PARALLEL_JOBS} ${DO_NOT_COMPILE_THE_GUI} V=1
|
||||
cd ..
|
||||
|
||||
LC_ALL=C autoreconf --install
|
||||
@@ -81,4 +79,4 @@ fi
|
||||
|
||||
if test $? -eq 0 && "$RUN_UNIT_TESTS" = true; then
|
||||
./src/test/test_lbrycrd
|
||||
fi
|
||||
fi
|
||||
+2
-2
@@ -2,8 +2,8 @@ dnl require autoconf 2.60 (AS_ECHO/AS_ECHO_N)
|
||||
AC_PREREQ([2.60])
|
||||
define(_CLIENT_VERSION_MAJOR, 0)
|
||||
define(_CLIENT_VERSION_MINOR, 17)
|
||||
define(_CLIENT_VERSION_REVISION, 4)
|
||||
define(_CLIENT_VERSION_BUILD, 1)
|
||||
define(_CLIENT_VERSION_REVISION, 3)
|
||||
define(_CLIENT_VERSION_BUILD, 2)
|
||||
define(_CLIENT_VERSION_IS_RELEASE, true)
|
||||
define(_COPYRIGHT_YEAR, 2019)
|
||||
define(_COPYRIGHT_HOLDERS,[The %s developers])
|
||||
|
||||
@@ -9,10 +9,10 @@ darwin_CXX=clang++ -target $(host) -mmacosx-version-min=$(OSX_MIN_VERSION) -isys
|
||||
darwin_CFLAGS=-pipe
|
||||
darwin_CXXFLAGS=$(darwin_CFLAGS) -std=c++11
|
||||
|
||||
darwin_release_CFLAGS=-O2 -g
|
||||
darwin_release_CFLAGS=-O2
|
||||
darwin_release_CXXFLAGS=$(darwin_release_CFLAGS)
|
||||
|
||||
darwin_debug_CFLAGS=-Og -g
|
||||
darwin_debug_CXXFLAGS=-O0 -g
|
||||
darwin_debug_CFLAGS=-Og
|
||||
darwin_debug_CXXFLAGS=$(darwin_debug_CFLAGS)
|
||||
|
||||
darwin_native_toolchain=native_cctools
|
||||
darwin_native_toolchain=native_cctools
|
||||
@@ -1,11 +1,11 @@
|
||||
linux_CFLAGS=-pipe
|
||||
linux_CXXFLAGS=$(linux_CFLAGS) -std=c++11
|
||||
|
||||
linux_release_CFLAGS=-O2 -g
|
||||
linux_release_CFLAGS=-O2
|
||||
linux_release_CXXFLAGS=$(linux_release_CFLAGS)
|
||||
|
||||
linux_debug_CFLAGS=-O1 -g
|
||||
linux_debug_CXXFLAGS=-O0 -g
|
||||
linux_debug_CFLAGS=-Og
|
||||
linux_debug_CXXFLAGS=$(linux_debug_CFLAGS)
|
||||
|
||||
linux_debug_CPPFLAGS=-D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
mingw32_CFLAGS=-pipe
|
||||
mingw32_CXXFLAGS=$(mingw32_CFLAGS) -std=c++11
|
||||
|
||||
mingw32_release_CFLAGS=-O2 -g
|
||||
mingw32_release_CFLAGS=-O2
|
||||
mingw32_release_CXXFLAGS=$(mingw32_release_CFLAGS)
|
||||
|
||||
mingw32_debug_CFLAGS=-O1 -g
|
||||
mingw32_debug_CXXFLAGS=-O0 -g
|
||||
mingw32_debug_CFLAGS=-O1
|
||||
mingw32_debug_CXXFLAGS=$(mingw32_debug_CFLAGS)
|
||||
|
||||
mingw32_debug_CPPFLAGS=-D_GLIBCXX_DEBUG -D_GLIBCXX_DEBUG_PEDANTIC
|
||||
@@ -1,6 +1,6 @@
|
||||
package=bdb
|
||||
$(package)_version=4.8.30
|
||||
$(package)_download_path=https://download.oracle.com/berkeley-db
|
||||
$(package)_download_path=http://download.oracle.com/berkeley-db
|
||||
$(package)_file_name=db-$($(package)_version).NC.tar.gz
|
||||
$(package)_sha256_hash=12edc0df75bf9abd7f82f821795bcee50f42cb2e5f76a6a281b85732798364ef
|
||||
$(package)_build_subdir=build_unix
|
||||
@@ -9,7 +9,6 @@ define $(package)_set_vars
|
||||
$(package)_config_opts=--disable-shared --enable-cxx --disable-replication
|
||||
$(package)_config_opts_mingw32=--enable-mingw
|
||||
$(package)_config_opts_linux=--with-pic
|
||||
$(package)_cppflags_mingw32=-DUNICODE -D_UNICODE
|
||||
endef
|
||||
|
||||
define $(package)_preprocess_cmds
|
||||
|
||||
@@ -21,6 +21,7 @@ define $(package)_preprocess_cmds
|
||||
PKG_CONFIG_SYSROOT_DIR=/ \
|
||||
PKG_CONFIG_LIBDIR=$(host_prefix)/lib/pkgconfig \
|
||||
PKG_CONFIG_PATH=$(host_prefix)/share/pkgconfig \
|
||||
sed -i.old 's/^GEN_DEPS.cc.*/& $(CXXFLAGS)/' source/config/mh-mingw* && \
|
||||
mkdir -p build && cd build && \
|
||||
../source/runConfigureICU Linux $($(package)_standard_opts) CXXFLAGS=-std=c++11 && \
|
||||
$(MAKE) && cd ..
|
||||
@@ -30,8 +31,6 @@ define $(package)_config_cmds
|
||||
PKG_CONFIG_SYSROOT_DIR=/ \
|
||||
PKG_CONFIG_LIBDIR=$(host_prefix)/lib/pkgconfig \
|
||||
PKG_CONFIG_PATH=$(host_prefix)/share/pkgconfig \
|
||||
sed -i.old 's/^GEN_DEPS.c=.*/& $($(package)_cflags)/' config/mh-mingw* && \
|
||||
sed -i.old 's/^GEN_DEPS.cc=.*/& $($(package)_cxxflags)/' config/mh-mingw* && \
|
||||
$($(package)_autoconf)
|
||||
endef
|
||||
|
||||
|
||||
@@ -27,5 +27,4 @@ define $(package)_stage_cmds
|
||||
endef
|
||||
|
||||
define $(package)_postprocess_cmds
|
||||
rm lib/*.la
|
||||
endef
|
||||
@@ -6,9 +6,7 @@ $(package)_sha256_hash=bcbabe1e2c7d0eec4ed612e10b94b112dd5f06fcefa994a0c79a45d83
|
||||
$(package)_patches=0001-fix-build-with-older-mingw64.patch 0002-disable-pthread_set_name_np.patch
|
||||
|
||||
define $(package)_set_vars
|
||||
$(package)_config_opts=--without-docs --disable-shared --without-libsodium --disable-curve --disable-curve-keygen --disable-perf --disable-Werror --disable-drafts
|
||||
$(package)_config_opts += --without-libsodium --without-libgssapi_krb5 --without-pgm --without-norm --without-vmci
|
||||
$(package)_config_opts += --disable-libunwind --disable-radix-tree --without-gcov
|
||||
$(package)_config_opts=--without-docs --disable-shared --without-libsodium --disable-curve --disable-curve-keygen --disable-perf --disable-Werror
|
||||
$(package)_config_opts_linux=--with-pic
|
||||
endef
|
||||
|
||||
@@ -32,5 +30,5 @@ endef
|
||||
|
||||
define $(package)_postprocess_cmds
|
||||
sed -i.old "s/ -lstdc++//" lib/pkgconfig/libzmq.pc && \
|
||||
rm -rf bin share lib/*.la
|
||||
rm -rf bin share
|
||||
endef
|
||||
+2
-2
@@ -166,10 +166,10 @@ public:
|
||||
consensus.vDeployments[Consensus::DEPLOYMENT_SEGWIT].nTimeout = 1548288000; // Jan 24, 2019
|
||||
|
||||
// The best chain should have at least this much work.
|
||||
consensus.nMinimumChainWork = uint256S("0000000000000000000000000000000000000000000002bfdb5232f364d6774e"); //700k
|
||||
consensus.nMinimumChainWork = uint256S("00000000000000000000000000000000000000000000024108e3204a44a57a5a"); //621000
|
||||
|
||||
// By default assume that the signatures in ancestors of this block are valid.
|
||||
consensus.defaultAssumeValid = uint256S("beaf6432c9a7be3ea8c333bd7a90d4b3e07b0f20c86aa2e5dfebc9eba340201c"); //700k
|
||||
consensus.defaultAssumeValid = uint256S("7899464514d0d8854919e87eb234fd5f0c35d06418bd5fd3c1a8f7092b2a9317"); //620000
|
||||
|
||||
/**
|
||||
* The message start string is designed to be unlikely to occur in normal data.
|
||||
|
||||
@@ -141,25 +141,25 @@ std::string CBaseBlob<BITS>::ToString() const
|
||||
template<uint32_t BITS>
|
||||
uint8_t* CBaseBlob<BITS>::begin() noexcept
|
||||
{
|
||||
return data.data();
|
||||
return data.begin();
|
||||
}
|
||||
|
||||
template<uint32_t BITS>
|
||||
const uint8_t* CBaseBlob<BITS>::begin() const noexcept
|
||||
{
|
||||
return data.data();
|
||||
return data.begin();
|
||||
}
|
||||
|
||||
template<uint32_t BITS>
|
||||
uint8_t* CBaseBlob<BITS>::end() noexcept
|
||||
{
|
||||
return data.data() + data.size();
|
||||
return data.end();
|
||||
}
|
||||
|
||||
template<uint32_t BITS>
|
||||
const uint8_t* CBaseBlob<BITS>::end() const noexcept
|
||||
{
|
||||
return data.data() + data.size();
|
||||
return data.end();
|
||||
}
|
||||
|
||||
template<uint32_t BITS>
|
||||
|
||||
+51
-22
@@ -436,21 +436,14 @@ uint256 CClaimTrieCacheBase::computeNodeHash(const std::string& name, int takeov
|
||||
|
||||
bool CClaimTrieCacheBase::checkConsistency()
|
||||
{
|
||||
auto checkQuery = db << "PRAGMA quick_check";
|
||||
for (auto&& row: checkQuery) {
|
||||
std::string message;
|
||||
row >> message;
|
||||
if (message != "ok") {
|
||||
logPrint << message << Clog::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// verify that all claims hash to the values on the nodes
|
||||
|
||||
// not checking everything as it takes too long
|
||||
auto query = db << "SELECT n.name, n.hash, "
|
||||
"IFNULL((SELECT CASE WHEN t.claimID IS NULL THEN 0 ELSE t.height END "
|
||||
"FROM takeover t WHERE t.name = n.name ORDER BY t.height DESC LIMIT 1), 0) FROM node n "
|
||||
"WHERE n.name IN (SELECT r.name FROM node r ORDER BY RANDOM() LIMIT 56789) OR LENGTH(n.parent) < 2";
|
||||
"COALESCE((SELECT CASE WHEN t.claimID IS NULL THEN 0 ELSE t.height END "
|
||||
"FROM takeover t WHERE t.name = n.name ORDER BY t.height DESC LIMIT 1), "
|
||||
"(SELECT ONE(c.activationHeight) FROM claim c WHERE c.nodeName = n.name "
|
||||
"AND c.activationHeight < ?1 AND c.expirationHeight >= ?1), "
|
||||
"0) FROM node n" << nNextHeight;
|
||||
for (auto&& row: query) {
|
||||
std::string name;
|
||||
uint256 hash;
|
||||
@@ -510,9 +503,12 @@ const std::string claimHashQuery_s =
|
||||
const std::string claimHashQueryLimit_s = claimHashQuery_s + " LIMIT 1";
|
||||
|
||||
extern const std::string proofClaimQuery_s =
|
||||
"SELECT n.name, IFNULL((SELECT CASE WHEN t.claimID IS NULL THEN 0 ELSE t.height END "
|
||||
"FROM takeover t WHERE t.name = n.name ORDER BY t.height DESC LIMIT 1), 0) FROM node n "
|
||||
"WHERE n.name IN (WITH RECURSIVE prefix(p) AS (VALUES(?) UNION ALL "
|
||||
"SELECT n.name, COALESCE((SELECT CASE WHEN t.claimID IS NULL THEN 0 ELSE t.height END "
|
||||
"FROM takeover t WHERE t.name = n.name ORDER BY t.height DESC LIMIT 1), "
|
||||
"(SELECT ONE(c.activationHeight) FROM claim c WHERE c.nodeName = n.name "
|
||||
"AND c.activationHeight < ?2 AND c.expirationHeight >= ?2), "
|
||||
"0) FROM node n "
|
||||
"WHERE n.name IN (WITH RECURSIVE prefix(p) AS (VALUES(?1) UNION ALL "
|
||||
"SELECT POPS(p) FROM prefix WHERE p != x'') SELECT p FROM prefix) "
|
||||
"ORDER BY n.name";
|
||||
|
||||
@@ -526,6 +522,17 @@ CClaimTrieCacheBase::CClaimTrieCacheBase(CClaimTrie* base)
|
||||
nNextHeight = base->nNextHeight;
|
||||
|
||||
applyPragmas(db, base->dbCacheBytes >> 10U); // in KB
|
||||
db.define("POPS", [](std::string s) -> std::string { if (!s.empty()) s.pop_back(); return s; });
|
||||
|
||||
// db.define("MERKLE_ROOT", [](std::vector<uint256>& hashes, const std::vector<unsigned char>& blob) { hashes.emplace_back(uint256(blob)); },
|
||||
// [](const std::vector<uint256>& hashes) { return ComputeMerkleRoot(hashes); });
|
||||
|
||||
db.define("ONE",
|
||||
[](std::vector<sqlite_int64>& accumulator, const sqlite_int64& value) { accumulator.push_back(value); },
|
||||
[](const std::vector<sqlite_int64>& accumulator) -> sqlite_int64 {
|
||||
if (accumulator.size() != 1) return 0;
|
||||
return accumulator[0];
|
||||
});
|
||||
}
|
||||
|
||||
void CClaimTrieCacheBase::ensureTransacting()
|
||||
@@ -554,8 +561,11 @@ uint256 CClaimTrieCacheBase::getMerkleHash()
|
||||
return hash;
|
||||
assert(transacting); // no data changed but we didn't have the root hash there already?
|
||||
auto updateQuery = db << "UPDATE node SET hash = ? WHERE name = ?";
|
||||
db << "SELECT n.name, IFNULL((SELECT CASE WHEN t.claimID IS NULL THEN 0 ELSE t.height END FROM takeover t WHERE t.name = n.name "
|
||||
"ORDER BY t.height DESC LIMIT 1), 0) FROM node n WHERE n.hash IS NULL ORDER BY LENGTH(n.name) DESC" // assumes n.name is blob
|
||||
db << "SELECT n.name, COALESCE((SELECT CASE WHEN t.claimID IS NULL THEN 0 ELSE t.height END "
|
||||
"FROM takeover t WHERE t.name = n.name ORDER BY t.height DESC LIMIT 1), "
|
||||
"(SELECT ONE(c.activationHeight) FROM claim c WHERE c.nodeName = n.name "
|
||||
"AND c.activationHeight < ?1 AND c.expirationHeight >= ?1), "
|
||||
"0) FROM node n WHERE n.hash IS NULL ORDER BY LENGTH(n.name) DESC" << nNextHeight
|
||||
>> [this, &hash, &updateQuery](const std::string& name, int takeoverHeight) {
|
||||
hash = computeNodeHash(name, takeoverHeight);
|
||||
updateQuery << hash << name;
|
||||
@@ -578,6 +588,16 @@ bool CClaimTrieCacheBase::getLastTakeoverForName(const std::string& name, uint16
|
||||
return true;
|
||||
}
|
||||
}
|
||||
auto query2 = db << "SELECT ONE(c.activationHeight), c.claimID FROM claim c WHERE c.nodeName = ?1 "
|
||||
"AND c.activationHeight < ?2 AND c.expirationHeight >= ?2" << name << nNextHeight;
|
||||
it = query2.begin();
|
||||
if (it != query2.end()) {
|
||||
*it >> takeoverHeight >> claimId;
|
||||
if (takeoverHeight > 0)
|
||||
return true;
|
||||
}
|
||||
|
||||
takeoverHeight = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -731,10 +751,13 @@ bool CClaimTrieCacheBase::incrementBlock()
|
||||
<< nNextHeight;
|
||||
|
||||
auto insertTakeoverQuery = db << "INSERT INTO takeover(name, height, claimID) VALUES(?, ?, ?)";
|
||||
auto checkExistingCountQuery = db << "SELECT COUNT(*) FROM (SELECT nodeName FROM claim WHERE nodeName = ?1 "
|
||||
"AND activationHeight <= ?2 AND expirationHeight > ?2 UNION ALL "
|
||||
"SELECT name FROM takeover WHERE name = ?1 LIMIT 2)";
|
||||
|
||||
// takeover handling:
|
||||
db << "SELECT name FROM node WHERE hash IS NULL"
|
||||
>> [this, &insertTakeoverQuery](const std::string& nameWithTakeover) {
|
||||
>> [this, &insertTakeoverQuery, &checkExistingCountQuery](const std::string& nameWithTakeover) {
|
||||
// if somebody activates on this block and they are the new best, then everybody activates on this block
|
||||
CClaimValue candidateValue;
|
||||
auto hasCandidate = getInfoForName(nameWithTakeover, candidateValue, 1);
|
||||
@@ -759,8 +782,13 @@ bool CClaimTrieCacheBase::incrementBlock()
|
||||
logPrint << "Takeover on " << nameWithTakeover << " at " << nNextHeight << ", happening: " << takeoverHappening << ", set before: " << hasCurrentWinner << Clog::endl;
|
||||
|
||||
if (takeoverHappening) {
|
||||
if (hasCandidate)
|
||||
insertTakeoverQuery << nameWithTakeover << nNextHeight << candidateValue.claimId;
|
||||
if (hasCandidate) {
|
||||
int64_t existing = 0;
|
||||
checkExistingCountQuery << nameWithTakeover << nNextHeight >> existing;
|
||||
checkExistingCountQuery++;
|
||||
if (existing != 1)
|
||||
insertTakeoverQuery << nameWithTakeover << nNextHeight << candidateValue.claimId;
|
||||
}
|
||||
else
|
||||
insertTakeoverQuery << nameWithTakeover << nNextHeight << nullptr;
|
||||
insertTakeoverQuery++;
|
||||
@@ -768,6 +796,7 @@ bool CClaimTrieCacheBase::incrementBlock()
|
||||
};
|
||||
|
||||
insertTakeoverQuery.used(true);
|
||||
checkExistingCountQuery.used(true);
|
||||
|
||||
nNextHeight++;
|
||||
return true;
|
||||
@@ -853,7 +882,7 @@ bool CClaimTrieCacheBase::getProofForName(const std::string& name, const uint160
|
||||
// cache the parent nodes
|
||||
getMerkleHash();
|
||||
proof = CClaimTrieProof();
|
||||
for (auto&& row: db << proofClaimQuery_s << name) {
|
||||
for (auto&& row: db << proofClaimQuery_s << name << nNextHeight) {
|
||||
CClaimValue claim;
|
||||
std::string key;
|
||||
int takeoverHeight;
|
||||
|
||||
+1
-8
@@ -102,15 +102,8 @@ typedef void* sockopt_arg_type;
|
||||
typedef char* sockopt_arg_type;
|
||||
#endif
|
||||
|
||||
// Note these both should work with the current usage of poll, but best to be safe
|
||||
// WIN32 poll is broken https://daniel.haxx.se/blog/2012/10/10/wsapoll-is-broken/
|
||||
// __APPLE__ poll is broke https://github.com/bitcoin/bitcoin/pull/14336#issuecomment-437384408
|
||||
#if defined(__linux__)
|
||||
#define USE_POLL
|
||||
#endif
|
||||
|
||||
bool static inline IsSelectableSocket(const SOCKET& s) {
|
||||
#if defined(USE_POLL) || defined(WIN32)
|
||||
#ifdef WIN32
|
||||
return true;
|
||||
#else
|
||||
return (s < FD_SETSIZE);
|
||||
|
||||
+4
-13
@@ -78,8 +78,6 @@ static const bool DEFAULT_STOPAFTERBLOCKIMPORT = false;
|
||||
std::unique_ptr<CConnman> g_connman;
|
||||
std::unique_ptr<PeerLogicValidation> peerLogic;
|
||||
|
||||
extern bool appIsFinance();
|
||||
|
||||
#if !(ENABLE_WALLET)
|
||||
class DummyWalletInit : public WalletInitInterface {
|
||||
public:
|
||||
@@ -394,7 +392,6 @@ void SetupServerArgs()
|
||||
#else
|
||||
hidden_args.emplace_back("-sysperms");
|
||||
#endif
|
||||
gArgs.AddArg("-finance", "Run daemon without claimtrie db", false, OptionsCategory::OPTIONS);
|
||||
gArgs.AddArg("-txindex", "Deprecated", false, OptionsCategory::HIDDEN);
|
||||
gArgs.AddArg("-addnode=<ip>", "Add a node to connect to and attempt to keep the connection open (see the `addnode` RPC command help for more info). This option can be specified multiple times to add multiple nodes.", false, OptionsCategory::CONNECTION);
|
||||
gArgs.AddArg("-banscore=<n>", strprintf("Threshold for disconnecting misbehaving peers (default: %u)", DEFAULT_BANSCORE_THRESHOLD), false, OptionsCategory::CONNECTION);
|
||||
@@ -944,13 +941,8 @@ bool AppInitParameterInteraction()
|
||||
|
||||
// Trim requested connection counts, to fit into system limitations
|
||||
// <int> in std::min<int>(...) to work around FreeBSD compilation issue described in #2695
|
||||
nMaxConnections = std::max(std::min<int>(nMaxConnections, FD_SETSIZE - nBind - MIN_CORE_FILEDESCRIPTORS - MAX_ADDNODE_CONNECTIONS), 0);
|
||||
nFD = RaiseFileDescriptorLimit(nMaxConnections + MIN_CORE_FILEDESCRIPTORS + MAX_ADDNODE_CONNECTIONS);
|
||||
#ifdef USE_POLL
|
||||
int fd_max = nFD;
|
||||
#else
|
||||
int fd_max = FD_SETSIZE;
|
||||
#endif
|
||||
nMaxConnections = std::max(std::min<int>(nMaxConnections, fd_max - nBind - MIN_CORE_FILEDESCRIPTORS - MAX_ADDNODE_CONNECTIONS), 0);
|
||||
if (nFD < MIN_CORE_FILEDESCRIPTORS)
|
||||
return InitError(_("Not enough file descriptors available."));
|
||||
nMaxConnections = std::min(nFD - MIN_CORE_FILEDESCRIPTORS - MAX_ADDNODE_CONNECTIONS, nMaxConnections);
|
||||
@@ -1221,8 +1213,6 @@ bool AppInitLockDataDirectory()
|
||||
return true;
|
||||
}
|
||||
|
||||
extern CChainState g_chainstate;
|
||||
|
||||
bool AppInitMain()
|
||||
{
|
||||
const CChainParams& chainparams = Params();
|
||||
@@ -1491,7 +1481,7 @@ bool AppInitMain()
|
||||
|
||||
// If the loaded chain has a wrong genesis, bail out immediately
|
||||
// (we're likely using a testnet datadir, or the other way around).
|
||||
if (!g_chainstate.mapBlockIndex.empty() && !LookupBlockIndex(chainparams.GetConsensus().hashGenesisBlock)) {
|
||||
if (!mapBlockIndex.empty() && !LookupBlockIndex(chainparams.GetConsensus().hashGenesisBlock)) {
|
||||
return InitError(_("Incorrect or no genesis block found. Wrong datadir for network?"));
|
||||
}
|
||||
|
||||
@@ -1554,7 +1544,7 @@ bool AppInitMain()
|
||||
|
||||
auto tip = chainActive.Tip();
|
||||
LogPrintf("Checking existing claim trie consistency...\n");
|
||||
if (tip && !appIsFinance() && !CClaimTrieCache(pclaimTrie).validateDb(tip->nHeight, tip->hashClaimTrie)) {
|
||||
if (tip && !CClaimTrieCache(pclaimTrie).validateDb(tip->nHeight, tip->hashClaimTrie)) {
|
||||
strLoadError = _("Error validating the stored claim trie");
|
||||
break;
|
||||
}
|
||||
@@ -1721,6 +1711,7 @@ bool AppInitMain()
|
||||
//// debug print
|
||||
{
|
||||
LOCK(cs_main);
|
||||
LogPrintf("mapBlockIndex.size() = %u\n", mapBlockIndex.size());
|
||||
chain_active_height = chainActive.Height();
|
||||
}
|
||||
LogPrintf("nBestHeight = %d\n", chain_active_height);
|
||||
|
||||
@@ -88,7 +88,8 @@ WalletTx MakeWalletTx(CWallet& wallet, const CWalletTx& wtx)
|
||||
WalletTxStatus MakeWalletTxStatus(const CWalletTx& wtx)
|
||||
{
|
||||
WalletTxStatus result;
|
||||
CBlockIndex* block = LookupBlockIndex(wtx.hashBlock);
|
||||
auto mi = ::mapBlockIndex.find(wtx.hashBlock);
|
||||
CBlockIndex* block = mi != ::mapBlockIndex.end() ? mi->second : nullptr;
|
||||
result.block_height = (block ? block->nHeight : std::numeric_limits<int>::max());
|
||||
result.blocks_to_maturity = wtx.GetBlocksToMaturity();
|
||||
result.depth_in_main_chain = wtx.GetDepthInMainChain();
|
||||
|
||||
+6
-56
@@ -26,10 +26,6 @@
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
|
||||
#ifdef USE_POLL
|
||||
#include <poll.h>
|
||||
#endif
|
||||
|
||||
#ifdef USE_UPNP
|
||||
#include <miniupnpc/miniupnpc.h>
|
||||
#include <miniupnpc/miniwget.h>
|
||||
@@ -39,7 +35,6 @@
|
||||
|
||||
|
||||
#include <math.h>
|
||||
#include <unordered_map>
|
||||
|
||||
// Dump addresses to peers.dat and banlist.dat every 15 minutes (900s)
|
||||
#define DUMP_ADDRESSES_INTERVAL 900
|
||||
@@ -76,10 +71,6 @@ enum BindFlags {
|
||||
BF_WHITELIST = (1U << 2),
|
||||
};
|
||||
|
||||
// The set of sockets cannot be modified while waiting
|
||||
// The sleep time needs to be small to avoid new sockets stalling
|
||||
static const uint64_t SELECT_TIMEOUT_MILLISECONDS = 50;
|
||||
|
||||
const static std::string NET_MESSAGE_COMMAND_OTHER = "*other*";
|
||||
|
||||
static const uint64_t RANDOMIZER_ID_NETGROUP = 0x6c0edd8036ef4036ULL; // SHA256("netgroup")[0:8]
|
||||
@@ -1241,34 +1232,23 @@ void CConnman::ThreadSocketHandler()
|
||||
//
|
||||
// Find which sockets have data to receive
|
||||
//
|
||||
struct timeval timeout;
|
||||
timeout.tv_sec = 0;
|
||||
timeout.tv_usec = 50000; // frequency to poll pnode->vSend
|
||||
|
||||
fd_set fdsetRecv;
|
||||
fd_set fdsetSend;
|
||||
fd_set fdsetError;
|
||||
FD_ZERO(&fdsetRecv);
|
||||
FD_ZERO(&fdsetSend);
|
||||
FD_ZERO(&fdsetError);
|
||||
|
||||
#ifdef USE_POLL
|
||||
std::unordered_map<SOCKET, struct pollfd> pollfds;
|
||||
#else
|
||||
struct timeval timeout;
|
||||
timeout.tv_sec = 0;
|
||||
timeout.tv_usec = SELECT_TIMEOUT_MILLISECONDS * 1000; // frequency to poll pnode->vSend
|
||||
|
||||
SOCKET hSocketMax = 0;
|
||||
bool have_fds = false;
|
||||
#endif
|
||||
|
||||
for (const ListenSocket& hListenSocket : vhListenSocket) {
|
||||
#ifdef USE_POLL
|
||||
pollfds[hListenSocket.socket].fd = hListenSocket.socket;
|
||||
pollfds[hListenSocket.socket].events = POLLIN;
|
||||
pollfds[hListenSocket.socket].revents = 0;
|
||||
#else
|
||||
FD_SET(hListenSocket.socket, &fdsetRecv);
|
||||
hSocketMax = std::max(hSocketMax, hListenSocket.socket);
|
||||
have_fds = true;
|
||||
#endif
|
||||
}
|
||||
|
||||
{
|
||||
@@ -1297,51 +1277,24 @@ void CConnman::ThreadSocketHandler()
|
||||
if (pnode->hSocket == INVALID_SOCKET)
|
||||
continue;
|
||||
|
||||
#ifdef USE_POLL
|
||||
pollfds[pnode->hSocket].fd = pnode->hSocket;
|
||||
pollfds[pnode->hSocket].events = POLLERR|POLLHUP;
|
||||
pollfds[pnode->hSocket].revents = 0;
|
||||
#else
|
||||
FD_SET(pnode->hSocket, &fdsetError);
|
||||
hSocketMax = std::max(hSocketMax, pnode->hSocket);
|
||||
have_fds = true;
|
||||
#endif
|
||||
|
||||
if (select_send) {
|
||||
#ifdef USE_POLL
|
||||
pollfds[pnode->hSocket].events |= POLLOUT;
|
||||
#else
|
||||
FD_SET(pnode->hSocket, &fdsetSend);
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
if (select_recv) {
|
||||
#ifdef USE_POLL
|
||||
pollfds[pnode->hSocket].events |= POLLIN;
|
||||
#else
|
||||
FD_SET(pnode->hSocket, &fdsetRecv);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef USE_POLL
|
||||
std::vector<struct pollfd> vpollfds;
|
||||
vpollfds.reserve(pollfds.size());
|
||||
for (auto it : pollfds)
|
||||
vpollfds.push_back(std::move(it.second));
|
||||
|
||||
if (poll(vpollfds.data(), vpollfds.size(), SELECT_TIMEOUT_MILLISECONDS) < 0)
|
||||
return;
|
||||
|
||||
for (struct pollfd pollfd_entry : vpollfds) {
|
||||
if (pollfd_entry.revents & POLLIN) FD_SET(pollfd_entry.fd, &fdsetRecv);
|
||||
if (pollfd_entry.revents & POLLOUT) FD_SET(pollfd_entry.fd, &fdsetSend);
|
||||
if (pollfd_entry.revents & (POLLERR|POLLHUP)) FD_SET(pollfd_entry.fd, &fdsetError);
|
||||
}
|
||||
#else
|
||||
int nSelect = select(have_fds ? hSocketMax + 1 : 0,
|
||||
&fdsetRecv, &fdsetSend, &fdsetError, &timeout);
|
||||
if (interruptNet)
|
||||
return;
|
||||
|
||||
if (nSelect == SOCKET_ERROR)
|
||||
{
|
||||
@@ -1357,10 +1310,7 @@ void CConnman::ThreadSocketHandler()
|
||||
if (!interruptNet.sleep_for(std::chrono::milliseconds(timeout.tv_usec/1000)))
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (interruptNet)
|
||||
return;
|
||||
//
|
||||
// Accept new connections
|
||||
//
|
||||
|
||||
+1
-24
@@ -19,10 +19,6 @@
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
|
||||
#ifdef USE_POLL
|
||||
#include <poll.h>
|
||||
#endif
|
||||
|
||||
#include <boost/algorithm/string/case_conv.hpp> // for to_lower()
|
||||
|
||||
#if !defined(MSG_NOSIGNAL)
|
||||
@@ -268,22 +264,11 @@ static IntrRecvError InterruptibleRecv(uint8_t* data, size_t len, int timeout, c
|
||||
if (!IsSelectableSocket(hSocket)) {
|
||||
return IntrRecvError::NetworkError;
|
||||
}
|
||||
// Only wait at most maxWait milliseconds at a time, unless
|
||||
// we're approaching the end of the specified total timeout
|
||||
int timeout_ms = std::min(endTime - curTime, maxWait);
|
||||
#ifdef USE_POLL
|
||||
struct pollfd pollfd;
|
||||
pollfd.fd = hSocket;
|
||||
pollfd.events = POLLIN;
|
||||
pollfd.revents = 0;
|
||||
int nRet = poll(&pollfd, 1, timeout_ms);
|
||||
#else
|
||||
struct timeval tval = MillisToTimeval(timeout_ms);
|
||||
struct timeval tval = MillisToTimeval(std::min(endTime - curTime, maxWait));
|
||||
fd_set fdset;
|
||||
FD_ZERO(&fdset);
|
||||
FD_SET(hSocket, &fdset);
|
||||
int nRet = select(hSocket + 1, &fdset, nullptr, nullptr, &tval);
|
||||
#endif
|
||||
if (nRet == SOCKET_ERROR) {
|
||||
return IntrRecvError::NetworkError;
|
||||
}
|
||||
@@ -514,19 +499,11 @@ bool ConnectSocketDirectly(const CService &addrConnect, const SOCKET& hSocket, i
|
||||
// WSAEINVAL is here because some legacy version of winsock uses it
|
||||
if (nErr == WSAEINPROGRESS || nErr == WSAEWOULDBLOCK || nErr == WSAEINVAL)
|
||||
{
|
||||
#ifdef USE_POLL
|
||||
struct pollfd pollfd;
|
||||
pollfd.fd = hSocket;
|
||||
pollfd.events = POLLIN | POLLOUT;
|
||||
pollfd.revents = 0;
|
||||
int nRet = poll(&pollfd, 1, nTimeout);
|
||||
#else
|
||||
struct timeval timeout = MillisToTimeval(nTimeout);
|
||||
fd_set fdset;
|
||||
FD_ZERO(&fdset);
|
||||
FD_SET(hSocket, &fdset);
|
||||
int nRet = select(hSocket + 1, nullptr, &fdset, nullptr, &timeout);
|
||||
#endif
|
||||
if (nRet == 0)
|
||||
{
|
||||
LogPrint(BCLog::NET, "connection to %s timeout\n", addrConnect.ToString());
|
||||
|
||||
@@ -1299,8 +1299,6 @@ struct CompareBlocksByHeight
|
||||
}
|
||||
};
|
||||
|
||||
extern CChainState g_chainstate;
|
||||
|
||||
static UniValue getchaintips(const JSONRPCRequest& request)
|
||||
{
|
||||
if (request.fHelp || request.params.size() != 0)
|
||||
@@ -1349,7 +1347,7 @@ static UniValue getchaintips(const JSONRPCRequest& request)
|
||||
std::set<const CBlockIndex*> setOrphans;
|
||||
std::set<const CBlockIndex*> setPrevs;
|
||||
|
||||
for (const auto& item : g_chainstate.mapBlockIndex)
|
||||
for (const std::pair<const uint256, CBlockIndex*>& item : mapBlockIndex)
|
||||
{
|
||||
if (!chainActive.Contains(item.second)) {
|
||||
setOrphans.insert(item.second);
|
||||
|
||||
@@ -288,7 +288,7 @@ CLAIM_OUTPUT
|
||||
"]",
|
||||
|
||||
// GETCLAIMPROOFBYBID
|
||||
S1("getclaimproofbybid \"" T_NAME "\" ( " T_BID " \"" T_BLOCKHASH R"(" )
|
||||
S1("getclaimproofbyid \"" T_NAME "\" ( " T_BID " \"" T_BLOCKHASH R"(" )
|
||||
Return the cryptographic proof that a name maps to a value or doesn't by a bid.
|
||||
Arguments:)")
|
||||
S3("1. ", T_NAME, NAME_TEXT)
|
||||
|
||||
@@ -33,15 +33,16 @@ void ParseClaimtrieId(const UniValue& v, std::string& claimId, const std::string
|
||||
|
||||
static CBlockIndex* BlockHashIndex(const uint256& blockHash)
|
||||
{
|
||||
auto index = LookupBlockIndex(blockHash);
|
||||
AssertLockHeld(cs_main);
|
||||
|
||||
if (index == nullptr)
|
||||
if (mapBlockIndex.count(blockHash) == 0)
|
||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
|
||||
|
||||
if (!chainActive.Contains(index))
|
||||
CBlockIndex* pblockIndex = mapBlockIndex[blockHash];
|
||||
if (!chainActive.Contains(pblockIndex))
|
||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "Block not in main chain");
|
||||
|
||||
return index;
|
||||
return pblockIndex;
|
||||
}
|
||||
|
||||
#define MAX_RPC_BLOCK_DECREMENTS 500
|
||||
@@ -881,11 +882,8 @@ static const CRPCCommand commands[] =
|
||||
{ "Claimtrie", "checknormalization", &checknormalization, { T_NAME } },
|
||||
};
|
||||
|
||||
extern bool appIsFinance();
|
||||
|
||||
void RegisterClaimTrieRPCCommands(CRPCTable &tableRPC)
|
||||
{
|
||||
if (!appIsFinance())
|
||||
for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++)
|
||||
tableRPC.appendCommand(commands[vcidx].name, &commands[vcidx]);
|
||||
for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++)
|
||||
tableRPC.appendCommand(commands[vcidx].name, &commands[vcidx]);
|
||||
}
|
||||
+1
-5
@@ -990,12 +990,8 @@ static const CRPCCommand commands[] =
|
||||
{ "hidden", "estimaterawfee", &estimaterawfee, {"conf_target", "threshold"} },
|
||||
};
|
||||
|
||||
extern bool appIsFinance();
|
||||
|
||||
void RegisterMiningRPCCommands(CRPCTable &t)
|
||||
{
|
||||
for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++)
|
||||
if (!appIsFinance() || (commands[vcidx].name != "getblocktemplate"
|
||||
&& commands[vcidx].name != "generatetoaddress"))
|
||||
t.appendCommand(commands[vcidx].name, &commands[vcidx]);
|
||||
t.appendCommand(commands[vcidx].name, &commands[vcidx]);
|
||||
}
|
||||
+15
-19
@@ -361,33 +361,29 @@ bool CBlockTreeDB::LoadBlockIndexGuts(const Consensus::Params& consensusParams,
|
||||
{
|
||||
auto query = db << "SELECT hash, prevHash, height, file, dataPos, undoPos, txCount, "
|
||||
"version, rootTxHash, rootTrieHash, time, bits, nonce, status "
|
||||
"FROM block_info ORDER BY height";
|
||||
"FROM block_info"; // insertBlockIndex puts them in order
|
||||
|
||||
// Load mapBlockIndex
|
||||
for (auto&& row: query) {
|
||||
boost::this_thread::interruption_point();
|
||||
// Construct block index object
|
||||
uint256 hash, prevHash;
|
||||
row >> hash >> prevHash;
|
||||
CBlockIndex* pindexNew = insertBlockIndex(hash);
|
||||
pindexNew->pprev = insertBlockIndex(prevHash);
|
||||
|
||||
row >> pindexNew->nHeight
|
||||
>> pindexNew->nFile
|
||||
>> pindexNew->nDataPos
|
||||
>> pindexNew->nUndoPos
|
||||
>> pindexNew->nTx
|
||||
>> pindexNew->nVersion
|
||||
>> pindexNew->hashMerkleRoot
|
||||
>> pindexNew->hashClaimTrie
|
||||
>> pindexNew->nTime
|
||||
>> pindexNew->nBits
|
||||
>> pindexNew->nNonce
|
||||
>> pindexNew->nStatus;
|
||||
|
||||
if ((pindexNew->nHeight & 0x3ff) == 0x3ff) { // don't check for shutdown on every single block
|
||||
boost::this_thread::interruption_point();
|
||||
if (ShutdownRequested())
|
||||
return false;
|
||||
}
|
||||
row >> pindexNew->nHeight;
|
||||
row >> pindexNew->nFile;
|
||||
row >> pindexNew->nDataPos;
|
||||
row >> pindexNew->nUndoPos;
|
||||
row >> pindexNew->nTx;
|
||||
row >> pindexNew->nVersion;
|
||||
row >> pindexNew->hashMerkleRoot;
|
||||
row >> pindexNew->hashClaimTrie;
|
||||
row >> pindexNew->nTime;
|
||||
row >> pindexNew->nBits;
|
||||
row >> pindexNew->nNonce;
|
||||
row >> pindexNew->nStatus;
|
||||
|
||||
pindexNew->nChainTx = pindexNew->pprev ? pindexNew->pprev->nChainTx + pindexNew->nTx : pindexNew->nTx;
|
||||
|
||||
|
||||
+26
-53
@@ -46,7 +46,6 @@
|
||||
#include <warnings.h>
|
||||
|
||||
#include <cmath>
|
||||
#include <functional>
|
||||
#include <future>
|
||||
#include <sstream>
|
||||
|
||||
@@ -63,6 +62,7 @@
|
||||
CChainState g_chainstate;
|
||||
CCriticalSection cs_main;
|
||||
|
||||
BlockMap& mapBlockIndex = g_chainstate.mapBlockIndex;
|
||||
CChain& chainActive = g_chainstate.chainActive;
|
||||
CBlockIndex *pindexBestHeader = nullptr;
|
||||
CWaitableCriticalSection g_best_block_mutex;
|
||||
@@ -98,22 +98,6 @@ CScript COINBASE_FLAGS;
|
||||
|
||||
const std::string strMessageMagic = "LBRYcrd Signed Message:\n";
|
||||
|
||||
bool appIsFinance()
|
||||
{
|
||||
static const auto finance = []() -> bool {
|
||||
auto finance = gArgs.GetBoolArg("-finance", false);
|
||||
if (finance)
|
||||
LogPrintf("NOTE: daemon is running without claimtrie functionality\n");
|
||||
return finance;
|
||||
}();
|
||||
return finance;
|
||||
}
|
||||
|
||||
const std::function<bool(const uint256&, const uint256&)> hashComp =
|
||||
[](const uint256& lhs, const uint256& rhs) {
|
||||
return appIsFinance() || lhs == rhs;
|
||||
};
|
||||
|
||||
// Internal stuff
|
||||
namespace {
|
||||
CBlockIndex *&pindexBestInvalid = g_chainstate.pindexBestInvalid;
|
||||
@@ -1527,7 +1511,7 @@ int ApplyTxInUndo(unsigned int index, CTxUndo& txUndo, CCoinsViewCache& view, CC
|
||||
DisconnectResult CChainState::DisconnectBlock(const CBlock& block, const CBlockIndex* pindex, CCoinsViewCache& view, CClaimTrieCache& trieCache)
|
||||
{
|
||||
assert(pindex->GetBlockHash() == view.GetBestBlock());
|
||||
if (!hashComp(pindex->hashClaimTrie, trieCache.getMerkleHash())) {
|
||||
if (pindex->hashClaimTrie != trieCache.getMerkleHash()) {
|
||||
LogPrintf("%s: Indexed claim hash doesn't match current: %s vs %s\n",
|
||||
__func__, pindex->hashClaimTrie.ToString(), trieCache.getMerkleHash().ToString());
|
||||
assert(false);
|
||||
@@ -1601,7 +1585,7 @@ DisconnectResult CChainState::DisconnectBlock(const CBlock& block, const CBlockI
|
||||
// move best block pointer to prevout block
|
||||
view.SetBestBlock(pindex->pprev->GetBlockHash());
|
||||
assert(trieCache.finalizeDecrement());
|
||||
if (!hashComp(trieCache.getMerkleHash(), pindex->pprev->hashClaimTrie)) {
|
||||
if (trieCache.getMerkleHash() != pindex->pprev->hashClaimTrie) {
|
||||
LogPrintf("Hash comparison failure at block %d\n", pindex->nHeight);
|
||||
assert(false);
|
||||
}
|
||||
@@ -1814,7 +1798,7 @@ bool CChainState::ConnectBlock(const CBlock& block, CValidationState& state, CBl
|
||||
assert(hashPrevBlock == view.GetBestBlock());
|
||||
|
||||
// also verify that the trie cache's current state corresponds to the previous block
|
||||
if (pindex->pprev != nullptr && !hashComp(pindex->pprev->hashClaimTrie, trieCache.getMerkleHash())) {
|
||||
if (pindex->pprev != nullptr && pindex->pprev->hashClaimTrie != trieCache.getMerkleHash()) {
|
||||
LogPrintf("%s: Previous block claim hash doesn't match current: %s vs %s\n",
|
||||
__func__, pindex->pprev->hashClaimTrie.ToString(), trieCache.getMerkleHash().ToString());
|
||||
assert(false);
|
||||
@@ -2076,7 +2060,7 @@ bool CChainState::ConnectBlock(const CBlock& block, CValidationState& state, CBl
|
||||
// TODO: if the "just check" flag is set, we should reduce the work done here. Incrementing blocks twice per mine is not efficient.
|
||||
assert(trieCache.incrementBlock());
|
||||
|
||||
if (!hashComp(trieCache.getMerkleHash(), block.hashClaimTrie)) {
|
||||
if (trieCache.getMerkleHash() != block.hashClaimTrie) {
|
||||
return state.DoS(100, error("ConnectBlock() : the merkle root of the claim trie does not match "
|
||||
"(actual=%s vs block=%s on height=%d)", trieCache.getMerkleHash().GetHex(),
|
||||
block.hashClaimTrie.GetHex(), pindex->nHeight), REJECT_INVALID, "bad-claim-merkle-hash");
|
||||
@@ -2367,10 +2351,8 @@ bool CChainState::DisconnectTip(CValidationState& state, const CChainParams& cha
|
||||
return error("DisconnectTip(): DisconnectBlock %s failed", pindexDelete->GetBlockHash().ToString());
|
||||
bool flushed = view.Flush();
|
||||
assert(flushed);
|
||||
if (!appIsFinance()) {
|
||||
assert(trieCache.flush());
|
||||
assert(pindexDelete->pprev->hashClaimTrie == trieCache.getMerkleHash());
|
||||
}
|
||||
assert(trieCache.flush());
|
||||
assert(pindexDelete->pprev->hashClaimTrie == trieCache.getMerkleHash());
|
||||
}
|
||||
LogPrint(BCLog::BENCH, "- Disconnect block: %.2fms\n", (GetTimeMicros() - nStart) * MILLI);
|
||||
// Write the chain state to disk, if necessary.
|
||||
@@ -2509,10 +2491,8 @@ bool CChainState::ConnectTip(CValidationState& state, const CChainParams& chainp
|
||||
LogPrint(BCLog::BENCH, " - Connect total: %.2fms [%.2fs (%.2fms/blk)]\n", (nTime3 - nTime2) * MILLI, nTimeConnectTotal * MICRO, nTimeConnectTotal * MILLI / nBlocksTotal);
|
||||
bool flushed = view.Flush();
|
||||
assert(flushed);
|
||||
if (!appIsFinance()) {
|
||||
flushed = trieCache.flush();
|
||||
assert(flushed);
|
||||
}
|
||||
flushed = trieCache.flush();
|
||||
assert(flushed);
|
||||
|
||||
// for verifying that rollback code works:
|
||||
// auto result = DisconnectBlock(blockConnecting, pindexNew, view, trieCache);
|
||||
@@ -3682,7 +3662,7 @@ void PruneOneBlockFile(const int fileNumber)
|
||||
{
|
||||
LOCK(cs_LastBlockFile);
|
||||
|
||||
for (const auto& entry : g_chainstate.mapBlockIndex) {
|
||||
for (const auto& entry : mapBlockIndex) {
|
||||
CBlockIndex* pindex = entry.second;
|
||||
if (pindex->nFile == fileNumber) {
|
||||
pindex->nStatus &= ~BLOCK_HAVE_DATA;
|
||||
@@ -3877,18 +3857,18 @@ CBlockIndex * CChainState::InsertBlockIndex(const uint256& hash)
|
||||
{
|
||||
AssertLockHeld(cs_main);
|
||||
|
||||
// Return existing
|
||||
auto mi = mapBlockIndex.find(hash);
|
||||
if (mi != mapBlockIndex.end())
|
||||
return mi->second;
|
||||
|
||||
if (hash.IsNull())
|
||||
return nullptr;
|
||||
|
||||
// Return existing
|
||||
BlockMap::iterator mi = mapBlockIndex.find(hash);
|
||||
if (mi != mapBlockIndex.end())
|
||||
return (*mi).second;
|
||||
|
||||
// Create new
|
||||
CBlockIndex* pindexNew = new CBlockIndex();
|
||||
mi = mapBlockIndex.insert(std::make_pair(hash, pindexNew)).first;
|
||||
pindexNew->phashBlock = &(mi->first);
|
||||
pindexNew->phashBlock = &((*mi).first);
|
||||
|
||||
return pindexNew;
|
||||
}
|
||||
@@ -3970,14 +3950,14 @@ bool static LoadBlockIndexDB(const CChainParams& chainparams) EXCLUSIVE_LOCKS_RE
|
||||
// Check presence of blk files
|
||||
LogPrintf("Checking all blk files are present...\n");
|
||||
std::set<int> setBlkDataFiles;
|
||||
for (const std::pair<const uint256, CBlockIndex*>& item : g_chainstate.mapBlockIndex)
|
||||
for (const std::pair<const uint256, CBlockIndex*>& item : mapBlockIndex)
|
||||
{
|
||||
CBlockIndex* pindex = item.second;
|
||||
if (pindex->nStatus & BLOCK_HAVE_DATA) {
|
||||
setBlkDataFiles.insert(pindex->nFile);
|
||||
}
|
||||
}
|
||||
for (auto it = setBlkDataFiles.begin(); it != setBlkDataFiles.end(); ++it)
|
||||
for (std::set<int>::iterator it = setBlkDataFiles.begin(); it != setBlkDataFiles.end(); it++)
|
||||
{
|
||||
CDiskBlockPos pos(*it, 0);
|
||||
if (CAutoFile(OpenBlockFile(pos, true), SER_DISK, CLIENT_VERSION).IsNull()) {
|
||||
@@ -4004,7 +3984,7 @@ bool LoadChainTip(const CChainParams& chainparams)
|
||||
|
||||
if (chainActive.Tip() && chainActive.Tip()->GetBlockHash() == pcoinsTip->GetBestBlock()) return true;
|
||||
|
||||
if (pcoinsTip->GetBestBlock().IsNull() && g_chainstate.mapBlockIndex.size() == 1) {
|
||||
if (pcoinsTip->GetBestBlock().IsNull() && mapBlockIndex.size() == 1) {
|
||||
// In case we just added the genesis block, connect it now, so
|
||||
// that we always have a chainActive.Tip() when we return.
|
||||
LogPrintf("%s: Connecting genesis block...\n", __func__);
|
||||
@@ -4219,8 +4199,7 @@ bool CChainState::ReplayBlocks(const CChainParams& params, CCoinsView* view)
|
||||
|
||||
cache.SetBestBlock(pindexNew->GetBlockHash());
|
||||
cache.Flush();
|
||||
if (!appIsFinance())
|
||||
trieCache.flush();
|
||||
trieCache.flush();
|
||||
uiInterface.ShowProgress("", 100, false);
|
||||
return true;
|
||||
}
|
||||
@@ -4365,10 +4344,10 @@ void UnloadBlockIndex()
|
||||
warningcache[b].clear();
|
||||
}
|
||||
|
||||
for (BlockMap::value_type& entry : g_chainstate.mapBlockIndex) {
|
||||
for (BlockMap::value_type& entry : mapBlockIndex) {
|
||||
delete entry.second;
|
||||
}
|
||||
g_chainstate.mapBlockIndex.clear();
|
||||
mapBlockIndex.clear();
|
||||
fHavePruned = false;
|
||||
|
||||
g_chainstate.UnloadBlockIndex();
|
||||
@@ -4381,7 +4360,7 @@ bool LoadBlockIndex(const CChainParams& chainparams)
|
||||
if (!fReindex) {
|
||||
bool ret = LoadBlockIndexDB(chainparams);
|
||||
if (!ret) return false;
|
||||
needs_init = g_chainstate.mapBlockIndex.empty();
|
||||
needs_init = mapBlockIndex.empty();
|
||||
|
||||
if (needs_init) {
|
||||
auto blockDir = GetDataDir() / "blocks";
|
||||
@@ -4920,21 +4899,15 @@ double GuessVerificationProgress(const ChainTxData& data, const CBlockIndex *pin
|
||||
return pindex->nChainTx / fTxTotal;
|
||||
}
|
||||
|
||||
CBlockIndex *LookupBlockIndex(const uint256 &hash) {
|
||||
AssertLockHeld(cs_main);
|
||||
auto it = g_chainstate.mapBlockIndex.find(hash);
|
||||
return it == g_chainstate.mapBlockIndex.end() ? nullptr : it->second;
|
||||
}
|
||||
|
||||
class CMainCleanup
|
||||
{
|
||||
public:
|
||||
CMainCleanup() {}
|
||||
~CMainCleanup() {
|
||||
// block headers
|
||||
auto it1 = g_chainstate.mapBlockIndex.begin();
|
||||
for (; it1 != g_chainstate.mapBlockIndex.end(); ++it1)
|
||||
BlockMap::iterator it1 = mapBlockIndex.begin();
|
||||
for (; it1 != mapBlockIndex.end(); it1++)
|
||||
delete (*it1).second;
|
||||
g_chainstate.mapBlockIndex.clear();
|
||||
mapBlockIndex.clear();
|
||||
}
|
||||
} instance_of_cmaincleanup;
|
||||
+14
-3
@@ -139,12 +139,18 @@ static const bool DEFAULT_PEERBLOOMFILTERS = true;
|
||||
/** Default for -stopatheight */
|
||||
static const int DEFAULT_STOPATHEIGHT = 0;
|
||||
|
||||
struct BlockHasher
|
||||
{
|
||||
size_t operator()(const uint256& hash) const { return GetCheapHash(hash); }
|
||||
};
|
||||
|
||||
extern CScript COINBASE_FLAGS;
|
||||
extern CCriticalSection cs_main;
|
||||
extern CBlockPolicyEstimator feeEstimator;
|
||||
extern CTxMemPool mempool;
|
||||
extern std::atomic_bool g_is_mempool_loaded;
|
||||
typedef std::map<uint256, CBlockIndex*> BlockMap;
|
||||
typedef std::unordered_map<uint256, CBlockIndex*, BlockHasher> BlockMap;
|
||||
extern BlockMap& mapBlockIndex;
|
||||
extern uint64_t nLastBlockTx;
|
||||
extern uint64_t nLastBlockWeight;
|
||||
extern const std::string strMessageMagic;
|
||||
@@ -459,7 +465,7 @@ public:
|
||||
|
||||
/**
|
||||
* If a block header hasn't already been seen, call CheckBlockHeader on it, ensure
|
||||
* that it doesn't descend from an invalid block, and then add it to mapBlockIndex.
|
||||
* that it doesn't descend from an invalid block, and then add it to mapBlockIndex.
|
||||
*/
|
||||
bool AcceptBlockHeader(const CBlockHeader& block, CValidationState& state, const CChainParams& chainparams, CBlockIndex** ppindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||
bool AcceptBlock(const std::shared_ptr<const CBlock>& pblock, CValidationState& state, const CChainParams& chainparams, CBlockIndex** ppindex, bool fRequested, const CDiskBlockPos* dbp, bool* fNewBlock) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||
@@ -591,7 +597,12 @@ public:
|
||||
/** Replay blocks that aren't fully applied to the database. */
|
||||
bool ReplayBlocks(const CChainParams& params, CCoinsView* view);
|
||||
|
||||
CBlockIndex* LookupBlockIndex(const uint256& hash);
|
||||
inline CBlockIndex* LookupBlockIndex(const uint256& hash)
|
||||
{
|
||||
AssertLockHeld(cs_main);
|
||||
BlockMap::const_iterator it = mapBlockIndex.find(hash);
|
||||
return it == mapBlockIndex.end() ? nullptr : it->second;
|
||||
}
|
||||
|
||||
/** Find the last common block between the parameter chain and a locator. */
|
||||
CBlockIndex* FindForkInGlobalIndex(const CChain& chain, const CBlockLocator& locator);
|
||||
|
||||
+4
-5
@@ -469,10 +469,10 @@ bool BerkeleyEnvironment::Salvage(const std::string& strFile, bool fAggressive,
|
||||
}
|
||||
|
||||
|
||||
void BerkeleyEnvironment::CheckpointLSN(const std::string& strFile, bool lsnReset)
|
||||
void BerkeleyEnvironment::CheckpointLSN(const std::string& strFile)
|
||||
{
|
||||
dbenv->txn_checkpoint(0, 0, 0);
|
||||
if (fMockDb || !lsnReset)
|
||||
if (fMockDb)
|
||||
return;
|
||||
dbenv->lsn_reset(strFile.c_str(), 0);
|
||||
}
|
||||
@@ -799,10 +799,9 @@ bool BerkeleyBatch::PeriodicFlush(BerkeleyDatabase& database)
|
||||
|
||||
// Flush wallet file so it's self contained
|
||||
env->CloseDb(strFile);
|
||||
// don't call lsn_reset at periodic time
|
||||
// it causes performace issues on big wallets
|
||||
env->CheckpointLSN(strFile, /* lsnReset */ false);
|
||||
env->CheckpointLSN(strFile);
|
||||
|
||||
env->mapFileUseCount.erase(mi++);
|
||||
LogPrint(BCLog::DB, "Flushed %s %dms\n", strFile, GetTimeMillis() - nStart);
|
||||
ret = true;
|
||||
}
|
||||
|
||||
+1
-1
@@ -83,7 +83,7 @@ public:
|
||||
bool Open(bool retry);
|
||||
void Close();
|
||||
void Flush(bool fShutdown);
|
||||
void CheckpointLSN(const std::string& strFile, bool lsnReset = true);
|
||||
void CheckpointLSN(const std::string& strFile);
|
||||
|
||||
void CloseDb(const std::string& strFile);
|
||||
void ReloadDbEnv();
|
||||
|
||||
+1
-1
@@ -245,7 +245,7 @@ void WalletInit::Start(CScheduler& scheduler) const
|
||||
}
|
||||
|
||||
// Run a thread to flush wallet periodically
|
||||
scheduler.scheduleEvery(MaybeCompactWalletDB, 1000);
|
||||
scheduler.scheduleEvery(MaybeCompactWalletDB, 500);
|
||||
}
|
||||
|
||||
void WalletInit::Flush() const
|
||||
|
||||
+15
-11
@@ -765,19 +765,23 @@ void ListNameClaims(const CWalletTx& wtx, CWallet* const pwallet, const std::str
|
||||
|
||||
CClaimTrieCache trieCache(pclaimTrie);
|
||||
|
||||
auto pindex = LookupBlockIndex(wtx.hashBlock);
|
||||
if (pindex)
|
||||
auto it = mapBlockIndex.find(wtx.hashBlock);
|
||||
if (it != mapBlockIndex.end())
|
||||
{
|
||||
entry.pushKV("height", pindex->nHeight);
|
||||
entry.pushKV("expiration height", pindex->nHeight + trieCache.expirationTime());
|
||||
if (pindex->nHeight + trieCache.expirationTime() > chainActive.Height())
|
||||
CBlockIndex* pindex = it->second;
|
||||
if (pindex)
|
||||
{
|
||||
entry.pushKV("expired", false);
|
||||
entry.pushKV("blocks to expiration", pindex->nHeight + trieCache.expirationTime() - chainActive.Height());
|
||||
}
|
||||
else
|
||||
{
|
||||
entry.pushKV("expired", true);
|
||||
entry.pushKV("height", pindex->nHeight);
|
||||
entry.pushKV("expiration height", pindex->nHeight + trieCache.expirationTime());
|
||||
if (pindex->nHeight + trieCache.expirationTime() > chainActive.Height())
|
||||
{
|
||||
entry.pushKV("expired", false);
|
||||
entry.pushKV("blocks to expiration", pindex->nHeight + trieCache.expirationTime() - chainActive.Height());
|
||||
}
|
||||
else
|
||||
{
|
||||
entry.pushKV("expired", true);
|
||||
}
|
||||
}
|
||||
}
|
||||
entry.pushKV("confirmations", wtx.GetDepthInMainChain());
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
#ifndef BITCOIN_WALLET_RPCWALLET_H
|
||||
#define BITCOIN_WALLET_RPCWALLET_H
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
class CRPCTable;
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
@@ -11,6 +13,7 @@
|
||||
#include <test/test_bitcoin.h>
|
||||
#include <validation.h>
|
||||
#include <wallet/coincontrol.h>
|
||||
#include <wallet/test/wallet_test_fixture.h>
|
||||
#include <policy/policy.h>
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
@@ -122,7 +125,7 @@ void rollbackBlock(const std::vector<uint256>& ids) {
|
||||
}
|
||||
// totally weird that invalidateblock is async
|
||||
while (GetMainSignals().CallbacksPending())
|
||||
MilliSleep(5);
|
||||
usleep(5000);
|
||||
}
|
||||
|
||||
uint256 AbandonAClaim(const uint256& txid, bool isSupport = false) {
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
extern UniValue importmulti(const JSONRPCRequest& request);
|
||||
extern UniValue dumpwallet(const JSONRPCRequest& request);
|
||||
extern UniValue importwallet(const JSONRPCRequest& request);
|
||||
extern CChainState g_chainstate;
|
||||
|
||||
BOOST_FIXTURE_TEST_SUITE(wallet_tests, WalletTestingSetup)
|
||||
|
||||
@@ -207,7 +206,7 @@ static int64_t AddTx(CWallet& wallet, uint32_t lockTime, int64_t mockTime, int64
|
||||
CBlockIndex* block = nullptr;
|
||||
if (blockTime > 0) {
|
||||
LOCK(cs_main);
|
||||
auto inserted = g_chainstate.mapBlockIndex.emplace(GetRandHash(), new CBlockIndex);
|
||||
auto inserted = mapBlockIndex.emplace(GetRandHash(), new CBlockIndex);
|
||||
assert(inserted.second);
|
||||
const uint256& hash = inserted.first->first;
|
||||
block = inserted.first->second;
|
||||
|
||||
Reference in new issue
Block a user