Changeset View
Changeset View
Standalone View
Standalone View
src/interfaces/chain.cpp
Show First 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | bool FillBlock(const CBlockIndex *index, const FoundBlock &block, | ||||
Params().GetConsensus())) { | Params().GetConsensus())) { | ||||
block.m_data->SetNull(); | block.m_data->SetNull(); | ||||
} | } | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
class LockImpl : public Chain::Lock, public UniqueLock<RecursiveMutex> { | class LockImpl : public Chain::Lock, public UniqueLock<RecursiveMutex> { | ||||
Optional<int> getHeight() override { | |||||
LockAssertion lock(::cs_main); | |||||
int height = ::ChainActive().Height(); | |||||
if (height >= 0) { | |||||
return height; | |||||
} | |||||
return nullopt; | |||||
} | |||||
Optional<int> getBlockHeight(const BlockHash &hash) override { | Optional<int> getBlockHeight(const BlockHash &hash) override { | ||||
LockAssertion lock(::cs_main); | LockAssertion lock(::cs_main); | ||||
CBlockIndex *block = LookupBlockIndex(hash); | CBlockIndex *block = LookupBlockIndex(hash); | ||||
if (block && ::ChainActive().Contains(block)) { | if (block && ::ChainActive().Contains(block)) { | ||||
return block->nHeight; | return block->nHeight; | ||||
} | } | ||||
return nullopt; | return nullopt; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 167 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; | ||||
} | } | ||||
Optional<int> getHeight() override { | |||||
LOCK(::cs_main); | |||||
int height = ::ChainActive().Height(); | |||||
if (height >= 0) { | |||||
return height; | |||||
} | |||||
return nullopt; | |||||
} | |||||
bool findBlock(const BlockHash &hash, | bool findBlock(const BlockHash &hash, | ||||
const FoundBlock &block) override { | const FoundBlock &block) override { | ||||
WAIT_LOCK(cs_main, lock); | WAIT_LOCK(cs_main, lock); | ||||
return FillBlock(LookupBlockIndex(hash), block, lock); | return FillBlock(LookupBlockIndex(hash), block, lock); | ||||
} | } | ||||
bool findFirstBlockWithTimeAndHeight(int64_t min_time, int min_height, | bool findFirstBlockWithTimeAndHeight(int64_t min_time, int min_height, | ||||
const FoundBlock &block) override { | const FoundBlock &block) override { | ||||
WAIT_LOCK(cs_main, lock); | WAIT_LOCK(cs_main, lock); | ||||
▲ Show 20 Lines • Show All 218 Lines • Show Last 20 Lines |