mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 20:12:57 +01:00
[validation] Replace tx index code in validation code with TxIndex.
This commit is contained in:
parent
8181db88f6
commit
e0a3b80033
@ -1483,12 +1483,6 @@ bool AppInitMain()
|
||||
return InitError(_("Incorrect or no genesis block found. Wrong datadir for network?"));
|
||||
}
|
||||
|
||||
// Check for changed -txindex state
|
||||
if (fTxIndex != gArgs.GetBoolArg("-txindex", DEFAULT_TXINDEX)) {
|
||||
strLoadError = _("You need to rebuild the database using -reindex to change -txindex");
|
||||
break;
|
||||
}
|
||||
|
||||
// Check for changed -prune state. What we are concerned about is a user who has pruned blocks
|
||||
// in the past, but is now trying to run unpruned.
|
||||
if (fHavePruned && !fPruneMode) {
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <coins.h>
|
||||
#include <consensus/validation.h>
|
||||
#include <core_io.h>
|
||||
#include <index/txindex.h>
|
||||
#include <init.h>
|
||||
#include <keystore.h>
|
||||
#include <validation.h>
|
||||
@ -176,10 +177,10 @@ UniValue getrawtransaction(const JSONRPCRequest& request)
|
||||
throw JSONRPCError(RPC_MISC_ERROR, "Block not available");
|
||||
}
|
||||
errmsg = "No such transaction found in the provided block";
|
||||
} else if (!g_txindex) {
|
||||
errmsg = "No such mempool transaction. Use -txindex to enable blockchain transaction queries";
|
||||
} else {
|
||||
errmsg = fTxIndex
|
||||
? "No such mempool or blockchain transaction"
|
||||
: "No such mempool transaction. Use -txindex to enable blockchain transaction queries";
|
||||
errmsg = "No such mempool or blockchain transaction";
|
||||
}
|
||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, errmsg + ". Use gettransaction for wallet transactions.");
|
||||
}
|
||||
|
@ -16,6 +16,7 @@
|
||||
#include <consensus/validation.h>
|
||||
#include <cuckoocache.h>
|
||||
#include <hash.h>
|
||||
#include <index/txindex.h>
|
||||
#include <init.h>
|
||||
#include <policy/fees.h>
|
||||
#include <policy/policy.h>
|
||||
@ -217,7 +218,6 @@ uint256 g_best_block;
|
||||
int nScriptCheckThreads = 0;
|
||||
std::atomic_bool fImporting(false);
|
||||
std::atomic_bool fReindex(false);
|
||||
bool fTxIndex = false;
|
||||
bool fHavePruned = false;
|
||||
bool fPruneMode = false;
|
||||
bool fIsBareMultisigStd = DEFAULT_PERMIT_BAREMULTISIG;
|
||||
@ -1028,9 +1028,9 @@ bool GetTransaction(const uint256& hash, CTransactionRef& txOut, const Consensus
|
||||
return true;
|
||||
}
|
||||
|
||||
if (fTxIndex) {
|
||||
if (g_txindex) {
|
||||
CDiskTxPos postx;
|
||||
if (pblocktree->ReadTxIndex(hash, postx)) {
|
||||
if (g_txindex->FindTx(hash, postx)) {
|
||||
CAutoFile file(OpenBlockFile(postx, true), SER_DISK, CLIENT_VERSION);
|
||||
if (file.IsNull())
|
||||
return error("%s: OpenBlockFile failed", __func__);
|
||||
@ -1668,26 +1668,6 @@ static bool WriteUndoDataForBlock(const CBlockUndo& blockundo, CValidationState&
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool WriteTxIndexDataForBlock(const CBlock& block, CValidationState& state, CBlockIndex* pindex)
|
||||
{
|
||||
if (!fTxIndex) return true;
|
||||
|
||||
CDiskTxPos pos(pindex->GetBlockPos(), GetSizeOfCompactSize(block.vtx.size()));
|
||||
std::vector<std::pair<uint256, CDiskTxPos> > vPos;
|
||||
vPos.reserve(block.vtx.size());
|
||||
for (const CTransactionRef& tx : block.vtx)
|
||||
{
|
||||
vPos.push_back(std::make_pair(tx->GetHash(), pos));
|
||||
pos.nTxOffset += ::GetSerializeSize(*tx, SER_DISK, CLIENT_VERSION);
|
||||
}
|
||||
|
||||
if (!pblocktree->WriteTxIndex(vPos)) {
|
||||
return AbortNode(state, "Failed to write transaction index");
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static CCheckQueue<CScriptCheck> scriptcheckqueue(128);
|
||||
|
||||
void ThreadScriptCheck() {
|
||||
@ -2079,9 +2059,6 @@ bool CChainState::ConnectBlock(const CBlock& block, CValidationState& state, CBl
|
||||
setDirtyBlockIndex.insert(pindex);
|
||||
}
|
||||
|
||||
if (!WriteTxIndexDataForBlock(block, state, pindex))
|
||||
return false;
|
||||
|
||||
assert(pindex->phashBlock);
|
||||
// add this block to the view's block chain
|
||||
view.SetBestBlock(pindex->GetBlockHash());
|
||||
@ -3903,10 +3880,6 @@ bool static LoadBlockIndexDB(const CChainParams& chainparams)
|
||||
pblocktree->ReadReindexing(fReindexing);
|
||||
if(fReindexing) fReindex = true;
|
||||
|
||||
// Check whether we have a transaction index
|
||||
pblocktree->ReadFlag("txindex", fTxIndex);
|
||||
LogPrintf("%s: transaction index %s\n", __func__, fTxIndex ? "enabled" : "disabled");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -4300,9 +4273,6 @@ bool LoadBlockIndex(const CChainParams& chainparams)
|
||||
// needs_init.
|
||||
|
||||
LogPrintf("Initializing databases...\n");
|
||||
// Use the provided setting for -txindex in the new database
|
||||
fTxIndex = gArgs.GetBoolArg("-txindex", DEFAULT_TXINDEX);
|
||||
pblocktree->WriteFlag("txindex", fTxIndex);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -171,7 +171,6 @@ extern uint256 g_best_block;
|
||||
extern std::atomic_bool fImporting;
|
||||
extern std::atomic_bool fReindex;
|
||||
extern int nScriptCheckThreads;
|
||||
extern bool fTxIndex;
|
||||
extern bool fIsBareMultisigStd;
|
||||
extern bool fRequireStandard;
|
||||
extern bool fCheckBlockIndex;
|
||||
|
Loading…
Reference in New Issue
Block a user