Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor!: don't send public key with signature #4518

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.

36 changes: 30 additions & 6 deletions cli/src/lib.rs
Expand Up @@ -80,7 +80,7 @@ struct IrohaMainState {
/// A boolean value indicating whether or not the peers will receive data from the network.
/// Used in sumeragi testing.
#[cfg(debug_assertions)]
pub freeze_status: Arc<AtomicBool>,
pub freeze_status: FreezeStatus,
}

/// A state of [`Iroha`] for when the network is started, but [`Torii`] not yet.
Expand Down Expand Up @@ -118,14 +118,37 @@ pub enum StartError {
StartTorii,
}

/// Handle for freezing and unfreezing the network
#[derive(Clone)]
#[cfg(debug_assertions)]
pub struct FreezeStatus(Arc<AtomicBool>, PeerId);

#[cfg(debug_assertions)]
impl FreezeStatus {
pub(crate) fn new(peer_id: PeerId) -> Self {
Self(Arc::new(AtomicBool::new(false)), peer_id)
}

/// Stop listening for messages
pub fn freeze(&self) {
iroha_logger::warn!(peer_id=%self.1, "NetworkRelay is frozen");
self.0.store(true, Ordering::SeqCst);
}
/// Start listening for messages
pub fn unfreeze(&self) {
iroha_logger::warn!(peer_id=%self.1, "NetworkRelay is unfrozen");
self.0.store(false, Ordering::SeqCst);
}
}

struct NetworkRelay {
sumeragi: SumeragiHandle,
block_sync: BlockSynchronizerHandle,
gossiper: TransactionGossiperHandle,
network: IrohaNetwork,
shutdown_notify: Arc<Notify>,
#[cfg(debug_assertions)]
freeze_status: Arc<AtomicBool>,
freeze_status: FreezeStatus,
}

impl NetworkRelay {
Expand Down Expand Up @@ -156,7 +179,7 @@ impl NetworkRelay {
use iroha_core::NetworkMessage::*;

#[cfg(debug_assertions)]
if self.freeze_status.load(Ordering::SeqCst) {
if self.freeze_status.0.load(Ordering::SeqCst) {
return;
}

Expand Down Expand Up @@ -330,7 +353,7 @@ impl Iroha<ToriiNotStarted> {
&config.block_sync,
sumeragi.clone(),
Arc::clone(&kura),
config.common.peer_id(),
config.common.peer_id.clone(),
network.clone(),
Arc::clone(&state),
)
Expand All @@ -346,7 +369,8 @@ impl Iroha<ToriiNotStarted> {
.start();

#[cfg(debug_assertions)]
let freeze_status = Arc::new(AtomicBool::new(false));
let freeze_status = FreezeStatus::new(config.common.peer_id.clone());
Arc::new(AtomicBool::new(false));

let notify_shutdown = Arc::new(Notify::new());

Expand Down Expand Up @@ -564,7 +588,7 @@ impl Iroha<ToriiNotStarted> {
impl<T> Iroha<T> {
#[allow(missing_docs)]
#[cfg(debug_assertions)]
pub fn freeze_status(&self) -> &Arc<AtomicBool> {
pub fn freeze_status(&self) -> &FreezeStatus {
&self.main_state.freeze_status
}

Expand Down
2 changes: 0 additions & 2 deletions cli/src/samples.rs
Expand Up @@ -60,8 +60,6 @@ pub fn get_config_toml(
let (public_key, private_key) = peer_key_pair.into_parts();
let (genesis_public_key, genesis_private_key) = genesis_key_pair.into_parts();

iroha_logger::info!(%public_key, "sample configuration public key");

let mut raw = toml::Table::new();
iroha_config::base::toml::Writer::new(&mut raw)
.write("chain_id", chain_id)
Expand Down
2 changes: 1 addition & 1 deletion client/benches/tps/utils.rs
Expand Up @@ -5,11 +5,11 @@ use iroha_client::{
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
Expand Up @@ -2,8 +2,10 @@
use std::{thread, time::Duration};

use iroha::samples::{construct_executor, get_config};
use iroha_client::{crypto::KeyPair, data_model::prelude::*};
use iroha_data_model::isi::InstructionBox;
use iroha_client::{
crypto::KeyPair,
data_model::{isi::InstructionBox, prelude::*},
};
use iroha_genesis::{GenesisNetwork, RawGenesisBlock, RawGenesisBlockBuilder};
use iroha_primitives::unique_vec;
use test_network::{
Expand Down
6 changes: 4 additions & 2 deletions client/examples/register_1000_triggers.rs
Expand Up @@ -3,8 +3,10 @@
use std::str::FromStr;

use iroha::samples::{construct_executor, get_config};
use iroha_client::{client::Client, data_model::prelude::*};
use iroha_data_model::trigger::TriggerId;
use iroha_client::{
client::Client,
data_model::{prelude::*, trigger::TriggerId},
};
use iroha_genesis::{GenesisNetwork, RawGenesisBlock, RawGenesisBlockBuilder};
use iroha_primitives::unique_vec;
use test_network::{
Expand Down
34 changes: 7 additions & 27 deletions client/src/client.rs
Expand Up @@ -14,13 +14,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 @@ -35,9 +28,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 @@ -67,24 +65,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 @@ -476,7 +456,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
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.
6 changes: 3 additions & 3 deletions client/src/query_builder.rs
@@ -1,10 +1,10 @@
use std::fmt::Debug;

use iroha_data_model::query::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, Pagination, Query, QueryOutputBox,
},
};

pub struct QueryRequestBuilder<'a, R> {
Expand Down
12 changes: 6 additions & 6 deletions client/tests/integration/asset.rs
Expand Up @@ -4,14 +4,14 @@ use eyre::Result;
use iroha_client::{
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
@@ -1,6 +1,5 @@
use eyre::Result;
use iroha_client::data_model::prelude::*;
use iroha_data_model::transaction::error::TransactionRejectionReason;
use iroha_client::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
Expand Up @@ -4,19 +4,17 @@ use eyre::Result;
use iroha_client::{
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
11 changes: 5 additions & 6 deletions client/tests/integration/extra_functional/unstable_network.rs
@@ -1,4 +1,3 @@
use core::sync::atomic::Ordering;
use std::thread;

use iroha_client::{
Expand All @@ -14,7 +13,7 @@ use tokio::runtime::Runtime;
const MAX_TRANSACTIONS_IN_BLOCK: u32 = 5;

#[test]
fn unstable_network_4_peers_1_fault() {
fn unstable_network_5_peers_1_fault() {
let n_peers = 4;
let n_transactions = 20;
unstable_network(n_peers, 1, n_transactions, false, 10_805);
Expand All @@ -28,15 +27,15 @@ fn soft_fork() {
}

#[test]
fn unstable_network_7_peers_1_fault() {
fn unstable_network_8_peers_1_fault() {
let n_peers = 7;
let n_transactions = 20;
unstable_network(n_peers, 1, n_transactions, false, 10_850);
}

#[test]
#[ignore = "This test does not guarantee to have positive outcome given a fixed time."]
fn unstable_network_7_peers_2_faults() {
fn unstable_network_9_peers_2_faults() {
unstable_network(7, 2, 5, false, 10_890);
}

Expand Down Expand Up @@ -97,7 +96,7 @@ fn unstable_network(
for _i in 0..n_transactions {
// Make random peers faulty.
for f in freezers.choose_multiple(&mut rng, n_offline_peers as usize) {
f.store(true, Ordering::SeqCst);
f.freeze();
}

let quantity = Numeric::ONE;
Expand Down Expand Up @@ -129,7 +128,7 @@ fn unstable_network(

// Return all peers to normal function.
for f in &freezers {
f.store(false, Ordering::SeqCst);
f.unfreeze();
}
}
}
3 changes: 1 addition & 2 deletions client/tests/integration/non_mintable.rs
Expand Up @@ -3,9 +3,8 @@ use std::str::FromStr as _;
use eyre::Result;
use iroha_client::{
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