state

package
v1.14.0 Latest Latest
Warning

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

Go to latest
Published: May 3, 2026 License: MIT Imports: 36 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrDuplicatedSubsidyTransaction = errors.New("duplicated subsidy transaction")

ErrDuplicatedSubsidyTransaction indicates that there is more than one subsidy transaction inside the block.

View Source
var ErrInvalidBlockVersion = errors.New("invalid block version")

ErrInvalidBlockVersion indicates that the block version is not valid.

View Source
var ErrInvalidCertificate = errors.New("invalid certificate")

ErrInvalidCertificate indicates that the block certificate is invalid.

View Source
var ErrInvalidSortitionSeed = errors.New("invalid sortition seed")

ErrInvalidSortitionSeed indicates that the block's sortition seed is either invalid or unverifiable.

View Source
var ErrInvalidSubsidyTransaction = errors.New("invalid subsidy transaction")

ErrInvalidSubsidyTransaction indicates that the subsidy transaction is not valid.

Functions

This section is empty.

Types

type ChainInfo added in v1.12.0

type ChainInfo struct {
	LastBlockHeight types.Height
	LastBlockHash   hash.Hash
	LastBlockTime   time.Time

	TotalPower     int64
	CommitteePower int64
	CommitteeSize  int

	TotalAccounts    int32
	TotalValidators  int32
	ActiveValidators int32
	AverageScore     float64

	IsPruned      bool
	PruningHeight types.Height
}

type CommitteeInfo added in v1.12.0

type CommitteeInfo struct {
	Validators       []*validator.Validator
	ProtocolVersions map[protocol.Version]float64
	CommitteePower   int64
}

CommitteeInfo holds committee validators, protocol versions, and total power.

type Facade

type Facade interface {
	Genesis() *genesis.Genesis
	Params() *param.Params
	LastBlockHeight() types.Height
	LastBlockHash() hash.Hash
	LastBlockTime() time.Time
	LastCertificate() *certificate.Certificate
	UpdateLastCertificate(v *vote.Vote) error
	ProposeBlock(valKey *bls.ValidatorKey, rewardAddr crypto.Address) (*block.Block, error)
	ValidateBlock(blk *block.Block, round types.Round) error
	CommitBlock(blk *block.Block, cert *certificate.Certificate) error
	CommitteeValidators() []*validator.Validator
	CommitteeInfo() *CommitteeInfo
	IsInCommittee(addr crypto.Address) bool
	Proposer(round types.Round) *validator.Validator
	IsProposer(addr crypto.Address, round types.Round) bool
	PendingTx(txID tx.ID) *tx.Tx
	AddPendingTx(trx *tx.Tx) error
	AddPendingTxAndBroadcast(trx *tx.Tx) error
	CommittedBlock(height types.Height) (*store.CommittedBlock, error)
	CommittedTx(txID tx.ID) (*store.CommittedTx, error)
	BlockHash(height types.Height) hash.Hash
	BlockHeight(h hash.Hash) types.Height
	AccountByAddress(addr crypto.Address) (*account.Account, error)
	ValidatorByAddress(addr crypto.Address) (*validator.Validator, error)
	ValidatorByNumber(number int32) (*validator.Validator, error)
	ValidatorAddresses() []crypto.Address
	UpdateValidatorProtocolVersion(addr crypto.Address, ver protocol.Version)
	CalculateFee(amt amount.Amount, payloadType payload.Type) amount.Amount
	PublicKey(addr crypto.Address) (crypto.PublicKey, error)
	AvailabilityScore(valNum int32) float64
	AllPendingTxs() []*tx.Tx
	ChainInfo() *ChainInfo
	CheckTransaction(trx *tx.Tx) error

	Close()
}

func LoadOrNewState

func LoadOrNewState(
	genDoc *genesis.Genesis,
	valKeys []*bls.ValidatorKey,
	store store.Store,
	txPool txpool.TxPool,
	eventPipe pipeline.Pipeline[any],
) (Facade, error)

type InvalidBlockTimeError added in v1.5.0

type InvalidBlockTimeError struct {
	Reason string
}

InvalidBlockTimeError is returned when the block time is not valid.

func (InvalidBlockTimeError) Error added in v1.5.0

func (e InvalidBlockTimeError) Error() string

type InvalidProposerError added in v1.5.0

type InvalidProposerError struct {
	Expected crypto.Address
	Got      crypto.Address
}

InvalidProposerError is returned when the block proposer is not as expected.

func (InvalidProposerError) Error added in v1.5.0

func (e InvalidProposerError) Error() string

type InvalidStateRootHashError added in v1.5.0

type InvalidStateRootHashError struct {
	Expected hash.Hash
	Got      hash.Hash
}

InvalidStateRootHashError is returned when the state root hash of the block does not match the current state root hash.

func (InvalidStateRootHashError) Error added in v1.5.0

type InvalidSubsidyAmountError added in v1.5.0

type InvalidSubsidyAmountError struct {
	Expected amount.Amount
	Got      amount.Amount
}

InvalidSubsidyAmountError is returned when the amount of the subsidy transaction is not as expected.

func (InvalidSubsidyAmountError) Error added in v1.5.0

type InvalidVoteForCertificateError added in v0.15.0

type InvalidVoteForCertificateError struct {
	Vote *vote.Vote
}

InvalidVoteForCertificateError is returned when an attempt to update the last certificate with an invalid vote is made.

func (InvalidVoteForCertificateError) Error added in v0.15.0

type MockState

type MockState struct {
	TestGenesis   *genesis.Genesis
	TestStore     *store.MockStore
	MockTxPool    *txpool.MockTxPool
	TestCommittee committee.Committee
	TestValKeys   []*bls.ValidatorKey
	TestParams    *param.Params
	// contains filtered or unexported fields
}

MockState is a mock implementation of the State interface for testing.

func MockingState

func MockingState(ts *testsuite.TestSuite) *MockState

func (*MockState) AccountByAddress

func (m *MockState) AccountByAddress(addr crypto.Address) (*account.Account, error)

func (*MockState) AddPendingTx

func (m *MockState) AddPendingTx(trx *tx.Tx) error

func (*MockState) AddPendingTxAndBroadcast

func (m *MockState) AddPendingTxAndBroadcast(trx *tx.Tx) error

func (*MockState) AllPendingTxs added in v1.3.0

func (m *MockState) AllPendingTxs() []*tx.Tx

func (*MockState) AvailabilityScore added in v0.19.0

func (*MockState) AvailabilityScore(_ int32) float64

func (*MockState) BlockHash

func (m *MockState) BlockHash(height types.Height) hash.Hash

func (*MockState) BlockHeight

func (m *MockState) BlockHeight(h hash.Hash) types.Height

func (*MockState) CalculateFee added in v0.15.0

func (m *MockState) CalculateFee(amt amount.Amount, payloadType payload.Type) amount.Amount

func (*MockState) ChainInfo added in v1.12.0

func (m *MockState) ChainInfo() *ChainInfo

func (*MockState) CheckTransaction added in v1.14.0

func (*MockState) CheckTransaction(*tx.Tx) error

func (*MockState) Close

func (*MockState) Close()

func (*MockState) CommitBlock

func (m *MockState) CommitBlock(blk *block.Block, cert *certificate.Certificate) error

func (*MockState) CommitTestBlocks

func (m *MockState) CommitTestBlocks(num int)

func (*MockState) CommittedBlock added in v0.15.0

func (m *MockState) CommittedBlock(height types.Height) (*store.CommittedBlock, error)

func (*MockState) CommittedTx added in v0.15.0

func (m *MockState) CommittedTx(txID tx.ID) (*store.CommittedTx, error)

func (*MockState) CommitteeInfo added in v1.12.0

func (m *MockState) CommitteeInfo() *CommitteeInfo

func (*MockState) CommitteeValidators

func (m *MockState) CommitteeValidators() []*validator.Validator

func (*MockState) Genesis added in v0.11.0

func (m *MockState) Genesis() *genesis.Genesis

func (*MockState) IsInCommittee

func (m *MockState) IsInCommittee(addr crypto.Address) bool

func (*MockState) IsProposer

func (m *MockState) IsProposer(addr crypto.Address, round types.Round) bool

func (*MockState) IsValidator

func (m *MockState) IsValidator(addr crypto.Address) bool

func (*MockState) LastBlockHash

func (m *MockState) LastBlockHash() hash.Hash

func (*MockState) LastBlockHeight

func (m *MockState) LastBlockHeight() types.Height

func (*MockState) LastBlockTime

func (m *MockState) LastBlockTime() time.Time

func (*MockState) LastCertificate

func (m *MockState) LastCertificate() *certificate.Certificate

func (*MockState) Params

func (m *MockState) Params() *param.Params

func (*MockState) PendingTx

func (m *MockState) PendingTx(txID tx.ID) *tx.Tx

func (*MockState) ProposeBlock

func (m *MockState) ProposeBlock(valKey *bls.ValidatorKey, _ crypto.Address) (*block.Block, error)

func (*MockState) Proposer

func (m *MockState) Proposer(round types.Round) *validator.Validator

func (*MockState) PublicKey added in v0.15.0

func (m *MockState) PublicKey(addr crypto.Address) (crypto.PublicKey, error)

func (*MockState) UpdateLastCertificate

func (*MockState) UpdateLastCertificate(_ *vote.Vote) error

func (*MockState) UpdateValidatorProtocolVersion added in v1.9.0

func (m *MockState) UpdateValidatorProtocolVersion(addr crypto.Address, ver protocol.Version)

func (*MockState) ValidateBlock

func (*MockState) ValidateBlock(_ *block.Block, _ types.Round) error

func (*MockState) ValidatorAddresses added in v0.12.0

func (m *MockState) ValidatorAddresses() []crypto.Address

func (*MockState) ValidatorByAddress

func (m *MockState) ValidatorByAddress(addr crypto.Address) (*validator.Validator, error)

func (*MockState) ValidatorByNumber

func (m *MockState) ValidatorByNumber(n int32) (*validator.Validator, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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