diff --git a/Cargo.lock b/Cargo.lock index 33fc39067ec..7a20653c141 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3497,7 +3497,6 @@ dependencies = [ "iroha_futures", "iroha_logger", "iroha_primitives", - "iroha_test_network", "parity-scale-codec", "rand", "thiserror", @@ -3665,7 +3664,6 @@ dependencies = [ name = "iroha_telemetry_derive" version = "2.0.0-rc.1.0" dependencies = [ - "iroha_core", "iroha_macro_utils", "manyhow", "proc-macro2", @@ -3685,7 +3683,6 @@ dependencies = [ "futures", "iroha", "iroha_config", - "iroha_core", "iroha_crypto", "iroha_data_model", "iroha_executor_data_model", diff --git a/crates/iroha/Cargo.toml b/crates/iroha/Cargo.toml index 0c1b753c0f7..0295f640e62 100644 --- a/crates/iroha/Cargo.toml +++ b/crates/iroha/Cargo.toml @@ -51,8 +51,7 @@ tls-rustls-webpki-roots = [ iroha_config = { workspace = true } iroha_config_base = { workspace = true } iroha_crypto = { workspace = true } -# FIXME: should remove `transparent_api` feature. Check the other FIXME comment in dev-dependencies -iroha_data_model = { workspace = true, features = ["http", "transparent_api"] } +iroha_data_model = { workspace = true, features = ["http"] } iroha_executor_data_model = { workspace = true } iroha_primitives = { workspace = true } iroha_logger = { workspace = true } diff --git a/crates/iroha_config_base/src/toml.rs b/crates/iroha_config_base/src/toml.rs index 2b7ab4adb1a..bbfd7547229 100644 --- a/crates/iroha_config_base/src/toml.rs +++ b/crates/iroha_config_base/src/toml.rs @@ -289,6 +289,7 @@ impl<'a> From<&'a mut Table> for Writer<'a> { /// Extension trait to implement writing with [`Writer`] directly into [`Table`] in a chained manner. pub trait WriteExt: Sized { /// See [`Writer::write`]. + #[must_use] fn write(self, path: P, value: T) -> Self; } diff --git a/crates/iroha_ffi/src/ir.rs b/crates/iroha_ffi/src/ir.rs index 3d84f84a7ac..4cbbd9293ca 100644 --- a/crates/iroha_ffi/src/ir.rs +++ b/crates/iroha_ffi/src/ir.rs @@ -124,14 +124,26 @@ pub trait IrTypeFamily { } impl IrTypeFamily for R { - type Ref<'itm> = &'itm Self where Self: 'itm; + type Ref<'itm> + = &'itm Self + where + Self: 'itm; // NOTE: Unused - type RefMut<'itm> = () where Self: 'itm; + type RefMut<'itm> + = () + where + Self: 'itm; type Box = Box; type BoxedSlice = Box<[Self]>; - type RefSlice<'itm> = &'itm [Self] where Self: 'itm; + type RefSlice<'itm> + = &'itm [Self] + where + Self: 'itm; // NOTE: Unused - type RefMutSlice<'itm> = () where Self: 'itm; + type RefMutSlice<'itm> + = () + where + Self: 'itm; type Vec = Vec; type Arr = [Self; N]; } @@ -166,22 +178,46 @@ impl IrTypeFamily for Transparent { type Arr = Self; } impl IrTypeFamily for &Extern { - type Ref<'itm> = &'itm Self where Self: 'itm; - type RefMut<'itm> = &'itm mut Self where Self: 'itm; + type Ref<'itm> + = &'itm Self + where + Self: 'itm; + type RefMut<'itm> + = &'itm mut Self + where + Self: 'itm; type Box = Box; type BoxedSlice = Box<[Self]>; - type RefSlice<'itm> = &'itm [Self] where Self: 'itm; - type RefMutSlice<'itm> = &'itm mut [Self] where Self: 'itm; + type RefSlice<'itm> + = &'itm [Self] + where + Self: 'itm; + type RefMutSlice<'itm> + = &'itm mut [Self] + where + Self: 'itm; type Vec = Vec; type Arr = [Self; N]; } impl IrTypeFamily for &mut Extern { - type Ref<'itm> = &'itm Self where Self: 'itm; - type RefMut<'itm> = &'itm mut Self where Self: 'itm; + type Ref<'itm> + = &'itm Self + where + Self: 'itm; + type RefMut<'itm> + = &'itm mut Self + where + Self: 'itm; type Box = Box; type BoxedSlice = Box<[Self]>; - type RefSlice<'itm> = &'itm [Self] where Self: 'itm; - type RefMutSlice<'itm> = &'itm mut [Self] where Self: 'itm; + type RefSlice<'itm> + = &'itm [Self] + where + Self: 'itm; + type RefMutSlice<'itm> + = &'itm mut [Self] + where + Self: 'itm; type Vec = Vec; type Arr = [Self; N]; } diff --git a/crates/iroha_p2p/Cargo.toml b/crates/iroha_p2p/Cargo.toml index 6b80621f569..f5090b0df5f 100644 --- a/crates/iroha_p2p/Cargo.toml +++ b/crates/iroha_p2p/Cargo.toml @@ -14,9 +14,7 @@ workspace = true [dependencies] iroha_logger = { workspace = true } iroha_crypto = { workspace = true, default-features = true } -iroha_data_model = { workspace = true, default-features = true, features = [ - "transparent_api", -] } +iroha_data_model = { workspace = true, default-features = true } iroha_primitives = { workspace = true } iroha_config = { workspace = true } iroha_futures = { workspace = true } @@ -39,4 +37,3 @@ bytes = { workspace = true } [dev-dependencies] iroha_config_base = { workspace = true } -iroha_test_network = { workspace = true } diff --git a/crates/iroha_p2p/src/network.rs b/crates/iroha_p2p/src/network.rs index 666e35d7226..b6de6220aa2 100644 --- a/crates/iroha_p2p/src/network.rs +++ b/crates/iroha_p2p/src/network.rs @@ -332,7 +332,7 @@ impl NetworkBase { .iter() // Peer is not connected but should .filter_map(|(peer, is_active)| { - (!self.peers.contains_key(&peer.public_key) + (!self.peers.contains_key(peer.public_key()) && !self .connecting_peers .values() @@ -362,7 +362,7 @@ impl NetworkBase { fn connect_peer(&mut self, peer: &PeerId) { iroha_logger::trace!( - listen_addr = %self.listen_addr, peer.id.address = %peer.address, + listen_addr = %self.listen_addr, peer.id.address = %peer.address(), "Creating new peer actor", ); @@ -372,7 +372,7 @@ impl NetworkBase { let service_message_sender = self.service_message_sender.clone(); connecting::( // NOTE: we intentionally use peer's address and our public key, it's used during handshake - peer.address.clone(), + peer.address().clone(), self.key_pair.clone(), conn_id, service_message_sender, @@ -410,7 +410,7 @@ impl NetworkBase { } // Insert peer if peer not in peers yet or replace peer if it's disambiguator value is smaller than new one (simultaneous connections resolution rule) - match self.peers.get(&peer_id.public_key) { + match self.peers.get(peer_id.public_key()) { Some(peer) if peer.disambiguator > disambiguator => { iroha_logger::debug!( "Peer is disconnected due to simultaneous connection resolution policy" @@ -428,7 +428,7 @@ impl NetworkBase { let ref_peer = RefPeer { handle: ready_peer_handle, conn_id: connection_id, - p2p_addr: peer_id.address.clone(), + p2p_addr: peer_id.address().clone(), disambiguator, }; let _ = peer_message_sender.send(self.peer_message_sender.clone()); @@ -439,10 +439,10 @@ impl NetworkBase { fn peer_terminated(&mut self, Terminated { peer_id, conn_id }: Terminated) { self.connecting_peers.remove(&conn_id); if let Some(peer_id) = peer_id { - if let Some(peer) = self.peers.get(&peer_id.public_key) { + if let Some(peer) = self.peers.get(peer_id.public_key()) { if peer.conn_id == conn_id { iroha_logger::debug!(conn_id, peer=%peer_id, "Peer terminated"); - self.peers.remove(&peer_id.public_key); + self.peers.remove(peer_id.public_key()); Self::remove_online_peer(&self.online_peers_sender, &peer_id); } } @@ -451,11 +451,11 @@ impl NetworkBase { fn post(&mut self, Post { data, peer_id }: Post) { iroha_logger::trace!(peer=%peer_id, "Post message"); - match self.peers.get(&peer_id.public_key) { + match self.peers.get(peer_id.public_key()) { Some(peer) => { if peer.handle.post(data).is_err() { iroha_logger::error!(peer=%peer_id, "Failed to send message to peer"); - self.peers.remove(&peer_id.public_key); + self.peers.remove(peer_id.public_key()); Self::remove_online_peer(&self.online_peers_sender, &peer_id); } } diff --git a/crates/iroha_p2p/tests/integration/p2p.rs b/crates/iroha_p2p/tests/integration/p2p.rs index cd33e3843ea..c5911f92f27 100644 --- a/crates/iroha_p2p/tests/integration/p2p.rs +++ b/crates/iroha_p2p/tests/integration/p2p.rs @@ -301,12 +301,12 @@ async fn start_network( barrier: Arc, shutdown_signal: ShutdownSignal, ) -> (PeerId, NetworkHandle) { - info!(peer_addr = %peer.address, "Starting network"); + info!(peer_addr = %peer.address(), "Starting network"); // This actor will get the messages from other peers and increment the counter let actor = TestActor::start(messages); - let PeerId { address, .. } = peer.clone(); + let address = peer.address().clone(); let idle_timeout = Duration::from_secs(60); let config = Config { address: WithOrigin::inline(address), @@ -329,14 +329,14 @@ async fn start_network( tokio::time::timeout(Duration::from_millis(10_000), async { let mut connections = network.wait_online_peers_update(HashSet::len).await; while conn_count != connections { - info!(peer_addr = %peer.address, %connections); + info!(peer_addr = %peer.address(), %connections); connections = network.wait_online_peers_update(HashSet::len).await; } }) .await .expect("Failed to get all connections"); - info!(peer_addr = %peer.address, %conn_count, "Got all connections!"); + info!(peer_addr = %peer.address(), %conn_count, "Got all connections!"); (peer, network) } diff --git a/crates/iroha_schema_derive/src/lib.rs b/crates/iroha_schema_derive/src/lib.rs index 8c1aa43e35d..d05ef94d247 100644 --- a/crates/iroha_schema_derive/src/lib.rs +++ b/crates/iroha_schema_derive/src/lib.rs @@ -221,15 +221,15 @@ pub fn schema_derive(input: TokenStream) -> TokenStream { ); // add trait bounds on field types using the same algorithm that parity scale codec uses - emitter.handle(trait_bounds::add( + trait_bounds::add( &input.ident, &mut input.generics, &input.data, - syn::parse_quote!(iroha_schema::IntoSchema), + &syn::parse_quote!(iroha_schema::IntoSchema), None, false, &syn::parse_quote!(iroha_schema), - )); + ); let impl_type_id = impl_type_id(&mut syn::parse2(original_input).unwrap()); diff --git a/crates/iroha_schema_derive/src/trait_bounds.rs b/crates/iroha_schema_derive/src/trait_bounds.rs index fe9548568a1..07cb309c11e 100644 --- a/crates/iroha_schema_derive/src/trait_bounds.rs +++ b/crates/iroha_schema_derive/src/trait_bounds.rs @@ -1,6 +1,6 @@ -//! Algorithm for generating trait bounds in IntoSchema derive +//! Algorithm for generating trait bounds in `IntoSchema` derive //! -//! Based on https://github.com/paritytech/parity-scale-codec/blob/2c61d4ab70dfa157556430546441cd2deb5031f2/derive/src/trait_bounds.rs +//! Based on use std::iter; @@ -8,7 +8,7 @@ use proc_macro2::Ident; use syn::{ parse_quote, visit::{self, Visit}, - Generics, Result, Type, TypePath, + Generics, Type, TypePath, }; use crate::{IntoSchemaData, IntoSchemaField}; @@ -119,18 +119,18 @@ pub fn add( generics: &mut Generics, data: &IntoSchemaData, // custom_trait_bound: Option>, - codec_bound: syn::Path, - codec_skip_bound: Option, + codec_bound: &syn::Path, + codec_skip_bound: Option<&syn::Path>, dumb_trait_bounds: bool, crate_path: &syn::Path, -) -> Result<()> { +) { let skip_type_params = Vec::::new(); // NOTE: not implementing custom trait bounds for now // can be implemented later if needed // = match custom_trait_bound { // Some(CustomTraitBound::SpecifiedBounds { bounds, .. }) => { // generics.make_where_clause().predicates.extend(bounds); - // return Ok(()); + // return; // } // Some(CustomTraitBound::SkipTypeParams { type_names, .. }) => { // type_names.into_iter().collect::>() @@ -144,13 +144,13 @@ pub fn add( .map(|tp| tp.ident.clone()) .collect::>(); if ty_params.is_empty() { - return Ok(()); + return; } let codec_types = - get_types_to_add_trait_bound(input_ident, data, &ty_params, dumb_trait_bounds)?; + get_types_to_add_trait_bound(input_ident, data, &ty_params, dumb_trait_bounds); - let compact_types = collect_types(data, |t| t.codec_attrs.compact)? + let compact_types = collect_types(data, |t| t.codec_attrs.compact) .into_iter() // Only add a bound if the type uses a generic .filter(|ty| type_contain_idents(ty, &ty_params)) @@ -158,7 +158,7 @@ pub fn add( let skip_types = if codec_skip_bound.is_some() { let needs_default_bound = |f: &IntoSchemaField| f.codec_attrs.skip; - collect_types(data, needs_default_bound)? + collect_types(data, needs_default_bound) .into_iter() // Only add a bound if the type uses a generic .filter(|ty| type_contain_idents(ty, &ty_params)) @@ -170,27 +170,25 @@ pub fn add( if !codec_types.is_empty() || !compact_types.is_empty() || !skip_types.is_empty() { let where_clause = generics.make_where_clause(); - codec_types.into_iter().for_each(|ty| { + for ty in codec_types { where_clause .predicates .push(parse_quote!(#ty : #codec_bound)) - }); + } - compact_types.into_iter().for_each(|ty| { + for ty in compact_types { where_clause .predicates .push(parse_quote!(#crate_path::Compact<#ty> : #codec_bound)) - }); + } - skip_types.into_iter().for_each(|ty| { + for ty in skip_types { let codec_skip_bound = codec_skip_bound.as_ref(); where_clause .predicates .push(parse_quote!(#ty : #codec_skip_bound)) - }); + } } - - Ok(()) } /// Returns all types that must be added to the where clause with the respective trait bound. @@ -199,16 +197,16 @@ fn get_types_to_add_trait_bound( data: &IntoSchemaData, ty_params: &[Ident], dumb_trait_bound: bool, -) -> Result> { +) -> Vec { if dumb_trait_bound { - Ok(ty_params.iter().map(|t| parse_quote!( #t )).collect()) + ty_params.iter().map(|t| parse_quote!( #t )).collect() } else { let needs_codec_bound = |f: &IntoSchemaField| { !f.codec_attrs.compact && true // utils::get_encoded_as_type(f).is_none() && !f.codec_attrs.skip }; - let res = collect_types(data, needs_codec_bound)? + collect_types(data, needs_codec_bound) .into_iter() // Only add a bound if the type uses a generic .filter(|ty| type_contain_idents(ty, ty_params)) @@ -226,16 +224,11 @@ fn get_types_to_add_trait_bound( // Remove all remaining types that start/contain the input ident to not have them in the // where clause. .filter(|ty| !type_or_sub_type_path_starts_with_ident(ty, input_ident)) - .collect(); - - Ok(res) + .collect() } } -fn collect_types( - data: &IntoSchemaData, - type_filter: fn(&IntoSchemaField) -> bool, -) -> Result> { +fn collect_types(data: &IntoSchemaData, type_filter: fn(&IntoSchemaField) -> bool) -> Vec { let types = match *data { IntoSchemaData::Struct(ref data) => data .fields @@ -258,5 +251,5 @@ fn collect_types( .collect(), }; - Ok(types) + types } diff --git a/crates/iroha_schema_gen/Cargo.toml b/crates/iroha_schema_gen/Cargo.toml index e1c1a416169..9fa7345a374 100644 --- a/crates/iroha_schema_gen/Cargo.toml +++ b/crates/iroha_schema_gen/Cargo.toml @@ -11,6 +11,7 @@ license.workspace = true workspace = true [dependencies] +# TODO: `transparent_api` feature shouldn't be activated/required here iroha_data_model = { workspace = true, features = ["http", "transparent_api"] } iroha_executor_data_model = { workspace = true } diff --git a/crates/iroha_telemetry_derive/Cargo.toml b/crates/iroha_telemetry_derive/Cargo.toml index be453c38274..83973e6c86b 100644 --- a/crates/iroha_telemetry_derive/Cargo.toml +++ b/crates/iroha_telemetry_derive/Cargo.toml @@ -30,6 +30,4 @@ manyhow = { workspace = true } iroha_macro_utils = { workspace = true } [dev-dependencies] -iroha_core = { workspace = true } - trybuild = { workspace = true } diff --git a/crates/iroha_telemetry_derive/tests/ui_fail/not_execute.rs b/crates/iroha_telemetry_derive/tests/ui_fail/not_execute.rs index 3cbfe765c0e..29057ec507e 100644 --- a/crates/iroha_telemetry_derive/tests/ui_fail/not_execute.rs +++ b/crates/iroha_telemetry_derive/tests/ui_fail/not_execute.rs @@ -1,6 +1,7 @@ -use iroha_core::state::StateTransaction; use iroha_telemetry_derive::metrics; +struct StateTransaction; + #[metrics(+"test_query", "another_test_query_without_timing")] fn exequte(_state_transaction: &StateTransaction) -> Result<(), ()> { Ok(()) diff --git a/crates/iroha_telemetry_derive/tests/ui_fail/not_execute.stderr b/crates/iroha_telemetry_derive/tests/ui_fail/not_execute.stderr index 0a80929d8ad..598a97db919 100644 --- a/crates/iroha_telemetry_derive/tests/ui_fail/not_execute.stderr +++ b/crates/iroha_telemetry_derive/tests/ui_fail/not_execute.stderr @@ -1,5 +1,5 @@ error: Function should be an `impl execute` - --> tests/ui_fail/not_execute.rs:5:4 + --> tests/ui_fail/not_execute.rs:6:4 | -5 | fn exequte(_state_transaction: &StateTransaction) -> Result<(), ()> { +6 | fn exequte(_state_transaction: &StateTransaction) -> Result<(), ()> { | ^^^^^^^ diff --git a/crates/iroha_telemetry_derive/tests/ui_fail/not_return_result.rs b/crates/iroha_telemetry_derive/tests/ui_fail/not_return_result.rs index a970bd8aadf..790462027ee 100644 --- a/crates/iroha_telemetry_derive/tests/ui_fail/not_return_result.rs +++ b/crates/iroha_telemetry_derive/tests/ui_fail/not_return_result.rs @@ -1,8 +1,9 @@ use iroha_telemetry_derive::metrics; -use iroha_core::state::StateTransaction; type MyNotResult = Option; +struct StateTransaction; + #[metrics(+"test_query", "another_test_query_without_timing")] fn execute(_state_transaction: &StateTransaction) -> MyNotResult { None diff --git a/crates/iroha_telemetry_derive/tests/ui_fail/not_return_result.stderr b/crates/iroha_telemetry_derive/tests/ui_fail/not_return_result.stderr index ec4fed2ce5e..4eaf1b890ac 100644 --- a/crates/iroha_telemetry_derive/tests/ui_fail/not_return_result.stderr +++ b/crates/iroha_telemetry_derive/tests/ui_fail/not_return_result.stderr @@ -1,5 +1,5 @@ error: Should return `Result`. Found MyNotResult - --> tests/ui_fail/not_return_result.rs:7:54 + --> tests/ui_fail/not_return_result.rs:8:54 | -7 | fn execute(_state_transaction: &StateTransaction) -> MyNotResult { +8 | fn execute(_state_transaction: &StateTransaction) -> MyNotResult { | ^^^^^^^^^^^ diff --git a/crates/iroha_telemetry_derive/tests/ui_fail/return_nothing.rs b/crates/iroha_telemetry_derive/tests/ui_fail/return_nothing.rs index f60bdd6bc7c..071dd9d7f7d 100644 --- a/crates/iroha_telemetry_derive/tests/ui_fail/return_nothing.rs +++ b/crates/iroha_telemetry_derive/tests/ui_fail/return_nothing.rs @@ -1,6 +1,7 @@ -use iroha_core::state::StateTransaction; use iroha_telemetry_derive::metrics; +struct StateTransaction; + #[metrics(+"test_query", "another_test_query_without_timing")] fn execute(_state_transaction: &StateTransaction) { Ok::<(), ()>(()); diff --git a/crates/iroha_telemetry_derive/tests/ui_fail/return_nothing.stderr b/crates/iroha_telemetry_derive/tests/ui_fail/return_nothing.stderr index f92d23ee205..df94191a7b0 100644 --- a/crates/iroha_telemetry_derive/tests/ui_fail/return_nothing.stderr +++ b/crates/iroha_telemetry_derive/tests/ui_fail/return_nothing.stderr @@ -1,7 +1,7 @@ error: `Fn` must return `Result`. Returns nothing instead. - --> tests/ui_fail/return_nothing.rs:4:1 + --> tests/ui_fail/return_nothing.rs:5:1 | -4 | #[metrics(+"test_query", "another_test_query_without_timing")] +5 | #[metrics(+"test_query", "another_test_query_without_timing")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: this error originates in the attribute macro `metrics` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/crates/iroha_test_network/Cargo.toml b/crates/iroha_test_network/Cargo.toml index 9510da71959..98fd4f67099 100644 --- a/crates/iroha_test_network/Cargo.toml +++ b/crates/iroha_test_network/Cargo.toml @@ -8,7 +8,6 @@ authors.workspace = true license.workspace = true [dependencies] -iroha_core.workspace = true iroha.workspace = true iroha_executor_data_model.workspace = true diff --git a/crates/iroha_test_network/src/lib.rs b/crates/iroha_test_network/src/lib.rs index 70190e9f660..01276976b44 100644 --- a/crates/iroha_test_network/src/lib.rs +++ b/crates/iroha_test_network/src/lib.rs @@ -23,7 +23,6 @@ use iroha_config::base::{ read::ConfigReader, toml::{TomlSource, WriteExt as _, Writer as TomlWriter}, }; -pub use iroha_core::state::StateReadOnly; use iroha_crypto::{ExposedPrivateKey, KeyPair, PrivateKey}; use iroha_data_model::{ events::pipeline::BlockEventFilter,