Skip to content

Commit

Permalink
groom Fullnode's new_with_bank() to match new() more
Browse files Browse the repository at this point in the history
  • Loading branch information
rob-solana committed Sep 12, 2018
1 parent a8fdb8a commit b522300
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 39 deletions.
8 changes: 1 addition & 7 deletions src/drone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,12 +163,9 @@ mod tests {
use logger;
use mint::Mint;
use netutil::get_ip_addr;
use service::Service;
use signature::{Keypair, KeypairUtil};
use std::fs::remove_dir_all;
use std::net::{SocketAddr, UdpSocket};
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use std::time::Duration;
use thin_client::ThinClient;

Expand Down Expand Up @@ -262,7 +259,6 @@ mod tests {
let bank = Bank::new(&alice);
let bob_pubkey = Keypair::new().pubkey();
let carlos_pubkey = Keypair::new().pubkey();
let exit = Arc::new(AtomicBool::new(false));
let leader_data = leader.info.clone();
let ledger_path = tmp_ledger_path("send_airdrop");

Expand All @@ -273,7 +269,6 @@ mod tests {
&[],
leader,
None,
exit.clone(),
Some(&ledger_path),
false,
);
Expand Down Expand Up @@ -307,8 +302,7 @@ mod tests {
assert!(client.poll_for_signature(&bob_sig).is_ok());

// restart the leader, drone should find the new one at the same gossip port
exit.store(true, Ordering::Relaxed);
server.join().unwrap();
server.close().unwrap();

let leader_keypair = Keypair::new();
let leader = Node::new_localhost_with_pubkey(leader_keypair.pubkey());
Expand Down
20 changes: 7 additions & 13 deletions src/fullnode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ impl Fullnode {

let entries = read_ledger(ledger_path, true).expect("opening ledger");

let entries = entries.map(|e| e.expect("failed to parse entry"));
let entries = entries
.map(|e| e.unwrap_or_else(|err| panic!("failed to parse entry. error: {}", err)));

info!("processing ledger...");
let (entry_height, ledger_tail) = bank.process_ledger(entries).expect("process_ledger");
Expand All @@ -76,7 +77,7 @@ impl Fullnode {
"starting... local gossip address: {} (advertising {})",
local_gossip_addr, node.info.contact_info.ncp
);
let exit = Arc::new(AtomicBool::new(false));

let local_requests_addr = node.sockets.requests.local_addr().unwrap();
let requests_addr = node.info.contact_info.rpu;
let leader_info = leader_addr.map(|i| NodeInfo::new_entry_point(&i));
Expand All @@ -87,7 +88,6 @@ impl Fullnode {
&ledger_tail,
node,
leader_info.as_ref(),
exit,
Some(ledger_path),
sigverify_disabled,
);
Expand Down Expand Up @@ -167,14 +167,13 @@ impl Fullnode {
ledger_tail: &[Entry],
mut node: Node,
leader_info: Option<&NodeInfo>,
exit: Arc<AtomicBool>,
ledger_path: Option<&str>,
sigverify_disabled: bool,
) -> Self {
if leader_info.is_none() {
node.info.leader_id = node.info.id;
}

let exit = Arc::new(AtomicBool::new(false));
let bank = Arc::new(bank);
let blob_recycler = BlobRecycler::default();
let mut thread_hdls = vec![];
Expand Down Expand Up @@ -303,20 +302,16 @@ mod tests {
use mint::Mint;
use service::Service;
use signature::{Keypair, KeypairUtil};
use std::sync::atomic::AtomicBool;
use std::sync::Arc;

#[test]
fn validator_exit() {
let keypair = Keypair::new();
let tn = Node::new_localhost_with_pubkey(keypair.pubkey());
let alice = Mint::new(10_000);
let bank = Bank::new(&alice);
let exit = Arc::new(AtomicBool::new(false));
let entry = tn.info.clone();
let v = Fullnode::new_with_bank(keypair, bank, 0, &[], tn, Some(&entry), exit, None, false);
v.exit();
v.join().unwrap();
let v = Fullnode::new_with_bank(keypair, bank, 0, &[], tn, Some(&entry), None, false);
v.close().unwrap();
}
#[test]
fn validator_parallel_exit() {
Expand All @@ -326,9 +321,8 @@ mod tests {
let tn = Node::new_localhost_with_pubkey(keypair.pubkey());
let alice = Mint::new(10_000);
let bank = Bank::new(&alice);
let exit = Arc::new(AtomicBool::new(false));
let entry = tn.info.clone();
Fullnode::new_with_bank(keypair, bank, 0, &[], tn, Some(&entry), exit, None, false)
Fullnode::new_with_bank(keypair, bank, 0, &[], tn, Some(&entry), None, false)
})
.collect();
//each validator can exit in parallel to speed many sequential calls to `join`
Expand Down
23 changes: 4 additions & 19 deletions src/thin_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -438,11 +438,8 @@ mod tests {
use ledger::LedgerWriter;
use logger;
use mint::Mint;
use service::Service;
use signature::{Keypair, KeypairUtil};
use std::fs::remove_dir_all;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Arc;
use transaction::{Instruction, Plan};

fn tmp_ledger(name: &str, mint: &Mint) -> String {
Expand All @@ -468,7 +465,6 @@ mod tests {
let alice = Mint::new(10_000);
let bank = Bank::new(&alice);
let bob_pubkey = Keypair::new().pubkey();
let exit = Arc::new(AtomicBool::new(false));
let ledger_path = tmp_ledger("thin_client", &alice);

let server = Fullnode::new_with_bank(
Expand All @@ -478,7 +474,6 @@ mod tests {
&[],
leader,
None,
exit.clone(),
Some(&ledger_path),
false,
);
Expand All @@ -500,8 +495,7 @@ mod tests {
client.poll_for_signature(&signature).unwrap();
let balance = client.get_balance(&bob_pubkey);
assert_eq!(balance.unwrap(), 500);
exit.store(true, Ordering::Relaxed);
server.join().unwrap();
server.close().unwrap();
remove_dir_all(ledger_path).unwrap();
}

Expand All @@ -515,7 +509,6 @@ mod tests {
let alice = Mint::new(10_000);
let bank = Bank::new(&alice);
let bob_pubkey = Keypair::new().pubkey();
let exit = Arc::new(AtomicBool::new(false));
let leader_data = leader.info.clone();
let ledger_path = tmp_ledger("bad_sig", &alice);

Expand All @@ -526,7 +519,6 @@ mod tests {
&[],
leader,
None,
exit.clone(),
Some(&ledger_path),
false,
);
Expand Down Expand Up @@ -564,8 +556,7 @@ mod tests {

let balance = client.get_balance(&bob_pubkey);
assert_eq!(balance.unwrap(), 500);
exit.store(true, Ordering::Relaxed);
server.join().unwrap();
server.close().unwrap();
remove_dir_all(ledger_path).unwrap();
}

Expand All @@ -577,7 +568,6 @@ mod tests {
let alice = Mint::new(10_000);
let bank = Bank::new(&alice);
let bob_pubkey = Keypair::new().pubkey();
let exit = Arc::new(AtomicBool::new(false));
let leader_data = leader.info.clone();
let ledger_path = tmp_ledger("client_check_signature", &alice);

Expand All @@ -588,7 +578,6 @@ mod tests {
&[],
leader,
None,
exit.clone(),
Some(&ledger_path),
false,
);
Expand All @@ -613,8 +602,7 @@ mod tests {

assert!(client.check_signature(&signature));

exit.store(true, Ordering::Relaxed);
server.join().unwrap();
server.close().unwrap();
remove_dir_all(ledger_path).unwrap();
}

Expand All @@ -640,7 +628,6 @@ mod tests {
let alice = Mint::new(10_000);
let bank = Bank::new(&alice);
let bob_keypair = Keypair::new();
let exit = Arc::new(AtomicBool::new(false));
let leader_data = leader.info.clone();
let ledger_path = tmp_ledger("zero_balance_check", &alice);

Expand All @@ -651,7 +638,6 @@ mod tests {
&[],
leader,
None,
exit.clone(),
Some(&ledger_path),
false,
);
Expand Down Expand Up @@ -690,8 +676,7 @@ mod tests {
let balance = client.poll_get_balance(&bob_keypair.pubkey());
assert!(balance.is_err());

exit.store(true, Ordering::Relaxed);
server.join().unwrap();
server.close().unwrap();
remove_dir_all(ledger_path).unwrap();
}
}

0 comments on commit b522300

Please sign in to comment.