op_pool: partial persistence support

This commit is contained in:
Michael Sproul
2019-06-18 17:55:18 +10:00
parent 38d2d03e3a
commit 604fe2d97f
6 changed files with 130 additions and 7 deletions

View File

@@ -1,10 +1,13 @@
use int_to_bytes::int_to_bytes8;
use ssz::ssz_encode;
use ssz_derive::{Decode, Encode};
use types::{AttestationData, BeaconState, ChainSpec, Domain, Epoch, EthSpec};
/// Serialized `AttestationData` augmented with a domain to encode the fork info.
#[derive(PartialEq, Eq, Clone, Hash, Debug)]
pub struct AttestationId(Vec<u8>);
#[derive(PartialEq, Eq, Clone, Hash, Debug, PartialOrd, Ord, Encode, Decode)]
pub struct AttestationId {
v: Vec<u8>,
}
/// Number of domain bytes that the end of an attestation ID is padded with.
const DOMAIN_BYTES_LEN: usize = 8;
@@ -18,7 +21,7 @@ impl AttestationId {
let mut bytes = ssz_encode(attestation);
let epoch = attestation.target_epoch;
bytes.extend_from_slice(&AttestationId::compute_domain_bytes(epoch, state, spec));
AttestationId(bytes)
AttestationId { v: bytes }
}
pub fn compute_domain_bytes<T: EthSpec>(
@@ -30,6 +33,6 @@ impl AttestationId {
}
pub fn domain_bytes_match(&self, domain_bytes: &[u8]) -> bool {
&self.0[self.0.len() - DOMAIN_BYTES_LEN..] == domain_bytes
&self.v[self.v.len() - DOMAIN_BYTES_LEN..] == domain_bytes
}
}