Documentation
¶
Index ¶
- Constants
- type BlockForgedEvent
- type ChainsyncResyncEvent
- type EpochNonceReadyEvent
- type EpochTransitionEvent
- type Event
- type EventBus
- func (e *EventBus) Close()
- func (e *EventBus) HasSubscribers(eventType EventType) bool
- func (e *EventBus) Publish(eventType EventType, evt Event)
- func (e *EventBus) PublishAsync(eventType EventType, evt Event) bool
- func (e *EventBus) RegisterSubscriber(eventType EventType, sub Subscriber) EventSubscriberId
- func (e *EventBus) Stop()
- func (e *EventBus) Subscribe(eventType EventType) (EventSubscriberId, <-chan Event)
- func (e *EventBus) SubscribeFunc(eventType EventType, handlerFunc EventHandlerFunc) EventSubscriberId
- func (e *EventBus) Unsubscribe(eventType EventType, subId EventSubscriberId)
- type EventHandlerFunc
- type EventSubscriberId
- type EventType
- type HardForkEvent
- type Subscriber
Constants ¶
const ( EventQueueSize = 10000 AsyncQueueSize = 1000 AsyncWorkerPoolSize = 4 RemoteDeliverTimeout = 5 * time.Second )
const BlockForgedEventType = EventType("block.forged")
BlockForgedEventType is the event type for locally forged blocks
const ChainsyncResyncEventType = EventType("chainsync.resync")
ChainsyncResyncEventType is the event type emitted when a chainsync re-sync is required (e.g. persistent fork detected or rollback exceeds the security parameter).
const EpochNonceReadyEventType = EventType("epoch.nonce_ready")
EpochNonceReadyEventType is emitted once the current epoch has advanced past the randomness stabilisation cutoff, which means the next epoch's nonce is now stable and its leader schedule can be precomputed.
const EpochTransitionEventType = EventType("epoch.transition")
EpochTransitionEventType is the event type for epoch transitions
const HardForkEventType = EventType("hardfork.transition")
HardForkEventType is the event type for hard fork (era transition) events
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BlockForgedEvent ¶ added in v0.22.0
type BlockForgedEvent struct {
// Slot is the slot number where the block was forged
Slot uint64
// BlockNumber is the block height in the chain
BlockNumber uint64
// BlockHash is the hash of the forged block
BlockHash []byte
// TxCount is the number of transactions included in the block
TxCount uint
// BlockSize is the size of the block in bytes
BlockSize uint
// Timestamp is when the block was forged
Timestamp time.Time
}
BlockForgedEvent is emitted when the node successfully forges a new block. This event is published after the block has been added to the local chain via chain.AddBlock(), which triggers automatic propagation to connected peers.
type ChainsyncResyncEvent ¶ added in v0.22.0
type ChainsyncResyncEvent struct {
ConnectionId ouroboros.ConnectionId
Reason string
}
ChainsyncResyncEvent carries the connection ID that should be re-synced.
type EpochNonceReadyEvent ¶ added in v0.27.3
EpochNonceReadyEvent signals that the next epoch's nonce is stable.
type EpochTransitionEvent ¶ added in v0.22.0
type EpochTransitionEvent struct {
PreviousEpoch uint64
NewEpoch uint64
BoundarySlot uint64
EpochNonce []byte
ProtocolVersion uint
// SnapshotSlot is the slot at which snapshot should be taken (typically boundary - 1)
SnapshotSlot uint64
}
EpochTransitionEvent is emitted when the chain crosses an epoch boundary
type EventBus ¶
func NewEventBus ¶
func NewEventBus( promRegistry prometheus.Registerer, logger *slog.Logger, ) *EventBus
NewEventBus creates a new EventBus with async worker pool
func (*EventBus) Close ¶ added in v0.27.2
func (e *EventBus) Close()
Close permanently shuts down the EventBus and its worker pool. Unlike Stop, Close does not restart async workers, so the EventBus cannot be reused.
func (*EventBus) HasSubscribers ¶ added in v0.25.1
func (*EventBus) Publish ¶
Publish allows a producer to send an event of a particular type to all subscribers
func (*EventBus) PublishAsync ¶ added in v0.21.0
PublishAsync enqueues an event for asynchronous delivery to all subscribers. This method returns immediately without blocking on subscriber delivery. Use this for non-critical events where immediate delivery is not required. Returns false if the EventBus is stopped, closed, or the async queue is full.
func (*EventBus) RegisterSubscriber ¶ added in v0.18.0
func (e *EventBus) RegisterSubscriber( eventType EventType, sub Subscriber, ) EventSubscriberId
RegisterSubscriber allows external adapters (e.g., network-backed subscribers) to register with the EventBus. It returns the assigned subscriber id. Returns 0 if the EventBus is stopped or closed.
func (*EventBus) Stop ¶ added in v0.18.0
func (e *EventBus) Stop()
Stop closes all subscriber channels and clears the subscribers map. This ensures that SubscribeFunc goroutines exit cleanly during shutdown. The EventBus can still be reused after Stop() is called.
func (*EventBus) Subscribe ¶
func (e *EventBus) Subscribe( eventType EventType, ) (EventSubscriberId, <-chan Event)
Subscribe allows a consumer to receive events of a particular type via a channel. Returns (0, nil) if the EventBus is stopped or closed.
func (*EventBus) SubscribeFunc ¶
func (e *EventBus) SubscribeFunc( eventType EventType, handlerFunc EventHandlerFunc, ) EventSubscriberId
SubscribeFunc allows a consumer to receive events of a particular type via a callback function. Returns 0 if the EventBus is stopped or closed.
func (*EventBus) Unsubscribe ¶
func (e *EventBus) Unsubscribe(eventType EventType, subId EventSubscriberId)
Unsubscribe stops delivery of events for a particular type for an existing subscriber
type EventHandlerFunc ¶
type EventHandlerFunc func(Event)
type EventSubscriberId ¶
type EventSubscriberId int
type HardForkEvent ¶ added in v0.22.0
type HardForkEvent struct {
// Slot is the slot at which the hard fork takes effect
Slot uint64
// EpochNo is the epoch number where the hard fork occurs
EpochNo uint64
// FromEra is the era ID before the hard fork
FromEra uint
// ToEra is the era ID after the hard fork
ToEra uint
// OldMajorVersion is the protocol major version before
OldMajorVersion uint
// OldMinorVersion is the protocol minor version before
OldMinorVersion uint
// NewMajorVersion is the protocol major version after
NewMajorVersion uint
// NewMinorVersion is the protocol minor version after
NewMinorVersion uint
}
HardForkEvent is emitted when a hard fork (era transition) occurs at an epoch boundary due to a protocol version change
type Subscriber ¶ added in v0.18.0
Subscriber is a delivery abstraction that allows the EventBus to deliver events to in-memory channels and to network-backed subscribers via the same interface. Implementations must ensure Close() is idempotent and safe to call multiple times.