consensus

package
v0.0.0-...-8cfcfd0 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2022 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LogBlockCollection

type LogBlockCollection map[uint64]map[int]*model.PbftBlock

blknum: { singerpairs: block }

func (LogBlockCollection) FindBlock

func (lm LogBlockCollection) FindBlock(num uint64) map[int]*model.PbftBlock

func (LogBlockCollection) ResetBlock

func (lm LogBlockCollection) ResetBlock(num uint64)

type LogGroupBySigner

type LogGroupBySigner map[string]LogMessage

type LogGroupByType

type LogGroupByType map[string]LogGroupBySigner

type LogMessage

type LogMessage struct {
	model.MessageType
	// contains filtered or unexported fields
}

type LogMsgCollection

type LogMsgCollection map[uint64]LogGroupByType

func (LogMsgCollection) ExistMsgBySinger

func (lm LogMsgCollection) ExistMsgBySinger(num uint64, msgType model.MessageType, view int, signer string) bool

检查被signer签名的消息是否已经收到

func (LogMsgCollection) FindMsg

func (lm LogMsgCollection) FindMsg(num uint64, msgType model.MessageType, view int) LogGroupBySigner

type MsgManager

type MsgManager struct {
	// block_num-view : blk
	BlockMsg      map[string]*model.PbftBlock
	BlockMsgLock  sync.RWMutex
	StateMsgs     map[string][]*StateMsg
	StateMsgLock  sync.RWMutex
	BlockView     map[uint64]map[uint64]struct{}
	BlockViewLock sync.RWMutex
}

func NewMsgManager

func NewMsgManager() *MsgManager

type MsgQueue

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

func NewMsgQueue

func NewMsgQueue() *MsgQueue

func (*MsgQueue) InsertMsg

func (mq *MsgQueue) InsertMsg(msg *model.PbftMessage)

func (*MsgQueue) WaitMsg

func (mq *MsgQueue) WaitMsg() <-chan *model.PbftMessage

type PBFT

type PBFT struct {
	Msgs *MsgQueue

	StopFlag bool

	sync.Mutex
	// contains filtered or unexported fields
}

func New

func (*PBFT) AddBroadcastTask

func (pbft *PBFT) AddBroadcastTask(msg *StateMsg)

func (*PBFT) AppendMsg

func (pbft *PBFT) AppendMsg(msg *model.PbftMessage) bool

func (*PBFT) ApplyBlock

func (pbft *PBFT) ApplyBlock(block *model.PbftBlock) error

ApplyBlock 执行区块变更

func (*PBFT) BroadcastMsgRoutine

func (pbft *PBFT) BroadcastMsgRoutine()

定时广播 由于网路原因 可能会导致一些节点不能一次成功收到消息 多次进行广播

func (*PBFT) ChangeState

func (pbft *PBFT) ChangeState(s model.States)

func (*PBFT) CommitBlock

func (pbft *PBFT) CommitBlock(block *model.PbftBlock) error

CommitBlock 提交区块

func (*PBFT) CompareStateMsg

func (pbft *PBFT) CompareStateMsg(a *StateMsg, b *StateMsg) bool

func (*PBFT) CurrentState

func (pbft *PBFT) CurrentState() model.States

func (*PBFT) Daemon

func (pbft *PBFT) Daemon()

func (*PBFT) FindBlock

func (pbft *PBFT) FindBlock(num, view uint64) *model.PbftBlock

func (*PBFT) FindStateMsg

func (pbft *PBFT) FindStateMsg(num, view uint64, msgType model.MessageType) []*StateMsg

func (*PBFT) FindStateMsgBySinger

func (pbft *PBFT) FindStateMsgBySinger(num, view uint64, msgType model.MessageType, signer []byte) *StateMsg

func (*PBFT) GetMsgSigner

func (pbft *PBFT) GetMsgSigner(msg *model.PbftMessage) []byte

func (*PBFT) IsPrimaryVerfier

func (pbft *PBFT) IsPrimaryVerfier() bool

func (*PBFT) IsVaildVerifier

func (pbft *PBFT) IsVaildVerifier(singerID []byte) bool

func (*PBFT) SignMsg

func (pbft *PBFT) SignMsg(msg *model.PbftMessage) (*model.PbftMessage, error)

func (*PBFT) Start

func (pbft *PBFT) Start()

func (*PBFT) StartAPI

func (pbft *PBFT) StartAPI(g *echo.Group)

func (*PBFT) StateMigrate

func (pbft *PBFT) StateMigrate(msg *model.PbftMessage)

Migrate 状态转移

func (*PBFT) Stop

func (pbft *PBFT) Stop()

func (*PBFT) TryApplyBlock

func (pbft *PBFT) TryApplyBlock(block *model.PbftBlock) error

TryApplyBlock 尝试执行区块交易 校验接收到区块交易是否正确

func (*PBFT) VerfifyBlockHeader

func (pbft *PBFT) VerfifyBlockHeader(blk *model.PbftBlock) bool

VerfifyBlockHeader 验证区块头 需要超过2/3f才能成功

func (*PBFT) VerfifyGenesisBlock

func (pbft *PBFT) VerfifyGenesisBlock(blk *model.PbftBlock) bool

func (*PBFT) VerfifyMostBlock

func (pbft *PBFT) VerfifyMostBlock(blk *model.PbftBlock) bool

VerfifyMostBlock 验证有超过2/3的节点已对区块进行了签名

func (*PBFT) VerfifyMsg

func (pbft *PBFT) VerfifyMsg(msg *model.PbftMessage) bool

type StateMachine

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

func NewStateMachine

func NewStateMachine() *StateMachine

type StateMsg

type StateMsg struct {
	MsgType       model.MessageType
	Msg           *model.PbftMessage
	GenericMsg    *model.PbftGenericMessage
	ViewChangeMsg *model.PbftViewChange
	Signer        []byte
	Broadcast     bool // 是否被广播过
	Readed        bool // 是否在状态迁移阶段被读取过
	sync.RWMutex       //
}

type StatePollingTimer

type StatePollingTimer struct {
	*time.Timer
}

func NewStatePollingTimer

func NewStatePollingTimer() *StatePollingTimer

func (*StatePollingTimer) AdjustmentPolling

func (st *StatePollingTimer) AdjustmentPolling(duration time.Duration)

Jump to

Keyboard shortcuts

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