Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
5c1b874
PR08: seam implementations and a single auction cycle
squadgazzz Aug 19, 2026
760fcae
PR09: settlement observation over execution windows
squadgazzz Aug 19, 2026
875dacf
PR10: binary wiring, liveness, and the metrics server
squadgazzz Aug 19, 2026
c71fa72
Reject zero competition parameters at config load and panic when a su…
squadgazzz Aug 19, 2026
1e84f50
Use the shared database pool config in the autopilot
squadgazzz Aug 19, 2026
dc194bc
Make the solve budget a wall-clock duration like the EVM autopilot
squadgazzz Aug 20, 2026
25db78c
Merge branch 'ilya/be-184-pr08-seam-implementations-single-auction-cy…
squadgazzz Aug 20, 2026
c413b06
Configure the solve deadline as a duration
squadgazzz Aug 20, 2026
6e3eb7b
Carry a wall-clock solve deadline and a settle submission deadline sl…
squadgazzz Aug 20, 2026
8520615
Merge branch 'ilya/be-184-pr08-seam-implementations-single-auction-cy…
squadgazzz Aug 20, 2026
7509fc2
Merge branch 'ilya/be-185-pr09-settlement-observation' into ilya/be-1…
squadgazzz Aug 20, 2026
fcb2ddd
Drop the auction tip field, the wall-clock deadline removed its last …
squadgazzz Aug 20, 2026
29a1041
Merge branch 'ilya/be-184-pr08-seam-implementations-single-auction-cy…
squadgazzz Aug 20, 2026
e30f76f
Merge branch 'ilya/be-185-pr09-settlement-observation' into ilya/be-1…
squadgazzz Aug 20, 2026
cb6dff6
Keep top-level config keys above the database section in the example
squadgazzz Aug 20, 2026
ccde2a0
Merge remote-tracking branch 'origin/main' into ilya/be-185-pr09-sett…
squadgazzz Aug 20, 2026
021a443
Merge branch 'ilya/be-185-pr09-settlement-observation' into ilya/be-1…
squadgazzz Aug 20, 2026
d8c06b6
Name the window operations after what they do
squadgazzz Aug 20, 2026
9b79c2b
Merge branch 'ilya/be-185-pr09-settlement-observation' into ilya/be-1…
squadgazzz Aug 20, 2026
1006c69
Merge remote-tracking branch 'origin/main' into ilya/be-185-pr09-sett…
squadgazzz Aug 21, 2026
81cc46e
Merge branch 'ilya/be-185-pr09-settlement-observation' into ilya/be-1…
squadgazzz Aug 21, 2026
64a5999
Trim the Competition doc to essence
squadgazzz Aug 24, 2026
9b8ebef
Write the settlement outcomes as literals
squadgazzz Aug 24, 2026
5348b84
Merge branch 'ilya/be-185-pr09-settlement-observation' into ilya/be-1…
squadgazzz Aug 24, 2026
bc786bd
State the settlement attribution constraint
squadgazzz Aug 24, 2026
65112e0
Merge branch 'ilya/be-185-pr09-settlement-observation' into ilya/be-1…
squadgazzz Aug 24, 2026
6df9bcd
Move the settlement window queries into the db layer
squadgazzz Aug 24, 2026
4e6b299
Merge branch 'ilya/be-185-pr09-settlement-observation' into ilya/be-1…
squadgazzz Aug 24, 2026
ff84a22
Drop the settlement read the single-query close replaced
squadgazzz Aug 24, 2026
ff9b940
Merge branch 'ilya/be-185-pr09-settlement-observation' into ilya/be-1…
squadgazzz Aug 24, 2026
b7d40da
Fold the settlement window types into one
squadgazzz Aug 24, 2026
cf362a0
Connect the crate's tests through one helper
squadgazzz Aug 24, 2026
6330161
Merge branch 'ilya/be-185-pr09-settlement-observation' into ilya/be-1…
squadgazzz Aug 24, 2026
a115d96
Own the cycle loop and the submission deadline in the run loop
squadgazzz Aug 25, 2026
31614ec
Configure the metrics port and group the on-chain addresses
squadgazzz Aug 25, 2026
4d44bf5
Merge remote-tracking branch 'origin/main' into ilya/be-185-pr09-sett…
squadgazzz Aug 25, 2026
b9c8eee
Merge branch 'ilya/be-185-pr09-settlement-observation' into ilya/be-1…
squadgazzz Aug 25, 2026
5661bba
Merge remote-tracking branch 'origin/main' into ilya/be-186-pr10-wiri…
squadgazzz Aug 25, 2026
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
8 changes: 8 additions & 0 deletions Cargo.lock

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

18 changes: 17 additions & 1 deletion crates/autopilot-svm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,45 @@ version = "0.1.0"
edition = "2024"
description = "Solana autopilot: the chain-generic auction loop and its seam traits"

[lib]
name = "autopilot_svm"
path = "src/lib.rs"

[[bin]]
name = "autopilot-svm"
path = "src/main.rs"

[dependencies]
anyhow = { workspace = true }
async-trait = { workspace = true }
axum = { workspace = true }
bigdecimal = { workspace = true }
chain-types = { workspace = true }
chrono = { workspace = true, features = ["serde"] }
clap = { workspace = true }
configs = { workspace = true }
const-hex = { workspace = true }
cow-solana-rpc = { workspace = true }
database = { workspace = true }
futures = { workspace = true }
humantime-serde = { workspace = true }
observe = { workspace = true }
reqwest = { workspace = true, features = ["json"] }
serde = { workspace = true }
serde-ext = { workspace = true }
serde_json = { workspace = true }
serde_with = { workspace = true }
solana-sdk = { workspace = true }
sqlx = { workspace = true }
thiserror = { workspace = true }
tikv-jemallocator = { workspace = true }
tokio = { workspace = true, features = ["macros", "rt-multi-thread", "time"] }
toml = { workspace = true }
tracing = { workspace = true }
url = { workspace = true }
winner-selection = { workspace = true }

[dev-dependencies]
axum = { workspace = true }

[lints]
workspace = true
32 changes: 32 additions & 0 deletions crates/autopilot-svm/example.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Example configuration for the Solana autopilot.

# Serves /metrics, /liveness, /ready, and /startup.
metrics-port = 9586
# The pod fails the liveness probe when no auction cycle completed in this
# time.
max-auction-age = "5m"

[database]
# The Postgres database the indexer writes to. A value like "%DB_WRITE_URL"
# reads the URL from that environment variable.
write-url = "postgresql://"

[rpc]
# The devnet node.
endpoint = "https://api.devnet.solana.com"
request-timeout = "10s"

[contracts]
wrapped-native-mint = "So11111111111111111111111111111111111111112"

[competition]
max-winners = 1
solve-deadline = "6s"
submission-deadline-slots = 25

[[drivers]]
name = "baseline"
url = "http://localhost:11088"

[logging]
filter = "info,autopilot_svm=debug"
4 changes: 4 additions & 0 deletions crates/autopilot-svm/src/domain/cycle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ impl Cycle for SolanaCycle {
type Solution = Solution;
/// The chain progress marker is the slot.
type Tip = u64;

fn submission_deadline(tip: &u64, allowance: u64) -> u64 {
tip + allowance
}
}

/// One driver's solution, attributed to the driver that proposed it so the
Expand Down
161 changes: 161 additions & 0 deletions crates/autopilot-svm/src/infra/config.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
//! Configuration of the autopilot's endpoints and competition parameters.

use {
configs::{database::DatabasePoolConfig, shared::LoggingConfig},
serde::Deserialize,
serde_ext::{deserialize_nonempty_vec, deserialize_solana_pubkey_b58},
solana_sdk::pubkey::Pubkey,
std::{num::NonZero, path::Path, time::Duration},
tokio::fs,
};

/// Load the autopilot configuration from a TOML file.
///
/// # Panics
///
/// This function panics if the config is invalid or on I/O errors.
pub async fn load(path: &Path) -> Config {
let data = fs::read_to_string(path)
.await
.unwrap_or_else(|e| panic!("I/O error while reading {path:?}: {e:?}"));

toml::de::from_str(&data).unwrap_or_else(|err| {
if std::env::var("TOML_TRACE_ERROR").is_ok_and(|v| v == "1") {
panic!("failed to parse TOML config at {path:?}: {err:#?}")
} else {
panic!(
"failed to parse TOML config at: {path:?}. Set TOML_TRACE_ERROR=1 to print \
parsing error but this may leak secrets."
)
}
})
}

/// Configuration of the autopilot's endpoints and competition parameters.
#[derive(Debug, Deserialize)]
#[serde(rename_all = "kebab-case", deny_unknown_fields)]
pub struct Config {
/// Connection configuration for the database the indexer writes to.
#[serde(default)]
pub database: DatabasePoolConfig,
/// JSON-RPC client configuration.
pub rpc: Rpc,
/// On-chain addresses the autopilot reads.
pub contracts: Contracts,
/// Competition parameters.
#[serde(default)]
pub competition: Competition,
/// Port the metrics and probes server binds to, on every interface.
#[serde(default = "default_metrics_port")]
pub metrics_port: u16,
/// If no auction cycle completed in this time the pod fails the liveness
/// check.
#[serde(with = "humantime_serde", default = "default_max_auction_age")]
pub max_auction_age: Duration,
/// The driver endpoints participating in every auction.
#[serde(deserialize_with = "deserialize_nonempty_vec")]
pub drivers: Vec<Driver>,
/// Logging configuration.
#[serde(default)]
pub logging: LoggingConfig,
}

impl Config {
/// Build the `observe::Config` for the tracing framework from the logging
/// configuration.
pub fn observe_config(&self) -> observe::Config {
observe::Config::new(
&self.logging.filter,
self.logging.stderr_threshold,
self.logging.use_json,
None,
)
}
}

const fn default_metrics_port() -> u16 {
observe::metrics::DEFAULT_METRICS_PORT
}

const fn default_max_auction_age() -> Duration {
Duration::from_mins(5)
}

/// JSON-RPC client configuration.
#[derive(Debug, Deserialize)]
#[serde(rename_all = "kebab-case", deny_unknown_fields)]
pub struct Rpc {
/// HTTP endpoint of the Solana JSON-RPC node.
pub endpoint: url::Url,
/// Timeout for a single RPC request.
#[serde(with = "humantime_serde")]
pub request_timeout: Duration,
}

/// On-chain addresses: programs and mints.
#[derive(Debug, Deserialize)]
#[serde(rename_all = "kebab-case", deny_unknown_fields)]
pub struct Contracts {
/// The wrapped native token mint (wSOL), the unit scores are denominated
/// in.
#[serde(deserialize_with = "deserialize_solana_pubkey_b58")]
pub wrapped_native_mint: Pubkey,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sounds like this could be a Contracts sub struct.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Probably makes sense, since EVM's Contracts already mixes both kinds (it holds weth next to the settlement contract), so the mint should be appropriate here too.

}

/// Competition parameters.
#[derive(Debug, Deserialize)]
#[serde(rename_all = "kebab-case", deny_unknown_fields, default)]
pub struct Competition {
/// Maximum number of winning solutions per auction.
pub max_winners: NonZero<usize>,
/// How long drivers get to answer `/solve`.
#[serde(with = "humantime_serde")]
pub solve_deadline: Duration,
/// Slots a settlement may take after ranking before it counts as late.
pub submission_deadline_slots: NonZero<u64>,
}

impl Default for Competition {
fn default() -> Self {
Self {
max_winners: NonZero::new(1).expect("non-zero literal"),
// The EVM fast chains run 6s solve deadlines.
solve_deadline: Duration::from_secs(6),
submission_deadline_slots: NonZero::new(25).expect("non-zero literal"),
}
}
}

/// One driver endpoint.
#[derive(Debug, Deserialize)]
#[serde(rename_all = "kebab-case", deny_unknown_fields)]
pub struct Driver {
/// Name for logs and metrics.
pub name: String,
/// HTTP endpoint of the driver API.
pub url: url::Url,
}

#[cfg(test)]
mod tests {
use super::*;

#[tokio::test]
async fn loads_the_example_config() {
let config = load(std::path::Path::new("example.toml")).await;
assert_eq!(config.database.write_url.as_str(), "postgresql://");
assert_eq!(
config.contracts.wrapped_native_mint,
"So11111111111111111111111111111111111111112"
.parse()
.unwrap()
);
assert_eq!(config.competition.max_winners.get(), 1);
assert_eq!(config.competition.solve_deadline, Duration::from_secs(6));
assert_eq!(config.competition.submission_deadline_slots.get(), 25);
assert_eq!(config.max_auction_age, Duration::from_secs(5 * 60));
assert_eq!(config.drivers.len(), 1);
assert_eq!(config.drivers[0].name, "baseline");
assert_eq!(config.logging.filter, "info,autopilot_svm=debug");
}
}
3 changes: 3 additions & 0 deletions crates/autopilot-svm/src/infra/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ use {
sqlx::PgExecutor,
};

/// The channel the schema's `solana.settlements` trigger notifies.
pub const SETTLEMENT_FINALIZED_CHANNEL: &str = "solana_settlement_finalized";

/// The `solana.orders` columns auction assembly reads.
#[derive(Clone, Debug, sqlx::FromRow)]
pub struct OrderRow {
Expand Down
18 changes: 2 additions & 16 deletions crates/autopilot-svm/src/infra/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ use {
std::sync::Arc,
};

/// Slots a settlement may take after ranking before it counts as late.
/// TODO: make configurable.
const SUBMISSION_DEADLINE_SLOTS: u64 = 25;

/// Sends `/settle` to each winner's driver. Submission runs detached, the
/// loop starts the next cycle while settlements land.
pub struct DriverExecutor {
Expand All @@ -34,11 +30,7 @@ impl DriverExecutor {

#[async_trait]
impl SettlementExecutor<SolanaCycle> for DriverExecutor {
fn submission_deadline(&self, tip: &u64) -> u64 {
tip + SUBMISSION_DEADLINE_SLOTS
}

async fn execute(&self, auction_id: i64, ranking: &Ranking, deadline: u64) {
async fn execute(&self, auction_id: i64, ranking: &Ranking, tip: &u64, deadline: u64) {
for winner in ranking.inner.winners() {
let key = (winner.solver(), winner.id());
let Some(driver) = ranking
Expand All @@ -59,13 +51,7 @@ impl SettlementExecutor<SolanaCycle> for DriverExecutor {
// the dispatch is the priority.
if let Err(err) = self
.windows
.open_dispatched(
auction_id,
winner.solver(),
winner.id(),
deadline.saturating_sub(SUBMISSION_DEADLINE_SLOTS),
deadline,
)
.open_dispatched(auction_id, winner.solver(), winner.id(), *tip, deadline)
.await
{
tracing::error!(auction_id, ?err, "failed to open the settlement window");
Expand Down
1 change: 1 addition & 0 deletions crates/autopilot-svm/src/infra/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Infrastructure: database access, driver clients, and the loop seams.

pub mod competition;
pub mod config;
pub mod db;
pub mod driver;
pub mod executor;
Expand Down
9 changes: 6 additions & 3 deletions crates/autopilot-svm/src/infra/observation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ impl NotifyHandler for SettlementWindows {
mod tests {
use {
super::SettlementWindows,
crate::infra::listen::ListenSession,
crate::infra::{db, listen::ListenSession},
chain_types::solana::Pubkey,
sqlx::PgPool,
std::time::Duration,
Expand Down Expand Up @@ -160,8 +160,11 @@ VALUES (10, $1, 0, $2, $3, NULL)
.await
.unwrap();

let task =
ListenSession::spawn(pool.clone(), "solana_settlement_finalized", windows.clone());
let task = ListenSession::spawn(
pool.clone(),
db::SETTLEMENT_FINALIZED_CHANNEL,
windows.clone(),
);

insert_settlement(&pool, 4242).await;

Expand Down
3 changes: 1 addition & 2 deletions crates/autopilot-svm/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! Solana-side autopilot components built on a chain-generic auction loop.

#![expect(dead_code, reason = "consumed by the binary wiring")]

pub mod run;
pub mod run_loop;

mod domain;
Expand Down
7 changes: 7 additions & 0 deletions crates/autopilot-svm/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#[global_allocator]
static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;

#[tokio::main]
async fn main() {
autopilot_svm::run::start(std::env::args()).await;
}
Loading
Loading