node

package
v0.5.11 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2019 License: MIT Imports: 20 Imported by: 3

Documentation

Index

Constants

View Source
const WGLIMIT = 20

WGLIMIT is the maximum number of goroutines that can be launched through state.goFunc

Variables

This section is empty.

Functions

This section is empty.

Types

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 join request
	// (InternalTransaction) 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 leave request 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

	// LastPeerChangeRound is updated whenever a join / leave request is
	// accepted
	LastPeerChangeRound 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.Entry) *Core

NewCore is a factory method that returns a new Core object

func (*Core) AddInternalTransaction added in v0.5.0

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

AddInternalTransaction adds an InternalTransaction to the pool, and creates a corresponding promise.

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 added in v0.5.0

func (c *Core) Busy() bool

Busy returns a boolean that denotes whether there is incomplete processing

func (*Core) Commit added in v0.4.1

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

Commit the Block to the App using the proxyCommitCallback

func (*Core) EventDiff

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

EventDiff returns Events that we are aware of, and that are not known by another. They are returned in topological order. The parameter otherKnown is a map containing the last Event index per participant, as seen by another peer. We compare this to our view of events and return the diff.

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 added in v0.4.1

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 added in v0.5.0

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

Leave causes the node to politely leave the network. If the node is not alone, it submits an InternalTransaction to be removed from the validator-set. Otherwise it does nothing.

func (*Core) ProcessAcceptedInternalTransactions added in v0.5.0

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

ProcessAcceptedInternalTransactions processes the accepted internal transactions

func (*Core) ProcessSigPool added in v0.4.1

func (c *Core) ProcessSigPool() error

ProcessSigPool calls Hashgraph ProcessSigPool

func (*Core) RecordHeads added in v0.4.1

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 added in v0.5.0

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 added in v0.4.1

type Graph struct {
	*Node
}

Graph is a struct containing a node

func NewGraph added in v0.4.1

func NewGraph(n *Node) *Graph

NewGraph is a factory method returning a Graph

func (*Graph) GetBlocks added in v0.4.1

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

GetBlocks returns an array of Blocks

func (*Graph) GetInfos added in v0.4.1

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

GetInfos returns an Infos struct

func (*Graph) GetParticipantEvents added in v0.4.1

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

GetParticipantEvents returns Participant Events

func (*Graph) GetRounds added in v0.4.1

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

GetRounds returns an array of RoundInfo

type Infos added in v0.4.1

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 added in v0.5.0

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

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

func NewJoinPromise added in v0.5.0

func NewJoinPromise(tx hashgraph.InternalTransaction) *JoinPromise

NewJoinPromise is a factory method for a JoinPromise

func (*JoinPromise) Respond added in v0.5.0

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

Respond handles sending a JoinPromiseResponse to a JoinPromise

type JoinPromiseResponse added in v0.5.0

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

JoinPromiseResponse is a struct returned by a JoinPromise

type Node

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

Node defines a babble node

func NewNode

func NewNode(conf *config.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) GetAllValidatorSets added in v0.5.4

func (n *Node) GetAllValidatorSets() (map[int][]*peers.Peer, error)

GetAllValidatorSets returns the entire history of validator-sets

func (*Node) GetBlock

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

GetBlock returns a block

func (*Node) GetID added in v0.5.0

func (n *Node) GetID() uint32

GetID returns the numeric ID of the node's validator

func (*Node) GetLastBlockIndex added in v0.5.4

func (n *Node) GetLastBlockIndex() int

GetLastBlockIndex returns the index of the last known block

func (*Node) GetLastConsensusRoundIndex added in v0.5.4

func (n *Node) GetLastConsensusRoundIndex() int

GetLastConsensusRoundIndex returns the index of the last consensus round

func (*Node) GetPeers added in v0.4.1

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

GetPeers returns the current peers. Not necessarily equal to the current validator-set

func (*Node) GetStats

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

GetStats returns information about the node.

func (*Node) GetValidatorSet added in v0.5.4

func (n *Node) GetValidatorSet(round int) ([]*peers.Peer, error)

GetValidatorSet returns the validator-set associated to a round

func (*Node) Init

func (n *Node) Init() error

Init controls the bootstrap process and sets the node's initial state based on configuration (Babbling, CatchingUp, Joining, or Suspended).

func (*Node) Leave added in v0.5.0

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.

func (*Node) Suspend added in v0.5.11

func (n *Node) Suspend()

Suspend puts the node in Suspended mode. It doesn't close the transport because it needs to respond to incoming SyncRequests.

type PeerSelector

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

PeerSelector defines and interface for Peer Selectors

type PeerSelectorItem added in v0.5.4

type PeerSelectorItem struct {
	Peer      *peers.Peer
	Connected bool
}

PeerSelectorItem is a wrapper around a Peer that keeps track of the connection status

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 the current set of peers

func (*RandomPeerSelector) UpdateLast

func (ps *RandomPeerSelector) UpdateLast(peer uint32, connected bool) (newConnection bool)

UpdateLast sets the last peer and updates its connection status

type State added in v0.5.0

type State uint32

State captures the state of a Babble node: Babbling, CatchingUp, Joining, Leaving, Suspended, or Shutdown

const (
	//Babbling is the initial state of a Babble node.
	Babbling State = iota
	//CatchingUp implements Fast Sync
	CatchingUp
	//Joining is joining
	Joining
	//Leaving is leaving
	Leaving
	//Shutdown is shutdown
	Shutdown
	//Suspended is initialised, but not gossipping
	Suspended
)

func (State) String added in v0.5.0

func (s State) String() string

String ...

type Validator added in v0.5.0

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 added in v0.5.0

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

NewValidator is a factory method for a Validator

func (*Validator) ID added in v0.5.0

func (v *Validator) ID() uint32

ID returns an ID for the validator

func (*Validator) PublicKeyBytes added in v0.5.0

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

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

func (*Validator) PublicKeyHex added in v0.5.0

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