-
Notifications
You must be signed in to change notification settings - Fork 699
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
fix: RPC endpoint always return stacks canonical height #6344
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall looks fine!
Waiting for open remarks to be addressed before approving
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new commit a95d3e7 centralizes the get_canonical_stacks_tip_height()
response header check in the TestRPC
facility. This opens an opportunity to clean up the RPC endpoint tests regarding canonical height assertions (let's call it height assert
for brevity).
Currently, each RPC endpoint should checks for the height assert
in their tests. This approach has proved to be error-prone. As a result, about 60% of RPC (e.g., callreadonly.rs
) perform this check in their tests, while 40% (e.g., getblock.rs
) do not. Ideally, these inconsistencies should be addressed in this PR.
Given the new commit, I propose the following improvement to our test strategy:
- Remove all individual
height assert
checks from the 60% of RPC endpoint tests that currently include them. - Introduce a dedicated test specifically for the
height assert
, which can target one or a few RPC endpoints (or just a mocked one if we could) and verify that theheight assert
matches the expected value.
This approach centralizes the height assert
check and relieves all RPC endpoint tests (including any future additions) from having to perform this verification individually.
What do you think?
I agree, this sounds like an improvement. I also had the same concern in the back of my mind. If we leave the tests as they are, future developers adding new endpoints might wonder whether they should include the height assert based on the mixed patterns in existing tests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGMT!
40825cc
Codecov Report❌ Patch coverage is ❌ Your project status has failed because the head coverage (64.60%) is below the target coverage (80.00%). You can increase the head coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## develop #6344 +/- ##
===========================================
+ Coverage 62.44% 64.60% +2.15%
===========================================
Files 552 555 +3
Lines 351797 350866 -931
===========================================
+ Hits 219676 226672 +6996
+ Misses 132121 124194 -7927
... and 341 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
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