state

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2020 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// ActivateDuration is about how long we should activate from pending or
	// inactive state.
	ActivateDuration = 6

	// CacheCRVotesSize indicate the size to cache votes information.
	CacheCRVotesSize = 6
)

Variables

This section is empty.

Functions

func DisableLog

func DisableLog()

DisableLog disables all library log output. Logging output is disabled by default until either UseLogger or SetLogWriter are called.

func UseLogger

func UseLogger(logger elalog.Logger)

UseLogger uses a specified Logger to output package logging info. This should be used in preference to SetLogWriter if the caller is also using elalog.

Types

type CRMember

type CRMember struct {
	Info             payload.CRInfo
	ImpeachmentVotes common.Fixed64
	DepositAmount    common.Fixed64
	DepositHash      common.Uint168
	Penalty          common.Fixed64
}

CRMember defines CR committee member related info.

func (*CRMember) Deserialize

func (c *CRMember) Deserialize(r io.Reader) (err error)

func (*CRMember) Serialize

func (c *CRMember) Serialize(w io.Writer) (err error)

type Candidate

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

Candidate defines information about CR candidates during the CR vote period

func (*Candidate) CancelHeight

func (c *Candidate) CancelHeight() uint32

RegisterHeight returns the height when the CR was unregistered.

func (*Candidate) DepositAmount

func (c *Candidate) DepositAmount() common.Fixed64

DepositAmount returns the deposit amount of the CR.

func (*Candidate) Deserialize

func (c *Candidate) Deserialize(r io.Reader) (err error)

func (*Candidate) Info

func (c *Candidate) Info() payload.CRInfo

Info returns a copy of the origin registered CR info.

func (*Candidate) Penalty

func (c *Candidate) Penalty() common.Fixed64

Penalty returns the penalty amount of deposit coin.

func (*Candidate) RegisterHeight

func (c *Candidate) RegisterHeight() uint32

RegisterHeight returns the height when the CR was registered.

func (*Candidate) Serialize

func (c *Candidate) Serialize(w io.Writer) (err error)

func (*Candidate) State

func (c *Candidate) State() CandidateState

State returns the CR's state, can be pending, active, canceled or returned.

func (*Candidate) Votes

func (c *Candidate) Votes() common.Fixed64

Votes returns the votes of the CR.

type CandidateState

type CandidateState byte

CandidateState defines states during a CR candidates lifetime

const (
	// Pending indicates the producer is just registered and didn't get 6
	// confirmations yet.
	Pending CandidateState = iota

	// Active indicates the CR is registered and confirmed by more than
	// 6 blocks.
	Active

	// Canceled indicates the CR was canceled.
	Canceled

	// Returned indicates the CR has canceled and deposit returned.
	Returned
)

func (CandidateState) String

func (ps CandidateState) String() string

type Checkpoint

type Checkpoint struct {
	KeyFrame
	StateKeyFrame
	// contains filtered or unexported fields
}

Checkpoint hold all CR related states to recover from scratch.

func NewCheckpoint

func NewCheckpoint(committee *Committee) *Checkpoint

func (*Checkpoint) DataExtension

func (c *Checkpoint) DataExtension() string

func (*Checkpoint) Deserialize

func (c *Checkpoint) Deserialize(r io.Reader) (err error)

func (*Checkpoint) EffectivePeriod

func (c *Checkpoint) EffectivePeriod() uint32

func (*Checkpoint) Generator

func (c *Checkpoint) Generator() func(buf []byte) checkpoint.ICheckPoint

func (*Checkpoint) GetHeight

func (c *Checkpoint) GetHeight() uint32

func (*Checkpoint) Key

func (c *Checkpoint) Key() string

func (*Checkpoint) LogError

func (c *Checkpoint) LogError(err error)

func (*Checkpoint) OnBlockSaved

func (c *Checkpoint) OnBlockSaved(block *types.DposBlock)

func (*Checkpoint) OnInit

func (c *Checkpoint) OnInit()

func (*Checkpoint) OnRollbackTo

func (c *Checkpoint) OnRollbackTo(height uint32) error

func (*Checkpoint) Priority

func (c *Checkpoint) Priority() checkpoint.Priority

func (*Checkpoint) SavePeriod

func (c *Checkpoint) SavePeriod() uint32

func (*Checkpoint) Serialize

func (c *Checkpoint) Serialize(w io.Writer) (err error)

func (*Checkpoint) SetHeight

func (c *Checkpoint) SetHeight(height uint32)

func (*Checkpoint) Snapshot

func (c *Checkpoint) Snapshot() checkpoint.ICheckPoint

func (*Checkpoint) StartHeight

func (c *Checkpoint) StartHeight() uint32

type Committee

type Committee struct {
	KeyFrame
	// contains filtered or unexported fields
}

func NewCommittee

func NewCommittee(params *config.Params) *Committee

func (*Committee) ExistCR

func (c *Committee) ExistCR(programCode []byte) bool

func (*Committee) GetAllMembers

func (c *Committee) GetAllMembers() []*CRMember

get all CRMembers

func (*Committee) GetMembersCodes

func (c *Committee) GetMembersCodes() [][]byte

func (*Committee) GetMembersDIDs

func (c *Committee) GetMembersDIDs() []common.Uint168

func (*Committee) GetState

func (c *Committee) GetState() *State

func (*Committee) IsInVotingPeriod

func (c *Committee) IsInVotingPeriod(height uint32) bool

func (*Committee) ProcessBlock

func (c *Committee) ProcessBlock(block *types.Block, confirm *payload.Confirm)

func (*Committee) Recover

func (c *Committee) Recover(checkpoint *Checkpoint)

func (*Committee) RollbackTo

func (c *Committee) RollbackTo(height uint32) error

type ICRRecord

type ICRRecord interface {
	GetHeightsDesc() ([]uint32, error)
	GetCheckpoint(height uint32) (*Checkpoint, error)
	SaveCheckpoint(point *Checkpoint) error
}

ICRRecord defines necessary operations about CR checkpoint

type KeyFrame

type KeyFrame struct {
	Members             []*CRMember
	LastCommitteeHeight uint32
}

StateKeyFrame holds necessary state about CR committee.

func NewKeyFrame

func NewKeyFrame() *KeyFrame

func (*KeyFrame) Deserialize

func (k *KeyFrame) Deserialize(r io.Reader) (err error)

func (*KeyFrame) Serialize

func (k *KeyFrame) Serialize(w io.Writer) (err error)

func (*KeyFrame) Snapshot

func (k *KeyFrame) Snapshot() *KeyFrame

type State

type State struct {
	StateKeyFrame
	// contains filtered or unexported fields
}

State hold all CR candidates related information, and process block by block to update votes and any other changes about candidates.

func NewState

func NewState(chainParams *config.Params) *State

func (*State) ExistCandidate

func (s *State) ExistCandidate(programCode []byte) bool

ExistCandidate judges if there is a candidate with specified program code.

func (*State) ExistCandidateByDID

func (s *State) ExistCandidateByDID(did common.Uint168) (ok bool)

ExistCandidateByDID judges if there is a candidate with specified did.

func (*State) ExistCandidateByDepositHash

func (s *State) ExistCandidateByDepositHash(did common.Uint168) bool

ExistCandidateByDepositHash judges if there is a candidate with deposit hash.

func (*State) ExistCandidateByNickname

func (s *State) ExistCandidateByNickname(nickname string) bool

ExistCandidateByNickname judges if there is a candidate with specified nickname.

func (*State) FinishVoting

func (s *State) FinishVoting(dids []common.Uint168) *StateKeyFrame

FinishVoting will close all voting util next voting period

func (*State) GetAllCandidates

func (s *State) GetAllCandidates() []*Candidate

GetAllCandidates returns all candidates holding within state.

func (*State) GetCandidate

func (s *State) GetCandidate(programCode []byte) *Candidate

GetCandidate returns candidate with specified program code, it will return nil if not found.

func (*State) GetCandidateByDID

func (s *State) GetCandidateByDID(did common.Uint168) *Candidate

GetCandidateByDID returns candidate with specified did, it will return nil nil if not found.

func (*State) GetCandidates

func (s *State) GetCandidates(state CandidateState) []*Candidate

GetCandidates returns candidates with specified candidate state.

func (*State) IsCRTransaction

func (s *State) IsCRTransaction(tx *types.Transaction) bool

IsCRTransaction returns if a transaction will change the CR and votes state.

func (*State) ProcessBlock

func (s *State) ProcessBlock(block *types.Block, confirm *payload.Confirm)

ProcessBlock takes a block and it's confirm to update CR state and votes accordingly.

func (*State) ProcessReturnDepositTxs

func (s *State) ProcessReturnDepositTxs(block *types.Block)

ProcessBlock takes a block and it's confirm to update CR state and votes accordingly.

func (*State) RollbackTo

func (s *State) RollbackTo(height uint32) error

RollbackTo restores the database state to the given height, if no enough history to rollback to return error.

type StateKeyFrame

type StateKeyFrame struct {
	CodeDIDMap         map[string]common.Uint168
	DepositHashMap     map[common.Uint168]struct{}
	PendingCandidates  map[common.Uint168]*Candidate
	ActivityCandidates map[common.Uint168]*Candidate
	CanceledCandidates map[common.Uint168]*Candidate
	Nicknames          map[string]struct{}
	Votes              map[string]*types.Output
	DepositOutputs     map[string]*types.Output
}

StateKeyFrame holds necessary state about CR state.

func NewStateKeyFrame

func NewStateKeyFrame() *StateKeyFrame

func (*StateKeyFrame) Deserialize

func (k *StateKeyFrame) Deserialize(r io.Reader) (err error)

func (*StateKeyFrame) Serialize

func (k *StateKeyFrame) Serialize(w io.Writer) (err error)

func (*StateKeyFrame) Snapshot

func (k *StateKeyFrame) Snapshot() *StateKeyFrame

Snapshot will create a new StateKeyFrame object and deep copy all related data.

Jump to

Keyboard shortcuts

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