validators

package
v0.6.6 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package validators provides a module for processing validator requests from a blockchain application using a pluggable validator manager and account store.

Package validators provides a module for processing validator requests from a blockchain application using a pluggable validator manager and account store.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ExecutionResponse

type ExecutionResponse struct {
	// Fee is the amount of tokens spent on the execution
	Fee     *big.Int
	GasUsed int64
}

type Spender

type Spender interface {
	Spend(ctx context.Context, spend *accounts.Spend) error
}

type ValidatorMgr

type ValidatorMgr interface {
	GenesisInit(ctx context.Context, vals []*validators.Validator, blockHeight int64) error
	CurrentSet(ctx context.Context) ([]*validators.Validator, error)
	Update(ctx context.Context, validator []byte, power int64) error
	Join(ctx context.Context, joiner []byte, power int64) error
	Leave(ctx context.Context, joiner []byte) error
	Approve(ctx context.Context, joiner, approver []byte) error
	Remove(ctx context.Context, target, validator []byte) error
	Finalize(ctx context.Context) ([]*validators.Validator, error) // end of block processing requires providing list of updates to the node's consensus client
	UpdateBlockHeight(blockHeight int64)

	PriceJoin(ctx context.Context) (*big.Int, error)
	PriceApprove(ctx context.Context) (*big.Int, error)
	PriceLeave(ctx context.Context) (*big.Int, error)
	PriceRemove(ctx context.Context) (*big.Int, error)
}

type ValidatorModule

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

ValidatorModule separates validator update and state persistence details from the processing of validator related transactions (pricing and account updates i.e. "spending").

func NewValidatorModule

func NewValidatorModule(mgr ValidatorMgr, accts Spender, opts ...ValidatorModuleOpt) *ValidatorModule

NewValidatorModule constructs a validator module. The ValidatorMgr handles the details of computing validator updates to be included in a block, while the Spender provides handles account balance updates when processing the transactions.

func (*ValidatorModule) Approve

func (vm *ValidatorModule) Approve(ctx context.Context, joiner []byte,
	txn *transactions.Transaction) (*ExecutionResponse, error)

Approve records an approval transaction from a current validator.

func (*ValidatorModule) CurrentSet

func (vm *ValidatorModule) CurrentSet(ctx context.Context) ([]*validators.Validator, error)

CurrentSet returns the current validator list. This may be used on construction of a resuming application.

func (*ValidatorModule) Finalize

func (vm *ValidatorModule) Finalize(ctx context.Context) ([]*validators.Validator, error)

Finalize is used at the end of block processing to retrieve the validator updates to be provided to the consensus client for the next block. This is not idempotent. The modules working list of updates is reset until subsequent join/approves are processed for the next block. end of block processing requires providing list of updates to the node's consensus client

func (*ValidatorModule) GenesisInit

func (vm *ValidatorModule) GenesisInit(ctx context.Context, vals []*validators.Validator, blockHeight int64) error

GenesisInit is called at the genesis block to set and initial list of validators.

func (*ValidatorModule) Join

Join creates a join request for a prospective validator.

func (*ValidatorModule) Leave

Leave creates a leave request for a current validator.

func (*ValidatorModule) PriceApprove

func (v *ValidatorModule) PriceApprove(ctx context.Context) (*big.Int, error)

func (*ValidatorModule) PriceJoin

func (v *ValidatorModule) PriceJoin(ctx context.Context) (*big.Int, error)

func (*ValidatorModule) PriceLeave

func (v *ValidatorModule) PriceLeave(ctx context.Context) (*big.Int, error)

func (*ValidatorModule) PriceRemove

func (v *ValidatorModule) PriceRemove(ctx context.Context) (*big.Int, error)

func (*ValidatorModule) Punish

func (vm *ValidatorModule) Punish(ctx context.Context, validator []byte, newPower int64) error

Punish may be used at the start of block processing when byzantine validators are listed by the consensus client.

func (*ValidatorModule) Remove

func (vm *ValidatorModule) Remove(ctx context.Context, validator []byte,
	txn *transactions.Transaction) (*ExecutionResponse, error)

Remove records a removal transaction targeting the given validator pubkey. The transaction sender must be a current validator. The caller ensures that the transaction signature is verified.

func (*ValidatorModule) UpdateBlockHeight

func (vm *ValidatorModule) UpdateBlockHeight(ctx context.Context, blockHeight int64)

Updates block height stored by the validator manager. Called in the abci Commit

type ValidatorModuleOpt

type ValidatorModuleOpt func(*ValidatorModule)

func WithLogger

func WithLogger(logger log.Logger) ValidatorModuleOpt

WithLogger sets the logger

Jump to

Keyboard shortcuts

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