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 dispute system #1085

Merged
merged 48 commits into from
Aug 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
fddeb1b
ZIP-0 Part II (#938)
Chralt98 May 16, 2023
d8ea5a8
Merge branch 'main' into release-dispute-system
Chralt98 Jun 7, 2023
ae0eccf
Merge branch 'main' into release-dispute-system
Chralt98 Jun 7, 2023
9ee2980
Merge branch 'main' into release-dispute-system
Chralt98 Jun 15, 2023
a085987
fix clippy
Chralt98 Jun 15, 2023
9fcf8f0
Merge branch 'main' into release-dispute-system
Chralt98 Aug 8, 2023
d5aa135
fix clippy
Chralt98 Aug 8, 2023
1da1683
Update dependencies to v0.9.38
sea212 Aug 20, 2023
398d8f7
More dependency updates
sea212 Aug 20, 2023
ab47324
Update standalone runtimes
sea212 Aug 20, 2023
2a60e3c
Fix build with feature runtime-benchmark
sea212 Aug 21, 2023
2fd134e
Update Zeitgeist parachain runtime
sea212 Aug 21, 2023
45b86e7
Update Battery Station parachain runtime
sea212 Aug 22, 2023
3237a78
Deduplicated dependencies
sea212 Aug 22, 2023
14ce98b
Merge branch 'main' into release-dispute-system
Chralt98 Aug 22, 2023
5ce5bb8
Make tests succeed for parachain runtime
sea212 Aug 22, 2023
37d6aee
Partially fix Zeitgeist xcm tests
sea212 Aug 22, 2023
2ad2d88
Make all runtime tests succeed
sea212 Aug 23, 2023
4089ecd
Update standalone client
sea212 Aug 23, 2023
504d3f1
Update parachain node
sea212 Aug 23, 2023
6a6f9ea
Add migrations
sea212 Aug 23, 2023
2d54592
Cargo fmt
sea212 Aug 23, 2023
b11c260
Satisfy Clippy
sea212 Aug 23, 2023
30af891
Cargo fmt
sea212 Aug 23, 2023
21ce803
Taplo format
sea212 Aug 23, 2023
9646a85
Update licenses
sea212 Aug 23, 2023
e57d27f
remove outsider bond from migration
Chralt98 Aug 23, 2023
fe589a5
Reduce runtime test dependencies by half
sea212 Aug 23, 2023
4ba8868
small changes
Chralt98 Aug 23, 2023
41d09c5
Add missing runtime-benchmark feature
sea212 Aug 23, 2023
ab0e64a
Use upper case copyright name
sea212 Aug 23, 2023
2599c7d
Remove test logger
sea212 Aug 23, 2023
328753d
Implement Production Court (#976)
Chralt98 Aug 23, 2023
6e27186
[Global Disputes] Fix issues after first battery station live test (#…
Chralt98 Aug 23, 2023
e12ca11
activate court and GD on battery station
Chralt98 Aug 23, 2023
71e8006
bump storage version of market commons
Chralt98 Aug 23, 2023
55133b0
Update runtime/zeitgeist/src/lib.rs
Chralt98 Aug 23, 2023
847fcac
Update runtime/zeitgeist/src/lib.rs
Chralt98 Aug 23, 2023
c684f28
Revert "Reduce runtime test dependencies by half"
sea212 Aug 24, 2023
9ad7516
Update weight templates
sea212 Aug 24, 2023
a4a7648
Use header option for benchmarks
sea212 Aug 24, 2023
c586c61
Update rust-toolchain
sea212 Aug 24, 2023
4d0cc4d
Satisfy clippy
sea212 Aug 25, 2023
abd7ed5
Use patched wasm-builder for new rustc
sea212 Aug 25, 2023
a3a18db
Format
sea212 Aug 25, 2023
9dd8010
Update licenses
sea212 Aug 25, 2023
d501c00
Merge remote-tracking branch 'origin/sea212-update-dependencies' into…
Chralt98 Aug 25, 2023
706ba4b
Merge branch 'main' into release-dispute-system
Chralt98 Aug 25, 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
609 changes: 261 additions & 348 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ hex-literal = { version = "0.3.4", default-features = false }
log = { version = "0.4.17", default-features = false }
num-traits = { version = "0.2.15", default-features = false }
rand = { version = "0.8.5", default-features = false }
rand_chacha = { version = "0.3.1", default-features = false }
serde = { version = "1.0.152", default-features = false }

[profile.dev.package]
Expand Down
93 changes: 86 additions & 7 deletions docs/changelog_for_devs.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,99 @@ and does not represent a complete changelog for the zeitgeistpm/zeitgeist
repository.

As of 0.3.9, the changelog's format is based on
https://keepachangelog.com/en/1.0.0/ and ⚠️ marks changes that might break
<https://keepachangelog.com/en/1.0.0/> and ⚠️ marks changes that might break
components which query the chain's storage, the extrinsics or the runtime
APIs/RPC interface.

## v0.4.0

[#976]: https://github.com/zeitgeistpm/zeitgeist/pull/976

### Changed

All things about Global Disputes Fix ⚠️ :

- Replace `WinnerInfo` by `GlobalDisputeInfo` with the following fields:
- `winner_outcome: OutcomeReport`
- `outcome_info: OutcomeInfo`
- `status: GdStatus`

### Removed

All things about Global Disputes Fix ⚠️ :

- Remove the following event:
- `OutcomeOwnersRewardedWithNoFunds`

### Added

- ⚠️ Add court production implementation ([#976]). Dispatchable calls are:
- `join_court` - Join the court with a stake to become a juror in order to get
the stake-weighted chance to be selected for decision making.
- `delegate` - Join the court with a stake to become a delegator in order to
delegate the voting power to actively participating jurors.
- `prepare_exit_court` - Prepare as a court participant to leave the court
system.
- `exit_court` - Exit the court system in order to get the stake back.
- `vote` - An actively participating juror votes secretely on a specific court
case, in which the juror got selected.
- `denounce_vote` - Denounce a selected and active juror, if the secret and
vote is known before the actual reveal period.
- `reveal_vote` - An actively participating juror reveals the previously
casted secret vote.
- `appeal` - After the reveal phase (aggregation period), the jurors decision
can be appealed.
- `reassign_juror_stakes` - After the appeal period is over, losers pay the
winners for the jurors and delegators.
- `set_inflation` - Set the yearly inflation rate of the court system. Events
are:
- `JurorJoined` - A juror joined the court system.
- `ExitPrepared` - A court participant prepared to exit the court system.
- `ExitedCourt` - A court participant exited the court system.
- `JurorVoted` - A juror voted on a specific court case.
- `JurorRevealedVote` - A juror revealed the previously casted secret vote.
- `DenouncedJurorVote` - A juror was denounced.
- `DelegatorJoined` - A delegator joined the court system.
- `CourtAppealed` - A court case was appealed.
- `MintedInCourt` - A court participant was rewarded with newly minted tokens.
- `StakesReassigned` - The juror and delegator stakes have been reassigned.
The losing jurors have been slashed. The winning jurors have been rewarded
by the losers. The losing jurors are those, who did not vote, or did not
vote with the plurality, were denounced or did not reveal their vote.
- `InflationSet` - The yearly inflation rate of the court system was set.

All things about Global Disputes Fix ⚠️ :

- Add new dispatchable function:
- `refund_vote_fees` - Return all vote funds and fees, when a global dispute
was destroyed.
- Add the following events:
- `OutcomeOwnerRewarded` for `Possession::Paid`
- `OutcomeOwnersRewarded` for `Possession::Shared`
- `OutcomesFullyCleaned` and `OutcomesPartiallyCleaned` for extrinsic
`refund_vote_fees`
- Add enum `Possession` with variants:
- `Paid { owner: AccountId, fee: Balance }`
- `Shared { owners: BoundedVec }`
- `OutcomeInfo` has the following fields:
- `outcome_sum: Balance`
- `possession: Possession`
- Add `GdStatus` with the following enum variants:
- `Active { add_outcome_end: BlockNumber, vote_end: BlockNumber }`
- `Finished`
- `Destroyed`

## v0.3.11

[#1049]: https://github.com/zeitgeistpm/zeitgeist/pull/1049

### Changed

- ⚠️ All tokens now use 10 fractional decimal places ([#1049]).
- Cross-consensus messages (XCM) assume the global canonical representation for token balances.
- The token metadata in the asset registry now assumes that the existential deposit and fee factor
are stored in base 10,000,000,000.
- Cross-consensus messages (XCM) assume the global canonical representation for
token balances.
- The token metadata in the asset registry now assumes that the existential
deposit and fee factor are stored in base 10,000,000,000.

## v0.3.10

Expand Down Expand Up @@ -113,7 +192,7 @@ APIs/RPC interface.
- Added xTokens pallet to transfer tokens accross chains
- Added AssetRegistry pallet to register foreign asset
- Added UnknownTokens pallet to handle unknown foreign assets
- More information at https://github.com/zeitgeistpm/zeitgeist/pull/661#top
- More information at <https://github.com/zeitgeistpm/zeitgeist/pull/661#top>

- Transformed integer scalar markets to fixed point with ten digits after the
decimal point. As soon as this update is deployed, the interpretation of the
Expand Down Expand Up @@ -212,8 +291,8 @@ APIs/RPC interface.
- The `MarketCounter` of the `market-commons` pallet is incremented by one. This
means that `MarketCounter` is now equal to the total number of markets ever
created, instead of equal to the id of the last market created. For details
regarding this fix, see https://github.com/zeitgeistpm/zeitgeist/pull/636 and
https://github.com/zeitgeistpm/zeitgeist/issues/365.
regarding this fix, see <https://github.com/zeitgeistpm/zeitgeist/pull/636>
and <https://github.com/zeitgeistpm/zeitgeist/issues/365>.

- Made the `min_asset_amount_out` and `max_price` parameters of
`swap_exact_amount_in` and the `max_asset_amount_in` and `max_price`
Expand Down
1 change: 0 additions & 1 deletion primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ std = [
"sp-core/std",
"sp-runtime/std",
]
with-global-disputes = []

[package]
authors = ["Zeitgeist PM <[email protected]>"]
Expand Down
10 changes: 6 additions & 4 deletions primitives/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ use crate::types::{Balance, BlockNumber};
use frame_support::{parameter_types, PalletId};

// Definitions for time
pub const BLOCKS_PER_YEAR: BlockNumber = (BLOCKS_PER_DAY * 36525) / 100;
pub const BLOCKS_PER_DAY: BlockNumber = BLOCKS_PER_HOUR * 24;
pub const BLOCKS_PER_YEAR: BlockNumber = (BLOCKS_PER_DAY * 36525) / 100; // 2_629_800
pub const BLOCKS_PER_DAY: BlockNumber = BLOCKS_PER_HOUR * 24; // 7_200
pub const MILLISECS_PER_BLOCK: u32 = 12000;
pub const BLOCKS_PER_MINUTE: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber);
pub const BLOCKS_PER_HOUR: BlockNumber = BLOCKS_PER_MINUTE * 60;
pub const BLOCKS_PER_MINUTE: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber); // 5
pub const BLOCKS_PER_HOUR: BlockNumber = BLOCKS_PER_MINUTE * 60; // 300

// Definitions for currency
pub const BASE: u128 = 10_000_000_000;
Expand Down Expand Up @@ -70,6 +70,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
21 changes: 18 additions & 3 deletions primitives/src/constants/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,33 @@ parameter_types! {

// Court
parameter_types! {
pub const CourtCaseDuration: u64 = BLOCKS_PER_DAY;
pub const AppealBond: Balance = 5 * BASE;
pub const AppealBondFactor: Balance = 2 * BASE;
pub const BlocksPerYear: BlockNumber = 10000;
pub const CourtPalletId: PalletId = PalletId(*b"zge/cout");
pub const StakeWeight: u128 = 2 * BASE;
pub const RequestInterval: BlockNumber = 15;
pub const VotePeriod: BlockNumber = 3;
pub const AggregationPeriod: BlockNumber = 4;
pub const AppealPeriod: BlockNumber = 5;
pub const LockId: LockIdentifier = *b"zge/cloc";
pub const MaxAppeals: u32 = 4;
pub const MaxDelegations: u32 = 5;
pub const MaxSelectedDraws: u32 = 510;
pub const MaxCourtParticipants: u32 = 1_000;
pub const MinJurorStake: Balance = 50 * CENT;
pub const InflationPeriod: BlockNumber = 20;
}

// Global disputes parameters
parameter_types! {
pub const AddOutcomePeriod: BlockNumber = 20;
pub const GlobalDisputeLockId: LockIdentifier = *b"zge/vote";
pub const GlobalDisputesPalletId: PalletId = PalletId(*b"zge/gldp");
pub const MaxGlobalDisputeVotes: u32 = 50;
pub const MaxOwners: u32 = 10;
pub const MinOutcomeVoteAmount: Balance = 10 * CENT;
pub const RemoveKeysLimit: u32 = 250;
pub const GdVotingPeriod: BlockNumber = 140;
pub const VotingOutcomeFee: Balance = 100 * CENT;
}

Expand All @@ -60,7 +74,6 @@ parameter_types! {
pub const AdvisoryBond: Balance = 25 * CENT;
pub const DisputeBond: Balance = 5 * BASE;
pub const DisputeFactor: Balance = 2 * BASE;
pub const GlobalDisputePeriod: BlockNumber = 7 * BLOCKS_PER_DAY;
pub const MaxCategories: u16 = 10;
pub const MaxDisputeDuration: BlockNumber = 50;
pub const MaxDisputes: u16 = 6;
Expand All @@ -85,6 +98,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
27 changes: 25 additions & 2 deletions primitives/src/market.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,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 @@ -100,13 +101,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 @@ -175,11 +177,32 @@ pub enum MarketCreation {
Advised,
}

/// Defines a global dispute item for the initialisation of a global dispute.
#[derive(Clone, Decode, Encode, MaxEncodedLen, PartialEq, Eq, RuntimeDebug, TypeInfo)]
pub struct GlobalDisputeItem<AccountId, Balance> {
/// The account that already paid somehow for the outcome.
pub owner: AccountId,
/// The outcome that was already paid for
/// and should be added as vote outcome inside global disputes.
pub outcome: OutcomeReport,
/// The initial amount added in the global dispute vote system initially for the outcome.
pub initial_vote_amount: Balance,
}

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

/// How a market should resolve disputes
Expand Down
2 changes: 1 addition & 1 deletion primitives/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ mod market_id;
mod swaps;
mod zeitgeist_multi_reservable_currency;

pub use dispute_api::{DisputeApi, DisputeResolutionApi};
pub use dispute_api::{DisputeApi, DisputeMaxWeightApi, DisputeResolutionApi};
pub use market_commons_pallet_api::MarketCommonsPalletApi;
pub use market_id::MarketId;
pub use swaps::Swaps;
Expand Down
Loading