Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

eth indexer: subscribe to blocks or logs instead of actively pulling each block every few second #123

Closed
ppca opened this issue Jan 18, 2025 · 2 comments · Fixed by #129
Closed
Assignees

Comments

@ppca
Copy link
Contributor

ppca commented Jan 18, 2025

The approach we take now for the eth indexer is every 5 second, we call the RPC to get the latest block and process it.
This approach may have the issue that there will always be delay for the user who initiates the sign request because we do not call RPC at the exact block time that the sign request comes in.

subscription will make sure we receive the latest block/log once it appears on eth side. I've not seen complaints about the subscribed stream being delayed, but it is a possibility.
In terms of pricing, I've only looked into Infura's pricing so far:

  • subcription is 300 credits/block
  • getting latest block (eth_getBlockByNumber) is 80 credits
  • getting latest block number (eth_getBlockNumber) is 80 credits
    For infura costs are comparable, but not sure about other providers.
@ailisp
Copy link
Contributor

ailisp commented Jan 20, 2025

This is a great idea! Looking at the approach you proposed, the docs says eth_subscribe can subscribe to new logs instead of blocks, so it will cost 300 credit only when there is a new sign request that will be very cheap and we can even use a free plan.

Theoratically we only need sign requests instead of latest block number, but if we do want block number, eth_subscribe to newHead (get notified each new block added to chain) is 5 credit. Eth sepolia block time is 12 seconds, so this is also much cheaper than current implementation

@ppca ppca self-assigned this Jan 22, 2025
@ppca
Copy link
Contributor Author

ppca commented Jan 22, 2025

the docs says eth_subscribe can subscribe to new logs instead of blocks
Yes, but their pricing still indicates that they charge per block tho by the following: "The credit costs for the logs and newHeads events are charged per block, whereas newPendingTransaction events are charged at approximately one second intervals."
Still, the benefit is no delay in processing requests in a block once logs show up.

80% done implementing it, but hardhat node web socket connection drops after a while locally. This is a common and known issue in the community. People reported that when they use Infura or Alchemy's websocket urls, this issue never happens. I'll try infura on our testnet contract to verify.

@ppca ppca linked a pull request Jan 22, 2025 that will close this issue
@ppca ppca closed this as completed in #129 Jan 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants