From d09523802b9dd3c1ef805a9943db2244a69b9c27 Mon Sep 17 00:00:00 2001 From: realbigsean Date: Fri, 23 Dec 2022 12:52:26 -0500 Subject: [PATCH] impl hash correctly for the blob wrapper --- consensus/types/src/blobs_sidecar.rs | 4 +++- consensus/types/src/signed_block_and_blobs.rs | 19 +++++-------------- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/consensus/types/src/blobs_sidecar.rs b/consensus/types/src/blobs_sidecar.rs index d522227a6f..de14f7cb52 100644 --- a/consensus/types/src/blobs_sidecar.rs +++ b/consensus/types/src/blobs_sidecar.rs @@ -1,3 +1,4 @@ +use derivative::Derivative; use crate::test_utils::TestRandom; use crate::{Blob, EthSpec, Hash256, SignedBeaconBlock, SignedRoot, Slot}; use kzg::KzgProof; @@ -10,9 +11,10 @@ use tree_hash_derive::TreeHash; #[cfg_attr(feature = "arbitrary-fuzz", derive(arbitrary::Arbitrary))] #[derive( - Debug, Clone, Serialize, Deserialize, Encode, Decode, TreeHash, PartialEq, Default, TestRandom, + Debug, Clone, Serialize, Deserialize, Encode, Decode, TreeHash, Default, TestRandom, Derivative )] #[serde(bound = "T: EthSpec")] +#[derivative(PartialEq, Hash(bound = "T: EthSpec"))] pub struct BlobsSidecar { pub beacon_block_root: Hash256, pub beacon_block_slot: Slot, diff --git a/consensus/types/src/signed_block_and_blobs.rs b/consensus/types/src/signed_block_and_blobs.rs index 4fcd09de4d..721fe59eca 100644 --- a/consensus/types/src/signed_block_and_blobs.rs +++ b/consensus/types/src/signed_block_and_blobs.rs @@ -5,6 +5,7 @@ use ssz::{Decode, DecodeError}; use ssz_derive::{Decode, Encode}; use std::sync::Arc; use tree_hash_derive::TreeHash; +use derivative::Derivative; #[derive(Debug, Clone, Serialize, Deserialize, Encode, Decode, TreeHash, PartialEq)] #[serde(bound = "T: EthSpec")] @@ -13,8 +14,8 @@ pub struct SignedBeaconBlockAndBlobsSidecarDecode { pub blobs_sidecar: BlobsSidecar, } -#[derive(Debug, Clone, Serialize, Deserialize, Encode, TreeHash, PartialEq)] -#[serde(bound = "T: EthSpec")] +#[derive(Debug, Clone, Serialize, Deserialize, Encode, TreeHash, Derivative)] +#[derivative(PartialEq, Hash(bound = "T: EthSpec"))] pub struct SignedBeaconBlockAndBlobsSidecar { pub beacon_block: Arc>, pub blobs_sidecar: Arc>, @@ -34,7 +35,8 @@ impl SignedBeaconBlockAndBlobsSidecar { } /// A wrapper over a [`SignedBeaconBlock`] or a [`SignedBeaconBlockAndBlobsSidecar`]. -#[derive(Clone, Debug)] +#[derive(Clone, Debug, Derivative)] +#[derivative(PartialEq, Hash(bound = "T: EthSpec"))] pub enum BlockWrapper { Block(Arc>), BlockAndBlob(SignedBeaconBlockAndBlobsSidecar), @@ -105,17 +107,6 @@ impl BlockWrapper { } } -// FIXME(sean): probably needs to be changed. This is needed because SignedBeaconBlockAndBlobsSidecar -// does not implement Hash -impl std::hash::Hash for BlockWrapper { - fn hash(&self, state: &mut H) { - match self { - BlockWrapper::Block(block) => block.hash(state), - BlockWrapper::BlockAndBlob(block_and_blob) => block_and_blob.beacon_block.hash(state), - } - } -} - impl From> for BlockWrapper { fn from(block: SignedBeaconBlock) -> Self { BlockWrapper::Block(Arc::new(block))