Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
9d7a6bf
added composite scenarios - setting up multiple contracts
arpitkarnatak May 21, 2025
171b220
Added better documentation for compose command
arpitkarnatak May 21, 2025
7c91fdf
Merge branch 'main' into feat/composite-scenaris
arpitkarnatak May 21, 2025
bb62181
Clippy fixes
arpitkarnatak May 21, 2025
4b15167
Run setup for contracts parallely
arpitkarnatak May 23, 2025
cdf64f4
Added parsing for spam commands with multiple stages, parallel execut…
arpitkarnatak May 25, 2025
34c9dd3
Added new struct ComposeFile, moved compose file parsing into separat…
arpitkarnatak May 26, 2025
e4c262d
Added separate composefile container
arpitkarnatak May 26, 2025
52ba64c
Added readme for contender compose file
arpitkarnatak May 26, 2025
2a437b2
added deleted parameters for setup return type in composefile
arpitkarnatak May 26, 2025
b40f725
Changed composefile struct properties, moved util functions in separa…
arpitkarnatak May 27, 2025
92e08ec
Removed unwrap statements in multithreaded spam calls
arpitkarnatak May 27, 2025
6f9e430
Test coverage for composefile, reducing filesizes by splitting into m…
arpitkarnatak May 28, 2025
d264c62
Add readme for writing composefiles
arpitkarnatak May 29, 2025
bfbd5ea
Pattern matching for tx types in setup and spam commands
arpitkarnatak Sep 14, 2025
7629a88
Added parameter -p to add private keys, removed private keys from com…
arpitkarnatak Sep 14, 2025
ad913cc
Added method to have engine params in composefile
arpitkarnatak Sep 14, 2025
dd613f6
Removed from method
arpitkarnatak Sep 14, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 52 additions & 2 deletions Cargo.lock

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

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
[workspace]
members = [
"crates/bundle_provider",
"crates/cli/",
"crates/cli/",
"crates/composefile/",
"crates/core/",
"crates/engine_provider",
"crates/sqlite_db/",
Expand All @@ -20,6 +21,7 @@ repository = "https://github.com/flashbots/contender"

[workspace.dependencies]
contender_core = { path = "crates/core/" }
contender_composefile = { path = "crates/composefile/" }
contender_sqlite = { path = "crates/sqlite_db/" }
contender_testfile = { path = "crates/testfile/" }
contender_bundle_provider = { path = "crates/bundle_provider/" }
Expand Down
48 changes: 48 additions & 0 deletions contender-compose.yml
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure this should be in the project root -- maybe it would fit better under scenarios/? Or we could have a new directory called composite-scenarios/ or something like that.
We should also use valid values, so that users with a simple node (e.g. anvil w/ default config) running on localhost:8545 can run the compose file without error. Any advanced examples we want to show off should go in a document under docs/.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we should also enforce a .compose.toml filename restriction, so users don't accidentally try to run core scenario files as compose files

Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
setup:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be cool if we didn't have to manually call setup. Feels like manually specifying rpc_urls for setup could get confusing in a large file (i.e. the user tries to spam on an alternate chain but forgets to run setup on that chain).

Instead, we could check if the scenario TOML file has any setup directives, then run TestScenario::estimate_setup_cost to find the required min_balance, then check the spam directives in the compose file to see which chains need to run which setup and run it automatically at the start.

simpler:
testfile: ./scenarios/simpler.toml
min_balance: 12.1
call_forkchoice: true
optimism: false
auth_rpc_url: "https://rpc.chain.com"
jwt_secret: SECRET
uniV2:
testfile: ./scenarios/uniV2.toml
rpc_url: http://localhost:8545 # Optional
min_balance: "11"
env:
- Key1=Valu1
- Key2=Valu2
tx_type: eip1559 # Optional

spam:
stages:
warmup:
- testfile: ./scenarios/simpler.toml
tps: 3
duration: 3
loop: 2
seed: "123"
- testfile: ./scenarios/simpler.toml
tps: 1
duration: 3
loop: 2
- testfile: ./scenarios/simpler.toml
tps: 4
duration: 3
loop: 2

call_forkchoice: true
optimism: false
auth_rpc_url: "https://rpc.chain.com"
jwt_secret: SECRET
medium:
- testfile: ./scenarios/uniV2.toml
tps: 10
min_balance: 20
loop: 1
duration: 2
- testfile: ./scenarios/simpler.toml
tps: 14
duration: 3
loop: 2
3 changes: 3 additions & 0 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ contender_core = { workspace = true }
contender_sqlite = { workspace = true }
contender_testfile = { workspace = true }
contender_engine_provider = { workspace = true }
contender_composefile = { workspace = true }

ansi_term = { workspace = true }
serde = { workspace = true }
Expand All @@ -42,7 +43,9 @@ serde_json = { workspace = true }
tracing = { workspace = true }
tracing-subscriber = { workspace = true }
webbrowser = { workspace = true }
yaml-rust2 = "0.10.2"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know I specified yaml when I wrote the issue but I wonder if toml would be better -- wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Toml can be nice, since we're using it for the other configurations too. For this case, I would prefer YAML solely because of the readability and syntax familiarity with Docker compose syntax.

op-alloy-network = { workspace = true }
hashlink = "0.10.0"

[dev-dependencies]
tempfile = "3.15.0"
113 changes: 113 additions & 0 deletions crates/cli/src/commands/composite.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
use std::{fmt::Debug, sync::Arc};

use contender_composefile::composefile::{ComposeFile, CompositeSpamConfiguration};
use tokio::{sync::Mutex, task};
use tracing::{error, info};

use crate::commands::{setup, spam, SetupCommandArgs, SpamCommandArgs};

#[derive(Debug, clap::Args)]
pub struct CompositeScenarioArgs {
pub filename: Option<String>,
pub private_keys: Option<Vec<String>>,
}

pub async fn composite(
db: &(impl contender_core::db::DbOps + Clone + Send + Sync + 'static),
args: CompositeScenarioArgs,
) -> Result<(), Box<dyn std::error::Error>> {
let compose_file_name = match args.filename {
Some(filepath) => filepath,
None => String::from("./contender-compose.yml"),
};

let compose_file = ComposeFile::init_from_path(compose_file_name)?;
let sharable_db = Arc::new(Mutex::new(db.clone()));
let sharable_private_keys = Arc::new(Mutex::new(args.private_keys));

let setup_scenarios = compose_file.get_setup_config()?;
let setup_tasks: Vec<_> = setup_scenarios
.into_iter()
.enumerate()
.map(|(index, scenario)| {
let db_clone = sharable_db.clone();
let scenario_config = scenario.clone();
let private_keys = sharable_private_keys.clone();
let setup_command_args = SetupCommandArgs::from_json(scenario_config.config);

task::spawn(async move {
let setup_command = setup_command_args
.await
.expect("msg")
.with_private_keys(private_keys.lock().await.clone());
match setup(&*db_clone.lock().await, setup_command).await {
Ok(_) => info!(
"Setup [{index}] - {}: completed successfully",
&scenario_config.name
),
Err(err) => error!(
"Setup [{index}] - {} failed: {err:?}",
&scenario_config.name
),
};
//setup(&*db_clone.lock().await, scenario_config.config).await.map_err(|e| Err("s".into()))
})
})
.collect();

futures::future::join_all(setup_tasks).await;

info!("================================================================================================= Done Composite run for setup =================================================================================================");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's remove the equal signs from this -- simple logs are fine


let spam_scenarios = compose_file.get_spam_config()?;
for scenario in spam_scenarios {
let CompositeSpamConfiguration {
stage_name,
spam_configs,
} = scenario;
info!("================================================================================================= Running stage: {stage_name:?} =================================================================================================");

let mut spam_tasks = Vec::new();
let sharable_stage_name_object = Arc::new(Mutex::new(stage_name.clone()));
for (spam_scenario_index, spam_command) in spam_configs.into_iter().enumerate() {
info!("Starting scenario [{spam_scenario_index:?}]");
let db_clone = sharable_db.clone();
let private_keys = sharable_private_keys.clone();
let private_keys_clone = private_keys.clone().lock().await.clone();
let task = task::spawn(async move {
let spam_call = async || -> Result<(), Box<dyn std::error::Error>> {
let spam_command_args = SpamCommandArgs::from_json(spam_command)
.await?
.with_private_keys(private_keys_clone);

let mut test_scenario = spam_command_args
.init_scenario(&*db_clone.lock().await)
.await?;
spam(
&*db_clone.lock().await,
&spam_command_args,
&mut test_scenario,
)
.await?;
Ok(())
};

match spam_call().await {
Ok(()) => {
info!("Successful: Scenario [{spam_scenario_index:?}]");
}
Err(err) => {
error!("Error occured while Scenario [{spam_scenario_index:?}]: {err:?}")
}
};
});
spam_tasks.push(task);
}

for task in spam_tasks {
task.await?;
}
info!("================================================================================================= Done Composite run for spam - Stage [{:?}] =================================================================================================", &*sharable_stage_name_object.clone().lock().await);
}
Ok(())
}
21 changes: 21 additions & 0 deletions crates/cli/src/commands/contender_subcommand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,27 @@ use super::spam::SpamCliArgs;

#[derive(Debug, Subcommand)]
pub enum ContenderSubcommand {
#[command(
name = "compose",
about = "Composite scenario execution, setup and spam multiple contracts from a single YML file."
)]
Composite {
#[arg(
short,
long,
long_help = "File path for composite scenario file",
default_value = "./contender-compose.yml"
)]
filename: Option<String>,
#[arg(
short,
long = "priv-key",
long_help = "Add private keys to wallet map. Used to fund agent accounts or sign transactions.
May be specified multiple times."
)]
private_keys: Option<Vec<String>>,
},

#[command(name = "admin", about = "Admin commands")]
Admin {
#[command(subcommand)]
Expand Down
2 changes: 2 additions & 0 deletions crates/cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub mod admin;
pub mod common;
pub mod composite;
mod contender_subcommand;
pub mod db;
mod report;
Expand All @@ -9,6 +10,7 @@ mod spamd;

use clap::Parser;

pub use composite::composite;
pub use contender_subcommand::{ContenderSubcommand, DbCommand};
pub use report::report;
pub use setup::{setup, SetupCliArgs, SetupCommandArgs};
Expand Down
Loading