Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ tracing_samplers = { path = "common/tracing_samplers" }
tree_hash = "0.12.0"
tree_hash_derive = "0.12.0"
typenum = "1"
types = { path = "consensus/types" }
types = { path = "consensus/types", features = ["testing"] }
url = "2"
uuid = { version = "0.8", features = ["serde", "v4"] }
validator_client = { path = "validator_client" }
Expand Down
21 changes: 14 additions & 7 deletions consensus/types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,16 @@ edition = { workspace = true }

[features]
default = ["sqlite", "legacy-arith"]
# Allow saturating arithmetic on slots and epochs. Enabled by default, but deprecated.
legacy-arith = []
sqlite = ["dep:rusqlite"]

testing = [
"dep:test_random_derive",
"dep:eth2_interop_keypairs",
"dep:rand_xorshift",
"dep:rayon",
"dep:smallvec",
]
arbitrary = [
"dep:arbitrary",
"bls/arbitrary",
Expand All @@ -31,7 +38,7 @@ bls = { workspace = true }
compare_fields = { workspace = true }
context_deserialize = { workspace = true }
educe = { workspace = true }
eth2_interop_keypairs = { path = "../../common/eth2_interop_keypairs" }
eth2_interop_keypairs = { path = "../../common/eth2_interop_keypairs", optional = true }
ethereum_hashing = { workspace = true }
ethereum_serde_utils = { workspace = true }
ethereum_ssz = { workspace = true }
Expand All @@ -47,21 +54,20 @@ metastruct = "0.1.0"
milhouse = { workspace = true }
parking_lot = { workspace = true }
rand = { workspace = true }
rand_xorshift = "0.4.0"
rayon = { workspace = true }
rand_xorshift = { version = "0.4.0", optional = true }
rayon = { workspace = true, optional = true }
regex = { workspace = true }
rpds = { workspace = true }
rusqlite = { workspace = true, optional = true }
safe_arith = { workspace = true }
serde = { workspace = true, features = ["rc"] }
serde_json = { workspace = true }
serde_yaml = { workspace = true }
smallvec = { workspace = true }
smallvec = { workspace = true, optional = true }
ssz_types = { workspace = true }
superstruct = { workspace = true }
swap_or_not_shuffle = { workspace = true }
tempfile = { workspace = true }
test_random_derive = { path = "../../common/test_random_derive" }
test_random_derive = { path = "../../common/test_random_derive", optional = true }
tracing = { workspace = true }
tree_hash = { workspace = true }
tree_hash_derive = { workspace = true }
Expand All @@ -72,6 +78,7 @@ beacon_chain = { workspace = true }
criterion = { workspace = true }
paste = { workspace = true }
state_processing = { workspace = true }
tempfile = { workspace = true }
tokio = { workspace = true }

[lints.clippy]
Expand Down
8 changes: 5 additions & 3 deletions consensus/types/src/attestation/aggregate_and_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@ use context_deserialize::context_deserialize;
use serde::{Deserialize, Serialize};
use ssz_derive::{Decode, Encode};
use superstruct::superstruct;
#[cfg(feature = "testing")]
use test_random_derive::TestRandom;
use tree_hash_derive::TreeHash;

#[cfg(feature = "testing")]
use crate::test_utils::TestRandom;
use crate::{
attestation::{
Attestation, AttestationBase, AttestationElectra, AttestationRef, SelectionProof,
},
core::{ChainSpec, Domain, EthSpec, Hash256, SignedRoot},
fork::{Fork, ForkName},
test_utils::TestRandom,
};

#[superstruct(
Expand All @@ -26,11 +28,11 @@ use crate::{
Deserialize,
Encode,
Decode,
TestRandom,
TreeHash,
TreeHash
),
context_deserialize(ForkName),
serde(bound = "E: EthSpec"),
cfg_attr(feature = "testing", derive(TestRandom)),
cfg_attr(
feature = "arbitrary",
derive(arbitrary::Arbitrary),
Expand Down
9 changes: 6 additions & 3 deletions consensus/types/src/attestation/attestation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,19 @@ use serde::{Deserialize, Deserializer, Serialize};
use ssz_derive::{Decode, Encode};
use ssz_types::{BitList, BitVector};
use superstruct::superstruct;
#[cfg(feature = "testing")]
use test_random_derive::TestRandom;
use tree_hash_derive::TreeHash;

#[cfg(feature = "testing")]
use crate::test_utils::TestRandom;
use crate::{
attestation::{
AttestationData, Checkpoint, IndexedAttestation, IndexedAttestationBase,
IndexedAttestationElectra,
},
core::{ChainSpec, Domain, EthSpec, Hash256, SignedRoot, Slot, SlotData},
fork::{Fork, ForkName},
test_utils::TestRandom,
};

#[derive(Debug, PartialEq, Clone)]
Expand Down Expand Up @@ -49,13 +51,13 @@ impl From<ssz_types::Error> for Error {
Deserialize,
Decode,
Encode,
TestRandom,
Educe,
TreeHash,
),
context_deserialize(ForkName),
educe(PartialEq, Hash(bound(E: EthSpec))),
serde(bound = "E: EthSpec", deny_unknown_fields),
cfg_attr(feature = "testing", derive(TestRandom)),
cfg_attr(
feature = "arbitrary",
derive(arbitrary::Arbitrary),
Expand Down Expand Up @@ -605,7 +607,8 @@ impl<'de, E: EthSpec> ContextDeserialize<'de, ForkName> for Vec<Attestation<E>>
*/

#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[derive(Debug, Clone, Serialize, Deserialize, Decode, Encode, TestRandom, TreeHash, PartialEq)]
#[cfg_attr(feature = "testing", derive(TestRandom))]
#[derive(Debug, Clone, Serialize, Deserialize, Decode, Encode, TreeHash, PartialEq)]
#[context_deserialize(ForkName)]
pub struct SingleAttestation {
#[serde(with = "serde_utils::quoted_u64")]
Expand Down
18 changes: 5 additions & 13 deletions consensus/types/src/attestation/attestation_data.rs
Original file line number Diff line number Diff line change
@@ -1,33 +1,25 @@
use context_deserialize::context_deserialize;
use serde::{Deserialize, Serialize};
use ssz_derive::{Decode, Encode};
#[cfg(feature = "testing")]
use test_random_derive::TestRandom;
use tree_hash_derive::TreeHash;

#[cfg(feature = "testing")]
use crate::test_utils::TestRandom;
use crate::{
attestation::Checkpoint,
core::{Hash256, SignedRoot, Slot, SlotData},
fork::ForkName,
test_utils::TestRandom,
};

/// The data upon which an attestation is based.
///
/// Spec v0.12.1
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "testing", derive(TestRandom))]
#[derive(
Debug,
Clone,
PartialEq,
Eq,
Serialize,
Deserialize,
Hash,
Encode,
Decode,
TreeHash,
TestRandom,
Default,
Debug, Clone, PartialEq, Eq, Serialize, Deserialize, Hash, Encode, Decode, TreeHash, Default,
)]
#[context_deserialize(ForkName)]
pub struct AttestationData {
Expand Down
6 changes: 4 additions & 2 deletions consensus/types/src/attestation/checkpoint.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
use context_deserialize::context_deserialize;
use serde::{Deserialize, Serialize};
use ssz_derive::{Decode, Encode};
#[cfg(feature = "testing")]
use test_random_derive::TestRandom;
use tree_hash_derive::TreeHash;

#[cfg(feature = "testing")]
use crate::test_utils::TestRandom;
use crate::{
core::{Epoch, Hash256},
fork::ForkName,
test_utils::TestRandom,
};

/// Casper FFG checkpoint, used in attestations.
///
/// Spec v0.12.1
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[cfg_attr(feature = "testing", derive(TestRandom))]
#[derive(
Debug,
Clone,
Expand All @@ -27,7 +30,6 @@ use crate::{
Encode,
Decode,
TreeHash,
TestRandom,
)]
#[context_deserialize(ForkName)]
pub struct Checkpoint {
Expand Down
7 changes: 5 additions & 2 deletions consensus/types/src/attestation/indexed_attestation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ use ssz::Encode;
use ssz_derive::{Decode, Encode};
use ssz_types::VariableList;
use superstruct::superstruct;
#[cfg(feature = "testing")]
use test_random_derive::TestRandom;
use tree_hash_derive::TreeHash;

use crate::{attestation::AttestationData, core::EthSpec, fork::ForkName, test_utils::TestRandom};
#[cfg(feature = "testing")]
use crate::test_utils::TestRandom;
use crate::{attestation::AttestationData, core::EthSpec, fork::ForkName};

/// Details an attestation that can be slashable.
///
Expand All @@ -31,13 +34,13 @@ use crate::{attestation::AttestationData, core::EthSpec, fork::ForkName, test_ut
Deserialize,
Decode,
Encode,
TestRandom,
Educe,
TreeHash,
),
context_deserialize(ForkName),
educe(PartialEq, Hash(bound(E: EthSpec))),
serde(bound = "E: EthSpec", deny_unknown_fields),
cfg_attr(feature = "testing", derive(TestRandom)),
cfg_attr(
feature = "arbitrary",
derive(arbitrary::Arbitrary),
Expand Down
10 changes: 7 additions & 3 deletions consensus/types/src/attestation/indexed_payload_attestation.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
use crate::test_utils::TestRandom;
use crate::{EthSpec, ForkName, PayloadAttestationData};
use bls::AggregateSignature;
use context_deserialize::context_deserialize;
use core::slice::Iter;
use serde::{Deserialize, Serialize};
use ssz_derive::{Decode, Encode};
use ssz_types::VariableList;
#[cfg(feature = "testing")]
use test_random_derive::TestRandom;
use tree_hash_derive::TreeHash;

#[derive(TestRandom, TreeHash, Debug, Clone, PartialEq, Encode, Decode, Serialize, Deserialize)]
#[cfg(feature = "testing")]
use crate::test_utils::TestRandom;
use crate::{EthSpec, attestation::PayloadAttestationData, fork::ForkName};

#[cfg_attr(feature = "testing", derive(TestRandom))]
#[derive(TreeHash, Debug, Clone, PartialEq, Encode, Decode, Serialize, Deserialize)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[serde(bound = "E: EthSpec", deny_unknown_fields)]
#[cfg_attr(feature = "arbitrary", arbitrary(bound = "E: EthSpec"))]
Expand Down
11 changes: 6 additions & 5 deletions consensus/types/src/attestation/participation_flags.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
use safe_arith::{ArithError, SafeArith};
use serde::{Deserialize, Serialize};
use ssz::{Decode, DecodeError, Encode};
#[cfg(feature = "testing")]
use test_random_derive::TestRandom;
use tree_hash::{PackedEncoding, TreeHash, TreeHashType};

use crate::{
core::{Hash256, consts::altair::NUM_FLAG_INDICES},
test_utils::TestRandom,
};
use crate::core::{Hash256, consts::altair::NUM_FLAG_INDICES};
#[cfg(feature = "testing")]
use crate::test_utils::TestRandom;

#[derive(Debug, Default, Clone, Copy, PartialEq, Deserialize, Serialize, TestRandom)]
#[cfg_attr(feature = "testing", derive(TestRandom))]
#[derive(Debug, Default, Clone, Copy, PartialEq, Deserialize, Serialize)]
#[serde(transparent)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
pub struct ParticipationFlags {
Expand Down
11 changes: 7 additions & 4 deletions consensus/types/src/attestation/payload_attestation.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
use crate::attestation::payload_attestation_data::PayloadAttestationData;
use crate::test_utils::TestRandom;
use crate::{EthSpec, ForkName};
use bls::AggregateSignature;
use context_deserialize::context_deserialize;
use educe::Educe;
use serde::{Deserialize, Serialize};
use ssz::BitVector;
use ssz_derive::{Decode, Encode};
#[cfg(feature = "testing")]
use test_random_derive::TestRandom;
use tree_hash_derive::TreeHash;

#[derive(TestRandom, TreeHash, Debug, Clone, Encode, Decode, Serialize, Deserialize, Educe)]
#[cfg(feature = "testing")]
use crate::test_utils::TestRandom;
use crate::{EthSpec, attestation::PayloadAttestationData, fork::ForkName};

#[cfg_attr(feature = "testing", derive(TestRandom))]
#[derive(TreeHash, Debug, Clone, Encode, Decode, Serialize, Deserialize, Educe)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[serde(bound = "E: EthSpec", deny_unknown_fields)]
#[cfg_attr(feature = "arbitrary", arbitrary(bound = "E: EthSpec"))]
Expand Down
12 changes: 7 additions & 5 deletions consensus/types/src/attestation/payload_attestation_data.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
use crate::test_utils::TestRandom;
use crate::{ForkName, Hash256, SignedRoot, Slot};
use context_deserialize::context_deserialize;
use serde::{Deserialize, Serialize};
use ssz_derive::{Decode, Encode};
#[cfg(feature = "testing")]
use test_random_derive::TestRandom;
use tree_hash_derive::TreeHash;

#[derive(
TestRandom, TreeHash, Debug, Clone, PartialEq, Eq, Encode, Decode, Serialize, Deserialize, Hash,
)]
#[cfg(feature = "testing")]
use crate::test_utils::TestRandom;
use crate::{Hash256, SignedRoot, Slot, fork::ForkName};

#[cfg_attr(feature = "testing", derive(TestRandom))]
#[derive(TreeHash, Debug, Clone, PartialEq, Eq, Encode, Decode, Serialize, Deserialize, Hash)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[context_deserialize(ForkName)]
pub struct PayloadAttestationData {
Expand Down
11 changes: 7 additions & 4 deletions consensus/types/src/attestation/payload_attestation_message.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
use crate::ForkName;
use crate::attestation::payload_attestation_data::PayloadAttestationData;
use crate::test_utils::TestRandom;
use bls::Signature;
use context_deserialize::context_deserialize;
use serde::{Deserialize, Serialize};
use ssz_derive::{Decode, Encode};
#[cfg(feature = "testing")]
use test_random_derive::TestRandom;
use tree_hash_derive::TreeHash;

#[derive(TestRandom, TreeHash, Debug, Clone, PartialEq, Encode, Decode, Serialize, Deserialize)]
#[cfg(feature = "testing")]
use crate::test_utils::TestRandom;
use crate::{ForkName, attestation::PayloadAttestationData};

#[cfg_attr(feature = "testing", derive(TestRandom))]
#[derive(TreeHash, Debug, Clone, PartialEq, Encode, Decode, Serialize, Deserialize)]
#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
#[context_deserialize(ForkName)]
pub struct PayloadAttestationMessage {
Expand Down
8 changes: 6 additions & 2 deletions consensus/types/src/attestation/pending_attestation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ use context_deserialize::context_deserialize;
use serde::{Deserialize, Serialize};
use ssz_derive::{Decode, Encode};
use ssz_types::BitList;
#[cfg(feature = "testing")]
use test_random_derive::TestRandom;
use tree_hash_derive::TreeHash;

use crate::{attestation::AttestationData, core::EthSpec, fork::ForkName, test_utils::TestRandom};
#[cfg(feature = "testing")]
use crate::test_utils::TestRandom;
use crate::{attestation::AttestationData, core::EthSpec, fork::ForkName};

/// An attestation that has been included in the state but not yet fully processed.
///
Expand All @@ -15,7 +18,8 @@ use crate::{attestation::AttestationData, core::EthSpec, fork::ForkName, test_ut
derive(arbitrary::Arbitrary),
arbitrary(bound = "E: EthSpec")
)]
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Encode, Decode, TreeHash, TestRandom)]
#[cfg_attr(feature = "testing", derive(TestRandom))]
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Encode, Decode, TreeHash)]
#[context_deserialize(ForkName)]
pub struct PendingAttestation<E: EthSpec> {
pub aggregation_bits: BitList<E::MaxValidatorsPerCommittee>,
Expand Down
Loading