Skip to content

Commit

Permalink
Merge branch 'main' into mkl-neo-swaps
Browse files Browse the repository at this point in the history
  • Loading branch information
maltekliemann authored Oct 11, 2023
2 parents 65d2168 + fdda998 commit 7211f85
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 22 deletions.
43 changes: 27 additions & 16 deletions zrml/prediction-markets/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -619,23 +619,34 @@ impl<T: frame_system::Config> WeightInfoZeitgeist for WeightInfo<T> {
/// Storage: Tokens TotalIssuance (r:2 w:2)
/// Proof: Tokens TotalIssuance (max_values: None, max_size: Some(43), added: 2518, mode: MaxEncodedLen)
fn redeem_shares_scalar() -> Weight {
Weight::from_ref_time(149_531_000)
.saturating_add(T::DbWeight::get().reads(6))
.saturating_add(T::DbWeight::get().writes(5))
// Proof Size summary in bytes:
// Measured: `1171`
// Estimated: `15855`
// Minimum execution time: 117_211 nanoseconds.
Weight::from_parts(133_970_000, 15855)
.saturating_add(T::DbWeight::get().reads(6_u64))
.saturating_add(T::DbWeight::get().writes(5_u64))
}
// Storage: MarketCommons Markets (r:1 w:1)
// Storage: PredictionMarkets MarketIdsPerOpenTimeFrame (r:1 w:1)
// Storage: PredictionMarkets MarketIdsPerCloseTimeFrame (r:1 w:1)
// Storage: Balances Reserves (r:1 w:1)
// Storage: PredictionMarkets MarketIdsForEdit (r:0 w:1)
fn reject_market(c: u32, o: u32, _r: u32) -> Weight {
Weight::from_ref_time(146_031_046)
// Standard Error: 4_161
.saturating_add(Weight::from_ref_time(27_268).saturating_mul(c.into()))
// Standard Error: 4_161
.saturating_add(Weight::from_ref_time(2_604).saturating_mul(o.into()))
.saturating_add(T::DbWeight::get().reads(4))
.saturating_add(T::DbWeight::get().writes(5))
/// Storage: MarketCommons Markets (r:1 w:1)
/// Proof: MarketCommons Markets (max_values: None, max_size: Some(541), added: 3016, mode: MaxEncodedLen)
/// Storage: PredictionMarkets MarketIdsPerOpenTimeFrame (r:1 w:1)
/// Proof: PredictionMarkets MarketIdsPerOpenTimeFrame (max_values: None, max_size: Some(1050), added: 3525, mode: MaxEncodedLen)
/// Storage: PredictionMarkets MarketIdsPerCloseTimeFrame (r:1 w:1)
/// Proof: PredictionMarkets MarketIdsPerCloseTimeFrame (max_values: None, max_size: Some(1050), added: 3525, mode: MaxEncodedLen)
/// Storage: Balances Reserves (r:1 w:1)
/// Proof: Balances Reserves (max_values: None, max_size: Some(1249), added: 3724, mode: MaxEncodedLen)
/// Storage: PredictionMarkets MarketIdsForEdit (r:0 w:1)
/// Proof: PredictionMarkets MarketIdsForEdit (max_values: None, max_size: Some(1050), added: 3525, mode: MaxEncodedLen)
fn reject_market(_c: u32, _o: u32, r: u32) -> Weight {
// Proof Size summary in bytes:
// Measured: `719 + c * (16 ±0) + o * (16 ±0)`
// Estimated: `13790`
// Minimum execution time: 94_260 nanoseconds.
Weight::from_parts(106_089_785, 13790)
// Standard Error: 266
.saturating_add(Weight::from_ref_time(1_689).saturating_mul(r.into()))
.saturating_add(T::DbWeight::get().reads(4_u64))
.saturating_add(T::DbWeight::get().writes(5_u64))
}
// Storage: MarketCommons Markets (r:1 w:1)
// Storage: Timestamp Now (r:1 w:0)
Expand Down
26 changes: 20 additions & 6 deletions zrml/swaps/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ mod pallet {
pub(crate) const ARBITRAGE_MAX_ITERATIONS: usize = 30;
const ARBITRAGE_THRESHOLD: u128 = CENT;
const MIN_BALANCE: u128 = CENT;
const ON_IDLE_MIN_WEIGHT: Weight = Weight::from_ref_time(1_000_000);
const ON_IDLE_MIN_WEIGHT: Weight = Weight::from_parts(1_000_000, 100_000);

#[pallet::call]
impl<T: Config> Pallet<T> {
Expand Down Expand Up @@ -1271,19 +1271,33 @@ mod pallet {
// The division can fail if the benchmark of `apply_to_cached_pools` is not linear in
// the number of pools. This shouldn't ever happen, but if it does, we ensure that
// `pool_count` is zero (this isn't really a runtime error).
let pool_count = weight
let weight_minus_overhead = weight.saturating_sub(overhead);
let max_pool_count_by_ref_time = weight_minus_overhead
.ref_time()
.saturating_sub(overhead.ref_time())
.checked_div(extra_weight_per_pool.ref_time())
.unwrap_or_else(|| {
log::warn!("Unexpected zero division when calculating arbitrage weight");
debug_assert!(
false,
"Unexpected zero division when calculating arbitrage ref time"
);
0_u64
});
let max_pool_count_by_proof_size = weight_minus_overhead
.proof_size()
.checked_div(extra_weight_per_pool.proof_size())
.unwrap_or_else(|| {
debug_assert!(
false,
"Unexpected zero division when calculating arbitrage proof size"
);
0_u64
});
if pool_count == 0_u64 {
let max_pool_count = max_pool_count_by_ref_time.min(max_pool_count_by_proof_size);
if max_pool_count == 0_u64 {
return weight;
}
Self::apply_to_cached_pools(
pool_count.saturated_into(),
max_pool_count.saturated_into(),
|pool_id| Self::execute_arbitrage(pool_id, ARBITRAGE_MAX_ITERATIONS),
extra_weight_per_pool,
)
Expand Down

0 comments on commit 7211f85

Please sign in to comment.