A Validator in the Züs network plays a critical role in ensuring the correctness and integrity of transactions, storage operations, and smart contract executions.
Validators verify operations and help maintain consensus within the blockchain ecosystem. They participate in staking mechanisms and earn rewards based on their contributions.
Validator Structure
The Validator structure defines key attributes associated with a validator node in the network.
Copy // Validator represents validator information.
type Validator struct {
ID common.Key `json:"validator_id"`
BaseURL string `json:"url"`
PublicKey string `json:"-"`
DelegateWallet string `json:"delegate_wallet"`
MinStake common.Balance `json:"min_stake"`
MaxStake common.Balance `json:"max_stake"`
NumDelegates int `json:"num_delegates"`
ServiceCharge float64 `json:"service_charge"`
StakeTotal int64 `json:"stake_total"`
TotalServiceCharge int64 `json:"total_service_charge"`
UncollectedServiceCharge int64 `json:"uncollected_service_charge"`
LastHealthCheck common.Timestamp `json:"last_health_check"`
IsKilled bool `json:"is_killed"`
IsShutdown bool `json:"is_shutdown"`
}
Attributes
ID : Unique identifier for the validator.
BaseURL : The URL through which the validator communicates with the network.
PublicKey : The public key associated with the validator.
DelegateWallet : The wallet address associated with the validator for staking and rewards.
MinStake : Minimum stake required for participation in validation.
MaxStake : Maximum stake allowed for a validator.
NumDelegates : The number of delegates that can stake on this validator.
ServiceCharge : Percentage of rewards charged by the validator as a service fee.
StakeTotal : Total amount staked on the validator.
TotalServiceCharge : Total service charge collected over time.
UncollectedServiceCharge : Pending service charges yet to be collected.
LastHealthCheck : Timestamp of the last health check performed on the validator.
IsKilled : Indicates if the validator is terminated.
IsShutdown : Indicates if the validator is currently shut down.
Updating Validator Settings
Validators can update their settings using the UpdateValidator
structure:
Copy // UpdateValidator is used during update validator settings calls.
type UpdateValidator struct {
ID common.Key `json:"validator_id"`
BaseURL *string `json:"url,omitempty"`
DelegateWallet *string `json:"delegate_wallet,omitempty"`
MinStake *common.Balance `json:"min_stake,omitempty"`
MaxStake *common.Balance `json:"max_stake,omitempty"`
NumDelegates *int `json:"num_delegates,omitempty"`
ServiceCharge *float64 `json:"service_charge,omitempty"`
StakeTotal *int64 `json:"stake_total,omitempty"`
TotalServiceCharge *int64 `json:"total_service_charge,omitempty"`
UncollectedServiceCharge *int64 `json:"uncollected_service_charge,omitempty"`
LastHealthCheck *common.Timestamp `json:"last_health_check,omitempty"`
IsKilled *bool `json:"is_killed,omitempty"`
IsShutdown *bool `json:"is_shutdown,omitempty"`
}
Converting UpdateValidator to Blockchain Validation Node
To apply updates to the blockchain, the UpdateValidator
struct must be converted to a blockchain-compatible format:
Copy func (v *UpdateValidator) ConvertToValidationNode() *blockchain.UpdateValidationNode {
blockValidator := &blockchain.UpdateValidationNode{
ID: string(v.ID),
BaseURL: v.BaseURL,
}
sp := &blockchain.UpdateStakePoolSettings{
DelegateWallet: v.DelegateWallet,
NumDelegates: v.NumDelegates,
ServiceCharge: v.ServiceCharge,
}
if v.DelegateWallet != nil ||
v.MinStake != nil ||
v.MaxStake != nil ||
v.NumDelegates != nil ||
v.ServiceCharge != nil {
blockValidator.StakePoolSettings = sp
}
return blockValidator
}
Retrieving Validator Information
Get a Single Validator
To retrieve information about a specific validator, use the GetValidator
function:
Copy func GetValidator(validatorID string) (validator *Validator, err error) {
if !client.IsSDKInitialized() {
return nil, sdkNotInitialized
}
var b []byte
b, err = screstapi.MakeSCRestAPICall(
STORAGE_SCADDRESS,
"/get_validator",
map[string]string{"validator_id": validatorID},
)
if err != nil {
return nil, errors.Wrap(err, "requesting validator:")
}
if len(b) == 0 {
return nil, errors.New("", "empty response from sharders")
}
validator = new(Validator)
if err = json.Unmarshal(b, validator); err != nil {
return nil, errors.Wrap(err, "decoding response:")
}
return
}
Get a List of Validators
To retrieve a list of validators in the network, use:
Copy func GetValidators(stakable bool) (validators []*Validator, err error) {
if !client.IsSDKInitialized() {
return nil, sdkNotInitialized
}
var b []byte
b, err = screstapi.MakeSCRestAPICall(
STORAGE_SCADDRESS,
"/validators",
map[string]string{
"stakable": strconv.FormatBool(stakable),
},
)
if err != nil {
return nil, errors.Wrap(err, "requesting validator list")
}
if len(b) == 0 {
return nil, errors.New("", "empty response from sharders")
}
if err = json.Unmarshal(b, &validators); err != nil {
return nil, errors.Wrap(err, "decoding response:")
}
return
}
Managing Validators
Update Validator Settings
Copy func UpdateValidatorSettings(v *UpdateValidator) (resp string, nonce int64, err error) {
if !client.IsSDKInitialized() {
return "", 0, sdkNotInitialized
}
var sn = transaction.SmartContractTxnData{
Name: transaction.STORAGESC_UPDATE_VALIDATOR_SETTINGS,
InputArgs: v.ConvertToValidationNode(),
}
resp, _, nonce, _, err = storageSmartContractTxn(sn)
return
}
Shutdown a Validator
Copy func ShutdownProvider(providerType ProviderType, providerID string) (string, int64, error) {
if !client.IsSDKInitialized() {
return "", 0, sdkNotInitialized
}
var input = map[string]string{
"provider_id": providerID,
}
var sn = transaction.SmartContractTxnData{
InputArgs: input,
}
switch providerType {
case ProviderValidator:
sn.Name = transaction.STORAGESC_SHUTDOWN_VALIDATOR
default:
return "", 0, fmt.Errorf("shutdown provider type %v not implemented", providerType)
}
hash, _, n, _, err := storageSmartContractTxn(sn)
return hash, n, err
}
Validators are integral to the Züs network, ensuring transaction integrity, maintaining consensus, and securing the blockchain. Properly managing validators, staking, and rewards distribution is crucial for a healthy decentralized ecosystem.