mirror of
https://gitlab.com/pulsechaincom/lighthouse-pulse.git
synced 2025-01-10 13:01:22 +00:00
f267bf2afe
* Start adding interop genesis state to lcli * Use more efficient method to generate genesis state * Remove duplicate int_to_bytes32 * Add lcli command to change state genesis time * Add option to allow VC to start with unsynced BN * Set VC to do parallel key loading * Don't default to dummy eth1 backend * Add endpoint to dump operation pool * Add metrics for op pool * Remove state clone for slot notifier * Add mem size approximation for tree hash cache * Avoid cloning tree hash when getting head * Fix failing API tests * Address Michael's comments * Add HashMap::from_par_iter
42 lines
1.3 KiB
Rust
42 lines
1.3 KiB
Rust
use int_to_bytes::int_to_bytes8;
|
|
use serde_derive::{Deserialize, Serialize};
|
|
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, PartialOrd, Ord, Encode, Decode, Serialize, Deserialize,
|
|
)]
|
|
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;
|
|
|
|
impl AttestationId {
|
|
pub fn from_data<T: EthSpec>(
|
|
attestation: &AttestationData,
|
|
state: &BeaconState<T>,
|
|
spec: &ChainSpec,
|
|
) -> Self {
|
|
let mut bytes = ssz_encode(attestation);
|
|
let epoch = attestation.target.epoch;
|
|
bytes.extend_from_slice(&AttestationId::compute_domain_bytes(epoch, state, spec));
|
|
AttestationId { v: bytes }
|
|
}
|
|
|
|
pub fn compute_domain_bytes<T: EthSpec>(
|
|
epoch: Epoch,
|
|
state: &BeaconState<T>,
|
|
spec: &ChainSpec,
|
|
) -> Vec<u8> {
|
|
int_to_bytes8(spec.get_domain(epoch, Domain::BeaconAttester, &state.fork))
|
|
}
|
|
|
|
pub fn domain_bytes_match(&self, domain_bytes: &[u8]) -> bool {
|
|
&self.v[self.v.len() - DOMAIN_BYTES_LEN..] == domain_bytes
|
|
}
|
|
}
|