-
Notifications
You must be signed in to change notification settings - Fork 87
feat: Add block validation logic against validated transactions (in-memory) #1460
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7c739f3
Add block validation logic
sergerad 461a3db
Update changelog
sergerad e65d0e4
ValidatorServer::new
sergerad 101ffc3
Update changelog PR #
sergerad 36a943a
Merge branch 'next' of github.com:0xMiden/miden-node into sergerad-va…
sergerad 4016a79
RM unnecessary clone
sergerad 8a12ebc
Return error on re-execution failure
sergerad 62fe142
Build block after tx validation
sergerad dce38b6
Use LruCache
sergerad 9bb671f
Update bundled command
sergerad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| use std::sync::Arc; | ||
|
|
||
| use miden_protocol::ProposedBlockError; | ||
| use miden_protocol::block::{BlockNumber, BlockSigner, ProposedBlock}; | ||
| use miden_protocol::crypto::dsa::ecdsa_k256_keccak::Signature; | ||
| use miden_protocol::transaction::TransactionId; | ||
|
|
||
| use crate::server::ValidatedTransactions; | ||
|
|
||
| // BLOCK VALIDATION ERROR | ||
| // ================================================================================================ | ||
|
|
||
| #[derive(thiserror::Error, Debug)] | ||
| pub enum BlockValidationError { | ||
| #[error("transaction {0} in block {1} has not been validated")] | ||
| TransactionNotValidated(TransactionId, BlockNumber), | ||
| #[error("failed to build block")] | ||
| BlockBuildingFailed(#[from] ProposedBlockError), | ||
| } | ||
|
|
||
| // BLOCK VALIDATION | ||
| // ================================================================================================ | ||
|
|
||
| /// Validates a block by checking that all transactions in the proposed block have been processed by | ||
| /// the validator in the past. | ||
| /// | ||
| /// Removes the validated transactions from the cache upon success. | ||
| pub async fn validate_block<S: BlockSigner>( | ||
| proposed_block: ProposedBlock, | ||
| signer: &S, | ||
| validated_transactions: Arc<ValidatedTransactions>, | ||
| ) -> Result<Signature, BlockValidationError> { | ||
| // Check that all transactions in the proposed block have been validated | ||
| for tx_header in proposed_block.transactions() { | ||
| let tx_id = tx_header.id(); | ||
| if validated_transactions.get(&tx_id).await.is_none() { | ||
| return Err(BlockValidationError::TransactionNotValidated( | ||
| tx_id, | ||
| proposed_block.block_num(), | ||
| )); | ||
| } | ||
| } | ||
|
|
||
| // Build the block header. | ||
| let (header, _) = proposed_block.into_header_and_body()?; | ||
|
|
||
| // Sign the header. | ||
| let signature = signer.sign(&header); | ||
|
|
||
| Ok(signature) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| mod block_validation; | ||
| mod server; | ||
| mod tx_validation; | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Let's bump this up to 10K transactions.