Files
node/vms/platformvm/client_permissionless_validator.go
zeekay 7cf87b230b node-unified is the node
The module already called itself github.com/luxfi/node while containing no node
in Go: cmd/luxd was twenty-one lines that printed the size of a few types, and
the Go column of the matrix measured a VM plugin. A repo that fetches the thing
it claims to be has not replaced it, so the Go sources move in — 1515 files,
the daemon and everything under it — and the build reaches outside this module
for nothing.

Rust and C++ sit beside it unchanged and are still measured against it by the
differential. That is the point of one repo: the reference implementation and
the two ports are the same checkout, so parity is a thing you can run rather
than a thing you assert.

Verified: builds, and the closure carries no lux-private — checked at build time
rather than believed. The daemon starts twelve chains on a local network
(P X C Q Z A B G K M F, plus D through its plugin) and reports healthy.
2026-09-07 16:15:25 -07:00

182 lines
5.6 KiB
Go

// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package platformvm
import (
"github.com/luxfi/address"
"github.com/luxfi/ids"
"github.com/luxfi/node/vms/platformvm/api"
"github.com/luxfi/node/vms/platformvm/signer"
)
// ClientStaker is the representation of a staker sent via client.
type ClientStaker struct {
// the txID of the transaction that added this staker.
TxID ids.ID
// the Unix time when they start staking
StartTime uint64
// the Unix time when they are done staking
EndTime uint64
// the validator weight when sampling validators
Weight uint64
// the node ID of the staker
NodeID ids.NodeID
}
// ClientOwner is the repr. of a reward owner sent over client
type ClientOwner struct {
Locktime uint64
Threshold uint32
Addresses []ids.ShortID
}
type ClientL1Validator struct {
ValidationID *ids.ID
RemainingBalanceOwner *ClientOwner
DeactivationOwner *ClientOwner
MinNonce *uint64
Balance *uint64
}
// ClientPermissionlessValidator is the repr. of a permissionless validator sent
// over client
type ClientPermissionlessValidator struct {
ClientStaker
ClientL1Validator
ValidationRewardOwner *ClientOwner
DelegationRewardOwner *ClientOwner
PotentialReward *uint64
AccruedDelegateeReward *uint64
DelegationFee float32
// Uptime is deprecated for Net Validators.
// It will be available only for Primary Network Validators.
Uptime *float32
// Connected is deprecated for Net Validators.
// It will be available only for Primary Network Validators.
Connected *bool
Signer *signer.ProofOfPossession
// The delegators delegating to this validator
DelegatorCount *uint64
DelegatorWeight *uint64
Delegators []ClientDelegator
}
// ClientDelegator is the repr. of a delegator sent over client
type ClientDelegator struct {
ClientStaker
RewardOwner *ClientOwner
PotentialReward *uint64
}
func apiStakerToClientStaker(validator api.Staker) ClientStaker {
return ClientStaker{
TxID: validator.TxID,
StartTime: uint64(validator.StartTime),
EndTime: uint64(validator.EndTime),
Weight: uint64(validator.Weight),
NodeID: validator.NodeID,
}
}
func apiOwnerToClientOwner(rewardOwner *api.Owner) (*ClientOwner, error) {
if rewardOwner == nil {
return nil, nil
}
addrs, err := address.ParseToIDs(rewardOwner.Addresses)
return &ClientOwner{
Locktime: uint64(rewardOwner.Locktime),
Threshold: uint32(rewardOwner.Threshold),
Addresses: addrs,
}, err
}
func getClientPermissionlessValidators(current []CurrentValidator) ([]ClientPermissionlessValidator, error) {
clientValidators := make([]ClientPermissionlessValidator, len(current))
for i, entry := range current {
apiValidator := entry.staker()
clientValidator, err := getClientPrimaryOrNetValidator(apiValidator)
if err != nil {
return nil, err
}
// If the validator is a L1 validator, we need to set the L1 fields as well
if apiValidator.ValidationID != nil {
l1Validator, err := getClientL1Validator(apiValidator)
if err != nil {
return nil, err
}
clientValidator.ClientL1Validator = l1Validator
}
clientValidators[i] = clientValidator
}
return clientValidators, nil
}
func getClientL1Validator(apiValidator api.PermissionlessValidator) (ClientL1Validator, error) {
remainingBalanceOwner, err := apiOwnerToClientOwner(apiValidator.RemainingBalanceOwner)
if err != nil {
return ClientL1Validator{}, err
}
deactivationOwner, err := apiOwnerToClientOwner(apiValidator.DeactivationOwner)
if err != nil {
return ClientL1Validator{}, err
}
return ClientL1Validator{
ValidationID: apiValidator.ValidationID,
RemainingBalanceOwner: remainingBalanceOwner,
DeactivationOwner: deactivationOwner,
MinNonce: (*uint64)(apiValidator.MinNonce),
Balance: (*uint64)(apiValidator.Balance),
}, nil
}
func getClientPrimaryOrNetValidator(apiValidator api.PermissionlessValidator) (ClientPermissionlessValidator, error) {
validationRewardOwner, err := apiOwnerToClientOwner(apiValidator.ValidationRewardOwner)
if err != nil {
return ClientPermissionlessValidator{}, err
}
delegationRewardOwner, err := apiOwnerToClientOwner(apiValidator.DelegationRewardOwner)
if err != nil {
return ClientPermissionlessValidator{}, err
}
var clientDelegators []ClientDelegator
if apiValidator.Delegators != nil {
clientDelegators = make([]ClientDelegator, len(*apiValidator.Delegators))
for j, apiDelegator := range *apiValidator.Delegators {
rewardOwner, err := apiOwnerToClientOwner(apiDelegator.RewardOwner)
if err != nil {
return ClientPermissionlessValidator{}, err
}
clientDelegators[j] = ClientDelegator{
ClientStaker: apiStakerToClientStaker(apiDelegator.Staker),
RewardOwner: rewardOwner,
PotentialReward: (*uint64)(apiDelegator.PotentialReward),
}
}
}
return ClientPermissionlessValidator{
ClientStaker: apiStakerToClientStaker(apiValidator.Staker),
ValidationRewardOwner: validationRewardOwner,
DelegationRewardOwner: delegationRewardOwner,
PotentialReward: (*uint64)(apiValidator.PotentialReward),
AccruedDelegateeReward: (*uint64)(apiValidator.AccruedDelegateeReward),
DelegationFee: float32(apiValidator.DelegationFee),
Uptime: (*float32)(apiValidator.Uptime),
Connected: apiValidator.Connected,
Signer: apiValidator.Signer,
DelegatorCount: (*uint64)(apiValidator.DelegatorCount),
DelegatorWeight: (*uint64)(apiValidator.DelegatorWeight),
Delegators: clientDelegators,
}, nil
}