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 =
|
let latest_header =
|
||||||
self.provider.latest_header()?.ok_or_else(|| ValidationApiError::MissingLatestBlock)?;
|
self.provider.latest_header()?.ok_or_else(|| ValidationApiError::MissingLatestBlock)?;
|
||||||
|
|
||||||
let parent_header = self
|
let parent_header = if block.parent_hash() == latest_header.hash() {
|
||||||
.provider
|
latest_header
|
||||||
.sealed_header_by_hash(block.parent_hash())?
|
} else {
|
||||||
.ok_or_else(|| ValidationApiError::MissingParentBlock)?;
|
// 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
|
||||||
|
{
|
||||||
|
return Err(ValidationApiError::BlockTooOld)
|
||||||
|
}
|
||||||
|
parent_header
|
||||||
|
};
|
||||||
|
|
||||||
if latest_header.number().saturating_sub(parent_header.number()) > self.validation_window {
|
|
||||||
return Err(ValidationApiError::BlockTooOld)
|
|
||||||
}
|
|
||||||
self.consensus.validate_header_against_parent(block.sealed_header(), &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())?;
|
self.validate_gas_limit(registered_gas_limit, &parent_header, block.sealed_header())?;
|
||||||
let parent_header_hash = parent_header.hash();
|
let parent_header_hash = parent_header.hash();
|
||||||
|
|||||||
Reference in New Issue
Block a user