Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Production Court #976

Merged
merged 315 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from 65 commits
Commits
Show all changes
315 commits
Select commit Hold shift + click to select a range
c3c5ca6
apply review suggestions
Chralt98 Mar 2, 2023
5d873d2
rename reserve_outcome to suggest_outcome
Chralt98 Mar 2, 2023
88a43dd
separate resolve_disputed_market into parts
Chralt98 Mar 2, 2023
09860bd
add debug asserts
Chralt98 Mar 6, 2023
1d07739
document types
Chralt98 Mar 6, 2023
b444b08
modify sort check
Chralt98 Mar 6, 2023
0e25a81
avoid double remove
Chralt98 Mar 6, 2023
0045fde
clarify docs
Chralt98 Mar 6, 2023
b218d56
avoid mut
Chralt98 Mar 6, 2023
c04d5ff
binary search by account id
Chralt98 Mar 6, 2023
f0cac31
Revert "binary search by account id"
Chralt98 Mar 7, 2023
7cdb8e0
make pool item key unique
Chralt98 Mar 7, 2023
d8d68a1
use secure random number generator
Chralt98 Mar 8, 2023
e35256f
add tests
Chralt98 Mar 16, 2023
b54fb94
add tests
Chralt98 Mar 16, 2023
f81d03d
found bug in exit court
Chralt98 Mar 16, 2023
e170226
correct slashable
Chralt98 Mar 17, 2023
2005d61
fix exit court
Chralt98 Mar 17, 2023
0cc48f0
correct tests
Chralt98 Mar 17, 2023
30d5b48
Merge branch 'chralt98-court-overhaul' into chralt98-court-tests
Chralt98 Mar 20, 2023
7f24521
fix bug, add tests
Chralt98 Mar 20, 2023
2facc32
fix second get_winner bug
Chralt98 Mar 20, 2023
7bf8993
modify tests
Chralt98 Mar 20, 2023
11e4433
fix draw active lock bug, add tests
Chralt98 Mar 21, 2023
a7e8b1b
rename total_slashable to consumed_stake
Chralt98 Mar 21, 2023
5a710f3
update config parameters, tests
Chralt98 Mar 21, 2023
869dbf6
modify params and add tests
Chralt98 Mar 22, 2023
92fe695
add denounce tests
Chralt98 Mar 22, 2023
37cb195
increase code safety
Chralt98 Mar 22, 2023
4d9afab
add tests
Chralt98 Mar 24, 2023
d3f55ac
add tests
Chralt98 Mar 24, 2023
b8cd91a
edit exchange API documentation
Chralt98 Mar 27, 2023
5d6df79
slash dispute bond
Chralt98 Mar 27, 2023
06c2cea
Merge branch 'chralt98-dispute-restructuring' into chralt98-court-ove…
Chralt98 Mar 27, 2023
1fc9b39
Merge branch 'release-dispute-system' into chralt98-dispute-restructu…
Chralt98 Mar 28, 2023
ce13fd2
add empty commit
Chralt98 Mar 28, 2023
7b3ff21
correct admin_destroy_market test
Chralt98 Mar 28, 2023
f445aac
Merge branch 'chralt98-dispute-restructuring' into chralt98-court-ove…
Chralt98 Mar 28, 2023
e9bed9f
revert get_resolution_outcome to on_resolution
Chralt98 Mar 28, 2023
a052320
remove gd dependency from simple disputes
Chralt98 Mar 28, 2023
1f7cf3d
Merge branch 'chralt98-dispute-restructuring' into chralt98-court-ove…
Chralt98 Mar 28, 2023
978b425
use appealed outcomes for global dispute
Chralt98 Mar 28, 2023
c432ef4
modify appeal bond formula
Chralt98 Mar 29, 2023
b7c0127
remove slash percentages
Chralt98 Mar 29, 2023
718b99b
benchmark court
Chralt98 Mar 30, 2023
a8b625c
Update zrml/court/src/types.rs
Chralt98 Mar 31, 2023
5fcdb90
Update zrml/court/src/types.rs
Chralt98 Mar 31, 2023
2a422d8
Update zrml/court/src/lib.rs
Chralt98 Mar 31, 2023
4ee4445
Update zrml/court/src/lib.rs
Chralt98 Mar 31, 2023
0409006
Update zrml/court/src/lib.rs
Chralt98 Mar 31, 2023
6be9a23
Update zrml/court/src/mock_storage.rs
Chralt98 Mar 31, 2023
44032bb
Update zrml/court/src/lib.rs
Chralt98 Mar 31, 2023
0cd2281
Update zrml/court/src/lib.rs
Chralt98 Mar 31, 2023
c7962c5
Update zrml/court/src/tests.rs
Chralt98 Mar 31, 2023
5c62d09
Update zrml/court/src/tests.rs
Chralt98 Mar 31, 2023
ea3c10a
periods to round timing, modify tests
Chralt98 Mar 31, 2023
c787a64
modify doc comments
Chralt98 Mar 31, 2023
fc3ec21
use onunbalanced
Chralt98 Mar 31, 2023
8ec3a1d
improve RequestInterval documentation
Chralt98 Mar 31, 2023
e5c93e5
improve consumed_stake documentation
Chralt98 Mar 31, 2023
c783f34
remove court from filter
Chralt98 Mar 31, 2023
3f4e11a
add treasury to court
Chralt98 Mar 31, 2023
7ba9309
correct errors
Chralt98 Mar 31, 2023
0e0e8ad
update comment
Chralt98 Mar 31, 2023
6eb35ba
update get_pool_item comment
Chralt98 Mar 31, 2023
3350021
update get_pool_item comment
Chralt98 Mar 31, 2023
326f4f2
Merge branch 'chralt98-court-overhaul' of github.com:zeitgeistpm/zeit…
Chralt98 Mar 31, 2023
b4a45a7
comment juror pool
Chralt98 Mar 31, 2023
6fe0223
improve doc comments
Chralt98 Mar 31, 2023
d9a3b9e
cargo fmt
Chralt98 Mar 31, 2023
06af2fb
rename constants
Chralt98 Mar 31, 2023
3c0de15
edit court pallet doc
Chralt98 Mar 31, 2023
bb61066
update tests
Chralt98 Mar 31, 2023
4729e1b
rename secret to commitment
Chralt98 Mar 31, 2023
7cbdbe5
make commit reveal failsafer
Chralt98 Mar 31, 2023
1c732de
outsource commitment function
Chralt98 Mar 31, 2023
c7e3986
update doc comments
Chralt98 Mar 31, 2023
5302bd3
merge punish tardy jurors reassign juror stakes
Chralt98 Mar 31, 2023
0bd260a
outsource get_n_random_numbers
Chralt98 Mar 31, 2023
c2c0683
correct logs
Chralt98 Mar 31, 2023
b75d015
rename default to get
Chralt98 Mar 31, 2023
1d3d707
improve extrinsic comments
Chralt98 Apr 3, 2023
6e3a4d5
simplify choose_multiple_weighted
Chralt98 Apr 3, 2023
1802297
improve naming
Chralt98 Apr 3, 2023
b2bca89
remove back_global_dispute
Chralt98 Apr 3, 2023
8fbba7a
unlock jurors from last draws
Chralt98 Apr 3, 2023
780198f
improve error description
Chralt98 Apr 3, 2023
03531fe
shorten mock periods
Chralt98 Apr 3, 2023
ce9a056
document private functions
Chralt98 Apr 3, 2023
6cadc38
add assert to check max appeals
Chralt98 Apr 3, 2023
0f5c763
add stake to juror joined event
Chralt98 Apr 3, 2023
d6abc98
correct test
Chralt98 Apr 3, 2023
31ed506
improve test
Chralt98 Apr 3, 2023
dd1cefc
update reassigned event comment
Chralt98 Apr 3, 2023
7ba0fcd
correct test
Chralt98 Apr 3, 2023
fa8cf27
add assert check
Chralt98 Apr 4, 2023
9fc3fe3
improve tests for draws
Chralt98 Apr 4, 2023
aced219
add reveal vote invalid salt fails test
Chralt98 Apr 4, 2023
49f05cd
denounce slash inside reassign_juror_stakes
Chralt98 Apr 4, 2023
09213de
improve test readibility
Chralt98 Apr 4, 2023
76e286c
rename periods to cycle_ends
Chralt98 Apr 4, 2023
1266ef3
add select jurors test
Chralt98 Apr 4, 2023
68d5817
change randomness source in court tests
Chralt98 Apr 4, 2023
0a5a7d0
fix clippy
Chralt98 Apr 4, 2023
a2a2098
imrpove tests
Chralt98 Apr 4, 2023
3c48e40
remove cccount lookup in tests
Chralt98 Apr 4, 2023
48d87f6
improve test setup
Chralt98 Apr 4, 2023
c16d461
add API tests, add missing unlockings
Chralt98 Apr 5, 2023
a8452fd
add full cycle court tests
Chralt98 Apr 6, 2023
499d1fb
remove invalid test
Chralt98 Apr 6, 2023
bc635e5
add missing WeightInfo
Chralt98 Apr 6, 2023
419c897
add inflation inside court
Chralt98 Apr 11, 2023
351f050
improve benchmarking and testing
Chralt98 Apr 12, 2023
67aa44d
add integrity_test
Chralt98 Apr 12, 2023
c3b61cb
Update zrml/simple-disputes/src/mock.rs
Chralt98 Apr 12, 2023
11960de
Update zrml/simple-disputes/src/mock.rs
Chralt98 Apr 12, 2023
6fc9197
Update zrml/prediction-markets/src/lib.rs
Chralt98 Apr 12, 2023
c638679
add doc string
Chralt98 Apr 12, 2023
553e082
add doc strings
Chralt98 Apr 12, 2023
55fdee0
Reduce settle_bonds LOC
sea212 Apr 3, 2023
0efc405
cargo fmt
Chralt98 Apr 12, 2023
aa09b01
Update zrml/prediction-markets/src/migrations.rs
Chralt98 Apr 12, 2023
2c15b96
Update zrml/prediction-markets/src/migrations.rs
Chralt98 Apr 12, 2023
a71bb5c
apply review suggestion
Chralt98 Apr 12, 2023
981ab1d
Merge branch 'chralt98-dispute-restructuring' into chralt98-court-ove…
Chralt98 Apr 13, 2023
3b789c1
add GDItem integration
Chralt98 Apr 13, 2023
17063e0
add delegations
Chralt98 Apr 13, 2023
ef0ded6
improve code structure
Chralt98 Apr 13, 2023
f4fb443
fix benchmarks
Chralt98 Apr 13, 2023
a0ac03d
optimize logic
Chralt98 Apr 14, 2023
afd9d61
add correct mdm benchmarking on_dispute
Chralt98 Apr 17, 2023
af0a25a
use on_dispute_weight inside api
Chralt98 Apr 17, 2023
b88aca4
improve mdm weight technique
Chralt98 Apr 17, 2023
f48a0a3
add mdm weights to on_resolution
Chralt98 Apr 18, 2023
cbe528a
add tests for pm
Chralt98 Apr 18, 2023
3c6c9fe
Merge branch 'main' into chralt98-dispute-restructuring
Chralt98 Apr 18, 2023
7ab62c4
modify migration logs, fix try-runtime
Chralt98 Apr 18, 2023
47061f1
adjust tests for binary search
Chralt98 Apr 19, 2023
a9f5f46
improve benchmarking
Chralt98 Apr 19, 2023
4a9a04b
do small change
Chralt98 Apr 19, 2023
86bd97e
little benchmark fix
Chralt98 Apr 20, 2023
af60129
Update zrml/authorized/src/benchmarks.rs
Chralt98 Apr 20, 2023
ddf14ff
Update zrml/authorized/src/benchmarks.rs
Chralt98 Apr 20, 2023
8513191
use result with weight struct
Chralt98 Apr 20, 2023
797917c
improve code
Chralt98 Apr 20, 2023
112f5f6
update benchmark and weights
Chralt98 Apr 20, 2023
1e0fcbc
improve dispute api weight system
Chralt98 Apr 21, 2023
da9ef19
test delegations for reassign
Chralt98 Apr 21, 2023
4c0a2f7
correct benchmarks and test
Chralt98 Apr 21, 2023
e2eba05
remove comment
Chralt98 Apr 21, 2023
213d610
Merge branch 'chralt98-dispute-restructuring' into chralt98-court-ove…
Chralt98 Apr 24, 2023
1d25aeb
add API benchmarks
Chralt98 Apr 24, 2023
7dd291f
update weights
Chralt98 Apr 24, 2023
1720ccf
use generic vote item instead of outcome report
Chralt98 Apr 25, 2023
0b0de97
update to court id and generic court
Chralt98 Apr 26, 2023
1c6d5b5
fix stuff and add documentation
Chralt98 Apr 26, 2023
c34b8c8
add court readme, use new parameters
Chralt98 Apr 28, 2023
e8a086b
improve naming, weighting
Chralt98 Apr 28, 2023
ae99d7f
Use accurate dispute weight instead of max
sea212 May 3, 2023
995eae3
take random ranges without replacement
Chralt98 May 4, 2023
1001f08
switch get_random_number algo
Chralt98 May 8, 2023
5ef62a8
integrate court and reject simple disputes
Chralt98 May 8, 2023
44d788a
update start_global_dispute bench
Chralt98 May 9, 2023
1f7f337
Merge branch 'release-dispute-system' into chralt98-dispute-restructu…
Chralt98 May 9, 2023
6025960
fix clippy
Chralt98 May 9, 2023
85e8fc7
Merge branch 'chralt98-dispute-restructuring' into chralt98-court-ove…
Chralt98 May 9, 2023
2e93087
use efficient draw without replacement algorithm
Chralt98 May 9, 2023
f128165
small edits
Chralt98 May 9, 2023
5790e4d
round to min juror stake, use other draw algo
Chralt98 May 10, 2023
0bba8ce
use partial fisher yates algorithm
Chralt98 May 11, 2023
631ad9b
improve naming and comments
Chralt98 May 12, 2023
b5d51f7
update changelog for devs
Chralt98 May 15, 2023
e27c384
improve dispute api documentation
Chralt98 May 15, 2023
3996a19
correct call filters
Chralt98 May 15, 2023
ed7b314
add copyright notice
Chralt98 May 15, 2023
45dcafc
remove is_outcome and is_binary
Chralt98 May 15, 2023
bb25f4a
remove unnecessary "Court" prefix
Chralt98 May 15, 2023
3c0c757
update copyright notices
Chralt98 May 15, 2023
b122ac1
remove front end comment
Chralt98 May 15, 2023
40c79b1
Update zrml/court/README.md
Chralt98 May 15, 2023
beb7caf
npx prettier court readme
Chralt98 May 15, 2023
7d52c61
Merge branch 'chralt98-court-overhaul' of github.com:zeitgeistpm/zeit…
Chralt98 May 15, 2023
d623ec7
improve style of terminology
Chralt98 May 15, 2023
77e4f53
update readme
Chralt98 May 15, 2023
c74938b
remove unnecessary impl block
Chralt98 May 15, 2023
291eb96
update comment
Chralt98 May 15, 2023
6486cf9
remove todo
Chralt98 May 15, 2023
4366285
make reward_pot package private
Chralt98 May 16, 2023
333ab10
Merge branch 'release-dispute-system' into chralt98-court-overhaul
Chralt98 May 16, 2023
99fc4cf
Update zrml/court/src/lib.rs
Chralt98 May 16, 2023
1b7fd2c
update integrity test
Chralt98 May 16, 2023
1eb1275
Merge branch 'chralt98-court-overhaul' of github.com:zeitgeistpm/zeit…
Chralt98 May 16, 2023
59a0644
improve join court doc
Chralt98 May 16, 2023
d971286
improve extrinsic documentation
Chralt98 May 16, 2023
593f5e0
update delegate doc
Chralt98 May 16, 2023
b8deb67
make some types package private
Chralt98 May 16, 2023
d95b289
fix struct comment
Chralt98 May 16, 2023
3ba2722
update readme
Chralt98 May 16, 2023
220db6b
update readme
Chralt98 May 16, 2023
8f95fbb
remove commitment matcher
Chralt98 May 16, 2023
d89ad7a
fix doc string
Chralt98 May 16, 2023
0c5b8dd
remove unnecessary error
Chralt98 May 16, 2023
4e1e405
improve import
Chralt98 May 16, 2023
83b7560
improve test case
Chralt98 May 17, 2023
ad0c472
fix inflation misbehaviour
Chralt98 May 17, 2023
1fd7d28
improve round timing structure
Chralt98 May 19, 2023
9a7d463
improve error names
Chralt98 May 19, 2023
63b72d8
fix get_valid_delegated_juror
Chralt98 May 19, 2023
b5445a0
remove wrong break
Chralt98 May 19, 2023
5ab27e9
update weight for select jurors
Chralt98 May 19, 2023
38e8b1e
allow rejoin after exit preparation
Chralt98 May 22, 2023
b434ba5
remove unnecessary apis
Chralt98 May 22, 2023
e05f9fd
improve naming and docs
Chralt98 May 24, 2023
5b78736
Merge branch 'main' into chralt98-court-overhaul
Chralt98 Jun 5, 2023
ead0bc5
fix clippy
Chralt98 Jun 5, 2023
56e7bac
Merge branch 'release-dispute-system' into chralt98-court-overhaul
Chralt98 Jun 7, 2023
fb1c9fc
Merge branch 'release-dispute-system' into chralt98-court-overhaul
Chralt98 Jun 15, 2023
ebdc6dc
Merge branch 'release-dispute-system' into chralt98-court-overhaul
Chralt98 Aug 8, 2023
b84b6ea
fix copyrights
Chralt98 Aug 8, 2023
22f08c5
Merge branch 'release-dispute-system' into chralt98-court-overhaul
Chralt98 Aug 8, 2023
644e583
update changelog for devs
Chralt98 Aug 21, 2023
3d70ec8
Update runtime/common/src/lib.rs
Chralt98 Aug 21, 2023
6f44b92
Update zrml/court/src/lib.rs
Chralt98 Aug 21, 2023
5c8bde2
Update zrml/court/src/benchmarks.rs
Chralt98 Aug 21, 2023
b11b188
comment benchmark components
Chralt98 Aug 21, 2023
5ab68a1
comment benchmark component
Chralt98 Aug 21, 2023
ee75b0a
Update zrml/court/README.md
Chralt98 Aug 21, 2023
502a60d
add terminology for court
Chralt98 Aug 21, 2023
824a542
Merge branch 'chralt98-court-overhaul' of github.com:zeitgeistpm/zeit…
Chralt98 Aug 21, 2023
292deed
Update zrml/prediction-markets/src/benchmarks.rs
Chralt98 Aug 21, 2023
4ddbac0
restructure import
Chralt98 Aug 21, 2023
b51db9d
Update zrml/court/src/lib.rs
Chralt98 Aug 21, 2023
9446d34
Update zrml/court/src/lib.rs
Chralt98 Aug 21, 2023
9d8b87b
Update zrml/court/src/lib.rs
Chralt98 Aug 21, 2023
9715890
use mul_floor and reduce indentation
Chralt98 Aug 21, 2023
db516dc
Merge branch 'chralt98-court-overhaul' of github.com:zeitgeistpm/zeit…
Chralt98 Aug 21, 2023
e471c1e
safe guard inflation emission
Chralt98 Aug 21, 2023
9a71638
use imbalance for minting
Chralt98 Aug 21, 2023
53dc51c
use saturated div
Chralt98 Aug 21, 2023
4dd0931
logging if inflation period mint too high
Chralt98 Aug 22, 2023
4f5fe1f
Merge branch 'release-dispute-system' into chralt98-court-overhaul
Chralt98 Aug 22, 2023
b14060a
Update zrml/court/src/lib.rs
Chralt98 Aug 22, 2023
a5ca6a4
reduce court InflationPeriod for Battery Station
Chralt98 Aug 22, 2023
5075923
Update zrml/court/src/lib.rs
Chralt98 Aug 22, 2023
6ec8c5d
fmt
Chralt98 Aug 22, 2023
0d7a506
fix tests
Chralt98 Aug 23, 2023
459e9ff
fix issue tokens without burn
Chralt98 Aug 23, 2023
3a33893
remove unnecessary error return
Chralt98 Aug 23, 2023
a04810b
allow equal amount to previous stake
Chralt98 Aug 23, 2023
7b399bb
Merge branch 'release-dispute-system' into chralt98-court-overhaul
Chralt98 Aug 23, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions primitives/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ pub const AUTHORIZED_PALLET_ID: PalletId = PalletId(*b"zge/atzd");
// Court
/// Pallet identifier, mainly used for named balance reserves.
pub const COURT_PALLET_ID: PalletId = PalletId(*b"zge/cout");
/// Lock identifier, mainly used for the locks on the accounts.
pub const COURT_LOCK_ID: [u8; 8] = *b"zge/colk";

// Global Disputes
pub const GLOBAL_DISPUTES_PALLET_ID: PalletId = PalletId(*b"zge/gldp");
Expand Down
22 changes: 19 additions & 3 deletions primitives/src/constants/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::{
};
use frame_support::{parameter_types, traits::LockIdentifier, PalletId};
use orml_traits::parameter_type_with_key;
use sp_runtime::Percent;

// Authorized
parameter_types! {
Expand All @@ -16,9 +17,23 @@ parameter_types! {

// Court
parameter_types! {
pub const AppealBond: Balance = 5 * BASE;
pub const AppealBondFactor: Balance = 2 * BASE;
pub const CourtCaseDuration: u64 = BLOCKS_PER_DAY;
pub const CourtPalletId: PalletId = PalletId(*b"zge/cout");
pub const StakeWeight: u128 = 2 * BASE;
pub const RequestInterval: BlockNumber = 50;
pub const CourtVotePeriod: BlockNumber = 34;
pub const CourtAggregationPeriod: BlockNumber = 34;
pub const CourtAppealPeriod: BlockNumber = 34;
pub const CourtLockId: LockIdentifier = *b"zge/cloc";
pub const DenounceSlashPercentage: Percent = Percent::from_percent(100);
pub const IterationLimit: u32 = 100;
pub const MaxAppeals: u32 = 6;
pub const MaxDraws: u32 = 191;
pub const MaxJurors: u32 = 1000;
pub const MinJurorStake: Balance = 50 * CENT;
pub const RedistributionPercentage: Percent = Percent::from_percent(10);
pub const TardySlashPercentage: Percent = Percent::from_percent(20);
}

// Global disputes parameters
Expand All @@ -40,8 +55,7 @@ parameter_types! {
// Prediction Market parameters
parameter_types! {
pub const AdvisoryBond: Balance = 25 * CENT;
pub const DisputeBond: Balance = 5 * BASE;
pub const DisputeFactor: Balance = 2 * BASE;
pub const DisputeBond: Balance = 20 * BASE;
pub const GlobalDisputePeriod: BlockNumber = 7 * BLOCKS_PER_DAY;
pub const MaxCategories: u16 = 10;
pub const MaxDisputeDuration: BlockNumber = 50;
Expand All @@ -67,6 +81,8 @@ parameter_types! {
// Simple disputes parameters
parameter_types! {
pub const SimpleDisputesPalletId: PalletId = PalletId(*b"zge/sedp");
pub const OutcomeBond: Balance = 5 * BASE;
pub const OutcomeFactor: Balance = 2 * BASE;
}

// Swaps parameters
Expand Down
15 changes: 13 additions & 2 deletions primitives/src/market.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ pub struct MarketBonds<AI, BA> {
pub creation: Option<Bond<AI, BA>>,
pub oracle: Option<Bond<AI, BA>>,
pub outsider: Option<Bond<AI, BA>>,
pub dispute: Option<Bond<AI, BA>>,
}

impl<AI: Ord, BA: frame_support::traits::tokens::Balance> MarketBonds<AI, BA> {
Expand All @@ -99,13 +100,14 @@ impl<AI: Ord, BA: frame_support::traits::tokens::Balance> MarketBonds<AI, BA> {
value_or_default(&self.creation)
.saturating_add(value_or_default(&self.oracle))
.saturating_add(value_or_default(&self.outsider))
.saturating_add(value_or_default(&self.dispute))
}
}

// Used primarily for testing purposes.
impl<AI, BA> Default for MarketBonds<AI, BA> {
fn default() -> Self {
MarketBonds { creation: None, oracle: None, outsider: None }
MarketBonds { creation: None, oracle: None, outsider: None, dispute: None }
}
}

Expand Down Expand Up @@ -174,13 +176,22 @@ pub enum MarketCreation {
Advised,
}

// TODO to remove, when Disputes storage item is removed
#[derive(Clone, Decode, Encode, Eq, MaxEncodedLen, PartialEq, RuntimeDebug, TypeInfo)]
pub struct MarketDispute<AccountId, BlockNumber> {
pub struct OldMarketDispute<AccountId, BlockNumber> {
pub at: BlockNumber,
pub by: AccountId,
pub outcome: OutcomeReport,
}

#[derive(Clone, Decode, Encode, Eq, MaxEncodedLen, PartialEq, RuntimeDebug, TypeInfo)]
pub struct MarketDispute<AccountId, BlockNumber, Balance> {
pub at: BlockNumber,
pub by: AccountId,
pub outcome: OutcomeReport,
pub bond: Balance,
}

/// How a market should resolve disputes
#[derive(Clone, Decode, Encode, Eq, MaxEncodedLen, PartialEq, RuntimeDebug, TypeInfo)]
pub enum MarketDisputeMechanism {
Expand Down
44 changes: 27 additions & 17 deletions primitives/src/traits/dispute_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@
// along with Zeitgeist. If not, see <https://www.gnu.org/licenses/>.

use crate::{
market::MarketDispute,
outcome_report::OutcomeReport,
types::{Asset, Market},
};
use frame_support::{dispatch::DispatchResult, pallet_prelude::Weight, BoundedVec};
use frame_support::{dispatch::DispatchResult, pallet_prelude::Weight};
use parity_scale_codec::MaxEncodedLen;
use sp_runtime::DispatchError;

Expand All @@ -37,6 +36,7 @@ type MarketOfDisputeApi<T> = Market<
pub trait DisputeApi {
type AccountId;
type Balance;
type NegativeImbalance;
type BlockNumber;
type MarketId: MaxEncodedLen;
type Moment;
Expand All @@ -46,11 +46,7 @@ pub trait DisputeApi {
///
/// Further interaction with the dispute API (if necessary) **should** happen through an
/// associated pallet. **May** assume that `market.dispute_mechanism` refers to the calling dispute API.
fn on_dispute(
previous_disputes: &[MarketDispute<Self::AccountId, Self::BlockNumber>],
market_id: &Self::MarketId,
market: &MarketOfDisputeApi<Self>,
) -> DispatchResult;
fn on_dispute(market_id: &Self::MarketId, market: &MarketOfDisputeApi<Self>) -> DispatchResult;

/// Manage market resolution of a disputed market.
///
Expand All @@ -61,20 +57,30 @@ pub trait DisputeApi {
///
/// Returns the dispute mechanism's report if available, otherwise `None`. If `None` is
/// returned, this means that the dispute could not be resolved.
fn on_resolution(
disputes: &[MarketDispute<Self::AccountId, Self::BlockNumber>],
fn get_resolution_outcome(
market_id: &Self::MarketId,
market: &MarketOfDisputeApi<Self>,
) -> Result<Option<OutcomeReport>, DispatchError>;

/// Allow the flow of funds to the market dispute mechanism.
/// **May** assume that `market.dispute_mechanism` refers to the calling dispute API.
///
/// # Returns
/// Returns the negative imbalance which is meant to be used for the treasury.
fn maybe_pay(
market_id: &Self::MarketId,
market: &MarketOfDisputeApi<Self>,
resolved_outcome: &OutcomeReport,
overall_imbalance: Self::NegativeImbalance,
) -> Result<Self::NegativeImbalance, DispatchError>;

/// Query the future resolution block of a disputed market.
/// **May** assume that `market.dispute_mechanism` refers to the calling dispute API.
///
/// # Returns
///
/// Returns the future resolution block if available, otherwise `None`.
fn get_auto_resolve(
disputes: &[MarketDispute<Self::AccountId, Self::BlockNumber>],
market_id: &Self::MarketId,
market: &MarketOfDisputeApi<Self>,
) -> Result<Option<Self::BlockNumber>, DispatchError>;
Expand All @@ -83,10 +89,20 @@ pub trait DisputeApi {
/// was unable to come to a conclusion.
/// **May** assume that `market.dispute_mechanism` refers to the calling dispute API.
fn has_failed(
disputes: &[MarketDispute<Self::AccountId, Self::BlockNumber>],
market_id: &Self::MarketId,
market: &MarketOfDisputeApi<Self>,
) -> Result<bool, DispatchError>;

/// Called, when a global dispute is started.
maltekliemann marked this conversation as resolved.
Show resolved Hide resolved
/// **May** assume that `market.dispute_mechanism` refers to the calling dispute API.
fn on_global_dispute(
market_id: &Self::MarketId,
market: &MarketOfDisputeApi<Self>,
) -> DispatchResult;

/// Called, when a market is destroyed.
/// **May** assume that `market.dispute_mechanism` refers to the calling dispute API.
fn clear(market_id: &Self::MarketId, market: &MarketOfDisputeApi<Self>) -> DispatchResult;
}

type MarketOfDisputeResolutionApi<T> = Market<
Expand All @@ -102,7 +118,6 @@ pub trait DisputeResolutionApi {
type Balance;
type BlockNumber;
type MarketId: MaxEncodedLen;
type MaxDisputes;
type Moment;

/// Resolve a market.
Expand Down Expand Up @@ -141,9 +156,4 @@ pub trait DisputeResolutionApi {
///
/// Returns the number of elements in the storage structure.
fn remove_auto_resolve(market_id: &Self::MarketId, resolve_at: Self::BlockNumber) -> u32;

/// Get the disputes of a market.
fn get_disputes(
market_id: &Self::MarketId,
) -> BoundedVec<MarketDispute<Self::AccountId, Self::BlockNumber>, Self::MaxDisputes>;
}
53 changes: 42 additions & 11 deletions runtime/battery-station/src/parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use super::VERSION;
use frame_support::{
parameter_types,
traits::LockIdentifier,
weights::{
constants::{BlockExecutionWeight, ExtrinsicBaseWeight, WEIGHT_PER_SECOND},
DispatchClass, Weight,
Expand All @@ -40,9 +41,6 @@ use sp_runtime::{
use sp_version::RuntimeVersion;
use zeitgeist_primitives::{constants::*, types::*};

#[cfg(feature = "with-global-disputes")]
use frame_support::traits::LockIdentifier;

pub(crate) const AVERAGE_ON_INITIALIZE_RATIO: Perbill = Perbill::from_percent(10);
pub(crate) const MAXIMUM_BLOCK_WEIGHT: Weight =
Weight::from_ref_time(WEIGHT_PER_SECOND.ref_time() / 2);
Expand Down Expand Up @@ -77,13 +75,42 @@ parameter_types! {
pub const TechnicalCommitteeMotionDuration: BlockNumber = 7 * BLOCKS_PER_DAY;

// Court
/// (Slashable) Bond that is provided for overriding the last appeal.
/// Slashed in case the final outcome does match the appealed outcome for which the `AppealBond`
/// was deposited.
pub const AppealBond: Balance = 5 * BASE;
/// `OutcomeBond` is increased by this factor after every new appeal.
pub const AppealBondFactor: Balance = 2 * BASE;
/// Duration of a single court case.
pub const CourtCaseDuration: u64 = BLOCKS_PER_DAY;
/// Pallet identifier, mainly used for named balance reserves.
pub const CourtPalletId: PalletId = COURT_PALLET_ID;
/// This value is multiplied by the current number of jurors to determine the stake
/// the juror has to pay.
pub const StakeWeight: u128 = 2 * BASE;
/// The time in which the jurors can cast their secret vote.
pub const CourtVotePeriod: BlockNumber = 2 * BLOCKS_PER_DAY;
/// The time in which the jurors should reveal their secret vote.
pub const CourtAggregationPeriod: BlockNumber = 2 * BLOCKS_PER_DAY;
/// The time in which a court case can get appealed.
pub const CourtAppealPeriod: BlockNumber = 3 * BLOCKS_PER_DAY;
/// The court lock identifier.
pub const CourtLockId: LockIdentifier = COURT_LOCK_ID;
/// The slash percentage if a secret vote gets revealed during the voting period.
pub const DenounceSlashPercentage: Percent = Percent::from_percent(100);
/// The iteration limit over all markets for the randomly selected jurors.
pub const IterationLimit: u32 = 100;
/// The maximum number of appeals until the court fails.
pub const MaxAppeals: u32 = 6;
/// The maximum number of randomly selected jurors for a dispute.
pub const MaxDraws: u32 = 191;
/// The maximum number of jurors that can be registered.
pub const MaxJurors: u32 = 10_000;
/// The minimum stake a user needs to reserve to become a juror.
pub const MinJurorStake: Balance = 1000 * BASE;
/// The percentage that is slashed if a juror did not vote for the plurality outcome.
pub const RedistributionPercentage: Percent = Percent::from_percent(10);
/// The interval for requesting multiple court votes at once.
pub const RequestInterval: BlockNumber = 7 * BLOCKS_PER_DAY;
/// The percentage that is being slashed from the juror's stake.
pub const TardySlashPercentage: Percent = Percent::from_percent(20);

// Democracy
/// How often (in blocks) new public referenda are launched.
Expand Down Expand Up @@ -152,11 +179,9 @@ parameter_types! {
/// The percentage of the advisory bond that gets slashed when a market is rejected.
pub const AdvisoryBondSlashPercentage: Percent = Percent::from_percent(0);
/// (Slashable) Bond that is provided for disputing the outcome.
/// Slashed in case the final outcome does not match the dispute for which the `DisputeBond`
/// was deposited.
pub const DisputeBond: Balance = 5 * BASE;
/// `DisputeBond` is increased by this factor after every dispute.
pub const DisputeFactor: Balance = 2 * BASE;
/// Unreserved in case the dispute was justified otherwise slashed.
/// This is when the resolved outcome is different to the default (reported) outcome.
pub const DisputeBond: Balance = 25 * BASE;
/// Maximum Categories a prediciton market can have (excluding base asset).
pub const MaxCategories: u16 = MAX_CATEGORIES;
/// Maximum block period for a dispute.
Expand Down Expand Up @@ -223,6 +248,12 @@ parameter_types! {
// Simple disputes parameters
/// Pallet identifier, mainly used for named balance reserves.
pub const SimpleDisputesPalletId: PalletId = SD_PALLET_ID;
/// (Slashable) Bond that is provided for overriding the last outcome addition.
/// Slashed in case the final outcome does not match the dispute for which the `OutcomeBond`
/// was deposited.
pub const OutcomeBond: Balance = 5 * BASE;
/// `OutcomeBond` is increased by this factor after every new outcome addition.
pub const OutcomeFactor: Balance = 2 * BASE;

// Swaps parameters
/// A precentage from the withdrawal amount a liquidity provider wants to withdraw
Expand Down
Loading