Skip to content

Add dedicated functions for reading the blockbody #17522

@mattsse

Description

@mattsse

Describe the feature

we currently only have:

/// Returns the block with given id from the database.
///
/// Returns `None` if block is not found.
fn block(&self, id: BlockHashOrNumber) -> ProviderResult<Option<Self::Block>>;

and

/// Returns the block with matching number from database.
///
/// If the header for this block is not found, this returns `None`.
/// If the header is found, but the transactions either do not exist, or are not indexed, this
/// will return None.
fn block(&self, id: BlockHashOrNumber) -> ProviderResult<Option<Self::Block>> {
if let Some(number) = self.convert_hash_or_number(id)? {
if let Some(header) = self.header_by_number(number)? {
// If the body indices are not found, this means that the transactions either do not
// exist in the database yet, or they do exit but are not indexed.
// If they exist but are not indexed, we don't have enough
// information to return the block anyways, so we return `None`.
let Some(transactions) = self.transactions_by_block(number.into())? else {
return Ok(None)
};
let body = self
.storage
.reader()
.read_block_bodies(self, vec![(&header, transactions)])?
.pop()
.ok_or(ProviderError::InvalidStorageOutput)?;
return Ok(Some(Self::Block::new(header, body)))
}
}
Ok(None)
}

we can add another function dedicated to the blockbody

TODO

  • add trait fn for block_body and impl it accordingly

Additional context

No response

Metadata

Metadata

Assignees

Labels

A-dbRelated to the databaseC-enhancementNew feature or requestD-good-first-issueNice and easy! A great choice to get started

Type

No type

Projects

Status

Backlog

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions