Documentation ¶
Overview ¶
Package protocol
@author: xwc1125
Package protocol ¶
@author: xwc1125
Package protocol ¶
@author: xwc1125
Package protocol ¶
@author: xwc1125
Package protocol ¶
@author: xwc1125
Package protocol ¶
@author: xwc1125
Package protocol ¶
@author: xwc1125
Package protocol ¶
@author: xwc1125
Index ¶
- Constants
- Variables
- func GetSignatureValidator(nodeKey protocol.NodeKey, data []byte, sig *signature.SignResult) (string, error)
- func PrepareCommittedSeal(hash types.Hash) []byte
- type Message
- type MessageSet
- type PBFTBackend
- type PBFTConfig
- type PBFTEngine
- type PrePrepare
- type Proposal
- type ProposalSelector
- type ProposerPolicy
- type Request
- type State
- type Subject
- type Validator
- type ValidatorSet
- type Validators
- type View
Constants ¶
View Source
const ( MsgPrePrepare uint64 = iota // prePrepare MsgPrepare // prepare MsgCommit // commit MsgRoundChange // 轮换 )
消息类型
Variables ¶
View Source
var ( ErrStoppedEngine = errors.New("stopped engine") // 共识已停止 ErrStartedEngine = errors.New("started engine") // 共识已经启动,再次启动时会报错 ErrOldMessage = errors.New("old message") // pbft旧消息 ErrUnknownAncestor = errors.New("unknown ancestor") // 校验新区块时,祖先区块未知 ErrFutureBlock = errors.New("block in the future") // 当区块的时间戳大于当前节点的时间戳 )
Functions ¶
func GetSignatureValidator ¶
func GetSignatureValidator(nodeKey protocol.NodeKey, data []byte, sig *signature.SignResult) (string, error)
GetSignatureValidator 从签名数据中获取签名地址
func PrepareCommittedSeal ¶
PrepareCommittedSeal 根据hash返回committed的签名消息内容
Types ¶
type Message ¶
type Message struct { Code uint64 `json:"code"` // 消息类型 Msg []byte `json:"msg"` // 消息内容 Validator string `json:"validator"` // 验证者(peerId) Signature *signature.SignResult `json:"signature" rlp:"nil"` // 签名内容 CommittedSeal *signature.SignResult `json:"committed_seal" rlp:"nil"` // 被提交的seal }
Message pbft消息结构
func (*Message) FromPayload ¶
func (m *Message) FromPayload(msg []byte, validateFn func(data []byte, signResult *signature.SignResult) (string, error)) error
FromPayload 将msgBytes转换为message
func (*Message) PayloadNoSig ¶
PayloadNoSig Signature为空的bytes数据
type MessageSet ¶
type MessageSet struct {
// contains filtered or unexported fields
}
MessageSet message集合
func NewMessageSet ¶
func NewMessageSet(valSet ValidatorSet) *MessageSet
NewMessageSet 根据validatorSet构造messageSet
type PBFTBackend ¶
type PBFTBackend interface { ID() string // 当前Validator的ID Validators(proposal Proposal) ValidatorSet // validator的集合 ParentValidators(proposal Proposal) ValidatorSet // 获取给定的提议父区块获取validator集合 Verify(proposal Proposal) error // 验证提议 Commit(proposal Proposal, seals []*signature.SignResult) error // 提交已批准的提议,提议将会写入区块链 Sign(data []byte) (*signature.SignResult, error) // 使用私钥进行签名数据 CheckSignature(data []byte, validator string, sig *signature.SignResult) error // 判断签名是否为给定的validator签署的 LastProposal() (Proposal, string) // 获取最新的proposal提议,及proposer提议者的地址 HasProposal(hash types.Hash, height uint64) bool // 检查给定Hash和高度是否有匹配的提议 GetProposer(height uint64) string // 根据区块高度获取提议者地址 }
PBFTBackend pbft核心函数接口
type PBFTConfig ¶
type PBFTConfig struct { Epoch uint64 `json:"epoch" mapstructure:"epoch"` // 期数 RequestTimeout uint64 `json:"timeout" mapstructure:"timeout"` // round 超时时间, 在BlockPeriod不为0时有效 BlockPeriod uint64 `json:"period" mapstructure:"period"` // 区块产生间隔(毫秒) ProposerPolicy ProposerPolicy `json:"policy" mapstructure:"policy"` // Proposer 策略 Managers []types.Address `json:"managers" mapstructure:"managers"` // 创世管理员地址 Validators []string `json:"validators" mapstructure:"validators"` // 创世验证者地址 }
PBFTConfig pbft的配置
type PBFTEngine ¶
type PBFTEngine interface { Start() error Stop() error Request(*Request) error RequestTimeout() NewChainHead() error }
PBFTEngine pbft共识引擎
type PrePrepare ¶
PrePrepare 预处理消息
type Proposal ¶
type Proposal interface { Height() uint64 // 返回提议的序列号 Hash() types.Hash // 返回提议的hash Timestamp() uint64 // 返回提议时间戳 }
Proposal 为区块在共识过程中的抽象接口。
type ProposalSelector ¶
type ProposalSelector func(ValidatorSet, string, uint64) Validator
ProposalSelector 提议选举策略
type ProposerPolicy ¶
type ProposerPolicy uint64
ProposerPolicy 提议策略
const ( RoundRobin ProposerPolicy = iota // 在每个区块或者round更换时,更换proposer Sticky // 在round更换时更换proposer )
type ValidatorSet ¶
type ValidatorSet interface { CalcProposer(lastProposer string, round uint64) // 根据Proposer计算下一个Proposer, 并记录到ValidatorSet, 通过GetProposer查询 GetProposer() Validator // 返回当前proposer IsProposer(id string) bool // 查询指定的id是否为proposer Policy() ProposerPolicy // 提议选举策略 GetByIndex(index uint64) Validator // 通过索引查找validator GetById(id string) (index int, validator Validator) // 通过ID查找validator, 并返回其索引 AddValidator(id string) bool // 添加validator RemoveValidator(id string) bool // 删除validator List() []Validator // 返回 validator 数组 Size() int // 返回验证者集合的长度 Copy() ValidatorSet // 复制 FaultTolerantNum() int // 容错节点数 }
ValidatorSet 验证者集
type Validators ¶
type Validators []Validator
Validators 校验者集合
func (Validators) Len ¶
func (slice Validators) Len() int
func (Validators) Less ¶
func (slice Validators) Less(i, j int) bool
func (Validators) Swap ¶
func (slice Validators) Swap(i, j int)
Source Files ¶
Click to show internal directories.
Click to hide internal directories.