Skip to content Search Apps Documentation Source Content File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

validators.gno

2.11 Kb · 69 lines
 1// Package validators implements on-chain validator set management
 2// through Proof of Authority. The realm exposes a public proposal
 3// constructor for GovDAO; on approval, the proposal callback applies
 4// the captured deltas to the chain's effective valset and publishes
 5// the new full set via gno.land/r/sys/params. The chain's EndBlocker
 6// reads the result on the next block and propagates to consensus.
 7//
 8// No in-realm validator state. All reads go through
 9// sysparams.GetValsetEffective (proposed-if-dirty, else current).
10package validators
11
12import (
13	"chain/runtime"
14	"strings"
15
16	"gno.land/p/nt/ufmt/v0"
17	"gno.land/p/sys/validators/v0"
18	sysparams "gno.land/r/sys/params"
19)
20
21// Operator-keyed proposal builder lives in proposal.gno
22// (NewValidatorProposalRequest + newValoperChangeExecutor). The legacy
23// signing-keyed NewProposalRequest was removed: every valid
24// signing-keyed input is also a valid operator-keyed input under
25// always-on valoper enforcement.
26
27// IsValidator returns true if addr is part of the effective validator
28// set (proposed if a v0 proposal is awaiting EndBlocker, else
29// current).
30func IsValidator(addr address) bool {
31	for _, v := range sysparams.GetValsetEffective() {
32		if v.Address == addr {
33			return true
34		}
35	}
36	return false
37}
38
39// GetValidator returns the validator with the given address from the
40// effective set; panics if absent.
41func GetValidator(addr address) validators.Validator {
42	for _, v := range sysparams.GetValsetEffective() {
43		if v.Address == addr {
44			return v
45		}
46	}
47	panic("validator not found")
48}
49
50// GetValidators returns the effective validator set.
51func GetValidators() []validators.Validator {
52	return sysparams.GetValsetEffective()
53}
54
55// Render displays the effective validator set.
56func Render(string) string {
57	var sb strings.Builder
58	h := runtime.ChainHeight()
59	set := sysparams.GetValsetEffective()
60	sb.WriteString(ufmt.Sprintf("## Valset at height %d\n\n", h))
61	if len(set) == 0 {
62		sb.WriteString("Valset is empty.\n")
63		return sb.String()
64	}
65	for i, v := range set {
66		sb.WriteString(ufmt.Sprintf("- #%d: %s (%d)\n", i, v.Address.String(), v.VotingPower))
67	}
68	return sb.String()
69}