install: Drop unneeded sha2 dependency (#7108)

* Poll for updates slower

* Drop sha2 dependency
This commit is contained in:
Michael Vines 2019-11-22 21:58:26 -07:00 committed by GitHub
parent 3e0b272a20
commit 306fbd8bd8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 34 additions and 30 deletions

1
Cargo.lock generated
View File

@ -3507,7 +3507,6 @@ dependencies = [
"serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_yaml 0.8.11 (registry+https://github.com/rust-lang/crates.io-index)",
"sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"solana-clap-utils 0.21.0",
"solana-client 0.21.0",
"solana-config-program 0.21.0",

View File

@ -26,7 +26,6 @@ reqwest = { version = "0.9.22", default-features = false, features = ["rustls-tl
serde = "1.0.102"
serde_derive = "1.0.102"
serde_yaml = "0.8.11"
sha2 = "0.8.0"
solana-clap-utils = { path = "../clap-utils", version = "0.21.0" }
solana-client = { path = "../client", version = "0.21.0" }
solana-config-program = { path = "../programs/config", version = "0.21.0" }

View File

@ -1,22 +1,27 @@
use crate::config::{Config, ExplicitRelease};
use crate::stop_process::stop_process;
use crate::update_manifest::{SignedUpdateManifest, UpdateManifest};
use crate::{
config::{Config, ExplicitRelease},
stop_process::stop_process,
update_manifest::{SignedUpdateManifest, UpdateManifest},
};
use chrono::{Local, TimeZone};
use console::{style, Emoji};
use indicatif::{ProgressBar, ProgressStyle};
use sha2::{Digest, Sha256};
use solana_client::rpc_client::RpcClient;
use solana_config_program::{config_instruction, get_config_data};
use solana_sdk::message::Message;
use solana_sdk::pubkey::Pubkey;
use solana_sdk::signature::{read_keypair_file, Keypair, KeypairUtil, Signable};
use solana_sdk::transaction::Transaction;
use std::fs::{self, File};
use std::io::{self, BufReader, Read};
use std::path::{Path, PathBuf};
use std::sync::mpsc;
use std::time::SystemTime;
use std::time::{Duration, Instant};
use solana_sdk::{
hash::{Hash, Hasher},
message::Message,
pubkey::Pubkey,
signature::{read_keypair_file, Keypair, KeypairUtil, Signable},
transaction::Transaction,
};
use std::{
fs::{self, File},
io::{self, BufReader, Read},
path::{Path, PathBuf},
sync::mpsc,
time::{Duration, Instant, SystemTime},
};
use tempdir::TempDir;
use url::Url;
@ -51,12 +56,12 @@ fn println_name_value(name: &str, value: &str) {
///
fn download_to_temp_archive(
url: &str,
expected_sha256: Option<&str>,
) -> Result<(TempDir, PathBuf, String), Box<dyn std::error::Error>> {
fn sha256_file_digest<P: AsRef<Path>>(path: P) -> Result<String, Box<dyn std::error::Error>> {
expected_sha256: Option<&Hash>,
) -> Result<(TempDir, PathBuf, Hash), Box<dyn std::error::Error>> {
fn sha256_file_digest<P: AsRef<Path>>(path: P) -> Result<Hash, Box<dyn std::error::Error>> {
let input = File::open(path)?;
let mut reader = BufReader::new(input);
let mut hasher = Sha256::new();
let mut hasher = Hasher::default();
let mut buffer = [0; 1024];
loop {
@ -64,9 +69,9 @@ fn download_to_temp_archive(
if count == 0 {
break;
}
hasher.input(&buffer[..count]);
hasher.hash(&buffer[..count]);
}
Ok(bs58::encode(hasher.result()).into_string())
Ok(hasher.result())
}
let url = Url::parse(url).map_err(|err| format!("Unable to parse {}: {}", url, err))?;
@ -788,7 +793,7 @@ pub fn update(config_file: &str) -> Result<bool, String> {
return Err("Unable to update to an older version".to_string());
}
}
let release_dir = config.release_dir(&update_manifest.download_sha256);
let release_dir = config.release_dir(&update_manifest.download_sha256.to_string());
let (_temp_dir, temp_archive, _temp_archive_sha256) = download_to_temp_archive(
&update_manifest.download_url,
Some(&update_manifest.download_sha256),

View File

@ -33,7 +33,7 @@ impl Config {
json_rpc_url: json_rpc_url.to_string(),
update_manifest_pubkey: *update_manifest_pubkey,
current_update_manifest: None,
update_poll_secs: 60, // check for updates once a minute
update_poll_secs: 60 * 60, // check for updates once an hour
explicit_release,
releases_dir: PathBuf::from(data_dir).join("releases"),
active_release_dir: PathBuf::from(data_dir).join("active_release"),

View File

@ -1,17 +1,18 @@
use serde_derive::{Deserialize, Serialize};
use solana_config_program::ConfigState;
use solana_sdk::pubkey::Pubkey;
use solana_sdk::signature::{Signable, Signature};
use std::borrow::Cow;
use std::error;
use std::io;
use solana_sdk::{
hash::Hash,
pubkey::Pubkey,
signature::{Signable, Signature},
};
use std::{borrow::Cow, error, io};
/// Information required to download and apply a given update
#[derive(Serialize, Deserialize, Default, Debug, PartialEq)]
pub struct UpdateManifest {
pub timestamp_secs: u64, // When the release was deployed in seconds since UNIX EPOCH
pub download_url: String, // Download URL to the release tar.bz2
pub download_sha256: String, // SHA256 digest of the release tar.bz2 file
pub download_sha256: Hash, // SHA256 digest of the release tar.bz2 file
}
/// Userdata of an Update Manifest program Account.