Poh subsystem cleanup, genesis plumbing, enable real PoH on edge testnet (#4292)

* Remove unused PohServiceConfig::Step

* Clarify variable name

* Poh::hash() now takes an iteration counter

* man -> max

* Inline functions with single call site

* Move PohServiceConfig into GenesisBlock

* Add plumbing to enable real PoH on testnets

* Batch hashes to improve PoH hash rate

* Ensure a constant hashes_per_tick

* Remove PohEntry mixin field

* Poh/PohEntry no longer maintains tick_height

* Ensure a constant hashes_per_tick

* ci/localnet-sanity.sh: Use real PoH

* Rework Poh/PohService to keep PohRecorder unlocked as much as possible while hashing
This commit is contained in:
Michael Vines
2019-05-18 14:01:36 -07:00
committed by GitHub
parent 7e1a7862db
commit 392a39dd54
26 changed files with 625 additions and 319 deletions

View File

@ -19,18 +19,26 @@ use solana::blocktree::create_new_ledger;
use solana_sdk::account::Account;
use solana_sdk::fee_calculator::FeeCalculator;
use solana_sdk::genesis_block::GenesisBlock;
use solana_sdk::hash::{hash, Hash};
use solana_sdk::poh_config::PohConfig;
use solana_sdk::signature::{read_keypair, KeypairUtil};
use solana_sdk::system_program;
use solana_sdk::timing;
use solana_stake_api::stake_state;
use solana_vote_api::vote_state;
use std::error;
use std::time::{Duration, Instant};
pub const BOOTSTRAP_LEADER_LAMPORTS: u64 = 42;
fn main() -> Result<(), Box<dyn error::Error>> {
let default_bootstrap_leader_lamports = &BOOTSTRAP_LEADER_LAMPORTS.to_string();
let default_lamports_per_signature =
&format!("{}", FeeCalculator::default().lamports_per_signature);
&FeeCalculator::default().lamports_per_signature.to_string();
let default_target_tick_duration =
&timing::duration_as_ms(&PohConfig::default().target_tick_duration).to_string();
let default_ticks_per_slot = &timing::DEFAULT_TICKS_PER_SLOT.to_string();
let default_slots_per_epoch = &timing::DEFAULT_SLOTS_PER_EPOCH.to_string();
let matches = App::new(crate_name!())
.about(crate_description!())
@ -106,6 +114,43 @@ fn main() -> Result<(), Box<dyn error::Error>> {
.default_value(default_lamports_per_signature)
.help("Number of lamports the cluster will charge for signature verification"),
)
.arg(
Arg::with_name("target_tick_duration")
.long("target-tick-duration")
.value_name("MILLIS")
.takes_value(true)
.default_value(default_target_tick_duration)
.help("The target tick rate of the cluster in milliseconds"),
)
.arg(
Arg::with_name("hashes_per_tick")
.long("hashes-per-tick")
.value_name("NUM_HASHES|\"auto\"|\"sleep\"")
.takes_value(true)
.default_value("auto")
.help(
"How many PoH hashes to roll before emitting the next tick. \
If \"auto\", determine based on --target-tick-duration \
and the hash rate of this computer. If \"sleep\", for development \
sleep for --target-tick-duration instead of hashing",
),
)
.arg(
Arg::with_name("ticks_per_slot")
.long("ticks-per-slot")
.value_name("TICKS")
.takes_value(true)
.default_value(default_ticks_per_slot)
.help("The number of ticks in a slot"),
)
.arg(
Arg::with_name("slots_per_epoch")
.long("slots-per-epoch")
.value_name("SLOTS")
.takes_value(true)
.default_value(default_slots_per_epoch)
.help("The number of slots in an epoch"),
)
.get_matches();
let bootstrap_leader_keypair_file = matches.value_of("bootstrap_leader_keypair_file").unwrap();
@ -169,6 +214,36 @@ fn main() -> Result<(), Box<dyn error::Error>> {
);
genesis_block.fee_calculator.lamports_per_signature =
value_t_or_exit!(matches, "lamports_per_signature", u64);
genesis_block.ticks_per_slot = value_t_or_exit!(matches, "ticks_per_slot", u64);
genesis_block.slots_per_epoch = value_t_or_exit!(matches, "slots_per_epoch", u64);
genesis_block.poh_config.target_tick_duration =
Duration::from_millis(value_t_or_exit!(matches, "target_tick_duration", u64));
match matches.value_of("hashes_per_tick").unwrap() {
"auto" => {
let mut v = Hash::default();
println!("Running 1 million hashes...");
let start = Instant::now();
for _ in 0..1_000_000 {
v = hash(&v.as_ref());
}
let end = Instant::now();
let elapsed = end.duration_since(start).as_millis();
let hashes_per_tick = (genesis_block.poh_config.target_tick_duration.as_millis()
* 1_000_000
/ elapsed) as u64;
println!("Hashes per tick: {}", hashes_per_tick);
genesis_block.poh_config.hashes_per_tick = Some(hashes_per_tick);
}
"sleep" => {
genesis_block.poh_config.hashes_per_tick = None;
}
_ => {
genesis_block.poh_config.hashes_per_tick =
Some(value_t_or_exit!(matches, "hashes_per_tick", u64));
}
}
create_new_ledger(ledger_path, &genesis_block)?;
Ok(())