Cleanup: field names should be nouns
This commit is contained in:
parent
ebc458cd32
commit
f2d4799491
|
@ -66,22 +66,22 @@ mod tests {
|
||||||
// Entry OR if the verifier tries to parallelize across multiple Entries.
|
// Entry OR if the verifier tries to parallelize across multiple Entries.
|
||||||
let mint = Mint::new(2);
|
let mint = Mint::new(2);
|
||||||
let acc = Accountant::new(&mint);
|
let acc = Accountant::new(&mint);
|
||||||
let stage = AccountingStage::new(acc, &mint.last_id(), None);
|
let accounting_stage = AccountingStage::new(acc, &mint.last_id(), None);
|
||||||
|
|
||||||
// Process a batch that includes a transaction that receives two tokens.
|
// Process a batch that includes a transaction that receives two tokens.
|
||||||
let alice = KeyPair::new();
|
let alice = KeyPair::new();
|
||||||
let tr = Transaction::new(&mint.keypair(), alice.pubkey(), 2, mint.last_id());
|
let tr = Transaction::new(&mint.keypair(), alice.pubkey(), 2, mint.last_id());
|
||||||
let events = vec![Event::Transaction(tr)];
|
let events = vec![Event::Transaction(tr)];
|
||||||
assert!(stage.process_events(events).is_ok());
|
assert!(accounting_stage.process_events(events).is_ok());
|
||||||
|
|
||||||
// Process a second batch that spends one of those tokens.
|
// Process a second batch that spends one of those tokens.
|
||||||
let tr = Transaction::new(&alice, mint.pubkey(), 1, mint.last_id());
|
let tr = Transaction::new(&alice, mint.pubkey(), 1, mint.last_id());
|
||||||
let events = vec![Event::Transaction(tr)];
|
let events = vec![Event::Transaction(tr)];
|
||||||
assert!(stage.process_events(events).is_ok());
|
assert!(accounting_stage.process_events(events).is_ok());
|
||||||
|
|
||||||
// Collect the ledger and feed it to a new accountant.
|
// Collect the ledger and feed it to a new accountant.
|
||||||
drop(stage.entry_sender);
|
drop(accounting_stage.entry_sender);
|
||||||
let entries: Vec<Entry> = stage.output.lock().unwrap().iter().collect();
|
let entries: Vec<Entry> = accounting_stage.output.lock().unwrap().iter().collect();
|
||||||
|
|
||||||
// Assert the user holds one token, not two. If the server only output one
|
// Assert the user holds one token, not two. If the server only output one
|
||||||
// entry, then the second transaction will be rejected, because it drives
|
// entry, then the second transaction will be rejected, because it drives
|
||||||
|
@ -156,17 +156,17 @@ mod bench {
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let (input, event_receiver) = channel();
|
let (input, event_receiver) = channel();
|
||||||
let stage = AccountingStage::new(acc, &mint.last_id(), None);
|
let accounting_stage = AccountingStage::new(acc, &mint.last_id(), None);
|
||||||
|
|
||||||
let now = Instant::now();
|
let now = Instant::now();
|
||||||
assert!(stage.process_events(events).is_ok());
|
assert!(accounting_stage.process_events(events).is_ok());
|
||||||
let duration = now.elapsed();
|
let duration = now.elapsed();
|
||||||
let sec = duration.as_secs() as f64 + duration.subsec_nanos() as f64 / 1_000_000_000.0;
|
let sec = duration.as_secs() as f64 + duration.subsec_nanos() as f64 / 1_000_000_000.0;
|
||||||
let tps = txs as f64 / sec;
|
let tps = txs as f64 / sec;
|
||||||
|
|
||||||
// Ensure that all transactions were successfully logged.
|
// Ensure that all transactions were successfully logged.
|
||||||
drop(stage.historian_input);
|
drop(accounting_stage.historian_input);
|
||||||
let entries: Vec<Entry> = stage.output.lock().unwrap().iter().collect();
|
let entries: Vec<Entry> = accounting_stage.output.lock().unwrap().iter().collect();
|
||||||
assert_eq!(entries.len(), 1);
|
assert_eq!(entries.len(), 1);
|
||||||
assert_eq!(entries[0].events.len(), txs as usize);
|
assert_eq!(entries[0].events.len(), txs as usize);
|
||||||
|
|
||||||
|
|
|
@ -115,9 +115,9 @@ fn main() {
|
||||||
|
|
||||||
eprintln!("creating networking stack...");
|
eprintln!("creating networking stack...");
|
||||||
|
|
||||||
let accounting = AccountingStage::new(acc, &last_id, Some(1000));
|
let accounting_stage = AccountingStage::new(acc, &last_id, Some(1000));
|
||||||
let exit = Arc::new(AtomicBool::new(false));
|
let exit = Arc::new(AtomicBool::new(false));
|
||||||
let tpu = Arc::new(Tpu::new(accounting));
|
let tpu = Arc::new(Tpu::new(accounting_stage));
|
||||||
let serve_sock = UdpSocket::bind(&serve_addr).unwrap();
|
let serve_sock = UdpSocket::bind(&serve_addr).unwrap();
|
||||||
let gossip_sock = UdpSocket::bind(&gossip_addr).unwrap();
|
let gossip_sock = UdpSocket::bind(&gossip_addr).unwrap();
|
||||||
let replicate_sock = UdpSocket::bind(&replicate_addr).unwrap();
|
let replicate_sock = UdpSocket::bind(&replicate_addr).unwrap();
|
||||||
|
|
|
@ -182,8 +182,8 @@ mod tests {
|
||||||
let acc = Accountant::new(&alice);
|
let acc = Accountant::new(&alice);
|
||||||
let bob_pubkey = KeyPair::new().pubkey();
|
let bob_pubkey = KeyPair::new().pubkey();
|
||||||
let exit = Arc::new(AtomicBool::new(false));
|
let exit = Arc::new(AtomicBool::new(false));
|
||||||
let accounting = AccountingStage::new(acc, &alice.last_id(), Some(30));
|
let accounting_stage = AccountingStage::new(acc, &alice.last_id(), Some(30));
|
||||||
let acc = Arc::new(Tpu::new(accounting));
|
let acc = Arc::new(Tpu::new(accounting_stage));
|
||||||
let threads = Tpu::serve(&acc, d, serve, skinny, gossip, exit.clone(), sink()).unwrap();
|
let threads = Tpu::serve(&acc, d, serve, skinny, gossip, exit.clone(), sink()).unwrap();
|
||||||
sleep(Duration::from_millis(300));
|
sleep(Duration::from_millis(300));
|
||||||
|
|
||||||
|
@ -218,8 +218,8 @@ mod tests {
|
||||||
let acc = Accountant::new(&alice);
|
let acc = Accountant::new(&alice);
|
||||||
let bob_pubkey = KeyPair::new().pubkey();
|
let bob_pubkey = KeyPair::new().pubkey();
|
||||||
let exit = Arc::new(AtomicBool::new(false));
|
let exit = Arc::new(AtomicBool::new(false));
|
||||||
let accounting = AccountingStage::new(acc, &alice.last_id(), Some(30));
|
let accounting_stage = AccountingStage::new(acc, &alice.last_id(), Some(30));
|
||||||
let tpu = Arc::new(Tpu::new(accounting));
|
let tpu = Arc::new(Tpu::new(accounting_stage));
|
||||||
let serve_addr = leader_serve.local_addr().unwrap();
|
let serve_addr = leader_serve.local_addr().unwrap();
|
||||||
let threads = Tpu::serve(
|
let threads = Tpu::serve(
|
||||||
&tpu,
|
&tpu,
|
||||||
|
@ -287,14 +287,14 @@ mod tests {
|
||||||
|
|
||||||
let leader_acc = {
|
let leader_acc = {
|
||||||
let acc = Accountant::new(&alice);
|
let acc = Accountant::new(&alice);
|
||||||
let accounting = AccountingStage::new(acc, &alice.last_id(), Some(30));
|
let accounting_stage = AccountingStage::new(acc, &alice.last_id(), Some(30));
|
||||||
Arc::new(Tpu::new(accounting))
|
Arc::new(Tpu::new(accounting_stage))
|
||||||
};
|
};
|
||||||
|
|
||||||
let replicant_acc = {
|
let replicant_acc = {
|
||||||
let acc = Accountant::new(&alice);
|
let acc = Accountant::new(&alice);
|
||||||
let accounting = AccountingStage::new(acc, &alice.last_id(), Some(30));
|
let accounting_stage = AccountingStage::new(acc, &alice.last_id(), Some(30));
|
||||||
Arc::new(Tpu::new(accounting))
|
Arc::new(Tpu::new(accounting_stage))
|
||||||
};
|
};
|
||||||
|
|
||||||
let leader_threads = Tpu::serve(
|
let leader_threads = Tpu::serve(
|
||||||
|
|
29
src/tpu.rs
29
src/tpu.rs
|
@ -30,7 +30,7 @@ use thin_client_service::{Request, Response, ThinClientService};
|
||||||
use timing;
|
use timing;
|
||||||
|
|
||||||
pub struct Tpu {
|
pub struct Tpu {
|
||||||
accounting: AccountingStage,
|
accounting_stage: AccountingStage,
|
||||||
thin_client_service: ThinClientService,
|
thin_client_service: ThinClientService,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,17 +38,17 @@ type SharedTpu = Arc<Tpu>;
|
||||||
|
|
||||||
impl Tpu {
|
impl Tpu {
|
||||||
/// Create a new Tpu that wraps the given Accountant.
|
/// Create a new Tpu that wraps the given Accountant.
|
||||||
pub fn new(accounting: AccountingStage) -> Self {
|
pub fn new(accounting_stage: AccountingStage) -> Self {
|
||||||
let thin_client_service = ThinClientService::new(accounting.acc.clone());
|
let thin_client_service = ThinClientService::new(accounting_stage.acc.clone());
|
||||||
Tpu {
|
Tpu {
|
||||||
accounting,
|
accounting_stage,
|
||||||
thin_client_service,
|
thin_client_service,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_entry<W: Write>(obj: &Tpu, writer: &Mutex<W>, entry: &Entry) {
|
fn update_entry<W: Write>(obj: &Tpu, writer: &Mutex<W>, entry: &Entry) {
|
||||||
trace!("update_entry entry");
|
trace!("update_entry entry");
|
||||||
obj.accounting.acc.register_entry_id(&entry.id);
|
obj.accounting_stage.acc.register_entry_id(&entry.id);
|
||||||
writeln!(
|
writeln!(
|
||||||
writer.lock().unwrap(),
|
writer.lock().unwrap(),
|
||||||
"{}",
|
"{}",
|
||||||
|
@ -61,14 +61,14 @@ impl Tpu {
|
||||||
fn receive_all<W: Write>(obj: &Tpu, writer: &Mutex<W>) -> Result<Vec<Entry>> {
|
fn receive_all<W: Write>(obj: &Tpu, writer: &Mutex<W>) -> Result<Vec<Entry>> {
|
||||||
//TODO implement a serialize for channel that does this without allocations
|
//TODO implement a serialize for channel that does this without allocations
|
||||||
let mut l = vec![];
|
let mut l = vec![];
|
||||||
let entry = obj.accounting
|
let entry = obj.accounting_stage
|
||||||
.output
|
.output
|
||||||
.lock()
|
.lock()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.recv_timeout(Duration::new(1, 0))?;
|
.recv_timeout(Duration::new(1, 0))?;
|
||||||
Self::update_entry(obj, writer, &entry);
|
Self::update_entry(obj, writer, &entry);
|
||||||
l.push(entry);
|
l.push(entry);
|
||||||
while let Ok(entry) = obj.accounting.output.lock().unwrap().try_recv() {
|
while let Ok(entry) = obj.accounting_stage.output.lock().unwrap().try_recv() {
|
||||||
Self::update_entry(obj, writer, &entry);
|
Self::update_entry(obj, writer, &entry);
|
||||||
l.push(entry);
|
l.push(entry);
|
||||||
}
|
}
|
||||||
|
@ -338,7 +338,7 @@ impl Tpu {
|
||||||
debug!("events: {} reqs: {}", events.len(), reqs.len());
|
debug!("events: {} reqs: {}", events.len(), reqs.len());
|
||||||
|
|
||||||
debug!("process_events");
|
debug!("process_events");
|
||||||
obj.accounting.process_events(events)?;
|
obj.accounting_stage.process_events(events)?;
|
||||||
debug!("done process_events");
|
debug!("done process_events");
|
||||||
|
|
||||||
debug!("process_requests");
|
debug!("process_requests");
|
||||||
|
@ -378,7 +378,7 @@ impl Tpu {
|
||||||
for msgs in &blobs {
|
for msgs in &blobs {
|
||||||
let blob = msgs.read().unwrap();
|
let blob = msgs.read().unwrap();
|
||||||
let entries: Vec<Entry> = deserialize(&blob.data()[..blob.meta.size]).unwrap();
|
let entries: Vec<Entry> = deserialize(&blob.data()[..blob.meta.size]).unwrap();
|
||||||
let acc = &obj.accounting.acc;
|
let acc = &obj.accounting_stage.acc;
|
||||||
for entry in entries {
|
for entry in entries {
|
||||||
acc.register_entry_id(&entry.id);
|
acc.register_entry_id(&entry.id);
|
||||||
for result in acc.process_verified_events(entry.events) {
|
for result in acc.process_verified_events(entry.events) {
|
||||||
|
@ -463,7 +463,8 @@ impl Tpu {
|
||||||
Mutex::new(writer),
|
Mutex::new(writer),
|
||||||
);
|
);
|
||||||
|
|
||||||
let t_skinny = Self::thin_client_service(obj.accounting.acc.clone(), exit.clone(), skinny);
|
let t_skinny =
|
||||||
|
Self::thin_client_service(obj.accounting_stage.acc.clone(), exit.clone(), skinny);
|
||||||
|
|
||||||
let tpu = obj.clone();
|
let tpu = obj.clone();
|
||||||
let t_server = spawn(move || loop {
|
let t_server = spawn(move || loop {
|
||||||
|
@ -787,8 +788,8 @@ mod tests {
|
||||||
let starting_balance = 10_000;
|
let starting_balance = 10_000;
|
||||||
let alice = Mint::new(starting_balance);
|
let alice = Mint::new(starting_balance);
|
||||||
let acc = Accountant::new(&alice);
|
let acc = Accountant::new(&alice);
|
||||||
let accounting = AccountingStage::new(acc, &alice.last_id(), Some(30));
|
let accounting_stage = AccountingStage::new(acc, &alice.last_id(), Some(30));
|
||||||
let tpu = Arc::new(Tpu::new(accounting));
|
let tpu = Arc::new(Tpu::new(accounting_stage));
|
||||||
let replicate_addr = target1_data.replicate_addr;
|
let replicate_addr = target1_data.replicate_addr;
|
||||||
let threads = Tpu::replicate(
|
let threads = Tpu::replicate(
|
||||||
&tpu,
|
&tpu,
|
||||||
|
@ -813,7 +814,7 @@ mod tests {
|
||||||
w.set_index(i).unwrap();
|
w.set_index(i).unwrap();
|
||||||
w.set_id(leader_id).unwrap();
|
w.set_id(leader_id).unwrap();
|
||||||
|
|
||||||
let acc = &tpu.accounting.acc;
|
let acc = &tpu.accounting_stage.acc;
|
||||||
|
|
||||||
let tr0 = Event::new_timestamp(&bob_keypair, Utc::now());
|
let tr0 = Event::new_timestamp(&bob_keypair, Utc::now());
|
||||||
let entry0 = entry::create_entry(&cur_hash, i, vec![tr0]);
|
let entry0 = entry::create_entry(&cur_hash, i, vec![tr0]);
|
||||||
|
@ -855,7 +856,7 @@ mod tests {
|
||||||
msgs.push(msg);
|
msgs.push(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
let acc = &tpu.accounting.acc;
|
let acc = &tpu.accounting_stage.acc;
|
||||||
let alice_balance = acc.get_balance(&alice.keypair().pubkey()).unwrap();
|
let alice_balance = acc.get_balance(&alice.keypair().pubkey()).unwrap();
|
||||||
assert_eq!(alice_balance, alice_ref_balance);
|
assert_eq!(alice_balance, alice_ref_balance);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue