poset

package
v0.0.0-...-59e56fa Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2020 License: MIT Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrWrongEpochHash   = errors.New("mismatched prev epoch hash")
	ErrNonZeroEpochHash = errors.New("prev epoch hash isn't zero for non-first event")
	ErrCheatersObserved = errors.New("Cheaters observed by self-parent aren't allowed as parents")
	ErrWrongFrame       = errors.New("Claimed frame mismatched with calculated")
	ErrWrongIsRoot      = errors.New("Claimed isRoot mismatched with calculated")
	ErrWrongMedianTime  = errors.New("Claimed medianTime mismatched with calculated")
)

Functions

This section is empty.

Types

type Checkpoint

type Checkpoint struct {
	// fields can change only after a frame is decided
	LastDecidedFrame idx.Frame
	LastBlockN       idx.Block
	LastAtropos      hash.Event
	AppHash          common.Hash
}

Checkpoint is for persistent storing.

type EpochState

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

type Event

type Event struct {
	*inter.Event
}

Event is a poset event for internal purpose.

type EventSource

type EventSource interface {
	HasEvent(hash.Event) bool
	GetEvent(hash.Event) *inter.Event
	GetEventHeader(idx.Epoch, hash.Event) *inter.EventHeaderData
}

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

type Events

type Events []*Event

Events is a ordered slice of events.

func (Events) String

func (ee Events) String() string

String returns human readable representation.

func (Events) UnWrap

func (ee Events) UnWrap() inter.Events

UnWrap extracts inter.Event.

type FrameInfo

type FrameInfo struct {
	TimeOffset        int64 // may be negative
	TimeRatio         inter.Timestamp
	LastConsensusTime inter.Timestamp
}

FrameInfo stores persistent data, associated with a frame

func (*FrameInfo) CalcConsensusTime

func (f *FrameInfo) CalcConsensusTime(lamport idx.Lamport) inter.Timestamp

CalcConsensusTime calcs consensus timestamp, using frame's time offset/ratio

func (*FrameInfo) DecodeRLP

func (f *FrameInfo) DecodeRLP(st *rlp.Stream) error

DecodeRLP is for RLP deserialization.

func (*FrameInfo) EncodeRLP

func (f *FrameInfo) EncodeRLP(w io.Writer) error

EncodeRLP is for RLP serialization.

type GenesisMismatchError

type GenesisMismatchError struct {
	Stored, New common.Hash
}

GenesisMismatchError is raised when trying to overwrite an existing genesis block with an incompatible one.

func (*GenesisMismatchError) Error

func (e *GenesisMismatchError) Error() string

Error implements error interface.

type GenesisState

type GenesisState struct {
	Epoch       idx.Epoch
	Time        inter.Timestamp // consensus time of the last Atropos
	LastAtropos hash.Event
	AppHash     common.Hash
}

GenesisState stores state of previous Epoch

func (*GenesisState) EpochName

func (g *GenesisState) EpochName() string

func (*GenesisState) Hash

func (g *GenesisState) Hash() common.Hash

type Poset

type Poset struct {
	*Checkpoint
	EpochState

	logger.Instance
	// contains filtered or unexported fields
}

Poset processes events to get consensus.

func New

func New(dag lachesis.DagConfig, store *Store, input EventSource) *Poset

New creates Poset instance. It does not start any process.

func (*Poset) Bootstrap

func (p *Poset) Bootstrap(callback inter.ConsensusCallbacks)

Bootstrap restores poset's state from store.

func (*Poset) GetConsensusTime

func (p *Poset) GetConsensusTime(id hash.Event) (inter.Timestamp, error)

GetConsensusTime calc consensus timestamp for given event, if event is confirmed.

func (*Poset) GetEpoch

func (p *Poset) GetEpoch() idx.Epoch

GetEpoch returns current epoch num to 3rd party.

func (*Poset) GetEpochValidators

func (p *Poset) GetEpochValidators() (*pos.Validators, idx.Epoch)

GetEpochValidators returns validators of current epoch, and the epoch. Don't mutate validators.

func (*Poset) GetEvent

func (p *Poset) GetEvent(h hash.Event) *Event

GetEvent returns event.

func (*Poset) GetEventHeader

func (p *Poset) GetEventHeader(epoch idx.Epoch, h hash.Event) *inter.EventHeaderData

GetEventHeader returns event header.

func (*Poset) GetGenesisHash

func (p *Poset) GetGenesisHash() common.Hash

GetGenesisHash returns PrevEpochHash of first epoch.

func (*Poset) GetValidators

func (p *Poset) GetValidators() *pos.Validators

GetValidators returns validators of current epoch. Don't mutate validators.

func (*Poset) GetVectorIndex

func (p *Poset) GetVectorIndex() *vector.Index

GetVectorIndex returns vector clock.

func (*Poset) LastBlock

func (p *Poset) LastBlock() (idx.Block, hash.Event)

LastBlock returns current block.

func (*Poset) Prepare

func (p *Poset) Prepare(e *inter.Event) *inter.Event

Prepare fills consensus-related fields: Frame, IsRoot, MedianTimestamp, PrevEpochHash returns nil if event should be dropped

func (*Poset) ProcessEvent

func (p *Poset) ProcessEvent(e *inter.Event) (err error)

ProcessEvent takes event into processing. Event order matter: parents first. ProcessEvent is not safe for concurrent use.

type Store

type Store struct {
	logger.Instance
	// contains filtered or unexported fields
}

Store is a poset 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(dbs *flushable.SyncedPool, cfg StoreConfig) *Store

NewStore creates store over key-value db.

func (*Store) AddRoot

func (s *Store) AddRoot(root *inter.Event)

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

func (*Store) ApplyGenesis

func (s *Store) ApplyGenesis(g *genesis.Genesis, genesisAtropos hash.Event, appHash common.Hash) error

ApplyGenesis writes initial state.

func (*Store) Close

func (s *Store) Close()

Close leaves underlying database.

func (*Store) GetCheckpoint

func (s *Store) GetCheckpoint() *Checkpoint

GetCheckpoint returns stored Checkpoint. State is seldom read; so no cache.

func (*Store) GetEpoch

func (s *Store) GetEpoch() *EpochState

GetEpoch returns stored epoch.

func (*Store) GetEventConfirmedOn

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

GetEventConfirmedOn returns confirmed event hash.

func (*Store) GetFrameInfo

func (s *Store) GetFrameInfo(e idx.Epoch, f idx.Frame) *FrameInfo

GetFrameInfo returns stored frame.

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 complex mutable cache!

func (*Store) GetGenesis

func (s *Store) GetGenesis() *EpochState

GetGenesis returns stored first epoch.

func (*Store) GetGenesisHash

func (s *Store) GetGenesisHash() common.Hash

GetGenesisHash returns PrevEpochHash of first epoch.

func (*Store) RecreateEpochDb

func (s *Store) RecreateEpochDb(n idx.Epoch)

RecreateEpochDb makes new epoch DB and drops prev.

func (*Store) SetCheckpoint

func (s *Store) SetCheckpoint(cp *Checkpoint)

SetCheckpoint save Checkpoint. Checkpoint is seldom read; so no cache.

func (*Store) SetEpoch

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

SetEpoch stores epoch.

func (*Store) SetEventConfirmedOn

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

SetEventConfirmedOn stores confirmed event hash.

func (*Store) SetFrameInfo

func (s *Store) SetFrameInfo(e idx.Epoch, f idx.Frame, info *FrameInfo)

SetFrameInfo stores event.

func (*Store) SetGenesis

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

SetGenesis stores first epoch.

type StoreConfig

type StoreConfig struct {
	// Cache size for Roots.
	Roots int
}

StoreConfig is a config for store db.

func DefaultStoreConfig

func DefaultStoreConfig() StoreConfig

DefaultStoreConfig for product.

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