Address clippy lints in tree-states (#4414)

* Address some clippy lints

* Box errors to fix error size lint

* Add Default impl for Validator

* Address more clippy lints

* Re-implement `check_state_diff`

* Fix misc test compile errors
This commit is contained in:
Paul Hauner
2023-06-20 11:47:52 +10:00
committed by GitHub
parent 23db089a7a
commit d56cec83fc
26 changed files with 94 additions and 73 deletions

View File

@@ -345,7 +345,7 @@ impl ForkChoiceTest {
let state_root = harness
.chain
.store
.get_blinded_block(&fc.fc_store().justified_checkpoint().root)
.get_blinded_block(&fc.fc_store().justified_checkpoint().root, None)
.unwrap()
.unwrap()
.message()
@@ -361,7 +361,7 @@ impl ForkChoiceTest {
.into_iter()
.map(|v| {
if v.is_active_at(state.current_epoch()) {
v.effective_balance
v.effective_balance()
} else {
0
}

View File

@@ -329,9 +329,11 @@ pub enum AttestationInvalid {
///
/// `is_current` is `true` if the attestation was compared to the
/// `state.current_justified_checkpoint`, `false` if compared to `state.previous_justified_checkpoint`.
///
/// Checkpoints have been boxed to keep the error size down and prevent clippy failures.
WrongJustifiedCheckpoint {
state: Checkpoint,
attestation: Checkpoint,
state: Box<Checkpoint>,
attestation: Box<Checkpoint>,
is_current: bool,
},
/// The aggregation bitfield length is not the smallest possible size to represent the committee.

View File

@@ -451,8 +451,8 @@ async fn invalid_attestation_wrong_justified_checkpoint() {
Err(BlockProcessingError::AttestationInvalid {
index: 0,
reason: AttestationInvalid::WrongJustifiedCheckpoint {
state: old_justified_checkpoint,
attestation: new_justified_checkpoint,
state: Box::new(old_justified_checkpoint),
attestation: Box::new(new_justified_checkpoint),
is_current: true,
}
})

View File

@@ -93,8 +93,8 @@ fn verify_casper_ffg_vote<T: EthSpec>(
verify!(
data.source == state.current_justified_checkpoint(),
Invalid::WrongJustifiedCheckpoint {
state: state.current_justified_checkpoint(),
attestation: data.source,
state: Box::new(state.current_justified_checkpoint()),
attestation: Box::new(data.source),
is_current: true,
}
);
@@ -103,8 +103,8 @@ fn verify_casper_ffg_vote<T: EthSpec>(
verify!(
data.source == state.previous_justified_checkpoint(),
Invalid::WrongJustifiedCheckpoint {
state: state.previous_justified_checkpoint(),
attestation: data.source,
state: Box::new(state.previous_justified_checkpoint()),
attestation: Box::new(data.source),
is_current: false,
}
);

View File

@@ -1,13 +1,10 @@
#![cfg(test)]
use crate::{test_utils::*, ForkName};
use beacon_chain::test_utils::{
interop_genesis_state_with_eth1, test_spec, BeaconChainHarness, EphemeralHarnessType,
DEFAULT_ETH1_BLOCK_HASH,
};
use beacon_chain::test_utils::{BeaconChainHarness, EphemeralHarnessType};
use beacon_chain::types::{
test_utils::TestRandom, BeaconState, BeaconStateAltair, BeaconStateBase, BeaconStateError,
BeaconStateMerge, ChainSpec, Domain, Epoch, EthSpec, FixedVector, Hash256, Keypair,
MainnetEthSpec, MinimalEthSpec, RelativeEpoch, Slot,
test_utils::TestRandom, BeaconState, BeaconStateAltair, BeaconStateBase, BeaconStateCapella,
BeaconStateError, BeaconStateMerge, ChainSpec, Domain, Epoch, EthSpec, FixedVector, Hash256,
Keypair, MainnetEthSpec, MinimalEthSpec, RelativeEpoch, Slot,
};
use ssz::Encode;
use std::ops::Mul;
@@ -418,6 +415,7 @@ fn check_num_fields_pow2() {
ForkName::Base => BeaconStateBase::<E>::NUM_FIELDS,
ForkName::Altair => BeaconStateAltair::<E>::NUM_FIELDS,
ForkName::Merge => BeaconStateMerge::<E>::NUM_FIELDS,
ForkName::Capella => BeaconStateCapella::<E>::NUM_FIELDS,
};
assert_eq!(
num_fields.next_power_of_two(),

View File

@@ -230,7 +230,15 @@ impl Validator {
}
}
/*
impl Default for Validator {
fn default() -> Self {
Validator {
pubkey: Arc::new(PublicKeyBytes::empty()),
mutable: <_>::default(),
}
}
}
impl Default for ValidatorMutable {
fn default() -> Self {
ValidatorMutable {
@@ -244,7 +252,6 @@ impl Default for ValidatorMutable {
}
}
}
*/
impl TreeHash for Validator {
fn tree_hash_type() -> tree_hash::TreeHashType {