consensus

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2019 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Agree int = iota
	Against
	ActionFecth
	ActionBroadcast
	ActionFinish
)

Variables

This section is empty.

Functions

func Hash

func Hash(content []byte) string

Types

type ActionIn

type ActionIn struct {
	AC     int
	ID     *big.Int
	Height *big.Int
}

type ConsensusFinish

type ConsensusFinish interface {
	ConsensusFinish()
}

type ConsensusHelp

type ConsensusHelp interface {
	GetRequest(id *big.Int) (*RequestMsg, error)
	Broadcast(height *big.Int)
}

type ConsensusVerify

type ConsensusVerify interface {
	SignMsg(h int64, res uint) *SignedVoteMsg
	CheckMsg(msg *RequestMsg) (*types.PbftSign, error)
	ReplyResult(msg *RequestMsg, signs []*types.PbftSign, res uint) bool
	InsertBlock(msg *PrePrepareMsg) bool
	RepeatFetch(id *big.Int, height int64)
}

type MsgLogs

type MsgLogs struct {
	ReqMsg *RequestMsg
	// contains filtered or unexported fields
}

func (*MsgLogs) Clear

func (m *MsgLogs) Clear()

func (*MsgLogs) GetCommitCount

func (m *MsgLogs) GetCommitCount() int

func (*MsgLogs) GetCommitMessages

func (m *MsgLogs) GetCommitMessages() map[string]*VoteMsg

func (*MsgLogs) GetCommitMsgs

func (m *MsgLogs) GetCommitMsgs(key string) (data *VoteMsg)

func (*MsgLogs) GetCommitMsgsSigns

func (m *MsgLogs) GetCommitMsgsSigns() []*types.PbftSign

func (*MsgLogs) GetCommitOne

func (m *MsgLogs) GetCommitOne() *VoteMsg

func (*MsgLogs) GetCommitPassCount

func (m *MsgLogs) GetCommitPassCount() int

func (*MsgLogs) GetPrepareCount

func (m *MsgLogs) GetPrepareCount() int

func (*MsgLogs) GetPrepareMessages

func (m *MsgLogs) GetPrepareMessages() map[string]*VoteMsg

func (*MsgLogs) GetPrepareMsg

func (m *MsgLogs) GetPrepareMsg(key string) (data *VoteMsg)

func (*MsgLogs) GetPrepareOne

func (m *MsgLogs) GetPrepareOne() *VoteMsg

func (*MsgLogs) SetCommitMsgs

func (m *MsgLogs) SetCommitMsgs(key string, data *VoteMsg)

func (*MsgLogs) SetPrepareMsg

func (m *MsgLogs) SetPrepareMsg(key string, data *VoteMsg)

type MsgType

type MsgType int
const (
	PrepareMsg MsgType = iota
	CommitMsg
)

type PBFT

type PBFT interface {
	StartConsensus(request *RequestMsg) (*PrePrepareMsg, error)
	PrePrepare(prePrepareMsg *PrePrepareMsg) (*VoteMsg, error)
	Prepare(prepareMsg *VoteMsg) (*VoteMsg, error)
	Commit(commitMsg *VoteMsg) (*ReplyMsg, *RequestMsg, error)
}

type PrePrepareMsg

type PrePrepareMsg struct {
	ViewID     int64       `json:"viewID"`
	SequenceID int64       `json:"sequenceID"`
	Digest     string      `json:"digest"`
	RequestMsg *RequestMsg `json:"requestMsg"`
	Height     int64       `json:"Height"`
}

type ReplyMsg

type ReplyMsg struct {
	ViewID    int64  `json:"viewID"`
	Timestamp int64  `json:"timestamp"`
	ClientID  string `json:"clientID"`
	NodeID    string `json:"nodeID"`
	Result    string `json:"result"`
	Height    int64  `json:"Height"`
}

type RequestMsg

type RequestMsg struct {
	Timestamp  int64  `json:"timestamp"`
	ClientID   string `json:"clientID"`
	Operation  string `json:"operation"`
	SequenceID int64  `json:"sequenceID"`
	Height     int64  `json:"Height"`
}

type SignedVoteMsg

type SignedVoteMsg struct {
	FastHeight *big.Int
	Result     uint   // 0--agree,1--against
	Sign       []byte // sign for fastblock height + hash + result + Pk
}

type Stage

type Stage int
const (
	Idle        Stage = iota // Node is created successfully, but the consensus process is not started yet.
	PrePrepared              // The ReqMsgs is processed successfully. The node is ready to head to the Prepare stage.
	Prepared                 // Same with `prepared` stage explained in the original paper.
	Committed                // Same with `committed-local` stage explained in the original paper.
)

type State

type State struct {
	ViewID         int64
	MsgLogs        *MsgLogs
	LastSequenceID int64
	CurrentStage   Stage
	FastStage      Stage
	BlockResults   *SignedVoteMsg
	Clear          bool
	MySign         *types.PbftSign
}

func CreateState

func CreateState(viewID int64, lastSequenceID int64) *State

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

func (*State) Commit

func (state *State) Commit(commitMsg *VoteMsg, f float64) (*ReplyMsg, *RequestMsg, error)

func (*State) PrePrepare

func (state *State) PrePrepare(prePrepareMsg *PrePrepareMsg) (*VoteMsg, error)

func (*State) Prepare

func (state *State) Prepare(prepareMsg *VoteMsg, f float64) (*VoteMsg, error)

func (*State) StartConsensus

func (state *State) StartConsensus(request *RequestMsg) (*PrePrepareMsg, error)

func (*State) VerifyMsg

func (state *State) VerifyMsg(viewID int64, sequenceID int64, digestGot string) bool

type StorgePrepareMsg

type StorgePrepareMsg struct {
	ViewID     int64  `json:"viewID"`
	SequenceID int64  `json:"sequenceID"`
	Digest     string `json:"digest"`
	NodeID     string `json:"nodeID"`
	Height     int64  `json:"Height"`
	MsgType    `json:"msgType"`
}

type VoteMsg

type VoteMsg struct {
	ViewID     int64           `json:"viewID"`
	SequenceID int64           `json:"sequenceID"`
	Digest     string          `json:"digest"`
	NodeID     string          `json:"nodeID"`
	Pass       *SignedVoteMsg  `json:"Pass"`
	Height     int64           `json:"Height"`
	Signs      *types.PbftSign `json:"signs"`
	MsgType    `json:"msgType"`
}

Jump to

Keyboard shortcuts

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