Merge branch 'master' into proto-array

This commit is contained in:
Paul Hauner
2020-01-24 17:00:32 +11:00
115 changed files with 3943 additions and 1029 deletions

View File

@@ -311,11 +311,7 @@ fn bench_block<T: EthSpec>(
)
.expect("should get indexed attestation");
(
local_spec.clone(),
local_state.clone(),
indexed_attestation.clone(),
)
(local_spec.clone(), local_state.clone(), indexed_attestation)
},
|(spec, ref mut state, indexed_attestation)| {
black_box(
@@ -349,11 +345,7 @@ fn bench_block<T: EthSpec>(
)
.expect("should get indexed attestation");
(
local_spec.clone(),
local_state.clone(),
indexed_attestation.clone(),
)
(local_spec.clone(), local_state.clone(), indexed_attestation)
},
|(spec, ref mut state, indexed_attestation)| {
black_box(
@@ -373,7 +365,7 @@ fn bench_block<T: EthSpec>(
);
let local_block = block.clone();
let local_state = state.clone();
let local_state = state;
c.bench(
&title,
Benchmark::new("get_attesting_indices", move |b| {
@@ -409,7 +401,7 @@ fn bench_block<T: EthSpec>(
.sample_size(10),
);
let local_block = block.clone();
let local_block = block;
c.bench(
&title,
Benchmark::new("ssz_block_len", move |b| {

View File

@@ -0,0 +1,23 @@
use integer_sqrt::IntegerSquareRoot;
use types::*;
/// Returns the base reward for some validator.
///
/// Spec v0.9.1
pub fn get_base_reward<T: EthSpec>(
state: &BeaconState<T>,
index: usize,
// Should be == get_total_active_balance(state, spec)
total_active_balance: u64,
spec: &ChainSpec,
) -> Result<u64, BeaconStateError> {
if total_active_balance == 0 {
Ok(0)
} else {
Ok(
state.get_effective_balance(index, spec)? * spec.base_reward_factor
/ total_active_balance.integer_sqrt()
/ spec.base_rewards_per_epoch,
)
}
}

View File

@@ -1,9 +1,11 @@
mod get_attesting_indices;
mod get_base_reward;
mod get_indexed_attestation;
mod initiate_validator_exit;
mod slash_validator;
pub use get_attesting_indices::get_attesting_indices;
pub use get_base_reward::get_base_reward;
pub use get_indexed_attestation::get_indexed_attestation;
pub use initiate_validator_exit::initiate_validator_exit;
pub use slash_validator::slash_validator;

View File

@@ -1,6 +1,7 @@
use super::super::common::get_base_reward;
use super::validator_statuses::{TotalBalances, ValidatorStatus, ValidatorStatuses};
use super::Error;
use integer_sqrt::IntegerSquareRoot;
use types::*;
/// Use to track the changes to a validators balance.
@@ -211,24 +212,3 @@ fn get_attestation_delta<T: EthSpec>(
delta
}
/// Returns the base reward for some validator.
///
/// Spec v0.9.1
fn get_base_reward<T: EthSpec>(
state: &BeaconState<T>,
index: usize,
// Should be == get_total_active_balance(state, spec)
total_active_balance: u64,
spec: &ChainSpec,
) -> Result<u64, BeaconStateError> {
if total_active_balance == 0 {
Ok(0)
} else {
Ok(
state.get_effective_balance(index, spec)? * spec.base_reward_factor
/ total_active_balance.integer_sqrt()
/ spec.base_rewards_per_epoch,
)
}
}

View File

@@ -29,7 +29,7 @@ where
F: FnMut(&mut BlockBuilder<T>),
G: FnMut(&mut BeaconBlock<T>),
{
let (mut block, state) = get_block::<T, _>(mutate_builder);
let (mut block, mut state) = get_block::<T, _>(mutate_builder);
/*
* Control check to ensure the valid block should pass verification.
@@ -79,7 +79,7 @@ where
assert_eq!(
per_block_processing(
&mut state.clone(),
&mut state,
&block,
None,
BlockSignatureStrategy::VerifyBulk,