Skip to content

Commit

Permalink
[refactor] #2478: Add SignedTransaction
Browse files Browse the repository at this point in the history
Signed-off-by: Shanin Roman <[email protected]>
  • Loading branch information
Erigara committed Sep 15, 2022
1 parent 194a3b2 commit e9563bf
Show file tree
Hide file tree
Showing 20 changed files with 216 additions and 151 deletions.
6 changes: 3 additions & 3 deletions cli/src/torii/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub enum Error {
Query(#[from] query::Error),
/// Failed to decode transaction
#[error("Failed to decode transaction")]
VersionedTransaction(#[source] iroha_version::error::Error),
VersionedSignedTransaction(#[source] iroha_version::error::Error),
/// Failed to accept transaction
#[error("Failed to accept transaction: {0}")]
AcceptTransaction(eyre::Report),
Expand Down Expand Up @@ -104,7 +104,7 @@ impl Reply for Error {
reply::with_status(utils::Scale(&err), query_status_code(&err)).into_response()
}
// TODO Have a type-preserved response body instead of a stringified one #2279
VersionedTransaction(err)
VersionedSignedTransaction(err)
| DecodeRequestPendingTransactions(err)
| EncodePendingTransactions(err) => {
reply::with_status(err.to_string(), err.status_code()).into_response()
Expand All @@ -119,7 +119,7 @@ impl Error {
use Error::*;
match self {
Query(e) => query_status_code(e),
VersionedTransaction(err)
VersionedSignedTransaction(err)
| DecodeRequestPendingTransactions(err)
| EncodePendingTransactions(err) => err.status_code(),
AcceptTransaction(_)
Expand Down
6 changes: 3 additions & 3 deletions cli/src/torii/routing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ impl TryFrom<SignedQueryRequest> for VerifiedQueryRequest {
pub(crate) async fn handle_instructions(
iroha_cfg: Configuration,
queue: Arc<Queue>,
transaction: VersionedTransaction,
transaction: VersionedSignedTransaction,
) -> Result<Empty> {
let transaction: Transaction = transaction.into_v1();
let transaction: SignedTransaction = transaction.into_v1();
let transaction = VersionedAcceptedTransaction::from_transaction(
transaction,
&iroha_cfg.sumeragi.transaction_limits,
Expand Down Expand Up @@ -208,7 +208,7 @@ async fn handle_pending_transactions(
.all_transactions()
.into_iter()
.map(VersionedAcceptedTransaction::into_v1)
.map(Transaction::from)
.map(SignedTransaction::from)
.paginate(pagination)
.collect(),
))
Expand Down
50 changes: 27 additions & 23 deletions client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ impl Client {
&self,
instructions: Executable,
metadata: UnlimitedMetadata,
) -> Result<Transaction> {
) -> Result<SignedTransaction> {
let transaction = Transaction::new(
self.account_id.clone(),
instructions,
Expand All @@ -345,7 +345,7 @@ impl Client {
///
/// # Errors
/// Fails if generating signature fails
pub fn sign_transaction(&self, transaction: Transaction) -> Result<Transaction> {
pub fn sign_transaction<Tx: Sign>(&self, transaction: Tx) -> Result<SignedTransaction> {
transaction
.sign(self.key_pair.clone())
.wrap_err("Failed to sign transaction")
Expand All @@ -369,7 +369,7 @@ impl Client {
pub fn submit(
&self,
instruction: impl Into<Instruction> + Debug,
) -> Result<HashOf<VersionedTransaction>> {
) -> Result<HashOf<VersionedSignedTransaction>> {
let isi = instruction.into();
self.submit_all([isi])
}
Expand All @@ -382,7 +382,7 @@ impl Client {
pub fn submit_all(
&self,
instructions: impl IntoIterator<Item = Instruction>,
) -> Result<HashOf<VersionedTransaction>> {
) -> Result<HashOf<VersionedSignedTransaction>> {
self.submit_all_with_metadata(instructions, UnlimitedMetadata::new())
}

Expand All @@ -396,7 +396,7 @@ impl Client {
&self,
instruction: Instruction,
metadata: UnlimitedMetadata,
) -> Result<HashOf<VersionedTransaction>> {
) -> Result<HashOf<VersionedSignedTransaction>> {
self.submit_all_with_metadata([instruction], metadata)
}

Expand All @@ -410,7 +410,7 @@ impl Client {
&self,
instructions: impl IntoIterator<Item = Instruction>,
metadata: UnlimitedMetadata,
) -> Result<HashOf<VersionedTransaction>> {
) -> Result<HashOf<VersionedSignedTransaction>> {
self.submit_transaction(self.build_transaction(instructions.into(), metadata)?)
}

Expand All @@ -421,8 +421,8 @@ impl Client {
/// Fails if sending transaction to peer fails or if it response with error
pub fn submit_transaction(
&self,
transaction: Transaction,
) -> Result<HashOf<VersionedTransaction>> {
transaction: SignedTransaction,
) -> Result<HashOf<VersionedSignedTransaction>> {
iroha_logger::trace!(tx=?transaction);
let (req, hash, resp_handler) =
self.prepare_transaction_request::<DefaultRequestBuilder>(transaction)?;
Expand All @@ -441,8 +441,8 @@ impl Client {
/// Fails if sending a transaction to a peer fails or there is an error in the response
pub fn submit_transaction_blocking(
&self,
transaction: Transaction,
) -> Result<HashOf<VersionedTransaction>> {
transaction: SignedTransaction,
) -> Result<HashOf<VersionedSignedTransaction>> {
let client = self.clone();
let (init_sender, init_receiver) = mpsc::channel();
let hash = transaction.hash();
Expand Down Expand Up @@ -476,9 +476,9 @@ impl Client {
// TODO: introduce timeout
fn listen_for_tx_confirmation(
&self,
hash: HashOf<Transaction>,
hash: HashOf<SignedTransaction>,
init_sender: &mpsc::Sender<()>,
) -> Result<HashOf<VersionedTransaction>> {
) -> Result<HashOf<VersionedSignedTransaction>> {
let event_iterator = self
.listen_for_events(PipelineEventFilter::new().hash(hash.into()).into())
.wrap_err("Failed to establish event listener connection")?;
Expand Down Expand Up @@ -515,10 +515,14 @@ impl Client {
/// Fails if transaction check fails
pub fn prepare_transaction_request<B: RequestBuilder>(
&self,
transaction: Transaction,
) -> Result<(B, HashOf<VersionedTransaction>, TransactionResponseHandler)> {
transaction: SignedTransaction,
) -> Result<(
B,
HashOf<VersionedSignedTransaction>,
TransactionResponseHandler,
)> {
transaction.check_limits(&self.transaction_limits)?;
let transaction: VersionedTransaction = transaction.into();
let transaction: VersionedSignedTransaction = transaction.into();
let hash = transaction.hash();
let transaction_bytes: Vec<u8> = transaction.encode_versioned();

Expand All @@ -542,7 +546,7 @@ impl Client {
pub fn submit_blocking(
&self,
instruction: impl Into<Instruction>,
) -> Result<HashOf<VersionedTransaction>> {
) -> Result<HashOf<VersionedSignedTransaction>> {
self.submit_all_blocking(vec![instruction.into()])
}

Expand All @@ -554,7 +558,7 @@ impl Client {
pub fn submit_all_blocking(
&self,
instructions: impl IntoIterator<Item = Instruction>,
) -> Result<HashOf<VersionedTransaction>> {
) -> Result<HashOf<VersionedSignedTransaction>> {
self.submit_all_blocking_with_metadata(instructions, UnlimitedMetadata::new())
}

Expand All @@ -568,7 +572,7 @@ impl Client {
&self,
instruction: impl Into<Instruction>,
metadata: UnlimitedMetadata,
) -> Result<HashOf<VersionedTransaction>> {
) -> Result<HashOf<VersionedSignedTransaction>> {
self.submit_all_blocking_with_metadata(vec![instruction.into()], metadata)
}

Expand All @@ -582,7 +586,7 @@ impl Client {
&self,
instructions: impl IntoIterator<Item = Instruction>,
metadata: UnlimitedMetadata,
) -> Result<HashOf<VersionedTransaction>> {
) -> Result<HashOf<VersionedSignedTransaction>> {
let transaction = self.build_transaction(instructions.into(), metadata)?;
self.submit_transaction_blocking(transaction)
}
Expand Down Expand Up @@ -825,11 +829,11 @@ impl Client {
/// Fails if subscribing to websocket fails
pub fn get_original_transaction_with_pagination(
&self,
transaction: &Transaction,
transaction: &SignedTransaction,
retry_count: u32,
retry_in: Duration,
pagination: Pagination,
) -> Result<Option<Transaction>> {
) -> Result<Option<SignedTransaction>> {
let pagination: Vec<_> = pagination.into();
for _ in 0..retry_count {
let response = DefaultRequestBuilder::new(
Expand Down Expand Up @@ -874,10 +878,10 @@ impl Client {
/// Fails if sending request fails
pub fn get_original_transaction(
&self,
transaction: &Transaction,
transaction: &SignedTransaction,
retry_count: u32,
retry_in: Duration,
) -> Result<Option<Transaction>> {
) -> Result<Option<SignedTransaction>> {
self.get_original_transaction_with_pagination(
transaction,
retry_count,
Expand Down
2 changes: 1 addition & 1 deletion client/tests/integration/events/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ fn test_with_instruction_and_status(
#[derive(Clone)]
struct Checker {
listener: iroha_client::client::Client,
hash: iroha_crypto::HashOf<Transaction>,
hash: iroha_crypto::HashOf<SignedTransaction>,
}

impl Checker {
Expand Down
2 changes: 1 addition & 1 deletion core/benches/validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const TRANSACTION_LIMITS: TransactionLimits = TransactionLimits {
max_wasm_size_bytes: 0,
};

fn build_test_transaction(keys: KeyPair) -> Transaction {
fn build_test_transaction(keys: KeyPair) -> SignedTransaction {
let domain_name = "domain";
let domain_id = DomainId::from_str(domain_name).expect("does not panic");
let create_domain = RegisterBox::new(Domain::new(domain_id));
Expand Down
4 changes: 2 additions & 2 deletions core/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,9 @@ pub struct BlockHeader {
/// Is an array of zeros for the first block.
pub previous_block_hash: HashOf<VersionedCommittedBlock>,
/// Hash of merkle tree root of the tree of valid transactions' hashes.
pub transactions_hash: HashOf<MerkleTree<VersionedTransaction>>,
pub transactions_hash: HashOf<MerkleTree<VersionedSignedTransaction>>,
/// Hash of merkle tree root of the tree of rejected transactions' hashes.
pub rejected_transactions_hash: HashOf<MerkleTree<VersionedTransaction>>,
pub rejected_transactions_hash: HashOf<MerkleTree<VersionedSignedTransaction>>,
/// Number of view changes after the previous block was committed and before this block was committed.
pub view_change_proofs: ViewChangeProofs,
/// Hashes of the blocks that were rejected by consensus.
Expand Down
8 changes: 4 additions & 4 deletions core/src/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ use crate::prelude::*;
/// Multiple producers, single consumer
#[derive(Debug)]
pub struct Queue {
queue: ArrayQueue<HashOf<VersionedTransaction>>,
txs: DashMap<HashOf<VersionedTransaction>, VersionedAcceptedTransaction>,
queue: ArrayQueue<HashOf<VersionedSignedTransaction>>,
txs: DashMap<HashOf<VersionedSignedTransaction>, VersionedAcceptedTransaction>,
/// Length of dashmap.
///
/// DashMap right now just iterates over itself and calculates its length like this:
Expand Down Expand Up @@ -58,7 +58,7 @@ pub enum Error {
#[error("Failure during signature condition execution, tx hash: {tx_hash}, reason: {reason}")]
SignatureCondition {
/// Transaction hash
tx_hash: HashOf<VersionedTransaction>,
tx_hash: HashOf<VersionedSignedTransaction>,
/// Failure reason
reason: Report,
},
Expand Down Expand Up @@ -182,7 +182,7 @@ impl Queue {
)]
fn pop(
&self,
seen: &mut Vec<HashOf<VersionedTransaction>>,
seen: &mut Vec<HashOf<VersionedSignedTransaction>>,
) -> Option<VersionedAcceptedTransaction> {
loop {
let hash = self.queue.pop()?;
Expand Down
2 changes: 1 addition & 1 deletion core/src/smartcontracts/isi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ pub mod error {
Block(HashOf<VersionedCommittedBlock>),
/// Transaction with given hash not found.
#[error("Transaction not found")]
Transaction(HashOf<VersionedTransaction>),
Transaction(HashOf<VersionedSignedTransaction>),
/// Value not found in context.
#[error("Value named {0} not found in context. ")]
Context(String),
Expand Down
4 changes: 2 additions & 2 deletions core/src/sumeragi/fault.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ where

/// Hashes of the transactions that were forwarded to a leader, but not yet confirmed with a receipt.
/// And time at which this transaction was sent to the leader by this peer.
pub(crate) txs_awaiting_receipts: HashMap<HashOf<VersionedTransaction>, Instant>,
pub(crate) txs_awaiting_receipts: HashMap<HashOf<VersionedSignedTransaction>, Instant>,
/// Hashes of the transactions that were accepted by the leader and are waiting to be stored in `CreatedBlock`.
pub(crate) txs_awaiting_created_block: HashSet<HashOf<VersionedTransaction>>,
pub(crate) txs_awaiting_created_block: HashSet<HashOf<VersionedSignedTransaction>>,

pub(crate) commit_time: Duration,
pub(crate) tx_receipt_time: Duration,
Expand Down
14 changes: 7 additions & 7 deletions core/src/sumeragi/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,14 @@ pub struct CheckCommitTimeout {
/// Reminder to check if block creation timeout happened.
#[derive(Debug, Clone, iroha_actor::Message)]
pub struct CheckCreationTimeout {
pub(crate) tx_hash: HashOf<VersionedTransaction>,
pub(crate) tx_hash: HashOf<VersionedSignedTransaction>,
pub(crate) proof: Proof,
}

/// Reminder to check if transaction receipt timeout happened.
#[derive(Debug, Clone, iroha_actor::Message)]
pub struct CheckReceiptTimeout {
pub(crate) tx_hash: HashOf<VersionedTransaction>,
pub(crate) tx_hash: HashOf<VersionedSignedTransaction>,
pub(crate) proof: Proof,
}

Expand Down Expand Up @@ -522,7 +522,7 @@ impl From<VersionedValidBlock> for BlockCommitted {
#[non_exhaustive]
pub struct TransactionForwarded {
/// Transaction that is forwarded from a client by a peer to the leader
pub transaction: VersionedTransaction,
pub transaction: VersionedSignedTransaction,
/// `PeerId` of the peer that forwarded this transaction to a leader.
pub peer: PeerId,
}
Expand Down Expand Up @@ -570,7 +570,7 @@ impl TransactionForwarded {
/// Message for gossiping batches of transactions.
#[derive(Decode, Encode, Debug, Clone)]
pub struct TransactionGossip {
txs: Vec<VersionedTransaction>,
txs: Vec<VersionedSignedTransaction>,
}

impl TransactionGossip {
Expand Down Expand Up @@ -613,11 +613,11 @@ impl TransactionGossip {
#[non_exhaustive]
pub struct TransactionReceipt {
/// The hash of the transaction that the leader received.
pub hash: HashOf<VersionedTransaction>,
pub hash: HashOf<VersionedSignedTransaction>,
/// The time at which the leader claims to have received this transaction.
pub received_at: Duration,
/// The signature of the leader.
pub signature: SignatureOf<VersionedTransaction>,
pub signature: SignatureOf<VersionedSignedTransaction>,
}

impl TransactionReceipt {
Expand All @@ -627,7 +627,7 @@ impl TransactionReceipt {
/// Can fail creating new signature
#[allow(clippy::expect_used, clippy::unwrap_in_result)]
pub fn new(
transaction: &VersionedTransaction,
transaction: &VersionedSignedTransaction,
key_pair: &KeyPair,
) -> Result<TransactionReceipt> {
let hash = transaction.hash();
Expand Down
6 changes: 3 additions & 3 deletions core/src/sumeragi/network_topology.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::{collections::HashSet, iter};

use eyre::{eyre, Context, Result};
use iroha_crypto::{Hash, HashOf, SignatureOf};
use iroha_data_model::{prelude::PeerId, transaction::VersionedTransaction};
use iroha_data_model::{prelude::PeerId, transaction::VersionedSignedTransaction};
use iroha_schema::IntoSchema;
use parity_scale_codec::{Decode, Encode};
use rand::{rngs::StdRng, seq::SliceRandom, SeedableRng};
Expand Down Expand Up @@ -325,9 +325,9 @@ impl Topology {
/// Fails if there are no such peer with this key and if signature verification fails
pub fn verify_signature_with_role(
&self,
signature: &SignatureOf<VersionedTransaction>,
signature: &SignatureOf<VersionedSignedTransaction>,
role: Role,
tx: &HashOf<VersionedTransaction>,
tx: &HashOf<VersionedSignedTransaction>,
) -> Result<()> {
if role
.peers(self)
Expand Down
Loading

0 comments on commit e9563bf

Please sign in to comment.