split out files, fixed a bug @garious!

This commit is contained in:
Anatoly Yakovenko 2018-07-03 10:20:02 -07:00 committed by Greg Fitzgerald
parent 3a90f138b2
commit fa70b3bf70
3 changed files with 66 additions and 74 deletions

View File

@ -8,7 +8,7 @@ extern crate solana;
use atty::{is, Stream};
use getopts::Options;
use solana::crdt::{ReplicatedData, TestNode};
use solana::fullnode::{FullNode, LedgerFile};
use solana::fullnode::{FullNode, InFile, OutFile};
use std::env;
use std::fs::File;
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
@ -83,23 +83,16 @@ fn main() -> () {
let fullnode = if matches.opt_present("t") {
let testnet_address_string = matches.opt_str("t").unwrap();
let testnet_addr = testnet_address_string.parse().unwrap();
FullNode::new(
node,
false,
LedgerFile::StdIn,
Some(testnet_addr),
LedgerFile::NoFile,
exit,
)
FullNode::new(node, false, InFile::StdIn, Some(testnet_addr), None, exit)
} else {
node.data.current_leader_id = node.data.id.clone();
let outfile = if let Some(f) = matches.opt_str("o") {
LedgerFile::Path(f)
OutFile::Path(f)
} else {
LedgerFile::StdIn
OutFile::StdOut
};
FullNode::new(node, true, LedgerFile::StdIn, None, outfile, exit)
FullNode::new(node, true, InFile::StdIn, None, Some(outfile), exit)
};
for t in fullnode.thread_hdls {
t.join().expect("join");

View File

@ -23,11 +23,13 @@ pub struct FullNode {
pub thread_hdls: Vec<JoinHandle<()>>,
}
pub enum LedgerFile {
NoFile,
pub enum InFile {
StdIn,
Path(String),
}
pub enum OutFile {
StdOut,
Sink,
Path(String),
}
@ -35,15 +37,15 @@ impl FullNode {
pub fn new(
mut node: TestNode,
leader: bool,
infile: LedgerFile,
infile: InFile,
network_entry_for_validator: Option<SocketAddr>,
outfile_for_leader: LedgerFile,
outfile_for_leader: Option<OutFile>,
exit: Arc<AtomicBool>,
) -> FullNode {
info!("creating bank...");
let bank = Bank::default();
let entry_height = match infile {
LedgerFile::Path(path) => {
InFile::Path(path) => {
let f = File::open(path).unwrap();
let mut r = BufReader::new(f);
let entries =
@ -51,14 +53,13 @@ impl FullNode {
info!("processing ledger...");
bank.process_ledger(entries).expect("process_ledger")
}
LedgerFile::StdIn => {
InFile::StdIn => {
let mut r = BufReader::new(stdin());
let entries =
entry_writer::read_entries(&mut r).map(|e| e.expect("failed to parse entry"));
info!("processing ledger...");
bank.process_ledger(entries).expect("process_ledger")
}
_ => panic!("expected LedgerFile::StdIn or LedgerFile::Path for infile"),
};
// entry_height is the network-wide agreed height of the ledger.
@ -92,43 +93,41 @@ impl FullNode {
server
} else {
node.data.current_leader_id = node.data.id.clone();
let server =
match outfile_for_leader {
LedgerFile::Path(file) => {
FullNode::new_leader(
bank,
entry_height,
//Some(Duration::from_millis(1000)),
None,
node,
exit.clone(),
File::create(file).expect("opening ledger file"),
)
},
LedgerFile::StdOut => {
FullNode::new_leader(
bank,
entry_height,
//Some(Duration::from_millis(1000)),
None,
node,
exit.clone(),
stdout(),
)
},
LedgerFile::Sink => {
FullNode::new_leader(
bank,
entry_height,
//Some(Duration::from_millis(1000)),
None,
node,
exit.clone(),
sink(),
)
},
_ => panic!("expected LedgerFile::StdOut, LedgerFile::Path, or LedgerFile::Sink, for infile"),
};
let server = match outfile_for_leader {
Some(OutFile::Path(file)) => {
FullNode::new_leader(
bank,
entry_height,
//Some(Duration::from_millis(1000)),
None,
node,
exit.clone(),
File::create(file).expect("opening ledger file"),
)
}
Some(OutFile::StdOut) => {
FullNode::new_leader(
bank,
entry_height,
//Some(Duration::from_millis(1000)),
None,
node,
exit.clone(),
stdout(),
)
}
None => {
FullNode::new_leader(
bank,
entry_height,
//Some(Duration::from_millis(1000)),
None,
node,
exit.clone(),
sink(),
)
}
};
info!(
"leader ready... local request address: {} (advertising {})",
local_requests_addr, requests_addr

View File

@ -7,7 +7,7 @@ extern crate solana;
use solana::crdt::TestNode;
use solana::crdt::{Crdt, ReplicatedData};
use solana::entry_writer::EntryWriter;
use solana::fullnode::{FullNode, LedgerFile};
use solana::fullnode::{FullNode, InFile};
use solana::logger;
use solana::mint::Mint;
use solana::ncp::Ncp;
@ -98,9 +98,9 @@ fn test_multi_node_validator_catchup_from_zero() {
let server = FullNode::new(
leader,
true,
LedgerFile::Path(ledger_path.clone()),
InFile::Path(ledger_path.clone()),
None,
None,
LedgerFile::Sink,
exit.clone(),
);
let mut threads = server.thread_hdls;
@ -109,9 +109,9 @@ fn test_multi_node_validator_catchup_from_zero() {
let mut val = FullNode::new(
validator,
false,
LedgerFile::Path(ledger_path.clone()),
InFile::Path(ledger_path.clone()),
Some(leader_data.gossip_addr),
LedgerFile::NoFile,
None,
exit.clone(),
);
threads.append(&mut val.thread_hdls);
@ -142,9 +142,9 @@ fn test_multi_node_validator_catchup_from_zero() {
let mut val = FullNode::new(
TestNode::new(),
false,
LedgerFile::Path(ledger_path.clone()),
InFile::Path(ledger_path.clone()),
Some(leader_data.gossip_addr),
LedgerFile::NoFile,
None,
exit.clone(),
);
threads.append(&mut val.thread_hdls);
@ -199,9 +199,9 @@ fn test_multi_node_basic() {
let server = FullNode::new(
leader,
true,
LedgerFile::Path(ledger_path.clone()),
InFile::Path(ledger_path.clone()),
None,
None,
LedgerFile::Sink,
exit.clone(),
);
let threads = server.thread_hdls;
@ -210,9 +210,9 @@ fn test_multi_node_basic() {
FullNode::new(
validator,
false,
LedgerFile::Path(ledger_path.clone()),
InFile::Path(ledger_path.clone()),
Some(leader_data.gossip_addr),
LedgerFile::NoFile,
None,
exit.clone(),
);
}
@ -255,9 +255,9 @@ fn test_multi_node_dynamic_network() {
let server = FullNode::new(
leader,
true,
LedgerFile::Path(ledger_path.clone()),
InFile::Path(ledger_path.clone()),
None,
None,
LedgerFile::Sink,
exit.clone(),
);
let threads = server.thread_hdls;
@ -277,9 +277,9 @@ fn test_multi_node_dynamic_network() {
let val = FullNode::new(
validator,
false,
LedgerFile::Path(ledger_path.clone()),
InFile::Path(ledger_path.clone()),
Some(leader_data.gossip_addr),
LedgerFile::NoFile,
None,
exit.clone(),
);
(rd, exit, val)
@ -323,9 +323,9 @@ fn test_multi_node_dynamic_network() {
let val = FullNode::new(
validator,
false,
LedgerFile::Path(ledger_path.clone()),
InFile::Path(ledger_path.clone()),
Some(leader_data.gossip_addr),
LedgerFile::NoFile,
None,
exit.clone(),
);
info!("{:x} ADDED", rd.debug_id());