mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-16 03:12:41 +00:00
Implement tree states & hierarchical state DB
This commit is contained in:
@@ -47,17 +47,20 @@ pub fn process_sync_aggregate<T: EthSpec>(
|
||||
// Apply participant and proposer rewards
|
||||
let committee_indices = state.get_sync_committee_indices(¤t_sync_committee)?;
|
||||
|
||||
let mut total_proposer_reward = 0;
|
||||
for (participant_index, participation_bit) in committee_indices
|
||||
.into_iter()
|
||||
.zip(aggregate.sync_committee_bits.iter())
|
||||
{
|
||||
// FIXME(sproul): double-check this for Capella, proposer shouldn't have 0 effective balance
|
||||
if participation_bit {
|
||||
increase_balance(state, participant_index, participant_reward)?;
|
||||
increase_balance(state, proposer_index as usize, proposer_reward)?;
|
||||
total_proposer_reward.safe_add_assign(proposer_reward)?;
|
||||
} else {
|
||||
decrease_balance(state, participant_index, participant_reward)?;
|
||||
}
|
||||
}
|
||||
increase_balance(state, proposer_index as usize, total_proposer_reward)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use super::signature_sets::Error as SignatureSetError;
|
||||
use crate::ContextError;
|
||||
use crate::{ContextError, EpochCacheError};
|
||||
use merkle_proof::MerkleTreeError;
|
||||
use safe_arith::ArithError;
|
||||
use ssz::DecodeError;
|
||||
@@ -78,6 +78,8 @@ pub enum BlockProcessingError {
|
||||
},
|
||||
ExecutionInvalid,
|
||||
ConsensusContext(ContextError),
|
||||
MilhouseError(milhouse::Error),
|
||||
EpochCacheError(EpochCacheError),
|
||||
WithdrawalsRootMismatch {
|
||||
expected: Hash256,
|
||||
found: Hash256,
|
||||
@@ -127,6 +129,18 @@ impl From<ContextError> for BlockProcessingError {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<EpochCacheError> for BlockProcessingError {
|
||||
fn from(e: EpochCacheError) -> Self {
|
||||
BlockProcessingError::EpochCacheError(e)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<milhouse::Error> for BlockProcessingError {
|
||||
fn from(e: milhouse::Error) -> Self {
|
||||
Self::MilhouseError(e)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<BlockOperationError<HeaderInvalid>> for BlockProcessingError {
|
||||
fn from(e: BlockOperationError<HeaderInvalid>) -> BlockProcessingError {
|
||||
match e {
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
use super::*;
|
||||
use crate::common::{
|
||||
altair::{get_base_reward, BaseRewardPerIncrement},
|
||||
get_attestation_participation_flag_indices, increase_balance, initiate_validator_exit,
|
||||
slash_validator,
|
||||
};
|
||||
use crate::per_block_processing::errors::{BlockProcessingError, IntoWithIndex};
|
||||
use crate::VerifySignatures;
|
||||
use safe_arith::SafeArith;
|
||||
use std::sync::Arc;
|
||||
use types::consts::altair::{PARTICIPATION_FLAG_WEIGHTS, PROPOSER_WEIGHT, WEIGHT_DENOMINATOR};
|
||||
|
||||
pub fn process_operations<T: EthSpec, Payload: AbstractExecPayload<T>>(
|
||||
@@ -126,7 +126,7 @@ pub mod altair {
|
||||
|
||||
let proposer_index = ctxt.get_proposer_index(state, spec)?;
|
||||
|
||||
let attesting_indices = &verify_attestation_for_block_inclusion(
|
||||
let attesting_indices = verify_attestation_for_block_inclusion(
|
||||
state,
|
||||
attestation,
|
||||
ctxt,
|
||||
@@ -134,7 +134,8 @@ pub mod altair {
|
||||
spec,
|
||||
)
|
||||
.map_err(|e| e.into_with_index(att_index))?
|
||||
.attesting_indices;
|
||||
.attesting_indices
|
||||
.clone();
|
||||
|
||||
// Matching roots, participation flag indices
|
||||
let data = &attestation.data;
|
||||
@@ -143,10 +144,8 @@ pub mod altair {
|
||||
get_attestation_participation_flag_indices(state, data, inclusion_delay, spec)?;
|
||||
|
||||
// Update epoch participation flags.
|
||||
let total_active_balance = state.get_total_active_balance()?;
|
||||
let base_reward_per_increment = BaseRewardPerIncrement::new(total_active_balance, spec)?;
|
||||
let mut proposer_reward_numerator = 0;
|
||||
for index in attesting_indices {
|
||||
for index in &attesting_indices {
|
||||
let index = *index as usize;
|
||||
|
||||
for (flag_index, &weight) in PARTICIPATION_FLAG_WEIGHTS.iter().enumerate() {
|
||||
@@ -160,8 +159,7 @@ pub mod altair {
|
||||
{
|
||||
validator_participation.add_flag(flag_index)?;
|
||||
proposer_reward_numerator.safe_add_assign(
|
||||
get_base_reward(state, index, base_reward_per_increment, spec)?
|
||||
.safe_mul(weight)?,
|
||||
ctxt.get_base_reward(state, index, spec)?.safe_mul(weight)?,
|
||||
)?;
|
||||
}
|
||||
}
|
||||
@@ -392,17 +390,19 @@ pub fn process_deposit<T: EthSpec>(
|
||||
|
||||
// Create a new validator.
|
||||
let validator = Validator {
|
||||
pubkey: deposit.data.pubkey,
|
||||
withdrawal_credentials: deposit.data.withdrawal_credentials,
|
||||
activation_eligibility_epoch: spec.far_future_epoch,
|
||||
activation_epoch: spec.far_future_epoch,
|
||||
exit_epoch: spec.far_future_epoch,
|
||||
withdrawable_epoch: spec.far_future_epoch,
|
||||
effective_balance: std::cmp::min(
|
||||
amount.safe_sub(amount.safe_rem(spec.effective_balance_increment)?)?,
|
||||
spec.max_effective_balance,
|
||||
),
|
||||
slashed: false,
|
||||
pubkey: Arc::new(deposit.data.pubkey),
|
||||
mutable: ValidatorMutable {
|
||||
withdrawal_credentials: deposit.data.withdrawal_credentials,
|
||||
activation_eligibility_epoch: spec.far_future_epoch,
|
||||
activation_epoch: spec.far_future_epoch,
|
||||
exit_epoch: spec.far_future_epoch,
|
||||
withdrawable_epoch: spec.far_future_epoch,
|
||||
effective_balance: std::cmp::min(
|
||||
amount.safe_sub(amount.safe_rem(spec.effective_balance_increment)?)?,
|
||||
spec.max_effective_balance,
|
||||
),
|
||||
slashed: false,
|
||||
},
|
||||
};
|
||||
state.validators_mut().push(validator)?;
|
||||
state.balances_mut().push(deposit.data.amount)?;
|
||||
|
||||
@@ -64,7 +64,7 @@ where
|
||||
.validators()
|
||||
.get(validator_index)
|
||||
.and_then(|v| {
|
||||
let pk: Option<PublicKey> = v.pubkey.decompress().ok();
|
||||
let pk: Option<PublicKey> = v.pubkey().decompress().ok();
|
||||
pk
|
||||
})
|
||||
.map(Cow::Owned)
|
||||
|
||||
@@ -29,7 +29,7 @@ pub fn verify_bls_to_execution_change<T: EthSpec>(
|
||||
|
||||
verify!(
|
||||
validator
|
||||
.withdrawal_credentials
|
||||
.withdrawal_credentials()
|
||||
.as_bytes()
|
||||
.first()
|
||||
.map(|byte| *byte == spec.bls_withdrawal_prefix_byte)
|
||||
@@ -41,7 +41,7 @@ pub fn verify_bls_to_execution_change<T: EthSpec>(
|
||||
// future.
|
||||
let pubkey_hash = hash(address_change.from_bls_pubkey.as_serialized());
|
||||
verify!(
|
||||
validator.withdrawal_credentials.as_bytes().get(1..) == pubkey_hash.get(1..),
|
||||
validator.withdrawal_credentials().as_bytes().get(1..) == pubkey_hash.get(1..),
|
||||
Invalid::WithdrawalCredentialsMismatch
|
||||
);
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ pub fn verify_exit<T: EthSpec>(
|
||||
|
||||
// Verify that the validator has not yet exited.
|
||||
verify!(
|
||||
validator.exit_epoch == spec.far_future_epoch,
|
||||
validator.exit_epoch() == spec.far_future_epoch,
|
||||
ExitInvalid::AlreadyExited(exit.validator_index)
|
||||
);
|
||||
|
||||
@@ -56,7 +56,7 @@ pub fn verify_exit<T: EthSpec>(
|
||||
|
||||
// Verify the validator has been active long enough.
|
||||
let earliest_exit_epoch = validator
|
||||
.activation_epoch
|
||||
.activation_epoch()
|
||||
.safe_add(spec.shard_committee_period)?;
|
||||
verify!(
|
||||
current_epoch >= earliest_exit_epoch,
|
||||
|
||||
Reference in New Issue
Block a user