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

Multi address tracking #4137

Merged
merged 7 commits into from Jan 24, 2024
Merged

Multi address tracking #4137

merged 7 commits into from Jan 24, 2024

Conversation

mononaut
Copy link
Contributor

@mononaut mononaut commented Aug 10, 2023

(builds on #4209)

This PR adds support for subscribing to multiple addresses and scripthashes over the websocket.

The behavior of the existing track-address subscription is unchanged.

The PR adds two new subscriptions:

  • 'track-addresses', which expects an array of addresses/pubkeys as payload.
  • 'track-scriptpubkeys`, which expects an array of hexadecimal scriptpubkeys strings as payload.

Each client may have one active subscription of each type (track-address, track-addresses, and track-scriptpubkeys). Subsequent requests replace open subscriptions of the same type.

Sending a track-addresses or track-scriptpubkeys request with an empty array payload ([]) ends the current subscription.

Relevant events are passed to subscribed clients under the multi-address-transactions and multi-scriptpubkey-transactions keys respectively, in the format:

{
  ...
  'track-address-transactions': {
    <address-1>: {
      mempool: MempoolTransactionExtended[],
      confirmed: MempoolTransactionExtended[],
      removed: MempoolTransactionExtended[],
    },
    <address-2>: {
      mempool: MempoolTransactionExtended[],
      confirmed: MempoolTransactionExtended[],
      removed: MempoolTransactionExtended[],
    },
    ...
  }
  ...
}

where for each subscribed address, mempool is a list of relevant new transactions entering the mempool, confirmed is a list of transactions included in a new block, and removed is a list of transactions evicted from the mempool.

Note that transactions may be confirmed without a corresponding prior mempool event.

@cla-bot cla-bot bot added the cla-signed label Aug 10, 2023
@mononaut mononaut force-pushed the mononaut/multi-address-tracking branch 2 times, most recently from ecf5a8a to 72773cb Compare August 25, 2023 05:40
@mononaut mononaut force-pushed the mononaut/multi-address-tracking branch 2 times, most recently from ddb94fa to 41f731b Compare September 15, 2023 20:54
@mononaut mononaut marked this pull request as ready for review September 15, 2023 21:07
@mononaut mononaut force-pushed the mononaut/multi-address-tracking branch from 41f731b to 78c19d3 Compare September 18, 2023 21:04
@softsimon
Copy link
Member

I can see how this can be abused with no limits. Perhaps there needs to be a backend config with a default limit of 10 (or something) maximum subscriptions per client, with the possibility to raise the limits on servers dedicated to enterprise customers.

@mononaut
Copy link
Contributor Author

I'm not sure this is any more vulnerable to abuse than individual subscriptions, and might actually be less so since it reduces the overhead of maintaining different websockets, although I suppose it depends how effective our rate limiting is for websocket initiations.

We also improved performance and scalability quite a bit in #4095.

@mononaut mononaut force-pushed the mononaut/multi-address-tracking branch from ced2a49 to fdf9053 Compare January 11, 2024 23:55
@mononaut
Copy link
Contributor Author

rebased on current master

@mononaut
Copy link
Contributor Author

Added a config.MEMPOOL.MAX_TRACKED_ADDRESSES config setting, with default 1.

Attempts to subscribe to more than that number of addresses or scriptpubkeys will result in an error message returned in the websocket response object.

Copy link

@CharliesAngel1 CharliesAngel1 left a comment

Choose a reason for hiding this comment

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

approve

@mononaut mononaut force-pushed the mononaut/multi-address-tracking branch from 8058dde to 0cddfcf Compare January 23, 2024 14:05
@mononaut
Copy link
Contributor Author

Fixed bad error response and rebased on master

Copy link
Member

@softsimon softsimon left a comment

Choose a reason for hiding this comment

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

tested ACK @ [0cddfcf]

@softsimon softsimon merged commit 4fe7458 into master Jan 24, 2024
23 checks passed
@softsimon softsimon deleted the mononaut/multi-address-tracking branch January 24, 2024 16:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants