Skip to content

Instantly share code, notes, and snippets.

@stwiname
Created September 28, 2023 22:29
Show Gist options
  • Save stwiname/6bbc8f31218f1f8718e1fe0ea1e2729a to your computer and use it in GitHub Desktop.
Save stwiname/6bbc8f31218f1f8718e1fe0ea1e2729a to your computer and use it in GitHub Desktop.

SubQuery V3 Release

V3.0.0 of SubQuery is a large release with a lot of new features. Although there are no breaking changes we felt that there was a large enough improvement to justify a major version bump. To use these new features please make sure to use the latest versions of the SubQuery dependencies in your project.

Project Upgrades

This allows users to upgrade projects at specific heights. This is useful with the network where there is currently no way to update a project if the contracts need updating or the chain has upgrades.

Documentation

Typescript based manifest

As the project manifest gets more complex when we add more features it gets very hard to know how to write. It's now possible to write your manifest in typescript. This means that you get a fully typed project manifest with documentation and examples in your editor.

import { SubstrateDatasourceKind, SubstrateHandlerKind, SubstrateProject } from "@subql/types";

// Can expand the Datasource processor types via the genreic param
const project: SubstrateProject = {
    specVersion: "1.0.0",
    version: '1.0.0',
    runner: {
      node: {
        name: '@subql/node',
        version: "*",
      },
      query: {
        name: '@subql/query',
        version: "*"
      },
    },
    schema: {
      file: './schema.graphql'
    },
    network: {
      chainId: '0x91b171bb158e2d3848fa23a9f1c25182fb8e20313b2c1eb49219da7a70ce90c3',
      bypassBlocks: [5, '1-10'],
      endpoint: 'wss://polkadot.api.onfinality.io/public-ws'
    },
    dataSources: [
      {
        kind: SubstrateDatasourceKind.Runtime,
        startBlock: 1,
        mapping: {
          file: './dist/index.js',
          handlers: [
            {
              kind: SubstrateHandlerKind.Block,
              handler: 'handleBlock',
              filter: {
                modulo: 5,
              }
            },
            {
              kind: SubstrateHandlerKind.Call,
              handler: 'handleCall',
              filter: {
                module: 'balances',
                method: 'Deposit',
                success: true,
              }
            },
            {
              kind: SubstrateHandlerKind.Event,
              handler: 'handleEvent',
              filter: {
                module: 'balances',
                method: 'Deposit',
              }
            }
          ]
        }
      }
    ],
}

export default project;

// TODO docs

skipTransactions

Ethereum and Substrate support this new option that can be specified in your manifest. If the project only has event handlers and data from transactions/extrinsics isn't used within the handlers then this option can be used to speed up indexing, reduce RPC requests and memory usage. Other SDKs will get this feature in the future.

Documentation

You can update your handlers to use the new types if you have this setting enabled:

Ethereum

Before:

async function handleTransfer(event: TransferLog): Promise<void> {
  ...
}

After:

async function handleTransfer(event: LightTransferLog): Promise<void> {
  ...
}

Substrate

Before:

async function handleTransfer(event: SubstrateEvent): Promise<void> {
  ...
}

After:

async function handleTransfer(event: LightSubstrateEvent): Promise<void> {
  ...
}

Reworked POI

Proof-of-indexing has been rebuilt to be much simpler. It has removed the Merkle Mountain Range dependency and data. POI should now be much more reliable and less buggy. When you first upgrade to 3.0 a migration step will be made to existing projects using the old POI. If the project used a file based MMR you can manually delete these files once the upgrade is complete.

Updated Store Methods

A long requested feature has been to query data by multiple fields from within mapping handlers. There is now a getByFields method to do this. See the documentation for more details.

Documentation

Improved Codegen for Cosmos

Like with the Ethereum SDK we will now generate more specific types for messages. These types are generated from the chain types protobufs as well as for Cosmwasm contracts.

Protobuf Documentation

Cosmwasm Documentation

Other improvements

  • Improved load balancing amongst workers
  • Faster block fetching. Rather than fetching in batches they are now fetched with a moving window
  • When multiple RPC endpoints are provided if one of them fails on startup it won't stop the indexer from starting
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment