veriblock-pop-cpp
C++11 Libraries for leveraging VeriBlock Proof-Of-Proof blockchain technology.
pop_context.hpp
1// Copyright (c) 2019-2022 Xenios SEZC
2// https://www.veriblock.org
3// Distributed under the MIT software license, see the accompanying
4// file LICENSE or http://www.opensource.org/licenses/mit-license.php.
5
6#ifndef ALTINTEGRATION_ALTINTEGRATION_HPP
7#define ALTINTEGRATION_ALTINTEGRATION_HPP
8
9#include <utility>
10
11#include "alt-util.hpp"
12#include "blockchain/alt_block_tree.hpp"
13#include "bootstraps.hpp"
14#include "config.hpp"
15#include "mempool.hpp"
16#include "pop_stateless_validator.hpp"
17#include "rewards/default_poprewards_calculator.hpp"
18#include "storage.hpp"
19
20namespace altintegration {
21
27struct PopContext {
29
30 // non-copyable
31 PopContext(const PopContext&) = delete;
32 PopContext& operator=(const PopContext&) = delete;
33
34 // movable
35 PopContext(PopContext&&) = default;
36 PopContext& operator=(PopContext&&) = default;
37
50 static std::shared_ptr<PopContext> create(
51 std::shared_ptr<Config> config,
52 std::shared_ptr<PayloadsStorage> payloadsProvider,
53 std::shared_ptr<BlockReader> blockProvider,
54 std::unique_ptr<EthashCache> ethashCache,
55 std::unique_ptr<ProgpowHeaderCache> progpowHeaderCache,
56 size_t validatorWorkers = 0);
57
66 VBK_CHECK_RETURN bool check(const ATV& payload, ValidationState& state);
67
76 VBK_CHECK_RETURN bool check(const VTB& payload, ValidationState& state);
77
86 VBK_CHECK_RETURN bool check(const VbkBlock& payload, ValidationState& state);
87
96 VBK_CHECK_RETURN bool check(const PopData& payload, ValidationState& state);
97
103 void saveAllTrees(BlockBatch& batch) const;
104
111 VBK_CHECK_RETURN bool loadAllTrees(bool fast_load, ValidationState& state);
112
124 VBK_CHECK_RETURN bool getPopPayout(const AltBlockTree::hash_t& prev,
125 PopPayouts& rewards,
126 ValidationState& state);
127
134 VBK_CHECK_RETURN PopData generatePopData();
135
151 VBK_CHECK_RETURN bool generatePublicationData(
152 PublicationData& output,
153 const std::vector<uint8_t>& endorsedBlockHeader,
154 const std::vector<uint8_t>& txMerkleRoot,
155 const PopData& popData,
156 const std::vector<uint8_t>& payoutInfo);
157
158 VBK_CHECK_RETURN const Config& getConfig() const;
159 VBK_CHECK_RETURN MemPool& getMemPool();
160 VBK_CHECK_RETURN AltBlockTree& getAltBlockTree();
161 VBK_CHECK_RETURN const AltBlockTree& getAltBlockTree() const;
162 VBK_CHECK_RETURN const VbkBlockTree& getVbkBlockTree() const;
163 VBK_CHECK_RETURN const BtcBlockTree& getBtcBlockTree() const;
164
166 void shutdown();
167
168 private:
169 PopContext() = default;
170
171 std::shared_ptr<Config> config_;
172 std::shared_ptr<MemPool> mempool_;
173 std::shared_ptr<AltBlockTree> altTree_;
174 std::shared_ptr<PopValidator> popValidator_;
175 std::shared_ptr<PopRewardsCalculator> popRewardsCalculator_;
176 std::shared_ptr<PayloadsStorage> payloadsProvider_;
177 std::shared_ptr<BlockReader> blockProvider_;
178};
179
180} // namespace altintegration
181
182#endif // ALTINTEGRATION_ALTINTEGRATION_HPP
Class that is used for storing validation state.
Altchains must configure AltBlockTree prior any usage by providing bootstrapping Config.
Defines logging helpers.
Definition: block.hpp:14
Atlchain endorsement.
Definition: atv.hpp:36
Represents simplified view on Altchain's block tree, maintains VBK tree and BTC tree.
An interface which represents single write batch of a group of blocks.
Definition: block_batch.hpp:22
BlockTree is a tree of blocks with single "bootstrap" block as root.
Definition: blocktree.hpp:30
A container for Bitcoin and Veriblock configuration data.
Definition: config.hpp:37
Data structure, that stores in memory all valid payloads (ATV, VTB, VbkBlock) submitted by other peer...
Definition: mempool.hpp:41
Main entrypoint into the veriblock-pop library.
Definition: pop_context.hpp:27
void shutdown()
stops PopContext internal thread pool used for stateless validation.
VBK_CHECK_RETURN bool getPopPayout(const AltBlockTree::hash_t &prev, PopPayouts &rewards, ValidationState &state)
Calculates POP rewards that should be paid in the next block after prev.
VBK_CHECK_RETURN bool check(const PopData &payload, ValidationState &state)
Checks PopData (stateless check).
VBK_CHECK_RETURN bool check(const ATV &payload, ValidationState &state)
Checks ATV (stateless check).
VBK_CHECK_RETURN bool loadAllTrees(bool fast_load, ValidationState &state)
Load ALT/VBK/BTC trees from disk via adapter BlockReader.
static std::shared_ptr< PopContext > create(std::shared_ptr< Config > config, std::shared_ptr< PayloadsStorage > payloadsProvider, std::shared_ptr< BlockReader > blockProvider, std::unique_ptr< EthashCache > ethashCache, std::unique_ptr< ProgpowHeaderCache > progpowHeaderCache, size_t validatorWorkers=0)
Factory function for PopContext.
VBK_CHECK_RETURN PopData generatePopData()
Generate PopData for the block next to the current tip.
VBK_CHECK_RETURN bool check(const VbkBlock &payload, ValidationState &state)
Checks VbkBlock (stateless check).
void saveAllTrees(BlockBatch &batch) const
Save ALT/VBK/BTC trees on disk via adapter BlockBatch.
VBK_CHECK_RETURN bool generatePublicationData(PublicationData &output, const std::vector< uint8_t > &endorsedBlockHeader, const std::vector< uint8_t > &txMerkleRoot, const PopData &popData, const std::vector< uint8_t > &payoutInfo)
Create PublicationData given required input parameters.
VBK_CHECK_RETURN bool check(const VTB &payload, ValidationState &state)
Checks VTB (stateless check).
Represents ALT block body of POP-related info.
Definition: popdata.hpp:27
A container for Pop payouts information.
Definition: pop_payouts.hpp:28
Publication data about ALT block inside VBK blockchain.
Veriblock to Bitcoin publication, committed to Veriblock blockchain in containingBlock.
Definition: vtb.hpp:37
Veriblock block tree.
Veriblock block.
Definition: vbkblock.hpp:32