veriblock-pop-cpp
C++11 Libraries for leveraging VeriBlock Proof-Of-Proof blockchain technology.
|
Base block tree that stores all blocks, maintains tree tips, maintains active chain. More...
Block |
Definition at line 35 of file base_block_tree.hpp.
#include <base_block_tree.hpp>
Public Types | |
using | block_t = Block |
using | block_height_t = typename block_t::height_t |
using | hash_t = typename Block::hash_t |
using | prev_block_hash_t = typename Block::prev_hash_t |
using | index_t = BlockIndex< Block > |
using | stored_index_t = StoredBlockIndex< Block > |
using | on_invalidate_t = void(const index_t &) |
using | block_index_t = std::unordered_map< prev_block_hash_t, std::unique_ptr< index_t > > |
Public Member Functions | |
const std::unordered_set< index_t * > & | getTips () const |
std::vector< index_t * > | getBlocks () const |
std::vector< index_t * > | getAllBlocks () const |
const BlockReader & | getBlockProvider () const |
BaseBlockTree (const BlockReader &blockProvider) | |
BaseBlockTree (const BaseBlockTree &)=delete | |
BaseBlockTree & | operator= (const BaseBlockTree &)=delete |
BaseBlockTree (BaseBlockTree &&)=default | |
BaseBlockTree & | operator= (BaseBlockTree &&)=default |
const Chain< index_t > & | getBestChain () const |
Getter for currently Active Chain. More... | |
template<typename T > | |
prev_block_hash_t | makePrevHash (const T &h) const |
template<typename T , typename = typename std::enable_if< std::is_same<T, hash_t>::value || std::is_same<T, prev_block_hash_t>::value>::type> | |
index_t * | getBlockIndex (const T &hash) |
Get BlockIndex by block hash. More... | |
template<typename T , typename = typename std::enable_if< std::is_same<T, hash_t>::value || std::is_same<T, prev_block_hash_t>::value>::type> | |
const index_t * | getBlockIndex (const T &hash) const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
template<typename T , typename = typename std::enable_if< std::is_same<T, hash_t>::value || std::is_same<T, prev_block_hash_t>::value>::type> | |
index_t * | findBlockIndex (const T &hash) |
Get BlockIndex by block hash. More... | |
template<typename T , typename = typename std::enable_if< std::is_same<T, hash_t>::value || std::is_same<T, prev_block_hash_t>::value>::type> | |
const index_t * | findBlockIndex (const T &hash) const |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
virtual bool | loadTip (const hash_t &hash, ValidationState &state) |
virtual bool | loadBlockForward (const stored_index_t &index, bool fast_load, ValidationState &state) |
Efficiently connects BlockIndex to this tree as a leaf, when it is loaded from disk. More... | |
void | removeSubtree (index_t &toRemove) |
Removes block and all its successors. More... | |
void | removeSubtree (const hash_t &toRemove) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
void | removeLeaf (index_t &toRemove) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
void | invalidateSubtree (index_t &toBeInvalidated, enum BlockValidityStatus reason, bool shouldDetermineBestChain=true) |
Mark given block as invalid. More... | |
void | invalidateSubtree (const hash_t &toBeInvalidated, enum BlockValidityStatus reason, bool shouldDetermineBestChain=true) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More... | |
void | revalidateSubtree (const hash_t &hash, enum BlockValidityStatus reason, bool shouldDetermineBestChain=true) |
void | revalidateSubtree (index_t &toBeValidated, enum BlockValidityStatus reason, bool shouldDetermineBestChain=true) |
bool | isBootstrapped () const |
Check if the blockchain is bootstrapped. More... | |
virtual bool | setState (const hash_t &block, ValidationState &state) |
virtual bool | setState (index_t &index, ValidationState &) |
virtual void | overrideTip (index_t &to) |
index_t & | getRoot () const |
const FinalizedPayloadsIndex< index_t > & | getFinalizedPayloadsIndex () const |
const PayloadsIndex< index_t > & | getPayloadsIndex () const |
DeferForkResolutionGuard | deferForkResolutionGuard () |
BaseBlockTree< VbkBlock >::prev_block_hash_t | makePrevHash (const hash_t &h) const |
HACK: getBlockIndex accepts either hash_t or prev_block_hash_t then, depending on what it received, it should do trim LE on full hash to receive short hash, which is stored inside a map. More... | |
Public Attributes | |
signals::Signal< void(const index_t &)> | onBlockBeforeDeallocated |
before we deallocate any block index we emit it to this signal More... | |
signals::Signal< on_invalidate_t > | onBlockValidityChanged |
signals to the end user that block have been invalidated More... | |
signals::Signal< void(const index_t &index)> | onBeforeOverrideTip |
chain reorg signal - the tip is being changed More... | |
Protected Member Functions | |
void | deallocateBlock (index_t &block) |
Permanently erases block from a block tree. More... | |
std::string | toPrettyString (size_t level=0) const |
void | decreaseAppliedBlockCount (size_t erasedBlocks) |
void | decreaseAppliedBlockCount (size_t) |
Protected Attributes | |
bool | isLoadingBlocks_ = false |
if true, we're in "loading blocks" state More... | |
bool | isLoaded_ = false |
if true, we can no longer execute loadBlock/loadTip on this tree. More... | |
block_index_t | blocks_ |
stores ALL blocks, including valid and invalid More... | |
std::unordered_set< index_t * > | tips_ |
stores ONLY VALID tips, including currently active tip More... | |
Chain< index_t > | activeChain_ |
currently applied chain More... | |
FinalizedPayloadsIndex< index_t > | finalizedPayloadsIndex_ |
stores mapping of payload id -> its containing ALT/VBK block which are already finalized. More... | |
PayloadsIndex< index_t > | payloadsIndex_ |
stores mapping of payload id -> its containing ALT/VBK blocks which are not yet finalized. More... | |
const BlockReader & | blockProvider_ |
using altintegration::BaseBlockTree< Block >::block_height_t = typename block_t::height_t |
Definition at line 37 of file base_block_tree.hpp.
using altintegration::BaseBlockTree< Block >::block_index_t = std::unordered_map<prev_block_hash_t, std::unique_ptr<index_t> > |
Definition at line 43 of file base_block_tree.hpp.
using altintegration::BaseBlockTree< Block >::block_t = Block |
Definition at line 36 of file base_block_tree.hpp.
using altintegration::BaseBlockTree< Block >::hash_t = typename Block::hash_t |
Definition at line 38 of file base_block_tree.hpp.
using altintegration::BaseBlockTree< Block >::index_t = BlockIndex<Block> |
Definition at line 40 of file base_block_tree.hpp.
using altintegration::BaseBlockTree< Block >::on_invalidate_t = void(const index_t&) |
Definition at line 42 of file base_block_tree.hpp.
using altintegration::BaseBlockTree< Block >::prev_block_hash_t = typename Block::prev_hash_t |
Definition at line 39 of file base_block_tree.hpp.
using altintegration::BaseBlockTree< Block >::stored_index_t = StoredBlockIndex<Block> |
Definition at line 41 of file base_block_tree.hpp.
|
inlinevirtual |
Definition at line 69 of file base_block_tree.hpp.
|
inline |
Definition at line 77 of file base_block_tree.hpp.
|
inlineprotected |
Definition at line 497 of file base_block_tree.hpp.
|
inlineprotected |
Definition at line 857 of file base_block_tree.hpp.
|
inlineprotected |
Definition at line 25 of file vbk_block_tree.hpp.
|
inline |
Definition at line 816 of file base_block_tree.hpp.
|
inline |
T | block type |
[in] | hash | block hash |
Definition at line 139 of file base_block_tree.hpp.
|
inline |
Definition at line 149 of file base_block_tree.hpp.
|
inline |
Definition at line 58 of file base_block_tree.hpp.
|
inline |
Definition at line 94 of file base_block_tree.hpp.
|
inline |
T | block type |
[in] | hash | block hash |
Definition at line 113 of file base_block_tree.hpp.
|
inline |
Definition at line 123 of file base_block_tree.hpp.
|
inline |
Definition at line 67 of file base_block_tree.hpp.
|
inline |
Definition at line 47 of file base_block_tree.hpp.
|
inline |
Definition at line 779 of file base_block_tree.hpp.
|
inline |
Definition at line 783 of file base_block_tree.hpp.
|
inline |
Definition at line 422 of file base_block_tree.hpp.
|
inline |
Definition at line 46 of file base_block_tree.hpp.
|
inline |
Definition at line 320 of file base_block_tree.hpp.
|
inline |
Also marks all successors as FAILED_CHILD.
[in] | toBeInvalidated | block to be invalidated |
[in] | reason | invalidation reason. BLOCK_FAILED_BLOCK is used to indicate that block is invalid because of consensus rules (altchain decided to invalidate it). BLOCK_FAILED_POP is used to indicate that block is invalid because it contains invalid POP data. |
[in] | shouldDetermineBestChain | when true, will trigger fork resolution with all tips. If it is known that block is on a fork (not on active chain), it is safe to omit fork resolution here. Otherwise, leaves tree in undefined state. |
Definition at line 265 of file base_block_tree.hpp.
|
inline |
Definition at line 386 of file base_block_tree.hpp.
|
inlinevirtual |
[in] | index | block to be connected |
[in] | fast_load | flag |
[out] | state | validation state |
Reimplemented in altintegration::AltBlockTree, altintegration::BlockTree< Block, ChainParams >, altintegration::BlockTree< VbkBlock, VbkChainParams >, and altintegration::VbkBlockTree.
Definition at line 189 of file base_block_tree.hpp.
|
inlinevirtual |
Definition at line 156 of file base_block_tree.hpp.
|
inline |
In this weird case, when Block=VbkBlock, we may call getBlockIndex(block->previousBlock)
, it is a call getBlockIndex(Blob<12>). But when
getBlockIndex` accepts it, it does an implicit cast to full hash (hash_t), adding zeroes in the end. Then, .trimLE returns 12 zeroes.
This hack allows us to inject explicit conversion hash_t (Blob<24>) -> prev_block_hash_t (Blob<12>).
Definition at line 305 of file vbk_block_tree.hpp.
|
inline |
Definition at line 98 of file base_block_tree.hpp.
|
inlinevirtual |
Definition at line 416 of file base_block_tree.hpp.
|
inline |
Definition at line 243 of file base_block_tree.hpp.
|
inline |
Definition at line 235 of file base_block_tree.hpp.
|
inline |
toRemove | block to be removed. |
Definition at line 200 of file base_block_tree.hpp.
|
inline |
Definition at line 328 of file base_block_tree.hpp.
|
inline |
Definition at line 340 of file base_block_tree.hpp.
|
inlinevirtual |
Definition at line 401 of file base_block_tree.hpp.
|
inlinevirtual |
Reimplemented in altintegration::AltBlockTree.
Definition at line 410 of file base_block_tree.hpp.
|
inlineprotected |
Definition at line 742 of file base_block_tree.hpp.
|
protected |
Definition at line 1158 of file base_block_tree.hpp.
|
protected |
Definition at line 1167 of file base_block_tree.hpp.
|
protected |
Definition at line 1154 of file base_block_tree.hpp.
|
protected |
For BTC tree does nothing. stores payloads only from finalized blocks.
Definition at line 1162 of file base_block_tree.hpp.
|
protected |
Definition at line 1152 of file base_block_tree.hpp.
|
protected |
Definition at line 1150 of file base_block_tree.hpp.
signals::Signal<void(const index_t& index)> altintegration::BaseBlockTree< Block >::onBeforeOverrideTip |
Definition at line 1146 of file base_block_tree.hpp.
signals::Signal<void(const index_t&)> altintegration::BaseBlockTree< Block >::onBlockBeforeDeallocated |
Definition at line 1142 of file base_block_tree.hpp.
signals::Signal<on_invalidate_t> altintegration::BaseBlockTree< Block >::onBlockValidityChanged |
Definition at line 1144 of file base_block_tree.hpp.
|
protected |
For BTC tree does nothing.
Definition at line 1165 of file base_block_tree.hpp.
|
protected |
Definition at line 1156 of file base_block_tree.hpp.