Fix bug in attestation production
This commit is contained in:
parent
bd860eb3e1
commit
c6fc4f0769
@ -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,
|
||||||
|
Loading…
Reference in New Issue
Block a user