Compare commits
14
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cb48bc3f2a | ||
|
|
83319b7f31 | ||
|
|
6b8935718e | ||
|
|
05d89e91cf | ||
|
|
43214bc6d2 | ||
|
|
15b61996b5 | ||
|
|
328ee12e8b | ||
|
|
6259378466 | ||
|
|
e5c8b6b8ff | ||
|
|
c02b04f120 | ||
|
|
216cc51825 | ||
|
|
b1aa5e04e1 | ||
|
|
0947307e14 | ||
|
|
966e7386d9 |
No files matched your search
@@ -119,3 +119,5 @@ contrib/devtools/split-debug.sh
|
||||
|
||||
.idea
|
||||
cmake-build-*/
|
||||
|
||||
compile_commands\.json
|
||||
@@ -20,7 +20,7 @@ the "--help" flag (e.g. `lbrycrdd --help`). Examples:
|
||||
|
||||
Run `./lbrycrdd -server -daemon` to start lbrycrdd in the background.
|
||||
|
||||
Run `./lbrycrd-cli getinfo` to check for some basic information about your LBRYcrd node.
|
||||
Run `./lbrycrd-cli -getinfo` to check for some basic information about your LBRYcrd node.
|
||||
|
||||
Run `./lbrycrd-cli help` to get a list of all commands that you can run. To get help on specific commands run `./lbrycrd-cli [command_name] help`
|
||||
|
||||
|
||||
+2
-1
@@ -131,6 +131,7 @@ BITCOIN_CORE_H = \
|
||||
keystore.h \
|
||||
lbry.h \
|
||||
dbwrapper.h \
|
||||
sqlwrapper.h \
|
||||
limitedmap.h \
|
||||
logging.h \
|
||||
memusage.h \
|
||||
@@ -479,7 +480,7 @@ lbrycrdd_LDADD = \
|
||||
$(LIBMEMENV) \
|
||||
$(LIBSECP256K1)
|
||||
|
||||
lbrycrdd_LDADD += $(BOOST_LIBS) $(BDB_LIBS) $(CRYPTO_LIBS) $(ICU_LIBS) $(MINIUPNPC_LIBS) $(EVENT_PTHREADS_LIBS) $(EVENT_LIBS) $(ZMQ_LIBS)
|
||||
lbrycrdd_LDADD += -lsqlite3 $(BOOST_LIBS) $(BDB_LIBS) $(CRYPTO_LIBS) $(ICU_LIBS) $(MINIUPNPC_LIBS) $(EVENT_PTHREADS_LIBS) $(EVENT_LIBS) $(ZMQ_LIBS) -lsqlite3
|
||||
|
||||
# lbrycrd-cli binary #
|
||||
lbrycrd_cli_SOURCES = bitcoin-cli.cpp
|
||||
|
||||
@@ -34,7 +34,7 @@ nodist_bench_bench_bitcoin_SOURCES = $(GENERATED_BENCH_FILES)
|
||||
|
||||
bench_bench_bitcoin_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(EVENT_CLFAGS) $(EVENT_PTHREADS_CFLAGS) $(BOOST_CPPFLAGS) -I$(builddir)/bench/
|
||||
bench_bench_bitcoin_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
|
||||
bench_bench_bitcoin_LDADD = \
|
||||
bench_bench_bitcoin_LDADD = -lsqlite3 \
|
||||
$(LIBBITCOIN_WALLET) \
|
||||
$(LIBBITCOIN_SERVER) \
|
||||
$(LIBBITCOIN_COMMON) \
|
||||
@@ -55,7 +55,7 @@ if ENABLE_WALLET
|
||||
bench_bench_bitcoin_SOURCES += bench/coin_selection.cpp
|
||||
endif
|
||||
|
||||
bench_bench_bitcoin_LDADD += $(BOOST_LIBS) $(BDB_LIBS) $(CRYPTO_LIBS) $(ICU_LIBS) $(MINIUPNPC_LIBS) $(EVENT_PTHREADS_LIBS) $(EVENT_LIBS)
|
||||
bench_bench_bitcoin_LDADD += $(BOOST_LIBS) $(BDB_LIBS) $(CRYPTO_LIBS) $(ICU_LIBS) $(MINIUPNPC_LIBS) $(EVENT_PTHREADS_LIBS) $(EVENT_LIBS) -lsqlite3
|
||||
bench_bench_bitcoin_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
|
||||
|
||||
CLEAN_BITCOIN_BENCH = bench/*.gcda bench/*.gcno $(GENERATED_BENCH_FILES)
|
||||
|
||||
@@ -121,11 +121,11 @@ if ENABLE_WALLET
|
||||
test_test_lbrycrd_LDADD += $(LIBBITCOIN_WALLET)
|
||||
endif
|
||||
|
||||
test_test_lbrycrd_LDADD += $(LIBBITCOIN_SERVER) $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CONSENSUS) $(LIBBITCOIN_CRYPTO) $(LIBUNIVALUE) \
|
||||
test_test_lbrycrd_LDADD += -lsqlite3 $(LIBBITCOIN_SERVER) $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) $(LIBBITCOIN_CONSENSUS) $(LIBBITCOIN_CRYPTO) $(LIBUNIVALUE) \
|
||||
$(LIBLEVELDB) $(LIBLEVELDB_SSE42) $(LIBMEMENV) $(BOOST_LIBS) $(BOOST_UNIT_TEST_FRAMEWORK_LIB) $(LIBSECP256K1) $(EVENT_LIBS) $(EVENT_PTHREADS_LIBS)
|
||||
test_test_lbrycrd_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
|
||||
|
||||
test_test_lbrycrd_LDADD += $(LIBBITCOIN_CONSENSUS) $(BDB_LIBS) $(CRYPTO_LIBS) $(ICU_LIBS) $(MINIUPNPC_LIBS)
|
||||
test_test_lbrycrd_LDADD += $(LIBBITCOIN_CONSENSUS) $(BDB_LIBS) $(CRYPTO_LIBS) $(ICU_LIBS) $(MINIUPNPC_LIBS) -lsqlite3
|
||||
test_test_lbrycrd_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) -static
|
||||
|
||||
if ENABLE_ZMQ
|
||||
|
||||
+1
-1
@@ -98,7 +98,7 @@ bool DeserializeFileDB(const fs::path& path, Data& data)
|
||||
FILE *file = fsbridge::fopen(path, "rb");
|
||||
CAutoFile filein(file, SER_DISK, CLIENT_VERSION);
|
||||
if (filein.IsNull())
|
||||
return error("%s: Failed to open file %s", __func__, path.string());
|
||||
return false;
|
||||
|
||||
return DeserializeDB(filein, data);
|
||||
}
|
||||
|
||||
+1
-1
@@ -361,7 +361,7 @@ public:
|
||||
consensus.nPowTargetSpacing = 1;
|
||||
consensus.nOriginalClaimExpirationTime = 500;
|
||||
consensus.nExtendedClaimExpirationTime = 600;
|
||||
consensus.nExtendedClaimExpirationForkHeight = 8000;
|
||||
consensus.nExtendedClaimExpirationForkHeight = 800;
|
||||
consensus.nAllowMinDiffMinHeight = -1;
|
||||
consensus.nAllowMinDiffMaxHeight = -1;
|
||||
consensus.nNormalizedNameForkHeight = 250; // SDK depends upon this number
|
||||
|
||||
+80
-48
@@ -2,8 +2,9 @@
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include "claimscriptop.h"
|
||||
#include "nameclaim.h"
|
||||
#include <coins.h>
|
||||
#include <claimscriptop.h>
|
||||
#include <nameclaim.h>
|
||||
|
||||
CClaimScriptAddOp::CClaimScriptAddOp(const COutPoint& point, CAmount nValue, int nHeight)
|
||||
: point(point), nValue(nValue), nHeight(nHeight)
|
||||
@@ -37,32 +38,37 @@ CClaimScriptUndoAddOp::CClaimScriptUndoAddOp(const COutPoint& point, int nHeight
|
||||
bool CClaimScriptUndoAddOp::claimName(CClaimTrieCache& trieCache, const std::string& name)
|
||||
{
|
||||
auto claimId = ClaimIdHash(point.hash, point.n);
|
||||
LogPrintf("--- [%lu]: OP_CLAIM_NAME \"%s\" with claimId %s and tx prevout %s at index %d\n", nHeight, name, claimId.GetHex(), point.hash.ToString(), point.n);
|
||||
LogPrint(BCLog::CLAIMS, "--- [%lu]: OP_CLAIM_NAME \"%s\" with claimId %s and tx prevout %s at index %d\n", nHeight, name, claimId.GetHex(), point.hash.ToString(), point.n);
|
||||
return undoAddClaim(trieCache, name, claimId);
|
||||
}
|
||||
|
||||
bool CClaimScriptUndoAddOp::updateClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId)
|
||||
{
|
||||
LogPrintf("--- [%lu]: OP_UPDATE_CLAIM \"%s\" with claimId %s and tx prevout %s at index %d\n", nHeight, name, claimId.GetHex(), point.hash.ToString(), point.n);
|
||||
LogPrint(BCLog::CLAIMS, "--- [%lu]: OP_UPDATE_CLAIM \"%s\" with claimId %s and tx prevout %s at index %d\n", nHeight, name, claimId.GetHex(), point.hash.ToString(), point.n);
|
||||
return undoAddClaim(trieCache, name, claimId);
|
||||
}
|
||||
|
||||
bool CClaimScriptUndoAddOp::undoAddClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId)
|
||||
{
|
||||
LogPrintf("%s: (txid: %s, nOut: %d) Removing %s, claimId: %s, from the claim trie due to block disconnect\n", __func__, point.hash.ToString(), point.n, name, claimId.ToString());
|
||||
LogPrint(BCLog::CLAIMS, "%s: (txid: %s, nOut: %d) Removing %s, claimId: %s, from the claim trie due to block disconnect\n", __func__, point.hash.ToString(), point.n, name, claimId.ToString());
|
||||
bool res = trieCache.undoAddClaim(name, point, nHeight);
|
||||
if (!res)
|
||||
LogPrintf("%s: Removing fails\n", __func__);
|
||||
LogPrint(BCLog::CLAIMS, "%s: Removing claim fails\n", __func__);
|
||||
return res;
|
||||
}
|
||||
|
||||
bool CClaimScriptUndoAddOp::supportClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId)
|
||||
{
|
||||
LogPrintf("--- [%lu]: OP_SUPPORT_CLAIM \"%s\" with claimId %s and tx prevout %s at index %d\n", nHeight, name, claimId.GetHex(), point.hash.ToString(), point.n);
|
||||
LogPrintf("%s: (txid: %s, nOut: %d) Removing support for %s, claimId: %s, from the claim trie due to block disconnect\n", __func__, point.hash.ToString(), point.n, name, claimId.ToString());
|
||||
if (LogAcceptCategory(BCLog::CLAIMS)) {
|
||||
LogPrintf("--- [%lu]: OP_SUPPORT_CLAIM \"%s\" with claimId %s and tx prevout %s at index %d\n", nHeight, name,
|
||||
claimId.GetHex(), point.hash.ToString(), point.n);
|
||||
LogPrintf(
|
||||
"%s: (txid: %s, nOut: %d) Removing support for %s, claimId: %s, from the claim trie due to block disconnect\n",
|
||||
__func__, point.hash.ToString(), point.n, name, claimId.ToString());
|
||||
}
|
||||
bool res = trieCache.undoAddSupport(name, point, nHeight);
|
||||
if (!res)
|
||||
LogPrintf("%s: Removing support fails\n", __func__);
|
||||
LogPrint(BCLog::CLAIMS, "%s: Removing support fails\n", __func__);
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -74,32 +80,36 @@ CClaimScriptSpendOp::CClaimScriptSpendOp(const COutPoint& point, int nHeight, in
|
||||
bool CClaimScriptSpendOp::claimName(CClaimTrieCache& trieCache, const std::string& name)
|
||||
{
|
||||
auto claimId = ClaimIdHash(point.hash, point.n);
|
||||
LogPrintf("+++ [%lu]: OP_CLAIM_NAME \"%s\" with claimId %s and tx prevout %s at index %d\n", nHeight, name, claimId.GetHex(), point.hash.ToString(), point.n);
|
||||
LogPrint(BCLog::CLAIMS, "+++ [%lu]: OP_CLAIM_NAME \"%s\" with claimId %s and tx prevout %s at index %d\n", nHeight, name, claimId.GetHex(), point.hash.ToString(), point.n);
|
||||
return spendClaim(trieCache, name, claimId);
|
||||
}
|
||||
|
||||
bool CClaimScriptSpendOp::updateClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId)
|
||||
{
|
||||
LogPrintf("+++ [%lu]: OP_UPDATE_CLAIM \"%s\" with claimId %s and tx prevout %s at index %d\n", nHeight, name, claimId.GetHex(), point.hash.ToString(), point.n);
|
||||
LogPrint(BCLog::CLAIMS, "+++ [%lu]: OP_UPDATE_CLAIM \"%s\" with claimId %s and tx prevout %s at index %d\n", nHeight, name, claimId.GetHex(), point.hash.ToString(), point.n);
|
||||
return spendClaim(trieCache, name, claimId);
|
||||
}
|
||||
|
||||
bool CClaimScriptSpendOp::spendClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId)
|
||||
{
|
||||
LogPrintf("%s: (txid: %s, nOut: %d) Removing %s, claimId: %s, from the claim trie\n", __func__, point.hash.ToString(), point.n, name, claimId.ToString());
|
||||
LogPrint(BCLog::CLAIMS, "%s: (txid: %s, nOut: %d) Removing %s, claimId: %s, from the claim trie\n", __func__, point.hash.ToString(), point.n, name, claimId.ToString());
|
||||
bool res = trieCache.spendClaim(name, point, nHeight, nValidHeight);
|
||||
if (!res)
|
||||
LogPrintf("%s: Removing fails\n", __func__);
|
||||
LogPrint(BCLog::CLAIMS, "%s: Removing fails\n", __func__);
|
||||
return res;
|
||||
}
|
||||
|
||||
bool CClaimScriptSpendOp::supportClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId)
|
||||
{
|
||||
LogPrintf("+++ [%lu]: OP_SUPPORT_CLAIM \"%s\" with claimId %s and tx prevout %s at index %d\n", nHeight, name, claimId.GetHex(), point.hash.ToString(), point.n);
|
||||
LogPrintf("%s: (txid: %s, nOut: %d) Restoring support for %s, claimId: %s, to the claim trie\n", __func__, point.hash.ToString(), point.n, name, claimId.ToString());
|
||||
if (LogAcceptCategory(BCLog::CLAIMS)) {
|
||||
LogPrintf("+++ [%lu]: OP_SUPPORT_CLAIM \"%s\" with claimId %s and tx prevout %s at index %d\n", nHeight, name,
|
||||
claimId.GetHex(), point.hash.ToString(), point.n);
|
||||
LogPrintf("%s: (txid: %s, nOut: %d) Restoring support for %s, claimId: %s, to the claim trie\n", __func__,
|
||||
point.hash.ToString(), point.n, name, claimId.ToString());
|
||||
}
|
||||
bool res = trieCache.spendSupport(name, point, nHeight, nValidHeight);
|
||||
if (!res)
|
||||
LogPrintf("%s: Removing support fails\n", __func__);
|
||||
LogPrint(BCLog::CLAIMS, "%s: Removing support fails\n", __func__);
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -120,13 +130,13 @@ bool CClaimScriptUndoSpendOp::updateClaim(CClaimTrieCache& trieCache, const std:
|
||||
|
||||
bool CClaimScriptUndoSpendOp::undoSpendClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId)
|
||||
{
|
||||
LogPrintf("%s: (txid: %s, nOut: %d) Restoring %s, claimId: %s, to the claim trie due to block disconnect\n", __func__, point.hash.ToString(), point.n, name, claimId.ToString());
|
||||
LogPrint(BCLog::CLAIMS, "%s: (txid: %s, nOut: %d) Restoring %s, claimId: %s, to the claim trie due to block disconnect\n", __func__, point.hash.ToString(), point.n, name, claimId.ToString());
|
||||
return trieCache.undoSpendClaim(name, point, claimId, nValue, nHeight, nValidHeight);
|
||||
}
|
||||
|
||||
bool CClaimScriptUndoSpendOp::supportClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId)
|
||||
{
|
||||
LogPrintf("%s: (txid: %s, nOut: %d) Restoring support for %s, claimId: %s, to the claim trie due to block disconnect\n", __func__, point.hash.ToString(), point.n, name, claimId.ToString());
|
||||
LogPrint(BCLog::CLAIMS, "%s: (txid: %s, nOut: %d) Restoring support for %s, claimId: %s, to the claim trie due to block disconnect\n", __func__, point.hash.ToString(), point.n, name, claimId.ToString());
|
||||
return trieCache.undoSpendSupport(name, point, claimId, nValue, nHeight, nValidHeight);
|
||||
}
|
||||
|
||||
@@ -153,59 +163,81 @@ bool ProcessClaim(CClaimScriptOp& claimOp, CClaimTrieCache& trieCache, const CSc
|
||||
throw std::runtime_error("Unimplemented OP handler.");
|
||||
}
|
||||
|
||||
bool SpendClaim(CClaimTrieCache& trieCache, const CScript& scriptPubKey, const COutPoint& point, int nHeight, int& nValidHeight, spentClaimsType& spentClaims)
|
||||
void UpdateCache(const CTransaction& tx, CClaimTrieCache& trieCache, const CCoinsViewCache& view, int nHeight, const CUpdateCacheCallbacks& callbacks)
|
||||
{
|
||||
class CSpendClaimHistory : public CClaimScriptSpendOp
|
||||
{
|
||||
public:
|
||||
CSpendClaimHistory(spentClaimsType& spentClaims, const COutPoint& point, int nHeight, int& nValidHeight)
|
||||
: CClaimScriptSpendOp(point, nHeight, nValidHeight), spentClaims(spentClaims)
|
||||
{
|
||||
}
|
||||
using CClaimScriptSpendOp::CClaimScriptSpendOp;
|
||||
|
||||
bool spendClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId) override
|
||||
{
|
||||
if (CClaimScriptSpendOp::spendClaim(trieCache, name, claimId)) {
|
||||
spentClaims.emplace_back(name, claimId);
|
||||
callback(name, claimId);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
spentClaimsType& spentClaims;
|
||||
std::function<void(const std::string& name, const uint160& claimId)> callback;
|
||||
};
|
||||
|
||||
CSpendClaimHistory spendClaim(spentClaims, point, nHeight, nValidHeight);
|
||||
return ProcessClaim(spendClaim, trieCache, scriptPubKey);
|
||||
}
|
||||
spentClaimsType spentClaims;
|
||||
|
||||
for (std::size_t j = 0; j < tx.vin.size(); j++) {
|
||||
const CTxIn& txin = tx.vin[j];
|
||||
const Coin& coin = view.AccessCoin(txin.prevout);
|
||||
|
||||
CScript scriptPubKey;
|
||||
int scriptHeight = nHeight;
|
||||
if (coin.out.IsNull() && callbacks.findScriptKey) {
|
||||
scriptPubKey = callbacks.findScriptKey(txin.prevout);
|
||||
} else {
|
||||
scriptHeight = coin.nHeight;
|
||||
scriptPubKey = coin.out.scriptPubKey;
|
||||
}
|
||||
|
||||
if (scriptPubKey.empty())
|
||||
continue;
|
||||
|
||||
int nValidAtHeight;
|
||||
CSpendClaimHistory spendClaim(COutPoint(txin.prevout.hash, txin.prevout.n), scriptHeight, nValidAtHeight);
|
||||
spendClaim.callback = [&spentClaims](const std::string& name, const uint160& claimId) {
|
||||
spentClaims.emplace_back(name, claimId);
|
||||
};
|
||||
if (ProcessClaim(spendClaim, trieCache, scriptPubKey) && callbacks.claimUndoHeights)
|
||||
callbacks.claimUndoHeights(j, nValidAtHeight);
|
||||
}
|
||||
|
||||
bool AddSpendClaim(CClaimTrieCache& trieCache, const CScript& scriptPubKey, const COutPoint& point, CAmount nValue, int nHeight, spentClaimsType& spentClaims)
|
||||
{
|
||||
class CAddSpendClaim : public CClaimScriptAddOp
|
||||
{
|
||||
public:
|
||||
CAddSpendClaim(spentClaimsType& spentClaims, const COutPoint& point, CAmount nValue, int nHeight)
|
||||
: CClaimScriptAddOp(point, nValue, nHeight), spentClaims(spentClaims)
|
||||
{
|
||||
}
|
||||
using CClaimScriptAddOp::CClaimScriptAddOp;
|
||||
|
||||
bool updateClaim(CClaimTrieCache& trieCache, const std::string& name, const uint160& claimId) override
|
||||
{
|
||||
spentClaimsType::iterator itSpent = spentClaims.begin();
|
||||
for (; itSpent != spentClaims.end(); ++itSpent) {
|
||||
if (callback(name, claimId))
|
||||
return CClaimScriptAddOp::updateClaim(trieCache, name, claimId);
|
||||
return false;
|
||||
}
|
||||
std::function<bool(const std::string& name, const uint160& claimId)> callback;
|
||||
};
|
||||
|
||||
for (std::size_t j = 0; j < tx.vout.size(); j++) {
|
||||
const CTxOut& txout = tx.vout[j];
|
||||
|
||||
if (txout.scriptPubKey.empty())
|
||||
continue;
|
||||
|
||||
CAddSpendClaim addClaim(COutPoint(tx.GetHash(), j), txout.nValue, nHeight);
|
||||
addClaim.callback = [&trieCache, &spentClaims](const std::string& name, const uint160& claimId) -> bool {
|
||||
for (auto itSpent = spentClaims.begin(); itSpent != spentClaims.end(); ++itSpent) {
|
||||
if (itSpent->second == claimId && trieCache.normalizeClaimName(name) == trieCache.normalizeClaimName(itSpent->first)) {
|
||||
spentClaims.erase(itSpent);
|
||||
return CClaimScriptAddOp::updateClaim(trieCache, name, claimId);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private:
|
||||
spentClaimsType& spentClaims;
|
||||
};
|
||||
|
||||
CAddSpendClaim addClaim(spentClaims, point, nValue, nHeight);
|
||||
return ProcessClaim(addClaim, trieCache, scriptPubKey);
|
||||
}
|
||||
};
|
||||
ProcessClaim(addClaim, trieCache, txout.scriptPubKey);
|
||||
}
|
||||
}
|
||||
+10
-15
@@ -225,26 +225,21 @@ typedef std::pair<std::string, uint160> spentClaimType;
|
||||
|
||||
typedef std::vector<spentClaimType> spentClaimsType;
|
||||
|
||||
struct CUpdateCacheCallbacks
|
||||
{
|
||||
std::function<CScript(const COutPoint& point)> findScriptKey;
|
||||
std::function<void(int, int)> claimUndoHeights;
|
||||
};
|
||||
|
||||
/**
|
||||
* Function to spend claim from tie, keeping the successful list on
|
||||
* @param[in] tx transaction inputs/outputs
|
||||
* @param[in] trieCache trie to operate on
|
||||
* @param[in] scriptPubKey claim script to be decoded
|
||||
* @param[in] view coins cache
|
||||
* @param[in] point pair of transaction hash and its index
|
||||
* @param[in] nHeight entry height of the claim
|
||||
* @param[out] nValidHeight valid height of the claim
|
||||
* @param[out] spentClaims inserts successfully spent claim
|
||||
* @param[out] fallback optional callbacks
|
||||
*/
|
||||
bool SpendClaim(CClaimTrieCache& trieCache, const CScript& scriptPubKey, const COutPoint& point, int nHeight, int& nValidHeight, spentClaimsType& spentClaims);
|
||||
|
||||
/**
|
||||
* Function to add / update (that present in spent list) claim in trie
|
||||
* @param[in] trieCache trie to operate on
|
||||
* @param[in] scriptPubKey claim script to be decoded
|
||||
* @param[in] point pair of transaction hash and its index
|
||||
* @param[in] nValue ` value of the claim
|
||||
* @param[in] nHeight entry height of the claim
|
||||
* @param[out] spentClaims erases successfully added claim
|
||||
*/
|
||||
bool AddSpendClaim(CClaimTrieCache& trieCache, const CScript& scriptPubKey, const COutPoint& point, CAmount nValue, int nHeight, spentClaimsType& spentClaims);
|
||||
void UpdateCache(const CTransaction& tx, CClaimTrieCache& trieCache, const CCoinsViewCache& view, int nHeight, const CUpdateCacheCallbacks& callbacks = {});
|
||||
|
||||
#endif // CLAIMSCRIPTOP_H
|
||||
+717
-693
File diff suppressed because it is too large.
Load diff
+166
-110
@@ -4,7 +4,7 @@
|
||||
#include <amount.h>
|
||||
#include <chain.h>
|
||||
#include <chainparams.h>
|
||||
#include <dbwrapper.h>
|
||||
#include <sqlwrapper.h>
|
||||
#include <prefixtrie.h>
|
||||
#include <primitives/transaction.h>
|
||||
#include <serialize.h>
|
||||
@@ -18,11 +18,13 @@
|
||||
#include <unordered_set>
|
||||
|
||||
// leveldb keys
|
||||
#define TRIE_NODE 'n'
|
||||
#define TRIE_NODE 'n' // deprecated
|
||||
#define TRIE_NODE_BY_HASH 'h'
|
||||
#define TRIE_NODE_BY_NAME 'g'
|
||||
#define CLAIM_BY_ID 'i'
|
||||
#define CLAIM_QUEUE_ROW 'r'
|
||||
#define CLAIM_QUEUE_NAME_ROW 'm'
|
||||
#define EXP_QUEUE_ROW 'e'
|
||||
#define CLAIM_EXP_QUEUE_ROW 'e'
|
||||
#define SUPPORT 's'
|
||||
#define SUPPORT_QUEUE_ROW 'u'
|
||||
#define SUPPORT_QUEUE_NAME_ROW 'p'
|
||||
@@ -39,9 +41,7 @@ struct CClaimValue
|
||||
int nHeight;
|
||||
int nValidAtHeight;
|
||||
|
||||
CClaimValue()
|
||||
{
|
||||
}
|
||||
CClaimValue() = default;
|
||||
|
||||
CClaimValue(const COutPoint& outPoint, const uint160& claimId, CAmount nAmount, int nHeight, int nValidAtHeight)
|
||||
: outPoint(outPoint), claimId(claimId), nAmount(nAmount), nEffectiveAmount(nAmount), nHeight(nHeight), nValidAtHeight(nValidAtHeight)
|
||||
@@ -63,6 +63,7 @@ struct CClaimValue
|
||||
READWRITE(nAmount);
|
||||
READWRITE(nHeight);
|
||||
READWRITE(nValidAtHeight);
|
||||
READWRITE(nEffectiveAmount);
|
||||
}
|
||||
|
||||
bool operator<(const CClaimValue& other) const
|
||||
@@ -97,9 +98,7 @@ struct CSupportValue
|
||||
int nHeight;
|
||||
int nValidAtHeight;
|
||||
|
||||
CSupportValue()
|
||||
{
|
||||
}
|
||||
CSupportValue() = default;
|
||||
|
||||
CSupportValue(const COutPoint& outPoint, const uint160& supportedClaimId, CAmount nAmount, int nHeight, int nValidAtHeight)
|
||||
: outPoint(outPoint), supportedClaimId(supportedClaimId), nAmount(nAmount), nHeight(nHeight), nValidAtHeight(nValidAtHeight)
|
||||
@@ -161,17 +160,6 @@ struct CClaimTrieData
|
||||
inline void SerializationOp(Stream& s, Operation ser_action)
|
||||
{
|
||||
READWRITE(hash);
|
||||
|
||||
if (ser_action.ForRead()) {
|
||||
if (s.eof()) {
|
||||
claims.clear();
|
||||
nHeightOfLastTakeover = 0;
|
||||
return;
|
||||
}
|
||||
}
|
||||
else if (claims.empty())
|
||||
return;
|
||||
|
||||
READWRITE(claims);
|
||||
READWRITE(nHeightOfLastTakeover);
|
||||
}
|
||||
@@ -192,14 +180,36 @@ struct CClaimTrieData
|
||||
}
|
||||
};
|
||||
|
||||
struct CClaimTrieDataNode {
|
||||
CClaimTrieData data;
|
||||
// we're using a vector to avoid RAM thrashing and for faster serialization ops.
|
||||
// We're assuming its data is inserted in order and never modified.
|
||||
std::vector<std::pair<std::string, uint256>> children;
|
||||
bool childrenSerialization = true;
|
||||
|
||||
CClaimTrieDataNode() = default;
|
||||
CClaimTrieDataNode(CClaimTrieDataNode&&) = default;
|
||||
CClaimTrieDataNode(const CClaimTrieDataNode&) = default;
|
||||
CClaimTrieDataNode& operator=(CClaimTrieDataNode&&) = default;
|
||||
CClaimTrieDataNode& operator=(const CClaimTrieDataNode& d) = default;
|
||||
|
||||
ADD_SERIALIZE_METHODS;
|
||||
|
||||
template <typename Stream, typename Operation>
|
||||
inline void SerializationOp(Stream& s, Operation ser_action)
|
||||
{
|
||||
READWRITE(data);
|
||||
if (childrenSerialization) // wanting constexpr but hoping the compiler is smart enough anyway
|
||||
READWRITE(children);
|
||||
}
|
||||
};
|
||||
|
||||
struct COutPointHeightType
|
||||
{
|
||||
COutPoint outPoint;
|
||||
int nHeight;
|
||||
|
||||
COutPointHeightType()
|
||||
{
|
||||
}
|
||||
COutPointHeightType() = default;
|
||||
|
||||
COutPointHeightType(const COutPoint& outPoint, int nHeight)
|
||||
: outPoint(outPoint), nHeight(nHeight)
|
||||
@@ -222,9 +232,7 @@ struct CNameOutPointHeightType
|
||||
COutPoint outPoint;
|
||||
int nHeight;
|
||||
|
||||
CNameOutPointHeightType()
|
||||
{
|
||||
}
|
||||
CNameOutPointHeightType() = default;
|
||||
|
||||
CNameOutPointHeightType(std::string name, const COutPoint& outPoint, int nHeight)
|
||||
: name(std::move(name)), outPoint(outPoint), nHeight(nHeight)
|
||||
@@ -247,15 +255,18 @@ struct CNameOutPointType
|
||||
std::string name;
|
||||
COutPoint outPoint;
|
||||
|
||||
CNameOutPointType()
|
||||
{
|
||||
}
|
||||
CNameOutPointType() = default;
|
||||
|
||||
CNameOutPointType(std::string name, const COutPoint& outPoint)
|
||||
: name(std::move(name)), outPoint(outPoint)
|
||||
{
|
||||
}
|
||||
|
||||
bool operator==(const CNameOutPointType& other) const
|
||||
{
|
||||
return name == other.name && outPoint == other.outPoint;
|
||||
}
|
||||
|
||||
ADD_SERIALIZE_METHODS;
|
||||
|
||||
template <typename Stream, typename Operation>
|
||||
@@ -268,6 +279,13 @@ struct CNameOutPointType
|
||||
|
||||
struct CClaimIndexElement
|
||||
{
|
||||
CClaimIndexElement() = default;
|
||||
|
||||
CClaimIndexElement(std::string name, CClaimValue claim)
|
||||
: name(std::move(name)), claim(std::move(claim))
|
||||
{
|
||||
}
|
||||
|
||||
ADD_SERIALIZE_METHODS;
|
||||
|
||||
template <typename Stream, typename Operation>
|
||||
@@ -288,8 +306,8 @@ struct CClaimsForNameType
|
||||
int nLastTakeoverHeight;
|
||||
std::string name;
|
||||
|
||||
CClaimsForNameType(claimEntryType claims, supportEntryType supports, int nLastTakeoverHeight, const std::string& name)
|
||||
: claims(std::move(claims)), supports(std::move(supports)), nLastTakeoverHeight(nLastTakeoverHeight), name(name)
|
||||
CClaimsForNameType(claimEntryType claims, supportEntryType supports, int nLastTakeoverHeight, std::string name)
|
||||
: claims(std::move(claims)), supports(std::move(supports)), nLastTakeoverHeight(nLastTakeoverHeight), name(std::move(name))
|
||||
{
|
||||
}
|
||||
|
||||
@@ -299,12 +317,11 @@ struct CClaimsForNameType
|
||||
CClaimsForNameType& operator=(const CClaimsForNameType&) = default;
|
||||
};
|
||||
|
||||
class CClaimTrie : public CPrefixTrie<std::string, CClaimTrieData>
|
||||
class CClaimTrie
|
||||
{
|
||||
int nNextHeight = 0;
|
||||
int nExpirationTime = 0;
|
||||
int nProportionalDelayFactor = 0;
|
||||
std::unique_ptr<CDBWrapper> db;
|
||||
std::unique_ptr<CSqlWrapper> db;
|
||||
|
||||
public:
|
||||
CClaimTrie() = default;
|
||||
@@ -321,11 +338,23 @@ public:
|
||||
friend struct ClaimTrieChainFixture;
|
||||
friend class CClaimTrieCacheExpirationFork;
|
||||
friend class CClaimTrieCacheNormalizationFork;
|
||||
|
||||
std::size_t getTotalNamesInTrie() const;
|
||||
std::size_t getTotalClaimsInTrie() const;
|
||||
CAmount getTotalValueOfClaimsInTrie(bool fControllingOnly) const;
|
||||
bool checkConsistency(const uint256& rootHash) const;
|
||||
|
||||
bool contains(const std::string& key) const;
|
||||
bool empty() const;
|
||||
bool find(const uint256& key, CClaimTrieDataNode& node) const;
|
||||
bool find(const std::string& key, CClaimTrieDataNode& node) const;
|
||||
|
||||
std::vector<std::pair<std::string, CClaimTrieDataNode>> nodes(const std::string& key) const;
|
||||
void recurseAllHashedNodes(const std::string& name, const CClaimTrieDataNode& current, std::function<void(const std::string&, const CClaimTrieDataNode&)> function) const;
|
||||
};
|
||||
|
||||
class CClaimTrieProofNode
|
||||
struct CClaimTrieProofNode
|
||||
{
|
||||
public:
|
||||
CClaimTrieProofNode(std::vector<std::pair<unsigned char, uint256>> children, bool hasValue, const uint256& valHash)
|
||||
: children(std::move(children)), hasValue(hasValue), valHash(valHash)
|
||||
{
|
||||
@@ -341,12 +370,9 @@ public:
|
||||
uint256 valHash;
|
||||
};
|
||||
|
||||
class CClaimTrieProof
|
||||
struct CClaimTrieProof
|
||||
{
|
||||
public:
|
||||
CClaimTrieProof()
|
||||
{
|
||||
}
|
||||
CClaimTrieProof() = default;
|
||||
|
||||
CClaimTrieProof(std::vector<CClaimTrieProofNode> nodes, bool hasValue, const COutPoint& outPoint, int nHeightOfLastTakeover)
|
||||
: nodes(std::move(nodes)), hasValue(hasValue), outPoint(outPoint), nHeightOfLastTakeover(nHeightOfLastTakeover)
|
||||
@@ -364,12 +390,13 @@ public:
|
||||
int nHeightOfLastTakeover;
|
||||
};
|
||||
|
||||
typedef std::pair<std::string, CClaimValue> claimQueueEntryType;
|
||||
typedef std::vector<claimQueueEntryType> claimQueueRowType;
|
||||
template <typename T>
|
||||
using queueEntryType = std::pair<std::string, T>;
|
||||
|
||||
typedef std::vector<queueEntryType<CClaimValue>> claimQueueRowType;
|
||||
typedef std::map<int, claimQueueRowType> claimQueueType;
|
||||
|
||||
typedef std::pair<std::string, CSupportValue> supportQueueEntryType;
|
||||
typedef std::vector<supportQueueEntryType> supportQueueRowType;
|
||||
typedef std::vector<queueEntryType<CSupportValue>> supportQueueRowType;
|
||||
typedef std::map<int, supportQueueRowType> supportQueueType;
|
||||
|
||||
typedef std::vector<COutPointHeightType> queueNameRowType;
|
||||
@@ -383,14 +410,15 @@ typedef std::map<int, expirationQueueRowType> expirationQueueType;
|
||||
typedef std::set<CClaimValue> claimIndexClaimListType;
|
||||
typedef std::vector<CClaimIndexElement> claimIndexElementListType;
|
||||
|
||||
typedef CPrefixTrie<std::string, CClaimTrieData> CClaimPrefixTrie;
|
||||
|
||||
class CClaimTrieCacheBase
|
||||
{
|
||||
public:
|
||||
explicit CClaimTrieCacheBase(CClaimTrie* base, bool fRequireTakeoverHeights = true);
|
||||
explicit CClaimTrieCacheBase(CClaimTrie* base);
|
||||
virtual ~CClaimTrieCacheBase() = default;
|
||||
|
||||
uint256 getMerkleHash();
|
||||
bool checkConsistency(int minimumHeight = 1) const;
|
||||
|
||||
bool getClaimById(const uint160& claimId, std::string& name, CClaimValue& claim) const;
|
||||
|
||||
@@ -404,10 +432,6 @@ public:
|
||||
bool haveSupport(const std::string& name, const COutPoint& outPoint) const;
|
||||
bool haveSupportInQueue(const std::string& name, const COutPoint& outPoint, int& nValidAtHeight);
|
||||
|
||||
std::size_t getTotalNamesInTrie() const;
|
||||
std::size_t getTotalClaimsInTrie() const;
|
||||
CAmount getTotalValueOfClaimsInTrie(bool fControllingOnly) const;
|
||||
|
||||
bool addClaim(const std::string& name, const COutPoint& outPoint, const uint160& claimId, CAmount nAmount, int nHeight);
|
||||
bool undoAddClaim(const std::string& name, const COutPoint& outPoint, int nHeight);
|
||||
|
||||
@@ -434,6 +458,8 @@ public:
|
||||
virtual bool getProofForName(const std::string& name, CClaimTrieProof& proof);
|
||||
virtual bool getInfoForName(const std::string& name, CClaimValue& claim) const;
|
||||
|
||||
virtual int expirationTime() const;
|
||||
|
||||
bool finalizeDecrement(std::vector<std::pair<std::string, int>>& takeoverHeightUndo);
|
||||
|
||||
virtual CClaimsForNameType getClaimsForName(const std::string& name) const;
|
||||
@@ -441,21 +467,18 @@ public:
|
||||
CAmount getEffectiveAmountForClaim(const std::string& name, const uint160& claimId, std::vector<CSupportValue>* supports = nullptr) const;
|
||||
CAmount getEffectiveAmountForClaim(const CClaimsForNameType& claims, const uint160& claimId, std::vector<CSupportValue>* supports = nullptr) const;
|
||||
|
||||
void setExpirationTime(int time);
|
||||
int expirationTime();
|
||||
CClaimPrefixTrie::const_iterator begin() const;
|
||||
CClaimPrefixTrie::const_iterator end() const;
|
||||
|
||||
CClaimTrie::const_iterator begin() const;
|
||||
CClaimTrie::const_iterator end() const;
|
||||
CClaimTrie::const_iterator find(const std::string& name) const;
|
||||
|
||||
void dumpToLog(CClaimTrie::const_iterator it, bool diffFromBase = true) const;
|
||||
void dumpToLog(CClaimPrefixTrie::const_iterator it, bool diffFromBase = true) const;
|
||||
virtual std::string adjustNameForValidHeight(const std::string& name, int validHeight) const;
|
||||
|
||||
protected:
|
||||
CClaimTrie* base;
|
||||
CClaimTrie cache;
|
||||
std::unordered_set<std::string> namesToCheckForTakeover;
|
||||
CClaimPrefixTrie nodesToAddOrUpdate; // nodes pulled in from base (and possibly modified thereafter), written to base on flush
|
||||
std::unordered_set<std::string> namesToCheckForTakeover; // takeover numbers are updated on increment
|
||||
|
||||
uint256 recursiveComputeMerkleHash(CClaimTrie::iterator& it);
|
||||
uint256 recursiveComputeMerkleHash(CClaimPrefixTrie::iterator& it);
|
||||
|
||||
virtual bool insertClaimIntoTrie(const std::string& name, const CClaimValue& claim, bool fCheckTakeover);
|
||||
virtual bool removeClaimFromTrie(const std::string& name, const COutPoint& outPoint, CClaimValue& claim, bool fCheckTakeover);
|
||||
@@ -463,29 +486,19 @@ protected:
|
||||
virtual bool insertSupportIntoMap(const std::string& name, const CSupportValue& support, bool fCheckTakeover);
|
||||
virtual bool removeSupportFromMap(const std::string& name, const COutPoint& outPoint, CSupportValue& support, bool fCheckTakeover);
|
||||
|
||||
virtual bool addClaimToQueues(const std::string& name, const CClaimValue& claim);
|
||||
|
||||
virtual bool addSupportToQueues(const std::string& name, const CSupportValue& support);
|
||||
virtual bool removeSupportFromQueue(const std::string& name, const COutPoint& outPoint, CSupportValue& support);
|
||||
|
||||
virtual std::string adjustNameForValidHeight(const std::string& name, int validHeight) const;
|
||||
|
||||
void addToExpirationQueue(int nExpirationHeight, CNameOutPointType& entry);
|
||||
void removeFromExpirationQueue(const std::string& name, const COutPoint& outPoint, int nHeight);
|
||||
|
||||
void addSupportToExpirationQueue(int nExpirationHeight, CNameOutPointType& entry);
|
||||
void removeSupportFromExpirationQueue(const std::string& name, const COutPoint& outPoint, int nHeight);
|
||||
|
||||
supportEntryType getSupportsForName(const std::string& name) const;
|
||||
|
||||
int getDelayForName(const std::string& name);
|
||||
virtual int getDelayForName(const std::string& name, const uint160& claimId);
|
||||
int getDelayForName(const std::string& name) const;
|
||||
virtual int getDelayForName(const std::string& name, const uint160& claimId) const;
|
||||
|
||||
CClaimTrie::iterator cacheData(const std::string& name, bool create = true);
|
||||
CClaimPrefixTrie::iterator cacheData(const std::string& name, bool create = true);
|
||||
|
||||
bool getLastTakeoverForName(const std::string& name, uint160& claimId, int& takeoverHeight) const;
|
||||
|
||||
int getNumBlocksOfContinuousOwnership(const std::string& name);
|
||||
int getNumBlocksOfContinuousOwnership(const std::string& name) const;
|
||||
|
||||
void reactivateClaim(const expirationQueueRowType& row, int height, bool increment);
|
||||
void reactivateSupport(const expirationQueueRowType& row, int height, bool increment);
|
||||
|
||||
expirationQueueType expirationQueueCache;
|
||||
expirationQueueType supportExpirationQueueCache;
|
||||
@@ -498,20 +511,19 @@ private:
|
||||
|
||||
std::unordered_map<std::string, std::pair<uint160, int>> takeoverCache;
|
||||
|
||||
bool fRequireTakeoverHeights;
|
||||
|
||||
claimQueueType claimQueueCache;
|
||||
claimQueueType claimQueueCache; // claims not active yet: to be written to disk on flush
|
||||
queueNameType claimQueueNameCache;
|
||||
supportQueueType supportQueueCache;
|
||||
supportQueueType supportQueueCache; // supports not active yet: to be written to disk on flush
|
||||
queueNameType supportQueueNameCache;
|
||||
claimIndexElementListType claimsToAdd;
|
||||
claimIndexClaimListType claimsToDelete;
|
||||
claimIndexElementListType claimsToAddToByIdIndex; // written to index on flush
|
||||
claimIndexClaimListType claimsToDeleteFromByIdIndex;
|
||||
|
||||
std::unordered_map<std::string, supportEntryType> cacheSupports;
|
||||
std::unordered_set<std::string> nodesToDelete;
|
||||
std::unordered_set<std::string> alreadyCachedNodes;
|
||||
std::unordered_map<std::string, supportEntryType> supportCache; // to be added/updated to base (and disk) on flush
|
||||
std::unordered_set<std::string> nodesToDelete; // to be removed from base (and disk) on flush
|
||||
std::unordered_set<std::string> nodesAlreadyCached; // set of nodes already pulled into cache from base
|
||||
std::unordered_map<std::string, bool> takeoverWorkaround;
|
||||
std::unordered_set<std::string> removalWorkaround;
|
||||
std::unordered_set<std::string> dirtyNodes;
|
||||
|
||||
bool shouldUseTakeoverWorkaround(const std::string& key) const;
|
||||
void addTakeoverWorkaroundPotential(const std::string& key);
|
||||
@@ -522,14 +534,53 @@ private:
|
||||
void markAsDirty(const std::string& name, bool fCheckTakeover);
|
||||
bool removeSupport(const std::string& name, const COutPoint& outPoint, int nHeight, int& nValidAtHeight, bool fCheckTakeover);
|
||||
bool removeClaim(const std::string& name, const COutPoint& outPoint, int nHeight, int& nValidAtHeight, bool fCheckTakeover);
|
||||
bool removeClaimFromQueue(const std::string& name, const COutPoint& outPoint, CClaimValue& claim);
|
||||
|
||||
typename claimQueueType::value_type* getQueueCacheRow(int nHeight, bool createIfNotExists = false);
|
||||
bool validateTrieConsistency(const CBlockIndex* tip);
|
||||
|
||||
template <typename T>
|
||||
std::pair<const int, std::vector<queueEntryType<T>>>* getQueueCacheRow(int nHeight, bool createIfNotExists = false);
|
||||
|
||||
template <typename T>
|
||||
typename queueNameType::value_type* getQueueCacheNameRow(const std::string& name, bool createIfNotExists = false);
|
||||
|
||||
template <typename T>
|
||||
typename expirationQueueType::value_type* getExpirationQueueCacheRow(int nHeight, bool createIfNotExists = false);
|
||||
typename supportQueueType::value_type* getSupportQueueCacheRow(int nHeight, bool createIfNotExists = false);
|
||||
typename queueNameType::value_type* getSupportQueueCacheNameRow(const std::string& name, bool createIfNotExists = false);
|
||||
typename expirationQueueType::value_type* getSupportExpirationQueueCacheRow(int nHeight, bool createIfNotExists = false);
|
||||
|
||||
template <typename T>
|
||||
bool haveInQueue(const std::string& name, const COutPoint& outPoint, int& nValidAtHeight);
|
||||
|
||||
template <typename T>
|
||||
T add(const std::string& name, const COutPoint& outPoint, const uint160& claimId, CAmount nAmount, int nHeight);
|
||||
|
||||
template <typename T>
|
||||
bool remove(T& value, const std::string& name, const COutPoint& outPoint, int nHeight, int& nValidAtHeight, bool fCheckTakeover = false);
|
||||
|
||||
template <typename T>
|
||||
bool addToQueue(const std::string& name, const T& value);
|
||||
|
||||
template <typename T>
|
||||
bool removeFromQueue(const std::string& name, const COutPoint& outPoint, T& value);
|
||||
|
||||
template <typename T>
|
||||
bool addToCache(const std::string& name, const T& value, bool fCheckTakeover = false);
|
||||
|
||||
template <typename T>
|
||||
bool removeFromCache(const std::string& name, const COutPoint& outPoint, T& value, bool fCheckTakeover = false);
|
||||
|
||||
template <typename T>
|
||||
bool undoSpend(const std::string& name, const T& value, int nValidAtHeight);
|
||||
|
||||
template <typename T>
|
||||
void undoIncrement(insertUndoType& insertUndo, std::vector<queueEntryType<T>>& expireUndo, std::set<T>* deleted = nullptr);
|
||||
|
||||
template <typename T>
|
||||
void undoDecrement(insertUndoType& insertUndo, std::vector<queueEntryType<T>>& expireUndo, std::vector<CClaimIndexElement>* added = nullptr, std::set<T>* deleted = nullptr);
|
||||
|
||||
template <typename T>
|
||||
void undoIncrement(const std::string& name, insertUndoType& insertUndo, std::vector<queueEntryType<T>>& expireUndo);
|
||||
|
||||
template <typename T>
|
||||
void reactivate(const expirationQueueRowType& row, int height, bool increment);
|
||||
|
||||
// for unit test
|
||||
friend struct ClaimTrieChainFixture;
|
||||
@@ -539,25 +590,34 @@ private:
|
||||
class CClaimTrieCacheExpirationFork : public CClaimTrieCacheBase
|
||||
{
|
||||
public:
|
||||
explicit CClaimTrieCacheExpirationFork(CClaimTrie* base, bool fRequireTakeoverHeights = true)
|
||||
: CClaimTrieCacheBase(base, fRequireTakeoverHeights)
|
||||
{
|
||||
}
|
||||
explicit CClaimTrieCacheExpirationFork(CClaimTrie* base);
|
||||
|
||||
bool forkForExpirationChange(bool increment);
|
||||
void setExpirationTime(int time);
|
||||
int expirationTime() const override;
|
||||
|
||||
// TODO: move the expiration fork code from main.cpp to overrides of increment/decrement block
|
||||
void expirationForkActive(int height, bool increment);
|
||||
|
||||
bool incrementBlock(insertUndoType& insertUndo,
|
||||
claimQueueRowType& expireUndo,
|
||||
insertUndoType& insertSupportUndo,
|
||||
supportQueueRowType& expireSupportUndo,
|
||||
std::vector<std::pair<std::string, int>>& takeoverHeightUndo) override;
|
||||
|
||||
bool decrementBlock(insertUndoType& insertUndo,
|
||||
claimQueueRowType& expireUndo,
|
||||
insertUndoType& insertSupportUndo,
|
||||
supportQueueRowType& expireSupportUndo) override;
|
||||
|
||||
private:
|
||||
void removeAndAddSupportToExpirationQueue(expirationQueueRowType& row, int height, bool increment);
|
||||
void removeAndAddToExpirationQueue(expirationQueueRowType& row, int height, bool increment);
|
||||
int nExpirationTime;
|
||||
bool forkForExpirationChange(bool increment);
|
||||
};
|
||||
|
||||
class CClaimTrieCacheNormalizationFork : public CClaimTrieCacheExpirationFork
|
||||
{
|
||||
public:
|
||||
explicit CClaimTrieCacheNormalizationFork(CClaimTrie* base, bool fRequireTakeoverHeights = true)
|
||||
: CClaimTrieCacheExpirationFork(base, fRequireTakeoverHeights), overrideInsertNormalization(false), overrideRemoveNormalization(false)
|
||||
explicit CClaimTrieCacheNormalizationFork(CClaimTrie* base)
|
||||
: CClaimTrieCacheExpirationFork(base), overrideInsertNormalization(false), overrideRemoveNormalization(false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -581,20 +641,16 @@ public:
|
||||
bool getProofForName(const std::string& name, CClaimTrieProof& proof) override;
|
||||
bool getInfoForName(const std::string& name, CClaimValue& claim) const override;
|
||||
CClaimsForNameType getClaimsForName(const std::string& name) const override;
|
||||
std::string adjustNameForValidHeight(const std::string& name, int validHeight) const override;
|
||||
|
||||
protected:
|
||||
bool insertClaimIntoTrie(const std::string& name, const CClaimValue& claim, bool fCheckTakeover = false) override;
|
||||
bool removeClaimFromTrie(const std::string& name, const COutPoint& outPoint, CClaimValue& claim, bool fCheckTakeover = false) override;
|
||||
bool insertClaimIntoTrie(const std::string& name, const CClaimValue& claim, bool fCheckTakeover) override;
|
||||
bool removeClaimFromTrie(const std::string& name, const COutPoint& outPoint, CClaimValue& claim, bool fCheckTakeover) override;
|
||||
|
||||
bool insertSupportIntoMap(const std::string& name, const CSupportValue& support, bool fCheckTakeover) override;
|
||||
bool removeSupportFromMap(const std::string& name, const COutPoint& outPoint, CSupportValue& support, bool fCheckTakeover) override;
|
||||
|
||||
int getDelayForName(const std::string& name, const uint160& claimId) override;
|
||||
|
||||
bool addClaimToQueues(const std::string& name, const CClaimValue& claim) override;
|
||||
bool addSupportToQueues(const std::string& name, const CSupportValue& support) override;
|
||||
|
||||
std::string adjustNameForValidHeight(const std::string& name, int validHeight) const override;
|
||||
int getDelayForName(const std::string& name, const uint160& claimId) const override;
|
||||
|
||||
private:
|
||||
bool overrideInsertNormalization;
|
||||
|
||||
+72
-57
@@ -1,4 +1,6 @@
|
||||
#include "claimtrie.h"
|
||||
|
||||
#include <chainparams.h>
|
||||
#include <claimtrie.h>
|
||||
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/foreach.hpp>
|
||||
@@ -6,29 +8,46 @@
|
||||
#include <boost/locale/conversion.hpp>
|
||||
#include <boost/locale/localization_backend.hpp>
|
||||
#include <boost/scope_exit.hpp>
|
||||
#include <boost/scoped_ptr.hpp>
|
||||
|
||||
void CClaimTrieCacheExpirationFork::removeAndAddToExpirationQueue(expirationQueueRowType& row, int height, bool increment)
|
||||
CClaimTrieCacheExpirationFork::CClaimTrieCacheExpirationFork(CClaimTrie* base)
|
||||
: CClaimTrieCacheBase(base)
|
||||
{
|
||||
for (auto e = row.begin(); e != row.end(); ++e) {
|
||||
// remove and insert with new expiration time
|
||||
removeFromExpirationQueue(e->name, e->outPoint, height);
|
||||
int extend_expiration = Params().GetConsensus().nExtendedClaimExpirationTime - Params().GetConsensus().nOriginalClaimExpirationTime;
|
||||
int new_expiration_height = increment ? height + extend_expiration : height - extend_expiration;
|
||||
CNameOutPointType entry(e->name, e->outPoint);
|
||||
addToExpirationQueue(new_expiration_height, entry);
|
||||
}
|
||||
setExpirationTime(Params().GetConsensus().GetExpirationTime(nNextHeight));
|
||||
}
|
||||
|
||||
void CClaimTrieCacheExpirationFork::removeAndAddSupportToExpirationQueue(expirationQueueRowType& row, int height, bool increment)
|
||||
void CClaimTrieCacheExpirationFork::setExpirationTime(int time)
|
||||
{
|
||||
for (auto e = row.begin(); e != row.end(); ++e) {
|
||||
// remove and insert with new expiration time
|
||||
removeSupportFromExpirationQueue(e->name, e->outPoint, height);
|
||||
int extend_expiration = Params().GetConsensus().nExtendedClaimExpirationTime - Params().GetConsensus().nOriginalClaimExpirationTime;
|
||||
int new_expiration_height = increment ? height + extend_expiration : height - extend_expiration;
|
||||
CNameOutPointType entry(e->name, e->outPoint);
|
||||
addSupportToExpirationQueue(new_expiration_height, entry);
|
||||
nExpirationTime = time;
|
||||
}
|
||||
|
||||
int CClaimTrieCacheExpirationFork::expirationTime() const
|
||||
{
|
||||
return nExpirationTime;
|
||||
}
|
||||
|
||||
bool CClaimTrieCacheExpirationFork::incrementBlock(insertUndoType& insertUndo, claimQueueRowType& expireUndo, insertUndoType& insertSupportUndo, supportQueueRowType& expireSupportUndo, std::vector<std::pair<std::string, int>>& takeoverHeightUndo)
|
||||
{
|
||||
if (CClaimTrieCacheBase::incrementBlock(insertUndo, expireUndo, insertSupportUndo, expireSupportUndo, takeoverHeightUndo)) {
|
||||
setExpirationTime(Params().GetConsensus().GetExpirationTime(nNextHeight));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CClaimTrieCacheExpirationFork::decrementBlock(insertUndoType& insertUndo, claimQueueRowType& expireUndo, insertUndoType& insertSupportUndo, supportQueueRowType& expireSupportUndo)
|
||||
{
|
||||
if (CClaimTrieCacheBase::decrementBlock(insertUndo, expireUndo, insertSupportUndo, expireSupportUndo)) {
|
||||
setExpirationTime(Params().GetConsensus().GetExpirationTime(nNextHeight));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void CClaimTrieCacheExpirationFork::expirationForkActive(int nHeight, bool increment)
|
||||
{
|
||||
if (nHeight == Params().GetConsensus().nExtendedClaimExpirationForkHeight)
|
||||
forkForExpirationChange(increment);
|
||||
}
|
||||
|
||||
bool CClaimTrieCacheExpirationFork::forkForExpirationChange(bool increment)
|
||||
@@ -42,23 +61,23 @@ bool CClaimTrieCacheExpirationFork::forkForExpirationChange(bool increment)
|
||||
*/
|
||||
|
||||
//look through db for expiration queues, if we haven't already found it in dirty expiration queue
|
||||
boost::scoped_ptr<CDBIterator> pcursor(base->db->NewIterator());
|
||||
for (pcursor->SeekToFirst(); pcursor->Valid(); pcursor->Next()) {
|
||||
CSqlIterator pcursor(*(base->db));
|
||||
for (pcursor.SeekToFirst(); pcursor.Valid(); pcursor.Next()) {
|
||||
std::pair<uint8_t, int> key;
|
||||
if (!pcursor->GetKey(key))
|
||||
if (!pcursor.GetKey(key))
|
||||
continue;
|
||||
int height = key.second;
|
||||
if (key.first == EXP_QUEUE_ROW) {
|
||||
if (key.first == CLAIM_EXP_QUEUE_ROW) {
|
||||
expirationQueueRowType row;
|
||||
if (pcursor->GetValue(row)) {
|
||||
removeAndAddToExpirationQueue(row, height, increment);
|
||||
if (pcursor.GetValue(row)) {
|
||||
reactivateClaim(row, height, increment);
|
||||
} else {
|
||||
return error("%s(): error reading expiration queue rows from disk", __func__);
|
||||
}
|
||||
} else if (key.first == SUPPORT_EXP_QUEUE_ROW) {
|
||||
expirationQueueRowType row;
|
||||
if (pcursor->GetValue(row)) {
|
||||
removeAndAddSupportToExpirationQueue(row, height, increment);
|
||||
if (pcursor.GetValue(row)) {
|
||||
reactivateSupport(row, height, increment);
|
||||
} else {
|
||||
return error("%s(): error reading support expiration queue rows from disk", __func__);
|
||||
}
|
||||
@@ -142,42 +161,48 @@ bool CClaimTrieCacheNormalizationFork::normalizeAllNamesInTrieIfNecessary(insert
|
||||
// run the one-time upgrade of all names that need to change
|
||||
// it modifies the (cache) trie as it goes, so we need to grab everything to be modified first
|
||||
|
||||
for (auto it = base->begin(); it != base->end(); ++it) {
|
||||
const std::string normalized = normalizeClaimName(it.key(), true);
|
||||
if (normalized == it.key())
|
||||
CSqlIterator pcursor(*(base->db));
|
||||
for (pcursor.SeekToFirst(); pcursor.Valid(); pcursor.Next()) {
|
||||
std::pair<uint8_t, std::string> key;
|
||||
if (!pcursor.GetKey(key) || key.first != TRIE_NODE_BY_NAME)
|
||||
continue;
|
||||
|
||||
auto supports = getSupportsForName(it.key());
|
||||
for (auto& support : supports) {
|
||||
const auto& name = key.second;
|
||||
const std::string normalized = normalizeClaimName(name, true);
|
||||
if (normalized == key.second)
|
||||
continue;
|
||||
|
||||
auto supports = getSupportsForName(name);
|
||||
for (auto support : supports) {
|
||||
// if it's already going to expire just skip it
|
||||
if (support.nHeight + base->nExpirationTime <= nNextHeight)
|
||||
if (support.nHeight + expirationTime() <= nNextHeight)
|
||||
continue;
|
||||
|
||||
CSupportValue removed;
|
||||
assert(removeSupportFromMap(it.key(), support.outPoint, removed, false));
|
||||
expireSupportUndo.emplace_back(it.key(), removed);
|
||||
assert(removeSupportFromMap(name, support.outPoint, support, false));
|
||||
expireSupportUndo.emplace_back(name, support);
|
||||
assert(insertSupportIntoMap(normalized, support, false));
|
||||
insertSupportUndo.emplace_back(it.key(), support.outPoint, -1);
|
||||
insertSupportUndo.emplace_back(name, support.outPoint, -1);
|
||||
}
|
||||
|
||||
namesToCheckForTakeover.insert(normalized);
|
||||
|
||||
auto cached = cacheData(it.key(), false);
|
||||
if (!cached || cached->claims.empty())
|
||||
auto cached = cacheData(name, false);
|
||||
if (!cached || cached->empty())
|
||||
continue;
|
||||
|
||||
for (auto& claim : it->claims) {
|
||||
if (claim.nHeight + base->nExpirationTime <= nNextHeight)
|
||||
auto claimsCopy = cached->claims;
|
||||
auto takeoverHeightCopy = cached->nHeightOfLastTakeover;
|
||||
for (auto claim : claimsCopy) {
|
||||
if (claim.nHeight + expirationTime() <= nNextHeight)
|
||||
continue;
|
||||
|
||||
CClaimValue removed;
|
||||
assert(removeClaimFromTrie(it.key(), claim.outPoint, removed, false));
|
||||
removeUndo.emplace_back(it.key(), removed);
|
||||
assert(insertClaimIntoTrie(normalized, claim, false));
|
||||
insertUndo.emplace_back(it.key(), claim.outPoint, -1);
|
||||
assert(removeClaimFromTrie(name, claim.outPoint, claim, false));
|
||||
removeUndo.emplace_back(name, claim);
|
||||
assert(insertClaimIntoTrie(normalized, claim, true));
|
||||
insertUndo.emplace_back(name, claim.outPoint, -1);
|
||||
}
|
||||
|
||||
takeoverHeightUndo.emplace_back(it.key(), it->nHeightOfLastTakeover);
|
||||
takeoverHeightUndo.emplace_back(name, takeoverHeightCopy);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -213,21 +238,11 @@ CClaimsForNameType CClaimTrieCacheNormalizationFork::getClaimsForName(const std:
|
||||
return CClaimTrieCacheExpirationFork::getClaimsForName(normalizeClaimName(name));
|
||||
}
|
||||
|
||||
int CClaimTrieCacheNormalizationFork::getDelayForName(const std::string& name, const uint160& claimId)
|
||||
int CClaimTrieCacheNormalizationFork::getDelayForName(const std::string& name, const uint160& claimId) const
|
||||
{
|
||||
return CClaimTrieCacheExpirationFork::getDelayForName(normalizeClaimName(name), claimId);
|
||||
}
|
||||
|
||||
bool CClaimTrieCacheNormalizationFork::addClaimToQueues(const std::string& name, const CClaimValue& claim)
|
||||
{
|
||||
return CClaimTrieCacheExpirationFork::addClaimToQueues(normalizeClaimName(name, claim.nValidAtHeight > Params().GetConsensus().nNormalizedNameForkHeight), claim);
|
||||
}
|
||||
|
||||
bool CClaimTrieCacheNormalizationFork::addSupportToQueues(const std::string& name, const CSupportValue& support)
|
||||
{
|
||||
return CClaimTrieCacheExpirationFork::addSupportToQueues(normalizeClaimName(name, support.nValidAtHeight > Params().GetConsensus().nNormalizedNameForkHeight), support);
|
||||
}
|
||||
|
||||
std::string CClaimTrieCacheNormalizationFork::adjustNameForValidHeight(const std::string& name, int validHeight) const
|
||||
{
|
||||
return normalizeClaimName(name, validHeight > Params().GetConsensus().nNormalizedNameForkHeight);
|
||||
|
||||
+1
-4
@@ -1461,7 +1461,7 @@ bool AppInitMain()
|
||||
pblocktree.reset();
|
||||
pblocktree.reset(new CBlockTreeDB(nBlockTreeDBCache, false, fReset));
|
||||
delete pclaimTrie;
|
||||
pclaimTrie = new CClaimTrie(false, fReindex);
|
||||
pclaimTrie = new CClaimTrie(false, fReindex || fReindexChainState);
|
||||
|
||||
if (fReset) {
|
||||
pblocktree->WriteReindexing(true);
|
||||
@@ -1702,9 +1702,6 @@ bool AppInitMain()
|
||||
}
|
||||
LogPrintf("nBestHeight = %d\n", chain_active_height);
|
||||
|
||||
const Consensus::Params& consensusParams = Params().GetConsensus();
|
||||
CClaimTrieCache(pclaimTrie).setExpirationTime(consensusParams.GetExpirationTime(chain_active_height));
|
||||
|
||||
if (gArgs.GetBoolArg("-listenonion", DEFAULT_LISTEN_ONION))
|
||||
StartTorControl();
|
||||
|
||||
|
||||
@@ -119,6 +119,7 @@ const CLogCategoryDesc LogCategories[] =
|
||||
{BCLog::COINDB, "coindb"},
|
||||
{BCLog::QT, "qt"},
|
||||
{BCLog::LEVELDB, "leveldb"},
|
||||
{BCLog::CLAIMS, "claims"},
|
||||
{BCLog::ALL, "1"},
|
||||
{BCLog::ALL, "all"},
|
||||
};
|
||||
|
||||
@@ -53,6 +53,7 @@ namespace BCLog {
|
||||
COINDB = (1 << 18),
|
||||
QT = (1 << 19),
|
||||
LEVELDB = (1 << 20),
|
||||
CLAIMS = (1 << 30),
|
||||
ALL = ~(uint32_t)0,
|
||||
};
|
||||
|
||||
|
||||
+35
-55
@@ -53,6 +53,35 @@ int64_t UpdateTime(CBlockHeader* pblock, const Consensus::Params& consensusParam
|
||||
return nNewTime - nOldTime;
|
||||
}
|
||||
|
||||
void blockToCache(const CBlock* pblock, CClaimTrieCache& trieCache, int nHeight)
|
||||
{
|
||||
insertUndoType dummyInsertUndo;
|
||||
claimQueueRowType dummyExpireUndo;
|
||||
insertUndoType dummyInsertSupportUndo;
|
||||
supportQueueRowType dummyExpireSupportUndo;
|
||||
std::vector<std::pair<std::string, int> > dummyTakeoverHeightUndo;
|
||||
|
||||
CUpdateCacheCallbacks callbacks = {
|
||||
.findScriptKey = [&pblock](const COutPoint& point) {
|
||||
for (auto& tx : pblock->vtx)
|
||||
if (tx->GetHash() == point.hash && point.n < tx->vout.size())
|
||||
return tx->vout[point.n].scriptPubKey;
|
||||
return CScript{};
|
||||
},
|
||||
.claimUndoHeights = {}
|
||||
};
|
||||
|
||||
trieCache.expirationForkActive(nHeight, true);
|
||||
|
||||
CCoinsViewCache view(pcoinsTip.get());
|
||||
|
||||
for (auto& tx : pblock->vtx)
|
||||
if (!tx->IsCoinBase())
|
||||
UpdateCache(*tx, trieCache, view, nHeight, callbacks);
|
||||
|
||||
trieCache.incrementBlock(dummyInsertUndo, dummyExpireUndo, dummyInsertSupportUndo, dummyExpireSupportUndo, dummyTakeoverHeightUndo);
|
||||
}
|
||||
|
||||
BlockAssembler::Options::Options() {
|
||||
blockMinFeeRate = CFeeRate(DEFAULT_BLOCK_MIN_TX_FEE);
|
||||
nBlockMaxWeight = DEFAULT_BLOCK_MAX_WEIGHT;
|
||||
@@ -118,12 +147,6 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
|
||||
CBlockIndex* pindexPrev = chainActive.Tip();
|
||||
assert(pindexPrev != nullptr);
|
||||
nHeight = pindexPrev->nHeight + 1;
|
||||
if (!pclaimTrie)
|
||||
{
|
||||
LogPrintf("CreateNewBlock(): pclaimTrie is invalid");
|
||||
return NULL;
|
||||
}
|
||||
CClaimTrieCache trieCache(pclaimTrie);
|
||||
pblock->nVersion = ComputeBlockVersion(pindexPrev, chainparams.GetConsensus());
|
||||
// -regtest only: allow overriding block.nVersion with
|
||||
// -blockversion=N to test forking scenarios
|
||||
@@ -150,7 +173,7 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
|
||||
|
||||
int nPackagesSelected = 0;
|
||||
int nDescendantsUpdated = 0;
|
||||
addPackageTxs(nPackagesSelected, nDescendantsUpdated, trieCache);
|
||||
addPackageTxs(nPackagesSelected, nDescendantsUpdated);
|
||||
|
||||
int64_t nTime1 = GetTimeMicros();
|
||||
|
||||
@@ -178,20 +201,14 @@ std::unique_ptr<CBlockTemplate> BlockAssembler::CreateNewBlock(const CScript& sc
|
||||
pblock->nNonce = 0;
|
||||
pblocktemplate->vTxSigOpsCost[0] = WITNESS_SCALE_FACTOR * GetLegacySigOpCount(*pblock->vtx[0]);
|
||||
|
||||
insertUndoType dummyInsertUndo;
|
||||
claimQueueRowType dummyExpireUndo;
|
||||
insertUndoType dummyInsertSupportUndo;
|
||||
supportQueueRowType dummyExpireSupportUndo;
|
||||
std::vector<std::pair<std::string, int> > dummyTakeoverHeightUndo;
|
||||
|
||||
trieCache.incrementBlock(dummyInsertUndo, dummyExpireUndo, dummyInsertSupportUndo, dummyExpireSupportUndo, dummyTakeoverHeightUndo);
|
||||
|
||||
CClaimTrieCache trieCache(pclaimTrie);
|
||||
blockToCache(pblock, trieCache, nHeight);
|
||||
pblock->hashClaimTrie = trieCache.getMerkleHash();
|
||||
|
||||
CValidationState state;
|
||||
if (!TestBlockValidity(state, chainparams, *pblock, pindexPrev, false, false)) {
|
||||
// if (trieCache.checkConsistency()) // TODO: bring back after prefixtrie merge
|
||||
// trieCache.dumpToLog(trieCache.begin());
|
||||
if (!trieCache.empty())
|
||||
trieCache.dumpToLog(trieCache.begin());
|
||||
throw std::runtime_error(strprintf("%s: TestBlockValidity failed: %s", __func__, FormatStateMessage(state)));
|
||||
}
|
||||
int64_t nTime2 = GetTimeMicros();
|
||||
@@ -311,42 +328,6 @@ void BlockAssembler::SortForBlock(const CTxMemPool::setEntries& package, std::ve
|
||||
std::sort(sortedEntries.begin(), sortedEntries.end(), CompareTxIterByAncestorCount());
|
||||
}
|
||||
|
||||
void iterToTrieCache(CTxMemPool::txiter iter, CClaimTrieCache& trieCache, const CTxMemPool::setEntries& entries, int nHeight)
|
||||
{
|
||||
spentClaimsType spentClaims;
|
||||
auto& tx = iter->GetTx();
|
||||
|
||||
CCoinsViewCache view(pcoinsTip.get());
|
||||
for (const CTxIn& txin: tx.vin) {
|
||||
const Coin& coin = view.AccessCoin(txin.prevout);
|
||||
CScript scriptPubKey;
|
||||
int scriptHeight = nHeight;
|
||||
if (coin.out.IsNull()) {
|
||||
for (auto entry : entries) {
|
||||
auto& e = entry->GetTx();
|
||||
if (e.GetHash() != txin.prevout.hash || txin.prevout.n >= e.vout.size())
|
||||
continue;
|
||||
scriptPubKey = e.vout[txin.prevout.n].scriptPubKey;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
scriptPubKey = coin.out.scriptPubKey;
|
||||
scriptHeight = coin.nHeight;
|
||||
}
|
||||
|
||||
if (!scriptPubKey.empty()) {
|
||||
int throwaway;
|
||||
SpendClaim(trieCache, scriptPubKey, COutPoint(txin.prevout.hash, txin.prevout.n), scriptHeight, throwaway, spentClaims);
|
||||
}
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < tx.vout.size(); ++i) {
|
||||
const CTxOut& txout = tx.vout[i];
|
||||
if (!txout.scriptPubKey.empty())
|
||||
AddSpendClaim(trieCache, txout.scriptPubKey, COutPoint(tx.GetHash(), i), txout.nValue, nHeight, spentClaims);
|
||||
}
|
||||
}
|
||||
|
||||
// This transaction selection algorithm orders the mempool based
|
||||
// on feerate of a transaction including all unconfirmed ancestors.
|
||||
// Since we don't remove transactions from the mempool as we select them
|
||||
@@ -357,7 +338,7 @@ void iterToTrieCache(CTxMemPool::txiter iter, CClaimTrieCache& trieCache, const
|
||||
// Each time through the loop, we compare the best transaction in
|
||||
// mapModifiedTxs with the next transaction in the mempool to decide what
|
||||
// transaction package to work on next.
|
||||
void BlockAssembler::addPackageTxs(int &nPackagesSelected, int &nDescendantsUpdated, CClaimTrieCache& trieCache)
|
||||
void BlockAssembler::addPackageTxs(int &nPackagesSelected, int &nDescendantsUpdated)
|
||||
{
|
||||
// mapModifiedTx will store sorted packages after they are modified
|
||||
// because some of their txs are already in the block
|
||||
@@ -474,7 +455,6 @@ void BlockAssembler::addPackageTxs(int &nPackagesSelected, int &nDescendantsUpda
|
||||
SortForBlock(ancestors, sortedEntries);
|
||||
|
||||
for (size_t i=0; i<sortedEntries.size(); ++i) {
|
||||
iterToTrieCache(sortedEntries[i], trieCache, inBlock, nHeight);
|
||||
AddToBlock(sortedEntries[i]);
|
||||
// Erase from the modified set, if present
|
||||
mapModifiedTx.erase(sortedEntries[i]);
|
||||
|
||||
+1
-1
@@ -170,7 +170,7 @@ private:
|
||||
/** Add transactions based on feerate including unconfirmed ancestors
|
||||
* Increments nPackagesSelected / nDescendantsUpdated with corresponding
|
||||
* statistics from the package selection (for logging statistics). */
|
||||
void addPackageTxs(int &nPackagesSelected, int &nDescendantsUpdated, CClaimTrieCache& trieCache) EXCLUSIVE_LOCKS_REQUIRED(mempool.cs);
|
||||
void addPackageTxs(int &nPackagesSelected, int &nDescendantsUpdated) EXCLUSIVE_LOCKS_REQUIRED(mempool.cs);
|
||||
|
||||
// helper functions for addPackageTxs()
|
||||
/** Remove confirmed (inBlock) entries from given set */
|
||||
|
||||
@@ -174,21 +174,6 @@ std::vector<typename CPrefixTrie<TKey, TData>::template Iterator<IsConst>> CPref
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <typename TKey>
|
||||
static std::size_t match(const TKey& a, const TKey& b)
|
||||
{
|
||||
std::size_t count = 0;
|
||||
auto ait = a.cbegin(), aend = a.cend();
|
||||
auto bit = b.cbegin(), bend = b.cend();
|
||||
while (ait != aend && bit != bend) {
|
||||
if (*ait != *bit) break;
|
||||
++count;
|
||||
++ait;
|
||||
++bit;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
template <typename TKey, typename TData>
|
||||
template <typename TIterator, typename TNode>
|
||||
TIterator CPrefixTrie<TKey, TData>::find(const TKey& key, TNode node, TIterator end)
|
||||
|
||||
@@ -193,4 +193,19 @@ inline bool operator!=(const std::reference_wrapper<std::unique_ptr<T>>& ref, co
|
||||
return !(ref == obj);
|
||||
}
|
||||
|
||||
template <typename TKey>
|
||||
static std::size_t match(const TKey& a, const TKey& b)
|
||||
{
|
||||
std::size_t count = 0;
|
||||
auto ait = a.cbegin(), aend = a.cend();
|
||||
auto bit = b.cbegin(), bend = b.cend();
|
||||
while (ait != aend && bit != bend) {
|
||||
if (*ait != *bit) break;
|
||||
++count;
|
||||
++ait;
|
||||
++bit;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
#endif // BITCOIN_PREFIXTRIE_H
|
||||
+45
-39
@@ -174,48 +174,52 @@ static UniValue getclaimsintrie(const JSONRPCRequest& request)
|
||||
throw JSONRPCError(RPC_METHOD_DEPRECATED, msg);
|
||||
}
|
||||
|
||||
UniValue ret(UniValue::VARR);
|
||||
uint256 rootHash;
|
||||
LOCK(cs_main);
|
||||
|
||||
CCoinsViewCache coinsCache(pcoinsTip.get());
|
||||
CClaimTrieCache trieCache(pclaimTrie);
|
||||
|
||||
if (!request.params.empty()) {
|
||||
CBlockIndex* blockIndex = BlockHashIndex(ParseHashV(request.params[0], "blockhash (optional parameter 1)"));
|
||||
CBlockIndex *blockIndex = BlockHashIndex(ParseHashV(request.params[0], "blockhash (optional parameter 1)"));
|
||||
RollBackTo(blockIndex, coinsCache, trieCache);
|
||||
}
|
||||
rootHash = trieCache.getMerkleHash();
|
||||
|
||||
UniValue ret(UniValue::VARR);
|
||||
for (auto it = trieCache.begin(); it != trieCache.end(); ++it)
|
||||
{
|
||||
CClaimTrieDataNode rootNode;
|
||||
if (!pclaimTrie->find(rootHash, rootNode))
|
||||
return ret;
|
||||
|
||||
pclaimTrie->recurseAllHashedNodes("", rootNode, [&ret, &trieCache, &coinsCache](const std::string &name,
|
||||
const CClaimTrieDataNode &node) {
|
||||
if (ShutdownRequested())
|
||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "Shutdown requested");
|
||||
|
||||
boost::this_thread::interruption_point();
|
||||
|
||||
if (it->empty())
|
||||
continue;
|
||||
if (node.data.empty())
|
||||
return;
|
||||
|
||||
UniValue claims(UniValue::VARR);
|
||||
for (auto itClaims = it->claims.cbegin(); itClaims != it->claims.cend(); ++itClaims) {
|
||||
for (auto itClaims = node.data.claims.cbegin(); itClaims != node.data.claims.cend(); ++itClaims) {
|
||||
UniValue claim(UniValue::VOBJ);
|
||||
claim.pushKV("claimId", itClaims->claimId.GetHex());
|
||||
claim.pushKV("txid", itClaims->outPoint.hash.GetHex());
|
||||
claim.pushKV("n", (int)itClaims->outPoint.n);
|
||||
claim.pushKV("n", (int) itClaims->outPoint.n);
|
||||
claim.pushKV("amount", ValueFromAmount(itClaims->nAmount));
|
||||
claim.pushKV("height", itClaims->nHeight);
|
||||
const Coin& coin = coinsCache.AccessCoin(itClaims->outPoint);
|
||||
if (coin.IsSpent())
|
||||
{
|
||||
LogPrintf("%s: the specified txout of %s appears to have been spent\n", __func__, itClaims->outPoint.hash.GetHex());
|
||||
const Coin &coin = coinsCache.AccessCoin(itClaims->outPoint);
|
||||
if (coin.IsSpent()) {
|
||||
LogPrintf("%s: the specified txout of %s appears to have been spent\n", __func__,
|
||||
itClaims->outPoint.hash.GetHex());
|
||||
claim.pushKV("error", "Txout spent");
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
int op;
|
||||
std::vector<std::vector<unsigned char> > vvchParams;
|
||||
if (!DecodeClaimScript(coin.out.scriptPubKey, op, vvchParams))
|
||||
{
|
||||
LogPrintf("%s: the specified txout of %s does not have an claim command\n", __func__, itClaims->outPoint.hash.GetHex());
|
||||
if (!DecodeClaimScript(coin.out.scriptPubKey, op, vvchParams)) {
|
||||
LogPrintf("%s: the specified txout of %s does not have an claim command\n", __func__,
|
||||
itClaims->outPoint.hash.GetHex());
|
||||
}
|
||||
claim.pushKV("value", HexStr(vvchParams[1].begin(), vvchParams[1].end()));
|
||||
}
|
||||
@@ -228,11 +232,10 @@ static UniValue getclaimsintrie(const JSONRPCRequest& request)
|
||||
}
|
||||
|
||||
UniValue nodeObj(UniValue::VOBJ);
|
||||
nodeObj.pushKV("normalized_name", escapeNonUtf8(it.key()));
|
||||
nodeObj.pushKV("normalized_name", escapeNonUtf8(name));
|
||||
nodeObj.pushKV("claims", claims);
|
||||
ret.push_back(nodeObj);
|
||||
}
|
||||
|
||||
});
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -258,27 +261,33 @@ static UniValue getnamesintrie(const JSONRPCRequest& request)
|
||||
"Result: \n"
|
||||
"\"names\" (array) all names in the trie that have claims\n");
|
||||
|
||||
LOCK(cs_main);
|
||||
uint256 rootHash;
|
||||
{
|
||||
LOCK(cs_main);
|
||||
|
||||
CCoinsViewCache coinsCache(pcoinsTip.get());
|
||||
CClaimTrieCache trieCache(pclaimTrie);
|
||||
CCoinsViewCache coinsCache(pcoinsTip.get());
|
||||
CClaimTrieCache trieCache(pclaimTrie);
|
||||
|
||||
if (!request.params.empty()) {
|
||||
CBlockIndex* blockIndex = BlockHashIndex(ParseHashV(request.params[0], "blockhash (optional parameter 1)"));
|
||||
RollBackTo(blockIndex, coinsCache, trieCache);
|
||||
if (!request.params.empty()) {
|
||||
CBlockIndex *blockIndex = BlockHashIndex(ParseHashV(request.params[0], "blockhash (optional parameter 1)"));
|
||||
RollBackTo(blockIndex, coinsCache, trieCache);
|
||||
}
|
||||
rootHash = trieCache.getMerkleHash();
|
||||
}
|
||||
|
||||
UniValue ret(UniValue::VARR);
|
||||
|
||||
for (auto it = trieCache.begin(); it != trieCache.end(); ++it) {
|
||||
CClaimTrieDataNode rootNode;
|
||||
if (!pclaimTrie->find(rootHash, rootNode))
|
||||
return ret;
|
||||
|
||||
pclaimTrie->recurseAllHashedNodes("", rootNode, [&ret](const std::string& name, const CClaimTrieDataNode& node) {
|
||||
if (!node.data.empty())
|
||||
ret.push_back(escapeNonUtf8(name));
|
||||
if (ShutdownRequested())
|
||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "Shutdown requested");
|
||||
|
||||
boost::this_thread::interruption_point();
|
||||
|
||||
if (!it->empty())
|
||||
ret.push_back(escapeNonUtf8(it.key()));
|
||||
}
|
||||
});
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -580,8 +589,7 @@ UniValue gettotalclaimednames(const JSONRPCRequest& request)
|
||||
" names in the trie\n"
|
||||
);
|
||||
LOCK(cs_main);
|
||||
CClaimTrieCache trieCache(pclaimTrie);
|
||||
auto num_names = trieCache.getTotalNamesInTrie();
|
||||
auto num_names = pclaimTrie->getTotalNamesInTrie();
|
||||
return int(num_names);
|
||||
}
|
||||
|
||||
@@ -597,8 +605,7 @@ UniValue gettotalclaims(const JSONRPCRequest& request)
|
||||
" of active claims\n"
|
||||
);
|
||||
LOCK(cs_main);
|
||||
CClaimTrieCache trieCache(pclaimTrie);
|
||||
auto num_claims = trieCache.getTotalClaimsInTrie();
|
||||
auto num_claims = pclaimTrie->getTotalClaimsInTrie();
|
||||
return int(num_claims);
|
||||
}
|
||||
|
||||
@@ -619,8 +626,7 @@ UniValue gettotalvalueofclaims(const JSONRPCRequest& request)
|
||||
bool controlling_only = false;
|
||||
if (request.params.size() == 1)
|
||||
controlling_only = request.params[0].get_bool();
|
||||
CClaimTrieCache trieCache(pclaimTrie);
|
||||
auto total_amount = trieCache.getTotalValueOfClaimsInTrie(controlling_only);
|
||||
auto total_amount = pclaimTrie->getTotalValueOfClaimsInTrie(controlling_only);
|
||||
return ValueFromAmount(total_amount);
|
||||
}
|
||||
|
||||
|
||||
+7
-7
@@ -559,8 +559,8 @@ template<typename Stream, typename K, typename T> void Unserialize(Stream& is, s
|
||||
/**
|
||||
* map
|
||||
*/
|
||||
template<typename Stream, typename K, typename T, typename Pred, typename A> void Serialize(Stream& os, const std::map<K, T, Pred, A>& m);
|
||||
template<typename Stream, typename K, typename T, typename Pred, typename A> void Unserialize(Stream& is, std::map<K, T, Pred, A>& m);
|
||||
template<typename Stream, typename K, typename T, typename ... Z> void Serialize(Stream& os, const std::map<K, T, Z...>& m);
|
||||
template<typename Stream, typename K, typename T, typename ... Z> void Unserialize(Stream& is, std::map<K, T, Z...>& m);
|
||||
|
||||
/**
|
||||
* set
|
||||
@@ -781,20 +781,20 @@ void Unserialize(Stream& is, std::pair<K, T>& item)
|
||||
/**
|
||||
* map
|
||||
*/
|
||||
template<typename Stream, typename K, typename T, typename Pred, typename A>
|
||||
void Serialize(Stream& os, const std::map<K, T, Pred, A>& m)
|
||||
template<typename Stream, typename K, typename T, typename ... Z>
|
||||
void Serialize(Stream& os, const std::map<K, T, Z...>& m)
|
||||
{
|
||||
WriteCompactSize(os, m.size());
|
||||
for (const auto& entry : m)
|
||||
Serialize(os, entry);
|
||||
}
|
||||
|
||||
template<typename Stream, typename K, typename T, typename Pred, typename A>
|
||||
void Unserialize(Stream& is, std::map<K, T, Pred, A>& m)
|
||||
template<typename Stream, typename K, typename T, typename ... Z>
|
||||
void Unserialize(Stream& is, std::map<K, T, Z...>& m)
|
||||
{
|
||||
m.clear();
|
||||
unsigned int nSize = ReadCompactSize(is);
|
||||
typename std::map<K, T, Pred, A>::iterator mi = m.begin();
|
||||
typename std::map<K, T, Z...>::iterator mi = m.begin();
|
||||
for (unsigned int i = 0; i < nSize; i++)
|
||||
{
|
||||
std::pair<K, T> item;
|
||||
|
||||
@@ -0,0 +1,323 @@
|
||||
// Copyright (c) 2012-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.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <clientversion.h>
|
||||
#include <fs.h>
|
||||
#include <serialize.h>
|
||||
#include <streams.h>
|
||||
#include <util.h>
|
||||
#include <utilstrencodings.h>
|
||||
#include <version.h>
|
||||
|
||||
#include <sqlite3.h>
|
||||
|
||||
class CSqlBatch;
|
||||
class CSqlIterator;
|
||||
|
||||
class CSqlWrapper
|
||||
{
|
||||
friend CSqlBatch;
|
||||
friend CSqlIterator;
|
||||
sqlite3 *pdb;
|
||||
mutable CDataStream ssKey;
|
||||
mutable CDataStream ssValue;
|
||||
|
||||
void VerifyRC(int rc, int target, int line) const {
|
||||
if (rc != target) {
|
||||
auto error = sqlite3_errmsg(pdb);
|
||||
LogPrintf("Query error %d on line %d: %s\n", rc, line, error);
|
||||
assert(rc == target);
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
/**
|
||||
* @param[in] path Location in the filesystem where leveldb data will be stored.
|
||||
* @param[in] nCacheSize Configures various leveldb cache settings.
|
||||
* @param[in] fMemory If true, use leveldb's memory environment.
|
||||
* @param[in] fWipe If true, remove all existing data.
|
||||
* @param[in] obfuscate If true, store data obfuscated via simple XOR. If false, XOR
|
||||
* with a zero'd byte array.
|
||||
*/
|
||||
CSqlWrapper(const fs::path& path, size_t nCacheSize, bool fMemory = false, bool fWipe = false):
|
||||
ssKey(SER_DISK, CLIENT_VERSION), ssValue(SER_DISK, CLIENT_VERSION) {
|
||||
int rc = sqlite3_open_v2(fMemory ? ":memory:" : path.c_str(), &pdb, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, nullptr);
|
||||
if (rc != SQLITE_OK)
|
||||
{
|
||||
LogPrintf("ERROR: Unable to open %s. Message: %s\n", path, sqlite3_errmsg(pdb));
|
||||
assert(rc == SQLITE_OK);
|
||||
}
|
||||
char* error = nullptr;
|
||||
rc = sqlite3_exec(pdb, "CREATE TABLE IF NOT EXISTS kv (key BLOB PRIMARY KEY, value BLOB);", nullptr, nullptr, &error);
|
||||
if (rc != SQLITE_OK) {
|
||||
LogPrintf("ERROR: Unable to create kv table. Message: %s\n", error);
|
||||
sqlite3_free(error);
|
||||
sqlite3_close(pdb);
|
||||
assert(rc == SQLITE_OK);
|
||||
}
|
||||
|
||||
if (fWipe) {
|
||||
rc = sqlite3_exec(pdb, "DELETE FROM kv;", nullptr, nullptr, &error);
|
||||
if (rc != SQLITE_OK) {
|
||||
LogPrintf("ERROR: Unable to drop kv table. Message: %s\n", error);
|
||||
sqlite3_free(error);
|
||||
sqlite3_close(pdb);
|
||||
assert(rc == SQLITE_OK);
|
||||
}
|
||||
}
|
||||
std::string pragmas = "PRAGMA cache_size=-" + std::to_string(nCacheSize >> 10)
|
||||
+ "; PRAGMA journal_mode=WAL; PRAGMA temp_store=MEMORY; PRAGMA synchronous=NORMAL; PRAGMA wal_autocheckpoint=10000;";
|
||||
rc = sqlite3_exec(pdb, pragmas.c_str(), nullptr, nullptr, &error);
|
||||
if (rc != SQLITE_OK) {
|
||||
LogPrintf("ERROR: Unable to set cache size. Message: %s\n", error);
|
||||
sqlite3_free(error);
|
||||
sqlite3_close(pdb);
|
||||
assert(rc == SQLITE_OK);
|
||||
}
|
||||
}
|
||||
~CSqlWrapper() {
|
||||
sqlite3_close(pdb);
|
||||
}
|
||||
|
||||
CSqlWrapper(const CSqlWrapper&) = delete;
|
||||
|
||||
template <typename K, typename V>
|
||||
bool Read(const K& key, V& value) const
|
||||
{
|
||||
ssKey << key;
|
||||
|
||||
sqlite3_stmt *stmt = nullptr;
|
||||
auto rc = sqlite3_prepare_v2(pdb, "SELECT value FROM kv WHERE key = ?", -1, &stmt, nullptr);
|
||||
VerifyRC(rc, SQLITE_OK, __LINE__);
|
||||
rc = sqlite3_bind_blob(stmt, 1, ssKey.data(), ssKey.size(), SQLITE_STATIC);
|
||||
VerifyRC(rc, SQLITE_OK, __LINE__);
|
||||
rc = sqlite3_step(stmt);
|
||||
bool ret = false;
|
||||
if (rc == SQLITE_ROW) {
|
||||
auto blob_size = sqlite3_column_bytes(stmt, 0);
|
||||
auto blob = reinterpret_cast<const char*>(sqlite3_column_blob(stmt, 0)); // released on step/finalize
|
||||
if (blob_size && blob) {
|
||||
try {
|
||||
CDataStream ssValue(blob, blob + blob_size, SER_DISK, CLIENT_VERSION);
|
||||
ssValue >> value;
|
||||
ret = true;
|
||||
} catch (const std::exception &) {}
|
||||
}
|
||||
}
|
||||
sqlite3_finalize(stmt);
|
||||
ssKey.clear();
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <typename K, typename V>
|
||||
bool Write(const K& key, const V& value, bool fSync = false)
|
||||
{
|
||||
ssKey << key;
|
||||
ssValue << value;
|
||||
|
||||
sqlite3_stmt *stmt = nullptr;
|
||||
auto rc = sqlite3_prepare_v2(pdb, "REPLACE INTO kv VALUES(?, ?)", -1, &stmt, nullptr);
|
||||
VerifyRC(rc, SQLITE_OK, __LINE__);
|
||||
rc = sqlite3_bind_blob(stmt, 1, ssKey.data(), ssKey.size(), SQLITE_STATIC);
|
||||
VerifyRC(rc, SQLITE_OK, __LINE__);
|
||||
rc = sqlite3_bind_blob(stmt, 2, ssValue.data(), ssValue.size(), SQLITE_STATIC);
|
||||
VerifyRC(rc, SQLITE_OK, __LINE__);
|
||||
rc = sqlite3_step(stmt);
|
||||
VerifyRC(rc, SQLITE_DONE, __LINE__);
|
||||
auto ret = sqlite3_changes(pdb) > 0;
|
||||
sqlite3_finalize(stmt);
|
||||
|
||||
ssKey.clear();
|
||||
ssValue.clear();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <typename K>
|
||||
bool Exists(const K& key) const
|
||||
{
|
||||
ssKey << key;
|
||||
|
||||
sqlite3_stmt *stmt = nullptr;
|
||||
auto rc = sqlite3_prepare_v2(pdb, "SELECT 1 FROM kv WHERE key = ?", -1, &stmt, nullptr);
|
||||
VerifyRC(rc, SQLITE_OK, __LINE__);
|
||||
rc = sqlite3_bind_blob(stmt, 1, ssKey.data(), ssKey.size(), SQLITE_STATIC);
|
||||
VerifyRC(rc, SQLITE_OK, __LINE__);
|
||||
rc = sqlite3_step(stmt);
|
||||
bool ret = false;
|
||||
if (rc == SQLITE_ROW)
|
||||
ret = 1 == sqlite3_column_int(stmt, 0);
|
||||
sqlite3_finalize(stmt);
|
||||
|
||||
ssKey.clear();
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <typename K>
|
||||
bool Erase(const K& key, bool fSync = false)
|
||||
{
|
||||
ssKey << key;
|
||||
|
||||
sqlite3_stmt *stmt = nullptr;
|
||||
auto rc = sqlite3_prepare_v2(pdb, "DELETE FROM kv WHERE key = ?", -1, &stmt, nullptr);
|
||||
VerifyRC(rc, SQLITE_OK, __LINE__);
|
||||
rc = sqlite3_bind_blob(stmt, 1, ssKey.data(), ssKey.size(), SQLITE_STATIC);
|
||||
VerifyRC(rc, SQLITE_OK, __LINE__);
|
||||
rc = sqlite3_step(stmt);
|
||||
VerifyRC(rc, SQLITE_DONE, __LINE__);
|
||||
auto ret = sqlite3_changes(pdb) > 0;
|
||||
sqlite3_finalize(stmt);
|
||||
ssKey.clear();
|
||||
if (fSync) Sync();
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool WriteBatch(CSqlBatch& batch, bool fSync = false) {
|
||||
int rc = sqlite3_exec(pdb, "COMMIT TRANSACTION;", nullptr, nullptr, nullptr);
|
||||
if (rc == SQLITE_OK) {
|
||||
if (fSync)
|
||||
Sync();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// not available for LevelDB; provide for compatibility with BDB
|
||||
bool Flush()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Sync()
|
||||
{
|
||||
auto rc = sqlite3_wal_checkpoint_v2(pdb, nullptr, SQLITE_CHECKPOINT_FULL, nullptr, nullptr);
|
||||
return rc == SQLITE_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the database managed by this class contains no entries.
|
||||
*/
|
||||
bool IsEmpty() {
|
||||
int64_t count = -1;
|
||||
static auto cb = [](void* state, int argc, char** argv, char** cols) {
|
||||
auto data = reinterpret_cast<int64_t*>(state);
|
||||
if (argc)
|
||||
*data = std::atoll(argv[0]);
|
||||
return SQLITE_OK;
|
||||
};
|
||||
int rc = sqlite3_exec(pdb, "SELECT COUNT(*) FROM kv", cb, &count, nullptr);
|
||||
assert(rc == SQLITE_OK);
|
||||
return count == 0;
|
||||
}
|
||||
};
|
||||
|
||||
/** Batch of changes queued to be written to a CDBWrapper */
|
||||
class CSqlBatch
|
||||
{
|
||||
friend class CSqlWrapper;
|
||||
|
||||
private:
|
||||
CSqlWrapper &parent;
|
||||
|
||||
public:
|
||||
/**
|
||||
* @param[in] _parent CDBWrapper that this batch is to be submitted to
|
||||
*/
|
||||
explicit CSqlBatch(CSqlWrapper &_parent) : parent(_parent) {
|
||||
int rc = sqlite3_exec(parent.pdb, "BEGIN TRANSACTION;", nullptr, nullptr, nullptr);
|
||||
parent.VerifyRC(rc, SQLITE_OK, __LINE__);
|
||||
};
|
||||
|
||||
void Clear()
|
||||
{
|
||||
int rc = sqlite3_exec(parent.pdb, "ROLLBACK TRANSACTION;", nullptr, nullptr, nullptr);
|
||||
parent.VerifyRC(rc, SQLITE_OK, __LINE__);
|
||||
}
|
||||
|
||||
template <typename K, typename V>
|
||||
void Write(const K& key, const V& value)
|
||||
{
|
||||
auto ret = parent.Write(key, value, false);
|
||||
assert(ret);
|
||||
}
|
||||
|
||||
template <typename K>
|
||||
void Erase(const K& key)
|
||||
{
|
||||
parent.Erase(key, false);
|
||||
}
|
||||
};
|
||||
|
||||
class CSqlIterator
|
||||
{
|
||||
private:
|
||||
const CSqlWrapper &parent;
|
||||
sqlite3_stmt *stmt;
|
||||
int last_step;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* @param[in] _parent Parent CDBWrapper instance.
|
||||
* @param[in] _piter The original leveldb iterator.
|
||||
*/
|
||||
CSqlIterator(const CSqlWrapper &_parent) :
|
||||
parent(_parent) {
|
||||
stmt = nullptr;
|
||||
auto rc = sqlite3_prepare_v2(parent.pdb, "SELECT * FROM kv;", -1, &stmt, nullptr);
|
||||
parent.VerifyRC(rc, SQLITE_OK, __LINE__);
|
||||
};
|
||||
|
||||
~CSqlIterator() {
|
||||
last_step = SQLITE_DONE;
|
||||
sqlite3_finalize(stmt);
|
||||
}
|
||||
|
||||
bool Valid() const { return last_step == SQLITE_ROW; }
|
||||
|
||||
void SeekToFirst() { auto rc = sqlite3_reset(stmt); assert(rc == SQLITE_OK); Next(); }
|
||||
|
||||
void Next() { last_step = sqlite3_step(stmt); }
|
||||
|
||||
template<typename K> bool GetKey(K& key) {
|
||||
if (last_step != SQLITE_ROW)
|
||||
return false;
|
||||
|
||||
auto blob_size = sqlite3_column_bytes(stmt, 0);
|
||||
auto blob = reinterpret_cast<const char*>(sqlite3_column_blob(stmt, 0)); // released on step/finalize
|
||||
if (blob_size && blob) {
|
||||
try {
|
||||
CDataStream ssKey(blob, blob + blob_size, SER_DISK, CLIENT_VERSION);
|
||||
ssKey >> key;
|
||||
return true;
|
||||
} catch (const std::exception &) {}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template<typename V> bool GetValue(V& value) {
|
||||
if (last_step != SQLITE_ROW)
|
||||
return false;
|
||||
|
||||
auto blob_size = sqlite3_column_bytes(stmt, 1);
|
||||
auto blob = reinterpret_cast<const char*>(sqlite3_column_blob(stmt, 1)); // released on step/finalize
|
||||
if (blob_size && blob) {
|
||||
try {
|
||||
CDataStream ssValue(blob, blob + blob_size, SER_DISK, CLIENT_VERSION);
|
||||
ssValue >> value;
|
||||
return true;
|
||||
} catch (const std::exception &) {}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int GetValueSize() {
|
||||
if (last_step != SQLITE_ROW)
|
||||
return -1;
|
||||
return sqlite3_column_bytes(stmt, 1);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -72,7 +72,7 @@ static BlockAssembler AssemblerForTest()
|
||||
}
|
||||
|
||||
// Test Fixtures
|
||||
struct ClaimTrieChainFixture: public CClaimTrieCacheBase
|
||||
struct ClaimTrieChainFixture: public CClaimTrieCacheExpirationFork
|
||||
{
|
||||
std::vector<CTransaction> coinbase_txs;
|
||||
std::vector<int> marks;
|
||||
@@ -86,9 +86,9 @@ struct ClaimTrieChainFixture: public CClaimTrieCacheBase
|
||||
int64_t originalExpiration;
|
||||
int64_t extendedExpiration;
|
||||
|
||||
using CClaimTrieCacheBase::getSupportsForName;
|
||||
using CClaimTrieCacheExpirationFork::getSupportsForName;
|
||||
|
||||
ClaimTrieChainFixture(): CClaimTrieCacheBase(pclaimTrie),
|
||||
ClaimTrieChainFixture(): CClaimTrieCacheExpirationFork(pclaimTrie),
|
||||
unique_block_counter(0), normalization_original(-1), expirationForkHeight(-1)
|
||||
{
|
||||
fRequireStandard = false;
|
||||
@@ -114,14 +114,12 @@ struct ClaimTrieChainFixture: public CClaimTrieCacheBase
|
||||
DecrementBlocks(chainActive.Height());
|
||||
auto& consensus = const_cast<Consensus::Params&>(Params().GetConsensus());
|
||||
if (normalization_original >= 0)
|
||||
{
|
||||
consensus.nNormalizedNameForkHeight = normalization_original;
|
||||
}
|
||||
|
||||
if (expirationForkHeight >= 0) {
|
||||
consensus.nExtendedClaimExpirationForkHeight = expirationForkHeight;
|
||||
consensus.nExtendedClaimExpirationTime = extendedExpiration;
|
||||
consensus.nOriginalClaimExpirationTime = originalExpiration;
|
||||
base->nExpirationTime = originalExpiration;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,7 +134,7 @@ struct ClaimTrieChainFixture: public CClaimTrieCacheBase
|
||||
consensus.nExtendedClaimExpirationForkHeight = target;
|
||||
consensus.nExtendedClaimExpirationTime = postForkExpirationTime;
|
||||
consensus.nOriginalClaimExpirationTime = preForkExpirationTime;
|
||||
base->nExpirationTime = targetMinusCurrent >= 0 ? preForkExpirationTime : postForkExpirationTime;
|
||||
setExpirationTime(targetMinusCurrent >= 0 ? preForkExpirationTime : postForkExpirationTime);
|
||||
}
|
||||
|
||||
void setNormalizationForkHeight(int targetMinusCurrent) {
|
||||
@@ -292,6 +290,7 @@ struct ClaimTrieChainFixture: public CClaimTrieCacheBase
|
||||
num_txs_for_next_block = 0;
|
||||
nNextHeight = chainActive.Height() + 1;
|
||||
}
|
||||
setExpirationTime(Params().GetConsensus().GetExpirationTime(nNextHeight - 1));
|
||||
}
|
||||
|
||||
//disconnect i blocks from tip
|
||||
@@ -306,9 +305,10 @@ struct ClaimTrieChainFixture: public CClaimTrieCacheBase
|
||||
}
|
||||
BOOST_CHECK_EQUAL(state.IsValid(), true);
|
||||
BOOST_CHECK_EQUAL(ActivateBestChain(state, Params()), true);
|
||||
nNextHeight = chainActive.Height() + 1;
|
||||
mempool.clear();
|
||||
num_txs_for_next_block = 0;
|
||||
nNextHeight = chainActive.Height() + 1;
|
||||
setExpirationTime(Params().GetConsensus().GetExpirationTime(nNextHeight - 1));
|
||||
}
|
||||
|
||||
// decrement back to last mark
|
||||
@@ -322,16 +322,16 @@ struct ClaimTrieChainFixture: public CClaimTrieCacheBase
|
||||
template <typename K>
|
||||
bool keyTypeEmpty(uint8_t keyType)
|
||||
{
|
||||
boost::scoped_ptr<CDBIterator> pcursor(base->db->NewIterator());
|
||||
pcursor->SeekToFirst();
|
||||
CSqlIterator pcursor(*(base->db));
|
||||
pcursor.SeekToFirst();
|
||||
|
||||
while (pcursor->Valid()) {
|
||||
while (pcursor.Valid()) {
|
||||
std::pair<uint8_t, K> key;
|
||||
if (pcursor->GetKey(key)) {
|
||||
if (pcursor.GetKey(key)) {
|
||||
if (key.first == keyType)
|
||||
return false;
|
||||
}
|
||||
pcursor->Next();
|
||||
pcursor.Next();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -351,16 +351,16 @@ struct ClaimTrieChainFixture: public CClaimTrieCacheBase
|
||||
if (!expirationQueue.second.empty())
|
||||
return false;
|
||||
}
|
||||
return keyTypeEmpty<int>(EXP_QUEUE_ROW);
|
||||
return keyTypeEmpty<int>(CLAIM_EXP_QUEUE_ROW);
|
||||
}
|
||||
|
||||
bool supportEmpty()
|
||||
{
|
||||
for (const auto& entry: cacheSupports) {
|
||||
for (const auto& entry: supportCache) {
|
||||
if (!entry.second.empty())
|
||||
return false;
|
||||
}
|
||||
return cacheSupports.empty() && keyTypeEmpty<std::string>(SUPPORT);
|
||||
return supportCache.empty() && keyTypeEmpty<std::string>(SUPPORT);
|
||||
}
|
||||
|
||||
bool supportQueueEmpty()
|
||||
@@ -431,6 +431,8 @@ struct ClaimTrieChainFixture: public CClaimTrieCacheBase
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::size_t getTotalNamesInTrie() const { return base->getTotalNamesInTrie(); }
|
||||
};
|
||||
|
||||
BOOST_FIXTURE_TEST_SUITE(claimtriebranching_tests, RegTestingSetup)
|
||||
@@ -495,10 +497,12 @@ BOOST_AUTO_TEST_CASE(triehash_fuzzer_test)
|
||||
}
|
||||
}
|
||||
fixture.IncrementBlocks(1);
|
||||
if (blocks > 13 && i % 50 == 0) // travisCI needs some periodic output
|
||||
std::cerr << "In triehash_fuzzer_test with " << fixture.getTotalNamesInTrie() << " names at block " << i << std::endl;
|
||||
}
|
||||
|
||||
if (blocks == 1000 && claimsPerBlock == 100)
|
||||
BOOST_CHECK_EQUAL(fixture.getMerkleHash().GetHex(), "c5df693adbe6b386a5d1e494e83a8f5745f32f6917a32b4f429e7c20b47171dd");
|
||||
BOOST_CHECK_EQUAL(fixture.getMerkleHash().GetHex(), "21b25760f8e0f3e95514ff90b8ef3758b270e50fe17f747ba29f99dd1874bf41");
|
||||
else if (blocks == 13 && claimsPerBlock == 100)
|
||||
BOOST_CHECK_EQUAL(fixture.getMerkleHash().GetHex(), "4e5984d6984f5f05d50e821e6228d56bcfbd16ca2093cd0308f6ff1c2bc8689a");
|
||||
else
|
||||
@@ -1021,7 +1025,7 @@ BOOST_AUTO_TEST_CASE(claimtrie_expire_test)
|
||||
BOOST_CHECK(fixture.is_best_claim("test", tx6));
|
||||
}
|
||||
/*
|
||||
* tests for CClaimTrie::getEffectiveAmountForClaim
|
||||
* tests for CClaimPrefixTrie::getEffectiveAmountForClaim
|
||||
*/
|
||||
BOOST_AUTO_TEST_CASE(claimtriebranching_get_effective_amount_for_claim)
|
||||
{
|
||||
@@ -1066,7 +1070,7 @@ BOOST_AUTO_TEST_CASE(claimtriebranching_get_effective_amount_for_claim)
|
||||
}
|
||||
|
||||
/*
|
||||
* tests for CClaimTrie::getClaimById basic consistency checks
|
||||
* tests for CClaimPrefixTrie::getClaimById basic consistency checks
|
||||
*/
|
||||
BOOST_AUTO_TEST_CASE(get_claim_by_id_test)
|
||||
{
|
||||
@@ -1157,7 +1161,7 @@ BOOST_AUTO_TEST_CASE(hardfork_claim_test)
|
||||
// make sure decrementing to before the fork height will apppropriately set back the
|
||||
// expiration time to the original expiraiton time
|
||||
fixture.DecrementBlocks(1);
|
||||
BOOST_CHECK_NE(fixture.expirationTime(), 6);
|
||||
BOOST_CHECK_EQUAL(fixture.expirationTime(), 3);
|
||||
fixture.IncrementBlocks(1);
|
||||
BOOST_CHECK_EQUAL(fixture.expirationTime(), 6);
|
||||
|
||||
@@ -1544,10 +1548,8 @@ BOOST_AUTO_TEST_CASE(claimtriecache_normalization)
|
||||
BOOST_CHECK(trieCache.incrementBlock(insertUndo, expireUndo, insertSupportUndo, expireSupportUndo, takeoverHeightUndo));
|
||||
BOOST_CHECK(trieCache.shouldNormalize());
|
||||
|
||||
// we cannot use getXXXForName cause they will normalized name
|
||||
for (auto it = pclaimTrie->begin(); it != pclaimTrie->end(); ++it) {
|
||||
BOOST_CHECK(it.key() != name);
|
||||
}
|
||||
CClaimTrieDataNode node;
|
||||
BOOST_CHECK(!pclaimTrie->find(name, node));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(undo_normalization_does_not_kill_claim_order)
|
||||
@@ -1723,7 +1725,8 @@ BOOST_AUTO_TEST_CASE(normalization_does_not_kill_sort_order)
|
||||
BOOST_AUTO_TEST_CASE(normalization_does_not_kill_expirations)
|
||||
{
|
||||
ClaimTrieChainFixture fixture;
|
||||
fixture.setExpirationTime(3);
|
||||
auto& consensus = Params().GetConsensus();
|
||||
fixture.setExpirationForkHeight(consensus.nExtendedClaimExpirationForkHeight, 3, consensus.nExtendedClaimExpirationTime);
|
||||
fixture.setNormalizationForkHeight(4);
|
||||
// need to see that claims expiring on the frame when we normalize aren't kept
|
||||
// need to see that supports expiring on the frame when we normalize aren't kept
|
||||
@@ -2182,7 +2185,7 @@ BOOST_AUTO_TEST_CASE(insert_update_claim_test)
|
||||
<< std::vector<unsigned char>(sName1.begin(), sName1.end())
|
||||
<< std::vector<unsigned char>(tx1ClaimId.begin(), tx1ClaimId.end())
|
||||
<< std::vector<unsigned char>(sValue1.begin(), sValue1.end()) << OP_2DROP << OP_2DROP << OP_TRUE;
|
||||
tx8.vout[0].nValue = tx8.vout[0].nValue - 1;
|
||||
tx8.vout[0].nValue -= 1;
|
||||
tx8.vout[1].scriptPubKey = CScript() << OP_CLAIM_NAME
|
||||
<< std::vector<unsigned char>(sName1.begin(), sName1.end())
|
||||
<< std::vector<unsigned char>(sValue2.begin(), sValue2.end()) << OP_2DROP << OP_DROP << OP_TRUE;
|
||||
@@ -3816,7 +3819,7 @@ BOOST_AUTO_TEST_CASE(bogus_claimtrie_hash_test)
|
||||
}
|
||||
|
||||
/*
|
||||
* tests for CClaimTrie::getClaimById basic consistency checks
|
||||
* tests for CClaimPrefixTrie::getClaimById basic consistency checks
|
||||
*/
|
||||
BOOST_AUTO_TEST_CASE(get_claim_by_id_test_2)
|
||||
{
|
||||
@@ -4098,14 +4101,17 @@ BOOST_AUTO_TEST_CASE(update_on_support2_test)
|
||||
CMutableTransaction s2 = fixture.MakeSupport(fixture.GetCoinbase(), tx1, name, 1);
|
||||
fixture.IncrementBlocks(1);
|
||||
|
||||
BOOST_CHECK_EQUAL(pclaimTrie->find(name)->nHeightOfLastTakeover, height + 1);
|
||||
CClaimTrieDataNode node;
|
||||
BOOST_CHECK(pclaimTrie->find(name, node));
|
||||
BOOST_CHECK_EQUAL(node.data.nHeightOfLastTakeover, height + 1);
|
||||
|
||||
fixture.Spend(s1);
|
||||
fixture.Spend(s2);
|
||||
CMutableTransaction u1 = fixture.MakeUpdate(tx1, name, value, ClaimIdHash(tx1.GetHash(), 0), 3);
|
||||
fixture.IncrementBlocks(1);
|
||||
|
||||
BOOST_CHECK_EQUAL(pclaimTrie->find(name)->nHeightOfLastTakeover, height + 1);
|
||||
BOOST_CHECK(pclaimTrie->find(name, node));
|
||||
BOOST_CHECK_EQUAL(node.data.nHeightOfLastTakeover, height + 1);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
@@ -12,7 +12,7 @@ using namespace std;
|
||||
class CClaimTrieCacheTest : public CClaimTrieCacheBase
|
||||
{
|
||||
public:
|
||||
explicit CClaimTrieCacheTest(CClaimTrie* base): CClaimTrieCacheBase(base, false)
|
||||
explicit CClaimTrieCacheTest(CClaimTrie* base): CClaimTrieCacheBase(base)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -23,22 +23,22 @@ public:
|
||||
|
||||
void insert(const std::string& key, CClaimTrieData&& data)
|
||||
{
|
||||
cache.insert(key, std::move(data));
|
||||
nodesToAddOrUpdate.insert(key, std::move(data));
|
||||
}
|
||||
|
||||
bool erase(const std::string& key)
|
||||
{
|
||||
return cache.erase(key);
|
||||
return nodesToAddOrUpdate.erase(key);
|
||||
}
|
||||
|
||||
int cacheSize()
|
||||
{
|
||||
return cache.height();
|
||||
return nodesToAddOrUpdate.height();
|
||||
}
|
||||
|
||||
CClaimTrie::iterator getCache(const std::string& key)
|
||||
CClaimPrefixTrie::iterator getCache(const std::string& key)
|
||||
{
|
||||
return cache.find(key);
|
||||
return nodesToAddOrUpdate.find(key);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -124,7 +124,7 @@ BOOST_AUTO_TEST_CASE(merkle_hash_multiple_test)
|
||||
|
||||
BOOST_CHECK(!pclaimTrie->empty());
|
||||
BOOST_CHECK_EQUAL(ntState.getMerkleHash(), hash2);
|
||||
BOOST_CHECK(ntState.checkConsistency(0));
|
||||
BOOST_CHECK(pclaimTrie->checkConsistency(hash2));
|
||||
|
||||
CClaimTrieCacheTest ntState1(pclaimTrie);
|
||||
ntState1.removeClaimFromTrie(std::string("test"), tx1OutPoint, unused, true);
|
||||
@@ -144,7 +144,7 @@ BOOST_AUTO_TEST_CASE(merkle_hash_multiple_test)
|
||||
|
||||
BOOST_CHECK(!pclaimTrie->empty());
|
||||
BOOST_CHECK_EQUAL(ntState2.getMerkleHash(), hash3);
|
||||
BOOST_CHECK(ntState2.checkConsistency(0));
|
||||
BOOST_CHECK(pclaimTrie->checkConsistency(hash3));
|
||||
|
||||
CClaimTrieCacheTest ntState3(pclaimTrie);
|
||||
ntState3.insertClaimIntoTrie(std::string("test"), CClaimValue(tx1OutPoint, hash160, 50, 100, 200), true);
|
||||
@@ -152,7 +152,7 @@ BOOST_AUTO_TEST_CASE(merkle_hash_multiple_test)
|
||||
ntState3.flush();
|
||||
BOOST_CHECK(!pclaimTrie->empty());
|
||||
BOOST_CHECK_EQUAL(ntState3.getMerkleHash(), hash4);
|
||||
BOOST_CHECK(ntState3.checkConsistency(0));
|
||||
BOOST_CHECK(pclaimTrie->checkConsistency(hash4));
|
||||
|
||||
CClaimTrieCacheTest ntState4(pclaimTrie);
|
||||
ntState4.removeClaimFromTrie(std::string("abab"), tx6OutPoint, unused, true);
|
||||
@@ -160,7 +160,7 @@ BOOST_AUTO_TEST_CASE(merkle_hash_multiple_test)
|
||||
ntState4.flush();
|
||||
BOOST_CHECK(!pclaimTrie->empty());
|
||||
BOOST_CHECK_EQUAL(ntState4.getMerkleHash(), hash2);
|
||||
BOOST_CHECK(ntState4.checkConsistency(0));
|
||||
BOOST_CHECK(pclaimTrie->checkConsistency(hash2));
|
||||
|
||||
CClaimTrieCacheTest ntState5(pclaimTrie);
|
||||
ntState5.removeClaimFromTrie(std::string("test"), tx3OutPoint, unused, true);
|
||||
@@ -169,7 +169,7 @@ BOOST_AUTO_TEST_CASE(merkle_hash_multiple_test)
|
||||
ntState5.flush();
|
||||
BOOST_CHECK(!pclaimTrie->empty());
|
||||
BOOST_CHECK_EQUAL(ntState5.getMerkleHash(), hash2);
|
||||
BOOST_CHECK(ntState5.checkConsistency(0));
|
||||
BOOST_CHECK(pclaimTrie->checkConsistency(hash2));
|
||||
|
||||
CClaimTrieCacheTest ntState6(pclaimTrie);
|
||||
ntState6.insertClaimIntoTrie(std::string("test"), CClaimValue(tx3OutPoint, hash160, 50, 101, 201), true);
|
||||
@@ -178,7 +178,7 @@ BOOST_AUTO_TEST_CASE(merkle_hash_multiple_test)
|
||||
ntState6.flush();
|
||||
BOOST_CHECK(!pclaimTrie->empty());
|
||||
BOOST_CHECK_EQUAL(ntState6.getMerkleHash(), hash2);
|
||||
BOOST_CHECK(ntState6.checkConsistency(0));
|
||||
BOOST_CHECK(pclaimTrie->checkConsistency(hash2));
|
||||
|
||||
CClaimTrieCacheTest ntState7(pclaimTrie);
|
||||
ntState7.removeClaimFromTrie(std::string("test"), tx3OutPoint, unused, true);
|
||||
@@ -190,7 +190,7 @@ BOOST_AUTO_TEST_CASE(merkle_hash_multiple_test)
|
||||
ntState7.flush();
|
||||
BOOST_CHECK(pclaimTrie->empty());
|
||||
BOOST_CHECK_EQUAL(ntState7.getMerkleHash(), hash0);
|
||||
BOOST_CHECK(ntState7.checkConsistency(0));
|
||||
BOOST_CHECK(pclaimTrie->checkConsistency(hash0));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(basic_insertion_info_test)
|
||||
@@ -299,28 +299,12 @@ BOOST_AUTO_TEST_CASE(iteratetrie_test)
|
||||
BOOST_CHECK(ctc.flush());
|
||||
|
||||
std::size_t count = 0;
|
||||
for (auto it = pclaimTrie->begin(); it != pclaimTrie->end(); ++it) {
|
||||
++count;
|
||||
if (it.key() == "test") {
|
||||
BOOST_CHECK_EQUAL(it->claims.size(), 1);
|
||||
}
|
||||
}
|
||||
BOOST_CHECK_EQUAL(count, 2);
|
||||
|
||||
count = 0;
|
||||
for (const auto& it: *pclaimTrie) {
|
||||
++count;
|
||||
if (it.first == "test") {
|
||||
const CClaimTrieData& data = it.second;
|
||||
BOOST_CHECK_EQUAL(data.claims.size(), 1);
|
||||
}
|
||||
}
|
||||
BOOST_CHECK_EQUAL(count, 2);
|
||||
|
||||
auto it = pclaimTrie->find("test");
|
||||
BOOST_CHECK(it != pclaimTrie->end());
|
||||
BOOST_CHECK_EQUAL(it->claims.size(), 1);
|
||||
BOOST_CHECK_EQUAL(pclaimTrie->height(), 1);
|
||||
CClaimTrieDataNode node;
|
||||
BOOST_CHECK(pclaimTrie->find("", node));
|
||||
BOOST_CHECK_EQUAL(node.children.size(), 1U);
|
||||
BOOST_CHECK(pclaimTrie->find("test", node));
|
||||
BOOST_CHECK_EQUAL(node.children.size(), 0U);
|
||||
BOOST_CHECK_EQUAL(node.data.claims.size(), 1);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(trie_stays_consistent_test)
|
||||
@@ -337,15 +321,15 @@ BOOST_AUTO_TEST_CASE(trie_stays_consistent_test)
|
||||
BOOST_CHECK(cache.insertClaimIntoTrie(name, value, false));
|
||||
|
||||
cache.flush();
|
||||
BOOST_CHECK(cache.checkConsistency(0));
|
||||
BOOST_CHECK(trie.checkConsistency(cache.getMerkleHash()));
|
||||
|
||||
for (auto& name: names) {
|
||||
CClaimValue temp;
|
||||
BOOST_CHECK(cache.removeClaimFromTrie(name, COutPoint(), temp, false));
|
||||
cache.flush();
|
||||
BOOST_CHECK(cache.checkConsistency(0));
|
||||
BOOST_CHECK(trie.checkConsistency(cache.getMerkleHash()));
|
||||
}
|
||||
BOOST_CHECK_EQUAL(trie.height(), 0);
|
||||
BOOST_CHECK(trie.empty());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(takeover_workaround_triggers)
|
||||
@@ -394,9 +378,29 @@ BOOST_AUTO_TEST_CASE(takeover_workaround_triggers)
|
||||
|
||||
BOOST_CHECK(cache.incrementBlock(icu, ecu, isu, esu, thu));
|
||||
|
||||
BOOST_CHECK_EQUAL(3, cache.find("aa")->nHeightOfLastTakeover);
|
||||
BOOST_CHECK_EQUAL(3, cache.find("bb")->nHeightOfLastTakeover);
|
||||
BOOST_CHECK_EQUAL(1, cache.find("cc")->nHeightOfLastTakeover);
|
||||
BOOST_CHECK_EQUAL(3, cache.getCache("aa")->nHeightOfLastTakeover);
|
||||
BOOST_CHECK_EQUAL(3, cache.getCache("bb")->nHeightOfLastTakeover);
|
||||
BOOST_CHECK_EQUAL(1, cache.getCache("cc")->nHeightOfLastTakeover);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(verify_basic_serialization)
|
||||
{
|
||||
CClaimValue cv;
|
||||
cv.outPoint = COutPoint(uint256S("123"), 2);
|
||||
cv.nHeight = 3;
|
||||
cv.claimId.SetHex("4567");
|
||||
cv.nEffectiveAmount = 4;
|
||||
cv.nAmount = 5;
|
||||
cv.nValidAtHeight = 6;
|
||||
|
||||
CDataStream ssData(SER_NETWORK, PROTOCOL_VERSION);
|
||||
ssData << cv;
|
||||
|
||||
CClaimValue cv2;
|
||||
ssData >> cv2;
|
||||
|
||||
BOOST_CHECK_EQUAL(cv, cv2);
|
||||
BOOST_CHECK_EQUAL(cv.nEffectiveAmount, cv2.nEffectiveAmount);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
@@ -20,6 +20,8 @@
|
||||
#include <script/sigcache.h>
|
||||
|
||||
#include "claimtrie.h"
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <boost/test/unit_test_parameters.hpp>
|
||||
|
||||
void CConnmanTest::AddNode(CNode& node)
|
||||
{
|
||||
@@ -39,7 +41,6 @@ void CConnmanTest::ClearNodes()
|
||||
uint256 insecure_rand_seed = GetRandHash();
|
||||
FastRandomContext insecure_rand_ctx(insecure_rand_seed);
|
||||
|
||||
extern bool fPrintToConsole;
|
||||
extern void noui_connect();
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const uint256& num)
|
||||
@@ -90,6 +91,14 @@ std::ostream& operator<<(std::ostream& os, const CSupportValue& support)
|
||||
BasicTestingSetup::BasicTestingSetup(const std::string& chainName)
|
||||
: m_path_root(fs::temp_directory_path() / "test_bitcoin" / strprintf("%lu_%i", (unsigned long)GetTime(), (int)(InsecureRandRange(1 << 30))))
|
||||
{
|
||||
// for debugging:
|
||||
if (boost::unit_test::runtime_config::get<boost::unit_test::log_level>(boost::unit_test::runtime_config::btrt_log_level)
|
||||
<= boost::unit_test::log_level::log_messages) {
|
||||
g_logger->m_print_to_console = true;
|
||||
g_logger->m_log_time_micros = true;
|
||||
g_logger->EnableCategory(BCLog::ALL);
|
||||
}
|
||||
|
||||
SHA256AutoDetect();
|
||||
RandomInit();
|
||||
ECC_Start();
|
||||
|
||||
@@ -44,7 +44,7 @@ struct BasicTestingSetup {
|
||||
ECCVerifyHandle globalVerifyHandle;
|
||||
|
||||
explicit BasicTestingSetup(const std::string& chainName = CBaseChainParams::MAIN);
|
||||
~BasicTestingSetup();
|
||||
virtual ~BasicTestingSetup();
|
||||
|
||||
fs::path SetDataDir(const std::string& name);
|
||||
|
||||
@@ -70,7 +70,7 @@ struct TestingSetup: public BasicTestingSetup {
|
||||
std::unique_ptr<PeerLogicValidation> peerLogic;
|
||||
|
||||
explicit TestingSetup(const std::string& chainName = CBaseChainParams::MAIN);
|
||||
~TestingSetup();
|
||||
~TestingSetup() override;
|
||||
};
|
||||
|
||||
class CBlock;
|
||||
@@ -89,7 +89,7 @@ struct TestChain100Setup : public TestingSetup {
|
||||
CBlock CreateAndProcessBlock(const std::vector<CMutableTransaction>& txns,
|
||||
const CScript& scriptPubKey);
|
||||
|
||||
~TestChain100Setup();
|
||||
~TestChain100Setup() override;
|
||||
|
||||
std::vector<CTransactionRef> m_coinbase_txns; // For convenience, coinbase transactions
|
||||
CKey coinbaseKey; // private/public key needed to spend coinbase transactions
|
||||
@@ -97,7 +97,7 @@ struct TestChain100Setup : public TestingSetup {
|
||||
|
||||
struct RegTestingSetup: public TestingSetup {
|
||||
RegTestingSetup();
|
||||
~RegTestingSetup();
|
||||
~RegTestingSetup() override;
|
||||
};
|
||||
|
||||
class CTxMemPoolEntry;
|
||||
|
||||
+42
-67
@@ -1546,7 +1546,6 @@ DisconnectResult CChainState::DisconnectBlock(const CBlock& block, const CBlockI
|
||||
}
|
||||
for (unsigned int j = tx.vin.size(); j-- > 0;) {
|
||||
const COutPoint &out = tx.vin[j].prevout;
|
||||
/* int res = ApplyTxInUndo(std::move(txundo.vprevout[j]), txundo, view, trieCache, out); */
|
||||
int res = ApplyTxInUndo(j, txundo, view, trieCache, out);
|
||||
if (res == DISCONNECT_FAILED) return DISCONNECT_FAILED;
|
||||
fClean = fClean && res != DISCONNECT_UNCLEAN;
|
||||
@@ -1563,24 +1562,17 @@ DisconnectResult CChainState::DisconnectBlock(const CBlock& block, const CBlockI
|
||||
assert(trieCache.finalizeDecrement(blockUndo.takeoverHeightUndo));
|
||||
auto merkleHash = trieCache.getMerkleHash();
|
||||
if (merkleHash != pindex->pprev->hashClaimTrie) {
|
||||
if (trieCache.checkConsistency()) {
|
||||
for (auto cit = trieCache.begin(); cit != trieCache.end(); ++cit) {
|
||||
if (cit->claims.size() && cit->nHeightOfLastTakeover <= 0)
|
||||
LogPrintf("Invalid takeover height discovered in cache for %s\n", cit.key());
|
||||
if (cit->hash.IsNull())
|
||||
LogPrintf("Invalid hash discovered in cache for %s\n", cit.key());
|
||||
}
|
||||
for (auto cit = trieCache.begin(); cit != trieCache.end(); ++cit) {
|
||||
if (cit->claims.size() && cit->nHeightOfLastTakeover <= 0)
|
||||
LogPrintf("Invalid takeover height discovered in cache for %s\n", cit.key());
|
||||
if (cit->hash.IsNull())
|
||||
LogPrintf("Invalid hash discovered in cache for %s\n", cit.key());
|
||||
}
|
||||
LogPrintf("Hash comparison failure at block %d\n", pindex->nHeight);
|
||||
assert(merkleHash == pindex->pprev->hashClaimTrie);
|
||||
}
|
||||
|
||||
if (pindex->nHeight == Params().GetConsensus().nExtendedClaimExpirationForkHeight)
|
||||
{
|
||||
LogPrintf("Decremented past the extended claim expiration hard fork height\n");
|
||||
trieCache.setExpirationTime(Params().GetConsensus().GetExpirationTime(pindex->nHeight-1));
|
||||
trieCache.forkForExpirationChange(false);
|
||||
}
|
||||
trieCache.expirationForkActive(pindex->nHeight, false);
|
||||
|
||||
return fClean ? DISCONNECT_OK : DISCONNECT_UNCLEAN;
|
||||
}
|
||||
@@ -1908,7 +1900,7 @@ bool CChainState::ConnectBlock(const CBlock& block, CValidationState& state, CBl
|
||||
// post BIP34 before approximately height 486,000,000 and presumably will
|
||||
// be reset before it reaches block 1,983,702 and starts doing unnecessary
|
||||
// BIP30 checking again.
|
||||
/* assert(pindex->pprev); */
|
||||
|
||||
if (pindex->pprev)
|
||||
{
|
||||
CBlockIndex *pindexBIP34height = pindex->pprev->GetAncestor(chainparams.GetConsensus().BIP34Height);
|
||||
@@ -1939,13 +1931,7 @@ bool CChainState::ConnectBlock(const CBlock& block, CValidationState& state, CBl
|
||||
// Get the script flags for this block
|
||||
unsigned int flags = GetBlockScriptFlags(pindex, chainparams.GetConsensus());
|
||||
|
||||
// v 13 LBRYcrd hard fork to extend expiration time
|
||||
if (pindex->nHeight == Params().GetConsensus().nExtendedClaimExpirationForkHeight)
|
||||
{
|
||||
LogPrintf("Incremented past the extended claim expiration hard fork height\n");
|
||||
trieCache.setExpirationTime(chainparams.GetConsensus().GetExpirationTime(pindex->nHeight));
|
||||
trieCache.forkForExpirationChange(true);
|
||||
}
|
||||
trieCache.expirationForkActive(pindex->nHeight, true);
|
||||
|
||||
int64_t nTime2 = GetTimeMicros(); nTimeForks += nTime2 - nTime1;
|
||||
LogPrint(BCLog::BENCH, " - Fork checks: %.2fms [%.2fs (%.2fms/blk)]\n", MILLI * (nTime2 - nTime1), nTimeForks * MICRO, nTimeForks * MILLI / nBlocksTotal);
|
||||
@@ -2015,35 +2001,13 @@ bool CChainState::ConnectBlock(const CBlock& block, CValidationState& state, CBl
|
||||
return error("ConnectBlock(): CheckInputs on %s failed with %s",
|
||||
tx.GetHash().ToString(), FormatStateMessage(state));
|
||||
control.Add(vChecks);
|
||||
|
||||
// To handle claim updates, stick all claims found in the inputs into a map of
|
||||
// name: (txhash, nOut). When running through the outputs, if any claim's
|
||||
// name is found in the map, send the name's txhash and nOut to the trie cache,
|
||||
// and then remove the name: (txhash, nOut) mapping from the map.
|
||||
// If there are two or more claims in the inputs with the same name, only
|
||||
// use the first.
|
||||
|
||||
spentClaimsType spentClaims;
|
||||
|
||||
for (unsigned int j = 0; j < tx.vin.size(); j++)
|
||||
{
|
||||
const CTxIn& txin = tx.vin[j];
|
||||
const Coin& coin = view.AccessCoin(txin.prevout);
|
||||
|
||||
if (coin.out.scriptPubKey.empty())
|
||||
continue;
|
||||
|
||||
int nValidAtHeight;
|
||||
if (SpendClaim(trieCache, coin.out.scriptPubKey, COutPoint(txin.prevout.hash, txin.prevout.n), coin.nHeight, nValidAtHeight, spentClaims))
|
||||
mClaimUndoHeights[j] = nValidAtHeight;
|
||||
}
|
||||
|
||||
for (unsigned int j = 0; j < tx.vout.size(); j++) {
|
||||
const CTxOut& txout = tx.vout[j];
|
||||
|
||||
if (!txout.scriptPubKey.empty())
|
||||
AddSpendClaim(trieCache, txout.scriptPubKey, COutPoint(tx.GetHash(), j), txout.nValue, pindex->nHeight, spentClaims);
|
||||
}
|
||||
CUpdateCacheCallbacks callbacks = {
|
||||
.findScriptKey = {},
|
||||
.claimUndoHeights = [&mClaimUndoHeights](int index, int nValidAtHeight) {
|
||||
mClaimUndoHeights.emplace(index, nValidAtHeight);
|
||||
}
|
||||
};
|
||||
UpdateCache(tx, trieCache, view, pindex->nHeight, callbacks);
|
||||
}
|
||||
|
||||
CTxUndo undoDummy;
|
||||
@@ -2082,7 +2046,7 @@ bool CChainState::ConnectBlock(const CBlock& block, CValidationState& state, CBl
|
||||
|
||||
if (trieCache.getMerkleHash() != block.hashClaimTrie)
|
||||
{
|
||||
if (trieCache.checkConsistency())
|
||||
if (!trieCache.empty()) // we could run checkConsistency here, but it would take a while
|
||||
trieCache.dumpToLog(trieCache.begin());
|
||||
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(),
|
||||
@@ -2238,6 +2202,7 @@ bool static FlushStateToDisk(const CChainParams& chainparams, CValidationState &
|
||||
if (full_flush_completed) {
|
||||
// Update best block in wallet (so we can detect restored wallets).
|
||||
GetMainSignals().ChainStateFlushed(chainActive.GetLocator());
|
||||
LogPrint(BCLog::BENCH, "Finished full disk flush in %.2fms\n", (GetTimeMicros() - nLastFlush) * MILLI);
|
||||
}
|
||||
} catch (const std::runtime_error& e) {
|
||||
return AbortNode(state, std::string("System error while flushing: ") + e.what());
|
||||
@@ -2324,14 +2289,22 @@ void static UpdateTip(const CBlockIndex *pindexNew, const CChainParams& chainPar
|
||||
DoWarning(strWarning);
|
||||
}
|
||||
}
|
||||
LogPrintf("%s: new best=%s height=%d version=0x%08x log2_work=%.8g tx=%lu date='%s' progress=%f cache=%.1fMiB(%utxo)", __func__, /* Continued */
|
||||
pindexNew->GetBlockHash().ToString(), pindexNew->nHeight, pindexNew->nVersion,
|
||||
log(pindexNew->nChainWork.getdouble())/log(2.0), (unsigned long)pindexNew->nChainTx,
|
||||
FormatISO8601DateTime(pindexNew->GetBlockTime()),
|
||||
GuessVerificationProgress(chainParams.TxData(), pindexNew), pcoinsTip->DynamicMemoryUsage() * (1.0 / (1<<20)), pcoinsTip->GetCacheSize());
|
||||
if (!warningMessages.empty())
|
||||
LogPrintf(" warning='%s'", warningMessages); /* Continued */
|
||||
LogPrintf("\n");
|
||||
static int64_t lastBlockPrintTime = 0;
|
||||
auto currentTime = GetAdjustedTime();
|
||||
auto oldBlock = pindexNew->nTime + MAX_FUTURE_BLOCK_TIME < currentTime;
|
||||
if (!warningMessages.empty() || !oldBlock || lastBlockPrintTime < currentTime - 15 || LogAcceptCategory(BCLog::CLAIMS)) {
|
||||
lastBlockPrintTime = currentTime;
|
||||
LogPrintf("%s: new best=%s height=%d version=0x%08x log2_work=%.8g txb=%lu tx=%lu date='%s' progress=%f cache=%.1fMiB(%utxo)%s",
|
||||
__func__, pindexNew->GetBlockHash().ToString(), pindexNew->nHeight, pindexNew->nVersion,
|
||||
log(pindexNew->nChainWork.getdouble()) / log(2.0), (unsigned long) pindexNew->nTx,
|
||||
(unsigned long) pindexNew->nChainTx, FormatISO8601DateTime(pindexNew->GetBlockTime()),
|
||||
GuessVerificationProgress(chainParams.TxData(), pindexNew),
|
||||
pcoinsTip->DynamicMemoryUsage() * (1.0 / (1U << 20U)), pcoinsTip->GetCacheSize(),
|
||||
oldBlock ? " (synchronizing)" : "");
|
||||
if (!warningMessages.empty())
|
||||
LogPrintf(" warning='%s'", warningMessages); /* Continued */
|
||||
LogPrintf("\n");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2808,12 +2781,14 @@ bool CChainState::ActivateBestChain(CValidationState &state, const CChainParams&
|
||||
} while (pindexNewTip != pindexMostWork);
|
||||
CheckBlockIndex(chainparams.GetConsensus());
|
||||
|
||||
// Write changes periodically to disk, after relay.
|
||||
if (!FlushStateToDisk(chainparams, state, FlushStateMode::PERIODIC)) {
|
||||
return false;
|
||||
auto flushMode = FlushStateMode::PERIODIC;
|
||||
if (pindexNewTip && pindexNewTip->nTime + chainparams.GetConsensus().nPowTargetSpacing > GetAdjustedTime()) {
|
||||
// trying to ensure that we flush to disk after new blocks when we're caught up to the chain
|
||||
// they're technically allowed to be two hours late, but experience says one minute is more likely
|
||||
// LogPrintf("Added tip with time %d but it is now %ll\n", pindexNewTip->nTime, GetAdjustedTime());
|
||||
flushMode = FlushStateMode::ALWAYS;
|
||||
}
|
||||
|
||||
return true;
|
||||
return FlushStateToDisk(chainparams, state, flushMode);
|
||||
}
|
||||
|
||||
bool ActivateBestChain(CValidationState &state, const CChainParams& chainparams, std::shared_ptr<const CBlock> pblock) {
|
||||
@@ -3083,7 +3058,7 @@ static bool FindBlockPos(CDiskBlockPos &pos, unsigned int nAddSize, unsigned int
|
||||
if (CheckDiskSpace(nNewChunks * BLOCKFILE_CHUNK_SIZE - pos.nPos, true)) {
|
||||
FILE *file = OpenBlockFile(pos);
|
||||
if (file) {
|
||||
LogPrintf("Pre-allocating up to position 0x%x in blk%05u.dat\n", nNewChunks * BLOCKFILE_CHUNK_SIZE, pos.nFile);
|
||||
LogPrint(BCLog::BENCH, "Pre-allocating up to position 0x%x in blk%05u.dat\n", nNewChunks * BLOCKFILE_CHUNK_SIZE, pos.nFile);
|
||||
AllocateFileRange(file, pos.nPos, nNewChunks * BLOCKFILE_CHUNK_SIZE - pos.nPos);
|
||||
fclose(file);
|
||||
}
|
||||
@@ -3116,7 +3091,7 @@ static bool FindUndoPos(CValidationState &state, int nFile, CDiskBlockPos &pos,
|
||||
if (CheckDiskSpace(nNewChunks * UNDOFILE_CHUNK_SIZE - pos.nPos, true)) {
|
||||
FILE *file = OpenUndoFile(pos);
|
||||
if (file) {
|
||||
LogPrintf("Pre-allocating up to position 0x%x in rev%05u.dat\n", nNewChunks * UNDOFILE_CHUNK_SIZE, pos.nFile);
|
||||
LogPrint(BCLog::BENCH, "Pre-allocating up to position 0x%x in rev%05u.dat\n", nNewChunks * UNDOFILE_CHUNK_SIZE, pos.nFile);
|
||||
AllocateFileRange(file, pos.nPos, nNewChunks * UNDOFILE_CHUNK_SIZE - pos.nPos);
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
+1
-1
@@ -200,7 +200,7 @@ static const unsigned int MIN_BLOCKS_TO_KEEP = 288;
|
||||
/** Minimum blocks required to signal NODE_NETWORK_LIMITED */
|
||||
static const unsigned int NODE_NETWORK_LIMITED_MIN_BLOCKS = 288;
|
||||
|
||||
static const signed int DEFAULT_CHECKBLOCKS = 288 * 3; // 36 hours
|
||||
static const signed int DEFAULT_CHECKBLOCKS = 144; // 6 hours
|
||||
static const unsigned int DEFAULT_CHECKLEVEL = 3;
|
||||
|
||||
// Require that user allocate at least 550MB for block & undo files (blk???.dat and rev???.dat)
|
||||
|
||||
+5
-1
@@ -154,6 +154,7 @@ BerkeleyEnvironment::BerkeleyEnvironment(const fs::path& dir_path) : strPath(dir
|
||||
|
||||
BerkeleyEnvironment::~BerkeleyEnvironment()
|
||||
{
|
||||
LOCK(cs_db);
|
||||
g_dbenvs.erase(strPath);
|
||||
Close();
|
||||
}
|
||||
@@ -558,6 +559,7 @@ BerkeleyBatch::BerkeleyBatch(BerkeleyDatabase& database, const char* pszMode, bo
|
||||
|
||||
void BerkeleyBatch::Flush()
|
||||
{
|
||||
LOCK(cs_db);
|
||||
if (activeTxn)
|
||||
return;
|
||||
|
||||
@@ -566,7 +568,9 @@ void BerkeleyBatch::Flush()
|
||||
if (fReadOnly)
|
||||
nMinutes = 1;
|
||||
|
||||
env->dbenv->txn_checkpoint(nMinutes ? gArgs.GetArg("-dblogsize", DEFAULT_WALLET_DBLOGSIZE) * 1024 : 0, nMinutes, 0);
|
||||
if (env && env->dbenv) { // env is nullptr for dummy databases (i.e. in tests). Don't actually flush if env is nullptr so we don't segfault
|
||||
env->dbenv->txn_checkpoint(nMinutes ? gArgs.GetArg("-dblogsize", DEFAULT_WALLET_DBLOGSIZE) * 1024 : 0, nMinutes, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void BerkeleyDatabase::IncrementUpdateCounter()
|
||||
|
||||
@@ -28,11 +28,11 @@ struct CatchWalletTestSetup: public TestingSetup {
|
||||
UniValue results = rpc_method(req);
|
||||
BOOST_CHECK_EQUAL(results["name"].get_str(), "tester_wallet");
|
||||
}
|
||||
~CatchWalletTestSetup() {
|
||||
~CatchWalletTestSetup() override {
|
||||
rpcfn_type rpc_method = tableRPC["unloadwallet"]->actor;
|
||||
JSONRPCRequest req;
|
||||
req.URI = "/wallet/tester_wallet";
|
||||
req.params = UniValue(UniValue::VARR);
|
||||
req.params.push_back("tester_wallet");
|
||||
rpc_method(req);
|
||||
}
|
||||
};
|
||||
@@ -42,6 +42,7 @@ BOOST_FIXTURE_TEST_SUITE(claim_rpc_tests, CatchWalletTestSetup)
|
||||
double AvailableBalance() {
|
||||
rpcfn_type rpc_method = tableRPC["getbalance"]->actor;
|
||||
JSONRPCRequest req;
|
||||
req.URI = "/wallet/tester_wallet";
|
||||
req.params = UniValue(UniValue::VARR);
|
||||
UniValue results = rpc_method(req);
|
||||
return results.get_real();
|
||||
@@ -51,6 +52,7 @@ uint256 ClaimAName(const std::string& name, const std::string& data, const std::
|
||||
// pass a txid as name for update
|
||||
rpcfn_type rpc_method = tableRPC[isUpdate ? "updateclaim" : "claimname"]->actor;
|
||||
JSONRPCRequest req;
|
||||
req.URI = "/wallet/tester_wallet";
|
||||
req.params = UniValue(UniValue::VARR);
|
||||
req.params.push_back(name);
|
||||
req.params.push_back(data);
|
||||
@@ -67,6 +69,7 @@ uint256 SupportAName(const std::string& name, const std::string& claimId, const
|
||||
// pass a txid as name for update
|
||||
rpcfn_type rpc_method = tableRPC["supportclaim"]->actor;
|
||||
JSONRPCRequest req;
|
||||
req.URI = "/wallet/tester_wallet";
|
||||
req.params = UniValue(UniValue::VARR);
|
||||
req.params.push_back(name);
|
||||
req.params.push_back(claimId);
|
||||
@@ -82,6 +85,7 @@ uint256 SupportAName(const std::string& name, const std::string& claimId, const
|
||||
UniValue LookupAllNames() {
|
||||
rpcfn_type rpc_method = tableRPC["listnameclaims"]->actor;
|
||||
JSONRPCRequest req;
|
||||
req.URI = "/wallet/tester_wallet";
|
||||
req.params = UniValue(UniValue::VARR);
|
||||
return rpc_method(req);
|
||||
}
|
||||
@@ -89,6 +93,7 @@ UniValue LookupAllNames() {
|
||||
std::vector<uint256> generateBlock(int blocks = 1) {
|
||||
rpcfn_type rpc_method = tableRPC["generate"]->actor;
|
||||
JSONRPCRequest req;
|
||||
req.URI = "/wallet/tester_wallet";
|
||||
req.params = UniValue(UniValue::VARR);
|
||||
req.params.push_back(blocks);
|
||||
UniValue results = rpc_method(req);
|
||||
@@ -107,6 +112,7 @@ void rollbackBlock(const std::vector<uint256>& ids) {
|
||||
rpcfn_type rpc_method = tableRPC["invalidateblock"]->actor;
|
||||
for (auto it = ids.rbegin(); it != ids.rend(); ++it) {
|
||||
JSONRPCRequest req;
|
||||
req.URI = "/wallet/tester_wallet";
|
||||
req.params = UniValue(UniValue::VARR);
|
||||
req.params.push_back(it->GetHex());
|
||||
rpc_method(req);
|
||||
@@ -119,6 +125,7 @@ void rollbackBlock(const std::vector<uint256>& ids) {
|
||||
uint256 AbandonAClaim(const uint256& txid, bool isSupport = false) {
|
||||
rpcfn_type pre_rpc_method = tableRPC["getrawchangeaddress"]->actor;
|
||||
JSONRPCRequest pre_req;
|
||||
pre_req.URI = "/wallet/tester_wallet";
|
||||
pre_req.params = UniValue(UniValue::VARR);
|
||||
pre_req.params.push_back("legacy");
|
||||
UniValue adr_hash = pre_rpc_method(pre_req);
|
||||
@@ -126,6 +133,7 @@ uint256 AbandonAClaim(const uint256& txid, bool isSupport = false) {
|
||||
// pass a txid as name for update
|
||||
rpcfn_type rpc_method = tableRPC[isSupport ? "abandonsupport" : "abandonclaim"]->actor;
|
||||
JSONRPCRequest req;
|
||||
req.URI = "/wallet/tester_wallet";
|
||||
req.params = UniValue(UniValue::VARR);
|
||||
req.params.push_back(txid.GetHex());
|
||||
req.params.push_back(adr_hash.get_str());
|
||||
|
||||
Reference in new issue
Block a user