Add attestation production to BeaconChain
This commit is contained in:
parent
d1ac7c037d
commit
e9abf06364
53
beacon_node/beacon_chain/src/attestation_production.rs
Normal file
53
beacon_node/beacon_chain/src/attestation_production.rs
Normal file
@ -0,0 +1,53 @@
|
||||
use super::{BeaconChain, ClientDB, SlotClock};
|
||||
use types::{AttestationData, Hash256};
|
||||
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum Error {
|
||||
/*
|
||||
DBError(String),
|
||||
StateTransitionError(TransitionError),
|
||||
PresentSlotIsNone,
|
||||
*/
|
||||
SlotTooOld,
|
||||
PresentSlotUnknown,
|
||||
StateError,
|
||||
}
|
||||
|
||||
impl<T, U> BeaconChain<T, U>
|
||||
where
|
||||
T: ClientDB,
|
||||
U: SlotClock,
|
||||
{
|
||||
pub fn produce_attestation_data(
|
||||
&self,
|
||||
slot: u64,
|
||||
shard: u64,
|
||||
) -> Result<AttestationData, Error> {
|
||||
let present_slot = self
|
||||
.present_slot()
|
||||
.ok_or_else(|| Error::PresentSlotUnknown)?;
|
||||
let state = self.state(present_slot).map_err(|_| Error::StateError)?;
|
||||
|
||||
let justified_slot = self.justified_slot();
|
||||
|
||||
let justified_block_root = *state
|
||||
.get_block_root(justified_slot, &self.spec)
|
||||
.ok_or_else(|| Error::SlotTooOld)?;
|
||||
|
||||
let head_slot = self.head().beacon_block.slot;
|
||||
let epoch_boundary_root = *state
|
||||
.get_block_root(head_slot % self.spec.epoch_length, &self.spec)
|
||||
.ok_or_else(|| Error::SlotTooOld)?;
|
||||
|
||||
Ok(AttestationData {
|
||||
slot,
|
||||
shard,
|
||||
beacon_block_root: self.head().beacon_block_root.clone(),
|
||||
epoch_boundary_root,
|
||||
shard_block_root: Hash256::zero(),
|
||||
latest_crosslink_root: Hash256::zero(),
|
||||
justified_slot,
|
||||
justified_block_root,
|
||||
})
|
||||
}
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
mod attestation_production;
|
||||
mod attestation_targets;
|
||||
mod block_graph;
|
||||
pub mod block_processing;
|
||||
|
Loading…
Reference in New Issue
Block a user