Skip to content

Conversation

kaladinlight
Copy link
Contributor

Currently in order to push confirmed transaction notifications to a client, you have to:

  • Subscribe to new blocks
  • Fetch block from blockbook on new block
  • Check if any subsccribed addresses are associated with any transactions in the block

Historically this has worked without any noticeable issue, however in integrating Base, I have noticed this no longer holds up due to the fast block times and high transaction throughput on chain. The node gets oversaturated with network requests causing it to fall out of sync along with blockbook. Even when they are staying in sync, I was seeing calls to get a block taking more than 30 minutes. I did make many attempts at increasing resources, cache sizes, etc. to improve performance without avail.

To reduce most overhead related to this scenario, I chose to add an optional newBlockTxs param to subscribeAddresses which will allow subscribing to addresses for mempool AND confirmed transactions now. By leveraging the mostly parsed sync blocks, we can detect all associated addresses for a transaction to determine if a confirmed transaction should be published to a client and only then, fetch the evm transaction receipt to ensure an api.Tx is sent to the client. This update cuts down nearly all of the previously seen network requests and completely fixed the performance issues seen in the above scenario.

(I went with newBlockTxs just to tie into the new block vernacular, but could update to confirmedTxs if that sounds better.)

@kaladinlight kaladinlight force-pushed the pub-new-block-txs branch 2 times, most recently from b5dd84c to fe7b7fa Compare February 6, 2025 18:18
@etimofeeva
Copy link
Contributor

@kaladinlight is this a finished PR ready for review?

@kaladinlight
Copy link
Contributor Author

@kaladinlight is this a finished PR ready for review?

@etimofeeva yep, it is ready to go!

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for publishing confirmed transaction notifications directly to clients subscribed to specific addresses, bypassing the need to repeatedly fetch blocks from blockbook. This optimizes performance on high-throughput chains like Base by leveraging already-parsed sync blocks to detect relevant transactions and only fetching receipts when needed.

  • Adds newBlockTxs parameter to subscribeAddresses for opting into confirmed transaction notifications
  • Refactors address subscription tracking to include per-subscription configuration details
  • Updates the block processing pipeline to pass full block objects instead of just hash/height

Reviewed Changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
static/test-websocket.html Adds UI checkbox for testing the new newBlockTxs option
server/ws_types.go Adds NewBlockTxs boolean field to subscription request struct
server/websocket.go Core implementation of confirmed transaction publishing with subscription tracking
server/public.go Updates block notification interface to pass full block objects
docs/api.md Documents the new optional parameter with example usage
db/sync.go Updates block processing callback to pass block objects
blockbook.go Updates callback function signatures for block processing
blockbook-api.ts Adds TypeScript interface for the new optional parameter
bchain/types.go Updates callback signature and adds transaction receipt method
bchain/coins/eth/ethrpc.go Refactors and exposes transaction receipt fetching method
bchain/coins/blockchain.go Adds metrics wrapper for new transaction receipt method
bchain/basechain.go Provides default implementation for transaction receipt method
api/worker.go Exposes transaction conversion method for external use

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants