or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Do you want to remove this version name and description?
Syncing
xxxxxxxxxx
Substreams in subgraphs
GIP: XXX
Title: Substreams as a Subgraph
Authors:
Created: <The date the GIP was created.>
Updated: <The date the GIP was last updated.>
Stage: Draft
Abstract
Substreams are a new streaming-first blockchain indexing technology developed for The Graph Network, focused on performance and composability.
A substreams package is a collection of interdependent modules, which combine to extract and transform blockchain events in a highly configurable and parallelisable way, producing a streaming output.
This GIP describes the simplest possible integration of Substreams with Subgraphs, to take that final streaming output and make it persistent and queryable.
Motivation
Adding Substream support to Graph Node is the fastest way to bring the performance and composability benefits of substreams to The Graph Network.
High Level Description
This introduces a new
substreams
"kind" of dataSource. This dataSource is identified on thesubgraph.yaml
by a name and a filepath. This filepath will point locally to a Substreams package, which will be uploaded to IPFS on deployment.Graph Node configuration
In order to support substream-based subgraphs, Graph Node will need to be Substream aware. An additional substream endpoint will be required for each network which Graph Node will want to support.
This can be an extension of the existing provider configuration in Graph Node:
Substreams may require dedicated error handling / retry logic, though a lot of the requirements should be covered by the Firehose cursor-based integration.
Mapping entities
Substreams have their own protobuf schemas (documentation). However to directly copy the raw substream schema would be to lose the ability to link and traverse entities in the resulting GraphQL schema.
Utilities should certainly be provided to auto-generate a
.graphql
file from a substream protobuf schema, with intelligent type mapping. However once generated, developers should be able to update the.graphql
schema, to identify connections between entities, and to add derived fields. Therefore there is still value in having a schema file as part of the subgraph definition.Updating entities
In order to support performant querying, Graph Node stores full entities at every block where those entities change. It supports "upsert" type behaviour, where saved values are merged with existing entities.
Substreams currently provide entity "deltas", which just capture the changed values. Therefore there is a requirement to fetch any prior entity values to create the full entity to store. This could be done on either the Substream or Graph Node side of the integration, so we should work through the trade offs & alternatives.
Graph Node will still need to "close" the block range for any existing entities, which could negatively impact indexing performance.
Deterministic indexing
A fundamental requirement is deterministic indexing, specifically the generation of a Proof of Indexing, which can then be cross-checked across indexers.
Depending on the implementation in Graph Node, this could leverage the existing Proof of Indexing setup, or it may need a dedicated Proof of Indexing in Graph Node.
Handling re-orgs
Graph Node will still need to be re-org aware. The substreams connection should provide the relevant information (which blocks to remove). Graph Node will need to remove entities from those blocks, and re-open the block range for older entities. This functionality already exists in Graph Node, but might need to be updated for the new data source.
Linear process & batch back-filling
Graph node will need to support linear processing, e.g. when indexing at the chain head. There is a possibility that linear processing historical blocks becomes a significant performance bottleneck. In that case, a dedicated "batch" insert implementation might be required to load historical data into the subgraph.
Monitoring
Graph Node's instrumentation & monitoring may need to be updated for the new type of indexing (e.g. tracking indexing time per block etc).
Graph CLI
Graph CLI will need to be updated for the new type of data source. Graph CLI could also include the helpers to auto-generate
.graphql
files for a given substream.Backwards Compatibility
This functionality is purely additive. Graph Node may need a new
specVersion
given the new structure of the manifest, but this could also be handled in the same way as the introduction of new protocols, where Graph Node versioning provides the necessary guarantees.Dependencies
Validation
Determinism - are indexing results consistent?
Performance - are the performance gains as expected?
Scaleability - can Graph Node support 1-2K subgraphs powered by substreams?
Rationale and Alternatives
Copyright Waiver
Copyright and related rights waived via CC0.
Notes
2022-07-18