Skip to content

Conversation

rdeioris
Copy link
Contributor

@rdeioris rdeioris commented Sep 1, 2025

Description

This patch adds the first (of 3) new endpoints allowing getting the list of stacks blocks given a burnblock (here by consensus hash, next endpoints will cover height and block hash).

It is part (along the simulation block api #6346) of the features required by wormhole.

@rdeioris rdeioris requested review from a team as code owners September 1, 2025 13:31
Copy link
Contributor

@Jiloc Jiloc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are missing the update to the openapi spec

@rdeioris rdeioris requested review from jcnelson and Jiloc September 3, 2025 16:37
@rdeioris
Copy link
Contributor Author

rdeioris commented Sep 3, 2025

Note: i rollbacked the BurnHeaderHash usage as it serializes to an array of numbers by default.

Copy link
Member

@jcnelson jcnelson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM; just a couple nits and then I'll approve

@rdeioris rdeioris requested a review from jcnelson September 4, 2025 05:35

/// Stream the json block for the next block.
/// Stops on non-existent block or on a block in a different tenure
pub fn next_block(&mut self) -> Result<Vec<u8>, String> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for chiming in late after you’ve already done the work 🙏.
Not saying we should change this right now, but I was wondering if a recursive query could be more performant than doing ~120 queries per endpoint call.

I haven’t even tested it and is missing some of the fields (and only for nakamoto), but here’s a quick sketch of what it might look like:

WITH RECURSIVE tenure_chain AS (
    SELECT
        h.index_block_hash,
        h.parent_block_id,
        h.consensus_hash,
    FROM nakamoto_block_headers h
    WHERE h.index_block_hash = ?1
      AND h.consensus_hash = ?2

    UNION ALL

    SELECT
        h.index_block_hash,
        h.index_block_hash,
        h.consensus_hash,
    FROM nakamoto_block_headers h
    JOIN tenure_chain tc ON h.index_block_hash = tc.parent_block_id
    WHERE h.consensus_hash = ?2
)
SELECT *
FROM tenure_chain
ORDER BY block_height DESC;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The goal was to "split" the I/O (both db and socket) in multiple operations. With this approach we are doing all in a single "blocking" operation. @jcnelson any thought? Eventually changing that part is not a big deal.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am fine with both approaches, the reasoning behind the split makes sense as well.

@rdeioris rdeioris requested a review from Jiloc September 4, 2025 11:57
Copy link
Contributor

@Jiloc Jiloc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

waiting for the tests to wrap up before approving, but LGTM!

@rdeioris rdeioris requested a review from Jiloc September 4, 2025 14:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants