pof

package
v0.0.0-...-a8cc34e Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2020 License: LGPL-3.0 Imports: 30 Imported by: 2

Documentation

Index

Constants

View Source
const (
	EmptyState        = iota
	RoundVoteState    = iota
	RoundVoteAckState = iota
	BlockWaitState    = iota
	BlockVoteState    = iota
)

consts

Variables

View Source
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

View Source
var (
	BlockGenMessageType = types.DefineHashedType("pof.BlockGenMessage")
)

Functions

This section is empty.

Types

type BlockGenMessage

type BlockGenMessage struct {
	Block              *types.Block
	GeneratorSignature common.Signature
	IsReply            bool
}

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

func NewBlockRound

func NewBlockRound() *BlockRound

NewBlockRound returns a VoteRound

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

type BlockVoteMessage struct {
	BlockVote *BlockVote
	Signature common.Signature
}

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

func (cs *Consensus) Candidates() []*Rank

Candidates returns a candidates

func (*Consensus) DecodeConsensusData

func (cs *Consensus) DecodeConsensusData(ConsensusData []byte) (uint32, error)

DecodeConsensusData decodes header's consensus data

func (*Consensus) Init

func (cs *Consensus) Init(cn *chain.Chain, ct chain.Committer) error

Init initializes the consensus

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

func (cs *Consensus) OnSaveData(b *types.Block, ctw *types.ContextWrapper) error

OnSaveData called when the context of the block saved

func (*Consensus) ValidateSignature

func (cs *Consensus) ValidateSignature(bh *types.Header, sigs []common.Signature) error

ValidateSignature called when required to validate signatures

type FormulatorAccount

type FormulatorAccount interface {
	types.Account
	IsFormulator() bool
	GeneratorHash() common.PublicHash
	IsActivated() bool
}

type FormulatorConfig

type FormulatorConfig struct {
	Formulator              common.Address
	MaxTransactionsPerBlock int
}

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

func (fr *FormulatorNode) Close()

Close terminates the formulator

func (*FormulatorNode) Init

func (fr *FormulatorNode) Init() error

Init initializes formulator

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

type FormulatorNodeMesh struct {
	sync.Mutex
	// contains filtered or unexported fields
}

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

func (ms *FormulatorNodeMesh) Run()

Run starts the formulator mesh

func (*FormulatorNodeMesh) SendTo

func (ms *FormulatorNodeMesh) SendTo(ID string, m interface{}) error

SendTo sends a message to the observer

type FormulatorService

type FormulatorService struct {
	sync.Mutex
	// contains filtered or unexported fields
}

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

func (*FormulatorService) SendTo

func (ms *FormulatorService) SendTo(addr common.Address, bs []byte) error

SendTo sends a message to the formulator

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

type NextRoundVoteMessage struct {
	RoundVote *RoundVote
	Signature common.Signature
}

NextRoundVoteMessage is a message for a next round vote

type ObserverNode

type ObserverNode struct {
	sync.Mutex
	// contains filtered or unexported fields
}

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

func (ob *ObserverNode) Close()

Close terminates the observer

func (*ObserverNode) Init

func (ob *ObserverNode) Init() error

Init initializes observer

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

type ObserverNodeMesh struct {
	sync.Mutex
	// contains filtered or unexported fields
}

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

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

type RankTable

type RankTable struct {
	sync.Mutex
	// contains filtered or unexported fields
}

RankTable implements the proof of formulator algorithm

func NewRankTable

func NewRankTable() *RankTable

NewRankTable returns a RankTable

func (*RankTable) CandidateCount

func (rt *RankTable) CandidateCount() int

CandidateCount returns a count of the rank table

func (*RankTable) Candidates

func (rt *RankTable) Candidates() []*Rank

Candidates returns a candidates

func (*RankTable) IsFormulator

func (rt *RankTable) IsFormulator(Formulator common.Address, Publichash common.PublicHash) bool

IsFormulator returns the given information is correct or not

func (*RankTable) RanksInMap

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

RanksInMap returns the ranks in the map

func (*RankTable) TopRank

func (rt *RankTable) TopRank(TimeoutCount int) (*Rank, error)

TopRank returns the top rank by Timeoutcount

func (*RankTable) TopRankInMap

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

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

type RoundVoteMessage struct {
	RoundVote *RoundVote
	Signature common.Signature
}

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

func NewVoteRound(TargetHeight uint32, MaxBlocksPerFormulator uint32) *VoteRound

NewVoteRound returns a VoteRound

Jump to

Keyboard shortcuts

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