pos

package
v1.0.0-rc.0 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// EmptyValidators is empty validators group
	EmptyValidators = NewBuilder().Build()
)

Functions

func StakeToBalance

func StakeToBalance(stake Stake) *big.Int

StakeToBalance converts validator's stake to balance Warning: for tests only!

Types

type GValidators

type GValidators []GenesisValidator

GValidators defines genesis validators

func (GValidators) Addresses

func (gv GValidators) Addresses() []common.Address

Addresses returns not sorted genesis addresses

func (GValidators) Map

Map converts GValidators to map

func (GValidators) TotalStake

func (gv GValidators) TotalStake() *big.Int

TotalStake returns sum of stakes

func (GValidators) Validators

func (gv GValidators) Validators() *Validators

Validators converts GValidators to Validators

type GenesisValidator

type GenesisValidator struct {
	ID      idx.StakerID
	Address common.Address
	Stake   *big.Int
}

GenesisValidator is helper structure to define genesis validators

type Stake

type Stake uint64

Stake amount.

func BalanceToStake

func BalanceToStake(balance *big.Int) Stake

BalanceToStake balance to validator's stake

type StakeCounter

type StakeCounter struct {
	// contains filtered or unexported fields
}

StakeCounter counts stakes.

func (*StakeCounter) Count

func (s *StakeCounter) Count(v idx.StakerID) bool

Count validator and return true if it hadn't counted before.

func (*StakeCounter) CountByIdx

func (s *StakeCounter) CountByIdx(stakerIdx idx.Validator) bool

CountByIdx validator and return true if it hadn't counted before.

func (*StakeCounter) HasQuorum

func (s *StakeCounter) HasQuorum() bool

HasQuorum achieved.

func (*StakeCounter) Sum

func (s *StakeCounter) Sum() Stake

Sum of counted stakes.

type StakeCounterProvider

type StakeCounterProvider func() *StakeCounter

StakeCounterProvider providers stake counter.

type Validators

type Validators struct {
	// contains filtered or unexported fields
}

Validators group of an epoch with stakes. Optimized for BFT algorithm calculations. Read-only.

func ArrayToValidators

func ArrayToValidators(ids []idx.StakerID, stakes []Stake) *Validators

ArrayToValidators builds new read-only Validators object from array

func EqualStakeValidators

func EqualStakeValidators(ids []idx.StakerID, stake Stake) *Validators

EqualStakeValidators builds new read-only Validators object with equal stakes (for tests)

func (*Validators) Builder

func (vv *Validators) Builder() ValidatorsBuilder

Builder returns a mutable copy of content

func (*Validators) Copy

func (vv *Validators) Copy() *Validators

Copy constructs a copy.

func (*Validators) DecodeRLP

func (vv *Validators) DecodeRLP(s *rlp.Stream) error

DecodeRLP is for RLP deserialization.

func (*Validators) EncodeRLP

func (vv *Validators) EncodeRLP(w io.Writer) error

EncodeRLP is for RLP serialization.

func (*Validators) Exists

func (vv *Validators) Exists(id idx.StakerID) bool

Exists returns boolean true if address exists in Validators object

func (*Validators) Get

func (vv *Validators) Get(id idx.StakerID) Stake

Get returns stake for validator by ID

func (*Validators) GetIdx

func (vv *Validators) GetIdx(id idx.StakerID) idx.Validator

GetIdx returns index (offset) of validator in the group

func (*Validators) GetStakeByIdx

func (vv *Validators) GetStakeByIdx(i idx.Validator) Stake

GetStakeByIdx returns stake for validator by index

func (*Validators) IDs

func (vv *Validators) IDs() []idx.StakerID

IDs returns not sorted ids.

func (*Validators) Idxs

func (vv *Validators) Idxs() map[idx.StakerID]idx.Validator

Idxs gets deterministic total order of validators.

func (*Validators) Len

func (vv *Validators) Len() int

Len returns count of validators in Validators objects

func (Validators) NewCounter

func (vv Validators) NewCounter() *StakeCounter

NewCounter constructor.

func (*Validators) Quorum

func (vv *Validators) Quorum() Stake

Quorum limit of validators.

func (*Validators) SortedIDs

func (vv *Validators) SortedIDs() []idx.StakerID

SortedIDs returns deterministically sorted ids. The order is the same as for Idxs().

func (*Validators) SortedStakes

func (vv *Validators) SortedStakes() []Stake

SortedStakes returns deterministically sorted stakes. The order is the same as for Idxs().

func (*Validators) TotalStake

func (vv *Validators) TotalStake() (sum Stake)

TotalStake of validators.

type ValidatorsBuilder

type ValidatorsBuilder map[idx.StakerID]Stake

ValidatorsBuilder is a helper to create Validators object

func NewBuilder

func NewBuilder() ValidatorsBuilder

NewBuilder creates new mutable ValidatorsBuilder

func (ValidatorsBuilder) Build

func (vv ValidatorsBuilder) Build() *Validators

Build new read-only Validators object

func (ValidatorsBuilder) Set

func (vv ValidatorsBuilder) Set(id idx.StakerID, stake Stake)

Set appends item to ValidatorsBuilder object

Jump to

Keyboard shortcuts

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