diff --git a/crates/core/src/client_events.rs b/crates/core/src/client_events.rs index bea9bf9d4..2e36f35aa 100644 --- a/crates/core/src/client_events.rs +++ b/crates/core/src/client_events.rs @@ -508,7 +508,7 @@ pub(crate) mod test { continue; } let request = ContractRequest::Update { - key: contract.key().clone(), + key: contract.key(), data: new_state, }; if state.owns_contracts.contains(&contract.key()) { diff --git a/crates/core/src/client_events/websocket.rs b/crates/core/src/client_events/websocket.rs index 117dac7a8..5d68f2db4 100644 --- a/crates/core/src/client_events/websocket.rs +++ b/crates/core/src/client_events/websocket.rs @@ -92,7 +92,7 @@ impl WebSocketProxy { let (tx, rx) = tokio::sync::mpsc::unbounded_channel(); if let Some(ch) = self.response_channels.get(&client_id) { ch.send(HostCallbackResult::SubscriptionChannel { - key: key.clone(), + key: *key, id: client_id, callback: rx, }) diff --git a/crates/core/src/config.rs b/crates/core/src/config.rs index 48e295f4d..b111bab2a 100644 --- a/crates/core/src/config.rs +++ b/crates/core/src/config.rs @@ -312,7 +312,7 @@ impl ConfigArgs { is_gateway: self.network_listener.is_gateway, }; - fs::create_dir_all(&this.config_dir())?; + fs::create_dir_all(this.config_dir())?; if should_persist { let mut file = File::create(this.config_dir().join("config.toml"))?; file.write_all( diff --git a/crates/core/src/contract.rs b/crates/core/src/contract.rs index 0f1d55f01..2d5206c0d 100644 --- a/crates/core/src/contract.rs +++ b/crates/core/src/contract.rs @@ -38,7 +38,7 @@ where } => { match contract_handler .executor() - .fetch_contract(key.clone(), fetch_contract) + .fetch_contract(key, fetch_contract) .instrument(tracing::info_span!("fetch_contract", %key, %fetch_contract)) .await { @@ -89,12 +89,7 @@ where } => { let put_result = contract_handler .executor() - .upsert_contract_state( - key.clone(), - Either::Left(state), - related_contracts, - contract, - ) + .upsert_contract_state(key, Either::Left(state), related_contracts, contract) .instrument(tracing::info_span!("upsert_contract_state", %key)) .await; contract_handler @@ -119,7 +114,7 @@ where let update_result = contract_handler .executor() .upsert_contract_state( - key.clone(), + key, Either::Left(state.clone()), related_contracts, None, diff --git a/crates/core/src/contract/executor.rs b/crates/core/src/contract/executor.rs index eb21f2227..4e434f85e 100644 --- a/crates/core/src/contract/executor.rs +++ b/crates/core/src/contract/executor.rs @@ -77,7 +77,7 @@ impl ExecutorError { if let RuntimeInnerError::ContractExecError(e) = error { if let Some(InnerOpError::Upsert(key)) = &op { - return ExecutorError::request(StdContractError::update_exec_error(key.clone(), e)); + return ExecutorError::request(StdContractError::update_exec_error(*key, e)); } } @@ -419,11 +419,6 @@ pub(crate) trait ContractExecutor: Send + 'static { fetch_contract: bool, ) -> impl Future), ExecutorError>> + Send; - fn store_contract( - &mut self, - contract: ContractContainer, - ) -> impl Future> + Send; - fn upsert_contract_state( &mut self, key: ContractKey, diff --git a/crates/core/src/contract/executor/mock_runtime.rs b/crates/core/src/contract/executor/mock_runtime.rs index 84406479b..5b53d9c9b 100644 --- a/crates/core/src/contract/executor/mock_runtime.rs +++ b/crates/core/src/contract/executor/mock_runtime.rs @@ -75,14 +75,6 @@ impl ContractExecutor for Executor { Ok((state, contract)) } - async fn store_contract(&mut self, contract: ContractContainer) -> Result<(), ExecutorError> { - self.runtime - .contract_store - .store_contract(contract) - .map_err(ExecutorError::other)?; - Ok(()) - } - async fn upsert_contract_state( &mut self, key: ContractKey, diff --git a/crates/core/src/contract/executor/runtime.rs b/crates/core/src/contract/executor/runtime.rs index c8d4c3c53..7eb180e1e 100644 --- a/crates/core/src/contract/executor/runtime.rs +++ b/crates/core/src/contract/executor/runtime.rs @@ -21,13 +21,6 @@ impl ContractExecutor for Executor { } } - async fn store_contract(&mut self, contract: ContractContainer) -> Result<(), ExecutorError> { - self.runtime - .contract_store - .store_contract(contract) - .map_err(ExecutorError::other) - } - async fn upsert_contract_state( &mut self, key: ContractKey, @@ -44,7 +37,7 @@ impl ContractExecutor for Executor { .map_err(ExecutorError::other)? .ok_or_else(|| { ExecutorError::request(StdContractError::Put { - key: key.clone(), + key, cause: "missing contract parameters".into(), }) })? @@ -57,9 +50,7 @@ impl ContractExecutor for Executor { .is_none() { let code = code.ok_or_else(|| { - ExecutorError::request(StdContractError::MissingContract { - key: key.clone().into(), - }) + ExecutorError::request(StdContractError::MissingContract { key: key.into() }) })?; self.runtime .contract_store @@ -187,7 +178,7 @@ impl Executor { notification_ch: tokio::sync::mpsc::UnboundedSender, summary: Option>, ) -> Result<(), Box> { - let channels = self.update_notifications.entry(key.clone()).or_default(); + let channels = self.update_notifications.entry(key).or_default(); if let Ok(i) = channels.binary_search_by_key(&&cli_id, |(p, _)| p) { let (_, existing_ch) = &channels[i]; if !existing_ch.same_channel(¬ification_ch) { @@ -203,7 +194,7 @@ impl Executor { if self .subscriber_summaries - .entry(key.clone()) + .entry(key) .or_default() .insert(cli_id, summary.map(StateSummary::into_owned)) .is_some() @@ -284,9 +275,9 @@ impl Executor { ContractRequest::Subscribe { key, summary } => { let updates = updates.ok_or_else(|| ExecutorError::other("missing update channel"))?; - self.register_contract_notifier(key.clone(), cli_id, updates, summary)?; + self.register_contract_notifier(key, cli_id, updates, summary)?; // by default a subscribe op has an implicit get - let res = self.perform_contract_get(false, key.clone()).await?; + let res = self.perform_contract_get(false, key).await?; #[cfg(any( all(not(feature = "local-mode"), not(feature = "network-mode")), all(feature = "local-mode", feature = "network-mode"), @@ -424,7 +415,7 @@ impl Executor { .await .map_err(|_| { ExecutorError::request(StdContractError::Put { - key: key.clone(), + key, cause: "failed while sending notifications".into(), }) })?; @@ -444,7 +435,7 @@ impl Executor { .ok_or_else(|| { RequestError::ContractError(StdContractError::Update { cause: "missing contract parameters".into(), - key: key.clone(), + key, }) })? }; @@ -458,7 +449,7 @@ impl Executor { let updates = vec![update]; let new_state = self - .get_updated_state(¶meters, current_state, key.clone(), updates) + .get_updated_state(¶meters, current_state, key, updates) .await?; // in the network impl this would be sent over the network @@ -485,10 +476,7 @@ impl Executor { } } // notify peers with deltas from summary in network - let request = UpdateContract { - key: key.clone(), - new_state, - }; + let request = UpdateContract { key, new_state }; let _op: operations::update::UpdateResult = self.op_request(request).await?; } @@ -513,7 +501,7 @@ impl Executor { Err(err) => { return Err(ExecutorError::execution( err, - Some(InnerOpError::Upsert(key.clone())), + Some(InnerOpError::Upsert(*key)), )) } }; @@ -670,14 +658,14 @@ impl Executor { let Some(contract) = self.get_contract_locally(&key).await? else { return Err(ExecutorError::request(RequestError::from( StdContractError::Get { - key: key.clone(), + key, cause: "Missing contract and/or parameters".into(), }, ))); }; got_contract = Some(contract); } else if fetch_contract { - got_contract = self.get_contract_from_network(key.clone()).await?; + got_contract = self.get_contract_from_network(key).await?; } } @@ -690,7 +678,7 @@ impl Executor { else { return Err(ExecutorError::request(RequestError::from( StdContractError::Get { - key: key.clone(), + key, cause: "Missing contract or parameters".into(), }, ))); @@ -703,7 +691,7 @@ impl Executor { if let Ok(Some(contract)) = self.get_contract_locally(&key).await { got_contract = Some(fetch_contract); } else { - got_contract = self.get_contract_from_network(key.clone()).await?; + got_contract = self.get_contract_from_network(key).await?; } } @@ -757,7 +745,7 @@ impl Executor { const DEPENDENCY_CYCLE_LIMIT_GUARD: usize = 100; let mut iterations = 0; - let original_key = key.clone(); + let original_key = key; let original_state = state.clone(); let original_params = params.clone(); let mut trying_key = key; @@ -837,21 +825,17 @@ impl Executor { if !is_valid { return Err(ExecutorError::request(StdContractError::Put { - key: trying_key.clone(), + key: trying_key, cause: "not valid".into(), })); } self.state_store - .store( - trying_key.clone(), - trying_state.clone(), - trying_params.clone(), - ) + .store(trying_key, trying_state.clone(), trying_params.clone()) .await .map_err(ExecutorError::other)?; if trying_key != original_key { - trying_key = original_key.clone(); + trying_key = original_key; trying_params = original_params.clone(); trying_state = original_state.clone(); continue; @@ -873,8 +857,9 @@ impl Executor { new_state: &WrappedState, ) -> Result<(), ExecutorError> { tracing::debug!(contract = %key, "notify of contract update"); - if let Some(notifiers) = self.update_notifications.get_mut(key) { - let summaries = self.subscriber_summaries.get_mut(key).unwrap(); + let key = *key; + if let Some(notifiers) = self.update_notifications.get_mut(&key) { + let summaries = self.subscriber_summaries.get_mut(&key).unwrap(); // in general there should be less than 32 failures let mut failures = Vec::with_capacity(32); for (peer_key, notifier) in notifiers.iter() { @@ -882,20 +867,19 @@ impl Executor { let update = match peer_summary { Some(summary) => self .runtime - .get_state_delta(key, params, new_state, &*summary) + .get_state_delta(&key, params, new_state, &*summary) .map_err(|err| { tracing::error!("{err}"); - ExecutorError::execution(err, Some(InnerOpError::Upsert(key.clone()))) + ExecutorError::execution(err, Some(InnerOpError::Upsert(key))) })? .to_owned() .into(), None => UpdateData::State(State::from(new_state.as_ref()).into_owned()), }; - if let Err(err) = notifier.send(Ok(ContractResponse::UpdateNotification { - key: key.clone(), - update, - } - .into())) + if let Err(err) = + notifier.send(Ok( + ContractResponse::UpdateNotification { key, update }.into() + )) { failures.push(*peer_key); tracing::error!(cli_id = %peer_key, "{err}"); @@ -985,10 +969,7 @@ impl Executor { ))); } } - match self - .local_state_or_from_network(&key.clone().into()) - .await? - { + match self.local_state_or_from_network(&key.into()).await? { Either::Right(GetResult { state, contract, .. }) => { diff --git a/crates/core/src/contract/handler.rs b/crates/core/src/contract/handler.rs index 4dbe50ddc..8dcfc8634 100644 --- a/crates/core/src/contract/handler.rs +++ b/crates/core/src/contract/handler.rs @@ -5,7 +5,6 @@ use std::sync::atomic::{AtomicU64, Ordering::SeqCst}; use std::sync::Arc; use std::time::Duration; -use freenet_stdlib::client_api::{ClientError, ClientRequest, HostResponse}; use freenet_stdlib::prelude::*; use serde::{Deserialize, Serialize}; use tokio::sync::mpsc::{self, UnboundedReceiver, UnboundedSender}; @@ -67,15 +66,6 @@ pub(crate) trait ContractHandler { fn channel(&mut self) -> &mut ContractHandlerChannel; - /// # Arguments - /// - updates: channel to send back updates from contracts to whoever is subscribed to the contract. - fn handle_request<'a, 's: 'a>( - &'s mut self, - req: ClientRequest<'a>, - client_id: ClientId, - updates: Option>>, - ) -> impl Future> + Send + 'a; - fn executor(&mut self) -> &mut Self::ContractExecutor; } @@ -104,19 +94,6 @@ impl ContractHandler for NetworkContractHandler { &mut self.channel } - async fn handle_request<'a, 's: 'a>( - &'s mut self, - req: ClientRequest<'a>, - client_id: ClientId, - updates: Option>>, - ) -> Result { - let res = self - .executor - .handle_request(client_id, req, updates) - .await?; - Ok(res) - } - fn executor(&mut self) -> &mut Self::ContractExecutor { &mut self.executor } @@ -143,19 +120,6 @@ impl ContractHandler for NetworkContractHandler { &mut self.channel } - async fn handle_request<'a, 's: 'a>( - &'s mut self, - req: ClientRequest<'a>, - client_id: ClientId, - updates: Option>>, - ) -> Result { - let res = self - .executor - .handle_request(client_id, req, updates) - .await?; - Ok(res) - } - fn executor(&mut self) -> &mut Self::ContractExecutor { &mut self.executor } @@ -470,10 +434,6 @@ pub mod test { } pub(super) mod in_memory { - use crate::client_events::ClientId; - use freenet_stdlib::client_api::{ClientError, ClientRequest, HostResponse}; - use tokio::sync::mpsc::UnboundedSender; - use super::{ super::{ executor::{ExecutorHalve, ExecutorToEventLoopChannel}, @@ -522,15 +482,6 @@ pub(super) mod in_memory { &mut self.channel } - async fn handle_request<'a, 's: 'a>( - &'s mut self, - _req: ClientRequest<'a>, - _client_id: ClientId, - _updates: Option>>, - ) -> Result { - unreachable!() - } - fn executor(&mut self) -> &mut Self::ContractExecutor { &mut self.runtime } diff --git a/crates/core/src/message.rs b/crates/core/src/message.rs index fc20645c9..61e76aad8 100644 --- a/crates/core/src/message.rs +++ b/crates/core/src/message.rs @@ -232,11 +232,7 @@ pub(crate) trait MessageStats { fn target(&self) -> Option; - fn terminal(&self) -> bool; - fn requested_location(&self) -> Option; - - fn track_stats(&self) -> bool; } #[derive(Debug, Serialize, Deserialize)] @@ -296,8 +292,6 @@ pub(crate) trait InnerMessage: Into { fn target(&self) -> Option>; - fn terminal(&self) -> bool; - fn requested_location(&self) -> Option; } @@ -348,23 +342,11 @@ impl MessageStats for NetMessage { } } - fn terminal(&self) -> bool { - match self { - NetMessage::V1(msg) => msg.terminal(), - } - } - fn requested_location(&self) -> Option { match self { NetMessage::V1(msg) => msg.requested_location(), } } - - fn track_stats(&self) -> bool { - match self { - NetMessage::V1(msg) => msg.track_stats(), - } - } } impl MessageStats for NetMessageV1 { @@ -392,18 +374,6 @@ impl MessageStats for NetMessageV1 { } } - fn terminal(&self) -> bool { - match self { - NetMessageV1::Connect(op) => op.terminal(), - NetMessageV1::Put(op) => op.terminal(), - NetMessageV1::Get(op) => op.terminal(), - NetMessageV1::Subscribe(op) => op.terminal(), - NetMessageV1::Update(op) => op.terminal(), - NetMessageV1::Aborted(_) => true, - NetMessageV1::Unsubscribed { .. } => true, - } - } - fn requested_location(&self) -> Option { match self { NetMessageV1::Connect(op) => op.requested_location(), @@ -415,13 +385,6 @@ impl MessageStats for NetMessageV1 { NetMessageV1::Unsubscribed { .. } => None, } } - - fn track_stats(&self) -> bool { - !matches!( - self, - NetMessageV1::Connect(_) | NetMessageV1::Subscribe(_) | NetMessageV1::Aborted(_) - ) - } } impl Display for NetMessage { diff --git a/crates/core/src/node.rs b/crates/core/src/node.rs index ff0eb82fd..92eea4e52 100644 --- a/crates/core/src/node.rs +++ b/crates/core/src/node.rs @@ -754,7 +754,7 @@ async fn process_message_v1( .await; } NetMessageV1::Unsubscribed { ref key, .. } => { - subscribe(op_manager, key.clone(), None).await; + subscribe(op_manager, *key, None).await; break; } _ => break, // Exit the loop if no applicable message type is found @@ -769,7 +769,7 @@ async fn subscribe(op_manager: Arc, key: ContractKey, client_id: Opti let timeout = tokio::time::timeout(TIMEOUT, async { // Initialize a subscribe op. loop { - let op = subscribe::start_op(key.clone()); + let op = subscribe::start_op(key); if let Some(client_id) = client_id { let _ = op_manager .ch_outbound @@ -782,7 +782,7 @@ async fn subscribe(op_manager: Arc, key: ContractKey, client_id: Opti { tracing::info!(%key, "Trying to subscribe to a contract not present, requesting it first"); missing_contract = true; - let get_op = get::start_op(key.clone(), true); + let get_op = get::start_op(key, true); if let Err(error) = get::request_get(&op_manager, get_op).await { tracing::error!(%key, %error, "Failed getting the contract while previously trying to subscribe; bailing"); break Err(error); @@ -927,7 +927,7 @@ impl PeerId { } thread_local! { - static PEER_ID: std::cell::RefCell> = std::cell::RefCell::new(None); + static PEER_ID: std::cell::RefCell> = const { std::cell::RefCell::new(None) }; } #[cfg(test)] diff --git a/crates/core/src/node/network_bridge/p2p_protoc.rs b/crates/core/src/node/network_bridge/p2p_protoc.rs index cfb571ead..70c3f2fad 100644 --- a/crates/core/src/node/network_bridge/p2p_protoc.rs +++ b/crates/core/src/node/network_bridge/p2p_protoc.rs @@ -225,7 +225,7 @@ impl P2pConnManager { Some(Err(err)) => { tracing::error!("Error in peer connection: {err}"); if let TransportError::ConnectionClosed(socket_addr) = err { - if let Some(peer) = self.connections.keys().find_map(|k| (&k.addr == &socket_addr).then(|| k.clone())) { + if let Some(peer) = self.connections.keys().find_map(|k| (k.addr == socket_addr).then(|| k.clone())) { op_manager.ring.prune_connection(peer.clone()).await; self.connections.remove(&peer); } @@ -676,16 +676,14 @@ impl P2pConnManager { conn.send(net_msg) .await .map_err(|_| ConnectionError::SendNotCompleted(peer))?; + } else if let Some(conn) = self.connections.get(&peer) { + tracing::debug!(target = %peer, "Connection status: {}", if conn.is_closed() { "closed" } else { "open" }); + conn.send(Either::Left(*net_msg)) + .await + .map_err(|_| ConnectionError::SendNotCompleted(peer))?; } else { - if let Some(conn) = self.connections.get(&peer) { - tracing::debug!(target = %peer, "Connection status: {}", conn.is_closed().then(|| "closed").unwrap_or("open")); - conn.send(Either::Left(*net_msg)) - .await - .map_err(|_| ConnectionError::SendNotCompleted(peer))?; - } else { - tracing::error!(target = %peer, "Connection likely dropped"); - return Err(ConnectionError::SendNotCompleted(peer)); - } + tracing::error!(target = %peer, "Connection likely dropped"); + return Err(ConnectionError::SendNotCompleted(peer)); } Ok(connection.map(Either::Right).unwrap_or(Either::Left(()))) diff --git a/crates/core/src/node/testing_impl/in_memory.rs b/crates/core/src/node/testing_impl/in_memory.rs index c5c3a766f..127745bce 100644 --- a/crates/core/src/node/testing_impl/in_memory.rs +++ b/crates/core/src/node/testing_impl/in_memory.rs @@ -102,7 +102,7 @@ where let key: ContractKey = contract.key(); self.op_manager .notify_contract_handler(ContractHandlerEvent::PutQuery { - key: key.clone(), + key, state, related_contracts: RelatedContracts::default(), contract: Some(contract), @@ -114,7 +114,7 @@ where self.op_manager.ring.get_peer_key().unwrap() ); if subscription { - self.op_manager.ring.seed_contract(key.clone()); + self.op_manager.ring.seed_contract(key); } if let Some(subscribers) = contract_subscribers.get(&key) { // add contract subscribers diff --git a/crates/core/src/operations.rs b/crates/core/src/operations.rs index 99efd3e18..0987fa2bf 100644 --- a/crates/core/src/operations.rs +++ b/crates/core/src/operations.rs @@ -306,7 +306,7 @@ impl From> for OpError { /// If the contract is not found, it will try to get it first if the `try_get` parameter is set. async fn start_subscription_request(op_manager: &OpManager, key: ContractKey, try_get: bool) { - let sub_op = subscribe::start_op(key.clone()); + let sub_op = subscribe::start_op(key); if let Err(error) = subscribe::request_subscribe(op_manager, sub_op).await { if !try_get { tracing::warn!(%error, "Error subscribing to contract"); @@ -314,7 +314,7 @@ async fn start_subscription_request(op_manager: &OpManager, key: ContractKey, tr } if let OpError::ContractError(ContractError::ContractNotFound(key)) = &error { tracing::debug!(%key, "Contract not found, trying to get it first"); - let get_op = get::start_op(key.clone(), true); + let get_op = get::start_op(*key, true); if let Err(error) = get::request_get(op_manager, get_op).await { tracing::warn!(%error, "Error getting contract"); } diff --git a/crates/core/src/operations/connect.rs b/crates/core/src/operations/connect.rs index 4382a211d..889b97ea6 100644 --- a/crates/core/src/operations/connect.rs +++ b/crates/core/src/operations/connect.rs @@ -684,8 +684,8 @@ impl ConnectState { /// # Arguments /// /// - gateways: Inmutable list of known gateways. Passed when starting up the node. -/// After the initial connections through the gateways are established all other connections -/// (to gateways or regular peers) will be treated as regular connections. +/// After the initial connections through the gateways are established all other connections +/// (to gateways or regular peers) will be treated as regular connections. /// /// - is_gateway: Whether this peer is a gateway or not. pub(crate) async fn initial_join_procedure( @@ -1045,17 +1045,6 @@ mod messages { } } - fn terminal(&self) -> bool { - use ConnectMsg::*; - matches!( - self, - Response { - msg: ConnectResponse::AcceptedBy { .. }, - .. - } | Connected { .. } - ) - } - fn requested_location(&self) -> Option { self.target().and_then(|pkloc| pkloc.borrow().location) } diff --git a/crates/core/src/operations/get.rs b/crates/core/src/operations/get.rs index 286271097..48488cea5 100644 --- a/crates/core/src/operations/get.rs +++ b/crates/core/src/operations/get.rs @@ -33,12 +33,12 @@ pub(crate) fn start_op(key: ContractKey, fetch_contract: bool) -> GetOp { id, state, result: None, - stats: Some(GetStats { + stats: Some(Box::new(GetStats { contract_location, next_peer: None, transfer_time: None, first_response_time: None, - }), + })), } } @@ -137,6 +137,7 @@ struct GetStats { transfer_time: Option<(Instant, Option)>, } +#[derive(Clone)] pub(crate) struct GetResult { key: ContractKey, pub state: WrappedState, @@ -158,7 +159,7 @@ pub(crate) struct GetOp { pub id: Transaction, state: Option, pub(super) result: Option, - stats: Option, + stats: Option>, } impl GetOp { @@ -174,7 +175,7 @@ impl GetOp { transfer_time: Some((transfer_start, Some(transfer_end))), .. }, - )) = self.result.as_ref().zip(self.stats.as_ref()) + )) = self.result.as_ref().zip(self.stats.as_deref()) { let payload_size = state.size() + contract @@ -205,7 +206,7 @@ impl GetOp { contract, }) => Ok(HostResponse::ContractResponse( freenet_stdlib::client_api::ContractResponse::GetResponse { - key: key.clone(), + key: *key, contract: contract.clone(), state: state.clone(), }, @@ -286,15 +287,15 @@ impl Operation for GetOp { )); tracing::info!(tx = %id, %key, target = %target.peer, "Seek contract"); new_state = self.state; - stats = Some(GetStats { + stats = Some(Box::new(GetStats { contract_location: Location::from(key), next_peer: None, transfer_time: None, first_response_time: None, - }); + })); let own_loc = op_manager.ring.own_location(); return_msg = Some(GetMsg::SeekNode { - key: key.clone(), + key: *key, id: *id, target: target.clone(), sender: own_loc.clone(), @@ -314,7 +315,7 @@ impl Operation for GetOp { } => { let htl = *htl; let id = *id; - let key: ContractKey = key.clone(); + let key: ContractKey = *key; let fetch_contract = *fetch_contract; let this_peer = target.clone(); @@ -324,7 +325,7 @@ impl Operation for GetOp { let get_result = op_manager .notify_contract_handler(ContractHandlerEvent::GetQuery { - key: key.clone(), + key, fetch_contract, }) .await; @@ -436,7 +437,7 @@ impl Operation for GetOp { { return_msg = Some(GetMsg::SeekNode { id: *id, - key: key.clone(), + key: *key, target, sender: this_peer.clone(), fetch_contract, @@ -444,7 +445,7 @@ impl Operation for GetOp { skip_list: new_skip_list.clone(), }); } else { - return Err(RingError::NoCachingPeers(key.clone()).into()); + return Err(RingError::NoCachingPeers(*key).into()); } new_state = Some(GetState::AwaitingResponse { retries: retries + 1, @@ -469,7 +470,7 @@ impl Operation for GetOp { new_state = None; return_msg = Some(GetMsg::ReturnGet { id: *id, - key: key.clone(), + key: *key, value: StoreResponse { state: None, contract: None, @@ -495,7 +496,7 @@ impl Operation for GetOp { skip_list, } => { let id = *id; - let key = key.clone(); + let key = *key; let require_contract = matches!( self.state, Some(GetState::AwaitingResponse { @@ -552,7 +553,7 @@ impl Operation for GetOp { if should_put { let res = op_manager .notify_contract_handler(ContractHandlerEvent::PutQuery { - key: key.clone(), + key, state: value.clone(), related_contracts: RelatedContracts::default(), // fixme: i think we need to get the related contracts so the final put is ok contract: contract.clone(), @@ -564,12 +565,7 @@ impl Operation for GetOp { op_manager.ring.is_seeding_contract(&key); if !is_subscribed_contract && should_subscribe { tracing::debug!(tx = %id, %key, peer = %op_manager.ring.get_peer_key().unwrap(), "Contract not cached @ peer, caching"); - super::start_subscription_request( - op_manager, - key.clone(), - false, - ) - .await; + super::start_subscription_request(op_manager, key, false).await; } } ContractHandlerEvent::PutResponse { @@ -618,7 +614,7 @@ impl Operation for GetOp { new_state = None; return_msg = None; result = Some(GetResult { - key: key.clone(), + key, state: value.clone(), contract: contract.clone(), }); @@ -631,7 +627,7 @@ impl Operation for GetOp { new_state = None; return_msg = Some(GetMsg::ReturnGet { id, - key: key.clone(), + key, value: StoreResponse { state: Some(value.clone()), contract: contract.clone(), @@ -641,7 +637,7 @@ impl Operation for GetOp { skip_list: skip_list.clone(), }); result = Some(GetResult { - key: key.clone(), + key, state: value.clone(), contract: contract.clone(), }); @@ -682,7 +678,7 @@ fn build_op_result( state: Option, msg: Option, result: Option, - stats: Option, + stats: Option>, ) -> Result { let output_op = Some(GetOp { id, @@ -703,7 +699,7 @@ async fn try_forward_or_return( (this_peer, sender): (PeerKeyLocation, PeerKeyLocation), skip_list: &[PeerId], op_manager: &OpManager, - stats: Option, + stats: Option>, ) -> Result { tracing::warn!( tx = %id, @@ -834,11 +830,6 @@ mod messages { } } - fn terminal(&self) -> bool { - use GetMsg::*; - matches!(self, ReturnGet { .. }) - } - fn requested_location(&self) -> Option { match self { GetMsg::RequestGet { key, .. } => Some(Location::from(key.id())), @@ -886,9 +877,9 @@ mod test { let mut gen = arbitrary::Unstructured::new(&bytes); let contract: WrappedContract = gen.arbitrary()?; let contract_val: WrappedState = gen.arbitrary()?; - let key = contract.key().clone(); + let key = *contract.key(); let get_event = ContractRequest::Get { - key: key.clone(), + key, fetch_contract: true, } .into(); @@ -940,10 +931,10 @@ mod test { let bytes = crate::util::test::random_bytes_1kb(); let mut gen = arbitrary::Unstructured::new(&bytes); let contract: WrappedContract = gen.arbitrary()?; - let key = contract.key().clone(); + let key = *contract.key(); let get_event = ContractRequest::Get { - key: key.clone(), + key, fetch_contract: false, } .into(); @@ -979,10 +970,10 @@ mod test { let mut gen = arbitrary::Unstructured::new(&bytes); let contract: WrappedContract = gen.arbitrary()?; let contract_val: WrappedState = gen.arbitrary()?; - let key = contract.key().clone(); + let key = *contract.key(); let get_event = ContractRequest::Get { - key: key.clone(), + key, fetch_contract: false, } .into(); diff --git a/crates/core/src/operations/put.rs b/crates/core/src/operations/put.rs index eb80b6ddd..c4d3bbbd1 100644 --- a/crates/core/src/operations/put.rs +++ b/crates/core/src/operations/put.rs @@ -63,7 +63,7 @@ impl PutOp { pub(super) fn to_host_result(&self) -> HostResult { if let Some(PutState::Finished { key }) = &self.state { Ok(HostResponse::ContractResponse( - freenet_stdlib::client_api::ContractResponse::PutResponse { key: key.clone() }, + freenet_stdlib::client_api::ContractResponse::PutResponse { key: *key }, )) } else { Err(ErrorKind::OperationError { @@ -189,7 +189,7 @@ impl Operation for PutOp { tracing::debug!(tx = %id, "Attempting contract value update"); put_contract( op_manager, - key.clone(), + key, value.clone(), related_contracts.clone(), contract, @@ -219,7 +219,7 @@ impl Operation for PutOp { // if already subscribed the value was already put and merging succeeded put_contract( op_manager, - key.clone(), + key, value.clone(), RelatedContracts::default(), contract, @@ -231,7 +231,7 @@ impl Operation for PutOp { // should put in this location, no hops left put_contract( op_manager, - key.clone(), + key, value.clone(), RelatedContracts::default(), contract, @@ -248,7 +248,7 @@ impl Operation for PutOp { op_manager, self.state, (broadcast_to, sender.clone()), - key.clone(), + key, (contract.clone(), value.clone()), ) .await @@ -272,7 +272,7 @@ impl Operation for PutOp { tracing::debug!("Attempting contract value update"); let new_value = put_contract( op_manager, - key.clone(), + *key, new_value.clone(), RelatedContracts::default(), contract, @@ -293,7 +293,7 @@ impl Operation for PutOp { op_manager, self.state, (broadcast_to, sender.clone()), - key.clone(), + *key, (contract.clone(), new_value), ) .await @@ -321,7 +321,7 @@ impl Operation for PutOp { for peer in broadcast_to.iter() { let msg = PutMsg::BroadcastTo { id: *id, - key: key.clone(), + key: *key, new_value: new_value.clone(), sender: sender.clone(), contract: contract.clone(), @@ -364,7 +364,7 @@ impl Operation for PutOp { return_msg = Some(PutMsg::SuccessfulPut { id: *id, target: upstream.clone(), - key: key.clone(), + key: *key, }); new_state = None; } @@ -374,8 +374,7 @@ impl Operation for PutOp { let is_subscribed_contract = op_manager.ring.is_seeding_contract(&key); if !is_subscribed_contract && op_manager.ring.should_seed(&key) { tracing::debug!(tx = %id, %key, peer = %op_manager.ring.get_peer_key().unwrap(), "Contract not cached @ peer, caching"); - super::start_subscription_request(op_manager, key.clone(), true) - .await; + super::start_subscription_request(op_manager, key, true).await; } tracing::info!( tx = %id, @@ -383,7 +382,7 @@ impl Operation for PutOp { this_peer = %op_manager.ring.get_peer_key().unwrap(), "Peer completed contract value put", ); - new_state = Some(PutState::Finished { key: key.clone() }); + new_state = Some(PutState::Finished { key }); if let Some(upstream) = upstream { return_msg = Some(PutMsg::SuccessfulPut { id: *id, @@ -419,7 +418,7 @@ impl Operation for PutOp { // after the contract has been cached, push the update query put_contract( op_manager, - key.clone(), + key, new_value.clone(), RelatedContracts::default(), contract, @@ -447,14 +446,14 @@ impl Operation for PutOp { // if already subscribed the value was already put and merging succeeded put_contract( op_manager, - key.clone(), + key, new_value.clone(), RelatedContracts::default(), contract, ) .await?; let (dropped_contract, old_subscribers) = - op_manager.ring.seed_contract(key.clone()); + op_manager.ring.seed_contract(key); if let Some(key) = dropped_contract { for subscriber in old_subscribers { conn_manager @@ -462,7 +461,7 @@ impl Operation for PutOp { &subscriber.peer, NetMessage::V1(NetMessageV1::Unsubscribed { transaction: Transaction::new::(), - key: key.clone(), + key, from: op_manager.ring.get_peer_key().unwrap(), }), ) @@ -475,7 +474,7 @@ impl Operation for PutOp { // should put in this location, no hops left put_contract( op_manager, - key.clone(), + key, new_value.clone(), RelatedContracts::default(), contract, @@ -491,7 +490,7 @@ impl Operation for PutOp { op_manager, self.state, (broadcast_to, sender.clone()), - key.clone(), + key, (contract.clone(), new_value.clone()), ) .await @@ -594,7 +593,7 @@ async fn try_to_broadcast( return_msg = Some(PutMsg::SuccessfulPut { id, target: upstream, - key: key.clone(), + key, }); } } @@ -884,14 +883,6 @@ mod messages { } } - fn terminal(&self) -> bool { - use PutMsg::*; - matches!( - self, - SuccessfulPut { .. } | SeekNode { .. } | PutForward { .. } - ) - } - fn requested_location(&self) -> Option { match self { Self::SeekNode { contract, .. } => Some(Location::from(contract.id())), @@ -947,7 +938,7 @@ mod test { let bytes = crate::util::test::random_bytes_1kb(); let mut gen = arbitrary::Unstructured::new(&bytes); let contract: WrappedContract = gen.arbitrary()?; - let key = contract.key().clone(); + let key = *contract.key(); let contract_val: WrappedState = gen.arbitrary()?; let new_value = WrappedState::new(Vec::from_iter(gen.arbitrary::<[u8; 20]>().unwrap())); @@ -1000,7 +991,7 @@ mod test { false, )], events_to_generate: HashMap::from_iter([(1, put_event)]), - contract_subscribers: HashMap::from_iter([(key.clone(), vec![node0_loc, node1_loc])]), + contract_subscribers: HashMap::from_iter([(key, vec![node0_loc, node1_loc])]), }; // establish network diff --git a/crates/core/src/operations/subscribe.rs b/crates/core/src/operations/subscribe.rs index 56da91f72..44f305345 100644 --- a/crates/core/src/operations/subscribe.rs +++ b/crates/core/src/operations/subscribe.rs @@ -65,9 +65,9 @@ pub(crate) async fn request_subscribe( sub_op: SubscribeOp, ) -> Result<(), OpError> { let (target, _id) = if let Some(SubscribeState::PrepareRequest { id, key }) = &sub_op.state { - if !super::has_contract(op_manager, key.clone()).await? { + if !super::has_contract(op_manager, *key).await? { return Err(OpError::ContractError(ContractError::ContractNotFound( - key.clone(), + *key, ))); } const EMPTY: &[PeerId] = &[]; @@ -77,7 +77,7 @@ pub(crate) async fn request_subscribe( .closest_potentially_caching(key, EMPTY) .into_iter() .next() - .ok_or_else(|| RingError::NoCachingPeers(key.clone()))?, + .ok_or_else(|| RingError::NoCachingPeers(*key))?, *id, ) } else { @@ -198,7 +198,7 @@ impl Operation for SubscribeOp { new_state = self.state; return_msg = Some(SubscribeMsg::SeekNode { id: *id, - key: key.clone(), + key: *key, target: target.clone(), subscriber: sender.clone(), skip_list: vec![sender.peer], @@ -219,7 +219,7 @@ impl Operation for SubscribeOp { let return_not_subbed = || -> OperationResult { OperationResult { return_msg: Some(NetMessage::from(SubscribeMsg::ReturnSub { - key: key.clone(), + key: *key, id: *id, subscribed: false, sender: this_peer.clone(), @@ -229,7 +229,7 @@ impl Operation for SubscribeOp { } }; - if !super::has_contract(op_manager, key.clone()).await? { + if !super::has_contract(op_manager, *key).await? { tracing::debug!(tx = %id, %key, "Contract not found, trying other peer"); let Some(new_target) = op_manager @@ -261,7 +261,7 @@ impl Operation for SubscribeOp { }), (SubscribeMsg::SeekNode { id: *id, - key: key.clone(), + key: *key, subscriber: this_peer, target: new_target, skip_list: new_skip_list, @@ -295,7 +295,7 @@ impl Operation for SubscribeOp { sender: target.clone(), target: subscriber.clone(), id: *id, - key: key.clone(), + key: *key, subscribed: true, }); } @@ -334,7 +334,7 @@ impl Operation for SubscribeOp { let subscriber = op_manager.ring.own_location(); return_msg = Some(SubscribeMsg::SeekNode { id: *id, - key: key.clone(), + key: *key, subscriber, target, skip_list: skip_list.clone(), @@ -342,7 +342,7 @@ impl Operation for SubscribeOp { retries: retries + 1, }); } else { - return Err(RingError::NoCachingPeers(key.clone()).into()); + return Err(RingError::NoCachingPeers(*key).into()); } new_state = Some(SubscribeState::AwaitingResponse { skip_list, @@ -385,7 +385,7 @@ impl Operation for SubscribeOp { if let Some(upstream_subscriber) = upstream_subscriber { return_msg = Some(SubscribeMsg::ReturnSub { id: *id, - key: key.clone(), + key: *key, sender: target.clone(), target: upstream_subscriber, subscribed: true, @@ -473,11 +473,6 @@ mod messages { } } - fn terminal(&self) -> bool { - use SubscribeMsg::*; - matches!(self, ReturnSub { .. } | SeekNode { .. }) - } - fn requested_location(&self) -> Option { match self { Self::SeekNode { key, .. } => Some(Location::from(key.id())), @@ -528,10 +523,10 @@ mod test { let mut gen = arbitrary::Unstructured::new(&bytes); let contract: WrappedContract = gen.arbitrary()?; let contract_val: WrappedState = gen.arbitrary()?; - let contract_key: ContractKey = contract.key().clone(); + let contract_key: ContractKey = *contract.key(); let event = ContractRequest::Subscribe { - key: contract_key.clone(), + key: contract_key, summary: None, } .into(); diff --git a/crates/core/src/operations/update.rs b/crates/core/src/operations/update.rs index 0b98d1758..518a2b5e8 100644 --- a/crates/core/src/operations/update.rs +++ b/crates/core/src/operations/update.rs @@ -50,7 +50,7 @@ impl UpdateOp { if let Some(UpdateState::Finished { key, summary }) = &self.state { Ok(HostResponse::ContractResponse( freenet_stdlib::client_api::ContractResponse::UpdateResponse { - key: key.clone(), + key: *key, summary: summary.clone(), }, )) @@ -171,7 +171,7 @@ impl Operation for UpdateOp { sender, target: target.clone(), value: value.clone(), - key: key.clone(), + key: *key, related_contracts: related_contracts.clone(), }); @@ -199,13 +199,8 @@ impl Operation for UpdateOp { if is_subscribed_contract { tracing::debug!("Peer is subscribed to contract. About to update it"); - update_contract( - op_manager, - key.clone(), - value.clone(), - related_contracts.clone(), - ) - .await?; + update_contract(op_manager, *key, value.clone(), related_contracts.clone()) + .await?; tracing::debug!( tx = %id, "Successfully updated a value for contract {} @ {:?} - update", @@ -214,7 +209,7 @@ impl Operation for UpdateOp { ); } else { tracing::debug!("contract not found in this peer. Should throw an error"); - return Err(OpError::RingError(RingError::NoCachingPeers(key.clone()))); + return Err(OpError::RingError(RingError::NoCachingPeers(*key))); } match try_to_broadcast( @@ -223,7 +218,7 @@ impl Operation for UpdateOp { op_manager, self.state, (broadcast_to, sender.clone()), - key.clone(), + *key, value.clone(), false, ) @@ -252,7 +247,7 @@ impl Operation for UpdateOp { tracing::debug!("Attempting contract value update - BroadcastTo - update"); let new_value = update_contract( op_manager, - key.clone(), + *key, new_value.clone(), RelatedContracts::default(), ) @@ -273,7 +268,7 @@ impl Operation for UpdateOp { op_manager, self.state, (broadcast_to, sender.clone()), - key.clone(), + *key, new_value, true, ) @@ -302,7 +297,7 @@ impl Operation for UpdateOp { for peer in broadcast_to.iter() { let msg = UpdateMsg::BroadcastTo { id: *id, - key: key.clone(), + key: *key, new_value: new_value.clone(), sender: sender.clone(), }; @@ -609,7 +604,7 @@ pub(crate) async fn request_update( op_manager .ring .add_subscriber(key, sender) - .map_err(|_| RingError::NoCachingPeers(key.clone()))?; + .map_err(|_| RingError::NoCachingPeers(*key))?; closest }; @@ -626,7 +621,7 @@ pub(crate) async fn request_update( related_contracts, }) => { let new_state = Some(UpdateState::AwaitingResponse { - key: key.clone(), + key, upstream: None, }); let msg = UpdateMsg::RequestUpdate { @@ -733,11 +728,6 @@ mod messages { } } - fn terminal(&self) -> bool { - use UpdateMsg::*; - matches!(self, SuccessfulUpdate { .. } | SeekNode { .. }) - } - fn requested_location(&self) -> Option { match self { UpdateMsg::RequestUpdate { key, .. } => Some(Location::from(key.id())), diff --git a/crates/core/src/ring.rs b/crates/core/src/ring.rs index 0418a75c2..00080a267 100644 --- a/crates/core/src/ring.rs +++ b/crates/core/src/ring.rs @@ -432,13 +432,12 @@ impl Ring { let mut old_subscribers = vec![]; let mut contract_to_drop = None; if self.seeding_contract.len() < Self::MAX_SEEDING_CONTRACTS { - let dropped_contract = self + let dropped_contract = *self .seeding_contract .iter() .min_by_key(|v| *v.value()) .unwrap() - .key() - .clone(); + .key(); self.seeding_contract.remove(&dropped_contract); if let Some((_, mut subscribers_of_contract)) = self.subscribers.remove(&dropped_contract) @@ -668,7 +667,7 @@ impl Ring { pub fn register_subscription(&self, contract: &ContractKey, subscriber: PeerKeyLocation) { self.subscribers - .entry(contract.clone()) + .entry(*contract) .or_insert(Vec::with_capacity(Self::TOTAL_MAX_SUBSCRIPTIONS)) .value_mut() .push(subscriber); @@ -682,7 +681,7 @@ impl Ring { ) -> Result<(), ()> { let mut subs = self .subscribers - .entry(contract.clone()) + .entry(*contract) .or_insert(Vec::with_capacity(Self::TOTAL_MAX_SUBSCRIPTIONS)); if subs.len() >= Self::MAX_SUBSCRIBERS { return Err(()); @@ -724,7 +723,7 @@ impl Ring { { let conns = &mut *self.connections_by_location.write(); if let Some(conns) = conns.get_mut(&loc) { - if let Some(pos) = conns.iter().position(|c| &c.location.peer == &peer) { + if let Some(pos) = conns.iter().position(|c| c.location.peer == peer) { conns.swap_remove(pos); } } diff --git a/crates/core/src/router/isotonic_estimator.rs b/crates/core/src/router/isotonic_estimator.rs index 874ecd425..ed0f1ebde 100644 --- a/crates/core/src/router/isotonic_estimator.rs +++ b/crates/core/src/router/isotonic_estimator.rs @@ -32,7 +32,7 @@ impl IsotonicEstimator { let mut peer_events: HashMap> = HashMap::new(); for event in history { - let point = Point::new(event.route_distance().as_f64(), event.result.clone()); + let point = Point::new(event.route_distance().as_f64(), event.result); all_points.push(point); peer_events @@ -308,12 +308,7 @@ mod tests { peer: PeerKeyLocation, contract_location: Location, ) -> IsotonicEvent { - let distance: f64 = peer - .location - .clone() - .unwrap() - .distance(contract_location) - .as_f64(); + let distance: f64 = peer.location.unwrap().distance(contract_location).as_f64(); let result = distance.powf(0.5) + peer.peer.clone().to_bytes()[0] as f64; IsotonicEvent { @@ -327,12 +322,7 @@ mod tests { peer: PeerKeyLocation, contract_location: Location, ) -> IsotonicEvent { - let distance: f64 = peer - .location - .clone() - .unwrap() - .distance(contract_location) - .as_f64(); + let distance: f64 = peer.location.unwrap().distance(contract_location).as_f64(); let result = (100.0 - distance).powf(0.5) + peer.peer.clone().to_bytes()[0] as f64; IsotonicEvent { diff --git a/crates/core/src/server/path_handlers.rs b/crates/core/src/server/path_handlers.rs index f2fbbcf4f..094913f01 100644 --- a/crates/core/src/server/path_handlers.rs +++ b/crates/core/src/server/path_handlers.rs @@ -34,7 +34,7 @@ pub(super) async fn contract_home( request_sender .send(ClientConnection::NewConnection { callbacks: response_sender, - assigned_token: Some((assigned_token, key.clone().into())), + assigned_token: Some((assigned_token, key.into())), }) .await .map_err(|err| WebSocketApiError::NodeError { @@ -53,7 +53,7 @@ pub(super) async fn contract_home( client_id, req: Box::new( ContractRequest::Get { - key: key.clone(), + key, fetch_contract: true, } .into(), diff --git a/crates/core/src/tracing.rs b/crates/core/src/tracing.rs index 0196489d6..8d6a19d3c 100644 --- a/crates/core/src/tracing.rs +++ b/crates/core/src/tracing.rs @@ -232,7 +232,7 @@ impl<'a> NetEventLog<'a> { id: *id, requester: op_manager.ring.get_peer_key().unwrap(), target: target.clone(), - key: key.clone(), + key: *key, }) } NetMessageV1::Put(PutMsg::Broadcasting { @@ -242,7 +242,7 @@ impl<'a> NetEventLog<'a> { .. }) => EventKind::Put(PutEvent::BroadcastEmitted { broadcast_to: broadcast_to.clone(), - key: key.clone(), + key: *key, value: new_value.clone(), }), NetMessageV1::Put(PutMsg::BroadcastTo { @@ -252,21 +252,21 @@ impl<'a> NetEventLog<'a> { .. }) => EventKind::Put(PutEvent::BroadcastReceived { requester: sender.peer.clone(), - key: key.clone(), + key: *key, value: new_value.clone(), }), NetMessageV1::Get(GetMsg::ReturnGet { key, value: StoreResponse { state: Some(_), .. }, .. - }) => EventKind::Get { key: key.clone() }, + }) => EventKind::Get { key: *key }, NetMessageV1::Subscribe(SubscribeMsg::ReturnSub { subscribed: true, key, sender, .. }) => EventKind::Subscribed { - key: key.clone(), + key: *key, at: sender.clone(), }, _ => EventKind::Ignored, @@ -1116,10 +1116,10 @@ pub(super) mod test { let mut was_received = false; for ev in events { match ev { - PutEvent::BroadcastEmitted { key, .. } if key.clone() == *for_key => { + PutEvent::BroadcastEmitted { key, .. } if key == for_key => { was_emitted = true; } - PutEvent::BroadcastReceived { key, .. } if key.clone() == *for_key => { + PutEvent::BroadcastReceived { key, .. } if key == for_key => { was_received = true; } _ => {} diff --git a/crates/core/src/util.rs b/crates/core/src/util.rs index 3403a32ca..1e0908bd3 100644 --- a/crates/core/src/util.rs +++ b/crates/core/src/util.rs @@ -100,6 +100,7 @@ impl ExponentialBackoff { } } +#[allow(clippy::result_unit_err)] pub fn get_free_port() -> Result { let mut port; for _ in 0..100 { diff --git a/crates/core/src/wasm_runtime/contract_store.rs b/crates/core/src/wasm_runtime/contract_store.rs index 3942cec97..3e7418308 100644 --- a/crates/core/src/wasm_runtime/contract_store.rs +++ b/crates/core/src/wasm_runtime/contract_store.rs @@ -114,7 +114,7 @@ impl ContractStore { pub fn store_contract(&mut self, contract: ContractContainer) -> RuntimeResult<()> { let (key, code) = match contract.clone() { ContractContainer::Wasm(ContractWasmAPIVersion::V1(contract_v1)) => { - (contract_v1.key().clone(), contract_v1.code().clone()) + (*contract_v1.key(), contract_v1.code().clone()) } _ => unimplemented!(), }; diff --git a/crates/core/src/wasm_runtime/runtime.rs b/crates/core/src/wasm_runtime/runtime.rs index ad7b0de0a..0015c0bff 100644 --- a/crates/core/src/wasm_runtime/runtime.rs +++ b/crates/core/src/wasm_runtime/runtime.rs @@ -185,14 +185,14 @@ impl Runtime { let contract = self .contract_store .fetch_contract(key, parameters) - .ok_or_else(|| RuntimeInnerError::ContractNotFound(key.clone()))?; + .ok_or_else(|| RuntimeInnerError::ContractNotFound(*key))?; let module = match contract { ContractContainer::Wasm(ContractWasmAPIVersion::V1(contract_v1)) => { Module::new(&self.wasm_store, contract_v1.code().data())? } _ => unimplemented!(), }; - self.contract_modules.insert(key.clone(), module); + self.contract_modules.insert(*key, module); self.contract_modules.get(key).unwrap() } .clone(); diff --git a/crates/core/src/wasm_runtime/state_store.rs b/crates/core/src/wasm_runtime/state_store.rs index e765bfc0a..958fb1ac6 100644 --- a/crates/core/src/wasm_runtime/state_store.rs +++ b/crates/core/src/wasm_runtime/state_store.rs @@ -82,14 +82,14 @@ where .get(key) .await .map_err(Into::into)? - .ok_or_else(|| StateStoreError::MissingContract(key.clone()))?; + .ok_or_else(|| StateStoreError::MissingContract(*key))?; } self.store - .store(key.clone(), state.clone()) + .store(*key, state.clone()) .await .map_err(Into::into)?; let cost = state.size() as i64; - self.state_mem_cache.insert(key.clone(), state, cost).await; + self.state_mem_cache.insert(*key, state, cost).await; Ok(()) } @@ -100,11 +100,11 @@ where params: Parameters<'static>, ) -> Result<(), StateStoreError> { self.store - .store(key.clone(), state.clone()) + .store(key, state.clone()) .await .map_err(Into::into)?; let cost = state.size() as i64; - self.state_mem_cache.insert(key.clone(), state, cost).await; + self.state_mem_cache.insert(key, state, cost).await; self.store .store_params(key, params.clone()) .await @@ -119,7 +119,7 @@ where return Ok(v.value().clone()); } let r = self.store.get(key).await.map_err(Into::into)?; - r.ok_or_else(|| StateStoreError::MissingContract(key.clone())) + r.ok_or_else(|| StateStoreError::MissingContract(*key)) } pub async fn get_params<'a>( diff --git a/crates/fdev/src/config.rs b/crates/fdev/src/config.rs index a9ede5673..9eb107815 100644 --- a/crates/fdev/src/config.rs +++ b/crates/fdev/src/config.rs @@ -44,11 +44,8 @@ pub enum SubCommand { impl SubCommand { pub fn is_child(&self) -> bool { if let SubCommand::Test(config) = self { - match &config.command { - crate::testing::TestMode::Network(config) => { - return matches!(config.mode, crate::testing::network::Process::Peer); - } - _ => {} + if let crate::testing::TestMode::Network(config) = &config.command { + return matches!(config.mode, crate::testing::network::Process::Peer); } } false diff --git a/crates/fdev/src/util.rs b/crates/fdev/src/util.rs index 576b0ce5d..dd0fe78a7 100644 --- a/crates/fdev/src/util.rs +++ b/crates/fdev/src/util.rs @@ -21,11 +21,6 @@ where let deser = serde_json::from_slice(data.as_ref())?; Ok(deser) } - #[cfg(feature = "messagepack")] - Some(DeserializationFmt::MessagePack) => { - let deser = rmp_serde::decode::from_read(data.as_ref())?; - Ok(deser) - } _ => Ok(bincode::deserialize(data.as_ref())?), } } diff --git a/crates/fdev/src/wasm_runtime/user_events.rs b/crates/fdev/src/wasm_runtime/user_events.rs index a93f63f9f..a09b2f98d 100644 --- a/crates/fdev/src/wasm_runtime/user_events.rs +++ b/crates/fdev/src/wasm_runtime/user_events.rs @@ -124,18 +124,6 @@ impl StdInput { tracing::debug!("{cmd:?} value:\n{json_str}"); Ok(json_str.into_bytes().into()) } - #[cfg(feature = "messagepack")] - Some(DeserializationFmt::MessagePack) => { - let mut buf = vec![]; - self.input.read_to_end(&mut buf).unwrap(); - let state = rmpv::decode::read_value_ref(&mut buf.as_ref()).map_err(|e| { - Box::new(ClientError::from(ErrorKind::Unhandled { - cause: format!("deserialization error: {e}"), - })) - })?; - tracing::debug!("{cmd:?} value:\n{state}"); - Ok(buf.into()) - } _ => { let state: Vec = self.read_input().map_err(|e| { Box::new(ClientError::from(ErrorKind::Unhandled { diff --git a/stdlib b/stdlib index 90b319249..7cde4e789 160000 --- a/stdlib +++ b/stdlib @@ -1 +1 @@ -Subproject commit 90b319249f80ccd82827091f36ac8faae8999566 +Subproject commit 7cde4e7895afe3dc00694f9b3aba6dc4b3223eaa