Merge remote-tracking branch 'origin/unstable' into electra_attestation_changes

This commit is contained in:
Michael Sproul
2024-06-14 12:32:47 +10:00
34 changed files with 92 additions and 95 deletions

View File

@@ -285,17 +285,17 @@ impl ForkChoiceTestDefinition {
}
}
/// Gives a root that is not the zero hash (unless i is `usize::max_value)`.
/// Gives a root that is not the zero hash (unless i is `usize::MAX)`.
fn get_root(i: u64) -> Hash256 {
Hash256::from_low_u64_be(i + 1)
}
/// Gives a hash that is not the zero hash (unless i is `usize::max_value)`.
/// Gives a hash that is not the zero hash (unless i is `usize::MAX)`.
fn get_hash(i: u64) -> ExecutionBlockHash {
ExecutionBlockHash::from_root(get_root(i))
}
/// Gives a checkpoint with a root that is not the zero hash (unless i is `usize::max_value)`.
/// Gives a checkpoint with a root that is not the zero hash (unless i is `usize::MAX)`.
/// `Epoch` will always equal `i`.
fn get_checkpoint(i: u64) -> Checkpoint {
Checkpoint {

View File

@@ -738,7 +738,7 @@ pub fn get_votes_test_definition() -> ForkChoiceTestDefinition {
// Ensure that pruning below the prune threshold does not prune.
ops.push(Operation::Prune {
finalized_root: get_root(5),
prune_threshold: usize::max_value(),
prune_threshold: usize::MAX,
expected_len: 11,
});

View File

@@ -995,7 +995,7 @@ mod test_compute_deltas {
use super::*;
use types::MainnetEthSpec;
/// Gives a hash that is not the zero hash (unless i is `usize::max_value)`.
/// Gives a hash that is not the zero hash (unless i is `usize::MAX)`.
fn hash_from_index(i: usize) -> Hash256 {
Hash256::from_low_u64_be(i as u64 + 1)
}

View File

@@ -155,12 +155,12 @@ mod test {
#[test]
fn errors() {
assert!(u32::max_value().safe_add(1).is_err());
assert!(u32::min_value().safe_sub(1).is_err());
assert!(u32::max_value().safe_mul(2).is_err());
assert!(u32::max_value().safe_div(0).is_err());
assert!(u32::max_value().safe_rem(0).is_err());
assert!(u32::max_value().safe_shl(32).is_err());
assert!(u32::max_value().safe_shr(32).is_err());
assert!(u32::MAX.safe_add(1).is_err());
assert!(u32::MIN.safe_sub(1).is_err());
assert!(u32::MAX.safe_mul(2).is_err());
assert!(u32::MAX.safe_div(0).is_err());
assert!(u32::MAX.safe_rem(0).is_err());
assert!(u32::MAX.safe_shl(32).is_err());
assert!(u32::MAX.safe_shr(32).is_err());
}
}

View File

@@ -30,7 +30,7 @@ impl Default for InclusionInfo {
/// Defaults to `delay` at its maximum value and `proposer_index` at zero.
fn default() -> Self {
Self {
delay: u64::max_value(),
delay: u64::MAX,
proposer_index: 0,
}
}

View File

@@ -17,7 +17,7 @@ use std::cmp::max;
/// - `list_size == 0`
/// - `index >= list_size`
/// - `list_size > 2**24`
/// - `list_size > usize::max_value() / 2`
/// - `list_size > usize::MAX / 2`
pub fn compute_shuffled_index(
index: usize,
list_size: usize,
@@ -26,7 +26,7 @@ pub fn compute_shuffled_index(
) -> Option<usize> {
if list_size == 0
|| index >= list_size
|| list_size > usize::max_value() / 2
|| list_size > usize::MAX / 2
|| list_size > 2_usize.pow(24)
{
return None;
@@ -140,7 +140,7 @@ mod tests {
fn returns_none_for_too_large_list() {
assert_eq!(
None,
compute_shuffled_index(100, usize::max_value() / 2, &[42, 42], 90)
compute_shuffled_index(100, usize::MAX / 2, &[42, 42], 90)
);
}
}

View File

@@ -75,7 +75,7 @@ impl Buf {
/// Returns `None` under any of the following conditions:
/// - `list_size == 0`
/// - `list_size > 2**24`
/// - `list_size > usize::max_value() / 2`
/// - `list_size > usize::MAX / 2`
pub fn shuffle_list(
mut input: Vec<usize>,
rounds: u8,
@@ -84,10 +84,7 @@ pub fn shuffle_list(
) -> Option<Vec<usize>> {
let list_size = input.len();
if input.is_empty()
|| list_size > usize::max_value() / 2
|| list_size > 2_usize.pow(24)
|| rounds == 0
if input.is_empty() || list_size > usize::MAX / 2 || list_size > 2_usize.pow(24) || rounds == 0
{
return None;
}

View File

@@ -36,8 +36,8 @@ fn get_state<E: EthSpec>(validator_count: usize) -> BeaconState<E> {
slashed: false,
activation_eligibility_epoch: Epoch::new(0),
activation_epoch: Epoch::new(0),
exit_epoch: Epoch::from(u64::max_value()),
withdrawable_epoch: Epoch::from(u64::max_value()),
exit_epoch: Epoch::from(u64::MAX),
withdrawable_epoch: Epoch::from(u64::MAX),
})
.collect(),
)

View File

@@ -86,7 +86,7 @@ impl CommitteeCache {
}
// The use of `NonZeroUsize` reduces the maximum number of possible validators by one.
if state.validators().len() == usize::max_value() {
if state.validators().len() == usize::MAX {
return Err(Error::TooManyValidators);
}

View File

@@ -70,7 +70,7 @@ impl Slot {
}
pub fn max_value() -> Slot {
Slot(u64::max_value())
Slot(u64::MAX)
}
}
@@ -80,7 +80,7 @@ impl Epoch {
}
pub fn max_value() -> Epoch {
Epoch(u64::max_value())
Epoch(u64::MAX)
}
/// The first slot in the epoch.
@@ -176,10 +176,10 @@ mod epoch_tests {
let slots_per_epoch = 32;
// The last epoch which can be represented by u64.
let epoch = Epoch::new(u64::max_value() / slots_per_epoch);
let epoch = Epoch::new(u64::MAX / slots_per_epoch);
// A slot number on the epoch should be equal to u64::max_value.
assert_eq!(epoch.end_slot(slots_per_epoch), Slot::new(u64::max_value()));
assert_eq!(epoch.end_slot(slots_per_epoch), Slot::new(u64::MAX));
}
#[test]

View File

@@ -352,7 +352,7 @@ macro_rules! new_tests {
fn new() {
assert_eq!($type(0), $type::new(0));
assert_eq!($type(3), $type::new(3));
assert_eq!($type(u64::max_value()), $type::new(u64::max_value()));
assert_eq!($type(u64::MAX), $type::new(u64::MAX));
}
};
}
@@ -368,17 +368,17 @@ macro_rules! from_into_tests {
let x: $other = $type(3).into();
assert_eq!(x, 3);
let x: $other = $type(u64::max_value()).into();
let x: $other = $type(u64::MAX).into();
// Note: this will fail on 32 bit systems. This is expected as we don't have a proper
// 32-bit system strategy in place.
assert_eq!(x, $other::max_value());
assert_eq!(x, $other::MAX);
}
#[test]
fn from() {
assert_eq!($type(0), $type::from(0_u64));
assert_eq!($type(3), $type::from(3_u64));
assert_eq!($type(u64::max_value()), $type::from($other::max_value()));
assert_eq!($type(u64::MAX), $type::from($other::MAX));
}
};
}
@@ -396,8 +396,8 @@ macro_rules! math_between_tests {
assert_partial_ord(1, Ordering::Less, 2);
assert_partial_ord(2, Ordering::Greater, 1);
assert_partial_ord(0, Ordering::Less, u64::max_value());
assert_partial_ord(u64::max_value(), Ordering::Greater, 0);
assert_partial_ord(0, Ordering::Less, u64::MAX);
assert_partial_ord(u64::MAX, Ordering::Greater, 0);
}
#[test]
@@ -412,9 +412,9 @@ macro_rules! math_between_tests {
assert_partial_eq(1, 0, false);
assert_partial_eq(1, 1, true);
assert_partial_eq(u64::max_value(), u64::max_value(), true);
assert_partial_eq(0, u64::max_value(), false);
assert_partial_eq(u64::max_value(), 0, false);
assert_partial_eq(u64::MAX, u64::MAX, true);
assert_partial_eq(0, u64::MAX, false);
assert_partial_eq(u64::MAX, 0, false);
}
#[test]
@@ -436,8 +436,8 @@ macro_rules! math_between_tests {
assert_add(7, 7, 14);
// Addition should be saturating.
assert_add(u64::max_value(), 1, u64::max_value());
assert_add(u64::max_value(), u64::max_value(), u64::max_value());
assert_add(u64::MAX, 1, u64::MAX);
assert_add(u64::MAX, u64::MAX, u64::MAX);
}
#[test]
@@ -455,8 +455,8 @@ macro_rules! math_between_tests {
assert_sub(1, 0, 1);
assert_sub(2, 1, 1);
assert_sub(14, 7, 7);
assert_sub(u64::max_value(), 1, u64::max_value() - 1);
assert_sub(u64::max_value(), u64::max_value(), 0);
assert_sub(u64::MAX, 1, u64::MAX - 1);
assert_sub(u64::MAX, u64::MAX, 0);
// Subtraction should be saturating
assert_sub(0, 1, 0);
@@ -480,7 +480,7 @@ macro_rules! math_between_tests {
assert_mul(0, 2, 0);
// Multiplication should be saturating.
assert_mul(u64::max_value(), 2, u64::max_value());
assert_mul(u64::MAX, 2, u64::MAX);
}
#[test]
@@ -499,7 +499,7 @@ macro_rules! math_between_tests {
assert_div(2, 2, 1);
assert_div(100, 50, 2);
assert_div(128, 2, 64);
assert_div(u64::max_value(), 2, 2_u64.pow(63) - 1);
assert_div(u64::MAX, 2, 2_u64.pow(63) - 1);
}
#[test]
@@ -544,8 +544,8 @@ macro_rules! math_tests {
assert_saturating_sub(1, 0, 1);
assert_saturating_sub(2, 1, 1);
assert_saturating_sub(14, 7, 7);
assert_saturating_sub(u64::max_value(), 1, u64::max_value() - 1);
assert_saturating_sub(u64::max_value(), u64::max_value(), 0);
assert_saturating_sub(u64::MAX, 1, u64::MAX - 1);
assert_saturating_sub(u64::MAX, u64::MAX, 0);
// Subtraction should be saturating
assert_saturating_sub(0, 1, 0);
@@ -565,8 +565,8 @@ macro_rules! math_tests {
assert_saturating_add(7, 7, 14);
// Addition should be saturating.
assert_saturating_add(u64::max_value(), 1, u64::max_value());
assert_saturating_add(u64::max_value(), u64::max_value(), u64::max_value());
assert_saturating_add(u64::MAX, 1, u64::MAX);
assert_saturating_add(u64::MAX, u64::MAX, u64::MAX);
}
#[test]
@@ -581,11 +581,11 @@ macro_rules! math_tests {
assert_checked_div(2, 2, Some(1));
assert_checked_div(100, 50, Some(2));
assert_checked_div(128, 2, Some(64));
assert_checked_div(u64::max_value(), 2, Some(2_u64.pow(63) - 1));
assert_checked_div(u64::MAX, 2, Some(2_u64.pow(63) - 1));
assert_checked_div(2, 0, None);
assert_checked_div(0, 0, None);
assert_checked_div(u64::max_value(), 0, None);
assert_checked_div(u64::MAX, 0, None);
}
#[test]
@@ -607,7 +607,7 @@ macro_rules! math_tests {
assert_is_power_of_two(4, true);
assert_is_power_of_two(2_u64.pow(4), true);
assert_is_power_of_two(u64::max_value(), false);
assert_is_power_of_two(u64::MAX, false);
}
#[test]
@@ -619,8 +619,8 @@ macro_rules! math_tests {
assert_ord(1, Ordering::Less, 2);
assert_ord(2, Ordering::Greater, 1);
assert_ord(0, Ordering::Less, u64::max_value());
assert_ord(u64::max_value(), Ordering::Greater, 0);
assert_ord(0, Ordering::Less, u64::MAX);
assert_ord(u64::MAX, Ordering::Greater, 0);
}
};
}
@@ -647,8 +647,8 @@ macro_rules! all_tests {
let x = $type(3).as_u64();
assert_eq!(x, 3);
let x = $type(u64::max_value()).as_u64();
assert_eq!(x, u64::max_value());
let x = $type(u64::MAX).as_u64();
assert_eq!(x, u64::MAX);
}
}
@@ -665,8 +665,8 @@ macro_rules! all_tests {
let x = $type(3).as_usize();
assert_eq!(x, 3);
let x = $type(u64::max_value()).as_usize();
assert_eq!(x, usize::max_value());
let x = $type(u64::MAX).as_usize();
assert_eq!(x, usize::MAX);
}
}
};

View File

@@ -254,12 +254,12 @@ impl Default for Validator {
Self {
pubkey: PublicKeyBytes::empty(),
withdrawal_credentials: Hash256::default(),
activation_eligibility_epoch: Epoch::from(std::u64::MAX),
activation_epoch: Epoch::from(std::u64::MAX),
exit_epoch: Epoch::from(std::u64::MAX),
withdrawable_epoch: Epoch::from(std::u64::MAX),
activation_eligibility_epoch: Epoch::from(u64::MAX),
activation_epoch: Epoch::from(u64::MAX),
exit_epoch: Epoch::from(u64::MAX),
withdrawable_epoch: Epoch::from(u64::MAX),
slashed: false,
effective_balance: std::u64::MAX,
effective_balance: u64::MAX,
}
}
}