consensus

package
v0.0.0-...-fb4f826 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2024 License: GPL-3.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FlagDebug       = "debug"
	FlagDataDir     = "dataDir"
	FlagChainID     = "chainID"
	FlagBroadcastTx = "broadcastTx"

	FlagPointPort = "pointPort"
	FlagTopicPort = "topicPort"
	FlagAPIPort   = "apiPort"

	// storage section
	FlagMerkleBranchFactor = "storage-merkleBranchFactor"

	// execution section
	FlagTxExecTimeout       = "execution-txExecTimeout"
	FlagExecConcurrentLimit = "execution-concurrentLimit"

	// consensus section
	FlagBlockTxLimit  = "consensus-blockTxLimit"
	FlagTxWaitTime    = "consensus-txWaitTime"
	FlagViewWidth     = "consensus-viewWidth"
	FlagLeaderTimeout = "consensus-leaderTimeout"
	FlagVoteStrategy  = "consensus-voteStrategy"
	FlagBenchmarkPath = "consensus-benchmarkPath"
)
View Source
const (
	AverageVote uint8 = iota
	RandomVote
	OrdinaryVote
	MonopolyVote
)
View Source
const ExecuteTxFlag = true // set to false when benchmark test
View Source
const PreserveTxFlag = false // set to true when benchmark test
View Source
const TwoPhaseBFTFlag = false // set to true to execute two-phase BFT protocol

Variables

View Source
var DefaultConfig = Config{
	BlockTxLimit:  500,
	TxWaitTime:    500 * time.Millisecond,
	ViewWidth:     60 * time.Second,
	LeaderTimeout: 5 * time.Second,
	VoteStrategy:  AverageVote,
	BenchmarkPath: "",
}

Functions

This section is empty.

Types

type Config

type Config struct {
	ChainID int64
	DataDir string // copy from node config

	// maximum tx count in a block
	BlockTxLimit int

	// proposal creation delay if no transactions in the pool
	TxWaitTime time.Duration

	// view duration for a leader
	ViewWidth time.Duration

	// leader must create next qc within this duration
	LeaderTimeout time.Duration

	// voting strategy adopted by validator
	VoteStrategy uint8

	// path to save the benchmark log of the consensus algorithm (it will not be saved if blank)
	BenchmarkPath string
}

type Consensus

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

func New

func New(resources *Resources, config Config) *Consensus

func (*Consensus) GetBlock

func (cons *Consensus) GetBlock(hash []byte) *core.Block

func (*Consensus) GetQC

func (cons *Consensus) GetQC(blkHash []byte) *core.QuorumCert

func (*Consensus) GetStatus

func (cons *Consensus) GetStatus() Status

func (*Consensus) Start

func (cons *Consensus) Start()

func (*Consensus) Stop

func (cons *Consensus) Stop()

type Execution

type Execution interface {
	Execute(blk *core.Block, txs []*core.Transaction) (*core.BlockCommit, []*core.TxCommit)
	MockExecute(blk *core.Block) (*core.BlockCommit, []*core.TxCommit)
}

type MockExecution

type MockExecution struct {
	mock.Mock
}

func (*MockExecution) Execute

func (m *MockExecution) Execute(blk *core.Block, txs []*core.Transaction) (*core.BlockCommit, []*core.TxCommit)

func (*MockExecution) MockExecute

func (m *MockExecution) MockExecute(blk *core.Block) (*core.BlockCommit, []*core.TxCommit)

type MockMsgService

type MockMsgService struct {
	mock.Mock
}

func (*MockMsgService) BroadcastProposal

func (m *MockMsgService) BroadcastProposal(blk *core.Block) error

func (*MockMsgService) BroadcastQC

func (m *MockMsgService) BroadcastQC(qc *core.QuorumCert) error

func (*MockMsgService) RequestBlock

func (m *MockMsgService) RequestBlock(pubKey *core.PublicKey, hash []byte) (*core.Block, error)

func (*MockMsgService) RequestBlockByHeight

func (m *MockMsgService) RequestBlockByHeight(pubKey *core.PublicKey, height uint64) (*core.Block, error)

func (*MockMsgService) RequestQC

func (m *MockMsgService) RequestQC(pubKey *core.PublicKey, blkHash []byte) (*core.QuorumCert, error)

func (*MockMsgService) SendQC

func (m *MockMsgService) SendQC(pubKey *core.PublicKey, qc *core.QuorumCert) error

func (*MockMsgService) SendVote

func (m *MockMsgService) SendVote(pubKey *core.PublicKey, vote *core.Vote) error

func (*MockMsgService) SubscribeProposal

func (m *MockMsgService) SubscribeProposal(buffer int) *emitter.Subscription

func (*MockMsgService) SubscribeQC

func (m *MockMsgService) SubscribeQC(buffer int) *emitter.Subscription

func (*MockMsgService) SubscribeVote

func (m *MockMsgService) SubscribeVote(buffer int) *emitter.Subscription

type MockStorage

type MockStorage struct {
	mock.Mock
}

func (*MockStorage) Commit

func (m *MockStorage) Commit(data *storage.CommitData) error

func (*MockStorage) GetBlock

func (m *MockStorage) GetBlock(hash []byte) (*core.Block, error)

func (*MockStorage) GetBlockHeight

func (m *MockStorage) GetBlockHeight() uint64

func (*MockStorage) GetLastBlock

func (m *MockStorage) GetLastBlock() (*core.Block, error)

func (*MockStorage) GetLastQC

func (m *MockStorage) GetLastQC() (*core.QuorumCert, error)

func (*MockStorage) GetMerkleRoot

func (m *MockStorage) GetMerkleRoot() []byte

func (*MockStorage) GetQC

func (m *MockStorage) GetQC(blkHash []byte) (*core.QuorumCert, error)

func (*MockStorage) HasTx

func (m *MockStorage) HasTx(hash []byte) bool

func (*MockStorage) StoreBlock

func (m *MockStorage) StoreBlock(blk *core.Block) error

func (*MockStorage) StoreQC

func (m *MockStorage) StoreQC(qc *core.QuorumCert) error

type MockTxPool

type MockTxPool struct {
	mock.Mock
}

func (*MockTxPool) GetStatus

func (m *MockTxPool) GetStatus() txpool.Status

func (*MockTxPool) GetTx

func (m *MockTxPool) GetTx(hash []byte) *core.Transaction

func (*MockTxPool) GetTxStatus

func (m *MockTxPool) GetTxStatus(hash []byte) txpool.TxStatus

func (*MockTxPool) GetTxsFromQueue

func (m *MockTxPool) GetTxsFromQueue(max int) [][]byte

func (*MockTxPool) GetTxsToExecute

func (m *MockTxPool) GetTxsToExecute(hashes [][]byte) ([]*core.Transaction, [][]byte)

func (*MockTxPool) PopTxsFromQueue

func (m *MockTxPool) PopTxsFromQueue(max int) [][]byte

func (*MockTxPool) PutTxsToQueue

func (m *MockTxPool) PutTxsToQueue(hashes [][]byte)

func (*MockTxPool) RemoveTxs

func (m *MockTxPool) RemoveTxs(hashes [][]byte)

func (*MockTxPool) SetTxsPending

func (m *MockTxPool) SetTxsPending(hashes [][]byte)

func (*MockTxPool) StoreTxs

func (m *MockTxPool) StoreTxs(txs *core.TxList) error

func (*MockTxPool) SubmitTx

func (m *MockTxPool) SubmitTx(tx *core.Transaction) error

func (*MockTxPool) SyncTxs

func (m *MockTxPool) SyncTxs(peer *core.PublicKey, hashes [][]byte) error

type MsgService

type MsgService interface {
	BroadcastProposal(blk *core.Block) error
	BroadcastQC(qc *core.QuorumCert) error
	SendVote(pubKey *core.PublicKey, vote *core.Vote) error
	RequestBlock(pubKey *core.PublicKey, hash []byte) (*core.Block, error)
	RequestBlockByHeight(pubKey *core.PublicKey, height uint64) (*core.Block, error)
	RequestQC(pubKey *core.PublicKey, blkHash []byte) (*core.QuorumCert, error)
	SendQC(pubKey *core.PublicKey, qc *core.QuorumCert) error
	SubscribeProposal(buffer int) *emitter.Subscription
	SubscribeVote(buffer int) *emitter.Subscription
	SubscribeQC(buffer int) *emitter.Subscription
}

type Resources

type Resources struct {
	Signer    core.Signer
	RoleStore core.RoleStore
	Storage   Storage
	MsgSvc    MsgService
	Host      *p2p.Host
	TxPool    TxPool
	Execution Execution
}

type Status

type Status struct {
	StartTime int64

	CommittedTxCount int // committed tx count since node is up
	BlockPoolSize    int
	QCPoolSize       int

	ViewStart   int64 // start timestamp of current view
	ViewChange  int32
	LeaderIndex uint32

	// current status (block height)
	BExec  uint64
	BLeaf  uint64
	QCHigh uint64
	View   uint32
}

type Storage

type Storage interface {
	GetMerkleRoot() []byte
	Commit(data *storage.CommitData) error
	StoreBlock(blk *core.Block) error
	GetBlock(hash []byte) (*core.Block, error)
	GetLastBlock() (*core.Block, error)
	StoreQC(qc *core.QuorumCert) error
	GetQC(blkHash []byte) (*core.QuorumCert, error)
	GetLastQC() (*core.QuorumCert, error)
	GetBlockHeight() uint64
	HasTx(hash []byte) bool
}

type TxPool

type TxPool interface {
	SubmitTx(tx *core.Transaction) error
	StoreTxs(txs *core.TxList) error
	PopTxsFromQueue(max int) [][]byte
	GetTxsFromQueue(max int) [][]byte
	SetTxsPending(hashes [][]byte)
	GetTxsToExecute(hashes [][]byte) ([]*core.Transaction, [][]byte)
	RemoveTxs(hashes [][]byte)
	PutTxsToQueue(hashes [][]byte)
	SyncTxs(peer *core.PublicKey, hashes [][]byte) error
	GetTx(hash []byte) *core.Transaction
	GetStatus() txpool.Status
	GetTxStatus(hash []byte) txpool.TxStatus
}

Jump to

Keyboard shortcuts

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