6#ifndef ALT_INTEGRATION_INCLUDE_VERIBLOCK_BLOCKCHAIN_ALT_CHAIN_PARAMS_HPP_
7#define ALT_INTEGRATION_INCLUDE_VERIBLOCK_BLOCKCHAIN_ALT_CHAIN_PARAMS_HPP_
12#include <veriblock/pop/blockchain/block_index.hpp>
13#include <veriblock/pop/entities/altblock.hpp>
14#include <veriblock/pop/serde.hpp>
15#include <veriblock/pop/validation_state.hpp>
58 return mMaxScoreThresholdNormal;
63 return mMaxScoreThresholdKeystone;
68 return mDifficultyAveragingInterval;
82 double mStartOfSlope = 1.0;
83 double mSlopeNormal = 0.2;
84 double mSlopeKeystone = 0.21325;
85 uint32_t mKeystoneRound = 3;
86 uint32_t mPayoutRounds = 4;
87 uint32_t mFlatScoreRound = 2;
88 bool mUseFlatScoreRound =
true;
89 double mMaxScoreThresholdNormal = 2.0;
90 double mMaxScoreThresholdKeystone = 3.0;
91 uint32_t mDifficultyAveragingInterval = 50;
92 int32_t mPopPayoutDelay = 50;
94 std::vector<double> mRoundRatios{0.97, 1.03, 1.07, 3.00};
96 std::vector<double> mLookupTable{
97 1.00000000, 1.00000000, 1.00000000, 1.00000000, 1.00000000, 1.00000000,
98 1.00000000, 1.00000000, 1.00000000, 1.00000000, 1.00000000, 1.00000000,
99 0.48296816, 0.31551694, 0.23325824, 0.18453616, 0.15238463, 0.12961255,
100 0.11265630, 0.09955094, 0.08912509, 0.08063761, 0.07359692, 0.06766428,
101 0.06259873, 0.05822428, 0.05440941, 0.05105386, 0.04807993, 0.04542644,
102 0.04304458, 0.04089495, 0.03894540, 0.03716941, 0.03554497, 0.03405359,
103 0.03267969, 0.03141000, 0.03023319, 0.02913950, 0.02812047, 0.02716878,
104 0.02627801, 0.02544253, 0.02465739, 0.02391820, 0.02322107, 0.02256255,
105 0.02193952, 0.02134922};
109template <
typename JsonValue>
111 auto obj = json::makeEmptyObject<JsonValue>();
113 json::putArrayKV(obj,
"roundRatios", p.
roundRatios());
125 json::putDoubleKV(obj,
"slopeNormal", p.
slopeNormal());
126 json::putDoubleKV(obj,
"startOfSlope", p.
startOfSlope());
140 size_t maxWorkerQueueSize()
const noexcept {
143 static const auto MAX = 400000;
144 VBK_ASSERT_MSG(ret < MAX,
145 "Worker size queue can not be more than %d, otherwise it "
146 "would take more than 50MB of RAM",
161 return mForkResolutionLookUpTable;
167 return mEndorsementSettlementInterval;
172 return *mPopPayoutsParams;
178 return mMaxVbkBlocksInAltBlock;
184 return mMaxVTBsInAltBlock;
190 return mMaxATVsInAltBlock;
198 return mMaxAltchainFutureBlockTime;
206 VBK_ASSERT(
static_cast<int64_t
>(mMaxReorgBlocks) >
207 static_cast<int64_t
>(mEndorsementSettlementInterval));
208 return mMaxReorgBlocks;
216 VBK_ASSERT(mPreserveBlocksBehindFinal >= mEndorsementSettlementInterval);
217 return mPreserveBlocksBehindFinal;
240 const std::vector<uint8_t>& bytes) const noexcept = 0;
257 const std::vector<uint8_t>& root,
265 uint32_t mMaxAltchainFutureBlockTime = 10 * 60;
266 uint32_t mKeystoneInterval = 5;
267 uint32_t mFinalityDelay = 100;
268 uint32_t mEndorsementSettlementInterval = 50;
269 uint32_t mPreserveBlocksBehindFinal = mEndorsementSettlementInterval;
272 size_t mMaxVbkBlocksInAltBlock = 200;
273 size_t mMaxVTBsInAltBlock = 200;
274 size_t mMaxATVsInAltBlock = 1000;
276 std::vector<uint32_t> mForkResolutionLookUpTable{
277 100, 100, 95, 89, 80, 69, 56, 40, 21};
296 const std::vector<uint8_t>& bytes)
const noexcept override {
297 return AssertDeserializeFromRaw<AltBlock>(bytes).getHash();
301 const std::vector<uint8_t>&,
304 return DeserializeFromRaw<AltBlock>(bytes, block, state);
311template <
typename JsonValue>
313 auto obj = json::makeEmptyObject<JsonValue>();
322 "endorsementSettlementInterval",
328 json::putKV(obj,
"payoutParams", ToJSON<JsonValue>(p.
getPayoutParams()));
Class that is used for storing validation state.
constexpr const auto MAX_POPDATA_ATV
absolute maximum number of ATV blocks per ALT block
static const int32_t ALT_MAX_REORG_BLOCKS_MIN_VALUE
minimum number of blocks in ALT tree
constexpr const auto SHA256_HASH_SIZE
sha256 hash size
constexpr const auto MAX_POPDATA_VBK
absolute maximum number of VBK blocks per ALT block
constexpr const auto MAX_POPDATA_SIZE
maximum size of single PopData in a single ALT block, in bytes.
constexpr const auto MAX_POPDATA_VTB
absolute maximum number of VTB blocks per ALT block
Represents a view on Altchain block - i.e.
std::vector< uint8_t > getHash(const std::vector< uint8_t > &bytes) const noexcept override
Calculate hash from block header.
AltBlock getBootstrapBlock() const noexcept override
"genesis" block for POP mining.
int64_t getIdentifier() const noexcept override
unique POP ID for the chain; identifies altchain in VBK
bool checkBlockHeader(const std::vector< uint8_t > &bytes, const std::vector< uint8_t > &, ValidationState &state) const noexcept override
Returns true if input bytes:
Base class for all Altchain-related configs.
const std::vector< uint32_t > & getForkResolutionLookUpTable() const noexcept
pop score lookup table for fork resolution
uint32_t getKeystoneInterval() const noexcept
number of blocks in single keystone interval.
uint32_t maxAltchainFutureBlockTime() const noexcept
Maximum future block time for altchain blocks.
virtual std::vector< uint8_t > getHash(const std::vector< uint8_t > &bytes) const noexcept=0
Calculate hash from block header.
size_t getMaxVTBsInAltBlock() const noexcept
total maximum number of VTBs per 1 ALT block
size_t getMaxPopDataSize() const noexcept
maximum size (in bytes) of single PopData per single ALT block
size_t getMaxATVsInAltBlock() const noexcept
total maximum number of ATVs per 1 ALT block
virtual AltBlock getBootstrapBlock() const noexcept=0
"genesis" block for POP mining.
const PopPayoutsParams & getPayoutParams() const noexcept
getter for reward parameters
uint32_t preserveBlocksBehindFinal() const noexcept
when finalizeBlockImpl is called, this many blocks behind final block will be preserved in RAM.
uint32_t getFinalityDelay() const noexcept
number of blocks in VBK used for finalization
virtual int64_t getIdentifier() const noexcept=0
unique POP ID for the chain; identifies altchain in VBK
size_t getMaxVbkBlocksInAltBlock() const noexcept
total maximum number of VBK blocks per 1 ALT block
int32_t getMaxReorgBlocks() const noexcept
Max number of blocks that can be reorganized in altchain.
uint32_t getEndorsementSettlementInterval() const noexcept
Validity window for ATVs.
virtual bool checkBlockHeader(const std::vector< uint8_t > &bytes, const std::vector< uint8_t > &root, ValidationState &state) const noexcept=0
Returns true if input bytes:
Defines config for POP payouts.
double maxScoreThresholdKeystone() const noexcept
limit block with keystones score to this value
uint32_t payoutRounds() const noexcept
total number of payout rounds.
bool useFlatScoreRound() const noexcept
should we use flat rewards at all
int32_t getPopPayoutDelay() const noexcept
number of blocks in ALT between endorsed block and payout block
uint32_t flatScoreRound() const noexcept
we use this round number to pay flat reward (does not depend on pop difficulty)
double slopeKeystone() const noexcept
slope for keystone rounds
const std::vector< double > & roundRatios() const noexcept
we have these payout modifiers for different rounds.
const std::vector< double > & relativeScoreLookupTable() const noexcept
reward score table we score each VeriBlock and lower the reward for late blocks
double startOfSlope() const noexcept
we start decreasing rewards after this score
uint32_t difficultyAveragingInterval() const noexcept
collect this amount of blocks BEFORE the block to calculate pop difficulty
uint32_t keystoneRound() const noexcept
among all rounds, this number represents round for keystone blocks.
double slopeNormal() const noexcept
we decrease reward coefficient for this value for each additional score point above startOfDecreasing...
double maxScoreThresholdNormal() const noexcept
limit block score to this value