Skip to content

Commit

Permalink
misc: add different bundle client endpoint, fix verification extra ga…
Browse files Browse the repository at this point in the history
…s, fix storage map grpc
  • Loading branch information
Vid201 committed Oct 31, 2024
1 parent 4ea56f9 commit ba4e44a
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 24 deletions.
9 changes: 6 additions & 3 deletions bin/silius/src/bundler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,24 @@ use std::{
};
use tracing::{info, warn};

pub async fn launch_bundler<M>(
#[allow(clippy::too_many_arguments)]
pub async fn launch_bundler<M, N>(
bundler_args: BundlerArgs,
uopool_args: UoPoolArgs,
common_args: BundlerAndUoPoolArgs,
rpc_args: RpcArgs,
metrics_args: MetricsArgs,
eth_client: Arc<M>,
eth_bundle_client: Arc<N>,
block_streams: Vec<BlockStream>,
) -> eyre::Result<()>
where
M: Middleware + Clone + 'static,
N: Middleware + Clone + 'static,
{
launch_uopool(
uopool_args.clone(),
eth_client.clone(),
eth_client,
block_streams,
common_args.chain,
common_args.entry_points.clone(),
Expand All @@ -78,7 +81,7 @@ where

launch_bundling(
bundler_args.clone(),
eth_client.clone(),
eth_bundle_client,
common_args.chain,
common_args.entry_points,
format!("http://{:?}:{:?}", uopool_args.uopool_addr, uopool_args.uopool_port),
Expand Down
11 changes: 11 additions & 0 deletions bin/silius/src/cli/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ pub struct BundlerArgs {
#[clap(long, default_value = "ethereum-client", value_parser=parse_bundle_strategy)]
pub bundle_strategy: BundleStrategy,

/// Sets the different endpoint for sending bundles.
///
/// By default, this will be the same as `eth-client-address`
#[clap(long)]
pub eth_client_bundle_address: Option<String>,

/// Indicates whether the access list is enabled.
#[clap(long)]
pub enable_access_list: bool,
Expand Down Expand Up @@ -392,6 +398,7 @@ mod tests {
manual_bundle_mode: false,
bundle_interval: 10,
bundle_strategy: BundleStrategy::EthereumClient,
eth_client_bundle_address: None,
bundler_addr: IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)),
bundler_port: 3002,
enable_access_list: false,
Expand Down Expand Up @@ -433,6 +440,7 @@ mod tests {
manual_bundle_mode: false,
bundle_interval: 10,
bundle_strategy: BundleStrategy::EthereumClient,
eth_client_bundle_address: None,
bundler_addr: IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)),
bundler_port: 3002,
enable_access_list: false,
Expand All @@ -458,6 +466,8 @@ mod tests {
"--bundler.port",
"3002",
"--manual-bundle-mode",
"--eth-client-bundle-address",
"http://127.0.0.1:8545",
];
assert_eq!(
BundlerArgs {
Expand All @@ -480,6 +490,7 @@ mod tests {
manual_bundle_mode: true,
bundle_interval: 10,
bundle_strategy: BundleStrategy::EthereumClient,
eth_client_bundle_address: Some(String::from("http://127.0.0.1:8545")),
bundler_addr: IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)),
bundler_port: 3002,
enable_access_list: false,
Expand Down
75 changes: 59 additions & 16 deletions bin/silius/src/cli/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,33 +43,69 @@ impl NodeCommand {
.await?;
let eth_client = Arc::new(MetricsMiddleware::new(http_client));

let eth_bundle_client = if let Some(eth_client_bundle_address) =
self.bundler.eth_client_bundle_address.clone()
{
let http_client_bundle =
create_http_provider(&eth_client_bundle_address, self.common.poll_interval)
.await?;
Arc::new(MetricsMiddleware::new(http_client_bundle))
} else {
eth_client.clone()
};

let block_streams =
create_http_block_streams(eth_client.clone(), self.common.entry_points.len()).await;

launch_bundler(
self.bundler,
self.uopool,
self.common.clone(),
self.rpc,
self.common.metrics,
eth_client,
eth_bundle_client,
block_streams,
)
.await?;
} else {
let http_client = create_ws_provider(&self.common.eth_client_address).await?;
let eth_client = Arc::new(MetricsMiddleware::new(http_client));
let ws_client = create_ws_provider(&self.common.eth_client_address).await?;
let eth_client = Arc::new(MetricsMiddleware::new(ws_client));

let block_streams =
create_ws_block_streams(eth_client.clone(), self.common.entry_points.len()).await;
launch_bundler(
self.bundler,
self.uopool,
self.common.clone(),
self.rpc,
self.common.metrics,
eth_client,
block_streams,
)
.await?;

if let Some(eth_client_bundle_address) = self.bundler.eth_client_bundle_address.clone()
{
let http_client_bundle =
create_http_provider(&eth_client_bundle_address, self.common.poll_interval)
.await?;
let eth_client_bundle = Arc::new(MetricsMiddleware::new(http_client_bundle));

launch_bundler(
self.bundler,
self.uopool,
self.common.clone(),
self.rpc,
self.common.metrics,
eth_client,
eth_client_bundle,
block_streams,
)
.await?;
} else {
launch_bundler(
self.bundler,
self.uopool,
self.common.clone(),
self.rpc,
self.common.metrics,
eth_client.clone(),
eth_client,
block_streams,
)
.await?;
}
}

pending().await
Expand All @@ -95,10 +131,17 @@ pub struct BundlerCommand {
impl BundlerCommand {
/// Execute the command
pub async fn execute(self) -> eyre::Result<()> {
if self.common.eth_client_address.clone().starts_with("http") {
let eth_client_address = if let Some(eth_client_bundle_address) =
self.bundler.eth_client_bundle_address.clone()
{
eth_client_bundle_address
} else {
self.common.eth_client_address.clone()
};

if eth_client_address.clone().starts_with("http") {
let eth_client = Arc::new(
create_http_provider(&self.common.eth_client_address, self.common.poll_interval)
.await?,
create_http_provider(&eth_client_address, self.common.poll_interval).await?,
);
launch_bundling(
self.bundler,
Expand All @@ -110,7 +153,7 @@ impl BundlerCommand {
)
.await?;
} else {
let eth_client = Arc::new(create_ws_provider(&self.common.eth_client_address).await?);
let eth_client = Arc::new(create_ws_provider(&eth_client_address).await?);
launch_bundling(
self.bundler,
eth_client,
Expand Down
6 changes: 3 additions & 3 deletions crates/grpc/src/proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ pub mod types {
.collect(),
slots: slots
.into_iter()
.map(|(k, v)| (Address::from_str(&k).unwrap_or_default(), v.slots))
.map(|(k, v)| (ethers::types::H160::from_str(&k).unwrap_or_default(), v.slots))
.collect(),
}
}
Expand All @@ -413,11 +413,11 @@ pub mod types {
Self {
root_hashes: root_hashes
.into_iter()
.map(|(k, v)| (k.to_string(), v.to_string()))
.map(|(k, v)| (format!("{:?}", k), format!("{:?}", v)))
.collect(),
slots: slots
.into_iter()
.map(|(k, v)| (k.to_string(), StorageSlots { slots: v }))
.map(|(k, v)| (format!("{:?}", k), StorageSlots { slots: v }))
.collect(),
}
}
Expand Down
2 changes: 2 additions & 0 deletions crates/mempool/src/uopool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ impl<M: Middleware + 'static, V: UserOperationValidator> UoPool<M, V> {
UserOperationValidatorMode::SimulationTrace,
)
.await;

debug!("Second validation for userop {:?} result: {:?}", uo.hash, val_out);

match val_out {
Expand All @@ -390,6 +391,7 @@ impl<M: Middleware + 'static, V: UserOperationValidator> UoPool<M, V> {
continue 'uos;
}
}

for addr in val_out.storage_map.slots.keys() {
if *addr != uo.sender && senders_all.contains(addr) {
continue 'uos;
Expand Down
10 changes: 8 additions & 2 deletions crates/mempool/src/validate/simulation/verification_extra_gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,15 @@ impl SimulationCheck for VerificationExtraGas {

let extra_gas = uo.verification_gas_limit - (pre_op_gas - uo.pre_verification_gas);

if extra_gas.as_u64() < MIN_EXTRA_GAS {
// If account is not deployed, check against MIN_EXTRA_GAS, else MIN_EXTRA_GAS / 2
let extra_gas_check =
if uo.init_code.is_empty() { MIN_EXTRA_GAS / 2 } else { MIN_EXTRA_GAS };

if extra_gas.as_u64() < extra_gas_check {
return Err(SimulationError::Validation {
inner: format!("Verification gas should have extra 2000 gas (has ${extra_gas})"),
inner: format!(
"Verification gas should have extra ${extra_gas_check} gas (has ${extra_gas})"
),
});
}

Expand Down

0 comments on commit ba4e44a

Please sign in to comment.