Skip to content

Commit aa28ed4

Browse files
committed
feat: enable post-capella HistoricalSummary Header validation
1 parent b80d992 commit aa28ed4

File tree

8 files changed

+234
-119
lines changed

8 files changed

+234
-119
lines changed

Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bin/e2hs-writer/src/reader.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ impl EpochReader {
7676
Some(Arc::new(
7777
lookup_epoch_acc(
7878
epoch_index,
79-
&HeaderValidator::new().pre_merge_acc,
79+
&HeaderValidator::new_without_historical_summaries().pre_merge_acc,
8080
&epoch_acc_path,
8181
)
8282
.await?,

bin/portal-bridge/src/bridge/e2hs.rs

+17-6
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ use e2store::{
1515
};
1616
use ethportal_api::{
1717
types::{
18-
execution::header_with_proof::HeaderWithProof, network::Subnetwork, portal_wire::OfferTrace,
18+
execution::header_with_proof::{BlockHeaderProof, HeaderWithProof},
19+
network::Subnetwork,
20+
portal_wire::OfferTrace,
1921
},
2022
BlockBody, ContentValue, HistoryContentKey, HistoryContentValue, OverlayContentKey,
2123
RawContentValue, Receipts,
@@ -95,7 +97,7 @@ impl E2HSBridge {
9597
Ok(Self {
9698
gossiper,
9799
block_semaphore,
98-
header_validator: HeaderValidator::new(),
100+
header_validator: HeaderValidator::new_without_historical_summaries(),
99101
block_range,
100102
random_fill,
101103
e2hs_files,
@@ -171,7 +173,7 @@ impl E2HSBridge {
171173
continue;
172174
}
173175
}
174-
if let Err(err) = self.validate_block_tuple(&block_tuple) {
176+
if let Err(err) = self.validate_block_tuple(&block_tuple).await {
175177
error!("Failed to validate block tuple: {err:?}");
176178
continue;
177179
}
@@ -206,10 +208,19 @@ impl E2HSBridge {
206208
.unwrap_or_else(|err| panic!("unable to read e2hs file at path: {e2hs_path:?} : {err}"))
207209
}
208210

209-
fn validate_block_tuple(&self, block_tuple: &BlockTuple) -> anyhow::Result<()> {
211+
async fn validate_block_tuple(&self, block_tuple: &BlockTuple) -> anyhow::Result<()> {
210212
let header_with_proof = &block_tuple.header_with_proof.header_with_proof;
211-
self.header_validator
212-
.validate_header_with_proof(header_with_proof)?;
213+
// The E2HS bridge doesn't have access to a provider so it can't validate historical summary
214+
// Header with Proofs
215+
if !matches!(
216+
header_with_proof.proof,
217+
BlockHeaderProof::HistoricalSummariesCapella(_)
218+
| BlockHeaderProof::HistoricalSummariesDeneb(_)
219+
) {
220+
self.header_validator
221+
.validate_header_with_proof(header_with_proof)
222+
.await?;
223+
}
213224
let body = &block_tuple.body.body;
214225
body.validate_against_header(&header_with_proof.header)?;
215226
let receipts = &block_tuple.receipts.receipts;

bin/trin/src/run.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use std::{net::SocketAddr, path::PathBuf, sync::Arc};
22

33
use ethportal_api::{
44
types::{distance::Distance, network::Subnetwork},
5-
utils::bytes::hex_encode,
65
version::get_trin_version,
76
};
87
use portalnet::{
@@ -14,7 +13,6 @@ use portalnet::{
1413
use rpc::{config::RpcConfig, launch_jsonrpc_server, RpcServerHandle};
1514
use tokio::sync::{mpsc, RwLock};
1615
use tracing::info;
17-
use tree_hash::TreeHash;
1816
use trin_beacon::initialize_beacon_network;
1917
use trin_history::initialize_history_network;
2018
use trin_state::initialize_state_network;
@@ -121,12 +119,7 @@ async fn run_trin_internal(
121119
}
122120

123121
// Initialize validation oracle
124-
let header_oracle = HeaderOracle::default();
125-
info!(
126-
hash_tree_root = %hex_encode(header_oracle.header_validator.pre_merge_acc.tree_hash_root().0),
127-
"Loaded pre-merge accumulator."
128-
);
129-
let header_oracle = Arc::new(RwLock::new(header_oracle));
122+
let header_oracle = Arc::new(RwLock::new(HeaderOracle::default()));
130123

131124
// Initialize and spawn uTP socket
132125
let (utp_talk_reqs_tx, utp_talk_reqs_rx) = mpsc::unbounded_channel();

crates/subnetworks/history/src/validation.rs

+21-11
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,32 @@ use ethportal_api::{
1111
};
1212
use ssz::Decode;
1313
use tokio::sync::RwLock;
14+
use tracing::info;
15+
use tree_hash::TreeHash;
1416
use trin_validation::{
17+
header_validator::{HeaderValidator, HistoricalSummariesProvider, HistoricalSummariesSource},
1518
oracle::HeaderOracle,
1619
validator::{ValidationResult, Validator},
1720
};
1821

1922
pub struct ChainHistoryValidator {
2023
pub header_oracle: Arc<RwLock<HeaderOracle>>,
24+
pub header_validator: HeaderValidator,
2125
}
2226

2327
impl ChainHistoryValidator {
2428
pub fn new(header_oracle: Arc<RwLock<HeaderOracle>>) -> Self {
25-
Self { header_oracle }
29+
let header_validator = HeaderValidator::new(HistoricalSummariesProvider::new(
30+
HistoricalSummariesSource::HeaderOracle(header_oracle.clone()),
31+
));
32+
info!(
33+
hash_tree_root = %header_validator.pre_merge_acc.tree_hash_root(),
34+
"Loaded pre-merge accumulator."
35+
);
36+
Self {
37+
header_oracle,
38+
header_validator,
39+
}
2640
}
2741
}
2842

@@ -44,11 +58,9 @@ impl Validator<HistoryContentKey> for ChainHistoryValidator {
4458
"Content validation failed: Invalid header hash. Found: {header_hash:?} - Expected: {:?}",
4559
hex_encode(header_hash)
4660
);
47-
self.header_oracle
48-
.read()
49-
.await
50-
.header_validator
51-
.validate_header_with_proof(&header_with_proof)?;
61+
self.header_validator
62+
.validate_header_with_proof(&header_with_proof)
63+
.await?;
5264

5365
Ok(ValidationResult::new(true))
5466
}
@@ -63,11 +75,9 @@ impl Validator<HistoryContentKey> for ChainHistoryValidator {
6375
"Content validation failed: Invalid header number. Found: {header_number} - Expected: {}",
6476
key.block_number
6577
);
66-
self.header_oracle
67-
.read()
68-
.await
69-
.header_validator
70-
.validate_header_with_proof(&header_with_proof)?;
78+
self.header_validator
79+
.validate_header_with_proof(&header_with_proof)
80+
.await?;
7181

7282
Ok(ValidationResult::new(true))
7383
}

crates/validation/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ serde.workspace = true
2626
serde_json.workspace = true
2727
ssz_types.workspace = true
2828
tokio.workspace = true
29+
tracing.workspace = true
2930
tree_hash.workspace = true
3031
tree_hash_derive.workspace = true
3132

0 commit comments

Comments
 (0)