consensus

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2018 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package consensus provides BFT-like algorithm to distribute list of records between participants

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CalculateHash added in v0.6.0

func CalculateHash(list []*core.Node) (result []byte, err error)

CalculateHash calculates hash of active node list

func CalculateNodeUnsyncHash added in v0.6.0

func CalculateNodeUnsyncHash(nodeID core.RecordRef, list []*core.Node) (*network.NodeUnsyncHash, error)

CalculateNodeUnsyncHash calculates hash for a NodeUnsyncHash

Types

type Communicator

type Communicator interface {
	// ExchangeData used in first consensus step to exchange data between participants
	ExchangeData(ctx context.Context, pulse core.PulseNumber, p Participant, data []*core.Node) ([]*core.Node, error)

	// ExchangeHash used in second consensus step to exchange only hashes of merged data vectors
	ExchangeHash(ctx context.Context, pulse core.PulseNumber, p Participant, data []*network.NodeUnsyncHash) ([]*network.NodeUnsyncHash, error)
}

Communicator interface is used to exchange messages between participants

type CommunicatorReceiver added in v0.6.0

type CommunicatorReceiver interface {
	// ExchangeData used in first consensus step to exchange data between participants
	ExchangeData(ctx context.Context, pulse core.PulseNumber, from core.RecordRef, data []*core.Node) ([]*core.Node, error)
	// ExchangeHash used in second consensus step to exchange only hashes of merged data vectors
	ExchangeHash(ctx context.Context, pulse core.PulseNumber, from core.RecordRef, data []*network.NodeUnsyncHash) ([]*network.NodeUnsyncHash, error)
}

CommunicatorReceiver

type Consensus

type Consensus interface {
	// DoConsensus is sync method, it performs all consensus steps and returns list of synced nodes
	// method should be executed in goroutine
	DoConsensus(ctx context.Context, holder UnsyncHolder, self Participant, allParticipants []Participant) ([]*core.Node, error)
}

Consensus interface provides method to make consensus between participants

func NewConsensus

func NewConsensus(communicator Communicator) Consensus

NewConsensus creates consensus

type Participant

type Participant interface {
	GetActiveNode() *core.Node
}

Participant describes one consensus participant

type Processor added in v0.6.0

type Processor interface {
	// ProcessPulse is called when we get new pulse from pulsar. Should be called in goroutine
	ProcessPulse(ctx context.Context, pulse core.Pulse)
	// IsPartOfConsensus returns whether we should perform all consensus interactions or not
	IsPartOfConsensus() bool
	// ReceiverHandler return handler that is responsible to handle consensus network requests
	ReceiverHandler() CommunicatorReceiver
	// SetNodeKeeper set NodeKeeper for the processor to integrate Processor with unsync -> sync -> active pipeline
	SetNodeKeeper(keeper network.NodeKeeper)
}

Processor is an interface to bind all functionality related to consensus with the network layer

type UnsyncHolder added in v0.6.0

type UnsyncHolder interface {
	// GetUnsync returns list of local unsync nodes. This list is created
	GetUnsync() []*core.Node
	// GetPulse returns actual pulse for current consensus process.
	GetPulse() core.PulseNumber
	// SetHash sets hash of unsync lists for each node of consensus.
	SetHash([]*network.NodeUnsyncHash)
	// GetHash get hash of unsync lists for each node of  If hash is not calculated yet, then this call blocks
	// until the hash is calculated with SetHash() call.
	GetHash(blockTimeout time.Duration) ([]*network.NodeUnsyncHash, error)
}

UnsyncHolder

Jump to

Keyboard shortcuts

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