Skip to content

Commit e0a3b80

Browse files
author
Jim Posen
committed
[validation] Replace tx index code in validation code with TxIndex.
1 parent 8181db8 commit e0a3b80

File tree

4 files changed

+7
-43
lines changed

4 files changed

+7
-43
lines changed

src/init.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,12 +1483,6 @@ bool AppInitMain()
14831483
return InitError(_("Incorrect or no genesis block found. Wrong datadir for network?"));
14841484
}
14851485

1486-
// Check for changed -txindex state
1487-
if (fTxIndex != gArgs.GetBoolArg("-txindex", DEFAULT_TXINDEX)) {
1488-
strLoadError = _("You need to rebuild the database using -reindex to change -txindex");
1489-
break;
1490-
}
1491-
14921486
// Check for changed -prune state. What we are concerned about is a user who has pruned blocks
14931487
// in the past, but is now trying to run unpruned.
14941488
if (fHavePruned && !fPruneMode) {

src/rpc/rawtransaction.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <coins.h>
88
#include <consensus/validation.h>
99
#include <core_io.h>
10+
#include <index/txindex.h>
1011
#include <init.h>
1112
#include <keystore.h>
1213
#include <validation.h>
@@ -176,10 +177,10 @@ UniValue getrawtransaction(const JSONRPCRequest& request)
176177
throw JSONRPCError(RPC_MISC_ERROR, "Block not available");
177178
}
178179
errmsg = "No such transaction found in the provided block";
180+
} else if (!g_txindex) {
181+
errmsg = "No such mempool transaction. Use -txindex to enable blockchain transaction queries";
179182
} else {
180-
errmsg = fTxIndex
181-
? "No such mempool or blockchain transaction"
182-
: "No such mempool transaction. Use -txindex to enable blockchain transaction queries";
183+
errmsg = "No such mempool or blockchain transaction";
183184
}
184185
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, errmsg + ". Use gettransaction for wallet transactions.");
185186
}

src/validation.cpp

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <consensus/validation.h>
1717
#include <cuckoocache.h>
1818
#include <hash.h>
19+
#include <index/txindex.h>
1920
#include <init.h>
2021
#include <policy/fees.h>
2122
#include <policy/policy.h>
@@ -217,7 +218,6 @@ uint256 g_best_block;
217218
int nScriptCheckThreads = 0;
218219
std::atomic_bool fImporting(false);
219220
std::atomic_bool fReindex(false);
220-
bool fTxIndex = false;
221221
bool fHavePruned = false;
222222
bool fPruneMode = false;
223223
bool fIsBareMultisigStd = DEFAULT_PERMIT_BAREMULTISIG;
@@ -1028,9 +1028,9 @@ bool GetTransaction(const uint256& hash, CTransactionRef& txOut, const Consensus
10281028
return true;
10291029
}
10301030

1031-
if (fTxIndex) {
1031+
if (g_txindex) {
10321032
CDiskTxPos postx;
1033-
if (pblocktree->ReadTxIndex(hash, postx)) {
1033+
if (g_txindex->FindTx(hash, postx)) {
10341034
CAutoFile file(OpenBlockFile(postx, true), SER_DISK, CLIENT_VERSION);
10351035
if (file.IsNull())
10361036
return error("%s: OpenBlockFile failed", __func__);
@@ -1668,26 +1668,6 @@ static bool WriteUndoDataForBlock(const CBlockUndo& blockundo, CValidationState&
16681668
return true;
16691669
}
16701670

1671-
static bool WriteTxIndexDataForBlock(const CBlock& block, CValidationState& state, CBlockIndex* pindex)
1672-
{
1673-
if (!fTxIndex) return true;
1674-
1675-
CDiskTxPos pos(pindex->GetBlockPos(), GetSizeOfCompactSize(block.vtx.size()));
1676-
std::vector<std::pair<uint256, CDiskTxPos> > vPos;
1677-
vPos.reserve(block.vtx.size());
1678-
for (const CTransactionRef& tx : block.vtx)
1679-
{
1680-
vPos.push_back(std::make_pair(tx->GetHash(), pos));
1681-
pos.nTxOffset += ::GetSerializeSize(*tx, SER_DISK, CLIENT_VERSION);
1682-
}
1683-
1684-
if (!pblocktree->WriteTxIndex(vPos)) {
1685-
return AbortNode(state, "Failed to write transaction index");
1686-
}
1687-
1688-
return true;
1689-
}
1690-
16911671
static CCheckQueue<CScriptCheck> scriptcheckqueue(128);
16921672

16931673
void ThreadScriptCheck() {
@@ -2079,9 +2059,6 @@ bool CChainState::ConnectBlock(const CBlock& block, CValidationState& state, CBl
20792059
setDirtyBlockIndex.insert(pindex);
20802060
}
20812061

2082-
if (!WriteTxIndexDataForBlock(block, state, pindex))
2083-
return false;
2084-
20852062
assert(pindex->phashBlock);
20862063
// add this block to the view's block chain
20872064
view.SetBestBlock(pindex->GetBlockHash());
@@ -3903,10 +3880,6 @@ bool static LoadBlockIndexDB(const CChainParams& chainparams)
39033880
pblocktree->ReadReindexing(fReindexing);
39043881
if(fReindexing) fReindex = true;
39053882

3906-
// Check whether we have a transaction index
3907-
pblocktree->ReadFlag("txindex", fTxIndex);
3908-
LogPrintf("%s: transaction index %s\n", __func__, fTxIndex ? "enabled" : "disabled");
3909-
39103883
return true;
39113884
}
39123885

@@ -4300,9 +4273,6 @@ bool LoadBlockIndex(const CChainParams& chainparams)
43004273
// needs_init.
43014274

43024275
LogPrintf("Initializing databases...\n");
4303-
// Use the provided setting for -txindex in the new database
4304-
fTxIndex = gArgs.GetBoolArg("-txindex", DEFAULT_TXINDEX);
4305-
pblocktree->WriteFlag("txindex", fTxIndex);
43064276
}
43074277
return true;
43084278
}

src/validation.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ extern uint256 g_best_block;
171171
extern std::atomic_bool fImporting;
172172
extern std::atomic_bool fReindex;
173173
extern int nScriptCheckThreads;
174-
extern bool fTxIndex;
175174
extern bool fIsBareMultisigStd;
176175
extern bool fRequireStandard;
177176
extern bool fCheckBlockIndex;

0 commit comments

Comments
 (0)