state

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2019 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

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 NewArbitrators

func NewArbitrators(chainParams *config.Params, bestHeight func() uint32) (*arbitrators, error)

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 Arbitrators

type Arbitrators interface {
	ProcessBlock(block *types.Block, confirm *payload.Confirm)
	ProcessSpecialTxPayload(p types.Payload, height uint32) error
	RollbackTo(height uint32) error

	IsArbitrator(pk []byte) bool
	GetArbitrators() [][]byte
	GetCandidates() [][]byte
	GetNextArbitrators() [][]byte
	GetNextCandidates() [][]byte
	GetNeedConnectArbiters(height uint32) map[string]*p2p.PeerAddr
	GetDutyIndexByHeight(height uint32) int
	GetDutyIndex() int

	GetCRCProducer(publicKey []byte) *Producer
	GetCRCArbitrators() map[string]*Producer
	IsCRCArbitrator(pk []byte) bool
	IsCRCArbitratorProgramHash(hash *common.Uint168) bool
	IsCRCArbitratorNodePublicKey(nodePublicKeyHex string) bool

	GetCurrentOwnerProgramHashes() []*common.Uint168
	GetCandidateOwnerProgramHashes() []*common.Uint168
	GetOwnerVotes(programHash *common.Uint168) common.Fixed64
	GetTotalVotesInRound() common.Fixed64

	GetOnDutyArbitrator() []byte
	GetNextOnDutyArbitrator(offset uint32) []byte

	GetArbitersCount() int
	GetArbitersMajorityCount() int
	HasArbitersMajorityCount(num int) bool
	HasArbitersMinorityCount(num int) bool

	DumpInfo()
}

type ArbitratorsMock

type ArbitratorsMock struct {
	CurrentArbitrators          [][]byte
	CurrentCandidates           [][]byte
	NextArbitrators             [][]byte
	NextCandidates              [][]byte
	CurrentOwnerProgramHashes   []*common.Uint168
	CandidateOwnerProgramHashes []*common.Uint168
	OwnerVotesInRound           map[common.Uint168]common.Fixed64
	TotalVotesInRound           common.Fixed64
	DutyChangedCount            int
	MajorityCount               int
}

mock object of arbitrators

func NewArbitratorsMock

func NewArbitratorsMock(arbitersByte [][]byte, changeCount, majorityCount int) *ArbitratorsMock

func (*ArbitratorsMock) DumpInfo

func (a *ArbitratorsMock) DumpInfo()

func (*ArbitratorsMock) GetArbitersCount

func (a *ArbitratorsMock) GetArbitersCount() int

func (*ArbitratorsMock) GetArbitersMajorityCount

func (a *ArbitratorsMock) GetArbitersMajorityCount() int

func (*ArbitratorsMock) GetArbitrators

func (a *ArbitratorsMock) GetArbitrators() [][]byte

func (*ArbitratorsMock) GetCRCArbitrators

func (a *ArbitratorsMock) GetCRCArbitrators() map[string]*Producer

func (*ArbitratorsMock) GetCRCProducer

func (a *ArbitratorsMock) GetCRCProducer(publicKey []byte) *Producer

func (*ArbitratorsMock) GetCandidateOwnerProgramHashes

func (a *ArbitratorsMock) GetCandidateOwnerProgramHashes() []*common.Uint168

func (*ArbitratorsMock) GetCandidates

func (a *ArbitratorsMock) GetCandidates() [][]byte

func (*ArbitratorsMock) GetCurrentOwnerProgramHashes

func (a *ArbitratorsMock) GetCurrentOwnerProgramHashes() []*common.Uint168

func (*ArbitratorsMock) GetDutyChangeCount

func (a *ArbitratorsMock) GetDutyChangeCount() int

func (*ArbitratorsMock) GetDutyChangedCount

func (a *ArbitratorsMock) GetDutyChangedCount() int

func (*ArbitratorsMock) GetDutyIndex

func (a *ArbitratorsMock) GetDutyIndex() int

func (*ArbitratorsMock) GetDutyIndexByHeight

func (a *ArbitratorsMock) GetDutyIndexByHeight(height uint32) int

func (*ArbitratorsMock) GetLastConfirmedBlockTimeStamp

func (a *ArbitratorsMock) GetLastConfirmedBlockTimeStamp() uint32

func (*ArbitratorsMock) GetNeedConnectArbiters

func (a *ArbitratorsMock) GetNeedConnectArbiters(height uint32) map[string]*p2p.PeerAddr

func (*ArbitratorsMock) GetNextArbitrators

func (a *ArbitratorsMock) GetNextArbitrators() [][]byte

func (*ArbitratorsMock) GetNextCandidates

func (a *ArbitratorsMock) GetNextCandidates() [][]byte

func (*ArbitratorsMock) GetNextOnDutyArbitrator

func (a *ArbitratorsMock) GetNextOnDutyArbitrator(offset uint32) []byte

func (*ArbitratorsMock) GetNormalArbitrators

func (a *ArbitratorsMock) GetNormalArbitrators() ([][]byte, error)

func (*ArbitratorsMock) GetOnDutyArbitrator

func (a *ArbitratorsMock) GetOnDutyArbitrator() []byte

func (*ArbitratorsMock) GetOwnerVotes

func (a *ArbitratorsMock) GetOwnerVotes(programHash *common.Uint168) common.Fixed64

func (*ArbitratorsMock) GetTotalVotesInRound

func (a *ArbitratorsMock) GetTotalVotesInRound() common.Fixed64

func (*ArbitratorsMock) HasArbitersMajorityCount

func (a *ArbitratorsMock) HasArbitersMajorityCount(num int) bool

func (*ArbitratorsMock) HasArbitersMinorityCount

func (a *ArbitratorsMock) HasArbitersMinorityCount(num int) bool

func (*ArbitratorsMock) IsArbitrator

func (a *ArbitratorsMock) IsArbitrator(pk []byte) bool

func (*ArbitratorsMock) IsCRCArbitrator

func (a *ArbitratorsMock) IsCRCArbitrator(pk []byte) bool

func (*ArbitratorsMock) IsCRCArbitratorNodePublicKey

func (a *ArbitratorsMock) IsCRCArbitratorNodePublicKey(nodePublicKeyHex string) bool

func (*ArbitratorsMock) IsCRCArbitratorProgramHash

func (a *ArbitratorsMock) IsCRCArbitratorProgramHash(hash *common.Uint168) bool

func (*ArbitratorsMock) ProcessBlock

func (a *ArbitratorsMock) ProcessBlock(block *types.Block, confirm *payload.Confirm)

func (*ArbitratorsMock) ProcessSpecialTxPayload

func (a *ArbitratorsMock) ProcessSpecialTxPayload(p types.Payload, height uint32) error

func (*ArbitratorsMock) RollbackTo

func (a *ArbitratorsMock) RollbackTo(height uint32) error

func (*ArbitratorsMock) SetArbitrators

func (a *ArbitratorsMock) SetArbitrators(ar [][]byte)

func (*ArbitratorsMock) SetCandidates

func (a *ArbitratorsMock) SetCandidates(ca [][]byte)

func (*ArbitratorsMock) SetDutyChangeCount

func (a *ArbitratorsMock) SetDutyChangeCount(count int)

func (*ArbitratorsMock) SetDutyChangedCount

func (a *ArbitratorsMock) SetDutyChangedCount(count int)

func (*ArbitratorsMock) SetNextArbitrators

func (a *ArbitratorsMock) SetNextArbitrators(ar [][]byte)

func (*ArbitratorsMock) SetNextCandidates

func (a *ArbitratorsMock) SetNextCandidates(ca [][]byte)

func (*ArbitratorsMock) TryEnterEmergency

func (a *ArbitratorsMock) TryEnterEmergency(blockTime uint32) bool

type ChangeType

type ChangeType byte

type Producer

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

Producer holds a producer's info. It provides read only methods to access producer's info.

func (*Producer) CancelHeight

func (p *Producer) CancelHeight() uint32

CancelHeight returns the height when the producer was canceled.

func (*Producer) IllegalHeight

func (p *Producer) IllegalHeight() uint32

func (*Producer) InactiveSince

func (p *Producer) InactiveSince() uint32

func (*Producer) Info

func (p *Producer) Info() payload.ProducerInfo

Info returns a copy of the origin registered producer info.

func (*Producer) NodePublicKey

func (p *Producer) NodePublicKey() []byte

func (*Producer) OwnerPublicKey

func (p *Producer) OwnerPublicKey() []byte

func (*Producer) Penalty

func (p *Producer) Penalty() common.Fixed64

func (*Producer) RegisterHeight

func (p *Producer) RegisterHeight() uint32

RegisterHeight returns the height when the producer was registered.

func (*Producer) State

func (p *Producer) State() ProducerState

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

func (*Producer) Votes

func (p *Producer) Votes() common.Fixed64

Votes returns the votes of the producer.

type ProducerState

type ProducerState byte

ProducerState represents the state of a producer.

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

	// Activate indicates the producer is registered and confirmed by more than
	// 6 blocks.
	Activate

	// Inactivate indicates the producer has been inactive for a period which shall
	// be punished and will be activate later
	Inactivate

	// Canceled indicates the producer was canceled.
	Canceled

	// FoundBad indicates the producer was found doing bad.
	FoundBad

	// ReturnedDeposit indicates the producer has canceled and returned deposit
	ReturnedDeposit
)

func (ProducerState) String

func (ps ProducerState) String() string

type State

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

State is a memory database storing DPOS producers state, like pending producers active producers and their votes.

func NewState

func NewState(chainParams *config.Params, getArbiters func() [][]byte) *State

NewState returns a new State instance.

func (*State) GetActiveProducers

func (s *State) GetActiveProducers() []*Producer

GetActiveProducers returns all producers that in active state.

func (*State) GetCanceledProducers

func (s *State) GetCanceledProducers() []*Producer

GetCanceledProducers returns all producers that in cancel state.

func (*State) GetHistory

func (s *State) GetHistory(height uint32) (*State, error)

GetHistory returns a history state instance storing the producers and votes on the historical height.

func (*State) GetIllegalProducers

func (s *State) GetIllegalProducers() []*Producer

GetIllegalProducers returns all illegal producers.

func (*State) GetInactiveProducers

func (s *State) GetInactiveProducers() []*Producer

func (*State) GetPendingProducers

func (s *State) GetPendingProducers() []*Producer

GetPendingProducers returns all producers that in pending state.

func (*State) GetProducer

func (s *State) GetProducer(publicKey []byte) *Producer

GetProducer returns a producer with the producer's node public key or it's owner public key including canceled and illegal producers. If no matches return nil.

func (*State) GetProducers

func (s *State) GetProducers() []*Producer

GetProducers returns all producers including pending and active producers (no canceled and illegal producers).

func (*State) GetSnapshot

func (s *State) GetSnapshot(height uint32) *State

GetSnapshot returns a snapshot of the state according to the given height.

func (*State) IsActiveProducer

func (s *State) IsActiveProducer(publicKey []byte) bool

IsActiveProducer returns if a producer is in activate list according to the public key.

func (*State) IsCanceledProducer

func (s *State) IsCanceledProducer(publicKey []byte) bool

IsCanceledProducer returns if a producer is in canceled list according to the public key.

func (*State) IsDPOSTransaction

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

IsDPOSTransaction returns if a transaction will change the producers and votes state.

func (*State) IsIllegalProducer

func (s *State) IsIllegalProducer(publicKey []byte) bool

IsIllegalProducer returns if a producer is in illegal list according to the public key.

func (*State) IsInactiveProducer

func (s *State) IsInactiveProducer(publicKey []byte) bool

IsInactiveProducer returns if a producer is in inactivate list according to the public key.

func (*State) IsPendingProducer

func (s *State) IsPendingProducer(publicKey []byte) bool

IsPendingProducer returns if a producer is in pending list according to the public key.

func (*State) NicknameExists

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

NicknameExists returns if a nickname is exists.

func (*State) ProcessBlock

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

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

func (*State) ProcessSpecialTxPayload

func (s *State) ProcessSpecialTxPayload(p types.Payload)

ProcessIllegalBlockEvidence takes a illegal block payload and change the producers state immediately. This is a spacial case that can be handled before it packed into a block.

func (*State) ProducerExists

func (s *State) ProducerExists(publicKey []byte) bool

ProducerExists returns if a producer is exists by it's node public key or owner public key.

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.

func (*State) SpecialTxExists

func (s *State) SpecialTxExists(hash *common.Uint256) bool

SpecialTxExists returns if a special tx (typically means illegal and inactive tx) is exists by it's hash

Jump to

Keyboard shortcuts

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