Centralize unwrap() within create_new_tmp_ledger!
This commit is contained in:
parent
88ecce12a2
commit
84bd9296cd
|
@ -38,7 +38,7 @@ fn nominal() {
|
|||
let (genesis_block, _mint_keypair) = GenesisBlock::new_with_leader(100, keypair.pubkey(), 50);
|
||||
let ticks_per_slot = genesis_block.ticks_per_slot;
|
||||
|
||||
let (ledger_path, _last_id) = create_new_tmp_ledger!(&genesis_block).unwrap();
|
||||
let (ledger_path, _last_id) = create_new_tmp_ledger!(&genesis_block);
|
||||
let ticks = ticks_per_slot as usize;
|
||||
|
||||
// Basic validation
|
||||
|
|
|
@ -1314,9 +1314,10 @@ macro_rules! create_new_tmp_ledger {
|
|||
//
|
||||
// Note: like `create_new_ledger` the returned ledger will have slot 0 full of ticks (and only
|
||||
// ticks)
|
||||
pub fn create_new_tmp_ledger(name: &str, genesis_block: &GenesisBlock) -> Result<(String, Hash)> {
|
||||
pub fn create_new_tmp_ledger(name: &str, genesis_block: &GenesisBlock) -> (String, Hash) {
|
||||
let ledger_path = get_tmp_ledger_path(name);
|
||||
create_new_ledger(&ledger_path, genesis_block).and_then(|last_id| Ok((ledger_path, last_id)))
|
||||
let last_id = create_new_ledger(&ledger_path, genesis_block).unwrap();
|
||||
(ledger_path, last_id)
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
|
|
|
@ -270,7 +270,7 @@ mod tests {
|
|||
*/
|
||||
|
||||
// Create a new ledger with slot 0 full of ticks
|
||||
let (ledger_path, mut last_id) = create_new_tmp_ledger!(&genesis_block).unwrap();
|
||||
let (ledger_path, mut last_id) = create_new_tmp_ledger!(&genesis_block);
|
||||
debug!("ledger_path: {:?}", ledger_path);
|
||||
|
||||
let blocktree = Blocktree::open_config(&ledger_path, ticks_per_slot)
|
||||
|
@ -319,7 +319,7 @@ mod tests {
|
|||
let ticks_per_slot = genesis_block.ticks_per_slot;
|
||||
|
||||
// Create a new ledger with slot 0 full of ticks
|
||||
let (ledger_path, last_id) = create_new_tmp_ledger!(&genesis_block).unwrap();
|
||||
let (ledger_path, last_id) = create_new_tmp_ledger!(&genesis_block);
|
||||
debug!("ledger_path: {:?}", ledger_path);
|
||||
let mut last_entry_id = last_id;
|
||||
|
||||
|
@ -445,7 +445,7 @@ mod tests {
|
|||
fn test_process_ledger_simple() {
|
||||
let leader_pubkey = Keypair::new().pubkey();
|
||||
let (genesis_block, mint_keypair) = GenesisBlock::new_with_leader(100, leader_pubkey, 50);
|
||||
let (ledger_path, last_id) = create_new_tmp_ledger!(&genesis_block).unwrap();
|
||||
let (ledger_path, last_id) = create_new_tmp_ledger!(&genesis_block);
|
||||
debug!("ledger_path: {:?}", ledger_path);
|
||||
|
||||
let mut entries = vec![];
|
||||
|
|
|
@ -501,7 +501,7 @@ mod tests {
|
|||
let validator_node = Node::new_localhost_with_pubkey(validator_keypair.pubkey());
|
||||
let (genesis_block, _mint_keypair) =
|
||||
GenesisBlock::new_with_leader(10_000, leader_keypair.pubkey(), 1000);
|
||||
let (validator_ledger_path, _last_id) = create_new_tmp_ledger!(&genesis_block).unwrap();
|
||||
let (validator_ledger_path, _last_id) = create_new_tmp_ledger!(&genesis_block);
|
||||
|
||||
let validator = Fullnode::new(
|
||||
validator_node,
|
||||
|
@ -522,16 +522,12 @@ mod tests {
|
|||
|
||||
let mut ledger_paths = vec![];
|
||||
let validators: Vec<Fullnode> = (0..2)
|
||||
.map(|i| {
|
||||
.map(|_| {
|
||||
let validator_keypair = Keypair::new();
|
||||
let validator_node = Node::new_localhost_with_pubkey(validator_keypair.pubkey());
|
||||
let (genesis_block, _mint_keypair) =
|
||||
GenesisBlock::new_with_leader(10_000, leader_keypair.pubkey(), 1000);
|
||||
let (validator_ledger_path, _last_id) = create_new_tmp_ledger(
|
||||
&format!("validator_parallel_exit_{}", i),
|
||||
&genesis_block,
|
||||
)
|
||||
.unwrap();
|
||||
let (validator_ledger_path, _last_id) = create_new_tmp_ledger!(&genesis_block);
|
||||
ledger_paths.push(validator_ledger_path.clone());
|
||||
Fullnode::new(
|
||||
validator_node,
|
||||
|
@ -579,8 +575,7 @@ mod tests {
|
|||
genesis_block.ticks_per_slot = ticks_per_slot;
|
||||
genesis_block.slots_per_epoch = slots_per_epoch;
|
||||
|
||||
let (bootstrap_leader_ledger_path, _last_id) =
|
||||
create_new_tmp_ledger!(&genesis_block).unwrap();
|
||||
let (bootstrap_leader_ledger_path, _last_id) = create_new_tmp_ledger!(&genesis_block);
|
||||
|
||||
// Start the bootstrap leader
|
||||
let bootstrap_leader = Fullnode::new(
|
||||
|
@ -788,7 +783,7 @@ mod tests {
|
|||
GenesisBlock::new_with_leader(10_000, leader_node.info.id, 500);
|
||||
genesis_block.ticks_per_slot = ticks_per_slot;
|
||||
|
||||
let (ledger_path, last_id) = create_new_tmp_ledger(test_name, &genesis_block).unwrap();
|
||||
let (ledger_path, last_id) = create_new_tmp_ledger!(&genesis_block);
|
||||
|
||||
// Add entries so that the validator is in the active set, then finish up the slot with
|
||||
// ticks (and maybe add extra slots full of empty ticks)
|
||||
|
|
|
@ -489,7 +489,7 @@ mod test {
|
|||
|
||||
let (genesis_block, _mint_keypair) = GenesisBlock::new_with_leader(10_000, leader_id, 500);
|
||||
|
||||
let (my_ledger_path, _last_id) = create_new_tmp_ledger!(&genesis_block).unwrap();
|
||||
let (my_ledger_path, _last_id) = create_new_tmp_ledger!(&genesis_block);
|
||||
|
||||
// Set up the cluster info
|
||||
let cluster_info_me = Arc::new(RwLock::new(ClusterInfo::new(my_node.info.clone())));
|
||||
|
|
|
@ -509,7 +509,7 @@ mod tests {
|
|||
|
||||
let (genesis_block, _mint_keypair) = GenesisBlock::new(1000);
|
||||
let ticks_per_slot = genesis_block.ticks_per_slot;
|
||||
let (ledger_path, _last_id) = create_new_tmp_ledger!(&genesis_block).unwrap();
|
||||
let (ledger_path, _last_id) = create_new_tmp_ledger!(&genesis_block);
|
||||
|
||||
let entries = make_tiny_test_entries(64);
|
||||
let blocktree = Blocktree::open_config(&ledger_path, ticks_per_slot).unwrap();
|
||||
|
@ -572,7 +572,7 @@ mod tests {
|
|||
|
||||
let (genesis_block, _mint_keypair) = GenesisBlock::new(1000);
|
||||
let ticks_per_slot = genesis_block.ticks_per_slot;;
|
||||
let (ledger_path, _last_id) = create_new_tmp_ledger!(&genesis_block).unwrap();
|
||||
let (ledger_path, _last_id) = create_new_tmp_ledger!(&genesis_block);
|
||||
|
||||
let entries = make_tiny_test_entries(128);
|
||||
let blocktree = Blocktree::open_config(&ledger_path, ticks_per_slot).unwrap();
|
||||
|
|
|
@ -469,7 +469,7 @@ pub fn new_fullnode() -> (Fullnode, NodeInfo, Keypair, String) {
|
|||
let node_info = node.info.clone();
|
||||
|
||||
let (genesis_block, mint_keypair) = GenesisBlock::new_with_leader(10_000, node_info.id, 42);
|
||||
let (ledger_path, _last_id) = create_new_tmp_ledger!(&genesis_block).unwrap();
|
||||
let (ledger_path, _last_id) = create_new_tmp_ledger!(&genesis_block);
|
||||
|
||||
let vote_account_keypair = Arc::new(Keypair::new());
|
||||
let voting_keypair = VotingKeypair::new_local(&vote_account_keypair);
|
||||
|
|
|
@ -52,7 +52,7 @@ fn test_multi_node_ledger_window() -> result::Result<()> {
|
|||
let ticks_per_slot = genesis_block.ticks_per_slot;
|
||||
info!("ticks_per_slot: {}", ticks_per_slot);
|
||||
|
||||
let (leader_ledger_path, last_id) = create_new_tmp_ledger!(&genesis_block).unwrap();
|
||||
let (leader_ledger_path, last_id) = create_new_tmp_ledger!(&genesis_block);
|
||||
ledger_paths.push(leader_ledger_path.clone());
|
||||
|
||||
// make a copy at zero
|
||||
|
@ -152,7 +152,7 @@ fn test_multi_node_validator_catchup_from_zero() -> result::Result<()> {
|
|||
let mut ledger_paths = Vec::new();
|
||||
|
||||
let (genesis_block, alice) = GenesisBlock::new_with_leader(10_000, leader_data.id, 500);
|
||||
let (genesis_ledger_path, _last_id) = create_new_tmp_ledger!(&genesis_block).unwrap();
|
||||
let (genesis_ledger_path, _last_id) = create_new_tmp_ledger!(&genesis_block);
|
||||
ledger_paths.push(genesis_ledger_path.clone());
|
||||
|
||||
let zero_ledger_path = tmp_copy_blocktree!(&genesis_ledger_path);
|
||||
|
@ -328,7 +328,7 @@ fn test_multi_node_basic() {
|
|||
|
||||
let (genesis_block, alice) = GenesisBlock::new_with_leader(10_000, leader_data.id, 500);
|
||||
|
||||
let (genesis_ledger_path, _last_id) = create_new_tmp_ledger!(&genesis_block).unwrap();
|
||||
let (genesis_ledger_path, _last_id) = create_new_tmp_ledger!(&genesis_block);
|
||||
ledger_paths.push(genesis_ledger_path.clone());
|
||||
|
||||
let leader_ledger_path = tmp_copy_blocktree!(&genesis_ledger_path);
|
||||
|
@ -429,7 +429,7 @@ fn test_boot_validator_from_file() {
|
|||
let mut ledger_paths = Vec::new();
|
||||
|
||||
let (genesis_block, alice) = GenesisBlock::new_with_leader(100_000, leader_pubkey, 1000);
|
||||
let (genesis_ledger_path, _last_id) = create_new_tmp_ledger!(&genesis_block).unwrap();
|
||||
let (genesis_ledger_path, _last_id) = create_new_tmp_ledger!(&genesis_block);
|
||||
ledger_paths.push(genesis_ledger_path.clone());
|
||||
|
||||
let leader_ledger_path = tmp_copy_blocktree!(&genesis_ledger_path);
|
||||
|
@ -541,11 +541,7 @@ fn test_leader_restart_validator_start_from_old_ledger() -> result::Result<()> {
|
|||
leader_keypair.pubkey(),
|
||||
initial_leader_balance,
|
||||
);
|
||||
let (ledger_path, _last_id) = create_new_tmp_ledger(
|
||||
"leader_restart_validator_start_from_old_ledger",
|
||||
&genesis_block,
|
||||
)
|
||||
.unwrap();
|
||||
let (ledger_path, _last_id) = create_new_tmp_ledger!(&genesis_block);
|
||||
|
||||
let bob_pubkey = Keypair::new().pubkey();
|
||||
|
||||
|
@ -653,7 +649,7 @@ fn test_multi_node_dynamic_network() {
|
|||
let bob_pubkey = Keypair::new().pubkey();
|
||||
|
||||
let (genesis_block, alice) = GenesisBlock::new_with_leader(10_000_000, leader_pubkey, 500);
|
||||
let (genesis_ledger_path, _last_id) = create_new_tmp_ledger!(&genesis_block).unwrap();
|
||||
let (genesis_ledger_path, _last_id) = create_new_tmp_ledger!(&genesis_block);
|
||||
|
||||
let mut ledger_paths = Vec::new();
|
||||
ledger_paths.push(genesis_ledger_path.clone());
|
||||
|
@ -866,7 +862,7 @@ fn test_leader_to_validator_transition() {
|
|||
|
||||
// Initialize the leader ledger. Make a mint and a genesis entry
|
||||
// in the leader ledger
|
||||
let (leader_ledger_path, last_id) = create_new_tmp_ledger!(&genesis_block).unwrap();
|
||||
let (leader_ledger_path, last_id) = create_new_tmp_ledger!(&genesis_block);
|
||||
|
||||
// Write the votes entries to the ledger that will cause leader rotation
|
||||
// to validator_keypair at slot 2
|
||||
|
@ -946,7 +942,7 @@ fn test_leader_validator_basic() {
|
|||
genesis_block.ticks_per_slot = ticks_per_slot;
|
||||
|
||||
// Make a common mint and a genesis entry for both leader + validator ledgers
|
||||
let (leader_ledger_path, last_id) = create_new_tmp_ledger!(&genesis_block).unwrap();
|
||||
let (leader_ledger_path, last_id) = create_new_tmp_ledger!(&genesis_block);
|
||||
|
||||
// Add validator vote on tick height 1
|
||||
{
|
||||
|
@ -1078,7 +1074,7 @@ fn test_dropped_handoff_recovery() {
|
|||
genesis_block.ticks_per_slot = ticks_per_slot;
|
||||
|
||||
// Make a common mint and a genesis entry for both leader + validator's ledgers
|
||||
let (genesis_ledger_path, last_id) = create_new_tmp_ledger!(&genesis_block).unwrap();
|
||||
let (genesis_ledger_path, last_id) = create_new_tmp_ledger!(&genesis_block);
|
||||
|
||||
// Create the validator keypair that will be the next leader in line
|
||||
let next_leader_keypair = Arc::new(Keypair::new());
|
||||
|
@ -1227,8 +1223,7 @@ fn test_full_leader_validator_network() {
|
|||
genesis_block.ticks_per_slot = ticks_per_slot;
|
||||
|
||||
// Make a common mint and a genesis entry for both leader + validator's ledgers
|
||||
let (bootstrap_leader_ledger_path, mut last_id) =
|
||||
create_new_tmp_ledger!(&genesis_block).unwrap();
|
||||
let (bootstrap_leader_ledger_path, mut last_id) = create_new_tmp_ledger!(&genesis_block);
|
||||
|
||||
// Create a common ledger with entries in the beginnging that will add all the validators
|
||||
// to the active set for leader election.
|
||||
|
@ -1416,7 +1411,7 @@ fn test_broadcast_last_tick() {
|
|||
genesis_block.ticks_per_slot = ticks_per_slot;
|
||||
|
||||
// Create leader ledger
|
||||
let (bootstrap_leader_ledger_path, _last_id) = create_new_tmp_ledger!(&genesis_block).unwrap();
|
||||
let (bootstrap_leader_ledger_path, _last_id) = create_new_tmp_ledger!(&genesis_block);
|
||||
|
||||
let blob_receiver_exit = Arc::new(AtomicBool::new(false));
|
||||
|
||||
|
@ -1608,7 +1603,7 @@ fn test_fullnode_rotate(
|
|||
genesis_block.slots_per_epoch = slots_per_epoch;
|
||||
|
||||
// Make a common mint and a genesis entry for both leader + validator ledgers
|
||||
let (leader_ledger_path, mut last_id) = create_new_tmp_ledger!(&genesis_block).unwrap();
|
||||
let (leader_ledger_path, mut last_id) = create_new_tmp_ledger!(&genesis_block);
|
||||
|
||||
let mut ledger_paths = Vec::new();
|
||||
ledger_paths.push(leader_ledger_path.clone());
|
||||
|
|
|
@ -42,13 +42,9 @@ fn test_replicator_startup_basic() {
|
|||
let leader_node = Node::new_localhost_with_pubkey(leader_keypair.pubkey());
|
||||
let leader_info = leader_node.info.clone();
|
||||
|
||||
let leader_ledger_path = "replicator_test_leader_ledger";
|
||||
|
||||
let (genesis_block, mint_keypair) =
|
||||
GenesisBlock::new_with_leader(1_000_000_000, leader_info.id, 42);
|
||||
|
||||
let (leader_ledger_path, _last_id) =
|
||||
create_new_tmp_ledger(leader_ledger_path, &genesis_block).unwrap();
|
||||
let (leader_ledger_path, _last_id) = create_new_tmp_ledger!(&genesis_block);
|
||||
|
||||
let validator_ledger_path = tmp_copy_blocktree!(&leader_ledger_path);
|
||||
|
||||
|
@ -279,17 +275,13 @@ fn test_replicator_startup_ledger_hang() {
|
|||
|
||||
let (genesis_block, _mint_keypair) =
|
||||
GenesisBlock::new_with_leader(100, leader_keypair.pubkey(), 42);
|
||||
let (replicator_test_replicator_ledger, _last_id) =
|
||||
create_new_tmp_ledger("replicator_test_replicator_ledger", &genesis_block).unwrap();
|
||||
let (replicator_test_replicator_ledger, _last_id) = create_new_tmp_ledger!(&genesis_block);
|
||||
|
||||
info!("starting leader node");
|
||||
let leader_node = Node::new_localhost_with_pubkey(leader_keypair.pubkey());
|
||||
let leader_info = leader_node.info.clone();
|
||||
|
||||
let leader_ledger_path = "replicator_test_leader_ledger";
|
||||
let (leader_ledger_path, _last_id) =
|
||||
create_new_tmp_ledger(leader_ledger_path, &genesis_block).unwrap();
|
||||
|
||||
let (leader_ledger_path, _last_id) = create_new_tmp_ledger!(&genesis_block);
|
||||
let validator_ledger_path = tmp_copy_blocktree!(&leader_ledger_path);
|
||||
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue