node

package
v0.0.0-...-50e3d47 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2019 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	HeartbeatTimeout time.Duration `mapstructure:"heartbeat"`
	TCPTimeout       time.Duration `mapstructure:"timeout"`
	JoinTimeout      time.Duration `mapstructure:"join_timeout"`
	CacheSize        int           `mapstructure:"cache-size"`
	SyncLimit        int           `mapstructure:"sync-limit"`
	EnableFastSync   bool          `mapstructure:"fast-sync"`
	Bootstrap        bool          `mapstructure:"bootstrap"`
	Logger           *logrus.Logger
}

Config is a Configuration Object Definition

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns a Default Config Object

func NewConfig

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

NewConfig eturns a new Config Object

func TestConfig

func TestConfig(t *testing.T) *Config

TestConfig returns a Preset Test Configuration

type ControlTimer

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

ControlTimer struct

func NewControlTimer

func NewControlTimer(timerFactory timerFactory) *ControlTimer

NewControlTimer is a ControlTimer factory method

func NewRandomControlTimer

func NewRandomControlTimer() *ControlTimer

NewRandomControlTimer is a ControlTimer factory method that produces a ControlTimer with a random timeout

func (*ControlTimer) Run

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

Run starts the Control Timer

func (*ControlTimer) Shutdown

func (c *ControlTimer) Shutdown()

Shutdown shuts down the ControlTimer

type Core

type Core struct {

	// Hash and Index of this instance's head Event
	Head string
	Seq  int

	// AcceptedRound is the first round at which the node's last JoinRequest
	// takes effect. A node will not create SelfEvents before reaching
	// AcceptedRound.Default -1.
	AcceptedRound int

	// RemovedRound is the round at which the node's last LeaveRequest takes
	// effect (if there is one). Default -1.
	RemovedRound int

	// TargetRound is the minimum Consensus Round that the node needs to reach.
	// It is useful to set this value to a joining peer's accepted-round to
	// prevent them from having to wait.
	TargetRound int
	// contains filtered or unexported fields
}

Core is the core Node object

func NewCore

func NewCore(
	validator *Validator,
	peers *peers.PeerSet,
	genesisPeers *peers.PeerSet,
	store hg.Store,
	proxyCommitCallback proxy.CommitCallback,
	logger *logrus.Logger) *Core

NewCore is a factory method that returns a new Core object

func (*Core) AddInternalTransaction

func (c *Core) AddInternalTransaction(tx hg.InternalTransaction) *JoinPromise

AddInternalTransaction adds an internal transaction

func (*Core) AddSelfEvent

func (c *Core) AddSelfEvent(otherHead string) error

AddSelfEvent adds a self event

func (*Core) AddTransactions

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

AddTransactions appends transactions to the transaction pool

func (*Core) Bootstrap

func (c *Core) Bootstrap() error

Bootstrap calls the Hashgraph Bootstrap

func (*Core) Busy

func (c *Core) Busy() bool

Busy returns a boolean that denotes whether there is incomplete processing

func (*Core) Commit

func (c *Core) Commit(block *hg.Block) error

Commit the Block to the App using the proxyCommitCallback

func (*Core) EventDiff

func (c *Core) EventDiff(known map[uint32]int) (events []*hg.Event, err error)

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

func (*Core) FastForward

func (c *Core) FastForward(block *hg.Block, frame *hg.Frame) error

FastForward is used whilst in catchingUp state to apply past blocks and frames

func (*Core) FromWire

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

FromWire takes Wire Events and returns Hashgraph Events

func (*Core) GetAnchorBlockWithFrame

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

GetAnchorBlockWithFrame returns GetAnchorBlockWithFrame from the hashgraph

func (*Core) GetConsensusEvents

func (c *Core) GetConsensusEvents() []string

GetConsensusEvents returns consensus events from the hashgragh store

func (*Core) GetConsensusEventsCount

func (c *Core) GetConsensusEventsCount() int

GetConsensusEventsCount returns the count of consensus events from the hashgragh store

func (*Core) GetConsensusTransactions

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

GetConsensusTransactions returns the transaction from the events returned by GetConsensusEvents()

func (*Core) GetConsensusTransactionsCount

func (c *Core) GetConsensusTransactionsCount() int

GetConsensusTransactionsCount return ConsensusTransacions from the hashgraph

func (*Core) GetEvent

func (c *Core) GetEvent(hash string) (*hg.Event, error)

GetEvent returns an event from the hashgrapg store

func (*Core) GetEventTransactions

func (c *Core) GetEventTransactions(hash string) ([][]byte, error)

GetEventTransactions returns the transactions for an event

func (*Core) GetHead

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

GetHead returns the head from the hashgraph store

func (*Core) GetLastBlockIndex

func (c *Core) GetLastBlockIndex() int

GetLastBlockIndex returns last block index from the hashgraph store

func (*Core) GetLastCommitedRoundEventsCount

func (c *Core) GetLastCommitedRoundEventsCount() int

GetLastCommitedRoundEventsCount returns LastCommitedRoundEvents from the hashgraph

func (*Core) GetLastConsensusRoundIndex

func (c *Core) GetLastConsensusRoundIndex() *int

GetLastConsensusRoundIndex returns the Last Consensus Round from the hashgraph

func (*Core) GetPendingLoadedEvents

func (c *Core) GetPendingLoadedEvents() int

GetPendingLoadedEvents returns pendign loading events from the hashgraph

func (*Core) GetUndeterminedEvents

func (c *Core) GetUndeterminedEvents() []string

GetUndeterminedEvents returns undetermined events from the hashgraph

func (*Core) InsertEventAndRunConsensus

func (c *Core) InsertEventAndRunConsensus(event *hg.Event, setWireInfo bool) error

InsertEventAndRunConsensus Inserts a hashgraph event and runs consensus

func (*Core) KnownEvents

func (c *Core) KnownEvents() map[uint32]int

KnownEvents returns known events from the Hashgraph store

func (*Core) Leave

func (c *Core) Leave(leaveTimeout time.Duration) error

Leave causes the node to leave the network

func (*Core) ProcessAcceptedInternalTransactions

func (c *Core) ProcessAcceptedInternalTransactions(roundReceived int, receipts []hg.InternalTransactionReceipt) error

ProcessAcceptedInternalTransactions processes the accepted internal transactions

func (*Core) ProcessSigPool

func (c *Core) ProcessSigPool() error

ProcessSigPool calls Hashgraph ProcessSigPool

func (*Core) RecordHeads

func (c *Core) RecordHeads() error

RecordHeads adds heads as SelfEvents

func (*Core) SetHeadAndSeq

func (c *Core) SetHeadAndSeq() error

SetHeadAndSeq sets the Head and Seq of a Core object

func (*Core) SetPeers

func (c *Core) SetPeers(ps *peers.PeerSet)

SetPeers sets the peers property and a New RandomPeerSelector

func (*Core) SignAndInsertSelfEvent

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

SignAndInsertSelfEvent signs a Hashgraph Event, inserts it and runs consensus

func (*Core) SignBlock

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

SignBlock signs the block

func (*Core) Sync

func (c *Core) Sync(fromID uint32, unknownEvents []hg.WireEvent) error

Sync decodes and inserts new Events into the Hashgraph. UnknownEvents are expected to be in topoligical order.

func (*Core) ToWire

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

ToWire takes Hashgraph Events and returns Wire Events

type Graph

type Graph struct {
	*Node
}

Graph is a struct containing a node

func NewGraph

func NewGraph(n *Node) *Graph

NewGraph is a factory method returning a Graph

func (*Graph) GetBlocks

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

GetBlocks returns an array of Blocks

func (*Graph) GetInfos

func (g *Graph) GetInfos() (Infos, error)

GetInfos returns an Infos struct

func (*Graph) GetParticipantEvents

func (g *Graph) GetParticipantEvents() (map[string]map[string]*hg.Event, error)

GetParticipantEvents returns Participant Events

func (*Graph) GetRounds

func (g *Graph) GetRounds() []*hg.RoundInfo

GetRounds returns an array of RoundInfo

type Infos

type Infos struct {
	ParticipantEvents map[string]map[string]*hg.Event
	Rounds            []*hg.RoundInfo
	Blocks            []*hg.Block
}

Infos is a struct providing Hashgraph information

type JoinPromise

type JoinPromise struct {
	Tx     hashgraph.InternalTransaction
	RespCh chan JoinPromiseResponse
}

JoinPromise is a struct for an asynchronous response to a Join Request

func NewJoinPromise

func NewJoinPromise(tx hashgraph.InternalTransaction) *JoinPromise

NewJoinPromise is a factory method for a JoinPromise

func (*JoinPromise) Respond

func (p *JoinPromise) Respond(accepted bool, acceptedRound int, peers []*peers.Peer)

Respond handles sending a JoinPromiseResponse to a JoinPromise

type JoinPromiseResponse

type JoinPromiseResponse struct {
	Accepted      bool
	AcceptedRound int
	Peers         []*peers.Peer
}

JoinPromiseResponse is a struct returned by a Join Promise

type Node

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

Node defines a huron node

func NewNode

func NewNode(conf *Config,
	validator *Validator,
	peers *peers.PeerSet,
	genesisPeers *peers.PeerSet,
	store hg.Store,
	trans net.Transport,
	proxy proxy.AppProxy,
) *Node

NewNode is a factory method that returns a Node instance

func (*Node) GetBlock

func (n *Node) GetBlock(blockIndex int) (*hg.Block, error)

GetBlock returns a block

func (*Node) GetGenesisPeers

func (n *Node) GetGenesisPeers() []*peers.Peer

GetGenesisPeers returns the genesis peers

func (*Node) GetID

func (n *Node) GetID() uint32

GetID returns the numeric ID of the node's validator

func (*Node) GetPeers

func (n *Node) GetPeers() []*peers.Peer

GetPeers returns the current peers

func (*Node) GetStats

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

GetStats returns information about the node.

func (*Node) Init

func (n *Node) Init() error

Init initialises the node based on its configuration. It controls the boostrap process which loads the hashgraph from an existing database (if bootstrap option is set in config). It also decides what state the node will start in (Babbling, CatchingUp, or Joining) based on the current validator-set and the value of the fast-sync option.

func (*Node) Leave

func (n *Node) Leave() error

Leave causes the node to politely leave the network via a LeaveRequest and wait for the node to be removed from the validator-list via consensus.

func (*Node) Run

func (n *Node) Run(gossip bool)

Run invokes the main loop of the node. The gossip parameter controls whether to actively participate in gossip or not.

func (*Node) RunAsync

func (n *Node) RunAsync(gossip bool)

RunAsync runs the node in a separate goroutine

func (*Node) Shutdown

func (n *Node) Shutdown()

Shutdown attempts to cleanly shutdown the node by waiting for pending work to be finished, stopping the control-timer, and closing the transport.

type PeerSelector

type PeerSelector interface {
	Peers() *peers.PeerSet
	UpdateLast(peer uint32)
	Next() *peers.Peer
}

PeerSelector defines and interface for Peer Selectors

type RandomPeerSelector

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

RandomPeerSelector defines a struct which controls the random selection of peers

func NewRandomPeerSelector

func NewRandomPeerSelector(peerSet *peers.PeerSet, selfID uint32) *RandomPeerSelector

NewRandomPeerSelector is a factory method that returns a new instance of RandomPeerSelector

func (*RandomPeerSelector) Next

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

Next returns the next peer

func (*RandomPeerSelector) Peers

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

Peers returns a set of peers

func (*RandomPeerSelector) UpdateLast

func (ps *RandomPeerSelector) UpdateLast(peer uint32)

UpdateLast sets the last peer

type State

type State uint32

State captures the state of a Huron node: Babbling, CatchingUp, Joining, or Shutdown

const (
	//Babbling is the initial state of a Huron node.
	Babbling State = iota
	//CatchingUp implements Fast Sync
	CatchingUp
	//Joining is joining
	Joining
	//Leaving is leaving
	Leaving
	//Shutdown is shutdown
	Shutdown
)

func (State) String

func (s State) String() string

String ...

type Validator

type Validator struct {
	Key     *ecdsa.PrivateKey
	Moniker string
	// contains filtered or unexported fields
}

Validator struct holds information about the validator for a node

func NewValidator

func NewValidator(key *ecdsa.PrivateKey, moniker string) *Validator

NewValidator is a factory method for a Validator

func (*Validator) ID

func (v *Validator) ID() uint32

ID returns an ID for the validator

func (*Validator) PublicKeyBytes

func (v *Validator) PublicKeyBytes() []byte

PublicKeyBytes returns the validator's public key as a byte array

func (*Validator) PublicKeyHex

func (v *Validator) PublicKeyHex() string

PublicKeyHex returns the validator's public key as a hex string

Jump to

Keyboard shortcuts

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