Skip to content

Commit

Permalink
doing split of progrsam into 2 spawns
Browse files Browse the repository at this point in the history
  • Loading branch information
dzmitry-lahoda committed Apr 8, 2024
1 parent 233e2df commit e2e5147
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 20 deletions.
8 changes: 5 additions & 3 deletions mantis/node/src/bin/mantis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,12 @@ async fn solve(
&cvm_glt,
pair_solution.ab.clone(),
);
let cvm_route = blackbox::get_route(router_api, a, b, &cvm_glt, salt.as_ref()).await;
let a_cvm_route = blackbox::get_route(router_api, a, &cvm_glt, salt.as_ref()).await;
let b_cvm_route = blackbox::get_route(router_api, b, &cvm_glt, salt.as_ref()).await;
let program = CvmProgram::ins
send_solution(
pair_solution.cows,
cvm_route,
vec![a_cvm_route, b_cvm_route],
tip,
pair_solution.optimal_price,
signing_key,
Expand All @@ -219,7 +221,7 @@ async fn solve(

async fn send_solution(
cows: Vec<OrderSolution>,
_cvm: CvmProgram,
cvm: Vec<CvmProgram>,
tip: &Tip,
optimal_price: Ratio,
signing_key: &cosmrs::crypto::secp256k1::SigningKey,
Expand Down
19 changes: 8 additions & 11 deletions mantis/node/src/mantis/blackbox/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,28 +103,25 @@ fn new_exchange(exchange: &Exchange) -> CvmInstruction {
}
}

/// `order_accounts` - account of order where to dispatch amounts (part of whole)
pub async fn get_route(
route_provider: &str,
a: IntentBankInput,
b: IntentBankInput,
input: IntentBankInput,
cvm_glt: &GetConfigResponse,
salt: &[u8],
) -> CvmProgram {
if route_provider == "priceless" {
panic!()
//bf::route(input, cvm_glt, salt);
) -> CvmInstruction {
if route_provider == "priceless" {
return bf::route(cvm_glt, input, salt);
} else {
let blackbox: Client = Client::new(route_provider);
let mut route = blackbox
.simulator_router_simulator_router_get(
&InAssetAmount::Variant0(
a.in_asset_amount.0.try_into().expect("in_asset_amount"),
input.in_asset_amount.0.try_into().expect("in_asset_amount"),
),
&InAssetId::Variant1(a.in_asset_id.to_string()),
&InAssetId::Variant1(input.in_asset_id.to_string()),
true,
&OutAssetAmount::Variant0(10),
&OutAssetId::Variant1(a.out_asset_id.to_string().into()),
&OutAssetId::Variant1(input.out_asset_id.to_string().into()),
)
.await
.expect("route found")
Expand All @@ -134,6 +131,6 @@ pub async fn get_route(

let mut program = CvmProgram::default();
build_next(&mut program, &mut route.next, cvm_glt, salt);
return program;
panic!("so need to build instruction so can plug into one program (transaciton)")
}
}
25 changes: 19 additions & 6 deletions mantis/node/src/solver/router/bf.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use std::collections::BTreeMap;

use blackbox_rs::types::SingleInputAssetCvmRoute;
use cvm_route::venue::VenueId;
use cvm_runtime::proto::pb::program::{Exchange, Transfer};
use cvm_runtime::shared::CvmProgram;
use cvm_runtime::shared::{CvmInstruction, CvmProgram};
use cvm_runtime::{exchange, AssetId, ExchangeId};
use petgraph::algo::{bellman_ford, min_spanning_tree};
use petgraph::data::FromElements;
Expand Down Expand Up @@ -31,25 +33,29 @@ pub fn get_all_asset_maps(cvm_glt: &cvm_runtime::outpost::GetConfigResponse) ->
pub fn route(
cvm_glt: &cvm_runtime::outpost::GetConfigResponse,
input: crate::mantis::solve::IntentBankInput,
) -> CvmProgram {
salt: &[u8],
) -> CvmInstruction {
let mut graph = petgraph::graph::DiGraph::new();
let mut assets_global_to_local = std::collections::BTreeMap::new();
for asset_id in cvm_glt.get_all_asset_ids() {
let node = graph.add_node(1);
assets_global_to_local.insert(asset_id, node);
}

let mut venue_local_to_global = BTreeMap::new();
for venue in get_all_asset_maps(cvm_glt) {
match venue {
Venue::Transfer(from, to) => {
let from_node = assets_global_to_local.get(&from).unwrap();
let to_node = assets_global_to_local.get(&to).unwrap();
graph.add_edge(*from_node, *to_node, 1.0);
let local_venue = graph.add_edge(*from_node, *to_node, 1.0);
venue_local_to_global.insert(local_venue, venue.clone());
}
Venue::Exchange(exchange_id, from, to) => {
let from_node = assets_global_to_local.get(&from).unwrap();
let to_node = assets_global_to_local.get(&to).unwrap();
graph.add_edge(*from_node, *to_node, 1.0);
let local_venue = graph.add_edge(*from_node, *to_node, 1.0);
venue_local_to_global.insert(local_venue, venue.clone());
}
}
}
Expand All @@ -58,7 +64,14 @@ pub fn route(
let routes =
bellman_ford::bellman_ford(&graph, *in_node_index)
.expect("bf");
let out_node_index = assets_global_to_local.get(&input.out_asset_id).unwrap();
let path = routes.predecessors[out_node_index.index()];
let out_node_index = assets_global_to_local.get(&input.out_asset_id).expect("node");


let mut out_node_index = out_node_index.index();
let mut in_node_index = routes.predecessors[out_node_index].expect("routable");
while true {

}

panic!()
}

0 comments on commit e2e5147

Please sign in to comment.