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> { | ||||
bool haveBlockOnDisk(int height) override { | |||||
LockAssertion lock(::cs_main); | |||||
CBlockIndex *block = ::ChainActive()[height]; | |||||
return block && (block->nStatus.hasData() != 0) && block->nTx > 0; | |||||
} | |||||
Optional<int> | |||||
findFirstBlockWithTimeAndHeight(int64_t time, int height, | |||||
BlockHash *hash) override { | |||||
LockAssertion lock(::cs_main); | |||||
CBlockIndex *block = | |||||
::ChainActive().FindEarliestAtLeast(time, height); | |||||
if (block) { | |||||
if (hash) { | |||||
*hash = block->GetBlockHash(); | |||||
} | |||||
return block->nHeight; | |||||
} | |||||
return nullopt; | |||||
} | |||||
Optional<int> findFork(const BlockHash &hash, | |||||
Optional<int> *height) override { | |||||
LockAssertion lock(::cs_main); | |||||
const CBlockIndex *block = LookupBlockIndex(hash); | |||||
const CBlockIndex *fork = | |||||
block ? ::ChainActive().FindFork(block) : nullptr; | |||||
if (height) { | |||||
if (block) { | |||||
*height = block->nHeight; | |||||
} else { | |||||
height->reset(); | |||||
} | |||||
} | |||||
if (fork) { | |||||
return fork->nHeight; | |||||
} | |||||
return nullopt; | |||||
} | |||||
CBlockLocator getTipLocator() override { | |||||
LockAssertion lock(::cs_main); | |||||
return ::ChainActive().GetLocator(); | |||||
} | |||||
Optional<int> findLocatorFork(const CBlockLocator &locator) override { | |||||
LockAssertion lock(::cs_main); | |||||
if (CBlockIndex *fork = | |||||
FindForkInGlobalIndex(::ChainActive(), locator)) { | |||||
return fork->nHeight; | |||||
} | |||||
return nullopt; | |||||
} | |||||
bool contextualCheckTransactionForCurrentBlock( | |||||
const Consensus::Params ¶ms, const CTransaction &tx, | |||||
TxValidationState &state) override { | |||||
LockAssertion lock(::cs_main); | |||||
return ContextualCheckTransactionForCurrentBlock(params, tx, state); | |||||
} | |||||
using UniqueLock::UniqueLock; | using UniqueLock::UniqueLock; | ||||
}; // namespace interfaces | }; // namespace interfaces | ||||
class NotificationsProxy : public CValidationInterface { | class NotificationsProxy : public CValidationInterface { | ||||
public: | public: | ||||
explicit NotificationsProxy( | explicit NotificationsProxy( | ||||
std::shared_ptr<Chain::Notifications> notifications) | std::shared_ptr<Chain::Notifications> notifications) | ||||
: m_notifications(std::move(notifications)) {} | : m_notifications(std::move(notifications)) {} | ||||
▲ Show 20 Lines • Show All 119 Lines • ▼ Show 20 Lines | public: | ||||
return nullopt; | return 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 { | |||||
LOCK(cs_main); | |||||
CBlockIndex *block = ::ChainActive()[height]; | |||||
return block && (block->nStatus.hasData() != 0) && block->nTx > 0; | |||||
} | |||||
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 nullopt; | |||||
} | |||||
CBlockLocator getTipLocator() override { | |||||
LOCK(cs_main); | |||||
return ::ChainActive().GetLocator(); | |||||
} | |||||
bool contextualCheckTransactionForCurrentBlock( | |||||
const CTransaction &tx, TxValidationState &state) override { | |||||
LockAssertion lock(::cs_main); | |||||
return ContextualCheckTransactionForCurrentBlock( | |||||
m_params.GetConsensus(), tx, state); | |||||
} | |||||
Optional<int> findLocatorFork(const CBlockLocator &locator) override { | |||||
LOCK(cs_main); | |||||
if (CBlockIndex *fork = | |||||
FindForkInGlobalIndex(::ChainActive(), locator)) { | |||||
return fork->nHeight; | |||||
} | |||||
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 |