veriblock-pop-cpp
C++11 Libraries for leveraging VeriBlock Proof-Of-Proof blockchain technology.
btc_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_BTC_CHAIN_PARAMS_HPP_
7#define ALT_INTEGRATION_INCLUDE_VERIBLOCK_BLOCKCHAIN_BTC_CHAIN_PARAMS_HPP_
8
9#include <veriblock/pop/entities/btcblock.hpp>
10#include <veriblock/pop/serde.hpp>
11#include <veriblock/pop/strutil.hpp>
12#include <veriblock/pop/uint.hpp>
13#include <veriblock/pop/validation_state.hpp>
14
15namespace altintegration {
16
19 virtual ~BtcChainParams() = default;
20 virtual uint256 getPowLimit() const = 0;
21 virtual uint32_t getPowTargetTimespan() const noexcept = 0;
22 virtual uint32_t getPowTargetSpacing() const noexcept = 0;
23 virtual bool getAllowMinDifficultyBlocks() const noexcept = 0;
24 virtual bool getPowNoRetargeting() const noexcept = 0;
25 // virtual BtcBlock getGenesisBlock() const noexcept = 0;
26 virtual bool EnableTimeAdjustment() const noexcept = 0;
27 uint32_t getDifficultyAdjustmentInterval() const noexcept {
28 return getPowTargetTimespan() / getPowTargetSpacing();
29 }
31 virtual uint32_t numBlocksForBootstrap() const noexcept = 0;
32 virtual const char* networkName() const noexcept = 0;
33 virtual uint32_t maxFutureBlockTime() const noexcept {
34 return mMaxFutureBlockTime;
35 }
36
38 int32_t getMaxReorgBlocks() const noexcept {
39 VBK_ASSERT(static_cast<uint32_t>(mMaxReorgBlocks) >=
40 getDifficultyAdjustmentInterval());
41 return mMaxReorgBlocks;
42 }
43
46 uint32_t preserveBlocksBehindFinal() const noexcept { return 0; }
47
49 int32_t getOldBlocksWindow() const noexcept { return mOldBlocksWindow; }
50
51 uint32_t mOldBlocksWindow = 1000;
52 int32_t mMaxReorgBlocks = BTC_MAX_REORG_BLOCKS_MIN_VALUE;
53
54 protected:
55 uint32_t mMaxFutureBlockTime = 2 * 60 * 60; // 2 hours
56};
57
65 ~BtcChainParamsMain() override = default;
66
67 bool EnableTimeAdjustment() const noexcept override { return true; }
68
69 const char* networkName() const noexcept override { return "main"; }
70
71 uint32_t numBlocksForBootstrap() const noexcept override {
72 return getDifficultyAdjustmentInterval();
73 };
74
75 uint256 getPowLimit() const override {
76 return uint256::fromHex(
77 "ffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000");
78 }
79
80 uint32_t getPowTargetTimespan() const noexcept override {
81 return 14 * 24 * 60 * 60; // two weeks
82 }
83 uint32_t getPowTargetSpacing() const noexcept override { return 10 * 60; }
84 bool getAllowMinDifficultyBlocks() const noexcept override { return false; }
85 bool getPowNoRetargeting() const noexcept override { return false; }
86 // BtcBlock getGenesisBlock() const noexcept override {
87 // BtcBlock block;
88 // block.version = 1;
89 // block.timestamp = 1231006505;
90 // block.nonce = 2083236893;
91 // block.bits = 0x1d00ffff;
92 // block.merkleRoot = uint256::fromHex(
93 // "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b");
94 //
95 // VBK_ASSERT(
96 // block.getHash() ==
97 // uint256::fromHex("000000000019d6689c085ae165831e934ff763ae46a2a6c172"
98 // "b3f1b60a8ce26f"));
99 //
100 // return block;
101 // }
102};
103
111 ~BtcChainParamsTest() override = default;
112
113 bool EnableTimeAdjustment() const noexcept override { return true; }
114
115 const char* networkName() const noexcept override { return "test"; }
116
117 uint32_t numBlocksForBootstrap() const noexcept override {
118 return getDifficultyAdjustmentInterval();
119 };
120
121 uint256 getPowLimit() const override {
122 return uint256::fromHex(
123 "ffffffffffffffffffffffffffffffffffffffffffffffffffffffff00000000");
124 }
125
126 uint32_t getPowTargetTimespan() const noexcept override {
127 return 14 * 24 * 60 * 60;
128 }
129 uint32_t getPowTargetSpacing() const noexcept override { return 10 * 60; }
130 bool getAllowMinDifficultyBlocks() const noexcept override { return true; }
131 bool getPowNoRetargeting() const noexcept override { return false; }
132 // BtcBlock getGenesisBlock() const noexcept override {
133 // BtcBlock block;
134 // block.version = 1;
135 // block.timestamp = 1296688602;
136 // block.nonce = 414098458;
137 // block.bits = 0x1d00ffff;
138 // block.merkleRoot = uint256::fromHex(
139 // "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b");
140 //
141 // VBK_ASSERT(
142 // block.getHash() ==
143 // uint256::fromHex("000000000933ea01ad0ee984209779baaec3ced90fa3f40871"
144 // "9526f8d77f4943"));
145 //
146 // return block;
147 // }
148};
149
157 ~BtcChainParamsRegTest() override = default;
158
160 bool EnableTimeAdjustment() const noexcept override { return false; }
161
162 const char* networkName() const noexcept override { return "regtest"; }
163
164 uint32_t numBlocksForBootstrap() const noexcept override { return 1; };
165
166 uint256 getPowLimit() const override {
167 return uint256::fromHex(
168 "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff7f");
169 }
170
171 uint32_t getPowTargetTimespan() const noexcept override {
172 return 14 * 24 * 60 * 60;
173 }
174 uint32_t getPowTargetSpacing() const noexcept override { return 10 * 60; }
175 bool getAllowMinDifficultyBlocks() const noexcept override { return true; }
176 bool getPowNoRetargeting() const noexcept override { return true; }
177 // BtcBlock getGenesisBlock() const noexcept override {
178 // BtcBlock block;
179 // block.version = 1;
180 // block.timestamp = 1296688602;
181 // block.nonce = 2;
182 // block.bits = 0x207fffff;
183 // block.merkleRoot = uint256::fromHex(
184 // "4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b");
185 //
186 // VBK_ASSERT(
187 // block.getHash() ==
188 // uint256::fromHex("0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca59"
189 // "0b1a11466e2206"));
190 //
191 // return block;
192 // }
193};
194
195} // namespace altintegration
196
197#endif // ALT_INTEGRATION_INCLUDE_VERIBLOCK_BLOCKCHAIN_BTC_CHAIN_PARAMS_HPP_
Defines logging helpers.
Definition: block.hpp:14
static const int32_t BTC_MAX_REORG_BLOCKS_MIN_VALUE
minimum number of blocks in BTC tree
Definition: consts.hpp:132
mainnet network params in Bitcoin chain.
uint32_t numBlocksForBootstrap() const noexcept override
minimum number of BTC blocks needed to bootstrap chain
regtest network params in Bitcoin chain.
bool EnableTimeAdjustment() const noexcept override
time adjustment is disabled in regtest mode
uint32_t numBlocksForBootstrap() const noexcept override
minimum number of BTC blocks needed to bootstrap chain
testnet3 network params in Bitcoin chain.
uint32_t numBlocksForBootstrap() const noexcept override
minimum number of BTC blocks needed to bootstrap chain
base class for BTC params
int32_t getOldBlocksWindow() const noexcept
all blocks further than this number of blocks are considered "old"
virtual uint32_t numBlocksForBootstrap() const noexcept=0
minimum number of BTC blocks needed to bootstrap chain
uint32_t preserveBlocksBehindFinal() const noexcept
when finalizeBlockImpl is called, this many blocks behind final block will be preserved in RAM.
int32_t getMaxReorgBlocks() const noexcept
by default we store this many last BTC blocks in RAM