events

package
v0.7.3 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

package events is used to track events that need to be included in a Kwil block. It contains an event store that is outside of consensus. The event store's primary purpose is to store events that are heard from other chains, and delete them once the node can verify that their event vote has been included in a block.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeleteEvent

func DeleteEvent(ctx context.Context, db sql.Executor, id types.UUID) error

DeleteEvent deletes an event from the event store. It is idempotent. If the event does not exist, it will not return an error.

func GetEvents

func GetEvents(ctx context.Context, db sql.Executor) ([]*types.VotableEvent, error)

GetEvents gets all events in the event store.

func MarkReceived

func MarkReceived(ctx context.Context, db sql.Executor, id types.UUID) error

MarkReceived marks that an event has been received by the network, and should not be re-broadcasted.

Types

type DB

type DB interface {
	sql.ReadTxMaker
	sql.DB
}

DB is a database connection.

type EventStore

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

EventStore stores events from external sources. Kwil uses the event store to track received events, and ensure that they are broadcasted to the network. It follows an at-least-once semantic, and so each event body should be unique. Events can be added idempotently; calling StoreEvent for an event that has already been stored or processed will incur some computational overhead, but will not cause any issues.

func NewEventStore

func NewEventStore(ctx context.Context, writerDB DB) (*EventStore, error)

NewEventStore creates a new event store. It takes a database connection to write events to. WARNING: This connection cannot be the same connection used during consensus / in txapp.

func (*EventStore) GetUnreceivedEvents

func (e *EventStore) GetUnreceivedEvents(ctx context.Context) ([]*types.VotableEvent, error)

GetUnreceivedEvents retrieves events that are neither received by the network nor previously broadcasted. An event is considered "received" only after its inclusion in a block. The function excludes events that have been broadcasted but are still pending in the mempool, awaiting block inclusion. It uses the local connection to the event store, instead of the consensus connection.

func (*EventStore) KV

func (e *EventStore) KV(prefix []byte) *KV

KV returns a kv store that is scoped to the given prefix. It allows the user to define their own semantics for tracking committed data. For example, it can be used to track the latest block number of some other chain. This allows users to implement complex logic for efficient restart, to avoid re-processing events. Key uniqueness is scoped to the event type.

func (*EventStore) MarkBroadcasted

func (e *EventStore) MarkBroadcasted(ctx context.Context, ids []types.UUID) error

MarkBroadcasted marks the event as broadcasted.

func (*EventStore) MarkRebroadcast

func (e *EventStore) MarkRebroadcast(ctx context.Context, ids []types.UUID) error

MarkRebroadcast marks the event to be rebroadcasted. Usually in scenarios where the transaction was rejected by mempool due to invalid nonces.

func (*EventStore) Store

func (e *EventStore) Store(ctx context.Context, data []byte, eventType string) error

Store stores an event in the event store. It uses the local connection to the event store, instead of the consensus connection.

type KV

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

KV is a KVStore that is scoped to an event type.

func (*KV) Delete

func (s *KV) Delete(ctx context.Context, key []byte) error

func (*KV) Get

func (s *KV) Get(ctx context.Context, key []byte) ([]byte, error)

func (*KV) Set

func (s *KV) Set(ctx context.Context, key []byte, value []byte) error

type VoteStore

type VoteStore interface {
	// IsProcessed checks if a resolution has been processed.
	IsProcessed(ctx context.Context, db sql.DB, resolutionID types.UUID) (bool, error)
}

VoteStore is a store that tracks votes.

Directories

Path Synopsis
package broadcast contains logic for broadcasting events to the Kwil network
package broadcast contains logic for broadcasting events to the Kwil network

Jump to

Keyboard shortcuts

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