Fix semantic Deneb <> tree-states conflicts

This commit is contained in:
Michael Sproul
2023-10-03 16:07:25 +11:00
parent 109c4a5d17
commit 9446fc88ed
20 changed files with 165 additions and 187 deletions

View File

@@ -280,6 +280,19 @@ impl From<BeaconStateHash> for Hash256 {
)),
num_fields(all()),
)),
Deneb(metastruct(
mappings(
map_beacon_state_deneb_fields(),
map_beacon_state_deneb_tree_list_fields(mutable, fallible, groups(tree_lists)),
),
bimappings(bimap_beacon_state_deneb_tree_list_fields(
other_type = "BeaconStateDeneb",
self_mutable,
fallible,
groups(tree_lists)
)),
num_fields(all()),
)),
),
cast_error(ty = "Error", expr = "Error::IncorrectStateVariant"),
partial_getter_error(ty = "Error", expr = "Error::IncorrectStateVariant")
@@ -414,6 +427,7 @@ where
only(Deneb),
partial_getter(rename = "latest_execution_payload_header_deneb")
)]
#[metastruct(exclude_from(tree_lists))]
pub latest_execution_payload_header: ExecutionPayloadHeaderDeneb<T>,
// Capella
@@ -570,31 +584,6 @@ impl<T: EthSpec> BeaconState<T> {
}
}
/// Specialised deserialisation method that uses the `ChainSpec` as context.
#[allow(clippy::arithmetic_side_effects)]
pub fn from_ssz_bytes(bytes: &[u8], spec: &ChainSpec) -> Result<Self, ssz::DecodeError> {
// Slot is after genesis_time (u64) and genesis_validators_root (Hash256).
let slot_start = <u64 as Decode>::ssz_fixed_len() + <Hash256 as Decode>::ssz_fixed_len();
let slot_end = slot_start + <Slot as Decode>::ssz_fixed_len();
let slot_bytes = bytes
.get(slot_start..slot_end)
.ok_or(DecodeError::InvalidByteLength {
len: bytes.len(),
expected: slot_end,
})?;
let slot = Slot::from_ssz_bytes(slot_bytes)?;
let fork_at_slot = spec.fork_name_at_slot::<T>(slot);
Ok(map_fork_name!(
fork_at_slot,
Self,
<_>::from_ssz_bytes(bytes)?
))
>>>>>>> origin/deneb-free-blobs
}
/// Returns the `tree_hash_root` of the state.
///
/// Spec v0.12.1
@@ -1404,6 +1393,16 @@ impl<T: EthSpec> BeaconState<T> {
&mut state.exit_cache,
&mut state.epoch_cache,
)),
BeaconState::Deneb(state) => Ok((
&mut state.validators,
&mut state.balances,
&state.previous_epoch_participation,
&state.current_epoch_participation,
&mut state.inactivity_scores,
&mut state.progressive_balances_cache,
&mut state.exit_cache,
&mut state.epoch_cache,
)),
}
}
@@ -2144,6 +2143,9 @@ impl<T: EthSpec, GenericValidator: ValidatorTrait> BeaconState<T, GenericValidat
Self::Capella(inner) => {
map_beacon_state_capella_tree_list_fields!(inner, |_, x| { x.apply_updates() })
}
Self::Deneb(inner) => {
map_beacon_state_deneb_tree_list_fields!(inner, |_, x| { x.apply_updates() })
}
}
self.eth1_data_votes_mut().apply_updates()?;
Ok(())
@@ -2199,6 +2201,11 @@ impl<T: EthSpec, GenericValidator: ValidatorTrait> BeaconState<T, GenericValidat
leaves.push(field.tree_hash_root());
});
}
BeaconState::Deneb(state) => {
map_beacon_state_deneb_fields!(state, |_, field| {
leaves.push(field.tree_hash_root());
});
}
};
// 3. Make deposit tree.

View File

@@ -1,6 +1,7 @@
use crate::{
BeaconState, BeaconStateAltair, BeaconStateBase, BeaconStateCapella, BeaconStateError as Error,
BeaconStateMerge, EthSpec, PublicKeyBytes, VList, Validator, ValidatorMutable,
BeaconState, BeaconStateAltair, BeaconStateBase, BeaconStateCapella, BeaconStateDeneb,
BeaconStateError as Error, BeaconStateMerge, EthSpec, PublicKeyBytes, VList, Validator,
ValidatorMutable,
};
use itertools::process_results;
use std::sync::Arc;
@@ -180,6 +181,23 @@ impl<E: EthSpec> BeaconState<E> {
next_withdrawal_validator_index
]
),
BeaconState::Deneb(s) => full_to_compact!(
s,
self,
Deneb,
BeaconStateDeneb,
[
previous_epoch_participation,
current_epoch_participation,
current_sync_committee,
next_sync_committee,
inactivity_scores,
latest_execution_payload_header,
historical_summaries,
next_withdrawal_index,
next_withdrawal_validator_index
]
),
}
}
}
@@ -241,6 +259,23 @@ impl<E: EthSpec> CompactBeaconState<E> {
next_withdrawal_validator_index
]
),
BeaconState::Deneb(inner) => compact_to_full!(
inner,
Deneb,
BeaconStateDeneb,
immutable_validators,
[
previous_epoch_participation,
current_epoch_participation,
current_sync_committee,
next_sync_committee,
inactivity_scores,
latest_execution_payload_header,
historical_summaries,
next_withdrawal_index,
next_withdrawal_validator_index
]
),
};
Ok(state)
}

View File

@@ -3,8 +3,8 @@ use crate::{test_utils::*, ForkName};
use beacon_chain::test_utils::{BeaconChainHarness, EphemeralHarnessType};
use beacon_chain::types::{
test_utils::TestRandom, BeaconState, BeaconStateAltair, BeaconStateBase, BeaconStateCapella,
BeaconStateError, BeaconStateMerge, ChainSpec, Domain, Epoch, EthSpec, FixedVector, Hash256,
Keypair, MainnetEthSpec, MinimalEthSpec, RelativeEpoch, Slot,
BeaconStateDeneb, BeaconStateError, BeaconStateMerge, ChainSpec, Domain, Epoch, EthSpec,
FixedVector, Hash256, Keypair, MainnetEthSpec, MinimalEthSpec, RelativeEpoch, Slot,
};
use ssz::Encode;
use std::ops::Mul;
@@ -416,6 +416,7 @@ fn check_num_fields_pow2() {
ForkName::Altair => BeaconStateAltair::<E>::NUM_FIELDS,
ForkName::Merge => BeaconStateMerge::<E>::NUM_FIELDS,
ForkName::Capella => BeaconStateCapella::<E>::NUM_FIELDS,
ForkName::Deneb => BeaconStateDeneb::<E>::NUM_FIELDS,
};
assert_eq!(
num_fields.next_power_of_two(),

View File

@@ -320,7 +320,7 @@ impl ChainSpec {
ForkName::Altair => self.inactivity_penalty_quotient_altair,
ForkName::Merge => self.inactivity_penalty_quotient_bellatrix,
ForkName::Capella => self.inactivity_penalty_quotient_bellatrix,
BeaconState::Deneb => self.inactivity_penalty_quotient_bellatrix,
ForkName::Deneb => self.inactivity_penalty_quotient_bellatrix,
}
}

View File

@@ -313,6 +313,9 @@ impl<'a, T: EthSpec> ExecutionPayloadHeaderRefMut<'a, T> {
ExecutionPayloadHeaderRefMut::Capella(mut_ref) => {
*mut_ref = header.try_into()?;
}
ExecutionPayloadHeaderRefMut::Deneb(mut_ref) => {
*mut_ref = header.try_into()?;
}
}
Ok(())
}

View File

@@ -210,7 +210,7 @@ pub type Uint256 = ethereum_types::U256;
pub type Address = H160;
pub type ForkVersion = [u8; 4];
pub type BLSFieldElement = Uint256;
pub type Blob<T> = FixedVector<u8, <T as EthSpec>::BytesPerBlob>;
pub type Blob<T> = ssz_types::FixedVector<u8, <T as EthSpec>::BytesPerBlob>;
pub type KzgProofs<T> = VariableList<KzgProof, <T as EthSpec>::MaxBlobCommitmentsPerBlock>;
pub type VersionedHash = Hash256;
pub type Hash64 = ethereum_types::H64;