Correct the key and value encoding for the cache

This commit is contained in:
Omar Abdulla
2025-08-16 18:18:43 +03:00
parent c34f5a3d95
commit 91773dd281
7 changed files with 73 additions and 88 deletions
Generated
+30 -33
View File
@@ -1452,26 +1452,6 @@ dependencies = [
"parity-scale-codec", "parity-scale-codec",
] ]
[[package]]
name = "bincode"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "36eaf5d7b090263e8150820482d5d93cd964a81e4019913c972f4edcc6edb740"
dependencies = [
"bincode_derive",
"serde",
"unty",
]
[[package]]
name = "bincode_derive"
version = "2.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bf95709a440f45e986983918d0e8a1f30a9b1df04918fc828670606804ac3c09"
dependencies = [
"virtue",
]
[[package]] [[package]]
name = "bit-set" name = "bit-set"
version = "0.8.0" version = "0.8.0"
@@ -1627,6 +1607,29 @@ dependencies = [
"tinyvec", "tinyvec",
] ]
[[package]]
name = "bson"
version = "2.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7969a9ba84b0ff843813e7249eed1678d9b6607ce5a3b8f0a47af3fcf7978e6e"
dependencies = [
"ahash",
"base64 0.22.1",
"bitvec",
"getrandom 0.2.16",
"getrandom 0.3.3",
"hex",
"indexmap 2.10.0",
"js-sys",
"once_cell",
"rand 0.9.2",
"serde",
"serde_bytes",
"serde_json",
"time",
"uuid",
]
[[package]] [[package]]
name = "bumpalo" name = "bumpalo"
version = "3.17.0" version = "3.17.0"
@@ -2705,8 +2708,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592" checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"js-sys",
"libc", "libc",
"wasi 0.11.0+wasi-snapshot-preview1", "wasi 0.11.0+wasi-snapshot-preview1",
"wasm-bindgen",
] ]
[[package]] [[package]]
@@ -2716,9 +2721,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26145e563e54f2cadc477553f1ec5ee650b00862f0a58bcd12cbdc5f0ea2d2f4" checksum = "26145e563e54f2cadc477553f1ec5ee650b00862f0a58bcd12cbdc5f0ea2d2f4"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"js-sys",
"libc", "libc",
"r-efi", "r-efi",
"wasi 0.14.2+wasi-0.2.4", "wasi 0.14.2+wasi-0.2.4",
"wasm-bindgen",
] ]
[[package]] [[package]]
@@ -4505,7 +4512,7 @@ version = "0.1.0"
dependencies = [ dependencies = [
"alloy", "alloy",
"anyhow", "anyhow",
"bincode", "bson",
"cacache", "cacache",
"clap", "clap",
"futures", "futures",
@@ -5026,6 +5033,7 @@ version = "1.0.140"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373" checksum = "20068b6e96dc6c9bd23e01df8827e6c7e1f2fddd43c21810382803c136b99373"
dependencies = [ dependencies = [
"indexmap 2.10.0",
"itoa", "itoa",
"memchr", "memchr",
"ryu", "ryu",
@@ -6284,12 +6292,6 @@ version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1"
[[package]]
name = "unty"
version = "0.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d49784317cd0d1ee7ec5c716dd598ec5b4483ea832a2dced265471cc0f690ae"
[[package]] [[package]]
name = "url" name = "url"
version = "2.5.4" version = "2.5.4"
@@ -6321,6 +6323,7 @@ checksum = "f33196643e165781c20a5ead5582283a7dacbb87855d867fbc2df3f81eddc1be"
dependencies = [ dependencies = [
"getrandom 0.3.3", "getrandom 0.3.3",
"js-sys", "js-sys",
"serde",
"wasm-bindgen", "wasm-bindgen",
] ]
@@ -6348,12 +6351,6 @@ version = "0.9.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
[[package]]
name = "virtue"
version = "0.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "051eb1abcf10076295e815102942cc58f9d5e3b4560e46e53c21e8ff6f3af7b1"
[[package]] [[package]]
name = "w3f-bls" name = "w3f-bls"
version = "0.1.9" version = "0.1.9"
+1 -1
View File
@@ -25,7 +25,7 @@ revive-dt-solc-binaries = { version = "0.1.0", path = "crates/solc-binaries" }
alloy-primitives = "1.2.1" alloy-primitives = "1.2.1"
alloy-sol-types = "1.2.1" alloy-sol-types = "1.2.1"
anyhow = "1.0" anyhow = "1.0"
bincode = { version = "2.0.1", features = ["serde"] } bson = { version = "2.15.0" }
cacache = { version = "13.1.0" } cacache = { version = "13.1.0" }
clap = { version = "4", features = ["derive"] } clap = { version = "4", features = ["derive"] }
foundry-compilers-artifacts = { version = "0.18.0" } foundry-compilers-artifacts = { version = "0.18.0" }
+1 -1
View File
@@ -23,7 +23,7 @@ revive-dt-report = { workspace = true }
alloy = { workspace = true } alloy = { workspace = true }
anyhow = { workspace = true } anyhow = { workspace = true }
bincode = { workspace = true } bson = { workspace = true }
cacache = { workspace = true } cacache = { workspace = true }
clap = { workspace = true } clap = { workspace = true }
futures = { workspace = true } futures = { workspace = true }
+33 -28
View File
@@ -19,7 +19,7 @@ use once_cell::sync::Lazy;
use semver::Version; use semver::Version;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use tokio::sync::{Mutex, RwLock}; use tokio::sync::{Mutex, RwLock};
use tracing::{debug, debug_span, instrument}; use tracing::{Instrument, debug, debug_span, instrument};
use crate::Platform; use crate::Platform;
@@ -40,7 +40,8 @@ impl CachedCompiler {
skip_all, skip_all,
fields( fields(
metadata_file_path = %metadata_file_path.as_ref().display(), metadata_file_path = %metadata_file_path.as_ref().display(),
%mode %mode,
platform = P::config_id().to_string()
), ),
err err
)] )]
@@ -70,24 +71,26 @@ impl CachedCompiler {
metadata_file_path: metadata_file_path.as_ref().to_path_buf(), metadata_file_path: metadata_file_path.as_ref().to_path_buf(),
solc_mode: mode.clone(), solc_mode: mode.clone(),
}; };
debug_span!(
"Running compilation for the cache key",
cache_key.platform_key = %cache_key.platform_key,
cache_key.compiler_version = %cache_key.compiler_version,
cache_key.metadata_file_path = %cache_key.metadata_file_path.display(),
cache_key.solc_mode = %cache_key.solc_mode,
);
let compilation_callback = || async move { let compilation_callback = || {
compile_contracts::<P>( async move {
metadata.directory()?, compile_contracts::<P>(
compiler_path, metadata.directory()?,
metadata.files_to_compile()?, compiler_path,
mode, metadata.files_to_compile()?,
deployed_libraries, mode,
) deployed_libraries,
.map(|compilation_result| compilation_result.map(CacheValue::new)) )
.await .map(|compilation_result| compilation_result.map(CacheValue::new))
.await
}
.instrument(debug_span!(
"Running compilation for the cache key",
cache_key.platform_key = %cache_key.platform_key,
cache_key.compiler_version = %cache_key.compiler_version,
cache_key.metadata_file_path = %cache_key.metadata_file_path.display(),
cache_key.solc_mode = %cache_key.solc_mode,
))
}; };
let compiled_contracts = match deployed_libraries { let compiled_contracts = match deployed_libraries {
@@ -95,12 +98,13 @@ impl CachedCompiler {
// means that linking is required in this case. // means that linking is required in this case.
Some(_) => { Some(_) => {
debug!("Deployed libraries defined, recompilation must take place"); debug!("Deployed libraries defined, recompilation must take place");
debug!("Cache miss");
compilation_callback().await?.compiler_output compilation_callback().await?.compiler_output
} }
// If no deployed libraries are specified then we can follow the cached flow and attempt // If no deployed libraries are specified then we can follow the cached flow and attempt
// to lookup the compilation artifacts in the cache. // to lookup the compilation artifacts in the cache.
None => { None => {
debug!("Deployed contract undefined, attempting to make use of cache"); debug!("Deployed libraries undefined, attempting to make use of cache");
// Lock this specific cache key such that we do not get inconsistent state. We want // Lock this specific cache key such that we do not get inconsistent state. We want
// that when multiple cases come in asking for the compilation artifacts then they // that when multiple cases come in asking for the compilation artifacts then they
@@ -182,6 +186,7 @@ impl ArtifactsCache {
} }
} }
#[instrument(level = "debug", skip_all, err)]
pub async fn with_invalidated_cache(self) -> Result<Self> { pub async fn with_invalidated_cache(self) -> Result<Self> {
cacache::clear(self.path.as_path()) cacache::clear(self.path.as_path())
.await .await
@@ -189,24 +194,24 @@ impl ArtifactsCache {
Ok(self) Ok(self)
} }
pub async fn insert(&self, key: CacheKey, value: CacheValue) -> Result<()> { #[instrument(level = "debug", skip_all, err)]
let key = bincode::serde::encode_to_vec(key, bincode::config::standard())?; pub async fn insert(&self, key: &CacheKey, value: &CacheValue) -> Result<()> {
let value = bincode::serde::encode_to_vec(value, bincode::config::standard())?; let key = bson::to_vec(key)?;
let value = bson::to_vec(value)?;
cacache::write(self.path.as_path(), key.encode_hex(), value).await?; cacache::write(self.path.as_path(), key.encode_hex(), value).await?;
Ok(()) Ok(())
} }
pub async fn get(&self, key: &CacheKey) -> Option<CacheValue> { pub async fn get(&self, key: &CacheKey) -> Option<CacheValue> {
let key = bincode::serde::encode_to_vec(key, bincode::config::standard()).ok()?; let key = bson::to_vec(key).ok()?;
let value = cacache::read(self.path.as_path(), key.encode_hex()) let value = cacache::read(self.path.as_path(), key.encode_hex())
.await .await
.ok()?; .ok()?;
let (value, _) = let value = bson::from_slice::<CacheValue>(&value).ok()?;
bincode::serde::decode_from_slice::<CacheValue, _>(&value, bincode::config::standard())
.ok()?;
Some(value) Some(value)
} }
#[instrument(level = "debug", skip_all, err)]
pub async fn get_or_insert_with( pub async fn get_or_insert_with(
&self, &self,
key: &CacheKey, key: &CacheKey,
@@ -220,7 +225,7 @@ impl ArtifactsCache {
None => { None => {
debug!("Cache miss"); debug!("Cache miss");
let value = callback().await?; let value = callback().await?;
self.insert(key.clone(), value.clone()).await?; self.insert(key, &value).await?;
Ok(value) Ok(value)
} }
} }
+1 -14
View File
@@ -155,17 +155,10 @@ where
async fn handle_input_contract_deployment( async fn handle_input_contract_deployment(
&mut self, &mut self,
metadata: &Metadata, metadata: &Metadata,
case_idx: CaseIdx, _: CaseIdx,
input: &Input, input: &Input,
node: &T::Blockchain, node: &T::Blockchain,
) -> anyhow::Result<HashMap<ContractInstance, TransactionReceipt>> { ) -> anyhow::Result<HashMap<ContractInstance, TransactionReceipt>> {
let span = tracing::debug_span!(
"Handling contract deployment",
?case_idx,
instance = ?input.instance
);
let _guard = span.enter();
let mut instances_we_must_deploy = IndexMap::<ContractInstance, bool>::new(); let mut instances_we_must_deploy = IndexMap::<ContractInstance, bool>::new();
for instance in input.find_all_contract_instances().into_iter() { for instance in input.find_all_contract_instances().into_iter() {
if !self.deployed_contracts.contains_key(&instance) { if !self.deployed_contracts.contains_key(&instance) {
@@ -316,9 +309,6 @@ where
resolver: &impl ResolverApi, resolver: &impl ResolverApi,
tracing_result: &CallFrame, tracing_result: &CallFrame,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
let span = tracing::info_span!("Handling input expectations");
let _guard = span.enter();
// Resolving the `input.expected` into a series of expectations that we can then assert on. // Resolving the `input.expected` into a series of expectations that we can then assert on.
let mut expectations = match input { let mut expectations = match input {
Input { Input {
@@ -508,9 +498,6 @@ where
execution_receipt: TransactionReceipt, execution_receipt: TransactionReceipt,
node: &T::Blockchain, node: &T::Blockchain,
) -> anyhow::Result<(TransactionReceipt, GethTrace, DiffMode)> { ) -> anyhow::Result<(TransactionReceipt, GethTrace, DiffMode)> {
let span = tracing::info_span!("Handling input diff");
let _guard = span.enter();
let trace_options = GethDebugTracingOptions::prestate_tracer(PreStateConfig { let trace_options = GethDebugTracingOptions::prestate_tracer(PreStateConfig {
diff_mode: Some(true), diff_mode: Some(true),
disable_code: None, disable_code: None,
+7 -8
View File
@@ -236,18 +236,17 @@ where
let is_supported = does_compiler_support_mode::<L>(args, &test.mode).await.ok().unwrap_or(false) && let is_supported = does_compiler_support_mode::<L>(args, &test.mode).await.ok().unwrap_or(false) &&
does_compiler_support_mode::<F>(args, &test.mode).await.ok().unwrap_or(false); does_compiler_support_mode::<F>(args, &test.mode).await.ok().unwrap_or(false);
tracing::warn!(
metadata_file_path = %test.path.display(),
case_idx = %test.case_idx,
case_name = ?test.case.name,
mode = %test.mode,
"Skipping test as one or both of the compilers don't support it"
);
// We filter_map to avoid needing to clone `test`, but return it as-is. // We filter_map to avoid needing to clone `test`, but return it as-is.
if is_supported { if is_supported {
Some(test) Some(test)
} else { } else {
tracing::warn!(
metadata_file_path = %test.path.display(),
case_idx = %test.case_idx,
case_name = ?test.case.name,
mode = %test.mode,
"Skipping test as one or both of the compilers don't support it"
);
None None
} }
}) })
-3
View File
@@ -281,9 +281,6 @@ impl EthereumNode for GethNode {
&self, &self,
transaction: TransactionRequest, transaction: TransactionRequest,
) -> anyhow::Result<alloy::rpc::types::TransactionReceipt> { ) -> anyhow::Result<alloy::rpc::types::TransactionReceipt> {
let span = tracing::debug_span!("Submitting transaction", ?transaction);
let _guard = span.enter();
let provider = Arc::new(self.provider().await?); let provider = Arc::new(self.provider().await?);
let transaction_hash = *provider.send_transaction(transaction).await?.tx_hash(); let transaction_hash = *provider.send_transaction(transaction).await?.tx_hash();