Skip to content

Commit

Permalink
Replace std hash map and set collections with indexmap alternatives
Browse files Browse the repository at this point in the history
  • Loading branch information
sug0 committed Feb 21, 2024
1 parent a7c580b commit 6821eef
Show file tree
Hide file tree
Showing 94 changed files with 189 additions and 163 deletions.
2 changes: 1 addition & 1 deletion crates/apps/src/lib/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2842,13 +2842,13 @@ pub mod cmds {
}

pub mod args {
use std::collections::HashMap;
use std::convert::TryFrom;
use std::env;
use std::net::SocketAddr;
use std::path::PathBuf;
use std::str::FromStr;

use namada::core::collections::HashMap;
use namada::ibc::core::host::types::identifiers::{ChannelId, PortId};
use namada::tx::data::GasLimit;
use namada::types::address::{Address, EstablishedAddress};
Expand Down
3 changes: 2 additions & 1 deletion crates/apps/src/lib/client/rpc.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Client RPC queries
use std::cmp::Ordering;
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
use std::collections::{BTreeMap, BTreeSet};
use std::fs::{self, read_dir};
use std::io;
use std::iter::Iterator;
Expand All @@ -15,6 +15,7 @@ use masp_primitives::merkle_tree::MerklePath;
use masp_primitives::sapling::{Node, ViewingKey};
use masp_primitives::transaction::components::I128Sum;
use masp_primitives::zip32::ExtendedFullViewingKey;
use namada::core::collections::{HashMap, HashSet};
use namada::governance::cli::offline::{
find_offline_proposal, find_offline_votes, read_offline_files,
OfflineSignedProposal, OfflineVote,
Expand Down
2 changes: 1 addition & 1 deletion crates/apps/src/lib/client/tx.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::collections::HashSet;
use std::fs::File;
use std::io::Write;

Expand All @@ -7,6 +6,7 @@ use borsh_ext::BorshSerializeExt;
use ledger_namada_rs::{BIP44Path, NamadaApp};
use ledger_transport_hid::hidapi::HidApi;
use ledger_transport_hid::TransportNativeHID;
use namada::core::collections::HashSet;
use namada::governance::cli::offline::{
OfflineProposal, OfflineSignedProposal, OfflineVote,
};
Expand Down
3 changes: 2 additions & 1 deletion crates/apps/src/lib/config/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ pub mod templates;
pub mod transactions;
pub mod utils;

use std::collections::{BTreeMap, HashMap};
use std::collections::BTreeMap;
use std::fmt::{Display, Formatter};
use std::str::FromStr;

use borsh::{BorshDeserialize, BorshSerialize};
use derivative::Derivative;
use namada::core::collections::HashMap;
use namada::governance::parameters::GovernanceParameters;
use namada::governance::pgf::parameters::PgfParameters;
use namada::ledger::eth_bridge::EthereumBridgeParams;
Expand Down
3 changes: 2 additions & 1 deletion crates/apps/src/lib/config/genesis/transactions.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Genesis transactions
use std::collections::{BTreeMap, BTreeSet, HashSet};
use std::collections::{BTreeMap, BTreeSet};
use std::fmt::Debug;
use std::net::SocketAddr;

Expand All @@ -11,6 +11,7 @@ use ledger_namada_rs::NamadaApp;
use ledger_transport_hid::hidapi::HidApi;
use ledger_transport_hid::TransportNativeHID;
use namada::account::AccountPublicKeysMap;
use namada::core::collections::HashSet;
use namada::ledger::pos::common::PublicKey;
use namada::ledger::pos::types::ValidatorMetaData;
use namada::tx::data::{pos, Fee, TxType};
Expand Down
2 changes: 1 addition & 1 deletion crates/apps/src/lib/config/genesis/utils.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::collections::HashSet;
use std::path::Path;

use eyre::Context;
use ledger_namada_rs::NamadaApp;
use ledger_transport_hid::TransportNativeHID;
use namada::core::collections::HashSet;
use namada::tx::Tx;
use namada::types::key::common;
use namada_sdk::wallet::Wallet;
Expand Down
2 changes: 1 addition & 1 deletion crates/apps/src/lib/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ pub mod genesis;
pub mod global;
pub mod utils;

use std::collections::HashMap;
use std::fs::{create_dir_all, File};
use std::io::Write;
use std::path::{Path, PathBuf};

use directories::ProjectDirs;
use namada::core::collections::HashMap;
use namada::types::chain::ChainId;
use namada::types::storage::BlockHeight;
use namada::types::time::Rfc3339String;
Expand Down
16 changes: 8 additions & 8 deletions crates/apps/src/lib/node/ledger/shell/finalize_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -850,11 +850,12 @@ fn pos_votes_from_abci(
/// are covered by the e2e tests.
#[cfg(test)]
mod test_finalize_block {
use std::collections::{BTreeMap, BTreeSet, HashMap};
use std::collections::{BTreeMap, BTreeSet};
use std::num::NonZeroU64;
use std::str::FromStr;

use data_encoding::HEXUPPER;
use namada::core::collections::HashMap;
use namada::core::ledger::replay_protection;
use namada::eth_bridge::storage::bridge_pool::{
self, get_key_from_hash, get_nonce_key, get_signed_root_key,
Expand Down Expand Up @@ -4888,12 +4889,9 @@ mod test_finalize_block {
)?;
assert_eq!(
consensus_vals,
HashSet::from_iter([
val1.clone(),
val2.clone(),
val3.clone(),
val4.clone()
])
[val1.clone(), val2.clone(), val3.clone(), val4.clone()]
.into_iter()
.collect::<HashSet<_>>(),
);
for offset in 1..=params.pipeline_len {
let consensus_vals = read_consensus_validator_set_addresses(
Expand All @@ -4902,7 +4900,9 @@ mod test_finalize_block {
)?;
assert_eq!(
consensus_vals,
HashSet::from_iter([val1.clone(), val3.clone(), val4.clone()])
[val1.clone(), val3.clone(), val4.clone()]
.into_iter()
.collect::<HashSet<_>>()
);
let val2_state = validator_state_handle(&val2)
.get(&shell.wl_storage, current_epoch + offset, &params)?
Expand Down
3 changes: 1 addition & 2 deletions crates/apps/src/lib/node/ledger/shell/governance.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::collections::HashMap;

use namada::core::collections::HashMap;
use namada::governance::pgf::storage::keys as pgf_storage;
use namada::governance::pgf::storage::steward::StewardDetail;
use namada::governance::pgf::{storage as pgf, ADDRESS};
Expand Down
4 changes: 2 additions & 2 deletions crates/apps/src/lib/node/ledger/shell/init_chain.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
//! Implementation of chain initialization for the Shell
use std::collections::HashMap;
use std::ops::ControlFlow;

use masp_primitives::merkle_tree::CommitmentTree;
use masp_primitives::sapling::Node;
use masp_proofs::bls12_381;
use namada::account::protocol_pk_key;
use namada::core::collections::HashMap;
use namada::ledger::parameters::Parameters;
use namada::ledger::{ibc, pos};
use namada::proof_of_stake::BecomeValidator;
Expand Down Expand Up @@ -281,7 +281,7 @@ where
genesis: &genesis::chain::Finalized,
vp_cache: &mut HashMap<String, Vec<u8>>,
) -> ControlFlow<(), Vec<u8>> {
use std::collections::hash_map::Entry;
use namada::core::collections::hash_map::Entry;
let Some(vp_filename) =
self.validate(
genesis
Expand Down
3 changes: 2 additions & 1 deletion crates/apps/src/lib/node/ledger/shell/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub mod testing;
pub mod utils;
mod vote_extensions;

use std::collections::{BTreeSet, HashSet};
use std::collections::BTreeSet;
use std::convert::{TryFrom, TryInto};
use std::mem;
use std::path::{Path, PathBuf};
Expand All @@ -31,6 +31,7 @@ use std::rc::Rc;
use borsh::BorshDeserialize;
use borsh_ext::BorshSerializeExt;
use masp_primitives::transaction::Transaction;
use namada::core::collections::HashSet;
use namada::core::hints;
use namada::ethereum_bridge::protocol::validation::bridge_pool_roots::validate_bp_roots_vext;
use namada::ethereum_bridge::protocol::validation::ethereum_events::validate_eth_events_vext;
Expand Down
14 changes: 6 additions & 8 deletions crates/apps/src/lib/node/ledger/shell/prepare_proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1183,10 +1183,9 @@ mod test_prepare_proposal {
if let ShellMode::Validator { local_config, .. } = &mut shell.mode {
// Remove the allowed btc
*local_config = Some(ValidatorLocalConfig {
accepted_gas_tokens: std::collections::HashMap::from([(
namada::types::address::nam(),
Amount::from(1),
)]),
accepted_gas_tokens: namada::core::collections::HashMap::from(
[(namada::types::address::nam(), Amount::from(1))],
),
});
}

Expand Down Expand Up @@ -1289,10 +1288,9 @@ mod test_prepare_proposal {
if let ShellMode::Validator { local_config, .. } = &mut shell.mode {
// Remove btc and increase minimum for nam
*local_config = Some(ValidatorLocalConfig {
accepted_gas_tokens: std::collections::HashMap::from([(
namada::types::address::nam(),
Amount::from(100),
)]),
accepted_gas_tokens: namada::core::collections::HashMap::from(
[(namada::types::address::nam(), Amount::from(100))],
),
});
}

Expand Down
3 changes: 2 additions & 1 deletion crates/apps/src/lib/node/ledger/shell/stats.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::collections::HashMap;
use std::fmt::Display;

use namada::core::collections::HashMap;

#[derive(Debug, Default)]
pub struct InternalStats {
successful_tx: u64,
Expand Down
2 changes: 1 addition & 1 deletion crates/apps/src/lib/node/ledger/shell/testing/node.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::collections::HashMap;
use std::future::poll_fn;
use std::mem::ManuallyDrop;
use std::path::PathBuf;
Expand All @@ -10,6 +9,7 @@ use color_eyre::eyre::{Report, Result};
use data_encoding::HEXUPPER;
use itertools::Either;
use lazy_static::lazy_static;
use namada::core::collections::HashMap;
use namada::eth_bridge::oracle::config::Config as OracleConfig;
use namada::ledger::dry_run_tx;
use namada::ledger::events::log::dumb_queries;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
//! Extend Tendermint votes with Ethereum events seen by a quorum of validators.
use std::collections::{BTreeMap, HashMap};
use std::collections::BTreeMap;

use namada::state::{DBIter, StorageHasher, DB};
use namada::tx::Signed;
use namada::types::ethereum_events::EthereumEvent;
use namada::vote_ext::ethereum_events::{self, MultiSignedEthEvent};
use namada_sdk::collections::HashMap;
use namada_sdk::eth_bridge::EthBridgeQueries;

use super::*;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
//! Extend Tendermint votes with validator set updates, to be relayed to
//! Namada's Ethereum bridge smart contracts.
use std::collections::HashMap;

use namada::core::collections::HashMap;
use namada::state::{DBIter, StorageHasher, DB};
use namada::vote_ext::validator_set_update;

Expand Down
3 changes: 1 addition & 2 deletions crates/apps/src/lib/node/ledger/storage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,9 @@ fn new_blake2b() -> Blake2b {

#[cfg(test)]
mod tests {
use std::collections::HashMap;

use borsh::BorshDeserialize;
use itertools::Itertools;
use namada::core::collections::HashMap;
use namada::eth_bridge::storage::proof::BridgePoolRootProof;
use namada::ledger::eth_bridge::storage::bridge_pool;
use namada::ledger::gas::STORAGE_ACCESS_GAS_PER_BYTE;
Expand Down
3 changes: 1 addition & 2 deletions crates/apps/src/lib/wallet/defaults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ pub use dev::{

#[cfg(any(test, feature = "testing", feature = "benches"))]
mod dev {
use std::collections::HashMap;

use lazy_static::lazy_static;
use namada::core::collections::HashMap;
use namada::ledger::{governance, pgf, pos};
use namada::types::address::{
apfel, btc, dot, eth, kartoffel, nam, schnitzel, Address,
Expand Down
2 changes: 1 addition & 1 deletion crates/apps/src/lib/wasm_loader/mod.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//! A module for loading WASM files and downloading pre-built WASMs.
use core::borrow::Borrow;
use std::collections::HashMap;
use std::fs;
use std::path::Path;

use data_encoding::HEXLOWER;
use eyre::{eyre, WrapErr};
use futures::future::join_all;
use namada::core::collections::HashMap;
use serde::{Deserialize, Serialize};
use sha2::{Digest, Sha256};
use thiserror::Error;
Expand Down
3 changes: 1 addition & 2 deletions crates/benches/host_env.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::collections::{HashMap, HashSet};

use criterion::{criterion_group, criterion_main, Criterion};
use namada::core::collections::{HashMap, HashSet};
use namada::core::types::account::AccountPublicKeysMap;
use namada::core::types::address;
use namada::ledger::storage::DB;
Expand Down
3 changes: 2 additions & 1 deletion crates/benches/native_vps.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
use std::cell::RefCell;
use std::collections::{BTreeSet, HashMap};
use std::collections::BTreeSet;
use std::rc::Rc;
use std::str::FromStr;

use criterion::{criterion_group, criterion_main, Criterion};
use masp_primitives::sapling::Node;
use namada::core::collections::HashMap;
use namada::core::types::address::{self, Address};
use namada::eth_bridge::storage::whitelist;
use namada::governance::pgf::storage::steward::StewardDetail;
Expand Down
2 changes: 1 addition & 1 deletion crates/benches/txs.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::collections::HashMap;
use std::str::FromStr;

use criterion::{criterion_group, criterion_main, Criterion};
use namada::account::{InitAccount, UpdateAccount};
use namada::core::collections::HashMap;
use namada::core::types::key::{
common, SecretKey as SecretKeyInterface, SigScheme,
};
Expand Down
3 changes: 2 additions & 1 deletion crates/core/src/types/account.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
//! Account types
use std::collections::{BTreeMap, HashMap};
use std::collections::BTreeMap;

use borsh::{BorshDeserialize, BorshSerialize};
use serde::{Deserialize, Serialize};

use super::key::{common, RefTo};
use crate::collections::HashMap;
use crate::hints;

#[derive(
Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/types/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
mod raw;

use std::collections::HashMap;
use std::fmt::{Debug, Display};
use std::hash::Hash;
use std::str::FromStr;
Expand All @@ -14,6 +13,7 @@ use data_encoding::HEXUPPER;
use serde::{Deserialize, Serialize};
use sha2::{Digest, Sha256};

use crate::collections::HashMap;
use crate::ibc::primitives::Signer;
use crate::impl_display_and_from_str_via_format;
use crate::types::ethereum_events::EthAddress;
Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/types/ibc.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! IBC-related data types
use std::cmp::Ordering;
use std::collections::HashMap;
use std::str::FromStr;

use borsh::{BorshDeserialize, BorshSerialize};
Expand All @@ -11,6 +10,7 @@ use serde::{Deserialize, Serialize};
use thiserror::Error;

use super::address::HASH_LEN;
use crate::collections::HashMap;
use crate::ibc::apps::transfer::types::msgs::transfer::MsgTransfer;
use crate::ibc::apps::transfer::types::{Memo, PrefixedDenom, TracePath};
use crate::ibc::core::handler::types::events::{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::collections::{HashMap, HashSet};

use eyre::Result;
use namada_core::collections::{HashMap, HashSet};
use namada_core::types::address::Address;
use namada_core::types::keccak::keccak_hash;
use namada_core::types::key::{common, SignableEthMessage};
Expand Down
Loading

0 comments on commit 6821eef

Please sign in to comment.