mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
perf: only fetch parent if not latest (#14412)
This commit is contained in:
@ -139,14 +139,23 @@ where
|
||||
let latest_header =
|
||||
self.provider.latest_header()?.ok_or_else(|| ValidationApiError::MissingLatestBlock)?;
|
||||
|
||||
let parent_header = if block.parent_hash() == latest_header.hash() {
|
||||
latest_header
|
||||
} else {
|
||||
// parent is not the latest header so we need to fetch it and ensure it's not too old
|
||||
let parent_header = self
|
||||
.provider
|
||||
.sealed_header_by_hash(block.parent_hash())?
|
||||
.ok_or_else(|| ValidationApiError::MissingParentBlock)?;
|
||||
|
||||
if latest_header.number().saturating_sub(parent_header.number()) > self.validation_window {
|
||||
if latest_header.number().saturating_sub(parent_header.number()) >
|
||||
self.validation_window
|
||||
{
|
||||
return Err(ValidationApiError::BlockTooOld)
|
||||
}
|
||||
parent_header
|
||||
};
|
||||
|
||||
self.consensus.validate_header_against_parent(block.sealed_header(), &parent_header)?;
|
||||
self.validate_gas_limit(registered_gas_limit, &parent_header, block.sealed_header())?;
|
||||
let parent_header_hash = parent_header.hash();
|
||||
|
||||
Reference in New Issue
Block a user