From 519d82d831e4c54604963c88db349c04f85f5014 Mon Sep 17 00:00:00 2001 From: Mac L Date: Thu, 13 Jun 2024 14:01:10 +1000 Subject: [PATCH] Add Stable BeaconState --- consensus/types/src/beacon_state.rs | 45 ++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/consensus/types/src/beacon_state.rs b/consensus/types/src/beacon_state.rs index 577f282a556..6bcb8b15461 100644 --- a/consensus/types/src/beacon_state.rs +++ b/consensus/types/src/beacon_state.rs @@ -224,6 +224,7 @@ impl From for Hash256 { serde(bound = "E: EthSpec", deny_unknown_fields), arbitrary(bound = "E: EthSpec"), derivative(Clone), + tree_hash(struct_behaviour = "profile", max_fields = "typenum::U128"), ), specific_variant_attributes( Base(metastruct( @@ -321,7 +322,7 @@ impl From for Hash256 { #[serde(untagged)] #[serde(bound = "E: EthSpec")] #[arbitrary(bound = "E: EthSpec")] -#[tree_hash(enum_behaviour = "transparent")] +#[tree_hash(enum_behaviour = "transparent_stable")] #[ssz(enum_behaviour = "transparent")] pub struct BeaconState where @@ -331,100 +332,126 @@ where #[superstruct(getter(copy))] #[metastruct(exclude_from(tree_lists))] #[serde(with = "serde_utils::quoted_u64")] + #[tree_hash(stable_index = 0)] pub genesis_time: u64, #[superstruct(getter(copy))] #[metastruct(exclude_from(tree_lists))] + #[tree_hash(stable_index = 1)] pub genesis_validators_root: Hash256, #[superstruct(getter(copy))] #[metastruct(exclude_from(tree_lists))] + #[tree_hash(stable_index = 2)] pub slot: Slot, #[superstruct(getter(copy))] #[metastruct(exclude_from(tree_lists))] + #[tree_hash(stable_index = 3)] pub fork: Fork, // History #[metastruct(exclude_from(tree_lists))] + #[tree_hash(stable_index = 4)] pub latest_block_header: BeaconBlockHeader, #[test_random(default)] #[compare_fields(as_iter)] + #[tree_hash(stable_index = 5)] pub block_roots: Vector, #[test_random(default)] #[compare_fields(as_iter)] + #[tree_hash(stable_index = 6)] pub state_roots: Vector, // Frozen in Capella, replaced by historical_summaries #[test_random(default)] #[compare_fields(as_iter)] + #[tree_hash(stable_index = 7)] pub historical_roots: List, // Ethereum 1.0 chain data #[metastruct(exclude_from(tree_lists))] + #[tree_hash(stable_index = 8)] pub eth1_data: Eth1Data, #[test_random(default)] + #[tree_hash(stable_index = 9)] pub eth1_data_votes: List, #[superstruct(getter(copy))] #[metastruct(exclude_from(tree_lists))] #[serde(with = "serde_utils::quoted_u64")] + #[tree_hash(stable_index = 10)] pub eth1_deposit_index: u64, // Registry #[test_random(default)] + #[tree_hash(stable_index = 11)] pub validators: List, #[serde(with = "ssz_types::serde_utils::quoted_u64_var_list")] #[compare_fields(as_iter)] #[test_random(default)] + #[tree_hash(stable_index = 12)] pub balances: List, // Randomness #[test_random(default)] + #[tree_hash(stable_index = 13)] pub randao_mixes: Vector, // Slashings #[test_random(default)] #[serde(with = "ssz_types::serde_utils::quoted_u64_fixed_vec")] + #[tree_hash(stable_index = 14)] pub slashings: Vector, // Attestations (genesis fork only) #[superstruct(only(Base))] #[test_random(default)] + #[tree_hash(stable_index = 15)] pub previous_epoch_attestations: List, E::MaxPendingAttestations>, #[superstruct(only(Base))] #[test_random(default)] + #[tree_hash(stable_index = 16)] pub current_epoch_attestations: List, E::MaxPendingAttestations>, // Participation (Altair and later) #[superstruct(only(Altair, Bellatrix, Capella, Deneb, Electra))] #[test_random(default)] + #[tree_hash(stable_index = 15)] pub previous_epoch_participation: List, #[superstruct(only(Altair, Bellatrix, Capella, Deneb, Electra))] #[test_random(default)] + #[tree_hash(stable_index = 16)] pub current_epoch_participation: List, // Finality #[test_random(default)] #[metastruct(exclude_from(tree_lists))] + #[tree_hash(stable_index = 17)] pub justification_bits: BitVector, #[superstruct(getter(copy))] #[metastruct(exclude_from(tree_lists))] + #[tree_hash(stable_index = 18)] pub previous_justified_checkpoint: Checkpoint, #[superstruct(getter(copy))] #[metastruct(exclude_from(tree_lists))] + #[tree_hash(stable_index = 19)] pub current_justified_checkpoint: Checkpoint, #[superstruct(getter(copy))] #[metastruct(exclude_from(tree_lists))] + #[tree_hash(stable_index = 20)] pub finalized_checkpoint: Checkpoint, // Inactivity #[serde(with = "ssz_types::serde_utils::quoted_u64_var_list")] #[superstruct(only(Altair, Bellatrix, Capella, Deneb, Electra))] #[test_random(default)] + #[tree_hash(stable_index = 21)] pub inactivity_scores: List, // Light-client sync committees #[superstruct(only(Altair, Bellatrix, Capella, Deneb, Electra))] #[metastruct(exclude_from(tree_lists))] + #[tree_hash(stable_index = 22)] pub current_sync_committee: Arc>, #[superstruct(only(Altair, Bellatrix, Capella, Deneb, Electra))] #[metastruct(exclude_from(tree_lists))] + #[tree_hash(stable_index = 23)] pub next_sync_committee: Arc>, // Execution @@ -433,72 +460,88 @@ where partial_getter(rename = "latest_execution_payload_header_bellatrix") )] #[metastruct(exclude_from(tree_lists))] + #[tree_hash(stable_index = 24)] pub latest_execution_payload_header: ExecutionPayloadHeaderBellatrix, #[superstruct( only(Capella), partial_getter(rename = "latest_execution_payload_header_capella") )] #[metastruct(exclude_from(tree_lists))] + #[tree_hash(stable_index = 24)] pub latest_execution_payload_header: ExecutionPayloadHeaderCapella, #[superstruct( only(Deneb), partial_getter(rename = "latest_execution_payload_header_deneb") )] #[metastruct(exclude_from(tree_lists))] + #[tree_hash(stable_index = 24)] pub latest_execution_payload_header: ExecutionPayloadHeaderDeneb, #[superstruct( only(Electra), partial_getter(rename = "latest_execution_payload_header_electra") )] #[metastruct(exclude_from(tree_lists))] + #[tree_hash(stable_index = 24)] pub latest_execution_payload_header: ExecutionPayloadHeaderElectra, // Capella #[superstruct(only(Capella, Deneb, Electra), partial_getter(copy))] #[serde(with = "serde_utils::quoted_u64")] #[metastruct(exclude_from(tree_lists))] + #[tree_hash(stable_index = 25)] pub next_withdrawal_index: u64, #[superstruct(only(Capella, Deneb, Electra), partial_getter(copy))] #[serde(with = "serde_utils::quoted_u64")] #[metastruct(exclude_from(tree_lists))] + #[tree_hash(stable_index = 26)] pub next_withdrawal_validator_index: u64, // Deep history valid from Capella onwards. #[superstruct(only(Capella, Deneb, Electra))] #[test_random(default)] + #[tree_hash(stable_index = 27)] pub historical_summaries: List, // Electra #[superstruct(only(Electra), partial_getter(copy))] #[metastruct(exclude_from(tree_lists))] #[serde(with = "serde_utils::quoted_u64")] + #[tree_hash(stable_index = 28)] pub deposit_receipts_start_index: u64, #[superstruct(only(Electra), partial_getter(copy))] #[metastruct(exclude_from(tree_lists))] #[serde(with = "serde_utils::quoted_u64")] + #[tree_hash(stable_index = 29)] pub deposit_balance_to_consume: u64, #[superstruct(only(Electra), partial_getter(copy))] #[metastruct(exclude_from(tree_lists))] #[serde(with = "serde_utils::quoted_u64")] + #[tree_hash(stable_index = 30)] pub exit_balance_to_consume: u64, #[superstruct(only(Electra), partial_getter(copy))] #[metastruct(exclude_from(tree_lists))] + #[tree_hash(stable_index = 31)] pub earliest_exit_epoch: Epoch, #[superstruct(only(Electra), partial_getter(copy))] #[metastruct(exclude_from(tree_lists))] #[serde(with = "serde_utils::quoted_u64")] + #[tree_hash(stable_index = 32)] pub consolidation_balance_to_consume: u64, #[superstruct(only(Electra), partial_getter(copy))] #[metastruct(exclude_from(tree_lists))] + #[tree_hash(stable_index = 33)] pub earliest_consolidation_epoch: Epoch, #[test_random(default)] #[superstruct(only(Electra))] + #[tree_hash(stable_index = 34)] pub pending_balance_deposits: List, #[test_random(default)] #[superstruct(only(Electra))] + #[tree_hash(stable_index = 35)] pub pending_partial_withdrawals: List, #[test_random(default)] #[superstruct(only(Electra))] + #[tree_hash(stable_index = 36)] pub pending_consolidations: List, // Caching (not in the spec)