Skip to content

Commit

Permalink
Revert "Use highwayhash in scrypto cache"
Browse files Browse the repository at this point in the history
This reverts commit 67faabf.
  • Loading branch information
lrubasze committed Jun 14, 2024
1 parent 67faabf commit a6d4613
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 33 deletions.
1 change: 0 additions & 1 deletion scrypto-compiler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ serde_json = { workspace = true }
wasm-opt = { workspace = true }
cargo_toml = { workspace = true }
fslock = { workspace = true }
highway = { version = "1.1.0" }

[dev-dependencies]
tempdir = "0.3.7"
Expand Down
37 changes: 5 additions & 32 deletions scrypto-compiler/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use cargo_toml::Manifest;
use fslock::{LockFile, ToOsStr};
use highway::{HighwayHash, HighwayHasher, Key};
use radix_common::prelude::*;
use radix_engine::utils::{extract_definition, ExtractSchemaError};
use radix_engine_interface::{blueprints::package::PackageDefinition, types::Level};
Expand All @@ -17,32 +16,6 @@ const BUILD_TARGET: &str = "wasm32-unknown-unknown";
const SCRYPTO_NO_SCHEMA: &str = "scrypto/no-schema";
const SCRYPTO_COVERAGE: &str = "scrypto/coverage";

#[derive(Debug)]
struct CacheHash([u8; 16]);

impl CacheHash {
fn hash(bytes: &[u8]) -> Self {
let key = Key([1, 2, 3, 4]);
let mut hasher128 = HighwayHasher::new(key);
hasher128.append(bytes);
let res128: [u64; 2] = hasher128.finalize128();

let mut bytes = [0u8; 16];

bytes[0..8].copy_from_slice(&res128[0].to_le_bytes());
bytes[8..16].copy_from_slice(&res128[1].to_le_bytes());

Self(bytes)
}
}

impl Display for CacheHash {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let hash_string: String = self.0.iter().map(|byte| format!("{:02x}", byte)).collect();
write!(f, "{}", hash_string)
}
}

#[derive(Debug)]
pub enum ScryptoCompilerError {
/// Returns IO Error which occurred during compilation and optional context information.
Expand Down Expand Up @@ -971,7 +944,7 @@ impl ScryptoCompiler {
Some(String::from("Read WASM file for RPD extract failed.")),
)
})?;
let code_hash = CacheHash::hash(&code);
let code_hash = hash(&code);

let package_definition =
extract_definition(&code).map_err(ScryptoCompilerError::SchemaExtractionError)?;
Expand Down Expand Up @@ -1031,14 +1004,14 @@ impl ScryptoCompiler {
fn get_scrypto_cache_paths(
&self,
manifest_def: &CompilerManifestDefinition,
code_hash: CacheHash,
code_hash: Hash,
create_if_not_exists: bool,
) -> Result<(PathBuf, PathBuf), ScryptoCompilerError> {
// WASM optimizations are optional and might be configured on different ways.
// They are applied in 2nd compilation, which means one can receive different WASMs
// for the same WASM files from 1st compilation.
let options = format!("{:?}{:?}", code_hash, self.input_params.wasm_optimization);
let hash_dir = CacheHash::hash(options.as_bytes());
let hash_dir = hash(options);

let cache_path = manifest_def
.target_directory
Expand Down Expand Up @@ -1071,7 +1044,7 @@ impl ScryptoCompiler {
fn store_artifacts_in_cache(
&self,
manifest_def: &CompilerManifestDefinition,
code_hash: CacheHash,
code_hash: Hash,
artifacts: &BuildArtifacts,
) -> Result<(), ScryptoCompilerError> {
let (rpd_cache_path, wasm_cache_path) =
Expand Down Expand Up @@ -1127,7 +1100,7 @@ impl ScryptoCompiler {
Some(String::from("Read WASM with schema file failed.")),
)
})?;
let code_hash = CacheHash::hash(&code);
let code_hash = hash(&code);

let (rpd_cache_path, wasm_cache_path) =
self.get_scrypto_cache_paths(manifest_def, code_hash, false)?;
Expand Down

0 comments on commit a6d4613

Please sign in to comment.