node

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: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Gossiping is the initial state of a Lachesis node.
	Gossiping state = iota
	// CatchingUp is the fast forward state
	CatchingUp
	// Shutdown is the shut down state
	Shutdown
	// Stop is the stop communicating state
	Stop
)
View Source
const (
	// MaxEventsPayloadSize is size limitation of txs in bytes.
	// TODO: collect the similar magic constants in protocol config.
	MaxEventsPayloadSize = 100 * 1024 * 1024
)

Variables

View Source
var (
	// ErrTooBigTx is returned when transaction size > MaxEventsPayloadSize
	ErrTooBigTx = fmt.Errorf("transaction too big")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	HeartbeatTimeout time.Duration `mapstructure:"heartbeat"`
	TCPTimeout       time.Duration `mapstructure:"timeout"`
	CacheSize        int           `mapstructure:"cache-size"`
	SyncLimit        int64         `mapstructure:"sync-limit"`
	Logger           *logrus.Logger
	TestDelay        uint64 `mapstructure:"test_delay"`
}

Config for node configuration settings

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig sets the default config for a node config

func NewConfig

func NewConfig(heartbeat time.Duration,
	timeout time.Duration,
	cacheSize int,
	syncLimit int64,
	logger *logrus.Logger) *Config

NewConfig creates a new node config

func TestConfig

func TestConfig(t testing.TB) *Config

TestConfig sets the test config for use with tests

type ControlTimer

type ControlTimer struct {
	Locker sync.RWMutex
	// contains filtered or unexported fields
}

ControlTimer struct that controls timing events in the node

func NewControlTimer

func NewControlTimer(timerFactory timerFactory) *ControlTimer

NewControlTimer creates a new control timer struct

func NewRandomControlTimer

func NewRandomControlTimer() *ControlTimer

NewRandomControlTimer creates a random time controller with no defaults set

func (*ControlTimer) GetSet

func (c *ControlTimer) GetSet() bool

GetSet retrieves the set

func (*ControlTimer) Run

func (c *ControlTimer) Run(init time.Duration)

Run handles all the time based events in the background

func (*ControlTimer) SetSet

func (c *ControlTimer) SetSet(v bool)

SetSet sets the set value for the set

func (*ControlTimer) Shutdown

func (c *ControlTimer) Shutdown()

Shutdown the control timer

type Core

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

Core struct that controls the consensus, transaction, and communication

func NewCore

func NewCore(id uint64, key *ecdsa.PrivateKey, participants *peers.Peers,
	store poset.Store, commitCh chan poset.Block, logger *logrus.Logger) *Core

NewCore creates a new core struct

func (*Core) AddBlockSignature

func (c *Core) AddBlockSignature(bs poset.BlockSignature)

AddBlockSignature add block signatures to the pending pool

func (*Core) AddInternalTransactions

func (c *Core) AddInternalTransactions(txs []*wire.InternalTransaction)

AddInternalTransactions add internal transactions to the pending pool

func (*Core) AddSelfEventBlock

func (c *Core) AddSelfEventBlock(otherHead poset.EventHash) error

AddSelfEventBlock adds an event block created by this node

func (*Core) AddTransactions

func (c *Core) AddTransactions(txs [][]byte) error

AddTransactions add transactions to the pending pool

func (*Core) Bootstrap

func (c *Core) Bootstrap() error

Bootstrap the poset with default values

func (*Core) EventDiff

func (c *Core) EventDiff(known map[uint64]int64) (events []poset.Event, err error)

EventDiff returns events that c knows about and are not in 'known'

func (*Core) FastForward

func (c *Core) FastForward(peer string, block poset.Block, frame poset.Frame) error

FastForward catch up to another peer if too far behind

func (*Core) FromWire

func (c *Core) FromWire(wireEvents []poset.WireEvent) ([]poset.Event, error)

FromWire converts wire events into event blocks (that were transported)

func (*Core) GetAnchorBlockWithFrame

func (c *Core) GetAnchorBlockWithFrame() (poset.Block, poset.Frame, error)

GetAnchorBlockWithFrame returns the current anchor block and their frame

func (*Core) GetBlockSignaturePoolCount

func (c *Core) GetBlockSignaturePoolCount() int64

GetBlockSignaturePoolCount returns the count of all pending block signatures

func (*Core) GetConsensusEvents

func (c *Core) GetConsensusEvents() poset.EventHashes

GetConsensusEvents get all known consensus events

func (*Core) GetConsensusEventsCount

func (c *Core) GetConsensusEventsCount() int64

GetConsensusEventsCount get the count of all known consensus events

func (*Core) GetConsensusTransactions

func (c *Core) GetConsensusTransactions() ([][]byte, error)

GetConsensusTransactions return all transactions that have reached finality

func (*Core) GetConsensusTransactionsCount

func (c *Core) GetConsensusTransactionsCount() uint64

GetConsensusTransactionsCount returns the count of transactions that are final

func (*Core) GetEventBlock

func (c *Core) GetEventBlock(hash poset.EventHash) (poset.Event, error)

GetEventBlock get a specific event block for the hash provided

func (*Core) GetEventBlockTransactions

func (c *Core) GetEventBlockTransactions(hash poset.EventHash) ([][]byte, error)

GetEventBlockTransactions get all transactions in an event block

func (*Core) GetHead

func (c *Core) GetHead() (poset.Event, error)

GetHead get the current latest event block head

func (*Core) GetInternalTransactionPoolCount

func (c *Core) GetInternalTransactionPoolCount() int64

GetInternalTransactionPoolCount returns the count of all pending internal transactions

func (*Core) GetLastBlockIndex

func (c *Core) GetLastBlockIndex() int64

GetLastBlockIndex returns the latest block index

func (*Core) GetLastCommittedRoundEventsCount

func (c *Core) GetLastCommittedRoundEventsCount() int

GetLastCommittedRoundEventsCount count of events in last round

func (*Core) GetLastConsensusRound

func (c *Core) GetLastConsensusRound() int64

GetLastConsensusRound returns the last consensus round known

func (*Core) GetPendingLoadedEvents

func (c *Core) GetPendingLoadedEvents() int64

GetPendingLoadedEvents returns all pending (but already stored) events

func (*Core) GetTransactionPoolCount

func (c *Core) GetTransactionPoolCount() int64

GetTransactionPoolCount returns the count of all pending transactions

func (*Core) GetUndeterminedEvents

func (c *Core) GetUndeterminedEvents() poset.EventHashes

GetUndeterminedEvents get all unconfirmed consensus events (pending)

func (*Core) Head

func (c *Core) Head() poset.EventHash

Head returns the current chain head for this core

func (*Core) Heights

func (c *Core) Heights() map[string]int64

Heights returns map with heights for each participant PubKeyHex

func (*Core) HeightsByID

func (c *Core) HeightsByID() map[uint64]int64

HeightsByID returns map with heights for each participant ID

func (*Core) HexID

func (c *Core) HexID() string

HexID returns the Hex representation of the public key

func (*Core) ID

func (c *Core) ID() uint64

ID returns the ID of this core

func (*Core) InDegrees

func (c *Core) InDegrees() map[string]int64

InDegrees returns all vertexes from other nodes that reference this top event block

func (*Core) InsertEvent

func (c *Core) InsertEvent(event poset.Event, setWireInfo bool) error

InsertEvent inserts an unknown event block

func (*Core) KnownEvents

func (c *Core) KnownEvents() map[uint64]int64

KnownEvents returns map of last known event blocks per participant.ID

func (*Core) OverSyncLimit

func (c *Core) OverSyncLimit(knownEvents map[uint64]int64, syncLimit int64) bool

OverSyncLimit checks if the unknown events is over the sync limit and if the node should catch up

func (*Core) PubKey

func (c *Core) PubKey() []byte

PubKey returns the public key of this core

func (*Core) RunConsensus

func (c *Core) RunConsensus() error

RunConsensus is the core consensus mechanism, this checks rounds/frames and creates blocks.

func (*Core) SetHeadAndHeight

func (c *Core) SetHeadAndHeight() error

SetHeadAndHeight calculates and sets the current head and height for the chain

func (*Core) SignAndInsertSelfEvent

func (c *Core) SignAndInsertSelfEvent(event poset.Event) error

SignAndInsertSelfEvent signs and inserts a self generated event block

func (*Core) SignBlock

func (c *Core) SignBlock(block poset.Block) (poset.BlockSignature, error)

SignBlock sign a block to register it as an anchor block

func (*Core) Sync

func (c *Core) Sync(peer *peers.Peer, unknownEvents []poset.WireEvent) error

Sync unknown events into our poset

func (*Core) ToWire

func (c *Core) ToWire(events []poset.Event) ([]poset.WireEvent, error)

ToWire converts event blocks into wire events (to be transported)

type FairPeerSelector

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

FairPeerSelector provides selection to prevent lazy node creation

func NewFairPeerSelector

func NewFairPeerSelector(participants *peers.Peers, args FairPeerSelectorCreationFnArgs) *FairPeerSelector

NewFairPeerSelector creates a new fair peer selection struct

func (*FairPeerSelector) Dismiss

func (ps *FairPeerSelector) Dismiss(peer string)

Indicate we are not in communication with a peer so it could be selected as a next peer

func (*FairPeerSelector) Engage

func (ps *FairPeerSelector) Engage(peer string)

Indicate we are in communication with a peer so it would be excluded from next peer selection

func (*FairPeerSelector) Next

func (ps *FairPeerSelector) Next() *peers.Peer

Next returns the next peer based on the work cost function selection

func (*FairPeerSelector) Peers

func (ps *FairPeerSelector) Peers() *peers.Peers

Peers returns all known peers

func (*FairPeerSelector) UpdateLast

func (ps *FairPeerSelector) UpdateLast(peer string)

UpdateLast sets the last peer communicated with (avoid double talk)

type FairPeerSelectorCreationFnArgs

type FairPeerSelectorCreationFnArgs struct {
	KPeerSize uint64
	LocalAddr string
}

FairPeerSelectorCreationFnArgs specifies which additional arguments are require to create a FairPeerSelector

type GetFlagTableFn

type GetFlagTableFn func() (map[string]int64, error)

GetFlagTableFn declares flag table function signature

type Graph

type Graph struct {
	*Node
}

Graph struct to represent the DAG

func NewGraph

func NewGraph(n *Node) *Graph

NewGraph creates a new DAG

func (*Graph) GetBlocks

func (g *Graph) GetBlocks() []poset.Block

GetBlocks returns all blocks in the DAG

func (*Graph) GetInfos

func (g *Graph) GetInfos() Infos

GetInfos returns the info subset for the DAG

func (*Graph) GetParticipantEvents

func (g *Graph) GetParticipantEvents() map[string]map[poset.EventHash]poset.Event

GetParticipantEvents returns all known events per participant

func (*Graph) GetRounds

func (g *Graph) GetRounds() []poset.RoundCreated

GetRounds returns the created rounds for the DAG

type Infos

type Infos struct {
	ParticipantEvents map[string]map[poset.EventHash]poset.Event
	Rounds            []poset.RoundCreated
	Blocks            []poset.Block
}

Infos struct for graph data (visualizer)

type Node

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

Node struct that keeps all high level node functions

func NewNode

func NewNode(conf *Config,
	id uint64,
	key *ecdsa.PrivateKey,
	participants *peers.Peers,
	store poset.Store,
	trans peer.SyncPeer,
	proxy proxy.AppProxy,
	selectorInitFunc SelectorCreationFn,
	selectorInitArgs SelectorCreationFnArgs,
	localAddr string) *Node

NewNode create a new node struct

func (*Node) EventDiff

func (n *Node) EventDiff(
	known map[uint64]int64) (events []poset.Event, err error)

EventDiff returns events that n knows about and are not in 'known'

func (*Node) GetBlock

func (n *Node) GetBlock(blockIndex int64) (poset.Block, error)

GetBlock returns the block for a given index

func (*Node) GetConsensusEvents

func (n *Node) GetConsensusEvents() poset.EventHashes

GetConsensusEvents returns all consensus events

func (*Node) GetConsensusTransactionsCount

func (n *Node) GetConsensusTransactionsCount() uint64

GetConsensusTransactionsCount get the count of finalized transactions

func (*Node) GetEventBlock

func (n *Node) GetEventBlock(event poset.EventHash) (poset.Event, error)

GetEventBlock returns a specific event block for the given hash

func (*Node) GetFrame

func (n *Node) GetFrame(i int64) (poset.Frame, error)

GetFrame returns the frame for a given index

func (*Node) GetKnownEvents

func (n *Node) GetKnownEvents() map[uint64]int64

GetKnownEvents returns all known events

func (*Node) GetLastBlockIndex

func (n *Node) GetLastBlockIndex() int64

GetLastBlockIndex returns the last block index

func (*Node) GetLastEventFrom

func (n *Node) GetLastEventFrom(participant string) (poset.EventHash, bool, error)

GetLastEventFrom returns the last event block for a specific participant

func (*Node) GetLastRound

func (n *Node) GetLastRound() int64

GetLastRound returns the last round

func (*Node) GetParticipants

func (n *Node) GetParticipants() (*peers.Peers, error)

GetParticipants returns all participants this node knows about

func (*Node) GetPendingLoadedEvents

func (n *Node) GetPendingLoadedEvents() int64

GetPendingLoadedEvents returns all the pending events

func (*Node) GetRoot

func (n *Node) GetRoot(rootIndex string) (poset.Root, error)

GetRoot returns the chain root for the frame

func (*Node) GetRound

func (n *Node) GetRound(roundIndex int64) (poset.RoundCreated, error)

GetRound returns the created round info for a given index

func (*Node) GetRoundClothos

func (n *Node) GetRoundClothos(roundIndex int64) poset.EventHashes

GetRoundClothos returns all clotho for a given round index

func (*Node) GetRoundEvents

func (n *Node) GetRoundEvents(roundIndex int64) int

GetRoundEvents returns all the round events for a given round index

func (*Node) GetStats

func (n *Node) GetStats() map[string]string

GetStats returns processing stats for the node

func (*Node) ID

func (n *Node) ID() uint64

ID shows the ID of the node

func (*Node) Init

func (n *Node) Init() error

Init initializes all the node processes

func (*Node) PushTx

func (n *Node) PushTx(tx []byte) error

PushTx push transactions into the pending pool

func (*Node) Register

func (n *Node) Register()

Register registers TODO

func (*Node) RoundClothos

func (n *Node) RoundClothos(i int64) poset.EventHashes

RoundClothos returns all clothos in a round

func (*Node) Run

func (n *Node) Run(gossip bool)

Run core run loop, takes care of all processes

func (*Node) RunAsync

func (n *Node) RunAsync(gossip bool)

RunAsync run the background processes asynchronously

func (*Node) Shutdown

func (n *Node) Shutdown()

Shutdown the node

func (*Node) Stop

func (n *Node) Stop()

Stop stops the node from gossiping

func (*Node) SyncRate

func (n *Node) SyncRate() float64

SyncRate returns the current synchronization (talking to over nodes) rate in ms

type NodeList

type NodeList map[*ecdsa.PrivateKey]*Node

NodeList is a list of connected nodes for tests purposes

func NewNodeList

func NewNodeList(count int, logger *logrus.Logger) NodeList

NewNodeList makes, fills and runs NodeList instance

func (NodeList) Keys

func (n NodeList) Keys() []*ecdsa.PrivateKey

Keys returns the all PrivateKeys slice

func (NodeList) StartRandTxStream

func (n NodeList) StartRandTxStream() (stop func())

StartRandTxStream sends random txs to nodes until stop() called

func (NodeList) Values

func (n NodeList) Values() []*Node

Values returns the all nodes slice

func (NodeList) WaitForBlock

func (n NodeList) WaitForBlock(target int64)

WaitForBlock waits until the target block has retrieved a state hash from the app

type PeerSelector

type PeerSelector interface {
	Peers() *peers.Peers
	UpdateLast(peer string)
	Next() *peers.Peer
	Engage(peer string)  // indicate we are in communication with that peer
	Dismiss(peer string) // indicate we are not in communication with that peer
}

PeerSelector provides an interface for the lachesis node to update the last peer it gossiped with and select the next peer to gossip with

func NewFairPeerSelectorWrapper

func NewFairPeerSelectorWrapper(participants *peers.Peers, args interface{}) PeerSelector

NewFairPeerSelectorWrapper implements SelectorCreationFn to allow dynamic creation of FairPeerSelector ie NewNode

func NewRandomPeerSelectorWrapper

func NewRandomPeerSelectorWrapper(participants *peers.Peers, args interface{}) PeerSelector

NewRandomPeerSelectorWrapper implements SelectorCreationFn to allow dynamic creation of RandomPeerSelector ie NewNode

func NewSmartPeerSelectorWrapper

func NewSmartPeerSelectorWrapper(participants *peers.Peers, args interface{}) PeerSelector

NewSmartPeerSelectorWrapper implements SelectorCreationFn to allow dynamic creation of SmartPeerSelector ie NewNode

type RandomPeerSelector

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

RandomPeerSelector is a randomized peer selection struct

func NewRandomPeerSelector

func NewRandomPeerSelector(participants *peers.Peers, args RandomPeerSelectorCreationFnArgs) *RandomPeerSelector

NewRandomPeerSelector creates a new random peer selector

func (*RandomPeerSelector) Dismiss

func (ps *RandomPeerSelector) Dismiss(peer string)

Indicate we are not in communication with a peer so it could be selected as a next peer

func (*RandomPeerSelector) Engage

func (ps *RandomPeerSelector) Engage(peer string)

Indicate we are in communication with a peer so it would be excluded from next peer selection

func (*RandomPeerSelector) Next

func (ps *RandomPeerSelector) Next() *peers.Peer

Next returns the next randomly selected peer(s) to communicate with

func (*RandomPeerSelector) Peers

func (ps *RandomPeerSelector) Peers() *peers.Peers

Peers returns all known peers

func (*RandomPeerSelector) UpdateLast

func (ps *RandomPeerSelector) UpdateLast(peer string)

UpdateLast sets the last peer communicated with (to avoid double talk)

type RandomPeerSelectorCreationFnArgs

type RandomPeerSelectorCreationFnArgs struct {
	LocalAddr string
}

RandomPeerSelectorCreationFnArgs arguments for RandomPeerSelector

type SelectorCreationFn

type SelectorCreationFn func(*peers.Peers, interface{}) PeerSelector

SelectorCreationFn declares the function signature to create variants of PeerSelector

type SelectorCreationFnArgs

type SelectorCreationFnArgs interface{}

SelectorCreationFnArgs specifies the union of possible arguments that can be extracted to create a variant of PeerSelector

type SmartPeerSelector

type SmartPeerSelector struct {
	GetFlagTable GetFlagTableFn
	// contains filtered or unexported fields
}

SmartPeerSelector provides selection based on FlagTable of a randomly chosen undermined event

func NewSmartPeerSelector

func NewSmartPeerSelector(participants *peers.Peers, args SmartPeerSelectorCreationFnArgs) *SmartPeerSelector

NewSmartPeerSelector creates a new smart peer selection struct

func (*SmartPeerSelector) Dismiss

func (ps *SmartPeerSelector) Dismiss(peer string)

Indicate we are not in communication with a peer so it could be selected as a next peer

func (*SmartPeerSelector) Engage

func (ps *SmartPeerSelector) Engage(peer string)

Indicate we are in communication with a peer so it would be excluded from next peer selection

func (*SmartPeerSelector) Next

func (ps *SmartPeerSelector) Next() *peers.Peer

Next returns the next peer based on the flag table cost function selection

func (*SmartPeerSelector) Peers

func (ps *SmartPeerSelector) Peers() *peers.Peers

Peers returns all known peers

func (*SmartPeerSelector) UpdateLast

func (ps *SmartPeerSelector) UpdateLast(peer string)

UpdateLast sets the last peer communicated with (avoid double talk)

type SmartPeerSelectorCreationFnArgs

type SmartPeerSelectorCreationFnArgs struct {
	GetFlagTable GetFlagTableFn
	LocalAddr    string
}

SmartPeerSelectorCreationFnArgs specifies which additional arguments are required to create a SmartPeerSelector

Jump to

Keyboard shortcuts

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