Documentation ¶
Index ¶
- Constants
- Variables
- func FromStakingKey(bs []byte) (common.Address, bool)
- func SetConsensusPolicy(chainCoord *common.Coordinate, pc *ConsensusPolicy)
- func ToAutoStakingKey(addr common.Address) []byte
- func ToStakingKey(addr common.Address) []byte
- type Consensus
- func (cs *Consensus) ApplyGenesis(ctd *data.ContextData) ([]byte, error)
- func (cs *Consensus) BlocksFromSameFormulator() uint32
- func (cs *Consensus) CandidateCount() int
- func (cs *Consensus) IsFormulator(Formulator common.Address, Publichash common.PublicHash) bool
- func (cs *Consensus) LoadFromSaveData(SaveData []byte) error
- func (cs *Consensus) ProcessContext(ctd *data.ContextData, HeaderHash hash.Hash256, bh *block.Header) ([]byte, error)
- func (cs *Consensus) RanksInMap(FormulatorMap map[common.Address]bool, Limit int) ([]*Rank, error)
- func (cs *Consensus) TopRank(TimeoutCount int) (*Rank, error)
- func (cs *Consensus) TopRankInMap(FormulatorMap map[common.Address]bool) (*Rank, int, error)
- type ConsensusPolicy
- type CreateAlpha
- func (tx *CreateAlpha) From() common.Address
- func (tx *CreateAlpha) Hash() hash.Hash256
- func (tx *CreateAlpha) IsUTXO() bool
- func (tx *CreateAlpha) MarshalJSON() ([]byte, error)
- func (tx *CreateAlpha) ReadFrom(r io.Reader) (int64, error)
- func (tx *CreateAlpha) Seq() uint64
- func (tx *CreateAlpha) WriteTo(w io.Writer) (int64, error)
- type CreateHyper
- func (tx *CreateHyper) From() common.Address
- func (tx *CreateHyper) Hash() hash.Hash256
- func (tx *CreateHyper) IsUTXO() bool
- func (tx *CreateHyper) MarshalJSON() ([]byte, error)
- func (tx *CreateHyper) ReadFrom(r io.Reader) (int64, error)
- func (tx *CreateHyper) Seq() uint64
- func (tx *CreateHyper) WriteTo(w io.Writer) (int64, error)
- type CreateOmega
- func (tx *CreateOmega) From() common.Address
- func (tx *CreateOmega) Hash() hash.Hash256
- func (tx *CreateOmega) IsUTXO() bool
- func (tx *CreateOmega) MarshalJSON() ([]byte, error)
- func (tx *CreateOmega) ReadFrom(r io.Reader) (int64, error)
- func (tx *CreateOmega) Seq() uint64
- func (tx *CreateOmega) WriteTo(w io.Writer) (int64, error)
- type CreateSigma
- func (tx *CreateSigma) From() common.Address
- func (tx *CreateSigma) Hash() hash.Hash256
- func (tx *CreateSigma) IsUTXO() bool
- func (tx *CreateSigma) MarshalJSON() ([]byte, error)
- func (tx *CreateSigma) ReadFrom(r io.Reader) (int64, error)
- func (tx *CreateSigma) Seq() uint64
- func (tx *CreateSigma) WriteTo(w io.Writer) (int64, error)
- type FormulationAccount
- type FormulationType
- type HyperPolicy
- type Rank
- func (rank *Rank) Clone() *Rank
- func (rank *Rank) Equal(b *Rank) bool
- func (rank *Rank) HashSpace() hash.Hash256
- func (rank *Rank) IsZero() bool
- func (rank *Rank) Key() string
- func (rank *Rank) Less(b *Rank) bool
- func (rank *Rank) Phase() uint32
- func (rank *Rank) ReadFrom(r io.Reader) (int64, error)
- func (rank *Rank) Score() uint64
- func (rank *Rank) Set(phase uint32, hashSpace hash.Hash256)
- func (rank *Rank) SetHashSpace(hashSpace hash.Hash256)
- func (rank *Rank) SetPhase(phase uint32)
- func (rank *Rank) String() string
- func (rank *Rank) WriteTo(w io.Writer) (int64, error)
- type Revoke
- type Staking
- func (tx *Staking) From() common.Address
- func (tx *Staking) Hash() hash.Hash256
- func (tx *Staking) IsUTXO() bool
- func (tx *Staking) MarshalJSON() ([]byte, error)
- func (tx *Staking) ReadFrom(r io.Reader) (int64, error)
- func (tx *Staking) Seq() uint64
- func (tx *Staking) WriteTo(w io.Writer) (int64, error)
- type StakingPolicy
- type Unstaking
- func (tx *Unstaking) From() common.Address
- func (tx *Unstaking) Hash() hash.Hash256
- func (tx *Unstaking) IsUTXO() bool
- func (tx *Unstaking) MarshalJSON() ([]byte, error)
- func (tx *Unstaking) ReadFrom(r io.Reader) (int64, error)
- func (tx *Unstaking) Seq() uint64
- func (tx *Unstaking) WriteTo(w io.Writer) (int64, error)
Constants ¶
const ( AlphaFormulatorType = FormulationType(1) SigmaFormulatorType = FormulationType(2) OmegaFormulatorType = FormulationType(3) HyperFormulatorType = FormulationType(4) )
formulator types
Variables ¶
var ( ErrInvalidSignerCount = errors.New("invalid signer count") ErrInvalidAccountSigner = errors.New("invalid account signer") ErrInvalidAccountType = errors.New("invalid account type") ErrInvalidKeyHashCount = errors.New("invalid key hash count") ErrInvalidSequence = errors.New("invalid sequence") ErrInsuffcientBalance = errors.New("insufficient balance") ErrInvalidToAddress = errors.New("invalid to address") ErrInvalidBlockHash = errors.New("invalid block hash") ErrInvalidPhase = errors.New("invalid phase") ErrExistAddress = errors.New("exist address") ErrExistAccountName = errors.New("exist account name") ErrInvalidAccountName = errors.New("invaild account name") ErrExceedCandidateCount = errors.New("exceed candidate count") ErrInsufficientCandidateCount = errors.New("insufficient candidate count") ErrInvalidMaxBlocksPerFormulator = errors.New("invalid max blocks per formulator") ErrInvalidHyperFormulationAddress = errors.New("invalid Hyper formulator address") ErrInsufficientStakingAmount = errors.New("insufficient staking amount") ErrExceedStakingAmount = errors.New("exceed staking amount") ErrCriticalStakingAmount = errors.New("critical staking amount") ErrInvalidStakingAddress = errors.New("invalid staking address") ErrInvalidStakingAmount = errors.New("invalid staking amount") ErrInvalidFormulatorCount = errors.New("invalid formulator count") ErrInsufficientFormulatorBlocks = errors.New("insufficient formulator blocks") ErrNotExistConsensusPolicy = errors.New("not exist formulator policy") ErrFormulatorCreationLimited = errors.New("formulator creation limited") )
consensus errors
var (
TagStaking = []byte{1, 0}
)
tags
Functions ¶
func FromStakingKey ¶
FromStakingKey returns the staking address if it is staking key
func SetConsensusPolicy ¶
func SetConsensusPolicy(chainCoord *common.Coordinate, pc *ConsensusPolicy)
func ToAutoStakingKey ¶
ToAutoStakingKey returns the auto staking key of the staking address
func ToStakingKey ¶
ToStakingKey returns the staking key of the staking address
Types ¶
type Consensus ¶
type Consensus struct { sync.Mutex ObserverKeyMap map[common.PublicHash]bool MaxBlocksPerFormulator uint32 FormulationAccountType account.Type // contains filtered or unexported fields }
Consensus supports the proof of formulation algorithm
func NewConsensus ¶
func NewConsensus(ObserverKeyMap map[common.PublicHash]bool, MaxBlocksPerFormulator uint32, FormulationAccountType account.Type) *Consensus
NewConsensus returns a Consensus
func (*Consensus) ApplyGenesis ¶
func (cs *Consensus) ApplyGenesis(ctd *data.ContextData) ([]byte, error)
ApplyGenesis initialize the consensus using the genesis context data
func (*Consensus) BlocksFromSameFormulator ¶
BlocksFromSameFormulator returns a number of blocks made from same formulator
func (*Consensus) CandidateCount ¶
CandidateCount returns a count of the rank table
func (*Consensus) IsFormulator ¶
IsFormulator returns the given information is correct or not
func (*Consensus) LoadFromSaveData ¶
LoadFromSaveData recover the status using the save data
func (*Consensus) ProcessContext ¶
func (cs *Consensus) ProcessContext(ctd *data.ContextData, HeaderHash hash.Hash256, bh *block.Header) ([]byte, error)
ProcessContext processes the consensus using the block and its context data
func (*Consensus) RanksInMap ¶
RanksInMap returns the ranks in the map
type ConsensusPolicy ¶
type ConsensusPolicy struct { RewardPerBlock *amount.Amount PayRewardEveryBlocks uint32 FormulatorCreationLimitHeight uint32 AlphaCreationAmount *amount.Amount AlphaEfficiency1000 uint32 AlphaUnlockRequiredBlocks uint32 SigmaRequiredAlphaBlocks uint32 SigmaRequiredAlphaCount uint32 SigmaEfficiency1000 uint32 SigmaUnlockRequiredBlocks uint32 OmegaRequiredSigmaBlocks uint32 OmegaRequiredSigmaCount uint32 OmegaEfficiency1000 uint32 OmegaUnlockRequiredBlocks uint32 HyperCreationAmount *amount.Amount HyperEfficiency1000 uint32 HyperUnlockRequiredBlocks uint32 StakingEfficiency1000 uint32 StakingUnlockRequiredBlocks uint32 }
ConsensusPolicy defines a staking policy user
func GetConsensusPolicy ¶
func GetConsensusPolicy(chainCoord *common.Coordinate) (*ConsensusPolicy, error)
func (*ConsensusPolicy) MarshalJSON ¶
func (pc *ConsensusPolicy) MarshalJSON() ([]byte, error)
MarshalJSON is a marshaler function
type CreateAlpha ¶
type CreateAlpha struct { transaction.Base Seq_ uint64 From_ common.Address Name string KeyHash common.PublicHash }
CreateAlpha is a consensus.CreateAlpha It is used to make formulation account
func (*CreateAlpha) From ¶
func (tx *CreateAlpha) From() common.Address
From returns the creator of the transaction
func (*CreateAlpha) Hash ¶
func (tx *CreateAlpha) Hash() hash.Hash256
Hash returns the hash value of it
func (*CreateAlpha) MarshalJSON ¶
func (tx *CreateAlpha) MarshalJSON() ([]byte, error)
MarshalJSON is a marshaler function
func (*CreateAlpha) ReadFrom ¶
func (tx *CreateAlpha) ReadFrom(r io.Reader) (int64, error)
ReadFrom is a deserialization function
func (*CreateAlpha) Seq ¶
func (tx *CreateAlpha) Seq() uint64
Seq returns the sequence of the transaction
type CreateHyper ¶
type CreateHyper struct { transaction.Base Seq_ uint64 From_ common.Address Name string KeyHash common.PublicHash }
CreateHyper is a consensus.CreateHyper It is used to make formulation account
func (*CreateHyper) From ¶
func (tx *CreateHyper) From() common.Address
From returns the creator of the transaction
func (*CreateHyper) Hash ¶
func (tx *CreateHyper) Hash() hash.Hash256
Hash returns the hash value of it
func (*CreateHyper) MarshalJSON ¶
func (tx *CreateHyper) MarshalJSON() ([]byte, error)
MarshalJSON is a marshaler function
func (*CreateHyper) ReadFrom ¶
func (tx *CreateHyper) ReadFrom(r io.Reader) (int64, error)
ReadFrom is a deserialization function
func (*CreateHyper) Seq ¶
func (tx *CreateHyper) Seq() uint64
Seq returns the sequence of the transaction
type CreateOmega ¶
type CreateOmega struct { transaction.Base Seq_ uint64 From_ common.Address SigmaFormulators []common.Address }
CreateOmega is a consensus.CreateOmega It is used to make formulation account
func (*CreateOmega) From ¶
func (tx *CreateOmega) From() common.Address
From returns the creator of the transaction
func (*CreateOmega) Hash ¶
func (tx *CreateOmega) Hash() hash.Hash256
Hash returns the hash value of it
func (*CreateOmega) MarshalJSON ¶
func (tx *CreateOmega) MarshalJSON() ([]byte, error)
MarshalJSON is a marshaler function
func (*CreateOmega) ReadFrom ¶
func (tx *CreateOmega) ReadFrom(r io.Reader) (int64, error)
ReadFrom is a deserialization function
func (*CreateOmega) Seq ¶
func (tx *CreateOmega) Seq() uint64
Seq returns the sequence of the transaction
type CreateSigma ¶
type CreateSigma struct { transaction.Base Seq_ uint64 From_ common.Address AlphaFormulators []common.Address }
CreateSigma is a consensus.CreateSigma It is used to make formulation account
func (*CreateSigma) From ¶
func (tx *CreateSigma) From() common.Address
From returns the creator of the transaction
func (*CreateSigma) Hash ¶
func (tx *CreateSigma) Hash() hash.Hash256
Hash returns the hash value of it
func (*CreateSigma) MarshalJSON ¶
func (tx *CreateSigma) MarshalJSON() ([]byte, error)
MarshalJSON is a marshaler function
func (*CreateSigma) ReadFrom ¶
func (tx *CreateSigma) ReadFrom(r io.Reader) (int64, error)
ReadFrom is a deserialization function
func (*CreateSigma) Seq ¶
func (tx *CreateSigma) Seq() uint64
Seq returns the sequence of the transaction
type FormulationAccount ¶
type FormulationAccount struct { account.Base FormulationType FormulationType KeyHash common.PublicHash Amount *amount.Amount Policy *HyperPolicy StakingAmount *amount.Amount }
FormulationAccount is a consensus.FormulationAccount It is used to indentify Hyper formulator that supports the staking system
func (*FormulationAccount) Clone ¶
func (acc *FormulationAccount) Clone() account.Account
Clone returns the clonend value of it
func (*FormulationAccount) MarshalJSON ¶
func (acc *FormulationAccount) MarshalJSON() ([]byte, error)
MarshalJSON is a marshaler function
type HyperPolicy ¶
type HyperPolicy struct { CommissionRatio1000 uint32 MinimumStaking *amount.Amount MaximumStaking *amount.Amount }
HyperPolicy defines a policy of Hyper formulator
func (*HyperPolicy) Clone ¶
func (pc *HyperPolicy) Clone() *HyperPolicy
Clone returns the clonend value of it
func (*HyperPolicy) MarshalJSON ¶
func (pc *HyperPolicy) MarshalJSON() ([]byte, error)
MarshalJSON is a marshaler function
type Rank ¶
type Rank struct { Address common.Address PublicHash common.PublicHash // contains filtered or unexported fields }
Rank represents the rank information of the formulation account
func InsertRankToList ¶
InsertRankToList inserts the rank by the score to the rank list
func NewRank ¶
func NewRank(Address common.Address, PublicHash common.PublicHash, phase uint32, hashSpace hash.Hash256) *Rank
NewRank returns a Rank
func (*Rank) SetHashSpace ¶
SetHashSpace set the hash space and update the score
type Revoke ¶
Revoke is a consensus.Revoke It is used to remove formulation account and get back staked coin
func (*Revoke) MarshalJSON ¶
MarshalJSON is a marshaler function
type Staking ¶
type Staking struct { transaction.Base Seq_ uint64 From_ common.Address HyperFormulator common.Address Amount *amount.Amount }
Staking is a consensus.Staking It is used to make formulation account
func (*Staking) MarshalJSON ¶
MarshalJSON is a marshaler function
type StakingPolicy ¶
type StakingPolicy struct {
AutoStaking bool
}
StakingPolicy defines a staking policy user
func (*StakingPolicy) MarshalJSON ¶
func (pc *StakingPolicy) MarshalJSON() ([]byte, error)
MarshalJSON is a marshaler function
type Unstaking ¶
type Unstaking struct { transaction.Base Seq_ uint64 From_ common.Address HyperFormulator common.Address Amount *amount.Amount }
Unstaking is a consensus.Unstaking It is used to make formulation account
func (*Unstaking) MarshalJSON ¶
MarshalJSON is a marshaler function