2019-11-12 19:30:35 -08:00
|
|
|
use log::*;
|
2019-03-01 10:36:52 -08:00
|
|
|
/// Cluster independant integration tests
|
|
|
|
///
|
|
|
|
/// All tests must start from an entry point and a funding keypair and
|
|
|
|
/// discover the rest of the network.
|
2019-11-06 13:15:00 -08:00
|
|
|
use rand::{thread_rng, Rng};
|
|
|
|
use solana_client::thin_client::create_client;
|
2019-08-21 10:23:33 -07:00
|
|
|
use solana_core::{
|
2019-10-18 09:28:51 -07:00
|
|
|
cluster_info::VALIDATOR_PORT_RANGE, consensus::VOTE_THRESHOLD_DEPTH, contact_info::ContactInfo,
|
|
|
|
gossip_service::discover_cluster,
|
|
|
|
};
|
|
|
|
use solana_ledger::{
|
2020-01-13 13:13:52 -08:00
|
|
|
blockstore::Blockstore,
|
2019-08-16 00:00:38 -07:00
|
|
|
entry::{Entry, EntrySlice},
|
|
|
|
};
|
|
|
|
use solana_sdk::{
|
|
|
|
client::SyncClient,
|
2019-12-03 16:31:59 -08:00
|
|
|
clock::{
|
2020-05-05 14:07:21 -07:00
|
|
|
self, Slot, DEFAULT_MS_PER_SLOT, DEFAULT_TICKS_PER_SECOND, DEFAULT_TICKS_PER_SLOT,
|
2019-12-03 16:31:59 -08:00
|
|
|
NUM_CONSECUTIVE_LEADER_SLOTS,
|
|
|
|
},
|
2019-11-06 13:15:00 -08:00
|
|
|
commitment_config::CommitmentConfig,
|
2019-12-03 16:31:59 -08:00
|
|
|
epoch_schedule::{EpochSchedule, MINIMUM_SLOTS_PER_EPOCH},
|
2019-08-16 00:00:38 -07:00
|
|
|
hash::Hash,
|
|
|
|
poh_config::PohConfig,
|
|
|
|
pubkey::Pubkey,
|
2020-02-20 13:28:55 -08:00
|
|
|
signature::{Keypair, Signature, Signer},
|
2019-08-16 00:00:38 -07:00
|
|
|
system_transaction,
|
2019-09-06 14:30:56 -07:00
|
|
|
timing::duration_as_ms,
|
2019-08-16 00:00:38 -07:00
|
|
|
transport::TransportError,
|
2019-03-21 07:43:21 -07:00
|
|
|
};
|
2019-08-21 23:59:11 -07:00
|
|
|
use std::{
|
|
|
|
collections::{HashMap, HashSet},
|
|
|
|
path::Path,
|
|
|
|
thread::sleep,
|
2020-05-05 14:07:21 -07:00
|
|
|
time::{Duration, Instant},
|
2019-08-21 23:59:11 -07:00
|
|
|
};
|
2019-03-01 10:36:52 -08:00
|
|
|
|
2019-08-19 23:22:56 -07:00
|
|
|
const DEFAULT_SLOT_MILLIS: u64 = (DEFAULT_TICKS_PER_SLOT * 1000) / DEFAULT_TICKS_PER_SECOND;
|
2019-03-05 17:56:51 -08:00
|
|
|
|
2019-03-01 10:36:52 -08:00
|
|
|
/// Spend and verify from every node in the network
|
2019-06-19 00:13:19 -07:00
|
|
|
pub fn spend_and_verify_all_nodes<S: ::std::hash::BuildHasher>(
|
2019-03-01 10:36:52 -08:00
|
|
|
entry_point_info: &ContactInfo,
|
|
|
|
funding_keypair: &Keypair,
|
|
|
|
nodes: usize,
|
2019-06-19 00:13:19 -07:00
|
|
|
ignore_nodes: HashSet<Pubkey, S>,
|
2019-03-01 10:36:52 -08:00
|
|
|
) {
|
2020-05-14 18:22:47 -07:00
|
|
|
let cluster_nodes = discover_cluster(&entry_point_info.gossip, nodes).unwrap();
|
2019-03-01 10:36:52 -08:00
|
|
|
assert!(cluster_nodes.len() >= nodes);
|
|
|
|
for ingress_node in &cluster_nodes {
|
2019-06-19 00:13:19 -07:00
|
|
|
if ignore_nodes.contains(&ingress_node.id) {
|
|
|
|
continue;
|
|
|
|
}
|
2019-03-01 10:36:52 -08:00
|
|
|
let random_keypair = Keypair::new();
|
2019-10-10 16:33:00 -07:00
|
|
|
let client = create_client(ingress_node.client_facing_addr(), VALIDATOR_PORT_RANGE);
|
2019-03-01 10:36:52 -08:00
|
|
|
let bal = client
|
2019-11-06 13:15:00 -08:00
|
|
|
.poll_get_balance_with_commitment(&funding_keypair.pubkey(), CommitmentConfig::recent())
|
2019-03-01 10:36:52 -08:00
|
|
|
.expect("balance in source");
|
|
|
|
assert!(bal > 0);
|
2019-11-06 13:15:00 -08:00
|
|
|
let (blockhash, _fee_calculator) = client
|
|
|
|
.get_recent_blockhash_with_commitment(CommitmentConfig::recent())
|
|
|
|
.unwrap();
|
2019-05-20 10:03:19 -07:00
|
|
|
let mut transaction =
|
|
|
|
system_transaction::transfer(&funding_keypair, &random_keypair.pubkey(), 1, blockhash);
|
2019-03-21 07:43:21 -07:00
|
|
|
let confs = VOTE_THRESHOLD_DEPTH + 1;
|
2019-03-01 10:36:52 -08:00
|
|
|
let sig = client
|
2019-10-23 12:11:04 -07:00
|
|
|
.retry_transfer_until_confirmed(&funding_keypair, &mut transaction, 10, confs)
|
2019-03-01 10:36:52 -08:00
|
|
|
.unwrap();
|
|
|
|
for validator in &cluster_nodes {
|
2019-06-19 00:13:19 -07:00
|
|
|
if ignore_nodes.contains(&validator.id) {
|
|
|
|
continue;
|
|
|
|
}
|
2019-10-10 16:33:00 -07:00
|
|
|
let client = create_client(validator.client_facing_addr(), VALIDATOR_PORT_RANGE);
|
2019-03-21 07:43:21 -07:00
|
|
|
client.poll_for_signature_confirmation(&sig, confs).unwrap();
|
2019-03-01 10:36:52 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-03-03 22:01:09 -08:00
|
|
|
|
2019-08-21 23:59:11 -07:00
|
|
|
pub fn verify_balances<S: ::std::hash::BuildHasher>(
|
|
|
|
expected_balances: HashMap<Pubkey, u64, S>,
|
|
|
|
node: &ContactInfo,
|
|
|
|
) {
|
2019-10-10 16:33:00 -07:00
|
|
|
let client = create_client(node.client_facing_addr(), VALIDATOR_PORT_RANGE);
|
2019-08-21 23:59:11 -07:00
|
|
|
for (pk, b) in expected_balances {
|
2019-11-06 13:15:00 -08:00
|
|
|
let bal = client
|
|
|
|
.poll_get_balance_with_commitment(&pk, CommitmentConfig::recent())
|
|
|
|
.expect("balance in source");
|
2019-08-21 23:59:11 -07:00
|
|
|
assert_eq!(bal, b);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn send_many_transactions(
|
|
|
|
node: &ContactInfo,
|
|
|
|
funding_keypair: &Keypair,
|
|
|
|
max_tokens_per_transfer: u64,
|
|
|
|
num_txs: u64,
|
|
|
|
) -> HashMap<Pubkey, u64> {
|
2019-10-10 16:33:00 -07:00
|
|
|
let client = create_client(node.client_facing_addr(), VALIDATOR_PORT_RANGE);
|
2019-08-21 23:59:11 -07:00
|
|
|
let mut expected_balances = HashMap::new();
|
2019-03-09 16:25:38 -08:00
|
|
|
for _ in 0..num_txs {
|
|
|
|
let random_keypair = Keypair::new();
|
|
|
|
let bal = client
|
2019-11-06 13:15:00 -08:00
|
|
|
.poll_get_balance_with_commitment(&funding_keypair.pubkey(), CommitmentConfig::recent())
|
2019-03-09 16:25:38 -08:00
|
|
|
.expect("balance in source");
|
|
|
|
assert!(bal > 0);
|
2019-11-06 13:15:00 -08:00
|
|
|
let (blockhash, _fee_calculator) = client
|
|
|
|
.get_recent_blockhash_with_commitment(CommitmentConfig::recent())
|
|
|
|
.unwrap();
|
2019-08-21 23:59:11 -07:00
|
|
|
let transfer_amount = thread_rng().gen_range(1, max_tokens_per_transfer);
|
|
|
|
|
|
|
|
let mut transaction = system_transaction::transfer(
|
|
|
|
&funding_keypair,
|
|
|
|
&random_keypair.pubkey(),
|
|
|
|
transfer_amount,
|
|
|
|
blockhash,
|
|
|
|
);
|
|
|
|
|
2019-03-09 16:25:38 -08:00
|
|
|
client
|
|
|
|
.retry_transfer(&funding_keypair, &mut transaction, 5)
|
|
|
|
.unwrap();
|
2019-08-21 23:59:11 -07:00
|
|
|
|
|
|
|
expected_balances.insert(random_keypair.pubkey(), transfer_amount);
|
2019-03-09 16:25:38 -08:00
|
|
|
}
|
2019-08-21 23:59:11 -07:00
|
|
|
|
|
|
|
expected_balances
|
2019-03-09 16:25:38 -08:00
|
|
|
}
|
|
|
|
|
2019-10-11 12:30:52 -07:00
|
|
|
pub fn validator_exit(entry_point_info: &ContactInfo, nodes: usize) {
|
2020-05-14 18:22:47 -07:00
|
|
|
let cluster_nodes = discover_cluster(&entry_point_info.gossip, nodes).unwrap();
|
2019-03-03 22:01:09 -08:00
|
|
|
assert!(cluster_nodes.len() >= nodes);
|
|
|
|
for node in &cluster_nodes {
|
2019-10-10 16:33:00 -07:00
|
|
|
let client = create_client(node.client_facing_addr(), VALIDATOR_PORT_RANGE);
|
2019-10-11 12:30:52 -07:00
|
|
|
assert!(client.validator_exit().unwrap());
|
2019-03-03 22:01:09 -08:00
|
|
|
}
|
2019-05-18 14:01:36 -07:00
|
|
|
sleep(Duration::from_millis(DEFAULT_SLOT_MILLIS));
|
2019-03-03 22:01:09 -08:00
|
|
|
for node in &cluster_nodes {
|
2019-10-10 16:33:00 -07:00
|
|
|
let client = create_client(node.client_facing_addr(), VALIDATOR_PORT_RANGE);
|
2019-10-11 12:30:52 -07:00
|
|
|
assert!(client.validator_exit().is_err());
|
2019-03-03 22:01:09 -08:00
|
|
|
}
|
|
|
|
}
|
2019-03-05 17:56:51 -08:00
|
|
|
|
2019-07-30 15:53:41 -07:00
|
|
|
pub fn verify_ledger_ticks(ledger_path: &Path, ticks_per_slot: usize) {
|
2020-01-13 13:13:52 -08:00
|
|
|
let ledger = Blockstore::open(ledger_path).unwrap();
|
2020-04-09 13:09:59 -07:00
|
|
|
let zeroth_slot = ledger.get_slot_entries(0, 0).unwrap();
|
2019-03-07 15:49:07 -08:00
|
|
|
let last_id = zeroth_slot.last().unwrap().hash;
|
|
|
|
let next_slots = ledger.get_slots_since(&[0]).unwrap().remove(&0).unwrap();
|
|
|
|
let mut pending_slots: Vec<_> = next_slots
|
|
|
|
.into_iter()
|
|
|
|
.map(|slot| (slot, 0, last_id))
|
|
|
|
.collect();
|
|
|
|
while !pending_slots.is_empty() {
|
|
|
|
let (slot, parent_slot, last_id) = pending_slots.pop().unwrap();
|
|
|
|
let next_slots = ledger
|
|
|
|
.get_slots_since(&[slot])
|
|
|
|
.unwrap()
|
|
|
|
.remove(&slot)
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
// If you're not the last slot, you should have a full set of ticks
|
|
|
|
let should_verify_ticks = if !next_slots.is_empty() {
|
|
|
|
Some((slot - parent_slot) as usize * ticks_per_slot)
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
};
|
|
|
|
|
|
|
|
let last_id = verify_slot_ticks(&ledger, slot, &last_id, should_verify_ticks);
|
|
|
|
pending_slots.extend(
|
|
|
|
next_slots
|
|
|
|
.into_iter()
|
|
|
|
.map(|child_slot| (child_slot, slot, last_id)),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-03 16:31:59 -08:00
|
|
|
pub fn time_until_nth_epoch(epoch: u64, slots_per_epoch: u64, stakers_slot_offset: u64) -> u64 {
|
|
|
|
let epoch_schedule = EpochSchedule::custom(slots_per_epoch, stakers_slot_offset, true);
|
|
|
|
epoch_schedule.get_last_slot_in_epoch(epoch) * DEFAULT_MS_PER_SLOT
|
|
|
|
}
|
|
|
|
|
2019-03-23 19:19:55 -07:00
|
|
|
pub fn sleep_n_epochs(
|
|
|
|
num_epochs: f64,
|
2019-05-18 14:01:36 -07:00
|
|
|
config: &PohConfig,
|
2019-03-23 19:19:55 -07:00
|
|
|
ticks_per_slot: u64,
|
|
|
|
slots_per_epoch: u64,
|
|
|
|
) {
|
2019-05-18 14:01:36 -07:00
|
|
|
let num_ticks_per_second = (1000 / duration_as_ms(&config.target_tick_duration)) as f64;
|
2019-03-23 19:19:55 -07:00
|
|
|
let num_ticks_to_sleep = num_epochs * ticks_per_slot as f64 * slots_per_epoch as f64;
|
2019-05-18 14:01:36 -07:00
|
|
|
let secs = ((num_ticks_to_sleep + num_ticks_per_second - 1.0) / num_ticks_per_second) as u64;
|
|
|
|
warn!("sleep_n_epochs: {} seconds", secs);
|
|
|
|
sleep(Duration::from_secs(secs));
|
2019-03-23 19:19:55 -07:00
|
|
|
}
|
|
|
|
|
2019-03-05 17:56:51 -08:00
|
|
|
pub fn kill_entry_and_spend_and_verify_rest(
|
|
|
|
entry_point_info: &ContactInfo,
|
|
|
|
funding_keypair: &Keypair,
|
|
|
|
nodes: usize,
|
2019-04-29 15:26:52 -07:00
|
|
|
slot_millis: u64,
|
2019-03-05 17:56:51 -08:00
|
|
|
) {
|
|
|
|
solana_logger::setup();
|
2020-05-14 18:22:47 -07:00
|
|
|
let cluster_nodes = discover_cluster(&entry_point_info.gossip, nodes).unwrap();
|
2019-03-05 17:56:51 -08:00
|
|
|
assert!(cluster_nodes.len() >= nodes);
|
2019-10-10 16:33:00 -07:00
|
|
|
let client = create_client(entry_point_info.client_facing_addr(), VALIDATOR_PORT_RANGE);
|
2019-11-15 08:36:33 -08:00
|
|
|
// sleep long enough to make sure we are in epoch 3
|
|
|
|
let first_two_epoch_slots = MINIMUM_SLOTS_PER_EPOCH * (3 + 1);
|
2019-05-23 14:50:23 -07:00
|
|
|
|
|
|
|
for ingress_node in &cluster_nodes {
|
|
|
|
client
|
2019-11-06 13:15:00 -08:00
|
|
|
.poll_get_balance_with_commitment(&ingress_node.id, CommitmentConfig::recent())
|
2019-05-23 14:50:23 -07:00
|
|
|
.unwrap_or_else(|err| panic!("Node {} has no balance: {}", ingress_node.id, err));
|
|
|
|
}
|
|
|
|
|
2019-03-21 07:43:21 -07:00
|
|
|
info!("sleeping for 2 leader fortnights");
|
|
|
|
sleep(Duration::from_millis(
|
2019-04-29 15:26:52 -07:00
|
|
|
slot_millis * first_two_epoch_slots as u64,
|
2019-03-21 07:43:21 -07:00
|
|
|
));
|
2019-04-29 15:26:52 -07:00
|
|
|
info!("done sleeping for first 2 warmup epochs");
|
2019-05-23 14:50:23 -07:00
|
|
|
info!("killing entry point: {}", entry_point_info.id);
|
2019-10-11 12:30:52 -07:00
|
|
|
assert!(client.validator_exit().unwrap());
|
2019-04-29 15:26:52 -07:00
|
|
|
info!("sleeping for some time");
|
2019-03-21 07:43:21 -07:00
|
|
|
sleep(Duration::from_millis(
|
2019-04-29 15:26:52 -07:00
|
|
|
slot_millis * NUM_CONSECUTIVE_LEADER_SLOTS,
|
2019-03-21 07:43:21 -07:00
|
|
|
));
|
|
|
|
info!("done sleeping for 2 fortnights");
|
2019-03-05 17:56:51 -08:00
|
|
|
for ingress_node in &cluster_nodes {
|
|
|
|
if ingress_node.id == entry_point_info.id {
|
2019-08-16 15:46:19 -07:00
|
|
|
info!("ingress_node.id == entry_point_info.id, continuing...");
|
2019-03-05 17:56:51 -08:00
|
|
|
continue;
|
|
|
|
}
|
2019-03-12 13:48:02 -07:00
|
|
|
|
2019-10-10 16:33:00 -07:00
|
|
|
let client = create_client(ingress_node.client_facing_addr(), VALIDATOR_PORT_RANGE);
|
2019-05-23 14:50:23 -07:00
|
|
|
let balance = client
|
2019-11-06 13:15:00 -08:00
|
|
|
.poll_get_balance_with_commitment(&funding_keypair.pubkey(), CommitmentConfig::recent())
|
2019-03-05 17:56:51 -08:00
|
|
|
.expect("balance in source");
|
2019-05-23 14:50:23 -07:00
|
|
|
assert_ne!(balance, 0);
|
2019-03-12 13:48:02 -07:00
|
|
|
|
|
|
|
let mut result = Ok(());
|
|
|
|
let mut retries = 0;
|
|
|
|
loop {
|
|
|
|
retries += 1;
|
|
|
|
if retries > 5 {
|
|
|
|
result.unwrap();
|
|
|
|
}
|
|
|
|
|
|
|
|
let random_keypair = Keypair::new();
|
2019-11-06 13:15:00 -08:00
|
|
|
let (blockhash, _fee_calculator) = client
|
|
|
|
.get_recent_blockhash_with_commitment(CommitmentConfig::recent())
|
|
|
|
.unwrap();
|
2019-04-03 08:45:57 -07:00
|
|
|
let mut transaction = system_transaction::transfer(
|
2019-03-12 13:48:02 -07:00
|
|
|
&funding_keypair,
|
|
|
|
&random_keypair.pubkey(),
|
|
|
|
1,
|
2019-05-13 12:49:37 -07:00
|
|
|
blockhash,
|
2019-03-12 13:48:02 -07:00
|
|
|
);
|
|
|
|
|
2019-03-21 07:43:21 -07:00
|
|
|
let confs = VOTE_THRESHOLD_DEPTH + 1;
|
2019-03-12 13:48:02 -07:00
|
|
|
let sig = {
|
2019-03-21 07:43:21 -07:00
|
|
|
let sig = client.retry_transfer_until_confirmed(
|
|
|
|
&funding_keypair,
|
|
|
|
&mut transaction,
|
|
|
|
5,
|
|
|
|
confs,
|
|
|
|
);
|
|
|
|
match sig {
|
2019-03-12 13:48:02 -07:00
|
|
|
Err(e) => {
|
2020-03-12 23:20:49 -07:00
|
|
|
result = Err(e);
|
2019-03-12 13:48:02 -07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(sig) => sig,
|
|
|
|
}
|
|
|
|
};
|
2019-08-16 15:46:19 -07:00
|
|
|
info!("poll_all_nodes_for_signature()");
|
2019-03-21 07:43:21 -07:00
|
|
|
match poll_all_nodes_for_signature(&entry_point_info, &cluster_nodes, &sig, confs) {
|
2019-03-12 13:48:02 -07:00
|
|
|
Err(e) => {
|
2019-08-16 15:46:19 -07:00
|
|
|
info!("poll_all_nodes_for_signature() failed {:?}", e);
|
2019-03-12 13:48:02 -07:00
|
|
|
result = Err(e);
|
|
|
|
}
|
|
|
|
Ok(()) => {
|
2019-08-16 15:46:19 -07:00
|
|
|
info!("poll_all_nodes_for_signature() succeeded, done.");
|
2019-03-12 13:48:02 -07:00
|
|
|
break;
|
|
|
|
}
|
2019-03-05 17:56:51 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-03-07 15:49:07 -08:00
|
|
|
|
2020-06-04 23:32:53 -07:00
|
|
|
pub fn check_for_new_roots(num_new_roots: usize, contact_infos: &[ContactInfo], test_name: &str) {
|
2020-05-05 14:07:21 -07:00
|
|
|
let mut roots = vec![HashSet::new(); contact_infos.len()];
|
|
|
|
let mut done = false;
|
|
|
|
let mut last_print = Instant::now();
|
|
|
|
while !done {
|
|
|
|
for (i, ingress_node) in contact_infos.iter().enumerate() {
|
|
|
|
let client = create_client(ingress_node.client_facing_addr(), VALIDATOR_PORT_RANGE);
|
|
|
|
let slot = client.get_slot().unwrap_or(0);
|
|
|
|
roots[i].insert(slot);
|
|
|
|
let min_node = roots.iter().map(|r| r.len()).min().unwrap_or(0);
|
|
|
|
if last_print.elapsed().as_secs() > 3 {
|
2020-06-04 23:32:53 -07:00
|
|
|
info!("{} min observed roots {}/16", test_name, min_node);
|
2020-05-05 14:07:21 -07:00
|
|
|
last_print = Instant::now();
|
|
|
|
}
|
|
|
|
done = min_node >= num_new_roots;
|
|
|
|
}
|
|
|
|
sleep(Duration::from_millis(clock::DEFAULT_MS_PER_SLOT / 2));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-12 13:48:02 -07:00
|
|
|
fn poll_all_nodes_for_signature(
|
|
|
|
entry_point_info: &ContactInfo,
|
|
|
|
cluster_nodes: &[ContactInfo],
|
|
|
|
sig: &Signature,
|
2019-03-21 07:43:21 -07:00
|
|
|
confs: usize,
|
2019-04-25 12:46:40 -07:00
|
|
|
) -> Result<(), TransportError> {
|
2019-03-12 13:48:02 -07:00
|
|
|
for validator in cluster_nodes {
|
|
|
|
if validator.id == entry_point_info.id {
|
|
|
|
continue;
|
|
|
|
}
|
2019-10-10 16:33:00 -07:00
|
|
|
let client = create_client(validator.client_facing_addr(), VALIDATOR_PORT_RANGE);
|
2019-03-21 07:43:21 -07:00
|
|
|
client.poll_for_signature_confirmation(&sig, confs)?;
|
2019-03-12 13:48:02 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2020-01-13 13:13:52 -08:00
|
|
|
fn get_and_verify_slot_entries(
|
|
|
|
blockstore: &Blockstore,
|
|
|
|
slot: Slot,
|
|
|
|
last_entry: &Hash,
|
|
|
|
) -> Vec<Entry> {
|
2020-04-09 13:09:59 -07:00
|
|
|
let entries = blockstore.get_slot_entries(slot, 0).unwrap();
|
2019-12-23 23:26:27 -08:00
|
|
|
assert_eq!(entries.verify(last_entry), true);
|
2019-03-07 15:49:07 -08:00
|
|
|
entries
|
|
|
|
}
|
|
|
|
|
|
|
|
fn verify_slot_ticks(
|
2020-01-13 13:13:52 -08:00
|
|
|
blockstore: &Blockstore,
|
2019-11-02 00:38:30 -07:00
|
|
|
slot: Slot,
|
2019-03-07 15:49:07 -08:00
|
|
|
last_entry: &Hash,
|
|
|
|
expected_num_ticks: Option<usize>,
|
|
|
|
) -> Hash {
|
2020-01-13 13:13:52 -08:00
|
|
|
let entries = get_and_verify_slot_entries(blockstore, slot, last_entry);
|
2019-03-07 15:49:07 -08:00
|
|
|
let num_ticks: usize = entries.iter().map(|entry| entry.is_tick() as usize).sum();
|
|
|
|
if let Some(expected_num_ticks) = expected_num_ticks {
|
|
|
|
assert_eq!(num_ticks, expected_num_ticks);
|
|
|
|
}
|
|
|
|
entries.last().unwrap().hash
|
|
|
|
}
|