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

Foreign API: Bulk block request #3751

Merged
merged 8 commits into from
Jun 12, 2023

Conversation

yeastplume
Copy link
Member

As requested, a foreign API function that returns a number of blocks (if they exist) based on the height at which they were applied.

Note this is WIP and subject to review and change, and we may need some form of limitation here to avoid an obvious DOS vector.

@yeastplume yeastplume changed the title [WIP] Foreign API: Bulk block request Foreign API: Bulk block request Jun 6, 2023
@yeastplume
Copy link
Member Author

Tested and ready for review, note there's a hardcoded max of 1000 blocks, similar to the existing max in get_unspent_outputs. Note this function doesn't lock the hashset, it's pure database lookup and should have less potential for interruption than existing foreign API functions.

/// Returns a BlockListing of available blocks
/// between min_height and max_height
/// The method will query the database for blocks starting at the block height min_height
/// and continue until max_height, skipping any blocks that aren't available.
///
/// # Arguments
/// * start_height - starting height to lookup.
/// * end_height - ending height to to lookup.
/// * 'max - The max number of blocks to return. /// Note this is overriden with BLOCK_TRANSFER_LIMIT if BLOCK_TRANSFER_LIMIT is exceeded /// /// # Returns /// * Result Containing: /// * A [BlockListing](types/struct.BlockListing.html) /// * or [Error`](struct.Error.html) if an error is encountered.
///

@yeastplume
Copy link
Member Author

  • Move logic into blocks_api::BlockHandler
  • Don't error if hash doesn't exist for given height
  • if start height < recorded tail in db, change start height to tail to avoid scanning entire DB for first existing block


match block_res {
Err(e) => {
if let Error::NotFound = e {
Copy link
Member

Choose a reason for hiding this comment

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

As I understand it, we'll skip blocks we can't find, which is ok, but do we expect to arrive at this state for some blocks or is it just defensive programming?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think there's a particular guarantee that there won't be gaps in the stored blocks, so no harm just handling the case.

Copy link
Member

@phyro phyro left a comment

Choose a reason for hiding this comment

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

Only left a minor question, other than that the code looks good to me. I am unable to test it at the moment, but have asked a few days ago vegycslol to do it and he confirmed it works for him on a non-archive node.

@yeastplume yeastplume merged commit 01370d7 into mimblewimble:master Jun 12, 2023
bayk added a commit to mwcproject/mwc-node that referenced this pull request Jun 23, 2024
* remove non-mainnet check for PIBD requests
* add first version of get blocks function
* .\api\src\foreign.rs
* add a max value to get_blocks, documentation
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.

2 participants