types: safe accessors for current crosslinks
This commit is contained in:
parent
9a21e41017
commit
f8d4e742ad
@ -629,6 +629,24 @@ impl<T: EthSpec> BeaconState<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the current crosslink for a shard.
|
||||||
|
///
|
||||||
|
/// Spec v0.6.1
|
||||||
|
pub fn get_current_crosslink(&self, shard: u64) -> Result<&Crosslink, Error> {
|
||||||
|
self.current_crosslinks
|
||||||
|
.get(shard as usize)
|
||||||
|
.ok_or(Error::ShardOutOfBounds)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the previous crosslink for a shard.
|
||||||
|
///
|
||||||
|
/// Spec v0.6.1
|
||||||
|
pub fn get_previous_crosslink(&self, shard: u64) -> Result<&Crosslink, Error> {
|
||||||
|
self.previous_crosslinks
|
||||||
|
.get(shard as usize)
|
||||||
|
.ok_or(Error::ShardOutOfBounds)
|
||||||
|
}
|
||||||
|
|
||||||
/// Transform an attestation into the crosslink that it reinforces.
|
/// Transform an attestation into the crosslink that it reinforces.
|
||||||
///
|
///
|
||||||
/// Spec v0.6.1
|
/// Spec v0.6.1
|
||||||
@ -636,15 +654,16 @@ impl<T: EthSpec> BeaconState<T> {
|
|||||||
&self,
|
&self,
|
||||||
data: &AttestationData,
|
data: &AttestationData,
|
||||||
spec: &ChainSpec,
|
spec: &ChainSpec,
|
||||||
) -> Crosslink {
|
) -> Result<Crosslink, Error> {
|
||||||
Crosslink {
|
let current_crosslink_epoch = self.get_current_crosslink(data.shard)?.epoch;
|
||||||
|
Ok(Crosslink {
|
||||||
epoch: std::cmp::min(
|
epoch: std::cmp::min(
|
||||||
data.target_epoch,
|
data.target_epoch,
|
||||||
self.current_crosslinks[data.shard as usize].epoch + spec.max_crosslink_epochs,
|
current_crosslink_epoch + spec.max_crosslink_epochs,
|
||||||
),
|
),
|
||||||
previous_crosslink_root: data.previous_crosslink_root,
|
previous_crosslink_root: data.previous_crosslink_root,
|
||||||
crosslink_data_root: data.crosslink_data_root,
|
crosslink_data_root: data.crosslink_data_root,
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Generate a seed for the given `epoch`.
|
/// Generate a seed for the given `epoch`.
|
||||||
|
Loading…
Reference in New Issue
Block a user