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

Test clippy lint for large futures #2137

Merged
merged 3 commits into from
Jun 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
future-size-threshold = 5000
2 changes: 1 addition & 1 deletion examples/counter/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl Contract for CounterContract {

#[cfg(test)]
mod tests {
use futures::FutureExt;
use futures::FutureExt as _;
use linera_sdk::{
util::BlockingWait,
views::{View, ViewStorageContext},
Expand Down
2 changes: 1 addition & 1 deletion examples/counter/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl QueryRoot {
#[cfg(test)]
mod tests {
use async_graphql::{Request, Response, Value};
use futures::FutureExt;
use futures::FutureExt as _;
use linera_sdk::{
util::BlockingWait,
views::{View, ViewStorageContext},
Expand Down
5 changes: 3 additions & 2 deletions linera-base/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// Copyright (c) Zefchain Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

#![deny(missing_docs)]

//! This module provides a common set of types and library functions that are shared
//! between the Linera protocol (compiled from Rust to native code) and Linera
//! applications (compiled from Rust to Wasm).

#![deny(missing_docs)]
#![deny(clippy::large_futures)]

#[doc(hidden)]
pub use async_trait::async_trait;

Expand Down
2 changes: 2 additions & 0 deletions linera-chain/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

//! This module manages the state of a Linera chain, including cross-chain communication.

#![deny(clippy::large_futures)]

mod chain;
pub mod data_types;
mod inbox;
Expand Down
2 changes: 2 additions & 0 deletions linera-chain/src/unit_tests/chain_tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) Zefchain Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

#![allow(clippy::large_futures)]

use std::{iter, sync::Arc};

use assert_matches::assert_matches;
Expand Down
25 changes: 13 additions & 12 deletions linera-core/src/chain_worker/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::{
sync::Arc,
};

use futures::{future, FutureExt};
use futures::{future, FutureExt as _};
use linera_base::{
crypto::CryptoHash,
data_types::{ArithmeticError, BlockHeight, HashedBlob},
Expand Down Expand Up @@ -189,9 +189,7 @@ where
let local_time = self.storage.clock().current_time();
let signer = block.authenticated_signer;

let executed_block = self
.chain
.execute_block(&block, local_time, None)
let executed_block = Box::pin(self.chain.execute_block(&block, local_time, None))
.await?
.with(block);

Expand Down Expand Up @@ -344,10 +342,11 @@ where
);
self.storage.clock().sleep_until(block.timestamp).await;
let local_time = self.storage.clock().current_time();
let outcome = self
.chain
.execute_block(block, local_time, oracle_records.clone())
.await?;
let outcome = Box::pin(
self.chain
.execute_block(block, local_time, oracle_records.clone()),
)
.await?;
if let Some(lite_certificate) = &validated_block_certificate {
let value = HashedCertificateValue::new_validated(outcome.clone().with(block.clone()));
lite_certificate
Expand Down Expand Up @@ -534,10 +533,12 @@ where
// Execute the block and update inboxes.
self.chain.remove_events_from_inboxes(block).await?;
let local_time = self.storage.clock().current_time();
let verified_outcome = self
.chain
.execute_block(block, local_time, Some(oracle_records.clone()))
.await?;
let verified_outcome = Box::pin(self.chain.execute_block(
block,
local_time,
Some(oracle_records.clone()),
))
.await?;
// We should always agree on the messages and state hash.
ensure!(
*messages == verified_outcome.messages,
Expand Down
2 changes: 1 addition & 1 deletion linera-core/src/join_set_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use std::{
task::{Context, Poll},
};

use futures::FutureExt;
use futures::FutureExt as _;
use tokio::{
sync::oneshot,
task::{AbortHandle, JoinSet},
Expand Down
2 changes: 2 additions & 0 deletions linera-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

//! This module defines the core Linera protocol.

#![deny(clippy::large_futures)]

pub mod chain_worker;
pub mod client;
pub mod data_types;
Expand Down
1 change: 1 addition & 0 deletions linera-core/src/unit_tests/wasm_client_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
// because they are slow and their behavior appears to be correctly check by the
// test with memory.

#![allow(clippy::large_futures)]
#![cfg(any(feature = "wasmer", feature = "wasmtime"))]

use std::collections::BTreeMap;
Expand Down
1 change: 1 addition & 0 deletions linera-core/src/unit_tests/wasm_worker_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//! These tests only run if a Wasm runtime has been configured by enabling either the `wasmer` or
//! the `wasmtime` feature flags.

#![allow(clippy::large_futures)]
#![cfg(any(feature = "wasmer", feature = "wasmtime"))]

use std::sync::Arc;
Expand Down
2 changes: 2 additions & 0 deletions linera-core/src/unit_tests/worker_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Copyright (c) Zefchain Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

#![allow(clippy::large_futures)]

#[path = "./wasm_worker_tests.rs"]
mod wasm;

Expand Down
2 changes: 2 additions & 0 deletions linera-execution/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

//! This module manages the execution of the system application and the user applications in a Linera chain.

#![deny(clippy::large_futures)]

mod applications;
pub mod committee;
mod execution;
Expand Down
2 changes: 1 addition & 1 deletion linera-rpc/src/grpc/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::{
use futures::{
channel::{mpsc, mpsc::Receiver},
future::BoxFuture,
FutureExt, StreamExt,
FutureExt as _, StreamExt,
};
use linera_base::identifiers::ChainId;
use linera_core::{
Expand Down
1 change: 1 addition & 0 deletions linera-rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//! This module provides network abstractions and the data schemas for remote procedure
//! calls (RPCs) in the Linera protocol.

#![deny(clippy::large_futures)]
// `tracing::instrument` is not compatible with this nightly Clippy lint
#![allow(unknown_lints)]
#![allow(clippy::blocks_in_conditions)]
Expand Down
2 changes: 1 addition & 1 deletion linera-sdk/src/test/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::sync::{
};

use dashmap::DashMap;
use futures::FutureExt;
use futures::FutureExt as _;
use linera_base::{
crypto::KeyPair,
data_types::Timestamp,
Expand Down
2 changes: 1 addition & 1 deletion linera-sdk/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ where
mod tests {
use std::task::{Context, Poll};

use futures::{future::poll_fn, task::noop_waker, FutureExt};
use futures::{future::poll_fn, task::noop_waker, FutureExt as _};

use super::{yield_once, BlockingWait};

Expand Down
2 changes: 1 addition & 1 deletion linera-sdk/src/views/mock_key_value_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::{
},
};

use futures::FutureExt;
use futures::FutureExt as _;
use linera_views::{
batch::Batch,
common::{ReadableKeyValueStore, WritableKeyValueStore},
Expand Down
2 changes: 1 addition & 1 deletion linera-service/src/grpc_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use std::{

use anyhow::Result;
use async_trait::async_trait;
use futures::{future::BoxFuture, FutureExt};
use futures::{future::BoxFuture, FutureExt as _};
use linera_base::identifiers::ChainId;
use linera_core::{notifier::Notifier, JoinSetExt as _};
use linera_rpc::{
Expand Down
2 changes: 2 additions & 0 deletions linera-service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

//! This module provides the executables needed to operate a Linera service, including a placeholder wallet acting as a GraphQL service for user interfaces.

#![deny(clippy::large_futures)]

pub mod chain_listener;
pub mod cli_wrappers;
pub mod config;
Expand Down
2 changes: 2 additions & 0 deletions linera-service/src/linera/client_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use std::{env, iter, num::NonZeroU16, path::PathBuf, time::Duration};

use chrono::{DateTime, Utc};
use futures::FutureExt as _;
use linera_base::{
crypto::PublicKey,
data_types::{Amount, ApplicationPermissions, TimeDelta},
Expand Down Expand Up @@ -139,6 +140,7 @@ impl ClientOptions {
self.wasm_runtime.with_wasm_default(),
Job(self, wallet),
)
.boxed()
.await?;
Ok(())
}
Expand Down
8 changes: 5 additions & 3 deletions linera-service/src/linera/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Copyright (c) Zefchain Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

#![deny(clippy::large_futures)]

use std::{collections::HashMap, env, path::PathBuf, sync::Arc, time::Instant};

use anyhow::{anyhow, bail, ensure, Context};
Expand All @@ -10,7 +12,7 @@ use chrono::Utc;
use client_context::ClientContext;
use client_options::ClientOptions;
use colored::Colorize;
use futures::{lock::Mutex, StreamExt};
use futures::{lock::Mutex, FutureExt as _, StreamExt};
use linera_base::{
crypto::{CryptoHash, CryptoRng, PublicKey},
data_types::{ApplicationPermissions, Timestamp},
Expand Down Expand Up @@ -1323,7 +1325,7 @@ async fn run(options: ClientOptions) -> anyhow::Result<()> {
let mut wallet_state = options.create_wallet(genesis_config, *testing_prng_seed)?;
wallet_state.extend(chains);
wallet_state.save()?;
options.initialize_storage().await?;
options.initialize_storage().boxed().await?;
Ok(())
}

Expand Down Expand Up @@ -1479,7 +1481,7 @@ Make sure to use a Linera client compatible with this network.
.map(|chain_id| UserChain::make_other(*chain_id, timestamp)),
);
wallet.save()?;
options.initialize_storage().await?;
options.initialize_storage().boxed().await?;
if *with_new_chain {
ensure!(
faucet.is_some(),
Expand Down
5 changes: 4 additions & 1 deletion linera-service/src/proxy.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
// Copyright (c) Zefchain Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

#![deny(clippy::large_futures)]

use std::{net::SocketAddr, path::PathBuf, time::Duration};

use anyhow::{bail, Result};
use async_trait::async_trait;
use futures::{SinkExt, StreamExt};
use futures::{FutureExt as _, SinkExt, StreamExt};
use linera_core::{node::NodeError, JoinSetExt as _};
use linera_rpc::{
config::{
Expand Down Expand Up @@ -341,6 +343,7 @@ impl ProxyOptions {
None,
ProxyContext::from_options(self)?,
)
.boxed()
.await
}
}
5 changes: 4 additions & 1 deletion linera-service/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
// Copyright (c) Zefchain Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

#![deny(clippy::large_futures)]

use std::{path::PathBuf, time::Duration};

use anyhow::bail;
use async_trait::async_trait;
use futures::{stream::FuturesUnordered, FutureExt, StreamExt, TryFutureExt};
use futures::{stream::FuturesUnordered, FutureExt as _, StreamExt, TryFutureExt as _};
use linera_base::crypto::{CryptoRng, KeyPair};
use linera_core::{worker::WorkerState, JoinSetExt as _};
use linera_execution::{committee::ValidatorName, WasmRuntime, WithWasmDefault};
Expand Down Expand Up @@ -466,6 +468,7 @@ async fn run(options: ServerOptions) {
.await
.unwrap();
run_with_storage(full_storage_config, &genesis_config, wasm_runtime, job)
.boxed()
.await
.unwrap();
}
Expand Down
6 changes: 4 additions & 2 deletions linera-service/src/unit_tests/chain_listener.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
// Copyright (c) Zefchain Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

#![allow(clippy::large_futures)]

use std::{collections::BTreeMap, sync::Arc};

use async_trait::async_trait;
use futures::lock::Mutex;
use futures::{lock::Mutex, FutureExt as _};
use linera_base::{
crypto::{KeyPair, PublicKey},
data_types::{Amount, BlockHeight, TimeDelta, Timestamp},
Expand Down Expand Up @@ -177,7 +179,7 @@ async fn test_chain_listener() -> anyhow::Result<()> {
.transfer(None, Amount::ONE, recipient0, UserData::default())
.await?;
for i in 0.. {
client0.synchronize_from_validators().await?;
client0.synchronize_from_validators().boxed().await?;
let balance = client0.local_balance().await?;
if balance == Amount::from_tokens(2) {
break;
Expand Down
2 changes: 2 additions & 0 deletions linera-service/src/unit_tests/faucet.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) Zefchain Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

#![allow(clippy::large_futures)]

use std::sync::Arc;

use async_trait::async_trait;
Expand Down
2 changes: 2 additions & 0 deletions linera-storage-service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
//! This module provides a shared key-value store server based on the RocksDB store and the in-memory store of `linera-views`.
//! The corresponding client implements the `KeyValueStore` and `AdminKeyValueStore` traits.

#![deny(clippy::large_futures)]

#[allow(clippy::derive_partial_eq_without_eq)]
// https://github.com/hyperium/tonic/issues/1056
pub mod key_value_store {
Expand Down
2 changes: 2 additions & 0 deletions linera-storage/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

//! This module defines the storage abstractions for individual chains and certificates.

#![deny(clippy::large_futures)]

mod chain_guards;
mod db_storage;
#[cfg(with_dynamodb)]
Expand Down
2 changes: 1 addition & 1 deletion linera-storage/src/unit_tests/chain_guards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::{
time::Duration,
};

use futures::FutureExt;
use futures::FutureExt as _;
use linera_base::identifiers::ChainId;
use tokio::{sync::Barrier, time::sleep};

Expand Down
Loading
Loading