Documentation
¶
Index ¶
- Constants
- Variables
- type BlockGenMessage
- type BlockGenRequest
- type BlockGenRequestMessage
- type BlockObSignMessage
- type BlockReqMessage
- type BlockRound
- type BlockVote
- type BlockVoteMessage
- type Consensus
- func (cs *Consensus) Candidates() []*Rank
- func (cs *Consensus) DecodeConsensusData(ConsensusData []byte) (uint32, error)
- func (cs *Consensus) Init(cn *chain.Chain, ct chain.Committer) error
- func (cs *Consensus) InitGenesis(ctw *types.ContextWrapper) error
- func (cs *Consensus) OnLoadChain(loader types.LoaderWrapper) error
- func (cs *Consensus) OnSaveData(b *types.Block, ctw *types.ContextWrapper) error
- func (cs *Consensus) ValidateSignature(bh *types.Header, sigs []common.Signature) error
- type FormulatorAccount
- type FormulatorConfig
- type FormulatorNode
- func (fr *FormulatorNode) AddTx(tx types.Transaction, sigs []common.Signature) error
- func (fr *FormulatorNode) Close()
- func (fr *FormulatorNode) Init() error
- func (fr *FormulatorNode) OnConnected(p peer.Peer)
- func (fr *FormulatorNode) OnDisconnected(p peer.Peer)
- func (fr *FormulatorNode) OnItemExpired(Interval time.Duration, Key string, Item interface{}, IsLast bool)
- func (fr *FormulatorNode) OnObserverConnected(p peer.Peer)
- func (fr *FormulatorNode) OnObserverDisconnected(p peer.Peer)
- func (fr *FormulatorNode) OnRecv(p peer.Peer, bs []byte) error
- func (fr *FormulatorNode) OnTimerExpired(height uint32, value string)
- func (fr *FormulatorNode) Run(BindAddress string)
- type FormulatorNodeMesh
- type FormulatorService
- func (ms *FormulatorService) FormulatorMap() map[common.Address]bool
- func (ms *FormulatorService) Peer(ID string) (peer.Peer, bool)
- func (ms *FormulatorService) PeerCount() int
- func (ms *FormulatorService) RemovePeer(ID string)
- func (ms *FormulatorService) Run(BindAddress string)
- func (ms *FormulatorService) SendTo(addr common.Address, bs []byte) error
- type NextRoundVote
- type NextRoundVoteAck
- type NextRoundVoteAckMessage
- type NextRoundVoteMessage
- type ObserverNode
- func (ob *ObserverNode) Close()
- func (ob *ObserverNode) Init() error
- func (ob *ObserverNode) OnFormulatorConnected(p peer.Peer)
- func (ob *ObserverNode) OnFormulatorDisconnected(p peer.Peer)
- func (ob *ObserverNode) OnTimerExpired(height uint32, value string)
- func (ob *ObserverNode) Run(BindObserver string, BindFormulator string)
- type ObserverNodeMesh
- func (ms *ObserverNodeMesh) BroadcastPacket(bs []byte)
- func (ms *ObserverNodeMesh) Peers() []peer.Peer
- func (ms *ObserverNodeMesh) RemovePeer(ID string)
- func (ms *ObserverNodeMesh) Run(BindAddress string)
- func (ms *ObserverNodeMesh) SendAnyone(bs []byte) error
- func (ms *ObserverNodeMesh) SendTo(pubhash common.PublicHash, bs []byte) error
- 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) 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
- type RankTable
- func (rt *RankTable) CandidateCount() int
- func (rt *RankTable) Candidates() []*Rank
- func (rt *RankTable) IsFormulator(Formulator common.Address, Publichash common.PublicHash) bool
- func (rt *RankTable) RanksInMap(FormulatorMap map[common.Address]bool, Limit int) ([]*Rank, error)
- func (rt *RankTable) TopRank(TimeoutCount int) (*Rank, error)
- func (rt *RankTable) TopRankInMap(FormulatorMap map[common.Address]bool) (*Rank, int, error)
- type RoundVote
- type RoundVoteAck
- type RoundVoteAckMessage
- type RoundVoteMessage
- type VoteRound
Constants ¶
const ( EmptyState = iota RoundVoteState = iota RoundVoteAckState = iota BlockWaitState = iota BlockVoteState = iota )
consts
Variables ¶
var ( ErrInsufficientCandidateCount = errors.New("insufficient candidate count") ErrExceedCandidateCount = errors.New("exceed candidate count") ErrInvalidMaxBlocksPerFormulator = errors.New("invalid max blocks per formulator") ErrInvalidObserverKey = errors.New("invalid observer key") ErrInvalidTopAddress = errors.New("invalid top address") ErrInvalidTopSignature = errors.New("invalid top signature") ErrInvalidSignatureCount = errors.New("invalid signature count") ErrInvalidPhase = errors.New("invalid phase") ErrExistAddress = errors.New("exist address") ErrFoundForkedBlockGen = errors.New("found forked block gen") ErrInvalidVote = errors.New("invalid vote") ErrInvalidRoundState = errors.New("invalid round state") ErrInvalidRequest = errors.New("invalid request") ErrAlreadyVoted = errors.New("already voted") ErrNotExistObserverPeer = errors.New("not exist observer peer") ErrNotExistFormulatorPeer = errors.New("not exist formulator peer") )
consensus errors
var (
BlockGenMessageType = types.DefineHashedType("pof.BlockGenMessage")
)
Functions ¶
This section is empty.
Types ¶
type BlockGenMessage ¶
BlockGenMessage is a message for a block generation
type BlockGenRequest ¶
type BlockGenRequest struct { ChainID uint8 LastHash hash.Hash256 TargetHeight uint32 TimeoutCount uint32 Formulator common.Address FormulatorPublicHash common.PublicHash PublicHash common.PublicHash Timestamp uint64 }
BlockGenRequest is a message to request block gen
type BlockGenRequestMessage ¶
type BlockGenRequestMessage struct { BlockGenRequest *BlockGenRequest Signature common.Signature }
BlockGenRequestMessage is a message to request block gen
type BlockObSignMessage ¶
type BlockObSignMessage struct { TargetHeight uint32 BlockSign *types.BlockSign ObserverSignatures []common.Signature }
BlockObSignMessage is a message for a block observer signatures
type BlockReqMessage ¶
type BlockReqMessage struct { PrevHash hash.Hash256 TargetHeight uint32 TimeoutCount uint32 Formulator common.Address FormulatorPublicHash common.PublicHash }
BlockReqMessage is a message for a block request
type BlockRound ¶
type BlockRound struct { BlockVoteMap map[common.PublicHash]*BlockVote BlockGenMessage *BlockGenMessage Context *types.Context BlockVoteMessageWaitMap map[common.PublicHash]*BlockVoteMessage BlockGenMessageWait *BlockGenMessage LastBlockGenRequestTime uint64 }
BlockRound is data for the block round
type BlockVote ¶
type BlockVote struct { TargetHeight uint32 Header *types.Header GeneratorSignature common.Signature ObserverSignature common.Signature IsReply bool }
BlockVote is message for a block vote
type BlockVoteMessage ¶
BlockVoteMessage is a message for a round vote
type Consensus ¶
type Consensus struct { sync.Mutex *chain.ConsensusBase // contains filtered or unexported fields }
Consensus implements the proof of formulator algorithm
func NewConsensus ¶
func NewConsensus(MaxBlocksPerFormulator uint32, ObserverKeys []common.PublicHash) *Consensus
NewConsensus returns a Consensus
func (*Consensus) Candidates ¶
Candidates returns a candidates
func (*Consensus) DecodeConsensusData ¶
DecodeConsensusData decodes header's consensus data
func (*Consensus) InitGenesis ¶
func (cs *Consensus) InitGenesis(ctw *types.ContextWrapper) error
InitGenesis initializes genesis data
func (*Consensus) OnLoadChain ¶
func (cs *Consensus) OnLoadChain(loader types.LoaderWrapper) error
OnLoadChain called when the chain loaded
func (*Consensus) OnSaveData ¶
OnSaveData called when the context of the block saved
type FormulatorAccount ¶
type FormulatorConfig ¶
FormulatorConfig defines configuration of the formulator
type FormulatorNode ¶
type FormulatorNode struct { sync.Mutex Config *FormulatorConfig // contains filtered or unexported fields }
FormulatorNode procudes a block by the consensus
func NewFormulatorNode ¶
func NewFormulatorNode(Config *FormulatorConfig, key key.Key, ndkey key.Key, NetAddressMap map[common.PublicHash]string, SeedNodeMap map[common.PublicHash]string, cs *Consensus, peerStorePath string) *FormulatorNode
NewFormulatorNode returns a FormulatorNode
func (*FormulatorNode) AddTx ¶
func (fr *FormulatorNode) AddTx(tx types.Transaction, sigs []common.Signature) error
AddTx adds tx to txpool
func (*FormulatorNode) OnConnected ¶
func (fr *FormulatorNode) OnConnected(p peer.Peer)
OnConnected is called after a new peer is connected
func (*FormulatorNode) OnDisconnected ¶
func (fr *FormulatorNode) OnDisconnected(p peer.Peer)
OnDisconnected is called when the peer is disconnected
func (*FormulatorNode) OnItemExpired ¶
func (fr *FormulatorNode) OnItemExpired(Interval time.Duration, Key string, Item interface{}, IsLast bool)
OnItemExpired is called when the item is expired
func (*FormulatorNode) OnObserverConnected ¶
func (fr *FormulatorNode) OnObserverConnected(p peer.Peer)
OnObserverConnected is called after a new observer peer is connected
func (*FormulatorNode) OnObserverDisconnected ¶
func (fr *FormulatorNode) OnObserverDisconnected(p peer.Peer)
OnObserverDisconnected is called when the observer peer is disconnected
func (*FormulatorNode) OnRecv ¶
func (fr *FormulatorNode) OnRecv(p peer.Peer, bs []byte) error
OnRecv called when message received
func (*FormulatorNode) OnTimerExpired ¶
func (fr *FormulatorNode) OnTimerExpired(height uint32, value string)
OnTimerExpired called when rquest expired
func (*FormulatorNode) Run ¶
func (fr *FormulatorNode) Run(BindAddress string)
Run runs the formulator
type FormulatorNodeMesh ¶
func NewFormulatorNodeMesh ¶
func NewFormulatorNodeMesh(key key.Key, NetAddressMap map[common.PublicHash]string, fr *FormulatorNode) *FormulatorNodeMesh
func (*FormulatorNodeMesh) BroadcastPacket ¶
func (ms *FormulatorNodeMesh) BroadcastPacket(bs []byte)
BroadcastPacket sends a packet to all peers
func (*FormulatorNodeMesh) Peers ¶
func (ms *FormulatorNodeMesh) Peers() []peer.Peer
Peers returns peers of the formulator mesh
func (*FormulatorNodeMesh) RemovePeer ¶
func (ms *FormulatorNodeMesh) RemovePeer(ID string)
RemovePeer removes peers from the mesh
func (*FormulatorNodeMesh) SendTo ¶
func (ms *FormulatorNodeMesh) SendTo(ID string, m interface{}) error
SendTo sends a message to the observer
type FormulatorService ¶
FormulatorService provides connectivity with formulators
func NewFormulatorService ¶
func NewFormulatorService(ob *ObserverNode) *FormulatorService
NewFormulatorService returns a FormulatorService
func (*FormulatorService) FormulatorMap ¶
func (ms *FormulatorService) FormulatorMap() map[common.Address]bool
FormulatorMap returns a formulator list as a map
func (*FormulatorService) Peer ¶
func (ms *FormulatorService) Peer(ID string) (peer.Peer, bool)
Peer returns the peer
func (*FormulatorService) PeerCount ¶
func (ms *FormulatorService) PeerCount() int
PeerCount returns a number of the peer
func (*FormulatorService) RemovePeer ¶
func (ms *FormulatorService) RemovePeer(ID string)
RemovePeer removes peers from the mesh
func (*FormulatorService) Run ¶
func (ms *FormulatorService) Run(BindAddress string)
Run provides a server
type NextRoundVote ¶
type NextRoundVote struct { ChainID uint8 TimeoutCount uint32 Formulator common.Address FormulatorPublicHash common.PublicHash Timestamp uint64 IsReply bool }
NextRoundVote is a message for a next round vote
type NextRoundVoteAck ¶
type NextRoundVoteAck struct { ChainID uint8 TimeoutCount uint32 Formulator common.Address FormulatorPublicHash common.PublicHash PublicHash common.PublicHash Timestamp uint64 IsReply bool }
NextRoundVoteAck is a message for a next round vote ack
type NextRoundVoteAckMessage ¶
type NextRoundVoteAckMessage struct { RoundVoteAck *RoundVoteAck Signature common.Signature }
NextRoundVoteAckMessage is a message for a next round vote
type NextRoundVoteMessage ¶
NextRoundVoteMessage is a message for a next round vote
type ObserverNode ¶
ObserverNode observes a block by the consensus
func NewObserverNode ¶
func NewObserverNode(key key.Key, NetAddressMap map[common.PublicHash]string, cs *Consensus) *ObserverNode
NewObserverNode returns a ObserverNode
func (*ObserverNode) OnFormulatorConnected ¶
func (ob *ObserverNode) OnFormulatorConnected(p peer.Peer)
OnFormulatorConnected is called after a new formulator peer is connected
func (*ObserverNode) OnFormulatorDisconnected ¶
func (ob *ObserverNode) OnFormulatorDisconnected(p peer.Peer)
OnFormulatorDisconnected is called when the formulator peer is disconnected
func (*ObserverNode) OnTimerExpired ¶
func (ob *ObserverNode) OnTimerExpired(height uint32, value string)
OnTimerExpired called when rquest expired
func (*ObserverNode) Run ¶
func (ob *ObserverNode) Run(BindObserver string, BindFormulator string)
Run starts the pof consensus on the observer
type ObserverNodeMesh ¶
func NewObserverNodeMesh ¶
func NewObserverNodeMesh(key key.Key, NetAddressMap map[common.PublicHash]string, ob *ObserverNode) *ObserverNodeMesh
func (*ObserverNodeMesh) BroadcastPacket ¶
func (ms *ObserverNodeMesh) BroadcastPacket(bs []byte)
BroadcastPacket sends a packet to all peers
func (*ObserverNodeMesh) Peers ¶
func (ms *ObserverNodeMesh) Peers() []peer.Peer
Peers returns peers of the observer mesh
func (*ObserverNodeMesh) RemovePeer ¶
func (ms *ObserverNodeMesh) RemovePeer(ID string)
RemovePeer removes peers from the mesh
func (*ObserverNodeMesh) Run ¶
func (ms *ObserverNodeMesh) Run(BindAddress string)
Run starts the observer mesh
func (*ObserverNodeMesh) SendAnyone ¶
func (ms *ObserverNodeMesh) SendAnyone(bs []byte) error
SendAnyone sends a message to the one of observers
func (*ObserverNodeMesh) SendTo ¶
func (ms *ObserverNodeMesh) SendTo(pubhash common.PublicHash, bs []byte) error
SendTo sends a message to the observer
type Rank ¶
type Rank struct { Address common.Address PublicHash common.PublicHash // contains filtered or unexported fields }
Rank represents the rank information of the formulator 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 RankTable ¶
RankTable implements the proof of formulator algorithm
func (*RankTable) CandidateCount ¶
CandidateCount returns a count of the rank table
func (*RankTable) Candidates ¶
Candidates returns a candidates
func (*RankTable) IsFormulator ¶
IsFormulator returns the given information is correct or not
func (*RankTable) RanksInMap ¶
RanksInMap returns the ranks in the map
type RoundVote ¶
type RoundVote struct { ChainID uint8 LastHash hash.Hash256 TargetHeight uint32 TimeoutCount uint32 Formulator common.Address FormulatorPublicHash common.PublicHash Timestamp uint64 IsReply bool }
RoundVote is a message for a round vote
type RoundVoteAck ¶
type RoundVoteAck struct { ChainID uint8 LastHash hash.Hash256 TargetHeight uint32 TimeoutCount uint32 Formulator common.Address FormulatorPublicHash common.PublicHash PublicHash common.PublicHash Timestamp uint64 IsReply bool }
RoundVoteAck is a message for a round vote ack
type RoundVoteAckMessage ¶
type RoundVoteAckMessage struct { RoundVoteAck *RoundVoteAck Signature common.Signature }
RoundVoteAckMessage is a message for a round vote
type RoundVoteMessage ¶
RoundVoteMessage is a message for a round vote
type VoteRound ¶
type VoteRound struct { RoundState int TargetHeight uint32 RoundVoteMessageMap map[common.PublicHash]*RoundVoteMessage RoundVoteAckMessageMap map[common.PublicHash]*RoundVoteAckMessage MinRoundVoteAck *RoundVoteAck BlockRoundMap map[uint32]*BlockRound RoundVoteWaitMap map[common.PublicHash]*RoundVoteMessage RoundVoteAckMessageWaitMap map[common.PublicHash]*RoundVoteAckMessage VoteFailCount int }
VoteRound is data for the voting round
func NewVoteRound ¶
NewVoteRound returns a VoteRound
Source Files
¶
- consensus.go
- consensus_method.go
- errors.go
- formulator_account.go
- formulator_mesh.go
- formulator_node.go
- formulator_node_observer.go
- formulator_node_peer.go
- formulator_node_send.go
- messages.go
- observer_formulator_service.go
- observer_mesh.go
- observer_node.go
- observer_node_formulator.go
- observer_node_observer.go
- observer_node_send.go
- rank.go
- rank_table.go
- util_key.go
- vote_round.go