Documentation
¶
Overview ¶
Package consensus is the core module to manage the consensus among nodes.
Index ¶
- Variables
- func ValidateDecreeContext(dc *DecreeContext) error
- func ValidateEngineContext(ec *EngineContext) error
- func ValidateQuorum(quorum *ultpb.Quorum, depth int, extraChecks bool) error
- func ValidateValidatorContext(vc *ValidatorContext) error
- type Ballot
- type BallotPhase
- type BallotSlice
- type Confirm
- type ConsensusValue
- type Decree
- type DecreeContext
- type Engine
- func (e *Engine) Externalize(idx uint64, value string) error
- func (e *Engine) GetQuorum(quorumHash string) (*Quorum, error)
- func (e *Engine) GetTxSet(txsetHash string) (*TxSet, error)
- func (e *Engine) Propose() error
- func (e *Engine) RecvStatement(stmt *ultpb.Statement) error
- func (e *Engine) RecvTxSet(txsetHash string, txset *TxSet) error
- func (e *Engine) Start()
- func (e *Engine) Stop()
- type EngineContext
- type Externalize
- type ExternalizeValue
- type Nominate
- type Prepare
- type Quorum
- type QuorumSlice
- type Statement
- type TxSet
- type Validator
- func (v *Validator) GetQuorum(quorumHash string) (*Quorum, error)
- func (v *Validator) GetTxSet(txsetHash string) (*TxSet, error)
- func (v *Validator) Ready() <-chan *Statement
- func (v *Validator) Recv(stmt *Statement) error
- func (v *Validator) RecvQuorum(quorumHash string, quorum *Quorum) error
- func (v *Validator) RecvTxSet(txsetHash string, txset *TxSet) error
- func (v *Validator) Stop()
- type ValidatorContext
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidTx = errors.New("invalid transaction") ErrInsufficientBalance = errors.New("insufficient balance") ErrInvalidSeqNum = errors.New("invalid sequence number") )
var (
ErrUnknownStmtType = errors.New("unknown statement type")
)
Functions ¶
func ValidateDecreeContext ¶
func ValidateDecreeContext(dc *DecreeContext) error
func ValidateEngineContext ¶
func ValidateEngineContext(ec *EngineContext) error
func ValidateQuorum ¶
Check whether the quorum is valid.
func ValidateValidatorContext ¶
func ValidateValidatorContext(vc *ValidatorContext) error
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 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 ¶
Get the latest sent statements including nominations and ballots.
func (*Decree) Recv ¶
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.
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 ¶
Externalize a consensus value with decree index.
func (*Engine) RecvStatement ¶
RecvStatement deals with received broadcast statement.
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 ExternalizeValue ¶
Information about the externalized value.
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 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) Recv ¶
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 ¶
RecvQuorum receives downloaded quorum and save it.