consensus

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2018 License: Apache-2.0 Imports: 11 Imported by: 2

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.ActiveNode) (result []byte, err error)

CalculateHash calculates hash of active node list

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.ActiveNode) ([]*core.ActiveNode, 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 []*NodeUnsyncHash) ([]*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.ActiveNode) ([]*core.ActiveNode, 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 []*NodeUnsyncHash) ([]*NodeUnsyncHash, error)
}

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.ActiveNode, error)
}

Consensus interface provides method to make consensus between participants

func NewConsensus

func NewConsensus(communicator Communicator) (Consensus, error)

NewConsensus creates consensus

type NodeUnsyncHash added in v0.6.0

type NodeUnsyncHash struct {
	NodeID core.RecordRef
	Hash   []byte
}

func CalculateNodeUnsyncHash added in v0.6.0

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

CalculateNodeUnsyncHash calculates hash for a NodeUnsyncHash

type Participant

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

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
}

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.ActiveNode
	// GetPulse returns actual pulse for current consensus process.
	GetPulse() core.PulseNumber
	// SetHash sets hash of unsync lists for each node of consensus.
	SetHash([]*NodeUnsyncHash)
	// GetHash get hash of unsync lists for each node of consensus. If hash is not calculated yet, then this call blocks
	// until the hash is calculated with SetHash() call
	GetHash(blockTimeout time.Duration) ([]*NodeUnsyncHash, error)
}

UnsyncHolder

Jump to

Keyboard shortcuts

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