hbft

package
v0.0.0-...-e1f35ab Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2020 License: LGPL-3.0 Imports: 9 Imported by: 6

Documentation

Index

Constants

View Source
const (
	SameViewPrimaryErr    = "BFT message from the same view"
	InvalidViewOrSeqIDErr = "the view ID or sequence ID of BFT message is not valid"
	InvalidParentHashErr  = "the hash of the parent completed stage is not valid"
	InvalidSignsCntErr    = "the signatures of the completed stage is not sufficient"
	NoSpecificBlockErr    = "the block in the stage is not received"
	InvalidNewBlockErr    = "new block that the BFT message contained is not valid"
	InvalidCompletedErr   = "the completed stage is not valid"
	ShouldNotHandleErr    = "the message we received should not be handled due to the stage of the node"
)

Variables

View Source
var (
	EmptyPreConfirmMsg = &PreConfirmMsg{
		NewBlock: types.NewBlockWithHeader(types.EmptyHeader),
		CurState: &StateMsg{
			Completed: make([]*types.HBFTStageCompleted, 0),
		},
	}

	EmptyConfirmMsg = &ConfirmMsg{
		CurState: &StateMsg{
			Completed: make([]*types.HBFTStageCompleted, 0),
		},
	}

	EmptyReplyMsg = &ReplyMsg{
		MsgHash: common.Hash{},
	}
)

Functions

func GetF2

func GetF2() int

func Hash

func Hash(content []byte) string

Types

type ConfirmMsg

type ConfirmMsg struct {
	ViewPrimary string    `json:"viewPrimary"`
	ViewID      uint64    `json:"viewID"`
	SequenceID  uint64    `json:"sequenceID"`
	CurState    *StateMsg `json:"curState"`
	Signature   []byte    `json:"signature"`
}

func (*ConfirmMsg) GetCompleted

func (m *ConfirmMsg) GetCompleted() []*types.HBFTStageCompleted

func (*ConfirmMsg) GetCurStage

func (m *ConfirmMsg) GetCurStage() Stage

func (*ConfirmMsg) GetMsgHash

func (m *ConfirmMsg) GetMsgHash() common.Hash

func (*ConfirmMsg) GetMsgType

func (m *ConfirmMsg) GetMsgType() TypeHBFTMsg

func (*ConfirmMsg) GetNewBlock

func (m *ConfirmMsg) GetNewBlock() *types.Block

func (*ConfirmMsg) GetSequenceID

func (m *ConfirmMsg) GetSequenceID() uint64

func (*ConfirmMsg) GetSignature

func (m *ConfirmMsg) GetSignature() []byte

func (*ConfirmMsg) GetViewID

func (m *ConfirmMsg) GetViewID() uint64

func (*ConfirmMsg) GetViewPrimary

func (m *ConfirmMsg) GetViewPrimary() string

func (*ConfirmMsg) Hash

func (msg *ConfirmMsg) Hash() common.Hash

type MsgHbftConsensus

type MsgHbftConsensus interface {
	GetViewPrimary() string
	GetViewID() uint64
	GetSequenceID() uint64
	GetNewBlock() *types.Block
	GetCurStage() Stage
	GetCompleted() []*types.HBFTStageCompleted
	GetMsgType() TypeHBFTMsg
	GetMsgHash() common.Hash
	GetSignature() []byte
	Hash() common.Hash
}

type MsgLogs

type MsgLogs struct {
	ReqMsg         *RequestMsg
	PreConfirmMsgs map[string]*PreConfirmMsg
	ConfirmMsgs    map[string]*ConfirmMsg
}

type PreConfirmMsg

type PreConfirmMsg struct {
	ViewPrimary string       `json:"viewPrimary"`
	ViewID      uint64       `json:"viewID"`
	SequenceID  uint64       `json:"sequenceID"`
	NewBlock    *types.Block `json:"newBlock"`
	CurState    *StateMsg    `json:"curState"`
	Signature   []byte       `json:"signature"`
}

func (*PreConfirmMsg) GetCompleted

func (m *PreConfirmMsg) GetCompleted() []*types.HBFTStageCompleted

func (*PreConfirmMsg) GetCurStage

func (m *PreConfirmMsg) GetCurStage() Stage

func (*PreConfirmMsg) GetMsgHash

func (m *PreConfirmMsg) GetMsgHash() common.Hash

func (*PreConfirmMsg) GetMsgType

func (m *PreConfirmMsg) GetMsgType() TypeHBFTMsg

func (*PreConfirmMsg) GetNewBlock

func (m *PreConfirmMsg) GetNewBlock() *types.Block

func (*PreConfirmMsg) GetSequenceID

func (m *PreConfirmMsg) GetSequenceID() uint64

func (*PreConfirmMsg) GetSignature

func (m *PreConfirmMsg) GetSignature() []byte

func (*PreConfirmMsg) GetViewID

func (m *PreConfirmMsg) GetViewID() uint64

func (*PreConfirmMsg) GetViewPrimary

func (m *PreConfirmMsg) GetViewPrimary() string

func (*PreConfirmMsg) Hash

func (msg *PreConfirmMsg) Hash() common.Hash

type ReplyMsg

type ReplyMsg struct {
	ViewPrimary string      `json:"viewPrimary"`
	ViewID      uint64      `json:"viewID"`
	SequenceID  uint64      `json:"sequenceID"`
	MsgType     TypeHBFTMsg `json:"MsgType"`
	MsgHash     common.Hash `json:"msgHash"`
	Signature   []byte      `json:"signature"`
}

func (*ReplyMsg) GetCompleted

func (m *ReplyMsg) GetCompleted() []*types.HBFTStageCompleted

func (*ReplyMsg) GetCurStage

func (m *ReplyMsg) GetCurStage() Stage

func (*ReplyMsg) GetMsgHash

func (m *ReplyMsg) GetMsgHash() common.Hash

func (*ReplyMsg) GetMsgType

func (m *ReplyMsg) GetMsgType() TypeHBFTMsg

func (*ReplyMsg) GetNewBlock

func (m *ReplyMsg) GetNewBlock() *types.Block

func (*ReplyMsg) GetSequenceID

func (m *ReplyMsg) GetSequenceID() uint64

func (*ReplyMsg) GetSignature

func (m *ReplyMsg) GetSignature() []byte

func (*ReplyMsg) GetViewID

func (m *ReplyMsg) GetViewID() uint64

func (*ReplyMsg) GetViewPrimary

func (m *ReplyMsg) GetViewPrimary() string

func (*ReplyMsg) Hash

func (msg *ReplyMsg) Hash() common.Hash

type RequestMsg

type RequestMsg struct {
	ViewPrimary string       `json:"viewPrimary"`
	ViewID      uint64       `json:"viewID"`
	Timestamp   uint64       `json:"timestamp"`
	SequenceID  uint64       `json:"sequenceID"`
	NewBlock    *types.Block `json:"newBlock"`
}

func (*RequestMsg) GetCompleted

func (m *RequestMsg) GetCompleted() []*types.HBFTStageCompleted

func (*RequestMsg) GetCurStage

func (m *RequestMsg) GetCurStage() Stage

func (*RequestMsg) GetMsgHash

func (m *RequestMsg) GetMsgHash() common.Hash

func (*RequestMsg) GetMsgType

func (m *RequestMsg) GetMsgType() TypeHBFTMsg

func (*RequestMsg) GetNewBlock

func (m *RequestMsg) GetNewBlock() *types.Block

func (*RequestMsg) GetSequenceID

func (m *RequestMsg) GetSequenceID() uint64

func (*RequestMsg) GetSignature

func (m *RequestMsg) GetSignature() []byte

func (*RequestMsg) GetViewID

func (m *RequestMsg) GetViewID() uint64

func (*RequestMsg) GetViewPrimary

func (m *RequestMsg) GetViewPrimary() string

func (*RequestMsg) Hash

func (m *RequestMsg) Hash() common.Hash

type Stage

type Stage uint

stage represents that the node in which state in the consensus process

const (
	Idle         Stage = iota // Node is created successfully, but the consensus process is not started yet.
	PreConfirm                // The `preConfirmMsg` is processed successfully. The node is ready to head to the Confirm stage.
	Confirm                   // The `confirmMsg` is processed successfully. The node is ready to head to the next block processing.
	InvalidStage              // Unavailable stage
)

type State

type State struct {
	ViewPrimary  string
	ViewID       uint64
	SequenceID   uint64
	CurrentStage Stage
	MsgHash      common.Hash
	Blocks       []*types.Block
	Completed    map[common.Hash]*types.HBFTStageCompleted
	MsgLogs      *MsgLogs
	// contains filtered or unexported fields
}

func CreateState

func CreateState(viewPrimary string, viewID uint64, sequenceID uint64, blocks []*types.Block) *State

lastSequenceID will be -1 if there is no last sequence ID.

func (*State) AppendBlock

func (state *State) AppendBlock(b *types.Block)

func (*State) BuildCompletedStageChain

func (state *State) BuildCompletedStageChain() (stages []*types.HBFTStageCompleted)

func (*State) CheckCompletedStage

func (state *State) CheckCompletedStage(completedStages []*types.HBFTStageCompleted, currentBlock *types.Block, cnt2f int) error

func (*State) CheckCurrentState

func (state *State) CheckCurrentState(msg interface{}, currentBlock, BFTFuture *types.Block, cnt2f int) error

func (*State) CheckView

func (state *State) CheckView(msg interface{}) error

func (*State) ClearConnected

func (state *State) ClearConnected(newHead *types.Header)

func (*State) GetNewestCompletedStage

func (state *State) GetNewestCompletedStage(currentBlock *types.Block) *types.HBFTStageCompleted

func (*State) GetNewestStateCompletedStage

func (state *State) GetNewestStateCompletedStage() *types.HBFTStageCompleted

func (*State) Reset

func (state *State) Reset(clearCompleted bool)

func (State) SetStageCompleted

func (state State) SetStageCompleted(stage *types.HBFTStageCompleted)

func (*State) StartConsensus

func (state *State) StartConsensus(request *RequestMsg, replys *[]*ReplyMsg, currentBlock *types.Block) (*PreConfirmMsg, error)

type StateMsg

type StateMsg struct {
	ViewID       uint64
	SequenceID   uint64
	CurrentStage Stage
	Completed    []*types.HBFTStageCompleted
}

type TypeHBFTMsg

type TypeHBFTMsg uint
const (
	MsgPreConfirm TypeHBFTMsg = iota
	MsgConfirm
	MsgReply
	MsgInvalid
)

Jump to

Keyboard shortcuts

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