forked from digibyte/digibyte
-
Notifications
You must be signed in to change notification settings - Fork 95
Expand file tree
/
Copy pathdeployment_burial_tests.cpp
More file actions
219 lines (181 loc) · 10.2 KB
/
Copy pathdeployment_burial_tests.cpp
File metadata and controls
219 lines (181 loc) · 10.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
// Copyright (c) 2026 The DigiByte Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
//
// Pins for the BIP90 burial of the TAPROOT, DIGIDOLLAR, and ALGOLOCK
// deployments (v9.26.5). The burial heights are the actual on-chain BIP9
// 'since' heights, verified against live getdeploymentinfo output on mainnet
// (tip 23,882,878) and a fully-synced testnet26 node:
// mainnet: taproot 21,168,000; digidollar 23,869,440; algolock 23,869,440
// testnet: taproot 0 (ALWAYS_ACTIVE); digidollar 600; algolock 0
// regtest/signet: all 0 (ALWAYS_ACTIVE)
// The static nDDActivationHeight/nOracleActivationHeight floor gates are
// deliberately NOT moved by the burial; EarliestActivationFloor must keep its
// pre-burial value on every network.
#include <chain.h>
#include <chainparams.h>
#include <consensus/digidollar.h>
#include <consensus/params.h>
#include <deploymentinfo.h>
#include <deploymentstatus.h>
#include <digidollar/digidollar.h>
#include <test/util/setup_common.h>
#include <util/chaintype.h>
#include <boost/test/unit_test.hpp>
#include <limits>
BOOST_FIXTURE_TEST_SUITE(deployment_burial_tests, BasicTestingSetup)
BOOST_AUTO_TEST_CASE(mainnet_burial_heights)
{
SelectParams(ChainType::MAIN);
const auto& params = Params().GetConsensus();
BOOST_CHECK_EQUAL(params.DeploymentHeight(Consensus::DEPLOYMENT_TAPROOT), 21168000);
BOOST_CHECK_EQUAL(params.DeploymentHeight(Consensus::DEPLOYMENT_DIGIDOLLAR), 23869440);
BOOST_CHECK_EQUAL(params.DeploymentHeight(Consensus::DEPLOYMENT_ALGOLOCK), 23869440);
// Burial heights sit on 40,320-block confirmation-window boundaries
// (BIP9 ACTIVE always begins at a period boundary).
BOOST_CHECK_EQUAL(params.DeploymentHeight(Consensus::DEPLOYMENT_TAPROOT) % params.nMinerConfirmationWindow, 0U);
BOOST_CHECK_EQUAL(params.DeploymentHeight(Consensus::DEPLOYMENT_DIGIDOLLAR) % params.nMinerConfirmationWindow, 0U);
// The static DD/oracle floor gates keep their pre-burial values: they are
// floors *below* the actual activation, and moving them would change
// historical oracle-P2P / prune-floor behavior.
BOOST_CHECK_EQUAL(params.nDDActivationHeight, 23627520);
BOOST_CHECK_EQUAL(params.nOracleActivationHeight, 23627520);
BOOST_CHECK_EQUAL(params.nDigiDollarMuSig2Height, 23627520);
BOOST_CHECK(params.nDDActivationHeight <= params.DeploymentHeight(Consensus::DEPLOYMENT_DIGIDOLLAR));
// EarliestActivationFloor is value-preserving: min(floor, burial) == floor.
BOOST_CHECK_EQUAL(DigiDollar::EarliestActivationFloor(params), 23627520);
// Warning floor covers the historical bit-2/23/0 signaling periods:
// burial height + one confirmation window.
BOOST_CHECK_EQUAL(params.MinBIP9WarningHeight,
params.DeploymentHeight(Consensus::DEPLOYMENT_DIGIDOLLAR) + static_cast<int>(params.nMinerConfirmationWindow));
// AlgoLock: the static Groestl backstop precedes the buried activation, so
// the OR'd enforcement predicate is unchanged at every mainnet height.
BOOST_CHECK(params.nGroestlDeactivationHeight <= params.DeploymentHeight(Consensus::DEPLOYMENT_ALGOLOCK));
BOOST_CHECK_EQUAL(params.nGroestlDeactivationHeight, 23808000);
}
BOOST_AUTO_TEST_CASE(testnet_burial_heights)
{
SelectParams(ChainType::TESTNET);
const auto& params = Params().GetConsensus();
BOOST_CHECK_EQUAL(params.DeploymentHeight(Consensus::DEPLOYMENT_TAPROOT), 0);
BOOST_CHECK_EQUAL(params.DeploymentHeight(Consensus::DEPLOYMENT_DIGIDOLLAR), 600);
BOOST_CHECK_EQUAL(params.DeploymentHeight(Consensus::DEPLOYMENT_ALGOLOCK), 0);
// On testnet26 the floor equals the burial height (lock-in happened in the
// earliest possible window), so everything stays collapsed onto 600.
BOOST_CHECK_EQUAL(params.nDDActivationHeight, 600);
BOOST_CHECK_EQUAL(params.nOracleActivationHeight, 600);
BOOST_CHECK_EQUAL(params.nDigiDollarMuSig2Height, 600);
BOOST_CHECK_EQUAL(DigiDollar::EarliestActivationFloor(params), 600);
BOOST_CHECK_EQUAL(params.MinBIP9WarningHeight, 600 + static_cast<int>(params.nMinerConfirmationWindow));
}
BOOST_AUTO_TEST_CASE(regtest_burial_defaults)
{
SelectParams(ChainType::REGTEST);
const auto& params = Params().GetConsensus();
// Buried at 0 == the old BIP9 ALWAYS_ACTIVE: active from genesis.
BOOST_CHECK_EQUAL(params.DeploymentHeight(Consensus::DEPLOYMENT_TAPROOT), 0);
BOOST_CHECK_EQUAL(params.DeploymentHeight(Consensus::DEPLOYMENT_DIGIDOLLAR), 0);
BOOST_CHECK_EQUAL(params.DeploymentHeight(Consensus::DEPLOYMENT_ALGOLOCK), 0);
// The intentional regtest asymmetry survives burial: deployment active
// from genesis while the static P2P/oracle height gates stay at 650.
BOOST_CHECK_EQUAL(params.nDDActivationHeight, 650);
BOOST_CHECK_EQUAL(params.nOracleActivationHeight, 650);
BOOST_CHECK_EQUAL(params.nDigiDollarMuSig2Height, 0);
BOOST_CHECK_EQUAL(DigiDollar::EarliestActivationFloor(params), 0);
// Genesis edge: null pprev means "next block is height 0", which is
// active for a buried height of 0 — matching old ALWAYS_ACTIVE behavior.
BOOST_CHECK(DigiDollar::IsDigiDollarEnabled(nullptr, params));
}
BOOST_AUTO_TEST_CASE(regtest_digidollaractivationheight_knob_moves_everything)
{
CChainParams::RegTestOptions opts;
opts.digidollar_activation_height = 432;
const auto chainparams = CChainParams::RegTest(opts);
const auto& params = chainparams->GetConsensus();
// The knob retargets the buried deployment height AND the static gates,
// preserving the pre-burial "everything activates together" contract —
// except activation now lands at exactly N instead of the next 144-block
// BIP9 window boundary >= max(432, N).
BOOST_CHECK_EQUAL(params.DeploymentHeight(Consensus::DEPLOYMENT_DIGIDOLLAR), 432);
BOOST_CHECK_EQUAL(params.nDDActivationHeight, 432);
BOOST_CHECK_EQUAL(params.nOracleActivationHeight, 432);
BOOST_CHECK_EQUAL(params.nDigiDollarMuSig2Height, 432);
BOOST_CHECK_EQUAL(DigiDollar::EarliestActivationFloor(params), 432);
}
BOOST_AUTO_TEST_CASE(regtest_testactivationheight_moves_only_deployment)
{
CChainParams::RegTestOptions opts;
opts.activation_heights[Consensus::BuriedDeployment::DEPLOYMENT_DIGIDOLLAR] = 999;
const auto chainparams = CChainParams::RegTest(opts);
const auto& params = chainparams->GetConsensus();
// -testactivationheight=digidollar@H moves ONLY the buried deployment
// height; the static gates keep their 650 defaults. This preserves the
// "BIP9-inactive while height gates open" split that wave20 exercises.
BOOST_CHECK_EQUAL(params.DeploymentHeight(Consensus::DEPLOYMENT_DIGIDOLLAR), 999);
BOOST_CHECK_EQUAL(params.nDDActivationHeight, 650);
BOOST_CHECK_EQUAL(params.nOracleActivationHeight, 650);
BOOST_CHECK_EQUAL(params.nDigiDollarMuSig2Height, 650); // min(650, 999)
BOOST_CHECK_EQUAL(DigiDollar::EarliestActivationFloor(params), 650); // min(650, 999)
}
BOOST_AUTO_TEST_CASE(regtest_knob_takes_precedence_over_testactivationheight)
{
CChainParams::RegTestOptions opts;
opts.activation_heights[Consensus::BuriedDeployment::DEPLOYMENT_DIGIDOLLAR] = 999;
opts.digidollar_activation_height = 432;
const auto chainparams = CChainParams::RegTest(opts);
const auto& params = chainparams->GetConsensus();
BOOST_CHECK_EQUAL(params.DeploymentHeight(Consensus::DEPLOYMENT_DIGIDOLLAR), 432);
BOOST_CHECK_EQUAL(params.nDDActivationHeight, 432);
}
BOOST_AUTO_TEST_CASE(buried_gate_flips_exactly_at_height)
{
CChainParams::RegTestOptions opts;
opts.digidollar_activation_height = 432;
const auto chainparams = CChainParams::RegTest(opts);
const auto& params = chainparams->GetConsensus();
// IsDigiDollarEnabled(pindexPrev) judges the block AFTER pindexPrev.
CBlockIndex prev_431; // next block is 432 -> first active block
prev_431.nHeight = 431;
CBlockIndex prev_430; // next block is 431 -> last inactive block
prev_430.nHeight = 430;
BOOST_CHECK(!DigiDollar::IsDigiDollarEnabled(&prev_430, params));
BOOST_CHECK(DigiDollar::IsDigiDollarEnabled(&prev_431, params));
// Buried DeploymentActiveAt agrees: block 431 inactive, block 432 active.
// (The VersionBitsCache parameter is [[maybe_unused]] for buried
// deployments — no cache is ever consulted.)
VersionBitsCache dummy_cache;
CBlockIndex block_432;
block_432.nHeight = 432;
CBlockIndex block_431;
block_431.nHeight = 431;
BOOST_CHECK(!DeploymentActiveAt(block_431, params, Consensus::DEPLOYMENT_DIGIDOLLAR, dummy_cache));
BOOST_CHECK(DeploymentActiveAt(block_432, params, Consensus::DEPLOYMENT_DIGIDOLLAR, dummy_cache));
}
BOOST_AUTO_TEST_CASE(disabled_deployment_semantics)
{
CChainParams::RegTestOptions opts;
opts.activation_heights[Consensus::BuriedDeployment::DEPLOYMENT_DIGIDOLLAR] =
std::numeric_limits<int>::max();
const auto chainparams = CChainParams::RegTest(opts);
const auto& params = chainparams->GetConsensus();
// Height == int max is the buried representation of "disabled": the
// deployment reports disabled and the activation floor collapses to 0
// (no prune lock), matching the old NEVER_ACTIVE contract.
BOOST_CHECK(!DeploymentEnabled(params, Consensus::DEPLOYMENT_DIGIDOLLAR));
BOOST_CHECK_EQUAL(DigiDollar::EarliestActivationFloor(params), 0);
CBlockIndex prev;
prev.nHeight = 1000000;
BOOST_CHECK(!DigiDollar::IsDigiDollarEnabled(&prev, params));
}
BOOST_AUTO_TEST_CASE(deployment_names_round_trip)
{
BOOST_CHECK(Consensus::ValidDeployment(Consensus::DEPLOYMENT_ALGOLOCK));
BOOST_CHECK_EQUAL(DeploymentName(Consensus::DEPLOYMENT_TAPROOT), "taproot");
BOOST_CHECK_EQUAL(DeploymentName(Consensus::DEPLOYMENT_DIGIDOLLAR), "digidollar");
BOOST_CHECK_EQUAL(DeploymentName(Consensus::DEPLOYMENT_ALGOLOCK), "algolock");
BOOST_CHECK(GetBuriedDeployment("taproot") == Consensus::BuriedDeployment::DEPLOYMENT_TAPROOT);
BOOST_CHECK(GetBuriedDeployment("digidollar") == Consensus::BuriedDeployment::DEPLOYMENT_DIGIDOLLAR);
BOOST_CHECK(GetBuriedDeployment("algolock") == Consensus::BuriedDeployment::DEPLOYMENT_ALGOLOCK);
BOOST_CHECK(!GetBuriedDeployment("digidollarx").has_value());
}
BOOST_AUTO_TEST_SUITE_END()