Merge branch 'block_processing' into validate_block
This commit is contained in:
commit
5034089398
@ -6,10 +6,10 @@ pub const MIN_SSZ_ATTESTION_RECORD_LENGTH: usize = {
|
|||||||
8 + // slot
|
8 + // slot
|
||||||
2 + // shard_id
|
2 + // shard_id
|
||||||
4 + // oblique_parent_hashes (empty list)
|
4 + // oblique_parent_hashes (empty list)
|
||||||
4 + 32 + // shard_block_hash
|
32 + // shard_block_hash
|
||||||
5 + // attester_bitfield (assuming 1 byte of bitfield)
|
5 + // attester_bitfield (assuming 1 byte of bitfield)
|
||||||
8 + // justified_slot
|
8 + // justified_slot
|
||||||
4 + 32 + // justified_block_hash
|
32 + // justified_block_hash
|
||||||
4 + (2 * 32) // aggregate sig (two 256 bit points)
|
4 + (2 * 32) // aggregate sig (two 256 bit points)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -3,13 +3,13 @@ use super::attestation_record::AttestationRecord;
|
|||||||
use super::ssz::{ Encodable, SszStream };
|
use super::ssz::{ Encodable, SszStream };
|
||||||
|
|
||||||
pub const MIN_SSZ_BLOCK_LENGTH: usize = {
|
pub const MIN_SSZ_BLOCK_LENGTH: usize = {
|
||||||
4 + 32 + // parent_hash
|
32 + // parent_hash
|
||||||
8 + // slot_number
|
8 + // slot_number
|
||||||
4 + 32 + // randao_reveal
|
32 + // randao_reveal
|
||||||
4 + // attestations (assuming zero)
|
4 + // attestations (assuming zero)
|
||||||
4 + 32 + // pow_chain_ref
|
32 + // pow_chain_ref
|
||||||
4 + 32 + // active_state_root
|
32 + // active_state_root
|
||||||
4 + 32 // crystallized_state_root
|
32 // crystallized_state_root
|
||||||
};
|
};
|
||||||
pub const MAX_SSZ_BLOCK_LENGTH: usize = MIN_SSZ_BLOCK_LENGTH + (1 << 24);
|
pub const MAX_SSZ_BLOCK_LENGTH: usize = MIN_SSZ_BLOCK_LENGTH + (1 << 24);
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ impl<'a> SszBlock<'a> {
|
|||||||
/*
|
/*
|
||||||
* Determine how many bytes are used to store attestation records.
|
* Determine how many bytes are used to store attestation records.
|
||||||
*/
|
*/
|
||||||
let attestation_len = decode_length(untrimmed_ssz, 80, LENGTH_BYTES)
|
let attestation_len = decode_length(untrimmed_ssz, 72, LENGTH_BYTES)
|
||||||
.map_err(|_| BlockValidatorError::TooShort)?;
|
.map_err(|_| BlockValidatorError::TooShort)?;
|
||||||
/*
|
/*
|
||||||
* The block only has one variable field, `attestations`, therefore
|
* The block only has one variable field, `attestations`, therefore
|
||||||
@ -96,7 +96,7 @@ impl<'a> SszBlock<'a> {
|
|||||||
|
|
||||||
/// Return the `parent_hash` field.
|
/// Return the `parent_hash` field.
|
||||||
pub fn parent_hash(&self) -> &[u8] {
|
pub fn parent_hash(&self) -> &[u8] {
|
||||||
&self.ssz[4..36]
|
&self.ssz[0..32]
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the `slot_number` field.
|
/// Return the `slot_number` field.
|
||||||
@ -109,7 +109,7 @@ impl<'a> SszBlock<'a> {
|
|||||||
* If you can make this function panic, please report
|
* If you can make this function panic, please report
|
||||||
* it to paul@sigmaprime.io
|
* it to paul@sigmaprime.io
|
||||||
*/
|
*/
|
||||||
if let Ok((n, _)) = u64::ssz_decode(&self.ssz, 36) {
|
if let Ok((n, _)) = u64::ssz_decode(&self.ssz, 32) {
|
||||||
n
|
n
|
||||||
} else {
|
} else {
|
||||||
unreachable!();
|
unreachable!();
|
||||||
@ -118,24 +118,24 @@ impl<'a> SszBlock<'a> {
|
|||||||
|
|
||||||
/// Return the `randao_reveal` field.
|
/// Return the `randao_reveal` field.
|
||||||
pub fn randao_reveal(&self) -> &[u8] {
|
pub fn randao_reveal(&self) -> &[u8] {
|
||||||
&self.ssz[48..80]
|
&self.ssz[40..72]
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the `attestations` field.
|
/// Return the `attestations` field.
|
||||||
pub fn attestations(&self) -> &[u8] {
|
pub fn attestations(&self) -> &[u8] {
|
||||||
let start = 80 + LENGTH_BYTES;
|
let start = 72 + LENGTH_BYTES;
|
||||||
&self.ssz[start..(start + self.attestation_len)]
|
&self.ssz[start..(start + self.attestation_len)]
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the `pow_chain_ref` field.
|
/// Return the `pow_chain_ref` field.
|
||||||
pub fn pow_chain_ref(&self) -> &[u8] {
|
pub fn pow_chain_ref(&self) -> &[u8] {
|
||||||
let start = self.len - (32 + LENGTH_BYTES + 32 + LENGTH_BYTES + 32);
|
let start = self.len - (32 * 3);
|
||||||
&self.ssz[start..(start + 32)]
|
&self.ssz[start..(start + 32)]
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the `active_state_root` field.
|
/// Return the `active_state_root` field.
|
||||||
pub fn act_state_root(&self) -> &[u8] {
|
pub fn act_state_root(&self) -> &[u8] {
|
||||||
let start = self.len - (32 + LENGTH_BYTES + 32);
|
let start = self.len - (32 * 2);
|
||||||
&self.ssz[start..(start + 32)]
|
&self.ssz[start..(start + 32)]
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -212,6 +212,17 @@ mod tests {
|
|||||||
assert!(SszBlock::from_slice(&ssz[..]).is_ok());
|
assert!(SszBlock::from_slice(&ssz[..]).is_ok());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_ssz_block_attestation_length() {
|
||||||
|
let mut block = Block::zero();
|
||||||
|
block.attestations.push(AttestationRecord::zero());
|
||||||
|
|
||||||
|
let serialized = get_block_ssz(&block);
|
||||||
|
let ssz_block = SszBlock::from_slice(&serialized).unwrap();
|
||||||
|
|
||||||
|
assert_eq!(ssz_block.attestation_len, MIN_SSZ_ATTESTION_RECORD_LENGTH);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_ssz_block_block_hash() {
|
fn test_ssz_block_block_hash() {
|
||||||
let mut block = Block::zero();
|
let mut block = Block::zero();
|
||||||
@ -224,9 +235,9 @@ mod tests {
|
|||||||
// will tell us if the hash changes, not that it matches some
|
// will tell us if the hash changes, not that it matches some
|
||||||
// canonical reference.
|
// canonical reference.
|
||||||
let expected_hash = [
|
let expected_hash = [
|
||||||
28, 184, 51, 12, 226, 15, 73, 50, 66, 19, 168, 149,
|
214, 217, 16, 230, 17, 204, 99, 222, 104, 90, 128, 228,
|
||||||
229, 122, 141, 111, 42, 236, 137, 157, 230, 90, 149,
|
12, 249, 56, 255, 110, 10, 229, 29, 110, 107, 105, 195,
|
||||||
58, 145, 52, 47, 62, 158, 131, 46, 147
|
219, 132, 138, 206, 204, 34, 21, 159
|
||||||
];
|
];
|
||||||
assert_eq!(hash, expected_hash);
|
assert_eq!(hash, expected_hash);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user