{"modulePath":"github.com/onflow/flow-go","version":"v0.51.2","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package optimistic_sync\n\n## Variables\n\n```go\nvar ErrInvalidTransition = errors.New(\"invalid state transition\")\n```\nErrInvalidTransition is returned when a state transition is invalid.\n\n```go\nvar ErrResultAbandoned = fmt.Errorf(\"result abandoned\")\n```\nErrResultAbandoned is returned when calling one of the methods after the result has been abandoned. Not exported because this is not an expected error condition.\n\n## Types\n\n```go\ntype Core interface {\n\t// Download retrieves all necessary data for processing from the network.\n\t// Download will block until the data is successfully downloaded, and has not internal timeout.\n\t// When Aboandon is called, the caller must cancel the context passed in to shutdown the operation\n\t// otherwise it may block indefinitely.\n\t//\n\t// Expected error returns during normal operation:\n\t// - [context.Canceled]: if the provided context was canceled before completion\n\tDownload(ctx context.Context) error\n\n\t// Index processes the downloaded data and stores it into in-memory indexes.\n\t// Must be called after Download.\n\t//\n\t// No error returns are expected during normal operations\n\tIndex() error\n\n\t// Persist stores the indexed data in permanent storage.\n\t// Must be called after Index.\n\t//\n\t// No error returns are expected during normal operations\n\tPersist() error\n\n\t// Abandon indicates that the protocol has abandoned this state. Hence processing will be aborted\n\t// and any data dropped.\n\t// This method will block until other in-progress operations are complete. If Download is in progress,\n\t// the caller should cancel its context to ensure the operation completes in a timely manner.\n\tAbandon()\n}\n```\n\\\u003ccomponent\\_spec\u003e Core defines the interface for pipelined execution result processing. There are 3 main steps which must be completed sequentially and exactly once. 1. Download the BlockExecutionData and TransactionResultErrorMessages for the execution result. 2. Index the downloaded data into mempools. 3. Persist the indexed data to into persisted storage.\n\nIf the protocol abandons the execution result, Abandon() is called to signal to the Core instance that processing will stop and any data accumulated may be discarded. Abandon() may be called at any time, but may block until in-progress operations are complete. \\\u003c/component\\_spec\u003e\n\nAll exported methods are safe for concurrent use.\n\n```go\ntype CoreFactory interface {\n\tNewCore(result *flow.ExecutionResult) Core\n}\n```\nCoreFactory is a factory object for creating new Core instances.\n\n```go\ntype Criteria struct {\n\t// AgreeingExecutorsCount is the number of receipts including the same ExecutionResult\n\tAgreeingExecutorsCount uint\n\t// RequiredExecutors is the list of EN node IDs, one of which must have produced the result\n\tRequiredExecutors flow.IdentifierList\n}\n```\nCriteria defines the filtering criteria for execution result queries. It specifies requirements for execution result selection including the number of agreeing executors and requires executor nodes.\n\n```go\nfunc (c *Criteria) OverrideWith(override Criteria) Criteria\n```\nOverrideWith overrides the original criteria with the incoming criteria, returning a new Criteria object. Fields from \\`override\\` criteria take precedence when set.\n\n```go\ntype ExecutionResultQueryProvider interface {\n\t// ExecutionResultQuery retrieves execution results and associated execution nodes for a given block ID\n\t// based on the provided criteria. It returns a Query containing the execution result and\n\t// the execution nodes that produced it.\n\t//\n\t// Expected errors during normal operations:\n\t//   - backend.InsufficientExecutionReceipts - found insufficient receipts for given block ID.\n\tExecutionResultQuery(blockID flow.Identifier, criteria Criteria) (*Query, error)\n}\n```\nExecutionResultQueryProvider provides execution results and execution nodes based on criteria. It allows querying for execution results by block ID with specific filtering criteria to ensure consistency and reliability of execution results.\n\n```go\ntype ExecutionStateCache interface {\n\t// Snapshot returns a view of the execution state as of the provided ExecutionResult.\n\t// The returned Snapshot provides access to execution state data for the fork ending\n\t// on the provided ExecutionResult which extends from the latest sealed result.\n\t// The result may be sealed or unsealed. Only data for finalized blocks is available.\n\t//\n\t// Expected errors during normal operation:\n\t//   - storage.ErrNotFound - result is not available, not ready for querying, or does not descend from the latest sealed result.\n\t//   - All other errors are potential indicators of bugs or corrupted internal state (continuation impossible)\n\tSnapshot(executionResultID flow.Identifier) (Snapshot, error)\n}\n```\nExecutionStateCache provides access to execution state snapshots for querying data at specific ExecutionResults.\n\n```go\ntype Pipeline interface {\n\tPipelineStateProvider\n\n\t// Run starts the pipeline processing and blocks until completion or context cancellation.\n\t// CAUTION: not concurrency safe! Run must only be called once.\n\t//\n\t// Expected Errors:\n\t//   - context.Canceled: when the context is canceled\n\t//   - All other errors are potential indicators of bugs or corrupted internal state (continuation impossible)\n\tRun(ctx context.Context, core Core, parentState State) error\n\n\t// SetSealed marks the pipeline's result as sealed, which enables transitioning from StateWaitingPersist to StatePersisting.\n\tSetSealed()\n\n\t// OnParentStateUpdated updates the pipeline's parent's state.\n\tOnParentStateUpdated(parentState State)\n\n\t// Abandon marks the pipeline as abandoned.\n\tAbandon()\n}\n```\nPipeline represents a processing pipelined state machine for a single ExecutionResult. The state machine is initialized in the Pending state.\n\nThe state machine is designed to be run in a single goroutine. The Run method must only be called once.\n\n```go\ntype PipelineFactory interface {\n\tNewPipeline(result *flow.ExecutionResult, isSealed bool) Pipeline\n}\n```\nPipelineFactory is a factory object for creating new Pipeline instances.\n\n```go\ntype PipelineStateConsumer interface {\n\t// OnStateUpdated is called when a pipeline's state changes to notify the receiver of the new state.\n\t// This method is will be called in the same goroutine that runs the pipeline, so it must not block.\n\tOnStateUpdated(newState State)\n}\n```\nPipelineStateConsumer is a receiver of the pipeline state updates. PipelineStateConsumer implementations must be - NON-BLOCKING and consume the state updates without noteworthy delay\n\n```go\ntype PipelineStateProvider interface {\n\t// GetState returns the current state of the pipeline.\n\tGetState() State\n}\n```\nPipelineStateProvider is an interface that provides a pipeline's state.\n\n```go\ntype Query struct {\n\t// ExecutionResult is the execution result for the queried block\n\tExecutionResult *flow.ExecutionResult\n\t// ExecutionNodes is the list of execution node identities that produced the result\n\tExecutionNodes flow.IdentitySkeletonList\n}\n```\nQuery contains the result of an execution result query. It includes both the execution result and the execution nodes that produced it.\n\n```go\ntype Snapshot interface {\n\t// Events returns a reader for querying event data.\n\tEvents() storage.EventsReader\n\n\t// Collections returns a reader for querying collection data.\n\tCollections() storage.CollectionsReader\n\n\t// Transactions returns a reader for querying transaction data.\n\tTransactions() storage.TransactionsReader\n\n\t// LightTransactionResults returns a reader for querying light transaction result data.\n\tLightTransactionResults() storage.LightTransactionResultsReader\n\n\t// TransactionResultErrorMessages returns a reader for querying transaction error message data.\n\tTransactionResultErrorMessages() storage.TransactionResultErrorMessagesReader\n\n\t// Registers returns a reader for querying register data.\n\tRegisters() storage.RegisterIndexReader\n}\n```\nSnapshot provides access to execution data readers for querying various data types from a specific ExecutionResult.\n\n```go\ntype State int32\n```\nState represents the state of the processing pipeline\n\n```go\nconst (\n\t// StatePending is the initial state after instantiation, before Run is called\n\tStatePending State = iota\n\t// StateProcessing represents the state where data processing (download and indexing) has been started\n\tStateProcessing\n\t// StateWaitingPersist represents the state where all data is indexed, but conditions to persist are not met\n\tStateWaitingPersist\n\t// StateComplete represents the state where all data is persisted to storage\n\tStateComplete\n\t// StateAbandoned represents the state where processing was aborted\n\tStateAbandoned\n)\n```\n\n```go\nfunc (s State) IsTerminal() bool\n```\nIsTerminal returns true if the state is a terminal state (Complete or Abandoned).\n\n```go\nfunc (s State) String() string\n```\nString representation of states for logging\n\n","path":"github.com/onflow/flow-go/module/executiondatasync/optimistic_sync","name":"optimistic_sync","synopsis":"","isRedistributable":true}
