Skip to content

Commit

Permalink
[Rust] upgrade to 1.81 (MystenLabs#19529)
Browse files Browse the repository at this point in the history
## Description 

Upgrade rust toolchain to 1.81. Fix lint.

## Test plan 

CI

---

## Release notes

Check each box that your changes affect. If none of the boxes relate to
your changes, release notes aren't required.

For each box you select, include information after the relevant heading
that describes the impact of your changes that a user might notice and
any actions they must take to implement updates.

- [ ] Protocol: 
- [ ] Nodes (Validators and Full nodes): 
- [ ] Indexer: 
- [ ] JSON-RPC: 
- [ ] GraphQL: 
- [ ] CLI: 
- [ ] Rust SDK:
- [ ] REST API:
  • Loading branch information
mwtian authored Sep 26, 2024
1 parent c838c1e commit 49175e2
Show file tree
Hide file tree
Showing 53 changed files with 331 additions and 370 deletions.
2 changes: 1 addition & 1 deletion consensus/core/src/broadcaster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ mod test {
if index == context.own_index {
continue;
}
assert!(blocks_sent.get(&index).is_none());
assert!(!blocks_sent.contains_key(&index));
}

// ... until LAST_BLOCK_RETRY_INTERVAL
Expand Down
11 changes: 7 additions & 4 deletions consensus/core/src/core_thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use mysten_metrics::{
monitored_mpsc::{channel, Receiver, Sender, WeakSender},
monitored_scope, spawn_logged_monitored_task,
};
use parking_lot::{Mutex, RwLock};
use parking_lot::RwLock;
use thiserror::Error;
use tokio::sync::{oneshot, watch};
use tracing::warn;
Expand Down Expand Up @@ -300,13 +300,15 @@ impl CoreThreadDispatcher for ChannelCoreThreadDispatcher {
}

// TODO: complete the Mock for thread dispatcher to be used from several tests
#[cfg(test)]
#[derive(Default)]
pub(crate) struct MockCoreThreadDispatcher {
add_blocks: Mutex<Vec<VerifiedBlock>>,
missing_blocks: Mutex<BTreeSet<BlockRef>>,
last_known_proposed_round: Mutex<Vec<Round>>,
add_blocks: parking_lot::Mutex<Vec<VerifiedBlock>>,
missing_blocks: parking_lot::Mutex<BTreeSet<BlockRef>>,
last_known_proposed_round: parking_lot::Mutex<Vec<Round>>,
}

#[cfg(test)]
impl MockCoreThreadDispatcher {
#[cfg(test)]
pub(crate) async fn get_add_blocks(&self) -> Vec<VerifiedBlock> {
Expand All @@ -327,6 +329,7 @@ impl MockCoreThreadDispatcher {
}
}

#[cfg(test)]
#[async_trait]
impl CoreThreadDispatcher for MockCoreThreadDispatcher {
async fn add_blocks(
Expand Down
9 changes: 3 additions & 6 deletions crates/mysten-metrics/src/metered_channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,22 +99,20 @@ impl<T> Receiver<T> {
/// Attempts to receive the next value for this receiver.
/// Decrements the gauge in case of a successful `try_recv`.
pub fn try_recv(&mut self) -> Result<T, TryRecvError> {
self.inner.try_recv().map(|val| {
self.inner.try_recv().inspect(|_| {
self.gauge.dec();
if let Some(total_gauge) = &self.total {
total_gauge.inc();
}
val
})
}

pub fn blocking_recv(&mut self) -> Option<T> {
self.inner.blocking_recv().map(|val| {
self.inner.blocking_recv().inspect(|_| {
self.gauge.dec();
if let Some(total_gauge) = &self.total {
total_gauge.inc();
}
val
})
}

Expand Down Expand Up @@ -194,9 +192,8 @@ impl<T> Sender<T> {
self.inner
.try_send(message)
// remove this unsightly hack once https://github.com/rust-lang/rust/issues/91345 is resolved
.map(|val| {
.inspect(|_| {
self.gauge.inc();
val
})
}

Expand Down
12 changes: 4 additions & 8 deletions crates/mysten-metrics/src/monitored_mpsc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,26 +252,24 @@ impl<T> Receiver<T> {
/// Attempts to receive the next value for this receiver.
/// Decrements the gauge in case of a successful `try_recv`.
pub fn try_recv(&mut self) -> Result<T, TryRecvError> {
self.inner.try_recv().map(|val| {
self.inner.try_recv().inspect(|_| {
if let Some(inflight) = &self.inflight {
inflight.dec();
}
if let Some(received) = &self.received {
received.inc();
}
val
})
}

pub fn blocking_recv(&mut self) -> Option<T> {
self.inner.blocking_recv().map(|val| {
self.inner.blocking_recv().inspect(|_| {
if let Some(inflight) = &self.inflight {
inflight.dec();
}
if let Some(received) = &self.received {
received.inc();
}
val
})
}

Expand Down Expand Up @@ -451,26 +449,24 @@ impl<T> UnboundedReceiver<T> {
/// Attempts to receive the next value for this receiver.
/// Decrements the gauge in case of a successful `try_recv`.
pub fn try_recv(&mut self) -> Result<T, TryRecvError> {
self.inner.try_recv().map(|val| {
self.inner.try_recv().inspect(|_| {
if let Some(inflight) = &self.inflight {
inflight.dec();
}
if let Some(received) = &self.received {
received.inc();
}
val
})
}

pub fn blocking_recv(&mut self) -> Option<T> {
self.inner.blocking_recv().map(|val| {
self.inner.blocking_recv().inspect(|_| {
if let Some(inflight) = &self.inflight {
inflight.dec();
}
if let Some(received) = &self.received {
received.inc();
}
val
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ impl Scenario {
};
let id = o.id();
// genesis objects are not managed by Scenario, ignore them
if reverse_id_map.get(&id).is_some() {
if reverse_id_map.contains_key(&id) {
self.objects.insert(id, o);
}
});
Expand Down
4 changes: 2 additions & 2 deletions crates/sui-core/src/traffic_controller/nodefw_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl NodeFWClient {
pub async fn block_addresses(&self, addresses: BlockAddresses) -> Result<(), reqwest::Error> {
let response = self
.client
.post(&format!("{}/block_addresses", self.remote_fw_url))
.post(format!("{}/block_addresses", self.remote_fw_url))
.json(&addresses)
.send()
.await?;
Expand All @@ -44,7 +44,7 @@ impl NodeFWClient {

pub async fn list_addresses(&self) -> Result<BlockAddresses, reqwest::Error> {
self.client
.get(&format!("{}/list_addresses", self.remote_fw_url))
.get(format!("{}/list_addresses", self.remote_fw_url))
.send()
.await?
.error_for_status()?
Expand Down
2 changes: 1 addition & 1 deletion crates/sui-faucet/src/faucet/simple_faucet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1636,7 +1636,7 @@ mod tests {
let candidates = faucet.drain_gas_queue(gas_coins.len() - 1).await;

assert_eq!(discarded, 1);
assert!(candidates.get(&tiny_coin_id).is_none());
assert!(!candidates.contains(&tiny_coin_id));
}

#[tokio::test]
Expand Down
5 changes: 2 additions & 3 deletions crates/sui-protocol-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3163,11 +3163,10 @@ mod test {
.feature_flags
.lookup_attr("some random string".to_owned())
.is_none());
assert!(prot
assert!(!prot
.feature_flags
.attr_map()
.get("some random string")
.is_none());
.contains_key("some random string"));

// Was false in v1
assert!(
Expand Down
4 changes: 2 additions & 2 deletions crates/sui-source-validation/src/toolchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,9 @@ fn download_and_compile(
let mut dest_binary = dest_version.clone();
dest_binary.extend(["target", "release"]);
if platform == "windows-x86_64" {
dest_binary.push(&format!("sui-{platform}.exe"));
dest_binary.push(format!("sui-{platform}.exe"));
} else {
dest_binary.push(&format!("sui-{platform}"));
dest_binary.push(format!("sui-{platform}"));
}
let dest_binary_os = OsStr::new(dest_binary.as_path());
set_executable_permission(dest_binary_os)?;
Expand Down
2 changes: 1 addition & 1 deletion crates/suiop-cli/src/cli/incidents/selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ mod tests {

assert_eq!(groups.len(), 3);
assert_eq!(groups.get("Incident 1").unwrap().len(), 2);
assert!(groups.get("Incident 2").is_none());
assert!(!groups.contains_key("Incident 2"));
assert_eq!(groups.get("Another thing entirely").unwrap().len(), 2);
assert_eq!(
groups
Expand Down
9 changes: 3 additions & 6 deletions crates/suiop-cli/src/cli/pulumi/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,11 +295,10 @@ fn create_basic_project(
);
fs::create_dir_all(project_dir).context("failed to create project directory")?;
// initialize pulumi project
run_pulumi_new(project_name, project_dir_str, project_opts).map_err(|e| {
run_pulumi_new(project_name, project_dir_str, project_opts).inspect_err(|_| {
remove_project_dir(project_dir).unwrap();
let backend = get_current_backend().unwrap();
remove_stack(&backend, project_name, "mysten/dev").unwrap();
e
})?;
// run go mod tidy to make sure all dependencies are installed
run_go_mod_tidy(project_dir_str)?;
Expand All @@ -323,11 +322,10 @@ fn create_mysten_k8s_project(
fs::create_dir_all(project_dir).context("failed to create project directory")?;
// initialize pulumi project
run_pulumi_new_from_template(project_name, project_dir_str, project_type, project_opts)
.map_err(|e| {
.inspect_err(|_| {
remove_project_dir(project_dir).unwrap();
let backend = get_current_backend().unwrap();
remove_stack(&backend, project_name, "mysten/dev").unwrap();
e
})?;
// run go mod tidy to make sure all dependencies are installed
run_go_mod_tidy(project_dir_str)?;
Expand Down Expand Up @@ -360,12 +358,11 @@ fn get_encryption_key_id(project_name: &str) -> Result<String> {
],
None,
)
.map_err(|e| {
.inspect_err(|_| {
error!(
"Cannot list KMS keys, please add your Google account to {}",
"pulumi/meta/gcp-iam-automation/config.toml".bright_yellow()
);
e
})?;
let stdout_str = String::from_utf8(output.stdout)?;
let keys: Vec<KMSKey> = serde_json::from_str(&stdout_str)?;
Expand Down
1 change: 1 addition & 0 deletions crates/typed-store-workspace-hack/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
name = "typed-store-workspace-hack"
version = "0.0.0"
license = "Apache-2.0"
edition = "2021"
publish = false

[dependencies]
Expand Down
4 changes: 2 additions & 2 deletions crates/typed-store/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::{borrow::Borrow, collections::BTreeMap, error::Error};

pub trait Map<'a, K, V>
where
K: Serialize + DeserializeOwned + ?Sized,
K: Serialize + DeserializeOwned,
V: Serialize + DeserializeOwned,
{
type Error: Error;
Expand Down Expand Up @@ -151,7 +151,7 @@ where
#[async_trait]
pub trait AsyncMap<'a, K, V>
where
K: Serialize + DeserializeOwned + ?Sized + std::marker::Sync,
K: Serialize + DeserializeOwned + std::marker::Sync,
V: Serialize + DeserializeOwned + std::marker::Sync + std::marker::Send,
{
type Error: Error;
Expand Down
2 changes: 1 addition & 1 deletion docker/deterministic-canary/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
ARG PROFILE=release
# ARG BUILD_DATE
# ARG GIT_REVISION
ARG RUST_VERSION=1.80.1
ARG RUST_VERSION=1.81.0

FROM scratch AS base

Expand Down
2 changes: 1 addition & 1 deletion docker/sui-bridge-indexer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# Copy in all crates, Cargo.toml and Cargo.lock unmodified,
# and build the application.
FROM rust:1.80.1-bullseye AS builder
FROM rust:1.81-bullseye AS builder
ARG PROFILE=release
ARG GIT_REVISION
ENV GIT_REVISION=$GIT_REVISION
Expand Down
2 changes: 1 addition & 1 deletion docker/sui-graphql-rpc/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# Copy in all crates, Cargo.toml and Cargo.lock unmodified,
# and build the application.
FROM rust:1.80.1-bullseye AS builder
FROM rust:1.81-bullseye AS builder
ARG PROFILE=release
ENV PROFILE=$PROFILE
ARG GIT_REVISION
Expand Down
2 changes: 1 addition & 1 deletion docker/sui-indexer-tidb/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# Copy in all crates, Cargo.toml and Cargo.lock unmodified,
# and build the application.
FROM rust:1.80.1-bullseye AS builder
FROM rust:1.81-bullseye AS builder
ARG PROFILE=release
ARG GIT_REVISION
ENV GIT_REVISION=$GIT_REVISION
Expand Down
2 changes: 1 addition & 1 deletion docker/sui-indexer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# Copy in all crates, Cargo.toml and Cargo.lock unmodified,
# and build the application.
FROM rust:1.80.1-bullseye AS builder
FROM rust:1.81-bullseye AS builder
ARG PROFILE=release
ARG GIT_REVISION
ENV GIT_REVISION=$GIT_REVISION
Expand Down
2 changes: 1 addition & 1 deletion docker/sui-node/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# Copy in all crates, Cargo.toml and Cargo.lock unmodified,
# and build the application.
FROM rust:1.80.1-bullseye AS builder
FROM rust:1.81-bullseye AS builder
ARG PROFILE=release
ARG GIT_REVISION
ENV GIT_REVISION=$GIT_REVISION
Expand Down
2 changes: 1 addition & 1 deletion docker/sui-services/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM rust:1.80.1-bullseye AS chef
FROM rust:1.81-bullseye AS chef
WORKDIR sui
ARG GIT_REVISION
ENV GIT_REVISION=$GIT_REVISION
Expand Down
2 changes: 1 addition & 1 deletion docker/sui-source-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM rust:1.80.1-bullseye AS chef
FROM rust:1.81-bullseye AS chef
WORKDIR sui
ARG GIT_REVISION
ENV GIT_REVISION=$GIT_REVISION
Expand Down
2 changes: 1 addition & 1 deletion docker/sui-tools/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# Copy in all crates, Cargo.toml and Cargo.lock unmodified,
# and build the application.
FROM rust:1.80.1-bullseye AS builder
FROM rust:1.81-bullseye AS builder
ARG PROFILE=release
ARG GIT_REVISION
ENV GIT_REVISION=$GIT_REVISION
Expand Down
Loading

0 comments on commit 49175e2

Please sign in to comment.