Move attestation validation into iter.for_each
This commit is contained in:
parent
a8b08fb300
commit
debc642b50
@ -1,4 +1,7 @@
|
|||||||
use std::sync::Arc;
|
use std::sync::{
|
||||||
|
Arc,
|
||||||
|
RwLock,
|
||||||
|
};
|
||||||
use super::attestation_record::{
|
use super::attestation_record::{
|
||||||
validate_attestation,
|
validate_attestation,
|
||||||
AttestationValidationError,
|
AttestationValidationError,
|
||||||
@ -170,22 +173,44 @@ pub fn validate_ssz_block<T>(b: &SszBlock,
|
|||||||
*
|
*
|
||||||
* TODO: make this parallelized.
|
* TODO: make this parallelized.
|
||||||
*/
|
*/
|
||||||
for attestation in other_attestations {
|
let failure: Option<SszBlockValidationError> = None;
|
||||||
let (a, _) = AttestationRecord::ssz_decode(&attestation, 0)?;
|
let failure = RwLock::new(failure);
|
||||||
let attestation_voters = validate_attestation(
|
other_attestations.iter()
|
||||||
&a,
|
.for_each(|attestation| {
|
||||||
block_slot,
|
if let Some(_) = *failure.read().unwrap() {
|
||||||
cycle_length,
|
()
|
||||||
last_justified_slot,
|
};
|
||||||
&parent_hashes,
|
match AttestationRecord::ssz_decode(&attestation, 0) {
|
||||||
&block_store,
|
Ok((a, _)) => {
|
||||||
&validator_store,
|
let result = validate_attestation(
|
||||||
&attester_map)?;
|
&a,
|
||||||
if attestation_voters.is_none() {
|
block_slot,
|
||||||
return Err(SszBlockValidationError::
|
cycle_length,
|
||||||
AttestationSignatureFailed);
|
last_justified_slot,
|
||||||
}
|
&parent_hashes,
|
||||||
}
|
&block_store,
|
||||||
|
&validator_store,
|
||||||
|
&attester_map);
|
||||||
|
match result {
|
||||||
|
Err(e) => {
|
||||||
|
let mut failure = failure.write().unwrap();
|
||||||
|
*failure = Some(SszBlockValidationError::from(e));
|
||||||
|
}
|
||||||
|
Ok(None) => {
|
||||||
|
let mut failure = failure.write().unwrap();
|
||||||
|
*failure = Some(SszBlockValidationError::AttestationSignatureFailed);
|
||||||
|
}
|
||||||
|
_ => ()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
let mut failure = failure.write().unwrap();
|
||||||
|
*failure = Some(SszBlockValidationError::from(e));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
// TODO: handle validation failure. Presently, it will just pass everything
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If we have reached this point, the block is a new valid block that is worthy of
|
* If we have reached this point, the block is a new valid block that is worthy of
|
||||||
|
Loading…
Reference in New Issue
Block a user