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

Split writeCurrentStakers into multiple functions #3500

Open
wants to merge 2 commits into
base: implement-acp-77-add-subnetid-nodeid
Choose a base branch
from

Conversation

StephenButtolph
Copy link
Contributor

@StephenButtolph StephenButtolph commented Oct 26, 2024

Why this should be merged

writeCurrentStakers is extremely complex as it is doing 3 things:

  1. Writing weight and public key diffs
  2. Updating the in-memory validator manager
  3. Updating the on-disk representation of the validator sets.

As we implement ACP-77:

  1. Writing weight and public key diffs

and

  1. Updating the in-memory validator manager

become more complex, as it is possible that the same subnetID + nodeID pair are removed from the pre-ACP-77 validator sets and added to the post-ACP-77 validator sets.

To avoid writeCurrentStakers from including ACP-77 validators as well (making one of the most complex functions even more complex), this PR moves the functionality into separate functions.

How this works

Moves code around and implements helper functions where possible.

How this was tested

Existing tests.

Need to be documented in RELEASES.md?

There are no user facing changes.

Copy link
Contributor Author

@StephenButtolph StephenButtolph left a comment

Choose a reason for hiding this comment

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

There are no testing changes because this is a pure refactor.

@@ -273,6 +274,34 @@ type diffValidator struct {
deletedDelegators map[ids.ID]*Staker
}

func (d *diffValidator) WeightDiff() (ValidatorWeightDiff, error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was previously implemented in writeCurrentStakersSubnetDiff.

//
// Note: This function may return a nil public key and no error if the primary
// network validator does not have a public key.
func (s *state) getInheritedPublicKey(nodeID ids.NodeID) (*bls.PublicKey, error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This logic previously existed as part of writeCurrentStakersSubnetDiff.

Comment on lines +1797 to +1799
s.updateValidatorManager(updateValidators),
s.writeValidatorDiffs(height),
s.writeCurrentStakers(codecVersion),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

While splitting these out is technically less efficient (and contains similar code). The functions were just getting too complex to understand. This is explicitly trading off some (imo insignificant) level of performance for clarity.

@StephenButtolph StephenButtolph self-assigned this Oct 27, 2024
@StephenButtolph StephenButtolph added this to the v1.11.13 milestone Oct 27, 2024
@StephenButtolph StephenButtolph marked this pull request as ready for review October 27, 2024 18:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: In Review 👀
Development

Successfully merging this pull request may close these issues.

1 participant