Skip to content

Commit

Permalink
Fix clippy warnings (#1120)
Browse files Browse the repository at this point in the history
  • Loading branch information
al8n authored Jun 8, 2024
1 parent b534bb4 commit 287b2d4
Show file tree
Hide file tree
Showing 30 changed files with 156 additions and 355 deletions.
2 changes: 1 addition & 1 deletion crates/core/src/client_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/client_events/websocket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
11 changes: 3 additions & 8 deletions crates/core/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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
Expand All @@ -119,7 +114,7 @@ where
let update_result = contract_handler
.executor()
.upsert_contract_state(
key.clone(),
key,
Either::Left(state.clone()),
related_contracts,
None,
Expand Down
7 changes: 1 addition & 6 deletions crates/core/src/contract/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand Down Expand Up @@ -419,11 +419,6 @@ pub(crate) trait ContractExecutor: Send + 'static {
fetch_contract: bool,
) -> impl Future<Output = Result<(WrappedState, Option<ContractContainer>), ExecutorError>> + Send;

fn store_contract(
&mut self,
contract: ContractContainer,
) -> impl Future<Output = Result<(), ExecutorError>> + Send;

fn upsert_contract_state(
&mut self,
key: ContractKey,
Expand Down
8 changes: 0 additions & 8 deletions crates/core/src/contract/executor/mock_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,6 @@ impl ContractExecutor for Executor<MockRuntime> {
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,
Expand Down
77 changes: 29 additions & 48 deletions crates/core/src/contract/executor/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,6 @@ impl ContractExecutor for Executor<Runtime> {
}
}

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,
Expand All @@ -44,7 +37,7 @@ impl ContractExecutor for Executor<Runtime> {
.map_err(ExecutorError::other)?
.ok_or_else(|| {
ExecutorError::request(StdContractError::Put {
key: key.clone(),
key,
cause: "missing contract parameters".into(),
})
})?
Expand All @@ -57,9 +50,7 @@ impl ContractExecutor for Executor<Runtime> {
.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
Expand Down Expand Up @@ -187,7 +178,7 @@ impl Executor<Runtime> {
notification_ch: tokio::sync::mpsc::UnboundedSender<HostResult>,
summary: Option<StateSummary<'_>>,
) -> Result<(), Box<RequestError>> {
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(&notification_ch) {
Expand All @@ -203,7 +194,7 @@ impl Executor<Runtime> {

if self
.subscriber_summaries
.entry(key.clone())
.entry(key)
.or_default()
.insert(cli_id, summary.map(StateSummary::into_owned))
.is_some()
Expand Down Expand Up @@ -284,9 +275,9 @@ impl Executor<Runtime> {
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"),
Expand Down Expand Up @@ -424,7 +415,7 @@ impl Executor<Runtime> {
.await
.map_err(|_| {
ExecutorError::request(StdContractError::Put {
key: key.clone(),
key,
cause: "failed while sending notifications".into(),
})
})?;
Expand All @@ -444,7 +435,7 @@ impl Executor<Runtime> {
.ok_or_else(|| {
RequestError::ContractError(StdContractError::Update {
cause: "missing contract parameters".into(),
key: key.clone(),
key,
})
})?
};
Expand All @@ -458,7 +449,7 @@ impl Executor<Runtime> {

let updates = vec![update];
let new_state = self
.get_updated_state(&parameters, current_state, key.clone(), updates)
.get_updated_state(&parameters, current_state, key, updates)
.await?;

// in the network impl this would be sent over the network
Expand All @@ -485,10 +476,7 @@ impl Executor<Runtime> {
}
}
// 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?;
}

Expand All @@ -513,7 +501,7 @@ impl Executor<Runtime> {
Err(err) => {
return Err(ExecutorError::execution(
err,
Some(InnerOpError::Upsert(key.clone())),
Some(InnerOpError::Upsert(*key)),
))
}
};
Expand Down Expand Up @@ -670,14 +658,14 @@ impl Executor<Runtime> {
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?;
}
}

Expand All @@ -690,7 +678,7 @@ impl Executor<Runtime> {
else {
return Err(ExecutorError::request(RequestError::from(
StdContractError::Get {
key: key.clone(),
key,
cause: "Missing contract or parameters".into(),
},
)));
Expand All @@ -703,7 +691,7 @@ impl Executor<Runtime> {
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?;
}
}

Expand Down Expand Up @@ -757,7 +745,7 @@ impl Executor<Runtime> {
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;
Expand Down Expand Up @@ -837,21 +825,17 @@ impl Executor<Runtime> {

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;
Expand All @@ -873,29 +857,29 @@ impl Executor<Runtime> {
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() {
let peer_summary = summaries.get_mut(peer_key).unwrap();
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}");
Expand Down Expand Up @@ -985,10 +969,7 @@ impl Executor<Runtime> {
)));
}
}
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, ..
}) => {
Expand Down
Loading

0 comments on commit 287b2d4

Please sign in to comment.