🍑

Subquery の チュートリアルでプチ詰まったとこ

2022/04/30に公開

はじめに

web2 ジュニアエンジニア(実務経験2年・スクール上がり)

このページに記載されている動画見ながらひたすらやりました。
https://doc.subquery.network/academy/herocourse/welcome.html

ほぼ動画を見ればわかるので、議事録として残しておきます。
ちなみに私が作ったレポジトリは下記です。
https://github.com/SomaSekimoto/demo-subql-project

ドキュメントは現在英語のみなので、そこを補完できるような記事になればと思います。

詰まったところ

開発環境でエラー

docker-compose up

ERROR: for graphql-engine  Container "xxxxx" is unhealthy.
ERROR: Encountered errors while bringing up the project.

起動時のログとか辿らなきゃいけないのか。。。

そんなことありません!!

コンテナ立ち上げる時のコマンドを、

docker-compose up

ではなく

docker compose up

にすれば、各コンテナの起動ログが見られます。

私の場合は、postgres のコンテナに異常があったので、
一旦 .data フォルダを削除して改めて コンテナ立ち上げると解消しました。

デプロイ時のエラー

依存packageのバージョンエラー

staging slot へのデプロイを試みた際に、エラーがあって結構な時間詰まりました。

2022-04-27,14:32:34.1651069954
start to build package
Cloning into '/data/subql'...
Note: checking out '3d5a742f5b4356f2a9f018c7bc5cd81c85c72d30'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b <new-branch-name>

HEAD is now at 3d5a742... add: logger in CallHandler
yarn install v1.22.17
info No lockfile found.
[1/4] Resolving packages...
warning @subql/cli > cli-ux@6.0.9: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.
warning @subql/cli > oclif > aws-sdk > uuid@3.3.2: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
warning @subql/cli > oclif > aws-sdk > querystring@0.2.0: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
warning @subql/cli > oclif > aws-sdk > url > querystring@0.2.0: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
[2/4] Fetching packages...
error ipfs-unixfs@6.0.7: The engine "node" is incompatible with this module. Expected version ">=16.0.0". Got "14.19.1"
error Found incompatible module.
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
download dependencies failed

何が何やら。。。

とにかくnodeのバージョンがあってないとのこと。
ここでかなり苦戦しました。デプロイするときに選択する、
@subql/node や @subql/query のバージョンを変えたり組み合わせを変えたり、package.json内のpackageのバージョンを下げてみたりと、やってみましたが解決せず。。。

Subquery のdiscordに投げてみました!
https://discord.com/channels/796198414798028831/809621232361668609/968894254476828673

すると1日もしないうちに回答が返ってきて、解決しました👍

https://discord.com/channels/796198414798028831/809621232361668609/969019554913206362

https://github.com/subquery/subql/discussions/926

package.json内に下記を追記する必要があった。
っていうか、依存パッケージのバージョン指定できること知らなかった。。。😅
勉強になります。

package.json
"resolutions": {
    "ipfs-unixfs": "6.0.6"
  }

これでデプロイ成功しました!!!

startBlock を変更するときのエラー

startBlockとは下記のことを言ってます。

..........
dataSources:
  - kind: substrate/Runtime
    startBlock: 785119 ←
    mapping:
..........

ここを変更して、再度デプロイしようとすると、下記エラーが。。

{"level":"warn","timestamp":"2022-04-29T16:26:20.573Z","pid":7,"hostname":"subquery-13395-indexer-deployment-75bcc49786-vvrg8","category":"configure","message":"Note that argument --subquery-name has been deprecated in favour of --db-schema"}
2022-04-29 16:26:23        API/INIT: RPC methods not decorated: eth_feeHistory
{"level":"error","timestamp":"2022-04-29T16:26:23.706Z","pid":7,"hostname":"subquery-13395-indexer-deployment-75bcc49786-vvrg8","category":"indexer","message":"Your start block is greater than the current indexed block height in your database. Either change your startBlock (project.yaml) to <= 785119 \n         or delete your database and start again from the currently specified startBlock"}

こちらは、エラー文の通り、startBlockの値を785119以下にするのか、1度プロジェクト消すのかしないといけないっぽいです。

staging lot でテストとしてデプロイしていただけなので、一度削除してデプロイしたら解消しました。

おわりに

polkadot 上のブロックチェーンの内容(ブロック・トランザクション・メタデータ)とその構築言語であるSubstrateへの理解がさらに深まりました。

あと、コミュニティの力は偉大です。三人寄れば文殊の知恵です。

にしてもまだまだわからないことが多いので、もし間違いあればドシドシ指摘お待ちしております。
これって指摘する側にもインセンティブがもっとあればいいのになぁとも思いますが。

Discussion