Clippy review
This commit is contained in:
@ -127,7 +127,7 @@ impl Accountant {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let mut plan = tr.plan.clone();
|
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() {
|
if plan.is_complete() {
|
||||||
complete_transaction(&mut self.balances, &plan);
|
complete_transaction(&mut self.balances, &plan);
|
||||||
@ -140,7 +140,7 @@ impl Accountant {
|
|||||||
|
|
||||||
fn process_verified_sig(&mut self, from: PublicKey, tx_sig: Signature) -> Result<()> {
|
fn process_verified_sig(&mut self, from: PublicKey, tx_sig: Signature) -> Result<()> {
|
||||||
if let Occupied(mut e) = self.pending.entry(tx_sig) {
|
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() {
|
if e.get().is_complete() {
|
||||||
complete_transaction(&mut self.balances, e.get());
|
complete_transaction(&mut self.balances, e.get());
|
||||||
e.remove_entry();
|
e.remove_entry();
|
||||||
@ -168,7 +168,7 @@ impl Accountant {
|
|||||||
// Check to see if any timelocked transactions can be completed.
|
// Check to see if any timelocked transactions can be completed.
|
||||||
let mut completed = vec![];
|
let mut completed = vec![];
|
||||||
for (key, plan) in &mut self.pending {
|
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() {
|
if plan.is_complete() {
|
||||||
complete_transaction(&mut self.balances, plan);
|
complete_transaction(&mut self.balances, plan);
|
||||||
completed.push(key.clone());
|
completed.push(key.clone());
|
||||||
|
@ -92,13 +92,13 @@ impl AccountantSkel {
|
|||||||
&mut self,
|
&mut self,
|
||||||
r_reader: &streamer::Receiver,
|
r_reader: &streamer::Receiver,
|
||||||
s_sender: &streamer::Sender,
|
s_sender: &streamer::Sender,
|
||||||
recycler: streamer::Recycler,
|
recycler: &streamer::Recycler,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let timer = Duration::new(1, 0);
|
let timer = Duration::new(1, 0);
|
||||||
let msgs = r_reader.recv_timeout(timer)?;
|
let msgs = r_reader.recv_timeout(timer)?;
|
||||||
let msgs_ = msgs.clone();
|
let msgs_ = msgs.clone();
|
||||||
let msgs__ = msgs.clone();
|
let msgs__ = msgs.clone();
|
||||||
let rsps = streamer::allocate(&recycler);
|
let rsps = streamer::allocate(recycler);
|
||||||
let rsps_ = rsps.clone();
|
let rsps_ = rsps.clone();
|
||||||
let l = msgs__.read().unwrap().packets.len();
|
let l = msgs__.read().unwrap().packets.len();
|
||||||
rsps.write()
|
rsps.write()
|
||||||
@ -124,7 +124,7 @@ impl AccountantSkel {
|
|||||||
ursps.packets.resize(num, streamer::Packet::default());
|
ursps.packets.resize(num, streamer::Packet::default());
|
||||||
}
|
}
|
||||||
s_sender.send(rsps_)?;
|
s_sender.send(rsps_)?;
|
||||||
streamer::recycle(&recycler, msgs_);
|
streamer::recycle(recycler, msgs_);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -150,9 +150,7 @@ impl AccountantSkel {
|
|||||||
let t_server = spawn(move || {
|
let t_server = spawn(move || {
|
||||||
if let Ok(me) = Arc::try_unwrap(obj) {
|
if let Ok(me) = Arc::try_unwrap(obj) {
|
||||||
loop {
|
loop {
|
||||||
let e = me.lock()
|
let e = me.lock().unwrap().process(&r_reader, &s_sender, &recycler);
|
||||||
.unwrap()
|
|
||||||
.process(&r_reader, &s_sender, recycler.clone());
|
|
||||||
if e.is_err() && exit.load(Ordering::Relaxed) {
|
if e.is_err() && exit.load(Ordering::Relaxed) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
//! The `ledger` crate provides the foundational data structures for Proof-of-History,
|
//! The `ledger` crate provides the foundational data structures for Proof-of-History,
|
||||||
//! an ordered log of events in time.
|
//! an ordered log of events in time.
|
||||||
|
|
||||||
/// Each entry contains three pieces of data. The 'num_hashes' field is the number
|
/// 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 hashes performed since the previous entry. The `id` field is the result
|
||||||
/// of hashing 'id' from the previous entry 'num_hashes' times. The 'event'
|
/// 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.
|
/// 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
|
/// 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
|
/// Though processing power varies across nodes, the network gives priority to the
|
||||||
/// fastest processor. Duration should therefore be estimated by assuming that the hash
|
/// 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.
|
/// 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))
|
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> {
|
pub fn next_ticks(start_hash: &Hash, num_hashes: u64, len: usize) -> Vec<Entry> {
|
||||||
let mut id = *start_hash;
|
let mut id = *start_hash;
|
||||||
let mut ticks = vec![];
|
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 {
|
pub fn verify(&self, spendable_tokens: i64) -> bool {
|
||||||
match *self {
|
match *self {
|
||||||
Plan::Pay(ref payment) => payment.tokens == spendable_tokens,
|
Plan::Pay(ref payment) | Plan::After(_, ref payment) => {
|
||||||
Plan::After(_, ref payment) => payment.tokens == spendable_tokens,
|
payment.tokens == spendable_tokens
|
||||||
|
}
|
||||||
Plan::Race(ref a, ref b) => {
|
Plan::Race(ref a, ref b) => {
|
||||||
a.1.tokens == spendable_tokens && b.1.tokens == spendable_tokens
|
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.
|
/// Apply a witness to the spending plan to see if the plan can be reduced.
|
||||||
/// If so, modify the plan in-place.
|
/// 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 {
|
let new_payment = match *self {
|
||||||
Plan::After(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),
|
||||||
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,
|
_ => None,
|
||||||
}.map(|x| x.clone());
|
}.cloned();
|
||||||
|
|
||||||
if let Some(payment) = new_payment {
|
if let Some(payment) = new_payment {
|
||||||
mem::replace(self, Plan::Pay(payment));
|
mem::replace(self, Plan::Pay(payment));
|
||||||
@ -135,7 +136,7 @@ mod tests {
|
|||||||
let to = PublicKey::default();
|
let to = PublicKey::default();
|
||||||
|
|
||||||
let mut plan = Plan::new_authorized_payment(from, 42, to);
|
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));
|
assert_eq!(plan, Plan::new_payment(42, to));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,7 +146,7 @@ mod tests {
|
|||||||
let to = PublicKey::default();
|
let to = PublicKey::default();
|
||||||
|
|
||||||
let mut plan = Plan::new_future_payment(dt, 42, to);
|
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));
|
assert_eq!(plan, Plan::new_payment(42, to));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -156,11 +157,11 @@ mod tests {
|
|||||||
let to = PublicKey::default();
|
let to = PublicKey::default();
|
||||||
|
|
||||||
let mut plan = Plan::new_cancelable_future_payment(dt, from, 42, to);
|
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));
|
assert_eq!(plan, Plan::new_payment(42, to));
|
||||||
|
|
||||||
let mut plan = Plan::new_cancelable_future_payment(dt, from, 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));
|
assert_eq!(plan, Plan::new_payment(42, from));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user