consensus

package
v0.0.0-...-4701ab3 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2019 License: LGPL-3.0 Imports: 15 Imported by: 11

Documentation

Index

Constants

View Source
const (
	AlphaFormulatorType = FormulationType(1)
	SigmaFormulatorType = FormulationType(2)
	OmegaFormulatorType = FormulationType(3)
	HyperFormulatorType = FormulationType(4)
)

formulator types

Variables

View Source
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")
	ErrUnauthorizedTransaction        = errors.New("unauthorized transaction")
)

consensus errors

View Source
var (
	TagStaking = []byte{1, 0}
)

tags

Functions

func FromStakingKey

func FromStakingKey(bs []byte) (common.Address, bool)

FromStakingKey returns the staking address if it is staking key

func SetConsensusPolicy

func SetConsensusPolicy(chainCoord *common.Coordinate, pc *ConsensusPolicy)

func ToAutoStakingKey

func ToAutoStakingKey(addr common.Address) []byte

ToAutoStakingKey returns the auto staking key of the staking address

func ToStakingKey

func ToStakingKey(addr common.Address) []byte

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

func (cs *Consensus) BlocksFromSameFormulator() uint32

BlocksFromSameFormulator returns a number of blocks made from same formulator

func (*Consensus) CandidateCount

func (cs *Consensus) CandidateCount() int

CandidateCount returns a count of the rank table

func (*Consensus) IsFormulator

func (cs *Consensus) IsFormulator(Formulator common.Address, Publichash common.PublicHash) bool

IsFormulator returns the given information is correct or not

func (*Consensus) LoadFromSaveData

func (cs *Consensus) LoadFromSaveData(SaveData []byte) error

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

func (cs *Consensus) RanksInMap(FormulatorMap map[common.Address]bool, Limit int) ([]*Rank, error)

RanksInMap returns the ranks in the map

func (*Consensus) TopRank

func (cs *Consensus) TopRank(TimeoutCount int) (*Rank, error)

TopRank returns the top rank by Timeoutcount

func (*Consensus) TopRankInMap

func (cs *Consensus) TopRankInMap(FormulatorMap map[common.Address]bool) (*Rank, int, error)

TopRankInMap returns the top rank by the given timeout count in the given 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

func (*ConsensusPolicy) ReadFrom

func (pc *ConsensusPolicy) ReadFrom(r io.Reader) (int64, error)

ReadFrom is a deserialization function

func (*ConsensusPolicy) WriteTo

func (pc *ConsensusPolicy) WriteTo(w io.Writer) (int64, error)

WriteTo is a serialization 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) IsUTXO

func (tx *CreateAlpha) IsUTXO() bool

IsUTXO returns false

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

func (*CreateAlpha) WriteTo

func (tx *CreateAlpha) WriteTo(w io.Writer) (int64, error)

WriteTo is a serialization function

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

func (tx *CreateHyper) IsUTXO() bool

IsUTXO returns false

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

func (*CreateHyper) WriteTo

func (tx *CreateHyper) WriteTo(w io.Writer) (int64, error)

WriteTo is a serialization function

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

func (tx *CreateOmega) IsUTXO() bool

IsUTXO returns false

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

func (*CreateOmega) WriteTo

func (tx *CreateOmega) WriteTo(w io.Writer) (int64, error)

WriteTo is a serialization function

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

func (tx *CreateSigma) IsUTXO() bool

IsUTXO returns false

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

func (*CreateSigma) WriteTo

func (tx *CreateSigma) WriteTo(w io.Writer) (int64, error)

WriteTo is a serialization function

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

func (*FormulationAccount) ReadFrom

func (acc *FormulationAccount) ReadFrom(r io.Reader) (int64, error)

ReadFrom is a deserialization function

func (*FormulationAccount) WriteTo

func (acc *FormulationAccount) WriteTo(w io.Writer) (int64, error)

WriteTo is a serialization function

type FormulationType

type FormulationType uint8

FormulationType is type of formulation account

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

func (*HyperPolicy) ReadFrom

func (pc *HyperPolicy) ReadFrom(r io.Reader) (int64, error)

ReadFrom is a deserialization function

func (*HyperPolicy) WriteTo

func (pc *HyperPolicy) WriteTo(w io.Writer) (int64, error)

WriteTo is a serialization 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

func InsertRankToList(ranks []*Rank, s *Rank) []*Rank

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

func (rank *Rank) Clone() *Rank

Clone returns the clonend value of it

func (*Rank) Equal

func (rank *Rank) Equal(b *Rank) bool

Equal checks that two values is same or not

func (*Rank) HashSpace

func (rank *Rank) HashSpace() hash.Hash256

HashSpace returns the hash space of the rank

func (*Rank) IsZero

func (rank *Rank) IsZero() bool

IsZero returns a == 0

func (*Rank) Key

func (rank *Rank) Key() string

Key returns unique key of the rank

func (*Rank) Less

func (rank *Rank) Less(b *Rank) bool

Less returns a < b

func (*Rank) Phase

func (rank *Rank) Phase() uint32

Phase returns the phase of the rank

func (*Rank) ReadFrom

func (rank *Rank) ReadFrom(r io.Reader) (int64, error)

ReadFrom is a deserialization function

func (*Rank) Score

func (rank *Rank) Score() uint64

Score returns the score of the rank

func (*Rank) Set

func (rank *Rank) Set(phase uint32, hashSpace hash.Hash256)

Set updates rank's properties and update the score

func (*Rank) SetHashSpace

func (rank *Rank) SetHashSpace(hashSpace hash.Hash256)

SetHashSpace set the hash space and update the score

func (*Rank) SetPhase

func (rank *Rank) SetPhase(phase uint32)

SetPhase set the phase and update the score

func (*Rank) String

func (rank *Rank) String() string

String returns the string of the rank using the byte array of rank value

func (*Rank) WriteTo

func (rank *Rank) WriteTo(w io.Writer) (int64, error)

WriteTo is a serialization function

type Revoke

type Revoke struct {
	transaction.Base
	Seq_    uint64
	From_   common.Address
	Heritor common.Address
}

Revoke is a consensus.Revoke It is used to remove formulation account and get back staked coin

func (*Revoke) From

func (tx *Revoke) From() common.Address

From returns the creator of the transaction

func (*Revoke) Hash

func (tx *Revoke) Hash() hash.Hash256

Hash returns the hash value of it

func (*Revoke) IsUTXO

func (tx *Revoke) IsUTXO() bool

IsUTXO returns false

func (*Revoke) MarshalJSON

func (tx *Revoke) MarshalJSON() ([]byte, error)

MarshalJSON is a marshaler function

func (*Revoke) ReadFrom

func (tx *Revoke) ReadFrom(r io.Reader) (int64, error)

ReadFrom is a deserialization function

func (*Revoke) Seq

func (tx *Revoke) Seq() uint64

Seq returns the sequence of the transaction

func (*Revoke) WriteTo

func (tx *Revoke) WriteTo(w io.Writer) (int64, error)

WriteTo is a serialization 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) From

func (tx *Staking) From() common.Address

From returns the creator of the transaction

func (*Staking) Hash

func (tx *Staking) Hash() hash.Hash256

Hash returns the hash value of it

func (*Staking) IsUTXO

func (tx *Staking) IsUTXO() bool

IsUTXO returns false

func (*Staking) MarshalJSON

func (tx *Staking) MarshalJSON() ([]byte, error)

MarshalJSON is a marshaler function

func (*Staking) ReadFrom

func (tx *Staking) ReadFrom(r io.Reader) (int64, error)

ReadFrom is a deserialization function

func (*Staking) Seq

func (tx *Staking) Seq() uint64

Seq returns the sequence of the transaction

func (*Staking) WriteTo

func (tx *Staking) WriteTo(w io.Writer) (int64, error)

WriteTo is a serialization 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

func (*StakingPolicy) ReadFrom

func (pc *StakingPolicy) ReadFrom(r io.Reader) (int64, error)

ReadFrom is a deserialization function

func (*StakingPolicy) WriteTo

func (pc *StakingPolicy) WriteTo(w io.Writer) (int64, error)

WriteTo is a serialization 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) From

func (tx *Unstaking) From() common.Address

From returns the creator of the transaction

func (*Unstaking) Hash

func (tx *Unstaking) Hash() hash.Hash256

Hash returns the hash value of it

func (*Unstaking) IsUTXO

func (tx *Unstaking) IsUTXO() bool

IsUTXO returns false

func (*Unstaking) MarshalJSON

func (tx *Unstaking) MarshalJSON() ([]byte, error)

MarshalJSON is a marshaler function

func (*Unstaking) ReadFrom

func (tx *Unstaking) ReadFrom(r io.Reader) (int64, error)

ReadFrom is a deserialization function

func (*Unstaking) Seq

func (tx *Unstaking) Seq() uint64

Seq returns the sequence of the transaction

func (*Unstaking) WriteTo

func (tx *Unstaking) WriteTo(w io.Writer) (int64, error)

WriteTo is a serialization function

Jump to

Keyboard shortcuts

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