validator

package
v0.0.0-...-f672fcd Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2024 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewValidatorSet

func NewValidatorSet(valz AccountSet, logger hclog.Logger) *validatorSet

NewValidatorSet creates a new validator set.

Types

type AccountSet

type AccountSet []*ValidatorMetadata

AccountSet is a type alias for slice of ValidatorMetadata instances

func (AccountSet) ApplyDelta

func (as AccountSet) ApplyDelta(validatorsDelta *ValidatorSetDelta) (AccountSet, error)

ApplyDelta receives ValidatorSetDelta and applies it to the values from the current AccountSet (removes the ones marked for deletion and adds the one which are being added by delta) Function returns new AccountSet with old and new data merged. AccountSet is immutable!

func (AccountSet) ContainsAddress

func (as AccountSet) ContainsAddress(address types.Address) bool

ContainsAddress checks whether ValidatorMetadata with given address is present in the AccountSet

func (AccountSet) ContainsNodeID

func (as AccountSet) ContainsNodeID(nodeID string) bool

ContainsNodeID checks whether ValidatorMetadata with given nodeID is present in the AccountSet

func (AccountSet) Copy

func (as AccountSet) Copy() AccountSet

Copy returns deep copy of AccountSet

func (AccountSet) Equals

func (as AccountSet) Equals(other AccountSet) bool

Equals compares checks if two AccountSet instances are equal (ordering is important)

func (AccountSet) GetAddresses

func (as AccountSet) GetAddresses() []types.Address

GetAddresses aggregates addresses for given AccountSet

func (AccountSet) GetAddressesAsSet

func (as AccountSet) GetAddressesAsSet() map[types.Address]struct{}

GetAddresses aggregates addresses as map for given AccountSet

func (AccountSet) GetBlsKeys

func (as AccountSet) GetBlsKeys() []*bls.PublicKey

GetBlsKeys aggregates public BLS keys for given AccountSet

func (AccountSet) GetFilteredValidators

func (as AccountSet) GetFilteredValidators(bitmap bitmap.Bitmap) (AccountSet, error)

GetFilteredValidators returns filtered validators based on provided bitmap. Filtered validators will contain validators whose index corresponds to the position in bitmap which has value set to 1.

func (*AccountSet) GetTotalVotingPower

func (as *AccountSet) GetTotalVotingPower() *big.Int

GetTotalVotingPower calculates sum of voting power for each validator in the AccountSet

func (AccountSet) GetValidatorMetadata

func (as AccountSet) GetValidatorMetadata(address types.Address) *ValidatorMetadata

GetValidatorMetadata tries to retrieve validator account metadata by given address from the account set. It returns nil if such account is not found.

func (AccountSet) Hash

func (as AccountSet) Hash() (types.Hash, error)

Hash returns hash value of the AccountSet

func (AccountSet) Index

func (as AccountSet) Index(addr types.Address) int

Index returns index of the given ValidatorMetadata, identified by address within the AccountSet. If given ValidatorMetadata is not present, it returns -1.

func (AccountSet) Len

func (as AccountSet) Len() int

Len returns length of AccountSet

func (AccountSet) Marshal

func (as AccountSet) Marshal() ([]byte, error)

Marshal marshals AccountSet to JSON

func (AccountSet) String

func (as AccountSet) String() string

fmt.Stringer implementation

func (AccountSet) ToAPIBinding

func (as AccountSet) ToAPIBinding() []*contractsapi.Validator

ToAPIBinding converts AccountSet to slice of contract api stubs to be encoded

func (*AccountSet) Unmarshal

func (as *AccountSet) Unmarshal(b []byte) error

Unmarshal unmarshals AccountSet from JSON

type GenesisValidator

type GenesisValidator struct {
	Address   types.Address
	BlsKey    string
	Stake     *big.Int
	MultiAddr string
}

GenesisValidator represents public information about validator accounts which are the part of genesis

func (*GenesisValidator) MarshalJSON

func (v *GenesisValidator) MarshalJSON() ([]byte, error)

func (*GenesisValidator) String

func (v *GenesisValidator) String() string

String implements fmt.Stringer interface

func (*GenesisValidator) ToValidatorMetadata

func (v *GenesisValidator) ToValidatorMetadata() (*ValidatorMetadata, error)

ToValidatorMetadata creates ValidatorMetadata instance

func (*GenesisValidator) UnmarshalBLSPublicKey

func (v *GenesisValidator) UnmarshalBLSPublicKey() (*bls.PublicKey, error)

UnmarshalBLSPublicKey unmarshals the hex encoded BLS public key

func (*GenesisValidator) UnmarshalJSON

func (v *GenesisValidator) UnmarshalJSON(data []byte) (err error)

type TestValidator

type TestValidator struct {
	Alias       string
	Account     *wallet.Account
	VotingPower uint64
}

func NewTestValidator

func NewTestValidator(tb testing.TB, alias string, votingPower uint64) *TestValidator

func (*TestValidator) Address

func (v *TestValidator) Address() types.Address

func (*TestValidator) Key

func (v *TestValidator) Key() *wallet.Key

func (*TestValidator) MustSign

func (v *TestValidator) MustSign(hash, domain []byte) *bls.Signature

func (*TestValidator) ParamsValidator

func (v *TestValidator) ParamsValidator() *GenesisValidator

func (*TestValidator) ValidatorMetadata

func (v *TestValidator) ValidatorMetadata() *ValidatorMetadata

type TestValidators

type TestValidators struct {
	Validators map[string]*TestValidator
}

func NewTestValidators

func NewTestValidators(tb testing.TB, validatorsCount int) *TestValidators

func NewTestValidatorsWithAliases

func NewTestValidatorsWithAliases(tb testing.TB, aliases []string, votingPowers ...[]uint64) *TestValidators

func (*TestValidators) Create

func (v *TestValidators) Create(t *testing.T, alias string, votingPower uint64)

func (*TestValidators) GetParamValidators

func (v *TestValidators) GetParamValidators(aliases ...string) (res []*GenesisValidator)

func (*TestValidators) GetPrivateIdentities

func (v *TestValidators) GetPrivateIdentities(aliases ...string) (res []*wallet.Account)

func (*TestValidators) GetPublicIdentities

func (v *TestValidators) GetPublicIdentities(aliases ...string) (res AccountSet)

func (*TestValidators) GetValidator

func (v *TestValidators) GetValidator(alias string) *TestValidator

func (*TestValidators) GetValidators

func (v *TestValidators) GetValidators(aliases ...string) (res []*TestValidator)

func (*TestValidators) IterAcct

func (v *TestValidators) IterAcct(aliases []string, handle func(t *TestValidator))

func (*TestValidators) ToValidatorSet

func (v *TestValidators) ToValidatorSet() ValidatorSet

func (*TestValidators) UpdateVotingPowers

func (v *TestValidators) UpdateVotingPowers(votingPowersMap map[string]uint64) AccountSet

type ValidatorMetadata

type ValidatorMetadata struct {
	Address     types.Address
	BlsKey      *bls.PublicKey
	VotingPower *big.Int
	IsActive    bool
}

ValidatorMetadata represents a validator metadata (its public identity)

func (*ValidatorMetadata) Copy

Copy returns a deep copy of ValidatorMetadata

func (*ValidatorMetadata) EqualAddressAndBlsKey

func (v *ValidatorMetadata) EqualAddressAndBlsKey(b *ValidatorMetadata) bool

EqualAddressAndBlsKey checks ValidatorMetadata equality against Address and BlsKey fields

func (*ValidatorMetadata) Equals

Equals checks ValidatorMetadata equality

func (*ValidatorMetadata) MarshalRLPWith

func (v *ValidatorMetadata) MarshalRLPWith(ar *fastrlp.Arena) *fastrlp.Value

MarshalRLPWith marshals ValidatorMetadata to the RLP format

func (*ValidatorMetadata) String

func (v *ValidatorMetadata) String() string

fmt.Stringer implementation

func (*ValidatorMetadata) UnmarshalRLPWith

func (v *ValidatorMetadata) UnmarshalRLPWith(val *fastrlp.Value) error

UnmarshalRLPWith unmarshals ValidatorMetadata from the RLP format

type ValidatorSet

type ValidatorSet interface {
	// Includes check if given address is among the current validator set
	Includes(address types.Address) bool

	// Len returns the size of the validator set
	Len() int

	// Accounts returns the list of the ValidatorMetadata
	Accounts() AccountSet

	// HasQuorum checks if submitted signers have reached quorum
	HasQuorum(blockNumber uint64, signers map[types.Address]struct{}) bool

	// GetVotingPowers retrieves map: string(address) -> vp
	GetVotingPowers() map[string]*big.Int
}

ValidatorSet interface of the current validator set

type ValidatorSetDelta

type ValidatorSetDelta struct {
	// Added is the slice of added validators
	Added AccountSet
	// Updated is the slice of updated valiadtors
	Updated AccountSet
	// Removed is a bitmap of the validators removed from the set
	Removed bitmap.Bitmap
}

ValidatorSetDelta holds information about added and removed validators compared to the previous epoch

func CreateValidatorSetDelta

func CreateValidatorSetDelta(oldValidatorSet, newValidatorSet AccountSet) (*ValidatorSetDelta, error)

CreateValidatorSetDelta calculates ValidatorSetDelta based on the provided old and new validator sets

func (*ValidatorSetDelta) Copy

Copy creates deep copy of ValidatorSetDelta

func (*ValidatorSetDelta) Equals

func (d *ValidatorSetDelta) Equals(other *ValidatorSetDelta) bool

Equals checks validator set delta equality

func (*ValidatorSetDelta) IsEmpty

func (d *ValidatorSetDelta) IsEmpty() bool

IsEmpty returns indication whether delta is empty (namely added, updated slices and removed bitmap are empty)

func (*ValidatorSetDelta) MarshalRLPWith

func (d *ValidatorSetDelta) MarshalRLPWith(ar *fastrlp.Arena) *fastrlp.Value

MarshalRLPWith marshals ValidatorSetDelta to RLP format

func (*ValidatorSetDelta) String

func (d *ValidatorSetDelta) String() string

fmt.Stringer interface implementation

func (*ValidatorSetDelta) UnmarshalRLPWith

func (d *ValidatorSetDelta) UnmarshalRLPWith(v *fastrlp.Value) error

UnmarshalRLPWith unmarshals ValidatorSetDelta from RLP format

Jump to

Keyboard shortcuts

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