-
Notifications
You must be signed in to change notification settings - Fork 52
Stm error handling with anyhow #2765
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: main
Are you sure you want to change the base?
Conversation
Test Results 4 files ±0 168 suites ±0 22m 18s ⏱️ -38s Results for commit a1ee8c1. ± Comparison against base commit 2ad7d5e. This pull request removes 12 and adds 15 tests. Note that renamed tests count towards both.♻️ This comment has been updated with latest results. |
| impl TryFromBytes for SingleSignature { | ||
| fn try_from_bytes(bytes: &[u8]) -> StdResult<Self> { | ||
| Self::from_bytes::<D>(bytes).map_err(|e| e.into()) | ||
| Self::from_bytes::<D>(bytes).map_err(|e| anyhow!(e)) |
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.
This should be enough here and in other occurrences in this module:
| Self::from_bytes::<D>(bytes).map_err(|e| anyhow!(e)) | |
| Self::from_bytes::<D>(bytes) |
| Err(error) => assert!( | ||
| matches!( | ||
| error.downcast_ref::<AggregationError>(), | ||
| Some(AggregationError::NotEnoughSignatures { .. }) | ||
| | Some(AggregationError::UsizeConversionInvalid) | ||
| | Some(AggregationError::UnsupportedProofSystem { .. }) | ||
| ), | ||
| "Unexpected error: {error}" | ||
| ), |
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.
We miss all the prints and additional asserts which were there before, maybe this is a bit better:
| Err(error) => assert!( | |
| matches!( | |
| error.downcast_ref::<AggregationError>(), | |
| Some(AggregationError::NotEnoughSignatures { .. }) | |
| | Some(AggregationError::UsizeConversionInvalid) | |
| | Some(AggregationError::UnsupportedProofSystem { .. }) | |
| ), | |
| "Unexpected error: {error}" | |
| ), | |
| Err(error) => match error.downcast_ref::<AggregationError>() { | |
| Some(AggregationError::NotEnoughSignatures(n, k)) => { | |
| println!("Not enough signatures"); | |
| assert!(n < params.k && k == params.k) | |
| }, | |
| Some(AggregationError::UsizeConversionInvalid) => { | |
| println!("Invalid usize conversion"); | |
| }, | |
| Some(AggregationError::UnsupportedProofSystem(aggregate_signature_type)) => { | |
| println!("Unsupported proof system: {:?}", aggregate_signature_type); | |
| }, | |
| None => { | |
| println!("Unexpected error during aggregation: {:?}", error); | |
| } | |
| }, |
|
|
||
| BlsSignature::verify_aggregate(msg.to_vec().as_slice(), &vks, &sigs)?; | ||
| BlsSignature::verify_aggregate(msg.to_vec().as_slice(), &vks, &sigs) | ||
| .with_context(|| "Basic verifier failed in multisignature verification.")?; |
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.
Maybe this is a bit more clear:
| .with_context(|| "Basic verifier failed in multisignature verification.")?; | |
| .with_context(|| "Basic verifier failed during BLS aggregate signature verification.")?; |
| unreachable!(), | ||
| Err(AggregationError::UnsupportedProofSystem(_)) => | ||
| unreachable!(), | ||
| Err(error) => { assert!( |
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.
Same comment as above about missing asserts?
| .with_context( | ||
| || "Failed to aggregate unique signatures during selection for the k indices.", |
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.
This would be more clear, WDYT?
| .with_context( | |
| || "Failed to aggregate unique signatures during selection for the k indices.", | |
| .with_context( | |
| || "There are not enough signatures to reach the quorum", |
| Err(RegisterError::KeyInvalid(a)) => { | ||
| assert_eq!(fake_it, 0); | ||
| assert!(a.verify_proof_of_possession().is_err()); | ||
| Err(error) => { assert!( |
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.
Same remark here for the missing assertions.
| Err(error) => assert!( | ||
| matches!( | ||
| error.downcast_ref::<AggregationError>(), | ||
| Some(AggregationError::NotEnoughSignatures { .. }) | ||
| ), | ||
| "Unexpected error: {error}" | ||
| ), |
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.
Same remark for missing asserts
| Err(error) => assert!( | ||
| matches!( | ||
| error.downcast_ref::<AggregationError>(), | ||
| Some(AggregationError::NotEnoughSignatures { .. }) | ||
| | Some(AggregationError::UsizeConversionInvalid) | ||
| | Some(AggregationError::UnsupportedProofSystem { .. }) | ||
| ), | ||
| "Unexpected error: {error}" | ||
| ), |
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.
Same remark for missing asserts
Content
This PR includes the changes needed to adapt the error handling of
mithril-stmto the best practices described here.Pre-submit checklist
Comments
TODO: Remove unused/unnecessary error types.
Issue(s)
Relates to #2764