Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions phase1-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ phase1 = { path = "../phase1" }
setup-utils = { path = "../setup-utils" }
snarkvm-curves = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "fc997c" }

fs-err = "2.6"
gumdrop = { version = "0.8.0" }
hex = { version = "0.4.2" }
memmap = { version = "0.7.0" }
Expand Down
4 changes: 2 additions & 2 deletions phase1-cli/src/transform_ratios.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use setup_utils::{calculate_hash, print_hash, CheckForCorrectness, UseCompressio

use snarkvm_curves::PairingEngine as Engine;

use fs_err::OpenOptions;
use memmap::*;
use std::fs::OpenOptions;

pub fn transform_ratios<T: Engine + Sync>(response_filename: &str, parameters: &Phase1Parameters<T>) {
println!(
Expand Down Expand Up @@ -42,7 +42,7 @@ pub fn transform_ratios<T: Engine + Sync>(response_filename: &str, parameters: &

let response_readable_map = unsafe {
MmapOptions::new()
.map(&response_reader)
.map(&response_reader.file())
.expect("unable to create a memory map for input")
};

Expand Down
1 change: 1 addition & 0 deletions phase1-coordinator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ snarkvm-curves = { git = "https://github.com/AleoHQ/snarkVM.git", rev = "fc997c"
anyhow = { version = "1.0.37" }
chrono = { version = "0.4", features = ["serde"] }
chrono-humanize = { version = "0.2" }
fs-err = { version = "2.6.0" }
itertools = "0.10"
futures = { version = "0.3" }
hex = { version = "0.4.2" }
Expand Down
25 changes: 13 additions & 12 deletions phase1-coordinator/src/storage/disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@ use crate::{
};

use anyhow::Result;
use fs_err::{self as fs, File, OpenOptions};
use itertools::Itertools;
use memmap::{MmapMut, MmapOptions};
use rayon::prelude::*;
use serde::{Deserialize, Serialize};

use std::{
collections::{BTreeSet, HashMap, HashSet},
convert::TryFrom,
fs::{self, File, OpenOptions},
io::{Error, ErrorKind, Write},
io::{self, Error, ErrorKind, Write},
path::{Path, PathBuf},
str::FromStr,
sync::{Arc, RwLock},
Expand Down Expand Up @@ -73,7 +74,7 @@ impl Disk {
let file = manifest.reopen_file(locator)?;

// Load the file into memory.
let memory = unsafe { MmapOptions::new().map_mut(&file)? };
let memory = unsafe { MmapOptions::new().map_mut(file.file())? };

// Add the object to the set of opened locators.
storage.open.insert(locator.clone(), Arc::new(RwLock::new(memory)));
Expand Down Expand Up @@ -115,7 +116,7 @@ impl Disk {
// Add the file to the locators.
self.open.insert(
locator.clone(),
Arc::new(RwLock::new(unsafe { MmapOptions::new().map_mut(&file)? })),
Arc::new(RwLock::new(unsafe { MmapOptions::new().map_mut(file.file())? })),
);

// Save the manifest update to disk.
Expand Down Expand Up @@ -305,7 +306,7 @@ impl Disk {
let file = manifest.resize_file(&locator, object.size())?;

// Update the writer.
*writer = unsafe { MmapOptions::new().map_mut(&file)? };
*writer = unsafe { MmapOptions::new().map_mut(file.file())? };

// Write the new object to the file.
(*writer).as_mut().write_all(&object.to_bytes())?;
Expand Down Expand Up @@ -699,7 +700,7 @@ impl DiskManifest {
let path = self.resolver.to_path(&locator)?;

// Open the file.
let file = OpenOptions::new().read(true).write(true).create_new(true).open(&path)?;
let file = OpenOptions::new().read(true).write(true).create_new(true).open(path)?;

// Set the initial file size.
file.set_len(size.unwrap_or(1))?;
Expand Down Expand Up @@ -734,7 +735,7 @@ impl DiskManifest {
let path = self.resolver.to_path(&locator)?;

// Open the file.
let file = OpenOptions::new().read(true).write(true).open(&path)?;
let file = OpenOptions::new().read(true).write(true).open(path)?;

// Add the file to the set of open files.
self.open.insert(locator.clone());
Expand Down Expand Up @@ -762,7 +763,7 @@ impl DiskManifest {
let path = self.resolver.to_path(&locator)?;

// Open the file.
let file = OpenOptions::new().read(true).write(true).open(&path)?;
let file = OpenOptions::new().read(true).write(true).open(path)?;

Ok(file)
}
Expand All @@ -784,7 +785,7 @@ impl DiskManifest {
let path = self.resolver.to_path(&locator)?;

// Open the file.
let file = OpenOptions::new().read(true).write(true).open(&path)?;
let file = OpenOptions::new().read(true).write(true).open(path)?;

// Resize the file.
file.set_len(size)?;
Expand Down Expand Up @@ -879,7 +880,7 @@ impl DiskManifest {
let path = self.resolver.to_path(&locator)?;

// Open the file.
let file = OpenOptions::new().read(true).write(true).open(&path)?;
let file = OpenOptions::new().read(true).write(true).open(path)?;

Ok(file.metadata()?.len())
}
Expand Down Expand Up @@ -1131,13 +1132,13 @@ impl DiskResolver {
// If the round directory does not exist, attempt to initialize the directory path.
let path = self.round_directory(round_height);
if !Path::new(&path).exists() {
std::fs::create_dir_all(&path).expect("unable to create the round directory");
fs::create_dir_all(&path).expect("unable to create the round directory");
}

// If the chunk directory does not exist, attempt to initialize the directory path.
let path = self.chunk_directory(round_height, chunk_id);
if !Path::new(&path).exists() {
std::fs::create_dir_all(&path).expect("unable to create the chunk directory");
fs::create_dir_all(&path).expect("unable to create the chunk directory");
}
}
}
Expand Down
8 changes: 7 additions & 1 deletion phase1-coordinator/src/storage/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use memmap::MmapMut;
use serde::{Deserialize, Serialize};
use std::{
convert::TryFrom,
path::Path,
path::{Path, PathBuf},
sync::{RwLockReadGuard, RwLockWriteGuard},
};

Expand Down Expand Up @@ -205,6 +205,12 @@ impl AsRef<Path> for LocatorPath {
}
}

impl Into<PathBuf> for LocatorPath {
fn into(self) -> PathBuf {
self.as_path().into()
}
}

impl std::fmt::Debug for LocatorPath {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
self.0.fmt(f)
Expand Down
3 changes: 2 additions & 1 deletion phase1-coordinator/src/testing/coordinator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use serial_test::serial;
use std::{path::Path, sync::Arc};
use tracing::*;

use fs_err as fs;
use once_cell::sync::OnceCell;

static INSTANCE: OnceCell<()> = OnceCell::new();
Expand Down Expand Up @@ -98,7 +99,7 @@ fn clear_test_storage(environment: &Environment) {
let path = environment.local_base_directory();
if Path::new(path).exists() {
warn!("Coordinator is clearing {:?}", &path);
match std::fs::remove_dir_all(&path) {
match fs::remove_dir_all(&path) {
Ok(_) => (),
Err(error) => error!(
"The testing framework tried to clear the test transcript and failed. {}",
Expand Down
3 changes: 2 additions & 1 deletion phase1-coordinator/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use crate::{
use chrono::Utc;
use phase1::{helpers::CurveKind, ContributionMode, ProvingSystem};

use fs_err as fs;
use rand::RngCore;
use rayon::iter::{IntoParallelRefIterator, ParallelIterator};
use std::{
Expand Down Expand Up @@ -1342,7 +1343,7 @@ fn check_round_matches_storage_files(storage: &Disk, round: &Round) {
let path = initial_challenge_location.as_path();
let chunk_dir = path.parent().unwrap();

let n_files = std::fs::read_dir(&chunk_dir).unwrap().count();
let n_files = fs::read_dir(&chunk_dir).unwrap().count();

let contributions_complete = chunk.only_contributions_complete(round.expected_number_of_contributions());

Expand Down
1 change: 1 addition & 0 deletions setup1-contributor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ blake2 = "0.9"
clap = { version = "2.33.3" }
dialoguer = "0.8"
egg-mode = "0.16"
fs-err = "2.6"
futures = { version = "0.3" }
futures-util = { version = "0.3.15", default-features = false, features = ["async-await", "sink", "std"] }
hex = { version = "0.4" }
Expand Down
8 changes: 4 additions & 4 deletions setup1-contributor/src/commands/contribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ use snarkvm_dpc::{parameters::testnet2::Testnet2Parameters, Address, PrivateKey,
use age::DecryptError;
use anyhow::{Context, Result};
use dialoguer::{theme::ColorfulTheme, Confirm, Input};
use fs_err::File;
use indicatif::{ProgressBar, ProgressStyle};
use lazy_static::lazy_static;
use panic_control::{spawn_quiet, ThreadResultExt};
Expand All @@ -41,10 +42,9 @@ use setup_utils::derive_rng_from_seed;
use std::{
collections::{HashMap, HashSet, VecDeque},
convert::TryFrom,
fs::File,
io::{Read, Write},
ops::Deref,
path::Path,
path::PathBuf,
str::FromStr,
sync::{Arc, RwLock},
time::Duration,
Expand Down Expand Up @@ -1152,12 +1152,12 @@ fn decrypt(passphrase: &SecretString, encrypted: &str) -> Result<Vec<u8>> {

/// Decrypts and reads the private key from the specified `keys_path`,
/// decrypting using the specified `passphrase`
fn read_keys<P: AsRef<Path>>(
fn read_keys<P: Into<PathBuf>>(
keys_path: P,
passphrase: &SecretString,
) -> Result<(SecretVec<u8>, PrivateKey<Testnet2Parameters>)> {
let mut contents = String::new();
std::fs::File::open(keys_path)?.read_to_string(&mut contents)?;
File::open(keys_path)?.read_to_string(&mut contents)?;
let keys: AleoSetupKeys = serde_json::from_str(&contents)?;

let seed = SecretVec::new(decrypt(passphrase, &keys.encrypted_seed)?);
Expand Down
3 changes: 2 additions & 1 deletion setup1-contributor/src/commands/generate.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use fs_err::File;
use std::io::Write;

use crate::cli::commands::generate::GenerateOptions;

pub fn generate_keys(opts: GenerateOptions) {
let mut file = std::fs::File::create(&opts.keys_path).expect("Should have created keys file");
let mut file = File::create(&opts.keys_path).expect("Should have created keys file");
let passphrase = crate::setup_keys::read_or_generate_passphrase(opts.passphrase);

println!("\nDO NOT FORGET YOUR PASSPHRASE!\n\nYou will need your passphrase to access your keys.\n\n");
Expand Down
7 changes: 4 additions & 3 deletions setup1-contributor/src/setup_keys/confirmation_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::path::Path;

use anyhow::Result;
use blake2::{Blake2s, Digest};
use fs_err as fs;
use serde::{Deserialize, Serialize};

const CONFIRMATION_KEY_FILE: &str = ".confirmation_key";
Expand Down Expand Up @@ -51,14 +52,14 @@ impl ConfirmationKey {
}

fn read_from_disk() -> Result<Self> {
let bytes = std::fs::read(CONFIRMATION_KEY_FILE)?;
let bytes = fs::read(CONFIRMATION_KEY_FILE)?;
let key_file = serde_json::from_slice(&bytes)?;
Ok(key_file)
}

fn write_to_disk(&self) -> Result<()> {
let bytes = serde_json::to_vec(self)?;
std::fs::write(CONFIRMATION_KEY_FILE, bytes)?;
fs::write(CONFIRMATION_KEY_FILE, bytes)?;
Ok(())
}

Expand All @@ -80,6 +81,6 @@ pub fn print_key_and_remove_the_file() -> Result<()> {
println!("Store this information in order to prove your participation in the setup");
println!("Do not share the confirmation key with others!");
println!("|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||");
std::fs::remove_file(CONFIRMATION_KEY_FILE)?;
fs::remove_file(CONFIRMATION_KEY_FILE)?;
Ok(())
}
4 changes: 2 additions & 2 deletions setup1-contributor/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ use snarkvm_dpc::{parameters::testnet2::Testnet2Parameters, Address, PrivateKey,
use snarkvm_utilities::ToBytes;

use anyhow::Result;
use rand::{CryptoRng, Rng};
#[cfg(test)]
use std::fs::{create_dir_all, write};
use fs_err::{create_dir_all, write};
use rand::{CryptoRng, Rng};
use std::{
convert::TryFrom,
fs::{remove_file, File},
Expand Down
Loading