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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions vms/platformvm/state/stakers.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package state

import (
"errors"
"fmt"

"github.com/google/btree"

Expand Down Expand Up @@ -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.

weightDiff := ValidatorWeightDiff{
Decrease: d.validatorStatus == deleted,
}
if d.validatorStatus != unmodified {
weightDiff.Amount = d.validator.Weight
}

for _, staker := range d.deletedDelegators {
if err := weightDiff.Add(true, staker.Weight); err != nil {
return ValidatorWeightDiff{}, fmt.Errorf("failed to decrease node weight diff: %w", err)
}
}

addedDelegatorIterator := iterator.FromTree(d.addedDelegators)
defer addedDelegatorIterator.Release()

for addedDelegatorIterator.Next() {
staker := addedDelegatorIterator.Value()

if err := weightDiff.Add(false, staker.Weight); err != nil {
return ValidatorWeightDiff{}, fmt.Errorf("failed to increase node weight diff: %w", err)
}
}

return weightDiff, nil
}

// GetValidator attempts to fetch the validator with the given subnetID and
// nodeID.
// Invariant: Assumes that the validator will never be removed and then added.
Expand Down
Loading
Loading