posposet

package
v0.0.0-...-168a2c3 Latest Latest
Warning

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

Go to latest
Published: May 30, 2019 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Block

type Block struct {
	Index  uint64
	Events hash.EventsSlice
}

Block is a chain block.

func NewBlock

func NewBlock(index uint64, ordered Events) *Block

NewBlock makes main chain block from topological ordered events.

func WireToBlock

func WireToBlock(w *wire.Block) *Block

WireToBlock converts from wire.

func (*Block) ToWire

func (e *Block) ToWire() *wire.Block

ToWire converts to proto.Message.

type Event

type Event struct {
	*inter.Event
	// contains filtered or unexported fields
}

Event is a poset event for internal purpose.

type EventSource

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

type Events

type Events []*Event

Events is a ordered slice of events.

func (Events) Len

func (ee Events) Len() int

func (Events) Less

func (ee Events) Less(i, j int) bool

func (Events) String

func (ee Events) String() string

String returns human readable representation.

func (Events) Swap

func (ee Events) Swap(i, j int)

type EventsByPeer

type EventsByPeer map[hash.Peer]hash.Events

EventsByNode is a event hashes grouped by creator. ( creator --> event hashes )

func WireToEventsByPeer

func WireToEventsByPeer(arr []*wire.EventDescr) EventsByPeer

WireToEventsByPeer converts from wire.

func (EventsByPeer) Add

func (ee EventsByPeer) Add(events EventsByPeer) (changed bool)

Add unions events into one.

func (EventsByPeer) AddOne

func (ee EventsByPeer) AddOne(event hash.Event, creator hash.Peer) (changed bool)

AddOne appends one event.

func (EventsByPeer) Contains

func (ee EventsByPeer) Contains(node hash.Peer, event hash.Event) bool

Contains returns true if event of node is in.

func (EventsByPeer) Each

func (ee EventsByPeer) Each() map[hash.Event]hash.Peer

Each returns range of all events.

func (EventsByPeer) String

func (ee EventsByPeer) String() string

String returns human readable string representation.

func (EventsByPeer) ToWire

func (ee EventsByPeer) ToWire() []*wire.EventDescr

ToWire converts to simple slice.

type FlagTable

type FlagTable map[hash.Event]EventsByPeer

FlagTable stores the reachability of each event to the roots. It helps to select root without using path searching algorithms. Zero-hash is a self-parent root. ( event hash --> root creator --> root hashes )

func WireToFlagTable

func WireToFlagTable(arr []*wire.Flag) FlagTable

WireToFlagTable converts from wire.

func (FlagTable) EventKnows

func (ft FlagTable) EventKnows(e hash.Event, node hash.Peer, event hash.Event) bool

EventKnows return true if e knows event of node.

func (FlagTable) IsRoot

func (ft FlagTable) IsRoot(event hash.Event) bool

IsRoot returns true if event is root.

func (FlagTable) Roots

func (ft FlagTable) Roots() EventsByPeer

Roots returns all roots by node.

func (FlagTable) ToWire

func (ft FlagTable) ToWire() []*wire.Flag

ToWire converts to simple slice.

type Frame

type Frame struct {
	Index            uint64
	FlagTable        FlagTable
	ClothoCandidates EventsByPeer
	Atroposes        TimestampsByEvent
	Balances         hash.Hash
	// contains filtered or unexported fields
}

Frame is a consensus tables for frame.

func WireToFrame

func WireToFrame(w *wire.Frame) *Frame

WireToFrame converts from wire.

func (*Frame) AddClothoCandidate

func (f *Frame) AddClothoCandidate(event hash.Event, creator hash.Peer)

AddClothoCandidate adds event into ClothoCandidates list.

func (*Frame) AddRootsOf

func (f *Frame) AddRootsOf(event hash.Event, roots EventsByPeer)

AddRootsOf appends known roots for event.

func (*Frame) GetRootsOf

func (f *Frame) GetRootsOf(event hash.Event) EventsByPeer

GetRootsOf returns known roots of event. For read only, please.

func (*Frame) Save

func (f *Frame) Save()

Save calls .save() if set.

func (*Frame) SetAtropos

func (f *Frame) SetAtropos(clotho hash.Event, consensusTime inter.Timestamp)

SetAtropos makes Atropos from Clotho and consensus time.

func (*Frame) SetBalances

func (f *Frame) SetBalances(balances hash.Hash) bool

SetBalances saves PoS-balances state.

func (*Frame) ToWire

func (f *Frame) ToWire() *wire.Frame

ToWire converts to proto.Message.

type Poset

type Poset struct {
	NewBlockCh chan uint64

	logger.Instance
	// contains filtered or unexported fields
}

Poset processes events to get consensus.

func New

func New(store *Store, input EventSource) *Poset

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

func (*Poset) Bootstrap

func (p *Poset) Bootstrap()

Bootstrap restores current state from store.

func (*Poset) FrameOfEvent

func (p *Poset) FrameOfEvent(event hash.Event) (frame *Frame, isRoot bool)

FrameOfEvent returns unfinished frame where event is in.

func (*Poset) GetEvent

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

GetEvent returns event.

func (*Poset) GetGenesisHash

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

func (*Poset) GetTransaction

func (p *Poset) GetTransaction(h hash.Transaction) *inter.InternalTransaction

GetTransaction returns transaction by hash.

func (*Poset) GetTransactionCount

func (p *Poset) GetTransactionCount(h hash.Peer) uint64

GetTransactionCount returns transaction count for peer.

func (*Poset) HasEvent

func (p *Poset) HasEvent(h hash.Event) bool

HasEvent returns true if event exists.

func (*Poset) PushEvent

func (p *Poset) PushEvent(e hash.Event)

PushEvent takes event into processing. Event order matter: parents first.

func (*Poset) StakeOf

func (p *Poset) StakeOf(addr hash.Peer) uint64

StakeOf returns stake balance of peer.

func (*Poset) Start

func (p *Poset) Start()

Start starts events processing.

func (*Poset) Stop

func (p *Poset) Stop()

Stop stops events processing.

type State

type State struct {
	LastFinishedFrameN uint64
	LastBlockN         uint64
	Genesis            hash.Hash
	TotalCap           uint64
}

State is a current poset state.

func WireToState

func WireToState(w *wire.State) *State

WireToState converts from wire.

func (*State) ToWire

func (s *State) ToWire() *wire.State

ToWire converts to proto.Message.

type Store

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

Store is a poset persistent storage working over physical key-value database. TODO: cache tables with LRU.

func NewMemStore

func NewMemStore() *Store

NewMemStore creates store over memory map.

func NewStore

func NewStore(db kvdb.Database, cached bool) *Store

NewStore creates store over key-value db.

func (*Store) ApplyGenesis

func (s *Store) ApplyGenesis(balances map[hash.Peer]uint64) error

ApplyGenesis stores initial state.

func (*Store) Close

func (s *Store) Close()

Close leaves underlying database.

func (*Store) GetBlock

func (s *Store) GetBlock(n uint64) *Block

GetBlock returns stored block. State is seldom read; so no cache.

func (*Store) GetEventFrame

func (s *Store) GetEventFrame(e hash.Event) *uint64

GetEventFrame returns frame num of event.

func (*Store) GetFrame

func (s *Store) GetFrame(n uint64) *Frame

GetFrame returns stored frame.

func (*Store) GetState

func (s *Store) GetState() *State

GetState returns stored state. State is seldom read; so no cache.

func (*Store) SetBlock

func (s *Store) SetBlock(b *Block)

SetBlock stores chain block. State is seldom read; so no cache.

func (*Store) SetEventFrame

func (s *Store) SetEventFrame(e hash.Event, frame uint64)

SetEventFrame stores frame num of event.

func (*Store) SetFrame

func (s *Store) SetFrame(f *Frame)

SetFrame stores event.

func (*Store) SetState

func (s *Store) SetState(st *State)

SetState stores state. State is seldom read; so no cache.

func (*Store) StateDB

func (s *Store) StateDB(from hash.Hash) *state.DB

StateDB returns state database.

type TimestampsByEvent

type TimestampsByEvent map[hash.Event]inter.Timestamp

TimestampsByEvent is a timestamps by event index.

func WireToTimestampsByEvent

func WireToTimestampsByEvent(arr map[string]uint64) TimestampsByEvent

WireToTimestampsByEvent converts from wire.

func (TimestampsByEvent) ToWire

func (tt TimestampsByEvent) ToWire() map[string]uint64

ToWire converts to simple slice.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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