Crate pallet_schemas

source ·
Expand description

Schema Management for Message and Stateful Storage

Schemas Pallet

The Schemas Pallet provides universal schema registration for data flowing through Frequency.

Summary

This pallet provides an on chain repository for schemas, thereby allowing participants of the network to flexibly interact and exchange messages with each other with the correct human intent and data structure. All Messages and Stateful Storage content must be attached to a Schema Identifier so that the content can be correctly parsed and interpreted.

Data Structure vs Human Intent

Schemas provide for both consistent data structures, but also human intent of the message. Some schemas may be structurally the same, but have a different interpretation of the contents. For example, two schemas might both only have a hash for contents, but one is a recording of the hash for time validation purposes, while the other is to mark an off-chain vote.

Schema Parameters

  • Model: The actual JSON representing the data structure.
  • Model Type: The type of serialization used. (Parquet, Avro, etc…)
  • Settings: Various options for the Schema like signature requirements.
  • Payload Location: The location the data for this Schema is stored.
Model Types
  • Parquet: Designed for lists and when a Provider is collecting items from many different MSAs and publishing them together.
  • AvroBinary: Useful for most generic data structures.
Settings
  • AppendOnly
    • Prior data is immutable and all new data is appended to existing data.
    • For Payload Locations: Itemized
  • SignatureRequired
    • An MSA control key signature is required instead of a delegation.
    • For Payload Locations: Itemized or Paginated
Payload Locations
  • OnChain: Data is stored directly in the Messages pallet data storage, usually as AvroBinary.
  • IPFS: Data is stored in IPFS and Messages pallet stores the CID.
  • Itemized: Data is stored in the Stateful Storage pallet as an array of individual items.
  • Paginated: Data is stored in the Stateful Storage pallet as a list of paged blobs.

Mainnet vs Testnet Schema Creation

Mainnet schemas must be approved by the Frequency Council. This is to prevent malicious schemas and increase the documentation around the schemas available.

On Testnets, schemas can be created by anyone, so there are no guarantees around schema correctness or quality. If you want to use a particular schema on a testnet, it is suggested that you use specific Schema Ids or publish the needed schema yourself.

Actions

The Schemas pallet provides for:

  • Registering or proposing new Schemas.
  • Retrieving schemas by their Id or name.
  • Validating a Schema model.
  • Retrieving last registered Schema Id.

Interactions

Extrinsics

Name/DescriptionCallerPaymentKey EventsRuntime Added
set_max_schema_model_bytes
Governance action to alter the maximum byte length of Schema models
GovernanceTokensSchemaMaxSizeChanged1
propose_to_create_schema_v2
Creates a proposal to the Frequency Council for a new schema
Token AccountTokensProposed66
create_schema_via_governance_v2
Governance action version of create_schema_v3
Frequency CouncilTokensSchemaCreated66
create_schema_v3
Creates a new Schema.
Mainnet: Governance
Testnet: Token Account
TokensSchemaCreated1
propose_to_create_schema_name
Creates a Council proposal to set the name of a Schema
Token AccountTokensProposed1
create_schema_name_via_governance
Governance action to set the name of a Schema
Frequency CouncilTokensSchemaNameCreated66

See Rust Docs for more details.

State Queries

NameDescriptionQueryRuntime Added
Get Max Current Schema IdentifierFetch current Schema Identifier maximumcurrentSchemaIdentifierMaximum1
Get Schema Model Max BytesFetch maximum number of bytes per Schema Model as set by GovernancegovernanceSchemaModelMaxBytes1
Get a Schema InfoFetch the metadata and settings for a schemaschemaInfos62
Get Schema Ids by NameFetch matching Schemas Ids by namespace and nameschemaNameToIds62
Get Schema Payload/ModelFetch the payload/model JSON for the specified SchemaschemaPayloads62

See the Rust Docs for additional state queries and details.

RPCs

Note: May be restricted based on node settings and configuration.

NameDescriptionCallNode Version
Get Schema by IdRetrieves the schema for the given Schema IdgetBySchemaIdv1.0.0+
Check Schema ValidityValidates a schema model and returns “true” if the model is correctcheckSchemaValidityv1.0.0+
Get Schema VersionsReturns an array of schema versionsgetVersionsv1.10.0+

* Must be enabled with off-chain indexing

See Rust Docs for more details.

Implementations

  • SchemaValidator: Functions for accessing and validating Schemas. This implementation is what is used in the runtime.
  • SchemaProvider: Allows another pallet to resolve schema information.

Re-exports

Modules

  • migration module
  • The pallet module in each FRAME pallet hosts the most important items needed to construct this pallet.
  • Autogenerated weights for pallet_schemas

Structs

  • Genesis Schemas need a way to load up and this is it!
  • A structure defining a Schema information (excluding the payload)
  • A structure defining name of a schema
  • A structure defining name of a schema

Constants

Type Aliases