feat: add util function for fetching tagged headers (#3097)

This commit is contained in:
Matthias Seitz
2023-06-12 07:58:39 +02:00
committed by GitHub
parent 1ee8f6ff30
commit 5b0536bd7b
6 changed files with 32 additions and 26 deletions

View File

@ -184,10 +184,6 @@ impl<DB: Database> BlockProvider for ShareableDatabase<DB> {
self.provider()?.pending_block()
}
fn pending_header(&self) -> Result<Option<SealedHeader>> {
self.provider()?.pending_header()
}
fn ommers(&self, id: BlockHashOrNumber) -> Result<Option<Vec<Header>>> {
self.provider()?.ommers(id)
}

View File

@ -206,10 +206,6 @@ impl<'this, TX: DbTx<'this>> BlockProvider for DatabaseProvider<'this, TX> {
Ok(None)
}
fn pending_header(&self) -> Result<Option<SealedHeader>> {
Ok(None)
}
fn ommers(&self, id: BlockHashOrNumber) -> Result<Option<Vec<Header>>> {
if let Some(number) = self.convert_hash_or_number(id)? {
// TODO: this can be optimized to return empty Vec post-merge

View File

@ -230,10 +230,6 @@ where
Ok(self.tree.pending_block())
}
fn pending_header(&self) -> Result<Option<SealedHeader>> {
Ok(self.tree.pending_header())
}
fn ommers(&self, id: BlockHashOrNumber) -> Result<Option<Vec<Header>>> {
self.database.provider()?.ommers(id)
}

View File

@ -306,10 +306,6 @@ impl BlockProvider for MockEthProvider {
Ok(None)
}
fn pending_header(&self) -> Result<Option<SealedHeader>> {
Ok(None)
}
fn ommers(&self, _id: BlockHashOrNumber) -> Result<Option<Vec<Header>>> {
Ok(None)
}

View File

@ -62,10 +62,6 @@ impl BlockProvider for NoopProvider {
Ok(None)
}
fn pending_header(&self) -> Result<Option<SealedHeader>> {
Ok(None)
}
fn ommers(&self, _id: BlockHashOrNumber) -> Result<Option<Vec<Header>>> {
Ok(None)
}

View File

@ -64,12 +64,6 @@ pub trait BlockProvider:
/// and the caller does not know the hash.
fn pending_block(&self) -> Result<Option<SealedBlock>>;
/// Returns the pending block header if available
///
/// Note: This returns a [SealedHeader] because it's expected that this is sealed by the
/// provider and the caller does not know the hash.
fn pending_header(&self) -> Result<Option<SealedHeader>>;
/// Returns the ommers/uncle headers of the given block from the database.
///
/// Returns `None` if block is not found.
@ -114,6 +108,38 @@ pub trait BlockProviderIdExt: BlockProvider + BlockIdProvider {
self.convert_block_number(id)?.map_or_else(|| Ok(None), |num| self.block(num.into()))
}
/// Returns the pending block header if available
///
/// Note: This returns a [SealedHeader] because it's expected that this is sealed by the
/// provider and the caller does not know the hash.
fn pending_header(&self) -> Result<Option<SealedHeader>> {
self.sealed_header_by_id(BlockNumberOrTag::Pending.into())
}
/// Returns the latest block header if available
///
/// Note: This returns a [SealedHeader] because it's expected that this is sealed by the
/// provider and the caller does not know the hash.
fn latest_header(&self) -> Result<Option<SealedHeader>> {
self.sealed_header_by_id(BlockNumberOrTag::Latest.into())
}
/// Returns the safe block header if available
///
/// Note: This returns a [SealedHeader] because it's expected that this is sealed by the
/// provider and the caller does not know the hash.
fn safe_header(&self) -> Result<Option<SealedHeader>> {
self.sealed_header_by_id(BlockNumberOrTag::Safe.into())
}
/// Returns the finalized block header if available
///
/// Note: This returns a [SealedHeader] because it's expected that this is sealed by the
/// provider and the caller does not know the hash.
fn finalized_header(&self) -> Result<Option<SealedHeader>> {
self.sealed_header_by_id(BlockNumberOrTag::Finalized.into())
}
/// Returns the block with the matching `BlockId` from the database.
///
/// Returns `None` if block is not found.