subsquid / squid-sdk

The main repo of the squid SDK
Apache License 2.0
1.23k stars 151 forks source link

FireSquid Ingest: Crashes on failed extrinsics #68

Closed XY-Wang closed 2 years ago

XY-Wang commented 2 years ago

Hi,

I'm running the newest FireSquid archive and batch processor for Rococo-contracts and noticed that the processor crashes when it tries to process a failed extrinsic.

This is the error that I'm getting:

10:43:53 FATAL sqd:processor AssertionError [ERR_ASSERTION]: The expression evaluated to a falsy value:

                               (0, assert_1.default)(val != null, msg)

                                 at assertNotNull (/home/xueying/dev/squid-ink/node_modules/@subsquid/util-internal/lib/misc.js:18:26)
                                 at tryMapGatewayBlock (/home/xueying/dev/squid-ink/node_modules/@subsquid/substrate-processor/lib/ingest.js:292:64)
                                 at mapGatewayBlock (/home/xueying/dev/squid-ink/node_modules/@subsquid/substrate-processor/lib/ingest.js:227:16)
                                 at Array.map (<anonymous>)
                                 at /home/xueying/dev/squid-ink/node_modules/@subsquid/substrate-processor/lib/ingest.js:60:45
                                 at processTicksAndRejections (node:internal/process/task_queues:96:5)
                             err:
                               generatedMessage: true
                               code: ERR_ASSERTION
                               actual: false
                               expected: true
                               operator: ==
                               blockHeight: 47346
                               blockHash: 0xa0902b864029f88d5f379a34654c2ad370c4ad8986fc52153b1fe08f802eef0c
                               batchRange:
                                 from: 0
                               archiveHeight: 477419
                               archiveQuery: query {
                                               status {
                                                 head
                                               }
                                               batch(fromBlock: 0, toBlock: 477419, limit: 500, includeAllBlocks: false, events: [{name: "System.NewAccount"}, {name: "Balances.Reserved"}, {name: "Balances.Transfer"}, {name: "Balances.Withdraw"}, {name: "Contracts.CodeStored"}, {name: "Contracts.ContractCodeUpdated"}, {name: "Balances.Endowed"}, {name: "Contracts.Instantiated"}, {name: "Contracts.ContractEmitted"}], calls: [{name: "Contracts.call"}]) {
                                                 header {
                                                   id
                                                   height
                                                   hash
                                                   parentHash
                                                   timestamp
                                                   specId
                                                 }
                                                 events
                                                 calls
                                                 extrinsics
                                               }
                                             }

                               batchBlocksFetched: 500

When I query my archive API, I see that at the erroneous block there is a failed extrinsic and no calls but the extrinsic does contain a callId:

  "batch": [
    {
      "header": {
        "id": "0000047346-a0902",
        "height": 47346,
        "hash": "0xa0902b864029f88d5f379a34654c2ad370c4ad8986fc52153b1fe08f802eef0c",
        "parentHash": "0x77370cc8389791254c41c9ef9c4b81f57003e9bc697fdb94dfd6d36dfd95570b",
        "timestamp": "2022-03-31T13:39:48.087+00:00",
        "specId": "canvas-kusama@16"
      },
      "calls": [],
      "extrinsics": [
        {
          "callId": "0000047346-000002-a0902",
          "error": {
            "__kind": "BadOrigin"
          },
          "fee": null,
          "hash": "0x6a0cac5df13038fc5bf2f36cc71ca62d4be54bb94325008e7898b34db5cd8532",
          "id": "0000047346-000002-a0902",
          "indexInBlock": 2,
          "pos": 10,
          "signature": {
            "address": {
              "__kind": "Id",
              "value": "0x2681a28014e7d3a5bfb32a003b3571f53c408acbc28d351d6bf58f5028c4ef14"
            },
            "signature": {
              "__kind": "Sr25519",
              "value": "0xba4d4de7ed277881786dfefb9275bd05aee8be4f626e115ea181ec41bab6ab6dfcb63318ed6d1c4685decc846f76476ba09f1cab84cda07b5e001a2813ffb682"
            },
            "signedExtensions": {
              "ChargeTransactionPayment": 0,
              "CheckMortality": {
                "__kind": "Mortal228",
                "value": 0
              },
              "CheckNonce": 0
            }
          },
          "success": false,
          "tip": "0",
          "version": 4
        }
      ]
    }

This is causing the processor to crash since in tryMapGatewayBlock of ingest.ts (lines 357-362) the processor is asserting that call is not null if callId exists. I imagine that the archive should be setting the callId to null in case of failed extrinsics?

I also encountered the same issue in Shibuya at block 1010459 using the Shibuya archive endpoint, https://shibuya.archive.subsquid.io/graphql

eldargab commented 2 years ago

@tmcgroul

tmcgroul commented 2 years ago

@XY-Wang sorry for the inconveniences. Will fix today

tmcgroul commented 2 years ago

@XY-Wang fix is available in subsquid/substrate-gateway:1.2.0 i also updated https://shibuya.archive.subsquid.io/graphql so you can check correctness

XY-Wang commented 2 years ago

Thanks for the quick fix @tmcgroul ! It works perfectly now, closing the issue.