Skip to content

Commit 23db089

Browse files
committed
Implement tree states & hierarchical state DB
1 parent 2bb62b7 commit 23db089

File tree

193 files changed

+6079
-5911
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

193 files changed

+6079
-5911
lines changed

Cargo.lock

Lines changed: 406 additions & 119 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

account_manager/src/validator/exit.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,8 @@ async fn publish_voluntary_exit<E: EthSpec>(
210210
let validator_data = get_validator_data(client, &keypair.pk).await?;
211211
match validator_data.status {
212212
ValidatorStatus::ActiveExiting => {
213-
let exit_epoch = validator_data.validator.exit_epoch;
214-
let withdrawal_epoch = validator_data.validator.withdrawable_epoch;
213+
let exit_epoch = validator_data.validator.exit_epoch();
214+
let withdrawal_epoch = validator_data.validator.withdrawable_epoch();
215215
let current_epoch = get_current_epoch::<E>(genesis_data.genesis_time, spec)
216216
.ok_or("Failed to get current epoch. Please check your system time")?;
217217
eprintln!("Voluntary exit has been accepted into the beacon chain, but not yet finalized. \
@@ -231,7 +231,7 @@ async fn publish_voluntary_exit<E: EthSpec>(
231231
ValidatorStatus::ExitedSlashed | ValidatorStatus::ExitedUnslashed => {
232232
eprintln!(
233233
"Validator has exited on epoch: {}",
234-
validator_data.validator.exit_epoch
234+
validator_data.validator.exit_epoch()
235235
);
236236
break;
237237
}
@@ -257,7 +257,7 @@ async fn get_validator_index_for_exit(
257257
ValidatorStatus::ActiveOngoing => {
258258
let eligible_epoch = validator_data
259259
.validator
260-
.activation_epoch
260+
.activation_epoch()
261261
.safe_add(spec.shard_committee_period)
262262
.map_err(|e| format!("Failed to calculate eligible epoch, validator activation epoch too high: {:?}", e))?;
263263

beacon_node/beacon_chain/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,12 @@ strum = { version = "0.24.0", features = ["derive"] }
6060
logging = { path = "../../common/logging" }
6161
execution_layer = { path = "../execution_layer" }
6262
sensitive_url = { path = "../../common/sensitive_url" }
63-
superstruct = "0.5.0"
63+
superstruct = "0.7.0"
6464
hex = "0.4.2"
6565
exit-future = "0.2.0"
6666
unused_port = {path = "../../common/unused_port"}
6767
oneshot_broadcast = { path = "../../common/oneshot_broadcast" }
68+
crossbeam-channel = "0.5.5"
6869

6970
[[test]]
7071
name = "beacon_chain_tests"

beacon_node/beacon_chain/src/attestation_rewards.rs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
4242
.ok_or(BeaconChainError::MissingBeaconState(state_root))?;
4343

4444
// Calculate ideal_rewards
45-
let participation_cache = ParticipationCache::new(&state, spec)?;
45+
let participation_cache = ParticipationCache::new(&state, spec)
46+
.map_err(|_| BeaconChainError::AttestationRewardsError)?;
4647

4748
let previous_epoch = state.previous_epoch();
4849

@@ -52,13 +53,9 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
5253
let weight = get_flag_weight(flag_index)
5354
.map_err(|_| BeaconChainError::AttestationRewardsError)?;
5455

55-
let unslashed_participating_indices = participation_cache
56-
.get_unslashed_participating_indices(flag_index, previous_epoch)?;
57-
58-
let unslashed_participating_balance =
59-
unslashed_participating_indices
60-
.total_balance()
61-
.map_err(|_| BeaconChainError::AttestationRewardsError)?;
56+
let unslashed_participating_balance = participation_cache
57+
.previous_epoch_flag_attesting_balance(flag_index)
58+
.map_err(|_| BeaconChainError::AttestationRewardsError)?;
6259

6360
let unslashed_participating_increments =
6461
unslashed_participating_balance.safe_div(spec.effective_balance_increment)?;
@@ -112,23 +109,24 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
112109
.collect::<Result<Vec<_>, _>>()?
113110
};
114111

115-
for validator_index in &validators {
116-
let eligible = state.is_eligible_validator(previous_epoch, *validator_index)?;
112+
for &validator_index in &validators {
113+
let validator = participation_cache
114+
.get_validator(validator_index)
115+
.map_err(|_| BeaconChainError::AttestationRewardsError)?;
116+
let eligible = validator.is_eligible;
117117
let mut head_reward = 0u64;
118118
let mut target_reward = 0i64;
119119
let mut source_reward = 0i64;
120120

121121
if eligible {
122-
let effective_balance = state.get_effective_balance(*validator_index)?;
122+
let effective_balance = validator.effective_balance;
123123

124124
for flag_index in 0..PARTICIPATION_FLAG_WEIGHTS.len() {
125125
let (ideal_reward, penalty) = ideal_rewards_hashmap
126126
.get(&(flag_index, effective_balance))
127127
.ok_or(BeaconChainError::AttestationRewardsError)?;
128-
let voted_correctly = participation_cache
129-
.get_unslashed_participating_indices(flag_index, previous_epoch)
130-
.map_err(|_| BeaconChainError::AttestationRewardsError)?
131-
.contains(*validator_index)
128+
let voted_correctly = validator
129+
.is_unslashed_participating_index(flag_index)
132130
.map_err(|_| BeaconChainError::AttestationRewardsError)?;
133131
if voted_correctly {
134132
if flag_index == TIMELY_HEAD_FLAG_INDEX {
@@ -148,7 +146,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
148146
}
149147
}
150148
total_rewards.push(TotalAttestationRewards {
151-
validator_index: *validator_index as u64,
149+
validator_index: validator_index as u64,
152150
head: head_reward,
153151
target: target_reward,
154152
source: source_reward,

beacon_node/beacon_chain/src/beacon_block_reward.rs

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@ use operation_pool::RewardCache;
44
use safe_arith::SafeArith;
55
use slog::error;
66
use state_processing::{
7-
common::{
8-
altair, get_attestation_participation_flag_indices, get_attesting_indices_from_state,
9-
},
7+
common::{get_attestation_participation_flag_indices, get_attesting_indices_from_state},
108
per_block_processing::{
119
altair::sync_committee::compute_sync_aggregate_rewards, get_slashable_indices,
1210
},
11+
ConsensusContext,
1312
};
1413
use store::{
1514
consts::altair::{PARTICIPATION_FLAG_WEIGHTS, PROPOSER_WEIGHT, WEIGHT_DENOMINATOR},
@@ -124,7 +123,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
124123
proposer_slashing_reward.safe_add_assign(
125124
state
126125
.get_validator(proposer_slashing.proposer_index() as usize)?
127-
.effective_balance
126+
.effective_balance()
128127
.safe_div(self.spec.whistleblower_reward_quotient)?,
129128
)?;
130129
}
@@ -146,7 +145,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
146145
attester_slashing_reward.safe_add_assign(
147146
state
148147
.get_validator(attester_index as usize)?
149-
.effective_balance
148+
.effective_balance()
150149
.safe_div(self.spec.whistleblower_reward_quotient)?,
151150
)?;
152151
}
@@ -178,9 +177,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
178177
block: BeaconBlockRef<'_, T::EthSpec, Payload>,
179178
state: &mut BeaconState<T::EthSpec>,
180179
) -> Result<BeaconBlockSubRewardValue, BeaconChainError> {
181-
let total_active_balance = state.get_total_active_balance()?;
182-
let base_reward_per_increment =
183-
altair::BaseRewardPerIncrement::new(total_active_balance, &self.spec)?;
180+
let mut ctxt = ConsensusContext::new(block.slot());
184181

185182
let mut total_proposer_reward = 0;
186183

@@ -216,13 +213,9 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
216213
{
217214
validator_participation.add_flag(flag_index)?;
218215
proposer_reward_numerator.safe_add_assign(
219-
altair::get_base_reward(
220-
state,
221-
index,
222-
base_reward_per_increment,
223-
&self.spec,
224-
)?
225-
.safe_mul(weight)?,
216+
ctxt.get_base_reward(state, index, &self.spec)
217+
.map_err(|_| BeaconChainError::BlockRewardAttestationError)?
218+
.safe_mul(weight)?,
226219
)?;
227220
}
228221
}

beacon_node/beacon_chain/src/beacon_block_streamer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ impl<T: BeaconChainTypes> BeaconBlockStreamer<T> {
429429
continue;
430430
}
431431

432-
match self.beacon_chain.store.try_get_full_block(&root) {
432+
match self.beacon_chain.store.try_get_full_block(&root, None) {
433433
Err(e) => db_blocks.push((root, Err(e.into()))),
434434
Ok(opt_block) => db_blocks.push((
435435
root,

0 commit comments

Comments
 (0)