mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-01-29 09:08:05 -05:00
perf(provider): return empty ommers after merge (#3222)
This commit is contained in:
@@ -221,11 +221,11 @@ impl ChainSpec {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the final difficulty if the given block number is after the Paris hardfork.
|
||||
/// Returns the final total difficulty if the given block number is after the Paris hardfork.
|
||||
///
|
||||
/// Note: technically this would also be valid for the block before the paris upgrade, but this
|
||||
/// edge case is omitted here.
|
||||
pub fn final_paris_difficulty(&self, block_number: u64) -> Option<U256> {
|
||||
pub fn final_paris_total_difficulty(&self, block_number: u64) -> Option<U256> {
|
||||
self.paris_block_and_final_difficulty.and_then(|(activated_at, final_difficulty)| {
|
||||
if block_number >= activated_at {
|
||||
Some(final_difficulty)
|
||||
|
||||
@@ -1410,7 +1410,7 @@ impl<'this, TX: DbTx<'this>> HeaderProvider for DatabaseProvider<'this, TX> {
|
||||
}
|
||||
|
||||
fn header_td_by_number(&self, number: BlockNumber) -> Result<Option<U256>> {
|
||||
if let Some(td) = self.chain_spec.final_paris_difficulty(number) {
|
||||
if let Some(td) = self.chain_spec.final_paris_total_difficulty(number) {
|
||||
// if this block is higher than the final paris(merge) block, return the final paris
|
||||
// difficulty
|
||||
return Ok(Some(td))
|
||||
@@ -1505,8 +1505,7 @@ impl<'this, TX: DbTx<'this>> BlockProvider for DatabaseProvider<'this, TX> {
|
||||
if let Some(number) = self.convert_hash_or_number(id)? {
|
||||
if let Some(header) = self.header_by_number(number)? {
|
||||
let withdrawals = self.withdrawals_by_block(number.into(), header.timestamp)?;
|
||||
let ommers = if withdrawals.is_none() { self.ommers(number.into())? } else { None }
|
||||
.unwrap_or_default();
|
||||
let ommers = self.ommers(number.into())?.unwrap_or_default();
|
||||
let transactions = self
|
||||
.transactions_by_block(number.into())?
|
||||
.ok_or(ProviderError::BlockBodyIndicesNotFound(number))?;
|
||||
@@ -1524,7 +1523,12 @@ impl<'this, TX: DbTx<'this>> BlockProvider for DatabaseProvider<'this, TX> {
|
||||
|
||||
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
|
||||
// If the Paris (Merge) hardfork block is known and block is after it, return empty
|
||||
// ommers.
|
||||
if self.chain_spec.final_paris_total_difficulty(number).is_some() {
|
||||
return Ok(Some(Vec::new()))
|
||||
}
|
||||
|
||||
let ommers = self.tx.get::<tables::BlockOmmers>(number)?.map(|o| o.ommers);
|
||||
return Ok(ommers)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user