Skip to content

Commit

Permalink
fix unsafe precondition check (#2129)
Browse files Browse the repository at this point in the history
* bump rust to 1.79

* fix clippy

* fix clippy

* fix ensure wasm

* revert rust version
  • Loading branch information
tcoratger authored Jul 3, 2024
1 parent 8f5ee1d commit f134883
Show file tree
Hide file tree
Showing 14 changed files with 31 additions and 19 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: Swatinem/rust-cache@v2
- name: Install wasm32 target
run: rustup target add wasm32-unknown-unknown
- run: cargo build -r --target wasm32-unknown-unknown -p torii-client

ensure-windows:
Expand All @@ -74,7 +76,7 @@ jobs:
with:
repo-token: ${{ secrets.github_token }}
- run: cargo build --target x86_64-pc-windows-msvc --bins

# This job is used to ensure the built katana image doesn't depend on any
# libraries that don't exist in the base docker image we use for distribution
ensure-docker:
Expand Down
2 changes: 1 addition & 1 deletion crates/dojo-world/src/manifest/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ impl DeploymentManifest {
// #[async_trait]
// impl<P: Provider + Sync + Send + 'static> RemoteLoadable<P> for DeploymentManifest {}

async fn get_remote_models_and_contracts<P: Provider>(
async fn get_remote_models_and_contracts<P>(
world: FieldElement,
provider: P,
) -> Result<(Vec<Manifest<DojoModel>>, Vec<Manifest<DojoContract>>), AbstractManifestError>
Expand Down
2 changes: 2 additions & 0 deletions crates/katana/core/src/service/messaging/ethereum.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(dead_code)]

use std::collections::HashMap;
use std::str::FromStr;
use std::sync::Arc;
Expand Down
6 changes: 4 additions & 2 deletions crates/katana/executor/src/implementation/blockifier/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,10 @@ impl<'a> StarknetVMProcessor<'a> {

// TODO: should we enforce the gas price to not be 0,
// as there's a flag to disable gas uasge instead?
let eth_l1_gas_price = unsafe { NonZeroU128::new_unchecked(header.gas_prices.eth) };
let strk_l1_gas_price = unsafe { NonZeroU128::new_unchecked(header.gas_prices.strk) };
let eth_l1_gas_price =
NonZeroU128::new(header.gas_prices.eth).unwrap_or(NonZeroU128::new(1).unwrap());
let strk_l1_gas_price =
NonZeroU128::new(header.gas_prices.strk).unwrap_or(NonZeroU128::new(1).unwrap());

// TODO: which values is correct for those one?
let eth_l1_data_gas_price = eth_l1_gas_price;
Expand Down
6 changes: 4 additions & 2 deletions crates/katana/executor/src/implementation/blockifier/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,10 @@ pub fn block_context_from_envs(block_env: &BlockEnv, cfg_env: &CfgEnv) -> BlockC
strk_fee_token_address: to_blk_address(cfg_env.fee_token_addresses.strk),
};

let eth_l1_gas_price = unsafe { NonZeroU128::new_unchecked(block_env.l1_gas_prices.eth) };
let strk_l1_gas_price = unsafe { NonZeroU128::new_unchecked(block_env.l1_gas_prices.strk) };
let eth_l1_gas_price =
NonZeroU128::new(block_env.l1_gas_prices.eth).unwrap_or(NonZeroU128::new(1).unwrap());
let strk_l1_gas_price =
NonZeroU128::new(block_env.l1_gas_prices.strk).unwrap_or(NonZeroU128::new(1).unwrap());

let gas_prices = GasPrices {
eth_l1_gas_price,
Expand Down
6 changes: 3 additions & 3 deletions crates/katana/executor/tests/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,15 +305,15 @@ fn test_executor_with_valid_blocks_impl<EF: ExecutorFactory>(
let actual_storage_updates = states.state_updates.storage_updates;
assert_eq!(actual_storage_updates.len(), 3, "only 3 contracts whose storage should be updated");
assert!(
actual_storage_updates.get(&DEFAULT_FEE_TOKEN_ADDRESS).is_some(),
actual_storage_updates.contains_key(&DEFAULT_FEE_TOKEN_ADDRESS),
"fee token storage must get updated"
);
assert!(
actual_storage_updates.get(&(deployed_contract.into())).is_some(),
actual_storage_updates.contains_key(&(deployed_contract.into())),
"deployed contract storage must get updated"
);
assert!(
actual_storage_updates.get(&new_acc).is_some(),
actual_storage_updates.contains_key(&new_acc),
"newly deployed account storage must get updated"
);
}
Expand Down
4 changes: 2 additions & 2 deletions crates/katana/primitives/src/genesis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ mod tests {
);

assert!(
actual_state_updates.declared_sierra_classes.get(&fee_token.class_hash).is_none(),
!actual_state_updates.declared_sierra_classes.contains_key(&fee_token.class_hash),
"The default fee token class doesnt have a sierra class"
);

Expand All @@ -553,7 +553,7 @@ mod tests {
);

assert!(
actual_state_updates.declared_sierra_classes.get(&ud.class_hash).is_none(),
!actual_state_updates.declared_sierra_classes.contains_key(&ud.class_hash),
"The default universal deployer class doesnt have a sierra class"
);

Expand Down
4 changes: 2 additions & 2 deletions crates/katana/storage/provider/src/providers/fork/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ impl StateProvider for ForkedSnapshot {

impl ContractClassProvider for ForkedSnapshot {
fn sierra_class(&self, hash: ClassHash) -> ProviderResult<Option<FlattenedSierraClass>> {
if self.inner.compiled_class_hashes.get(&hash).is_some() {
if self.inner.compiled_class_hashes.contains_key(&hash) {
Ok(self.classes.sierra_classes.read().get(&hash).cloned())
} else {
ContractClassProvider::sierra_class(&self.inner.db, hash)
Expand All @@ -206,7 +206,7 @@ impl ContractClassProvider for ForkedSnapshot {
}

fn class(&self, hash: ClassHash) -> ProviderResult<Option<CompiledClass>> {
if self.inner.compiled_class_hashes.get(&hash).is_some() {
if self.inner.compiled_class_hashes.contains_key(&hash) {
Ok(self.classes.compiled_classes.read().get(&hash).cloned())
} else {
ContractClassProvider::class(&self.inner.db, hash)
Expand Down
2 changes: 1 addition & 1 deletion crates/sozo/ops/src/migration/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ pub async fn update_manifests_and_abis(
};

local_manifest.world.inner.address = Some(world_address);
local_manifest.world.inner.seed = salt.to_owned();
salt.clone_into(&mut local_manifest.world.inner.seed);

// when the migration has not been applied because in `plan` mode or because of an error,
// the `migration_output` is empty.
Expand Down
2 changes: 2 additions & 0 deletions crates/sozo/ops/src/migration/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,13 @@ where
Ok(())
}

#[allow(dead_code)]
enum ContractDeploymentOutput {
AlreadyDeployed(FieldElement),
Output(DeployOutput),
}

#[allow(dead_code)]
enum ContractUpgradeOutput {
Output(UpgradeOutput),
}
Expand Down
8 changes: 4 additions & 4 deletions crates/torii/core/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ pub fn map_row_to_ty(
let option = row.try_get::<String, &str>(&column_name)?;
enum_ty.set_option(&option)?;

let path = [path, &name].join("$");
let path = [path, name].join("$");
for option in &mut enum_ty.options {
map_row_to_ty(&path, &option.name, &mut option.ty, row, arrays_rows)?;
}
Expand All @@ -483,21 +483,21 @@ pub fn map_row_to_ty(
// struct can be the main entrypoint to our model schema
// so we dont format the table name if the path is empty
let path =
if path.is_empty() { struct_ty.name.clone() } else { [path, &name].join("$") };
if path.is_empty() { struct_ty.name.clone() } else { [path, name].join("$") };

for member in &mut struct_ty.children {
map_row_to_ty(&path, &member.name, &mut member.ty, row, arrays_rows)?;
}
}
Ty::Tuple(ty) => {
let path = [path, &name].join("$");
let path = [path, name].join("$");

for (i, member) in ty.iter_mut().enumerate() {
map_row_to_ty(&path, &format!("_{}", i), member, row, arrays_rows)?;
}
}
Ty::Array(ty) => {
let path = [path, &name].join("$");
let path = [path, name].join("$");
// filter by entity id in case we have multiple entities
let rows = arrays_rows
.get(&path)
Expand Down
1 change: 1 addition & 0 deletions crates/torii/graphql/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ pub struct Content {
pub socials: Vec<Social>,
}

#[allow(dead_code)]
#[derive(Deserialize, Debug)]
#[serde(rename_all = "camelCase")]
pub struct Metadata {
Expand Down
1 change: 1 addition & 0 deletions crates/torii/libp2p/src/client/events.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use gossipsub::Event as GossipsubEvent;
use libp2p::{gossipsub, identify, ping};

#[allow(dead_code)]
#[derive(Debug)]
pub(crate) enum ClientEvent {
Gossipsub(GossipsubEvent),
Expand Down
2 changes: 1 addition & 1 deletion crates/torii/libp2p/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ pub fn parse_value_to_ty(value: &PrimitiveType, ty: &mut Ty) -> Result<(), Error
}
},
Ty::ByteArray(s) => {
*s = string.clone();
s.clone_from(string);
}
_ => {
return Err(Error::InvalidMessageError(format!(
Expand Down

0 comments on commit f134883

Please sign in to comment.