-
Notifications
You must be signed in to change notification settings - Fork 675
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
base: master
Are you sure you want to change the base?
Conversation
Signed-off-by: Ceyhun Onur <[email protected]>
…go into add-l1-validators-api
|
||
func (s *Service) getL1Validators(subnetID ids.ID, nodeIDs set.Set[ids.NodeID]) ([]interface{}, error) { | ||
validators := []interface{}{} | ||
baseStakers, l1Validators, _, err := s.vm.state.GetCurrentValidators(subnetID) |
There was a problem hiding this comment.
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{ |
There was a problem hiding this comment.
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), |
There was a problem hiding this comment.
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(), |
There was a problem hiding this comment.
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{ |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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?
Why this should be merged
It adds L1 support and shows L1 validators in
platform.getCurrentValidators
API.How this works
validationID
to theplatform.getL1Validator
API outputs.platform.getCurrentValidators
API.PermissionedValidator
struct as it is no longer used.getL1Validators
andgetPrimaryOrSubnetValidators
methods to handle fetching validators based on subnet ID.convertL1ValidatorToAPI
method to convert L1 validator data to API format.GetL1Validators
method to theState
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.