Add arbitrary attestation for beacon chain harness
This commit is contained in:
parent
7a4c3e26ac
commit
46c0e17682
@ -425,65 +425,20 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Produce an `AttestationData` that is valid for the present `slot` and given `shard`.
|
/// Produce an `AttestationData` that is valid for the present `slot` and given `shard`.
|
||||||
|
///
|
||||||
|
/// Attests to the canonical chain.
|
||||||
pub fn produce_attestation_data(&self, shard: u64) -> Result<AttestationData, Error> {
|
pub fn produce_attestation_data(&self, shard: u64) -> Result<AttestationData, Error> {
|
||||||
let state = self.state.read();
|
let state = self.state.read();
|
||||||
let head_block_root = self.head().beacon_block_root;
|
let head_block_root = self.head().beacon_block_root;
|
||||||
let head_block_slot = self.head().beacon_block.slot;
|
let head_block_slot = self.head().beacon_block.slot;
|
||||||
|
|
||||||
self.produce_attestation_data_for_block(shard, head_block_root, head_block_slot, &*state)
|
self.produce_attestation_data_for_block(shard, head_block_root, head_block_slot, &*state)
|
||||||
/*
|
|
||||||
let slots_per_epoch = T::EthSpec::slots_per_epoch();
|
|
||||||
|
|
||||||
self.metrics.attestation_production_requests.inc();
|
|
||||||
let timer = self.metrics.attestation_production_times.start_timer();
|
|
||||||
|
|
||||||
let state = self.state.read();
|
|
||||||
|
|
||||||
let current_epoch_start_slot = self
|
|
||||||
.state
|
|
||||||
.read()
|
|
||||||
.slot
|
|
||||||
.epoch(slots_per_epoch)
|
|
||||||
.start_slot(slots_per_epoch);
|
|
||||||
|
|
||||||
let target_root = if state.slot == current_epoch_start_slot {
|
|
||||||
// If we're on the first slot of the state's epoch.
|
|
||||||
if self.head().beacon_block.slot == state.slot {
|
|
||||||
// If the current head block is from the current slot, use its block root.
|
|
||||||
self.head().beacon_block_root
|
|
||||||
} else {
|
|
||||||
// If the current head block is not from this slot, use the slot from the previous
|
|
||||||
// epoch.
|
|
||||||
*self
|
|
||||||
.state
|
|
||||||
.read()
|
|
||||||
.get_block_root(current_epoch_start_slot - slots_per_epoch)?
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// If we're not on the first slot of the epoch.
|
|
||||||
*self.state.read().get_block_root(current_epoch_start_slot)?
|
|
||||||
};
|
|
||||||
|
|
||||||
let previous_crosslink_root =
|
|
||||||
Hash256::from_slice(&state.get_current_crosslink(shard)?.tree_hash_root());
|
|
||||||
|
|
||||||
self.metrics.attestation_production_successes.inc();
|
|
||||||
timer.observe_duration();
|
|
||||||
|
|
||||||
Ok(AttestationData {
|
|
||||||
beacon_block_root: self.head().beacon_block_root,
|
|
||||||
source_epoch: state.current_justified_epoch,
|
|
||||||
source_root: state.current_justified_root,
|
|
||||||
target_epoch: state.current_epoch(),
|
|
||||||
target_root,
|
|
||||||
shard,
|
|
||||||
previous_crosslink_root,
|
|
||||||
crosslink_data_root: Hash256::zero(),
|
|
||||||
})
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Produce an `AttestationData` that attests to the chain denoted by `block_root` and `state`.
|
/// Produce an `AttestationData` that attests to the chain denoted by `block_root` and `state`.
|
||||||
|
///
|
||||||
|
/// Permits attesting to any arbitrary chain. Generally, the `produce_attestation_data`
|
||||||
|
/// function should be used as it attests to the canonical chain.
|
||||||
pub fn produce_attestation_data_for_block(
|
pub fn produce_attestation_data_for_block(
|
||||||
&self,
|
&self,
|
||||||
shard: u64,
|
shard: u64,
|
||||||
|
@ -134,13 +134,11 @@ where
|
|||||||
.expect("should not error during block processing");
|
.expect("should not error during block processing");
|
||||||
|
|
||||||
if let BlockProcessingOutcome::Processed { block_root } = outcome {
|
if let BlockProcessingOutcome::Processed { block_root } = outcome {
|
||||||
//
|
self.add_attestations_to_op_pool(&new_state, block_root, slot);
|
||||||
} else {
|
} else {
|
||||||
panic!("block should be successfully processed");
|
panic!("block should be successfully processed");
|
||||||
}
|
}
|
||||||
|
|
||||||
self.add_attestations_to_op_pool();
|
|
||||||
|
|
||||||
state = new_state;
|
state = new_state;
|
||||||
slot += 1;
|
slot += 1;
|
||||||
}
|
}
|
||||||
@ -198,8 +196,12 @@ where
|
|||||||
(block, state)
|
(block, state)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_attestations_to_op_pool(&self) {
|
fn add_attestations_to_op_pool(
|
||||||
let state = &self.chain.current_state();
|
&self,
|
||||||
|
state: &BeaconState<E>,
|
||||||
|
head_block_root: Hash256,
|
||||||
|
head_block_slot: Slot,
|
||||||
|
) {
|
||||||
let spec = &self.spec;
|
let spec = &self.spec;
|
||||||
let fork = &state.fork;
|
let fork = &state.fork;
|
||||||
|
|
||||||
@ -213,7 +215,12 @@ where
|
|||||||
for (i, validator_index) in cc.committee.iter().enumerate() {
|
for (i, validator_index) in cc.committee.iter().enumerate() {
|
||||||
let data = self
|
let data = self
|
||||||
.chain
|
.chain
|
||||||
.produce_attestation_data(cc.shard)
|
.produce_attestation_data_for_block(
|
||||||
|
cc.shard,
|
||||||
|
head_block_root,
|
||||||
|
head_block_slot,
|
||||||
|
state,
|
||||||
|
)
|
||||||
.expect("should produce attestation data");
|
.expect("should produce attestation data");
|
||||||
|
|
||||||
let mut aggregation_bitfield = Bitfield::new();
|
let mut aggregation_bitfield = Bitfield::new();
|
||||||
|
Loading…
Reference in New Issue
Block a user