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
{{ message }}
Repository navigation
Include current chain tip hash in all API response headers #6584
Please include the current chain tip hash in all API response headers. While this is a non-breaking nice-to-have extension to the Esplora API, it would be great to make this mandatory/clearly documented feature of a next-gen API protocol.
Problem to be solved
When syncing against mempool API, wallets (in particular Lightning wallets) might need to make multiple sequential requests to collect all data for a given item. However, they don't necessarily have a solid way to detect if the chain moved under them in the time they made these requests. Even checking in the beginning and at the end is ofc course race-y, as the chain might have moved (yielding inconsistent data for some of the API calls) and moved back.
Proposed solution
A very simple extension would be to include the current chain tip hash as an HTTP header of any given API response. This would allow any client upon receipt to clearly see for which chain state the returned response was valid. While this could easily be added as an optional non-breaking extension to the Esplora-flavored API, it would be even better to see this be a required part of the API contract for any future/next-gen API protocol, so that wallet developers can actually start leaning on this feature.
Additional info
The need for such a consistency feature comes up now and then, but we particularly discovered it when implementing Esplora-based syncing for LDK a while back. Our stopgap solution is to apply several heuristics to detect inconsistencies and start over when we do, but this is tricky, requires additional API calls (inefficient), and error-prone.
I agree this would be a very useful feature to have for wallet syncing.
My main concern is that we don't want to simply push the issue of "the chain moving under you while syncing requests are in flight" one layer further up the stack, without actually solving the underlying consistency problem.
e.g. although conceptually each chain tip maps to a single stable canonical address state, the current architecture of mempool/electrs isn't guaranteed to uphold that property because headers, transaction data, address history, and caches can be observed at different intermediate stages of block indexing.
So I'd be reluctant to link responses to a specific chain tip unless or until we can actually guarantee the level of consistency that implies.
But it's definitely something we'll look into both for the current API and to consider in the design of any next-gen protocol.
My main concern is that we don't want to simply push the issue of "the chain moving under you while syncing requests are in flight" one layer further up the stack, without actually solving the underlying consistency problem.
e.g. although conceptually each chain tip maps to a single stable canonical address state, the current architecture of mempool/electrs isn't guaranteed to uphold that property because headers, transaction data, address history, and caches can be observed at different intermediate stages of block indexing.
Hmm, well, that consistency issue seems like a huge omission that might have further implications outside of this issue, so it might need to get fixed anyways? And once the backend is sufficiently safe, including the header should be ~free?
But it's definitely something we'll look into both for the current API and to consider in the design of any next-gen protocol.
It would be definitely be appreciated to still fix this 'for current gen'. For 'next gen' the question becomes whether there could be a protocol design that gets rid of the need of sequential requests at all, i.e., something where the wallet could just request all it needs in a single request or similar. But that's def. out-of-scope for this issue, and even just having the tip hash always available would go a long way.
to be clear, there’s no correctness or safety issue in the mempool APIs, and nothing to “fix” per se.
I'm saying that adding chain tip hash headers doesn't necessarily fix your problem of trying assemble a consistent point-in-time state from multiple sequential requests.
in particular, we offer no guarantee that a particular response corresponds to an exact block boundary - very rarely it might represent a (perfectly valid) state from partway through the application of a new block, in which case a chain tip hash header would be misleading.
We implemented the backend part in ElectrumX (server), and have been testing it on mainnet on a popular server. It seems ~fine. Although making the block-state and the mempool-state consistent while processing the request is not really practical with ElectrumX's current architecture, so as described in the spec PR, my current approach was to have a retry logic. Longer term one proper way to tackle this would be to have separate RPCs for already mined state and for mempool state.
As I am not familiar with the architecture of electrs or mempool/electrs, not sure what would be required there.
Are you saying the changes required to implement this in mempool/electrs would not be reasonable to make in the nearish future?
It would be good to know this and get complaints before we "finalise" protocol version 1.7 :)
to be clear, there’s no correctness or safety issue in the mempool APIs, and nothing to “fix” per se.
in particular, we offer no guarantee that a particular response corresponds to an exact block boundary - very rarely it might represent a (perfectly valid) state from partway through the application of a new block, in which case a chain tip hash header would be misleading.
I would argue these are contradictory statements. I don't really know how I'd build a wallet that syncs against an API where you might get a response that is "mid-block". This seems like it can cause any number of downstream issues.
Activity
mononaut commentedon Jun 19, 2026
Thanks for the suggestion!
I agree this would be a very useful feature to have for wallet syncing.
My main concern is that we don't want to simply push the issue of "the chain moving under you while syncing requests are in flight" one layer further up the stack, without actually solving the underlying consistency problem.
e.g. although conceptually each chain tip maps to a single stable canonical address state, the current architecture of mempool/electrs isn't guaranteed to uphold that property because headers, transaction data, address history, and caches can be observed at different intermediate stages of block indexing.
So I'd be reluctant to link responses to a specific chain tip unless or until we can actually guarantee the level of consistency that implies.
But it's definitely something we'll look into both for the current API and to consider in the design of any next-gen protocol.
tnull commentedon Jun 19, 2026
Hmm, well, that consistency issue seems like a huge omission that might have further implications outside of this issue, so it might need to get fixed anyways? And once the backend is sufficiently safe, including the header should be ~free?
It would be definitely be appreciated to still fix this 'for current gen'. For 'next gen' the question becomes whether there could be a protocol design that gets rid of the need of sequential requests at all, i.e., something where the wallet could just request all it needs in a single request or similar. But that's def. out-of-scope for this issue, and even just having the tip hash always available would go a long way.
mononaut commentedon Jun 19, 2026
to be clear, there’s no correctness or safety issue in the mempool APIs, and nothing to “fix” per se.
I'm saying that adding chain tip hash headers doesn't necessarily fix your problem of trying assemble a consistent point-in-time state from multiple sequential requests.
in particular, we offer no guarantee that a particular response corresponds to an exact block boundary - very rarely it might represent a (perfectly valid) state from partway through the application of a new block, in which case a chain tip hash header would be misleading.
SomberNight commentedon Jun 25, 2026
This was also proposed for Electrum protocol 1.7.
We implemented the backend part in ElectrumX (server), and have been testing it on mainnet on a popular server. It seems ~fine. Although making the block-state and the mempool-state consistent while processing the request is not really practical with ElectrumX's current architecture, so as described in the spec PR, my current approach was to have a retry logic. Longer term one proper way to tackle this would be to have separate RPCs for already mined state and for mempool state.
As I am not familiar with the architecture of electrs or mempool/electrs, not sure what would be required there.
Are you saying the changes required to implement this in mempool/electrs would not be reasonable to make in the nearish future?
It would be good to know this and get complaints before we "finalise" protocol version 1.7 :)
TheBlueMatt commentedon Jun 26, 2026
I would argue these are contradictory statements. I don't really know how I'd build a wallet that syncs against an API where you might get a response that is "mid-block". This seems like it can cause any number of downstream issues.
docs: chain-view pin for confirmed-tx APIs (Yuval / mempool#6584)
esplora: pin each chain read to its starting tip and name it in X-Bit…