checkpoint-labs / checkpoint

Checkpoint is a library for indexing data of Starknet contracts.
https://checkpoint.box
MIT License
55 stars 22 forks source link

Bug: last_indexed_block reset to Zero after reaching the seed blocks #300

Open shardAstronaut opened 5 days ago

shardAstronaut commented 5 days ago

Description

I'm indexing ETH contract on Starknet, the indexer index all the blocks but just after reaching last seed block the last_indexed_block is set to ZERO and the data is deleted.

"@snapshot-labs/checkpoint": "^0.1.0-beta.31",

issue

bonustrack commented 5 days ago

@shardAstronaut This is weird, it might have been fixed already. Can you try using a more recent version of Checkpoint? 0.1.0-beta.35 or 0.1.0-beta.36 (this latest version support only Postgres and Checkpoint ORM).

shardAstronaut commented 5 days ago

@bonustrack I upgraded the package to beta.36 and I still have the same issue. On the logs I get this error {"error":"RangeError: Maximum call stack size exceeded"} I'll indexing without seed blocks and see.

bonustrack commented 5 days ago

@shardAstronaut Is your code available on GitHub to check?

shardAstronaut commented 4 days ago

@bonustrack I pushed the code to this repo https://github.com/shardAstronaut/checkpoint-template When running the indexer you will get this log error just after the indexer reach the seed blocks.

[1719415002170] DEBUG: handling transaction done
    component: "checkpoint"
    txIndex: 141
[1719415002170] DEBUG: handling transaction
    component: "checkpoint"
    txIndex: 142
[1719415002170] INFO: found contract event
    component: "checkpoint"
    contract: "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7"
    event: "Transfer"
    handlerFn: "liquity_eth_Transfer"
[1719415002171] DEBUG: handling transaction done
    component: "checkpoint"
    txIndex: 142
[1719415002171] DEBUG: handling transaction
    component: "checkpoint"
    txIndex: 143
[1719415002171] INFO: found contract event
    component: "checkpoint"
    contract: "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7"
    event: "Transfer"
    handlerFn: "liquity_eth_Transfer"
[1719415002171] INFO: found contract event
    component: "checkpoint"
    contract: "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7"
    event: "Transfer"
    handlerFn: "liquity_eth_Transfer"
[1719415002173] DEBUG: handling transaction done
    component: "checkpoint"
    txIndex: 143
[1719415002173] DEBUG: handling block done
    component: "checkpoint"
    blockNumber: 250990
[1719415002176] DEBUG: next checkpoint blocks
    component: "checkpoints_store"
    result: []
    block: 250991
    contracts: [
      "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7"
    ]
toBlock 251991
toBlock 251991
events 0
addressEvents 336273
----------------Before-------------------
/home/astro/Desktop/checkpoint-template/node_modules/@snapshot-labs/checkpoint/dist/src/providers/starknet/provider.js:257
            events.push(...addressEvents);
                   ^
RangeError: Maximum call stack size exceeded
    at StarknetProvider.getCheckpointsRange (/home/astro/Desktop/checkpoint-template/node_modules/@snapshot-labs/checkpoint/dist/src/providers/starknet/provider.js:257:20)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Checkpoint.preload (/home/astro/Desktop/checkpoint-template/node_modules/@snapshot-labs/checkpoint/dist/src/checkpoint.js:274:33)
    at async Checkpoint.next (/home/astro/Desktop/checkpoint-template/node_modules/@snapshot-labs/checkpoint/dist/src/checkpoint.js:295:40)
    at async Checkpoint.start (/home/astro/Desktop/checkpoint-template/node_modules/@snapshot-labs/checkpoint/dist/src/checkpoint.js:160:16)
    at async run (/home/astro/Desktop/checkpoint-template/src/index.ts:26:3)

The issue is with the array.push method that stores the data in stack which throws Maximum call stack size exceeded I opened a PR here with a fix https://github.com/checkpoint-labs/checkpoint/pull/302

Sekhmet commented 4 days ago

@shardAstronaut just to confirm, this issue (last_indexed_block is 0) is still there even on latest version with your bug fix applied?

Sekhmet commented 3 days ago

I couldn't reproduce this issue on master with your demo repo:

image

It will pause for a bit as it scans 1000 blocks at the time initially and then jumps to process all those blocks it found related events at (and for high-traffic token like ETH it's pretty much every block).