Skip to content

Conversation

@kwvg
Copy link
Collaborator

@kwvg kwvg commented Apr 18, 2024

Motivation

Since #5940, CActiveMasternodeManager ceased to be a global variable and became a conditional smart pointer initialized based on the value of fMasternodeMode.

Likewise, since #5555, we can tell if any CFlatDB-based manager has successfully loaded its database. CGovernanceManager is one of them and conditionally loads its database based on the value of fGovernanceDisabled.

fMasternodeMode and fGovernanceDisabled were (and the former to a certain degree still is) unavoidable globals due to the way the functionality they influenced was structured (i.e. decided in initialization code with no way to query from the manager itself). As we can directly ask the managers now, we can start reducing the usage of these globals and at least in this PR, get rid of one of them.

This PR was the idea of PastaPastaPasta, special thanks for the suggestion!

Additional Information

  • There are two conventions being used for checking nullptr-ity of a pointer, if (mn_activeman) and if (mn_activeman != nullptr). The former is used in initialization and RPC code due to existing conventions there (source, source, source). The latter is used whenever the value has to be passed as a bool (you cannot pass the implicit conversion to a bool argument without explicitly casting it) and in Dash-specific code where it is the prevalent convention (source, source).

    Unfortunately, that means this PR expresses the same thing sometimes in two different ways but this approach was taken so that reading is consistent within the same file. Codebase-wide harmonization is outside the scope of this PR.

  • Where mn_activeman isn't directly available, the result of the check is passed as an argument named is_masternode and/or set for the manager during its construction as m_is_masternode (const bool) as it is expected for the CActiveMasternodeManager's presence or absence to remain as-is for the duration of the manager's lifetime.

    This does mean that some parts of the codebase check for mn_activeman while others check for {m_}is_masternode, which does reduce clarity while reading. Suggestions on improving this are welcomed.

  • One of the reasons this PR was made was to avoid having to deal the possibility of fMasternodeMode or fDisableGovernance from desynchronizing from the behaviour of the managers it's suppose to influence. It's why additional assertions were placed in to make sure that fMasternodeMode and the existence of mn_activeman were always in sync (source, source).

    But removing the tracking global and relying on a manager's state itself prevents a potential desync, which is what this PR is aiming to do.

Breaking Changes

None expected.

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have made corresponding changes to the documentation (note: N/A)
  • I have assigned this pull request to a milestone (for repository code-owners and collaborators only)

@github-actions
Copy link

This pull request has conflicts, please rebase.

kwvg added 5 commits April 24, 2024 18:42
CActiveMasternodeManager no longer exists as a global variable, it is a
conditionally initialized smart pointer. If it exists, then it's in masternode
mode, no need to check if we're in masternode mode anymore.
kwvg and others added 5 commits April 25, 2024 10:04
Co-authored-by: Konstantin Akimov <knstqq@gmail.com>
CGovernanceManager::IsValid() returns true only if its db is successfully
initialized. If we attempt to initialize it and fail, init logic will
report to us that it failed. If we don't attempt to initialize it at all,
it will remain false.

Since fDisableGovernance is the same as not initializing it at all and
the other case where IsValid() is false is dealt with in init, we can
use IsValid() to infer if governance is enabled.
Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
@kwvg kwvg requested review from UdjinM6 and knst April 25, 2024 11:44
Copy link
Collaborator

@knst knst left a comment

Choose a reason for hiding this comment

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

LGTM b4477e4

Copy link

@UdjinM6 UdjinM6 left a comment

Choose a reason for hiding this comment

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

utACK

Copy link
Member

@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.

utACK

@PastaPastaPasta PastaPastaPasta merged commit f9e123e into dashpay:develop Apr 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants