Skip to content

Commit

Permalink
refactor: refactor uopool adjustments on other crates
Browse files Browse the repository at this point in the history
  • Loading branch information
zsluedem committed Nov 26, 2023
1 parent d7252e1 commit 87aa4e2
Show file tree
Hide file tree
Showing 33 changed files with 607 additions and 400 deletions.
37 changes: 23 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions bin/silius/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@ ethers = { workspace = true }
expanded-pathbuf = { workspace = true }
eyre = { workspace = true }
log = "0.4.19"
parking_lot = { workspace = true }
pin-utils = "0.1"
silius-bundler = { path = "../../crates/bundler" }
silius-contracts = { path = "../../crates/contracts" }
silius-grpc = { path = "../../crates/grpc" }
silius-p2p = { path = "../../crates/p2p" }
silius-primitives = { path = "../../crates/primitives" }
silius-rpc = { path = "../../crates/rpc" }
silius-uopool = { path = "../../crates/uopool" }
tokio = { workspace = true }
tracing = { workspace = true }
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
269 changes: 244 additions & 25 deletions bin/silius/src/bundler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,45 @@ use crate::{
};
use alloy_chains::Chain;
use ethers::{providers::Middleware, types::Address};
use parking_lot::RwLock;
use silius_contracts::EntryPoint;
use silius_grpc::{
bundler_client::BundlerClient, bundler_service_run, uo_pool_client::UoPoolClient,
uopool_service_run,
};
use silius_primitives::{
bundler::SendBundleMode,
consts::{flashbots_relay_endpoints, p2p::DISCOVERY_SECRET_FILE_NAME},
consts::{entry_point, flashbots_relay_endpoints, p2p::DISCOVERY_SECRET_FILE_NAME},
consts::{
p2p::DB_FOLDER_NAME,
reputation::{
BAN_SLACK, MIN_INCLUSION_RATE_DENOMINATOR, MIN_UNSTAKE_DELAY, THROTTLING_SLACK,
},
},
provider::BlockStream,
Wallet,
reputation::ReputationEntry,
simulation::CodeHash,
UserOperation, UserOperationHash, Wallet,
};
use silius_rpc::{
debug_api::{DebugApiServer, DebugApiServerImpl},
eth_api::{EthApiServer, EthApiServerImpl},
web3_api::{Web3ApiServer, Web3ApiServerImpl},
JsonRpcServer, JsonRpcServerType,
};
use std::{collections::HashSet, future::pending, net::SocketAddr, str::FromStr, sync::Arc};
use silius_uopool::{
init_env,
validate::validator::{new_canonical, new_canonical_unsafe},
CodeHashes, DatabaseTable, EntitiesReputation, Mempool, Reputation, UserOperations,
UserOperationsByEntity, UserOperationsBySender, WriteMap,
};
use std::{
collections::{HashMap, HashSet},
future::pending,
net::SocketAddr,
str::FromStr,
sync::Arc,
};
use tracing::info;

pub async fn launch_bundler<M>(
Expand Down Expand Up @@ -161,29 +183,226 @@ where
None => datadir.join(DISCOVERY_SECRET_FILE_NAME),
};

uopool_service_run(
SocketAddr::new(args.uopool_addr, args.uopool_port),
datadir,
entry_points,
eth_client,
block_streams,
chain_id,
args.max_verification_gas,
args.min_stake,
args.min_priority_fee_per_gas,
args.whitelist,
args.uopool_mode,
args.p2p_opts.enable_p2p,
node_key_file,
args.p2p_opts.to_config(),
args.p2p_opts.bootnodes,
)
.await?;

info!(
"Started uopool gRPC service at {:?}:{:?}",
args.uopool_addr, args.uopool_port
let entrypoint_api = EntryPoint::new(
eth_client.clone(),
Address::from_str(entry_point::ADDRESS).expect("address should be valid"),
);
match (args.uopool_mode, args.use_memory) {
(silius_primitives::UoPoolMode::Standard, true) => {
let validator = new_canonical(
entrypoint_api,
chain_id,
args.max_verification_gas,
args.min_priority_fee_per_gas,
);
let mempool = Mempool::new(
Arc::new(RwLock::new(
HashMap::<UserOperationHash, UserOperation>::default(),
)),
Arc::new(RwLock::new(
HashMap::<Address, HashSet<UserOperationHash>>::default(),
)),
Arc::new(RwLock::new(
HashMap::<Address, HashSet<UserOperationHash>>::default(),
)),
Arc::new(RwLock::new(
HashMap::<UserOperationHash, Vec<CodeHash>>::default(),
)),
);
let mut reputation = Reputation::new(
MIN_INCLUSION_RATE_DENOMINATOR,
THROTTLING_SLACK,
BAN_SLACK,
args.min_stake,
MIN_UNSTAKE_DELAY.into(),
Arc::new(RwLock::new(HashSet::<Address>::default())),
Arc::new(RwLock::new(HashSet::<Address>::default())),
Arc::new(RwLock::new(HashMap::<Address, ReputationEntry>::default())),
);
for whiteaddr in args.whitelist.iter() {
reputation.add_whitelist(whiteaddr);
}
uopool_service_run(
SocketAddr::new(args.uopool_addr, args.uopool_port),
entry_points,
eth_client,
block_streams,
chain_id,
args.max_verification_gas,
mempool,
reputation,
validator,
args.p2p_opts.enable_p2p,
node_key_file,
args.p2p_opts.to_config(),
args.p2p_opts.bootnodes,
)
.await?;
info!(
"Started uopool gRPC service at {:?}:{:?}",
args.uopool_addr, args.uopool_port
);
}
(silius_primitives::UoPoolMode::Standard, false) => {
let validator = new_canonical(
entrypoint_api,
chain_id,
args.max_verification_gas,
args.min_priority_fee_per_gas,
);
let env = Arc::new(
init_env::<WriteMap>(datadir.join(DB_FOLDER_NAME)).expect("Init mdbx failed"),
);
env.create_tables()
.expect("Create mdbx database tables failed");
let mempool = Mempool::new(
DatabaseTable::<WriteMap, UserOperations>::new(env.clone()),
DatabaseTable::<WriteMap, UserOperationsBySender>::new(env.clone()),
DatabaseTable::<WriteMap, UserOperationsByEntity>::new(env.clone()),
DatabaseTable::<WriteMap, CodeHashes>::new(env.clone()),
);
let mut reputation = Reputation::new(
MIN_INCLUSION_RATE_DENOMINATOR,
THROTTLING_SLACK,
BAN_SLACK,
args.min_stake,
MIN_UNSTAKE_DELAY.into(),
Arc::new(RwLock::new(HashSet::<Address>::default())),
Arc::new(RwLock::new(HashSet::<Address>::default())),
DatabaseTable::<WriteMap, EntitiesReputation>::new(env.clone()),
);
for whiteaddr in args.whitelist.iter() {
reputation.add_whitelist(whiteaddr);
}
uopool_service_run(
SocketAddr::new(args.uopool_addr, args.uopool_port),
entry_points,
eth_client,
block_streams,
chain_id,
args.max_verification_gas,
mempool,
reputation,
validator,
args.p2p_opts.enable_p2p,
node_key_file,
args.p2p_opts.to_config(),
args.p2p_opts.bootnodes,
)
.await?;
info!(
"Started uopool gRPC service at {:?}:{:?}",
args.uopool_addr, args.uopool_port
);
}
(silius_primitives::UoPoolMode::Unsafe, true) => {
let validator = new_canonical_unsafe(
entrypoint_api,
chain_id,
args.max_verification_gas,
args.min_priority_fee_per_gas,
);
let mempool = Mempool::new(
Arc::new(RwLock::new(
HashMap::<UserOperationHash, UserOperation>::default(),
)),
Arc::new(RwLock::new(
HashMap::<Address, HashSet<UserOperationHash>>::default(),
)),
Arc::new(RwLock::new(
HashMap::<Address, HashSet<UserOperationHash>>::default(),
)),
Arc::new(RwLock::new(
HashMap::<UserOperationHash, Vec<CodeHash>>::default(),
)),
);
let mut reputation = Reputation::new(
MIN_INCLUSION_RATE_DENOMINATOR,
THROTTLING_SLACK,
BAN_SLACK,
args.min_stake,
MIN_UNSTAKE_DELAY.into(),
Arc::new(RwLock::new(HashSet::<Address>::default())),
Arc::new(RwLock::new(HashSet::<Address>::default())),
Arc::new(RwLock::new(HashMap::<Address, ReputationEntry>::default())),
);
for whiteaddr in args.whitelist.iter() {
reputation.add_whitelist(whiteaddr);
}
uopool_service_run(
SocketAddr::new(args.uopool_addr, args.uopool_port),
entry_points,
eth_client,
block_streams,
chain_id,
args.max_verification_gas,
mempool,
reputation,
validator,
args.p2p_opts.enable_p2p,
node_key_file,
args.p2p_opts.to_config(),
args.p2p_opts.bootnodes,
)
.await?;
info!(
"Started uopool gRPC service at {:?}:{:?}",
args.uopool_addr, args.uopool_port
);
}
(silius_primitives::UoPoolMode::Unsafe, false) => {
let validator = new_canonical_unsafe(
entrypoint_api,
chain_id,
args.max_verification_gas,
args.min_priority_fee_per_gas,
);
let env = Arc::new(
init_env::<WriteMap>(datadir.join(DB_FOLDER_NAME)).expect("Init mdbx failed"),
);
env.create_tables()
.expect("Create mdbx database tables failed");
let mempool = Mempool::new(
DatabaseTable::<WriteMap, UserOperations>::new(env.clone()),
DatabaseTable::<WriteMap, UserOperationsBySender>::new(env.clone()),
DatabaseTable::<WriteMap, UserOperationsByEntity>::new(env.clone()),
DatabaseTable::<WriteMap, CodeHashes>::new(env.clone()),
);
let mut reputation = Reputation::new(
MIN_INCLUSION_RATE_DENOMINATOR,
THROTTLING_SLACK,
BAN_SLACK,
args.min_stake,
MIN_UNSTAKE_DELAY.into(),
Arc::new(RwLock::new(HashSet::<Address>::default())),
Arc::new(RwLock::new(HashSet::<Address>::default())),
DatabaseTable::<WriteMap, EntitiesReputation>::new(env.clone()),
);
for whiteaddr in args.whitelist.iter() {
reputation.add_whitelist(whiteaddr);
}
uopool_service_run(
SocketAddr::new(args.uopool_addr, args.uopool_port),
entry_points,
eth_client,
block_streams,
chain_id,
args.max_verification_gas,
mempool,
reputation,
validator,
args.p2p_opts.enable_p2p,
node_key_file,
args.p2p_opts.to_config(),
args.p2p_opts.bootnodes,
)
.await?;
info!(
"Started uopool gRPC service at {:?}:{:?}",
args.uopool_addr, args.uopool_port
);
}
};

Ok(())
}
Expand Down
Loading

0 comments on commit 87aa4e2

Please sign in to comment.