Skip to content

Commit c97918f

Browse files
committed
Merge branch 'unstable' into blobs-to-val-store
2 parents ee08d17 + 7e2df6b commit c97918f

24 files changed

+238
-93
lines changed

beacon_node/beacon_chain/src/block_reward.rs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use crate::{BeaconChain, BeaconChainError, BeaconChainTypes};
22
use eth2::lighthouse::{AttestationRewards, BlockReward, BlockRewardMeta};
3-
use operation_pool::{AttMaxCover, MaxCover, RewardCache, SplitAttestation};
3+
use operation_pool::{
4+
AttMaxCover, MaxCover, RewardCache, SplitAttestation, PROPOSER_REWARD_DENOMINATOR,
5+
};
46
use state_processing::{
57
common::get_attesting_indices_from_state,
68
per_block_processing::altair::sync_committee::compute_sync_aggregate_rewards,
@@ -65,13 +67,10 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
6567
let mut curr_epoch_total = 0;
6668

6769
for cover in &per_attestation_rewards {
68-
for &reward in cover.fresh_validators_rewards.values() {
69-
if cover.att.data.slot.epoch(T::EthSpec::slots_per_epoch()) == state.current_epoch()
70-
{
71-
curr_epoch_total += reward;
72-
} else {
73-
prev_epoch_total += reward;
74-
}
70+
if cover.att.data.slot.epoch(T::EthSpec::slots_per_epoch()) == state.current_epoch() {
71+
curr_epoch_total += cover.score() as u64;
72+
} else {
73+
prev_epoch_total += cover.score() as u64;
7574
}
7675
}
7776

@@ -80,7 +79,16 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
8079
// Drop the covers.
8180
let per_attestation_rewards = per_attestation_rewards
8281
.into_iter()
83-
.map(|cover| cover.fresh_validators_rewards)
82+
.map(|cover| {
83+
// Divide each reward numerator by the denominator. This can lead to the total being
84+
// less than the sum of the individual rewards due to the fact that integer division
85+
// does not distribute over addition.
86+
let mut rewards = cover.fresh_validators_rewards;
87+
rewards
88+
.values_mut()
89+
.for_each(|reward| *reward /= PROPOSER_REWARD_DENOMINATOR);
90+
rewards
91+
})
8492
.collect();
8593

8694
// Add the attestation data if desired.

beacon_node/http_api/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ pub fn serve<T: BeaconChainTypes>(
709709
.clone()
710710
.and(warp::path("validator_balances"))
711711
.and(warp::path::end())
712-
.and(warp_utils::json::json())
712+
.and(warp_utils::json::json_no_body())
713713
.then(
714714
|state_id: StateId,
715715
task_spawner: TaskSpawner<T::EthSpec>,

beacon_node/http_api/src/validators.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,13 @@ pub fn get_beacon_state_validator_balances<T: BeaconChainTypes>(
8181
.map_state_and_execution_optimistic_and_finalized(
8282
&chain,
8383
|state, execution_optimistic, finalized| {
84-
let ids_filter_set: Option<HashSet<&ValidatorId>> =
85-
optional_ids.map(|f| HashSet::from_iter(f.iter()));
84+
let ids_filter_set: Option<HashSet<&ValidatorId>> = match optional_ids {
85+
// if optional_ids (the request data body) is [], returns a `None`, so that later when calling .is_none_or() will return True
86+
// Hence, all validators will pass through .filter(), and balances of all validators are returned, in accordance to the spec
87+
Some([]) => None,
88+
Some(ids) => Some(HashSet::from_iter(ids.iter())),
89+
None => None,
90+
};
8691

8792
Ok((
8893
state

beacon_node/http_api/tests/tests.rs

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -927,18 +927,32 @@ impl ApiTester {
927927
.map(|res| res.data);
928928

929929
let expected = state_opt.map(|(state, _execution_optimistic, _finalized)| {
930-
let mut validators = Vec::with_capacity(validator_indices.len());
931-
932-
for i in validator_indices {
933-
if i < state.balances().len() as u64 {
934-
validators.push(ValidatorBalanceData {
935-
index: i,
936-
balance: *state.balances().get(i as usize).unwrap(),
937-
});
930+
// If validator_indices is empty, return balances for all validators
931+
if validator_indices.is_empty() {
932+
state
933+
.balances()
934+
.iter()
935+
.enumerate()
936+
.map(|(index, balance)| ValidatorBalanceData {
937+
index: index as u64,
938+
balance: *balance,
939+
})
940+
.collect()
941+
} else {
942+
// Same behaviour as before for the else branch
943+
let mut validators = Vec::with_capacity(validator_indices.len());
944+
945+
for i in validator_indices {
946+
if i < state.balances().len() as u64 {
947+
validators.push(ValidatorBalanceData {
948+
index: i,
949+
balance: *state.balances().get(i as usize).unwrap(),
950+
});
951+
}
938952
}
939-
}
940953

941-
validators
954+
validators
955+
}
942956
});
943957

944958
assert_eq!(result_index_ids, expected, "{:?}", state_id);

beacon_node/operation_pool/src/attestation.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,18 @@ use state_processing::common::{
77
use std::collections::HashMap;
88
use types::{
99
beacon_state::BeaconStateBase,
10-
consts::altair::{PARTICIPATION_FLAG_WEIGHTS, WEIGHT_DENOMINATOR},
10+
consts::altair::{PARTICIPATION_FLAG_WEIGHTS, PROPOSER_WEIGHT, WEIGHT_DENOMINATOR},
1111
Attestation, BeaconState, BitList, ChainSpec, EthSpec,
1212
};
1313

14+
pub const PROPOSER_REWARD_DENOMINATOR: u64 =
15+
(WEIGHT_DENOMINATOR - PROPOSER_WEIGHT) * WEIGHT_DENOMINATOR / PROPOSER_WEIGHT;
16+
1417
#[derive(Debug, Clone)]
1518
pub struct AttMaxCover<'a, E: EthSpec> {
1619
/// Underlying attestation.
1720
pub att: CompactAttestationRef<'a, E>,
18-
/// Mapping of validator indices and their rewards.
21+
/// Mapping of validator indices and their reward *numerators*.
1922
pub fresh_validators_rewards: HashMap<u64, u64>,
2023
}
2124

@@ -30,7 +33,7 @@ impl<'a, E: EthSpec> AttMaxCover<'a, E> {
3033
if let BeaconState::Base(ref base_state) = state {
3134
Self::new_for_base(att, state, base_state, total_active_balance, spec)
3235
} else {
33-
Self::new_for_altair_deneb(att, state, reward_cache, spec)
36+
Self::new_for_altair_or_later(att, state, reward_cache, spec)
3437
}
3538
}
3639

@@ -68,7 +71,7 @@ impl<'a, E: EthSpec> AttMaxCover<'a, E> {
6871
}
6972

7073
/// Initialise an attestation cover object for Altair or later.
71-
pub fn new_for_altair_deneb(
74+
pub fn new_for_altair_or_later(
7275
att: CompactAttestationRef<'a, E>,
7376
state: &BeaconState<E>,
7477
reward_cache: &'a RewardCache,
@@ -103,10 +106,7 @@ impl<'a, E: EthSpec> AttMaxCover<'a, E> {
103106
}
104107
}
105108

106-
let proposer_reward = proposer_reward_numerator
107-
.checked_div(WEIGHT_DENOMINATOR.checked_mul(spec.proposer_reward_quotient)?)?;
108-
109-
Some((index, proposer_reward)).filter(|_| proposer_reward != 0)
109+
Some((index, proposer_reward_numerator)).filter(|_| proposer_reward_numerator != 0)
110110
})
111111
.collect();
112112

@@ -163,7 +163,7 @@ impl<'a, E: EthSpec> MaxCover for AttMaxCover<'a, E> {
163163
}
164164

165165
fn score(&self) -> usize {
166-
self.fresh_validators_rewards.values().sum::<u64>() as usize
166+
(self.fresh_validators_rewards.values().sum::<u64>() / PROPOSER_REWARD_DENOMINATOR) as usize
167167
}
168168
}
169169

beacon_node/operation_pool/src/lib.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ mod reward_cache;
99
mod sync_aggregate_id;
1010

1111
pub use crate::bls_to_execution_changes::ReceivedPreCapella;
12-
pub use attestation::{earliest_attestation_validators, AttMaxCover};
12+
pub use attestation::{earliest_attestation_validators, AttMaxCover, PROPOSER_REWARD_DENOMINATOR};
1313
pub use attestation_storage::{CompactAttestationRef, SplitAttestation};
1414
pub use max_cover::MaxCover;
1515
pub use persistence::{
@@ -1402,7 +1402,8 @@ mod release_tests {
14021402
.retain(|validator_index, _| !seen_indices.contains(validator_index));
14031403

14041404
// Check that rewards are in decreasing order
1405-
let rewards = fresh_validators_rewards.values().sum();
1405+
let rewards =
1406+
fresh_validators_rewards.values().sum::<u64>() / PROPOSER_REWARD_DENOMINATOR;
14061407
assert!(prev_reward >= rewards);
14071408
prev_reward = rewards;
14081409
seen_indices.extend(fresh_validators_rewards.keys());

book/.markdownlint.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,8 @@ MD036: false
2525

2626
# MD040 code blocks should have a language specified: https://github.com/DavidAnson/markdownlint/blob/main/doc/md040.md
2727
# Set to false as the help_x.md files are code blocks without a language specified, which is fine and does not need to change
28-
MD040: false
28+
MD040: false
29+
30+
# MD059 Link text should be descriptive: https://github.com/DavidAnson/markdownlint/blob/main/doc/md059.md
31+
# Set to false because it is too strict
32+
MD059: false

book/src/advanced_database_migrations.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ Several conditions need to be met in order to run `lighthouse db`:
125125
2. The command must run as the user that owns the beacon node database. If you are using systemd then
126126
your beacon node might run as a user called `lighthousebeacon`.
127127
3. The `--datadir` flag must be set to the location of the Lighthouse data directory.
128-
4. The `--network` flag must be set to the correct network, e.g. `mainnet`, `holesky` or `sepolia`.
128+
4. The `--network` flag must be set to the correct network, e.g. `mainnet`, `hoodi` or `sepolia`.
129129

130130
The general form for a `lighthouse db` command is:
131131

book/src/advanced_release_candidates.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@ There can also be a scenario that a bug has been found and requires an urgent fi
4040

4141
## When *not* to use a release candidate
4242

43-
Other than the above scenarios, it is generally not recommended to use release candidates for any critical tasks on mainnet (e.g., staking). To test new release candidate features, try one of the testnets (e.g., Holesky).
43+
Other than the above scenarios, it is generally not recommended to use release candidates for any critical tasks on mainnet (e.g., staking). To test new release candidate features, try one of the testnets (e.g., Hoodi).

book/src/advanced_web3signer.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,11 @@ SSL client authentication with the "self-signed" certificate in `/home/paul/my-k
5656
> with a new timeout in milliseconds. This is the timeout before requests to Web3Signer are
5757
> considered to be failures. Setting a value that is too long may create contention and late duties
5858
> in the VC. Setting it too short will result in failed signatures and therefore missed duties.
59+
60+
## Slashing protection database
61+
62+
Web3signer can be configured with its own slashing protection database. This makes the local slashing protection database by Lighthouse redundant. To disable Lighthouse slashing protection database for web3signer keys, use the flag `--disable-slashing-protection-web3signer` on the validator client.
63+
64+
> Note: DO NOT use this flag unless you are certain that slashing protection is enabled on web3signer.
65+
66+
The `--init-slashing-protection` flag is also required to initialize the slashing protection database locally.

0 commit comments

Comments
 (0)