state

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: May 22, 2020 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MinDepositAmount is the minimum deposit as a producer.
	MinDepositAmount = 5000 * 100000000

	// ActivateDuration is about how long we should activate from pending or
	// inactive state.
	ActivateDuration = 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 BudgetStatus

type BudgetStatus uint8
const (
	// Unfinished indicates the proposal owner haven't started or uploaded the
	// status of the budget to CR Council.
	Unfinished BudgetStatus = iota

	// Withdrawable indicates the proposal owner have finished the milestone,
	// but haven't get the payment.
	Withdrawable

	// Withdrawn indicates the proposal owner have finished the milestone and
	// got the payment.
	Withdrawn

	// Rejected indicates the proposal owner have uploaded the status to CR
	// Council but the secretary-general rejected my request.
	Rejected

	// Closed indicates the proposal has been terminated and the milestone will
	// not be finished forever.
	Closed
)

func (*BudgetStatus) Name

func (s *BudgetStatus) Name() string

type CRMember

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

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) 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) 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) AvailableWithdrawalAmount

func (c *Committee) AvailableWithdrawalAmount(hash common.Uint256) common.Fixed64

func (*Committee) Exist

func (c *Committee) Exist(cid common.Uint168) bool

func (*Committee) ExistCR

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

func (*Committee) ExistCandidateByDepositHash

func (c *Committee) ExistCandidateByDepositHash(hash common.Uint168) bool

func (*Committee) ExistCandidateByNickname

func (c *Committee) ExistCandidateByNickname(nickname string) bool

func (*Committee) ExistDraft

func (c *Committee) ExistDraft(hash common.Uint256) bool

func (*Committee) ExistProposal

func (c *Committee) ExistProposal(hash common.Uint256) bool

func (*Committee) GetAllCandidates

func (c *Committee) GetAllCandidates() []*Candidate

func (*Committee) GetAllHistoryMembers

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

get all history CRMembers

func (*Committee) GetAllMembers

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

get all CRMembers ordered by CID

func (*Committee) GetAllProposals

func (c *Committee) GetAllProposals() ProposalsMap

func (*Committee) GetAvailableDepositAmount

func (c *Committee) GetAvailableDepositAmount(cid common.Uint168) common.Fixed64

func (*Committee) GetCandidate

func (c *Committee) GetCandidate(cid common.Uint168) *Candidate

func (*Committee) GetCandidateByCID

func (c *Committee) GetCandidateByCID(cid common.Uint168) *Candidate

GetCandidateByCID returns candidate with specified cid, it will return nil if not found.

func (*Committee) GetCandidateByID

func (c *Committee) GetCandidateByID(id common.Uint168) *Candidate

GetCandidateByID returns candidate with specified cid or did, it will return nil if not found.

func (*Committee) GetCandidateByPublicKey

func (c *Committee) GetCandidateByPublicKey(publicKey string) *Candidate

GetCandidateByPublicKey returns candidate with specified public key, it will return nil if not found.

func (*Committee) GetCandidates

func (c *Committee) GetCandidates(state CandidateState) []*Candidate

func (*Committee) GetDepositAmountByID

func (c *Committee) GetDepositAmountByID(
	id common.Uint168) (common.Fixed64, common.Fixed64, error)

func (*Committee) GetDepositAmountByPublicKey

func (c *Committee) GetDepositAmountByPublicKey(
	publicKey string) (common.Fixed64, common.Fixed64, error)

func (*Committee) GetElectedMembers

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

get all elected CRMembers

func (*Committee) GetImpeachableMembers

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

get all impeachable CRMembers

func (*Committee) GetMember

func (c *Committee) GetMember(did common.Uint168) *CRMember

func (*Committee) GetMembersCodes

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

func (*Committee) GetMembersDIDs

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

func (*Committee) GetPenalty

func (c *Committee) GetPenalty(cid common.Uint168) common.Fixed64

func (*Committee) GetProposal

func (c *Committee) GetProposal(hash common.Uint256) *ProposalState

func (*Committee) GetProposalByDraftHash

func (c *Committee) GetProposalByDraftHash(draftHash common.Uint256) *ProposalState

func (*Committee) GetProposalManager deprecated

func (c *Committee) GetProposalManager() *ProposalManager

Deprecated: just for testing

func (*Committee) GetProposals

func (c *Committee) GetProposals(status ProposalStatus) ProposalsMap

func (*Committee) GetState deprecated

func (c *Committee) GetState() *State

Deprecated: just for testing

func (*Committee) IsAppropriationNeeded

func (c *Committee) IsAppropriationNeeded() bool

func (*Committee) IsCRMember

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

func (*Committee) IsCRMemberByDID

func (c *Committee) IsCRMemberByDID(did common.Uint168) bool

func (*Committee) IsInElectionPeriod

func (c *Committee) IsInElectionPeriod() bool

func (*Committee) IsInVotingPeriod

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

func (*Committee) IsProposalAllowed

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

func (*Committee) IsProposalFull

func (c *Committee) IsProposalFull(did common.Uint168) bool

func (*Committee) IsRefundable

func (c *Committee) IsRefundable(cid common.Uint168) 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) RegisterFuncitons

func (c *Committee) RegisterFuncitons(cfg *CommitteeFuncsConfig)

func (*Committee) RollbackTo

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

func (*Committee) Snapshot

func (c *Committee) Snapshot() *CommitteeKeyFrame

type CommitteeFuncsConfig

type CommitteeFuncsConfig struct {
	GetTxReference func(tx *types.Transaction) (
		map[*types.Input]types.Output, error)
	GetHeight                        func() uint32
	CreateCRAppropriationTransaction func() (*types.Transaction, error)
	IsCurrent                        func() bool
	Broadcast                        func(msg p2p.Message)
	AppendToTxpool                   func(transaction *types.Transaction) elaerr.ELAError
	GetUTXO                          func(programHash *common.Uint168) ([]*types.UTXO, error)
}

type CommitteeKeyFrame

type CommitteeKeyFrame struct {
	*KeyFrame
	*StateKeyFrame
	*ProposalKeyFrame
}

type DepositInfo

type DepositInfo struct {
	Refundable    bool
	DepositAmount common.Fixed64
	Penalty       common.Fixed64
	TotalAmount   common.Fixed64
}

func (*DepositInfo) Deserialize

func (d *DepositInfo) Deserialize(r io.Reader) (err error)

func (*DepositInfo) Serialize

func (d *DepositInfo) Serialize(w io.Writer) (err error)

type FunctionsConfig

type FunctionsConfig struct {
	GetHistoryMember func(code []byte) []*CRMember
	GetTxReference   func(tx *types.Transaction) (
		map[*types.Input]types.Output, 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                    map[common.Uint168]*CRMember
	HistoryMembers             map[uint64]map[common.Uint168]*CRMember
	LastCommitteeHeight        uint32
	LastVotingStartHeight      uint32
	InElectionPeriod           bool
	NeedAppropriation          bool
	CRCFoundationLockedAmounts []common.Fixed64
	CRCFoundationBalance       common.Fixed64
	CRCCommitteeBalance        common.Fixed64
	CRCCommitteeUsedAmount     common.Fixed64
	CRCCurrentStageAmount      common.Fixed64
	DestroyedAmount            common.Fixed64
	CirculationAmount          common.Fixed64
	AppropriationAmount        common.Fixed64
}

StateKeyFrame holds necessary state about CR committee.

func NewKeyFrame

func NewKeyFrame() *KeyFrame

func (*KeyFrame) Deserialize

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

func (*KeyFrame) Serialize

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

func (*KeyFrame) Snapshot

func (kf *KeyFrame) Snapshot() *KeyFrame

type MemberState

type MemberState byte

MemberState defines states during a CR member lifetime

const (
	// MemberElected indicates the CR member is Elected.
	MemberElected MemberState = iota

	// MemberImpeached indicates the CR member was impeached.
	MemberImpeached

	// MemberTerminated indicates the CR member was terminated because elected
	// CR members are not enough.
	MemberTerminated

	// MemberReturned indicates the CR member has deposit returned.
	MemberReturned
)

func (*MemberState) String

func (s *MemberState) String() string

type ProposalHashSet

type ProposalHashSet map[common.Uint256]struct{}

func NewProposalHashSet

func NewProposalHashSet() ProposalHashSet

func (*ProposalHashSet) Add

func (set *ProposalHashSet) Add(proposalHash common.Uint256) bool

func (*ProposalHashSet) Clear

func (set *ProposalHashSet) Clear()

func (*ProposalHashSet) Contains

func (set *ProposalHashSet) Contains(proposalHash common.Uint256) bool

func (*ProposalHashSet) Equal

func (set *ProposalHashSet) Equal(other ProposalHashSet) bool

func (*ProposalHashSet) Len

func (set *ProposalHashSet) Len() int

func (*ProposalHashSet) Remove

func (set *ProposalHashSet) Remove(proposalHash common.Uint256)

type ProposalKeyFrame

type ProposalKeyFrame struct {
	Proposals ProposalsMap
	//key is did value is proposalhash set
	ProposalHashes  map[common.Uint168]ProposalHashSet
	ProposalSession map[uint64][]common.Uint256
}

ProposalKeyFrame holds all runtime state about CR proposals.

func NewProposalKeyFrame

func NewProposalKeyFrame() *ProposalKeyFrame

func (*ProposalKeyFrame) Deserialize

func (p *ProposalKeyFrame) Deserialize(r io.Reader) (err error)

func (*ProposalKeyFrame) Serialize

func (p *ProposalKeyFrame) Serialize(w io.Writer) (err error)

func (*ProposalKeyFrame) Snapshot

func (p *ProposalKeyFrame) Snapshot() *ProposalKeyFrame

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

type ProposalManager

type ProposalManager struct {
	ProposalKeyFrame
	// contains filtered or unexported fields
}

ProposalManager used to manage all proposals existing in block chain.

func NewProposalManager

func NewProposalManager(params *config.Params) *ProposalManager

type ProposalState

type ProposalState struct {
	Status   ProposalStatus
	Proposal payload.CRCProposal
	TxHash   common.Uint256

	CRVotes            map[common.Uint168]payload.VoteResult
	VotersRejectAmount common.Fixed64
	RegisterHeight     uint32
	VoteStartHeight    uint32

	WithdrawnBudgets    map[uint8]common.Fixed64 // proposalWithdraw
	WithdrawableBudgets map[uint8]common.Fixed64 // proposalTracking
	BudgetsStatus       map[uint8]BudgetStatus
	FinalPaymentStatus  bool

	TrackingCount    uint8
	TerminatedHeight uint32
	ProposalOwner    []byte
}

ProposalState defines necessary state about an CR proposals.

func (*ProposalState) Deserialize

func (p *ProposalState) Deserialize(r io.Reader) (err error)

func (*ProposalState) Serialize

func (p *ProposalState) Serialize(w io.Writer) (err error)

type ProposalStatus

type ProposalStatus uint8
const (
	// Registered is the status means the CRC proposal tx has been on the best
	//	chain.
	Registered ProposalStatus = 0x00

	// CRAgreed means CRC has agreed the proposal.
	CRAgreed ProposalStatus = 0x01

	// VoterAgreed means there are not enough negative vote about the proposal.
	VoterAgreed ProposalStatus = 0x02

	// Finished means the proposal has run out the lifetime.
	Finished ProposalStatus = 0x03

	// CRCanceled means the proposal canceled by CRC voting.
	CRCanceled ProposalStatus = 0x04

	// VoterCanceled means the proposal canceled by voters' reject voting.
	VoterCanceled ProposalStatus = 0x05

	// Terminated means proposal had been approved by both CR and voters,
	// whoever the proposal related project has been decided to terminate for
	// some reason.
	Terminated ProposalStatus = 0x06

	// Aborted means the proposal was cancelled because of a snap election.
	Aborted ProposalStatus = 0x07
)

func (ProposalStatus) String

func (status ProposalStatus) String() string

type ProposalsMap

type ProposalsMap map[common.Uint256]*ProposalState

func NewProposalMap

func NewProposalMap() ProposalsMap

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) ExistCandidateByCID

func (s *State) ExistCandidateByCID(cid common.Uint168) (ok bool)

ExistCandidateByCID judges if there is a candidate with specified cid.

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) SetManager

func (s *State) SetManager(manager *ProposalManager)

SetManager set current proposal manager that holds state of proposals.

type StateKeyFrame

type StateKeyFrame struct {
	CodeCIDMap        map[string]common.Uint168
	DepositHashCIDMap map[common.Uint168]common.Uint168
	Candidates        map[common.Uint168]*Candidate
	HistoryCandidates map[uint64]map[common.Uint168]*Candidate

	CurrentSession       uint64
	Nicknames            map[string]struct{}
	Votes                map[string]struct{}
	DepositOutputs       map[string]common.Fixed64
	CRCFoundationOutputs map[string]common.Fixed64
	CRCCommitteeOutputs  map[string]common.Fixed64
	// contains filtered or unexported fields
}

StateKeyFrame holds necessary state about CR state.

func NewStateKeyFrame

func NewStateKeyFrame() *StateKeyFrame

func (*StateKeyFrame) Deserialize

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

func (*StateKeyFrame) DeserializeFixed64Map

func (kf *StateKeyFrame) DeserializeFixed64Map(
	r io.Reader) (vmap map[string]common.Fixed64, err error)

func (*StateKeyFrame) Serialize

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

func (*StateKeyFrame) SerializeFixed64Map

func (kf *StateKeyFrame) SerializeFixed64Map(w io.Writer,
	vmap map[string]common.Fixed64) (err error)

func (*StateKeyFrame) Snapshot

func (kf *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