Skip to content

fix: RPC endpoint always return stacks canonical height #6344

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

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

Jiloc
Copy link
Contributor

@Jiloc Jiloc commented Aug 1, 2025

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.,

assert_eq!(
response.preamble().get_canonical_stacks_tip_height(),
Some(1)
);
)

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:

  • the various HttpPreambleExtensions functions to set the header now expect a u64 instead of a u32, avoiding the u64 -> u32 casting.
  • add a is_success function to HttpResponsePreamble to easily check the response header.

Applicable issues

  • fixes #

Additional info (benefits, drawbacks, caveats)

Checklist

  • Test coverage for new or modified code paths
  • Changelog is updated
  • Required documentation changes (e.g., docs/rpc/openapi.yaml and rpc-endpoints.md for v2 endpoints, event-dispatcher.md for new events)
  • New clarity functions have corresponding PR in clarity-benchmarking repo
  • New integration test(s) added to bitcoin-tests.yml

@Jiloc Jiloc self-assigned this Aug 1, 2025
@Jiloc Jiloc added this to the 3.2.0.0.1 milestone Aug 1, 2025
@Jiloc Jiloc moved this to Status: 💻 In Progress in Stacks Core Eng Aug 1, 2025
@Jiloc Jiloc requested a review from jcnelson August 4, 2025 09:47
@Jiloc Jiloc marked this pull request as ready for review August 4, 2025 09:48
@Jiloc Jiloc requested review from a team as code owners August 4, 2025 09:48
@Jiloc Jiloc requested a review from rdeioris August 4, 2025 11:19
@Jiloc Jiloc moved this from Status: 💻 In Progress to Status: In Review in Stacks Core Eng Aug 4, 2025
@aldur aldur linked an issue Aug 4, 2025 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Status: In Review
Development

Successfully merging this pull request may close these issues.

[Bug] /v3/health always fails with HTTP 500
1 participant