diff --git a/crates/primitives/src/chain/spec.rs b/crates/primitives/src/chain/spec.rs index a3a0f06fe5..3ea29f0f29 100644 --- a/crates/primitives/src/chain/spec.rs +++ b/crates/primitives/src/chain/spec.rs @@ -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 { + pub fn final_paris_total_difficulty(&self, block_number: u64) -> Option { self.paris_block_and_final_difficulty.and_then(|(activated_at, final_difficulty)| { if block_number >= activated_at { Some(final_difficulty) diff --git a/crates/storage/provider/src/providers/database/provider.rs b/crates/storage/provider/src/providers/database/provider.rs index e24d467042..d4d3f332a1 100644 --- a/crates/storage/provider/src/providers/database/provider.rs +++ b/crates/storage/provider/src/providers/database/provider.rs @@ -1410,7 +1410,7 @@ impl<'this, TX: DbTx<'this>> HeaderProvider for DatabaseProvider<'this, TX> { } fn header_td_by_number(&self, number: BlockNumber) -> Result> { - 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>> { 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::(number)?.map(|o| o.ommers); return Ok(ommers) }