events

package
v0.2.13-beta.0 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2022 License: MIT Imports: 16 Imported by: 3

Documentation

Overview

Package events defines events published by go-spacemsh node using nodes pubsub

Index

Constants

View Source
const (
	LayerStatusTypeUnknown   = iota
	LayerStatusTypeApproved  // approved by Hare
	LayerStatusTypeConfirmed // confirmed by Tortoise
)

The status of a layer TODO: this list is woefully inadequate and does not map to reality. See https://github.com/spacemeshos/api/issues/144.

Variables

This section is empty.

Functions

func CloseEventPubSub added in v0.1.16

func CloseEventPubSub()

CloseEventPubSub closes events pubsub and destroys it.

func CloseEventReporter added in v0.1.15

func CloseEventReporter()

CloseEventReporter shuts down the event reporting service and closes open channels.

func EventHook added in v1.0.0

func EventHook() func(entry zapcore.Entry) error

EventHook returns hook for logger.

func InitializeEventPubsub

func InitializeEventPubsub(ur string) error

InitializeEventPubsub initializes the global pubsub broadcaster server.

func InitializeEventReporter added in v0.1.15

func InitializeEventReporter(url string) error

InitializeEventReporter initializes the event reporting interface.

func InitializeEventReporterWithOptions added in v0.1.15

func InitializeEventReporterWithOptions(url string) error

InitializeEventReporterWithOptions initializes the event reporting interface with a nonzero channel buffer. This is useful for testing, where we want reporting to block.

func Publish

func Publish(event Event)

Publish publishes an event on the pubsub singleton.

func ReportAccountUpdate added in v0.1.15

func ReportAccountUpdate(a types.Address)

ReportAccountUpdate reports an account whose data has been updated.

func ReportAtxCreated added in v0.1.15

func ReportAtxCreated(created bool, epoch uint32, id string)

ReportAtxCreated reports a created activation.

func ReportCalculatedBeacon

func ReportCalculatedBeacon(epoch types.EpochID, beacon string)

ReportCalculatedBeacon reports calculated beacon.

func ReportDoneCreatingProposal

func ReportDoneCreatingProposal(eligible bool, layer uint32, error string)

ReportDoneCreatingProposal reports a created block.

func ReportError added in v0.1.15

func ReportError(err NodeError)

ReportError reports an error.

func ReportLayerUpdate added in v1.0.0

func ReportLayerUpdate(layer LayerUpdate)

ReportLayerUpdate reports a new layer, or an update to an existing layer.

func ReportNewActivation added in v0.1.15

func ReportNewActivation(activation *types.ActivationTx)

ReportNewActivation reports a new activation.

func ReportNewBlock added in v0.1.15

func ReportNewBlock(b *types.Block)

ReportNewBlock reports a new block.

func ReportNewProposal

func ReportNewProposal(p *types.Proposal)

ReportNewProposal reports a new proposal.

func ReportNewTx added in v0.1.15

func ReportNewTx(layerID types.LayerID, tx *types.Transaction)

ReportNewTx dispatches incoming events to the reporter singleton.

func ReportNodeStatusUpdate added in v0.1.15

func ReportNodeStatusUpdate()

ReportNodeStatusUpdate reports an update to the node status. It just pings the listener to notify them that there is an update; the listener is responsible for fetching the new status details. This is because status contains disparate information coming from different services, and the listener already knows how to gather that information so there is no point in duplicating that logic here. Note: There is some overlap with channelLayer here, as a new latest or verified layer should be sent over that channel as well. However, that happens inside the Mesh, at the source. It doesn't currently happen here because the status update includes only a layer ID, not full layer data, and the Reporter currently has no way to retrieve full layer data.

func ReportReceipt added in v0.1.15

func ReportReceipt(r TxReceipt)

ReportReceipt reports creation or receipt of a new tx receipt.

func ReportRewardReceived added in v0.1.15

func ReportRewardReceived(r Reward)

ReportRewardReceived reports a new reward.

func ReportTxWithValidity added in v0.1.15

func ReportTxWithValidity(layerID types.LayerID, tx *types.Transaction, valid bool)

ReportTxWithValidity reports a tx along with whether it was just invalidated.

func ReportValidActivation added in v0.1.15

func ReportValidActivation(activation *types.ActivationTx, valid bool)

ReportValidActivation reports a valid activation.

func ReportValidTx added in v0.1.15

func ReportValidTx(tx *types.Transaction, valid bool)

ReportValidTx reports a valid transaction.

func SubscribeAccount added in v1.0.0

func SubscribeAccount() event.Subscription

SubscribeAccount subscribes to account data updates.

func SubscribeActivations added in v1.0.0

func SubscribeActivations() event.Subscription

SubscribeActivations subscribes to activations.

func SubscribeErrors added in v1.0.0

func SubscribeErrors() event.Subscription

SubscribeErrors subscribes to node errors.

func SubscribeLayers added in v1.0.0

func SubscribeLayers() event.Subscription

SubscribeLayers subscribes to all layer data.

func SubscribeReceipts

func SubscribeReceipts() event.Subscription

SubscribeReceipts subscribes to receipts.

func SubscribeRewards added in v1.0.0

func SubscribeRewards() event.Subscription

SubscribeRewards subscribes to rewards.

func SubscribeStatus added in v1.0.0

func SubscribeStatus() event.Subscription

SubscribeStatus subscribes to node status messages.

func SubscribeToLayers added in v0.1.15

func SubscribeToLayers(newLayerCh timesync.LayerTimer)

SubscribeToLayers is used to track and report automatically every time a new layer is reached.

func SubscribeTxs added in v1.0.0

func SubscribeTxs() event.Subscription

SubscribeTxs subscribes to new transactions.

Types

type Account added in v1.0.0

type Account struct {
	types.Address
}

Account wraps account address.

type ActivationTx added in v1.0.0

type ActivationTx struct {
	*types.ActivationTx
}

ActivationTx wraps *types.ActivationTx.

type AtxCreated

type AtxCreated struct {
	Created bool
	ID      string
	Epoch   uint32
}

AtxCreated signals this miner has created an activation transaction.

func (AtxCreated) GetChannel

func (AtxCreated) GetChannel() ChannelID

GetChannel gets the message type which means on which this message should be sent.

type BeaconCalculated

type BeaconCalculated struct {
	Epoch  types.EpochID
	Beacon string
}

BeaconCalculated signals this miner has calculated a beacon.

func (BeaconCalculated) GetChannel

func (BeaconCalculated) GetChannel() ChannelID

GetChannel gets the message type which means on which this message should be sent.

type ChannelID added in v0.1.11

type ChannelID byte

ChannelID is the ID on which subscribers must register in order to listen to messages on the channel.

const (
	EventNewBlock ChannelID = 1 + iota
	EventBlockValid
	EventNewAtx
	EventAtxValid
	EventNewTx
	EventTxValid
	EventRewardReceived
	EventCreatedBlock
	EventCreatedAtx
	EventCalculatedBeacon
	EventNewProposal
)

These consts are used as prefixes for different messages in pubsub.

type DoneCreatingProposal

type DoneCreatingProposal struct {
	Eligible bool
	Layer    uint32
	Error    string
}

DoneCreatingProposal signals that this miner has created a proposal.

func (DoneCreatingProposal) GetChannel

func (DoneCreatingProposal) GetChannel() ChannelID

GetChannel gets the message type which means on which this message should be sent.

type Event

type Event interface {
	// GetChannel returns the channel on which this message will be published.
	GetChannel() ChannelID
}

Event defines the interface that each message sent by the EventPublisher needs to implement for it to correctly be routed by topic.

type EventPublisher

type EventPublisher struct {
	*Publisher
}

EventPublisher is the struct that publishes events to subscribers by topics.

func NewEventPublisher

func NewEventPublisher(eventURL string) (*EventPublisher, error)

NewEventPublisher is a constructor for the event publisher, it received a url string in format of tcp://localhost:56565 to start listening for connections.

func (*EventPublisher) Close

func (p *EventPublisher) Close() error

Close closes the published internal socket.

func (*EventPublisher) PublishEvent

func (p *EventPublisher) PublishEvent(event Event) error

PublishEvent publishes the provided event on pubsub infra.

type EventReporter added in v0.1.15

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

EventReporter is the struct that receives incoming events and dispatches them.

type LayerUpdate added in v1.0.0

type LayerUpdate struct {
	LayerID types.LayerID
	Status  int
}

LayerUpdate packages up a layer with its status (which a layer does not ordinarily contain).

func (LayerUpdate) Field added in v1.0.0

func (nl LayerUpdate) Field() log.Field

Field returns a log field. Implements the LoggableField interface.

type NewAtx

type NewAtx struct {
	ID      string
	EpochID uint32
}

NewAtx signals that a new ATX has been received.

func (NewAtx) GetChannel

func (NewAtx) GetChannel() ChannelID

GetChannel gets the message type which means on which this message should be sent.

type NewBlock

type NewBlock struct {
	ID    string
	Layer uint32
}

NewBlock is sent when a new block is created by this miner.

func (NewBlock) GetChannel

func (NewBlock) GetChannel() ChannelID

GetChannel gets the message type which means on which this message should be sent.

type NewProposal

type NewProposal struct {
	ID    string
	Layer uint32
	Atx   string
}

NewProposal is sent when a new proposal is created by this miner.

func (NewProposal) GetChannel

func (NewProposal) GetChannel() ChannelID

GetChannel gets the message type which means on which this message should be sent.

type NewTx

type NewTx struct {
	ID          string
	Origin      string
	Destination string
	Amount      uint64
	Fee         uint64
}

NewTx signals that a new transaction has been received and not yet validated.

func (NewTx) GetChannel

func (NewTx) GetChannel() ChannelID

GetChannel gets the message type which means on which this message should be sent.

type NodeError added in v0.1.15

type NodeError struct {
	Msg   string
	Trace string
	Level zapcore.Level
}

NodeError represents an internal error to be reported.

type Publisher

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

Publisher is a wrapper for mangos pubsub publisher socket.

func (*Publisher) Close added in v0.1.16

func (p *Publisher) Close()

Close closes the publishers output socket.

type Reward added in v0.1.15

type Reward struct {
	Layer       types.LayerID
	Total       uint64
	LayerReward uint64
	Coinbase    types.Address
	// TODO: We don't currently have a way to get the Layer Computed.
	// See https://github.com/spacemeshos/go-spacemesh/issues/2275
	// LayerComputed
	Smesher types.NodeID
}

Reward represents a reward object with extra data needed by the API.

type RewardReceived

type RewardReceived struct {
	Coinbase  string
	Amount    uint64
	SmesherID []byte
}

RewardReceived signals reward has been received.

func (RewardReceived) GetChannel

func (RewardReceived) GetChannel() ChannelID

GetChannel gets the message type which means on which this message should be sent.

type Status added in v1.0.0

type Status struct{}

Status indicates status change event.

type Subscriber

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

Subscriber defines the struct of the receiving end of the pubsub messages.

func NewSubscriber

func NewSubscriber(url string) (*Subscriber, error)

NewSubscriber received url string as input on which it will register to receive messages passed by server.

func (*Subscriber) Close

func (sub *Subscriber) Close() error

Close closes the socket which in turn will Close the listener func.

func (*Subscriber) StartListening

func (sub *Subscriber) StartListening()

StartListening runs in a go routine and listens to all channels this subscriber is registered to. it then passes the messages received to the appropriate reader channel.

func (*Subscriber) Subscribe

func (sub *Subscriber) Subscribe(topic ChannelID) (chan []byte, error)

Subscribe subscribes to the given topic, returns a channel on which data from the topic is received.

func (*Subscriber) SubscribeToAll

func (sub *Subscriber) SubscribeToAll() (chan []byte, error)

SubscribeToAll subscribes to all available topics.

type Transaction added in v1.0.0

type Transaction struct {
	Transaction *types.Transaction
	LayerID     types.LayerID
	Valid       bool
}

Transaction wraps a tx with its layer ID and validity info.

type TxReceipt added in v0.1.15

type TxReceipt struct {
	ID      types.TransactionID
	Result  int
	GasUsed uint64
	Fee     uint64
	Layer   types.LayerID
	Index   uint32
	Address types.Address
}

TxReceipt represents a transaction receipt.

type ValidAtx

type ValidAtx struct {
	ID    string
	Valid bool
}

ValidAtx signals that an activation transaction with id ID has been validated.

func (ValidAtx) GetChannel

func (ValidAtx) GetChannel() ChannelID

GetChannel gets the message type which means on which this message should be sent.

type ValidBlock

type ValidBlock struct {
	ID    string
	Valid bool
}

ValidBlock signals that block with id ID has been validated.

func (ValidBlock) GetChannel

func (ValidBlock) GetChannel() ChannelID

GetChannel gets the message type which means on which this message should be sent.

type ValidTx

type ValidTx struct {
	ID    string
	Valid bool
}

ValidTx signals that the transaction with id ID has been validated.

func (ValidTx) GetChannel

func (ValidTx) GetChannel() ChannelID

GetChannel gets the message type which means on which this message should be sent.

Jump to

Keyboard shortcuts

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