Skip to content

Commit

Permalink
refactor: move simulation to mempool
Browse files Browse the repository at this point in the history
  • Loading branch information
dancoombs committed Jul 25, 2023
1 parent e262dc3 commit 119566d
Show file tree
Hide file tree
Showing 18 changed files with 1,430 additions and 570 deletions.
221 changes: 206 additions & 15 deletions proto/op_pool.proto
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,23 @@ message GetSupportedEntryPointsResponse {

message AddOpRequest {
bytes entry_point = 1;
MempoolOp op = 2;
UserOperation op = 2;
}
message AddOpResponse {
oneof result {
AddOpSuccess success = 1;
AddOpFailure failure = 2;
}
}

message AddOpSuccess {
bytes hash = 1;
}

message AddOpFailure {
MempoolError error = 1;
}

message GetOpsRequest {
bytes entry_point = 1;
uint64 max_ops = 2;
Expand Down Expand Up @@ -122,22 +133,202 @@ enum ReputationStatus {
BANNED = 2;
}

message ErrorInfo {
string reason = 1;
map<string, string> metadata = 2;
// MEMPOOL ERRORS
message MempoolError {
oneof error {
string internal = 1;
ReplacementUnderpricedError replacement_underpriced = 2;
MaxOperationsReachedError max_operations_reached = 3;
EntityThrottledError entity_throttled = 4;
DiscardedOnInsertError discarded_on_insert = 5;
PrecheckViolationError precheck_violation = 6;
SimulationViolationError simulation_violation = 7;
InvalidSignatureError invalid_signature = 8;
UnsupportedAggregatorError unsupported_aggregator = 9;
}
}

message ReplacementUnderpricedError {
bytes current_fee = 1;
bytes current_priority_fee = 2;
}

message MaxOperationsReachedError {
uint64 num_ops = 1;
bytes sender_address = 2;
}

message EntityThrottledError {
Entity entity = 1;
}

message DiscardedOnInsertError {}

message InvalidSignatureError {}

message UnsupportedAggregatorError {
bytes aggregator_address = 1;
}

// PRECHECK VIOLATIONS
message PrecheckViolationError {
oneof violation {
InitCodeTooShort init_code_too_short = 1;
SenderIsNotContractAndNoInitCode sender_is_not_contract_and_no_init_code = 2;
ExistingSenderWithInitCode existing_sender_with_init_code = 3;
FactoryIsNotContract factory_is_not_contract = 4;
VerificationGasLimitTooHigh verification_gas_limit_too_high = 5;
PreVerificationGasTooLow pre_verification_gas_too_low = 6;
PaymasterTooShort paymaster_too_short = 7;
PaymasterIsNotContract paymaster_is_not_contract = 8;
PaymasterDepositTooLow paymaster_deposit_too_low = 9;
SenderFundsTooLow sender_funds_too_low = 10;
MaxFeePerGasTooLow max_fee_per_gas_too_low = 11;
MaxPriorityFeePerGasTooLow max_priority_fee_per_gas_too_low = 12;
CallGasLimitTooLow call_gas_limit_too_low = 13;
}
}

message InitCodeTooShort {
uint64 length = 1;
}

message SenderIsNotContractAndNoInitCode {
bytes sender_address = 1;
}

message ExistingSenderWithInitCode {
bytes sender_address = 1;
}

message FactoryIsNotContract {
bytes factory_address = 1;
}

message VerificationGasLimitTooHigh {
bytes actual_gas = 1;
bytes max_gas = 2;
}

message PreVerificationGasTooLow {
bytes actual_gas = 1;
bytes min_gas = 2;
}

message PaymasterTooShort {
uint64 length = 1;
}

message PaymasterIsNotContract {
bytes paymaster_address = 1;
}

message PaymasterDepositTooLow {
bytes actual_deposit = 1;
bytes min_deposit = 2;
}

enum ErrorReason {
ERROR_REASON_UNSPECIFIED = 0;
ERROR_REASON_INTERNAL = 1;
ERROR_REASON_ENTITY_THROTTLED = 2;
ERROR_REASON_OPERATION_REJECTED = 3;
ERROR_REASON_REPLACEMENT_UNDERPRICED = 4;
ERROR_REASON_OPERATION_DISCARDED_ON_INSERT = 5;
message SenderFundsTooLow {
bytes actual_funds = 1;
bytes min_funds = 2;
}

enum ErrorMetadataKey {
ERROR_METADATA_KEY_UNSPECIFIED = 0;
ERROR_METADATA_KEY_CURRENT_MAX_PRIORITY_FEE_PER_GAS = 1;
ERROR_METADATA_KEY_CURRENT_MAX_FEE_PER_GAS = 2;
message MaxFeePerGasTooLow {
bytes actual_fee = 1;
bytes min_fee = 2;
}

message MaxPriorityFeePerGasTooLow {
bytes actual_fee = 1;
bytes min_fee = 2;
}

message CallGasLimitTooLow {
bytes actual_gas_limit = 1;
bytes min_gas_limit = 2;
}

// SIMULATION VIOLATIONS
message SimulationViolationError {
oneof violation {
UnintendedRevertWithMessage unintended_revert_with_message = 1;
UsedForbiddenOpcode used_forbidden_opcode = 2;
UsedForbiddenPrecompile used_forbidden_precompile = 3;
FactoryCalledCreate2Twice factory_called_create2_twice = 4;
InvalidStorageAccess invalid_storage_access = 5;
NotStaked not_staked = 6;
UnintendedRevert unintended_revert = 7;
DidNotRevert did_not_revert = 8;
WrongNumberOfPhases wrong_number_of_phases = 9;
CallHadValue call_had_value = 10;
OutOfGas out_of_gas = 11;
AccessedUndeployedContract accessed_undeployed_contract = 12;
CalledBannedEntryPointMethod called_banned_entry_point_method = 13;
CodeHashChanged code_hash_changed = 14;
AggregatorValidationFailed aggregator_validation_failed = 15;
}
}

message UnintendedRevertWithMessage {
Entity entity = 1;
string reason = 2;
}

message UsedForbiddenOpcode {
Entity entity = 1;
bytes contract_address = 2;
uint32 opcode = 3;
}

message UsedForbiddenPrecompile {
Entity entity = 1;
bytes contract_address = 2;
bytes precompile_address = 3;
}

message FactoryCalledCreate2Twice {
bytes factory_address = 1;
}

message InvalidStorageAccess {
Entity entity = 1;
bytes contract_address = 2;
bytes slot = 3;
}

message NotStaked {
Entity entity = 1;
bytes min_stake = 2;
bytes min_unstake_delay = 3;
}

message UnintendedRevert {
EntityType entity_type = 1;
}

message DidNotRevert {}

message WrongNumberOfPhases {
uint32 num_phases = 1;
}

message CallHadValue {
Entity entity = 1;
}

message OutOfGas {
Entity entity = 1;
}

message AccessedUndeployedContract {
Entity entity = 1;
bytes contract_address = 2;
}

message CalledBannedEntryPointMethod {
Entity entity = 1;
}

message CodeHashChanged {}

message AggregatorValidationFailed {}
2 changes: 0 additions & 2 deletions src/cli/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ pub async fn run(bundler_args: NodeCliArgs, common_args: CommonArgs) -> anyhow::
pool_url,
builder_url,
(&common_args).try_into()?,
(&common_args).into(),
(&common_args).try_into()?,
)
.await?;

Expand Down
23 changes: 20 additions & 3 deletions src/cli/pool.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use std::time::Duration;
use std::{collections::HashMap, time::Duration};

use anyhow::Context;
use clap::Args;
use ethers::types::H256;

use super::CommonArgs;
use crate::{
cli::json::get_json_config,
common::handle::spawn_tasks_with_shutdown,
common::{handle::spawn_tasks_with_shutdown, mempool::MempoolConfig},
op_pool::{self, PoolConfig, PoolTask},
};

Expand Down Expand Up @@ -96,6 +97,14 @@ impl PoolArgs {
tracing::info!("blocklist: {:?}", blocklist);
tracing::info!("allowlist: {:?}", allowlist);

let mempool_channel_configs = match &common.mempool_config_path {
Some(path) => {
get_json_config::<HashMap<H256, MempoolConfig>>(path, &common.aws_region).await?
}
None => HashMap::from([(H256::zero(), MempoolConfig::default())]),
};
tracing::info!("Mempool channel configs: {:?}", mempool_channel_configs);

let pool_configs = common
.entry_points
.iter()
Expand All @@ -110,16 +119,24 @@ impl PoolArgs {
max_size_of_pool_bytes: self.max_size_in_bytes,
blocklist: blocklist.clone(),
allowlist: allowlist.clone(),
precheck_settings: common.try_into()?,
sim_settings: common.try_into()?,
mempool_channel_configs: mempool_channel_configs.clone(),
})
})
.collect::<anyhow::Result<Vec<PoolConfig>>>()?;

let http_url = common
.node_http
.as_ref()
.ok_or_else(|| anyhow::anyhow!("node_http is required"))?;

Ok(op_pool::Args {
port: self.port,
host: self.host.clone(),
chain_id: common.chain_id,
ws_url: common.node_ws.clone(),
http_url: common.node_http.clone(),
http_url: http_url.to_owned(),
http_poll_interval: Duration::from_millis(self.http_poll_interval_millis),
pool_configs,
})
Expand Down
21 changes: 3 additions & 18 deletions src/cli/rpc.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use std::{collections::HashMap, time::Duration};
use std::time::Duration;

use anyhow::Context;
use clap::Args;
use ethers::types::H256;

use super::{json::get_json_config, CommonArgs};
use super::CommonArgs;
use crate::{
common::{handle::spawn_tasks_with_shutdown, mempool::MempoolConfig, precheck, simulation},
common::handle::spawn_tasks_with_shutdown,
rpc::{self, estimation, RpcTask},
};

Expand Down Expand Up @@ -61,8 +60,6 @@ impl RpcArgs {
common: &CommonArgs,
pool_url: String,
builder_url: String,
precheck_settings: precheck::Settings,
sim_settings: simulation::Settings,
estimation_settings: estimation::Settings,
) -> anyhow::Result<rpc::Args> {
let apis = self
Expand All @@ -71,13 +68,6 @@ impl RpcArgs {
.map(|api| api.parse())
.collect::<Result<Vec<_>, _>>()?;

let mempool_configs = match &common.mempool_config_path {
Some(path) => {
get_json_config::<HashMap<H256, MempoolConfig>>(path, &common.aws_region).await?
}
None => HashMap::from([(H256::zero(), MempoolConfig::default())]),
};

Ok(rpc::Args {
port: self.port,
host: self.host.clone(),
Expand All @@ -95,11 +85,8 @@ impl RpcArgs {
.context("rpc requires node_http arg")?,
chain_id: common.chain_id,
api_namespaces: apis,
precheck_settings,
sim_settings,
estimation_settings,
rpc_timeout: Duration::from_secs(self.timeout_seconds.parse()?),
mempool_configs,
})
}
}
Expand Down Expand Up @@ -142,8 +129,6 @@ pub async fn run(rpc_args: RpcCliArgs, common_args: CommonArgs) -> anyhow::Resul
pool_url,
builder_url,
(&common_args).try_into()?,
(&common_args).into(),
(&common_args).try_into()?,
)
.await?;

Expand Down
Loading

0 comments on commit 119566d

Please sign in to comment.