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

v0 source pure

v0 - Unaudited: This is an initial version that has not yet been formally audited. A fully audited version will be pu...

Readme View source

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.

Overview

v0 - Unaudited: This is an initial version 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.

Package poa implements a Proof of Authority validator set management system.

Variables 1

Functions 2

func WithInitialSet

1func WithInitialSet(validators []validators.Validator) Option
source

WithInitialSet sets the initial PoA validator set

func NewPoA

1func NewPoA(opts ...Option) *PoA
source

NewPoA creates a new empty Proof of Authority validator set

Types 2

type PoA

struct
1type PoA struct {
2	validators *bptree.BPTree // address -> validators.Validator
3}
source

PoA specifies the Proof of Authority validator set, with simple add / remove constraints.

To add: - proposed validator must not be part of the set already - proposed validator voting power must be > 0

To remove: - proposed validator must be part of the set already

Methods on PoA

func AddValidator

method on PoA
1func (p *PoA) AddValidator(address_XXX address, pubKey string, power uint64) (validators.Validator, error)
source

func GetValidator

method on PoA
1func (p *PoA) GetValidator(address_XXX address) (validators.Validator, error)
source

func GetValidators

method on PoA
1func (p *PoA) GetValidators() []validators.Validator
source

func IsValidator

method on PoA
1func (p *PoA) IsValidator(address_XXX address) bool
source

func RemoveValidator

method on PoA
1func (p *PoA) RemoveValidator(address_XXX address) (validators.Validator, error)
source

Imports 3

Source Files 6