Skip to content

add l1 support to getcurrentvalidators client response #3843

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

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

Conversation

ceyonur
Copy link
Contributor

@ceyonur ceyonur commented Mar 26, 2025

Why this should be merged

L1 Validators are not supported in client.GetCurrentValidators response. This PR adds ClientL1Validator to ClientPermissionlessValidator so that it can show L1 validators fields in the response.

How this works

This pull request includes several changes to the vms/platformvm package to enhance the representation and handling of L1 validators. The most important changes involve adding new types and refactoring existing ones to support the new L1 validator structure.

Enhancements to L1 Validator Representation:

  • Added APIL1Validator and BaseL1Validator types to represent L1 validators with additional fields such as PublicKey, RemainingBalanceOwner, DeactivationOwner, MinNonce, and Balance. (vms/platformvm/api/static_service.go)
  • Updated ClientL1Validator type to include fields for ValidationID, RemainingBalanceOwner, DeactivationOwner, MinNonce, and Balance. (vms/platformvm/client_permissionless_validator.go)

Refactoring and Code Simplification:

  • Refactored the GetL1Validator function to handle optional fields and convert them appropriately. (vms/platformvm/client.go) [1] [2]
  • Removed the deprecated RewardOwner field from PermissionlessValidator and replaced it with ValidationRewardOwner and DelegationRewardOwner. (vms/platformvm/api/static_service.go)

API and Service Updates:

  • Updated the convertL1ValidatorToAPI function to use the new platformapi.APIL1Validator type and handle the conversion of nested fields. (vms/platformvm/service.go)

How this was tested

Existing tests should cover the service changes. We dont have any client UT, locally tested it.

Need to be documented in RELEASES.md?

Updated

// [Endtime] is the Unix time repr. of when they are done staking
// [NodeID] is the node ID of the staker
// [Uptime] is the observed uptime of this staker
// [Weight] is the validator weight (stake) when sampling validators
type Staker struct {
TxID ids.ID `json:"txID"`
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TxID and EndTime will have zero values for L1 validators. I did not want to break any client implementation. If we think it's weird to show these for L1 validators I can set them to pointers. We can even break Staker into BaseStaker and Staker and move those fields there.

@ceyonur ceyonur changed the title add l1 support for getcurrentvalidators client response add l1 support to getcurrentvalidators client response Mar 26, 2025
Comment on lines +379 to +387
var minNonce uint64
if res.MinNonce != nil {
minNonce = uint64(*res.MinNonce)
}
var balance uint64
if res.Balance != nil {
balance = uint64(*res.Balance)
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason this wasn't also applied to the weight? I'm assuming you did this to check vars that are meant to change/be updated

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 is to ensure they're not nil before de-referencing. Weight is not a pointer here thus cannot be nil.

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, just curious] why is weight stored as a non-pointer?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Weight is common in all validator types (stakers vs l1 validators), so they will always be present in json. By using a pointer we can mark it them as being "nilable" in json representations. Otherwise they will be always shown with their zero values.

@meaghanfitzgerald
Copy link
Contributor

afaict this pr does not change the response object for getCurrentValidators, lgtm

Copy link

This PR has become stale because it has been open for 30 days with no activity. Adding the lifecycle/frozen label will cause this PR to ignore lifecycle events.

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