Merge branch 'blop-pool' into validator-enhancements

This commit is contained in:
Age Manning
2019-03-30 16:16:30 +11:00
24 changed files with 1423 additions and 391 deletions

View File

@@ -8,6 +8,7 @@ edition = "2018"
bls = { path = "../utils/bls" }
boolean-bitfield = { path = "../utils/boolean-bitfield" }
dirs = "1.0"
derivative = "1.0"
ethereum-types = "0.5"
hashing = { path = "../utils/hashing" }
hex = "0.3"

View File

@@ -28,6 +28,29 @@ pub struct Attestation {
pub aggregate_signature: AggregateSignature,
}
impl Attestation {
/// Are the aggregation bitfields of these attestations disjoint?
pub fn signers_disjoint_from(&self, other: &Attestation) -> bool {
self.aggregation_bitfield
.intersection(&other.aggregation_bitfield)
.is_zero()
}
/// Aggregate another Attestation into this one.
///
/// The aggregation bitfields must be disjoint, and the data must be the same.
pub fn aggregate(&mut self, other: &Attestation) {
debug_assert_eq!(self.data, other.data);
debug_assert!(self.signers_disjoint_from(other));
self.aggregation_bitfield
.union_inplace(&other.aggregation_bitfield);
self.custody_bitfield.union_inplace(&other.custody_bitfield);
self.aggregate_signature
.add_aggregate(&other.aggregate_signature);
}
}
#[cfg(test)]
mod tests {
use super::*;

View File

@@ -1,7 +1,7 @@
use crate::*;
use serde_derive::{Deserialize, Serialize};
#[derive(Debug, PartialEq, Clone, Default, Serialize, Deserialize)]
#[derive(Debug, PartialEq, Clone, Copy, Default, Serialize, Deserialize)]
pub struct AttestationDuty {
pub slot: Slot,
pub shard: Shard,

View File

@@ -1,5 +1,5 @@
use crate::test_utils::TestRandom;
use crate::{AttestationData, Bitfield, Slot};
use crate::{Attestation, AttestationData, Bitfield, Slot};
use rand::RngCore;
use serde_derive::{Deserialize, Serialize};
use ssz_derive::{Decode, Encode, TreeHash};
@@ -16,6 +16,18 @@ pub struct PendingAttestation {
pub inclusion_slot: Slot,
}
impl PendingAttestation {
/// Create a `PendingAttestation` from an `Attestation`, at the given `inclusion_slot`.
pub fn from_attestation(attestation: &Attestation, inclusion_slot: Slot) -> Self {
PendingAttestation {
data: attestation.data.clone(),
aggregation_bitfield: attestation.aggregation_bitfield.clone(),
custody_bitfield: attestation.custody_bitfield.clone(),
inclusion_slot,
}
}
}
#[cfg(test)]
mod tests {
use super::*;

View File

@@ -19,7 +19,7 @@ pub fn generate_deterministic_keypairs(validator_count: usize) -> Vec<Keypair> {
.collect::<Vec<usize>>()
.par_iter()
.map(|&i| {
let secret = int_to_bytes48(i as u64 + 1);
let secret = int_to_bytes48(i as u64 + 1000);
let sk = SecretKey::from_bytes(&secret).unwrap();
let pk = PublicKey::from_secret_key(&sk);
Keypair { sk, pk }

View File

@@ -1,6 +1,7 @@
use super::Slot;
use crate::test_utils::TestRandom;
use bls::{PublicKey, Signature};
use derivative::Derivative;
use rand::RngCore;
use serde_derive::{Deserialize, Serialize};
use ssz::TreeHash;
@@ -12,7 +13,6 @@ use test_random_derive::TestRandom;
/// Spec v0.5.0
#[derive(
Debug,
PartialEq,
Clone,
Serialize,
Deserialize,
@@ -21,7 +21,9 @@ use test_random_derive::TestRandom;
TreeHash,
TestRandom,
SignedRoot,
Derivative,
)]
#[derivative(PartialEq, Eq, Hash)]
pub struct Transfer {
pub sender: u64,
pub recipient: u64,
@@ -29,6 +31,7 @@ pub struct Transfer {
pub fee: u64,
pub slot: Slot,
pub pubkey: PublicKey,
#[derivative(Hash = "ignore")]
pub signature: Signature,
}