mirror of
https://github.com/sigp/lighthouse.git
synced 2026-04-29 18:53:32 +00:00
Update Rust Edition to 2024 (#7766)
* #7749 Thanks @dknopik and @michaelsproul for your help!
This commit is contained in:
@@ -159,8 +159,10 @@ fn valid_multiple_validators_not_surrounding() {
|
||||
#[test]
|
||||
fn invalid_source_exceeds_target() {
|
||||
StreamTest {
|
||||
cases: vec![Test::single(attestation_data_builder(1, 0))
|
||||
.expect_invalid_att(InvalidAttestation::SourceExceedsTarget)],
|
||||
cases: vec![
|
||||
Test::single(attestation_data_builder(1, 0))
|
||||
.expect_invalid_att(InvalidAttestation::SourceExceedsTarget),
|
||||
],
|
||||
..StreamTest::default()
|
||||
}
|
||||
.run()
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use slashing_protection::SUPPORTED_INTERCHANGE_FORMAT_VERSION;
|
||||
use slashing_protection::interchange::{
|
||||
Interchange, InterchangeData, InterchangeMetadata, SignedAttestation, SignedBlock,
|
||||
};
|
||||
use slashing_protection::interchange_test::{MultiTestCase, TestCase};
|
||||
use slashing_protection::test_utils::{pubkey, DEFAULT_GENESIS_VALIDATORS_ROOT};
|
||||
use slashing_protection::SUPPORTED_INTERCHANGE_FORMAT_VERSION;
|
||||
use slashing_protection::test_utils::{DEFAULT_GENESIS_VALIDATORS_ROOT, pubkey};
|
||||
use std::fs::{self, File};
|
||||
use std::io::Write;
|
||||
use std::path::Path;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use crate::{
|
||||
interchange::{Interchange, SignedAttestation, SignedBlock},
|
||||
test_utils::{pubkey, DEFAULT_GENESIS_VALIDATORS_ROOT},
|
||||
SigningRoot, SlashingDatabase,
|
||||
interchange::{Interchange, SignedAttestation, SignedBlock},
|
||||
test_utils::{DEFAULT_GENESIS_VALIDATORS_ROOT, pubkey},
|
||||
};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::HashSet;
|
||||
@@ -270,9 +270,11 @@ pub fn check_minification_invariants(interchange: &Interchange, minified: &Inter
|
||||
assert_eq!(mini_block.signing_root, None);
|
||||
|
||||
// All original blocks should have slots <= the mini block.
|
||||
assert!(original_blocks
|
||||
.iter()
|
||||
.all(|block| block.slot <= mini_block.slot));
|
||||
assert!(
|
||||
original_blocks
|
||||
.iter()
|
||||
.all(|block| block.slot <= mini_block.slot)
|
||||
);
|
||||
}
|
||||
|
||||
// Minified data should contain 1 attestation per validator, unless the validator never
|
||||
@@ -289,10 +291,12 @@ pub fn check_minification_invariants(interchange: &Interchange, minified: &Inter
|
||||
let mini_attestation = minified_attestations.first().unwrap();
|
||||
assert_eq!(mini_attestation.signing_root, None);
|
||||
|
||||
assert!(original_attestations
|
||||
.iter()
|
||||
.all(|att| att.source_epoch <= mini_attestation.source_epoch
|
||||
&& att.target_epoch <= mini_attestation.target_epoch));
|
||||
assert!(
|
||||
original_attestations
|
||||
.iter()
|
||||
.all(|att| att.source_epoch <= mini_attestation.source_epoch
|
||||
&& att.target_epoch <= mini_attestation.target_epoch)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,8 +13,8 @@ pub mod test_utils;
|
||||
pub use crate::signed_attestation::{InvalidAttestation, SignedAttestation};
|
||||
pub use crate::signed_block::{InvalidBlock, SignedBlock};
|
||||
pub use crate::slashing_database::{
|
||||
InterchangeError, InterchangeImportOutcome, SlashingDatabase,
|
||||
SUPPORTED_INTERCHANGE_FORMAT_VERSION,
|
||||
InterchangeError, InterchangeImportOutcome, SUPPORTED_INTERCHANGE_FORMAT_VERSION,
|
||||
SlashingDatabase,
|
||||
};
|
||||
use rusqlite::Error as SQLError;
|
||||
use std::fmt::Display;
|
||||
@@ -89,7 +89,7 @@ impl SigningRoot {
|
||||
|
||||
/// Safely parse a `SigningRoot` from the given `column` of an SQLite `row`.
|
||||
fn signing_root_from_row(column: usize, row: &rusqlite::Row) -> rusqlite::Result<SigningRoot> {
|
||||
use rusqlite::{types::Type, Error};
|
||||
use rusqlite::{Error, types::Type};
|
||||
|
||||
let bytes: Vec<u8> = row.get(column)?;
|
||||
if bytes.len() == 32 {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::{signing_root_from_row, SigningRoot};
|
||||
use crate::{SigningRoot, signing_root_from_row};
|
||||
use types::{AttestationData, Epoch, Hash256, SignedRoot};
|
||||
|
||||
/// An attestation that has previously been signed.
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::{signing_root_from_row, SigningRoot};
|
||||
use crate::{SigningRoot, signing_root_from_row};
|
||||
use types::{BeaconBlockHeader, Hash256, SignedRoot, Slot};
|
||||
|
||||
/// A block that has previously been signed.
|
||||
|
||||
@@ -4,10 +4,10 @@ use crate::interchange::{
|
||||
};
|
||||
use crate::signed_attestation::InvalidAttestation;
|
||||
use crate::signed_block::InvalidBlock;
|
||||
use crate::{signing_root_from_row, NotSafe, Safe, SignedAttestation, SignedBlock, SigningRoot};
|
||||
use crate::{NotSafe, Safe, SignedAttestation, SignedBlock, SigningRoot, signing_root_from_row};
|
||||
use filesystem::restrict_file_permissions;
|
||||
use r2d2_sqlite::SqliteConnectionManager;
|
||||
use rusqlite::{params, OptionalExtension, Transaction, TransactionBehavior};
|
||||
use rusqlite::{OptionalExtension, Transaction, TransactionBehavior, params};
|
||||
use std::fs::File;
|
||||
use std::path::Path;
|
||||
use std::time::Duration;
|
||||
@@ -356,15 +356,15 @@ impl SlashingDatabase {
|
||||
.prepare("SELECT MIN(slot) FROM signed_blocks WHERE validator_id = ?1")?
|
||||
.query_row(params![validator_id], |row| row.get(0))?;
|
||||
|
||||
if let Some(min_slot) = min_slot {
|
||||
if slot <= min_slot {
|
||||
return Err(NotSafe::InvalidBlock(
|
||||
InvalidBlock::SlotViolatesLowerBound {
|
||||
block_slot: slot,
|
||||
bound_slot: min_slot,
|
||||
},
|
||||
));
|
||||
}
|
||||
if let Some(min_slot) = min_slot
|
||||
&& slot <= min_slot
|
||||
{
|
||||
return Err(NotSafe::InvalidBlock(
|
||||
InvalidBlock::SlotViolatesLowerBound {
|
||||
block_slot: slot,
|
||||
bound_slot: min_slot,
|
||||
},
|
||||
));
|
||||
}
|
||||
|
||||
Ok(Safe::Valid)
|
||||
@@ -467,30 +467,30 @@ impl SlashingDatabase {
|
||||
.prepare("SELECT MIN(source_epoch) FROM signed_attestations WHERE validator_id = ?1")?
|
||||
.query_row(params![validator_id], |row| row.get(0))?;
|
||||
|
||||
if let Some(min_source) = min_source {
|
||||
if att_source_epoch < min_source {
|
||||
return Err(NotSafe::InvalidAttestation(
|
||||
InvalidAttestation::SourceLessThanLowerBound {
|
||||
source_epoch: att_source_epoch,
|
||||
bound_epoch: min_source,
|
||||
},
|
||||
));
|
||||
}
|
||||
if let Some(min_source) = min_source
|
||||
&& att_source_epoch < min_source
|
||||
{
|
||||
return Err(NotSafe::InvalidAttestation(
|
||||
InvalidAttestation::SourceLessThanLowerBound {
|
||||
source_epoch: att_source_epoch,
|
||||
bound_epoch: min_source,
|
||||
},
|
||||
));
|
||||
}
|
||||
|
||||
let min_target = txn
|
||||
.prepare("SELECT MIN(target_epoch) FROM signed_attestations WHERE validator_id = ?1")?
|
||||
.query_row(params![validator_id], |row| row.get(0))?;
|
||||
|
||||
if let Some(min_target) = min_target {
|
||||
if att_target_epoch <= min_target {
|
||||
return Err(NotSafe::InvalidAttestation(
|
||||
InvalidAttestation::TargetLessThanOrEqLowerBound {
|
||||
target_epoch: att_target_epoch,
|
||||
bound_epoch: min_target,
|
||||
},
|
||||
));
|
||||
}
|
||||
if let Some(min_target) = min_target
|
||||
&& att_target_epoch <= min_target
|
||||
{
|
||||
return Err(NotSafe::InvalidAttestation(
|
||||
InvalidAttestation::TargetLessThanOrEqLowerBound {
|
||||
target_epoch: att_target_epoch,
|
||||
bound_epoch: min_target,
|
||||
},
|
||||
));
|
||||
}
|
||||
|
||||
// Everything has been checked, return Valid
|
||||
@@ -1218,9 +1218,10 @@ mod tests {
|
||||
assert_eq!(db.conn_pool.max_size(), POOL_SIZE);
|
||||
assert_eq!(db.conn_pool.connection_timeout(), CONNECTION_TIMEOUT);
|
||||
let conn = db.conn_pool.get().unwrap();
|
||||
assert!(conn
|
||||
.pragma_query_value(None, "foreign_keys", |row| { row.get::<_, bool>(0) })
|
||||
.unwrap());
|
||||
assert!(
|
||||
conn.pragma_query_value(None, "foreign_keys", |row| { row.get::<_, bool>(0) })
|
||||
.unwrap()
|
||||
);
|
||||
assert_eq!(
|
||||
conn.pragma_query_value(None, "locking_mode", |row| { row.get::<_, String>(0) })
|
||||
.unwrap()
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::*;
|
||||
use tempfile::{tempdir, TempDir};
|
||||
use types::{test_utils::generate_deterministic_keypair, AttestationData, BeaconBlockHeader};
|
||||
use tempfile::{TempDir, tempdir};
|
||||
use types::{AttestationData, BeaconBlockHeader, test_utils::generate_deterministic_keypair};
|
||||
|
||||
pub const DEFAULT_VALIDATOR_INDEX: usize = 0;
|
||||
pub const DEFAULT_DOMAIN: Hash256 = Hash256::ZERO;
|
||||
@@ -135,10 +135,12 @@ fn roundtrip_database(dir: &TempDir, db: &SlashingDatabase, is_empty: bool) {
|
||||
.export_all_interchange_info(DEFAULT_GENESIS_VALIDATORS_ROOT)
|
||||
.unwrap();
|
||||
|
||||
assert!(exported
|
||||
.minify()
|
||||
.unwrap()
|
||||
.equiv(&reexported.minify().unwrap()));
|
||||
assert!(
|
||||
exported
|
||||
.minify()
|
||||
.unwrap()
|
||||
.equiv(&reexported.minify().unwrap())
|
||||
);
|
||||
assert_eq!(is_empty, exported.is_empty());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user