Changeset View
Changeset View
Standalone View
Standalone View
src/interfaces/chain.cpp
Show All 29 Lines | |||||
#include <validation.h> | #include <validation.h> | ||||
#include <validationinterface.h> | #include <validationinterface.h> | ||||
#include <utility> | #include <utility> | ||||
namespace interfaces { | namespace interfaces { | ||||
namespace { | namespace { | ||||
bool FillBlock(const CBlockIndex *index, const FoundBlock &block, | |||||
UniqueLock<RecursiveMutex> &lock) { | |||||
if (!index) { | |||||
return false; | |||||
} | |||||
if (block.m_hash) { | |||||
*block.m_hash = index->GetBlockHash(); | |||||
} | |||||
if (block.m_height) { | |||||
*block.m_height = index->nHeight; | |||||
} | |||||
if (block.m_time) { | |||||
*block.m_time = index->GetBlockTime(); | |||||
} | |||||
if (block.m_max_time) { | |||||
*block.m_max_time = index->GetBlockTimeMax(); | |||||
} | |||||
if (block.m_mtp_time) { | |||||
*block.m_mtp_time = index->GetMedianTimePast(); | |||||
} | |||||
if (block.m_data) { | |||||
REVERSE_LOCK(lock); | |||||
if (!ReadBlockFromDisk(*block.m_data, index, | |||||
Params().GetConsensus())) { | |||||
block.m_data->SetNull(); | |||||
} | |||||
} | |||||
return true; | |||||
} | |||||
class LockImpl : public Chain::Lock, public UniqueLock<RecursiveMutex> { | class LockImpl : public Chain::Lock, public UniqueLock<RecursiveMutex> { | ||||
Optional<int> getHeight() override { | Optional<int> getHeight() override { | ||||
LockAssertion lock(::cs_main); | LockAssertion lock(::cs_main); | ||||
int height = ::ChainActive().Height(); | int height = ::ChainActive().Height(); | ||||
if (height >= 0) { | if (height >= 0) { | ||||
return height; | return height; | ||||
} | } | ||||
return nullopt; | return nullopt; | ||||
▲ Show 20 Lines • Show All 203 Lines • ▼ Show 20 Lines | public: | ||||
::cs_main, "cs_main", __FILE__, __LINE__, try_lock); | ::cs_main, "cs_main", __FILE__, __LINE__, try_lock); | ||||
if (try_lock && lock && !*lock) { | if (try_lock && lock && !*lock) { | ||||
return {}; | return {}; | ||||
} | } | ||||
// Temporary to avoid CWG 1579 | // Temporary to avoid CWG 1579 | ||||
std::unique_ptr<Chain::Lock> result = std::move(lock); | std::unique_ptr<Chain::Lock> result = std::move(lock); | ||||
return result; | return result; | ||||
} | } | ||||
bool findBlock(const BlockHash &hash, CBlock *block, int64_t *time, | bool findBlock(const BlockHash &hash, | ||||
int64_t *time_max) override { | const FoundBlock &block) override { | ||||
CBlockIndex *index; | WAIT_LOCK(cs_main, lock); | ||||
{ | return FillBlock(LookupBlockIndex(hash), block, lock); | ||||
LOCK(cs_main); | |||||
index = LookupBlockIndex(hash); | |||||
if (!index) { | |||||
return false; | |||||
} | |||||
if (time) { | |||||
*time = index->GetBlockTime(); | |||||
} | |||||
if (time_max) { | |||||
*time_max = index->GetBlockTimeMax(); | |||||
} | |||||
} | |||||
if (block && | |||||
!ReadBlockFromDisk(*block, index, Params().GetConsensus())) { | |||||
block->SetNull(); | |||||
} | |||||
return true; | |||||
} | } | ||||
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)); | ||||
▲ Show 20 Lines • Show All 133 Lines • Show Last 20 Lines |