Skip to content

Commit

Permalink
Merge pull request #384 from ralexstokes/ssz-fixes
Browse files Browse the repository at this point in the history
derive SSZ traits for accesssory ref types regardless of mutability
  • Loading branch information
ralexstokes authored Apr 19, 2024
2 parents 732d9ea + 21c4390 commit 0f7b619
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 20 deletions.
3 changes: 2 additions & 1 deletion ethereum-consensus/src/types/beacon_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,8 @@ impl<
Err(serde::de::Error::custom("no variant could be deserialized from input"))
}
}
#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, PartialEq, Eq, HashTreeRoot)]
#[ssz(transparent)]
pub enum BeaconBlockRef<
'a,
const MAX_PROPOSER_SLASHINGS: usize,
Expand Down
3 changes: 2 additions & 1 deletion ethereum-consensus/src/types/beacon_block_body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,8 @@ impl<
Err(serde::de::Error::custom("no variant could be deserialized from input"))
}
}
#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, PartialEq, Eq, HashTreeRoot)]
#[ssz(transparent)]
pub enum BeaconBlockBodyRef<
'a,
const MAX_PROPOSER_SLASHINGS: usize,
Expand Down
3 changes: 2 additions & 1 deletion ethereum-consensus/src/types/beacon_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -959,7 +959,8 @@ impl<
Err(serde::de::Error::custom("no variant could be deserialized from input"))
}
}
#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, PartialEq, Eq, HashTreeRoot)]
#[ssz(transparent)]
pub enum BeaconStateRef<
'a,
const SLOTS_PER_HISTORICAL_ROOT: usize,
Expand Down
3 changes: 2 additions & 1 deletion ethereum-consensus/src/types/blinded_beacon_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,8 @@ impl<
Err(serde::de::Error::custom("no variant could be deserialized from input"))
}
}
#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, PartialEq, Eq, HashTreeRoot)]
#[ssz(transparent)]
pub enum BlindedBeaconBlockRef<
'a,
const MAX_PROPOSER_SLASHINGS: usize,
Expand Down
3 changes: 2 additions & 1 deletion ethereum-consensus/src/types/blinded_beacon_block_body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,8 @@ impl<
Err(serde::de::Error::custom("no variant could be deserialized from input"))
}
}
#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, PartialEq, Eq, HashTreeRoot)]
#[ssz(transparent)]
pub enum BlindedBeaconBlockBodyRef<
'a,
const MAX_PROPOSER_SLASHINGS: usize,
Expand Down
3 changes: 2 additions & 1 deletion ethereum-consensus/src/types/execution_payload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,8 @@ impl<
Err(serde::de::Error::custom("no variant could be deserialized from input"))
}
}
#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, PartialEq, Eq, HashTreeRoot)]
#[ssz(transparent)]
pub enum ExecutionPayloadRef<
'a,
const BYTES_PER_LOGS_BLOOM: usize,
Expand Down
3 changes: 2 additions & 1 deletion ethereum-consensus/src/types/execution_payload_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,8 @@ impl<'de, const BYTES_PER_LOGS_BLOOM: usize, const MAX_EXTRA_DATA_BYTES: usize>
Err(serde::de::Error::custom("no variant could be deserialized from input"))
}
}
#[derive(Debug, PartialEq, Eq)]
#[derive(Debug, PartialEq, Eq, HashTreeRoot)]
#[ssz(transparent)]
pub enum ExecutionPayloadHeaderRef<
'a,
const BYTES_PER_LOGS_BLOOM: usize,
Expand Down
18 changes: 5 additions & 13 deletions spec-gen/src/type_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ use crate::{
use convert_case::{Case, Casing};
use std::{collections::HashSet, fs};
use syn::{
parse_quote, token::Mut, visit::Visit, AngleBracketedGenericArguments, Arm, Attribute, Expr,
GenericParam, Generics, Ident, ImplItemMethod, Item, ItemStruct,
parse_quote, token::Mut, visit::Visit, AngleBracketedGenericArguments, Arm, Expr, GenericParam,
Generics, Ident, ImplItemMethod, Item, ItemStruct,
};

const SOURCE_ROOT: &str = "ethereum-consensus/src";
Expand Down Expand Up @@ -671,17 +671,10 @@ fn derive_ref_impl_type(
}
})
.collect::<Vec<syn::Variant>>();
let derive_attr: Attribute = if is_mut {
parse_quote!(#[derive(Debug, PartialEq, Eq, HashTreeRoot)])
} else {
parse_quote!(#[derive(Debug, PartialEq, Eq)])
};
let ssz_attr: Option<Attribute> =
if is_mut { Some(parse_quote!(#[ssz(transparent)])) } else { None };
(
parse_quote! {
#derive_attr
#ssz_attr
#[derive(Debug, PartialEq, Eq, HashTreeRoot)]
#[ssz(transparent)]
pub enum #type_name #generics {
#(#variant_defns,)*
}
Expand Down Expand Up @@ -828,8 +821,7 @@ fn render(target_type: &Type, items: Vec<Item>) {
}

pub fn run() {
let fork_sequence =
&[Fork::Phase0, Fork::Altair, Fork::Bellatrix, Fork::Capella, Fork::Deneb, Fork::Electra];
let fork_sequence = &[Fork::Phase0, Fork::Altair, Fork::Bellatrix, Fork::Capella, Fork::Deneb];
let types = [
Type::BeaconBlockBody,
Type::BeaconBlock,
Expand Down

0 comments on commit 0f7b619

Please sign in to comment.