veriblock-pop-cpp
C++11 Libraries for leveraging VeriBlock Proof-Of-Proof blockchain technology.
vbk_chain_params.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 ALT_INTEGRATION_INCLUDE_VERIBLOCK_BLOCKCHAIN_VBK_CHAIN_PARAMS_HPP_
7#define ALT_INTEGRATION_INCLUDE_VERIBLOCK_BLOCKCHAIN_VBK_CHAIN_PARAMS_HPP_
8
9#include <memory>
10#include <veriblock/pop/entities/vbkblock.hpp>
11#include <veriblock/pop/serde.hpp>
12#include <veriblock/pop/uint.hpp>
13
14namespace altintegration {
15
20 virtual ~VbkChainParams() = default;
21 virtual int getProgPowForkHeight() const = 0;
22 virtual uint32_t getProgPowStartTimeEpoch() const noexcept = 0;
23 virtual bool isProgPowStartTimeEpochEnabled() const noexcept { return true; }
24 virtual const char* networkName() const = 0;
25 virtual uint256 getMinimumDifficulty() const = 0;
26 virtual VbkNetworkType getTransactionMagicByte() const noexcept = 0;
27 virtual bool getPowNoRetargeting() const noexcept = 0;
28 virtual uint32_t getRetargetPeriod() const noexcept = 0;
29 virtual uint32_t getTargetBlockTime() const noexcept = 0;
30 virtual uint32_t numBlocksForBootstrap() const noexcept = 0;
31 virtual uint32_t maxFutureBlockTime() const noexcept {
32 return mMaxFutureBlockTime;
33 }
34
38 virtual bool EnableTimeAdjustment() const noexcept = 0;
39
40 virtual int32_t getMaxReorgBlocks() const noexcept { return mMaxReorgBlocks; }
41 virtual uint32_t getKeystoneInterval() const noexcept { return 20; }
42
43 virtual uint32_t getFinalityDelay() const noexcept { return 11; }
44
46 virtual int32_t getOldBlocksWindow() const noexcept {
47 return mOldBlocksWindow;
48 }
49
50 virtual const std::vector<uint32_t>& getForkResolutionLookUpTable()
51 const noexcept {
52 return forkResolutionLookUpTable_;
53 }
54
55 virtual int32_t getEndorsementSettlementInterval() const noexcept {
56 return mEndorsementSettlementInterval;
57 }
58
63 uint32_t preserveBlocksBehindFinal() const noexcept {
64 VBK_ASSERT(mPreserveBlocksBehindFinal >= mEndorsementSettlementInterval);
65 return mPreserveBlocksBehindFinal;
66 }
67
68 /* roughly 100h worth of VBK block production */
69 // equal to 1.5*8000 (1.5 progpow epochs)
70 uint32_t mOldBlocksWindow = 12000;
71
72 uint32_t mEndorsementSettlementInterval = 400;
73 uint32_t mPreserveBlocksBehindFinal = mEndorsementSettlementInterval;
74 int32_t mMaxReorgBlocks = VBK_MAX_REORG_BLOCKS_MIN_VALUE;
75
76 protected:
77 uint32_t mMaxFutureBlockTime = 5 * 60; // 5 min
78 std::vector<uint32_t> forkResolutionLookUpTable_{
79 100, 100, 95, 89, 80, 69, 56, 40, 21};
80};
81
87 ~VbkChainParamsMain() override = default;
88
89 int getProgPowForkHeight() const override { return 1512000; }
90 virtual uint32_t getProgPowStartTimeEpoch() const noexcept override {
91 return 1600716052U;
92 }
93
94 const char* networkName() const override { return "main"; }
95
96 uint32_t numBlocksForBootstrap() const noexcept override {
97 return getRetargetPeriod();
98 }
99
100 // hex(90 000 000 000) = 14f46b0400
101 uint256 getMinimumDifficulty() const override {
102 return ArithUint256::fromHex("14f46b0400");
103 }
104 VbkNetworkType getTransactionMagicByte() const noexcept override {
106 r.hasValue = false;
107 r.value = 0;
108 return r;
109 }
110 bool getPowNoRetargeting() const noexcept override { return false; }
111
112 bool EnableTimeAdjustment() const noexcept override { return true; }
113
114 uint32_t getRetargetPeriod() const noexcept override { return 100; }
115
116 uint32_t getTargetBlockTime() const noexcept override { return 30; }
117};
118
124 ~VbkChainParamsTest() override = default;
125
126 int getProgPowForkHeight() const override { return 872000; }
127 uint32_t getProgPowStartTimeEpoch() const noexcept override {
128 return 1600444017U;
129 }
130
131 const char* networkName() const override { return "test"; }
132
133 uint32_t numBlocksForBootstrap() const noexcept override {
134 return getRetargetPeriod();
135 }
136
137 // hex(100000000) = 5f5e100
138 uint256 getMinimumDifficulty() const override {
139 return ArithUint256::fromHex("05F5E100");
140 }
141
142 VbkNetworkType getTransactionMagicByte() const noexcept override {
144 r.hasValue = true;
145 r.value = 0xAA;
146 return r;
147 }
148 bool getPowNoRetargeting() const noexcept override { return false; }
149
150 bool EnableTimeAdjustment() const noexcept override { return true; }
151
152 uint32_t getRetargetPeriod() const noexcept override { return 100; }
153
154 uint32_t getTargetBlockTime() const noexcept override { return 30; }
155};
156
165 ~VbkChainParamsRegTest() override = default;
166
167 int getProgPowForkHeight() const override { return 0; }
168 uint32_t getProgPowStartTimeEpoch() const noexcept override {
169 // disabled (see 'false' below)
170 return 0;
171 }
172 bool isProgPowStartTimeEpochEnabled() const noexcept override {
173 return false;
174 }
175
176 const char* networkName() const override { return "regtest"; }
177
178 uint32_t numBlocksForBootstrap() const noexcept override { return 0; }
179
180 // hex(1) = 1
181 uint256 getMinimumDifficulty() const override {
182 return uint256::fromHex("1");
183 }
184 VbkNetworkType getTransactionMagicByte() const noexcept override {
186 r.hasValue = true;
187 r.value = 0xBB;
188 return r;
189 }
190 bool EnableTimeAdjustment() const noexcept override { return false; }
191
192 bool getPowNoRetargeting() const noexcept override { return true; }
193
194 uint32_t getRetargetPeriod() const noexcept override { return 100; }
195
196 uint32_t getTargetBlockTime() const noexcept override { return 30; }
197};
198
199} // namespace altintegration
200
201#endif // ALT_INTEGRATION_INCLUDE_VERIBLOCK_BLOCKCHAIN_VBK_CHAIN_PARAMS_HPP_
static ArithUint256 fromHex(const std::string &hex)
Defines logging helpers.
Definition: block.hpp:14
static const int32_t VBK_MAX_REORG_BLOCKS_MIN_VALUE
minimum number of blocks in VBK tree
Definition: consts.hpp:130
bool EnableTimeAdjustment() const noexcept override
In miner it is hard to simulate correct timestamps, so this flag disables Time Adjustment Algorithm i...
bool EnableTimeAdjustment() const noexcept override
In miner it is hard to simulate correct timestamps, so this flag disables Time Adjustment Algorithm i...
bool EnableTimeAdjustment() const noexcept override
In miner it is hard to simulate correct timestamps, so this flag disables Time Adjustment Algorithm i...
VeriBlock chain parameters.
uint32_t preserveBlocksBehindFinal() const noexcept
when finalizeBlockImpl is called, this many blocks behind final block will be preserved in RAM.
virtual int32_t getOldBlocksWindow() const noexcept
all blocks further than this number of blocks are considered "old"
virtual bool EnableTimeAdjustment() const noexcept=0
In miner it is hard to simulate correct timestamps, so this flag disables Time Adjustment Algorithm i...
works as optional<uint8_t>
bool hasValue
if hasValue == false, it is mainnet
uint8_t value
otherwise, use value for network ID