orderedsync

package
v0.10.2 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2025 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

package orderedsync is a general purpose extension that synchronizes data from systems where absolute order is guaranteed (e.g. blockchains, streaming services, or other event-based systems). Because Kwil's resolution system does not natively guarantee order (e.g. listeners can submit events in order: event1, event2, event 3, but they can be resolved in order: event2, event1, event3), chainsync is used to guarantee the order of events. It requires that all events for a single point in time be submitted in one resolution, and that they point to the last point in time which had events that were relevant. This effectively creates a linked list of resolutions that can be used to ensure that we do not process events out of order. When orderedsync is used, it creates a new namespace in the engine in which it stores all confirmed data. This makes all confirmed data (even if not all of its parent resolutions have not been confirmed) part of the network state. Within an end block, orderedsync will process all information that has not been confirmed and pass it to it's respective listener.

Index

Constants

View Source
const (
	// ExtensionName is the unique name of the extension.
	// It is used to register the resolution and to create a namespace
	// in the engine for the confirmed data.
	ExtensionName = "kwil_ordered_sync"
)

Variables

View Source
var Synchronizer = &cachedSync{
	topics: make(map[string]*topicInfo),
}

Synchronizer is the global instance of the ordered sync extension.

Functions

func RegisterResolveFunc

func RegisterResolveFunc(s string, resolveFn ResolveFunc)

RegisterResolveFunc registers a resolve function. It gives it a name which it can be identified by. It MUST be called in init.

Types

type ResolutionMessage

type ResolutionMessage struct {
	// Topic is the topic that the resolution is for.
	Topic string
	// PreviousPointInTime is the point in time that the resolution is for.
	// It is a pointer because it can be nil if this is the first resolution.
	PreviousPointInTime *int64
	// PointInTime is the point in time that the resolution is for.
	// It is used to order the resolutions.
	PointInTime int64
	// Data is the data that is being resolved.
	Data []byte
}

func (*ResolutionMessage) MarshalBinary

func (r *ResolutionMessage) MarshalBinary() ([]byte, error)

func (*ResolutionMessage) UnmarshalBinary

func (r *ResolutionMessage) UnmarshalBinary(data []byte) error

type ResolveFunc

type ResolveFunc func(ctx context.Context, app *common.App, block *common.BlockContext, res *ResolutionMessage) error

Jump to

Keyboard shortcuts

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