vbft

package
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2020 License: LGPL-3.0 Imports: 43 Imported by: 0

README

VBFT

VBFT is a VRF(virtual random function) based BFT consensus algorithm, and use PoS for its governance.

Features

  • Scalable
  • High performance
  • BFT
  • Well defined governance protocol

VBFT introduction is available here.

Documentation

Index

Constants

View Source
const (
	CAP_MESSAGE_CHANNEL  = 4096
	CAP_ACTION_CHANNEL   = 64
	CAP_MSG_SEND_CHANNEL = 16
)
View Source
const (
	// TODO: move to config file
	MAX_PEER_CONNECTIONS      = 100
	MAX_SYNCING_CHECK_BLK_NUM = 10
)

Variables

This section is empty.

Functions

func GetGovernanceView

func GetGovernanceView(memdb *overlaydb.MemDB) (*gov.GovernanceView, error)

func GetPeersConfig

func GetPeersConfig(memdb *overlaydb.MemDB) ([]*config.VBFTPeerStakeInfo, error)

func GetStorageValue

func GetStorageValue(memdb *overlaydb.MemDB, backend *ledger.Ledger, addr common.Address, key []byte) (value []byte, err error)

func GetVbftConfigInfo

func GetVbftConfigInfo(memdb *overlaydb.MemDB) (*config.VBFTConfig, error)

func HashMsg

func HashMsg(msg ConsensusMsg) (common.Uint256, error)

func SerializeVbftMsg

func SerializeVbftMsg(msg ConsensusMsg) ([]byte, error)

func SignMsg

func SignMsg(account *account.Account, msg ConsensusMsg) ([]byte, error)

Types

type BftAction

type BftAction struct {
	Type     BftActionType
	BlockNum uint32
	Proposal *blockProposalMsg
	// contains filtered or unexported fields
}

type BftActionType

type BftActionType uint8
const (
	MakeProposal BftActionType = iota
	EndorseBlock
	CommitBlock
	SealBlock
	FastForward // for syncer catch up
	ReBroadcast
	SubmitBlock
)

type Block

type Block struct {
	Block              *types.Block
	EmptyBlock         *types.Block
	Info               *vconfig.VbftBlockInfo
	PrevExecMerkleRoot common.Uint256
	CrossChainMsg      *types.CrossChainMsg
}

func (*Block) Deserialize

func (blk *Block) Deserialize(data []byte) error

func (*Block) Serialize

func (blk *Block) Serialize() []byte

type BlockFetchRespMsg

type BlockFetchRespMsg struct {
	BlockNumber uint32         `json:"block_number"`
	BlockHash   common.Uint256 `json:"block_hash"`
	BlockData   *Block         `json:"block_data"`
}

func (*BlockFetchRespMsg) Deserialize

func (msg *BlockFetchRespMsg) Deserialize(data []byte) error

func (*BlockFetchRespMsg) GetBlockNum

func (msg *BlockFetchRespMsg) GetBlockNum() uint32

func (*BlockFetchRespMsg) Serialize

func (msg *BlockFetchRespMsg) Serialize() ([]byte, error)

func (*BlockFetchRespMsg) Type

func (msg *BlockFetchRespMsg) Type() MsgType

func (*BlockFetchRespMsg) Verify

func (msg *BlockFetchRespMsg) Verify(pub keypair.PublicKey) error

type BlockFromPeers

type BlockFromPeers map[uint32]*Block // index by peerId

type BlockInfoFetchMsg

type BlockInfoFetchMsg struct {
	StartBlockNum uint32 `json:"start_block_num"`
}

func (*BlockInfoFetchMsg) GetBlockNum

func (msg *BlockInfoFetchMsg) GetBlockNum() uint32

func (*BlockInfoFetchMsg) Serialize

func (msg *BlockInfoFetchMsg) Serialize() ([]byte, error)

func (*BlockInfoFetchMsg) Type

func (msg *BlockInfoFetchMsg) Type() MsgType

func (*BlockInfoFetchMsg) Verify

func (msg *BlockInfoFetchMsg) Verify(pub keypair.PublicKey) error

type BlockInfoFetchRespMsg

type BlockInfoFetchRespMsg struct {
	Blocks []*BlockInfo_ `json:"blocks"`
}

to fetch committed block from neighbours

func (*BlockInfoFetchRespMsg) GetBlockNum

func (msg *BlockInfoFetchRespMsg) GetBlockNum() uint32

func (*BlockInfoFetchRespMsg) Serialize

func (msg *BlockInfoFetchRespMsg) Serialize() ([]byte, error)

func (*BlockInfoFetchRespMsg) Type

func (msg *BlockInfoFetchRespMsg) Type() MsgType

func (*BlockInfoFetchRespMsg) Verify

func (msg *BlockInfoFetchRespMsg) Verify(pub keypair.PublicKey) error

type BlockInfo_

type BlockInfo_ struct {
	BlockNum   uint32            `json:"block_num"`
	Proposer   uint32            `json:"proposer"`
	Signatures map[uint32][]byte `json:"signatures"`
}

type BlockList

type BlockList []*Block

type BlockMsgFromPeer

type BlockMsgFromPeer struct {
	// contains filtered or unexported fields
}

type BlockParticipantConfig

type BlockParticipantConfig struct {
	BlockNum    uint32
	Vrf         vconfig.VRFValue
	ChainConfig *vconfig.ChainConfig
	Proposers   []uint32
	Endorsers   []uint32
	Committers  []uint32
}

type BlockPool

type BlockPool struct {
	HistoryLen uint32
	// contains filtered or unexported fields
}

type BlockSyncReq

type BlockSyncReq struct {
	// contains filtered or unexported fields
}

type CandidateEndorseSigInfo

type CandidateEndorseSigInfo struct {
	EndorsedProposer uint32
	Signature        []byte
	ForEmpty         bool
	CrossChainMsgSig []byte
}

type CandidateInfo

type CandidateInfo struct {
	// server endorsed proposals
	EndorsedProposal      *blockProposalMsg
	EndorsedEmptyProposal *blockProposalMsg

	// server committed proposals (one of them must be nil)
	CommittedProposal      *blockProposalMsg
	CommittedEmptyProposal *blockProposalMsg

	// server sealed block for this round
	SealedBlock *Block

	// candidate msgs for this round
	Proposals  []*blockProposalMsg
	CommitMsgs []*blockCommitMsg

	// indexed by endorserIndex
	EndorseSigs map[uint32][]*CandidateEndorseSigInfo
	// contains filtered or unexported fields
}

type ChainStore

type ChainStore struct {
	// contains filtered or unexported fields
}

func OpenBlockStore

func OpenBlockStore(db *ledger.Ledger, serverPid *actor.PID) (*ChainStore, error)

func (*ChainStore) AddBlock

func (self *ChainStore) AddBlock(block *Block) error

func (*ChainStore) GetChainedBlockNum

func (self *ChainStore) GetChainedBlockNum() uint32

func (*ChainStore) ReloadFromLedger

func (self *ChainStore) ReloadFromLedger()

type ConsensusMsg

type ConsensusMsg interface {
	Type() MsgType
	Verify(pub keypair.PublicKey) error
	GetBlockNum() uint32
	Serialize() ([]byte, error)
}

func DeserializeVbftMsg

func DeserializeVbftMsg(msgPayload []byte) (ConsensusMsg, error)

type ConsensusMsgPayload

type ConsensusMsgPayload struct {
	Type    MsgType `json:"type"`
	Len     uint32  `json:"len"`
	Payload []byte  `json:"payload"`
}

type ConsensusRound

type ConsensusRound struct {
	// contains filtered or unexported fields
}

type ConsensusRoundMsgs

type ConsensusRoundMsgs map[MsgType][]ConsensusMsg // indexed by MsgType (proposal, endorsement, ...)

type EventTimer

type EventTimer struct {
	C chan *TimerEvent
	// contains filtered or unexported fields
}

func NewEventTimer

func NewEventTimer(server *Server) *EventTimer

func (*EventTimer) Cancel2ndProposalTimer

func (self *EventTimer) Cancel2ndProposalTimer(blockNum uint32)

func (*EventTimer) CancelBackoffTimer

func (self *EventTimer) CancelBackoffTimer(blockNum uint32)

func (*EventTimer) CancelCommitMsgTimer

func (self *EventTimer) CancelCommitMsgTimer(blockNum uint32)

func (*EventTimer) CancelEndorseEmptyBlockTimer

func (self *EventTimer) CancelEndorseEmptyBlockTimer(blockNum uint32)

func (*EventTimer) CancelEndorseMsgTimer

func (self *EventTimer) CancelEndorseMsgTimer(blockNum uint32)

func (*EventTimer) CancelProposalBackoffTimer

func (self *EventTimer) CancelProposalBackoffTimer(blockNum uint32)

func (*EventTimer) CancelProposalTimer

func (self *EventTimer) CancelProposalTimer(blockNum uint32)

func (*EventTimer) CancelTimer

func (self *EventTimer) CancelTimer(idx uint32)

func (*EventTimer) CancelTxBlockTimeout

func (self *EventTimer) CancelTxBlockTimeout(blockNum uint32)

func (*EventTimer) Start2ndProposalTimer

func (self *EventTimer) Start2ndProposalTimer(blockNum uint32) error

func (*EventTimer) StartBackoffTimer

func (self *EventTimer) StartBackoffTimer(blockNum uint32) error

func (*EventTimer) StartCommitTimer

func (self *EventTimer) StartCommitTimer(blockNum uint32) error

func (*EventTimer) StartEndorseEmptyBlockTimer

func (self *EventTimer) StartEndorseEmptyBlockTimer(blockNum uint32) error

func (*EventTimer) StartEndorsingTimer

func (self *EventTimer) StartEndorsingTimer(blockNum uint32) error

func (*EventTimer) StartProposalBackoffTimer

func (self *EventTimer) StartProposalBackoffTimer(blockNum uint32) error

func (*EventTimer) StartProposalTimer

func (self *EventTimer) StartProposalTimer(blockNum uint32) error

func (*EventTimer) StartTimer

func (self *EventTimer) StartTimer(Idx uint32, timeout time.Duration)

func (*EventTimer) StartTxBlockTimeout

func (self *EventTimer) StartTxBlockTimeout(blockNum uint32) error

type FaultyReport

type FaultyReport struct {
	FaultyID      uint32         `json:"faulty_id"`
	FaultyMsgHash common.Uint256 `json:"faulty_block_hash"`
}

type MsgPool

type MsgPool struct {
	// contains filtered or unexported fields
}

func (*MsgPool) AddMsg

func (pool *MsgPool) AddMsg(msg ConsensusMsg, msgHash common.Uint256) error

func (*MsgPool) DropMsg

func (pool *MsgPool) DropMsg(msg ConsensusMsg)

func (*MsgPool) GetBlockSubmitMsgNums

func (pool *MsgPool) GetBlockSubmitMsgNums(blocknum uint32) []ConsensusMsg

func (*MsgPool) GetCommitMsgs

func (pool *MsgPool) GetCommitMsgs(blocknum uint32) []ConsensusMsg

func (*MsgPool) GetEndorsementsMsgs

func (pool *MsgPool) GetEndorsementsMsgs(blocknum uint32) []ConsensusMsg

func (*MsgPool) GetProposalMsgs

func (pool *MsgPool) GetProposalMsgs(blocknum uint32) []ConsensusMsg

func (*MsgPool) HasMsg

func (pool *MsgPool) HasMsg(msg ConsensusMsg, msgHash common.Uint256) bool

type MsgType

type MsgType uint8
const (
	BlockProposalMessage MsgType = iota
	BlockEndorseMessage
	BlockCommitMessage

	PeerHandshakeMessage
	PeerHeartbeatMessage

	BlockInfoFetchMessage
	BlockInfoFetchRespMessage
	ProposalFetchMessage
	BlockFetchMessage
	BlockFetchRespMessage
	BlockSubmitMessage
)

type Peer

type Peer struct {
	Index  uint32
	PubKey keypair.PublicKey

	LatestInfo     *peerHeartbeatMsg // latest heartbeat msg
	LastUpdateTime time.Time         // time received heartbeat from peer
	// contains filtered or unexported fields
}

type PeerPool

type PeerPool struct {
	IDMap  map[string]uint32
	P2pMap map[uint32]common.PeerId //value: p2p random id
	// contains filtered or unexported fields
}

func NewPeerPool

func NewPeerPool(maxSize int, server *Server) *PeerPool

func (*PeerPool) GetAllPubKeys

func (pool *PeerPool) GetAllPubKeys() map[uint32]keypair.PublicKey

func (*PeerPool) GetPeerIndex

func (pool *PeerPool) GetPeerIndex(nodeId string) (uint32, bool)

func (*PeerPool) GetPeerPubKey

func (pool *PeerPool) GetPeerPubKey(peerIdx uint32) keypair.PublicKey

func (*PeerPool) RemovePeerIndex

func (pool *PeerPool) RemovePeerIndex(nodeId string)

type PeerState

type PeerState struct {
	// contains filtered or unexported fields
}

type PeerSyncer

type PeerSyncer struct {
	// contains filtered or unexported fields
}

type PendingBlock

type PendingBlock struct {
	// contains filtered or unexported fields
}

type SendMsgEvent

type SendMsgEvent struct {
	ToPeer uint32 // peer index
	Msg    ConsensusMsg
}

type Server

type Server struct {
	Index uint32

	LastConfigBlockNum uint32
	// contains filtered or unexported fields
}

func NewVbftServer

func NewVbftServer(account *account.Account, txpool *actor.PID, p2p p2p.P2P) (*Server, error)

func (*Server) CheckSubmitBlock

func (self *Server) CheckSubmitBlock(blkNum uint32, stateRoot common.Uint256) bool

func (*Server) GetCommittedBlockNo

func (self *Server) GetCommittedBlockNo() uint32

func (*Server) GetCurrentBlockNo

func (self *Server) GetCurrentBlockNo() uint32

func (*Server) GetPID

func (self *Server) GetPID() *actor.PID

func (*Server) Halt

func (self *Server) Halt() error

func (*Server) LoadChainConfig

func (self *Server) LoadChainConfig(blkNum uint32) error

func (*Server) NewConsensusPayload

func (self *Server) NewConsensusPayload(payload *p2pmsg.ConsensusPayload)

func (*Server) Receive

func (self *Server) Receive(context actor.Context)

func (*Server) Start

func (self *Server) Start() error

type ServerState

type ServerState int
const (
	Init ServerState = iota
	LocalConfigured
	Configured       // config loaded from chain
	Syncing          // syncing block from neighbours
	WaitNetworkReady // sync reached, and keep synced, try connecting with more peers
	SyncReady        // start processing consensus msg, but not broadcasting proposal/endorse/commit
	Synced           // start bft
	SyncingCheck     // potentially lost syncing
)

type StateEvent

type StateEvent struct {
	Type StateEventType
	// contains filtered or unexported fields
}

type StateEventType

type StateEventType int
const (
	ConfigLoaded     StateEventType = iota
	UpdatePeerConfig                // notify statemgmt on peer heartbeat
	UpdatePeerState                 // notify statemgmt on peer heartbeat
	SyncReadyTimeout
	ForceCheckSync
	SyncDone
	LiveTick
)

type StateMgr

type StateMgr struct {
	StateEventC chan *StateEvent
	// contains filtered or unexported fields
}

type SyncCheckReq

type SyncCheckReq struct {
	// contains filtered or unexported fields
}

type SyncMsg

type SyncMsg struct {
	// contains filtered or unexported fields
}

type Syncer

type Syncer struct {
	// contains filtered or unexported fields
}

type TimerEvent

type TimerEvent struct {
	// contains filtered or unexported fields
}

type TimerEventType

type TimerEventType int
const (
	EventProposeBlockTimeout TimerEventType = iota
	EventProposalBackoff
	EventRandomBackoff
	EventPropose2ndBlockTimeout
	EventEndorseBlockTimeout
	EventEndorseEmptyBlockTimeout
	EventCommitBlockTimeout
	EventPeerHeartbeat
	EventTxPool
	EventTxBlockTimeout
	EventMax
)

type TimerItem

type TimerItem struct {
	// contains filtered or unexported fields
}

type TimerQueue

type TimerQueue []*TimerItem

func (TimerQueue) Len

func (tq TimerQueue) Len() int

func (TimerQueue) Less

func (tq TimerQueue) Less(i, j int) bool

func (*TimerQueue) Pop

func (tq *TimerQueue) Pop() interface{}

func (*TimerQueue) Push

func (tq *TimerQueue) Push(x interface{})

func (TimerQueue) Swap

func (tq TimerQueue) Swap(i, j int)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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