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 = ["saturating-arith"] }
url = "2"
uuid = { version = "0.8", features = ["serde", "v4"] }
validator_client = { path = "validator_client" }
Expand Down
5 changes: 2 additions & 3 deletions consensus/state_processing/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ authors = ["Paul Hauner <paul@paulhauner.com>", "Michael Sproul <michael@sigmapr
edition = { workspace = true }

[features]
default = ["legacy-arith"]
default = []
fake_crypto = ["bls/fake_crypto"]
legacy-arith = ["types/legacy-arith"]
arbitrary-fuzz = [
"types/arbitrary-fuzz",
"merkle_proof/arbitrary",
Expand Down Expand Up @@ -40,7 +39,7 @@ test_random_derive = { path = "../../common/test_random_derive" }
tracing = { workspace = true }
tree_hash = { workspace = true }
typenum = { workspace = true }
types = { workspace = true }
types = { workspace = true, features = ["saturating-arith"] }

[dev-dependencies]
beacon_chain = { workspace = true }
Expand Down
7 changes: 4 additions & 3 deletions consensus/types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ authors = [
edition = { workspace = true }

[features]
default = ["sqlite", "legacy-arith"]
# Allow saturating arithmetic on slots and epochs. Enabled by default, but deprecated.
legacy-arith = []
default = ["sqlite"]
# Enable +, -, *, /, % operators for Slot and Epoch types.
# Operations saturate instead of wrapping.
saturating-arith = []
sqlite = ["dep:rusqlite"]
arbitrary = [
"dep:arbitrary",
Expand Down
2 changes: 1 addition & 1 deletion consensus/types/src/core/slot_epoch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use crate::{
test_utils::TestRandom,
};

#[cfg(feature = "legacy-arith")]
#[cfg(feature = "saturating-arith")]
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Rem, Sub, SubAssign};

#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
Expand Down
6 changes: 3 additions & 3 deletions consensus/types/src/core/slot_epoch_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ macro_rules! impl_safe_arith {
}

// Deprecated: prefer `SafeArith` methods for new code.
#[cfg(feature = "legacy-arith")]
#[cfg(feature = "saturating-arith")]
macro_rules! impl_math_between {
($main: ident, $other: ident) => {
impl Add<$other> for $main {
Expand Down Expand Up @@ -321,9 +321,9 @@ macro_rules! impl_common {
impl_u64_eq_ord!($type);
impl_safe_arith!($type, $type);
impl_safe_arith!($type, u64);
#[cfg(feature = "legacy-arith")]
#[cfg(feature = "saturating-arith")]
impl_math_between!($type, $type);
#[cfg(feature = "legacy-arith")]
#[cfg(feature = "saturating-arith")]
impl_math_between!($type, u64);
impl_math!($type);
impl_display!($type);
Expand Down
8 changes: 7 additions & 1 deletion consensus/types/src/state/committee_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,13 @@ impl CommitteeCache {
.saturating_sub(spec.min_seed_lookahead)
.saturating_sub(1u64);

if reqd_randao_epoch < state.min_randao_epoch() || epoch > state.current_epoch() + 1 {
if reqd_randao_epoch < state.min_randao_epoch()
|| epoch
> state
.current_epoch()
.safe_add(1)
.map_err(BeaconStateError::ArithError)?
{
return Err(BeaconStateError::EpochOutOfBounds);
}

Expand Down