mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-03 00:31:50 +00:00
check if the slashing protection database is locked before creating keys (#1949)
## Issue Addressed Closes #1790 ## Proposed Changes Make a new method that creates an empty transaction with `TransactionBehavior::Exclusive` to check whether the slashing protection is locked. Call this method before attempting to create or import new validator keystores. ## Additional Info N/A Co-authored-by: realbigsean <seananderson33@gmail.com>
This commit is contained in:
@@ -136,6 +136,13 @@ impl SlashingDatabase {
|
||||
#[cfg(windows)]
|
||||
fn set_db_file_permissions(file: &File) -> Result<(), NotSafe> {}
|
||||
|
||||
/// Creates an empty transaction and drops it. Used to test whether the database is locked.
|
||||
pub fn test_transaction(&self) -> Result<(), NotSafe> {
|
||||
let mut conn = self.conn_pool.get()?;
|
||||
Transaction::new(&mut conn, TransactionBehavior::Exclusive)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Register a validator with the slashing protection database.
|
||||
///
|
||||
/// This allows the validator to record their signatures in the database, and check
|
||||
@@ -803,4 +810,14 @@ mod tests {
|
||||
let db2 = SlashingDatabase::open(&file).unwrap();
|
||||
check(&db2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_transaction_failure() {
|
||||
let dir = tempdir().unwrap();
|
||||
let file = dir.path().join("db.sqlite");
|
||||
let _db1 = SlashingDatabase::create(&file).unwrap();
|
||||
|
||||
let db2 = SlashingDatabase::open(&file).unwrap();
|
||||
db2.test_transaction().unwrap_err();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user