Skip to content

Commit

Permalink
fix: rebase and other problems
Browse files Browse the repository at this point in the history
  • Loading branch information
Vid201 authored and zsluedem committed Jan 3, 2024
1 parent 4b8490c commit 6a3d0f5
Show file tree
Hide file tree
Showing 15 changed files with 50 additions and 48 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions crates/bundler/src/bundler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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::<Vec<UserOperationHash>>()
);
trace!("Bundle content: {uos:?}");

match self.send_bundle_mode {
Expand Down
4 changes: 1 addition & 3 deletions crates/contracts/src/entry_point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,7 @@ impl<M: Middleware + 'static> EntryPoint<M> {
None,
)
.await
.map_err(|e| {
EntryPointError::from_middleware_error::<M>(e).expect_err("call err is expected")
})
.map_err(|err| EntryPointError::Provider { inner: err.to_string() })
}

pub async fn simulate_handle_op<U: Into<UserOperation>>(
Expand Down
1 change: 1 addition & 0 deletions crates/mempool/src/database/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
25 changes: 16 additions & 9 deletions crates/mempool/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[cfg(feature = "mdbx")]
use crate::DatabaseError;
use ethers::types::{Address, U256};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -42,6 +43,7 @@ pub enum MempoolErrorKind {
inner: String,
},
/// Database error
#[cfg(feature = "mdbx")]
#[error(transparent)]
Database(DatabaseError),
/// Any other error
Expand Down Expand Up @@ -70,6 +72,7 @@ impl From<SimulationError> for MempoolErrorKind {
}
}

#[cfg(feature = "mdbx")]
impl From<reth_db::Error> for MempoolErrorKind {
fn from(e: reth_db::Error) -> Self {
Self::Database(e.into())
Expand All @@ -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<reth_db::Error> for ReputationError {
fn from(e: reth_db::Error) -> Self {
Self::Database(e.into())
Expand Down Expand Up @@ -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)]
Expand All @@ -170,6 +175,7 @@ pub enum SanityError {
inner: String,
},
/// Database error
#[cfg(feature = "mdbx")]
#[error(transparent)]
Database(DatabaseError),
/// Any other error
Expand Down Expand Up @@ -199,7 +205,7 @@ impl From<EntryPointError> 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}")]
Expand All @@ -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}")]
Expand All @@ -238,6 +244,7 @@ pub enum SimulationError {
inner: String,
},
/// Database error
#[cfg(feature = "mdbx")]
#[error(transparent)]
Database(DatabaseError),
/// Any other error
Expand Down
2 changes: 1 addition & 1 deletion crates/mempool/src/uopool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
})
}
}
Expand Down
6 changes: 3 additions & 3 deletions crates/mempool/src/validate/sanity/unstaked_entities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl<M: Middleware> SanityCheck<M> for UnstakedEntities {
return Err(SanityError::EntityRoles {
entity: SENDER.into(),
address: sender,
entity_other: "(factory/paymaster/aggregator)".into(),
entity_other: "different".into(),
});
}

Expand All @@ -131,7 +131,7 @@ impl<M: Middleware> SanityCheck<M> for UnstakedEntities {
return Err(SanityError::EntityRoles {
entity: FACTORY.into(),
address: sender,
entity_other: "(sender/paymaster/aggregator)".into(),
entity_other: "sender".into(),
});
}

Expand Down Expand Up @@ -159,7 +159,7 @@ impl<M: Middleware> SanityCheck<M> for UnstakedEntities {
return Err(SanityError::EntityRoles {
entity: PAYMASTER.into(),
address: sender,
entity_other: "(sender/factory/aggregator)".into(),
entity_other: "sender".into(),
});
}

Expand Down
8 changes: 4 additions & 4 deletions crates/mempool/src/validate/simulation_trace/call_stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -165,11 +165,11 @@ impl<M: Middleware> SimulationTraceCheck<M> 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(),
});
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -177,11 +177,11 @@ impl<M: Middleware> SimulationTraceCheck<M> 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}"),
});
}
}
}
Expand Down
11 changes: 2 additions & 9 deletions crates/p2p/src/discovery.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand All @@ -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<Output = Result<mpsc::Receiver<Event>, discv5::Error>>
+ Send,
>,
>,
),
Awaiting(Pin<Box<dyn Future<Output = Result<mpsc::Receiver<Event>, discv5::Error>> + Send>>),
/// The future has completed.
Present(mpsc::Receiver<Event>),
// The future has failed or discv5 has been disabled. There are no events from discv5.
Expand Down
3 changes: 2 additions & 1 deletion crates/p2p/src/gossipsub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ pub fn create_gossisub(mempool_ids: Vec<String>) -> Result<Gossipsub, String> {
.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,
Expand Down
4 changes: 2 additions & 2 deletions crates/p2p/src/request_response/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down
6 changes: 1 addition & 5 deletions crates/p2p/src/request_response/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self::OutboundProtocol, Self::OutboundOpenInfo, Self::ToBehaviour>,
> {
match self.worker_streams.poll_unpin(cx) {
Poll::Ready((_, Ok(Ok(event)))) => {
Expand Down
4 changes: 2 additions & 2 deletions crates/rpc/src/middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ where
}

if let Ok(err) = serde_json::from_slice::<JsonRpcErrorResponse>(&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")
Expand Down
2 changes: 1 addition & 1 deletion tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6a3d0f5

Please sign in to comment.