Documentation
¶
Index ¶
- Constants
- Variables
- type BlockGenMessage
- type BlockGenRequestMessage
- type BlockObSignMessage
- type BlockReqMessage
- type BlockRound
- type BlockVoteMessage
- type GeneratorConfig
- type GeneratorNode
- func (fr *GeneratorNode) ActiveGenerators() ([]common.Address, error)
- func (fr *GeneratorNode) AddTx(tx *types.Transaction, sig common.Signature) error
- func (fr *GeneratorNode) Close()
- func (fr *GeneratorNode) GetTxFromTXPool(TxHash hash.Hash256) *txpool.PoolItem
- func (fr *GeneratorNode) Init() error
- func (fr *GeneratorNode) OnConnected(p peer.Peer)
- func (fr *GeneratorNode) OnDisconnected(p peer.Peer)
- func (fr *GeneratorNode) OnItemExpired(Interval time.Duration, Key string, Item interface{}, IsLast bool) queue.TxExpiredType
- func (fr *GeneratorNode) OnObserverConnected(p peer.Peer)
- func (fr *GeneratorNode) OnObserverDisconnected(p peer.Peer)
- func (fr *GeneratorNode) OnRecv(p peer.Peer, bs []byte) error
- func (fr *GeneratorNode) OnTimerExpired(height uint32, value string)
- func (fr *GeneratorNode) PushTx(tx *types.Transaction, sig common.Signature) error
- func (fr *GeneratorNode) Run(BindAddress string)
- func (fr *GeneratorNode) TxPoolList() []*txpool.PoolItem
- type GeneratorNodeMesh
- type GeneratorService
- func (ms *GeneratorService) ActiveGenerators() []common.Address
- func (ms *GeneratorService) GeneratorMap() map[common.Address]bool
- func (ms *GeneratorService) Peer(ID string) (peer.Peer, bool)
- func (ms *GeneratorService) PeerCount() int
- func (ms *GeneratorService) Peers() []peer.Peer
- func (ms *GeneratorService) RemovePeer(ID string)
- func (ms *GeneratorService) Run(BindAddress string)
- func (ms *GeneratorService) SendTo(addr common.Address, bs []byte) error
- type ObserverNode
- func (ob *ObserverNode) Close()
- func (ob *ObserverNode) Init() error
- func (ob *ObserverNode) OnGeneratorConnected(p peer.Peer)
- func (ob *ObserverNode) OnGeneratorDisconnected(p peer.Peer)
- func (ob *ObserverNode) OnTimerExpired(height uint32, value string)
- func (ob *ObserverNode) ResetRound()
- func (ob *ObserverNode) Run(BindObserver string, BindGenerator 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(PubKey common.PublicKey, bs []byte) error
- type RoundState
- type RoundVoteAckMessage
- type RoundVoteMessage
- type VoteRound
Constants ¶
const BlockTime = 500 * time.Millisecond
BlockTime defines the block generation interval
Variables ¶
var ( ErrInsufficientCandidateCount = errors.New("insufficient candidate count") ErrExceedCandidateCount = errors.New("exceed candidate count") ErrInvalidMaxBlocksPerGenerator = errors.New("invalid max blocks per generator") 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") ErrNotExistGeneratorPeer = errors.New("not exist generator peer") ErrActiveGeneratorTimout = errors.New("timeout for active generator") )
consensus errors
var ( RoundVoteMessageType = p2p.RegisterSerializableType(&RoundVoteMessage{}) RoundVoteAckMessageType = p2p.RegisterSerializableType(&RoundVoteAckMessage{}) BlockReqMessageType = p2p.RegisterSerializableType(&BlockReqMessage{}) BlockGenMessageType = p2p.RegisterSerializableType(&BlockGenMessage{}) BlockVoteMessageType = p2p.RegisterSerializableType(&BlockVoteMessage{}) BlockObSignMessageType = p2p.RegisterSerializableType(&BlockObSignMessage{}) BlockGenRequestMessageType = p2p.RegisterSerializableType(&BlockGenRequestMessage{}) )
var (
DEBUG = false
)
var RoundStates = [...]string{
"EmptyState ",
"RoundVoteState ",
"RoundVoteAckState",
"BlockWaitState ",
"BlockVoteState ",
}
Functions ¶
This section is empty.
Types ¶
type BlockGenMessage ¶
BlockGenMessage is a message for a block generation
func (*BlockGenMessage) TypeID ¶
func (s *BlockGenMessage) TypeID() uint32
type BlockGenRequestMessage ¶
type BlockGenRequestMessage struct { ChainID *big.Int LastHash hash.Hash256 TargetHeight uint32 TimeoutCount uint32 Generator common.Address Timestamp uint64 }
BlockGenRequestMessage is a message to request block gen
func (*BlockGenRequestMessage) ReadFrom ¶
func (s *BlockGenRequestMessage) ReadFrom(r io.Reader) (int64, error)
func (*BlockGenRequestMessage) TypeID ¶
func (s *BlockGenRequestMessage) TypeID() uint32
type BlockObSignMessage ¶
type BlockObSignMessage struct { TargetHeight uint32 BlockSign *types.BlockSign ObserverSignatures []common.Signature }
BlockObSignMessage is a message for a block observer signatures
func (*BlockObSignMessage) ReadFrom ¶
func (s *BlockObSignMessage) ReadFrom(r io.Reader) (int64, error)
func (*BlockObSignMessage) TypeID ¶
func (s *BlockObSignMessage) TypeID() uint32
type BlockReqMessage ¶
type BlockReqMessage struct { PrevHash hash.Hash256 TargetHeight uint32 TimeoutCount uint32 Generator common.Address }
BlockReqMessage is a message for a block request
func (*BlockReqMessage) TypeID ¶
func (s *BlockReqMessage) TypeID() uint32
type BlockRound ¶
type BlockRound struct { BlockVoteMap map[common.PublicKey]*BlockVoteMessage BlockGenMessage *BlockGenMessage Context *types.Context Receipts types.Receipts BlockVoteMessageWaitMap map[common.PublicKey]*BlockVoteMessage BlockGenMessageWait *BlockGenMessage LastBlockGenRequestTime uint64 }
BlockRound is data for the block round
type BlockVoteMessage ¶
type BlockVoteMessage struct { TargetHeight uint32 Header *types.Header GeneratorSignature common.Signature ObserverSignature common.Signature IsReply bool }
BlockVoteMessage is message for a block vote
func (*BlockVoteMessage) TypeID ¶
func (s *BlockVoteMessage) TypeID() uint32
type GeneratorConfig ¶
type GeneratorConfig struct {
MaxTransactionsPerBlock int
}
GeneratorConfig defines configuration of the generator
type GeneratorNode ¶
type GeneratorNode struct { sync.Mutex ChainID *big.Int Config *GeneratorConfig // contains filtered or unexported fields }
GeneratorNode procudes a block by the consensus
func NewGeneratorNode ¶
func NewGeneratorNode(ChainID *big.Int, Config *GeneratorConfig, cn *chain.Chain, key key.Key, ndkey key.Key, NetAddressMap map[common.PublicKey]string, SeedNodeMap map[common.PublicKey]string, peerStorePath string) *GeneratorNode
NewGeneratorNode returns a GeneratorNode
func (*GeneratorNode) ActiveGenerators ¶
func (fr *GeneratorNode) ActiveGenerators() ([]common.Address, error)
ActiveGenerators returns the received active(=connected) generators from observer wait 2 seconds for respective observer response
func (*GeneratorNode) AddTx ¶
func (fr *GeneratorNode) AddTx(tx *types.Transaction, sig common.Signature) error
AddTx adds tx to txpool
func (*GeneratorNode) GetTxFromTXPool ¶
func (fr *GeneratorNode) GetTxFromTXPool(TxHash hash.Hash256) *txpool.PoolItem
GetTxFromTXPool returned tx from txpool
func (*GeneratorNode) OnConnected ¶
func (fr *GeneratorNode) OnConnected(p peer.Peer)
OnConnected is called after a new peer is connected
func (*GeneratorNode) OnDisconnected ¶
func (fr *GeneratorNode) OnDisconnected(p peer.Peer)
OnDisconnected is called when the peer is disconnected
func (*GeneratorNode) OnItemExpired ¶
func (fr *GeneratorNode) OnItemExpired(Interval time.Duration, Key string, Item interface{}, IsLast bool) queue.TxExpiredType
OnItemExpired is called when the item is expired
func (*GeneratorNode) OnObserverConnected ¶
func (fr *GeneratorNode) OnObserverConnected(p peer.Peer)
OnObserverConnected is called after a new observer peer is connected
func (*GeneratorNode) OnObserverDisconnected ¶
func (fr *GeneratorNode) OnObserverDisconnected(p peer.Peer)
OnObserverDisconnected is called when the observer peer is disconnected
func (*GeneratorNode) OnRecv ¶
func (fr *GeneratorNode) OnRecv(p peer.Peer, bs []byte) error
OnRecv called when message received
func (*GeneratorNode) OnTimerExpired ¶
func (fr *GeneratorNode) OnTimerExpired(height uint32, value string)
OnTimerExpired called when rquest expired
func (*GeneratorNode) PushTx ¶
func (fr *GeneratorNode) PushTx(tx *types.Transaction, sig common.Signature) error
PushTx pushes transaction
func (*GeneratorNode) TxPoolList ¶
func (fr *GeneratorNode) TxPoolList() []*txpool.PoolItem
TxPoolList returned tx list from txpool
type GeneratorNodeMesh ¶
func NewGeneratorNodeMesh ¶
func NewGeneratorNodeMesh(key key.Key, NetAddressMap map[common.PublicKey]string, fr *GeneratorNode) *GeneratorNodeMesh
func (*GeneratorNodeMesh) BroadcastPacket ¶
func (ms *GeneratorNodeMesh) BroadcastPacket(bs []byte)
BroadcastPacket sends a packet to all peers
func (*GeneratorNodeMesh) Peers ¶
func (ms *GeneratorNodeMesh) Peers() []peer.Peer
Peers returns peers of the generator mesh
func (*GeneratorNodeMesh) RemovePeer ¶
func (ms *GeneratorNodeMesh) RemovePeer(ID string)
RemovePeer removes peers from the mesh
func (*GeneratorNodeMesh) SendTo ¶
func (ms *GeneratorNodeMesh) SendTo(ID string, m p2p.Serializable) error
SendTo sends a message to the observer
type GeneratorService ¶
GeneratorService provides connectivity with generators
func NewGeneratorService ¶
func NewGeneratorService(ob *ObserverNode) *GeneratorService
NewGeneratorService returns a GeneratorService
func (*GeneratorService) ActiveGenerators ¶
func (ms *GeneratorService) ActiveGenerators() []common.Address
Generators returns a Generator list slice
func (*GeneratorService) GeneratorMap ¶
func (ms *GeneratorService) GeneratorMap() map[common.Address]bool
GeneratorMap returns a Generator list as a map
func (*GeneratorService) Peer ¶
func (ms *GeneratorService) Peer(ID string) (peer.Peer, bool)
Peer returns the peer
func (*GeneratorService) PeerCount ¶
func (ms *GeneratorService) PeerCount() int
PeerCount returns a number of the peer
func (*GeneratorService) Peers ¶
func (ms *GeneratorService) Peers() []peer.Peer
Peers returns peer list
func (*GeneratorService) RemovePeer ¶
func (ms *GeneratorService) RemovePeer(ID string)
RemovePeer removes peers from the mesh
func (*GeneratorService) Run ¶
func (ms *GeneratorService) Run(BindAddress string)
Run provides a server
type ObserverNode ¶
ObserverNode observes a block by the consensus
func NewObserverNode ¶
func NewObserverNode(ChainID *big.Int, key key.Key, NetAddressMap map[common.PublicKey]string, cn *chain.Chain, obID string) *ObserverNode
NewObserverNode returns a ObserverNode
func (*ObserverNode) OnGeneratorConnected ¶
func (ob *ObserverNode) OnGeneratorConnected(p peer.Peer)
OnGeneratorConnected is called after a new generator peer is connected
func (*ObserverNode) OnGeneratorDisconnected ¶
func (ob *ObserverNode) OnGeneratorDisconnected(p peer.Peer)
OnGeneratorDisconnected is called when the generator peer is disconnected
func (*ObserverNode) OnTimerExpired ¶
func (ob *ObserverNode) OnTimerExpired(height uint32, value string)
OnTimerExpired called when rquest expired
func (*ObserverNode) ResetRound ¶
func (ob *ObserverNode) ResetRound()
func (*ObserverNode) Run ¶
func (ob *ObserverNode) Run(BindObserver string, BindGenerator string)
Run starts the pof consensus on the observer
type ObserverNodeMesh ¶
func NewObserverNodeMesh ¶
func NewObserverNodeMesh(key key.Key, NetAddressMap map[common.PublicKey]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
type RoundState ¶
type RoundState int
const ( EmptyState RoundState = iota RoundVoteState RoundVoteAckState BlockWaitState BlockVoteState )
consts
func (RoundState) String ¶
func (r RoundState) String() string
type RoundVoteAckMessage ¶
type RoundVoteAckMessage struct { ChainID *big.Int LastHash hash.Hash256 TargetHeight uint32 TimeoutCount uint32 Generator common.Address PublicKey common.PublicKey Timestamp uint64 IsReply bool }
RoundVoteAckMessage is a message for a round vote ack
func (*RoundVoteAckMessage) ReadFrom ¶
func (s *RoundVoteAckMessage) ReadFrom(r io.Reader) (int64, error)
func (*RoundVoteAckMessage) TypeID ¶
func (s *RoundVoteAckMessage) TypeID() uint32
type RoundVoteMessage ¶
type RoundVoteMessage struct { ChainID *big.Int LastHash hash.Hash256 TargetHeight uint32 TimeoutCount uint32 Generator common.Address PublicKey common.PublicKey Timestamp uint64 IsReply bool }
RoundVoteMessage is a message for a round vote
func (*RoundVoteMessage) TypeID ¶
func (s *RoundVoteMessage) TypeID() uint32
type VoteRound ¶
type VoteRound struct { RoundState RoundState TargetHeight uint32 RoundVoteMessageMap map[common.PublicKey]*RoundVoteMessage RoundVoteAckMessageMap map[common.PublicKey]*RoundVoteAckMessage MinRoundVoteAck *RoundVoteAckMessage BlockRoundMap map[uint32]*BlockRound RoundVoteWaitMap map[common.PublicKey]*RoundVoteMessage RoundVoteAckMessageWaitMap map[common.PublicKey]*RoundVoteAckMessage VoteFailCount int }
VoteRound is data for the voting round
func NewVoteRound ¶
NewVoteRound returns a VoteRound
Source Files
¶
- debug.go
- errors.go
- generator_mesh.go
- generator_node.go
- generator_node_observer.go
- generator_node_peer.go
- generator_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
- util_key.go
- vote_round.go