Documentation ¶
Index ¶
- Constants
- Variables
- func Handshake(p *p2p.Peer, rw p2p.MsgReadWriter, mac string, sig []byte, term uint64, ...) (address common.Address, dporVersion int, err error)
- func ImpeachedProposer(header *types.Header) (common.Address, error)
- func IsCheckPoint(number uint64, termLen uint64, viewLen uint64) bool
- func IsDefaultValidator(nodeID string, defaultValidators []string) bool
- func IsDporMsg(msg p2p.Msg) bool
- func IsSyncMsg(msg p2p.Msg) bool
- func ReadSignerStatus(msg p2p.Msg, signerStatusData *SignerStatusData) (address common.Address, dporVersion int, err error)
- func RecoverBlockFromMsg(msg p2p.Msg, p interface{}) (*types.Block, error)
- func RecoverHeaderFromMsg(msg p2p.Msg, p interface{}) (*types.Header, error)
- func TermOf(blockNum uint64) uint64
- func ValidMacSig(mac string, sig []byte) (valid bool, signer common.Address, err error)
- func VerifyBlockFields(block *types.Block) error
- func VerifyHeaderFields(header *types.Header) error
- func WaitForEnoughImpeachValidators(h *Handler, term uint64, quitCh chan struct{}) (validators map[common.Address]*RemoteValidator)
- func WaitForEnoughPreprepareValidators(h *Handler, term uint64, quitCh chan struct{}, deadline time.Time) (validators map[common.Address]*RemoteValidator)
- func WaitForEnoughValidators(h *Handler, term uint64, quitCh chan struct{}) (validators map[common.Address]*RemoteValidator)
- type Action
- type BlockIdentifier
- type BlockOrHeader
- type ChainBackend
- type ClientBackend
- type ConsensusStateMachine
- type ContractBackend
- type ContractCaller
- type DSMStatus
- type Dialer
- func (d *Dialer) AddPeer(cpcVersion int, p *p2p.Peer, rw p2p.MsgReadWriter, mac string, sig []byte, ...) (string, bool, bool, error)
- func (d *Dialer) AddRemoteProposer(cpcVersion int, dporVersion int, p *p2p.Peer, rw p2p.MsgReadWriter, ...) (*RemoteProposer, error)
- func (d *Dialer) AddRemoteValidator(cpcVersion int, dporVersion int, p *p2p.Peer, rw p2p.MsgReadWriter, ...) (*RemoteValidator, error)
- func (d *Dialer) AllUselessProposers() map[common.Address]*RemoteProposer
- func (d *Dialer) EnoughImpeachValidatorsOfTerm(term uint64) (validators map[common.Address]*RemoteValidator, enough bool)
- func (d *Dialer) EnoughValidatorsOfTerm(term uint64) (validators map[common.Address]*RemoteValidator, enough bool)
- func (d *Dialer) GetProposer(addr string) (*RemoteProposer, bool)
- func (d *Dialer) GetValidator(addr string) (*RemoteValidator, bool)
- func (d *Dialer) IsCurrentOrFutureProposer(address common.Address, term uint64, futureTerm uint64) bool
- func (d *Dialer) IsCurrentOrFutureValidator(address common.Address, term uint64, futureTerm uint64) bool
- func (d *Dialer) KeepConnection()
- func (d *Dialer) PeerInfos() ([]*PeerInfo, error)
- func (d *Dialer) ProposersOfTerm(term uint64) map[common.Address]*RemoteProposer
- func (d *Dialer) RemoveRemoteProposers(addr string) error
- func (d *Dialer) RemoveRemoteValidators(addr string) error
- func (d *Dialer) SetDporService(dpor DporService)
- func (d *Dialer) SetProposer(addr string, proposer *RemoteProposer)
- func (d *Dialer) SetServer(server *p2p.Server)
- func (d *Dialer) SetValidator(addr string, validator *RemoteValidator)
- func (d *Dialer) Stop()
- func (d *Dialer) UpdateRemoteProposers(term uint64, proposers []common.Address) error
- func (d *Dialer) ValidatorsOfTerm(term uint64) map[common.Address]*RemoteValidator
- type DporService
- type HandleGeneratedImpeachBlock
- type Handler
- func (h *Handler) AddPeer(version int, p *p2p.Peer, rw p2p.MsgReadWriter) (string, bool, bool, error)
- func (h *Handler) Available() bool
- func (h *Handler) BroadcastCommitHeader(header *types.Header)
- func (h *Handler) BroadcastCommitImpeachHeader(header *types.Header)
- func (h *Handler) BroadcastPrepareHeader(header *types.Header)
- func (h *Handler) BroadcastPrepareImpeachHeader(header *types.Header)
- func (h *Handler) BroadcastPreprepareBlock(block *types.Block)
- func (h *Handler) BroadcastPreprepareImpeachBlock(block *types.Block)
- func (h *Handler) BroadcastValidateBlock(block *types.Block)
- func (h *Handler) BroadcastValidateImpeachBlock(block *types.Block)
- func (h *Handler) Coinbase() common.Address
- func (h *Handler) GetDialer() *Dialer
- func (h *Handler) GetProtocol() consensus.Protocol
- func (h *Handler) HandleMsg(addr string, version int, p *p2p.Peer, rw p2p.MsgReadWriter, msg p2p.Msg) (string, error)
- func (h *Handler) Length() uint64
- func (h *Handler) Name() string
- func (h *Handler) NodeInfo() interface{}
- func (h *Handler) PeerInfos() ([]*PeerInfo, error)
- func (h *Handler) PendingBlockBroadcastLoop()
- func (h *Handler) PendingImpeachBlockBroadcastLoop()
- func (h *Handler) ProposerBroadcastPreprepareBlock(block *types.Block)
- func (vh *Handler) ReceiveFailbackImpeachBlock(block *types.Block) error
- func (vh *Handler) ReceiveImpeachBlock(block *types.Block) error
- func (ph *Handler) ReceiveMinedPendingBlock(block *types.Block) error
- func (h *Handler) RemovePeer(addr string)
- func (h *Handler) SetAvailable()
- func (h *Handler) SetCoinbase(coinbase common.Address)
- func (h *Handler) SetDialer(d *Dialer)
- func (h *Handler) SetDporService(dpor DporService)
- func (h *Handler) SetDporStateMachine(fsm ConsensusStateMachine)
- func (h *Handler) SetServer(server *p2p.Server)
- func (h *Handler) Start()
- func (h *Handler) Stop()
- func (h *Handler) Version() uint
- type HandlerMode
- type LBFT
- type LBFT2
- func (p *LBFT2) CommitHandler(input *BlockOrHeader, msgCode MsgCode, state consensus.State) ([]*BlockOrHeader, Action, MsgCode, consensus.State, error)
- func (p *LBFT2) FSM(input *BlockOrHeader, msgCode MsgCode) ([]*BlockOrHeader, Action, MsgCode, error)
- func (p *LBFT2) Faulty() uint64
- func (p *LBFT2) IdleHandler(input *BlockOrHeader, msgCode MsgCode, state consensus.State) ([]*BlockOrHeader, Action, MsgCode, consensus.State, error)
- func (p *LBFT2) ImpeachCommitHandler(input *BlockOrHeader, msgCode MsgCode, state consensus.State) ([]*BlockOrHeader, Action, MsgCode, consensus.State, error)
- func (p *LBFT2) ImpeachHandler(input *BlockOrHeader, msgCode MsgCode, state consensus.State) ([]*BlockOrHeader, Action, MsgCode, consensus.State, error)
- func (p *LBFT2) ImpeachPrepareHandler(input *BlockOrHeader, msgCode MsgCode, state consensus.State) ([]*BlockOrHeader, Action, MsgCode, consensus.State, error)
- func (p *LBFT2) Number() uint64
- func (p *LBFT2) PrepareHandler(input *BlockOrHeader, msgCode MsgCode, state consensus.State) ([]*BlockOrHeader, Action, MsgCode, consensus.State, error)
- func (p *LBFT2) SetNumber(number uint64)
- func (p *LBFT2) SetState(state consensus.State)
- func (p *LBFT2) State() consensus.State
- func (p *LBFT2) Status() DSMStatus
- func (p *LBFT2) ValidateHandler(input *BlockOrHeader, msgCode MsgCode, state consensus.State) ([]*BlockOrHeader, Action, MsgCode, consensus.State, error)
- type MsgCode
- type PeerInfo
- type RecentBlocks
- type RemoteProposer
- type RemoteSigner
- type RemoteValidator
- func (s *RemoteValidator) AsyncSendCommitHeader(header *types.Header)
- func (s *RemoteValidator) AsyncSendCommitImpeachHeader(header *types.Header)
- func (s *RemoteValidator) AsyncSendImpeachValidateBlock(block *types.Block)
- func (s *RemoteValidator) AsyncSendPrepareHeader(header *types.Header)
- func (s *RemoteValidator) AsyncSendPrepareImpeachHeader(header *types.Header)
- func (s *RemoteValidator) AsyncSendPreprepareBlock(block *types.Block)
- func (s *RemoteValidator) AsyncSendPreprepareImpeachBlock(block *types.Block)
- func (s *RemoteValidator) AsyncSendValidateBlock(block *types.Block)
- func (s *RemoteValidator) SendCommitHeader(header *types.Header) error
- func (s *RemoteValidator) SendCommitImpeachHeader(header *types.Header) error
- func (s *RemoteValidator) SendImpeachValidateBlock(block *types.Block) error
- func (s *RemoteValidator) SendNewSignerMsg(eb common.Address) error
- func (s *RemoteValidator) SendPrepareHeader(header *types.Header) error
- func (s *RemoteValidator) SendPrepareImpeachHeader(header *types.Header) error
- func (s *RemoteValidator) SendPreprepareBlock(block *types.Block) error
- func (s *RemoteValidator) SendPreprepareImpeachBlock(block *types.Block) error
- func (s *RemoteValidator) SendValidateBlock(block *types.Block) error
- func (s *RemoteValidator) Stop()
- type Role
- type SignFn
- type SignerStatusData
- type VerifyBlockFn
Constants ¶
const ( // ProtocolName protocol name ProtocolName = "dpor" // ProtocolVersion protocol version ProtocolVersion = 65 // ProtocolLength protocol length, max msg code ProtocolLength = 100 )
const ( // PbftMsgOutset is not a msg code, just used for msg code comparing PbftMsgOutset = 0x42 // NewSignerMsg is a msg code used for network building NewSignerMsg = 0x42 // those are messages for normal block verification PreprepareBlockMsg = 0x43 PrepareHeaderMsg = 0x44 CommitHeaderMsg = 0x45 ValidateBlockMsg = 0x46 // those are messages for abnormal(impeachment) block verification PreprepareImpeachBlockMsg = 0x47 PrepareImpeachHeaderMsg = 0x48 CommitImpeachHeaderMsg = 0x49 ValidateImpeachBlockMsg = 0x50 )
Protocol messages belonging to cpc/01
const ( // ErrMsgTooLarge is returned if msg if too large ErrMsgTooLarge = iota // ErrDecode is returned if decode failed ErrDecode // ErrInvalidMsgCode is returned if msg code is invalid ErrInvalidMsgCode // ErrProtocolVersionMismatch is returned if protocol version is not matched when handshaking ErrProtocolVersionMismatch // ErrNetworkIDMismatch is returned if networkid is not matched when handshaking ErrNetworkIDMismatch // ErrGenesisBlockMismatch is returned if genesis block is different from remote signer ErrGenesisBlockMismatch // ErrNoStatusMsg is returned if failed when reading status msg ErrNoStatusMsg // ErrExtraStatusMsg is returned if failed when extracting status msg ErrExtraStatusMsg // ErrSuspendedPeer is returned if remote signer is dead ErrSuspendedPeer )
const ProtocolMaxMsgSize = 10 * 1024 * 1024
ProtocolMaxMsgSize Maximum cap on the size of a protocol message
Variables ¶
var ( // ErrUnknownHandlerMode is returned if in an unknown mode ErrUnknownHandlerMode = errors.New("unknown dpor handler mode") // ErrFailToAddPendingBlock is returned if failed to add block to pending ErrFailToAddPendingBlock = errors.New("fail to add pending block") // ErrNotSigner is returned if remote peer is not signer when handshaking ErrNotSigner = errors.New("peer is not in the PV committees") )
var ( ErrBlockAlreadyInChain = errors.New("the block is already in local chain") ErrMsgTooOld = errors.New("the msg is outdated") ErrInvalidBlockFormat = errors.New("the block format is invalid") ErrInvalidHeaderFormat = errors.New("the header format is invalid") )
errors returned by fsm
Functions ¶
func Handshake ¶
func Handshake(p *p2p.Peer, rw p2p.MsgReadWriter, mac string, sig []byte, term uint64, futureTerm uint64) (address common.Address, dporVersion int, err error)
Handshake tries to handshake with remote validator
func ImpeachedProposer ¶
ImpeachedProposer returns the impeached proposer of a header if the block is an impeach block
func IsCheckPoint ¶
IsCheckPoint returns if a given block number is in a checkpoint with given termLen and viewLen
func IsDefaultValidator ¶
IsDefaultValidator checks if a validator is a default validator
func ReadSignerStatus ¶
func ReadSignerStatus(msg p2p.Msg, signerStatusData *SignerStatusData) (address common.Address, dporVersion int, err error)
ReadSignerStatus reads status of remote validator
func RecoverBlockFromMsg ¶
RecoverBlockFromMsg recovers a block from a p2p msg
func RecoverHeaderFromMsg ¶
RecoverHeaderFromMsg recovers a header from a p2p msg
func ValidMacSig ¶
ValidMacSig recovers an address from a signed mac
func VerifyBlockFields ¶
VerifyBlockFields verifies that all fields in the block do exist. if the function returns nil, then nil-pointer panic will not occur.
func VerifyHeaderFields ¶
VerifyHeaderFields verifies that all fields in the header do exist. if the function returns nil, then nil-pointer panic will not occur.
func WaitForEnoughImpeachValidators ¶
func WaitForEnoughImpeachValidators(h *Handler, term uint64, quitCh chan struct{}) (validators map[common.Address]*RemoteValidator)
func WaitForEnoughPreprepareValidators ¶
func WaitForEnoughPreprepareValidators(h *Handler, term uint64, quitCh chan struct{}, deadline time.Time) (validators map[common.Address]*RemoteValidator)
WaitForEnoughPreprepareValidators is used by proposer when trying to broadcast a preprepare block msg
func WaitForEnoughValidators ¶
func WaitForEnoughValidators(h *Handler, term uint64, quitCh chan struct{}) (validators map[common.Address]*RemoteValidator)
Types ¶
type BlockIdentifier ¶
type BlockIdentifier struct {
// contains filtered or unexported fields
}
BlockIdentifier is the identifier to a block
func NewBlockIdentifier ¶
func NewBlockIdentifier(number uint64, hash common.Hash) BlockIdentifier
NewBlockIdentifier creates a block identifier with given block number and hash
type BlockOrHeader ¶
type BlockOrHeader struct {
// contains filtered or unexported fields
}
BlockOrHeader represents a block or a header
func NewBOHFromBlock ¶
func NewBOHFromBlock(block *types.Block) *BlockOrHeader
NewBOHFromBlock creates a new BlockOrHeader from a block
func NewBOHFromHeader ¶
func NewBOHFromHeader(header *types.Header) *BlockOrHeader
NewBOHFromHeader creates a new BlockOrHeader from a header
func (*BlockOrHeader) Hash ¶
func (bh *BlockOrHeader) Hash() common.Hash
Hash returns hash of the boh
func (*BlockOrHeader) IsBlock ¶
func (bh *BlockOrHeader) IsBlock() bool
IsBlock checks if the boh is a block
func (*BlockOrHeader) IsHeader ¶
func (bh *BlockOrHeader) IsHeader() bool
IsHeader checks if the boh is a header
func (*BlockOrHeader) Number ¶
func (bh *BlockOrHeader) Number() uint64
Number returns number of the boh
type ChainBackend ¶
type ChainBackend interface { HeaderByNumber(ctx context.Context, number *big.Int) (*types.Header, error) BalanceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (*big.Int, error) NonceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (uint64, error) }
ChainBackend is the chain client operation interface
type ClientBackend ¶
type ClientBackend interface { ChainBackend ContractBackend }
ClientBackend is the client operation interface
type ConsensusStateMachine ¶
type ConsensusStateMachine interface { Status() DSMStatus Faulty() uint64 FSM(input *BlockOrHeader, msgCode MsgCode) ([]*BlockOrHeader, Action, MsgCode, error) }
ConsensusStateMachine is a state machine used for consensus protocol for validators msg processing
type ContractBackend ¶
type ContractBackend interface { bind.ContractBackend }
ContractBackend is the contract client operation interface
type ContractCaller ¶
type ContractCaller struct { Key *keystore.Key Client ClientBackend GasLimit uint64 }
ContractCaller is used to call the contract with given key and client. TODO: remove this later
func NewContractCaller ¶
func NewContractCaller(key *keystore.Key, client ClientBackend, gasLimit uint64) (*ContractCaller, error)
NewContractCaller returns a ContractCaller.
type Dialer ¶
type Dialer struct {
// contains filtered or unexported fields
}
Dialer dials a remote peer
func (*Dialer) AddPeer ¶
func (d *Dialer) AddPeer(cpcVersion int, p *p2p.Peer, rw p2p.MsgReadWriter, mac string, sig []byte, term uint64, futureTerm uint64) (string, bool, bool, error)
AddPeer adds a peer to local dpor peer set: remote proposers or remote validators
func (*Dialer) AddRemoteProposer ¶
func (d *Dialer) AddRemoteProposer(cpcVersion int, dporVersion int, p *p2p.Peer, rw p2p.MsgReadWriter, address common.Address) (*RemoteProposer, error)
AddRemoteProposer adds a p2p peer to local proposers set
func (*Dialer) AddRemoteValidator ¶
func (d *Dialer) AddRemoteValidator(cpcVersion int, dporVersion int, p *p2p.Peer, rw p2p.MsgReadWriter, address common.Address) (*RemoteValidator, error)
AddRemoteValidator adds a p2p peer to local validators set
func (*Dialer) AllUselessProposers ¶
func (d *Dialer) AllUselessProposers() map[common.Address]*RemoteProposer
AllUselessProposers returns all useless proposers
func (*Dialer) EnoughImpeachValidatorsOfTerm ¶
func (d *Dialer) EnoughImpeachValidatorsOfTerm(term uint64) (validators map[common.Address]*RemoteValidator, enough bool)
EnoughImpeachValidatorsOfTerm returns validator of given term and whether it is enough for impeach
func (*Dialer) EnoughValidatorsOfTerm ¶
func (d *Dialer) EnoughValidatorsOfTerm(term uint64) (validators map[common.Address]*RemoteValidator, enough bool)
EnoughValidatorsOfTerm returns validator of given term and whether it is enough
func (*Dialer) GetProposer ¶
func (d *Dialer) GetProposer(addr string) (*RemoteProposer, bool)
func (*Dialer) GetValidator ¶
func (d *Dialer) GetValidator(addr string) (*RemoteValidator, bool)
func (*Dialer) IsCurrentOrFutureProposer ¶
func (d *Dialer) IsCurrentOrFutureProposer(address common.Address, term uint64, futureTerm uint64) bool
IsCurrentOrFutureProposer checks if an address is a proposer in the period between current term and future term
func (*Dialer) IsCurrentOrFutureValidator ¶
func (d *Dialer) IsCurrentOrFutureValidator(address common.Address, term uint64, futureTerm uint64) bool
IsCurrentOrFutureValidator checks if an address is a validator in the period between current term and future term
func (*Dialer) KeepConnection ¶
func (d *Dialer) KeepConnection()
KeepConnection tries to dial remote validators if local node is a current or future proposer and disconnect remote validators if it is not
func (*Dialer) ProposersOfTerm ¶
func (d *Dialer) ProposersOfTerm(term uint64) map[common.Address]*RemoteProposer
ProposersOfTerm returns all proposers of given term
func (*Dialer) RemoveRemoteProposers ¶
RemoveRemoteProposers removes remote proposer by it's addr
func (*Dialer) RemoveRemoteValidators ¶
RemoveRemoteValidators removes remote proposer by it's addr
func (*Dialer) SetDporService ¶
func (d *Dialer) SetDporService(dpor DporService)
SetDporService sets dpor service to dialer
func (*Dialer) SetProposer ¶
func (d *Dialer) SetProposer(addr string, proposer *RemoteProposer)
func (*Dialer) SetValidator ¶
func (d *Dialer) SetValidator(addr string, validator *RemoteValidator)
func (*Dialer) UpdateRemoteProposers ¶
UpdateRemoteProposers updates dialer.remoteProposers.
func (*Dialer) ValidatorsOfTerm ¶
func (d *Dialer) ValidatorsOfTerm(term uint64) map[common.Address]*RemoteValidator
ValidatorsOfTerm returns all validators of given term
type DporService ¶
type DporService interface { // Coinbase returns current coinbase Coinbase() common.Address // TermLength returns term length TermLength() uint64 // Faulty returns the number of faulty nodes Faulty() uint64 // ViewLength returns view length ViewLength() uint64 // ValidatorsNum returns number of validators ValidatorsNum() uint64 // Period returns period of block generation Period() time.Duration // BlockDelay returns max delay of preprepare block propagation BlockDelay() time.Duration // TermOf returns the term number of given block number TermOf(number uint64) uint64 // FutureTermOf returns the future term number of given block number FutureTermOf(number uint64) uint64 // VerifyProposerOf verifies if an address is a proposer of given term VerifyProposerOf(signer common.Address, term uint64) (bool, error) // VerifyValidatorOf verifies if an address is a validator of given term VerifyValidatorOf(signer common.Address, term uint64) (bool, error) // ValidatorsOf returns the list of validators in committee for the specified block number ValidatorsOf(number uint64) ([]common.Address, error) // ProposersOf returns the list of proposers in committee for the specified block number ProposersOf(number uint64) ([]common.Address, error) // ProposerOf returns the proposer of the specified block number by rpt and election calculation ProposerOf(number uint64) (common.Address, error) // ValidatorsOfTerm returns the list of validators in committee for the specified term ValidatorsOfTerm(term uint64) ([]common.Address, error) // ProposersOfTerm returns the list of proposers in committee for the specified term ProposersOfTerm(term uint64) ([]common.Address, error) // VerifyHeaderWithState verifies the given header // if in preprepared state, verify basic fields // if in prepared state, verify if enough prepare sigs // if in committed state, verify if enough commit sigs VerifyHeaderWithState(header *types.Header, state consensus.State) error // ValidateBlock verifies a block ValidateBlock(block *types.Block, verifySigs bool, verifyProposers bool) error // SignHeader signs the block if not signed it yet SignHeader(header *types.Header, state consensus.State) error // BroadcastBlock broadcasts a block to normal peers(not pbft replicas) BroadcastBlock(block *types.Block, prop bool) // InsertChain inserts a block to chain InsertChain(block *types.Block) error // Status returns a pbft replica's status Status() *consensus.PbftStatus // StatusUpdate updates status of dpor StatusUpdate() error // CreateImpeachBlock returns an impeachment block CreateImpeachBlock() (*types.Block, error) // CreateFailbackImpeachBlocks creates impeachment blocks with failback timestamps CreateFailbackImpeachBlocks() (firstImpeachment *types.Block, secondImpeachment *types.Block, err error) // GetCurrentBlock returns current block GetCurrentBlock() *types.Block // HasBlockInChain returns if a block is in local chain HasBlockInChain(hash common.Hash, number uint64) bool // GetBlockFromChain returns a block from local chain with given hash and number GetBlockFromChain(hash common.Hash, number uint64) *types.Block // ImpeachTimeout returns the timeout for impeachment ImpeachTimeout() time.Duration // ECRecoverProposer recovers proposer's address from a seal of a header ECRecoverProposer(header *types.Header) (common.Address, error) // ECRecoverSigs recovers signer address and corresponding signature, it ignores empty signature and return empty // addresses if one of the sigs are illegal ECRecoverSigs(header *types.Header, state consensus.State) ([]common.Address, []types.DporSignature, error) // Update the signature to prepare signature cache(two kinds of sigs, one for prepared, another for final) UpdatePrepareSigsCache(validator common.Address, hash common.Hash, sig types.DporSignature) // Update the signature to final signature cache(two kinds of sigs, one for prepared, another for final) UpdateFinalSigsCache(validator common.Address, hash common.Hash, sig types.DporSignature) // GetMac signs a Mac GetMac() (string, []byte, error) // SyncFrom tries to sync block from given peer SyncFrom(p *p2p.Peer) // Synchronize tries to sync block from best peer Synchronize() }
DporService provides functions used by dpor handler
type HandleGeneratedImpeachBlock ¶
HandleGeneratedImpeachBlock handles generated impeach block
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler implements PbftHandler
func NewHandler ¶
NewHandler creates a new Handler
func (*Handler) AddPeer ¶
func (h *Handler) AddPeer(version int, p *p2p.Peer, rw p2p.MsgReadWriter) (string, bool, bool, error)
AddPeer adds a p2p peer to local peer set
func (*Handler) BroadcastCommitHeader ¶
BroadcastCommitHeader broadcasts signed commit header to remote validators
func (*Handler) BroadcastCommitImpeachHeader ¶
BroadcastCommitImpeachHeader broadcasts signed impeach commit header to remote validators
func (*Handler) BroadcastPrepareHeader ¶
BroadcastPrepareHeader broadcasts signed prepare header to remote validators
func (*Handler) BroadcastPrepareImpeachHeader ¶
BroadcastPrepareImpeachHeader broadcasts signed impeach prepare header to remote validators
func (*Handler) BroadcastPreprepareBlock ¶
BroadcastPreprepareBlock broadcasts generated block to validators
func (*Handler) BroadcastPreprepareImpeachBlock ¶
BroadcastPreprepareImpeachBlock broadcasts generated impeach block to validators
func (*Handler) BroadcastValidateBlock ¶
BroadcastValidateBlock broadcasts validate block to validators
func (*Handler) BroadcastValidateImpeachBlock ¶
BroadcastValidateImpeachBlock broadcasts validate impeach block to validators
func (*Handler) GetProtocol ¶
GetProtocol returns handler protocol
func (*Handler) HandleMsg ¶
func (h *Handler) HandleMsg(addr string, version int, p *p2p.Peer, rw p2p.MsgReadWriter, msg p2p.Msg) (string, error)
HandleMsg handles a msg of peer with id "addr"
func (*Handler) PendingBlockBroadcastLoop ¶
func (h *Handler) PendingBlockBroadcastLoop()
PendingBlockBroadcastLoop loops to broadcast blocks
func (*Handler) PendingImpeachBlockBroadcastLoop ¶
func (h *Handler) PendingImpeachBlockBroadcastLoop()
PendingImpeachBlockBroadcastLoop loops to broadcasts pending impeachment block
func (*Handler) ProposerBroadcastPreprepareBlock ¶
ProposerBroadcastPreprepareBlock broadcasts generated block to validators
func (*Handler) ReceiveFailbackImpeachBlock ¶
ReceiveFailbackImpeachBlock receives a failback impeach block to add to pending block channel
func (*Handler) ReceiveImpeachBlock ¶
ReceiveImpeachBlock receives an impeach block to add to pending block channel
func (*Handler) ReceiveMinedPendingBlock ¶
ReceiveMinedPendingBlock receives a block to add to pending block channel
func (*Handler) RemovePeer ¶
RemovePeer removes a p2p peer with its addr
func (*Handler) SetCoinbase ¶
SetCoinbase sets coinbase of handler
func (*Handler) SetDporService ¶
func (h *Handler) SetDporService(dpor DporService)
SetDporService sets dpor service to handler
func (*Handler) SetDporStateMachine ¶
func (h *Handler) SetDporStateMachine(fsm ConsensusStateMachine)
SetDporStateMachine sets dpor state machine
type HandlerMode ¶
type HandlerMode int
HandlerMode indicates the run mode of handler
const ( LBFTMode HandlerMode = iota LBFT2Mode )
Those are handler mode
type LBFT ¶
type LBFT struct {
// contains filtered or unexported fields
}
LBFT is the 1.0 version for lbft protocol within validator committee
type LBFT2 ¶
type LBFT2 struct {
// contains filtered or unexported fields
}
LBFT2 is a state machine used for consensus protocol for validators msg processing
func NewLBFT2 ¶
func NewLBFT2(faulty uint64, dpor DporService, handleImpeachBlock HandleGeneratedImpeachBlock, handleFailbackImpeachBlock HandleGeneratedImpeachBlock, db database.Database) *LBFT2
NewLBFT2 create an LBFT2 instance
func (*LBFT2) CommitHandler ¶
func (p *LBFT2) CommitHandler(input *BlockOrHeader, msgCode MsgCode, state consensus.State) ([]*BlockOrHeader, Action, MsgCode, consensus.State, error)
CommitHandler is the handler for Commit state
func (*LBFT2) FSM ¶
func (p *LBFT2) FSM(input *BlockOrHeader, msgCode MsgCode) ([]*BlockOrHeader, Action, MsgCode, error)
FSM implements ConsensusStateMachine.FSM
func (*LBFT2) IdleHandler ¶
func (p *LBFT2) IdleHandler(input *BlockOrHeader, msgCode MsgCode, state consensus.State) ([]*BlockOrHeader, Action, MsgCode, consensus.State, error)
IdleHandler is the handler for Idle state
func (*LBFT2) ImpeachCommitHandler ¶
func (p *LBFT2) ImpeachCommitHandler(input *BlockOrHeader, msgCode MsgCode, state consensus.State) ([]*BlockOrHeader, Action, MsgCode, consensus.State, error)
ImpeachCommitHandler is the handler for ImpeachCommit state
func (*LBFT2) ImpeachHandler ¶
func (p *LBFT2) ImpeachHandler(input *BlockOrHeader, msgCode MsgCode, state consensus.State) ([]*BlockOrHeader, Action, MsgCode, consensus.State, error)
ImpeachHandler is the handler for all impeachment related msg
func (*LBFT2) ImpeachPrepareHandler ¶
func (p *LBFT2) ImpeachPrepareHandler(input *BlockOrHeader, msgCode MsgCode, state consensus.State) ([]*BlockOrHeader, Action, MsgCode, consensus.State, error)
ImpeachPrepareHandler is the handler for ImpeachPrepare state
func (*LBFT2) PrepareHandler ¶
func (p *LBFT2) PrepareHandler(input *BlockOrHeader, msgCode MsgCode, state consensus.State) ([]*BlockOrHeader, Action, MsgCode, consensus.State, error)
PrepareHandler is the handler for Prepare state
func (*LBFT2) ValidateHandler ¶
func (p *LBFT2) ValidateHandler(input *BlockOrHeader, msgCode MsgCode, state consensus.State) ([]*BlockOrHeader, Action, MsgCode, consensus.State, error)
ValidateHandler is the handler for bot Validate state and ImpeachValidate state
type MsgCode ¶
type MsgCode uint8
MsgCode is type enumerator for FSM message type
type RecentBlocks ¶
type RecentBlocks struct {
// contains filtered or unexported fields
}
RecentBlocks caches recent received blocks
func NewRecentBlocks ¶
func NewRecentBlocks(db database.Database) *RecentBlocks
NewRecentBlocks creates a new block cache object
func (*RecentBlocks) AddBlock ¶
func (rb *RecentBlocks) AddBlock(block *types.Block) error
AddBlock adds a block to caches
func (*RecentBlocks) GetBlock ¶
func (rb *RecentBlocks) GetBlock(bi BlockIdentifier) (*types.Block, error)
GetBlock returns a block with given block identifier
func (*RecentBlocks) GetBlockIdentifiers ¶
func (rb *RecentBlocks) GetBlockIdentifiers() []BlockIdentifier
GetBlockIdentifiers returns a slice of block identifiers in this cache
func (*RecentBlocks) RemoveBlock ¶
func (rb *RecentBlocks) RemoveBlock(bi BlockIdentifier) error
RemoveBlock removes a block from caches
type RemoteProposer ¶
type RemoteProposer struct {
*RemoteSigner
}
RemoteProposer represents a remote proposer waiting to be connected.
func NewRemoteProposer ¶
func NewRemoteProposer(address common.Address) *RemoteProposer
NewRemoteProposer creates a new remote proposer
type RemoteSigner ¶
RemoteSigner represents a remote peer, ether proposer or validator
func NewRemoteSigner ¶
func NewRemoteSigner(address common.Address) *RemoteSigner
NewRemoteSigner creates a new remote signer
func (*RemoteSigner) AddStatic ¶
func (s *RemoteSigner) AddStatic(srv *p2p.Server) error
AddStatic adds remote validator as a static peer
func (*RemoteSigner) Coinbase ¶
func (s *RemoteSigner) Coinbase() common.Address
Coinbase returns remote peer's addr
func (*RemoteSigner) EnodeID ¶
func (s *RemoteSigner) EnodeID() string
EnodeID returns remote signer's enode id
func (*RemoteSigner) Info ¶
func (s *RemoteSigner) Info() *PeerInfo
func (*RemoteSigner) SetPeer ¶
func (s *RemoteSigner) SetPeer(cpcVersion int, dporVersion int, role Role, p *p2p.Peer, rw p2p.MsgReadWriter)
SetPeer sets a p2p peer
type RemoteValidator ¶
type RemoteValidator struct { *RemoteSigner // contains filtered or unexported fields }
RemoteValidator represents a remote signer waiting to be connected and communicate with.
func NewRemoteValidator ¶
func NewRemoteValidator(address common.Address) *RemoteValidator
NewRemoteValidator creates a new NewRemoteValidator with given view idx and address.
func (*RemoteValidator) AsyncSendCommitHeader ¶
func (s *RemoteValidator) AsyncSendCommitHeader(header *types.Header)
AsyncSendCommitHeader sends new signed block header.
func (*RemoteValidator) AsyncSendCommitImpeachHeader ¶
func (s *RemoteValidator) AsyncSendCommitImpeachHeader(header *types.Header)
AsyncSendCommitImpeachHeader sends new signed block header.
func (*RemoteValidator) AsyncSendImpeachValidateBlock ¶
func (s *RemoteValidator) AsyncSendImpeachValidateBlock(block *types.Block)
AsyncSendImpeachValidateBlock queues an entire block for propagation to a remote peer. If the peer's broadcast queue is full, the event is silently dropped.
func (*RemoteValidator) AsyncSendPrepareHeader ¶
func (s *RemoteValidator) AsyncSendPrepareHeader(header *types.Header)
AsyncSendPrepareHeader adds a msg to broadcast channel
func (*RemoteValidator) AsyncSendPrepareImpeachHeader ¶
func (s *RemoteValidator) AsyncSendPrepareImpeachHeader(header *types.Header)
AsyncSendPrepareImpeachHeader adds a msg to broadcast channel
func (*RemoteValidator) AsyncSendPreprepareBlock ¶
func (s *RemoteValidator) AsyncSendPreprepareBlock(block *types.Block)
AsyncSendPreprepareBlock queues an entire block for propagation to a remote peer. If the peer's broadcast queue is full, the event is silently dropped.
func (*RemoteValidator) AsyncSendPreprepareImpeachBlock ¶
func (s *RemoteValidator) AsyncSendPreprepareImpeachBlock(block *types.Block)
AsyncSendPreprepareImpeachBlock queues an entire block for propagation to a remote peer. If the peer's broadcast queue is full, the event is silently dropped.
func (*RemoteValidator) AsyncSendValidateBlock ¶
func (s *RemoteValidator) AsyncSendValidateBlock(block *types.Block)
AsyncSendValidateBlock queues an entire block for propagation to a remote peer. If the peer's broadcast queue is full, the event is silently dropped.
func (*RemoteValidator) SendCommitHeader ¶
func (s *RemoteValidator) SendCommitHeader(header *types.Header) error
SendCommitHeader sends new signed block header.
func (*RemoteValidator) SendCommitImpeachHeader ¶
func (s *RemoteValidator) SendCommitImpeachHeader(header *types.Header) error
SendCommitImpeachHeader sends new signed block header.
func (*RemoteValidator) SendImpeachValidateBlock ¶
func (s *RemoteValidator) SendImpeachValidateBlock(block *types.Block) error
SendImpeachValidateBlock propagates an entire block to a remote peer.
func (*RemoteValidator) SendNewSignerMsg ¶
func (s *RemoteValidator) SendNewSignerMsg(eb common.Address) error
SendNewSignerMsg sends a
func (*RemoteValidator) SendPrepareHeader ¶
func (s *RemoteValidator) SendPrepareHeader(header *types.Header) error
SendPrepareHeader sends new signed block header.
func (*RemoteValidator) SendPrepareImpeachHeader ¶
func (s *RemoteValidator) SendPrepareImpeachHeader(header *types.Header) error
SendPrepareImpeachHeader sends new signed block header.
func (*RemoteValidator) SendPreprepareBlock ¶
func (s *RemoteValidator) SendPreprepareBlock(block *types.Block) error
SendPreprepareBlock propagates an entire block to a remote peer.
func (*RemoteValidator) SendPreprepareImpeachBlock ¶
func (s *RemoteValidator) SendPreprepareImpeachBlock(block *types.Block) error
SendPreprepareImpeachBlock propagates an entire block to a remote peer.
func (*RemoteValidator) SendValidateBlock ¶
func (s *RemoteValidator) SendValidateBlock(block *types.Block) error
SendValidateBlock propagates an entire block to a remote peer.
func (*RemoteValidator) Stop ¶
func (s *RemoteValidator) Stop()
type SignFn ¶
SignFn is a signer callback function to request a hash to be signed by a backing account.
type SignerStatusData ¶
SignerStatusData represents signer status when handshaking
type VerifyBlockFn ¶
VerifyBlockFn verifies basic fields of a block