state

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2021 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MajoritySignRatioNumerator defines the ratio numerator to achieve
	// majority signatures.
	MajoritySignRatioNumerator = float64(2)

	// MajoritySignRatioDenominator defines the ratio denominator to achieve
	// majority signatures.
	MajoritySignRatioDenominator = float64(3)

	// MaxNormalInactiveChangesCount defines the max count arbitrators can
	// change when more than 1/3 arbiters don't sign cause to confirm fail
	MaxNormalInactiveChangesCount = 3

	// MaxSnapshotLength defines the max length the snapshot map should take
	MaxSnapshotLength = 20
)
View Source
const (
	// CheckpointKey defines key of DPoS checkpoint.
	CheckpointKey = "cp_dpos"

	// CheckPointInterval defines interval height between two neighbor check
	// points.
	CheckPointInterval = uint32(720)
)
View Source
const (
	DSNormal       degradationState = 0x00
	DSUnderstaffed degradationState = 0x01
	DSInactive     degradationState = 0x02
)
View Source
const (

	// ActivateDuration is about how long we should activate from pending or
	// inactive state
	ActivateDuration = 6
)
View Source
const CacheVotesSize = 6

CacheVotesSize indicate the size to cache votes information.

View Source
const IrreversibleHeight = 6

IrreversibleHeight defines the max height that the chain be reorganized

Variables

View Source
var (
	ErrInsufficientProducer = errors.New("producers count less than min arbitrators count")
)

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, committee *state.Committee,
	getProducerDepositAmount func(common.Uint168) (common.Fixed64, error),
	tryUpdateCRMemberInactivity func(did common.Uint168, needReset bool, height uint32),
	tryRevertCRMemberInactivityfunc func(did common.Uint168, oriState state.MemberState, oriInactiveCount uint32, height uint32),
	tryUpdateCRMemberIllegal func(did common.Uint168, height uint32),
	tryRevertCRMemberIllegal func(did common.Uint168, oriState state.MemberState, height uint32)) (
	*arbitrators, error)

func SerializeArbiterMember added in v0.5.0

func SerializeArbiterMember(ar ArbiterMember, w io.Writer) (err 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 ArbiterInfo added in v0.7.0

type ArbiterInfo struct {
	NodePublicKey   []byte
	IsNormal        bool
	IsCRMember      bool
	ClaimedDPOSNode bool
}

type ArbiterMember added in v0.5.0

type ArbiterMember interface {
	common.Serializable
	GetType() ArbiterType

	GetOwnerPublicKey() []byte
	GetOwnerProgramHash() common.Uint168

	GetNodePublicKey() []byte
	Clone() ArbiterMember

	IsNormal() bool
}

func ArbiterMemberFromReader added in v0.5.0

func ArbiterMemberFromReader(r io.Reader) (result ArbiterMember, err error)

func NewCRCArbiter added in v0.5.0

func NewCRCArbiter(nodePK []byte, ownerPK []byte, cr *state.CRMember,
	isNormal bool) (ArbiterMember, error)

func NewDPoSArbiter added in v0.5.0

func NewDPoSArbiter(producer *Producer) (ArbiterMember, error)

func NewOriginArbiter added in v0.5.0

func NewOriginArbiter(key []byte) (ArbiterMember, error)

type ArbiterType added in v0.5.0

type ArbiterType uint8
const (
	Origin   ArbiterType = 0x00
	DPoS     ArbiterType = 0x01
	CROrigin ArbiterType = 0x02
	CRC      ArbiterType = 0x03
)

type Arbitrators

type Arbitrators interface {
	Start()
	CheckDPOSIllegalTx(block *types.Block) error
	ProcessSpecialTxPayload(p types.Payload, height uint32) error
	CheckCRCAppropriationTx(block *types.Block) error
	CheckNextTurnDPOSInfoTx(block *types.Block) error
	CheckCustomIDResultsTx(block *types.Block) error
	CheckRevertToDPOSTX(block *types.Block) error

	IsArbitrator(pk []byte) bool
	IsNextCRCArbitrator(pk []byte) bool
	IsMemberElectedNextCRCArbitrator(pk []byte) bool
	GetArbitrators() []*ArbiterInfo
	GetCandidates() [][]byte
	GetAllProducersPublicKey() []string
	GetNextArbitrators() []*ArbiterInfo
	GetNextCandidates() [][]byte
	GetNeedConnectArbiters() []peer.PID
	GetDutyIndexByHeight(height uint32) int
	GetDutyIndex() int

	GetCurrentRewardData() RewardData
	GetNextRewardData() RewardData
	GetArbitersRoundReward() map[common.Uint168]common.Fixed64
	GetFinalRoundChange() common.Fixed64
	SetNeedRevertToDPOSTX(need bool)
	IsInPOWMode() bool
	GetRevertToPOWBlockHeight() uint32
	GetLastBlockTimestamp() uint32
	IsInactiveMode() bool
	IsUnderstaffedMode() bool

	GetConnectedProducer(publicKey []byte) ArbiterMember
	GetCRCArbiters() []*ArbiterInfo
	GetNextCRCArbiters() [][]byte
	CRCProducerCount() int
	IsCRCArbitrator(pk []byte) bool
	IsActiveProducer(pk []byte) bool
	IsDisabledProducer(pk []byte) bool
	IsNeedNextTurnDPOSInfo() bool

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

	GetOnDutyCrossChainArbitrator() []byte
	GetCrossChainArbiters() []*ArbiterInfo
	GetCrossChainArbitersCount() int
	GetCrossChainArbitersMajorityCount() int

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

	GetSnapshot(height uint32) []*CheckPoint
	DumpInfo(height uint32)
}

type ArbitratorsMock

type ArbitratorsMock struct {
	CurrentArbitrators          []ArbiterMember
	CRCArbitrators              []ArbiterMember
	NextCRCArbitrators          []ArbiterMember
	CurrentCandidates           []ArbiterMember
	NextArbitrators             []ArbiterMember
	NextCandidates              []ArbiterMember
	CurrentOwnerProgramHashes   []*common.Uint168
	CandidateOwnerProgramHashes []*common.Uint168
	ArbitersRoundReward         map[common.Uint168]common.Fixed64
	OwnerVotesInRound           map[common.Uint168]common.Fixed64
	CRCArbitratorsMap           map[string]*Producer
	TotalVotesInRound           common.Fixed64
	DutyChangedCount            int
	MajorityCount               int
	FinalRoundChange            common.Fixed64
	LastBlockTimestamp          uint32
	InactiveMode                bool
	ActiveProducer              []ArbiterMember
	Snapshot                    []*CheckPoint
	CurrentReward               RewardData
	NextReward                  RewardData
}

mock object of arbitrators

func NewArbitratorsMock

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

func (*ArbitratorsMock) CRCProducerCount added in v0.5.0

func (a *ArbitratorsMock) CRCProducerCount() int

func (*ArbitratorsMock) CheckCRCAppropriationTx added in v0.5.0

func (a *ArbitratorsMock) CheckCRCAppropriationTx(block *types.Block) error

func (*ArbitratorsMock) CheckCustomIDResultsTx added in v0.7.0

func (a *ArbitratorsMock) CheckCustomIDResultsTx(block *types.Block) error

func (*ArbitratorsMock) CheckDPOSIllegalTx added in v0.3.2

func (a *ArbitratorsMock) CheckDPOSIllegalTx(block *types.Block) error

func (*ArbitratorsMock) CheckNextTurnDPOSInfoTx added in v0.7.0

func (a *ArbitratorsMock) CheckNextTurnDPOSInfoTx(block *types.Block) error

func (*ArbitratorsMock) CheckRevertToDPOSTX added in v0.7.0

func (a *ArbitratorsMock) CheckRevertToDPOSTX(block *types.Block) error

func (*ArbitratorsMock) DumpInfo

func (a *ArbitratorsMock) DumpInfo(height uint32)

func (*ArbitratorsMock) GetAllProducersPublicKey added in v0.7.0

func (a *ArbitratorsMock) GetAllProducersPublicKey() []string

func (*ArbitratorsMock) GetArbitersCount

func (a *ArbitratorsMock) GetArbitersCount() int

func (*ArbitratorsMock) GetArbitersMajorityCount

func (a *ArbitratorsMock) GetArbitersMajorityCount() int

func (*ArbitratorsMock) GetArbitersRoundReward added in v0.3.2

func (a *ArbitratorsMock) GetArbitersRoundReward() map[common.Uint168]common.Fixed64

func (*ArbitratorsMock) GetArbitrators

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

func (*ArbitratorsMock) GetCRCArbiters added in v0.3.2

func (a *ArbitratorsMock) GetCRCArbiters() []*ArbiterInfo

func (*ArbitratorsMock) GetCRCArbitersCount added in v0.3.2

func (a *ArbitratorsMock) GetCRCArbitersCount() int

func (*ArbitratorsMock) GetCandidates

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

func (*ArbitratorsMock) GetConnectedProducer added in v0.5.0

func (a *ArbitratorsMock) GetConnectedProducer(publicKey []byte) ArbiterMember

func (*ArbitratorsMock) GetCrossChainArbiters added in v0.3.2

func (a *ArbitratorsMock) GetCrossChainArbiters() []*ArbiterInfo

func (*ArbitratorsMock) GetCrossChainArbitersCount added in v0.3.2

func (a *ArbitratorsMock) GetCrossChainArbitersCount() int

func (*ArbitratorsMock) GetCrossChainArbitersMajorityCount added in v0.3.2

func (a *ArbitratorsMock) GetCrossChainArbitersMajorityCount() int

func (*ArbitratorsMock) GetCurrentRewardData added in v0.3.2

func (a *ArbitratorsMock) GetCurrentRewardData() RewardData

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(uint32) int

func (*ArbitratorsMock) GetFinalRoundChange added in v0.3.2

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

func (*ArbitratorsMock) GetLastBlockTimestamp added in v0.7.0

func (a *ArbitratorsMock) GetLastBlockTimestamp() uint32

func (*ArbitratorsMock) GetNeedConnectArbiters

func (a *ArbitratorsMock) GetNeedConnectArbiters() []peer.PID

func (*ArbitratorsMock) GetNextArbitrators

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

func (*ArbitratorsMock) GetNextCRCArbiters added in v0.7.0

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

func (*ArbitratorsMock) GetNextCandidates

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

func (*ArbitratorsMock) GetNextOnDutyArbitrator

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

func (*ArbitratorsMock) GetNextRewardData added in v0.3.2

func (a *ArbitratorsMock) GetNextRewardData() RewardData

func (*ArbitratorsMock) GetNormalArbitrators

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

func (*ArbitratorsMock) GetOnDutyArbitrator

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

func (*ArbitratorsMock) GetOnDutyCrossChainArbitrator added in v0.3.2

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

func (*ArbitratorsMock) GetRevertToPOWBlockHeight added in v0.7.0

func (a *ArbitratorsMock) GetRevertToPOWBlockHeight() uint32

func (*ArbitratorsMock) GetSnapshot added in v0.3.2

func (a *ArbitratorsMock) GetSnapshot(height uint32) []*CheckPoint

func (*ArbitratorsMock) HasArbitersMajorityCount

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

func (*ArbitratorsMock) HasArbitersMinorityCount

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

func (*ArbitratorsMock) IsActiveProducer added in v0.3.2

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

func (*ArbitratorsMock) IsArbitrator

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

func (*ArbitratorsMock) IsCRCArbitrator

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

func (*ArbitratorsMock) IsDisabledProducer added in v0.3.2

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

func (*ArbitratorsMock) IsInPOWMode added in v0.7.0

func (a *ArbitratorsMock) IsInPOWMode() bool

func (*ArbitratorsMock) IsInactiveMode added in v0.3.2

func (a *ArbitratorsMock) IsInactiveMode() bool

func (*ArbitratorsMock) IsMemberElectedNextCRCArbitrator added in v0.7.0

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

func (*ArbitratorsMock) IsNeedNextTurnDPOSInfo added in v0.7.0

func (a *ArbitratorsMock) IsNeedNextTurnDPOSInfo() bool

func (*ArbitratorsMock) IsNextCRCArbitrator added in v0.7.0

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

func (*ArbitratorsMock) IsUnderstaffedMode added in v0.3.2

func (a *ArbitratorsMock) IsUnderstaffedMode() bool

func (*ArbitratorsMock) ProcessSpecialTxPayload

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

func (*ArbitratorsMock) RecoverFromCheckPoints added in v0.3.2

func (a *ArbitratorsMock) RecoverFromCheckPoints(height uint32) (uint32, error)

func (*ArbitratorsMock) SetArbitrators

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

func (*ArbitratorsMock) SetCandidates

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

func (*ArbitratorsMock) SetDutyChangeCount

func (a *ArbitratorsMock) SetDutyChangeCount(count int)

func (*ArbitratorsMock) SetDutyChangedCount

func (a *ArbitratorsMock) SetDutyChangedCount(count int)

func (*ArbitratorsMock) SetNeedRevertToDPOSTX added in v0.7.0

func (a *ArbitratorsMock) SetNeedRevertToDPOSTX(need bool)

func (*ArbitratorsMock) SetNextArbitrators

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

func (*ArbitratorsMock) SetNextCandidates

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

func (*ArbitratorsMock) Start added in v0.3.2

func (a *ArbitratorsMock) Start()

type ChangeType

type ChangeType byte

type CheckPoint added in v0.3.2

type CheckPoint struct {
	StateKeyFrame
	Height                uint32
	DutyIndex             int
	CurrentArbitrators    []ArbiterMember
	NextArbitrators       []ArbiterMember
	NextCandidates        []ArbiterMember
	CurrentCandidates     []ArbiterMember
	CurrentReward         RewardData
	NextReward            RewardData
	CurrentCRCArbitersMap map[common.Uint168]ArbiterMember
	NextCRCArbitersMap    map[common.Uint168]ArbiterMember
	NextCRCArbiters       []ArbiterMember
	// contains filtered or unexported fields
}

CheckPoint defines all variables need record in database

func NewCheckpoint added in v0.5.0

func NewCheckpoint(ar *arbitrators) *CheckPoint

func (*CheckPoint) DataExtension added in v0.5.0

func (c *CheckPoint) DataExtension() string

func (*CheckPoint) Deserialize added in v0.5.0

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

Deserialize read data to reader

func (*CheckPoint) EffectivePeriod added in v0.5.0

func (c *CheckPoint) EffectivePeriod() uint32

func (*CheckPoint) Generator added in v0.5.0

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

func (*CheckPoint) GetHeight added in v0.5.0

func (c *CheckPoint) GetHeight() uint32

func (*CheckPoint) Key added in v0.5.0

func (c *CheckPoint) Key() string

func (*CheckPoint) LogError added in v0.5.0

func (c *CheckPoint) LogError(err error)

func (*CheckPoint) OnBlockSaved added in v0.5.0

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

func (*CheckPoint) OnInit added in v0.5.0

func (c *CheckPoint) OnInit()

func (*CheckPoint) OnRollbackSeekTo added in v0.8.0

func (c *CheckPoint) OnRollbackSeekTo(height uint32)

func (*CheckPoint) OnRollbackTo added in v0.5.0

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

func (*CheckPoint) Priority added in v0.5.0

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

func (*CheckPoint) SavePeriod added in v0.5.0

func (c *CheckPoint) SavePeriod() uint32

func (*CheckPoint) Serialize added in v0.5.0

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

Serialize write data to writer

func (*CheckPoint) SetHeight added in v0.5.0

func (c *CheckPoint) SetHeight(height uint32)

func (*CheckPoint) Snapshot added in v0.5.0

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

func (*CheckPoint) StartHeight added in v0.5.0

func (c *CheckPoint) StartHeight() uint32

type ConsesusAlgorithm added in v0.7.0

type ConsesusAlgorithm byte
const (
	DPOS ConsesusAlgorithm = 0x00
	POW  ConsesusAlgorithm = 0x01
)

type IArbitratorsRecord added in v0.3.2

type IArbitratorsRecord interface {
	GetHeightsDesc() ([]uint32, error)
	GetCheckPoint(height uint32) (*CheckPoint, error)
	SaveArbitersState(point *CheckPoint) error
}

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) ActivateRequestHeight added in v0.3.2

func (p *Producer) ActivateRequestHeight() uint32

func (*Producer) AvailableAmount added in v0.7.0

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

func (*Producer) CancelHeight

func (p *Producer) CancelHeight() uint32

CancelHeight returns the height when the producer was canceled.

func (*Producer) DepositAmount added in v0.5.0

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

func (*Producer) Deserialize added in v0.3.2

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

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) Serialize added in v0.3.2

func (p *Producer) Serialize(w io.Writer) error

func (*Producer) State

func (p *Producer) State() ProducerState

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

func (*Producer) TotalAmount added in v0.7.0

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

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

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

	// Inactive indicates the producer has been inactivated for a period which shall
	// be punished and will be activated later.
	Inactive

	// Canceled indicates the producer was canceled.
	Canceled

	// Illegal indicates the producer was found to break the consensus.
	Illegal

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

func (ProducerState) String

func (ps ProducerState) String() string

type RewardData added in v0.3.2

type RewardData struct {
	OwnerVotesInRound map[common.Uint168]common.Fixed64
	TotalVotesInRound common.Fixed64
}

RewardData defines variables to calculate reward of a round

func NewRewardData added in v0.3.2

func NewRewardData() *RewardData

func (*RewardData) Deserialize added in v0.3.2

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

func (*RewardData) Serialize added in v0.3.2

func (d *RewardData) Serialize(w io.Writer) error

type State

type State struct {
	*StateKeyFrame
	// 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() []*ArbiterInfo,
	getCRMembers func() []*state.CRMember,
	isInElectionPeriod func() bool,
	getProducerDepositAmount func(common.Uint168) (common.Fixed64, error),
	tryUpdateCRMemberInactivity func(did common.Uint168, needReset bool, height uint32),
	tryRevertCRMemberInactivityfunc func(did common.Uint168, oriState state.MemberState, oriInactiveCount uint32, height uint32),
	tryUpdateCRMemberIllegal func(did common.Uint168, height uint32),
	tryRevertCRMemberIllegal func(did common.Uint168, oriState state.MemberState, height uint32)) *State

NewState returns a new State instance.

func (*State) ExistProducerByDepositHash added in v0.5.0

func (s *State) ExistProducerByDepositHash(programHash common.Uint168) bool

func (*State) GetActiveProducers

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

GetActiveProducers returns all producers that in active state.

func (*State) GetAllProducers added in v0.3.2

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

GetAllProducers returns all producers including pending, active, canceled, illegal and inactive producers.

func (*State) GetAllProducersPublicKey added in v0.7.0

func (s *State) GetAllProducersPublicKey() []string

func (*State) GetCanceledProducers

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

GetCanceledProducers returns all producers that in cancel state.

func (*State) GetConsensusAlgorithm added in v0.7.0

func (s *State) GetConsensusAlgorithm() ConsesusAlgorithm

func (*State) GetHistory

func (s *State) GetHistory(height uint32) (*StateKeyFrame, 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

GetIllegalProducers returns all inactive producers.

func (*State) GetLastIrreversibleHeight added in v0.7.0

func (s *State) GetLastIrreversibleHeight() uint32

func (*State) GetPendingCanceledProducers added in v0.3.2

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

GetPendingCanceledProducers returns all producers that in pending canceled state.

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) GetReturnedDepositProducers added in v0.3.2

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

GetReturnedDepositProducers returns producers that in returned deposit state.

func (*State) GetVotedProducers added in v0.3.2

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

GetVotedProducers returns all producers that in active state with votes.

func (*State) IsAbleToRecoverFromInactiveMode added in v0.3.2

func (s *State) IsAbleToRecoverFromInactiveMode() bool

IsAbleToRecoverFromInactiveMode returns if most of the emergency arbiters have activated and able to work again

func (*State) IsAbleToRecoverFromUnderstaffedState added in v0.3.2

func (s *State) IsAbleToRecoverFromUnderstaffedState() bool

IsAbleToRecoverFromInactiveMode returns if there are enough active arbiters

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) IsIrreversible added in v0.7.0

func (s *State) IsIrreversible(curBlockHeight uint32, detachNodesLen int) bool

is this Height Irreversible

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) LeaveEmergency added in v0.3.2

func (s *State) LeaveEmergency(history *utils.History, height uint32)

LeaveEmergency will reset EmergencyInactiveArbiters variable

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, height uint32)

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) ProcessVoteStatisticsBlock added in v0.3.9

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

ProcessVoteStatisticsBlock deal with block with vote statistics error.

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) ProducerNodePublicKeyExists added in v0.3.2

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

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

func (*State) ProducerOwnerPublicKeyExists added in v0.3.2

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

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

func (*State) RemoveSpecialTx added in v0.7.0

func (s *State) RemoveSpecialTx(hash common.Uint256)

removeSpecialTx record hash of a special tx

func (*State) RollbackSeekTo added in v0.8.0

func (s *State) RollbackSeekTo(height uint32)

OnRollbackSeekTo restores the database state to the given height.

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(tx *types.Transaction) bool

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

type StateKeyFrame added in v0.3.2

type StateKeyFrame struct {
	NodeOwnerKeys            map[string]string // NodePublicKey as key, OwnerPublicKey as value
	PendingProducers         map[string]*Producer
	ActivityProducers        map[string]*Producer
	InactiveProducers        map[string]*Producer
	CanceledProducers        map[string]*Producer
	IllegalProducers         map[string]*Producer
	PendingCanceledProducers map[string]*Producer
	Votes                    map[string]struct{}
	DepositOutputs           map[string]common.Fixed64
	Nicknames                map[string]struct{}
	SpecialTxHashes          map[common.Uint256]struct{}
	PreBlockArbiters         map[string]struct{}
	ProducerDepositMap       map[common.Uint168]struct{}

	EmergencyInactiveArbiters map[string]struct{}
	LastRandomCandidateOwner  string
	VersionStartHeight        uint32
	VersionEndHeight          uint32
	LastRandomCandidateHeight uint32
	DPOSWorkHeight            uint32
	ConsensusAlgorithm        ConsesusAlgorithm
	LastBlockTimestamp        uint32
	NeedRevertToDPOSTX        bool
	NeedNextTurnDPOSInfo      bool
	NoProducers               bool
	NoClaimDPOSNode           bool
	//this height we receieved reverttopow tx and also it is pow work height
	RevertToPOWBlockHeight uint32
	//last irreversible height
	LastIrreversibleHeight uint32
	//record the height our consensus chang from pow into dpos.
	//when it is dpos and before RevertToPOWStartHeight  DPOSStartHeight is height - IrreversibleHeight
	DPOSStartHeight uint32
}

StateKeyFrame holds necessary state about State

func NewStateKeyFrame added in v0.5.0

func NewStateKeyFrame() *StateKeyFrame

func (*StateKeyFrame) Deserialize added in v0.3.2

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

func (*StateKeyFrame) DeserializeDIDSet added in v0.5.0

func (s *StateKeyFrame) DeserializeDIDSet(
	r io.Reader) (vmap map[common.Uint168]struct{}, err error)

func (*StateKeyFrame) DeserializeFixed64Map added in v0.5.0

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

func (*StateKeyFrame) DeserializeHashSet added in v0.3.2

func (s *StateKeyFrame) DeserializeHashSet(
	r io.Reader) (vmap map[common.Uint256]struct{}, err error)

func (*StateKeyFrame) DeserializeProducerMap added in v0.3.2

func (s *StateKeyFrame) DeserializeProducerMap(
	r io.Reader) (pmap map[string]*Producer, err error)

func (*StateKeyFrame) DeserializeStringMap added in v0.3.2

func (s *StateKeyFrame) DeserializeStringMap(
	r io.Reader) (smap map[string]string, err error)

func (*StateKeyFrame) DeserializeStringSet added in v0.3.2

func (s *StateKeyFrame) DeserializeStringSet(
	r io.Reader) (vmap map[string]struct{}, err error)

func (*StateKeyFrame) Serialize added in v0.3.2

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

func (*StateKeyFrame) SerializeDIDSet added in v0.5.0

func (s *StateKeyFrame) SerializeDIDSet(vmap map[common.Uint168]struct{},
	w io.Writer) (err error)

func (*StateKeyFrame) SerializeFixed64Map added in v0.5.0

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

func (*StateKeyFrame) SerializeHashSet added in v0.3.2

func (s *StateKeyFrame) SerializeHashSet(vmap map[common.Uint256]struct{},
	w io.Writer) (err error)

func (*StateKeyFrame) SerializeProducerMap added in v0.3.2

func (s *StateKeyFrame) SerializeProducerMap(pmap map[string]*Producer,
	w io.Writer) (err error)

func (*StateKeyFrame) SerializeStringMap added in v0.3.2

func (s *StateKeyFrame) SerializeStringMap(smap map[string]string,
	w io.Writer) (err error)

func (*StateKeyFrame) SerializeStringSet added in v0.3.2

func (s *StateKeyFrame) SerializeStringSet(vmap map[string]struct{},
	w io.Writer) (err error)

Jump to

Keyboard shortcuts

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