Skip to content

Commit

Permalink
Upgrade Rust (MystenLabs#10777)
Browse files Browse the repository at this point in the history
  • Loading branch information
mystenmark authored Apr 12, 2023
1 parent 2f9483f commit 61faeaf
Show file tree
Hide file tree
Showing 33 changed files with 45 additions and 81 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions crates/sui-adapter/src/programmable_transactions/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -898,8 +898,8 @@ fn package_for_linkage<S: StorageView>(

/// Load `type_tag` to get a `Type` in the provided `session`. `session`'s linkage context may be
/// reset after this operation, because during the operation, it may change when loading a struct.
pub fn load_type<'vm, 'state, S: StorageView>(
session: &mut Session<'state, 'vm, LinkageView<'state, S>>,
pub fn load_type<'state, S: StorageView>(
session: &mut Session<'state, '_, LinkageView<'state, S>>,
type_tag: &TypeTag,
) -> VMResult<Type> {
use move_binary_format::errors::PartialVMError;
Expand Down
4 changes: 2 additions & 2 deletions crates/sui-adapter/src/programmable_transactions/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -655,8 +655,8 @@ fn check_compatibility<'a, S: StorageView>(
Ok(())
}

fn fetch_package<'a, S: StorageView>(
context: &'a ExecutionContext<S>,
fn fetch_package<S: StorageView>(
context: &ExecutionContext<S>,
package_id: &ObjectID,
) -> Result<MovePackage, ExecutionError> {
let mut fetched_packages = fetch_packages(context, vec![package_id])?;
Expand Down
9 changes: 2 additions & 7 deletions crates/sui-config/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -770,12 +770,7 @@ impl Builder {
let committee = Self::committee(&objects);

let checkpoint = {
let signatures = self
.signatures
.clone()
.into_iter()
.map(|(_, s)| s)
.collect();
let signatures = self.signatures.clone().into_values().collect();

CertifiedCheckpointSummary::new(checkpoint, signatures, &committee).unwrap()
};
Expand Down Expand Up @@ -1717,7 +1712,7 @@ impl TokenDistributionSchedule {
///
/// The file is encoded such that the final entry in the CSV file is used to denote the
/// allocation to the stake subsidy fund. It must be in the following format:
/// '0x0000000000000000000000000000000000000000000000000000000000000000,<amount to stake subsidy fund>,'
/// `0x0000000000000000000000000000000000000000000000000000000000000000,<amount to stake subsidy fund>,`
///
/// All entries in a token distribution schedule must add up to 10B Sui.
pub fn from_csv<R: std::io::Read>(reader: R) -> Result<Self> {
Expand Down
2 changes: 0 additions & 2 deletions crates/sui-core/benches/batch_verification_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ fn gen_certs(
let (receiver, _): (_, AccountKeyPair) = get_key_pair();

let senders: Vec<_> = (0..count)
.into_iter()
.map(|_| get_key_pair::<AccountKeyPair>())
.collect();

Expand Down Expand Up @@ -80,7 +79,6 @@ fn async_verifier_bench(c: &mut Criterion) {

b.iter(|| {
let handles: Vec<_> = (0..(num_threads * over_subscription))
.into_iter()
.map(|_| {
let batch_verifier = batch_verifier.clone();
let certs = certs.clone();
Expand Down
2 changes: 1 addition & 1 deletion crates/sui-core/src/transaction_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ impl TransactionManager {
inner
.pending_certificates
.get(digest)
.map(|cert| cert.acquiring_locks.keys().cloned().into_iter().collect())
.map(|cert| cert.acquiring_locks.keys().cloned().collect())
}

// Returns the number of transactions waiting on each object ID.
Expand Down
3 changes: 0 additions & 3 deletions crates/sui-core/src/unit_tests/batch_verification_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ fn gen_certs(
let (receiver, _): (_, AccountKeyPair) = get_key_pair();

let senders: Vec<_> = (0..count)
.into_iter()
.map(|_| get_key_pair::<AccountKeyPair>())
.collect();

Expand All @@ -46,7 +45,6 @@ fn gen_ckpts(
count: usize,
) -> Vec<SignedCheckpointSummary> {
(0..count)
.into_iter()
.map(|i| {
let k = &key_pairs[i % key_pairs.len()];
let name = k.public().into();
Expand Down Expand Up @@ -117,7 +115,6 @@ async fn test_async_verifier() {
let verifier = Arc::new(SignatureVerifier::new(committee.clone(), metrics));

let tasks: Vec<_> = (0..32)
.into_iter()
.map(|_| {
let verifier = verifier.clone();
let committee = committee.clone();
Expand Down
9 changes: 2 additions & 7 deletions crates/sui-core/src/unit_tests/execution_driver_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,17 +280,13 @@ async fn test_execution_with_dependencies() {
// ---- Initialize a network with three accounts, each with 10 gas objects.

const NUM_ACCOUNTS: usize = 3;
let accounts: Vec<(_, AccountKeyPair)> = (0..NUM_ACCOUNTS)
.into_iter()
.map(|_| get_key_pair())
.collect_vec();
let accounts: Vec<(_, AccountKeyPair)> =
(0..NUM_ACCOUNTS).map(|_| get_key_pair()).collect_vec();

const NUM_GAS_OBJECTS_PER_ACCOUNT: usize = 10;
let gas_objects = (0..NUM_ACCOUNTS)
.into_iter()
.map(|i| {
(0..NUM_GAS_OBJECTS_PER_ACCOUNT)
.into_iter()
.map(|_| Object::with_owner_for_testing(accounts[i].0))
.collect_vec()
})
Expand Down Expand Up @@ -459,7 +455,6 @@ async fn test_per_object_overload() {
let (addr, key) = get_key_pair();
const NUM_GAS_OBJECTS_PER_ACCOUNT: usize = 2000;
let gas_objects = (0..NUM_GAS_OBJECTS_PER_ACCOUNT)
.into_iter()
.map(|_| Object::with_owner_for_testing(addr))
.collect_vec();
let (aggregator, authorities, _genesis, package) =
Expand Down
1 change: 0 additions & 1 deletion crates/sui-framework-build/src/compiled_package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,6 @@ impl CompiledPackage {
self.dependency_ids
.published
.values()
.into_iter()
.map(|object_id| object_id.to_hex_uncompressed())
.collect()
}
Expand Down
7 changes: 1 addition & 6 deletions crates/sui-framework/src/natives/test_scenario.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,12 +303,7 @@ pub fn ids_for_address(
.address_inventories
.get(&account)
.and_then(|inv| inv.get(&specified_ty))
.map(|s| {
s.keys()
.map(|id| pack_id(*id))
.into_iter()
.collect::<Vec<Value>>()
})
.map(|s| s.keys().map(|id| pack_id(*id)).collect::<Vec<Value>>())
.unwrap_or_default();
let ids_vector = Value::vector_for_testing_only(ids);
Ok(NativeResult::ok(legacy_test_cost(), smallvec![ids_vector]))
Expand Down
2 changes: 0 additions & 2 deletions crates/sui-indexer/src/handlers/checkpoint_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ where
loop {
let download_futures = (next_cursor_sequence_number
..next_cursor_sequence_number + current_parallel_downloads as i64)
.into_iter()
.map(|seq_num| {
self.download_checkpoint_data(seq_num as u64, /* skip objects */ false)
});
Expand Down Expand Up @@ -282,7 +281,6 @@ where
loop {
let download_futures = (next_cursor_sequence_number
..next_cursor_sequence_number + current_parallel_downloads as i64)
.into_iter()
.map(|seq_num| {
self.download_checkpoint_data(seq_num as u64, /* skip objects */ true)
});
Expand Down
2 changes: 1 addition & 1 deletion crates/sui-indexer/src/models/checkpoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl Checkpoint {
total_transaction_blocks: rpc_checkpoint.transactions.len() as i64,
network_total_transactions: rpc_checkpoint.network_total_transactions as i64,
timestamp_ms: rpc_checkpoint.timestamp_ms as i64,
total_transactions: total_transactions as i64,
total_transactions,
validator_signature: rpc_checkpoint.validator_signature.encode_base64(),
})
}
Expand Down
1 change: 0 additions & 1 deletion crates/sui-json-rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ impl JsonRpcServerBuilder {
Ok(value) => {
let allow_hosts = value
.split(',')
.into_iter()
.map(HeaderValue::from_str)
.collect::<Result<Vec<_>, _>>()?;
AllowOrigin::list(allow_hosts)
Expand Down
2 changes: 1 addition & 1 deletion crates/sui-proc-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ workspace-hack = { version = "0.1", path = "../workspace-hack" }
proc-macro2 = "1"

[target.'cfg(msim)'.dependencies]
msim-macros = { git = "https://github.com/MystenLabs/mysten-sim.git", rev = "8190dcd907e45755d48ab14992f8df5ac31dacc9", package = "msim-macros" }
msim-macros = { git = "https://github.com/MystenLabs/mysten-sim.git", rev = "e9011f96b84615b63cd8b5835e606a2fc218a1bd", package = "msim-macros" }
2 changes: 1 addition & 1 deletion crates/sui-protocol-config-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use proc_macro::TokenStream;
use quote::quote;
use syn::{parse_macro_input, Data, DeriveInput, Fields, Type};

/// This proc macro generates getters for protocol config fields of type Option<T>.
/// This proc macro generates getters for protocol config fields of type `Option<T>`.
/// Example for a field: `new_constant: Option<u64>`, we derive
/// ```rust,ignore
/// pub fn new_constant(&self) -> u64 {
Expand Down
9 changes: 2 additions & 7 deletions crates/sui-rpc-loadgen/src/payload/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,20 +218,15 @@ pub struct MultiGetTransactionBlocks {
pub digests: Vec<TransactionDigest>,
}

#[derive(Clone, EnumString)]
#[derive(Clone, EnumString, Default)]
#[strum(serialize_all = "lowercase")]
pub enum AddressQueryType {
#[default]
From,
To,
Both,
}

impl Default for AddressQueryType {
fn default() -> Self {
AddressQueryType::From
}
}

#[derive(Clone)]
pub struct MultiGetObjects {
pub object_ids: Vec<ObjectID>,
Expand Down
6 changes: 3 additions & 3 deletions crates/sui-rpc-loadgen/src/payload/rpc_command_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ fn write_data_to_file<T: Serialize>(data: &T, file_path: &str) -> Result<(), any
fs::create_dir_all(&path_buf).map_err(|e| anyhow!("Error creating directory: {}", e))?;

let file_name = format!("{}.json", file_path);
let file = File::create(&file_name).map_err(|e| anyhow!("Error creating file: {}", e))?;
let file = File::create(file_name).map_err(|e| anyhow!("Error creating file: {}", e))?;
serde_json::to_writer(file, data).map_err(|e| anyhow!("Error writing to file: {}", e))?;

Ok(())
Expand Down Expand Up @@ -636,7 +636,7 @@ async fn prepare_new_signer_and_coins(
.extend(split_coins(client, &burner_keypair, coin_id, gas_coin_id, splits).await);
}
}
assert_eq!(results.len(), num_coins as usize);
assert_eq!(results.len(), num_coins);
debug!("Split off {} coins for gas payment {results:?}", num_coins);
(results, burner_keypair.encode_base64())
}
Expand All @@ -648,7 +648,7 @@ fn num_transactions_needed(num_coins: usize, new_coins_per_txn: usize) -> usize
if num_coins == 1 {
return 0;
}
((num_coins + new_coins_per_txn - 1) / new_coins_per_txn) as usize
(num_coins + new_coins_per_txn - 1) / new_coins_per_txn
}

/// Calculate the split amounts for a given number of coins, amount per coin, and maximum number of coins per transaction.
Expand Down
2 changes: 1 addition & 1 deletion crates/sui-simulator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ tower = "0.4.13"
lru = "0.10"

[target.'cfg(msim)'.dependencies]
msim = { git = "https://github.com/MystenLabs/mysten-sim.git", rev = "8190dcd907e45755d48ab14992f8df5ac31dacc9", package = "msim" }
msim = { git = "https://github.com/MystenLabs/mysten-sim.git", rev = "e9011f96b84615b63cd8b5835e606a2fc218a1bd", package = "msim" }
1 change: 0 additions & 1 deletion crates/sui-storage/src/mutex_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ impl<K: Hash + Eq + Send + Sync + 'static, L: Lock + 'static> LockTable<K, L> {

let lock_table: Arc<Vec<RwLock<InnerLockTable<K, L>>>> = Arc::new(
(0..num_shards)
.into_iter()
.map(|_| RwLock::new(HashMap::new()))
.collect(),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub const RESULT: &str = "Result";
pub const NESTED_RESULT: &str = "NestedResult";

impl Display for CommandToken {
fn fmt<'f>(&self, formatter: &mut fmt::Formatter<'f>) -> Result<(), fmt::Error> {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
let s = match *self {
CommandToken::Whitespace => "[whitespace]",
CommandToken::Comment => "[comment]",
Expand Down
20 changes: 10 additions & 10 deletions crates/sui-types/src/base_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,13 @@ pub struct MoveObjectType(MoveObjectType_);
/// `MoveObjectType`
#[derive(Eq, PartialEq, PartialOrd, Ord, Debug, Clone, Deserialize, Serialize, Hash)]
pub enum MoveObjectType_ {
/// A type that is not 0x2::coin::Coin<T>
/// A type that is not `0x2::coin::Coin<T>`
Other(StructTag),
/// A SUI coin (i.e., 0x2::coin::Coin<0x2::sui::SUI>)
/// A SUI coin (i.e., `0x2::coin::Coin<0x2::sui::SUI>`)
GasCoin,
/// A record of a staked SUI coin (i.e., 0x3::staking_pool::StakedSui)
/// A record of a staked SUI coin (i.e., `0x3::staking_pool::StakedSui`)
StakedSui,
/// A non-SUI coin type (i.e., 0x2::coin::Coin<T> where T != 0x2::sui::SUI)
/// A non-SUI coin type (i.e., `0x2::coin::Coin<T> where T != 0x2::sui::SUI`)
Coin(TypeTag),
// NOTE: if adding a new type here, and there are existing on-chain objects of that
// type with Other(_), that is ok, but you must hand-roll PartialEq/Eq/Ord/maybe Hash
Expand Down Expand Up @@ -208,7 +208,7 @@ impl MoveObjectType {
}
}

/// Return true if `self` is 0x2::coin::Coin<T> for some T (note: T can be SUI)
/// Return true if `self` is `0x2::coin::Coin<T>` for some T (note: T can be SUI)
pub fn is_coin(&self) -> bool {
match &self.0 {
MoveObjectType_::GasCoin | MoveObjectType_::Coin(_) => true,
Expand All @@ -226,7 +226,7 @@ impl MoveObjectType {
}
}

/// Return true if `self` is 0x2::coin::Coin<t>
/// Return true if `self` is `0x2::coin::Coin<t>`
pub fn is_coin_t(&self, t: &TypeTag) -> bool {
match &self.0 {
MoveObjectType_::GasCoin => GAS::is_gas_type(t),
Expand Down Expand Up @@ -399,7 +399,7 @@ impl ObjectType {
}
}

/// Return true if `self` is 0x2::coin::Coin<t>
/// Return true if `self` is `0x2::coin::Coin<t>`
pub fn is_coin_t(&self, t: &TypeTag) -> bool {
match self {
ObjectType::Struct(s) => s.is_coin_t(t),
Expand Down Expand Up @@ -446,7 +446,7 @@ impl SuiAddress {
AccountAddress::random().into()
}

/// Serialize an Option<SuiAddress> in Hex.
/// Serialize an `Option<SuiAddress>` in Hex.
pub fn optional_address_as_hex<S>(
key: &Option<SuiAddress>,
serializer: S,
Expand All @@ -457,7 +457,7 @@ impl SuiAddress {
serializer.serialize_str(&key.map(Hex::encode).unwrap_or_default())
}

/// Deserialize into an Option<SuiAddress>.
/// Deserialize into an `Option<SuiAddress>`.
pub fn optional_address_from_hex<'de, D>(
deserializer: D,
) -> Result<Option<SuiAddress>, D::Error>
Expand Down Expand Up @@ -860,7 +860,7 @@ impl ObjectID {
Self(AccountAddress::new(obj_id))
}

/// Const fn variant of <ObjectID as From<AccountAddress>>::from
/// Const fn variant of `<ObjectID as From<AccountAddress>>::from`
pub const fn from_address(addr: AccountAddress) -> Self {
Self(addr)
}
Expand Down
2 changes: 1 addition & 1 deletion crates/sui-types/src/committee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl Committee {
mut voting_weights: BTreeMap<AuthorityName, StakeUnit>,
) -> Self {
let num_nodes = voting_weights.len();
let total_votes: StakeUnit = voting_weights.iter().map(|(_, votes)| *votes).sum();
let total_votes: StakeUnit = voting_weights.values().cloned().sum();

let normalization_coef = TOTAL_VOTING_POWER as f64 / total_votes as f64;
let mut total_sum = 0;
Expand Down
2 changes: 1 addition & 1 deletion crates/sui-types/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub trait BackingPackageStore {
.map(|opt_obj| opt_obj.and_then(|obj| obj.data.try_into_package()))
}
/// Returns Ok(<object for each package id in `package_ids`>) if all package IDs in
/// `package_id` were found. If any package in `package_ids` was not found it returns Err(<list
/// `package_id` were found. If any package in `package_ids` was not found it returns a list
/// of any package ids that are unable to be found>).
fn get_package_objects<'a>(
&self,
Expand Down
5 changes: 1 addition & 4 deletions crates/sui/src/genesis_inspector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,7 @@ pub(crate) fn examine_genesis_checkpoint(genesis: UnsignedGenesis) {
.map(|v| (v.staking_pool.id, v))
.collect::<BTreeMap<_, _>>();

let mut validator_options = validator_map
.iter()
.map(|(name, _)| *name)
.collect::<Vec<_>>();
let mut validator_options: Vec<_> = validator_map.keys().copied().collect();
validator_options.extend_from_slice(&[STR_ALL, STR_EXIT]);
println!("Total Number of Validators: {}", validator_set.len());

Expand Down
1 change: 0 additions & 1 deletion crates/sui/tests/reconfiguration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,6 @@ async fn test_inactive_validator_pool_read() {
fn gen_keys(count: usize) -> Vec<AccountKeyPair> {
let mut rng = StdRng::from_seed([0; 32]);
(0..count)
.into_iter()
.map(|_| get_key_pair_from_rng::<AccountKeyPair, _>(&mut rng).1)
.collect()
}
Expand Down
2 changes: 1 addition & 1 deletion crates/typed-store/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ typed-store-derive = {path = "../typed-store-derive"}
# Most packages should depend on sui-simulator instead of directly on msim, but for typed-store
# that creates a circular dependency.
[target.'cfg(msim)'.dependencies]
msim = { git = "https://github.com/MystenLabs/mysten-sim.git", rev = "8190dcd907e45755d48ab14992f8df5ac31dacc9", package = "msim" }
msim = { git = "https://github.com/MystenLabs/mysten-sim.git", rev = "e9011f96b84615b63cd8b5835e606a2fc218a1bd", package = "msim" }
Loading

0 comments on commit 61faeaf

Please sign in to comment.