Skip to content

Commit

Permalink
Fixes suggested by @Erigara and @outoftardis
Browse files Browse the repository at this point in the history
Signed-off-by: Daniil Polyakov <arjentix@gmail.com>
  • Loading branch information
Arjentix committed Aug 8, 2022
1 parent d54bd05 commit 2e74385
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 19 deletions.
11 changes: 5 additions & 6 deletions core/src/queue.rs
Expand Up @@ -99,14 +99,13 @@ impl Queue {
if tx.is_in_blockchain(&self.wsv) {
return Err(Error::InBlockchain);
}

if *tx.check_signature_condition(&self.wsv)? {
Ok(())
} else {
Err(Error::SignatureCondition(eyre!(
if !*tx.check_signature_condition(&self.wsv)? {
return Err(Error::SignatureCondition(eyre!(
"Signature condition check failed"
)))
)));
}

Ok(())
}

/// Pushes transaction into queue.
Expand Down
6 changes: 2 additions & 4 deletions core/src/sumeragi/fault.rs
Expand Up @@ -3,6 +3,7 @@
//! used in code.

use iroha_config::sumeragi::Configuration;
use iroha_primitives::must_use::MustUse;

use super::*;

Expand Down Expand Up @@ -526,10 +527,7 @@ impl<G: GenesisNetworkTrait, F: FaultInjection> SumeragiWithFault<G, F> {
"Forwarding tx to leader"
);
// Don't require leader to submit receipts and therefore create blocks if the tx is still waiting for more signatures.
if matches!(
tx.check_signature_condition(&self.wsv),
Ok(must_use_bool) if *must_use_bool
) {
if let Ok(MustUse(true)) = tx.check_signature_condition(&self.wsv) {
self.txs_awaiting_receipts.insert(tx.hash(), Instant::now());
}
let no_tx_receipt = view_change::Proof::no_transaction_receipt_received(
Expand Down
9 changes: 2 additions & 7 deletions core/src/tx.rs
Expand Up @@ -181,13 +181,8 @@ impl TransactionValidator {
}

let option_reason = match tx.check_signature_condition(&self.wsv) {
Ok(must_use_bool) => {
if *must_use_bool {
None
} else {
Some("Signature condition not satisfied.".to_owned())
}
}
Ok(MustUse(true)) => None,
Ok(MustUse(false)) => Some("Signature condition not satisfied.".to_owned()),
Err(reason) => Some(reason.to_string()),
}
.map(|reason| UnsatisfiedSignatureConditionFail { reason })
Expand Down
2 changes: 1 addition & 1 deletion data_model/src/lib.rs
Expand Up @@ -399,7 +399,7 @@ impl IdentifiableBox {

/// Create a [`Vec`] containing the arguments, which should satisfy `Into<Value>` bound.
///
/// Syntax is the same as [`vec`](macro@vec)
/// Syntax is the same as in [`vec`](macro@vec)
#[macro_export]
macro_rules! val_vec {
() => { Vec::new() };
Expand Down
6 changes: 5 additions & 1 deletion primitives/src/must_use.rs
Expand Up @@ -44,23 +44,27 @@ use derive_more::{AsMut, AsRef, Constructor, Deref, Display};
AsMut,
Deref,
)]
#[repr(transparent)]
#[must_use]
pub struct MustUse<T>(T);
pub struct MustUse<T>(pub T);

impl<T> MustUse<T> {
/// Get inner value
#[inline]
pub fn into_inner(self) -> T {
self.0
}
}

impl<T> Borrow<T> for MustUse<T> {
#[inline]
fn borrow(&self) -> &T {
&self.0
}
}

impl<T> BorrowMut<T> for MustUse<T> {
#[inline]
fn borrow_mut(&mut self) -> &mut T {
&mut self.0
}
Expand Down

0 comments on commit 2e74385

Please sign in to comment.