Running daemon without claimtrie functionality
Signed-off-by: Anthony Fieroni <bvbfan@abv.bg>
This commit is contained in:
parent
85ea861144
commit
e18650cbf0
4 changed files with 45 additions and 13 deletions
|
@ -78,6 +78,8 @@ static const bool DEFAULT_STOPAFTERBLOCKIMPORT = false;
|
|||
std::unique_ptr<CConnman> g_connman;
|
||||
std::unique_ptr<PeerLogicValidation> peerLogic;
|
||||
|
||||
extern bool appIsFinance();
|
||||
|
||||
#if !(ENABLE_WALLET)
|
||||
class DummyWalletInit : public WalletInitInterface {
|
||||
public:
|
||||
|
@ -392,6 +394,7 @@ void SetupServerArgs()
|
|||
#else
|
||||
hidden_args.emplace_back("-sysperms");
|
||||
#endif
|
||||
gArgs.AddArg("-finance", "Run daemon without claimtrie db", false, OptionsCategory::OPTIONS);
|
||||
gArgs.AddArg("-txindex", "Deprecated", false, OptionsCategory::HIDDEN);
|
||||
gArgs.AddArg("-addnode=<ip>", "Add a node to connect to and attempt to keep the connection open (see the `addnode` RPC command help for more info). This option can be specified multiple times to add multiple nodes.", false, OptionsCategory::CONNECTION);
|
||||
gArgs.AddArg("-banscore=<n>", strprintf("Threshold for disconnecting misbehaving peers (default: %u)", DEFAULT_BANSCORE_THRESHOLD), false, OptionsCategory::CONNECTION);
|
||||
|
@ -1551,7 +1554,7 @@ bool AppInitMain()
|
|||
|
||||
auto tip = chainActive.Tip();
|
||||
LogPrintf("Checking existing claim trie consistency...\n");
|
||||
if (tip && !CClaimTrieCache(pclaimTrie).validateDb(tip->nHeight, tip->hashClaimTrie)) {
|
||||
if (tip && !appIsFinance() && !CClaimTrieCache(pclaimTrie).validateDb(tip->nHeight, tip->hashClaimTrie)) {
|
||||
strLoadError = _("Error validating the stored claim trie");
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -881,8 +881,11 @@ static const CRPCCommand commands[] =
|
|||
{ "Claimtrie", "checknormalization", &checknormalization, { T_NAME } },
|
||||
};
|
||||
|
||||
extern bool appIsFinance();
|
||||
|
||||
void RegisterClaimTrieRPCCommands(CRPCTable &tableRPC)
|
||||
{
|
||||
for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++)
|
||||
tableRPC.appendCommand(commands[vcidx].name, &commands[vcidx]);
|
||||
if (!appIsFinance())
|
||||
for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++)
|
||||
tableRPC.appendCommand(commands[vcidx].name, &commands[vcidx]);
|
||||
}
|
||||
|
|
|
@ -990,8 +990,12 @@ static const CRPCCommand commands[] =
|
|||
{ "hidden", "estimaterawfee", &estimaterawfee, {"conf_target", "threshold"} },
|
||||
};
|
||||
|
||||
extern bool appIsFinance();
|
||||
|
||||
void RegisterMiningRPCCommands(CRPCTable &t)
|
||||
{
|
||||
for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++)
|
||||
t.appendCommand(commands[vcidx].name, &commands[vcidx]);
|
||||
if (!appIsFinance() || (commands[vcidx].name != "getblocktemplate"
|
||||
&& commands[vcidx].name != "generatetoaddress"))
|
||||
t.appendCommand(commands[vcidx].name, &commands[vcidx]);
|
||||
}
|
||||
|
|
|
@ -46,6 +46,7 @@
|
|||
#include <warnings.h>
|
||||
|
||||
#include <cmath>
|
||||
#include <functional>
|
||||
#include <future>
|
||||
#include <sstream>
|
||||
|
||||
|
@ -97,6 +98,22 @@ CScript COINBASE_FLAGS;
|
|||
|
||||
const std::string strMessageMagic = "LBRYcrd Signed Message:\n";
|
||||
|
||||
bool appIsFinance()
|
||||
{
|
||||
static const auto finance = []() -> bool {
|
||||
auto finance = gArgs.GetBoolArg("-finance", false);
|
||||
if (finance)
|
||||
LogPrintf("NOTE: daemon is running without claimtrie functionality\n");
|
||||
return finance;
|
||||
}();
|
||||
return finance;
|
||||
}
|
||||
|
||||
const std::function<bool(const uint256&, const uint256&)> hashComp =
|
||||
[](const uint256& lhs, const uint256& rhs) {
|
||||
return appIsFinance() || lhs == rhs;
|
||||
};
|
||||
|
||||
// Internal stuff
|
||||
namespace {
|
||||
CBlockIndex *&pindexBestInvalid = g_chainstate.pindexBestInvalid;
|
||||
|
@ -1510,7 +1527,7 @@ int ApplyTxInUndo(unsigned int index, CTxUndo& txUndo, CCoinsViewCache& view, CC
|
|||
DisconnectResult CChainState::DisconnectBlock(const CBlock& block, const CBlockIndex* pindex, CCoinsViewCache& view, CClaimTrieCache& trieCache)
|
||||
{
|
||||
assert(pindex->GetBlockHash() == view.GetBestBlock());
|
||||
if (pindex->hashClaimTrie != trieCache.getMerkleHash()) {
|
||||
if (!hashComp(pindex->hashClaimTrie, trieCache.getMerkleHash())) {
|
||||
LogPrintf("%s: Indexed claim hash doesn't match current: %s vs %s\n",
|
||||
__func__, pindex->hashClaimTrie.ToString(), trieCache.getMerkleHash().ToString());
|
||||
assert(false);
|
||||
|
@ -1584,7 +1601,7 @@ DisconnectResult CChainState::DisconnectBlock(const CBlock& block, const CBlockI
|
|||
// move best block pointer to prevout block
|
||||
view.SetBestBlock(pindex->pprev->GetBlockHash());
|
||||
assert(trieCache.finalizeDecrement());
|
||||
if (trieCache.getMerkleHash() != pindex->pprev->hashClaimTrie) {
|
||||
if (!hashComp(trieCache.getMerkleHash(), pindex->pprev->hashClaimTrie)) {
|
||||
LogPrintf("Hash comparison failure at block %d\n", pindex->nHeight);
|
||||
assert(false);
|
||||
}
|
||||
|
@ -1797,7 +1814,7 @@ bool CChainState::ConnectBlock(const CBlock& block, CValidationState& state, CBl
|
|||
assert(hashPrevBlock == view.GetBestBlock());
|
||||
|
||||
// also verify that the trie cache's current state corresponds to the previous block
|
||||
if (pindex->pprev != nullptr && pindex->pprev->hashClaimTrie != trieCache.getMerkleHash()) {
|
||||
if (pindex->pprev != nullptr && !hashComp(pindex->pprev->hashClaimTrie, trieCache.getMerkleHash())) {
|
||||
LogPrintf("%s: Previous block claim hash doesn't match current: %s vs %s\n",
|
||||
__func__, pindex->pprev->hashClaimTrie.ToString(), trieCache.getMerkleHash().ToString());
|
||||
assert(false);
|
||||
|
@ -2059,7 +2076,7 @@ bool CChainState::ConnectBlock(const CBlock& block, CValidationState& state, CBl
|
|||
// TODO: if the "just check" flag is set, we should reduce the work done here. Incrementing blocks twice per mine is not efficient.
|
||||
assert(trieCache.incrementBlock());
|
||||
|
||||
if (trieCache.getMerkleHash() != block.hashClaimTrie) {
|
||||
if (!hashComp(trieCache.getMerkleHash(), block.hashClaimTrie)) {
|
||||
return state.DoS(100, error("ConnectBlock() : the merkle root of the claim trie does not match "
|
||||
"(actual=%s vs block=%s on height=%d)", trieCache.getMerkleHash().GetHex(),
|
||||
block.hashClaimTrie.GetHex(), pindex->nHeight), REJECT_INVALID, "bad-claim-merkle-hash");
|
||||
|
@ -2350,8 +2367,10 @@ bool CChainState::DisconnectTip(CValidationState& state, const CChainParams& cha
|
|||
return error("DisconnectTip(): DisconnectBlock %s failed", pindexDelete->GetBlockHash().ToString());
|
||||
bool flushed = view.Flush();
|
||||
assert(flushed);
|
||||
assert(trieCache.flush());
|
||||
assert(pindexDelete->pprev->hashClaimTrie == trieCache.getMerkleHash());
|
||||
if (!appIsFinance()) {
|
||||
assert(trieCache.flush());
|
||||
assert(pindexDelete->pprev->hashClaimTrie == trieCache.getMerkleHash());
|
||||
}
|
||||
}
|
||||
LogPrint(BCLog::BENCH, "- Disconnect block: %.2fms\n", (GetTimeMicros() - nStart) * MILLI);
|
||||
// Write the chain state to disk, if necessary.
|
||||
|
@ -2490,8 +2509,10 @@ bool CChainState::ConnectTip(CValidationState& state, const CChainParams& chainp
|
|||
LogPrint(BCLog::BENCH, " - Connect total: %.2fms [%.2fs (%.2fms/blk)]\n", (nTime3 - nTime2) * MILLI, nTimeConnectTotal * MICRO, nTimeConnectTotal * MILLI / nBlocksTotal);
|
||||
bool flushed = view.Flush();
|
||||
assert(flushed);
|
||||
flushed = trieCache.flush();
|
||||
assert(flushed);
|
||||
if (!appIsFinance()) {
|
||||
flushed = trieCache.flush();
|
||||
assert(flushed);
|
||||
}
|
||||
|
||||
// for verifying that rollback code works:
|
||||
// auto result = DisconnectBlock(blockConnecting, pindexNew, view, trieCache);
|
||||
|
@ -4198,7 +4219,8 @@ bool CChainState::ReplayBlocks(const CChainParams& params, CCoinsView* view)
|
|||
|
||||
cache.SetBestBlock(pindexNew->GetBlockHash());
|
||||
cache.Flush();
|
||||
trieCache.flush();
|
||||
if (!appIsFinance())
|
||||
trieCache.flush();
|
||||
uiInterface.ShowProgress("", 100, false);
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue