From 024a4aa7ac1a12fc852c00326a432a34e7233c02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9COgnyan?= Date: Thu, 23 Jan 2025 12:09:23 +0200 Subject: [PATCH] feat: disable history validation --- crates/subnetworks/history/src/validation.rs | 196 +++++++++---------- 1 file changed, 94 insertions(+), 102 deletions(-) diff --git a/crates/subnetworks/history/src/validation.rs b/crates/subnetworks/history/src/validation.rs index 4c5d96265..844b27da3 100644 --- a/crates/subnetworks/history/src/validation.rs +++ b/crates/subnetworks/history/src/validation.rs @@ -1,16 +1,6 @@ use std::sync::Arc; -use alloy::primitives::B256; -use anyhow::{anyhow, ensure}; -use ethportal_api::{ - types::execution::{ - block_body::BlockBody, header::Header, header_with_proof::HeaderWithProof, - receipts::Receipts, - }, - utils::bytes::hex_encode, - HistoryContentKey, -}; -use ssz::Decode; +use ethportal_api::HistoryContentKey; use tokio::sync::RwLock; use trin_validation::{ oracle::HeaderOracle, @@ -24,101 +14,103 @@ pub struct ChainHistoryValidator { impl Validator for ChainHistoryValidator { async fn validate_content( &self, - content_key: &HistoryContentKey, - content: &[u8], + _content_key: &HistoryContentKey, + _content: &[u8], ) -> anyhow::Result> { - match content_key { - HistoryContentKey::BlockHeaderByHash(key) => { - let header_with_proof = - HeaderWithProof::from_ssz_bytes(content).map_err(|err| { - anyhow!("Header by hash content has invalid encoding: {err:?}") - })?; - let header_hash = header_with_proof.header.hash(); - ensure!( - header_hash == B256::from(key.block_hash), - "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)?; - - Ok(ValidationResult::new(true)) - } - HistoryContentKey::BlockHeaderByNumber(key) => { - let header_with_proof = - HeaderWithProof::from_ssz_bytes(content).map_err(|err| { - anyhow!("Header by number content has invalid encoding: {err:?}") - })?; - let header_number = header_with_proof.header.number; - ensure!( - header_number == key.block_number, - "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)?; - - Ok(ValidationResult::new(true)) - } - HistoryContentKey::BlockBody(key) => { - let block_body = BlockBody::from_ssz_bytes(content) - .map_err(|msg| anyhow!("Block Body content has invalid encoding: {:?}", msg))?; - let trusted_header: Header = self - .header_oracle - .read() - .await - .recursive_find_header_by_hash_with_proof(B256::from(key.block_hash)) - .await? - .header; - let actual_uncles_root = block_body.uncles_root(); - if actual_uncles_root != trusted_header.uncles_hash { - return Err(anyhow!( - "Content validation failed: Invalid uncles root. Found: {:?} - Expected: {:?}", - actual_uncles_root, - trusted_header.uncles_hash - )); - } - let actual_txs_root = block_body.transactions_root()?; - if actual_txs_root != trusted_header.transactions_root { - return Err(anyhow!( - "Content validation failed: Invalid transactions root. Found: {:?} - Expected: {:?}", - actual_txs_root, - trusted_header.transactions_root - )); - } - Ok(ValidationResult::new(true)) - } - HistoryContentKey::BlockReceipts(key) => { - let receipts = Receipts::from_ssz_bytes(content).map_err(|msg| { - anyhow!("Block Receipts content has invalid encoding: {:?}", msg) - })?; - let trusted_header: Header = self - .header_oracle - .read() - .await - .recursive_find_header_by_hash_with_proof(B256::from(key.block_hash)) - .await? - .header; - let actual_receipts_root = receipts.root()?; - if actual_receipts_root != trusted_header.receipts_root { - return Err(anyhow!( - "Content validation failed: Invalid receipts root. Found: {:?} - Expected: {:?}", - actual_receipts_root, - trusted_header.receipts_root - )); - } - Ok(ValidationResult::new(true)) - } - } + // match content_key { + // HistoryContentKey::BlockHeaderByHash(key) => { + // let header_with_proof = + // HeaderWithProof::from_ssz_bytes(content).map_err(|err| { + // anyhow!("Header by hash content has invalid encoding: {err:?}") + // })?; + // let header_hash = header_with_proof.header.hash(); + // ensure!( + // header_hash == B256::from(key.block_hash), + // "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)?; + // + // Ok(ValidationResult::new(true)) + // } + // HistoryContentKey::BlockHeaderByNumber(key) => { + // let header_with_proof = + // HeaderWithProof::from_ssz_bytes(content).map_err(|err| { + // anyhow!("Header by number content has invalid encoding: {err:?}") + // })?; + // let header_number = header_with_proof.header.number; + // ensure!( + // header_number == key.block_number, + // "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)?; + // + // Ok(ValidationResult::new(true)) + // } + // HistoryContentKey::BlockBody(key) => { + // let block_body = BlockBody::from_ssz_bytes(content) + // .map_err(|msg| anyhow!("Block Body content has invalid encoding: {:?}", + // msg))?; let trusted_header: Header = self + // .header_oracle + // .read() + // .await + // .recursive_find_header_by_hash_with_proof(B256::from(key.block_hash)) + // .await? + // .header; + // let actual_uncles_root = block_body.uncles_root(); + // if actual_uncles_root != trusted_header.uncles_hash { + // return Err(anyhow!( + // "Content validation failed: Invalid uncles root. Found: {:?} - Expected: + // {:?}", actual_uncles_root, + // trusted_header.uncles_hash + // )); + // } + // let actual_txs_root = block_body.transactions_root()?; + // if actual_txs_root != trusted_header.transactions_root { + // return Err(anyhow!( + // "Content validation failed: Invalid transactions root. Found: {:?} - + // Expected: {:?}", actual_txs_root, + // trusted_header.transactions_root + // )); + // } + // Ok(ValidationResult::new(true)) + // } + // HistoryContentKey::BlockReceipts(key) => { + // let receipts = Receipts::from_ssz_bytes(content).map_err(|msg| { + // anyhow!("Block Receipts content has invalid encoding: {:?}", msg) + // })?; + // let trusted_header: Header = self + // .header_oracle + // .read() + // .await + // .recursive_find_header_by_hash_with_proof(B256::from(key.block_hash)) + // .await? + // .header; + // let actual_receipts_root = receipts.root()?; + // if actual_receipts_root != trusted_header.receipts_root { + // return Err(anyhow!( + // "Content validation failed: Invalid receipts root. Found: {:?} - + // Expected: {:?}", actual_receipts_root, + // trusted_header.receipts_root + // )); + // } + // Ok(ValidationResult::new(true)) + // } + // } + Ok(ValidationResult::new(true)) } } +#[cfg(any())] #[cfg(test)] #[allow(clippy::unwrap_used)] mod tests {