What’s wrong?
RLNContract.getLogs fetches all history logs from the provider every time it’s called. It’ll take much time for each log when the number of logs and the block height grows.
How to fix it?
We can get logs step by step and save them locally, to avoid getting all historical logs every time we call getLogs. For example, we can start from the block where the contract is deployed, query logs from a certain number of blocks each time, memorize the latest block height we’ve queried, and repeat.
We also need to make sure the logs are still valid even after a reorg. A naive way is that we only query blocks up to latest_block_height - num_blocks_delayed. num_blocks_delayed is large enough so that the blocks with height smaller than latest_block_height - num_blocks_delayed can barely reorg.
What’s wrong?
RLNContract.getLogsfetches all history logs from the provider every time it’s called. It’ll take much time for each log when the number of logs and the block height grows.How to fix it?
We can get logs step by step and save them locally, to avoid getting all historical logs every time we call
getLogs. For example, we can start from the block where the contract is deployed, query logs from a certain number of blocks each time, memorize the latest block height we’ve queried, and repeat.We also need to make sure the logs are still valid even after a reorg. A naive way is that we only query blocks up to
latest_block_height - num_blocks_delayed.num_blocks_delayedis large enough so that the blocks with height smaller thanlatest_block_height - num_blocks_delayedcan barely reorg.