Expand description
Best-effort execution framework for offchain routines with explicit logging and storage semantics.
In FRAME, most logic is executed via dispatchable extrinsics or inherents, both of which execute transactionally and revert on failure.
Offchain workers operate outside that model: they run asynchronously, without rollback, and with only best-effort guarantees.
This module introduces routines as a structured way to write such logic, where each routine is context-driven and multiple routines can be composed and executed under best-effort guarantees.
§What routines provide
- A disciplined execution model via
Routines - Per-routine semantics, including authorization through
RoutineOfand domain-specific error policies - Composability, allowing multiple routines to run independently under best-effort guarantees
Unlike extrinsics, routines are not atomic. Failures are local and do not prevent other routines from executing.
§Logging over rollback
In the absence of transactional guarantees, routines rely on Logging:
- errors are recorded and returned, not used to revert execution
- observability replaces rollback as the primary debugging mechanism
§Storage as execution semantics
Routines can integrate with KeyValueStore abstractions backed by
offchain storage models such as Persistent, ForkAware, and Finalized.
These make fork behavior explicit and allow safe state handling across re-orgs and repeated execution.
§Summary
Routines provide a structured, context-aware model for offchain execution:
- best-effort instead of transactional
- logging-driven instead of rollback-driven
- explicit in both execution and storage semantics
Structs§
- Finalized
- Marker type for finality-aware offchain storage, combining fork-aware and persistent state to derive confidence-graded values via routine-defined policies and observations.
- Fork
Aware - Marker type for fork-aware offchain storage, enabling re-org-sensitive, fork-scoped state with routine-defined error and logging semantics.
- Fork
Local Depot - Fork-local storage scope for
ForksHandlerimplementingForkScopes. - Ledger
- Persistent observation ledger used by
Finalizedstorage. - Observation
- Persistent observation record for a value managed by
Finalizedstorage. - Persistent
- Marker type for persistent offchain storage, providing fork-independent, non-reverting state with routine-defined error and logging semantics.
- Value
Hash - Stable, fork-independent identifier for values managed by
Finalizedstorage.
Enums§
- Confidence
- Confidence signal derived for a value evaluated by
Finalizedstorage. - LogLevel
- Represents log severity levels.
Traits§
- Finalized
Offchain Storage Error - Defines caller-facing error signals specific to
Finalizedstorage. - Finalized
Policy - Defines a finality evaluation policy for values managed by
Finalizedstorage. - KeyValue
Store - Trait for a simple key-value storage with integrated logging.
- Logging
- Trait for structured logging in detached, asynchronous routines.
- Offchain
Storage Error - Defines how offchain storage failures are reported to callers.
- Routine
Of - Authorization interface for a
Routines. - Routines
- Structured execution interface for offchain routines.
- Substrate
Offchain Storage - Marker trait for Substrate offchain storage kinds (backends).
Type Aliases§
- Confidence
Map 🔒 - LogFormatter
- Defines the function signature that can be passed to the logging system to customize how log messages are formatted.
- Moment
- Wall-clock timestamp type used by
Finalizedstorage.