-
Notifications
You must be signed in to change notification settings - Fork 145
feat: enable post-capella HistoricalSummary Header validation #1774
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,9 @@ use e2store::{ | |
}; | ||
use ethportal_api::{ | ||
types::{ | ||
execution::header_with_proof::HeaderWithProof, network::Subnetwork, portal_wire::OfferTrace, | ||
execution::header_with_proof::{BlockHeaderProof, HeaderWithProof}, | ||
network::Subnetwork, | ||
portal_wire::OfferTrace, | ||
}, | ||
BlockBody, ContentValue, HistoryContentKey, HistoryContentValue, OverlayContentKey, | ||
RawContentValue, Receipts, | ||
|
@@ -95,7 +97,7 @@ impl E2HSBridge { | |
Ok(Self { | ||
gossiper, | ||
block_semaphore, | ||
header_validator: HeaderValidator::new(), | ||
header_validator: HeaderValidator::new_without_historical_summaries(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't we use the logic from #1777 and fetch historical summaries before we start gossiping? HistoricalSummaries fetched at the start of the bridge should be sufficient for all content that we want to gossip, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Me and Milos talked and this concern will be dealt with in a followup PR |
||
block_range, | ||
random_fill, | ||
e2hs_files, | ||
|
@@ -171,7 +173,7 @@ impl E2HSBridge { | |
continue; | ||
} | ||
} | ||
if let Err(err) = self.validate_block_tuple(&block_tuple) { | ||
if let Err(err) = self.validate_block_tuple(&block_tuple).await { | ||
error!("Failed to validate block tuple: {err:?}"); | ||
continue; | ||
} | ||
|
@@ -206,10 +208,19 @@ impl E2HSBridge { | |
.unwrap_or_else(|err| panic!("unable to read e2hs file at path: {e2hs_path:?} : {err}")) | ||
} | ||
|
||
fn validate_block_tuple(&self, block_tuple: &BlockTuple) -> anyhow::Result<()> { | ||
async fn validate_block_tuple(&self, block_tuple: &BlockTuple) -> anyhow::Result<()> { | ||
let header_with_proof = &block_tuple.header_with_proof.header_with_proof; | ||
self.header_validator | ||
.validate_header_with_proof(header_with_proof)?; | ||
// The E2HS bridge doesn't have access to a provider so it can't validate historical summary | ||
// Header with Proofs | ||
if !matches!( | ||
header_with_proof.proof, | ||
BlockHeaderProof::HistoricalSummariesCapella(_) | ||
| BlockHeaderProof::HistoricalSummariesDeneb(_) | ||
) { | ||
self.header_validator | ||
.validate_header_with_proof(header_with_proof) | ||
.await?; | ||
} | ||
let body = &block_tuple.body.body; | ||
body.validate_against_header(&header_with_proof.header)?; | ||
let receipts = &block_tuple.receipts.receipts; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,18 +11,32 @@ use ethportal_api::{ | |
}; | ||
use ssz::Decode; | ||
use tokio::sync::RwLock; | ||
use tracing::info; | ||
use tree_hash::TreeHash; | ||
use trin_validation::{ | ||
header_validator::{HeaderValidator, HistoricalSummariesProvider, HistoricalSummariesSource}, | ||
oracle::HeaderOracle, | ||
validator::{ValidationResult, Validator}, | ||
}; | ||
|
||
pub struct ChainHistoryValidator { | ||
pub header_oracle: Arc<RwLock<HeaderOracle>>, | ||
pub header_validator: HeaderValidator, | ||
} | ||
|
||
impl ChainHistoryValidator { | ||
pub fn new(header_oracle: Arc<RwLock<HeaderOracle>>) -> Self { | ||
Self { header_oracle } | ||
let header_validator = HeaderValidator::new(HistoricalSummariesProvider::new( | ||
HistoricalSummariesSource::HeaderOracle(header_oracle.clone()), | ||
)); | ||
info!( | ||
hash_tree_root = %header_validator.pre_merge_acc.tree_hash_root(), | ||
"Loaded pre-merge accumulator." | ||
); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: This should probably be in |
||
Self { | ||
header_oracle, | ||
header_validator, | ||
} | ||
} | ||
} | ||
|
||
|
@@ -44,11 +58,9 @@ impl Validator<HistoryContentKey> for ChainHistoryValidator { | |
"Content validation failed: Invalid header hash. Found: {header_hash:?} - Expected: {:?}", | ||
hex_encode(header_hash) | ||
); | ||
self.header_oracle | ||
.read() | ||
.await | ||
.header_validator | ||
.validate_header_with_proof(&header_with_proof)?; | ||
self.header_validator | ||
.validate_header_with_proof(&header_with_proof) | ||
.await?; | ||
|
||
Ok(ValidationResult::new(true)) | ||
} | ||
|
@@ -63,11 +75,9 @@ impl Validator<HistoryContentKey> for ChainHistoryValidator { | |
"Content validation failed: Invalid header number. Found: {header_number} - Expected: {}", | ||
key.block_number | ||
); | ||
self.header_oracle | ||
.read() | ||
.await | ||
.header_validator | ||
.validate_header_with_proof(&header_with_proof)?; | ||
self.header_validator | ||
.validate_header_with_proof(&header_with_proof) | ||
.await?; | ||
|
||
Ok(ValidationResult::new(true)) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems that we are creating
HeaderValidator
just to reference defaultPreMergeAccumulator
. Why not usePreMergeAccumulator::default()
directly?