consensus

package
v0.0.0-...-9098a98 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2019 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Package consensus is the core module to manage the consensus among nodes.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidTx           = errors.New("invalid transaction")
	ErrInsufficientBalance = errors.New("insufficient balance")
	ErrInvalidSeqNum       = errors.New("invalid sequence number")
)
View Source
var (
	ErrUnknownStmtType = errors.New("unknown statement type")
)

Functions

func ValidateDecreeContext

func ValidateDecreeContext(dc *DecreeContext) error

func ValidateEngineContext

func ValidateEngineContext(ec *EngineContext) error

func ValidateQuorum

func ValidateQuorum(quorum *ultpb.Quorum, depth int, extraChecks bool) error

Check whether the quorum is valid.

func ValidateValidatorContext

func ValidateValidatorContext(vc *ValidatorContext) error

Types

type Ballot

type Ballot = ultpb.Ballot

Type alias for proto types.

type BallotPhase

type BallotPhase uint8
const (
	BallotPhasePrepare BallotPhase = iota
	BallotPhaseConfirm
	BallotPhaseExternalize
)

type BallotSlice

type BallotSlice []*Ballot

Custom sorter for ballot slice.

func (BallotSlice) Len

func (bs BallotSlice) Len() int

Return the length of underlying ballot slice.

func (BallotSlice) Less

func (bs BallotSlice) Less(i, j int) bool

Sort ballots in descending order by comparing. counter first then value

func (BallotSlice) Swap

func (bs BallotSlice) Swap(i, j int)

type Confirm

type Confirm = ultpb.Confirm

Type alias for proto types.

type ConsensusValue

type ConsensusValue = ultpb.ConsensusValue

Type alias for proto types.

type Decree

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

Decree is an abstractive decision about the consensus value that the consensus engine will reach in each round.

func NewDecree

func NewDecree(ctx *DecreeContext) *Decree

func (*Decree) GetLatestStatements

func (d *Decree) GetLatestStatements() []*Statement

Get the latest sent statements including nominations and ballots.

func (*Decree) Nominate

func (d *Decree) Nominate(prevHash, currHash string, isRenominate bool) error

Nominate nominates a consensus value for the decree.

func (*Decree) Recv

func (d *Decree) Recv(stmt *Statement) error

Recv receives the validated statement and redistributes it to the corresponding handler. If it is a nomination statement, we send it to the nomination handler. Other types of statements belong to ballot protocol, we directly pass the statement to the handler can distinguish fine grained type of the statement.

func (*Decree) StopNomination

func (d *Decree) StopNomination()

Stop the nomination.

type DecreeContext

type DecreeContext struct {
	Index           uint64                   // decree index
	NodeID          string                   // local node ID
	Quorum          *Quorum                  // local node quorum
	QuorumHash      string                   // local node quorum hash
	StmtChan        chan<- *Statement        // channel for broadcasting statement
	ExternalizeChan chan<- *ExternalizeValue // channel for notifying externlized value
	LM              *ledger.Manager
	Validator       *Validator
}

DecreeContext contains contextual information Decree needs.

type Engine

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

Engine is the driver of underlying federated consensus protocol.

func NewEngine

func NewEngine(ctx *EngineContext) *Engine

NewEngine creates an instance of Engine with EngineContext.

func (*Engine) Externalize

func (e *Engine) Externalize(idx uint64, value string) error

Externalize a consensus value with decree index.

func (*Engine) GetQuorum

func (e *Engine) GetQuorum(quorumHash string) (*Quorum, error)

Get the quorum of the quorum hash.

func (*Engine) GetTxSet

func (e *Engine) GetTxSet(txsetHash string) (*TxSet, error)

Get the txset of the txset hash.

func (*Engine) Propose

func (e *Engine) Propose() error

Try to propose current transaction set for consensus.

func (*Engine) RecvStatement

func (e *Engine) RecvStatement(stmt *ultpb.Statement) error

RecvStatement deals with received broadcast statement.

func (*Engine) RecvTxSet

func (e *Engine) RecvTxSet(txsetHash string, txset *TxSet) error

Recv downloaded txset.

func (*Engine) Start

func (e *Engine) Start()

func (*Engine) Stop

func (e *Engine) Stop()

Stop the consensus engine.

type EngineContext

type EngineContext struct {
	NetworkID  string
	Database   db.Database
	Seed       string
	NodeID     string
	Role       string
	MaxDecrees uint64
	PM         *peer.Manager
	AM         *account.Manager
	LM         *ledger.Manager
	TM         *tx.Manager
	// Initial quorum parsed from config file.
	Quorum *ultpb.Quorum
	// Interval of consensus proposition in seconds.
	ProposeInterval int
}

EngineContext represents contextual information Engine needs.

type Externalize

type Externalize = ultpb.Externalize

Type alias for proto types.

type ExternalizeValue

type ExternalizeValue struct {
	Index uint64 // index of decree
	Value string // consensus value
}

Information about the externalized value.

type Nominate

type Nominate = ultpb.Nominate

Type alias for proto types.

type Prepare

type Prepare = ultpb.Prepare

Type alias for proto types.

type Quorum

type Quorum = ultpb.Quorum

Type alias for proto types.

type QuorumSlice

type QuorumSlice []*Quorum

Custom sorter for quorum.

func (QuorumSlice) Len

func (qs QuorumSlice) Len() int

Returns the length of underlying quorum slice.

func (QuorumSlice) Less

func (qs QuorumSlice) Less(i, j int) bool

Sort quorums by lexicographical order of validators then by the lexicographical order of nest quorums.

func (QuorumSlice) Swap

func (qs QuorumSlice) Swap(i, j int)

type Statement

type Statement = ultpb.Statement

Type alias for proto types.

type TxSet

type TxSet = ultpb.TxSet

Type alias for proto types.

type Validator

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

Validator validates incoming consensus messages and requests missing information of transaction and quorum from other peers.

func NewValidator

func NewValidator(ctx *ValidatorContext) *Validator

func (*Validator) GetQuorum

func (v *Validator) GetQuorum(quorumHash string) (*Quorum, error)

Get the quorum of the corresponding quorum hash,

func (*Validator) GetTxSet

func (v *Validator) GetTxSet(txsetHash string) (*TxSet, error)

Get the txset from the ledger manager.

func (*Validator) Ready

func (v *Validator) Ready() <-chan *Statement

Ready returns ready statements with full information.

func (*Validator) Recv

func (v *Validator) Recv(stmt *Statement) error

Recv checks whether the input statement has the complete information including quorum and txset for the consensus engine to process. If all the necessary information are present, it will directly return the statement to ready channel. Otherwise, it will try to download the missing part of information from peers.

func (*Validator) RecvQuorum

func (v *Validator) RecvQuorum(quorumHash string, quorum *Quorum) error

RecvQuorum receives downloaded quorum and save it.

func (*Validator) RecvTxSet

func (v *Validator) RecvTxSet(txsetHash string, txset *TxSet) error

RecvTxSet receives downloaded txset and save it.

func (*Validator) Stop

func (v *Validator) Stop()

Stop the validator.

type ValidatorContext

type ValidatorContext struct {
	Database           db.Database // database instance
	LM                 *ledger.Manager
	MaxDecrees         uint64
	QuorumDownloadChan chan<- string
	TxSetDownloadChan  chan<- string
}

ValidatorContext contains contextual information validator needs.

Jump to

Keyboard shortcuts

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