Skip to content

Commit

Permalink
Make txpool_content call configurable (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
vkgnosis authored Apr 12, 2022
1 parent 1f60047 commit a163b3b
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 15 deletions.
8 changes: 6 additions & 2 deletions crates/e2e/tests/e2e/eth_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ use solver::{
metrics::NoopMetrics,
settlement_access_list::{create_priority_estimator, AccessListEstimatorType},
settlement_submission::{
submitter::custom_nodes_api::CustomNodesApi, SolutionSubmitter, StrategyArgs,
submitter::custom_nodes_api::{CustomNodesApi, PendingTransactionConfig},
SolutionSubmitter, StrategyArgs,
},
};
use std::{sync::Arc, time::Duration};
Expand Down Expand Up @@ -226,7 +227,10 @@ async fn eth_integration(web3: Web3) {
retry_interval: Duration::from_secs(5),
transaction_strategies: vec![
solver::settlement_submission::TransactionStrategy::CustomNodes(StrategyArgs {
submit_api: Box::new(CustomNodesApi::new(vec![web3.clone()])),
submit_api: Box::new(CustomNodesApi::new(
vec![web3.clone()],
PendingTransactionConfig::Ignore,
)),
max_additional_tip: 0.,
additional_tip_percentage_of_max_fee: 0.,
}),
Expand Down
8 changes: 6 additions & 2 deletions crates/e2e/tests/e2e/onchain_settlement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ use solver::{
metrics::NoopMetrics,
settlement_access_list::{create_priority_estimator, AccessListEstimatorType},
settlement_submission::{
submitter::custom_nodes_api::CustomNodesApi, SolutionSubmitter, StrategyArgs,
submitter::custom_nodes_api::{CustomNodesApi, PendingTransactionConfig},
SolutionSubmitter, StrategyArgs,
},
};
use std::{sync::Arc, time::Duration};
Expand Down Expand Up @@ -231,7 +232,10 @@ async fn onchain_settlement(web3: Web3) {
retry_interval: Duration::from_secs(5),
transaction_strategies: vec![
solver::settlement_submission::TransactionStrategy::CustomNodes(StrategyArgs {
submit_api: Box::new(CustomNodesApi::new(vec![web3.clone()])),
submit_api: Box::new(CustomNodesApi::new(
vec![web3.clone()],
PendingTransactionConfig::Ignore,
)),
max_additional_tip: 0.,
additional_tip_percentage_of_max_fee: 0.,
}),
Expand Down
8 changes: 6 additions & 2 deletions crates/e2e/tests/e2e/settlement_without_onchain_liquidity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ use solver::{
metrics::NoopMetrics,
settlement_access_list::{create_priority_estimator, AccessListEstimatorType},
settlement_submission::{
submitter::custom_nodes_api::CustomNodesApi, SolutionSubmitter, StrategyArgs,
submitter::custom_nodes_api::{CustomNodesApi, PendingTransactionConfig},
SolutionSubmitter, StrategyArgs,
},
};
use std::{sync::Arc, time::Duration};
Expand Down Expand Up @@ -220,7 +221,10 @@ async fn onchain_settlement_without_liquidity(web3: Web3) {
retry_interval: Duration::from_secs(5),
transaction_strategies: vec![
solver::settlement_submission::TransactionStrategy::CustomNodes(StrategyArgs {
submit_api: Box::new(CustomNodesApi::new(vec![web3.clone()])),
submit_api: Box::new(CustomNodesApi::new(
vec![web3.clone()],
PendingTransactionConfig::Ignore,
)),
max_additional_tip: 0.,
additional_tip_percentage_of_max_fee: 0.,
}),
Expand Down
8 changes: 6 additions & 2 deletions crates/e2e/tests/e2e/smart_contract_orders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ use solver::{
metrics::NoopMetrics,
settlement_access_list::{create_priority_estimator, AccessListEstimatorType},
settlement_submission::{
submitter::custom_nodes_api::CustomNodesApi, SolutionSubmitter, StrategyArgs,
submitter::custom_nodes_api::{CustomNodesApi, PendingTransactionConfig},
SolutionSubmitter, StrategyArgs,
},
};
use std::{sync::Arc, time::Duration};
Expand Down Expand Up @@ -189,7 +190,10 @@ async fn smart_contract_orders(web3: Web3) {
retry_interval: Duration::from_secs(5),
transaction_strategies: vec![
solver::settlement_submission::TransactionStrategy::CustomNodes(StrategyArgs {
submit_api: Box::new(CustomNodesApi::new(vec![web3.clone()])),
submit_api: Box::new(CustomNodesApi::new(
vec![web3.clone()],
PendingTransactionConfig::Ignore,
)),
max_additional_tip: 0.,
additional_tip_percentage_of_max_fee: 0.,
}),
Expand Down
8 changes: 6 additions & 2 deletions crates/e2e/tests/e2e/vault_balances.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ use solver::{
metrics::NoopMetrics,
settlement_access_list::{create_priority_estimator, AccessListEstimatorType},
settlement_submission::{
submitter::custom_nodes_api::CustomNodesApi, SolutionSubmitter, StrategyArgs,
submitter::custom_nodes_api::{CustomNodesApi, PendingTransactionConfig},
SolutionSubmitter, StrategyArgs,
},
};
use std::{sync::Arc, time::Duration};
Expand Down Expand Up @@ -170,7 +171,10 @@ async fn vault_balances(web3: Web3) {
retry_interval: Duration::from_secs(5),
transaction_strategies: vec![
solver::settlement_submission::TransactionStrategy::CustomNodes(StrategyArgs {
submit_api: Box::new(CustomNodesApi::new(vec![web3.clone()])),
submit_api: Box::new(CustomNodesApi::new(
vec![web3.clone()],
PendingTransactionConfig::Ignore,
)),
max_additional_tip: 0.,
additional_tip_percentage_of_max_fee: 0.,
}),
Expand Down
18 changes: 15 additions & 3 deletions crates/solver/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ use solver::{
settlement_simulation::TenderlyApi,
settlement_submission::{
submitter::{
custom_nodes_api::CustomNodesApi, eden_api::EdenApi, flashbots_api::FlashbotsApi,
custom_nodes_api::{CustomNodesApi, PendingTransactionConfig},
eden_api::EdenApi,
flashbots_api::FlashbotsApi,
},
SolutionSubmitter, StrategyArgs, TransactionStrategy,
},
Expand Down Expand Up @@ -295,6 +297,10 @@ struct Arguments {
/// in the settlement are checked for price deviation.
#[clap(long, env, use_value_delimiter = true)]
token_list_restriction_for_price_checks: Option<Vec<H160>>,

/// How pending transactions should be fetched.
#[clap(long, env, arg_enum, default_value = "ignore")]
pending_transaction_config: PendingTransactionConfig,
}

#[derive(Copy, Clone, Debug, clap::ArgEnum)]
Expand Down Expand Up @@ -583,7 +589,10 @@ async fn main() {
.map(|strategy| match strategy {
TransactionStrategyArg::PublicMempool => {
TransactionStrategy::CustomNodes(StrategyArgs {
submit_api: Box::new(CustomNodesApi::new(vec![web3.clone()])),
submit_api: Box::new(CustomNodesApi::new(
vec![web3.clone()],
args.pending_transaction_config,
)),
max_additional_tip: 0.,
additional_tip_percentage_of_max_fee: 0.,
})
Expand All @@ -608,7 +617,10 @@ async fn main() {
"missing transaction submission nodes"
);
TransactionStrategy::CustomNodes(StrategyArgs {
submit_api: Box::new(CustomNodesApi::new(submission_nodes.clone())),
submit_api: Box::new(CustomNodesApi::new(
submission_nodes.clone(),
args.pending_transaction_config,
)),
max_additional_tip: 0.,
additional_tip_percentage_of_max_fee: 0.,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,27 @@ const ALREADY_KNOWN_TRANSACTION: &[&str] = &[
"INTERNAL_ERROR: nonce too low", //erigon
];

#[derive(Copy, Clone, Debug, clap::ArgEnum)]
pub enum PendingTransactionConfig {
/// Attempt to fetch pending transactions using txpool_content call. This can cause problems
/// when nodes return a large amount of data or are slow to respond.
TxPool,
/// Do not attempt to fetch pending transactions.
Ignore,
}

#[derive(Clone)]
pub struct CustomNodesApi {
nodes: Vec<Web3>,
pending_transaction_config: PendingTransactionConfig,
}

impl CustomNodesApi {
pub fn new(nodes: Vec<Web3>) -> Self {
Self { nodes }
pub fn new(nodes: Vec<Web3>, pending_transaction_config: PendingTransactionConfig) -> Self {
Self {
nodes,
pending_transaction_config,
}
}
}

Expand Down Expand Up @@ -107,6 +120,10 @@ impl TransactionSubmitting for CustomNodesApi {
address: &H160,
nonce: U256,
) -> Result<Option<EstimatedGasPrice>> {
match self.pending_transaction_config {
PendingTransactionConfig::Ignore => return Ok(None),
PendingTransactionConfig::TxPool => (),
}
let transactions = crate::pending_transactions::pending_transactions(web3.transport())
.await
.context("pending_transactions failed")?;
Expand Down

0 comments on commit a163b3b

Please sign in to comment.