Skip to content

Commit

Permalink
[refactor] hyperledger-iroha#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 20, 2024
1 parent ac3d4c9 commit 6ace5d8
Show file tree
Hide file tree
Showing 14 changed files with 90 additions and 257 deletions.
83 changes: 19 additions & 64 deletions client/src/client.rs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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(())
}
Loading

0 comments on commit 6ace5d8

Please sign in to comment.