Skip to content

Commit

Permalink
[refactor] #4229: Removed MST aggregation
Browse files Browse the repository at this point in the history
Signed-off-by: Stukalov-A-M <stukalov07@gmail.com>
  • Loading branch information
Stukalov-A-M committed Feb 29, 2024
1 parent fd09f10 commit 96bf997
Show file tree
Hide file tree
Showing 18 changed files with 113 additions and 295 deletions.
83 changes: 19 additions & 64 deletions client/src/client.rs
Expand Up @@ -32,7 +32,6 @@ use crate::{
predicate::PredicateBox,
prelude::*,
query::{Pagination, Query, Sorting},
transaction::TransactionPayload,
BatchedResponse, ChainId, ValidationFail,
},
http::{Method as HttpMethod, RequestBuilder, Response, StatusCode},
Expand Down Expand Up @@ -491,7 +490,7 @@ impl Client {
///
/// # Errors
/// Fails if sending transaction to peer fails or if it response with error
pub fn submit(&self, instruction: impl Instruction) -> Result<HashOf<TransactionPayload>> {
pub fn submit(&self, instruction: impl Instruction) -> Result<HashOf<SignedTransaction>> {
let isi = instruction.into();
self.submit_all([isi])
}
Expand All @@ -504,7 +503,7 @@ impl Client {
pub fn submit_all(
&self,
instructions: impl IntoIterator<Item = impl Instruction>,
) -> Result<HashOf<TransactionPayload>> {
) -> Result<HashOf<SignedTransaction>> {
self.submit_all_with_metadata(instructions, UnlimitedMetadata::new())
}

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

Expand All @@ -532,7 +531,7 @@ impl Client {
&self,
instructions: impl IntoIterator<Item = impl Instruction>,
metadata: UnlimitedMetadata,
) -> Result<HashOf<TransactionPayload>> {
) -> Result<HashOf<SignedTransaction>> {
self.submit_transaction(&self.build_transaction(instructions, metadata))
}

Expand All @@ -544,7 +543,7 @@ impl Client {
pub fn submit_transaction(
&self,
transaction: &SignedTransaction,
) -> Result<HashOf<TransactionPayload>> {
) -> Result<HashOf<SignedTransaction>> {
iroha_logger::trace!(tx=?transaction, "Submitting");
let (req, hash) = self.prepare_transaction_request::<DefaultRequestBuilder>(transaction);
let response = req
Expand All @@ -563,9 +562,9 @@ impl Client {
pub fn submit_transaction_blocking(
&self,
transaction: &SignedTransaction,
) -> Result<HashOf<TransactionPayload>> {
) -> Result<HashOf<SignedTransaction>> {
let (init_sender, init_receiver) = tokio::sync::oneshot::channel();
let hash = transaction.hash_of_payload();
let hash = transaction.hash();

thread::scope(|spawner| {
let submitter_handle = spawner.spawn(move || -> Result<()> {
Expand All @@ -592,8 +591,8 @@ impl Client {
fn listen_for_tx_confirmation(
&self,
init_sender: tokio::sync::oneshot::Sender<bool>,
hash: HashOf<TransactionPayload>,
) -> Result<HashOf<TransactionPayload>> {
hash: HashOf<SignedTransaction>,
) -> Result<HashOf<SignedTransaction>> {
let deadline = tokio::time::Instant::now() + self.transaction_status_timeout;
let rt = tokio::runtime::Builder::new_current_thread()
.enable_all()
Expand Down Expand Up @@ -629,8 +628,8 @@ impl Client {

async fn listen_for_tx_confirmation_loop(
event_iterator: &mut AsyncEventStream,
hash: HashOf<TransactionPayload>,
) -> Result<HashOf<TransactionPayload>> {
hash: HashOf<SignedTransaction>,
) -> Result<HashOf<SignedTransaction>> {
while let Some(event) = event_iterator.next().await {
if let Event::Pipeline(this_event) = event? {
match this_event.status() {
Expand All @@ -657,7 +656,7 @@ impl Client {
fn prepare_transaction_request<B: RequestBuilder>(
&self,
transaction: &SignedTransaction,
) -> (B, HashOf<TransactionPayload>) {
) -> (B, HashOf<SignedTransaction>) {
let transaction_bytes: Vec<u8> = transaction.encode_versioned();

(
Expand All @@ -669,7 +668,7 @@ impl Client {
)
.headers(self.headers.clone())
.body(transaction_bytes),
transaction.hash_of_payload(),
transaction.hash(),
)
}

Expand All @@ -681,7 +680,7 @@ impl Client {
pub fn submit_blocking(
&self,
instruction: impl Instruction,
) -> Result<HashOf<TransactionPayload>> {
) -> Result<HashOf<SignedTransaction>> {
self.submit_all_blocking(vec![instruction.into()])
}

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

Expand All @@ -707,7 +706,7 @@ impl Client {
&self,
instruction: impl Instruction,
metadata: UnlimitedMetadata,
) -> Result<HashOf<TransactionPayload>> {
) -> Result<HashOf<SignedTransaction>> {
self.submit_all_blocking_with_metadata(vec![instruction.into()], metadata)
}

Expand All @@ -721,7 +720,7 @@ impl Client {
&self,
instructions: impl IntoIterator<Item = impl Instruction>,
metadata: UnlimitedMetadata,
) -> Result<HashOf<TransactionPayload>> {
) -> Result<HashOf<SignedTransaction>> {
let transaction = self.build_transaction(instructions, metadata);
self.submit_transaction_blocking(&transaction)
}
Expand Down Expand Up @@ -973,50 +972,6 @@ impl Client {
)
}

/// Find the original transaction in the local pending tx queue.
/// Should be used for an MST case.
///
/// # Errors
/// - if sending request fails
pub fn get_original_matching_transactions(
&self,
transaction: &SignedTransaction,
retry_count: u32,
retry_in: Duration,
) -> Result<Vec<SignedTransaction>> {
let url = self
.torii_url
.join(torii_uri::MATCHING_PENDING_TRANSACTIONS)
.expect("Valid URI");
let body = transaction.encode();

for _ in 0..retry_count {
let response = DefaultRequestBuilder::new(HttpMethod::POST, url.clone())
.headers(self.headers.clone())
.header(http::header::CONTENT_TYPE, APPLICATION_JSON)
.body(body.clone())
.build()?
.send()?;

if response.status() == StatusCode::OK {
let pending_transactions: Vec<SignedTransaction> =
DecodeAll::decode_all(&mut response.body().as_slice())?;

if !pending_transactions.is_empty() {
return Ok(pending_transactions);
}
thread::sleep(retry_in);
} else {
return Err(eyre!(
"Failed to make query request with HTTP status: {}, {}",
response.status(),
std::str::from_utf8(response.body()).unwrap_or(""),
));
}
}
Ok(Vec::new())
}

/// Get value of config on peer
///
/// # Errors
Expand Down Expand Up @@ -1622,7 +1577,7 @@ mod tests {
|| client.build_transaction(Vec::<InstructionBox>::new(), UnlimitedMetadata::new());
let tx1 = build_transaction();
let tx2 = build_transaction();
assert_ne!(tx1.hash_of_payload(), tx2.hash_of_payload());
assert_ne!(tx1.hash(), tx2.hash());

let tx2 = {
let mut tx =
Expand All @@ -1640,7 +1595,7 @@ mod tests {

client.sign_transaction(tx)
};
assert_eq!(tx1.hash_of_payload(), tx2.hash_of_payload());
assert_eq!(tx1.hash(), tx2.hash());
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions client/tests/integration/burn_public_keys.rs
@@ -1,7 +1,7 @@
use iroha_client::{
client::{account, transaction, Client},
crypto::{HashOf, KeyPair, PublicKey},
data_model::{isi::Instruction, prelude::*, transaction::TransactionPayload},
data_model::{isi::Instruction, prelude::*},
};
use test_network::*;

Expand All @@ -11,7 +11,7 @@ fn submit(
submitter: Option<(AccountId, KeyPair)>,
) -> (
HashOf<SignedTransaction>,
eyre::Result<HashOf<TransactionPayload>>,
eyre::Result<HashOf<SignedTransaction>>,
) {
let chain_id = ChainId::from("0");

Expand Down
4 changes: 2 additions & 2 deletions client/tests/integration/events/pipeline.rs
Expand Up @@ -52,7 +52,7 @@ fn test_with_instruction_and_status_and_port(
// Given
let submitter = client;
let transaction = submitter.build_transaction(instruction, UnlimitedMetadata::new());
let hash = transaction.hash_of_payload();
let hash = transaction.hash();
let mut handles = Vec::new();
for listener in clients {
let checker = Checker { listener, hash };
Expand All @@ -74,7 +74,7 @@ fn test_with_instruction_and_status_and_port(
#[derive(Clone)]
struct Checker {
listener: iroha_client::client::Client,
hash: HashOf<TransactionPayload>,
hash: HashOf<SignedTransaction>,
}

impl Checker {
Expand Down
23 changes: 13 additions & 10 deletions client/tests/integration/multisignature_transaction.rs
@@ -1,8 +1,9 @@
use std::{str::FromStr as _, thread, time::Duration};
use std::{str::FromStr as _, thread};

use eyre::Result;
use iroha_client::{
client::{self, Client, QueryResult},
client,
client::{Client, QueryResult},
config::Config as ClientConfig,
crypto::KeyPair,
data_model::{
Expand All @@ -15,7 +16,7 @@ use test_network::*;

#[allow(clippy::too_many_lines)]
#[test]
fn multisignature_transactions_should_wait_for_all_signatures() -> Result<()> {
fn multisignature_transactions_should_be_accepted_after_fully_signed() -> Result<()> {
let (_rt, network, client) = Network::start_test_with_runtime(4, Some(10_945));
wait_for_genesis_committed(&network.clients(), 0);
let pipeline_time = Config::pipeline_time();
Expand Down Expand Up @@ -54,7 +55,11 @@ fn multisignature_transactions_should_wait_for_all_signatures() -> Result<()> {
let client = Client::new(client_config.clone());
let instructions = [mint_asset.clone()];
let transaction = client.build_transaction(instructions, UnlimitedMetadata::new());
client.submit_transaction(&client.sign_transaction(transaction))?;
// The tx signed by the first account
let _ = client
.submit_transaction(&client.sign_transaction(transaction.clone()))
.expect_err("Transaction should not be added into the queue");

thread::sleep(pipeline_time);

//Then
Expand All @@ -77,14 +82,11 @@ fn multisignature_transactions_should_wait_for_all_signatures() -> Result<()> {

client_config.key_pair = key_pair_2;
let client_2 = Client::new(client_config);
let instructions = [mint_asset];
let transaction = client_2.build_transaction(instructions, UnlimitedMetadata::new());
let transaction = client_2
.get_original_matching_transactions(&transaction, 3, Duration::from_millis(100))?
.pop()
.expect("Found no pending transaction for this account.");
// The tx signed by the second account
client_2.submit_transaction(&client_2.sign_transaction(transaction))?;

thread::sleep(pipeline_time);

let assets = client_1
.request(request)?
.collect::<QueryResult<Vec<_>>>()?;
Expand All @@ -94,5 +96,6 @@ fn multisignature_transactions_should_wait_for_all_signatures() -> Result<()> {
.find(|asset| *asset.id() == asset_id)
.expect("Failed to find expected asset");
assert_eq!(AssetValue::Quantity(quantity), *camomile_asset.value());

Ok(())
}
2 changes: 1 addition & 1 deletion client_cli/pytests/README.md
Expand Up @@ -164,7 +164,7 @@ The variables:

```shell
CLIENT_CLI_BINARY=/path/to/iroha_client_cli
CLIENT_CLI_CONFIG=/path/to/config.toml
CLIENT_CLI_CONFIG=/path/to/client.toml
TORII_API_PORT_MIN=8080
TORII_API_PORT_MAX=8083
```
Expand Down
11 changes: 4 additions & 7 deletions client_cli/pytests/src/client_cli/client_cli.py
Expand Up @@ -22,10 +22,7 @@ class ClientCli:
"""

BASE_PATH = CLIENT_CLI_PATH
# --skip-mst-check flag is used because
# MST isn't used in the tests
# and don't using this flag results in tests being broken by interactive prompt
BASE_FLAGS = ["--config=" + PATH_CONFIG_CLIENT_CLI, "--skip-mst-check"]
BASE_FLAGS = ["--config=" + PATH_CONFIG_CLIENT_CLI]

def __init__(self, config: Config):
"""
Expand Down Expand Up @@ -132,7 +129,7 @@ def domain(self, domain: str):
:return: The current ClientCli object.
:rtype: ClientCli
"""
self.command.insert(3, "domain")
self.command.insert(2, "domain")
self.command.append("--id=" + domain)
self.execute()
return self
Expand All @@ -150,7 +147,7 @@ def account(self, account: str, domain: str, key: str):
:return: The current ClientCli object.
:rtype: ClientCli
"""
self.command.insert(3, "account")
self.command.insert(2, "account")
self.command.append("--id=" + account + "@" + domain)
self.command.append("--key=ed0120" + key)
self.execute()
Expand All @@ -169,7 +166,7 @@ def asset(self, asset_definition=None, account=None, value_of_value_type=None):
:return: The current ClientCli object.
:rtype: ClientCli
"""
self.command.insert(3, "asset")
self.command.insert(2, "asset")
if asset_definition and account and value_of_value_type:
self.command.append(
"--asset-id="
Expand Down
4 changes: 4 additions & 0 deletions client_cli/pytests/src/client_cli/configuration.py
Expand Up @@ -39,6 +39,10 @@ def load(self, path_config_client_cli):
"""
if not os.path.exists(path_config_client_cli):
raise IOError(f"No config file found at {path_config_client_cli}")

if not os.path.isfile(path_config_client_cli):
raise IOError(f"The path is not a file: {path_config_client_cli}")

with open(path_config_client_cli, "r", encoding="utf-8") as config_file:
self._config = tomlkit.load(config_file)
self.file = path_config_client_cli
Expand Down
2 changes: 1 addition & 1 deletion client_cli/pytests/src/client_cli/iroha.py
Expand Up @@ -21,7 +21,7 @@ def _execute_command(self, command_name: str):
:param command_name: The name of the command to execute.
:type command_name: str
"""
self.command.insert(3, command_name)
self.command.insert(2, command_name)
self.execute()

def should(self, *args, **kwargs):
Expand Down

0 comments on commit 96bf997

Please sign in to comment.