6#ifndef ALT_INTEGRATION_UTIL_HPP
7#define ALT_INTEGRATION_UTIL_HPP
15#include "hashutil.hpp"
16#include "keystone_util.hpp"
17#include "veriblock/pop/blockchain/alt_block_tree.hpp"
18#include "veriblock/pop/blockchain/block_index.hpp"
19#include "veriblock/pop/blockchain/blocktree.hpp"
20#include "veriblock/pop/entities/atv.hpp"
21#include "veriblock/pop/entities/context_info_container.hpp"
22#include "veriblock/pop/entities/popdata.hpp"
23#include "veriblock/pop/entities/publication_data.hpp"
24#include "veriblock/pop/entities/vbkblock.hpp"
25#include "veriblock/pop/entities/vtb.hpp"
26#include "veriblock/pop/uint.hpp"
27#include "veriblock/pop/validation_state.hpp"
34struct AuthenticatedContextInfoContainer;
35struct ContextInfoContainer;
37template <
typename Block,
typename ChainParams>
42template <
typename BlockTreeT>
44 const BlockTreeT& tree,
45 typename BlockTreeT::hash_t tip,
46 size_t size = std::numeric_limits<size_t>::max()) {
47 std::vector<typename BlockTreeT::block_t> ret;
48 auto* cursor = tree.getBlockIndex(tip);
50 while (cursor !=
nullptr && i++ < size) {
51 ret.push_back(cursor->getHeader());
52 cursor = cursor->pprev;
58template <
typename BlockTree>
61 std::vector<std::vector<uint8_t>> ret;
65 for (
size_t i = 0; i < size && tip !=
nullptr; i++) {
66 ret.push_back(tip->getHash().asVector());
71 std::reverse(ret.begin(), ret.end());
76template <
typename Block,
typename ChainParams>
78 const std::vector<std::vector<uint8_t>>& blocks,
80 for (
const auto& b : blocks) {
81 Block block = Block::fromRaw(b);
82 if (!tree.acceptBlockHeader(block, state)) {
103 const std::vector<uint8_t>& txMerkleRoot,
105 const std::vector<uint8_t>& payoutInfo,
111 const std::vector<uint8_t>& endorsedBlockHeader,
113 const std::vector<uint8_t>& txMerkleRoot,
115 const std::vector<uint8_t>& payoutInfo,
120 const std::vector<uint8_t>& endorsedBlockHeader,
122 const std::vector<uint8_t>& txMerkleRoot,
124 const std::vector<ATV::id_t>& atv_ids,
125 const std::vector<VTB::id_t>& vtb_ids,
126 const std::vector<VbkBlock::id_t>& vbk_ids,
127 const std::vector<uint8_t>& payoutInfo,
133 const uint256& popDataMerkleRoot,
Class that is used for storing validation state.
uint256 CalculateTopLevelMerkleRoot(const std::vector< uint8_t > &txMerkleRoot, const uint256 &popDataMerkleRoot, const ContextInfoContainer &ctx)
calculates top level merkle root that cryptographically authenticates block content (transactions,...
bool addBlocks(BlockTree< Block, ChainParams > &tree, const std::vector< std::vector< uint8_t > > &blocks, ValidationState &state)
helper to accept multiple blocks
bool GeneratePublicationData(const std::vector< uint8_t > &endorsedBlockHeader, const std::vector< uint8_t > &txMerkleRoot, const PopData &popData, const std::vector< uint8_t > &payoutInfo, const AltBlockTree &tree, PublicationData &out)
Creates a PublicationData - an entity, which stores information about Altchain block endorsement.
int getMaxAtvsInVbkBlock(uint64_t altchainId)
The second to the last byte is used to determine the max number of occurrences The first 7 bits deter...
std::vector< std::vector< uint8_t > > getLastKnownBlocks(const BlockTree &tree, size_t size)
helper to get last N known block hashes
std::vector< typename BlockTreeT::block_t > getContext(const BlockTreeT &tree, typename BlockTreeT::hash_t tip, size_t size=std::numeric_limits< size_t >::max())
Build a context (blocks necessary to connect) in a tree from tip backwards size elements.
Represents simplified view on Altchain's block tree, maintains VBK tree and BTC tree.
Base class for all Altchain-related configs.
Contains ContextInfoContainer and merkle path which authenticates hash of ContextInfoContainer to a b...
const Chain< index_t > & getBestChain() const
Getter for currently Active Chain.
BlockTree is a tree of blocks with single "bootstrap" block as root.
Container of context info for endorsed block.
Represents ALT block body of POP-related info.
Publication data about ALT block inside VBK blockchain.