Skip to content

Commit c4c5b9c

Browse files
committed
consensus/params: set default values for BIP9Deployment
While chainparams should explicilty set values for each possible entry in vDeployments, in the past that has been missed resulting in potential undefined behaviour due to accessing unitinitialized data. Reduce the severity of future bugs of that nature by providing benign default values. Adds a unit test to alert if the default value is not overwritten for the real chains (NEVER_ACTIVE/NEVER_ACTIVE rather than NEVER_ACTIVE/NO_TIMEOUT).
1 parent 47bac47 commit c4c5b9c

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/consensus/params.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ constexpr bool ValidDeployment(DeploymentPos dep) { return dep < MAX_VERSION_BIT
4040
*/
4141
struct BIP9Deployment {
4242
/** Bit position to select the particular bit in nVersion. */
43-
int bit;
43+
int bit{28};
4444
/** Start MedianTime for version bits miner confirmation. Can be a date in the past */
45-
int64_t nStartTime;
45+
int64_t nStartTime{NEVER_ACTIVE};
4646
/** Timeout/expiry MedianTime for the deployment attempt. */
47-
int64_t nTimeout;
47+
int64_t nTimeout{NEVER_ACTIVE};
4848
/** If lock in occurs, delay activation until at least this block
4949
* height. Note that activation will only occur on a retarget
5050
* boundary.

src/test/versionbits_tests.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@ static void check_computeblockversion(const Consensus::Params& params, Consensus
275275
nStartTime == Consensus::BIP9Deployment::NEVER_ACTIVE)
276276
{
277277
BOOST_CHECK_EQUAL(min_activation_height, 0);
278+
BOOST_CHECK_EQUAL(nTimeout, Consensus::BIP9Deployment::NO_TIMEOUT);
278279
return;
279280
}
280281

0 commit comments

Comments
 (0)