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

Court: Max regular appeal round tweaks #93

Merged
merged 1 commit into from Aug 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 13 additions & 8 deletions contracts/Court.sol
Expand Up @@ -20,9 +20,9 @@ contract Court is IJurorsRegistryOwner, ICRVotingOwner, ISubscriptionsOwner {
using SafeERC20 for ERC20;
using SafeMath for uint256;

uint256 internal constant MAX_JURORS_PER_DRAFT_BATCH = 10; // to cap gas used on draft
uint256 internal constant FINAL_ROUND_WEIGHT_PRECISION = 1000; // to improve roundings
uint64 internal constant APPEAL_STEP_FACTOR = 3;
uint256 internal constant MAX_JURORS_PER_DRAFT_BATCH = 10; // to cap gas used on draft
uint256 internal constant MAX_REGULAR_APPEAL_ROUNDS_LIMIT = 10; // to cap the max number of regular appeal rounds
uint256 internal constant FINAL_ROUND_WEIGHT_PRECISION = 1000; // to improve roundings
// TODO: move all other constants up here

struct CourtConfig {
Expand All @@ -38,6 +38,7 @@ contract Court is IJurorsRegistryOwner, ICRVotingOwner, ISubscriptionsOwner {
uint64 appealTerms;
uint16 penaltyPct;
uint16 finalRoundReduction; // ‱ of reduction applied for final appeal round (1/10,000)
uint64 appealStepFactor;
uint32 maxRegularAppealRounds; // before the final appeal
}

Expand Down Expand Up @@ -136,7 +137,7 @@ contract Court is IJurorsRegistryOwner, ICRVotingOwner, ISubscriptionsOwner {
string internal constant ERROR_JUROR_ALREADY_REWARDED = "CTJUROR_ALRDY_REWARDED";
string internal constant ERROR_JUROR_NOT_COHERENT = "CTJUROR_INCOHERENT";
string internal constant ERROR_WRONG_PENALTY_PCT = "CTBAD_PENALTY";
string internal constant ERROR_ZERO_MAX_ROUNDS = "COURT_ZERO_MAX_ROUNDS";
string internal constant ERROR_INVALID_MAX_APPEAL_ROUNDS = "CTINVALID_MAX_APPEAL_ROUNDS";

uint64 internal constant ZERO_TERM_ID = 0; // invalid term that doesn't accept disputes
uint64 internal constant MODIFIER_ALLOWED_TERM_TRANSITIONS = 1;
Expand Down Expand Up @@ -205,6 +206,7 @@ contract Court is IJurorsRegistryOwner, ICRVotingOwner, ISubscriptionsOwner {
uint256 _minJurorsActiveBalance,
uint64[3] _roundStateDurations,
uint16[2] _pcts, //_penaltyPct, _finalRoundReduction
uint64 _appealStepFactor,
uint32 _maxRegularAppealRounds,
uint256[5] _subscriptionParams // _periodDuration, _feeAmount, _prePaymentPeriods, _latePaymentPenaltyPct, _governorSharePct
) public {
Expand Down Expand Up @@ -232,6 +234,7 @@ contract Court is IJurorsRegistryOwner, ICRVotingOwner, ISubscriptionsOwner {
_roundStateDurations,
_pcts[0], // _penaltyPct
_pcts[1], // _finalRoundReduction
_appealStepFactor,
_maxRegularAppealRounds
);
terms[ZERO_TERM_ID].startTime = _firstTermStartTime - _termDuration;
Expand Down Expand Up @@ -404,14 +407,14 @@ contract Court is IJurorsRegistryOwner, ICRVotingOwner, ISubscriptionsOwner {
uint64 appealDraftTermId = termId + 1; // Appeals are drafted in the next term

uint256 roundId;
if (_roundId == config.maxRegularAppealRounds - 1) { // final round, roundId starts at 0
if (_roundId >= config.maxRegularAppealRounds - 1) { // final round, roundId starts at 0
// number of jurors will be the number of times the minimum stake is hold in the registry, multiplied by a precision factor for division roundings
(roundId, appealJurorNumber) = _newFinalAdjudicationRound(_disputeId, appealDraftTermId);
} else {
// no need for more checks, as final appeal won't ever be in Appealable state,
// so it would never reach here (first check would fail), but we add this as a sanity check
assert(_roundId < config.maxRegularAppealRounds);
appealJurorNumber = APPEAL_STEP_FACTOR * currentRound.jurorNumber;
appealJurorNumber = config.appealStepFactor * currentRound.jurorNumber;
// make sure it's odd
if (appealJurorNumber % 2 == 0) {
appealJurorNumber++;
Expand Down Expand Up @@ -669,7 +672,7 @@ contract Court is IJurorsRegistryOwner, ICRVotingOwner, ISubscriptionsOwner {
CourtConfig storage config = courtConfigs[terms[round.draftTermId].courtConfigId];

// for the final round
if (roundId == config.maxRegularAppealRounds) {
if (roundId >= config.maxRegularAppealRounds) {
return _canCommitFinalRound(disputeId, roundId, _voter);
}

Expand Down Expand Up @@ -909,6 +912,7 @@ contract Court is IJurorsRegistryOwner, ICRVotingOwner, ISubscriptionsOwner {
uint64[3] _roundStateDurations,
uint16 _penaltyPct,
uint16 _finalRoundReduction,
uint64 _appealStepFactor,
uint32 _maxRegularAppealRounds
)
internal
Expand All @@ -920,7 +924,7 @@ contract Court is IJurorsRegistryOwner, ICRVotingOwner, ISubscriptionsOwner {
// We make sure that when applying penalty pct to juror min stake it doesn't result in zero
uint256 minJurorsActiveBalance = jurorsRegistry.minJurorsActiveBalance();
require(uint256(_penaltyPct) * minJurorsActiveBalance >= PCT_BASE, ERROR_WRONG_PENALTY_PCT);
require(_maxRegularAppealRounds > uint32(0), ERROR_ZERO_MAX_ROUNDS);
require(_maxRegularAppealRounds > uint32(0) && _maxRegularAppealRounds <= MAX_REGULAR_APPEAL_ROUNDS_LIMIT, ERROR_INVALID_MAX_APPEAL_ROUNDS);

for (uint i = 0; i < _roundStateDurations.length; i++) {
require(_roundStateDurations[i] > 0, ERROR_CONFIG_PERIOD_ZERO_TERMS);
Expand All @@ -941,6 +945,7 @@ contract Court is IJurorsRegistryOwner, ICRVotingOwner, ISubscriptionsOwner {
appealTerms: _roundStateDurations[2],
penaltyPct: _penaltyPct,
finalRoundReduction: _finalRoundReduction,
appealStepFactor: _appealStepFactor,
maxRegularAppealRounds: _maxRegularAppealRounds
});

Expand Down
9 changes: 4 additions & 5 deletions contracts/test/CourtMock.sol
Expand Up @@ -20,6 +20,7 @@ contract CourtMock is Court {
uint256 _jurorMinStake,
uint64[3] _roundStateDurations,
uint16[2] _pcts,
uint64 _appealStepFactor,
uint32 _maxRegularAppealRounds,
uint256[5] _subscriptionParams // _periodDuration, _feeAmount, _prePaymentPeriods, _latePaymentPenaltyPct, _governorSharePct
)
Expand All @@ -36,7 +37,9 @@ contract CourtMock is Court {
_jurorMinStake,
_roundStateDurations,
_pcts,
_maxRegularAppealRounds,_subscriptionParams
_appealStepFactor,
_maxRegularAppealRounds,
_subscriptionParams
)
public
{}
Expand Down Expand Up @@ -71,10 +74,6 @@ contract CourtMock is Court {
return MAX_JURORS_PER_DRAFT_BATCH;
}

function getAppealStepFactor() public pure returns (uint64) {
return APPEAL_STEP_FACTOR;
}

function getAdjudicationState(uint256 _disputeId, uint256 _roundId, uint64 _termId) public view returns (AdjudicationState) {
return _adjudicationStateAtTerm(_disputeId, _roundId, _termId);
}
Expand Down
1 change: 1 addition & 0 deletions test/court-batches.js
Expand Up @@ -90,6 +90,7 @@ contract('Court: Batches', ([ rich, governor, arbitrable, juror1, juror2, juror3
jurorMinStake,
[ commitTerms, appealTerms, revealTerms ],
[ penaltyPct, finalRoundReduction ],
3,
4,
[ 0, 0, 0, 0, 0 ]
)
Expand Down
1 change: 1 addition & 0 deletions test/court-disputes.js
Expand Up @@ -125,6 +125,7 @@ contract('Court: Disputes', ([ poor, rich, governor, juror1, juror2, juror3, oth
jurorMinStake,
[ commitTerms, appealTerms, revealTerms ],
[ penaltyPct, finalRoundReduction ],
3,
4,
[ 0, 0, 0, 0, 0 ]
)
Expand Down
5 changes: 2 additions & 3 deletions test/court-final-appeal-non-exact.js
Expand Up @@ -40,7 +40,6 @@ contract('Court: final appeal (non-exact)', ([ poor, rich, governor, juror1, jur
const NO_DATA = ''
const ZERO_ADDRESS = '0x' + '00'.repeat(20)
const SETTLE_BATCH_SIZE = 15
let APPEAL_STEP_FACTOR
const DECIMALS = 1e18

const termDuration = 10
Expand All @@ -52,6 +51,7 @@ contract('Court: final appeal (non-exact)', ([ poor, rich, governor, juror1, jur
const appealTerms = 1
const penaltyPct = 100 // 100‱ = 1%
const finalRoundReduction = 3300 // 100‱ = 1%
const APPEAL_STEP_FACTOR = 3
const MAX_REGULAR_APPEAL_ROUNDS = 4

const initialBalance = new web3.BigNumber(1e6).mul(DECIMALS)
Expand Down Expand Up @@ -106,12 +106,11 @@ contract('Court: final appeal (non-exact)', ([ poor, rich, governor, juror1, jur
jurorMinStake,
[ commitTerms, appealTerms, revealTerms ],
[ penaltyPct, finalRoundReduction ],
APPEAL_STEP_FACTOR,
MAX_REGULAR_APPEAL_ROUNDS,
[ 0, 0, 0, 0, 0 ]
)

APPEAL_STEP_FACTOR = (await this.court.getAppealStepFactor.call()).toNumber()

await this.jurorsRegistry.mock_hijackTreeSearch()
await this.court.mock_setBlockNumber(startBlock)

Expand Down
4 changes: 2 additions & 2 deletions test/court-final-appeal.js
Expand Up @@ -42,9 +42,9 @@ contract('Court: final appeal', ([ poor, rich, governor, juror1, juror2, juror3,
const NO_DATA = ''
const ZERO_ADDRESS = '0x' + '00'.repeat(20)
const SETTLE_BATCH_SIZE = 40
const APPEAL_STEP_FACTOR = 3
const MAX_REGULAR_APPEAL_ROUNDS = 4
let MAX_JURORS_PER_DRAFT_BATCH
let APPEAL_STEP_FACTOR

const termDuration = 10
const firstTermStart = 10
Expand Down Expand Up @@ -115,12 +115,12 @@ contract('Court: final appeal', ([ poor, rich, governor, juror1, juror2, juror3,
jurorMinStake,
[ commitTerms, appealTerms, revealTerms ],
[ penaltyPct, finalRoundReduction ],
APPEAL_STEP_FACTOR,
MAX_REGULAR_APPEAL_ROUNDS,
[ 0, 0, 0, 0, 0 ]
)

MAX_JURORS_PER_DRAFT_BATCH = (await this.court.getMaxJurorsPerDraftBatch.call()).toNumber()
APPEAL_STEP_FACTOR = (await this.court.getAppealStepFactor.call()).toNumber()

await this.court.mock_setBlockNumber(startBlock)

Expand Down
1 change: 1 addition & 0 deletions test/court-init.js
Expand Up @@ -68,6 +68,7 @@ contract('Court: init', ([ governor ]) => {
jurorMinStake,
[ commitTerms, appealTerms, revealTerms ],
[ penaltyPct, finalRoundReduction ],
3,
4,
[ 0, 0, 0, 0, 0 ]
),
Expand Down
1 change: 1 addition & 0 deletions test/court-lifecycle.js
Expand Up @@ -86,6 +86,7 @@ contract('Court: Lifecycle', ([ poor, rich, governor, juror1, juror2 ]) => {
jurorMinStake,
[ commitTerms, appealTerms, revealTerms ],
[ penaltyPct, finalRoundReduction ],
3,
4,
[ 0, 0, 0, 0, 0 ]
)
Expand Down