mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-14 10:22:38 +00:00
Optimisations and bug fixes for state advance
This commit is reasonably performant on Prater!
This commit is contained in:
@@ -1462,6 +1462,15 @@ fn load_parent<T: BeaconChainTypes>(
|
||||
BeaconChainError::DBInconsistent(format!("Missing state {:?}", parent_state_root))
|
||||
})?;
|
||||
|
||||
if block.slot() != state.slot() {
|
||||
slog::warn!(
|
||||
chain.log,
|
||||
"Parent state is not advanced";
|
||||
"block_slot" => block.slot(),
|
||||
"state_slot" => state.slot(),
|
||||
);
|
||||
}
|
||||
|
||||
let beacon_state_root = if parent_state_root == advanced_state_root {
|
||||
Some(parent_state_root)
|
||||
} else {
|
||||
|
||||
@@ -49,8 +49,8 @@ enum Error {
|
||||
block_root: Hash256,
|
||||
},
|
||||
BadStateSlot {
|
||||
state_slot: Slot,
|
||||
current_slot: Slot,
|
||||
_state_slot: Slot,
|
||||
_current_slot: Slot,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -215,18 +215,18 @@ fn advance_head<T: BeaconChainTypes>(
|
||||
.get_advanced_state(head_block_root, current_slot, head_info.state_root)?
|
||||
.ok_or(Error::HeadMissingFromSnapshotCache(head_block_root))?;
|
||||
|
||||
if state.slot() == current_slot {
|
||||
if state.slot() == current_slot + 1 {
|
||||
return Err(Error::StateAlreadyAdvanced {
|
||||
block_root: head_block_root,
|
||||
});
|
||||
} else if state.slot() + 1 != current_slot {
|
||||
} else if state.slot() != current_slot {
|
||||
// Protect against advancing a state more than a single slot.
|
||||
//
|
||||
// Advancing more than one slot without storing the intermediate state would corrupt the
|
||||
// database. Future works might store temporary, intermediate states inside this function.
|
||||
return Err(Error::BadStateSlot {
|
||||
state_slot: state.slot(),
|
||||
current_slot: current_slot,
|
||||
_state_slot: state.slot(),
|
||||
_current_slot: current_slot,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -97,8 +97,9 @@ impl<'a, T: EthSpec> AttMaxCover<'a, T> {
|
||||
let mut proposer_reward_numerator = 0;
|
||||
let participation = participation_list.get(index)?;
|
||||
|
||||
let effective_balance = state.get_effective_balance(index).ok()?;
|
||||
let base_reward =
|
||||
altair::get_base_reward(state, index, total_active_balance, spec).ok()?;
|
||||
altair::get_base_reward(effective_balance, total_active_balance, spec).ok()?;
|
||||
|
||||
for (flag_index, weight) in PARTICIPATION_FLAG_WEIGHTS.iter().enumerate() {
|
||||
if att_participation_flags.contains(&flag_index)
|
||||
|
||||
@@ -717,7 +717,10 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
|
||||
if *state_root == self.get_split_info().state_root {
|
||||
let mut state = get_full_state(&self.hot_db, state_root, &self.spec)?
|
||||
.ok_or(HotColdDBError::MissingEpochBoundaryState(*state_root))?;
|
||||
state.apply_pending_mutations()?;
|
||||
|
||||
// Do a tree hash here so that the cache is fully built.
|
||||
state.update_tree_hash_cache()?;
|
||||
|
||||
let latest_block_root = state.get_latest_block_root(*state_root);
|
||||
return Ok(Some((state, latest_block_root)));
|
||||
}
|
||||
@@ -750,7 +753,7 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
|
||||
let state_root_iter = state_roots.into_iter().map(Ok);
|
||||
|
||||
let mut state = self.replay_blocks(prev_state, blocks, slot, state_root_iter)?;
|
||||
state.apply_pending_mutations()?;
|
||||
state.update_tree_hash_cache()?;
|
||||
|
||||
Ok(Some((state, latest_block_root)))
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user