Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor/feat: Refactor and add safety belts in llmq utils #5378

Merged
merged 2 commits into from
May 20, 2023

Conversation

UdjinM6
Copy link

@UdjinM6 UdjinM6 commented May 17, 2023

Issue being fixed or feature implemented

We use pQuorumBaseBlockIndex name when we shouldn't and we don't check that quorum types and block indexes provided as input params in llmq utils satisfy our requirements. This is kind of ok-ish as long as we use these functions appropriately but it's better to make things clearer and to have actual checks imo.

noticed this while reviewing #5366

What was done?

Rename pQuorumBaseBlockIndex to pCycleQuorumBaseBlockIndex/pindex in a few places. Check that quorum types and block indexes have expected values.

How Has This Been Tested?

run tests locally

Breaking Changes

n/a

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
  • I have assigned this pull request to a milestone (for repository code-owners and collaborators only)

@UdjinM6 UdjinM6 added this to the 20 milestone May 17, 2023
@UdjinM6 UdjinM6 changed the title chore: Refactor and add safety belts in llmq utils refactor/feat: Refactor and add safety belts in llmq utils May 17, 2023
@@ -65,6 +65,7 @@ void PreComputeQuorumMembers(const CBlockIndex* pindex, bool reset_cache)

uint256 GetHashModifier(const Consensus::LLMQParams& llmqParams, const CBlockIndex* pCycleQuorumBaseBlockIndex)
{
ASSERT_IF_DEBUG(pCycleQuorumBaseBlockIndex->nHeight % llmqParams.dkgInterval == 0);
Copy link
Member

Choose a reason for hiding this comment

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

I kinda wonder if we should create an "ASSUME" macro or something similar which if debug is enabled with act as an assert, but if not debug would print to log if the assumption was false? Idk, probably not the most useful

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.

light-utACK for squash merge... I do think it'd be better to have some way to tell which condition failed

@UdjinM6
Copy link
Author

UdjinM6 commented May 18, 2023

light-utACK for squash merge... I do think it'd be better to have some way to tell which condition failed

it fails like that (I broke GetHashModifier intentionally to illustrate it):

Assertion failure:
  assertion: (pCycleQuorumBaseBlockIndex->nHeight % llmqParams.dkgInterval == 1)
  file: utils.cpp, line: 68
  function: GetHashModifier

@UdjinM6 UdjinM6 requested a review from ogabrielides May 18, 2023 18:47
void PreComputeQuorumMembers(const CBlockIndex* pQuorumBaseBlockIndex, bool reset_cache = false);
uint256 GetHashModifier(const Consensus::LLMQParams& llmqParams, const CBlockIndex* pQuorumBaseBlockIndex);
void PreComputeQuorumMembers(const CBlockIndex* pindex, bool reset_cache = false);
uint256 GetHashModifier(const Consensus::LLMQParams& llmqParams, const CBlockIndex* pCycleQuorumBaseBlockIndex);
Copy link
Collaborator

Choose a reason for hiding this comment

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

My only "objection" is here. GetHashModifier is called for both non-rotated and rotated quorums, hence "cycle" is more adapted to rotation.

Copy link
Author

Choose a reason for hiding this comment

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

for non-rotation quorums pCycleQuorumBaseBlockIndex == pQuorumBaseBlockIndex and since using pQuorumBaseBlockIndex for rotation ones is wrong using pCycleQuorumBaseBlockIndex for both is a good compromise imo

Copy link
Collaborator

@ogabrielides ogabrielides left a comment

Choose a reason for hiding this comment

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

Besides above comment, LGTM

@UdjinM6 UdjinM6 merged commit 8bf40ea into dashpay:develop May 20, 2023
@UdjinM6 UdjinM6 deleted the refac_utils branch May 20, 2023 14:21
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.

3 participants