state

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: May 6, 2020 License: Apache-2.0, Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBranchNameUsed   = errors.New("state db:branch name has been used")
	ErrStateIsNil       = errors.New("the state has no data")
	ErrRevertFromBackup = errors.New("state revert from backup, not find data")
)

Functions

func StateDB

func StateDB(config *viper.Viper) dbm.DB

Types

type BlockStore

type BlockStore interface {
	Height() int
	LoadBlock(height int) *types.Block
	LoadBlockMeta(height int) *types.BlockMeta
}

TODO: Should we move blockchain/store.go to its own package?

type BlockVerifier added in v1.4.0

type BlockVerifier interface {
	ValidateBlock(*types.Block) error
}

type ErrAppBlockHeightTooHigh

type ErrAppBlockHeightTooHigh struct {
	CoreHeight int64
	AppHeight  int64
}

func (ErrAppBlockHeightTooHigh) Error

func (e ErrAppBlockHeightTooHigh) Error() string

type ErrBlockHashMismatch

type ErrBlockHashMismatch struct {
	CoreHash []byte
	AppHash  []byte
	Height   int
}

func (ErrBlockHashMismatch) Error

func (e ErrBlockHashMismatch) Error() string

type ErrInvalidBlock

type ErrInvalidBlock error

type ErrLastStateMismatch

type ErrLastStateMismatch struct {
	Height int64
	Core   []byte
	App    []byte
}

func (ErrLastStateMismatch) Error

func (e ErrLastStateMismatch) Error() string

type ErrProxyAppConn

type ErrProxyAppConn error

type ErrStateMismatch

type ErrStateMismatch struct {
	Got      *State
	Expected *State
}

func (ErrStateMismatch) Error

func (e ErrStateMismatch) Error() string

type ErrUnknownBlock

type ErrUnknownBlock struct {
	Height int64
}

func (ErrUnknownBlock) Error

func (e ErrUnknownBlock) Error() string

type Handshaker

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

func NewHandshaker

func NewHandshaker(config cfg.Config, state *State, store BlockStore) *Handshaker

func (*Handshaker) Handshake

func (h *Handshaker) Handshake() error

TODO: retry the handshake/replay if it fails ?

type IBlockExecutable

type IBlockExecutable interface {
	BeginBlock(*types.Block, events.Fireable, *types.PartSetHeader) error
	ExecBlock(*types.Block, events.Fireable, *types.ExecuteResult) error
	EndBlock(*types.Block, events.Fireable, *types.PartSetHeader, []*types.ValidatorAttr, *types.ValidatorSet) error
}

type State

type State struct {

	// should not change
	GenesisDoc *types.GenesisDoc
	ChainID    string

	// updated at end of ExecBlock
	LastBlockHeight    int64 // Genesis state has this set to 0.  So, Block(H=0) does not exist.
	LastBlockID        types.BlockID
	LastBlockTime      time.Time
	Validators         *types.ValidatorSet
	LastValidators     *types.ValidatorSet // block.LastCommit validated against this
	LastNonEmptyHeight int64

	// AppHash is updated after Commit
	AppHash []byte
	// ReceiptsHash is updated only after eval the txs
	ReceiptsHash []byte
	// contains filtered or unexported fields
}

NOTE: not goroutine-safe.

func GetState

func GetState(config *viper.Viper, stateDB dbm.DB) *State

Load the most recent state from "state" db, or create a new one (and save) from genesis.

func LoadState

func LoadState(db dbm.DB) *State

func MakeGenesisState

func MakeGenesisState(db dbm.DB, genDoc *types.GenesisDoc) *State

func MakeGenesisStateFromFile

func MakeGenesisStateFromFile(db dbm.DB, genDocFile string) *State

func (*State) ApplyBlock

func (s *State) ApplyBlock(eventSwitch types.EventSwitch, block *types.Block, partsHeader types.PartSetHeader, mempool types.IMempool, round int64) error

ApplyBlock executes the block, then commits and updates the mempool atomically

func (*State) Bytes

func (s *State) Bytes() []byte

Bytes return go-wired []byte

func (*State) CommitStateUpdateMempool

func (s *State) CommitStateUpdateMempool(eventSwitch types.EventSwitch, block *types.Block, mempool types.IMempool, round int64) error

mempool must be locked during commit and update because state is typically reset on Commit and old txs must be replayed against committed state before new txs are run in the mempool, lest they be invalid

func (*State) Copy

func (s *State) Copy() *State

func (*State) Equals

func (s *State) Equals(s2 *State) bool

func (*State) ExecBlock

func (s *State) ExecBlock(eventSwitch types.EventSwitch, block *types.Block, blockPartsHeader types.PartSetHeader, round int64) error

Execute the block to mutate State. Validates block and then executes Data.Txs in the block.

func (*State) GetChainID

func (s *State) GetChainID() string

func (*State) GetLastBlockInfo

func (s *State) GetLastBlockInfo() (types.BlockID, int64, time.Time)

func (*State) GetValidators

func (s *State) GetValidators() (*types.ValidatorSet, *types.ValidatorSet)

func (*State) LoadIntermediate

func (s *State) LoadIntermediate()

Load the intermediate state into the current state and do some sanity checks

func (*State) Save

func (s *State) Save()

func (*State) SaveIntermediate

func (s *State) SaveIntermediate()

func (*State) SaveToKey

func (s *State) SaveToKey(key []byte)

func (*State) SetBlockAndValidators

func (s *State) SetBlockAndValidators(header *types.Header, blockPartsHeader types.PartSetHeader, prevValSet, nextValSet *types.ValidatorSet)

Mutate state variables to match block and validators after running EndBlock

func (*State) SetBlockExecutable

func (s *State) SetBlockExecutable(ex IBlockExecutable)

func (*State) SetBlockVerifier added in v1.4.0

func (s *State) SetBlockVerifier(verifier BlockVerifier)

func (*State) ValidateBlock

func (s *State) ValidateBlock(block *types.Block) error

type StateTool

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

func (*StateTool) BackupLastState

func (st *StateTool) BackupLastState(branchName string) error

func (*StateTool) ChangeToIntermidiate

func (st *StateTool) ChangeToIntermidiate()

func (*StateTool) DelBackup

func (st *StateTool) DelBackup(branchName string)

func (*StateTool) Init

func (st *StateTool) Init(config *cfg.Viper) error

func (*StateTool) LastHeight

func (st *StateTool) LastHeight() int64

func (*StateTool) NewValSet

func (st *StateTool) NewValSet(lastHeight int64) *types.ValidatorSet

func (*StateTool) RevertFromBackup

func (st *StateTool) RevertFromBackup(branchName string) error

func (*StateTool) SaveNewState

func (st *StateTool) SaveNewState(valSet *types.ValidatorSet, nextBlock, lastBlock *types.Block, lastBlockMeta *types.BlockMeta, lastBlockID *types.BlockID) error

back to height of lastBlock TODO whatif the validator_set has been changed

type TPSCalculator

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

func NewTPSCalculator

func NewTPSCalculator(count uint32) *TPSCalculator

func (*TPSCalculator) AddRecord

func (c *TPSCalculator) AddRecord(txExcuted uint32)

func (*TPSCalculator) TPS

func (c *TPSCalculator) TPS() int

Jump to

Keyboard shortcuts

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