Changeset View
Changeset View
Standalone View
Standalone View
src/interfaces/chain.cpp
Show First 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | bool FillBlock(const CBlockIndex *index, const FoundBlock &block, | ||||
*block.m_time = index->GetBlockTime(); | *block.m_time = index->GetBlockTime(); | ||||
} | } | ||||
if (block.m_max_time) { | if (block.m_max_time) { | ||||
*block.m_max_time = index->GetBlockTimeMax(); | *block.m_max_time = index->GetBlockTimeMax(); | ||||
} | } | ||||
if (block.m_mtp_time) { | if (block.m_mtp_time) { | ||||
*block.m_mtp_time = index->GetMedianTimePast(); | *block.m_mtp_time = index->GetMedianTimePast(); | ||||
} | } | ||||
if (block.m_in_active_chain) { | |||||
*block.m_in_active_chain = ChainActive()[index->nHeight] == index; | |||||
} | |||||
if (block.m_next_block) { | |||||
FillBlock(ChainActive()[index->nHeight] == index | |||||
? ChainActive()[index->nHeight + 1] | |||||
: nullptr, | |||||
*block.m_next_block, lock); | |||||
} | |||||
if (block.m_data) { | if (block.m_data) { | ||||
REVERSE_LOCK(lock); | REVERSE_LOCK(lock); | ||||
if (!ReadBlockFromDisk(*block.m_data, index, | if (!ReadBlockFromDisk(*block.m_data, index, | ||||
Params().GetConsensus())) { | Params().GetConsensus())) { | ||||
block.m_data->SetNull(); | block.m_data->SetNull(); | ||||
} | } | ||||
} | } | ||||
return true; | return true; | ||||
▲ Show 20 Lines • Show All 103 Lines • ▼ Show 20 Lines | public: | ||||
std::optional<int> getHeight() override { | std::optional<int> getHeight() override { | ||||
LOCK(::cs_main); | LOCK(::cs_main); | ||||
int height = ::ChainActive().Height(); | int height = ::ChainActive().Height(); | ||||
if (height >= 0) { | if (height >= 0) { | ||||
return height; | return height; | ||||
} | } | ||||
return std::nullopt; | return std::nullopt; | ||||
} | } | ||||
std::optional<int> getBlockHeight(const BlockHash &hash) override { | |||||
LOCK(::cs_main); | |||||
CBlockIndex *block = g_chainman.m_blockman.LookupBlockIndex(hash); | |||||
if (block && ::ChainActive().Contains(block)) { | |||||
return block->nHeight; | |||||
} | |||||
return std::nullopt; | |||||
} | |||||
BlockHash getBlockHash(int height) override { | BlockHash getBlockHash(int height) override { | ||||
LOCK(::cs_main); | LOCK(::cs_main); | ||||
CBlockIndex *block = ::ChainActive()[height]; | CBlockIndex *block = ::ChainActive()[height]; | ||||
assert(block); | assert(block); | ||||
return block->GetBlockHash(); | return block->GetBlockHash(); | ||||
} | } | ||||
bool haveBlockOnDisk(int height) override { | bool haveBlockOnDisk(int height) override { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
CBlockIndex *block = ::ChainActive()[height]; | CBlockIndex *block = ::ChainActive()[height]; | ||||
return block && (block->nStatus.hasData() != 0) && block->nTx > 0; | return block && (block->nStatus.hasData() != 0) && block->nTx > 0; | ||||
} | } | ||||
std::optional<int> | |||||
findFirstBlockWithTimeAndHeight(int64_t time, int height, | |||||
BlockHash *hash) override { | |||||
LOCK(cs_main); | |||||
CBlockIndex *block = | |||||
::ChainActive().FindEarliestAtLeast(time, height); | |||||
if (block) { | |||||
if (hash) { | |||||
*hash = block->GetBlockHash(); | |||||
} | |||||
return block->nHeight; | |||||
} | |||||
return std::nullopt; | |||||
} | |||||
CBlockLocator getTipLocator() override { | CBlockLocator getTipLocator() override { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
return ::ChainActive().GetLocator(); | return ::ChainActive().GetLocator(); | ||||
} | } | ||||
bool contextualCheckTransactionForCurrentBlock( | bool contextualCheckTransactionForCurrentBlock( | ||||
const CTransaction &tx, TxValidationState &state) override { | const CTransaction &tx, TxValidationState &state) override { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
return ContextualCheckTransactionForCurrentBlock( | return ContextualCheckTransactionForCurrentBlock( | ||||
Show All 16 Lines | public: | ||||
} | } | ||||
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); | ||||
return FillBlock( | return FillBlock( | ||||
ChainActive().FindEarliestAtLeast(min_time, min_height), block, | ChainActive().FindEarliestAtLeast(min_time, min_height), block, | ||||
lock); | lock); | ||||
} | } | ||||
bool findNextBlock(const BlockHash &block_hash, int block_height, | |||||
const FoundBlock &next, bool *reorg) override { | |||||
WAIT_LOCK(cs_main, lock); | |||||
CBlockIndex *block = ChainActive()[block_height]; | |||||
if (block && block->GetBlockHash() != block_hash) { | |||||
block = nullptr; | |||||
} | |||||
if (reorg) { | |||||
*reorg = !block; | |||||
} | |||||
return FillBlock(block ? ChainActive()[block_height + 1] : nullptr, | |||||
next, lock); | |||||
} | |||||
bool findAncestorByHeight(const BlockHash &block_hash, | bool findAncestorByHeight(const BlockHash &block_hash, | ||||
int ancestor_height, | int ancestor_height, | ||||
const FoundBlock &ancestor_out) override { | const FoundBlock &ancestor_out) override { | ||||
WAIT_LOCK(cs_main, lock); | WAIT_LOCK(cs_main, lock); | ||||
if (const CBlockIndex *block = | if (const CBlockIndex *block = | ||||
g_chainman.m_blockman.LookupBlockIndex(block_hash)) { | g_chainman.m_blockman.LookupBlockIndex(block_hash)) { | ||||
if (const CBlockIndex *ancestor = | if (const CBlockIndex *ancestor = | ||||
block->GetAncestor(ancestor_height)) { | block->GetAncestor(ancestor_height)) { | ||||
▲ Show 20 Lines • Show All 242 Lines • Show Last 20 Lines |