Skip to content
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

get_raw_block api endpoint #820

Merged
merged 3 commits into from
Mar 16, 2023
Merged

Conversation

huangminghuang
Copy link
Contributor

@huangminghuang huangminghuang commented Mar 15, 2023

This PR

  • adds the following API endpoints
    • /v1/chain/get_raw_block: returns the raw block content without ABI decoding
    • /v1/chain/get_block_header: returns the block header with optional block extensions
      • Input/output:
    struct get_raw_block_header_params {
       string block_num_or_id;
       bool include_extensions = false; // include block extensions (requires reading entire block off disk)
    }; 
    
    struct get_raw_block_header_results {
       chain::block_id_type  id;
       fc::variant           signed_block_header;
       std::optional<chain::extensions_type> block_extensions;
    };
    
  • add cleos get block options for the added API endpoints above
    • --raw: corresponding to get_raw_block
    • --header: corresponding to get_block_header with include_extensions set to false
    • --header_with_extensions: corresponding to get_block_header with include_extensions set to true

Resolves #642

@huangminghuang huangminghuang requested a review from heifner March 15, 2023 13:53
@heifner heifner requested review from linh2931 and greg7mdp March 15, 2023 17:31
@heifner heifner removed the request for review from linh2931 March 15, 2023 21:38
@heifner heifner added documentation Improvements or additions to documentation OCI Work exclusive to OCI team labels Mar 15, 2023
@stephenpdeos stephenpdeos requested review from ScottBailey and linh2931 and removed request for greg7mdp March 16, 2023 16:16
@ScottBailey ScottBailey removed their request for review March 16, 2023 18:45

EOS_ASSERT( !params.block_num_or_id.empty() && params.block_num_or_id.size() <= 64,
chain::block_id_type_exception,
"Invalid Block number or ID, must be greater than 0 and less than 64 characters"
Copy link
Member

Choose a reason for hiding this comment

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

You have an extra equal to 64 checked while greater than 0 is not checked. This is not blocking. You can fix in RC.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe the assertion condition is right but the message description was problematic, fixed in commit af1dcf2

std::optional<signed_block_header> header;

if( block_num ) {
header = db.fetch_block_header_by_number( *block_num );
Copy link
Member

Choose a reason for hiding this comment

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

No try block for db.fetch_block_header_by_number?

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 try you saw in the else was thrown from the type conversion from string to block_id_type, not from the fetch_block_header_by_id itself. In this line, the block_num is already the right type; therefore, its not going to throw here. This is exactly the same logic with get_raw_block() in line 1920.

@huangminghuang huangminghuang merged commit 326c169 into main Mar 16, 2023
@huangminghuang huangminghuang deleted the huangminghuang/get_raw_block branch March 16, 2023 21:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation OCI Work exclusive to OCI team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Creation of v1/chain/get_raw_block chain API endpoint
3 participants