Unimplement TreeHash for BeaconState (#6083)

* Unimplement `TreeHash` for `BeaconState`
This commit is contained in:
Michael Sproul
2024-07-12 23:06:08 +10:00
committed by GitHub
parent 0c0b56d9e8
commit 2f0af2be89
16 changed files with 117 additions and 70 deletions

View File

@@ -93,7 +93,6 @@ use std::io::Write;
use std::sync::Arc;
use store::{Error as DBError, HotStateSummary, KeyValueStore, StoreOp};
use task_executor::JoinHandle;
use tree_hash::TreeHash;
use types::{
BeaconBlockRef, BeaconState, BeaconStateError, ChainSpec, Epoch, EthSpec, ExecutionBlockHash,
Hash256, InconsistentFork, PublicKey, PublicKeyBytes, RelativeEpoch, SignedBeaconBlock,
@@ -2107,7 +2106,14 @@ pub fn verify_header_signature<T: BeaconChainTypes, Err: BlockBlobError>(
fn write_state<E: EthSpec>(prefix: &str, state: &BeaconState<E>, log: &Logger) {
if WRITE_BLOCK_PROCESSING_SSZ {
let root = state.tree_hash_root();
let mut state = state.clone();
let Ok(root) = state.canonical_root() else {
error!(
log,
"Unable to hash state for writing";
);
return;
};
let filename = format!("{}_slot_{}_root_{}.ssz", prefix, state.slot(), root);
let mut path = std::env::temp_dir().join("lighthouse");
let _ = fs::create_dir_all(path.clone());

View File

@@ -1195,7 +1195,7 @@ mod test {
let head = chain.head_snapshot();
let state = &head.beacon_state;
let mut state = head.beacon_state.clone();
let block = &head.beacon_block;
assert_eq!(state.slot(), Slot::new(0), "should start from genesis");
@@ -1206,7 +1206,7 @@ mod test {
);
assert_eq!(
block.state_root(),
state.canonical_root(),
state.canonical_root().unwrap(),
"block should have correct state root"
);
assert_eq!(

View File

@@ -720,12 +720,12 @@ mod test {
let mut state_roots = Vec::new();
// Get enough blocks to fill the cache to capacity, ensuring all blocks have blobs
while pending_blocks.len() < capacity {
let (pending_block, _) = availability_pending_block(&harness).await;
let (mut pending_block, _) = availability_pending_block(&harness).await;
if pending_block.num_blobs_expected() == 0 {
// we need blocks with blobs
continue;
}
let state_root = pending_block.import_data.state.canonical_root();
let state_root = pending_block.import_data.state.canonical_root().unwrap();
states.push(pending_block.import_data.state.clone());
pending_blocks.push_back(pending_block);
state_roots.push(state_root);

View File

@@ -209,10 +209,10 @@ impl<T: BeaconChainTypes> StateLRUCache<T> {
impl<E: EthSpec> From<AvailabilityPendingExecutedBlock<E>>
for DietAvailabilityPendingExecutedBlock<E>
{
fn from(value: AvailabilityPendingExecutedBlock<E>) -> Self {
fn from(mut value: AvailabilityPendingExecutedBlock<E>) -> Self {
Self {
block: value.block,
state_root: value.import_data.state.canonical_root(),
state_root: value.import_data.state.canonical_root().unwrap(),
parent_block: value.import_data.parent_block,
parent_eth1_finalization_data: value.import_data.parent_eth1_finalization_data,
confirmed_state_roots: value.import_data.confirmed_state_roots,

View File

@@ -2246,7 +2246,7 @@ where
.unwrap();
state = new_state;
block_hash_from_slot.insert(*slot, block_hash);
state_hash_from_slot.insert(*slot, state.tree_hash_root().into());
state_hash_from_slot.insert(*slot, state.canonical_root().unwrap().into());
latest_block_hash = Some(block_hash);
}
(