Skip to content

Commit

Permalink
less fails
Browse files Browse the repository at this point in the history
  • Loading branch information
dzmitry-lahoda committed Apr 19, 2024
1 parent 1028cb7 commit 60fddf6
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 17 deletions.
4 changes: 2 additions & 2 deletions mantis/node/src/bin/mantis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ async fn get_data_and_solve(
rpc: &CosmosChainInfo,
tip: &Tip,
gas: Gas,
all_orders: Vec<OrderItem>,
all_active_orders: Vec<OrderItem>,
router_api: &String,
) {
log::info!(target: "mantis::solver", "Solving orders");
Expand All @@ -198,7 +198,7 @@ async fn get_data_and_solve(
};

let msgs = mantis_node::mantis::blackbox::solve::<CoinToss>(
all_orders,
all_active_orders,
signing_key,
tip,
cvm_glt,
Expand Down
28 changes: 16 additions & 12 deletions mantis/node/src/mantis/blackbox/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,30 +139,30 @@ fn build_instructions(
}
NextItem::SpawnStrStr(spawn) => {
if let Some(next) = spawn.next.get(0) {
let mut next = build_instructions(final_instructions, next, cvm_glt, salt);
let mut next = build_instructions(final_instructions, next, cvm_glt, salt);
let program = CvmProgram {
tag: salt.to_vec(),
instructions: next,
};
let to_asset_id = spawn.out_asset_id.parse().expect("out");
let spawn = CvmInstruction::Spawn {
network_id: cvm_glt.get_network_for_asset(to_asset_id),
salt: salt.to_vec(),
assets: CvmFundsFilter::all_of(spawn.in_asset_id.parse().expect("in")),
program,
let spawn = CvmInstruction::Spawn {
network_id: cvm_glt.get_network_for_asset(to_asset_id),
salt: salt.to_vec(),
assets: CvmFundsFilter::all_of(spawn.in_asset_id.parse().expect("in")),
program,
};
vec![spawn]
vec![spawn]
} else {
let program = CvmProgram {
tag: salt.to_vec(),
instructions: final_instructions,
};
let to_asset_id = spawn.out_asset_id.parse().expect("out");
let spawn = CvmInstruction::Spawn {
network_id: cvm_glt.get_network_for_asset(to_asset_id),
salt: salt.to_vec(),
assets: CvmFundsFilter::all_of(spawn.in_asset_id.parse().expect("in")),
program,
let spawn = CvmInstruction::Spawn {
network_id: cvm_glt.get_network_for_asset(to_asset_id),
salt: salt.to_vec(),
assets: CvmFundsFilter::all_of(spawn.in_asset_id.parse().expect("in")),
program,
};
vec![spawn]
}
Expand All @@ -179,6 +179,10 @@ pub async fn solve<Decider: Get<bool>>(
) -> Vec<cw_mantis_order::ExecMsg> {
let cows_per_pair = find_cows(&active_orders);
let mut msgs = vec![];

// this we do just to avoid one pair to fail all others, really need to handle all errors gracefully or run solver(thread/process) per pair (i am for second)
let cows_per_pair = cows_per_pair.into_iter().take(1).collect::<Vec<_>>();

for pair_solution in cows_per_pair {
let salt = super::cosmos::cvm::calculate_salt(signing_key, tip, pair_solution.ab.clone());
let cvm_program = if let Some(ref cvm_glt) = cvm_glt {
Expand Down
9 changes: 6 additions & 3 deletions mantis/node/src/mantis/solve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ pub fn find_cows(all_orders: &[OrderItem]) -> Vec<PairSolution> {
value: orders.collect(),
};
let optimal_price = orders.compute_optimal_price(1000);
println!("mantis::solver::cows::optimal_price: {:?}", optimal_price);
println!("mantis::solver::cows::orders: {:?}", orders);
log::info!("mantis::solver::cows::optimal_price: {:?}", optimal_price);
log::info!("mantis::solver::cows::orders: {:?}", orders);
let mut solution = Solution::new(orders.value.clone());
solution = solution.match_orders(optimal_price);
let cows = solution
Expand All @@ -158,7 +158,7 @@ pub fn find_cows(all_orders: &[OrderItem]) -> Vec<PairSolution> {
})
.collect::<Vec<_>>();
let optimal_price = decimal_to_fraction(optimal_price.0);
println!("cows: {:?}", cows);
log::info!("cows: {:?}", cows);
if !cows.is_empty() {
let pair_solution = PairSolution {
ab,
Expand All @@ -168,6 +168,9 @@ pub fn find_cows(all_orders: &[OrderItem]) -> Vec<PairSolution> {
cows_per_pair.push(pair_solution);
}
}
use rand::prelude::SliceRandom;
cows_per_pair.shuffle(&mut rand::thread_rng());

cows_per_pair
}

Expand Down

0 comments on commit 60fddf6

Please sign in to comment.