consensus

package
v0.0.0-...-169a2f2 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2021 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultConfig = Config{
	BlockTxLimit:  400,
	TxWaitTime:    1 * time.Second,
	BeatTimeout:   500 * time.Millisecond,
	BlockDelay:    40 * time.Millisecond,
	ViewWidth:     30 * time.Second,
	LeaderTimeout: 10 * time.Second,
}

Functions

This section is empty.

Types

type Config

type Config struct {
	ChainID int64

	// maximum tx count in a block
	BlockTxLimit int

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

	// for leader, delay to propose next block if she cannot create qc")
	BeatTimeout 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
}

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)
}

type MsgService

type MsgService interface {
	BroadcastProposal(blk *core.Block) error
	BroadcastNewView(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)
	SendNewView(pubKey *core.PublicKey, qc *core.QuorumCert) error

	SubscribeProposal(buffer int) *emitter.Subscription
	SubscribeVote(buffer int) *emitter.Subscription
	SubscribeNewView(buffer int) *emitter.Subscription
}

type Resources

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

type Status

type Status struct {
	StartTime int64

	// commited tx count since node is up
	CommitedTxCount 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 {
	PopTxsFromQueue(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
}

Jump to

Keyboard shortcuts

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