consensus

package
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 30, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CountVotes

func CountVotes(votes []string) int

CountVotes counts the number of non-nil votes in a vote array

func ParseBitArray

func ParseBitArray(bitArray string) (pattern string, voted int64, total int64, percent float64)

ParseBitArray extracts the bit pattern and percentages from the bit array string Format: "BA{99:xx_xx_x_...} 63976000/106137430 = 0.60"

func ParseHeightRoundStep

func ParseHeightRoundStep(hrs string) (height int64, round int, step int, err error)

ParseHeightRoundStep parses the "height/round/step" string

Types

type ConsensusResponse

type ConsensusResponse struct {
	JSONRPC string `json:"jsonrpc"`
	ID      int    `json:"id"`
	Result  struct {
		RoundState RoundState `json:"round_state"`
	} `json:"result"`
}

ConsensusResponse represents the JSON-RPC response from /consensus_state

type HeightVote

type HeightVote struct {
	Round              int      `json:"round"`
	Prevotes           []string `json:"prevotes"`
	PrevotesBitArray   string   `json:"prevotes_bit_array"`
	Precommits         []string `json:"precommits"`
	PrecommitsBitArray string   `json:"precommits_bit_array"`
}

HeightVote contains vote information for a round

type ProposerInfo

type ProposerInfo struct {
	Address string `json:"address"`
	Index   int    `json:"index"`
}

ProposerInfo contains proposer details

type PubKey

type PubKey struct {
	Type  string `json:"type"`
	Value string `json:"value"`
}

PubKey represents a validator's public key

type RoundState

type RoundState struct {
	HeightRoundStep   string       `json:"height/round/step"`
	StartTime         time.Time    `json:"start_time"`
	ProposalBlockHash string       `json:"proposal_block_hash"`
	LockedBlockHash   string       `json:"locked_block_hash"`
	ValidBlockHash    string       `json:"valid_block_hash"`
	HeightVoteSet     []HeightVote `json:"height_vote_set"`
	Proposer          ProposerInfo `json:"proposer"`
}

RoundState contains the consensus round information

type State

type State struct {
	Height          int64
	Round           int
	Step            int
	StartTime       time.Time
	Elapsed         time.Duration
	ProposerAddress string
	ProposerIndex   int

	// Vote stats
	TotalValidators  int
	TotalVotingPower int64

	// Prevote stats
	PrevoteCount    int
	PrevotePower    int64
	PrevotePercent  float64
	PrevoteBitArray string

	// Precommit stats
	PrecommitCount    int
	PrecommitPower    int64
	PrecommitPercent  float64
	PrecommitBitArray string

	// Validator list with vote status
	Validators []ValidatorStatus

	// Error state
	Error error
}

State represents the parsed consensus state for display

func ParseConsensusState

func ParseConsensusState(resp *ConsensusResponse, validators []Validator) (*State, error)

ParseConsensusState converts raw consensus data into a State struct

type Validator

type Validator struct {
	Address          string `json:"address"`
	PubKey           PubKey `json:"pub_key"`
	VotingPower      string `json:"voting_power"`
	ProposerPriority string `json:"proposer_priority"`
}

Validator represents a validator in the set

type ValidatorStatus

type ValidatorStatus struct {
	Index       int
	Address     string
	PubKey      string // Base64 encoded consensus pubkey for moniker lookup
	VotingPower int64
	Prevoted    bool
	Precommited bool
	IsProposer  bool
}

ValidatorStatus represents a validator's current voting status

type ValidatorsResponse

type ValidatorsResponse struct {
	JSONRPC string `json:"jsonrpc"`
	ID      int    `json:"id"`
	Result  struct {
		BlockHeight string      `json:"block_height"`
		Validators  []Validator `json:"validators"`
		Count       string      `json:"count"`
		Total       string      `json:"total"`
	} `json:"result"`
}

ValidatorsResponse represents the JSON-RPC response from /validators

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL