-
Notifications
You must be signed in to change notification settings - Fork 99
chore: Misc followups for block validation #1402
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 all commits
5579f83
7dbaaeb
6c7bfde
e1faced
037bfa1
a6008ff
4ce6db0
4a1535e
6fbed3a
2ac463b
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 |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ use std::sync::Arc; | |
| use futures::FutureExt; | ||
| use futures::never::Never; | ||
| use miden_block_prover::LocalBlockProver; | ||
| use miden_lib::block::build_block; | ||
| use miden_node_utils::tracing::OpenTelemetrySpanExt; | ||
| use miden_objects::MIN_PROOF_SECURITY_LEVEL; | ||
| use miden_objects::batch::{OrderedBatches, ProvenBatch}; | ||
|
|
@@ -27,7 +28,7 @@ use url::Url; | |
| use crate::errors::BuildBlockError; | ||
| use crate::mempool::SharedMempool; | ||
| use crate::store::StoreClient; | ||
| use crate::validator::BlockProducerValidatorClient; | ||
| use crate::validator::{BlockProducerValidatorClient, BodyDiff, HeaderDiff, ValidatorError}; | ||
| use crate::{COMPONENT, TelemetryInjectorExt}; | ||
|
|
||
| // BLOCK BUILDER | ||
|
|
@@ -230,16 +231,43 @@ impl BlockBuilder { | |
| proposed_block: ProposedBlock, | ||
| block_inputs: BlockInputs, | ||
| ) -> Result<(OrderedBatches, BlockInputs, BlockHeader, BlockBody), BuildBlockError> { | ||
| let response = self | ||
| // Concurrently build the block and validate it via the validator. | ||
| let build_result = tokio::task::spawn_blocking({ | ||
| let proposed_block = proposed_block.clone(); | ||
| move || build_block(proposed_block) | ||
| }); | ||
| let (header, body) = self | ||
| .validator | ||
| .validate_block(proposed_block.clone()) | ||
| .sign_block(proposed_block.clone()) | ||
| .await | ||
| .map_err(|err| BuildBlockError::ValidateBlockFailed(err.into()))?; | ||
| let (expected_header, expected_body) = build_result | ||
| .await | ||
| .map_err(BuildBlockError::ValidateBlockFailed)?; | ||
| .map_err(|err| BuildBlockError::other(format!("task join error: {err}")))? | ||
| .map_err(BuildBlockError::ProposeBlockFailed)?; | ||
|
|
||
| // TODO: Check that the returned header and body match the proposed block. | ||
| // Check that the header and body returned from the validator is consistent with the | ||
| // proposed block. | ||
| // TODO(sergerad): Update Eq implementation once signatures are part of the header. | ||
| if header != expected_header { | ||
| let diff = HeaderDiff { | ||
| validator_header: header, | ||
| expected_header, | ||
| } | ||
| .into(); | ||
| return Err(BuildBlockError::ValidateBlockFailed( | ||
| ValidatorError::HeaderMismatch(diff).into(), | ||
| )); | ||
| } | ||
| if body != expected_body { | ||
| let diff = BodyDiff { validator_body: body, expected_body }.into(); | ||
| return Err(BuildBlockError::ValidateBlockFailed( | ||
| ValidatorError::BodyMismatch(diff).into(), | ||
| )); | ||
| } | ||
|
|
||
| let (ordered_batches, ..) = proposed_block.into_parts(); | ||
| Ok((ordered_batches, block_inputs, response.header, response.body)) | ||
| Ok((ordered_batches, block_inputs, header, body)) | ||
| } | ||
|
|
||
| #[instrument(target = COMPONENT, name = "block_builder.prove_block", skip_all, err)] | ||
|
|
@@ -268,13 +296,17 @@ impl BlockBuilder { | |
| body: BlockBody, | ||
| block_proof: BlockProof, | ||
| ) -> Result<ProvenBlock, BuildBlockError> { | ||
| // SAFETY: The header and body are assumed valid and consistent with the proof. | ||
|
Collaborator
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. This
Collaborator
Author
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. Would mean I have to wrap it in a future manually in the call chain, probably prefer to keep it in fn signature? .and_then(|(proposed_block, header, body, block_proof)| async {self.construct_proven_block(proposed_block, header, body, block_proof)})
Collaborator
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. I've done it similarly in the batch builder Though I also did consider just saying screw it and keeping the async. I think its up to you, at the time I thought its worth indicating to the reader that the function is not async (e.g. it stood out to me on reading just the fn now).
Collaborator
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. If you want it to be shorter, you can always leave the tuple in place .and_then(|args| async {self.construct_proven_block(args.0, args.1, args.2, args.3)})Its a pity rust doesn't have a spread operator so one could do |
||
| let proven_block = ProvenBlock::new_unchecked(header, body, block_proof); | ||
| if proven_block.proof_security_level() < MIN_PROOF_SECURITY_LEVEL { | ||
| return Err(BuildBlockError::SecurityLevelTooLow( | ||
| proven_block.proof_security_level(), | ||
| MIN_PROOF_SECURITY_LEVEL, | ||
| )); | ||
| } | ||
| // TODO(sergerad): Consider removing this validation. Once block proving is implemented, | ||
| // this would be replaced with verifying the proof returned from the prover against | ||
| // the block header. | ||
| validate_tx_headers(&proven_block, &ordered_batches.to_transactions())?; | ||
|
|
||
| Ok(proven_block) | ||
|
|
@@ -464,7 +496,7 @@ impl BlockProver { | |
| /// passed in the proposed block. | ||
| /// | ||
| /// This expects that transactions from the proposed block and proven block are in the same | ||
| /// order, as define by [`OrderedTransactionHeaders`]. | ||
| /// order, as defined by [`OrderedTransactionHeaders`]. | ||
| fn validate_tx_headers( | ||
| proven_block: &ProvenBlock, | ||
| proposed_txs: &OrderedTransactionHeaders, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.