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 ¶
- func DeleteEvent(ctx context.Context, db sql.Executor, id types.UUID) error
- func GetEvents(ctx context.Context, db sql.Executor) ([]*types.VotableEvent, error)
- func MarkReceived(ctx context.Context, db sql.Executor, id types.UUID) error
- type DB
- type EventStore
- func (e *EventStore) GetUnreceivedEvents(ctx context.Context) ([]*types.VotableEvent, error)
- func (e *EventStore) KV(prefix []byte) *KV
- func (e *EventStore) MarkBroadcasted(ctx context.Context, ids []types.UUID) error
- func (e *EventStore) MarkRebroadcast(ctx context.Context, ids []types.UUID) error
- func (e *EventStore) Store(ctx context.Context, data []byte, eventType string) error
- type KV
- type VoteStore
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeleteEvent ¶
DeleteEvent deletes an event from the event store. It is idempotent. If the event does not exist, it will not return an error.
Types ¶
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 ¶
MarkBroadcasted marks the event as broadcasted.
func (*EventStore) MarkRebroadcast ¶
MarkRebroadcast marks the event to be rebroadcasted. Usually in scenarios where the transaction was rejected by mempool due to invalid nonces.