mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-09 19:51:47 +00:00
* add light client optimistic and finality update rpc * Arc the updates in the response * add conditional advertisement for both LightClientOptimisticUpdate and LightClientFinalityUpdate * alter display for inboundrequest light client optimistic and finality updates * remove LightClientOptimistic/FinalityReuest struct and some minor fixes * rebase * failing rpc_test for LightClientBootstrap and beginning of MockLib2pLightClient * minor change * added MockRPCHandler by importing everything except OutboundRequest. Need to implement the ConnectionHandler trait now should be copy pastable * almost there but ran into issue where needed to implement BaseOutboundRequest. * failing but running with a light client service of sorts * small test change * changed Protocol::LightClientBootstrap response limit * deleted some stuff from ConnectionHandler Implementation for the mock light client if you need to make something with multiple requests work maybe check here * deleted purging expired inbound/outbound streams code * deleted drive inbound streams that need to be processed * removed unused imports * made things private again * deleted inject_fully_negotiated_inbound * made more things private again * more * turned the logger off in the test * added failing test for new rpc * add rate limit for new rpcs * change InboundUpgrade function to use new rpcs. fmt. add test for LightClientFinalityUpdate * rebasing fix * add LightClientUpdate to handle_rpc functions * added context bytes * fmt * use correct unsed_tcp4_port function * fix for recent config changes and adding context_bytes for the light client protocols * fix clippy complaint * Merge branch 'unstable' into lc-reqresp # Conflicts: # beacon_node/beacon_processor/src/lib.rs # beacon_node/lighthouse_network/src/peer_manager/mod.rs # beacon_node/lighthouse_network/src/rpc/codec/ssz_snappy.rs # beacon_node/lighthouse_network/src/rpc/config.rs # beacon_node/lighthouse_network/src/rpc/methods.rs # beacon_node/lighthouse_network/src/rpc/mod.rs # beacon_node/lighthouse_network/src/rpc/outbound.rs # beacon_node/lighthouse_network/src/rpc/protocol.rs # beacon_node/lighthouse_network/src/rpc/rate_limiter.rs # beacon_node/lighthouse_network/src/rpc/self_limiter.rs # beacon_node/lighthouse_network/src/service/api_types.rs # beacon_node/lighthouse_network/tests/common/mod.rs # beacon_node/lighthouse_network/tests/rpc_tests.rs # beacon_node/network/src/network_beacon_processor/rpc_methods.rs # beacon_node/network/src/router.rs * Error handling updates and various cleanups. * Moar minor clean ups. * Do not ban peer for rate limiting light client requests * Merge branch 'unstable' into lc-reqresp. Also removed the mock light client tests to make it compile (See #4940). # Conflicts: # beacon_node/lighthouse_network/src/rpc/codec/ssz_snappy.rs # beacon_node/lighthouse_network/src/rpc/methods.rs # beacon_node/lighthouse_network/src/rpc/mod.rs # beacon_node/lighthouse_network/src/rpc/protocol.rs # beacon_node/lighthouse_network/src/service/api_types.rs # beacon_node/lighthouse_network/tests/common/mod.rs # beacon_node/network/src/network_beacon_processor/rpc_methods.rs # beacon_node/network/src/router.rs # consensus/types/src/light_client_bootstrap.rs # consensus/types/src/light_client_finality_update.rs # consensus/types/src/light_client_optimistic_update.rs * Remove unnecessary changes * Add missing light client queue handling. * Merge branch 'unstable' into lc-reqresp * Merge branch 'unstable' into lc-reqresp # Conflicts: # beacon_node/lighthouse_network/src/rpc/codec/ssz_snappy.rs # beacon_node/lighthouse_network/src/service/api_types.rs # consensus/types/src/light_client_finality_update.rs # consensus/types/src/light_client_optimistic_update.rs * Add context bytes for light client RPC responses. * Add RPC limits for light client object. * Fix lint * Fix incorrect light client max size computation. * Merge branch 'unstable' into lc-reqresp # Conflicts: # beacon_node/lighthouse_network/src/rpc/codec/ssz_snappy.rs # beacon_node/lighthouse_network/src/rpc/protocol.rs # beacon_node/lighthouse_network/src/service/api_types.rs * Remove unwanted local changes. * Merge branch 'unstable' into lc-reqresp * Replace `unimplemented` electra code path with deneb values.
64 lines
1.9 KiB
Rust
64 lines
1.9 KiB
Rust
use crate::common::decrease_balance;
|
|
use crate::per_epoch_processing::{
|
|
single_pass::{process_epoch_single_pass, SinglePassConfig},
|
|
Error,
|
|
};
|
|
use safe_arith::{SafeArith, SafeArithIter};
|
|
use types::{BeaconState, ChainSpec, EthSpec, Unsigned};
|
|
|
|
/// Process slashings.
|
|
pub fn process_slashings<E: EthSpec>(
|
|
state: &mut BeaconState<E>,
|
|
total_balance: u64,
|
|
spec: &ChainSpec,
|
|
) -> Result<(), Error> {
|
|
let epoch = state.current_epoch();
|
|
let sum_slashings = state.get_all_slashings().iter().copied().safe_sum()?;
|
|
|
|
let adjusted_total_slashing_balance = std::cmp::min(
|
|
sum_slashings.safe_mul(spec.proportional_slashing_multiplier_for_state(state))?,
|
|
total_balance,
|
|
);
|
|
|
|
let target_withdrawable_epoch =
|
|
epoch.safe_add(E::EpochsPerSlashingsVector::to_u64().safe_div(2)?)?;
|
|
let indices = state
|
|
.validators()
|
|
.iter()
|
|
.enumerate()
|
|
.filter(|(_, validator)| {
|
|
validator.slashed && target_withdrawable_epoch == validator.withdrawable_epoch
|
|
})
|
|
.map(|(index, validator)| (index, validator.effective_balance))
|
|
.collect::<Vec<(usize, u64)>>();
|
|
|
|
for (index, validator_effective_balance) in indices {
|
|
let increment = spec.effective_balance_increment;
|
|
let penalty_numerator = validator_effective_balance
|
|
.safe_div(increment)?
|
|
.safe_mul(adjusted_total_slashing_balance)?;
|
|
let penalty = penalty_numerator
|
|
.safe_div(total_balance)?
|
|
.safe_mul(increment)?;
|
|
|
|
decrease_balance(state, index, penalty)?;
|
|
}
|
|
|
|
Ok(())
|
|
}
|
|
|
|
pub fn process_slashings_slow<E: EthSpec>(
|
|
state: &mut BeaconState<E>,
|
|
spec: &ChainSpec,
|
|
) -> Result<(), Error> {
|
|
process_epoch_single_pass(
|
|
state,
|
|
spec,
|
|
SinglePassConfig {
|
|
slashings: true,
|
|
..SinglePassConfig::disable_all()
|
|
},
|
|
)?;
|
|
Ok(())
|
|
}
|