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

/p/nt/poa/v0

Directory · 6 Files
README.md Open

v0 - Unaudited This is an initial version of this package that has not yet been formally audited. A fully audited version will be published as a subsequent release. Use in production at your own risk.

poa - Proof of Authority validator set

Stateful Proof of Authority validator set with simple add/remove constraints. This is a low-level building block intended to be embedded by chain-level governance code (e.g. a GovDAO bridge to gno.land/p/sys/validators), not a typical realm utility.

Constraints:

  • Add: validator must not be in the set already and voting power must be > 0.
  • Remove: validator must be in the set.

Usage

 1import (
 2    "gno.land/p/nt/poa/v0"
 3    "gno.land/p/sys/validators"
 4)
 5
 6// Start with a pre-seeded validator set.
 7set := poa.NewPoA(poa.WithInitialSet([]validators.Validator{
 8    {Address: "g1...", PubKey: "gpub1...", VotingPower: 10},
 9}))
10
11// Add a validator.
12v, err := set.AddValidator("g1xyz...", "gpub1xyz...", 5)
13if err != nil {
14    panic(err)
15}
16
17// Inspect membership.
18if set.IsValidator("g1xyz...") {
19    // ...
20}
21
22// List the full current set.
23all := set.GetValidators()
24
25// Remove a validator.
26removed, err := set.RemoveValidator(v.Address)

API

 1type PoA struct { /* ... */ }
 2
 3// Construct an empty set; options seed initial validators.
 4func NewPoA(opts ...Option) *PoA
 5
 6// WithInitialSet seeds the validator set at construction time.
 7func WithInitialSet(vs []validators.Validator) Option
 8
 9func (p *PoA) AddValidator(addr address, pubKey string, power uint64) (validators.Validator, error)
10func (p *PoA) RemoveValidator(addr address) (validators.Validator, error)
11func (p *PoA) IsValidator(addr address) bool
12func (p *PoA) GetValidator(addr address) (validators.Validator, error)
13func (p *PoA) GetValidators() []validators.Validator

Validators are stored and returned as validators.Validator from gno.land/p/sys/validators.

Errors

  • ErrInvalidVotingPowerAddValidator called with power == 0.
  • validators.ErrValidatorExists — adding an address already in the set.
  • validators.ErrValidatorMissing — removing or fetching an address that is not in the set.

Notes

  • Public keys are stored as-is — there is no on-chain verification yet (TODO in source).
  • The package is intentionally narrow: it only manages the in-memory set. Consensus-layer wiring (proposing/applying changes to the actual validator set) is the caller's responsibility.