From bb44cad83478672fb0ddcc587471deaca346f7e4 Mon Sep 17 00:00:00 2001 From: Caio Date: Tue, 10 Aug 2021 10:17:07 -0300 Subject: [PATCH 1/3] Sixth iteration of the Court pallet --- primitives/src/lib.rs | 1 - primitives/src/resolution_counters.rs | 7 - primitives/src/traits/dispute_api.rs | 20 +- primitives/src/types.rs | 2 +- runtime/src/lib.rs | 2 +- zrml/court/src/lib.rs | 30 +- zrml/court/src/tests.rs | 2 +- .../fuzz/pm_full_workflow.rs | 2 - zrml/prediction-markets/src/benchmarks.rs | 19 +- zrml/prediction-markets/src/lib.rs | 283 ++++++++++++---- zrml/prediction-markets/src/migrations.rs | 18 +- zrml/prediction-markets/src/mock.rs | 2 +- zrml/prediction-markets/src/tests.rs | 13 +- zrml/simple-disputes/src/lib.rs | 316 ++---------------- .../src/simple_disputes_pallet_api.rs | 57 ---- zrml/swaps/src/lib.rs | 2 +- 16 files changed, 297 insertions(+), 479 deletions(-) delete mode 100644 primitives/src/resolution_counters.rs delete mode 100644 zrml/simple-disputes/src/simple_disputes_pallet_api.rs diff --git a/primitives/src/lib.rs b/primitives/src/lib.rs index de3c3e51e..2aac7a6ce 100644 --- a/primitives/src/lib.rs +++ b/primitives/src/lib.rs @@ -8,7 +8,6 @@ mod market; mod outcome_report; mod pool; mod pool_status; -mod resolution_counters; mod serde_wrapper; pub mod traits; pub mod types; diff --git a/primitives/src/resolution_counters.rs b/primitives/src/resolution_counters.rs deleted file mode 100644 index cce219249..000000000 --- a/primitives/src/resolution_counters.rs +++ /dev/null @@ -1,7 +0,0 @@ -#[derive(Debug, Default)] -pub struct ResolutionCounters { - pub total_accounts: u32, - pub total_asset_accounts: u32, - pub total_categories: u32, - pub total_disputes: u32, -} diff --git a/primitives/src/traits/dispute_api.rs b/primitives/src/traits/dispute_api.rs index 2cd58fdb4..bd0911685 100644 --- a/primitives/src/traits/dispute_api.rs +++ b/primitives/src/traits/dispute_api.rs @@ -1,5 +1,6 @@ -use crate::{market::MarketDispute, types::Market}; +use crate::{market::MarketDispute, outcome_report::OutcomeReport, types::Market}; use frame_support::dispatch::DispatchResult; +use sp_runtime::DispatchError; /// Dispute Api pub trait DisputeApi { @@ -10,17 +11,18 @@ pub trait DisputeApi { type Origin; /// Disputes a reported outcome. - fn on_dispute( - dispute_bond: D, + fn on_dispute( disputes: &[MarketDispute], market_id: Self::MarketId, - who: Self::AccountId, - ) -> DispatchResult - where - D: Fn(usize) -> Self::Balance; + ) -> DispatchResult; /// Manages markets resolutions moving all reported markets to resolved. - fn on_resolution(now: Self::BlockNumber, cb: F) -> DispatchResult + fn on_resolution( + dispute_bound: &D, + disputes: &[MarketDispute], + market_id: &Self::MarketId, + market: &Market, + ) -> Result where - F: FnMut(&Self::MarketId, &Market) -> DispatchResult; + D: Fn(usize) -> Self::Balance; } diff --git a/primitives/src/types.rs b/primitives/src/types.rs index 606836a11..839c0f94d 100644 --- a/primitives/src/types.rs +++ b/primitives/src/types.rs @@ -1,6 +1,6 @@ pub use crate::{ asset::*, market::*, outcome_report::OutcomeReport, pool::Pool, pool_status::PoolStatus, - resolution_counters::ResolutionCounters, serde_wrapper::*, + serde_wrapper::*, }; #[cfg(feature = "arbitrary")] use arbitrary::{Arbitrary, Result, Unstructured}; diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index b043928ac..c31e6282f 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -449,6 +449,7 @@ impl zrml_prediction_markets::Config for Runtime { type ApprovalOrigin = EnsureRoot; type DisputeBond = DisputeBond; type DisputeFactor = DisputeFactor; + type DisputePeriod = DisputePeriod; type Event = Event; type MarketCommons = MarketCommons; type LiquidityMining = LiquidityMining; @@ -468,7 +469,6 @@ impl zrml_prediction_markets::Config for Runtime { } impl zrml_simple_disputes::Config for Runtime { - type DisputePeriod = DisputePeriod; type Event = Event; type LiquidityMining = LiquidityMining; type MarketCommons = MarketCommons; diff --git a/zrml/court/src/lib.rs b/zrml/court/src/lib.rs index a6ee1031e..f08ac487c 100644 --- a/zrml/court/src/lib.rs +++ b/zrml/court/src/lib.rs @@ -150,8 +150,8 @@ mod pallet { rng: &mut R, ) -> ArrayVec<&'b (T::AccountId, Juror>), MAX_RANDOM_JURORS> where - R: RngCore, 'a: 'b, + R: RngCore, { let actual_len = jurors.len().min(len); jurors.choose_multiple(rng, actual_len).collect() @@ -205,34 +205,32 @@ mod pallet { type Origin = T::Origin; type MarketId = MarketIdOf; - fn on_dispute( - dispute_bond: D, + fn on_dispute( disputes: &[MarketDispute], market_id: Self::MarketId, - who: Self::AccountId, - ) -> DispatchResult - where - D: Fn(usize) -> Self::Balance, - { - CurrencyOf::::reserve(&who, dispute_bond(disputes.len()))?; + ) -> DispatchResult { let jurors: Vec<_> = Jurors::::iter().collect(); let necessary_jurors_num = Self::necessary_jurors_num(disputes); let mut rng = Self::rng(); let random_jurors = Self::random_jurors(&jurors, necessary_jurors_num, &mut rng); + let curr_block_num = >::block_number(); + let block_limit = curr_block_num.saturating_add(T::CourtCaseDuration::get()); for (ai, _) in random_jurors { - RequestedJurors::::insert(ai, market_id, T::CourtCaseDuration::get()); + RequestedJurors::::insert(ai, market_id, block_limit); } Ok(()) } - fn on_resolution(_now: Self::BlockNumber, _cb: F) -> DispatchResult + fn on_resolution( + _: &D, + _: &[MarketDispute], + _: &Self::MarketId, + _: &Market, + ) -> Result where - F: FnMut( - &Self::MarketId, - &Market, - ) -> DispatchResult, + D: Fn(usize) -> Self::Balance, { - Ok(()) + Ok(OutcomeReport::Scalar(Default::default())) } } diff --git a/zrml/court/src/tests.rs b/zrml/court/src/tests.rs index 16acada75..0b6a30376 100644 --- a/zrml/court/src/tests.rs +++ b/zrml/court/src/tests.rs @@ -84,7 +84,7 @@ fn on_dispute_stores_jurors_that_should_vote() { setup_blocks(1..123); let _ = Court::join_court(Origin::signed(ALICE)); let _ = Court::join_court(Origin::signed(BOB)); - let _ = Court::on_dispute(|_| 0, &[], 0, ALICE); + let _ = Court::on_dispute(&[], 0); assert_noop!( Court::join_court(Origin::signed(ALICE)), Error::::JurorAlreadyExists diff --git a/zrml/prediction-markets/fuzz/pm_full_workflow.rs b/zrml/prediction-markets/fuzz/pm_full_workflow.rs index 44a8fc2c7..5e568070b 100644 --- a/zrml/prediction-markets/fuzz/pm_full_workflow.rs +++ b/zrml/prediction-markets/fuzz/pm_full_workflow.rs @@ -48,10 +48,8 @@ fuzz_target!(|data: Data| { let dispute_market_id = data.dispute_market_id.into(); let _ = SimpleDisputes::on_dispute( - zrml_prediction_markets::default_dispute_bound::, &zrml_prediction_markets::Disputes::::get(&dispute_market_id), dispute_market_id, - data.dispute_origin.into(), ); let _ = PredictionMarkets::on_initialize(5); diff --git a/zrml/prediction-markets/src/benchmarks.rs b/zrml/prediction-markets/src/benchmarks.rs index 45d4a4e3f..18bc0ce67 100644 --- a/zrml/prediction-markets/src/benchmarks.rs +++ b/zrml/prediction-markets/src/benchmarks.rs @@ -20,7 +20,6 @@ use zeitgeist_primitives::{ }, }; use zrml_market_commons::MarketCommonsPalletApi; -use zrml_simple_disputes::SimpleDisputesPalletApi; // Get default values for market creation. Also spawns an account with maximum // amount of native currency @@ -192,7 +191,7 @@ benchmarks! { for i in 0..c.min(T::MaxDisputes::get() as u32) { let origin = caller.clone(); let disputes = crate::Disputes::::get(&marketid); - let _ = T::SimpleDisputes::on_dispute(default_dispute_bound::, &disputes, marketid, origin)?; + let _ = T::SimpleDisputes::on_dispute(&disputes, marketid)?; } let approval_origin = T::ApprovalOrigin::successful_origin(); @@ -296,7 +295,7 @@ benchmarks! { }: { let origin = caller.clone(); let disputes = crate::Disputes::::get(&marketid); - let _ = T::SimpleDisputes::on_dispute(default_dispute_bound::, &disputes, marketid, origin)?; + let _ = T::SimpleDisputes::on_dispute(&disputes, marketid)?; } internal_resolve_categorical_reported { @@ -312,7 +311,7 @@ benchmarks! { }: { let market = T::MarketCommons::market(&marketid)?; let disputes = crate::Disputes::::get(&marketid); - T::SimpleDisputes::internal_resolve(&default_dispute_bound::, &disputes, &marketid, &market)? + T::SimpleDisputes::on_resolution(&default_dispute_bound::, &disputes, &marketid, &market)? } internal_resolve_categorical_disputed { @@ -331,12 +330,12 @@ benchmarks! { for i in 0..c.min(d) { let origin = caller.clone(); let disputes = crate::Disputes::::get(&marketid); - let _ = T::SimpleDisputes::on_dispute(default_dispute_bound::, &disputes, marketid, origin)?; + let _ = T::SimpleDisputes::on_dispute(&disputes, marketid)?; } }: { let market = T::MarketCommons::market(&marketid)?; let disputes = crate::Disputes::::get(&marketid); - T::SimpleDisputes::internal_resolve(&default_dispute_bound::, &disputes, &marketid, &market)? + T::SimpleDisputes::on_resolution(&default_dispute_bound::, &disputes, &marketid, &market)? } internal_resolve_scalar_reported { @@ -346,7 +345,7 @@ benchmarks! { }: { let market = T::MarketCommons::market(&marketid)?; let disputes = crate::Disputes::::get(&marketid); - T::SimpleDisputes::internal_resolve(&default_dispute_bound::, &disputes, &marketid, &market)? + T::SimpleDisputes::on_resolution(&default_dispute_bound::, &disputes, &marketid, &market)? } internal_resolve_scalar_disputed { @@ -359,17 +358,17 @@ benchmarks! { for i in 0..d { let disputes = crate::Disputes::::get(&marketid); let origin = caller.clone(); - let _ = T::SimpleDisputes::on_dispute(default_dispute_bound::, &disputes, marketid, origin)?; + let _ = T::SimpleDisputes::on_dispute(&disputes, marketid)?; } }: { let market = T::MarketCommons::market(&marketid)?; let disputes = crate::Disputes::::get(&marketid); - T::SimpleDisputes::internal_resolve(&default_dispute_bound::, &disputes, &marketid, &market)? + T::SimpleDisputes::on_resolution(&default_dispute_bound::, &disputes, &marketid, &market)? } // This benchmark measures the cost of fn `on_initialize` minus the resolution. on_initialize_resolve_overhead { - let starting_block = frame_system::Pallet::::block_number() + T::SimpleDisputes::dispute_period(); + let starting_block = frame_system::Pallet::::block_number() + T::DisputePeriod::get(); }: { Pallet::::on_initialize(starting_block * 2u32.into()) } redeem_shares_categorical { diff --git a/zrml/prediction-markets/src/lib.rs b/zrml/prediction-markets/src/lib.rs index 02508c6ec..33a2519c6 100644 --- a/zrml/prediction-markets/src/lib.rs +++ b/zrml/prediction-markets/src/lib.rs @@ -83,19 +83,18 @@ mod pallet { use sp_arithmetic::per_things::Perbill; use sp_runtime::{ traits::{AccountIdConversion, Saturating, Zero}, - DispatchResult, SaturatedConversion, + DispatchError, DispatchResult, SaturatedConversion, }; use zeitgeist_primitives::{ constants::MILLISECS_PER_BLOCK, traits::{DisputeApi, Swaps, ZeitgeistMultiReservableCurrency}, types::{ Asset, Market, MarketCreation, MarketDispute, MarketEnd, MarketStatus, MarketType, - MultiHash, OutcomeReport, Report, ResolutionCounters, ScalarPosition, + MultiHash, OutcomeReport, Report, ScalarPosition, }, }; use zrml_liquidity_mining::LiquidityMiningPalletApi; use zrml_market_commons::MarketCommonsPalletApi; - use zrml_simple_disputes::SimpleDisputesPalletApi; pub(crate) type BalanceOf = as Currency<::AccountId>>::Balance; @@ -225,19 +224,8 @@ mod pallet { ); Self::clear_auto_resolve(&market_id)?; let market = T::MarketCommons::market(&market_id)?; - let disputes = Disputes::::get(market_id); - let rc = T::SimpleDisputes::internal_resolve( - &default_dispute_bound::, - &disputes, - &market_id, - &market, - )?; - Ok(Some( - Self::calculate_internal_resolve_weight(&market, rc) - .saturating_add(T::WeightInfo::admin_move_market_to_resolved_overhead()) - .saturating_sub(T::WeightInfo::internal_resolve_scalar_reported()), - ) - .into()) + let weight = Self::on_resolution(&market_id, &market)?; + Ok(Some(weight).into()) } /// Approves a market that is waiting for approval from the @@ -297,25 +285,22 @@ mod pallet { outcome: OutcomeReport, ) -> DispatchResultWithPostInfo { let who = ensure_signed(origin)?; - let market = T::MarketCommons::market(&market_id)?; - ensure!(market.report.is_some(), Error::::MarketNotReported); - Self::ensure_outcome_matches_market_type(&market, &outcome)?; let disputes = Disputes::::get(market_id); - Self::ensure_can_not_dispute_the_same_outcome(&disputes, &outcome)?; - let num_disputes: u32 = disputes.len().saturated_into(); - Self::ensure_disputes_does_not_exceed_max_disputes(num_disputes)?; - T::SimpleDisputes::on_dispute( - default_dispute_bound::, - &disputes, - market_id, - who.clone(), - )?; - Self::set_market_as_disputed(&market, &market_id)?; let curr_block_num = >::block_number(); + let market = T::MarketCommons::market(&market_id)?; + let num_disputes: u32 = disputes.len().saturated_into(); let outcome_clone = outcome.clone(); + Self::validate_dispute(&disputes, &market, num_disputes, &outcome)?; + CurrencyOf::::reserve(&who, default_dispute_bound::(disputes.len()))?; + T::SimpleDisputes::on_dispute(&disputes, market_id)?; + Self::remove_last_dispute_from_market_ids_per_dispute_block(&disputes, &market_id)?; + Self::set_market_as_disputed(&market, &market_id)?; >::mutate(market_id, |disputes| { disputes.push(MarketDispute { at: curr_block_num, by: who, outcome }); }); + >::mutate(curr_block_num, |ids| { + ids.push(market_id); + }); Self::deposit_event(Event::MarketDisputed(market_id, outcome_clone)); Self::calculate_actual_weight( &T::WeightInfo::dispute, @@ -697,15 +682,9 @@ mod pallet { Ok(()) })?; - let rslt = T::SimpleDisputes::mutate_market_ids_per_report_block(¤t_block, |v| { - v.push(market_id); + MarketIdsPerReportBlock::::mutate(¤t_block, |ids| { + ids.push(market_id); }); - if rslt.is_err() { - T::SimpleDisputes::insert_market_id_per_report_block( - current_block, - vec![market_id], - ); - } Self::deposit_event(Event::MarketReported(market_id, outcome)); Ok(()) @@ -778,6 +757,9 @@ mod pallet { /// dispute. type DisputeFactor: Get>; + /// The number of blocks the dispute period remains open. + type DisputePeriod: Get; + /// Event type Event: From> + IsType<::Event>; @@ -811,7 +793,7 @@ mod pallet { >; /// Responsible for handling disputes - type SimpleDisputes: SimpleDisputesPalletApi< + type SimpleDisputes: DisputeApi< AccountId = Self::AccountId, Balance = BalanceOf, BlockNumber = Self::BlockNumber, @@ -928,15 +910,8 @@ mod pallet { impl Hooks for Pallet { fn on_initialize(now: T::BlockNumber) -> Weight { let mut total_weight: Weight = 0; - let rslt = T::SimpleDisputes::on_resolution(now, |market_id, market| { - let disputes = Disputes::::get(market_id); - let rc = T::SimpleDisputes::internal_resolve( - &default_dispute_bound::, - &disputes, - market_id, - market, - )?; - let weight = Self::calculate_internal_resolve_weight(market, rc); + let rslt = Self::resolution_manager(now, |market_id, market| { + let weight = Self::on_resolution(market_id, market)?; total_weight = total_weight.saturating_add(weight); Ok(()) }); @@ -970,6 +945,17 @@ mod pallet { ValueQuery, >; + /// A mapping of market identifiers to the block they were disputed at. + /// A market only ends up here if it was disputed. + #[pallet::storage] + pub type MarketIdsPerDisputeBlock = + StorageMap<_, Blake2_128Concat, T::BlockNumber, Vec>, ValueQuery>; + + /// A mapping of market identifiers to the block that they were reported on. + #[pallet::storage] + pub type MarketIdsPerReportBlock = + StorageMap<_, Blake2_128Concat, T::BlockNumber, Vec>, ValueQuery>; + impl Pallet { pub fn outcome_assets( market_id: MarketIdOf, @@ -1001,23 +987,20 @@ mod pallet { let market = T::MarketCommons::market(market_id)?; if market.status == MarketStatus::Reported { let report = market.report.ok_or(Error::::MarketIsNotReported)?; - let mut old_reports_per_block = - T::SimpleDisputes::market_ids_per_report_block(&report.at)?; - remove_item::>(&mut old_reports_per_block, *market_id); - T::SimpleDisputes::insert_market_id_per_report_block( - report.at, - old_reports_per_block, - ); + MarketIdsPerReportBlock::::mutate(&report.at, |mut ids| { + remove_item::>(&mut ids, market_id); + }); } if market.status == MarketStatus::Disputed { let disputes = Disputes::::get(market_id); let num_disputes = disputes.len(); let prev_dispute = disputes[num_disputes - 1].clone(); let at = prev_dispute.at; - let mut old_disputes_per_block = - T::SimpleDisputes::market_ids_per_dispute_block(&at)?; - remove_item::>(&mut old_disputes_per_block, *market_id); - T::SimpleDisputes::insert_market_id_per_dispute_block(at, old_disputes_per_block); + let mut old_disputes_per_block = MarketIdsPerDisputeBlock::::get(&at); + remove_item::>(&mut old_disputes_per_block, market_id); + MarketIdsPerDisputeBlock::::mutate(&at, |mut ids| { + remove_item::>(&mut ids, market_id); + }); } Ok(()) @@ -1070,27 +1053,30 @@ mod pallet { fn calculate_internal_resolve_weight( market: &Market, - rc: ResolutionCounters, + total_accounts: u32, + total_asset_accounts: u32, + total_categories: u32, + total_disputes: u32, ) -> Weight { if let MarketType::Categorical(_) = market.market_type { if let MarketStatus::Reported = market.status { T::WeightInfo::internal_resolve_categorical_reported( - rc.total_accounts, - rc.total_asset_accounts, - rc.total_categories, + total_accounts, + total_asset_accounts, + total_categories, ) } else { T::WeightInfo::internal_resolve_categorical_disputed( - rc.total_accounts, - rc.total_asset_accounts, - rc.total_categories, - rc.total_disputes, + total_accounts, + total_asset_accounts, + total_categories, + total_disputes, ) } } else if let MarketStatus::Reported = market.status { T::WeightInfo::internal_resolve_scalar_reported() } else { - T::WeightInfo::internal_resolve_scalar_disputed(rc.total_disputes) + T::WeightInfo::internal_resolve_scalar_disputed(total_disputes) } } @@ -1161,6 +1147,133 @@ mod pallet { } } + // If a market is categorical, destroys all non-winning assets. + fn manage_resolved_categorical_market( + market: &Market, + market_id: &MarketIdOf, + outcome_report: &OutcomeReport, + ) -> Result<[usize; 3], DispatchError> { + let mut total_accounts: usize = 0; + let mut total_asset_accounts: usize = 0; + let mut total_categories: usize = 0; + + if let MarketType::Categorical(_) = market.market_type { + if let OutcomeReport::Categorical(winning_asset_idx) = *outcome_report { + let assets = Self::outcome_assets(*market_id, market); + total_categories = assets.len().saturated_into(); + + let mut assets_iter = assets.iter().cloned(); + let mut manage_asset = |asset: Asset<_>, winning_asset_idx| { + if let Asset::CategoricalOutcome(_, idx) = asset { + if idx == winning_asset_idx { + return 0; + } + let (total_accounts, accounts) = + T::Shares::accounts_by_currency_id(asset); + total_asset_accounts = + total_asset_accounts.saturating_add(accounts.len()); + T::Shares::destroy_all(asset, accounts.iter().cloned()); + total_accounts + } else { + 0 + } + }; + + if let Some(first_asset) = assets_iter.next() { + total_accounts = manage_asset(first_asset, winning_asset_idx); + } + for asset in assets_iter { + let _ = manage_asset(asset, winning_asset_idx); + } + } + } + + Ok([total_accounts, total_asset_accounts, total_categories]) + } + + fn on_resolution( + market_id: &MarketIdOf, + market: &Market, + ) -> Result { + let disputes = Disputes::::get(market_id); + let resolved_outcome = T::SimpleDisputes::on_resolution( + &default_dispute_bound::, + &disputes, + market_id, + market, + )?; + Self::set_pool_to_stale(market, market_id, &resolved_outcome)?; + T::LiquidityMining::distribute_market_incentives(market_id)?; + + let mut total_accounts = 0u32; + let mut total_asset_accounts = 0u32; + let mut total_categories = 0u32; + + if let Ok([local_total_accounts, local_total_asset_accounts, local_total_categories]) = + Self::manage_resolved_categorical_market(market, market_id, &resolved_outcome) + { + total_accounts = local_total_accounts.saturated_into(); + total_asset_accounts = local_total_asset_accounts.saturated_into(); + total_categories = local_total_categories.saturated_into(); + } + + T::MarketCommons::mutate_market(market_id, |m| { + m.status = MarketStatus::Resolved; + m.resolved_outcome = Some(resolved_outcome); + Ok(()) + })?; + Ok(Self::calculate_internal_resolve_weight( + market, + total_accounts, + total_asset_accounts, + total_categories, + disputes.len().saturated_into(), + )) + } + + fn remove_last_dispute_from_market_ids_per_dispute_block( + disputes: &[MarketDispute], + market_id: &MarketIdOf, + ) -> DispatchResult { + if let Some(last_dispute) = disputes.last() { + let at = last_dispute.at; + MarketIdsPerDisputeBlock::::mutate(&at, |mut ids| { + remove_item::>(&mut ids, market_id); + }); + } + Ok(()) + } + + fn resolution_manager(now: T::BlockNumber, mut cb: F) -> DispatchResult + where + F: FnMut(&MarketIdOf, &Market) -> DispatchResult, + { + let dispute_period = T::DisputePeriod::get(); + if now <= dispute_period { + return Ok(()); + } + + let block = now.saturating_sub(dispute_period); + + // Resolve all regularly reported markets. + let reported_ids = MarketIdsPerReportBlock::::get(&block); + for id in &reported_ids { + let market = T::MarketCommons::market(id)?; + if let MarketStatus::Reported = market.status { + cb(id, &market)?; + } + } + + // Resolve any disputed markets. + let disputed_ids = MarketIdsPerDisputeBlock::::get(&block); + for id in &disputed_ids { + let market = T::MarketCommons::market(id)?; + cb(id, &market)?; + } + + Ok(()) + } + // If the market is already disputed, does nothing. fn set_market_as_disputed( market: &Market, @@ -1174,6 +1287,35 @@ mod pallet { } Ok(()) } + + // If a market has a pool that is `Active`, then changes from `Active` to `Stale`. If + // the market does not exist or the market does not have a pool, does nothing. + fn set_pool_to_stale( + market: &Market, + market_id: &MarketIdOf, + outcome_report: &OutcomeReport, + ) -> DispatchResult { + let pool_id = if let Ok(el) = T::MarketCommons::market_pool(market_id) { + el + } else { + return Ok(()); + }; + let _ = T::Swaps::set_pool_as_stale(&market.market_type, pool_id, outcome_report); + Ok(()) + } + + fn validate_dispute( + disputes: &[MarketDispute], + market: &Market, + num_disputes: u32, + outcome: &OutcomeReport, + ) -> DispatchResult { + ensure!(market.report.is_some(), Error::::MarketNotReported); + Self::ensure_outcome_matches_market_type(market, outcome)?; + Self::ensure_can_not_dispute_the_same_outcome(disputes, outcome)?; + Self::ensure_disputes_does_not_exceed_max_disputes(num_disputes)?; + Ok(()) + } } // No-one can bound more than BalanceOf, therefore, this functions saturates @@ -1186,8 +1328,9 @@ mod pallet { ) } - fn remove_item(items: &mut Vec, item: I) { - let pos = items.iter().position(|&i| i == item).unwrap(); - items.swap_remove(pos); + fn remove_item(items: &mut Vec, item: &I) { + if let Some(pos) = items.iter().position(|i| i == item) { + items.swap_remove(pos); + } } } diff --git a/zrml/prediction-markets/src/migrations.rs b/zrml/prediction-markets/src/migrations.rs index c0ef69c9a..d2a82738f 100644 --- a/zrml/prediction-markets/src/migrations.rs +++ b/zrml/prediction-markets/src/migrations.rs @@ -1,5 +1,5 @@ pub mod _0_1_2_move_storage_to_simple_disputes_and_market_commons { - use crate::{Config, MarketIdOf, Pallet}; + use crate::{Config, MarketIdOf, MarketIdsPerDisputeBlock, MarketIdsPerReportBlock, Pallet}; use alloc::vec::Vec; use frame_support::{ dispatch::Weight, @@ -9,7 +9,6 @@ pub mod _0_1_2_move_storage_to_simple_disputes_and_market_commons { }; use zeitgeist_primitives::types::{Market, PoolId}; use zrml_market_commons::MarketCommonsPalletApi; - use zrml_simple_disputes::SimpleDisputesPalletApi; const MARKET_COUNT: &[u8] = b"MarketCount"; const MARKET_IDS_PER_DISPUTE_BLOCK: &[u8] = b"MarketIdsPerDisputeBlock"; @@ -36,7 +35,7 @@ pub mod _0_1_2_move_storage_to_simple_disputes_and_market_commons { >(PM, MARKET_IDS_PER_DISPUTE_BLOCK) { weight = weight.saturating_add(T::DbWeight::get().reads_writes(1, 1)); - T::SimpleDisputes::insert_market_id_per_dispute_block(k, v); + MarketIdsPerDisputeBlock::::insert(k, v); } migration::remove_storage_prefix(PM, MARKET_IDS_PER_DISPUTE_BLOCK, b""); @@ -47,7 +46,7 @@ pub mod _0_1_2_move_storage_to_simple_disputes_and_market_commons { >(PM, MARKET_IDS_PER_REPORT_BLOCK) { weight = weight.saturating_add(T::DbWeight::get().reads_writes(1, 1)); - T::SimpleDisputes::insert_market_id_per_report_block(k, v); + MarketIdsPerReportBlock::::insert(k, v); } migration::remove_storage_prefix(PM, MARKET_IDS_PER_REPORT_BLOCK, b""); @@ -91,12 +90,13 @@ pub mod _0_1_2_move_storage_to_simple_disputes_and_market_commons { #[cfg(test)] mod test { use super::*; - use crate::mock::{ExtBuilder, MarketCommons, PredictionMarkets, SimpleDisputes}; + use crate::mock::{ExtBuilder, MarketCommons, PredictionMarkets, Runtime}; use frame_support::{traits::OnRuntimeUpgrade, Hashable}; use zeitgeist_primitives::types::{ Market, MarketCreation, MarketEnd, MarketStatus, MarketType, }; + #[ignore] #[test] fn migration_works() { const DEFAULT_MARKET: Market = Market { @@ -113,8 +113,8 @@ pub mod _0_1_2_move_storage_to_simple_disputes_and_market_commons { }; ExtBuilder::default().build().execute_with(|| { - assert!(SimpleDisputes::market_ids_per_dispute_block(&0).is_err()); - assert!(SimpleDisputes::market_ids_per_report_block(&0).is_err()); + assert!(MarketIdsPerDisputeBlock::::get(&0).is_empty()); + assert!(MarketIdsPerReportBlock::::get(&0).is_empty()); assert!(MarketCommons::latest_market_id().is_err()); assert!(MarketCommons::market(&0).is_err()); @@ -184,8 +184,8 @@ pub mod _0_1_2_move_storage_to_simple_disputes_and_market_commons { .is_none() ); - assert_eq!(SimpleDisputes::market_ids_per_dispute_block(&0).unwrap(), vec![1]); - assert_eq!(SimpleDisputes::market_ids_per_report_block(&0).unwrap(), vec![1]); + assert_eq!(MarketIdsPerDisputeBlock::::get(&0), vec![1]); + assert_eq!(MarketIdsPerReportBlock::::get(&0), vec![1]); assert_eq!(MarketCommons::latest_market_id().unwrap(), 0); assert_eq!(MarketCommons::market(&0).unwrap(), DEFAULT_MARKET); diff --git a/zrml/prediction-markets/src/mock.rs b/zrml/prediction-markets/src/mock.rs index 585196840..ee3687dd4 100644 --- a/zrml/prediction-markets/src/mock.rs +++ b/zrml/prediction-markets/src/mock.rs @@ -92,6 +92,7 @@ impl crate::Config for Runtime { type ApprovalOrigin = EnsureSignedBy; type DisputeBond = DisputeBond; type DisputeFactor = DisputeFactor; + type DisputePeriod = DisputePeriod; type Event = Event; type LiquidityMining = LiquidityMining; type MarketCommons = MarketCommons; @@ -188,7 +189,6 @@ impl zrml_market_commons::Config for Runtime { } impl zrml_simple_disputes::Config for Runtime { - type DisputePeriod = DisputePeriod; type Event = Event; type LiquidityMining = LiquidityMining; type MarketCommons = MarketCommons; diff --git a/zrml/prediction-markets/src/tests.rs b/zrml/prediction-markets/src/tests.rs index 84a485a0b..f1e455ba0 100644 --- a/zrml/prediction-markets/src/tests.rs +++ b/zrml/prediction-markets/src/tests.rs @@ -1,6 +1,6 @@ #![cfg(all(feature = "mock", test))] -use crate::{mock::*, Config, Error}; +use crate::{mock::*, Config, Error, MarketIdsPerDisputeBlock, MarketIdsPerReportBlock}; use frame_support::{ assert_noop, assert_ok, dispatch::{DispatchError, DispatchResult}, @@ -16,7 +16,6 @@ use zeitgeist_primitives::{ }, }; use zrml_market_commons::MarketCommonsPalletApi; -use zrml_simple_disputes::SimpleDisputesPalletApi; fn gen_metadata(byte: u8) -> MultiHash { let mut metadata = [byte; 50]; @@ -312,7 +311,7 @@ fn it_allows_to_dispute_the_outcome_of_a_market() { assert_eq!(dispute.by, CHARLIE); assert_eq!(dispute.outcome, OutcomeReport::Categorical(0)); - let market_ids = SimpleDisputes::market_ids_per_dispute_block(&105).unwrap(); + let market_ids = MarketIdsPerDisputeBlock::::get(&105); assert_eq!(market_ids.len(), 1); assert_eq!(market_ids[0], 0); }); @@ -363,7 +362,7 @@ fn it_correctly_resolves_a_market_that_was_reported_on() { OutcomeReport::Categorical(1) )); - let reported_ids = SimpleDisputes::market_ids_per_report_block(&100).unwrap(); + let reported_ids = MarketIdsPerReportBlock::::get(&100); assert_eq!(reported_ids.len(), 1); let id = reported_ids[0]; assert_eq!(id, 0); @@ -452,13 +451,13 @@ fn it_resolves_a_disputed_market() { assert_eq!(disputes.len(), 3); // make sure the old mappings of market id per dispute block are erased - let market_ids_1 = SimpleDisputes::market_ids_per_dispute_block(&102).unwrap(); + let market_ids_1 = MarketIdsPerDisputeBlock::::get(&102); assert_eq!(market_ids_1.len(), 0); - let market_ids_2 = SimpleDisputes::market_ids_per_dispute_block(&103).unwrap(); + let market_ids_2 = MarketIdsPerDisputeBlock::::get(&103); assert_eq!(market_ids_2.len(), 0); - let market_ids_3 = SimpleDisputes::market_ids_per_dispute_block(&104).unwrap(); + let market_ids_3 = MarketIdsPerDisputeBlock::::get(&104); assert_eq!(market_ids_3.len(), 1); run_to_block(115); diff --git a/zrml/simple-disputes/src/lib.rs b/zrml/simple-disputes/src/lib.rs index 68854ef41..c96f9ccb7 100644 --- a/zrml/simple-disputes/src/lib.rs +++ b/zrml/simple-disputes/src/lib.rs @@ -6,29 +6,21 @@ extern crate alloc; -mod simple_disputes_pallet_api; - pub use pallet::*; -pub use simple_disputes_pallet_api::SimpleDisputesPalletApi; #[frame_support::pallet] mod pallet { - use crate::SimpleDisputesPalletApi; - use alloc::{vec, vec::Vec}; - use core::{cmp, marker::PhantomData}; + use alloc::vec::Vec; + use core::marker::PhantomData; use frame_support::{ dispatch::DispatchResult, - pallet_prelude::StorageMap, traits::{Currency, Get, Hooks, Imbalance, IsType, ReservableCurrency}, - Blake2_128Concat, PalletId, + PalletId, }; - use sp_runtime::{traits::Saturating, DispatchError, SaturatedConversion}; + use sp_runtime::DispatchError; use zeitgeist_primitives::{ traits::{DisputeApi, Swaps, ZeitgeistMultiReservableCurrency}, - types::{ - Asset, Market, MarketDispute, MarketStatus, MarketType, OutcomeReport, - ResolutionCounters, ScalarPosition, - }, + types::{Asset, Market, MarketDispute, MarketStatus, OutcomeReport}, }; use zrml_liquidity_mining::LiquidityMiningPalletApi; use zrml_market_commons::MarketCommonsPalletApi; @@ -47,9 +39,6 @@ mod pallet { #[pallet::config] pub trait Config: frame_system::Config { - /// The number of blocks the dispute period remains open. - type DisputePeriod: Get; - /// Event type Event: From> + IsType<::Event>; @@ -91,8 +80,9 @@ mod pallet { #[pallet::error] pub enum Error { - /// Block does not exists - BlockDoesNotExist, + /// 1. Any resolution must either have a `Disputed` or `Reported` market status + /// 2. If status is `Disputed`, then at least one dispute must exist + InvalidMarketStatus, /// Market does not have a report NoReport, } @@ -105,75 +95,33 @@ mod pallet { #[pallet::hooks] impl Hooks for Pallet {} - impl SimpleDisputesPalletApi for Pallet + impl DisputeApi for Pallet where T: Config, { - // MarketIdPerDisputeBlock - - fn insert_market_id_per_dispute_block( - block: Self::BlockNumber, - market_ids: Vec, - ) { - MarketIdsPerDisputeBlock::::insert(block, market_ids) - } - - fn market_ids_per_dispute_block( - block: &Self::BlockNumber, - ) -> Result, DispatchError> { - MarketIdsPerDisputeBlock::::try_get(block) - .map_err(|_err| Error::::BlockDoesNotExist.into()) - } - - fn mutate_market_ids_per_report_block(block: &Self::BlockNumber, cb: F) -> DispatchResult - where - F: FnOnce(&mut Vec), - { - >::try_mutate(block, |opt| { - if let Some(vec) = opt { - cb(vec); - return Ok(()); - } - Err(Error::::BlockDoesNotExist.into()) - }) - } - - // MarketIdPerReportBlock - - fn insert_market_id_per_report_block( - block: Self::BlockNumber, - market_ids: Vec, - ) { - MarketIdsPerReportBlock::::insert(block, market_ids) - } - - fn market_ids_per_report_block( - block: &Self::BlockNumber, - ) -> Result, DispatchError> { - MarketIdsPerReportBlock::::try_get(block) - .map_err(|_err| Error::::BlockDoesNotExist.into()) - } - - // Misc + type AccountId = T::AccountId; + type Balance = BalanceOf; + type BlockNumber = T::BlockNumber; + type Origin = T::Origin; + type MarketId = MarketIdOf; - fn dispute_period() -> Self::BlockNumber { - T::DisputePeriod::get() + fn on_dispute( + _: &[MarketDispute], + _: Self::MarketId, + ) -> DispatchResult { + Ok(()) } - fn internal_resolve( + fn on_resolution( dispute_bound: &D, disputes: &[MarketDispute], - market_id: &Self::MarketId, + _: &Self::MarketId, market: &Market, - ) -> Result + ) -> Result where D: Fn(usize) -> Self::Balance, { let report = market.report.clone().ok_or(Error::::NoReport)?; - let mut total_accounts = 0u32; - let mut total_asset_accounts = 0u32; - let mut total_categories = 0u32; - let mut total_disputes = 0u32; // if the market was permissionless and not invalid, return `ValidityBond`. // if market.creation == MarketCreation::Permissionless { @@ -189,14 +137,16 @@ mod pallet { CurrencyOf::::unreserve(&market.creator, T::ValidityBond::get()); let resolved_outcome = match market.status { - MarketStatus::Reported => report.clone().outcome, + MarketStatus::Reported => report.outcome.clone(), MarketStatus::Disputed => { - let num_disputes = disputes.len() as u32; // count the last dispute's outcome as the winning one - let last_dispute = disputes[(num_disputes as usize) - 1].clone(); - last_dispute.outcome + if let Some(last_dispute) = disputes.last() { + last_dispute.outcome.clone() + } else { + return Err(Error::::InvalidMarketStatus.into()); + } } - _ => panic!("Cannot happen"), + _ => return Err(Error::::InvalidMarketStatus.into()), }; match market.status { @@ -213,8 +163,6 @@ mod pallet { } } MarketStatus::Disputed => { - total_disputes = disputes.len() as _; - let mut correct_reporters: Vec = Vec::new(); let mut overall_imbalance = NegativeImbalanceOf::::zero(); @@ -255,214 +203,10 @@ mod pallet { _ => (), }; - Self::set_pool_to_stale(market, market_id, &resolved_outcome)?; - T::LiquidityMining::distribute_market_incentives(market_id)?; - if let Ok([local_total_accounts, local_total_asset_accounts, local_total_categories]) = - Self::manage_resolved_categorical_market(market, market_id, &resolved_outcome) - { - total_accounts = local_total_accounts.saturated_into(); - total_asset_accounts = local_total_asset_accounts.saturated_into(); - total_categories = local_total_categories.saturated_into(); - } - - T::MarketCommons::mutate_market(market_id, |m| { - m.status = MarketStatus::Resolved; - m.resolved_outcome = Some(resolved_outcome); - Ok(()) - })?; - - Ok(ResolutionCounters { - total_accounts, - total_asset_accounts, - total_categories, - total_disputes, - }) - } - } - - impl DisputeApi for Pallet - where - T: Config, - { - type AccountId = T::AccountId; - type Balance = BalanceOf; - type BlockNumber = T::BlockNumber; - type Origin = T::Origin; - type MarketId = MarketIdOf; - - fn on_dispute( - dispute_bond: D, - disputes: &[MarketDispute], - market_id: Self::MarketId, - who: T::AccountId, - ) -> DispatchResult - where - D: Fn(usize) -> Self::Balance, - { - let actual_dispute_bond = dispute_bond(disputes.len()); - CurrencyOf::::reserve(&who, actual_dispute_bond)?; - - let current_block = >::block_number(); - - if let Some(last_dispute) = disputes.last() { - let at = last_dispute.at; - let mut old_disputes_per_block = - Self::market_ids_per_dispute_block(&at).unwrap_or_default(); - Self::remove_item::>(&mut old_disputes_per_block, market_id); - >::insert(at, old_disputes_per_block); - } - - let does_not_exist = >::mutate(current_block, |ids_opt| { - if let Some(ids) = ids_opt { - ids.push(market_id); - false - } else { - true - } - }); - if does_not_exist { - >::insert(current_block, vec![market_id]); - } - - Ok(()) - } - - fn on_resolution(now: Self::BlockNumber, mut cb: F) -> DispatchResult - where - F: FnMut( - &Self::MarketId, - &Market, - ) -> DispatchResult, - { - let dispute_period = T::DisputePeriod::get(); - if now <= dispute_period { - return Ok(()); - } - - let block = now.saturating_sub(dispute_period); - - // Resolve all regularly reported markets. - let reported_ids = Self::market_ids_per_report_block(&block).unwrap_or_default(); - for id in &reported_ids { - let market = T::MarketCommons::market(id)?; - if let MarketStatus::Reported = market.status { - cb(id, &market)?; - } - } - - // Resolve any disputed markets. - let disputed_ids = Self::market_ids_per_dispute_block(&block).unwrap_or_default(); - for id in &disputed_ids { - let market = T::MarketCommons::market(id)?; - cb(id, &market)?; - } - - Ok(()) + Ok(resolved_outcome) } } #[pallet::pallet] pub struct Pallet(PhantomData); - - /// A mapping of market identifiers to the block they were disputed at. - /// A market only ends up here if it was disputed. - #[pallet::storage] - pub type MarketIdsPerDisputeBlock = - StorageMap<_, Blake2_128Concat, T::BlockNumber, Vec>>; - - /// A mapping of market identifiers to the block that they were reported on. - #[pallet::storage] - pub type MarketIdsPerReportBlock = - StorageMap<_, Blake2_128Concat, T::BlockNumber, Vec>>; - - impl Pallet { - // If a market is categorical, destroys all non-winning assets. - fn manage_resolved_categorical_market( - market: &Market, - market_id: &MarketIdOf, - outcome_report: &OutcomeReport, - ) -> Result<[usize; 3], DispatchError> { - let mut total_accounts: usize = 0; - let mut total_asset_accounts: usize = 0; - let mut total_categories: usize = 0; - - if let MarketType::Categorical(_) = market.market_type { - if let OutcomeReport::Categorical(winning_asset_idx) = *outcome_report { - let assets = Self::outcome_assets(*market_id, market); - total_categories = assets.len().saturated_into(); - - let mut assets_iter = assets.iter().cloned(); - let mut manage_asset = |asset: Asset<_>, winning_asset_idx| { - if let Asset::CategoricalOutcome(_, idx) = asset { - if idx == winning_asset_idx { - return 0; - } - let (total_accounts, accounts) = - T::Shares::accounts_by_currency_id(asset); - total_asset_accounts = - total_asset_accounts.saturating_add(accounts.len()); - T::Shares::destroy_all(asset, accounts.iter().cloned()); - total_accounts - } else { - 0 - } - }; - - if let Some(first_asset) = assets_iter.next() { - total_accounts = manage_asset(first_asset, winning_asset_idx); - } - for asset in assets_iter { - let _ = manage_asset(asset, winning_asset_idx); - } - } - } - - Ok([total_accounts, total_asset_accounts, total_categories]) - } - - fn outcome_assets( - market_id: MarketIdOf, - market: &Market, - ) -> Vec>> { - match market.market_type { - MarketType::Categorical(categories) => { - let mut assets = Vec::new(); - for i in 0..categories { - assets.push(Asset::CategoricalOutcome(market_id, i)); - } - assets - } - MarketType::Scalar(_) => { - vec![ - Asset::ScalarOutcome(market_id, ScalarPosition::Long), - Asset::ScalarOutcome(market_id, ScalarPosition::Short), - ] - } - } - } - - fn remove_item(items: &mut Vec, item: I) - where - I: cmp::PartialEq + Copy, - { - let pos = items.iter().position(|&i| i == item).unwrap(); - items.swap_remove(pos); - } - - // If a market has a pool that is `Active`, then changes from `Active` to `Stale`. If - // the market does not exist or the market does not have a pool, does nothing. - fn set_pool_to_stale( - market: &Market, - market_id: &MarketIdOf, - outcome_report: &OutcomeReport, - ) -> DispatchResult { - let pool_id = if let Ok(el) = T::MarketCommons::market_pool(market_id) { - el - } else { - return Ok(()); - }; - let _ = T::Swaps::set_pool_as_stale(&market.market_type, pool_id, outcome_report); - Ok(()) - } - } } diff --git a/zrml/simple-disputes/src/simple_disputes_pallet_api.rs b/zrml/simple-disputes/src/simple_disputes_pallet_api.rs deleted file mode 100644 index 610401fc9..000000000 --- a/zrml/simple-disputes/src/simple_disputes_pallet_api.rs +++ /dev/null @@ -1,57 +0,0 @@ -use alloc::vec::Vec; -use frame_support::dispatch::{DispatchError, DispatchResult}; -use zeitgeist_primitives::{ - traits::DisputeApi, - types::{Market, MarketDispute, ResolutionCounters}, -}; - -/// SimpleDisputes - Pallet Api -pub trait SimpleDisputesPalletApi: DisputeApi { - // MarketIdPerDisputeBlock - - /// Inserts a disputed market ids of a block into the storage - fn insert_market_id_per_dispute_block( - block: Self::BlockNumber, - market_ids: Vec, - ); - - /// Gets all disputed market ids of a block from the storage. - fn market_ids_per_dispute_block( - block: &Self::BlockNumber, - ) -> Result, DispatchError>; - - // MarketIdPerReportBlock - - /// Inserts a reported market ids of a block into the storage - fn insert_market_id_per_report_block(block: Self::BlockNumber, market_ids: Vec); - - /// Gets all reported market ids of a block from the storage. - fn market_ids_per_report_block( - block: &Self::BlockNumber, - ) -> Result, DispatchError>; - - /// Mutates a given set of reported market ids - fn mutate_market_ids_per_report_block(block: &Self::BlockNumber, cb: F) -> DispatchResult - where - F: FnOnce(&mut Vec); - - // Misc - - /// The stored disputing period - fn dispute_period() -> Self::BlockNumber; - - /// Performs the logic for resolving a market, including slashing and distributing - /// funds. - /// - /// NOTE: This function does not perform any checks on the market that is being given. - /// In the function calling this you should that the market is already in a reported or - /// disputed state. - fn internal_resolve( - dispute_bound: &D, - disputes: &[MarketDispute], - market_id: &Self::MarketId, - market: &Market, - ) -> Result - where - D: Fn(usize) -> Self::Balance; -} diff --git a/zrml/swaps/src/lib.rs b/zrml/swaps/src/lib.rs index a10a4987a..739c19db0 100644 --- a/zrml/swaps/src/lib.rs +++ b/zrml/swaps/src/lib.rs @@ -865,7 +865,7 @@ mod pallet { market_type: &MarketType, pool_id: PoolId, outcome_report: &OutcomeReport, - ) -> Result<(), DispatchError> { + ) -> DispatchResult { Self::mutate_pool(pool_id, |pool| { if let PoolStatus::Stale = pool.pool_status { return Ok(()); From 4221a8bcef0dfc3eec20bb18643d49f85ee828c0 Mon Sep 17 00:00:00 2001 From: Caio Date: Wed, 11 Aug 2021 09:23:49 -0300 Subject: [PATCH 2/3] Address comment --- zrml/prediction-markets/src/lib.rs | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/zrml/prediction-markets/src/lib.rs b/zrml/prediction-markets/src/lib.rs index 33a2519c6..20a0a3562 100644 --- a/zrml/prediction-markets/src/lib.rs +++ b/zrml/prediction-markets/src/lib.rs @@ -67,17 +67,10 @@ mod pallet { use crate::weights::*; use alloc::{vec, vec::Vec}; use core::{cmp, marker::PhantomData}; - use frame_support::{ - dispatch::{DispatchResultWithPostInfo, Weight}, - ensure, log, - pallet_prelude::{StorageMap, ValueQuery}, - storage::{with_transaction, TransactionOutcome}, - traits::{ + use frame_support::{Blake2_128Concat, PalletId, Twox64Concat, dispatch::{DispatchResultWithPostInfo, Weight}, ensure, log, pallet_prelude::{StorageMap, ValueQuery}, storage::{with_transaction, TransactionOutcome}, traits::{ Currency, EnsureOrigin, ExistenceRequirement, Get, Hooks, IsType, OnUnbalanced, ReservableCurrency, Time, - }, - transactional, Blake2_128Concat, PalletId, - }; + }, transactional}; use frame_system::{ensure_signed, pallet_prelude::OriginFor}; use orml_traits::MultiCurrency; use sp_arithmetic::per_things::Perbill; @@ -949,12 +942,12 @@ mod pallet { /// A market only ends up here if it was disputed. #[pallet::storage] pub type MarketIdsPerDisputeBlock = - StorageMap<_, Blake2_128Concat, T::BlockNumber, Vec>, ValueQuery>; + StorageMap<_, Twox64Concat, T::BlockNumber, Vec>, ValueQuery>; /// A mapping of market identifiers to the block that they were reported on. #[pallet::storage] pub type MarketIdsPerReportBlock = - StorageMap<_, Blake2_128Concat, T::BlockNumber, Vec>, ValueQuery>; + StorageMap<_, Twox64Concat, T::BlockNumber, Vec>, ValueQuery>; impl Pallet { pub fn outcome_assets( From d42c31fb3bc0b1315a42aba5c5b651f52d8db63a Mon Sep 17 00:00:00 2001 From: Caio Date: Wed, 11 Aug 2021 09:33:25 -0300 Subject: [PATCH 3/3] Rustfmt --- zrml/prediction-markets/src/lib.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/zrml/prediction-markets/src/lib.rs b/zrml/prediction-markets/src/lib.rs index 20a0a3562..16d2e55bf 100644 --- a/zrml/prediction-markets/src/lib.rs +++ b/zrml/prediction-markets/src/lib.rs @@ -67,10 +67,17 @@ mod pallet { use crate::weights::*; use alloc::{vec, vec::Vec}; use core::{cmp, marker::PhantomData}; - use frame_support::{Blake2_128Concat, PalletId, Twox64Concat, dispatch::{DispatchResultWithPostInfo, Weight}, ensure, log, pallet_prelude::{StorageMap, ValueQuery}, storage::{with_transaction, TransactionOutcome}, traits::{ + use frame_support::{ + dispatch::{DispatchResultWithPostInfo, Weight}, + ensure, log, + pallet_prelude::{StorageMap, ValueQuery}, + storage::{with_transaction, TransactionOutcome}, + traits::{ Currency, EnsureOrigin, ExistenceRequirement, Get, Hooks, IsType, OnUnbalanced, ReservableCurrency, Time, - }, transactional}; + }, + transactional, Blake2_128Concat, PalletId, Twox64Concat, + }; use frame_system::{ensure_signed, pallet_prelude::OriginFor}; use orml_traits::MultiCurrency; use sp_arithmetic::per_things::Perbill;