Add comments to new functions
This commit is contained in:
parent
a29eca57a1
commit
ec0e13b764
@ -9,6 +9,8 @@ macro_rules! ensure {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns `Ok(())` if some `AttesterSlashing` is valid to be included in some `BeaconState`,
|
||||||
|
/// otherwise returns an `Err`.
|
||||||
pub fn verify_slashable_attestation(
|
pub fn verify_slashable_attestation(
|
||||||
state: &mut BeaconState,
|
state: &mut BeaconState,
|
||||||
attester_slashing: &AttesterSlashing,
|
attester_slashing: &AttesterSlashing,
|
||||||
|
@ -1,9 +1,20 @@
|
|||||||
use crate::*;
|
use crate::*;
|
||||||
use ssz::TreeHash;
|
use ssz::TreeHash;
|
||||||
|
|
||||||
|
/// Builds an `AttesterSlashing`.
|
||||||
pub struct AttesterSlashingBuilder();
|
pub struct AttesterSlashingBuilder();
|
||||||
|
|
||||||
impl AttesterSlashingBuilder {
|
impl AttesterSlashingBuilder {
|
||||||
|
/// Builds an `AttesterSlashing` that is a double vote.
|
||||||
|
///
|
||||||
|
/// The `signer` function is used to sign the double-vote and accepts:
|
||||||
|
///
|
||||||
|
/// - `validator_index: u64`
|
||||||
|
/// - `message: &[u8]`
|
||||||
|
/// - `epoch: Epoch`
|
||||||
|
/// - `domain: u64`
|
||||||
|
///
|
||||||
|
/// Where domain is a domain "constant" (e.g., `spec.domain_attestation`).
|
||||||
pub fn double_vote<F>(
|
pub fn double_vote<F>(
|
||||||
validator_indices: &[u64],
|
validator_indices: &[u64],
|
||||||
signer: F,
|
signer: F,
|
||||||
|
@ -1140,6 +1140,9 @@ impl BeaconState {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Verify ``bitfield`` against the ``committee_size``.
|
||||||
|
///
|
||||||
|
/// Spec v0.2.0
|
||||||
pub fn verify_bitfield(&self, bitfield: &Bitfield, committee_size: usize) -> bool {
|
pub fn verify_bitfield(&self, bitfield: &Bitfield, committee_size: usize) -> bool {
|
||||||
if bitfield.num_bytes() != ((committee_size + 7) / 8) {
|
if bitfield.num_bytes() != ((committee_size + 7) / 8) {
|
||||||
return false;
|
return false;
|
||||||
@ -1159,6 +1162,9 @@ impl BeaconState {
|
|||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Verify validity of ``slashable_attestation`` fields.
|
||||||
|
///
|
||||||
|
/// Spec v0.2.0
|
||||||
pub fn verify_slashable_attestation(
|
pub fn verify_slashable_attestation(
|
||||||
&self,
|
&self,
|
||||||
slashable_attestation: &SlashableAttestation,
|
slashable_attestation: &SlashableAttestation,
|
||||||
|
@ -1,9 +1,20 @@
|
|||||||
use crate::*;
|
use crate::*;
|
||||||
use ssz::TreeHash;
|
use ssz::TreeHash;
|
||||||
|
|
||||||
|
/// Builds a `ProposerSlashing`.
|
||||||
pub struct ProposerSlashingBuilder();
|
pub struct ProposerSlashingBuilder();
|
||||||
|
|
||||||
impl ProposerSlashingBuilder {
|
impl ProposerSlashingBuilder {
|
||||||
|
/// Builds a `ProposerSlashing` that is a double vote.
|
||||||
|
///
|
||||||
|
/// The `signer` function is used to sign the double-vote and accepts:
|
||||||
|
///
|
||||||
|
/// - `validator_index: u64`
|
||||||
|
/// - `message: &[u8]`
|
||||||
|
/// - `epoch: Epoch`
|
||||||
|
/// - `domain: u64`
|
||||||
|
///
|
||||||
|
/// Where domain is a domain "constant" (e.g., `spec.domain_attestation`).
|
||||||
pub fn double_vote<F>(proposer_index: u64, signer: F, spec: &ChainSpec) -> ProposerSlashing
|
pub fn double_vote<F>(proposer_index: u64, signer: F, spec: &ChainSpec) -> ProposerSlashing
|
||||||
where
|
where
|
||||||
F: Fn(u64, &[u8], Epoch, u64) -> Signature,
|
F: Fn(u64, &[u8], Epoch, u64) -> Signature,
|
||||||
|
@ -54,15 +54,17 @@ pub struct Validator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Validator {
|
impl Validator {
|
||||||
/// This predicate indicates if the validator represented by this record is considered "active" at `slot`.
|
/// Returns `true` if the validator is considered active at some epoch.
|
||||||
pub fn is_active_at(&self, epoch: Epoch) -> bool {
|
pub fn is_active_at(&self, epoch: Epoch) -> bool {
|
||||||
self.activation_epoch <= epoch && epoch < self.exit_epoch
|
self.activation_epoch <= epoch && epoch < self.exit_epoch
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns `true` if the validator is considered exited at some epoch.
|
||||||
pub fn is_exited_at(&self, epoch: Epoch) -> bool {
|
pub fn is_exited_at(&self, epoch: Epoch) -> bool {
|
||||||
self.exit_epoch <= epoch
|
self.exit_epoch <= epoch
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns `true` if the validator is considered penalized at some epoch.
|
||||||
pub fn is_penalized_at(&self, epoch: Epoch) -> bool {
|
pub fn is_penalized_at(&self, epoch: Epoch) -> bool {
|
||||||
self.penalized_epoch <= epoch
|
self.penalized_epoch <= epoch
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user