Fix bug in attestation production

This commit is contained in:
Paul Hauner 2019-03-31 15:35:27 +11:00
parent bd860eb3e1
commit c6fc4f0769
No known key found for this signature in database
GPG Key ID: D362883A9218FCC6

View File

@ -482,14 +482,37 @@ where
trace!("BeaconChain::produce_attestation: shard: {}", shard); trace!("BeaconChain::produce_attestation: shard: {}", shard);
let state = self.state.read(); let state = self.state.read();
let target_root = *self.state.read().get_block_root( let current_epoch_start_slot = self
self.state .state
.read()
.slot
.epoch(self.spec.slots_per_epoch)
.start_slot(self.spec.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.
let root = *self.state.read().get_block_root(
current_epoch_start_slot - self.spec.slots_per_epoch,
&self.spec,
)?;
root
}
} else {
// If we're not on the first slot of the epoch.
let root = *self
.state
.read() .read()
.slot .get_block_root(current_epoch_start_slot, &self.spec)?;
.epoch(self.spec.slots_per_epoch)
.start_slot(self.spec.slots_per_epoch), root
&self.spec, };
)?;
Ok(AttestationData { Ok(AttestationData {
slot: self.state.read().slot, slot: self.state.read().slot,