mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 03:52:49 +01:00
feat: show human friendly error if missing spentindex, txindex or addressindex
It also fixes spam messages about missing txindex for each RPC call getrawtransaction node0 2024-12-03T18:54:33.349605Z [ http] [httpserver.cpp:248] [http_request_cb] [http] Received a POST request for / from 127.0.0.1:40052 node0 2024-12-03T18:54:33.349634Z [httpworker.3] [rpc/request.cpp:180] [parse] [rpc] ThreadRPCServer method=getrawtransaction user=__cookie__ node0 2024-12-03T18:54:33.349729Z [httpworker.3] [util/system.h:57] [error] ERROR: Spent index not enabled node0 2024-12-03T18:54:33.349735Z [httpworker.3] [util/system.h:57] [error] ERROR: Spent index not enabled node0 2024-12-03T18:54:33.349738Z [httpworker.3] [util/system.h:57] [error] ERROR: Spent index not enabled node0 2024-12-03T18:54:33.349808Z [httpworker.3] [httprpc.cpp:93] [~RpcHttpRequest] [bench] HTTP RPC request handled: user=__cookie__ command=getrawtransaction external=false status=200 elapsed_time_ms=0 node0 2024-12-03T18:54:33.349998Z [ http] [httpserver.cpp:248] [http_request_cb] [http] Received a POST request for / from 127.0.0.1:40052 node0 2024-12-03T18:54:33.350027Z [httpworker.0] [rpc/request.cpp:180] [parse] [rpc] ThreadRPCServer method=getrawtransaction user=__cookie__ node0 2024-12-03T18:54:33.350128Z [httpworker.0] [util/system.h:57] [error] ERROR: Spent index not enabled node0 2024-12-03T18:54:33.350133Z [httpworker.0] [util/system.h:57] [error] ERROR: Spent index not enabled node0 2024-12-03T18:54:33.350137Z [httpworker.0] [util/system.h:57] [error] ERROR: Spent index not enabled
This commit is contained in:
parent
02948b2695
commit
dd1b36636c
@ -870,6 +870,10 @@ static RPCHelpMan getblockhashes()
|
|||||||
},
|
},
|
||||||
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
||||||
{
|
{
|
||||||
|
if (!IsTimestampIndexAvailable()) {
|
||||||
|
throw JSONRPCError(RPC_INVALID_REQUEST, "Timestamp index is disabled. You should run Dash Core with -timestampindex (requires reindex)");
|
||||||
|
}
|
||||||
|
|
||||||
unsigned int high = request.params[0].get_int();
|
unsigned int high = request.params[0].get_int();
|
||||||
unsigned int low = request.params[1].get_int();
|
unsigned int low = request.params[1].get_int();
|
||||||
std::vector<uint256> blockHashes;
|
std::vector<uint256> blockHashes;
|
||||||
|
@ -10,6 +10,11 @@
|
|||||||
#include <txmempool.h>
|
#include <txmempool.h>
|
||||||
#include <uint256.h>
|
#include <uint256.h>
|
||||||
|
|
||||||
|
bool IsAddressIndexAvailable()
|
||||||
|
{
|
||||||
|
return fAddressIndex;
|
||||||
|
}
|
||||||
|
|
||||||
bool GetAddressIndex(CBlockTreeDB& block_tree_db, const uint160& addressHash, const AddressType type,
|
bool GetAddressIndex(CBlockTreeDB& block_tree_db, const uint160& addressHash, const AddressType type,
|
||||||
std::vector<CAddressIndexEntry>& addressIndex,
|
std::vector<CAddressIndexEntry>& addressIndex,
|
||||||
const int32_t start, const int32_t end)
|
const int32_t start, const int32_t end)
|
||||||
@ -67,6 +72,11 @@ bool GetMempoolAddressDeltaIndex(const CTxMemPool& mempool,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool IsSpentIndexAvailable()
|
||||||
|
{
|
||||||
|
return fSpentIndex;
|
||||||
|
}
|
||||||
|
|
||||||
bool GetSpentIndex(CBlockTreeDB& block_tree_db, const CTxMemPool& mempool, const CSpentIndexKey& key,
|
bool GetSpentIndex(CBlockTreeDB& block_tree_db, const CTxMemPool& mempool, const CSpentIndexKey& key,
|
||||||
CSpentIndexValue& value)
|
CSpentIndexValue& value)
|
||||||
{
|
{
|
||||||
@ -84,6 +94,11 @@ bool GetSpentIndex(CBlockTreeDB& block_tree_db, const CTxMemPool& mempool, const
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool IsTimestampIndexAvailable()
|
||||||
|
{
|
||||||
|
return fTimestampIndex;
|
||||||
|
}
|
||||||
|
|
||||||
bool GetTimestampIndex(CBlockTreeDB& block_tree_db, const uint32_t high, const uint32_t low,
|
bool GetTimestampIndex(CBlockTreeDB& block_tree_db, const uint32_t high, const uint32_t low,
|
||||||
std::vector<uint256>& hashes)
|
std::vector<uint256>& hashes)
|
||||||
{
|
{
|
||||||
|
@ -24,6 +24,7 @@ enum class AddressType : uint8_t;
|
|||||||
|
|
||||||
extern RecursiveMutex cs_main;
|
extern RecursiveMutex cs_main;
|
||||||
|
|
||||||
|
bool IsAddressIndexAvailable();
|
||||||
bool GetAddressIndex(CBlockTreeDB& block_tree_db, const uint160& addressHash, const AddressType type,
|
bool GetAddressIndex(CBlockTreeDB& block_tree_db, const uint160& addressHash, const AddressType type,
|
||||||
std::vector<CAddressIndexEntry>& addressIndex,
|
std::vector<CAddressIndexEntry>& addressIndex,
|
||||||
const int32_t start = 0, const int32_t end = 0)
|
const int32_t start = 0, const int32_t end = 0)
|
||||||
@ -35,9 +36,13 @@ bool GetMempoolAddressDeltaIndex(const CTxMemPool& mempool,
|
|||||||
const std::vector<CMempoolAddressDeltaKey>& addressDeltaIndex,
|
const std::vector<CMempoolAddressDeltaKey>& addressDeltaIndex,
|
||||||
std::vector<CMempoolAddressDeltaEntry>& addressDeltaEntries,
|
std::vector<CMempoolAddressDeltaEntry>& addressDeltaEntries,
|
||||||
const bool timestamp_sort = false);
|
const bool timestamp_sort = false);
|
||||||
|
|
||||||
|
bool IsSpentIndexAvailable();
|
||||||
bool GetSpentIndex(CBlockTreeDB& block_tree_db, const CTxMemPool& mempool, const CSpentIndexKey& key,
|
bool GetSpentIndex(CBlockTreeDB& block_tree_db, const CTxMemPool& mempool, const CSpentIndexKey& key,
|
||||||
CSpentIndexValue& value)
|
CSpentIndexValue& value)
|
||||||
EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
|
EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
|
||||||
|
|
||||||
|
bool IsTimestampIndexAvailable();
|
||||||
bool GetTimestampIndex(CBlockTreeDB& block_tree_db, const uint32_t high, const uint32_t low,
|
bool GetTimestampIndex(CBlockTreeDB& block_tree_db, const uint32_t high, const uint32_t low,
|
||||||
std::vector<uint256>& hashes)
|
std::vector<uint256>& hashes)
|
||||||
EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
|
EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
|
||||||
|
@ -742,6 +742,10 @@ static RPCHelpMan getaddressmempool()
|
|||||||
},
|
},
|
||||||
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
||||||
{
|
{
|
||||||
|
if (!IsAddressIndexAvailable()) {
|
||||||
|
throw JSONRPCError(RPC_INVALID_REQUEST, "Address index is disabled. You should run Dash Core with -addressindex (requires reindex)");
|
||||||
|
}
|
||||||
|
|
||||||
CTxMemPool& mempool = EnsureAnyMemPool(request.context);
|
CTxMemPool& mempool = EnsureAnyMemPool(request.context);
|
||||||
|
|
||||||
std::vector<std::pair<uint160, AddressType>> addresses;
|
std::vector<std::pair<uint160, AddressType>> addresses;
|
||||||
@ -814,6 +818,9 @@ static RPCHelpMan getaddressutxos()
|
|||||||
},
|
},
|
||||||
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
||||||
{
|
{
|
||||||
|
if (!IsAddressIndexAvailable()) {
|
||||||
|
throw JSONRPCError(RPC_INVALID_REQUEST, "Address index is disabled. You should run Dash Core with -addressindex (requires reindex)");
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<std::pair<uint160, AddressType> > addresses;
|
std::vector<std::pair<uint160, AddressType> > addresses;
|
||||||
|
|
||||||
@ -887,7 +894,9 @@ static RPCHelpMan getaddressdeltas()
|
|||||||
},
|
},
|
||||||
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
||||||
{
|
{
|
||||||
|
if (!IsAddressIndexAvailable()) {
|
||||||
|
throw JSONRPCError(RPC_INVALID_REQUEST, "Address index is disabled. You should run Dash Core with -addressindex (requires reindex)");
|
||||||
|
}
|
||||||
|
|
||||||
UniValue startValue = find_value(request.params[0].get_obj(), "start");
|
UniValue startValue = find_value(request.params[0].get_obj(), "start");
|
||||||
UniValue endValue = find_value(request.params[0].get_obj(), "end");
|
UniValue endValue = find_value(request.params[0].get_obj(), "end");
|
||||||
@ -979,6 +988,9 @@ static RPCHelpMan getaddressbalance()
|
|||||||
},
|
},
|
||||||
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
||||||
{
|
{
|
||||||
|
if (!IsAddressIndexAvailable()) {
|
||||||
|
throw JSONRPCError(RPC_INVALID_REQUEST, "Address index is disabled. You should run Dash Core with -addressindex (requires reindex)");
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<std::pair<uint160, AddressType> > addresses;
|
std::vector<std::pair<uint160, AddressType> > addresses;
|
||||||
|
|
||||||
@ -1052,6 +1064,9 @@ static RPCHelpMan getaddresstxids()
|
|||||||
},
|
},
|
||||||
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
||||||
{
|
{
|
||||||
|
if (!IsAddressIndexAvailable()) {
|
||||||
|
throw JSONRPCError(RPC_INVALID_REQUEST, "Address index is disabled. You should run Dash Core with -addressindex (requires reindex)");
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<std::pair<uint160, AddressType> > addresses;
|
std::vector<std::pair<uint160, AddressType> > addresses;
|
||||||
|
|
||||||
@ -1142,6 +1157,9 @@ static RPCHelpMan getspentinfo()
|
|||||||
},
|
},
|
||||||
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
||||||
{
|
{
|
||||||
|
if (!IsSpentIndexAvailable()) {
|
||||||
|
throw JSONRPCError(RPC_INVALID_REQUEST, "Spent index is disabled. You should run Dash Core with -spentindex (requires reindex)");
|
||||||
|
}
|
||||||
|
|
||||||
UniValue txidValue = find_value(request.params[0].get_obj(), "txid");
|
UniValue txidValue = find_value(request.params[0].get_obj(), "txid");
|
||||||
UniValue indexValue = find_value(request.params[0].get_obj(), "index");
|
UniValue indexValue = find_value(request.params[0].get_obj(), "index");
|
||||||
|
@ -71,9 +71,12 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, CTxMemPool& mempo
|
|||||||
// data into the returned UniValue.
|
// data into the returned UniValue.
|
||||||
|
|
||||||
uint256 txid = tx.GetHash();
|
uint256 txid = tx.GetHash();
|
||||||
|
CSpentIndexTxInfo *txSpentInfoPtr{nullptr};
|
||||||
|
|
||||||
// Add spent information if spentindex is enabled
|
// Add spent information if spentindex is enabled
|
||||||
CSpentIndexTxInfo txSpentInfo;
|
CSpentIndexTxInfo txSpentInfo;
|
||||||
|
if (IsSpentIndexAvailable()) {
|
||||||
|
txSpentInfo = CSpentIndexTxInfo{};
|
||||||
for (const auto& txin : tx.vin) {
|
for (const auto& txin : tx.vin) {
|
||||||
if (!tx.IsCoinBase()) {
|
if (!tx.IsCoinBase()) {
|
||||||
CSpentIndexValue spentInfo;
|
CSpentIndexValue spentInfo;
|
||||||
@ -90,8 +93,10 @@ void TxToJSON(const CTransaction& tx, const uint256 hashBlock, CTxMemPool& mempo
|
|||||||
txSpentInfo.mSpentInfo.emplace(spentKey, spentInfo);
|
txSpentInfo.mSpentInfo.emplace(spentKey, spentInfo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
txSpentInfoPtr = &txSpentInfo;
|
||||||
|
}
|
||||||
|
|
||||||
TxToUniv(tx, uint256(), entry, true, /* txundo = */ nullptr, &txSpentInfo);
|
TxToUniv(tx, uint256(), entry, true, /* txundo = */ nullptr, txSpentInfoPtr);
|
||||||
|
|
||||||
bool chainLock = false;
|
bool chainLock = false;
|
||||||
if (!hashBlock.IsNull()) {
|
if (!hashBlock.IsNull()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user