mimblewimble / grin

Minimal implementation of the Mimblewimble protocol.
https://grin.mw/
Apache License 2.0
5.04k stars 990 forks source link

Foreign API: Bulk block request #3751

Closed yeastplume closed 1 year ago

yeastplume commented 1 year ago

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 commented 1 year ago

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 /// or Error if an error is encountered. ///

yeastplume commented 1 year ago