-
Notifications
You must be signed in to change notification settings - Fork 37.7k
rpc: Add mempoolchanges #19476
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
rpc: Add mempoolchanges #19476
Conversation
This is a POC, please don't review the code, just the approach. It needs to define the change format among other details. |
Seems like this should probably use longpolling instead? |
@luke-jr ☝️ |
Might be a good idea to optionally start with full |
@instagibbs that's already the case, |
Longpolling would support multiple clients on a single buffer. So each request would get a new position id, and requesting with that position id would tell the node where in the shared buffer to begin with new data. |
@luke-jr yes, it would be possible to share the buffer for all active clients. The problem is when a new client starts a stream, it needs to receive the current mempool and then resume from the shared buffer. I consider this an optimization. |
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
16611c7
to
100f1d2
Compare
100f1d2
to
ac09588
Compare
ac09588
to
47083b0
Compare
Anyone interested in this may be interested in #19572 as well. |
I promised a quick review after the developer IRC chat. My concerns would be: If a client is struggling to handle a particular message type, it's not unimaginable that it might keep re-connecting for a new stream, getting a message and failing. Each time the Since there's no TCP session for each resource, how would I troubleshoot a bitcoind that's no longer responding to There is also notably no isolation between streams. I can cause havoc (or at least, defeat the whole reliable nature of this scheme) by requesting an event from a different client's stream. The original client is then gaped and has no idea. You could defend against this by including the stream sequence number in the reply (so the client can detect gaps) and issuing the stream identifier numbers secure-randomly (to make them non-predictable), but these are both extra bytes you need to carry around on every request/response that a per-subscriber TCP stream does away with. |
Thanks for the comments @shuckc I'm not that worried about memory. Of course it would be a problem if you start lots of streams and you don't poll from them. We could limit the sum of all streams sizes. Anyway, internally streams could share the same data, see #19476 (comment). Currently the client has to periodically request for changes, but the connection can be reused as we support multiple requests on the same connection. Long polling is not implemented, but once it's implemented it only reduces unnecessary empty requests. I think this approach would be preferable in the REST interface with actual long polling, where the response doesn't actually finishes, but the client keeps reading them. But we don't have support in http server for this yet.
I thought of
I'm assuming clients don't mess around with other streams, that's why the stream id isn't reused. I though about letting the client give a name for the stream (
A per-subscriber TCP stream isn't fault tolerant, that's the point here where the server holds the changes until that subscriber comes again. |
🐙 This pull request conflicts with the target branch and needs rebase. Want to unsubscribe from rebase notifications on this pull request? Just convert this pull request to a "draft". |
Closing now that #19572 is merged. |
The new RPC
mempoolchanges
allows a client to retrieve mempool changes in a reliable way.The client needs to start a dedicated stream:
This returns the stream ID and at this point it contains the mempool content and it will keep track of all mempool changes.
To retrieve the actual changes the client calls:
This pulls up to 10 changes from the given stream.
Finally the client can stop the stream with
Also, the stream is limited and if that limit is reached then the stream is automatically stopped.
TODO: option to block until changes are available.