mirror of
https://github.com/sigp/lighthouse.git
synced 2026-06-29 10:54:24 +00:00
Update Rust Edition to 2024 (#7766)
* #7749 Thanks @dknopik and @michaelsproul for your help!
This commit is contained in:
@@ -1,25 +1,25 @@
|
||||
use beacon_chain::{
|
||||
observed_operations::ObservationOutcome, BeaconChain, BeaconChainError, BeaconChainTypes,
|
||||
BeaconChain, BeaconChainError, BeaconChainTypes, observed_operations::ObservationOutcome,
|
||||
};
|
||||
use directory::size_of_dir;
|
||||
use lighthouse_network::PubsubMessage;
|
||||
use network::NetworkMessage;
|
||||
use slasher::{
|
||||
metrics::{self, SLASHER_DATABASE_SIZE, SLASHER_RUN_TIME},
|
||||
Slasher,
|
||||
metrics::{self, SLASHER_DATABASE_SIZE, SLASHER_RUN_TIME},
|
||||
};
|
||||
use slot_clock::SlotClock;
|
||||
use state_processing::{
|
||||
VerifyOperation,
|
||||
per_block_processing::errors::{
|
||||
AttesterSlashingInvalid, BlockOperationError, ProposerSlashingInvalid,
|
||||
},
|
||||
VerifyOperation,
|
||||
};
|
||||
use std::sync::mpsc::{sync_channel, Receiver, SyncSender, TrySendError};
|
||||
use std::sync::Arc;
|
||||
use std::sync::mpsc::{Receiver, SyncSender, TrySendError, sync_channel};
|
||||
use task_executor::TaskExecutor;
|
||||
use tokio::sync::mpsc::UnboundedSender;
|
||||
use tokio::time::{interval_at, Duration, Instant};
|
||||
use tokio::time::{Duration, Instant, interval_at};
|
||||
use tracing::{debug, error, info, trace, warn};
|
||||
use types::{AttesterSlashing, Epoch, EthSpec, ProposerSlashing};
|
||||
|
||||
@@ -211,15 +211,14 @@ impl<T: BeaconChainTypes> SlasherService<T> {
|
||||
beacon_chain.import_attester_slashing(verified_slashing);
|
||||
|
||||
// Publish to the network if broadcast is enabled.
|
||||
if slasher.config().broadcast {
|
||||
if let Err(e) =
|
||||
if slasher.config().broadcast
|
||||
&& let Err(e) =
|
||||
Self::publish_attester_slashing(beacon_chain, network_sender, slashing)
|
||||
{
|
||||
debug!(
|
||||
error = ?e,
|
||||
"Unable to publish attester slashing"
|
||||
);
|
||||
}
|
||||
{
|
||||
debug!(
|
||||
error = ?e,
|
||||
"Unable to publish attester slashing"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -260,15 +259,14 @@ impl<T: BeaconChainTypes> SlasherService<T> {
|
||||
};
|
||||
beacon_chain.import_proposer_slashing(verified_slashing);
|
||||
|
||||
if slasher.config().broadcast {
|
||||
if let Err(e) =
|
||||
if slasher.config().broadcast
|
||||
&& let Err(e) =
|
||||
Self::publish_proposer_slashing(beacon_chain, network_sender, slashing)
|
||||
{
|
||||
debug!(
|
||||
error = ?e,
|
||||
"Unable to publish proposer slashing"
|
||||
);
|
||||
}
|
||||
{
|
||||
debug!(
|
||||
error = ?e,
|
||||
"Unable to publish proposer slashing"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ use crate::{
|
||||
use flate2::bufread::{ZlibDecoder, ZlibEncoder};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::borrow::Borrow;
|
||||
use std::collections::{btree_map::Entry, BTreeMap, HashSet};
|
||||
use std::collections::{BTreeMap, HashSet, btree_map::Entry};
|
||||
use std::io::Read;
|
||||
use std::sync::Arc;
|
||||
use types::{AttesterSlashing, Epoch, EthSpec, IndexedAttestation};
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use crate::{database::IndexedAttestationId, Error};
|
||||
use crate::{Error, database::IndexedAttestationId};
|
||||
use ssz_derive::{Decode, Encode};
|
||||
use std::borrow::Cow;
|
||||
use std::sync::{
|
||||
atomic::{AtomicU64, Ordering},
|
||||
Arc,
|
||||
atomic::{AtomicU64, Ordering},
|
||||
};
|
||||
use tree_hash::TreeHash as _;
|
||||
use tree_hash_derive::TreeHash;
|
||||
|
||||
@@ -4,8 +4,8 @@ mod mdbx_impl;
|
||||
mod redb_impl;
|
||||
|
||||
use crate::{
|
||||
metrics, AttesterRecord, AttesterSlashingStatus, CompactAttesterRecord, Config, Database,
|
||||
Error, ProposerSlashingStatus,
|
||||
AttesterRecord, AttesterSlashingStatus, CompactAttesterRecord, Config, Database, Error,
|
||||
ProposerSlashingStatus, metrics,
|
||||
};
|
||||
use byteorder::{BigEndian, ByteOrder};
|
||||
use interface::{Environment, OpenDatabases, RwTransaction};
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
#![cfg(feature = "mdbx")]
|
||||
|
||||
use crate::{
|
||||
Config, Error,
|
||||
config::MEGABYTE,
|
||||
database::{
|
||||
interface::{Key, OpenDatabases, Value},
|
||||
*,
|
||||
},
|
||||
Config, Error,
|
||||
};
|
||||
use mdbx::{DatabaseFlags, Geometry, WriteFlags};
|
||||
use std::borrow::Cow;
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
#![cfg(feature = "redb")]
|
||||
use crate::{
|
||||
Config, Error,
|
||||
config::REDB_DATA_FILENAME,
|
||||
database::{
|
||||
interface::{Key, OpenDatabases, Value},
|
||||
*,
|
||||
},
|
||||
Config, Error,
|
||||
};
|
||||
use derivative::Derivative;
|
||||
use redb::{ReadableTable, TableDefinition};
|
||||
|
||||
@@ -23,8 +23,8 @@ pub use attester_record::{AttesterRecord, CompactAttesterRecord, IndexedAttester
|
||||
pub use block_queue::BlockQueue;
|
||||
pub use config::{Config, DatabaseBackend, DatabaseBackendOverride};
|
||||
pub use database::{
|
||||
interface::{Database, Environment, RwTransaction},
|
||||
IndexedAttestationId, SlasherDB,
|
||||
interface::{Database, Environment, RwTransaction},
|
||||
};
|
||||
pub use error::Error;
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::{database::CURRENT_SCHEMA_VERSION, Error, SlasherDB};
|
||||
use crate::{Error, SlasherDB, database::CURRENT_SCHEMA_VERSION};
|
||||
use types::EthSpec;
|
||||
|
||||
impl<E: EthSpec> SlasherDB<E> {
|
||||
|
||||
@@ -5,8 +5,8 @@ use crate::metrics::{
|
||||
SLASHER_NUM_BLOCKS_PROCESSED,
|
||||
};
|
||||
use crate::{
|
||||
array, AttestationBatch, AttestationQueue, AttesterRecord, BlockQueue, Config, Error,
|
||||
IndexedAttestationId, ProposerSlashingStatus, RwTransaction, SimpleBatch, SlasherDB,
|
||||
AttestationBatch, AttestationQueue, AttesterRecord, BlockQueue, Config, Error,
|
||||
IndexedAttestationId, ProposerSlashingStatus, RwTransaction, SimpleBatch, SlasherDB, array,
|
||||
};
|
||||
use parking_lot::Mutex;
|
||||
use std::collections::HashSet;
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
use std::collections::HashSet;
|
||||
use std::sync::Arc;
|
||||
use types::{
|
||||
indexed_attestation::{IndexedAttestationBase, IndexedAttestationElectra},
|
||||
AggregateSignature, AttestationData, AttesterSlashing, AttesterSlashingBase,
|
||||
AttesterSlashingElectra, BeaconBlockHeader, ChainSpec, Checkpoint, Epoch, EthSpec,
|
||||
FixedBytesExtended, Hash256, IndexedAttestation, MainnetEthSpec, Signature,
|
||||
SignedBeaconBlockHeader, Slot,
|
||||
indexed_attestation::{IndexedAttestationBase, IndexedAttestationElectra},
|
||||
};
|
||||
|
||||
pub type E = MainnetEthSpec;
|
||||
|
||||
@@ -3,12 +3,12 @@
|
||||
use maplit::hashset;
|
||||
use rayon::prelude::*;
|
||||
use slasher::{
|
||||
Config, Slasher,
|
||||
config::DEFAULT_CHUNK_SIZE,
|
||||
test_utils::{
|
||||
att_slashing, chain_spec, indexed_att, indexed_att_electra,
|
||||
slashed_validators_from_slashings, E,
|
||||
E, att_slashing, chain_spec, indexed_att, indexed_att_electra,
|
||||
slashed_validators_from_slashings,
|
||||
},
|
||||
Config, Slasher,
|
||||
};
|
||||
use std::collections::HashSet;
|
||||
use tempfile::tempdir;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#![cfg(feature = "lmdb")]
|
||||
|
||||
use slasher::{config::MDBX_DATA_FILENAME, Config, DatabaseBackend, DatabaseBackendOverride};
|
||||
use slasher::{Config, DatabaseBackend, DatabaseBackendOverride, config::MDBX_DATA_FILENAME};
|
||||
use std::fs::File;
|
||||
use tempfile::tempdir;
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#![cfg(any(feature = "mdbx", feature = "lmdb", feature = "redb"))]
|
||||
|
||||
use slasher::{
|
||||
test_utils::{block as test_block, chain_spec, E},
|
||||
Config, Slasher,
|
||||
test_utils::{E, block as test_block, chain_spec},
|
||||
};
|
||||
use tempfile::tempdir;
|
||||
use types::{Epoch, EthSpec};
|
||||
@@ -56,10 +56,8 @@ fn block_pruning() {
|
||||
(config.history_length - 1) * slots_per_epoch as usize + 1
|
||||
);
|
||||
// Check epochs of all slashings are from within range.
|
||||
assert!(proposer_slashings.iter().all(|slashing| slashing
|
||||
.signed_header_1
|
||||
.message
|
||||
.slot
|
||||
.epoch(slots_per_epoch)
|
||||
> current_epoch - config.history_length as u64));
|
||||
assert!(proposer_slashings.iter().all(|slashing| {
|
||||
slashing.signed_header_1.message.slot.epoch(slots_per_epoch)
|
||||
> current_epoch - config.history_length as u64
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
#![cfg(any(feature = "mdbx", feature = "lmdb", feature = "redb"))]
|
||||
|
||||
use rand::prelude::*;
|
||||
use rand::{prelude::*, rng};
|
||||
use slasher::{
|
||||
test_utils::{
|
||||
block, chain_spec, indexed_att, slashed_validators_from_attestations,
|
||||
slashed_validators_from_slashings, E,
|
||||
},
|
||||
Config, Slasher, SlasherDB,
|
||||
test_utils::{
|
||||
E, block, chain_spec, indexed_att, slashed_validators_from_attestations,
|
||||
slashed_validators_from_slashings,
|
||||
},
|
||||
};
|
||||
use std::cmp::max;
|
||||
use std::sync::Arc;
|
||||
use tempfile::{tempdir, TempDir};
|
||||
use tempfile::{TempDir, tempdir};
|
||||
use types::{Epoch, EthSpec};
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -49,11 +49,11 @@ fn random_test(seed: u64, mut db: SlasherDB<E>, test_config: TestConfig) -> Slas
|
||||
let mut rng = StdRng::seed_from_u64(seed);
|
||||
|
||||
let mut config = Config::new(db.get_config().database_path.clone());
|
||||
config.validator_chunk_size = 1 << rng.gen_range(1..4);
|
||||
config.validator_chunk_size = 1 << rng.random_range(1..4);
|
||||
|
||||
let chunk_size_exponent = rng.gen_range(1..4);
|
||||
let chunk_size_exponent = rng.random_range(1..4);
|
||||
config.chunk_size = 1 << chunk_size_exponent;
|
||||
config.history_length = 1 << rng.gen_range(chunk_size_exponent..chunk_size_exponent + 3);
|
||||
config.history_length = 1 << rng.random_range(chunk_size_exponent..chunk_size_exponent + 3);
|
||||
|
||||
let config = Arc::new(config);
|
||||
db.update_config(config.clone());
|
||||
@@ -62,13 +62,13 @@ fn random_test(seed: u64, mut db: SlasherDB<E>, test_config: TestConfig) -> Slas
|
||||
|
||||
let validators = (0..num_validators as u64).collect::<Vec<u64>>();
|
||||
|
||||
let num_attestations = rng.gen_range(2..max_attestations + 1);
|
||||
let num_attestations = rng.random_range(2..max_attestations + 1);
|
||||
|
||||
let mut current_epoch = Epoch::new(0);
|
||||
let mut attestations = vec![];
|
||||
|
||||
for _ in 0..num_attestations {
|
||||
let num_attesters = rng.gen_range(1..num_validators);
|
||||
let num_attesters = rng.random_range(1..num_validators);
|
||||
let mut attesting_indices = validators
|
||||
.choose_multiple(&mut rng, num_attesters)
|
||||
.copied()
|
||||
@@ -77,20 +77,20 @@ fn random_test(seed: u64, mut db: SlasherDB<E>, test_config: TestConfig) -> Slas
|
||||
|
||||
// If checking slashings, generate valid attestations in range.
|
||||
let (source, target) = if check_slashings {
|
||||
let source = rng.gen_range(
|
||||
let source = rng.random_range(
|
||||
current_epoch
|
||||
.as_u64()
|
||||
.saturating_sub(config.history_length as u64 - 1)
|
||||
..current_epoch.as_u64() + 1,
|
||||
);
|
||||
let target = rng.gen_range(source..current_epoch.as_u64() + 1);
|
||||
let target = rng.random_range(source..current_epoch.as_u64() + 1);
|
||||
(source, target)
|
||||
} else {
|
||||
let source = rng.gen_range(0..max(3 * current_epoch.as_u64(), 1));
|
||||
let target = rng.gen_range(source..max(3 * current_epoch.as_u64(), source + 1));
|
||||
let source = rng.random_range(0..max(3 * current_epoch.as_u64(), 1));
|
||||
let target = rng.random_range(source..max(3 * current_epoch.as_u64(), source + 1));
|
||||
(source, target)
|
||||
};
|
||||
let target_root = rng.gen_range(0..3);
|
||||
let target_root = rng.random_range(0..3);
|
||||
let attestation = indexed_att(&attesting_indices, source, target, target_root);
|
||||
|
||||
if check_slashings {
|
||||
@@ -101,25 +101,26 @@ fn random_test(seed: u64, mut db: SlasherDB<E>, test_config: TestConfig) -> Slas
|
||||
slasher.accept_attestation(attestation);
|
||||
|
||||
// Maybe add a random block too
|
||||
if test_config.add_blocks && rng.gen_bool(0.1) {
|
||||
let slot = rng.gen_range(0..1 + 3 * current_epoch.as_u64() * E::slots_per_epoch() / 2);
|
||||
let proposer = rng.gen_range(0..num_validators as u64);
|
||||
let block_root = rng.gen_range(0..2);
|
||||
if test_config.add_blocks && rng.random_bool(0.1) {
|
||||
let slot =
|
||||
rng.random_range(0..1 + 3 * current_epoch.as_u64() * E::slots_per_epoch() / 2);
|
||||
let proposer = rng.random_range(0..num_validators as u64);
|
||||
let block_root = rng.random_range(0..2);
|
||||
slasher.accept_block_header(block(slot, proposer, block_root));
|
||||
}
|
||||
|
||||
// Maybe process
|
||||
if rng.gen_bool(0.1) {
|
||||
if rng.random_bool(0.1) {
|
||||
slasher.process_queued(current_epoch).unwrap();
|
||||
|
||||
// Maybe prune
|
||||
if rng.gen_bool(0.1) {
|
||||
if rng.random_bool(0.1) {
|
||||
slasher.prune_database(current_epoch).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
// Maybe advance to the next epoch
|
||||
if rng.gen_bool(0.5) {
|
||||
if rng.random_bool(0.5) {
|
||||
if check_slashings {
|
||||
slasher.process_queued(current_epoch).unwrap();
|
||||
}
|
||||
@@ -147,10 +148,10 @@ fn random_test(seed: u64, mut db: SlasherDB<E>, test_config: TestConfig) -> Slas
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn no_crash() {
|
||||
let mut rng = thread_rng();
|
||||
let mut rng = rng();
|
||||
let (_tempdir, mut db) = make_db();
|
||||
loop {
|
||||
db = random_test(rng.gen(), db, TestConfig::default());
|
||||
db = random_test(rng.random(), db, TestConfig::default());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,11 +159,11 @@ fn no_crash() {
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn no_crash_with_blocks() {
|
||||
let mut rng = thread_rng();
|
||||
let mut rng = rng();
|
||||
let (_tempdir, mut db) = make_db();
|
||||
loop {
|
||||
db = random_test(
|
||||
rng.gen(),
|
||||
rng.random(),
|
||||
db,
|
||||
TestConfig {
|
||||
add_blocks: true,
|
||||
@@ -176,11 +177,11 @@ fn no_crash_with_blocks() {
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn check_slashings() {
|
||||
let mut rng = thread_rng();
|
||||
let mut rng = rng();
|
||||
let (_tempdir, mut db) = make_db();
|
||||
loop {
|
||||
db = random_test(
|
||||
rng.gen(),
|
||||
rng.random(),
|
||||
db,
|
||||
TestConfig {
|
||||
check_slashings: true,
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
#![cfg(any(feature = "mdbx", feature = "lmdb", feature = "redb"))]
|
||||
|
||||
use slasher::{
|
||||
test_utils::{chain_spec, indexed_att},
|
||||
Config, Slasher,
|
||||
test_utils::{chain_spec, indexed_att},
|
||||
};
|
||||
use tempfile::tempdir;
|
||||
use types::Epoch;
|
||||
|
||||
Reference in New Issue
Block a user