abft

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2022 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FirstFrame = idx.Frame(1)
	FirstEpoch = idx.Epoch(1)
)

Variables

View Source
var (
	ErrNoGenesis = errors.New("genesis not applied")
)
View Source
var (
	ErrWrongFrame = errors.New("claimed frame mismatched with calculated")
)

Functions

This section is empty.

Types

type Config

type Config struct {
}

func DefaultConfig

func DefaultConfig() Config

DefaultConfig for livenet.

func LiteConfig

func LiteConfig() Config

LiteConfig is for tests or inmemory.

type DagIndex

type DagIndex interface {
	dagidx.VectorClock
	dagidx.ForklessCause
}

type DagIndexer

type DagIndexer interface {
	dagidx.VectorClock
	dagidx.ForklessCause

	Add(dag.Event) error
	Flush()
	DropNotFlushed()

	Reset(validators *pos.Validators, db kvdb.Store, getEvent func(hash.Event) dag.Event)
}

type EpochDBProducer

type EpochDBProducer func(epoch idx.Epoch) kvdb.DropableStore

type EpochState

type EpochState struct {
	// stored values
	// these values change only after a change of epoch
	Epoch      idx.Epoch
	Validators *pos.Validators
}

func (EpochState) String

func (es EpochState) String() string

type EventSource

type EventSource interface {
	HasEvent(hash.Event) bool
	GetEvent(hash.Event) dag.Event
}

EventSource is a callback for getting events from an external storage.

type Genesis

type Genesis struct {
	Epoch      idx.Epoch
	Validators *pos.Validators
}

Genesis stores genesis state

type IndexedLachesis

type IndexedLachesis struct {
	*Lachesis
	// contains filtered or unexported fields
}

IndexedLachesis performs events ordering and detects cheaters It's a wrapper around Orderer, which adds features which might potentially be application-specific: confirmed events traversal, DAG index updates and cheaters detection. Use this structure if need a general-purpose consensus. Instead, use lower-level abft.Orderer.

func NewIndexedLachesis

func NewIndexedLachesis(store *Store, input EventSource, dagIndexer DagIndexer, crit func(error), config Config) *IndexedLachesis

New creates IndexedLachesis instance.

func (*IndexedLachesis) Bootstrap

func (p *IndexedLachesis) Bootstrap(callback lachesis.ConsensusCallbacks) error

func (*IndexedLachesis) Build

func (p *IndexedLachesis) Build(e dag.MutableEvent) error

Build fills consensus-related fields: Frame, IsRoot returns error if event should be dropped

func (*IndexedLachesis) Process

func (p *IndexedLachesis) Process(e dag.Event) (err error)

Process takes event into processing. Event order matter: parents first. All the event checkers must be launched. Process is not safe for concurrent use.

type Lachesis

type Lachesis struct {
	*Orderer
	// contains filtered or unexported fields
}

Lachesis performs events ordering and detects cheaters It's a wrapper around Orderer, which adds features which might potentially be application-specific: confirmed events traversal, cheaters detection. Use this structure if need a general-purpose consensus. Instead, use lower-level abft.Orderer.

func NewLachesis

func NewLachesis(store *Store, input EventSource, dagIndex DagIndex, crit func(error), config Config) *Lachesis

NewLachesis creates Lachesis instance.

func (*Lachesis) Bootstrap

func (p *Lachesis) Bootstrap(callback lachesis.ConsensusCallbacks) error

func (*Lachesis) BootstrapWithOrderer

func (p *Lachesis) BootstrapWithOrderer(callback lachesis.ConsensusCallbacks, ordererCallbacks OrdererCallbacks) error

func (*Lachesis) OrdererCallbacks

func (p *Lachesis) OrdererCallbacks() OrdererCallbacks

type LastDecidedState

type LastDecidedState struct {
	// fields can change only after a frame is decided
	LastDecidedFrame idx.Frame
}

LastDecidedState is for persistent storing.

type Orderer

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

Orderer processes events to reach finality on their order. Unlike abft.Lachesis, this raw level of abstraction doesn't track cheaters detection

func NewOrderer

func NewOrderer(store *Store, input EventSource, dagIndex OrdererDagIndex, crit func(error), config Config) *Orderer

NewOrderer creates Orderer instance. Unlike Lachesis, Orderer doesn't updates DAG indexes for events, and doesn't detect cheaters It has only one purpose - reaching consensus on events order.

func (*Orderer) Bootstrap

func (p *Orderer) Bootstrap(callback OrdererCallbacks) error

Bootstrap restores abft's state from store.

func (*Orderer) Build

func (p *Orderer) Build(e dag.MutableEvent) error

Build fills consensus-related fields: Frame, IsRoot returns error if event should be dropped

func (*Orderer) Process

func (p *Orderer) Process(e dag.Event) (err error)

Process takes event into processing. Event order matter: parents first. All the event checkers must be launched. Process is not safe for concurrent use.

func (*Orderer) Reset

func (p *Orderer) Reset(epoch idx.Epoch, validators *pos.Validators) error

Reset switches epoch state to a new empty epoch.

type OrdererCallbacks

type OrdererCallbacks struct {
	ApplyAtropos func(decidedFrame idx.Frame, atropos hash.Event) (sealEpoch *pos.Validators)

	EpochDBLoaded func(idx.Epoch)
}

type OrdererDagIndex

type OrdererDagIndex interface {
	dagidx.ForklessCause
}

type Store

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

Store is a abft persistent storage working over parent key-value database.

func NewMemStore

func NewMemStore() *Store

NewMemStore creates store over memory map. Store is always blank.

func NewStore

func NewStore(mainDB kvdb.Store, getDB EpochDBProducer, crit func(error), cfg StoreConfig) *Store

NewStore creates store over key-value db.

func (*Store) AddRoot

func (s *Store) AddRoot(selfParentFrame idx.Frame, root dag.Event)

AddRoot stores the new root Not safe for concurrent use due to the complex mutable cache!

func (*Store) ApplyGenesis

func (s *Store) ApplyGenesis(g *Genesis) error

ApplyGenesis writes initial state.

func (*Store) Close

func (s *Store) Close() error

Close leaves underlying database.

func (*Store) GetEpoch

func (s *Store) GetEpoch() idx.Epoch

GetEpoch returns current epoch

func (*Store) GetEpochState

func (s *Store) GetEpochState() *EpochState

GetEpochState returns stored epoch.

func (*Store) GetEventConfirmedOn

func (s *Store) GetEventConfirmedOn(e hash.Event) idx.Frame

GetEventConfirmedOn returns confirmed event hash.

func (*Store) GetFrameRoots

func (s *Store) GetFrameRoots(f idx.Frame) []election.RootAndSlot

GetFrameRoots returns all the roots in the specified frame Not safe for concurrent use due to the complex mutable cache!

func (*Store) GetLastDecidedFrame

func (s *Store) GetLastDecidedFrame() idx.Frame

func (*Store) GetLastDecidedState

func (s *Store) GetLastDecidedState() *LastDecidedState

GetLastDecidedState returns stored LastDecidedState. State is seldom read; so no cache.

func (*Store) GetValidators

func (s *Store) GetValidators() *pos.Validators

GetValidators returns current validators

func (*Store) SetEpochState

func (s *Store) SetEpochState(e *EpochState)

SetEpochState stores epoch.

func (*Store) SetEventConfirmedOn

func (s *Store) SetEventConfirmedOn(e hash.Event, on idx.Frame)

SetEventConfirmedOn stores confirmed event hash.

func (*Store) SetLastDecidedState

func (s *Store) SetLastDecidedState(v *LastDecidedState)

SetLastDecidedState save LastDecidedState. LastDecidedState is seldom read; so no cache.

type StoreCacheConfig

type StoreCacheConfig struct {
	// Cache size for Roots.
	RootsNum    uint
	RootsFrames int
}

StoreCacheConfig is a cache config for store db.

type StoreConfig

type StoreConfig struct {
	Cache StoreCacheConfig
}

StoreConfig is a config for store db.

func DefaultStoreConfig

func DefaultStoreConfig(scale cachescale.Func) StoreConfig

DefaultStoreConfig for livenet.

func LiteStoreConfig

func LiteStoreConfig() StoreConfig

LiteStoreConfig is for tests or inmemory.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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