Start work on attestation endpoint

This commit is contained in:
Paul Hauner
2019-11-21 09:17:06 +11:00
parent b60836be7c
commit 451f8e6767
5 changed files with 87 additions and 37 deletions

View File

@@ -444,6 +444,42 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
}
}
/// Produce an `Attestation` that is valid for the given `slot` `shard`.
///
/// Always attests to the canonical chain.
pub fn produce_attestation(
&self,
shard: u64,
slot: Slot,
) -> Result<Attestation<T::EthSpec>, Error> {
let state = self.state_at_slot(slot)?;
let head = self.head();
let data = self.produce_attestation_data_for_block(
shard,
head.beacon_block_root,
head.beacon_block.slot,
&state,
)?;
let relative_epoch =
RelativeEpoch::from_slot(state.slot, slot, T::EthSpec::slots_per_epoch())?;
let committee_len = state
.get_crosslink_committee_for_shard(shard, relative_epoch)?
.committee
.len();
let empty_bitfield = BitList::with_capacity(committee_len)?;
Ok(Attestation {
aggregation_bits: empty_bitfield.clone(),
data,
custody_bits: empty_bitfield,
signature: AggregateSignature::new(),
})
}
/// Produce an `AttestationData` that is valid for the given `slot` `shard`.
///
/// Always attests to the canonical chain.

View File

@@ -1,5 +1,6 @@
use crate::eth1_chain::Error as Eth1ChainError;
use crate::fork_choice::Error as ForkChoiceError;
use ssz_types::Error as SszTypesError;
use state_processing::per_block_processing::errors::AttestationValidationError;
use state_processing::BlockProcessingError;
use state_processing::SlotProcessingError;
@@ -41,10 +42,14 @@ pub enum BeaconChainError {
AttestationValidationError(AttestationValidationError),
/// Returned when an internal check fails, indicating corrupt data.
InvariantViolated(String),
RelativeEpochError(RelativeEpochError),
SszTypesError(SszTypesError),
}
easy_from_to!(SlotProcessingError, BeaconChainError);
easy_from_to!(AttestationValidationError, BeaconChainError);
easy_from_to!(RelativeEpochError, BeaconChainError);
easy_from_to!(SszTypesError, BeaconChainError);
#[derive(Debug, PartialEq)]
pub enum BlockProductionError {