You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
mhchia
changed the title
Save queried logs to avoid redundant queries
Save queried logs to save redundant queries
Aug 24, 2023
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 thanlatest_block_height - num_blocks_delayed
can barely reorg.The text was updated successfully, but these errors were encountered: