add BlockchainReadRequest::Block[ByHash]

This commit is contained in:
hinto.janai 2024-09-06 20:45:25 -04:00
parent 81d8d2baa6
commit b8656961f3
No known key found for this signature in database
GPG key ID: D47CE05FA175A499
2 changed files with 43 additions and 3 deletions

View file

@ -86,9 +86,11 @@ fn map_request(
/* SOMEDAY: pre-request handling, run some code for each request? */ /* SOMEDAY: pre-request handling, run some code for each request? */
match request { match request {
R::BlockExtendedHeader(block) => block_extended_header(env, block), R::Block(height) => block(env, height),
R::BlockExtendedHeaderByHash(block) => block_extended_header_by_hash(env, block), R::BlockByHash(hash) => block_by_hash(env, hash),
R::BlockHash(block, chain) => block_hash(env, block, chain), R::BlockExtendedHeader(height) => block_extended_header(env, height),
R::BlockExtendedHeaderByHash(hash) => block_extended_header_by_hash(env, hash),
R::BlockHash(height, chain) => block_hash(env, height, chain),
R::FindBlock(_) => todo!("Add alt blocks to DB"), R::FindBlock(_) => todo!("Add alt blocks to DB"),
R::FilterUnknownHashes(hashes) => filter_unknown_hashes(env, hashes), R::FilterUnknownHashes(hashes) => filter_unknown_hashes(env, hashes),
R::BlockExtendedHeaderInRange(range, chain) => { R::BlockExtendedHeaderInRange(range, chain) => {
@ -177,6 +179,28 @@ macro_rules! get_tables {
// TODO: The overhead of parallelism may be too much for every request, perfomace test to find optimal // TODO: The overhead of parallelism may be too much for every request, perfomace test to find optimal
// amount of parallelism. // amount of parallelism.
/// [`BlockchainReadRequest::Block`].
#[inline]
fn block(env: &ConcreteEnv, block_height: BlockHeight) -> ResponseResult {
// Single-threaded, no `ThreadLocal` required.
let env_inner = env.env_inner();
let tx_ro = env_inner.tx_ro()?;
let tables = env_inner.open_tables(&tx_ro)?;
Ok(BlockchainResponse::Block(todo!()))
}
/// [`BlockchainReadRequest::BlockByHash`].
#[inline]
fn block_by_hash(env: &ConcreteEnv, block_hash: BlockHash) -> ResponseResult {
// Single-threaded, no `ThreadLocal` required.
let env_inner = env.env_inner();
let tx_ro = env_inner.tx_ro()?;
let tables = env_inner.open_tables(&tx_ro)?;
Ok(BlockchainResponse::BlockByHash(todo!()))
}
/// [`BlockchainReadRequest::BlockExtendedHeader`]. /// [`BlockchainReadRequest::BlockExtendedHeader`].
#[inline] #[inline]
fn block_extended_header(env: &ConcreteEnv, block_height: BlockHeight) -> ResponseResult { fn block_extended_header(env: &ConcreteEnv, block_height: BlockHeight) -> ResponseResult {

View file

@ -22,6 +22,16 @@ use crate::types::{Chain, ExtendedBlockHeader, OutputOnChain, VerifiedBlockInfor
/// See `Response` for the expected responses per `Request`. /// See `Response` for the expected responses per `Request`.
#[derive(Debug, Clone, PartialEq, Eq)] #[derive(Debug, Clone, PartialEq, Eq)]
pub enum BlockchainReadRequest { pub enum BlockchainReadRequest {
/// Request a block.
///
/// The input is the block's height.
Block(usize),
/// Request a block.
///
/// The input is the block's hash.
BlockByHash([u8; 32]),
/// Request a block's extended header. /// Request a block's extended header.
/// ///
/// The input is the block's height. /// The input is the block's height.
@ -129,6 +139,12 @@ pub enum BlockchainWriteRequest {
#[derive(Debug, Clone, PartialEq, Eq)] #[derive(Debug, Clone, PartialEq, Eq)]
pub enum BlockchainResponse { pub enum BlockchainResponse {
//------------------------------------------------------ Reads //------------------------------------------------------ Reads
/// Response to [`BlockchainReadRequest::Block`].
Block(VerifiedBlockInformation),
/// Response to [`BlockchainReadRequest::BlockByHash`].
BlockByHash(VerifiedBlockInformation),
/// Response to [`BlockchainReadRequest::BlockExtendedHeader`]. /// Response to [`BlockchainReadRequest::BlockExtendedHeader`].
/// ///
/// Inner value is the extended headed of the requested block. /// Inner value is the extended headed of the requested block.