Skip to content

Commit

Permalink
fix: update metadata size calculation to use FixedSet.iter()
Browse files Browse the repository at this point in the history
This is solving the following TODO: implement iter for FixedSet to avoid the clone

Iter() was implemented for FixedSet in the newest version of `tari_utilities` so this PR updates the main repo to point to the `main` branch of `tari_utilities` and then uses this iter() implementation to do what the TODO suggests which is to to avoid the clone by using the iterator.
  • Loading branch information
philipr-za committed Mar 7, 2022
1 parent 5169a80 commit dbbe095
Show file tree
Hide file tree
Showing 25 changed files with 407 additions and 368 deletions.
706 changes: 372 additions & 334 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion applications/tari_app_grpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ tari_common_types = { version = "^0.28", path = "../../base_layer/common_types"}
tari_core = { path = "../../base_layer/core"}
tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", branch = "main" }
tari_comms = { path = "../../comms"}
tari_utilities = "0.3.0"
tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", branch = "main" }

chrono = { version = "0.4.19", default-features = false }
prost = "0.9"
Expand Down
2 changes: 1 addition & 1 deletion applications/tari_app_utilities/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", branch
tari_common = { path = "../../common" }
tari_common_types = { path = "../../base_layer/common_types" }
tari_p2p = { path = "../../base_layer/p2p", features = ["auto-update"] }
tari_utilities = "0.3.0"
tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", branch = "main" }

config = { version = "0.9.3" }
futures = { version = "^0.3.16", default-features = false, features = ["alloc"] }
Expand Down
2 changes: 1 addition & 1 deletion applications/tari_base_node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ tari_mmr = { path = "../../base_layer/mmr", features = ["native_bitmap"] }
tari_p2p = { path = "../../base_layer/p2p", features = ["auto-update"] }
tari_service_framework = { path = "../../base_layer/service_framework" }
tari_shutdown = { path = "../../infrastructure/shutdown" }
tari_utilities = "0.3.0"
tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", branch = "main" }

anyhow = "1.0.53"
bincode = "1.3.1"
Expand Down
2 changes: 1 addition & 1 deletion applications/tari_collectibles/src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ tari_common_types = { path = "../../../base_layer/common_types" }
tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", branch = "main" }
tari_key_manager = { path = "../../../base_layer/key_manager" }
tari_mmr = { path = "../../../base_layer/mmr"}
tari_utilities = "*"
tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", branch = "main" }
tari_dan_common_types = { path = "../../../dan_layer/common_types"}

blake2 = "^0.9.0"
Expand Down
2 changes: 1 addition & 1 deletion applications/tari_console_wallet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ tari_p2p = { path = "../../base_layer/p2p", features = ["auto-update"] }
tari_app_grpc = { path = "../tari_app_grpc" }
tari_shutdown = { path = "../../infrastructure/shutdown" }
tari_key_manager = { path = "../../base_layer/key_manager" }
tari_utilities = "0.3.0"
tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", branch = "main" }

sha2 = "0.9.5"
digest = "0.9.0"
Expand Down
2 changes: 1 addition & 1 deletion applications/tari_merge_mining_proxy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ tari_comms = { path = "../../comms" }
tari_core = { path = "../../base_layer/core", default-features = false, features = ["transactions"] }
tari_app_utilities = { path = "../tari_app_utilities" }
tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", branch = "main" }
tari_utilities = "^0.3"
tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", branch = "main" }

anyhow = "1.0.53"
bincode = "1.3.1"
Expand Down
2 changes: 1 addition & 1 deletion applications/tari_mining_node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ tari_comms = { path = "../../comms" }
tari_app_utilities = { path = "../tari_app_utilities"}
tari_app_grpc = { path = "../tari_app_grpc" }
tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", branch = "main" }
tari_utilities = "0.3.0"
tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", branch = "main" }

crossbeam = "0.8"
futures = "0.3"
Expand Down
2 changes: 1 addition & 1 deletion applications/tari_stratum_transcoder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ tari_app_grpc = { path = "../tari_app_grpc" }
tari_common = { path = "../../common" }
tari_core = { path = "../../base_layer/core", default-features = false, features = ["transactions"] }
tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", branch = "main" }
tari_utilities = "^0.3"
tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", branch = "main" }

bincode = "1.3.1"
bytes = "0.5"
Expand Down
2 changes: 1 addition & 1 deletion applications/test_faucet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ avx2 = ["simd"]

[dependencies]
tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", branch = "main" }
tari_utilities = "^0.3"
tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", branch = "main" }
tari_common_types = { path = "../../base_layer/common_types" }

rand = "0.8"
Expand Down
2 changes: 1 addition & 1 deletion base_layer/common_types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2018"

[dependencies]
tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", branch = "main" }
tari_utilities = "^0.3"
tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", branch = "main" }

digest = "0.9.0"
lazy_static = "1.4.0"
Expand Down
2 changes: 1 addition & 1 deletion base_layer/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ tari_service_framework = { version = "^0.28", path = "../service_framework" }
tari_shutdown = { version = "^0.28", path = "../../infrastructure/shutdown" }
tari_storage = { version = "^0.28", path = "../../infrastructure/storage" }
tari_test_utils = { version = "^0.28", path = "../../infrastructure/test_utils" }
tari_utilities = "0.3.0"
tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", branch = "main" }

async-trait = "0.1.50"
bincode = "1.1.4"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,17 +290,16 @@ impl SenderTransactionInitializer {
.map(|o| self.fee.weighting().round_up_metadata_size(o.metadata_byte_size()))
.sum::<usize>();

// TODO: implement iter for FixedSet to avoid the clone #LOGGED
size += self
.recipient_scripts
.clone()
.into_vec()
.iter()
.map(|script| {
self.fee.weighting().round_up_metadata_size(
self.get_recipient_output_features().consensus_encode_exact_size() +
script.consensus_encode_exact_size(),
)
.filter_map(|script| {
script.map(|s| {
self.fee.weighting().round_up_metadata_size(
self.get_recipient_output_features().consensus_encode_exact_size() +
s.consensus_encode_exact_size(),
)
})
})
.sum::<usize>();

Expand Down
4 changes: 4 additions & 0 deletions base_layer/key_manager/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,8 @@ pub enum MnemonicError {
ByteArrayError(#[from] ByteArrayError),
#[error("Encoding a mnemonic sequence to bytes requires exactly 24 mnemonic words")]
EncodeInvalidLength,
#[error("Bits to integer conversion error")]
BitsToIntConversion,
#[error("Integer to bits conversion error")]
IntToBitsConversion,
}
6 changes: 3 additions & 3 deletions base_layer/key_manager/src/mnemonic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ pub fn from_bytes(bytes: Vec<u8>, language: &MnemonicLanguage) -> Result<Vec<Str
let start_index = i * group_bit_count;
let stop_index = start_index + group_bit_count;
let sub_v = &bits[start_index..stop_index].to_vec();
let word_index = bits_to_uint(sub_v);
match find_mnemonic_word_from_index(word_index as usize, language) {
let word_index = checked_bits_to_uint(sub_v).ok_or(MnemonicError::BitsToIntConversion)?;
match find_mnemonic_word_from_index(word_index, language) {
Ok(mnemonic_word) => mnemonic_sequence.push(mnemonic_word),
Err(err) => return Err(err),
}
Expand All @@ -215,7 +215,7 @@ pub fn to_bytes_with_language(mnemonic_seq: &[String], language: &MnemonicLangua
for curr_word in mnemonic_seq {
match find_mnemonic_index_from_word(curr_word, language) {
Ok(index) => {
let curr_bits = uint_to_bits(index, 11);
let curr_bits = checked_uint_to_bits(index, 11).ok_or(MnemonicError::IntToBitsConversion)?;
bits.extend(curr_bits.iter().cloned());
},
Err(err) => return Err(err),
Expand Down
2 changes: 1 addition & 1 deletion base_layer/mmr/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ native_bitmap = ["croaring"]
benches = ["criterion"]

[dependencies]
tari_utilities = "^0.3"
tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", branch = "main" }
thiserror = "1.0.26"
digest = "0.9.0"
log = "0.4"
Expand Down
2 changes: 1 addition & 1 deletion base_layer/p2p/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", branch
tari_service_framework = { version = "^0.28", path = "../service_framework" }
tari_shutdown = { version = "^0.28", path = "../../infrastructure/shutdown" }
tari_storage = { version = "^0.28", path = "../../infrastructure/storage" }
tari_utilities = "^0.3"
tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", branch = "main" }

anyhow = "1.0.53"
bytes = "0.5"
Expand Down
2 changes: 1 addition & 1 deletion base_layer/tari_stratum_ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ tari_comms = { version = "^0.28", path = "../../comms" }
tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", branch = "main" }
tari_common = { path = "../../common" }
tari_core = { path = "../../base_layer/core", default-features = false, features = ["transactions"]}
tari_utilities = "^0.3"
tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", branch = "main" }
libc = "0.2.65"
thiserror = "1.0.26"
hex = "0.4.2"
Expand Down
2 changes: 1 addition & 1 deletion base_layer/wallet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ tari_service_framework = { version = "^0.28", path = "../service_framework" }
tari_shutdown = { version = "^0.28", path = "../../infrastructure/shutdown" }
tari_storage = { version = "^0.28", path = "../../infrastructure/storage" }
tari_common_sqlite = { path = "../../common_sqlite" }
tari_utilities = "0.3.0"
tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", branch = "main" }

aes-gcm = "^0.8"
async-trait = "0.1.50"
Expand Down
2 changes: 1 addition & 1 deletion base_layer/wallet_ffi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ tari_key_manager = { version = "^0.28", path = "../key_manager" }
tari_p2p = { version = "^0.28", path = "../p2p" }
tari_wallet = { version = "^0.28", path = "../wallet", features = ["c_integration"]}
tari_shutdown = { version = "^0.28", path = "../../infrastructure/shutdown" }
tari_utilities = "^0.3"
tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", branch = "main" }

chrono = { version = "0.4.19", default-features = false, features = ["serde"] }
futures = { version = "^0.3.1", features =["compat", "std"]}
Expand Down
2 changes: 1 addition & 1 deletion comms/dht/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ edition = "2018"
tari_comms = { version = "^0.28", path = "../", features = ["rpc"] }
tari_comms_rpc_macros = { version = "^0.28", path = "../rpc_macros" }
tari_crypto = { git = "https://github.com/tari-project/tari-crypto.git", branch = "main" }
tari_utilities = { version = "^0.3" }
tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", branch = "main" }
tari_shutdown = { version = "^0.28", path = "../../infrastructure/shutdown" }
tari_storage = { version = "^0.28", path = "../../infrastructure/storage" }
tari_common_sqlite = { path = "../../common_sqlite" }
Expand Down
4 changes: 1 addition & 3 deletions comms/dht/src/store_forward/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use tari_comms::{
message::MessageError,
peer_manager::{NodeId, PeerManagerError},
};
use tari_utilities::{byte_array::ByteArrayError, ciphers::cipher::CipherError};
use tari_utilities::byte_array::ByteArrayError;
use thiserror::Error;

use crate::{actor::DhtActorError, envelope::DhtMessageError, outbound::DhtOutboundError, storage::StorageError};
Expand All @@ -54,8 +54,6 @@ pub enum StoreAndForwardError {
StoredMessageNotEncrypted,
#[error("Unable to decrypt received stored message")]
DecryptionFailed,
#[error("CipherError: {0}")]
CipherError(#[from] CipherError),
#[error("DhtActorError: {0}")]
DhtActorError(#[from] DhtActorError),
#[error("Received duplicate stored message")]
Expand Down
2 changes: 1 addition & 1 deletion dan_layer/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ tari_storage = { path = "../../infrastructure/storage" }
tari_core = {path = "../../base_layer/core"}
tari_dan_common_types = {path = "../common_types"}
tari_common_types = {path = "../../base_layer/common_types"}
tari_utilities = "0.3.0"
tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", branch = "main" }

anyhow = "1.0.53"
async-trait = "0.1.50"
Expand Down
2 changes: 1 addition & 1 deletion dan_layer/storage_sqlite/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2018"
tari_dan_core = {path="../core"}
tari_common = { path = "../../common"}
tari_common_types = {path = "../../base_layer/common_types"}
tari_utilities = "0.3.0"
tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", branch = "main" }


diesel = { version = "1.4.8", features = ["sqlite"] }
Expand Down
2 changes: 1 addition & 1 deletion infrastructure/storage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ serde_derive = "1.0.80"

[dev-dependencies]
rand = "0.8"
tari_utilities = "^0.3"
tari_utilities = { git = "https://github.com/tari-project/tari_utilities.git", branch = "main" }

0 comments on commit dbbe095

Please sign in to comment.