Implement tree states & hierarchical state DB

This commit is contained in:
Michael Sproul
2023-06-19 10:14:47 +10:00
parent 2bb62b7f7d
commit 23db089a7a
193 changed files with 6093 additions and 5925 deletions

View File

@@ -47,18 +47,17 @@ impl<'a, T: EthSpec> AttMaxCover<'a, T> {
.get_beacon_committee(att.data.slot, att.data.index)
.ok()?;
let indices = get_attesting_indices::<T>(committee.committee, &fresh_validators).ok()?;
let sqrt_total_active_balance = base::SqrtTotalActiveBalance::new(total_active_balance);
let fresh_validators_rewards: HashMap<u64, u64> = indices
.iter()
.copied()
.flat_map(|validator_index| {
let reward = base::get_base_reward(
state,
validator_index as usize,
total_active_balance,
spec,
)
.ok()?
.checked_div(spec.proposer_reward_quotient)?;
let effective_balance =
state.get_effective_balance(validator_index as usize).ok()?;
let reward =
base::get_base_reward(effective_balance, sqrt_total_active_balance, spec)
.ok()?
.checked_div(spec.proposer_reward_quotient)?;
Some((validator_index, reward))
})
.collect();
@@ -99,8 +98,11 @@ impl<'a, T: EthSpec> AttMaxCover<'a, T> {
let mut proposer_reward_numerator = 0;
// FIXME(sproul): store base_reward in reward cache
// let effective_balance = reward_cache.get_effective_balance(index)?;
let effective_balance = state.get_effective_balance(index as usize).ok()?;
let base_reward =
altair::get_base_reward(state, index as usize, base_reward_per_increment, spec)
altair::get_base_reward(effective_balance, base_reward_per_increment, spec)
.ok()?;
for (flag_index, weight) in PARTICIPATION_FLAG_WEIGHTS.iter().enumerate() {

View File

@@ -379,7 +379,7 @@ impl<T: EthSpec> OperationPool<T> {
&& state
.validators()
.get(slashing.as_inner().signed_header_1.message.proposer_index as usize)
.map_or(false, |validator| !validator.slashed)
.map_or(false, |validator| !validator.slashed())
},
|slashing| slashing.as_inner().clone(),
T::MaxProposerSlashings::to_usize(),
@@ -438,7 +438,7 @@ impl<T: EthSpec> OperationPool<T> {
pub fn prune_proposer_slashings(&self, head_state: &BeaconState<T>) {
prune_validator_hash_map(
&mut self.proposer_slashings.write(),
|_, validator| validator.exit_epoch <= head_state.finalized_checkpoint().epoch,
|_, validator| validator.exit_epoch() <= head_state.finalized_checkpoint().epoch,
head_state,
);
}
@@ -457,7 +457,7 @@ impl<T: EthSpec> OperationPool<T> {
//
// We cannot check the `slashed` field since the `head` is not finalized and
// a fork could un-slash someone.
validator.exit_epoch > head_state.finalized_checkpoint().epoch
validator.exit_epoch() > head_state.finalized_checkpoint().epoch
})
.map_or(false, |indices| !indices.is_empty());
@@ -514,7 +514,7 @@ impl<T: EthSpec> OperationPool<T> {
//
// We choose simplicity over the gain of pruning more exits since they are small and
// should not be seen frequently.
|_, validator| validator.exit_epoch <= head_state.finalized_checkpoint().epoch,
|_, validator| validator.exit_epoch() <= head_state.finalized_checkpoint().epoch,
head_state,
);
}

View File

@@ -205,8 +205,8 @@ impl<T: EthSpec> StoreItem for PersistedOperationPoolV5<T> {
DBColumn::OpPool
}
fn as_store_bytes(&self) -> Vec<u8> {
self.as_ssz_bytes()
fn as_store_bytes(&self) -> Result<Vec<u8>, StoreError> {
Ok(self.as_ssz_bytes())
}
fn from_store_bytes(bytes: &[u8]) -> Result<Self, StoreError> {
@@ -219,8 +219,8 @@ impl<T: EthSpec> StoreItem for PersistedOperationPoolV12<T> {
DBColumn::OpPool
}
fn as_store_bytes(&self) -> Vec<u8> {
self.as_ssz_bytes()
fn as_store_bytes(&self) -> Result<Vec<u8>, StoreError> {
Ok(self.as_ssz_bytes())
}
fn from_store_bytes(bytes: &[u8]) -> Result<Self, StoreError> {
@@ -233,8 +233,8 @@ impl<T: EthSpec> StoreItem for PersistedOperationPoolV14<T> {
DBColumn::OpPool
}
fn as_store_bytes(&self) -> Vec<u8> {
self.as_ssz_bytes()
fn as_store_bytes(&self) -> Result<Vec<u8>, StoreError> {
Ok(self.as_ssz_bytes())
}
fn from_store_bytes(bytes: &[u8]) -> Result<Self, StoreError> {
@@ -247,8 +247,8 @@ impl<T: EthSpec> StoreItem for PersistedOperationPoolV15<T> {
DBColumn::OpPool
}
fn as_store_bytes(&self) -> Vec<u8> {
self.as_ssz_bytes()
fn as_store_bytes(&self) -> Result<Vec<u8>, StoreError> {
Ok(self.as_ssz_bytes())
}
fn from_store_bytes(bytes: &[u8]) -> Result<Self, StoreError> {
@@ -262,8 +262,8 @@ impl<T: EthSpec> StoreItem for PersistedOperationPool<T> {
DBColumn::OpPool
}
fn as_store_bytes(&self) -> Vec<u8> {
self.as_ssz_bytes()
fn as_store_bytes(&self) -> Result<Vec<u8>, StoreError> {
Ok(self.as_ssz_bytes())
}
fn from_store_bytes(bytes: &[u8]) -> Result<Self, StoreError> {