fix: RPC endpoint always return stacks canonical height #6344
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
The
X-Canonical-Stacks-Tip-Height
header is intended to be included in all succesfull RPC responses, and this has mostly been the case until epoch 2.5. However, over time this behavior was inconsistently applied, as the header had to be manually added in each endpoint's implementation. This made it easy to forget during implementation or review of new endpoints.This PR refactors the code to centralize the logic for setting this header, ensuring it is automatically included in all relevant responses. So we eliminate the need to manually include it in each endpoint and write dedicated tests for it for each new endpoint. The presence of the header continues to be covered by existing integration tests for various endpoints (e.g.,
stacks-core/stackslib/src/net/api/tests/getinfo.rs
Lines 90 to 93 in 9d53951
The following endpoints were previously missing the header and are now covered:
/v2/blocks/:block_id
/v2/headers/:height
/v2/mempool/query
/v2/microblock/*
/v3/tenures/fork_info
/v3/blocks/:block_id
/v3/blocks/height/:block_height
/v3/health
/v3/sortitions/*
/v3/tenures/:block_id
/v3/tenures/info
/v3/tenures/tip/:consensus_hash
/v3/transaction/:txid
This change also lays the groundwork for a follow-up PR that will use this header to determine the highest Stacks tip height among peers via their RPC responses.
Other changes:
HttpPreambleExtensions
functions to set the header now expect a u64 instead of a u32, avoiding the u64 -> u32 casting.is_success
function toHttpResponsePreamble
to easily check the response header.Applicable issues
Additional info (benefits, drawbacks, caveats)
Checklist
docs/rpc/openapi.yaml
andrpc-endpoints.md
for v2 endpoints,event-dispatcher.md
for new events)clarity-benchmarking
repobitcoin-tests.yml