Documentation ¶
Index ¶
- Constants
- func DisableLog()
- func UseLogger(logger elalog.Logger)
- type CRMember
- type Candidate
- func (c *Candidate) CancelHeight() uint32
- func (c *Candidate) DepositAmount() common.Fixed64
- func (c *Candidate) Deserialize(r io.Reader) (err error)
- func (c *Candidate) Info() payload.CRInfo
- func (c *Candidate) Penalty() common.Fixed64
- func (c *Candidate) RegisterHeight() uint32
- func (c *Candidate) Serialize(w io.Writer) (err error)
- func (c *Candidate) State() CandidateState
- func (c *Candidate) Votes() common.Fixed64
- type CandidateState
- type Checkpoint
- func (c *Checkpoint) DataExtension() string
- func (c *Checkpoint) Deserialize(r io.Reader) (err error)
- func (c *Checkpoint) EffectivePeriod() uint32
- func (c *Checkpoint) Generator() func(buf []byte) checkpoint.ICheckPoint
- func (c *Checkpoint) GetHeight() uint32
- func (c *Checkpoint) Key() string
- func (c *Checkpoint) LogError(err error)
- func (c *Checkpoint) OnBlockSaved(block *types.DposBlock)
- func (c *Checkpoint) OnInit()
- func (c *Checkpoint) OnRollbackTo(height uint32) error
- func (c *Checkpoint) Priority() checkpoint.Priority
- func (c *Checkpoint) SavePeriod() uint32
- func (c *Checkpoint) Serialize(w io.Writer) (err error)
- func (c *Checkpoint) SetHeight(height uint32)
- func (c *Checkpoint) Snapshot() checkpoint.ICheckPoint
- func (c *Checkpoint) StartHeight() uint32
- type Committee
- func (c *Committee) ExistCR(programCode []byte) bool
- func (c *Committee) GetAllMembers() []*CRMember
- func (c *Committee) GetMembersCIDs() []common.Uint168
- func (c *Committee) GetMembersCodes() [][]byte
- func (c *Committee) GetState() *State
- func (c *Committee) IsInVotingPeriod(height uint32) bool
- func (c *Committee) ProcessBlock(block *types.Block, confirm *payload.Confirm)
- func (c *Committee) Recover(checkpoint *Checkpoint)
- func (c *Committee) RollbackTo(height uint32) error
- type ICRRecord
- type KeyFrame
- type State
- func (s *State) ExistCandidate(programCode []byte) bool
- func (s *State) ExistCandidateByCID(cid common.Uint168) (ok bool)
- func (s *State) ExistCandidateByDepositHash(cid common.Uint168) bool
- func (s *State) ExistCandidateByNickname(nickname string) bool
- func (s *State) FinishVoting(dids []common.Uint168) *StateKeyFrame
- func (s *State) GetAllCandidates() []*Candidate
- func (s *State) GetCandidate(programCode []byte) *Candidate
- func (s *State) GetCandidateByCID(cid common.Uint168) *Candidate
- func (s *State) GetCandidateByID(id common.Uint168) *Candidate
- func (s *State) GetCandidateByPublicKey(publicKey string) *Candidate
- func (s *State) GetCandidates(state CandidateState) []*Candidate
- func (s *State) IsCRTransaction(tx *types.Transaction) bool
- func (s *State) ProcessBlock(block *types.Block, confirm *payload.Confirm)
- func (s *State) ProcessReturnDepositTxs(block *types.Block)
- func (s *State) RollbackTo(height uint32) error
- type StateKeyFrame
Constants ¶
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.
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.
type Candidate ¶
type Candidate struct {
// contains filtered or unexported fields
}
Candidate defines information about CR candidates during the CR vote period
func (*Candidate) CancelHeight ¶
RegisterHeight returns the height when the CR was unregistered.
func (*Candidate) DepositAmount ¶
DepositAmount returns the deposit amount of the CR.
func (*Candidate) RegisterHeight ¶
RegisterHeight returns the height when the CR was registered.
func (*Candidate) State ¶
func (c *Candidate) State() CandidateState
State returns the CR's state, can be pending, active, canceled or returned.
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) 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 (*Committee) GetMembersCIDs ¶ added in v0.4.2
func (*Committee) GetMembersCodes ¶
func (*Committee) IsInVotingPeriod ¶
func (*Committee) ProcessBlock ¶
func (*Committee) Recover ¶
func (c *Committee) Recover(checkpoint *Checkpoint)
func (*Committee) RollbackTo ¶
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 ¶
StateKeyFrame holds necessary state about CR committee.
func NewKeyFrame ¶
func NewKeyFrame() *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 (*State) ExistCandidate ¶
ExistCandidate judges if there is a candidate with specified program code.
func (*State) ExistCandidateByCID ¶ added in v0.4.2
ExistCandidateByCID judges if there is a candidate with specified did.
func (*State) ExistCandidateByDepositHash ¶
ExistCandidateByDepositHash judges if there is a candidate with deposit hash.
func (*State) ExistCandidateByNickname ¶
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 ¶
GetAllCandidates returns all candidates holding within state.
func (*State) GetCandidate ¶
GetCandidate returns candidate with specified program code, it will return nil if not found.
func (*State) GetCandidateByCID ¶ added in v0.4.2
GetCandidateByCID returns candidate with specified cid, it will return nil if not found.
func (*State) GetCandidateByID ¶ added in v0.4.2
GetCandidateByID returns candidate with specified cid or did, it will return nil if not found.
func (*State) GetCandidateByPublicKey ¶ added in v0.4.2
GetCandidateByPublicKey returns candidate with specified public key, it will return 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 ¶
ProcessBlock takes a block and it's confirm to update CR state and votes accordingly.
func (*State) ProcessReturnDepositTxs ¶
ProcessBlock takes a block and it's confirm to update CR state and votes accordingly.
func (*State) RollbackTo ¶
RollbackTo restores the database state to the given height, if no enough history to rollback to return error.
type StateKeyFrame ¶
type StateKeyFrame struct { CodeCIDMap 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) Snapshot ¶
func (k *StateKeyFrame) Snapshot() *StateKeyFrame
Snapshot will create a new StateKeyFrame object and deep copy all related data.