Skip to content

Commit

Permalink
Pass around --max-genesis-archive-unpacked-size (solana-labs#9161)
Browse files Browse the repository at this point in the history
automerge
  • Loading branch information
ryoqun authored Apr 30, 2020
1 parent a0514eb commit a912360
Show file tree
Hide file tree
Showing 12 changed files with 208 additions and 53 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

7 changes: 5 additions & 2 deletions core/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use solana_ledger::{
blockstore::{Blockstore, CompletedSlotsReceiver},
blockstore_processor::{self, BankForksInfo},
create_new_tmp_ledger,
hardened_unpack::open_genesis_config,
hardened_unpack::{open_genesis_config, MAX_GENESIS_ARCHIVE_UNPACKED_SIZE},
leader_schedule::FixedSchedule,
leader_schedule_cache::LeaderScheduleCache,
};
Expand Down Expand Up @@ -82,6 +82,7 @@ pub struct ValidatorConfig {
pub frozen_accounts: Vec<Pubkey>,
pub no_rocksdb_compaction: bool,
pub accounts_hash_interval_slots: u64,
pub max_genesis_archive_unpacked_size: u64,
}

impl Default for ValidatorConfig {
Expand Down Expand Up @@ -109,6 +110,7 @@ impl Default for ValidatorConfig {
frozen_accounts: vec![],
no_rocksdb_compaction: false,
accounts_hash_interval_slots: std::u64::MAX,
max_genesis_archive_unpacked_size: MAX_GENESIS_ARCHIVE_UNPACKED_SIZE,
}
}
}
Expand Down Expand Up @@ -569,7 +571,8 @@ fn new_banks_from_blockstore(
LeaderScheduleCache,
Option<(Slot, Hash)>,
) {
let genesis_config = open_genesis_config(blockstore_path);
let genesis_config =
open_genesis_config(blockstore_path, config.max_genesis_archive_unpacked_size);

// This needs to be limited otherwise the state in the VoteAccount data
// grows too large
Expand Down
1 change: 1 addition & 0 deletions genesis/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ serde_yaml = "0.8.11"
solana-clap-utils = { path = "../clap-utils", version = "1.2.0" }
solana-genesis-programs = { path = "../genesis-programs", version = "1.2.0" }
solana-ledger = { path = "../ledger", version = "1.2.0" }
solana-logger = { path = "../logger", version = "1.2.0" }
solana-sdk = { path = "../sdk", version = "1.2.0" }
solana-stake-program = { path = "../programs/stake", version = "1.2.0" }
solana-storage-program = { path = "../programs/storage", version = "1.2.0" }
Expand Down
26 changes: 24 additions & 2 deletions genesis/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ use solana_clap_utils::{
input_validators::{is_pubkey_or_keypair, is_rfc3339_datetime, is_valid_percentage},
};
use solana_genesis::{genesis_accounts::add_genesis_accounts, Base64Account};
use solana_ledger::{blockstore::create_new_ledger, poh::compute_hashes_per_tick};
use solana_ledger::{
blockstore::create_new_ledger, hardened_unpack::MAX_GENESIS_ARCHIVE_UNPACKED_SIZE,
poh::compute_hashes_per_tick,
};
use solana_sdk::{
account::Account,
clock,
Expand Down Expand Up @@ -121,6 +124,7 @@ fn main() -> Result<(), Box<dyn error::Error>> {
timing::duration_as_us(&PohConfig::default().target_tick_duration);
let default_ticks_per_slot = &clock::DEFAULT_TICKS_PER_SLOT.to_string();
let default_operating_mode = "stable";
let default_genesis_archive_unpacked_size = MAX_GENESIS_ARCHIVE_UNPACKED_SIZE.to_string();

let matches = App::new(crate_name!())
.about(crate_description!())
Expand Down Expand Up @@ -327,6 +331,16 @@ fn main() -> Result<(), Box<dyn error::Error>> {
"Selects the features that will be enabled for the cluster"
),
)
.arg(
Arg::with_name("max_genesis_archive_unpacked_size")
.long("max-genesis-archive-unpacked-size")
.value_name("NUMBER")
.takes_value(true)
.default_value(&default_genesis_archive_unpacked_size)
.help(
"maximum total uncompressed file size of created genesis archive",
),
)
.get_matches();

let faucet_lamports = value_t!(matches, "faucet_lamports", u64).unwrap_or(0);
Expand Down Expand Up @@ -513,6 +527,9 @@ fn main() -> Result<(), Box<dyn error::Error>> {
}
}

let max_genesis_archive_unpacked_size =
value_t_or_exit!(matches, "max_genesis_archive_unpacked_size", u64);

let issued_lamports = genesis_config
.accounts
.iter()
Expand All @@ -521,7 +538,12 @@ fn main() -> Result<(), Box<dyn error::Error>> {

add_genesis_accounts(&mut genesis_config, issued_lamports - faucet_lamports);

create_new_ledger(&ledger_path, &genesis_config)?;
solana_logger::setup();
create_new_ledger(
&ledger_path,
&genesis_config,
max_genesis_archive_unpacked_size,
)?;

println!("{}", genesis_config);
Ok(())
Expand Down
48 changes: 37 additions & 11 deletions ledger-tool/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use solana_ledger::{
blockstore::Blockstore,
blockstore_db::{self, Column, Database},
blockstore_processor::{BankForksInfo, ProcessOptions},
hardened_unpack::open_genesis_config,
hardened_unpack::{open_genesis_config, MAX_GENESIS_ARCHIVE_UNPACKED_SIZE},
rooted_slot_iterator::RootedSlotIterator,
snapshot_utils,
};
Expand Down Expand Up @@ -575,6 +575,12 @@ fn load_bank_forks(
)
}

fn open_genesis_config_by(ledger_path: &Path, matches: &ArgMatches<'_>) -> GenesisConfig {
let max_genesis_archive_unpacked_size =
value_t_or_exit!(matches, "max_genesis_archive_unpacked_size", u64);
open_genesis_config(ledger_path, max_genesis_archive_unpacked_size)
}

#[allow(clippy::cognitive_complexity)]
fn main() {
const DEFAULT_ROOT_COUNT: &str = "1";
Expand Down Expand Up @@ -612,6 +618,13 @@ fn main() {
.long("allow-dead-slots")
.takes_value(false)
.help("Output dead slots as well");
let default_genesis_archive_unpacked_size = MAX_GENESIS_ARCHIVE_UNPACKED_SIZE.to_string();
let max_genesis_archive_unpacked_size_arg = Arg::with_name("max_genesis_archive_unpacked_size")
.long("max-genesis-archive-unpacked-size")
.value_name("NUMBER")
.takes_value(true)
.default_value(&default_genesis_archive_unpacked_size)
.help("maximum total uncompressed size of unpacked genesis archive");

let matches = App::new(crate_name!())
.about(crate_description!())
Expand Down Expand Up @@ -663,15 +676,18 @@ fn main() {
.subcommand(
SubCommand::with_name("genesis")
.about("Prints the ledger's genesis config")
.arg(&max_genesis_archive_unpacked_size_arg)
)
.subcommand(
SubCommand::with_name("genesis-hash")
.about("Prints the ledger's genesis hash")
.arg(&max_genesis_archive_unpacked_size_arg)
)
.subcommand(
SubCommand::with_name("shred-version")
.about("Prints the ledger's shred hash")
.arg(&hard_forks_arg)
.arg(&max_genesis_archive_unpacked_size_arg)
)
.subcommand(
SubCommand::with_name("bounds")
Expand All @@ -696,6 +712,7 @@ fn main() {
.arg(&account_paths_arg)
.arg(&halt_at_slot_arg)
.arg(&hard_forks_arg)
.arg(&max_genesis_archive_unpacked_size_arg)
.arg(
Arg::with_name("skip_poh_verify")
.long("skip-poh-verify")
Expand All @@ -709,6 +726,7 @@ fn main() {
.arg(&account_paths_arg)
.arg(&halt_at_slot_arg)
.arg(&hard_forks_arg)
.arg(&max_genesis_archive_unpacked_size_arg)
.arg(
Arg::with_name("include_all_votes")
.long("include-all-votes")
Expand All @@ -727,6 +745,7 @@ fn main() {
.arg(&no_snapshot_arg)
.arg(&account_paths_arg)
.arg(&hard_forks_arg)
.arg(&max_genesis_archive_unpacked_size_arg)
.arg(
Arg::with_name("snapshot_slot")
.index(1)
Expand Down Expand Up @@ -755,6 +774,7 @@ fn main() {
.takes_value(false)
.help("Include sysvars too"),
)
.arg(&max_genesis_archive_unpacked_size_arg)
).subcommand(
SubCommand::with_name("prune")
.about("Prune the ledger from a yaml file containing a list of slots to prune.")
Expand Down Expand Up @@ -847,11 +867,14 @@ fn main() {
LedgerOutputMethod::Print,
);
}
("genesis", Some(_arg_matches)) => {
println!("{}", open_genesis_config(&ledger_path));
("genesis", Some(arg_matches)) => {
println!("{}", open_genesis_config_by(&ledger_path, arg_matches));
}
("genesis-hash", Some(_arg_matches)) => {
println!("{}", open_genesis_config(&ledger_path).hash());
("genesis-hash", Some(arg_matches)) => {
println!(
"{}",
open_genesis_config_by(&ledger_path, arg_matches).hash()
);
}
("shred-version", Some(arg_matches)) => {
let process_options = ProcessOptions {
Expand All @@ -860,7 +883,7 @@ fn main() {
poh_verify: false,
..ProcessOptions::default()
};
let genesis_config = open_genesis_config(&ledger_path);
let genesis_config = open_genesis_config_by(&ledger_path, arg_matches);
match load_bank_forks(arg_matches, &ledger_path, &genesis_config, process_options) {
Ok((bank_forks, bank_forks_info, _leader_schedule_cache, _snapshot_hash)) => {
let bank_info = &bank_forks_info[0];
Expand Down Expand Up @@ -923,12 +946,15 @@ fn main() {
poh_verify: !arg_matches.is_present("skip_poh_verify"),
..ProcessOptions::default()
};
println!("{}", open_genesis_config(&ledger_path).hash());
println!(
"genesis hash: {}",
open_genesis_config_by(&ledger_path, arg_matches).hash()
);

load_bank_forks(
arg_matches,
&ledger_path,
&open_genesis_config(&ledger_path),
&open_genesis_config_by(&ledger_path, arg_matches),
process_options,
)
.unwrap_or_else(|err| {
Expand All @@ -950,7 +976,7 @@ fn main() {
match load_bank_forks(
arg_matches,
&ledger_path,
&open_genesis_config(&ledger_path),
&open_genesis_config_by(&ledger_path, arg_matches),
process_options,
) {
Ok((bank_forks, bank_forks_info, _leader_schedule_cache, _snapshot_hash)) => {
Expand Down Expand Up @@ -991,7 +1017,7 @@ fn main() {
poh_verify: false,
..ProcessOptions::default()
};
let genesis_config = open_genesis_config(&ledger_path);
let genesis_config = open_genesis_config_by(&ledger_path, arg_matches);
match load_bank_forks(arg_matches, &ledger_path, &genesis_config, process_options) {
Ok((bank_forks, _bank_forks_info, _leader_schedule_cache, _snapshot_hash)) => {
let bank = bank_forks.get(snapshot_slot).unwrap_or_else(|| {
Expand Down Expand Up @@ -1055,7 +1081,7 @@ fn main() {
poh_verify: false,
..ProcessOptions::default()
};
let genesis_config = open_genesis_config(&ledger_path);
let genesis_config = open_genesis_config_by(&ledger_path, arg_matches);
let include_sysvars = arg_matches.is_present("include_sysvars");
match load_bank_forks(arg_matches, &ledger_path, &genesis_config, process_options) {
Ok((bank_forks, bank_forks_info, _leader_schedule_cache, _snapshot_hash)) => {
Expand Down
64 changes: 61 additions & 3 deletions ledger/src/blockstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::{
blockstore_meta::*,
entry::{create_ticks, Entry},
erasure::ErasureConfig,
hardened_unpack::{unpack_genesis_archive, MAX_GENESIS_ARCHIVE_UNPACKED_SIZE},
leader_schedule_cache::LeaderScheduleCache,
next_slots_iterator::NextSlotsIterator,
shred::{Result as ShredResult, Shred, Shredder},
Expand Down Expand Up @@ -45,6 +46,7 @@ use std::{
cmp,
collections::HashMap,
fs,
io::{Error as IOError, ErrorKind},
path::{Path, PathBuf},
rc::Rc,
sync::{
Expand Down Expand Up @@ -2622,7 +2624,11 @@ fn calculate_stake_weighted_timestamp(
// Creates a new ledger with slot 0 full of ticks (and only ticks).
//
// Returns the blockhash that can be used to append entries with.
pub fn create_new_ledger(ledger_path: &Path, genesis_config: &GenesisConfig) -> Result<Hash> {
pub fn create_new_ledger(
ledger_path: &Path,
genesis_config: &GenesisConfig,
max_genesis_archive_unpacked_size: u64,
) -> Result<Hash> {
Blockstore::destroy(ledger_path)?;
genesis_config.write(&ledger_path)?;

Expand Down Expand Up @@ -2658,7 +2664,6 @@ pub fn create_new_ledger(ledger_path: &Path, genesis_config: &GenesisConfig) ->
.output()
.unwrap();
if !output.status.success() {
use std::io::{Error as IOError, ErrorKind};
use std::str::from_utf8;
error!("tar stdout: {}", from_utf8(&output.stdout).unwrap_or("?"));
error!("tar stderr: {}", from_utf8(&output.stderr).unwrap_or("?"));
Expand All @@ -2672,6 +2677,54 @@ pub fn create_new_ledger(ledger_path: &Path, genesis_config: &GenesisConfig) ->
)));
}

// ensure the genesis archive can be unpacked and it is under
// max_genesis_archive_unpacked_size, immedately after creating it above.
{
let temp_dir = tempfile::TempDir::new().unwrap();
// unpack into a temp dir, while completely discarding the unpacked files
let unpack_check = unpack_genesis_archive(
&archive_path,
&temp_dir.into_path(),
max_genesis_archive_unpacked_size,
);
if let Err(unpack_err) = unpack_check {
// stash problematic original archived genesis related files to
// examine them later and to prevent validator and ledger-tool from
// naively consuming them
let mut error_messages = String::new();

fs::rename(
&ledger_path.join("genesis.tar.bz2"),
ledger_path.join("genesis.tar.bz2.failed"),
)
.unwrap_or_else(|e| {
error_messages += &format!("/failed to stash problematic genesis.tar.bz2: {}", e)
});
fs::rename(
&ledger_path.join("genesis.bin"),
ledger_path.join("genesis.bin.failed"),
)
.unwrap_or_else(|e| {
error_messages += &format!("/failed to stash problematic genesis.bin: {}", e)
});
fs::rename(
&ledger_path.join("rocksdb"),
ledger_path.join("rocksdb.failed"),
)
.unwrap_or_else(|e| {
error_messages += &format!("/failed to stash problematic rocksdb: {}", e)
});

return Err(BlockstoreError::IO(IOError::new(
ErrorKind::Other,
format!(
"Error checking to unpack genesis archive: {}{}",
unpack_err, error_messages
),
)));
}
}

Ok(last_hash)
}

Expand Down Expand Up @@ -2739,7 +2792,12 @@ pub fn verify_shred_slots(slot: Slot, parent_slot: Slot, last_root: Slot) -> boo
// ticks)
pub fn create_new_ledger_from_name(name: &str, genesis_config: &GenesisConfig) -> (PathBuf, Hash) {
let ledger_path = get_ledger_path_from_name(name);
let blockhash = create_new_ledger(&ledger_path, genesis_config).unwrap();
let blockhash = create_new_ledger(
&ledger_path,
genesis_config,
MAX_GENESIS_ARCHIVE_UNPACKED_SIZE,
)
.unwrap();
(ledger_path, blockhash)
}

Expand Down
3 changes: 2 additions & 1 deletion ledger/src/blockstore_db.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::blockstore_meta;
use crate::{blockstore_meta, hardened_unpack::UnpackError};
use bincode::{deserialize, serialize};
use byteorder::{BigEndian, ByteOrder};
use log::*;
Expand Down Expand Up @@ -55,6 +55,7 @@ pub enum BlockstoreError {
Serialize(#[from] Box<bincode::ErrorKind>),
FsExtraError(#[from] fs_extra::error::Error),
SlotCleanedUp,
UnpackError(#[from] UnpackError),
}
pub type Result<T> = std::result::Result<T, BlockstoreError>;

Expand Down
Loading

0 comments on commit a912360

Please sign in to comment.