Ensure password dir exists in val dir builder

This commit is contained in:
Paul Hauner
2022-08-29 19:06:55 +10:00
parent fdd0311507
commit b2887f8b55
3 changed files with 8 additions and 0 deletions

1
Cargo.lock generated
View File

@@ -7345,6 +7345,7 @@ dependencies = [
"bls",
"deposit_contract",
"derivative",
"directory",
"eth2_keystore",
"filesystem",
"hex",

View File

@@ -20,6 +20,7 @@ tree_hash = "0.4.1"
hex = "0.4.2"
derivative = "2.1.1"
lockfile = { path = "../lockfile" }
directory = { path = "../directory" }
[dev-dependencies]
tempfile = "3.1.0"

View File

@@ -1,6 +1,7 @@
use crate::{Error as DirError, ValidatorDir};
use bls::get_withdrawal_credentials;
use deposit_contract::{encode_eth1_tx_data, Error as DepositError};
use directory::ensure_dir_exists;
use eth2_keystore::{Error as KeystoreError, Keystore, KeystoreBuilder, PlainText};
use filesystem::create_with_600_perms;
use rand::{distributions::Alphanumeric, Rng};
@@ -41,6 +42,7 @@ pub enum Error {
#[cfg(feature = "insecure_keys")]
InsecureKeysError(String),
MissingPasswordDir,
UnableToCreatePasswordDir(String),
}
impl From<KeystoreError> for Error {
@@ -160,6 +162,10 @@ impl<'a> Builder<'a> {
create_dir_all(&dir).map_err(Error::UnableToCreateDir)?;
}
if let Some(password_dir) = &self.password_dir {
ensure_dir_exists(password_dir).map_err(Error::UnableToCreatePasswordDir)?;
}
// The withdrawal keystore must be initialized in order to store it or create an eth1
// deposit.
if (self.store_withdrawal_keystore || self.deposit_info.is_some())