Make the code even more concurrent

This commit is contained in:
Omar Abdulla
2025-08-18 18:39:03 +03:00
parent d45b8da8e3
commit ad3d580df9
6 changed files with 130 additions and 107 deletions
+1
View File
@@ -17,6 +17,7 @@ alloy = { workspace = true }
alloy-primitives = { workspace = true }
alloy-sol-types = { workspace = true }
anyhow = { workspace = true }
futures = { workspace = true }
regex = { workspace = true }
tracing = { workspace = true }
semver = { workspace = true }
+33 -28
View File
@@ -9,6 +9,7 @@ use alloy::{
};
use alloy_primitives::{FixedBytes, utils::parse_units};
use anyhow::Context;
use futures::{FutureExt, StreamExt, TryFutureExt, TryStreamExt, stream};
use semver::VersionReq;
use serde::{Deserialize, Serialize};
@@ -427,14 +428,18 @@ impl Calldata {
buffer.extend_from_slice(bytes);
}
Calldata::Compound(items) => {
for (arg_idx, arg) in items.iter().enumerate() {
buffer.extend(
let resolved = stream::iter(items.iter().enumerate())
.map(|(arg_idx, arg)| async move {
arg.resolve(resolver, context)
.instrument(info_span!("Resolving argument", %arg, arg_idx))
.await?
.to_be_bytes::<32>(),
);
}
.map_ok(|value| value.to_be_bytes::<32>())
.await
})
.buffered(0xFF)
.try_collect::<Vec<_>>()
.await?;
buffer.extend(resolved.into_iter().flatten());
}
};
Ok(())
@@ -457,30 +462,30 @@ impl Calldata {
match self {
Calldata::Single(calldata) => Ok(calldata == other),
Calldata::Compound(items) => {
// Chunking the "other" calldata into 32 byte chunks since each
// one of the items in the compound calldata represents 32 bytes
for (this, other) in items.iter().zip(other.chunks(32)) {
// The matterlabs format supports wildcards and therefore we
// also need to support them.
if this.as_ref() == "*" {
continue;
}
stream::iter(items.iter().zip(other.chunks(32)))
.map(|(this, other)| async move {
// The matterlabs format supports wildcards and therefore we
// also need to support them.
if this.as_ref() == "*" {
return Ok::<_, anyhow::Error>(true);
}
let other = if other.len() < 32 {
let mut vec = other.to_vec();
vec.resize(32, 0);
std::borrow::Cow::Owned(vec)
} else {
std::borrow::Cow::Borrowed(other)
};
let other = if other.len() < 32 {
let mut vec = other.to_vec();
vec.resize(32, 0);
std::borrow::Cow::Owned(vec)
} else {
std::borrow::Cow::Borrowed(other)
};
let this = this.resolve(resolver, context).await?;
let other = U256::from_be_slice(&other);
if this != other {
return Ok(false);
}
}
Ok(true)
let this = this.resolve(resolver, context).await?;
let other = U256::from_be_slice(&other);
Ok(this == other)
})
.buffered(0xFF)
.all(|v| async move { v.is_ok_and(|v| v) })
.map(Ok)
.await
}
}
}