pub trait Algorithm: Send + Sync {
type GraphType: Send + Sync;
type GraphManager: GraphManager<Self::GraphType> + Default;
// Required methods
fn name(&self) -> &str;
async fn find_best_route(
&self,
request: SolveRequest<'_, Self::GraphType>,
) -> Result<RouteResult, AlgorithmError>;
fn computation_requirements(&self) -> ComputationRequirements;
fn timeout(&self) -> Duration;
}Expand description
Trait for route-finding algorithms.
Algorithms are generic over their preferred graph type G, allowing them to:
- Use different graph crates (petgraph, custom, etc.)
- Leverage built-in algorithms from graph libraries
- Optimize their graph representation for their specific needs
§Implementation Notes
- Algorithms should respect the timeout from
timeout() - They should use
graphfor path finding (BFS/etc) - They should use
marketto read component states for simulation - They should NOT modify the graph or market data
Required Associated Types§
Sourcetype GraphManager: GraphManager<Self::GraphType> + Default
type GraphManager: GraphManager<Self::GraphType> + Default
The graph manager type for this algorithm. This allows the solver to automatically create the appropriate graph manager.
Required Methods§
Sourceasync fn find_best_route(
&self,
request: SolveRequest<'_, Self::GraphType>,
) -> Result<RouteResult, AlgorithmError>
async fn find_best_route( &self, request: SolveRequest<'_, Self::GraphType>, ) -> Result<RouteResult, AlgorithmError>
Finds the best route for the order the request carries.
SolveRequest holds the graph, the market, the order, the overlay to read state through,
the derived data, and what the caller excludes from a route. Read these through the getters
or move them out with SolveRequest::into_parts.
Honour SolveRequest::exclusions during search and simulation. The worker rejects
returned routes that violate the request filter.
§Returns
The best route and its gas-adjusted net output amount, or an error if no route could be found.
Sourcefn computation_requirements(&self) -> ComputationRequirements
fn computation_requirements(&self) -> ComputationRequirements
Returns the derived data computation requirements for this algorithm.
Algorithms declare freshness requirements for derived data:
require_fresh: Data must be from the current block (same as MarketState)allow_stale: Data can be from any past block, as long as it exists
Workers use this to determine when they can safely solve.
Default implementation returns no requirements - algorithm works without any derived data.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".