Skip to content

Commit

Permalink
refactor!: don't send public key with signature
Browse files Browse the repository at this point in the history
Signed-off-by: Marin Veršić <[email protected]>
  • Loading branch information
mversic committed Jun 11, 2024
1 parent 86d3cbc commit b044546
Show file tree
Hide file tree
Showing 41 changed files with 1,333 additions and 1,675 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion client/benches/tps/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ use iroha::{
client::Client,
crypto::KeyPair,
data_model::{
events::pipeline::{BlockEventFilter, BlockStatus},
parameter::{default::MAX_TRANSACTIONS_IN_BLOCK, ParametersBuilder},
prelude::*,
},
};
use iroha_data_model::events::pipeline::{BlockEventFilter, BlockStatus};
use nonzero_ext::nonzero;
use serde::Deserialize;
use test_network::*;
Expand Down
6 changes: 4 additions & 2 deletions client/examples/million_accounts_genesis.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
//! This file contains examples from the Rust tutorial.
use std::{thread, time::Duration};

use iroha::{crypto::KeyPair, data_model::prelude::*};
use iroha_data_model::isi::InstructionBox;
use iroha::{
crypto::KeyPair,
data_model::{::isi::InstructionBox, prelude::*},
};
use iroha_genesis::{GenesisTransaction, GenesisTransactionBuilder};
use iroha_primitives::unique_vec;
use irohad::samples::{construct_executor, get_config};
Expand Down
7 changes: 4 additions & 3 deletions client/examples/register_1000_triggers.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
//! Example of registering multiple triggers
//! Used to show Iroha's trigger deduplication capabilities
use iroha::{client::Client, data_model::prelude::*};
use iroha_crypto::KeyPair;
use iroha_data_model::trigger::TriggerId;
use iroha::{
client::Client,
data_model::{prelude::*, trigger::TriggerId},
};
use iroha_genesis::{GenesisTransaction, GenesisTransactionBuilder};
use iroha_primitives::unique_vec;
use irohad::samples::{construct_executor, get_config};
Expand Down
34 changes: 7 additions & 27 deletions client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@ use eyre::{eyre, Result, WrapErr};
use futures_util::StreamExt;
use http_default::{AsyncWebSocketStream, WebSocketStream};
pub use iroha_config::client_api::ConfigDTO;
use iroha_data_model::{
events::pipeline::{
BlockEventFilter, BlockStatus, PipelineEventBox, PipelineEventFilterBox,
TransactionEventFilter, TransactionStatus,
},
query::QueryOutputBox,
};
use iroha_logger::prelude::*;
use iroha_telemetry::metrics::Status;
use iroha_torii_const::uri as torii_uri;
Expand All @@ -36,9 +29,14 @@ use crate::{
crypto::{HashOf, KeyPair},
data_model::{
block::SignedBlock,
events::pipeline::{
BlockEventFilter, BlockStatus, PipelineEventBox, PipelineEventFilterBox,
TransactionEventFilter, TransactionStatus,
},
isi::Instruction,
prelude::*,
query::{predicate::PredicateBox, Pagination, Query, Sorting},
query::{predicate::PredicateBox, Pagination, Query, QueryOutputBox, Sorting},
transaction::TransactionBuilder,
BatchedResponse, ChainId, ValidationFail,
},
http::{Method as HttpMethod, RequestBuilder, Response, StatusCode},
Expand Down Expand Up @@ -68,24 +66,6 @@ impl<R> QueryResponseHandler<R> {
/// `Result` with [`ClientQueryError`] as an error
pub type QueryResult<T> = core::result::Result<T, ClientQueryError>;

/// Trait for signing transactions
pub trait Sign {
/// Sign transaction with provided key pair.
fn sign(self, key_pair: &crate::crypto::KeyPair) -> SignedTransaction;
}

impl Sign for TransactionBuilder {
fn sign(self, key_pair: &crate::crypto::KeyPair) -> SignedTransaction {
self.sign(key_pair)
}
}

impl Sign for SignedTransaction {
fn sign(self, key_pair: &crate::crypto::KeyPair) -> SignedTransaction {
self.sign(key_pair)
}
}

impl<R: QueryOutput> QueryResponseHandler<R>
where
<R as TryFrom<QueryOutputBox>>::Error: Into<eyre::Error>,
Expand Down Expand Up @@ -496,7 +476,7 @@ impl Client {
///
/// # Errors
/// Fails if signature generation fails
pub fn sign_transaction<Tx: Sign>(&self, transaction: Tx) -> SignedTransaction {
pub fn sign_transaction(&self, transaction: TransactionBuilder) -> SignedTransaction {
transaction.sign(&self.key_pair)
}

Expand Down
7 changes: 5 additions & 2 deletions client/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@ use derive_more::Display;
use error_stack::ResultExt;
use eyre::Result;
use iroha_config_base::{read::ConfigReader, toml::TomlSource};
use iroha_crypto::KeyPair;
use iroha_data_model::{prelude::*, ChainId};
use iroha_primitives::small::SmallStr;
use serde::{Deserialize, Serialize};
use serde_with::{DeserializeFromStr, SerializeDisplay};
use url::Url;

use crate::{
crypto::KeyPair,
data_model::{prelude::*, ChainId},
};

mod user;

#[allow(missing_docs)]
Expand Down
Empty file.
7 changes: 4 additions & 3 deletions client/src/query_builder.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use std::fmt::Debug;

use iroha_data_model::query::{IterableQuery, QueryOutputBox};

use crate::{
client::{Client, QueryOutput, QueryResult},
data_model::query::{predicate::PredicateBox, sorting::Sorting, FetchSize, Pagination, Query},
data_model::query::{
predicate::PredicateBox, sorting::Sorting, FetchSize, IterableQuery, Pagination, Query,
QueryOutputBox,
},
};

pub struct QueryRequestBuilder<'a, R> {
Expand Down
12 changes: 6 additions & 6 deletions client/tests/integration/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ use eyre::Result;
use iroha::{
client::{self, QueryResult},
crypto::KeyPair,
data_model::prelude::*,
data_model::{
asset::{AssetId, AssetValue, AssetValueType},
isi::error::{InstructionEvaluationError, InstructionExecutionError, Mismatch, TypeError},
prelude::*,
transaction::error::TransactionRejectionReason,
},
};
use iroha_config::parameters::actual::Root as Config;
use iroha_data_model::{
asset::{AssetId, AssetValue, AssetValueType},
isi::error::{InstructionEvaluationError, InstructionExecutionError, Mismatch, TypeError},
transaction::error::TransactionRejectionReason,
};
use serde_json::json;
use test_network::*;
use test_samples::{gen_account_in, ALICE_ID, BOB_ID};
Expand Down
4 changes: 1 addition & 3 deletions client/tests/integration/domain_owner_permissions.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use eyre::Result;
use iroha::data_model::prelude::*;
use iroha_data_model::transaction::error::TransactionRejectionReason;
use iroha::data_model::{prelude::*, transaction::error::TransactionRejectionReason};
use serde_json::json;
use test_network::*;
use test_samples::{gen_account_in, ALICE_ID, BOB_ID};
Expand Down Expand Up @@ -304,7 +303,6 @@ fn domain_owner_trigger_permissions() -> Result<()> {
Ok(())
}

#[ignore = "migrated to client cli python tests"]
#[test]
fn domain_owner_transfer() -> Result<()> {
let (_rt, _peer, test_client) = <PeerBuilder>::new().with_port(11_100).start_with_runtime();
Expand Down
14 changes: 6 additions & 8 deletions client/tests/integration/events/pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,17 @@ use eyre::Result;
use iroha::{
crypto::HashOf,
data_model::{
events::pipeline::{
BlockEvent, BlockEventFilter, BlockStatus, TransactionEventFilter, TransactionStatus,
},
isi::error::InstructionExecutionError,
parameter::{default::MAX_TRANSACTIONS_IN_BLOCK, ParametersBuilder},
prelude::*,
transaction::error::TransactionRejectionReason,
ValidationFail,
},
};
use iroha_config::parameters::actual::Root as Config;
use iroha_data_model::{
events::pipeline::{
BlockEvent, BlockEventFilter, BlockStatus, TransactionEventFilter, TransactionStatus,
},
isi::error::InstructionExecutionError,
transaction::error::TransactionRejectionReason,
ValidationFail,
};
use test_network::*;

// Needed to re-enable ignored tests.
Expand Down
3 changes: 1 addition & 2 deletions client/tests/integration/non_mintable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ use std::str::FromStr as _;
use eyre::Result;
use iroha::{
client::{self, QueryResult},
data_model::{metadata::UnlimitedMetadata, prelude::*},
data_model::{isi::InstructionBox, metadata::UnlimitedMetadata, prelude::*},
};
use iroha_data_model::isi::InstructionBox;
use test_network::*;
use test_samples::ALICE_ID;

Expand Down
9 changes: 4 additions & 5 deletions client/tests/integration/permissions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ use eyre::Result;
use iroha::{
client::{self, Client, QueryResult},
crypto::KeyPair,
data_model::prelude::*,
};
use iroha_data_model::{
permission::Permission, role::RoleId, transaction::error::TransactionRejectionReason,
JsonString,
data_model::{
permission::Permission, prelude::*, role::RoleId,
transaction::error::TransactionRejectionReason, JsonString,
},
};
use iroha_genesis::GenesisTransaction;
use serde_json::json;
Expand Down
3 changes: 1 addition & 2 deletions client/tests/integration/roles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ use std::str::FromStr as _;
use eyre::Result;
use iroha::{
client::{self, QueryResult},
data_model::prelude::*,
data_model::{prelude::*, transaction::error::TransactionRejectionReason},
};
use iroha_data_model::transaction::error::TransactionRejectionReason;
use serde_json::json;
use test_network::*;
use test_samples::{gen_account_in, ALICE_ID};
Expand Down
15 changes: 8 additions & 7 deletions client/tests/integration/transfer_asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ use std::str::FromStr;

use iroha::{
client::{self, QueryResult},
data_model::{isi::Instruction, prelude::*, Registered},
};
use iroha_data_model::{
account::{Account, AccountId},
asset::{Asset, AssetDefinition},
isi::InstructionBox,
name::Name,
data_model::{
account::{Account, AccountId},
asset::{Asset, AssetDefinition},
isi::{Instruction, InstructionBox},
name::Name,
prelude::*,
Registered,
},
};
use test_network::*;
use test_samples::{gen_account_in, ALICE_ID};
Expand Down
2 changes: 1 addition & 1 deletion client/tests/integration/triggers/by_call_trigger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ use std::{str::FromStr as _, sync::mpsc, thread, time::Duration};
use eyre::{eyre, Result, WrapErr};
use iroha::{
client::{self, Client},
crypto::KeyPair,
data_model::{
prelude::*,
query::error::{FindError, QueryExecutionFail},
transaction::{Executable, WasmSmartContract},
},
};
use iroha_crypto::KeyPair;
use iroha_genesis::GenesisTransaction;
use iroha_logger::info;
use serde_json::json;
Expand Down
9 changes: 5 additions & 4 deletions client/tests/integration/tx_chain_id.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::str::FromStr;

use iroha_data_model::prelude::*;
use iroha::data_model::prelude::*;
use iroha_data_model::asset::AssetDefinitionId;
use iroha_primitives::numeric::numeric;
use test_network::*;
use test_samples::gen_account_in;
Expand All @@ -12,7 +11,9 @@ fn send_tx_with_different_chain_id() {
// Given
let (sender_id, sender_keypair) = gen_account_in("wonderland");
let (receiver_id, _receiver_keypair) = gen_account_in("wonderland");
let asset_definition_id = AssetDefinitionId::from_str("test_asset#wonderland").unwrap();
let asset_definition_id = "test_asset#wonderland"
.parse::<AssetDefinitionId>()
.unwrap();
let to_transfer = numeric!(1);

let create_sender_account: InstructionBox =
Expand Down
6 changes: 4 additions & 2 deletions core/benches/blocks/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,16 @@ pub fn create_block(
.sign(key_pair);
let limits = state.transaction_executor().transaction_limits;

let topology = Topology::new(UniqueVec::new());
let (peer_public_key, _) = KeyPair::random().into_parts();
let peer_id = PeerId::new("127.0.0.1:8080".parse().unwrap(), peer_public_key);
let topology = Topology::new(vec![peer_id]);
let block = BlockBuilder::new(
vec![AcceptedTransaction::accept(transaction, &chain_id, &limits).unwrap()],
topology.clone(),
Vec::new(),
)
.chain(0, state)
.sign(key_pair)
.sign(key_pair.private_key())
.unpack(|_| {})
.commit(&topology)
.unpack(|_| {})
Expand Down
12 changes: 7 additions & 5 deletions core/benches/kura.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use iroha_core::{
};
use iroha_crypto::KeyPair;
use iroha_data_model::{prelude::*, transaction::TransactionLimits};
use iroha_primitives::unique_vec::UniqueVec;
use test_samples::gen_account_in;
use tokio::{fs, runtime::Runtime};

Expand Down Expand Up @@ -47,17 +46,20 @@ async fn measure_block_size_for_n_executors(n_executors: u32) {

let query_handle = LiveQueryStore::test().start();
let state = State::new(World::new(), kura, query_handle);
let topology = Topology::new(UniqueVec::new());
let (peer_public_key, peer_private_key) = KeyPair::random().into_parts();
let peer_id = PeerId::new("127.0.0.1:8080".parse().unwrap(), peer_public_key);
let topology = Topology::new(vec![peer_id]);
let mut block = {
let mut state_block = state.block();
BlockBuilder::new(vec![tx], topology, Vec::new())
BlockBuilder::new(vec![tx], topology.clone(), Vec::new())
.chain(0, &mut state_block)
.sign(&KeyPair::random())
.sign(&peer_private_key)
.unpack(|_| {})
};

let key_pair = KeyPair::random();
for _ in 1..n_executors {
block = block.sign(&KeyPair::random());
block.sign(&key_pair, &topology);
}
let mut block_store = BlockStore::new(dir.path(), LockStatus::Unlocked);
block_store.create_files_if_they_do_not_exist().unwrap();
Expand Down
Loading

0 comments on commit b044546

Please sign in to comment.