consensus

package
v0.0.0-...-92d0b4a Latest Latest
Warning

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

Go to latest
Published: May 31, 2024 License: GPL-3.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const ExecuteTxFlag = false // set to false when benchmark test
View Source
const GenerateTxFlag = true
View Source
const PreserveTxFlag = true // set to true when benchmark test
View Source
const VoteBatchFlag = false // set to false to prevent voting on batch

Variables

View Source
var DefaultConfig = Config{
	BatchTxLimit:    200,
	BlockBatchLimit: -1,
	VoteBatchLimit:  -1,
	TxWaitTime:      1 * time.Second,
	BatchWaitTime:   3 * time.Second,
	ProposeTimeout:  2 * time.Second,
	BlockDelay:      1 * time.Second,
	ViewWidth:       60 * time.Second,
	LeaderTimeout:   20 * time.Second,
	BenchmarkPath:   "",
}

Functions

This section is empty.

Types

type Config

type Config struct {
	ChainID int64

	// maximum tx count in a batch
	BatchTxLimit int

	// maximum batch count in a block
	BlockBatchLimit int

	// batch count in a batch vote
	VoteBatchLimit int

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

	// maximum delay the leader waits for voting on a batch
	BatchWaitTime time.Duration

	// duration to wait to propose next block if leader cannot create qc
	ProposeTimeout time.Duration

	// minimum delay between each block (i.e, it can define maximum block rate)
	BlockDelay time.Duration

	// view duration for a leader
	ViewWidth time.Duration

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

	// 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) 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 MsgService

type MsgService interface {
	BroadcastProposal(blk *core.Block) error
	BroadcastBatch(batch *core.Batch) error
	BroadcastNewView(qc *core.QuorumCert) error
	SendBatch(pubKey *core.PublicKey, batch *core.Batch) error
	SendVote(pubKey *core.PublicKey, vote *core.Vote) error
	SendBatchVote(pubKey *core.PublicKey, vote *core.BatchVote) error
	RequestBlock(pubKey *core.PublicKey, hash []byte) (*core.Block, error)
	RequestBlockByHeight(pubKey *core.PublicKey, height uint64) (*core.Block, error)
	SendNewView(pubKey *core.PublicKey, qc *core.QuorumCert) error
	SubscribeBatch(buffer int) *emitter.Subscription
	SubscribeProposal(buffer int) *emitter.Subscription
	SubscribeVote(buffer int) *emitter.Subscription
	SubscribeBatchVote(buffer int) *emitter.Subscription
	SubscribeNewView(buffer int) *emitter.Subscription
}

type Resources

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

type Status

type Status struct {
	StartTime int64

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

	// start timestamp of current view
	ViewStart int64

	// set to true when current view timeout
	// set to false once the view leader created the first qc
	PendingViewChange bool
	LeaderIndex       int

	// hotstuff state (block heights)
	BVote  uint64
	BLock  uint64
	BExec  uint64
	BLeaf  uint64
	QCHigh uint64
}

type Storage

type Storage interface {
	GetMerkleRoot() []byte
	Commit(data *storage.CommitData) error
	GetBlock(hash []byte) (*core.Block, error)
	GetLastBlock() (*core.Block, 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
	StorePendingTxs(txs *core.TxList) error
	PopTxsFromQueue(max int) []*core.Transaction
	GetTxsFromQueue(max int) []*core.Transaction
	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