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

add L1 support to getCurrentValidators API #3564

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

ceyonur
Copy link
Contributor

@ceyonur ceyonur commented Nov 21, 2024

Why this should be merged

It adds L1 support and shows L1 validators in platform.getCurrentValidators API.

How this works

  • Added validationID to the platform.getL1Validator API outputs.
  • Added L1 support to the platform.getCurrentValidators API.
  • Removed the PermissionedValidator struct as it is no longer used.
  • Introduced getL1Validators and getPrimaryOrSubnetValidators methods to handle fetching validators based on subnet ID.
  • Added convertL1ValidatorToAPI method to convert L1 validator data to API format.
  • Added GetL1Validators method to the State interface to return both base stakers and L1 validators in a converted L1.

How this was tested

Locally

Need to be documented in RELEASES.md?

Yes, updated.

@ceyonur ceyonur self-assigned this Nov 21, 2024

func (s *Service) getL1Validators(subnetID ids.ID, nodeIDs set.Set[ids.NodeID]) ([]interface{}, error) {
validators := []interface{}{}
baseStakers, l1Validators, _, err := s.vm.state.GetCurrentValidators(subnetID)
Copy link
Contributor

Choose a reason for hiding this comment

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

(No action required) The docstring for GetCurrentValidators refers to the stakers returned as 'legacy stakers'. What does that imply in the context of an L1?

continue
}
weight := avajson.Uint64(staker.Weight)
apiStaker := platformapi.Staker{
Copy link
Contributor

Choose a reason for hiding this comment

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

(No action required) It appears that that conversion of state.Staker to platformapi.Staker` is defined twice in this file. Maybe avoid this duplication?

Also - and not for this PR - the need to perform this conversion seems a bit strange. Presumably there is room to unify these types?

@@ -2130,7 +2130,7 @@ func TestGetCurrentValidators(t *testing.T) {
NodeID: ids.GenerateTestNodeID(),
PublicKey: otherPK,
Weight: 1,
StartTime: now,
StartTime: now.Add(1 * time.Second),
Copy link
Contributor

Choose a reason for hiding this comment

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

(No action required) Why does the start time change in these tests?

name: "initial stakers",
initial: []*state.Staker{
{
TxID: ids.GenerateTestID(),
Copy link
Contributor

Choose a reason for hiding this comment

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

(No action required) Given that the following fields are initialized the same way for current tests, maybe move their initialization to the test body to ensure that only relevant fields need be maintained for each test case?

  • Staker.TxID
  • L1Validator.ValidationID
  • *.SubnetID
  • *.NodeID

},
}

remaningBalanceOwner := message.PChainOwner{
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: s/remaning/remaining/


require.NoError(service.vm.state.PutL1Validator(l1Validator))

if l1Validator.Weight == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

(No action required) Why it it desirable to call PutL1Validator with zero weight but not add to l1ValidatorsByVID?

service.vm.ctx.Lock.Unlock()

testValidator := func(vdr interface{}) ids.NodeID {
switch v := vdr.(type) {
Copy link
Contributor

Choose a reason for hiding this comment

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

(No action required) Not for this PR, but maybe these types would benefit from an equality method to simplify this kind of testing?

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.

2 participants