From 6a3d0f5ab19d2f8f2ff458d02a6587b910e29895 Mon Sep 17 00:00:00 2001 From: Vid Kersic Date: Mon, 1 Jan 2024 22:12:11 +0100 Subject: [PATCH] fix: rebase and other problems --- Makefile | 4 +-- crates/bundler/src/bundler.rs | 10 ++++++-- crates/contracts/src/entry_point.rs | 4 +-- crates/mempool/src/database/mod.rs | 1 + crates/mempool/src/error.rs | 25 ++++++++++++------- crates/mempool/src/uopool.rs | 2 +- .../src/validate/sanity/unstaked_entities.rs | 6 ++--- .../validate/simulation_trace/call_stack.rs | 8 +++--- .../simulation_trace/storage_access.rs | 8 +++--- crates/p2p/src/discovery.rs | 11 ++------ crates/p2p/src/gossipsub.rs | 3 ++- crates/p2p/src/request_response/behaviour.rs | 4 +-- crates/p2p/src/request_response/handler.rs | 6 +---- crates/rpc/src/middleware.rs | 4 +-- tests/Cargo.toml | 2 +- 15 files changed, 50 insertions(+), 48 deletions(-) diff --git a/Makefile b/Makefile index c0c7b418..8d0077d5 100644 --- a/Makefile +++ b/Makefile @@ -20,10 +20,10 @@ run-silius-create-wallet: cargo run --release -- create-wallet --output-path ${HOME}/.silius run-silius-debug: - cargo run --release -- node --eth-client-address ws://127.0.0.1:8546 --mnemonic-file ${HOME}/.silius/0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --beneficiary 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --entry-points 0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789 --http --ws --http.api eth,debug,web3 --ws.api eth,debug,web3 + cargo run --release -- node --eth-client-address ws://127.0.0.1:8546 --mnemonic-file ${HOME}/.silius/0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --beneficiary 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --entry-points 0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789 --http --ws --http.api eth,debug,web3 --ws.api eth,debug,web3 --poll-interval 5 run-silius-debug-mode: - cargo run --profile debug-fast -- node --verbosity 4 --eth-client-address ws://127.0.0.1:8546 --mnemonic-file /home/vid/.silius/0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --beneficiary 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --entry-points 0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789 --http --ws --http.api eth,debug,web3 --ws.api eth,debug,web3 + cargo run --profile debug-fast -- node --verbosity 4 --eth-client-address ws://127.0.0.1:8546 --mnemonic-file /home/vid/.silius/0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --beneficiary 0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266 --entry-points 0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789 --http --ws --http.api eth,debug,web3 --ws.api eth,debug,web3 --poll-interval 5 fetch-thirdparty: git submodule update --init diff --git a/crates/bundler/src/bundler.rs b/crates/bundler/src/bundler.rs index 7a90d0c4..fb065f00 100644 --- a/crates/bundler/src/bundler.rs +++ b/crates/bundler/src/bundler.rs @@ -14,7 +14,7 @@ use silius_contracts::entry_point::EntryPointAPI; use silius_primitives::{ bundler::SendStrategy, constants::{flashbots_relay_endpoints, supported_chains}, - UserOperation, Wallet, + UserOperation, UserOperationHash, Wallet, }; use std::{sync::Arc, time::Duration}; use tracing::{info, trace}; @@ -158,7 +158,13 @@ where return Ok(H256::default()); }; - info!("Creating a new bundle with {} user operations", uos.len()); + info!( + "Creating a new bundle with {} user operations: {:?}", + uos.len(), + uos.iter() + .map(|uo| uo.hash(&self.entry_point, &self.chain.id().into())) + .collect::>() + ); trace!("Bundle content: {uos:?}"); match self.send_bundle_mode { diff --git a/crates/contracts/src/entry_point.rs b/crates/contracts/src/entry_point.rs index 236b38a9..8146ea9b 100644 --- a/crates/contracts/src/entry_point.rs +++ b/crates/contracts/src/entry_point.rs @@ -213,9 +213,7 @@ impl EntryPoint { None, ) .await - .map_err(|e| { - EntryPointError::from_middleware_error::(e).expect_err("call err is expected") - }) + .map_err(|err| EntryPointError::Provider { inner: err.to_string() }) } pub async fn simulate_handle_op>( diff --git a/crates/mempool/src/database/mod.rs b/crates/mempool/src/database/mod.rs index 552add43..14b3090e 100644 --- a/crates/mempool/src/database/mod.rs +++ b/crates/mempool/src/database/mod.rs @@ -1,5 +1,6 @@ //! The database implementation of the [Mempool](crate::mempool::Mempool) trait. Primarily used for //! storing mempool information in a local database. + pub use self::env::DatabaseError; use self::env::Env; use reth_libmdbx::EnvironmentKind; diff --git a/crates/mempool/src/error.rs b/crates/mempool/src/error.rs index a11c1224..9c6b18ff 100644 --- a/crates/mempool/src/error.rs +++ b/crates/mempool/src/error.rs @@ -1,3 +1,4 @@ +#[cfg(feature = "mdbx")] use crate::DatabaseError; use ethers::types::{Address, U256}; use serde::{Deserialize, Serialize}; @@ -42,6 +43,7 @@ pub enum MempoolErrorKind { inner: String, }, /// Database error + #[cfg(feature = "mdbx")] #[error(transparent)] Database(DatabaseError), /// Any other error @@ -70,6 +72,7 @@ impl From for MempoolErrorKind { } } +#[cfg(feature = "mdbx")] impl From for MempoolErrorKind { fn from(e: reth_db::Error) -> Self { Self::Database(e.into()) @@ -94,30 +97,32 @@ pub enum InvalidMempoolUserOperationError { #[derive(Debug, Error, Serialize, Deserialize)] pub enum ReputationError { /// Entity is banned - #[error("{entity} {address} is banned")] + #[error("{entity} {address:?} is banned")] BannedEntity { entity: String, address: Address }, /// Entity is throttled - #[error("{entity} {address} is throttled")] + #[error("{entity} {address:?} is throttled")] ThrottledEntity { entity: String, address: Address }, /// Stake of the entity is too low - #[error("{entity} {address} stake {stake} is too low {min_stake}")] + #[error("{entity} {address:?} stake {stake} is too low {min_stake}")] StakeTooLow { entity: String, address: Address, stake: U256, min_stake: U256 }, /// Unstake delay of the entity is too low - #[error("{entity} {address} unstake delay {unstake_delay} is too low {min_unstake_delay}")] + #[error("{entity} {address:?} unstake delay {unstake_delay} is too low {min_unstake_delay}")] UnstakeDelayTooLow { address: Address, entity: String, unstake_delay: U256, min_unstake_delay: U256, }, - /// Entity is unstaked (with optional message) - #[error("{entity} {address} is unstaked")] + /// Entity is unstaked + #[error("{entity} {address:?} is unstaked")] UnstakedEntity { entity: String, address: Address }, /// Database error + #[cfg(feature = "mdbx")] #[error(transparent)] Database(DatabaseError), } +#[cfg(feature = "mdbx")] impl From for ReputationError { fn from(e: reth_db::Error) -> Self { Self::Database(e.into()) @@ -158,7 +163,7 @@ pub enum SanityError { #[error("{inner}")] Sender { inner: String }, /// Entity role validation - #[error("A {entity} at {address} in this user operation is used as a {entity_other} entity in another user operation currently in mempool")] + #[error("A {entity} at {address:?} in this user operation is used as a {entity_other} entity in another useroperation currently in mempool")] EntityRoles { entity: String, address: Address, entity_other: String }, /// Reputation error #[error(transparent)] @@ -170,6 +175,7 @@ pub enum SanityError { inner: String, }, /// Database error + #[cfg(feature = "mdbx")] #[error(transparent)] Database(DatabaseError), /// Any other error @@ -199,7 +205,7 @@ impl From for SanityError { #[derive(Debug, Error, Serialize, Deserialize)] pub enum SimulationError { /// Signature verification failed - #[error("Invalid user operation signature or paymaster signature")] + #[error("Invalid userop signature or paymaster signature")] Signature, /// User operation timestamp invalid #[error("{inner}")] @@ -217,7 +223,7 @@ pub enum SimulationError { #[error("Storage access validation failed for slot: {slot}")] StorageAccess { slot: String }, /// Unstaked entity did something it shouldn't - #[error("A unstaked {entity} at {address} {inner}")] + #[error("A unstaked {entity} at {address:?}: {inner}")] Unstaked { entity: String, address: Address, inner: String }, /// Errors related to calls #[error("Illegal call into {inner}")] @@ -238,6 +244,7 @@ pub enum SimulationError { inner: String, }, /// Database error + #[cfg(feature = "mdbx")] #[error(transparent)] Database(DatabaseError), /// Any other error diff --git a/crates/mempool/src/uopool.rs b/crates/mempool/src/uopool.rs index 4a0ca988..9cbb2447 100644 --- a/crates/mempool/src/uopool.rs +++ b/crates/mempool/src/uopool.rs @@ -467,7 +467,7 @@ where Err(err) => { return Err(MempoolError { hash: uo.hash(&self.entry_point.address(), &self.chain.id().into()), - kind: SimulationError::from(err).into(), + kind: SimulationError::Execution { inner: err.to_string() }.into(), }) } } diff --git a/crates/mempool/src/validate/sanity/unstaked_entities.rs b/crates/mempool/src/validate/sanity/unstaked_entities.rs index ff54e48f..f3e94dfd 100644 --- a/crates/mempool/src/validate/sanity/unstaked_entities.rs +++ b/crates/mempool/src/validate/sanity/unstaked_entities.rs @@ -105,7 +105,7 @@ impl SanityCheck for UnstakedEntities { return Err(SanityError::EntityRoles { entity: SENDER.into(), address: sender, - entity_other: "(factory/paymaster/aggregator)".into(), + entity_other: "different".into(), }); } @@ -131,7 +131,7 @@ impl SanityCheck for UnstakedEntities { return Err(SanityError::EntityRoles { entity: FACTORY.into(), address: sender, - entity_other: "(sender/paymaster/aggregator)".into(), + entity_other: "sender".into(), }); } @@ -159,7 +159,7 @@ impl SanityCheck for UnstakedEntities { return Err(SanityError::EntityRoles { entity: PAYMASTER.into(), address: sender, - entity_other: "(sender/factory/aggregator)".into(), + entity_other: "sender".into(), }); } diff --git a/crates/mempool/src/validate/simulation_trace/call_stack.rs b/crates/mempool/src/validate/simulation_trace/call_stack.rs index d27edb62..2c8c47ce 100644 --- a/crates/mempool/src/validate/simulation_trace/call_stack.rs +++ b/crates/mempool/src/validate/simulation_trace/call_stack.rs @@ -2,7 +2,7 @@ use crate::{ mempool::{Mempool, UserOperationAct, UserOperationAddrAct, UserOperationCodeHashAct}, reputation::{HashSetOp, ReputationEntryOp}, validate::{utils::extract_stake_info, SimulationTraceCheck, SimulationTraceHelper}, - Reputation, ReputationError, SimulationError, + Reputation, SimulationError, }; use ethers::{abi::AbiDecode, providers::Middleware}; use silius_contracts::{ @@ -165,11 +165,11 @@ impl SimulationTraceCheck for CallStack { if !context.is_empty() && reputation.verify_stake(PAYMASTER, Some(*stake_info)).is_err() { - return Err(ReputationError::UnstakedEntity { + return Err(SimulationError::Unstaked { entity: PAYMASTER.into(), address: stake_info.address, - } - .into()); + inner: "must not return context".into(), + }); } } } diff --git a/crates/mempool/src/validate/simulation_trace/storage_access.rs b/crates/mempool/src/validate/simulation_trace/storage_access.rs index dc1f2090..47700ba8 100644 --- a/crates/mempool/src/validate/simulation_trace/storage_access.rs +++ b/crates/mempool/src/validate/simulation_trace/storage_access.rs @@ -2,7 +2,7 @@ use crate::{ mempool::{Mempool, UserOperationAct, UserOperationAddrAct, UserOperationCodeHashAct}, reputation::{HashSetOp, ReputationEntryOp}, validate::{utils::extract_stake_info, SimulationTraceCheck, SimulationTraceHelper}, - Reputation, ReputationError, SimulationError, + Reputation, SimulationError, }; use ethers::{ providers::Middleware, @@ -177,11 +177,11 @@ impl SimulationTraceCheck for StorageAccess { } if !slot_staked.is_empty() && !stake_info_l.is_staked() { - return Err(ReputationError::UnstakedEntity { + return Err(SimulationError::Unstaked { entity: LEVEL_TO_ENTITY[l].into(), address: stake_info_l.address, - } - .into()); + inner: format!("accessed slot {slot_staked}"), + }); } } } diff --git a/crates/p2p/src/discovery.rs b/crates/p2p/src/discovery.rs index 21a44252..fd482cbf 100644 --- a/crates/p2p/src/discovery.rs +++ b/crates/p2p/src/discovery.rs @@ -1,7 +1,7 @@ use crate::config::Config; use discv5::{ enr::{CombinedKey, NodeId}, - Discv5, ConfigBuilder, Event, Enr, + ConfigBuilder, Discv5, Enr, Event, }; use futures::{stream::FuturesUnordered, Future, FutureExt, StreamExt}; use libp2p::swarm::{dummy::ConnectionHandler, NetworkBehaviour}; @@ -28,14 +28,7 @@ pub struct Discovery { pub enum EventStream { /// Awaiting an event stream to be generated. This is required due to the poll nature of /// `Discovery` - Awaiting( - Pin< - Box< - dyn Future, discv5::Error>> - + Send, - >, - >, - ), + Awaiting(Pin, discv5::Error>> + Send>>), /// The future has completed. Present(mpsc::Receiver), // The future has failed or discv5 has been disabled. There are no events from discv5. diff --git a/crates/p2p/src/gossipsub.rs b/crates/p2p/src/gossipsub.rs index 90c72aa0..93f9f2f1 100644 --- a/crates/p2p/src/gossipsub.rs +++ b/crates/p2p/src/gossipsub.rs @@ -117,7 +117,8 @@ pub fn create_gossisub(mempool_ids: Vec) -> Result { .validate_messages() .validation_mode(ValidationMode::Anonymous) .message_id_fn(message_id_fn) - .build().map_err(|err| err.to_string())?; + .build() + .map_err(|err| err.to_string())?; let snappy_transform = SnappyTransform::new(MAX_GOSSIP_SNAP_SIZE); let mut gossipsub = Gossipsub::new_with_subscription_filter_and_transform( MessageAuthenticity::Anonymous, diff --git a/crates/p2p/src/request_response/behaviour.rs b/crates/p2p/src/request_response/behaviour.rs index ebccec0e..38cfdda3 100644 --- a/crates/p2p/src/request_response/behaviour.rs +++ b/crates/p2p/src/request_response/behaviour.rs @@ -7,8 +7,8 @@ use futures::channel::oneshot; use libp2p::{ swarm::{ dial_opts::DialOpts, ConnectionClosed, ConnectionDenied, ConnectionId, DialFailure, - FromSwarm, NetworkBehaviour, NotifyHandler, THandler, THandlerInEvent, - THandlerOutEvent, ToSwarm, + FromSwarm, NetworkBehaviour, NotifyHandler, THandler, THandlerInEvent, THandlerOutEvent, + ToSwarm, }, PeerId, }; diff --git a/crates/p2p/src/request_response/handler.rs b/crates/p2p/src/request_response/handler.rs index def273cb..85dd5f3c 100644 --- a/crates/p2p/src/request_response/handler.rs +++ b/crates/p2p/src/request_response/handler.rs @@ -402,11 +402,7 @@ impl ConnectionHandler for Handler { &mut self, cx: &mut std::task::Context<'_>, ) -> std::task::Poll< - ConnectionHandlerEvent< - Self::OutboundProtocol, - Self::OutboundOpenInfo, - Self::ToBehaviour, - >, + ConnectionHandlerEvent, > { match self.worker_streams.poll_unpin(cx) { Poll::Ready((_, Ok(Ok(event)))) => { diff --git a/crates/rpc/src/middleware.rs b/crates/rpc/src/middleware.rs index f176eab5..8e6ec790 100644 --- a/crates/rpc/src/middleware.rs +++ b/crates/rpc/src/middleware.rs @@ -105,8 +105,8 @@ where } if let Ok(err) = serde_json::from_slice::(&res_bb) { - if err.error.code() == ErrorCode::MethodNotFound.code() - && err.error.message() == METHOD_NOT_FOUND_MSG + if err.error.code() == ErrorCode::MethodNotFound.code() && + err.error.message() == METHOD_NOT_FOUND_MSG { let req = Request::post(addr.clone()) .header(hyper::header::CONTENT_TYPE, "application/json") diff --git a/tests/Cargo.toml b/tests/Cargo.toml index b2761cb1..a1b6b28f 100644 --- a/tests/Cargo.toml +++ b/tests/Cargo.toml @@ -14,7 +14,7 @@ homepage = "https://github.com/silius-rs/silius/tree/main/tests" [dependencies] # workspace dependencies silius-contracts = { workspace = true } -silius-mempool = { workspace = true } +silius-mempool = { workspace = true, features = ["mdbx"] } silius-primitives = { workspace = true } # eth