Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix] #1897: Removed usize/isize from serialization #1989

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions actor/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Iroha simple actor framework.
#![allow(clippy::same_name_method)]
#![allow(clippy::expect_used)]

#[cfg(feature = "deadlock_detection")]
use std::any::type_name;
Expand Down Expand Up @@ -288,7 +289,7 @@ where
#[async_trait::async_trait]
pub trait Actor: Send + Sized + 'static {
/// Capacity of actor queue
fn mailbox_capacity(&self) -> usize {
fn mailbox_capacity(&self) -> u32 {
100
}

Expand All @@ -305,7 +306,12 @@ pub trait Actor: Send + Sized + 'static {
/// Initialize actor with its address.
fn preinit(self) -> InitializedActor<Self> {
let mailbox_capacity = self.mailbox_capacity();
InitializedActor::new(self, mailbox_capacity)
InitializedActor::new(
self,
mailbox_capacity
.try_into()
.expect("u32 should always fit in usize"),
)
}

/// Initialize actor with default values
Expand Down
4 changes: 2 additions & 2 deletions cli/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ pub struct Configuration {
#[config(env_prefix = "IROHA_NETWORK_")]
pub struct NetworkConfiguration {
/// Actor mailbox size
pub mailbox: usize,
pub mailbox: u32,
}

const DEFAULT_MAILBOX_SIZE: usize = 100;
const DEFAULT_MAILBOX_SIZE: u32 = 100;

impl Default for NetworkConfiguration {
fn default() -> Self {
Expand Down
8 changes: 4 additions & 4 deletions cli/src/torii/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ pub const DEFAULT_TORII_P2P_ADDR: &str = "127.0.0.1:1337";
/// Default socket for reporting internal status and metrics
pub const DEFAULT_TORII_TELEMETRY_URL: &str = "127.0.0.1:8180";
/// Default maximum size of single transaction
pub const DEFAULT_TORII_MAX_TRANSACTION_SIZE: usize = 2_usize.pow(15);
pub const DEFAULT_TORII_MAX_TRANSACTION_SIZE: u32 = 2_u32.pow(15);
/// Default upper bound on `content-length` specified in the HTTP request header
pub const DEFAULT_TORII_MAX_CONTENT_LENGTH: usize = 2_usize.pow(12) * 4000;
pub const DEFAULT_TORII_MAX_CONTENT_LENGTH: u32 = 2_u32.pow(12) * 4000;

/// Structure that defines the configuration parameters of `Torii` which is the routing module.
/// For example the `p2p_addr`, which is used for consensus and block-synchronisation purposes,
Expand All @@ -27,9 +27,9 @@ pub struct ToriiConfiguration {
/// Torii URL for reporting internal status and metrics for administration.
pub telemetry_url: String,
/// Maximum number of bytes in raw transaction. Used to prevent from DOS attacks.
pub max_transaction_size: usize,
pub max_transaction_size: u32,
/// Maximum number of bytes in raw message. Used to prevent from DOS attacks.
pub max_content_len: usize,
pub max_content_len: u32,
}

impl Default for ToriiConfiguration {
Expand Down
2 changes: 1 addition & 1 deletion cli/src/torii/routing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ impl<W: WorldTrait> Torii<W> {
warp::path(uri::TRANSACTION)
.and(add_state!(self.iroha_cfg, self.queue))
.and(warp::body::content_length_limit(
self.iroha_cfg.torii.max_content_len as u64,
self.iroha_cfg.torii.max_content_len.into(),
))
.and(body::versioned()),
)
Expand Down
8 changes: 4 additions & 4 deletions core/src/block_sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub struct BlockSynchronizer<S: SumeragiTrait, W: WorldTrait> {
gossip_period: Duration,
batch_size: u32,
broker: Broker,
mailbox: usize,
mailbox: u32,
}

/// Block synchronizer
Expand Down Expand Up @@ -99,7 +99,7 @@ pub struct ReceiveUpdates;

#[async_trait::async_trait]
impl<S: SumeragiTrait, W: WorldTrait> Actor for BlockSynchronizer<S, W> {
fn mailbox_capacity(&self) -> usize {
fn mailbox_capacity(&self) -> u32 {
self.mailbox
}

Expand Down Expand Up @@ -350,7 +350,7 @@ pub mod config {

const DEFAULT_BATCH_SIZE: u32 = 4;
const DEFAULT_GOSSIP_PERIOD_MS: u64 = 10000;
const DEFAULT_MAILBOX_SIZE: usize = 100;
const DEFAULT_MAILBOX_SIZE: u32 = 100;

/// Configuration for `BlockSynchronizer`.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize, Configurable)]
Expand All @@ -364,7 +364,7 @@ pub mod config {
/// Underlying network (`iroha_network`) should support transferring messages this large.
pub batch_size: u32,
/// Mailbox size
pub mailbox: usize,
pub mailbox: u32,
}

impl Default for BlockSyncConfiguration {
Expand Down
16 changes: 8 additions & 8 deletions core/src/kura.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub struct KuraWithIO<W: WorldTrait, IO> {
merkle_tree: MerkleTree<VersionedCommittedBlock>,
wsv: Arc<WorldStateView<W>>,
broker: Broker,
mailbox: usize,
mailbox: u32,
}

/// Production qualification of `KuraWithIO`
Expand All @@ -70,7 +70,7 @@ impl<W: WorldTrait, IO: DiskIO> KuraWithIO<W, IO> {
blocks_per_file: NonZeroU64,
wsv: Arc<WorldStateView<W>>,
broker: Broker,
mailbox: usize,
mailbox: u32,
io: IO,
) -> Result<Self> {
Ok(Self {
Expand Down Expand Up @@ -105,7 +105,7 @@ pub trait KuraTrait:
blocks_per_file: NonZeroU64,
wsv: Arc<WorldStateView<Self::World>>,
broker: Broker,
mailbox: usize,
mailbox: u32,
) -> Result<Self>;

/// Loads kura from configuration
Expand Down Expand Up @@ -138,7 +138,7 @@ impl<W: WorldTrait> KuraTrait for Kura<W> {
blocks_per_file: NonZeroU64,
wsv: Arc<WorldStateView<W>>,
broker: Broker,
mailbox: usize,
mailbox: u32,
) -> Result<Self> {
Self::new_meta(
mode,
Expand All @@ -155,7 +155,7 @@ impl<W: WorldTrait> KuraTrait for Kura<W> {

#[async_trait::async_trait]
impl<W: WorldTrait, IO: DiskIO> Actor for KuraWithIO<W, IO> {
fn mailbox_capacity(&self) -> usize {
fn mailbox_capacity(&self) -> u32 {
self.mailbox
}

Expand Down Expand Up @@ -486,7 +486,7 @@ pub mod config {

const DEFAULT_BLOCKS_PER_STORAGE_FILE: u64 = 1000_u64;
const DEFAULT_BLOCK_STORE_PATH: &str = "./blocks";
const DEFAULT_MAILBOX_SIZE: usize = 100;
const DEFAULT_MAILBOX_SIZE: u32 = 100;

/// Configuration of kura
#[derive(Clone, Deserialize, Serialize, Debug, Configurable, PartialEq, Eq)]
Expand All @@ -504,7 +504,7 @@ pub mod config {
pub blocks_per_storage_file: NonZeroU64,
/// Default mailbox size
#[serde(default = "default_mailbox_size")]
pub mailbox: usize,
pub mailbox: u32,
}

impl Default for KuraConfiguration {
Expand Down Expand Up @@ -543,7 +543,7 @@ pub mod config {
)
}

const fn default_mailbox_size() -> usize {
const fn default_mailbox_size() -> u32 {
DEFAULT_MAILBOX_SIZE
}
}
Expand Down
8 changes: 6 additions & 2 deletions core/src/queue.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! Module with queue actor
#![allow(clippy::expect_used)]

use std::{sync::Arc, time::Duration};

Expand Down Expand Up @@ -80,12 +81,15 @@ impl<W: WorldTrait> Queue<W> {
}

/// Returns `n` randomly selected transaction from the queue.
pub fn n_random_transactions(&self, n: usize) -> Vec<VersionedAcceptedTransaction> {
pub fn n_random_transactions(&self, n: u32) -> Vec<VersionedAcceptedTransaction> {
self.txs
.iter()
.filter(|e| self.is_pending(e.value()))
.map(|e| e.value().clone())
.choose_multiple(&mut rand::thread_rng(), n)
.choose_multiple(
&mut rand::thread_rng(),
n.try_into().expect("u32 should always fit in usize"),
)
}

fn check_tx(&self, tx: &VersionedAcceptedTransaction) -> Result<(), Error> {
Expand Down
9 changes: 6 additions & 3 deletions core/src/smartcontracts/wasm.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! This module contains logic related to executing smartcontracts via
//! `WebAssembly` VM Smartcontracts can be written in Rust, compiled
//! to wasm format and submitted in a transaction
#![allow(clippy::expect_used)]

use std::sync::Arc;

Expand Down Expand Up @@ -140,7 +141,9 @@ impl<'a, W: WorldTrait> State<'a, W> {
validator: None,

store_limits: StoreLimitsBuilder::new()
.memory_size(config.max_memory)
.memory_size(config.max_memory.try_into().expect(
"config.max_memory is a u32 so this can't fail on any supported platform",
))
.instances(1)
.memories(1)
.tables(1)
Expand Down Expand Up @@ -491,7 +494,7 @@ pub mod config {
use serde::{Deserialize, Serialize};

const DEFAULT_FUEL_LIMIT: u64 = 1_000_000;
const DEFAULT_MAX_MEMORY: usize = 500 * 2_usize.pow(20); // 500 MiB
const DEFAULT_MAX_MEMORY: u32 = 500 * 2_u32.pow(20); // 500 MiB

/// [`WebAssembly Runtime`](super::Runtime) configuration.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize, Configurable)]
Expand All @@ -503,7 +506,7 @@ pub mod config {
pub fuel_limit: u64,

/// Maximum amount of linear memory a given smartcontract can allocate
pub max_memory: usize,
pub max_memory: u32,
}

impl Default for Configuration {
Expand Down
8 changes: 4 additions & 4 deletions core/src/sumeragi/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ pub const DEFAULT_COMMIT_TIME_MS: u64 = 2000;
/// Default amount of time Peer waits for `TxReceipt` from the leader.
pub const DEFAULT_TX_RECEIPT_TIME_MS: u64 = 500;
const DEFAULT_N_TOPOLOGY_SHIFTS_BEFORE_RESHUFFLE: u64 = 1;
const DEFAULT_MAILBOX_SIZE: usize = 100;
const DEFAULT_MAILBOX_SIZE: u32 = 100;
const DEFAULT_GOSSIP_PERIOD_MS: u64 = 1000;
const DEFAULT_GOSSIP_BATCH_SIZE: usize = 500;
const DEFAULT_GOSSIP_BATCH_SIZE: u32 = 500;

/// `SumeragiConfiguration` provides an ability to define parameters such as `BLOCK_TIME_MS`
/// and list of `TRUSTED_PEERS`.
Expand All @@ -44,9 +44,9 @@ pub struct SumeragiConfiguration {
/// Limits to which transactions must adhere
pub transaction_limits: TransactionLimits,
/// Mailbox size
pub mailbox: usize,
pub mailbox: u32,
/// Maximum number of transactions in tx gossip batch message. While configuring this, attention should be payed to `p2p` max message size.
pub gossip_batch_size: usize,
pub gossip_batch_size: u32,
/// Period in milliseconds for pending transaction gossiping between peers.
pub gossip_period_ms: u64,
}
Expand Down
6 changes: 3 additions & 3 deletions core/src/sumeragi/fault.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ where
/// [`iroha_p2p::Network`] actor address
pub network: Addr<IrohaNetwork>,
/// Mailbox size
pub mailbox: usize,
pub mailbox: u32,
pub(crate) fault_injection: PhantomData<F>,
pub(crate) gossip_batch_size: usize,
pub(crate) gossip_batch_size: u32,
pub(crate) gossip_period: Duration,
}

Expand Down Expand Up @@ -161,7 +161,7 @@ impl<G: GenesisNetworkTrait, K: KuraTrait<World = W>, W: WorldTrait, F: FaultInj
impl<G: GenesisNetworkTrait, K: KuraTrait, W: WorldTrait, F: FaultInjection> Actor
for SumeragiWithFault<G, K, W, F>
{
fn mailbox_capacity(&self) -> usize {
fn mailbox_capacity(&self) -> u32 {
self.mailbox
}

Expand Down
2 changes: 1 addition & 1 deletion data_model/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Iroha Data Model contains structures for Domains, Peers, Accounts and Assets with simple,
//! non-specific functions like serialization.

#![allow(clippy::module_name_repetitions)]
#![allow(clippy::module_name_repetitions, clippy::unwrap_in_result)]
#![cfg_attr(not(feature = "std"), no_std)]

#[cfg(not(feature = "std"))]
Expand Down
31 changes: 24 additions & 7 deletions data_model/src/pagination.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//! Structures and traits related to pagination.
#![allow(clippy::expect_used)]

#[cfg(not(feature = "std"))]
use alloc::{
Expand Down Expand Up @@ -60,7 +61,8 @@ impl<I: Iterator> Iterator for Paginated<I> {
#[allow(clippy::option_if_let_else)]
// Required because of E0524. 2 closures with unique refs to self
if let Some(start) = self.pagination.start.take() {
self.iter.nth(start)
self.iter
.nth(start.try_into().expect("u32 should always fit in usize"))
} else {
self.iter.next()
}
Expand All @@ -71,14 +73,14 @@ impl<I: Iterator> Iterator for Paginated<I> {
#[derive(Clone, Eq, PartialEq, Debug, Default, Copy, Deserialize, Serialize)]
pub struct Pagination {
/// start of indexing
pub start: Option<usize>,
pub start: Option<u32>,
/// limit of indexing
pub limit: Option<usize>,
pub limit: Option<u32>,
}

impl Pagination {
/// Constructs [`Pagination`].
pub const fn new(start: Option<usize>, limit: Option<usize>) -> Self {
pub const fn new(start: Option<u32>, limit: Option<u32>) -> Self {
Self { start, limit }
}
}
Expand Down Expand Up @@ -129,10 +131,25 @@ impl From<Pagination> for Vec<(&'static str, usize)> {
fn from(pagination: Pagination) -> Self {
match (pagination.start, pagination.limit) {
(Some(start), Some(limit)) => {
vec![(PAGINATION_START, start), (PAGINATION_LIMIT, limit)]
vec![
(
PAGINATION_START,
start.try_into().expect("u32 should always fit in usize"),
),
(
PAGINATION_LIMIT,
limit.try_into().expect("u32 should always fit in usize"),
),
]
}
(Some(start), None) => vec![(PAGINATION_START, start)],
(None, Some(limit)) => vec![(PAGINATION_LIMIT, limit)],
(Some(start), None) => vec![(
PAGINATION_START,
start.try_into().expect("u32 should always fit in usize"),
)],
(None, Some(limit)) => vec![(
PAGINATION_LIMIT,
limit.try_into().expect("u32 should always fit in usize"),
)],
(None, None) => Vec::new(),
}
}
Expand Down
Loading