Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/blockchain.cpp
Show First 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | CTxMemPool &EnsureMemPool() { | ||||
} | } | ||||
return *g_rpc_node->mempool; | return *g_rpc_node->mempool; | ||||
} | } | ||||
/** | /** | ||||
* Calculate the difficulty for a given block index. | * Calculate the difficulty for a given block index. | ||||
*/ | */ | ||||
double GetDifficulty(const CBlockIndex *blockindex) { | double GetDifficulty(const CBlockIndex *blockindex) { | ||||
assert(blockindex); | CHECK_NONFATAL(blockindex); | ||||
int nShift = (blockindex->nBits >> 24) & 0xff; | int nShift = (blockindex->nBits >> 24) & 0xff; | ||||
double dDiff = double(0x0000ffff) / double(blockindex->nBits & 0x00ffffff); | double dDiff = double(0x0000ffff) / double(blockindex->nBits & 0x00ffffff); | ||||
while (nShift < 29) { | while (nShift < 29) { | ||||
dDiff *= 256.0; | dDiff *= 256.0; | ||||
nShift++; | nShift++; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 1,001 Lines • ▼ Show 20 Lines | static UniValue pruneblockchain(const Config &config, | ||||
} else if (height > chainHeight - MIN_BLOCKS_TO_KEEP) { | } else if (height > chainHeight - MIN_BLOCKS_TO_KEEP) { | ||||
LogPrint(BCLog::RPC, "Attempt to prune blocks close to the tip. " | LogPrint(BCLog::RPC, "Attempt to prune blocks close to the tip. " | ||||
"Retaining the minimum number of blocks.\n"); | "Retaining the minimum number of blocks.\n"); | ||||
height = chainHeight - MIN_BLOCKS_TO_KEEP; | height = chainHeight - MIN_BLOCKS_TO_KEEP; | ||||
} | } | ||||
PruneBlockFilesManual(height); | PruneBlockFilesManual(height); | ||||
const CBlockIndex *block = ::ChainActive().Tip(); | const CBlockIndex *block = ::ChainActive().Tip(); | ||||
assert(block); | CHECK_NONFATAL(block); | ||||
while (block->pprev && (block->pprev->nStatus.hasData())) { | while (block->pprev && (block->pprev->nStatus.hasData())) { | ||||
block = block->pprev; | block = block->pprev; | ||||
} | } | ||||
return uint64_t(block->nHeight); | return uint64_t(block->nHeight); | ||||
} | } | ||||
static UniValue gettxoutsetinfo(const Config &config, | static UniValue gettxoutsetinfo(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
▲ Show 20 Lines • Show All 322 Lines • ▼ Show 20 Lines | UniValue getblockchaininfo(const Config &config, | ||||
obj.pushKV("initialblockdownload", | obj.pushKV("initialblockdownload", | ||||
::ChainstateActive().IsInitialBlockDownload()); | ::ChainstateActive().IsInitialBlockDownload()); | ||||
obj.pushKV("chainwork", tip->nChainWork.GetHex()); | obj.pushKV("chainwork", tip->nChainWork.GetHex()); | ||||
obj.pushKV("size_on_disk", CalculateCurrentUsage()); | obj.pushKV("size_on_disk", CalculateCurrentUsage()); | ||||
obj.pushKV("pruned", fPruneMode); | obj.pushKV("pruned", fPruneMode); | ||||
if (fPruneMode) { | if (fPruneMode) { | ||||
const CBlockIndex *block = tip; | const CBlockIndex *block = tip; | ||||
assert(block); | CHECK_NONFATAL(block); | ||||
while (block->pprev && (block->pprev->nStatus.hasData())) { | while (block->pprev && (block->pprev->nStatus.hasData())) { | ||||
block = block->pprev; | block = block->pprev; | ||||
} | } | ||||
obj.pushKV("pruneheight", block->nHeight); | obj.pushKV("pruneheight", block->nHeight); | ||||
// if 0, execution bypasses the whole if block. | // if 0, execution bypasses the whole if block. | ||||
bool automatic_pruning = (gArgs.GetArg("-prune", 0) != 1); | bool automatic_pruning = (gArgs.GetArg("-prune", 0) != 1); | ||||
▲ Show 20 Lines • Show All 493 Lines • ▼ Show 20 Lines | if (request.params[1].isNull()) { | ||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found"); | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found"); | ||||
} | } | ||||
if (!::ChainActive().Contains(pindex)) { | if (!::ChainActive().Contains(pindex)) { | ||||
throw JSONRPCError(RPC_INVALID_PARAMETER, | throw JSONRPCError(RPC_INVALID_PARAMETER, | ||||
"Block is not in main chain"); | "Block is not in main chain"); | ||||
} | } | ||||
} | } | ||||
assert(pindex != nullptr); | CHECK_NONFATAL(pindex != nullptr); | ||||
if (request.params[0].isNull()) { | if (request.params[0].isNull()) { | ||||
blockcount = std::max(0, std::min(blockcount, pindex->nHeight - 1)); | blockcount = std::max(0, std::min(blockcount, pindex->nHeight - 1)); | ||||
} else { | } else { | ||||
blockcount = request.params[0].get_int(); | blockcount = request.params[0].get_int(); | ||||
if (blockcount < 0 || | if (blockcount < 0 || | ||||
(blockcount > 0 && blockcount >= pindex->nHeight)) { | (blockcount > 0 && blockcount >= pindex->nHeight)) { | ||||
▲ Show 20 Lines • Show All 163 Lines • ▼ Show 20 Lines | if (request.params[0].isNum()) { | ||||
} | } | ||||
if (!::ChainActive().Contains(pindex)) { | if (!::ChainActive().Contains(pindex)) { | ||||
throw JSONRPCError(RPC_INVALID_PARAMETER, | throw JSONRPCError(RPC_INVALID_PARAMETER, | ||||
strprintf("Block is not in chain %s", | strprintf("Block is not in chain %s", | ||||
Params().NetworkIDString())); | Params().NetworkIDString())); | ||||
} | } | ||||
} | } | ||||
assert(pindex != nullptr); | CHECK_NONFATAL(pindex != nullptr); | ||||
std::set<std::string> stats; | std::set<std::string> stats; | ||||
if (!request.params[1].isNull()) { | if (!request.params[1].isNull()) { | ||||
const UniValue stats_univalue = request.params[1].get_array(); | const UniValue stats_univalue = request.params[1].get_array(); | ||||
for (unsigned int i = 0; i < stats_univalue.size(); i++) { | for (unsigned int i = 0; i < stats_univalue.size(); i++) { | ||||
const std::string stat = stats_univalue[i].get_str(); | const std::string stat = stats_univalue[i].get_str(); | ||||
stats.insert(stat); | stats.insert(stat); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 73 Lines • ▼ Show 20 Lines | for (size_t i = 0; i < block.vtx.size(); ++i) { | ||||
tx_total_in += prevoutput.nValue; | tx_total_in += prevoutput.nValue; | ||||
utxo_size_inc -= | utxo_size_inc -= | ||||
GetSerializeSize(prevoutput, PROTOCOL_VERSION) + | GetSerializeSize(prevoutput, PROTOCOL_VERSION) + | ||||
PER_UTXO_OVERHEAD; | PER_UTXO_OVERHEAD; | ||||
} | } | ||||
Amount txfee = tx_total_in - tx_total_out; | Amount txfee = tx_total_in - tx_total_out; | ||||
assert(MoneyRange(txfee)); | CHECK_NONFATAL(MoneyRange(txfee)); | ||||
if (do_medianfee) { | if (do_medianfee) { | ||||
fee_array.push_back(txfee); | fee_array.push_back(txfee); | ||||
} | } | ||||
maxfee = std::max(maxfee, txfee); | maxfee = std::max(maxfee, txfee); | ||||
minfee = std::min(minfee, txfee); | minfee = std::min(minfee, txfee); | ||||
totalfee += txfee; | totalfee += txfee; | ||||
Amount feerate = txfee / tx_size; | Amount feerate = txfee / tx_size; | ||||
▲ Show 20 Lines • Show All 131 Lines • ▼ Show 20 Lines | |||||
class CoinsViewScanReserver { | class CoinsViewScanReserver { | ||||
private: | private: | ||||
bool m_could_reserve; | bool m_could_reserve; | ||||
public: | public: | ||||
explicit CoinsViewScanReserver() : m_could_reserve(false) {} | explicit CoinsViewScanReserver() : m_could_reserve(false) {} | ||||
bool reserve() { | bool reserve() { | ||||
assert(!m_could_reserve); | CHECK_NONFATAL(!m_could_reserve); | ||||
std::lock_guard<std::mutex> lock(g_utxosetscan); | std::lock_guard<std::mutex> lock(g_utxosetscan); | ||||
if (g_scan_in_progress) { | if (g_scan_in_progress) { | ||||
return false; | return false; | ||||
} | } | ||||
g_scan_in_progress = true; | g_scan_in_progress = true; | ||||
m_could_reserve = true; | m_could_reserve = true; | ||||
return true; | return true; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 154 Lines • ▼ Show 20 Lines | if (request.params[0].get_str() == "status") { | ||||
g_scan_progress = 0; | g_scan_progress = 0; | ||||
int64_t count = 0; | int64_t count = 0; | ||||
std::unique_ptr<CCoinsViewCursor> pcursor; | std::unique_ptr<CCoinsViewCursor> pcursor; | ||||
CBlockIndex *tip; | CBlockIndex *tip; | ||||
{ | { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
::ChainstateActive().ForceFlushStateToDisk(); | ::ChainstateActive().ForceFlushStateToDisk(); | ||||
pcursor = std::unique_ptr<CCoinsViewCursor>(pcoinsdbview->Cursor()); | pcursor = std::unique_ptr<CCoinsViewCursor>(pcoinsdbview->Cursor()); | ||||
assert(pcursor); | CHECK_NONFATAL(pcursor); | ||||
tip = ::ChainActive().Tip(); | tip = ::ChainActive().Tip(); | ||||
assert(tip); | CHECK_NONFATAL(tip); | ||||
} | } | ||||
bool res = FindScriptPubKey(g_scan_progress, g_should_abort_scan, count, | bool res = FindScriptPubKey(g_scan_progress, g_should_abort_scan, count, | ||||
pcursor.get(), needles, coins); | pcursor.get(), needles, coins); | ||||
result.pushKV("success", res); | result.pushKV("success", res); | ||||
result.pushKV("txouts", count); | result.pushKV("txouts", count); | ||||
result.pushKV("height", tip->nHeight); | result.pushKV("height", tip->nHeight); | ||||
result.pushKV("bestblock", tip->GetBlockHash().GetHex()); | result.pushKV("bestblock", tip->GetBlockHash().GetHex()); | ||||
▲ Show 20 Lines • Show All 155 Lines • Show Last 20 Lines |