Skip to content

Conversation

ajtowns
Copy link
Contributor

@ajtowns ajtowns commented Jan 11, 2022

Adds default values for vDeployments in consensus/params.h so that undefined behaviour is avoided if a deployment is not initialized. Also adds a check in the unit tests to alert if this is happening, since even if it doesn't invoke undefined behaviour it's probably a mistake.

@ajtowns
Copy link
Contributor Author

ajtowns commented Jan 11, 2022

Something like this was previously proposed in #21401. Deployments have been left uninitialised in the past, see #20157 and also taproot activation in elements so this seems worth having the compiler check for doing something to avoid similar mistakes. I think it ends up pretty readable too.

@ajtowns ajtowns force-pushed the 202112-deployments branch from fb00b70 to 02bda4e Compare January 11, 2022 06:07
@DrahtBot
Copy link
Contributor

DrahtBot commented Jan 11, 2022

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

No conflicts as of last run.

Copy link
Contributor Author

@ajtowns ajtowns left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Went over this with @amitiuttarwar and noticed some things.

const T t;

template<typename... I>
ArrayInitElement(I... i) : t{i...} { };
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this potentially copies its arguments unnecessarily and would be better as ArrayInitElement(I&&... i) : t{std::forward<I>(i)...} { }. Also, no need for a semicolon.

{
static_assert(E < N, "too many initializers for array");
static_assert(E == O, "array initializer element is out of order");
if constexpr (E < N) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: this if constexpr is only here to avoid redundant warnings that std::get<N> and step<N+1> would generate.

@ajtowns ajtowns force-pushed the 202112-deployments branch from 6eaf3af to 08aa93b Compare January 13, 2022 04:02
Copy link
Contributor

@PastaPastaPasta PastaPastaPasta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strong concept ACK, I have a few suggestions / concerns

@JeremyRubin
Copy link
Contributor

Concept ACK

is there other ongoing work on deployment tech that is motivating this change? Or just good maitenance.

@ajtowns
Copy link
Contributor Author

ajtowns commented Jan 14, 2022

is there other ongoing work on deployment tech that is motivating this change? Or just good maitenance.

There were a bunch of clean ups that got dropped to get speedy trial done speedily; seems a good time to reconsider them now that versionbits logic isn't actively being used, and before we update to whatever might come after speedy trial. This seemed a good one to start with since it's caused bugs twice now.

@ajtowns ajtowns force-pushed the 202112-deployments branch from 08aa93b to 8bb515a Compare January 15, 2022 09:05
@PastaPastaPasta
Copy link
Contributor

Please see PastaPastaPasta@768a84f to constexpr all the things

@ajtowns ajtowns marked this pull request as draft January 28, 2022 06:35
@ajtowns
Copy link
Contributor Author

ajtowns commented Jan 28, 2022

Marked as draft, since both #23508 (simple, user-visible improvement) and #23536 (changes how consensus is enforced so annoying to re-test after rebase) should be merged first, in my opinion.

@ajtowns ajtowns force-pushed the 202112-deployments branch from 8bb515a to 22886c1 Compare January 28, 2022 08:16
@ajtowns
Copy link
Contributor Author

ajtowns commented Feb 17, 2022

Rebased. Removed that .at() change based on https://www.erisian.com.au/bitcoin-core-dev/log-2022-02-02.html#l-301 . Still in draft for #23536

@ajtowns ajtowns force-pushed the 202112-deployments branch from 3d3724e to e679415 Compare March 11, 2022 10:05
@ajtowns ajtowns marked this pull request as ready for review March 11, 2022 10:08
@ajtowns
Copy link
Contributor Author

ajtowns commented Mar 11, 2022

Removes all the template magic; and downgrades the "you forgot to initialize a deployment" check from compile-time to the unit tests, and doesn't convert to std::array. On the upside, this means this PR no longer conflicts with #23536.

Based on this week's meeting, also switches to using designated initializers. Doesn't do designated initializers because you seem to need to specify /std:c++latest instead of /std:c++17 for Visual Studio to support that.

@ajtowns ajtowns force-pushed the 202112-deployments branch from e679415 to 16cd0f4 Compare March 11, 2022 10:42
@ajtowns ajtowns changed the title Refactor vDeployments setup to avoid uninitialized variables Add defaults to vDeployments to avoid uninitialized variables Mar 11, 2022
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).
@ajtowns ajtowns force-pushed the 202112-deployments branch from 16cd0f4 to c4c5b9c Compare April 5, 2022 04:42
@laanwj
Copy link
Member

laanwj commented May 26, 2022

Code review ACK c4c5b9c

@laanwj laanwj merged commit c5e67be into bitcoin:master May 26, 2022
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request May 28, 2022
…zed variables

c4c5b9c consensus/params: set default values for BIP9Deployment (Anthony Towns)

Pull request description:

  Adds default values for `vDeployments` in `consensus/params.h` so that undefined behaviour is avoided if a deployment is not initialized. Also adds a check in the unit tests to alert if this is happening, since even if it doesn't invoke undefined behaviour it's probably a mistake.

ACKs for top commit:
  laanwj:
    Code review ACK c4c5b9c

Tree-SHA512: 22d7ff86a817d9e9e67c47301fc3b7e9d5821c13565d7706711f113dea220eea29b413a7c8d029691009159cebc85a108d77cb52418734091c196bafb2b12423
@bitcoin bitcoin locked and limited conversation to collaborators May 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants