Clippy review
This commit is contained in:
parent
fad7ff8bf0
commit
60524ad5f2
|
@ -127,7 +127,7 @@ impl Accountant {
|
|||
}
|
||||
|
||||
let mut plan = tr.plan.clone();
|
||||
plan.apply_witness(Witness::Timestamp(self.last_time));
|
||||
plan.apply_witness(&Witness::Timestamp(self.last_time));
|
||||
|
||||
if plan.is_complete() {
|
||||
complete_transaction(&mut self.balances, &plan);
|
||||
|
@ -140,7 +140,7 @@ impl Accountant {
|
|||
|
||||
fn process_verified_sig(&mut self, from: PublicKey, tx_sig: Signature) -> Result<()> {
|
||||
if let Occupied(mut e) = self.pending.entry(tx_sig) {
|
||||
e.get_mut().apply_witness(Witness::Signature(from));
|
||||
e.get_mut().apply_witness(&Witness::Signature(from));
|
||||
if e.get().is_complete() {
|
||||
complete_transaction(&mut self.balances, e.get());
|
||||
e.remove_entry();
|
||||
|
@ -168,7 +168,7 @@ impl Accountant {
|
|||
// Check to see if any timelocked transactions can be completed.
|
||||
let mut completed = vec![];
|
||||
for (key, plan) in &mut self.pending {
|
||||
plan.apply_witness(Witness::Timestamp(self.last_time));
|
||||
plan.apply_witness(&Witness::Timestamp(self.last_time));
|
||||
if plan.is_complete() {
|
||||
complete_transaction(&mut self.balances, plan);
|
||||
completed.push(key.clone());
|
||||
|
|
|
@ -92,13 +92,13 @@ impl AccountantSkel {
|
|||
&mut self,
|
||||
r_reader: &streamer::Receiver,
|
||||
s_sender: &streamer::Sender,
|
||||
recycler: streamer::Recycler,
|
||||
recycler: &streamer::Recycler,
|
||||
) -> Result<()> {
|
||||
let timer = Duration::new(1, 0);
|
||||
let msgs = r_reader.recv_timeout(timer)?;
|
||||
let msgs_ = msgs.clone();
|
||||
let msgs__ = msgs.clone();
|
||||
let rsps = streamer::allocate(&recycler);
|
||||
let rsps = streamer::allocate(recycler);
|
||||
let rsps_ = rsps.clone();
|
||||
let l = msgs__.read().unwrap().packets.len();
|
||||
rsps.write()
|
||||
|
@ -124,7 +124,7 @@ impl AccountantSkel {
|
|||
ursps.packets.resize(num, streamer::Packet::default());
|
||||
}
|
||||
s_sender.send(rsps_)?;
|
||||
streamer::recycle(&recycler, msgs_);
|
||||
streamer::recycle(recycler, msgs_);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -150,9 +150,7 @@ impl AccountantSkel {
|
|||
let t_server = spawn(move || {
|
||||
if let Ok(me) = Arc::try_unwrap(obj) {
|
||||
loop {
|
||||
let e = me.lock()
|
||||
.unwrap()
|
||||
.process(&r_reader, &s_sender, recycler.clone());
|
||||
let e = me.lock().unwrap().process(&r_reader, &s_sender, &recycler);
|
||||
if e.is_err() && exit.load(Ordering::Relaxed) {
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
//! The `ledger` crate provides the foundational data structures for Proof-of-History,
|
||||
//! an ordered log of events in time.
|
||||
|
||||
/// Each entry contains three pieces of data. The 'num_hashes' field is the number
|
||||
/// of hashes performed since the previous entry. The 'id' field is the result
|
||||
/// of hashing 'id' from the previous entry 'num_hashes' times. The 'event'
|
||||
/// field points to an Event that took place shortly after 'id' was generated.
|
||||
/// Each entry contains three pieces of data. The `num_hashes` field is the number
|
||||
/// of hashes performed since the previous entry. The `id` field is the result
|
||||
/// of hashing `id` from the previous entry `num_hashes` times. The `event`
|
||||
/// field points to an Event that took place shortly after `id` was generated.
|
||||
///
|
||||
/// If you divide 'num_hashes' by the amount of time it takes to generate a new hash, you
|
||||
/// If you divide `num_hashes` by the amount of time it takes to generate a new hash, you
|
||||
/// get a duration estimate since the last event. Since processing power increases
|
||||
/// over time, one should expect the duration 'num_hashes' represents to decrease proportionally.
|
||||
/// over time, one should expect the duration `num_hashes` represents to decrease proportionally.
|
||||
/// Though processing power varies across nodes, the network gives priority to the
|
||||
/// fastest processor. Duration should therefore be estimated by assuming that the hash
|
||||
/// was generated by the fastest processor at the time the entry was recorded.
|
||||
|
@ -24,7 +24,7 @@ pub fn verify_slice(entries: &[Entry], start_hash: &Hash) -> bool {
|
|||
event_pairs.all(|(x0, x1)| x1.verify(&x0.id))
|
||||
}
|
||||
|
||||
/// Create a vector of Ticks of length 'len' from 'start_hash' hash and 'num_hashes'.
|
||||
/// Create a vector of Ticks of length `len` from `start_hash` hash and `num_hashes`.
|
||||
pub fn next_ticks(start_hash: &Hash, num_hashes: u64, len: usize) -> Vec<Entry> {
|
||||
let mut id = *start_hash;
|
||||
let mut ticks = vec![];
|
||||
|
|
23
src/plan.rs
23
src/plan.rs
|
@ -75,8 +75,9 @@ impl Plan {
|
|||
|
||||
pub fn verify(&self, spendable_tokens: i64) -> bool {
|
||||
match *self {
|
||||
Plan::Pay(ref payment) => payment.tokens == spendable_tokens,
|
||||
Plan::After(_, ref payment) => payment.tokens == spendable_tokens,
|
||||
Plan::Pay(ref payment) | Plan::After(_, ref payment) => {
|
||||
payment.tokens == spendable_tokens
|
||||
}
|
||||
Plan::Race(ref a, ref b) => {
|
||||
a.1.tokens == spendable_tokens && b.1.tokens == spendable_tokens
|
||||
}
|
||||
|
@ -85,13 +86,13 @@ impl Plan {
|
|||
|
||||
/// Apply a witness to the spending plan to see if the plan can be reduced.
|
||||
/// If so, modify the plan in-place.
|
||||
pub fn apply_witness(&mut self, witness: Witness) {
|
||||
pub fn apply_witness(&mut self, witness: &Witness) {
|
||||
let new_payment = match *self {
|
||||
Plan::After(ref cond, ref payment) if cond.is_satisfied(&witness) => Some(payment),
|
||||
Plan::Race((ref cond, ref payment), _) if cond.is_satisfied(&witness) => Some(payment),
|
||||
Plan::Race(_, (ref cond, ref payment)) if cond.is_satisfied(&witness) => Some(payment),
|
||||
Plan::After(ref cond, ref payment) if cond.is_satisfied(witness) => Some(payment),
|
||||
Plan::Race((ref cond, ref payment), _) if cond.is_satisfied(witness) => Some(payment),
|
||||
Plan::Race(_, (ref cond, ref payment)) if cond.is_satisfied(witness) => Some(payment),
|
||||
_ => None,
|
||||
}.map(|x| x.clone());
|
||||
}.cloned();
|
||||
|
||||
if let Some(payment) = new_payment {
|
||||
mem::replace(self, Plan::Pay(payment));
|
||||
|
@ -135,7 +136,7 @@ mod tests {
|
|||
let to = PublicKey::default();
|
||||
|
||||
let mut plan = Plan::new_authorized_payment(from, 42, to);
|
||||
plan.apply_witness(Witness::Signature(from));
|
||||
plan.apply_witness(&Witness::Signature(from));
|
||||
assert_eq!(plan, Plan::new_payment(42, to));
|
||||
}
|
||||
|
||||
|
@ -145,7 +146,7 @@ mod tests {
|
|||
let to = PublicKey::default();
|
||||
|
||||
let mut plan = Plan::new_future_payment(dt, 42, to);
|
||||
plan.apply_witness(Witness::Timestamp(dt));
|
||||
plan.apply_witness(&Witness::Timestamp(dt));
|
||||
assert_eq!(plan, Plan::new_payment(42, to));
|
||||
}
|
||||
|
||||
|
@ -156,11 +157,11 @@ mod tests {
|
|||
let to = PublicKey::default();
|
||||
|
||||
let mut plan = Plan::new_cancelable_future_payment(dt, from, 42, to);
|
||||
plan.apply_witness(Witness::Timestamp(dt));
|
||||
plan.apply_witness(&Witness::Timestamp(dt));
|
||||
assert_eq!(plan, Plan::new_payment(42, to));
|
||||
|
||||
let mut plan = Plan::new_cancelable_future_payment(dt, from, 42, to);
|
||||
plan.apply_witness(Witness::Signature(from));
|
||||
plan.apply_witness(&Witness::Signature(from));
|
||||
assert_eq!(plan, Plan::new_payment(42, from));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue