Skip to content

Commit 9911f34

Browse files
authored
Feature gate arbitrary crate in the consensus types crate (#7743)
Which issue # does this PR address? Puts the `arbitrary` crate behind a feature flag in the `types` crate.
1 parent 4daa015 commit 9911f34

File tree

82 files changed

+404
-576
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

82 files changed

+404
-576
lines changed

Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ malloc_utils = { path = "common/malloc_utils" }
184184
maplit = "1"
185185
merkle_proof = { path = "consensus/merkle_proof" }
186186
metrics = { path = "common/metrics" }
187-
milhouse = "0.6"
187+
milhouse = { version = "0.7", default-features = false }
188188
mockall = "0.13"
189189
mockall_double = "0.3"
190190
mockito = "1.5.0"

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM rust:1.84.0-bullseye AS builder
1+
FROM rust:1.88.0-bullseye AS builder
22
RUN apt-get update && apt-get -y upgrade && apt-get install -y cmake libclang-dev
33
COPY . lighthouse
44
ARG FEATURES

consensus/types/Cargo.toml

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,22 @@ default = ["sqlite", "legacy-arith"]
99
# Allow saturating arithmetic on slots and epochs. Enabled by default, but deprecated.
1010
legacy-arith = []
1111
sqlite = ["dep:rusqlite"]
12-
# The `arbitrary-fuzz` feature is a no-op provided for backwards compatibility.
13-
# For simplicity `Arbitrary` is now derived regardless of the feature's presence.
14-
arbitrary-fuzz = []
12+
arbitrary = [
13+
"dep:arbitrary",
14+
"bls/arbitrary",
15+
"ethereum_ssz/arbitrary",
16+
"milhouse/arbitrary",
17+
"ssz_types/arbitrary",
18+
"swap_or_not_shuffle/arbitrary",
19+
]
20+
arbitrary-fuzz = ["arbitrary"]
1521
portable = ["bls/supranational-portable"]
1622

1723
[dependencies]
1824
alloy-primitives = { workspace = true }
1925
alloy-rlp = { version = "0.3.4", features = ["derive"] }
20-
# The arbitrary dependency is enabled by default since Capella to avoid complexity introduced by
21-
# `AbstractExecPayload`
22-
arbitrary = { workspace = true, features = ["derive"] }
23-
bls = { workspace = true, features = ["arbitrary"] }
26+
arbitrary = { workspace = true, features = ["derive"], optional = true }
27+
bls = { workspace = true }
2428
compare_fields = { workspace = true }
2529
compare_fields_derive = { workspace = true }
2630
context_deserialize = { workspace = true }
@@ -29,7 +33,7 @@ derivative = { workspace = true }
2933
eth2_interop_keypairs = { path = "../../common/eth2_interop_keypairs" }
3034
ethereum_hashing = { workspace = true }
3135
ethereum_serde_utils = { workspace = true }
32-
ethereum_ssz = { workspace = true, features = ["arbitrary"] }
36+
ethereum_ssz = { workspace = true }
3337
ethereum_ssz_derive = { workspace = true }
3438
fixed_bytes = { workspace = true }
3539
hex = { workspace = true }
@@ -52,9 +56,9 @@ serde = { workspace = true, features = ["rc"] }
5256
serde_json = { workspace = true }
5357
serde_yaml = { workspace = true }
5458
smallvec = { workspace = true }
55-
ssz_types = { workspace = true, features = ["arbitrary"] }
59+
ssz_types = { workspace = true }
5660
superstruct = { workspace = true }
57-
swap_or_not_shuffle = { workspace = true, features = ["arbitrary"] }
61+
swap_or_not_shuffle = { workspace = true }
5862
tempfile = { workspace = true }
5963
test_random_derive = { path = "../../common/test_random_derive" }
6064
tracing = { workspace = true }

consensus/types/src/activation_queue.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ use crate::{ChainSpec, Epoch, Validator};
22
use std::collections::BTreeSet;
33

44
/// Activation queue computed during epoch processing for use in the *next* epoch.
5-
#[derive(Debug, PartialEq, Eq, Default, Clone, arbitrary::Arbitrary)]
5+
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
6+
#[derive(Debug, PartialEq, Eq, Default, Clone)]
67
pub struct ActivationQueue {
78
/// Validators represented by `(activation_eligibility_epoch, index)` in sorted order.
89
///

consensus/types/src/aggregate_and_proof.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use tree_hash_derive::TreeHash;
1616
variants(Base, Electra),
1717
variant_attributes(
1818
derive(
19-
arbitrary::Arbitrary,
2019
Debug,
2120
Clone,
2221
PartialEq,
@@ -29,23 +28,29 @@ use tree_hash_derive::TreeHash;
2928
),
3029
context_deserialize(ForkName),
3130
serde(bound = "E: EthSpec"),
32-
arbitrary(bound = "E: EthSpec"),
31+
cfg_attr(
32+
feature = "arbitrary",
33+
derive(arbitrary::Arbitrary),
34+
arbitrary(bound = "E: EthSpec"),
35+
),
3336
),
3437
ref_attributes(
35-
derive(Debug, PartialEq, TreeHash, Serialize,),
38+
derive(Debug, PartialEq, TreeHash, Serialize),
3639
serde(untagged, bound = "E: EthSpec"),
3740
tree_hash(enum_behaviour = "transparent")
3841
),
3942
map_ref_into(AttestationRef)
4043
)]
41-
#[derive(
42-
arbitrary::Arbitrary, Debug, Clone, PartialEq, Serialize, Deserialize, Encode, TreeHash,
44+
#[cfg_attr(
45+
feature = "arbitrary",
46+
derive(arbitrary::Arbitrary),
47+
arbitrary(bound = "E: EthSpec")
4348
)]
49+
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Encode, TreeHash)]
4450
#[serde(untagged)]
4551
#[tree_hash(enum_behaviour = "transparent")]
4652
#[ssz(enum_behaviour = "transparent")]
4753
#[serde(bound = "E: EthSpec", deny_unknown_fields)]
48-
#[arbitrary(bound = "E: EthSpec")]
4954
pub struct AggregateAndProof<E: EthSpec> {
5055
/// The index of the validator that created the attestation.
5156
#[serde(with = "serde_utils::quoted_u64")]

consensus/types/src/attestation.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,34 +46,31 @@ impl From<ssz_types::Error> for Error {
4646
Encode,
4747
TestRandom,
4848
Derivative,
49-
arbitrary::Arbitrary,
5049
TreeHash,
5150
),
5251
context_deserialize(ForkName),
5352
derivative(PartialEq, Hash(bound = "E: EthSpec")),
5453
serde(bound = "E: EthSpec", deny_unknown_fields),
55-
arbitrary(bound = "E: EthSpec"),
54+
cfg_attr(
55+
feature = "arbitrary",
56+
derive(arbitrary::Arbitrary),
57+
arbitrary(bound = "E: EthSpec")
58+
)
5659
),
5760
ref_attributes(derive(TreeHash), tree_hash(enum_behaviour = "transparent")),
5861
cast_error(ty = "Error", expr = "Error::IncorrectStateVariant"),
5962
partial_getter_error(ty = "Error", expr = "Error::IncorrectStateVariant")
6063
)]
61-
#[derive(
62-
Debug,
63-
Clone,
64-
Serialize,
65-
TreeHash,
66-
Encode,
67-
Derivative,
68-
Deserialize,
69-
arbitrary::Arbitrary,
70-
PartialEq,
64+
#[cfg_attr(
65+
feature = "arbitrary",
66+
derive(arbitrary::Arbitrary),
67+
arbitrary(bound = "E: EthSpec")
7168
)]
69+
#[derive(Debug, Clone, Serialize, TreeHash, Encode, Derivative, Deserialize, PartialEq)]
7270
#[serde(untagged)]
7371
#[tree_hash(enum_behaviour = "transparent")]
7472
#[ssz(enum_behaviour = "transparent")]
7573
#[serde(bound = "E: EthSpec", deny_unknown_fields)]
76-
#[arbitrary(bound = "E: EthSpec")]
7774
pub struct Attestation<E: EthSpec> {
7875
#[superstruct(only(Base), partial_getter(rename = "aggregation_bits_base"))]
7976
pub aggregation_bits: BitList<E::MaxValidatorsPerCommittee>,
@@ -601,6 +598,7 @@ impl<'de, E: EthSpec> ContextDeserialize<'de, ForkName> for Vec<Attestation<E>>
601598
}
602599
*/
603600

601+
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
604602
#[derive(
605603
Debug,
606604
Clone,
@@ -610,7 +608,6 @@ impl<'de, E: EthSpec> ContextDeserialize<'de, ForkName> for Vec<Attestation<E>>
610608
Encode,
611609
TestRandom,
612610
Derivative,
613-
arbitrary::Arbitrary,
614611
TreeHash,
615612
PartialEq,
616613
)]

consensus/types/src/attestation_data.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ use tree_hash_derive::TreeHash;
99
/// The data upon which an attestation is based.
1010
///
1111
/// Spec v0.12.1
12+
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
1213
#[derive(
13-
arbitrary::Arbitrary,
1414
Debug,
1515
Clone,
1616
PartialEq,

consensus/types/src/attestation_duty.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use crate::*;
22
use serde::{Deserialize, Serialize};
33

4-
#[derive(arbitrary::Arbitrary, Debug, PartialEq, Clone, Copy, Default, Serialize, Deserialize)]
4+
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
5+
#[derive(Debug, PartialEq, Clone, Copy, Default, Serialize, Deserialize)]
56
pub struct AttestationDuty {
67
/// The slot during which the attester must attest.
78
pub slot: Slot,

consensus/types/src/attester_slashing.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,26 @@ use tree_hash_derive::TreeHash;
2525
Decode,
2626
TreeHash,
2727
TestRandom,
28-
arbitrary::Arbitrary
2928
),
3029
context_deserialize(ForkName),
3130
derivative(PartialEq, Eq, Hash(bound = "E: EthSpec")),
3231
serde(bound = "E: EthSpec"),
33-
arbitrary(bound = "E: EthSpec")
32+
cfg_attr(
33+
feature = "arbitrary",
34+
derive(arbitrary::Arbitrary),
35+
arbitrary(bound = "E: EthSpec")
36+
),
3437
),
3538
ref_attributes(derive(Debug))
3639
)]
37-
#[derive(
38-
Debug, Clone, Serialize, Encode, Deserialize, TreeHash, Derivative, arbitrary::Arbitrary,
40+
#[cfg_attr(
41+
feature = "arbitrary",
42+
derive(arbitrary::Arbitrary),
43+
arbitrary(bound = "E: EthSpec")
3944
)]
45+
#[derive(Debug, Clone, Serialize, Encode, Deserialize, TreeHash, Derivative)]
4046
#[derivative(PartialEq, Eq, Hash(bound = "E: EthSpec"))]
4147
#[serde(bound = "E: EthSpec", untagged)]
42-
#[arbitrary(bound = "E: EthSpec")]
4348
#[ssz(enum_behaviour = "transparent")]
4449
#[tree_hash(enum_behaviour = "transparent")]
4550
pub struct AttesterSlashing<E: EthSpec> {

0 commit comments

Comments
 (0)