From e744fb86067ffbb4a1d0456e7df8cad35bdd0ff6 Mon Sep 17 00:00:00 2001 From: Tiago Carvalho Date: Tue, 20 Feb 2024 14:49:48 +0000 Subject: [PATCH 1/5] Add `indexmap` dep to Cargo manifest --- Cargo.lock | 12 ++++++++++++ Cargo.toml | 1 + crates/core/Cargo.toml | 1 + wasm/Cargo.lock | 12 ++++++++++++ wasm_for_tests/wasm_source/Cargo.lock | 12 ++++++++++++ 5 files changed, 38 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 7f042d5736..54020e6fe2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3470,6 +3470,17 @@ dependencies = [ "hashbrown 0.14.3", ] +[[package]] +name = "indexmap" +version = "2.2.4" +source = "git+https://github.com/heliaxdev/indexmap?tag=2.2.4-heliax-1#b5b5b547bd6ab04bbb16e060326a50ddaeb6c909" +dependencies = [ + "borsh", + "equivalent", + "hashbrown 0.14.3", + "serde 1.0.193", +] + [[package]] name = "informalsystems-pbjson" version = "0.6.0" @@ -4340,6 +4351,7 @@ dependencies = [ "ics23", "impl-num-traits", "index-set", + "indexmap 2.2.4", "k256", "masp_primitives", "namada_macros", diff --git a/Cargo.toml b/Cargo.toml index f969b26308..e98c9f55fe 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -106,6 +106,7 @@ ibc-derive = "0.4.0" ibc-testkit = {version = "0.48.1", default-features = false} ics23 = "0.11.0" index-set = { git = "https://github.com/heliaxdev/index-set", tag = "v0.8.1", features = ["serialize-borsh", "serialize-serde"] } +indexmap = { git = "https://github.com/heliaxdev/indexmap", tag = "2.2.4-heliax-1", features = ["borsh-schema", "serde"] } itertools = "0.10.0" jubjub = "0.10" k256 = { version = "0.13.0", default-features = false, features = ["ecdsa", "pkcs8", "precomputed-tables", "serde", "std"]} diff --git a/crates/core/Cargo.toml b/crates/core/Cargo.toml index bb4437f87d..0ad9f9125e 100644 --- a/crates/core/Cargo.toml +++ b/crates/core/Cargo.toml @@ -43,6 +43,7 @@ ibc.workspace = true ics23.workspace = true impl-num-traits = "0.1.2" index-set.workspace = true +indexmap.workspace = true k256.workspace = true masp_primitives.workspace = true num256.workspace = true diff --git a/wasm/Cargo.lock b/wasm/Cargo.lock index 6bec97d17f..f31573a34d 100644 --- a/wasm/Cargo.lock +++ b/wasm/Cargo.lock @@ -2890,6 +2890,17 @@ dependencies = [ "hashbrown 0.14.3", ] +[[package]] +name = "indexmap" +version = "2.2.4" +source = "git+https://github.com/heliaxdev/indexmap?tag=2.2.4-heliax-1#b5b5b547bd6ab04bbb16e060326a50ddaeb6c909" +dependencies = [ + "borsh", + "equivalent", + "hashbrown 0.14.3", + "serde", +] + [[package]] name = "informalsystems-pbjson" version = "0.6.0" @@ -3417,6 +3428,7 @@ dependencies = [ "ics23", "impl-num-traits", "index-set", + "indexmap 2.2.4", "k256", "masp_primitives", "namada_macros", diff --git a/wasm_for_tests/wasm_source/Cargo.lock b/wasm_for_tests/wasm_source/Cargo.lock index ab33194d13..1d1ca33ae9 100644 --- a/wasm_for_tests/wasm_source/Cargo.lock +++ b/wasm_for_tests/wasm_source/Cargo.lock @@ -2890,6 +2890,17 @@ dependencies = [ "hashbrown 0.14.3", ] +[[package]] +name = "indexmap" +version = "2.2.4" +source = "git+https://github.com/heliaxdev/indexmap?tag=2.2.4-heliax-1#b5b5b547bd6ab04bbb16e060326a50ddaeb6c909" +dependencies = [ + "borsh", + "equivalent", + "hashbrown 0.14.3", + "serde", +] + [[package]] name = "informalsystems-pbjson" version = "0.6.0" @@ -3417,6 +3428,7 @@ dependencies = [ "ics23", "impl-num-traits", "index-set", + "indexmap 2.2.4", "k256", "masp_primitives", "namada_macros", From f28c77c116277748f415e16a72bb039ab5c06f1f Mon Sep 17 00:00:00 2001 From: Tiago Carvalho Date: Tue, 20 Feb 2024 14:50:29 +0000 Subject: [PATCH 2/5] Re-export index map and set from core --- crates/core/src/lib.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/crates/core/src/lib.rs b/crates/core/src/lib.rs index 667aae67aa..a035f86f95 100644 --- a/crates/core/src/lib.rs +++ b/crates/core/src/lib.rs @@ -17,6 +17,22 @@ pub mod borsh { pub use borsh_ext::*; } +#[allow(missing_docs)] +pub mod collections { + //! Re-exports of collection types. + + pub mod hash_map { + pub use indexmap::map::{IndexMap as HashMap, *}; + } + + pub mod hash_set { + pub use indexmap::set::{IndexSet as HashSet, *}; + } + + pub use hash_map::HashMap; + pub use hash_set::HashSet; +} + pub mod account; pub mod address; pub mod chain; From 26021a926bf4dbd7783b534d2fbaf9eac6cbfec7 Mon Sep 17 00:00:00 2001 From: Tiago Carvalho Date: Tue, 20 Feb 2024 15:00:03 +0000 Subject: [PATCH 3/5] Replace std hash map and set collections with indexmap alternatives --- crates/apps/src/lib/cli.rs | 2 +- crates/apps/src/lib/client/rpc.rs | 3 ++- crates/apps/src/lib/client/tx.rs | 2 +- crates/apps/src/lib/config/genesis.rs | 3 ++- .../apps/src/lib/config/genesis/transactions.rs | 3 ++- crates/apps/src/lib/config/genesis/utils.rs | 2 +- crates/apps/src/lib/config/mod.rs | 2 +- .../src/lib/node/ledger/shell/finalize_block.rs | 16 ++++++++-------- .../src/lib/node/ledger/shell/governance.rs | 3 +-- .../src/lib/node/ledger/shell/init_chain.rs | 4 ++-- .../lib/node/ledger/shell/prepare_proposal.rs | 17 +++++++++-------- crates/apps/src/lib/node/ledger/shell/stats.rs | 3 ++- .../src/lib/node/ledger/shell/testing/node.rs | 2 +- .../ledger/shell/vote_extensions/eth_events.rs | 4 ++-- .../shell/vote_extensions/val_set_update.rs | 2 +- crates/apps/src/lib/node/ledger/storage/mod.rs | 3 +-- crates/apps/src/lib/wallet/defaults.rs | 3 +-- crates/apps/src/lib/wasm_loader/mod.rs | 2 +- crates/benches/host_env.rs | 3 +-- crates/benches/native_vps.rs | 3 ++- crates/benches/txs.rs | 2 +- crates/core/src/account.rs | 3 ++- crates/core/src/address.rs | 3 +-- crates/core/src/event.rs | 2 +- crates/core/src/ibc.rs | 2 +- crates/encoding_spec/src/main.rs | 3 ++- .../protocol/transactions/bridge_pool_roots.rs | 3 +-- .../transactions/ethereum_events/events.rs | 8 ++++---- .../transactions/ethereum_events/mod.rs | 3 ++- .../src/protocol/transactions/utils.rs | 3 ++- .../transactions/validator_set_update/mod.rs | 3 +-- .../src/protocol/transactions/votes.rs | 3 ++- .../src/protocol/transactions/votes/update.rs | 7 ++++--- crates/ethereum_bridge/src/storage/proof.rs | 3 +-- crates/ethereum_bridge/src/test_utils.rs | 2 +- crates/governance/src/pgf/cli/steward.rs | 3 +-- crates/governance/src/pgf/storage/mod.rs | 3 +-- crates/governance/src/pgf/storage/steward.rs | 3 +-- crates/governance/src/utils.rs | 2 +- crates/ibc/src/context/router.rs | 2 +- .../light_sdk/src/reading/asynchronous/pos.rs | 3 ++- crates/light_sdk/src/reading/blocking/pos.rs | 3 ++- crates/light_sdk/src/transaction/pgf.rs | 3 +-- crates/namada/src/ledger/governance/utils.rs | 3 +-- .../src/ledger/native_vp/ethereum_bridge/vp.rs | 4 +++- .../namada/src/ledger/native_vp/ibc/context.rs | 3 ++- crates/namada/src/ledger/native_vp/ibc/mod.rs | 3 ++- crates/namada/src/ledger/native_vp/masp.rs | 3 ++- crates/namada/src/ledger/native_vp/mod.rs | 2 +- .../namada/src/ledger/native_vp/multitoken.rs | 3 ++- crates/namada/src/ledger/pgf/utils.rs | 3 +-- crates/namada/src/ledger/protocol/mod.rs | 3 +-- crates/namada/src/vm/prefix_iter.rs | 3 +-- .../src/vm/wasm/compilation_cache/common.rs | 10 +++++----- crates/proof_of_stake/src/epoched.rs | 2 +- crates/proof_of_stake/src/lib.rs | 3 ++- crates/proof_of_stake/src/queries.rs | 3 ++- crates/proof_of_stake/src/rewards.rs | 3 +-- crates/proof_of_stake/src/slashing.rs | 3 ++- crates/proof_of_stake/src/storage.rs | 3 ++- .../proof_of_stake/src/tests/state_machine.rs | 7 ++++--- .../src/tests/state_machine_v2.rs | 7 ++++--- crates/proof_of_stake/src/tests/test_pos.rs | 5 +++-- crates/proof_of_stake/src/types/mod.rs | 3 ++- .../proof_of_stake/src/validator_set_update.rs | 3 +-- crates/sdk/src/args.rs | 2 +- crates/sdk/src/eth_bridge/bridge_pool.rs | 4 ++-- crates/sdk/src/events/log.rs | 4 ++-- crates/sdk/src/events/log/dumb_queries.rs | 7 +++---- crates/sdk/src/events/mod.rs | 5 ++--- crates/sdk/src/lib.rs | 2 +- crates/sdk/src/masp.rs | 3 ++- crates/sdk/src/queries/shell/eth_bridge.rs | 6 +++--- crates/sdk/src/queries/vp/pos.rs | 3 ++- crates/sdk/src/rpc.rs | 5 +++-- crates/sdk/src/signing.rs | 3 ++- crates/sdk/src/tx.rs | 3 ++- crates/sdk/src/wallet/mod.rs | 10 ++++++---- crates/sdk/src/wallet/store.rs | 3 ++- crates/shielded_token/src/conversion.rs | 2 +- crates/state/src/write_log.rs | 4 +++- crates/storage/src/collections/lazy_map.rs | 6 ++++-- crates/storage/src/collections/lazy_set.rs | 7 +++++-- crates/tests/src/e2e/ibc_tests.rs | 3 ++- crates/tests/src/e2e/ledger_tests.rs | 2 +- crates/tests/src/e2e/setup.rs | 2 +- crates/tests/src/integration/setup.rs | 2 +- .../src/storage_api/collections/lazy_map.rs | 3 ++- .../storage_api/collections/nested_lazy_map.rs | 3 ++- crates/tests/src/vm_host_env/ibc.rs | 2 +- crates/tx/src/data/pgf.rs | 5 ++--- crates/tx/src/lib.rs | 3 +-- crates/tx/src/types.rs | 3 ++- crates/vote_ext/src/bridge_pool_roots.rs | 4 ++-- crates/vote_ext/src/ethereum_events.rs | 3 ++- crates/vote_ext/src/validator_set_update.rs | 2 +- .../src/collection_validation/lazy_map.rs | 2 +- crates/vp_prelude/src/lib.rs | 3 ++- 98 files changed, 192 insertions(+), 165 deletions(-) diff --git a/crates/apps/src/lib/cli.rs b/crates/apps/src/lib/cli.rs index 109c0d78af..233d70c3f4 100644 --- a/crates/apps/src/lib/cli.rs +++ b/crates/apps/src/lib/cli.rs @@ -2925,7 +2925,6 @@ pub mod cmds { } pub mod args { - use std::collections::HashMap; use std::env; use std::net::SocketAddr; use std::path::PathBuf; @@ -2933,6 +2932,7 @@ pub mod args { use namada::core::address::{Address, EstablishedAddress}; use namada::core::chain::{ChainId, ChainIdPrefix}; + use namada::core::collections::HashMap; use namada::core::dec::Dec; use namada::core::ethereum_events::EthAddress; use namada::core::keccak::KeccakHash; diff --git a/crates/apps/src/lib/client/rpc.rs b/crates/apps/src/lib/client/rpc.rs index 52f2c56ba4..ed67675576 100644 --- a/crates/apps/src/lib/client/rpc.rs +++ b/crates/apps/src/lib/client/rpc.rs @@ -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::str::FromStr; @@ -15,6 +15,7 @@ use masp_primitives::sapling::{Node, ViewingKey}; use masp_primitives::transaction::components::I128Sum; use masp_primitives::zip32::ExtendedFullViewingKey; use namada::core::address::{Address, InternalAddress, MASP}; +use namada::core::collections::{HashMap, HashSet}; use namada::core::hash::Hash; use namada::core::ibc::{is_ibc_denom, IbcTokenHash}; use namada::core::key::*; diff --git a/crates/apps/src/lib/client/tx.rs b/crates/apps/src/lib/client/tx.rs index 30d41f17c7..d8330fb1ed 100644 --- a/crates/apps/src/lib/client/tx.rs +++ b/crates/apps/src/lib/client/tx.rs @@ -1,4 +1,3 @@ -use std::collections::HashSet; use std::fs::File; use std::io::Write; @@ -8,6 +7,7 @@ use ledger_namada_rs::{BIP44Path, NamadaApp}; use ledger_transport_hid::hidapi::HidApi; use ledger_transport_hid::TransportNativeHID; use namada::core::address::{Address, ImplicitAddress}; +use namada::core::collections::HashSet; use namada::core::dec::Dec; use namada::core::key::{self, *}; use namada::governance::cli::offline::{ diff --git a/crates/apps/src/lib/config/genesis.rs b/crates/apps/src/lib/config/genesis.rs index 8ab5fcb1d4..d1237ed04d 100644 --- a/crates/apps/src/lib/config/genesis.rs +++ b/crates/apps/src/lib/config/genesis.rs @@ -6,7 +6,7 @@ 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; @@ -14,6 +14,7 @@ use borsh::{BorshDeserialize, BorshSerialize}; use derivative::Derivative; use namada::core::address::{Address, EstablishedAddress}; use namada::core::chain::ProposalBytes; +use namada::core::collections::HashMap; use namada::core::key::*; use namada::core::storage; use namada::core::string_encoding::StringEncoded; diff --git a/crates/apps/src/lib/config/genesis/transactions.rs b/crates/apps/src/lib/config/genesis/transactions.rs index a1b4213b38..7f132359de 100644 --- a/crates/apps/src/lib/config/genesis/transactions.rs +++ b/crates/apps/src/lib/config/genesis/transactions.rs @@ -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; @@ -13,6 +13,7 @@ use ledger_transport_hid::TransportNativeHID; use namada::account::AccountPublicKeysMap; use namada::core::address::{Address, EstablishedAddress}; use namada::core::chain::ChainId; +use namada::core::collections::HashSet; use namada::core::dec::Dec; use namada::core::key::{ common, ed25519, RefTo, SerializeWithBorsh, SigScheme, diff --git a/crates/apps/src/lib/config/genesis/utils.rs b/crates/apps/src/lib/config/genesis/utils.rs index a67f259db0..ea1acd9cbd 100644 --- a/crates/apps/src/lib/config/genesis/utils.rs +++ b/crates/apps/src/lib/config/genesis/utils.rs @@ -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::core::key::common; use namada::tx::Tx; use namada_sdk::wallet::Wallet; diff --git a/crates/apps/src/lib/config/mod.rs b/crates/apps/src/lib/config/mod.rs index 782ffee77d..018783debc 100644 --- a/crates/apps/src/lib/config/mod.rs +++ b/crates/apps/src/lib/config/mod.rs @@ -5,13 +5,13 @@ 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::chain::ChainId; +use namada::core::collections::HashMap; use namada::core::storage::BlockHeight; use namada::core::time::Rfc3339String; use serde::{Deserialize, Serialize}; diff --git a/crates/apps/src/lib/node/ledger/shell/finalize_block.rs b/crates/apps/src/lib/node/ledger/shell/finalize_block.rs index 5c92d3f8db..62aea7fe73 100644 --- a/crates/apps/src/lib/node/ledger/shell/finalize_block.rs +++ b/crates/apps/src/lib/node/ledger/shell/finalize_block.rs @@ -737,10 +737,11 @@ fn pos_votes_from_abci( /// are covered by the e2e tests. #[cfg(test)] mod test_finalize_block { - use std::collections::{BTreeMap, HashMap, HashSet}; + use std::collections::BTreeMap; use std::num::NonZeroU64; use std::str::FromStr; + use namada::core::collections::{HashMap, HashSet}; use namada::core::dec::{Dec, POS_DECIMAL_PRECISION}; use namada::core::ethereum_events::{EthAddress, Uint as ethUint}; use namada::core::hash::Hash; @@ -4698,12 +4699,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::>(), ); for offset in 1..=params.pipeline_len { let consensus_vals = read_consensus_validator_set_addresses( @@ -4712,7 +4710,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::>() ); let val2_state = validator_state_handle(&val2) .get(&shell.state, current_epoch + offset, ¶ms)? diff --git a/crates/apps/src/lib/node/ledger/shell/governance.rs b/crates/apps/src/lib/node/ledger/shell/governance.rs index e568f5e212..70285a18bd 100644 --- a/crates/apps/src/lib/node/ledger/shell/governance.rs +++ b/crates/apps/src/lib/node/ledger/shell/governance.rs @@ -1,5 +1,4 @@ -use std::collections::HashMap; - +use namada::core::collections::HashMap; use namada::core::encode; use namada::core::event::EmitEvents; use namada::core::storage::Epoch; diff --git a/crates/apps/src/lib/node/ledger/shell/init_chain.rs b/crates/apps/src/lib/node/ledger/shell/init_chain.rs index 8982367b78..bb586f05fc 100644 --- a/crates/apps/src/lib/node/ledger/shell/init_chain.rs +++ b/crates/apps/src/lib/node/ledger/shell/init_chain.rs @@ -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::core::hash::Hash as CodeHash; use namada::core::time::{TimeZone, Utc}; use namada::ledger::parameters::Parameters; @@ -274,7 +274,7 @@ where genesis: &genesis::chain::Finalized, vp_cache: &mut HashMap>, ) -> ControlFlow<(), Vec> { - use std::collections::hash_map::Entry; + use namada::core::collections::hash_map::Entry; let Some(vp_filename) = self .validate( genesis diff --git a/crates/apps/src/lib/node/ledger/shell/prepare_proposal.rs b/crates/apps/src/lib/node/ledger/shell/prepare_proposal.rs index b08c2bec59..55a65df981 100644 --- a/crates/apps/src/lib/node/ledger/shell/prepare_proposal.rs +++ b/crates/apps/src/lib/node/ledger/shell/prepare_proposal.rs @@ -1173,10 +1173,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::core::address::testing::nam(), - Amount::from(1), - )]), + accepted_gas_tokens: namada::core::collections::HashMap::from( + [(namada::core::address::testing::nam(), Amount::from(1))], + ), }); } @@ -1279,10 +1278,12 @@ 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::core::address::testing::nam(), - Amount::from(100), - )]), + accepted_gas_tokens: namada::core::collections::HashMap::from( + [( + namada::core::address::testing::nam(), + Amount::from(100), + )], + ), }); } diff --git a/crates/apps/src/lib/node/ledger/shell/stats.rs b/crates/apps/src/lib/node/ledger/shell/stats.rs index 0a677ed576..9162bb792b 100644 --- a/crates/apps/src/lib/node/ledger/shell/stats.rs +++ b/crates/apps/src/lib/node/ledger/shell/stats.rs @@ -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, diff --git a/crates/apps/src/lib/node/ledger/shell/testing/node.rs b/crates/apps/src/lib/node/ledger/shell/testing/node.rs index f133082f8e..fc651a57ee 100644 --- a/crates/apps/src/lib/node/ledger/shell/testing/node.rs +++ b/crates/apps/src/lib/node/ledger/shell/testing/node.rs @@ -1,4 +1,3 @@ -use std::collections::HashMap; use std::future::poll_fn; use std::mem::ManuallyDrop; use std::path::PathBuf; @@ -11,6 +10,7 @@ use data_encoding::HEXUPPER; use itertools::Either; use lazy_static::lazy_static; use namada::control_flow::time::Duration; +use namada::core::collections::HashMap; use namada::core::ethereum_events::EthereumEvent; use namada::core::ethereum_structs; use namada::core::hash::Hash; diff --git a/crates/apps/src/lib/node/ledger/shell/vote_extensions/eth_events.rs b/crates/apps/src/lib/node/ledger/shell/vote_extensions/eth_events.rs index 881e25e278..d074c074a3 100644 --- a/crates/apps/src/lib/node/ledger/shell/vote_extensions/eth_events.rs +++ b/crates/apps/src/lib/node/ledger/shell/vote_extensions/eth_events.rs @@ -1,8 +1,9 @@ //! Extend Tendermint votes with Ethereum events seen by a quorum of validators. -use std::collections::{BTreeMap, HashMap}; +use std::collections::BTreeMap; use namada::vote_ext::ethereum_events::MultiSignedEthEvent; +use namada_sdk::collections::HashMap; use super::*; @@ -135,7 +136,6 @@ where #[cfg(test)] mod test_vote_extensions { - use borsh_ext::BorshSerializeExt; use namada::core::address::testing::gen_established_address; use namada::core::ethereum_events::{ diff --git a/crates/apps/src/lib/node/ledger/shell/vote_extensions/val_set_update.rs b/crates/apps/src/lib/node/ledger/shell/vote_extensions/val_set_update.rs index 1eba475c22..695032e0b4 100644 --- a/crates/apps/src/lib/node/ledger/shell/vote_extensions/val_set_update.rs +++ b/crates/apps/src/lib/node/ledger/shell/vote_extensions/val_set_update.rs @@ -1,7 +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 super::*; diff --git a/crates/apps/src/lib/node/ledger/storage/mod.rs b/crates/apps/src/lib/node/ledger/storage/mod.rs index 7da4d37fc9..144a9e0dd7 100644 --- a/crates/apps/src/lib/node/ledger/storage/mod.rs +++ b/crates/apps/src/lib/node/ledger/storage/mod.rs @@ -52,11 +52,10 @@ fn new_blake2b() -> Blake2b { #[cfg(test)] mod tests { - use std::collections::HashMap; - use borsh::BorshDeserialize; use itertools::Itertools; use namada::core::chain::ChainId; + use namada::core::collections::HashMap; use namada::core::ethereum_events::Uint; use namada::core::hash::Hash; use namada::core::keccak::KeccakHash; diff --git a/crates/apps/src/lib/wallet/defaults.rs b/crates/apps/src/lib/wallet/defaults.rs index 1885c2ade7..2393b28c6b 100644 --- a/crates/apps/src/lib/wallet/defaults.rs +++ b/crates/apps/src/lib/wallet/defaults.rs @@ -10,13 +10,12 @@ pub use dev::{ #[cfg(any(test, feature = "testing", feature = "benches"))] mod dev { - use std::collections::HashMap; - use lazy_static::lazy_static; use namada::core::address::testing::{ apfel, btc, dot, eth, kartoffel, nam, schnitzel, }; use namada::core::address::Address; + use namada::core::collections::HashMap; use namada::core::key::*; use namada::ledger::{governance, pgf, pos}; use namada_sdk::wallet::alias::Alias; diff --git a/crates/apps/src/lib/wasm_loader/mod.rs b/crates/apps/src/lib/wasm_loader/mod.rs index f7248d74e4..99e29be69a 100644 --- a/crates/apps/src/lib/wasm_loader/mod.rs +++ b/crates/apps/src/lib/wasm_loader/mod.rs @@ -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; diff --git a/crates/benches/host_env.rs b/crates/benches/host_env.rs index a3955d44c4..c57877b2af 100644 --- a/crates/benches/host_env.rs +++ b/crates/benches/host_env.rs @@ -1,8 +1,7 @@ -use std::collections::{HashMap, HashSet}; - use criterion::{criterion_group, criterion_main, Criterion}; use namada::core::account::AccountPublicKeysMap; use namada::core::address; +use namada::core::collections::{HashMap, HashSet}; use namada::ledger::storage::DB; use namada::token::{Amount, Transfer}; use namada::tx::Signature; diff --git a/crates/benches/native_vps.rs b/crates/benches/native_vps.rs index e9c9708b50..618fb2e00d 100644 --- a/crates/benches/native_vps.rs +++ b/crates/benches/native_vps.rs @@ -1,11 +1,12 @@ 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::address::{self, Address, InternalAddress}; +use namada::core::collections::HashMap; use namada::core::eth_bridge_pool::{GasFee, PendingTransfer}; use namada::core::masp::{TransferSource, TransferTarget}; use namada::eth_bridge::storage::whitelist; diff --git a/crates/benches/txs.rs b/crates/benches/txs.rs index 04a40f74b7..c29b928e2a 100644 --- a/crates/benches/txs.rs +++ b/crates/benches/txs.rs @@ -1,9 +1,9 @@ -use std::collections::HashMap; use std::str::FromStr; use criterion::{criterion_group, criterion_main, Criterion}; use namada::account::{InitAccount, UpdateAccount}; use namada::core::address::{self, Address}; +use namada::core::collections::HashMap; use namada::core::eth_bridge_pool::{GasFee, PendingTransfer}; use namada::core::hash::Hash; use namada::core::key::{ diff --git a/crates/core/src/account.rs b/crates/core/src/account.rs index 10c7d936ca..e013dc7178 100644 --- a/crates/core/src/account.rs +++ b/crates/core/src/account.rs @@ -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( diff --git a/crates/core/src/address.rs b/crates/core/src/address.rs index 1a6b524dba..611add65a0 100644 --- a/crates/core/src/address.rs +++ b/crates/core/src/address.rs @@ -675,11 +675,10 @@ pub fn gen_deterministic_established_address(seed: impl AsRef) -> Address { /// Helpers for testing with addresses. #[cfg(any(test, feature = "testing"))] pub mod testing { - use std::collections::HashMap; - use proptest::prelude::*; use super::*; + use crate::collections::HashMap; use crate::key::*; use crate::token::Denomination; diff --git a/crates/core/src/event.rs b/crates/core/src/event.rs index d82121de50..f8b2aaa48e 100644 --- a/crates/core/src/event.rs +++ b/crates/core/src/event.rs @@ -1,6 +1,5 @@ //! Ledger events -use std::collections::HashMap; use std::fmt::{self, Display}; use std::ops::{Index, IndexMut}; use std::str::FromStr; @@ -8,6 +7,7 @@ use std::str::FromStr; use thiserror::Error; use crate::borsh::{BorshDeserialize, BorshSerialize}; +use crate::collections::HashMap; use crate::ethereum_structs::{BpTransferStatus, EthBridgeEvent}; use crate::ibc::IbcEvent; diff --git a/crates/core/src/ibc.rs b/crates/core/src/ibc.rs index d3d5995b09..c5f979332a 100644 --- a/crates/core/src/ibc.rs +++ b/crates/core/src/ibc.rs @@ -1,7 +1,6 @@ //! IBC-related data types use std::cmp::Ordering; -use std::collections::HashMap; use std::str::FromStr; use borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; @@ -12,6 +11,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::{ diff --git a/crates/encoding_spec/src/main.rs b/crates/encoding_spec/src/main.rs index 70bb8db141..ea5858ae3f 100644 --- a/crates/encoding_spec/src/main.rs +++ b/crates/encoding_spec/src/main.rs @@ -15,7 +15,7 @@ #![deny(rustdoc::broken_intra_doc_links)] #![deny(rustdoc::private_intra_doc_links)] -use std::collections::{BTreeMap, HashSet}; +use std::collections::BTreeMap; use std::io::Write; use borsh::schema::{BorshSchemaContainer, Declaration, Definition}; @@ -25,6 +25,7 @@ use lazy_static::lazy_static; use madato::types::TableRow; use namada::account; use namada::core::address::Address; +use namada::core::collections::HashSet; use namada::core::key::ed25519::{PublicKey, Signature}; use namada::core::storage::{self, Epoch}; use namada::core::token; diff --git a/crates/ethereum_bridge/src/protocol/transactions/bridge_pool_roots.rs b/crates/ethereum_bridge/src/protocol/transactions/bridge_pool_roots.rs index 088806bffa..a8dc6ede33 100644 --- a/crates/ethereum_bridge/src/protocol/transactions/bridge_pool_roots.rs +++ b/crates/ethereum_bridge/src/protocol/transactions/bridge_pool_roots.rs @@ -1,7 +1,6 @@ -use std::collections::{HashMap, HashSet}; - use eyre::Result; use namada_core::address::Address; +use namada_core::collections::{HashMap, HashSet}; use namada_core::keccak::keccak_hash; use namada_core::key::{common, SignableEthMessage}; use namada_core::storage::BlockHeight; diff --git a/crates/ethereum_bridge/src/protocol/transactions/ethereum_events/events.rs b/crates/ethereum_bridge/src/protocol/transactions/ethereum_events/events.rs index 818ec66f10..873a8e0375 100644 --- a/crates/ethereum_bridge/src/protocol/transactions/ethereum_events/events.rs +++ b/crates/ethereum_bridge/src/protocol/transactions/ethereum_events/events.rs @@ -1,11 +1,12 @@ //! Logic for acting on events -use std::collections::{BTreeSet, HashSet}; +use std::collections::BTreeSet; use std::str::FromStr; use borsh::BorshDeserialize; use eyre::{Result, WrapErr}; use namada_core::address::Address; +use namada_core::collections::HashSet; use namada_core::eth_abi::Encode; use namada_core::eth_bridge_pool::{ erc20_nut_address, erc20_token_address, PendingTransfer, @@ -355,7 +356,7 @@ where balance.spend(&pending_transfer.gas_fee.amount) })?; state.delete(&key)?; - _ = pending_keys.remove(&key); + _ = pending_keys.swap_remove(&key); _ = changed_keys.insert(key); _ = changed_keys.insert(pool_balance_key); _ = changed_keys.insert(relayer_rewards_key); @@ -568,11 +569,10 @@ where #[cfg(test)] mod tests { - use std::collections::HashMap; - use assert_matches::assert_matches; use namada_core::address::gen_established_address; use namada_core::address::testing::{gen_implicit_address, nam, wnam}; + use namada_core::collections::HashMap; use namada_core::eth_bridge_pool::GasFee; use namada_core::ethereum_events::testing::{ arbitrary_keccak_hash, arbitrary_nonce, DAI_ERC20_ETH_ADDRESS, diff --git a/crates/ethereum_bridge/src/protocol/transactions/ethereum_events/mod.rs b/crates/ethereum_bridge/src/protocol/transactions/ethereum_events/mod.rs index 99dec94cb4..6ad568aa3f 100644 --- a/crates/ethereum_bridge/src/protocol/transactions/ethereum_events/mod.rs +++ b/crates/ethereum_bridge/src/protocol/transactions/ethereum_events/mod.rs @@ -3,12 +3,13 @@ mod eth_msgs; mod events; -use std::collections::{BTreeSet, HashMap, HashSet}; +use std::collections::BTreeSet; use borsh::BorshDeserialize; use eth_msgs::EthMsgUpdate; use eyre::Result; use namada_core::address::Address; +use namada_core::collections::{HashMap, HashSet}; use namada_core::ethereum_events::EthereumEvent; use namada_core::ethereum_structs::EthBridgeEvent; use namada_core::key::common; diff --git a/crates/ethereum_bridge/src/protocol/transactions/utils.rs b/crates/ethereum_bridge/src/protocol/transactions/utils.rs index 5f57f11849..995df8125d 100644 --- a/crates/ethereum_bridge/src/protocol/transactions/utils.rs +++ b/crates/ethereum_bridge/src/protocol/transactions/utils.rs @@ -1,8 +1,9 @@ -use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet}; +use std::collections::{BTreeMap, BTreeSet}; use eyre::eyre; use itertools::Itertools; use namada_core::address::Address; +use namada_core::collections::{HashMap, HashSet}; use namada_core::storage::BlockHeight; use namada_core::token; use namada_proof_of_stake::pos_queries::PosQueries; diff --git a/crates/ethereum_bridge/src/protocol/transactions/validator_set_update/mod.rs b/crates/ethereum_bridge/src/protocol/transactions/validator_set_update/mod.rs index 13de4cd87a..de1f817705 100644 --- a/crates/ethereum_bridge/src/protocol/transactions/validator_set_update/mod.rs +++ b/crates/ethereum_bridge/src/protocol/transactions/validator_set_update/mod.rs @@ -1,9 +1,8 @@ //! Code for handling validator set update protocol txs. -use std::collections::{HashMap, HashSet}; - use eyre::Result; use namada_core::address::Address; +use namada_core::collections::{HashMap, HashSet}; use namada_core::key::common; use namada_core::storage::{BlockHeight, Epoch}; use namada_core::token::Amount; diff --git a/crates/ethereum_bridge/src/protocol/transactions/votes.rs b/crates/ethereum_bridge/src/protocol/transactions/votes.rs index be8a097200..32efab6557 100644 --- a/crates/ethereum_bridge/src/protocol/transactions/votes.rs +++ b/crates/ethereum_bridge/src/protocol/transactions/votes.rs @@ -1,11 +1,12 @@ //! Logic and data types relating to tallying validators' votes for pieces of //! data stored in the ledger, where those pieces of data should only be acted //! on once they have received enough votes -use std::collections::{BTreeMap, BTreeSet, HashMap}; +use std::collections::{BTreeMap, BTreeSet}; use borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; use eyre::{eyre, Result}; use namada_core::address::Address; +use namada_core::collections::HashMap; use namada_core::storage::{BlockHeight, Epoch}; use namada_core::token; use namada_core::voting_power::FractionalVotingPower; diff --git a/crates/ethereum_bridge/src/protocol/transactions/votes/update.rs b/crates/ethereum_bridge/src/protocol/transactions/votes/update.rs index d2dc8c9dc5..a1da975531 100644 --- a/crates/ethereum_bridge/src/protocol/transactions/votes/update.rs +++ b/crates/ethereum_bridge/src/protocol/transactions/votes/update.rs @@ -1,8 +1,9 @@ -use std::collections::{BTreeSet, HashMap, HashSet}; +use std::collections::BTreeSet; use borsh::BorshDeserialize; use eyre::{eyre, Result}; use namada_core::address::Address; +use namada_core::collections::{HashMap, HashSet}; use namada_core::storage::BlockHeight; use namada_core::token; use namada_proof_of_stake::pos_queries::PosQueries; @@ -60,7 +61,7 @@ impl NewVotes { let mut inner = self.inner; let mut removed = HashSet::default(); for voter in voters { - if inner.remove(voter).is_some() { + if inner.swap_remove(voter).is_some() { removed.insert(voter); } } @@ -69,7 +70,7 @@ impl NewVotes { } impl IntoIterator for NewVotes { - type IntoIter = std::collections::hash_set::IntoIter; + type IntoIter = namada_core::collections::hash_set::IntoIter; type Item = (Address, BlockHeight, token::Amount); fn into_iter(self) -> Self::IntoIter { diff --git a/crates/ethereum_bridge/src/storage/proof.rs b/crates/ethereum_bridge/src/storage/proof.rs index 2f5895f363..4fee82a3ae 100644 --- a/crates/ethereum_bridge/src/storage/proof.rs +++ b/crates/ethereum_bridge/src/storage/proof.rs @@ -1,9 +1,8 @@ //! Proofs over some arbitrary data. -use std::collections::HashMap; - use borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; use ethers::abi::Tokenizable; +use namada_core::collections::HashMap; use namada_core::eth_abi::Encode; use namada_core::ethereum_events::Uint; use namada_core::keccak::KeccakHash; diff --git a/crates/ethereum_bridge/src/test_utils.rs b/crates/ethereum_bridge/src/test_utils.rs index 28d42921a6..cc678a79b2 100644 --- a/crates/ethereum_bridge/src/test_utils.rs +++ b/crates/ethereum_bridge/src/test_utils.rs @@ -1,11 +1,11 @@ //! Test utilities for the Ethereum bridge crate. -use std::collections::HashMap; use std::num::NonZeroU64; use namada_account::protocol_pk_key; use namada_core::address::testing::wnam; use namada_core::address::{self, Address}; +use namada_core::collections::HashMap; use namada_core::dec::Dec; use namada_core::ethereum_events::EthAddress; use namada_core::keccak::KeccakHash; diff --git a/crates/governance/src/pgf/cli/steward.rs b/crates/governance/src/pgf/cli/steward.rs index bac7482603..c6e0196187 100644 --- a/crates/governance/src/pgf/cli/steward.rs +++ b/crates/governance/src/pgf/cli/steward.rs @@ -1,6 +1,5 @@ -use std::collections::HashMap; - use namada_core::address::Address; +use namada_core::collections::HashMap; use namada_core::dec::Dec; use serde::{Deserialize, Serialize}; diff --git a/crates/governance/src/pgf/storage/mod.rs b/crates/governance/src/pgf/storage/mod.rs index 1b523ecf9a..7dbd54f2c1 100644 --- a/crates/governance/src/pgf/storage/mod.rs +++ b/crates/governance/src/pgf/storage/mod.rs @@ -5,9 +5,8 @@ pub mod keys; /// Pgf steward structures pub mod steward; -use std::collections::HashMap; - use namada_core::address::Address; +use namada_core::collections::HashMap; use namada_core::dec::Dec; use namada_storage::{Result, StorageRead, StorageWrite}; diff --git a/crates/governance/src/pgf/storage/steward.rs b/crates/governance/src/pgf/storage/steward.rs index 973c33ed78..b44fff23e6 100644 --- a/crates/governance/src/pgf/storage/steward.rs +++ b/crates/governance/src/pgf/storage/steward.rs @@ -1,7 +1,6 @@ -use std::collections::HashMap; - use borsh::{BorshDeserialize, BorshSerialize}; use namada_core::address::Address; +use namada_core::collections::HashMap; use namada_core::dec::Dec; use crate::pgf::REWARD_DISTRIBUTION_LIMIT; diff --git a/crates/governance/src/utils.rs b/crates/governance/src/utils.rs index 4619c90473..b8725b393e 100644 --- a/crates/governance/src/utils.rs +++ b/crates/governance/src/utils.rs @@ -1,8 +1,8 @@ -use std::collections::HashMap; use std::fmt::Display; use namada_core::address::Address; use namada_core::borsh::{BorshDeserialize, BorshSerialize}; +use namada_core::collections::HashMap; use namada_core::dec::Dec; use namada_core::storage::Epoch; use namada_core::token; diff --git a/crates/ibc/src/context/router.rs b/crates/ibc/src/context/router.rs index da7b90c31d..a1b7547c49 100644 --- a/crates/ibc/src/context/router.rs +++ b/crates/ibc/src/context/router.rs @@ -1,8 +1,8 @@ //! Functions to handle IBC modules -use std::collections::HashMap; use std::rc::Rc; +use namada_core::collections::HashMap; use namada_core::ibc::core::host::types::identifiers::PortId; use namada_core::ibc::core::router::module::Module; use namada_core::ibc::core::router::router::Router; diff --git a/crates/light_sdk/src/reading/asynchronous/pos.rs b/crates/light_sdk/src/reading/asynchronous/pos.rs index 9330db274d..c2e67c3f0a 100644 --- a/crates/light_sdk/src/reading/asynchronous/pos.rs +++ b/crates/light_sdk/src/reading/asynchronous/pos.rs @@ -1,5 +1,6 @@ -use std::collections::{BTreeSet, HashMap, HashSet}; +use std::collections::BTreeSet; +use namada_sdk::collections::{HashMap, HashSet}; use namada_sdk::key::common; use namada_sdk::proof_of_stake::types::{ BondsAndUnbondsDetails, CommissionPair, ValidatorMetaData, ValidatorState, diff --git a/crates/light_sdk/src/reading/blocking/pos.rs b/crates/light_sdk/src/reading/blocking/pos.rs index 4a070d36f8..231adf5349 100644 --- a/crates/light_sdk/src/reading/blocking/pos.rs +++ b/crates/light_sdk/src/reading/blocking/pos.rs @@ -1,6 +1,7 @@ -use std::collections::{BTreeSet, HashMap, HashSet}; +use std::collections::BTreeSet; use namada_sdk::address::Address; +use namada_sdk::collections::{HashMap, HashSet}; use namada_sdk::key::common; use namada_sdk::proof_of_stake::types::{ BondsAndUnbondsDetails, CommissionPair, ValidatorMetaData, ValidatorState, diff --git a/crates/light_sdk/src/transaction/pgf.rs b/crates/light_sdk/src/transaction/pgf.rs index 48afb38a68..8aebe3c3e7 100644 --- a/crates/light_sdk/src/transaction/pgf.rs +++ b/crates/light_sdk/src/transaction/pgf.rs @@ -1,6 +1,5 @@ -use std::collections::HashMap; - use namada_sdk::address::Address; +use namada_sdk::collections::HashMap; use namada_sdk::dec::Dec; use namada_sdk::hash::Hash; use namada_sdk::key::common; diff --git a/crates/namada/src/ledger/governance/utils.rs b/crates/namada/src/ledger/governance/utils.rs index 3b79168723..ec31e87d54 100644 --- a/crates/namada/src/ledger/governance/utils.rs +++ b/crates/namada/src/ledger/governance/utils.rs @@ -1,7 +1,6 @@ //! Governance utility functions -use std::collections::HashMap; - +use namada_core::collections::HashMap; use namada_governance::utils::TallyResult; use namada_sdk::events::{Event, EventLevel}; use thiserror::Error; diff --git a/crates/namada/src/ledger/native_vp/ethereum_bridge/vp.rs b/crates/namada/src/ledger/native_vp/ethereum_bridge/vp.rs index 52f3012901..e02de3d52c 100644 --- a/crates/namada/src/ledger/native_vp/ethereum_bridge/vp.rs +++ b/crates/namada/src/ledger/native_vp/ethereum_bridge/vp.rs @@ -1,8 +1,10 @@ //! Validity predicate for the Ethereum bridge -use std::collections::{BTreeSet, HashSet}; + +use std::collections::BTreeSet; use eyre::{eyre, Result}; use namada_core::address::Address; +use namada_core::collections::HashSet; use namada_core::storage::Key; use namada_ethereum_bridge::storage; use namada_ethereum_bridge::storage::escrow_key; diff --git a/crates/namada/src/ledger/native_vp/ibc/context.rs b/crates/namada/src/ledger/native_vp/ibc/context.rs index e4cfd76dd7..f0469a35a9 100644 --- a/crates/namada/src/ledger/native_vp/ibc/context.rs +++ b/crates/namada/src/ledger/native_vp/ibc/context.rs @@ -1,8 +1,9 @@ //! Contexts for IBC validity predicate -use std::collections::{BTreeSet, HashMap, HashSet}; +use std::collections::BTreeSet; use borsh_ext::BorshSerializeExt; +use namada_core::collections::{HashMap, HashSet}; use namada_core::storage::Epochs; use namada_ibc::{IbcCommonContext, IbcStorageContext}; use namada_state::{StateRead, StorageError, StorageRead, StorageWrite}; diff --git a/crates/namada/src/ledger/native_vp/ibc/mod.rs b/crates/namada/src/ledger/native_vp/ibc/mod.rs index e16f7af60f..019e974f88 100644 --- a/crates/namada/src/ledger/native_vp/ibc/mod.rs +++ b/crates/namada/src/ledger/native_vp/ibc/mod.rs @@ -3,12 +3,13 @@ pub mod context; use std::cell::RefCell; -use std::collections::{BTreeSet, HashSet}; +use std::collections::BTreeSet; use std::rc::Rc; use std::time::Duration; use context::{PseudoExecutionContext, VpValidationContext}; use namada_core::address::Address; +use namada_core::collections::HashSet; use namada_core::storage::Key; use namada_gas::{IBC_ACTION_EXECUTE_GAS, IBC_ACTION_VALIDATE_GAS}; use namada_ibc::{ diff --git a/crates/namada/src/ledger/native_vp/masp.rs b/crates/namada/src/ledger/native_vp/masp.rs index 874bb6a464..e4e52b489e 100644 --- a/crates/namada/src/ledger/native_vp/masp.rs +++ b/crates/namada/src/ledger/native_vp/masp.rs @@ -1,7 +1,7 @@ //! MASP native VP use std::cmp::Ordering; -use std::collections::{BTreeSet, HashMap, HashSet}; +use std::collections::BTreeSet; use borsh_ext::BorshSerializeExt; use masp_primitives::asset_type::AssetType; @@ -11,6 +11,7 @@ use masp_primitives::transaction::components::I128Sum; use masp_primitives::transaction::Transaction; use namada_core::address::Address; use namada_core::address::InternalAddress::Masp; +use namada_core::collections::{HashMap, HashSet}; use namada_core::masp::encode_asset_type; use namada_core::storage::{IndexedTx, Key}; use namada_gas::MASP_VERIFY_SHIELDED_TX_GAS; diff --git a/crates/namada/src/ledger/native_vp/mod.rs b/crates/namada/src/ledger/native_vp/mod.rs index 1a6dc2e517..1700ec8548 100644 --- a/crates/namada/src/ledger/native_vp/mod.rs +++ b/crates/namada/src/ledger/native_vp/mod.rs @@ -630,7 +630,7 @@ where #[cfg(any(test, feature = "testing"))] pub(super) mod testing { - use std::collections::HashMap; + use namada_core::collections::HashMap; use super::*; diff --git a/crates/namada/src/ledger/native_vp/multitoken.rs b/crates/namada/src/ledger/native_vp/multitoken.rs index 1286fa1a67..860e98794b 100644 --- a/crates/namada/src/ledger/native_vp/multitoken.rs +++ b/crates/namada/src/ledger/native_vp/multitoken.rs @@ -1,7 +1,8 @@ //! Native VP for multitokens -use std::collections::{BTreeSet, HashMap}; +use std::collections::BTreeSet; +use namada_core::collections::HashMap; use namada_governance::is_proposal_accepted; use namada_state::StateRead; use namada_token::storage_key::is_any_token_parameter_key; diff --git a/crates/namada/src/ledger/pgf/utils.rs b/crates/namada/src/ledger/pgf/utils.rs index 6f6153885e..88945f43f6 100644 --- a/crates/namada/src/ledger/pgf/utils.rs +++ b/crates/namada/src/ledger/pgf/utils.rs @@ -1,6 +1,5 @@ -use std::collections::HashMap; - use namada_core::address::Address; +use namada_core::collections::HashMap; use crate::ledger::events::EventType; use crate::token; diff --git a/crates/namada/src/ledger/protocol/mod.rs b/crates/namada/src/ledger/protocol/mod.rs index 6a7991ef65..2135315a90 100644 --- a/crates/namada/src/ledger/protocol/mod.rs +++ b/crates/namada/src/ledger/protocol/mod.rs @@ -1032,11 +1032,10 @@ fn merge_vp_results( #[cfg(test)] mod tests { - use std::collections::HashMap; - use borsh::BorshDeserialize; use eyre::Result; use namada_core::chain::ChainId; + use namada_core::collections::HashMap; use namada_core::ethereum_events::testing::DAI_ERC20_ETH_ADDRESS; use namada_core::ethereum_events::{EthereumEvent, TransferToNamada}; use namada_core::keccak::keccak_hash; diff --git a/crates/namada/src/vm/prefix_iter.rs b/crates/namada/src/vm/prefix_iter.rs index 0044e2d17a..2d9ceac4b7 100644 --- a/crates/namada/src/vm/prefix_iter.rs +++ b/crates/namada/src/vm/prefix_iter.rs @@ -1,8 +1,7 @@ //! The storage prefix iterators can be used to iterate over a common prefix of //! storage keys. -use std::collections::HashMap; - +use namada_core::collections::HashMap; use namada_state::PrefixIter; /// A temporary iterators storage, used during a wasm run after which it's diff --git a/crates/namada/src/vm/wasm/compilation_cache/common.rs b/crates/namada/src/vm/wasm/compilation_cache/common.rs index 08f03e0d04..56b31607ca 100644 --- a/crates/namada/src/vm/wasm/compilation_cache/common.rs +++ b/crates/namada/src/vm/wasm/compilation_cache/common.rs @@ -5,7 +5,6 @@ //! `universal` module). use std::collections::hash_map::RandomState; -use std::collections::HashMap; use std::fs; use std::marker::PhantomData; use std::num::NonZeroUsize; @@ -15,6 +14,7 @@ use std::thread::sleep; use std::time::Duration; use clru::{CLruCache, CLruCacheConfig, WeightScale}; +use namada_core::collections::HashMap; use wasmer::{Module, Store}; use wasmer_cache::{FileSystemCache, Hash as CacheHash}; @@ -366,7 +366,7 @@ impl Cache { err ); let mut progress = self.progress.write().unwrap(); - progress.remove(&hash); + progress.swap_remove(&hash); Err(err) } }, @@ -377,7 +377,7 @@ impl Cache { err ); let mut progress = self.progress.write().unwrap(); - progress.remove(&hash); + progress.swap_remove(&hash); Err(err) } } @@ -441,7 +441,7 @@ impl Cache { hash.to_string(), err ); - progress.remove(&hash); + progress.swap_remove(&hash); return Err(err); } }, @@ -453,7 +453,7 @@ impl Cache { hash.to_string(), err ); - progress.remove(&hash); + progress.swap_remove(&hash); return Err(err); } }; diff --git a/crates/proof_of_stake/src/epoched.rs b/crates/proof_of_stake/src/epoched.rs index f218c74e5a..cccc36f19d 100644 --- a/crates/proof_of_stake/src/epoched.rs +++ b/crates/proof_of_stake/src/epoched.rs @@ -1,12 +1,12 @@ //! [`Epoched`] and [`EpochedDelta`] are structures for data that is set for //! future (and possibly past) epochs. -use std::collections::HashMap; use std::fmt::Debug; use std::marker::PhantomData; use std::{cmp, ops}; use borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; +use namada_core::collections::HashMap; use namada_core::storage::{self, Epoch}; use namada_storage::collections::lazy_map::{LazyMap, NestedMap}; use namada_storage::collections::{self, LazyCollection}; diff --git a/crates/proof_of_stake/src/lib.rs b/crates/proof_of_stake/src/lib.rs index 4eaf8fc281..dda8099ea2 100644 --- a/crates/proof_of_stake/src/lib.rs +++ b/crates/proof_of_stake/src/lib.rs @@ -24,10 +24,11 @@ mod tests; use core::fmt::Debug; use std::cmp::{self}; -use std::collections::{BTreeMap, BTreeSet, HashSet}; +use std::collections::{BTreeMap, BTreeSet}; pub use error::*; use namada_core::address::{Address, InternalAddress}; +use namada_core::collections::HashSet; use namada_core::dec::Dec; use namada_core::event::EmitEvents; use namada_core::key::common; diff --git a/crates/proof_of_stake/src/queries.rs b/crates/proof_of_stake/src/queries.rs index 361f82d258..fb3d2e0c7e 100644 --- a/crates/proof_of_stake/src/queries.rs +++ b/crates/proof_of_stake/src/queries.rs @@ -1,10 +1,11 @@ //! Queriezzz use std::cmp; -use std::collections::{BTreeMap, HashMap, HashSet}; +use std::collections::BTreeMap; use borsh::BorshDeserialize; use namada_core::address::Address; +use namada_core::collections::{HashMap, HashSet}; use namada_core::dec::Dec; use namada_core::storage::Epoch; use namada_core::token; diff --git a/crates/proof_of_stake/src/rewards.rs b/crates/proof_of_stake/src/rewards.rs index e9c8ab72e7..32852aabfd 100644 --- a/crates/proof_of_stake/src/rewards.rs +++ b/crates/proof_of_stake/src/rewards.rs @@ -1,8 +1,7 @@ //! PoS rewards distribution. -use std::collections::{HashMap, HashSet}; - use namada_core::address::{self, Address}; +use namada_core::collections::{HashMap, HashSet}; use namada_core::dec::Dec; use namada_core::storage::{BlockHeight, Epoch}; use namada_core::token::{self, Amount}; diff --git a/crates/proof_of_stake/src/slashing.rs b/crates/proof_of_stake/src/slashing.rs index 513027fe49..fe5fd5f018 100644 --- a/crates/proof_of_stake/src/slashing.rs +++ b/crates/proof_of_stake/src/slashing.rs @@ -1,10 +1,11 @@ //! Slashing tingzzzz use std::cmp::{self, Reverse}; -use std::collections::{BTreeMap, BTreeSet, HashMap}; +use std::collections::{BTreeMap, BTreeSet}; use borsh::BorshDeserialize; use namada_core::address::Address; +use namada_core::collections::HashMap; use namada_core::dec::Dec; use namada_core::key::tm_raw_hash_to_string; use namada_core::storage::{BlockHeight, Epoch}; diff --git a/crates/proof_of_stake/src/storage.rs b/crates/proof_of_stake/src/storage.rs index 9cae1168a9..ac4e06d605 100644 --- a/crates/proof_of_stake/src/storage.rs +++ b/crates/proof_of_stake/src/storage.rs @@ -1,10 +1,11 @@ //! PoS functions for reading and writing to storage and lazy collection handles //! associated with given `storage_key`s. -use std::collections::{BTreeSet, HashSet}; +use std::collections::BTreeSet; use namada_account::protocol_pk_key; use namada_core::address::Address; +use namada_core::collections::HashSet; use namada_core::dec::Dec; use namada_core::key::{common, tm_consensus_key_raw_hash}; use namada_core::storage::Epoch; diff --git a/crates/proof_of_stake/src/tests/state_machine.rs b/crates/proof_of_stake/src/tests/state_machine.rs index 7bf14ce6d5..aef82ded92 100644 --- a/crates/proof_of_stake/src/tests/state_machine.rs +++ b/crates/proof_of_stake/src/tests/state_machine.rs @@ -1,12 +1,13 @@ //! Test PoS transitions with a state machine use std::cmp; -use std::collections::{BTreeMap, BTreeSet, HashSet, VecDeque}; +use std::collections::{BTreeMap, BTreeSet, VecDeque}; use std::ops::Deref; use assert_matches::assert_matches; use itertools::Itertools; use namada_core::address::{self, Address}; +use namada_core::collections::HashSet; use namada_core::dec::Dec; use namada_core::key; use namada_core::key::common::PublicKey; @@ -2602,7 +2603,7 @@ impl ReferenceStateMachine for AbstractPosState { .below_threshold_set .entry(current_epoch + offset) .or_default() - .remove(address); + .swap_remove(address); debug_assert!(removed); } else { // Just make sure the validator is already jailed @@ -3753,7 +3754,7 @@ impl AbstractPosState { ValidatorState::BelowThreshold => { // We know that this validator will be promoted into one of the // higher sets, so first remove from the below-threshold set. - below_thresh_set.remove(validator); + below_thresh_set.swap_remove(validator); let num_consensus = consensus_set.iter().fold(0, |sum, (_, validators)| { diff --git a/crates/proof_of_stake/src/tests/state_machine_v2.rs b/crates/proof_of_stake/src/tests/state_machine_v2.rs index 9a2d1234d7..f7253586d2 100644 --- a/crates/proof_of_stake/src/tests/state_machine_v2.rs +++ b/crates/proof_of_stake/src/tests/state_machine_v2.rs @@ -1,6 +1,6 @@ //! Test PoS transitions with a state machine -use std::collections::{BTreeMap, BTreeSet, HashSet, VecDeque}; +use std::collections::{BTreeMap, BTreeSet, VecDeque}; use std::ops::{AddAssign, Deref}; use std::{cmp, mem}; @@ -8,6 +8,7 @@ use assert_matches::assert_matches; use derivative::Derivative; use itertools::Itertools; use namada_core::address::{self, Address}; +use namada_core::collections::HashSet; use namada_core::dec::Dec; use namada_core::key; use namada_core::key::common::PublicKey; @@ -768,7 +769,7 @@ impl AbstractPosState { ValidatorState::BelowThreshold => { // We know that this validator will be promoted into one of the // higher sets, so first remove from the below-threshold set. - below_thresh_set.remove(validator); + below_thresh_set.swap_remove(validator); let num_consensus = consensus_set.iter().fold(0, |sum, (_, validators)| { @@ -4072,7 +4073,7 @@ impl ReferenceStateMachine for AbstractPosState { .below_threshold_set .entry(current_epoch + offset) .or_default() - .remove(address); + .swap_remove(address); debug_assert!(removed); } else { // Just make sure the validator is already jailed diff --git a/crates/proof_of_stake/src/tests/test_pos.rs b/crates/proof_of_stake/src/tests/test_pos.rs index afd40941ed..87abf4cf01 100644 --- a/crates/proof_of_stake/src/tests/test_pos.rs +++ b/crates/proof_of_stake/src/tests/test_pos.rs @@ -1,9 +1,10 @@ //! PoS system tests -use std::collections::{BTreeMap, HashSet}; +use std::collections::BTreeMap; use assert_matches::assert_matches; use namada_core::address::Address; +use namada_core::collections::HashSet; use namada_core::dec::Dec; use namada_core::key::testing::{common_sk_from_simple_seed, gen_keypair}; use namada_core::key::RefTo; @@ -223,7 +224,7 @@ fn test_test_init_genesis_aux( for (i, validator) in validators.into_iter().enumerate() { let addr = &validator.address; let self_bonds = bond_details - .remove(&BondId { + .swap_remove(&BondId { source: addr.clone(), validator: addr.clone(), }) diff --git a/crates/proof_of_stake/src/types/mod.rs b/crates/proof_of_stake/src/types/mod.rs index f0567a3aae..572b99839f 100644 --- a/crates/proof_of_stake/src/types/mod.rs +++ b/crates/proof_of_stake/src/types/mod.rs @@ -3,13 +3,14 @@ mod rev_order; use core::fmt::Debug; -use std::collections::{BTreeMap, HashMap}; +use std::collections::BTreeMap; use std::fmt::Display; use std::hash::Hash; use std::ops::Sub; use borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; use namada_core::address::Address; +use namada_core::collections::HashMap; use namada_core::dec::Dec; use namada_core::key::common; use namada_core::storage::{Epoch, KeySeg}; diff --git a/crates/proof_of_stake/src/validator_set_update.rs b/crates/proof_of_stake/src/validator_set_update.rs index 8d15820b88..2a3d7a13d3 100644 --- a/crates/proof_of_stake/src/validator_set_update.rs +++ b/crates/proof_of_stake/src/validator_set_update.rs @@ -1,8 +1,7 @@ //! Validator set updates -use std::collections::{HashMap, HashSet}; - use namada_core::address::Address; +use namada_core::collections::{HashMap, HashSet}; use namada_core::key::PublicKeyTmRawHash; use namada_core::storage::Epoch; use namada_core::token; diff --git a/crates/sdk/src/args.rs b/crates/sdk/src/args.rs index 1b3617be49..15b936c154 100644 --- a/crates/sdk/src/args.rs +++ b/crates/sdk/src/args.rs @@ -1,11 +1,11 @@ //! Structures encapsulating SDK arguments -use std::collections::HashMap; use std::path::PathBuf; use std::time::Duration as StdDuration; use namada_core::address::Address; use namada_core::chain::ChainId; +use namada_core::collections::HashMap; use namada_core::dec::Dec; use namada_core::ethereum_events::EthAddress; use namada_core::keccak::KeccakHash; diff --git a/crates/sdk/src/eth_bridge/bridge_pool.rs b/crates/sdk/src/eth_bridge/bridge_pool.rs index 81fe057eb0..5b2f482338 100644 --- a/crates/sdk/src/eth_bridge/bridge_pool.rs +++ b/crates/sdk/src/eth_bridge/bridge_pool.rs @@ -2,7 +2,6 @@ use std::borrow::Cow; use std::cmp::Ordering; -use std::collections::{HashMap, HashSet}; use std::sync::Arc; use borsh_ext::BorshSerializeExt; @@ -10,6 +9,7 @@ use ethbridge_bridge_contract::Bridge; use ethers::providers::Middleware; use futures::future::FutureExt; use namada_core::address::{Address, InternalAddress}; +use namada_core::collections::{HashMap, HashSet}; use namada_core::eth_abi::Encode; use namada_core::eth_bridge_pool::{ erc20_token_address, GasFee, PendingTransfer, TransferToEthereum, @@ -1013,7 +1013,7 @@ mod recommendations { Uint::from_u64( voting_powers .iter() - .filter_map(|(a, &p)| sigs.get(a).map(|_| p)) + .filter_map(|(a, &p)| sigs.get(*a).map(|_| p)) .take_while(|p| { if power <= FractionalVotingPower::TWO_THIRDS { power += FractionalVotingPower::new( diff --git a/crates/sdk/src/events/log.rs b/crates/sdk/src/events/log.rs index 3eb19f89e7..2e1b07cdab 100644 --- a/crates/sdk/src/events/log.rs +++ b/crates/sdk/src/events/log.rs @@ -103,7 +103,7 @@ mod tests { event_type: EventType::Accepted, level: EventLevel::Block, attributes: { - let mut attrs = std::collections::HashMap::new(); + let mut attrs = namada_core::collections::HashMap::new(); attrs.insert("hash".to_string(), hash.to_string()); attrs }, @@ -112,7 +112,7 @@ mod tests { event_type: EventType::Applied, level: EventLevel::Block, attributes: { - let mut attrs = std::collections::HashMap::new(); + let mut attrs = namada_core::collections::HashMap::new(); attrs.insert("hash".to_string(), hash.to_string()); attrs }, diff --git a/crates/sdk/src/events/log/dumb_queries.rs b/crates/sdk/src/events/log/dumb_queries.rs index 1d2b0527a2..e10365b7e2 100644 --- a/crates/sdk/src/events/log/dumb_queries.rs +++ b/crates/sdk/src/events/log/dumb_queries.rs @@ -6,8 +6,7 @@ //! tm.event='NewBlock' AND .<$attr>='<$value>' //! ``` -use std::collections::HashMap; - +use namada_core::collections::HashMap; use namada_core::hash::Hash; use namada_core::storage::BlockHeight; @@ -141,7 +140,7 @@ mod tests { event_type: EventType::Accepted, level: EventLevel::Block, attributes: { - let mut attrs = std::collections::HashMap::new(); + let mut attrs = namada_core::collections::HashMap::new(); attrs.insert("hash".to_string(), HASH.to_string()); attrs }, @@ -152,7 +151,7 @@ mod tests { event_type: EventType::Applied, level: EventLevel::Block, attributes: { - let mut attrs = std::collections::HashMap::new(); + let mut attrs = namada_core::collections::HashMap::new(); attrs.insert("hash".to_string(), HASH.to_string()); attrs }, diff --git a/crates/sdk/src/events/mod.rs b/crates/sdk/src/events/mod.rs index c160e08dc8..222b1a1382 100644 --- a/crates/sdk/src/events/mod.rs +++ b/crates/sdk/src/events/mod.rs @@ -1,8 +1,7 @@ //! Logic to do with events emitted by the ledger. pub mod log; -use std::collections::HashMap; - +use namada_core::collections::HashMap; pub use namada_core::event::{Event, EventError, EventLevel, EventType}; use serde_json::Value; @@ -22,7 +21,7 @@ impl Attributes { /// Get ownership of the value associated to the input key pub fn take(&mut self, key: &str) -> Option { - self.0.remove(key) + self.0.swap_remove(key) } } diff --git a/crates/sdk/src/lib.rs b/crates/sdk/src/lib.rs index 71dc57aa46..13b2fd79f8 100644 --- a/crates/sdk/src/lib.rs +++ b/crates/sdk/src/lib.rs @@ -27,7 +27,6 @@ pub mod io; pub mod queries; pub mod wallet; -use std::collections::HashSet; #[cfg(feature = "async-send")] pub use std::marker::Send as MaybeSend; #[cfg(feature = "async-send")] @@ -37,6 +36,7 @@ use std::str::FromStr; use args::{InputAmount, SdkTypes}; use namada_core::address::Address; +use namada_core::collections::HashSet; use namada_core::dec::Dec; use namada_core::ethereum_events::EthAddress; use namada_core::ibc::core::host::types::identifiers::{ChannelId, PortId}; diff --git a/crates/sdk/src/masp.rs b/crates/sdk/src/masp.rs index 581f548dcb..4cd575d6fe 100644 --- a/crates/sdk/src/masp.rs +++ b/crates/sdk/src/masp.rs @@ -1,7 +1,7 @@ //! MASP verification wrappers. use std::cmp::Ordering; -use std::collections::{btree_map, BTreeMap, BTreeSet, HashMap, HashSet}; +use std::collections::{btree_map, BTreeMap, BTreeSet}; use std::env; use std::fmt::Debug; use std::ops::Deref; @@ -51,6 +51,7 @@ use masp_proofs::prover::LocalTxProver; #[cfg(not(feature = "testing"))] use masp_proofs::sapling::SaplingVerificationContext; use namada_core::address::{Address, MASP}; +use namada_core::collections::{HashMap, HashSet}; use namada_core::dec::Dec; pub use namada_core::masp::{ encode_asset_type, AssetData, BalanceOwner, ExtendedViewingKey, diff --git a/crates/sdk/src/queries/shell/eth_bridge.rs b/crates/sdk/src/queries/shell/eth_bridge.rs index 766d191427..93c9252af0 100644 --- a/crates/sdk/src/queries/shell/eth_bridge.rs +++ b/crates/sdk/src/queries/shell/eth_bridge.rs @@ -1,12 +1,12 @@ //! Ethereum bridge related shell queries. use std::borrow::Cow; -use std::collections::{HashMap, HashSet}; use std::str::FromStr; use borsh::{BorshDeserialize, BorshSerialize}; use borsh_ext::BorshSerializeExt; use namada_core::address::Address; +use namada_core::collections::{HashMap, HashSet}; use namada_core::eth_abi::{Encode, EncodeCell}; use namada_core::eth_bridge_pool::{PendingTransfer, PendingTransferAppendix}; use namada_core::ethereum_events::{ @@ -257,7 +257,7 @@ where }); } else { for hash in store.keys() { - if transfer_hashes.remove(hash) { + if transfer_hashes.swap_remove(hash) { status.pending.insert(hash.clone()); } if transfer_hashes.is_empty() { @@ -296,7 +296,7 @@ where .as_str() .try_into() .expect("We must have a valid KeccakHash"); - if !transfer_hashes.remove(&tx_hash) { + if !transfer_hashes.swap_remove(&tx_hash) { return None; } Some((tx_hash, is_relayed, transfer_hashes.is_empty())) diff --git a/crates/sdk/src/queries/vp/pos.rs b/crates/sdk/src/queries/vp/pos.rs index 19235566aa..f5942ea152 100644 --- a/crates/sdk/src/queries/vp/pos.rs +++ b/crates/sdk/src/queries/vp/pos.rs @@ -1,9 +1,10 @@ //! Queries router and handlers for PoS validity predicate -use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet}; +use std::collections::{BTreeMap, BTreeSet}; use borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; use namada_core::address::Address; +use namada_core::collections::{HashMap, HashSet}; use namada_core::key::common; use namada_core::storage::Epoch; use namada_core::token; diff --git a/crates/sdk/src/rpc.rs b/crates/sdk/src/rpc.rs index 9b7de172fb..076903a82f 100644 --- a/crates/sdk/src/rpc.rs +++ b/crates/sdk/src/rpc.rs @@ -1,7 +1,7 @@ //! SDK RPC queries use std::cell::Cell; -use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet}; +use std::collections::{BTreeMap, BTreeSet}; use std::ops::ControlFlow; use std::str::FromStr; @@ -11,6 +11,7 @@ use masp_primitives::merkle_tree::MerklePath; use masp_primitives::sapling::Node; use namada_account::Account; use namada_core::address::{Address, InternalAddress}; +use namada_core::collections::{HashMap, HashSet}; use namada_core::hash::Hash; use namada_core::key::common; use namada_core::storage::{ @@ -720,7 +721,7 @@ pub async fn query_tx_response( ) })?; // Reformat the event attributes so as to ease value extraction - let event_map: std::collections::HashMap<&str, &str> = query_event + let event_map: namada_core::collections::HashMap<&str, &str> = query_event .attributes .iter() .map(|tag| (tag.key.as_ref(), tag.value.as_ref())) diff --git a/crates/sdk/src/signing.rs b/crates/sdk/src/signing.rs index 82c0c7f4ae..11b5e37557 100644 --- a/crates/sdk/src/signing.rs +++ b/crates/sdk/src/signing.rs @@ -1,5 +1,5 @@ //! Functions to sign transactions -use std::collections::{BTreeMap, HashMap, HashSet}; +use std::collections::BTreeMap; use std::fmt::Display; use borsh::BorshDeserialize; @@ -13,6 +13,7 @@ use masp_primitives::transaction::components::sapling::fees::{ use masp_primitives::transaction::Transaction; use namada_account::{AccountPublicKeysMap, InitAccount, UpdateAccount}; use namada_core::address::{Address, ImplicitAddress, InternalAddress, MASP}; +use namada_core::collections::{HashMap, HashSet}; use namada_core::key::*; use namada_core::masp::{AssetData, ExtendedViewingKey, PaymentAddress}; use namada_core::sign::SignatureIndex; diff --git a/crates/sdk/src/tx.rs b/crates/sdk/src/tx.rs index 1c7e19cbd9..c039eecf65 100644 --- a/crates/sdk/src/tx.rs +++ b/crates/sdk/src/tx.rs @@ -1,7 +1,7 @@ //! SDK functions to construct different types of transactions use std::borrow::Cow; -use std::collections::{BTreeMap, HashSet}; +use std::collections::BTreeMap; use std::fs::File; use std::path::{Path, PathBuf}; use std::time::Duration; @@ -20,6 +20,7 @@ use masp_primitives::transaction::components::transparent::fees::{ use masp_primitives::transaction::components::I128Sum; use namada_account::{InitAccount, UpdateAccount}; use namada_core::address::{Address, InternalAddress, MASP}; +use namada_core::collections::HashSet; use namada_core::dec::Dec; use namada_core::hash::Hash; use namada_core::ibc::apps::transfer::types::msgs::transfer::MsgTransfer; diff --git a/crates/sdk/src/wallet/mod.rs b/crates/sdk/src/wallet/mod.rs index 4d90279c42..aca6517729 100644 --- a/crates/sdk/src/wallet/mod.rs +++ b/crates/sdk/src/wallet/mod.rs @@ -5,7 +5,7 @@ mod keys; pub mod pre_genesis; pub mod store; -use std::collections::{BTreeMap, HashMap, HashSet}; +use std::collections::BTreeMap; use std::fmt::Display; use std::str::FromStr; @@ -13,6 +13,7 @@ use alias::Alias; use bip39::{Language, Mnemonic, MnemonicType, Seed}; use borsh::{BorshDeserialize, BorshSerialize}; use namada_core::address::Address; +use namada_core::collections::{HashMap, HashSet}; use namada_core::key::*; use namada_core::masp::{ ExtendedSpendingKey, ExtendedViewingKey, PaymentAddress, @@ -769,7 +770,7 @@ impl Wallet { // Try cache first if let Some(cached_key) = self .decrypted_key_cache - .get(&alias_pkh_or_pk.as_ref().into()) + .get(&Alias::from(alias_pkh_or_pk.as_ref())) { return Ok(cached_key.clone()); } @@ -810,8 +811,9 @@ impl Wallet { password: Option>, ) -> Result { // Try cache first - if let Some(cached_key) = - self.decrypted_spendkey_cache.get(&alias.as_ref().into()) + if let Some(cached_key) = self + .decrypted_spendkey_cache + .get(&Alias::from(alias.as_ref())) { return Ok(*cached_key); } diff --git a/crates/sdk/src/wallet/store.rs b/crates/sdk/src/wallet/store.rs index 068b81a9fd..82b32a887d 100644 --- a/crates/sdk/src/wallet/store.rs +++ b/crates/sdk/src/wallet/store.rs @@ -1,6 +1,6 @@ //! Wallet Store information -use std::collections::{BTreeMap, HashSet}; +use std::collections::BTreeMap; use std::fmt::Display; use std::str::FromStr; @@ -8,6 +8,7 @@ use bimap::BiBTreeMap; use itertools::Itertools; use masp_primitives::zip32; use namada_core::address::{Address, ImplicitAddress}; +use namada_core::collections::HashSet; use namada_core::key::*; use namada_core::masp::{ ExtendedSpendingKey, ExtendedViewingKey, PaymentAddress, diff --git a/crates/shielded_token/src/conversion.rs b/crates/shielded_token/src/conversion.rs index f9f5826271..773486ab99 100644 --- a/crates/shielded_token/src/conversion.rs +++ b/crates/shielded_token/src/conversion.rs @@ -523,10 +523,10 @@ where #[cfg(test)] mod tests { - use std::collections::HashMap; use std::str::FromStr; use namada_core::address; + use namada_core::collections::HashMap; use namada_core::dec::testing::arb_non_negative_dec; use namada_core::time::DurationSecs; use namada_core::token::testing::arb_amount; diff --git a/crates/state/src/write_log.rs b/crates/state/src/write_log.rs index 6ce1f31d54..1e3e10a899 100644 --- a/crates/state/src/write_log.rs +++ b/crates/state/src/write_log.rs @@ -1,10 +1,11 @@ //! Write log is temporary storage for modifications performed by a transaction. //! before they are committed to the ledger's storage. -use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet}; +use std::collections::{BTreeMap, BTreeSet}; use itertools::Itertools; use namada_core::address::{Address, EstablishedAddressGen, InternalAddress}; +use namada_core::collections::{HashMap, HashSet}; use namada_core::hash::Hash; use namada_core::ibc::IbcEvent; use namada_core::storage; @@ -1049,6 +1050,7 @@ pub mod testing { arb_storage_modification(can_init_account), 0..100, ) + .prop_map(|map| map.into_iter().collect()) }) } diff --git a/crates/storage/src/collections/lazy_map.rs b/crates/storage/src/collections/lazy_map.rs index 7c7ea1c2b9..c1153910e0 100644 --- a/crates/storage/src/collections/lazy_map.rs +++ b/crates/storage/src/collections/lazy_map.rs @@ -18,14 +18,16 @@ pub const DATA_SUBKEY: &str = "data"; /// Lazy map. /// -/// This can be used as an alternative to `std::collections::HashMap` and -/// `BTreeMap`. In the lazy map, the elements do not reside in memory but are +/// This can be used as an alternative to [`HashMap`] and +/// [`BTreeMap`]. In the lazy map, the elements do not reside in memory but are /// instead read and written to storage sub-keys of the storage `key` used to /// construct the map. /// /// In the [`LazyMap`], the type of key `K` can be anything that implements /// [`storage::KeySeg`] and this trait is used to turn the keys into key /// segments. +/// +/// [`HashMap`]: `namada_core::collections::HashMap` #[derive(Debug)] pub struct LazyMap { key: storage::Key, diff --git a/crates/storage/src/collections/lazy_set.rs b/crates/storage/src/collections/lazy_set.rs index bee96d41a5..850fa1fcae 100644 --- a/crates/storage/src/collections/lazy_set.rs +++ b/crates/storage/src/collections/lazy_set.rs @@ -12,14 +12,17 @@ use crate::{ResultExt, StorageRead, StorageWrite}; /// A lazy set. /// -/// This can be used as an alternative to `std::collections::HashSet` and -/// `BTreeSet`. In the lazy set, the elements do not reside in memory but are +/// This can be used as an alternative to [`HashSet`] and +/// [`BTreeSet`]. In the lazy set, the elements do not reside in memory but are /// instead read and written to storage sub-keys of the storage `key` used to /// construct the set. /// /// In the [`LazySet`], the type of key `K` can be anything that implements /// [`storage::KeySeg`], and this trait is used to turn the keys into key /// segments. +/// +/// [`HashSet`]: `namada_core::collections::HashSet` +/// [`BTreeSet`]: `std::collections::BTreeSet` #[derive(Debug)] pub struct LazySet { key: storage::Key, diff --git a/crates/tests/src/e2e/ibc_tests.rs b/crates/tests/src/e2e/ibc_tests.rs index 46fe94802b..d0012f84d7 100644 --- a/crates/tests/src/e2e/ibc_tests.rs +++ b/crates/tests/src/e2e/ibc_tests.rs @@ -11,7 +11,7 @@ use core::str::FromStr; use core::time::Duration; -use std::collections::{BTreeSet, HashMap}; +use std::collections::BTreeSet; use std::path::{Path, PathBuf}; use color_eyre::eyre::Result; @@ -77,6 +77,7 @@ use namada_apps::config::{ethereum_bridge, TendermintMode}; use namada_apps::facade::tendermint::block::Header as TmHeader; use namada_apps::facade::tendermint::merkle::proof::ProofOps as TmProof; use namada_apps::facade::tendermint_rpc::{Client, HttpClient, Url}; +use namada_core::collections::HashMap; use namada_core::string_encoding::StringEncoded; use namada_sdk::masp::fs::FsShieldedUtils; use prost::Message; diff --git a/crates/tests/src/e2e/ledger_tests.rs b/crates/tests/src/e2e/ledger_tests.rs index 17c85d5fd7..0cac8a42db 100644 --- a/crates/tests/src/e2e/ledger_tests.rs +++ b/crates/tests/src/e2e/ledger_tests.rs @@ -10,7 +10,6 @@ //! `NAMADA_E2E_KEEP_TEMP=true`. #![allow(clippy::type_complexity)] -use std::collections::HashMap; use std::fmt::Display; use std::path::PathBuf; use std::process::Command; @@ -32,6 +31,7 @@ use namada_apps::config::ethereum_bridge; use namada_apps::config::utils::convert_tm_addr_to_socket_addr; use namada_apps::facade::tendermint_config::net::Address as TendermintAddress; use namada_core::chain::ChainId; +use namada_core::collections::HashMap; use namada_core::token::NATIVE_MAX_DECIMAL_PLACES; use namada_sdk::governance::pgf::cli::steward::Commission; use namada_sdk::masp::fs::FsShieldedUtils; diff --git a/crates/tests/src/e2e/setup.rs b/crates/tests/src/e2e/setup.rs index 4d996052d2..21a4cd6b90 100644 --- a/crates/tests/src/e2e/setup.rs +++ b/crates/tests/src/e2e/setup.rs @@ -1,4 +1,3 @@ -use std::collections::HashMap; use std::ffi::OsStr; use std::fmt::Display; use std::fs::{create_dir_all, File, OpenOptions}; @@ -28,6 +27,7 @@ use namada_apps::config::genesis::{templates, transactions, GenesisAddress}; use namada_apps::config::{ethereum_bridge, genesis, Config}; use namada_apps::{config, wallet}; use namada_core::address::Address; +use namada_core::collections::HashMap; use namada_core::key::{RefTo, SchemeType}; use namada_core::string_encoding::StringEncoded; use namada_core::token::NATIVE_MAX_DECIMAL_PLACES; diff --git a/crates/tests/src/integration/setup.rs b/crates/tests/src/integration/setup.rs index e8aa6b4ee7..f7604ad507 100644 --- a/crates/tests/src/integration/setup.rs +++ b/crates/tests/src/integration/setup.rs @@ -1,4 +1,3 @@ -use std::collections::HashMap; use std::mem::ManuallyDrop; use std::path::Path; use std::str::FromStr; @@ -24,6 +23,7 @@ use namada_apps::node::ledger::shell::testing::utils::TestDir; use namada_apps::node::ledger::shell::Shell; use namada_apps::wallet::pre_genesis; use namada_core::chain::ChainIdPrefix; +use namada_core::collections::HashMap; use namada_sdk::wallet::alias::Alias; use crate::e2e::setup::{copy_wasm_to_chain_dir, SINGLE_NODE_NET_GENESIS}; diff --git a/crates/tests/src/storage_api/collections/lazy_map.rs b/crates/tests/src/storage_api/collections/lazy_map.rs index 5533fccfc0..48d5f64511 100644 --- a/crates/tests/src/storage_api/collections/lazy_map.rs +++ b/crates/tests/src/storage_api/collections/lazy_map.rs @@ -58,7 +58,8 @@ mod tests { /// `Transition`s, which are also being accumulated into /// `current_transitions`. It then: /// - /// - checks its state against an in-memory `std::collections::HashMap` + /// - checks its state against an in-memory + /// `namada_core::collections::HashMap` /// - runs validation and checks that the `LazyMap::Action`s reported from /// validation match with transitions that were applied /// diff --git a/crates/tests/src/storage_api/collections/nested_lazy_map.rs b/crates/tests/src/storage_api/collections/nested_lazy_map.rs index 2df9ae95bf..7658a66223 100644 --- a/crates/tests/src/storage_api/collections/nested_lazy_map.rs +++ b/crates/tests/src/storage_api/collections/nested_lazy_map.rs @@ -68,7 +68,8 @@ mod tests { /// `Transition`s, which are also being accumulated into /// `current_transitions`. It then: /// - /// - checks its state against an in-memory `std::collections::HashMap` + /// - checks its state against an in-memory + /// `namada_core::collections::HashMap` /// - runs validation and checks that the `LazyMap::Action`s reported from /// validation match with transitions that were applied /// diff --git a/crates/tests/src/vm_host_env/ibc.rs b/crates/tests/src/vm_host_env/ibc.rs index bf5ed4dabe..aa5eaddde1 100644 --- a/crates/tests/src/vm_host_env/ibc.rs +++ b/crates/tests/src/vm_host_env/ibc.rs @@ -1,6 +1,5 @@ use core::time::Duration; use std::cell::RefCell; -use std::collections::HashMap; use ibc_testkit::testapp::ibc::clients::mock::client_state::{ client_type, MockClientState, @@ -82,6 +81,7 @@ use namada::tendermint::time::Time as TmTime; use namada::token::{self, Amount, DenominatedAmount}; use namada::tx::Tx; use namada::vm::{wasm, WasmCacheRwAccess}; +use namada_core::collections::HashMap; use namada_core::validity_predicate::VpSentinel; use namada_sdk::state::StateRead; use namada_test_utils::TestWasms; diff --git a/crates/tx/src/data/pgf.rs b/crates/tx/src/data/pgf.rs index 5343ae4daa..da188eab0d 100644 --- a/crates/tx/src/data/pgf.rs +++ b/crates/tx/src/data/pgf.rs @@ -1,7 +1,6 @@ -use std::collections::HashMap; - use namada_core::address::Address; use namada_core::borsh::{BorshDeserialize, BorshSerialize}; +use namada_core::collections::HashMap; use namada_core::dec::Dec; use serde::{Deserialize, Serialize}; use thiserror::Error; @@ -47,7 +46,7 @@ pub mod tests { ) -> UpdateStewardCommission { UpdateStewardCommission { steward, - commission, + commission: commission.into_iter().collect(), } } } diff --git a/crates/tx/src/lib.rs b/crates/tx/src/lib.rs index 6c866e8513..cd2998a6c5 100644 --- a/crates/tx/src/lib.rs +++ b/crates/tx/src/lib.rs @@ -4,9 +4,8 @@ pub mod data; pub mod proto; mod types; -use std::collections::HashMap; - use data::TxType; +use namada_core::collections::HashMap; use namada_core::event::{Event, EventLevel, EventType}; pub use namada_core::key::SignableEthMessage; pub use namada_core::sign::SignatureIndex; diff --git a/crates/tx/src/types.rs b/crates/tx/src/types.rs index 9533209425..89f4d30ab5 100644 --- a/crates/tx/src/types.rs +++ b/crates/tx/src/types.rs @@ -1,6 +1,6 @@ use std::borrow::Cow; use std::cmp::Ordering; -use std::collections::{BTreeMap, HashMap, HashSet}; +use std::collections::BTreeMap; use std::hash::{Hash, Hasher}; use std::marker::PhantomData; @@ -16,6 +16,7 @@ use namada_core::borsh::{ BorshDeserialize, BorshSchema, BorshSerialize, BorshSerializeExt, }; use namada_core::chain::ChainId; +use namada_core::collections::{HashMap, HashSet}; use namada_core::key::*; use namada_core::masp::AssetData; use namada_core::sign::SignatureIndex; diff --git a/crates/vote_ext/src/bridge_pool_roots.rs b/crates/vote_ext/src/bridge_pool_roots.rs index 41b1f85b54..eec1da22a1 100644 --- a/crates/vote_ext/src/bridge_pool_roots.rs +++ b/crates/vote_ext/src/bridge_pool_roots.rs @@ -2,11 +2,11 @@ //! of the bridge pool merkle root to be added //! to storage. This will be used to generate //! bridge pool inclusion proofs for Ethereum. -use std::collections::HashSet; use std::ops::{Deref, DerefMut}; use namada_core::address::Address; use namada_core::borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; +use namada_core::collections::HashSet; use namada_core::key::common; use namada_core::key::common::Signature; use namada_core::storage::BlockHeight; @@ -117,7 +117,7 @@ impl DerefMut for MultiSignedVext { } impl IntoIterator for MultiSignedVext { - type IntoIter = std::collections::hash_set::IntoIter; + type IntoIter = namada_core::collections::hash_set::IntoIter; type Item = SignedVext; fn into_iter(self) -> Self::IntoIter { diff --git a/crates/vote_ext/src/ethereum_events.rs b/crates/vote_ext/src/ethereum_events.rs index 05fa0c3b3a..1673f1f2a7 100644 --- a/crates/vote_ext/src/ethereum_events.rs +++ b/crates/vote_ext/src/ethereum_events.rs @@ -1,11 +1,12 @@ //! Contains types necessary for processing Ethereum events //! in vote extensions. -use std::collections::{BTreeSet, HashMap}; +use std::collections::BTreeSet; use std::ops::Deref; use namada_core::address::Address; use namada_core::borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; +use namada_core::collections::HashMap; use namada_core::ethereum_events::EthereumEvent; use namada_core::key::common::{self, Signature}; use namada_core::storage::BlockHeight; diff --git a/crates/vote_ext/src/validator_set_update.rs b/crates/vote_ext/src/validator_set_update.rs index 7c997f39a1..8ef5cc5502 100644 --- a/crates/vote_ext/src/validator_set_update.rs +++ b/crates/vote_ext/src/validator_set_update.rs @@ -1,11 +1,11 @@ //! Contains types necessary for processing validator set updates //! in vote extensions. use std::cmp::Ordering; -use std::collections::HashMap; use std::ops::Deref; use namada_core::address::Address; use namada_core::borsh::{BorshDeserialize, BorshSchema, BorshSerialize}; +use namada_core::collections::HashMap; use namada_core::eth_abi::{AbiEncode, Encode, Token}; use namada_core::ethereum_events::EthAddress; use namada_core::keccak::KeccakHash; diff --git a/crates/vp_env/src/collection_validation/lazy_map.rs b/crates/vp_env/src/collection_validation/lazy_map.rs index 80b83d4cd3..6ff0999786 100644 --- a/crates/vp_env/src/collection_validation/lazy_map.rs +++ b/crates/vp_env/src/collection_validation/lazy_map.rs @@ -2,9 +2,9 @@ use core::fmt::Debug; use core::hash::Hash; -use std::collections::HashMap; use namada_core::borsh::{BorshDeserialize, BorshSerialize}; +use namada_core::collections::HashMap; use namada_core::storage; use namada_storage::collections::lazy_map::{LazyMap, NestedSubKey, SubKey}; use namada_storage::collections::{Nested, Simple}; diff --git a/crates/vp_prelude/src/lib.rs b/crates/vp_prelude/src/lib.rs index 098d328e26..38607ddd78 100644 --- a/crates/vp_prelude/src/lib.rs +++ b/crates/vp_prelude/src/lib.rs @@ -13,7 +13,7 @@ pub mod ibc { // used in the VP input use core::slice; -pub use std::collections::{BTreeSet, HashSet}; +pub use std::collections::BTreeSet; use std::marker::PhantomData; pub use namada_core::address::Address; @@ -21,6 +21,7 @@ pub use namada_core::borsh::{ BorshDeserialize, BorshSerialize, BorshSerializeExt, }; use namada_core::chain::CHAIN_ID_LENGTH; +pub use namada_core::collections::HashSet; use namada_core::hash::{Hash, HASH_LENGTH}; use namada_core::internal::HostEnvResult; use namada_core::storage::{ From 458f3f63ff8fe3d7a62953dacae9f9cdc39251f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Zemanovi=C4=8D?= Date: Thu, 22 Feb 2024 13:59:38 +0000 Subject: [PATCH 4/5] add clippy config --- clippy.toml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 clippy.toml diff --git a/clippy.toml b/clippy.toml new file mode 100644 index 0000000000..e5bc0863d7 --- /dev/null +++ b/clippy.toml @@ -0,0 +1,4 @@ +disallowed-types = [ + { path = "std::collections::HashMap", reason = "Non-deterministic iter - use indexmap::IndexMap instead" }, + { path = "std::collections::HashSet", reason = "Non-deterministic iter - use indexmap::IndexSet instead" }, +] From df1038de72b70946cf933a883f2841430e843a84 Mon Sep 17 00:00:00 2001 From: Tiago Carvalho Date: Thu, 22 Feb 2024 10:51:43 +0000 Subject: [PATCH 5/5] Changelog for #2685 --- .../unreleased/bug-fixes/2685-replace-hash-data-structs.md | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/unreleased/bug-fixes/2685-replace-hash-data-structs.md diff --git a/.changelog/unreleased/bug-fixes/2685-replace-hash-data-structs.md b/.changelog/unreleased/bug-fixes/2685-replace-hash-data-structs.md new file mode 100644 index 0000000000..e62f215e3b --- /dev/null +++ b/.changelog/unreleased/bug-fixes/2685-replace-hash-data-structs.md @@ -0,0 +1,3 @@ +- Use `indexmap` maps and sets in favor of `std` collections, to avoid + iteration order related bugs in the state machine code of Namada. + ([\#2685](https://github.com/anoma/namada/pull/2685)) \ No newline at end of file