Skip to content

Commit

Permalink
Update gas when setting score with gas (#2542)
Browse files Browse the repository at this point in the history
# Description
When computing a score for a solution using a gas estimate we should
also update the gas estimate of the whole settlement not just the score.

## How to test
Adjusted naive solver e2e tests
  • Loading branch information
MartinquaXD authored Mar 19, 2024
1 parent 53dfd47 commit 778097c
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 11 deletions.
9 changes: 7 additions & 2 deletions crates/solvers/src/domain/solution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,21 @@ impl Solution {
Self { score, ..self }
}

/// Sets the provided gas and computes the risk adjusted score accordingly.
pub fn with_risk_adjusted_score(
self,
risk: &Risk,
gas: eth::Gas,
gas_price: auction::GasPrice,
) -> Self {
let nmb_orders = self.trades.len();
self.with_score(Score::RiskAdjusted(SuccessProbability(
let scored = self.with_score(Score::RiskAdjusted(SuccessProbability(
risk.success_probability(gas, gas_price, nmb_orders),
)))
)));
Self {
gas: Some(gas),
..scored
}
}

/// Returns `self` with eligible interactions internalized using the
Expand Down
3 changes: 2 additions & 1 deletion crates/solvers/src/tests/naive/extract_deepest_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ async fn test() {
"score": {
"kind": "riskAdjusted",
"successProbability": 0.5,
}
},
"gas": 94391,
}]
}),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ async fn sell_orders_on_both_sides() {
"score": {
"kind": "riskAdjusted",
"successProbability": 0.5,
}
},
"gas": 259417,
}]
}),
);
Expand Down
12 changes: 8 additions & 4 deletions crates/solvers/src/tests/naive/matches_orders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ async fn sell_orders_on_both_sides() {
"score": {
"kind": "riskAdjusted",
"successProbability": 0.5,
}
},
"gas": 259417,
}]
}),
);
Expand Down Expand Up @@ -213,7 +214,8 @@ async fn sell_orders_on_one_side() {
"score": {
"kind": "riskAdjusted",
"successProbability": 0.5,
}
},
"gas": 259417,
}]
}),
);
Expand Down Expand Up @@ -321,7 +323,8 @@ async fn buy_orders_on_both_sides() {
"score": {
"kind": "riskAdjusted",
"successProbability": 0.5,
}
},
"gas": 259417,
}]
}),
);
Expand Down Expand Up @@ -429,7 +432,8 @@ async fn buy_and_sell_orders() {
"score": {
"kind": "riskAdjusted",
"successProbability": 0.5,
}
},
"gas": 259417,
}]
}),
);
Expand Down
3 changes: 2 additions & 1 deletion crates/solvers/src/tests/naive/reserves_too_small.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ async fn test() {
"score": {
"kind": "riskAdjusted",
"successProbability": 0.5,
}
},
"gas": 204391,
}]
}),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ async fn test() {
"score": {
"kind": "riskAdjusted",
"successProbability": 0.5,
}
},
"gas": 259417,
}]
}),
);
Expand Down
3 changes: 2 additions & 1 deletion crates/solvers/src/tests/naive/without_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ async fn test() {
"score": {
"kind": "riskAdjusted",
"successProbability": 0.5,
}
},
"gas": 259417,
}]
}),
);
Expand Down

0 comments on commit 778097c

Please sign in to comment.