-
Notifications
You must be signed in to change notification settings - Fork 175
Celestia: re-add block verification #2764
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
base: dev
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| #[cfg(test)] | ||
| mod tests; | ||
|
|
||
| pub use crate::config::CelestiaConfig; | ||
| pub use crate::config::{CelestiaConfig, VerifyOnFetchMode}; | ||
| use crate::metrics::client::{ | ||
| BlobGetAllMeasurement, GetBlockHeaderMeasurement, GetChainHeadMeasurement, | ||
| GetNamespaceDataMeasurement, HeaderSyncStateMeasurement, StateBalanceForAddressMeasurement, | ||
|
|
@@ -28,7 +28,9 @@ use celestia_types::nmt::Namespace; | |
| use futures::stream::BoxStream; | ||
| use futures::StreamExt; | ||
| use sov_rollup_interface::common::HexHash; | ||
| use sov_rollup_interface::da::{DaProof, DaSpec, RelevantBlobs, RelevantProofs}; | ||
| use sov_rollup_interface::da::{ | ||
| BlobReaderTrait, DaProof, DaSpec, DaVerifier, RelevantBlobs, RelevantProofs, | ||
| }; | ||
| use sov_rollup_interface::node::da::{ | ||
| run_maybe_retryable_async_fn_with_retries, DaService, MaybeRetryable, SubmitBlobReceipt, | ||
| }; | ||
|
|
@@ -45,6 +47,7 @@ pub struct CelestiaService { | |
| client: Arc<celestia_client::Client>, | ||
| rollup_batch_namespace: Namespace, | ||
| rollup_proof_namespace: Namespace, | ||
| verify_on_fetch_mode: VerifyOnFetchMode, | ||
| signer_address: Option<CelestiaAddress>, | ||
| safe_lead_time: Duration, | ||
| backoff_policy: ExponentialBuilder, | ||
|
|
@@ -54,10 +57,12 @@ pub struct CelestiaService { | |
| } | ||
|
|
||
| impl CelestiaService { | ||
| #[allow(clippy::too_many_arguments)] | ||
| fn with_client( | ||
| client: celestia_client::Client, | ||
| rollup_batch_namespace: Namespace, | ||
| rollup_proof_namespace: Namespace, | ||
| verify_on_fetch_mode: VerifyOnFetchMode, | ||
| signer_address: Option<CelestiaAddress>, | ||
| safe_lead_time: Duration, | ||
| backoff_policy: ExponentialBuilder, | ||
|
|
@@ -69,6 +74,7 @@ impl CelestiaService { | |
| client: Arc::new(client), | ||
| rollup_batch_namespace, | ||
| rollup_proof_namespace, | ||
| verify_on_fetch_mode, | ||
| signer_address, | ||
| safe_lead_time, | ||
| backoff_policy, | ||
|
|
@@ -231,6 +237,7 @@ impl CelestiaService { | |
| client, | ||
| chain_params.rollup_batch_namespace, | ||
| chain_params.rollup_proof_namespace, | ||
| config.verify_on_fetch_mode, | ||
| fetched_signer, | ||
| Duration::from_millis(config.safe_lead_time_ms), | ||
| backoff_policy, | ||
|
|
@@ -356,7 +363,28 @@ impl CelestiaService { | |
| tracker.submit(get_block_measurement); | ||
| }); | ||
| tracing::trace!(height, "get_block_at metrics send, returning"); | ||
| FilteredCelestiaBlock::new(rollup_batch_shares, rollup_proof_shares, header) | ||
| let block = FilteredCelestiaBlock::new(rollup_batch_shares, rollup_proof_shares, header)?; | ||
| match self.verify_on_fetch_mode { | ||
| VerifyOnFetchMode::Off => {} | ||
| VerifyOnFetchMode::LogError => { | ||
| if let Err(error) = self.verify_block_integrity(&block) { | ||
| tracing::error!( | ||
| height, | ||
| ?error, | ||
| "Celestia block integrity verification failed; continuing because \ | ||
| verify_on_fetch_mode is `log_error`" | ||
| ); | ||
| } | ||
|
citizen-stig marked this conversation as resolved.
|
||
| } | ||
| VerifyOnFetchMode::ReturnError => { | ||
| self.verify_block_integrity(&block).map_err(|error| { | ||
| anyhow::anyhow!( | ||
| "Celestia block integrity verification failed at height {height}: {error}" | ||
| ) | ||
| })?; | ||
| } | ||
|
Comment on lines
+379
to
+385
Contributor
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. 📝 Info: ReturnError mode double-wraps the error, losing the anyhow chain At Was this helpful? React with 👍 or 👎 to provide feedback. |
||
| } | ||
| Ok(block) | ||
| } | ||
|
|
||
| async fn get_head_block_header_inner( | ||
|
|
@@ -423,6 +451,28 @@ impl CelestiaService { | |
| .map(|res| res.map(CelestiaHeader::from).map_err(|e| e.into())) | ||
| .boxed()) | ||
| } | ||
|
|
||
| fn verify_block_integrity(&self, block: &FilteredCelestiaBlock) -> anyhow::Result<()> { | ||
| let verifier = CelestiaVerifier::new(RollupParams { | ||
| rollup_batch_namespace: self.rollup_batch_namespace, | ||
| rollup_proof_namespace: self.rollup_proof_namespace, | ||
| }); | ||
|
|
||
| let mut relevant_blobs = extract_relevant_blobs(block); | ||
| // Advance full blob data first, then derive proofs for the consumed ranges. | ||
| for blob in relevant_blobs | ||
| .batch_blobs | ||
| .iter_mut() | ||
| .chain(relevant_blobs.proof_blobs.iter_mut()) | ||
| { | ||
| blob.advance(blob.total_len()); | ||
| } | ||
| let relevant_proofs = get_extraction_proof(block, &relevant_blobs); | ||
|
|
||
| verifier.verify_relevant_tx_list(&block.header, &relevant_blobs, relevant_proofs)?; | ||
|
|
||
| Ok(()) | ||
| } | ||
| } | ||
|
|
||
| #[async_trait] | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.