Changeset View
Changeset View
Standalone View
Standalone View
src/interfaces/chain.cpp
Show First 20 Lines • Show All 107 Lines • ▼ Show 20 Lines | class LockImpl : public Chain::Lock, public UniqueLock<RecursiveMutex> { | ||||
if (block) { | if (block) { | ||||
if (hash) { | if (hash) { | ||||
*hash = block->GetBlockHash(); | *hash = block->GetBlockHash(); | ||||
} | } | ||||
return block->nHeight; | return block->nHeight; | ||||
} | } | ||||
return nullopt; | return nullopt; | ||||
} | } | ||||
Optional<int> findPruned(int start_height, | |||||
Optional<int> stop_height) override { | |||||
LockAssertion lock(::cs_main); | |||||
if (::fPruneMode) { | |||||
CBlockIndex *block = stop_height ? ::ChainActive()[*stop_height] | |||||
: ::ChainActive().Tip(); | |||||
while (block && block->nHeight >= start_height) { | |||||
if (block->nStatus.hasData() == 0) { | |||||
return block->nHeight; | |||||
} | |||||
block = block->pprev; | |||||
} | |||||
} | |||||
return nullopt; | |||||
} | |||||
Optional<int> findFork(const BlockHash &hash, | Optional<int> findFork(const BlockHash &hash, | ||||
Optional<int> *height) override { | Optional<int> *height) override { | ||||
LockAssertion lock(::cs_main); | LockAssertion lock(::cs_main); | ||||
const CBlockIndex *block = LookupBlockIndex(hash); | const CBlockIndex *block = LookupBlockIndex(hash); | ||||
const CBlockIndex *fork = | const CBlockIndex *fork = | ||||
block ? ::ChainActive().FindFork(block) : nullptr; | block ? ::ChainActive().FindFork(block) : nullptr; | ||||
if (height) { | if (height) { | ||||
if (block) { | if (block) { | ||||
▲ Show 20 Lines • Show All 192 Lines • ▼ Show 20 Lines | public: | ||||
void findCoins(std::map<COutPoint, Coin> &coins) override { | void findCoins(std::map<COutPoint, Coin> &coins) override { | ||||
return FindCoins(coins); | return FindCoins(coins); | ||||
} | } | ||||
double guessVerificationProgress(const BlockHash &block_hash) override { | double guessVerificationProgress(const BlockHash &block_hash) override { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
return GuessVerificationProgress(Params().TxData(), | return GuessVerificationProgress(Params().TxData(), | ||||
LookupBlockIndex(block_hash)); | LookupBlockIndex(block_hash)); | ||||
} | } | ||||
bool hasBlocks(const BlockHash &block_hash, int min_height, | |||||
Optional<int> max_height) override { | |||||
// hasBlocks returns true if all ancestors of block_hash in | |||||
// specified range have block data (are not pruned), false if any | |||||
// ancestors in specified range are missing data. | |||||
// | |||||
// For simplicity and robustness, min_height and max_height are only | |||||
// used to limit the range, and passing min_height that's too low or | |||||
// max_height that's too high will not crash or change the result. | |||||
LOCK(::cs_main); | |||||
if (CBlockIndex *block = LookupBlockIndex(block_hash)) { | |||||
if (max_height && block->nHeight >= *max_height) { | |||||
block = block->GetAncestor(*max_height); | |||||
} | |||||
for (; block->nStatus.hasData(); block = block->pprev) { | |||||
// Check pprev to not segfault if min_height is too low | |||||
if (block->nHeight <= min_height || !block->pprev) { | |||||
return true; | |||||
} | |||||
} | |||||
} | |||||
return false; | |||||
} | |||||
bool hasDescendantsInMempool(const TxId &txid) override { | bool hasDescendantsInMempool(const TxId &txid) override { | ||||
LOCK(::g_mempool.cs); | LOCK(::g_mempool.cs); | ||||
auto it = ::g_mempool.GetIter(txid); | auto it = ::g_mempool.GetIter(txid); | ||||
return it && (*it)->GetCountWithDescendants() > 1; | return it && (*it)->GetCountWithDescendants() > 1; | ||||
} | } | ||||
bool broadcastTransaction(const Config &config, | bool broadcastTransaction(const Config &config, | ||||
const CTransactionRef &tx, | const CTransactionRef &tx, | ||||
std::string &err_string, | std::string &err_string, | ||||
▲ Show 20 Lines • Show All 124 Lines • Show Last 20 Lines |