Skip to content

Commit

Permalink
Easy changes following first review
Browse files Browse the repository at this point in the history
  • Loading branch information
area committed Apr 13, 2022
1 parent c4dcafb commit 4679dbe
Show file tree
Hide file tree
Showing 14 changed files with 231 additions and 231 deletions.
4 changes: 2 additions & 2 deletions helpers/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const FINALIZED_TASK_STATE = 2;
const SECONDS_PER_DAY = 86400;

const MINING_CYCLE_DURATION = 60 * 60 * 1; // 1 hour
const DISPUTE_DEFENCE_WINDOW = 60 * 20; // Twenty minutes
const CHALLENGE_RESPONSE_WINDOW_DURATION = 60 * 20; // Twenty minutes
const ALL_ENTRIES_ALLOWED_END_OF_WINDOW = 60 * 10; // Ten minutes
const DECAY_RATE = {
NUMERATOR: new BN("999679150010889"), // eslint-disable-line prettier/prettier
Expand Down Expand Up @@ -109,7 +109,7 @@ module.exports = {
FINALIZED_TASK_STATE,
SECONDS_PER_DAY,
MINING_CYCLE_DURATION,
DISPUTE_DEFENCE_WINDOW,
CHALLENGE_RESPONSE_WINDOW_DURATION,
ALL_ENTRIES_ALLOWED_END_OF_WINDOW,
DECAY_RATE,
GLOBAL_SKILL_ID,
Expand Down
24 changes: 12 additions & 12 deletions helpers/test-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import BN from "bn.js";
import { ethers } from "ethers";
import { BigNumber } from "bignumber.js";

import { UINT256_MAX, MIN_STAKE, MINING_CYCLE_DURATION, DEFAULT_STAKE, DISPUTE_DEFENCE_WINDOW } from "./constants";
import { UINT256_MAX, MIN_STAKE, MINING_CYCLE_DURATION, DEFAULT_STAKE, CHALLENGE_RESPONSE_WINDOW_DURATION } from "./constants";

const IColony = artifacts.require("IColony");
const IMetaColony = artifacts.require("IMetaColony");
Expand Down Expand Up @@ -609,7 +609,7 @@ export async function runBinarySearch(client1, client2, test) {
// Binary search will error when it is complete.
let noError = true;
while (noError) {
await forwardTime(DISPUTE_DEFENCE_WINDOW, test);
await forwardTime(CHALLENGE_RESPONSE_WINDOW_DURATION, test);
try {
await client1.respondToBinarySearchForChallenge();
} catch (err) {
Expand All @@ -631,7 +631,7 @@ export async function getActiveRepCycle(colonyNetwork) {
}

export async function advanceMiningCycleNoContest({ colonyNetwork, client, minerAddress, test }) {
await forwardTime(MINING_CYCLE_DURATION + DISPUTE_DEFENCE_WINDOW, test);
await forwardTime(MINING_CYCLE_DURATION + CHALLENGE_RESPONSE_WINDOW_DURATION, test);
const repCycle = await getActiveRepCycle(colonyNetwork);

if (client !== undefined) {
Expand All @@ -655,7 +655,7 @@ export async function accommodateChallengeAndInvalidateHashViaTimeout(colonyNetw
const [round1, idx1] = await client1.getMySubmissionRoundAndIndex();
// Make a submission from client1
const submission1before = await repCycle.getReputationHashSubmission(client1.minerAddress);
await forwardTime(DISPUTE_DEFENCE_WINDOW, this);
await forwardTime(CHALLENGE_RESPONSE_WINDOW_DURATION, this);

// Submit JRH for submission 1 if needed
// We only do this if client2 is defined so that we test JRH submission in rounds other than round 0.
Expand All @@ -666,7 +666,7 @@ export async function accommodateChallengeAndInvalidateHashViaTimeout(colonyNetw
}

// Timeout the other client
await forwardTime(DISPUTE_DEFENCE_WINDOW, this);
await forwardTime(CHALLENGE_RESPONSE_WINDOW_DURATION, this);

const toInvalidateIdx = idx1.mod(2).eq(1) ? idx1.sub(1) : idx1.add(1);
const accounts = await web3GetAccounts();
Expand Down Expand Up @@ -716,11 +716,11 @@ export async function accommodateChallengeAndInvalidateHash(colonyNetwork, test,
toInvalidateIdx = idx1;
}
// Forward time, so that whichever has failed to respond by now has timed out.
await forwardTime(DISPUTE_DEFENCE_WINDOW * 2, test); // First window is the response window, second window is the invalidate window
await forwardTime(CHALLENGE_RESPONSE_WINDOW_DURATION * 2, test); // First window is the response window, second window is the invalidate window
} else {
toInvalidateIdx = idx1.mod(2).eq(1) ? idx1.sub(1) : idx1.add(1);
}
await forwardTime(DISPUTE_DEFENCE_WINDOW + 1, this);
await forwardTime(CHALLENGE_RESPONSE_WINDOW_DURATION + 1, this);

const signingAddress = await client1.realWallet.getAddress();
return repCycle.invalidateHash(round1, toInvalidateIdx, { from: signingAddress });
Expand All @@ -731,7 +731,7 @@ async function navigateChallenge(colonyNetwork, client1, client2, errors) {
const [round1, idx1] = await client1.getMySubmissionRoundAndIndex();
const submission1before = await repCycle.getReputationHashSubmission(client1.minerAddress);

await forwardTime(DISPUTE_DEFENCE_WINDOW);
await forwardTime(CHALLENGE_RESPONSE_WINDOW_DURATION);

// Submit JRH for submission 1 if needed
// We only do this if client2 is defined so that we test JRH submission in rounds other than round 0.
Expand All @@ -751,7 +751,7 @@ async function navigateChallenge(colonyNetwork, client1, client2, errors) {
"Clients are not facing each other in this round"
).to.be.true;

await forwardTime(DISPUTE_DEFENCE_WINDOW);
await forwardTime(CHALLENGE_RESPONSE_WINDOW_DURATION);

if (submission2before.jrhNLeaves === "0") {
if (errors.client2.confirmJustificationRootHash) {
Expand All @@ -771,7 +771,7 @@ async function navigateChallenge(colonyNetwork, client1, client2, errors) {
let binarySearchStep = -1;
let binarySearchError = false;
while (submission1.lowerBound !== submission1.upperBound && binarySearchError === false) {
await forwardTime(DISPUTE_DEFENCE_WINDOW);
await forwardTime(CHALLENGE_RESPONSE_WINDOW_DURATION);
binarySearchStep += 1;
if (errors.client1.respondToBinarySearchForChallenge[binarySearchStep]) {
await checkErrorRevertEthers(client1.respondToBinarySearchForChallenge(), errors.client1.respondToBinarySearchForChallenge[binarySearchStep]);
Expand Down Expand Up @@ -799,7 +799,7 @@ async function navigateChallenge(colonyNetwork, client1, client2, errors) {
return;
}

await forwardTime(DISPUTE_DEFENCE_WINDOW);
await forwardTime(CHALLENGE_RESPONSE_WINDOW_DURATION);

if (errors.client1.confirmBinarySearchResult) {
await checkErrorRevertEthers(client1.confirmBinarySearchResult(), errors.client1.confirmBinarySearchResult);
Expand All @@ -816,7 +816,7 @@ async function navigateChallenge(colonyNetwork, client1, client2, errors) {
return;
}

await forwardTime(DISPUTE_DEFENCE_WINDOW);
await forwardTime(CHALLENGE_RESPONSE_WINDOW_DURATION);

// Respond to the challenge - usually, only one of these should work.
// If both work, then the starting reputation is 0 and one client is lying
Expand Down
6 changes: 3 additions & 3 deletions packages/reputation-miner/ReputationMinerClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const disputeStages = {
CONFIRM_NEW_HASH: 5
}

const DISPUTE_DEFENCE_WINDOW = 1200;
const CHALLENGE_RESPONSE_WINDOW_DURATION = 20 * 60;

const cache = apicache.middleware

Expand Down Expand Up @@ -577,11 +577,11 @@ class ReputationMinerClient {
// Has our opponent timed out?
// TODO: Remove these magic numbers

const opponentTimeout = ethers.BigNumber.from(block.timestamp).sub(oppEntry.lastResponseTimestamp).gte(DISPUTE_DEFENCE_WINDOW);
const opponentTimeout = ethers.BigNumber.from(block.timestamp).sub(oppEntry.lastResponseTimestamp).gte(CHALLENGE_RESPONSE_WINDOW_DURATION);
if (opponentTimeout){
const responsePossible = await repCycle.getResponsePossible(
disputeStages.INVALIDATE_HASH,
ethers.BigNumber.from(oppEntry.lastResponseTimestamp).add(DISPUTE_DEFENCE_WINDOW)
ethers.BigNumber.from(oppEntry.lastResponseTimestamp).add(CHALLENGE_RESPONSE_WINDOW_DURATION)
);
if (responsePossible) {
// If so, invalidate them.
Expand Down
8 changes: 4 additions & 4 deletions test-chainid/chainid-dependent-behaviour.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
MINING_CYCLE_DURATION,
DEFAULT_STAKE,
MIN_STAKE,
DISPUTE_DEFENCE_WINDOW,
CHALLENGE_RESPONSE_WINDOW_DURATION,
WAD,
ALL_ENTRIES_ALLOWED_END_OF_WINDOW,
} from "../helpers/constants";
Expand Down Expand Up @@ -118,12 +118,12 @@ contract("Contract Storage", (accounts) => {

const rewardSize = await repCycle.getDisputeRewardSize();

await forwardTime(MINING_CYCLE_DURATION / 2 + DISPUTE_DEFENCE_WINDOW * 2 + 1, this);
await forwardTime(MINING_CYCLE_DURATION / 2 + CHALLENGE_RESPONSE_WINDOW_DURATION * 2 + 1, this);

await repCycle.invalidateHash(0, 0, { from: MINER1 });
await repCycle.invalidateHash(0, 3, { from: MINER1 });

await forwardTime(DISPUTE_DEFENCE_WINDOW - ALL_ENTRIES_ALLOWED_END_OF_WINDOW + 1, this);
await forwardTime(CHALLENGE_RESPONSE_WINDOW_DURATION - ALL_ENTRIES_ALLOWED_END_OF_WINDOW + 1, this);
const networkBalanceBefore = await clnyToken.balanceOf(colonyNetwork.address);
const tx = await repCycle.confirmNewHash(1, { from: MINER1 });

Expand Down Expand Up @@ -161,7 +161,7 @@ contract("Contract Storage", (accounts) => {
await repCycle.getNSubmissionsForHash("0x12345678", 10, "0x00");
await repCycle.submitRootHash("0x12345678", 10, "0x00", 1, { from: MINER1 });

await forwardTime(DISPUTE_DEFENCE_WINDOW + 1, this);
await forwardTime(CHALLENGE_RESPONSE_WINDOW_DURATION + 1, this);
const tx = await repCycle.confirmNewHash(0, { from: MINER1 });
await expectNoEvent(tx, "Transfer(address indexed,address indexed,uint256)", [colonyNetwork.address, metaColony.address, 0]);
await expectNoEvent(tx, "Burn(address indexed,uint256)", [colonyNetwork.address, 0]);
Expand Down
4 changes: 2 additions & 2 deletions test-gas-costs/gasCosts.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
DEFAULT_STAKE,
INITIAL_FUNDING,
GLOBAL_SKILL_ID,
DISPUTE_DEFENCE_WINDOW,
CHALLENGE_RESPONSE_WINDOW_DURATION,
} from "../helpers/constants";

import {
Expand Down Expand Up @@ -267,7 +267,7 @@ contract("All", function (accounts) {
client2: { respondToChallenge: "colony-reputation-mining-increased-reputation-value-incorrect" },
});
const repCycle = await getActiveRepCycle(colonyNetwork);
await forwardTime(DISPUTE_DEFENCE_WINDOW + 1, this);
await forwardTime(CHALLENGE_RESPONSE_WINDOW_DURATION + 1, this);
await repCycle.confirmNewHash(2, { from: STAKER1 });

// withdraw
Expand Down
4 changes: 2 additions & 2 deletions test/contracts-network/reputation-basic-functionality.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import bnChai from "bn-chai";
import { ethers } from "ethers";

import { giveUserCLNYTokens, giveUserCLNYTokensAndStake } from "../../helpers/test-data-generator";
import { MIN_STAKE, MINING_CYCLE_DURATION, DECAY_RATE, DISPUTE_DEFENCE_WINDOW } from "../../helpers/constants";
import { MIN_STAKE, MINING_CYCLE_DURATION, DECAY_RATE, CHALLENGE_RESPONSE_WINDOW_DURATION } from "../../helpers/constants";
import { forwardTime, checkErrorRevert, getActiveRepCycle, advanceMiningCycleNoContest, getBlockTime } from "../../helpers/test-helper";

const { expect } = chai;
Expand Down Expand Up @@ -192,7 +192,7 @@ contract("Reputation mining - basic functionality", (accounts) => {
expect(nSubmissionsForHash).to.eq.BN(1);

// Cleanup
await forwardTime(DISPUTE_DEFENCE_WINDOW + 1, this);
await forwardTime(CHALLENGE_RESPONSE_WINDOW_DURATION + 1, this);
await repCycle.confirmNewHash(0, { from: MINER1 });
});
});
Expand Down
4 changes: 2 additions & 2 deletions test/extensions/funding-queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import bnChai from "bn-chai";
import { ethers } from "ethers";
import { soliditySha3 } from "web3-utils";

import { UINT256_MAX, WAD, MINING_CYCLE_DURATION, SECONDS_PER_DAY, DISPUTE_DEFENCE_WINDOW } from "../../helpers/constants";
import { UINT256_MAX, WAD, MINING_CYCLE_DURATION, SECONDS_PER_DAY, CHALLENGE_RESPONSE_WINDOW_DURATION } from "../../helpers/constants";

import {
checkErrorRevert,
Expand Down Expand Up @@ -161,7 +161,7 @@ contract("Funding Queues", (accounts) => {

const rootHash = await reputationTree.getRootHash();
const repCycle = await getActiveRepCycle(colonyNetwork);
await forwardTime(MINING_CYCLE_DURATION + DISPUTE_DEFENCE_WINDOW + 1, this);
await forwardTime(MINING_CYCLE_DURATION + CHALLENGE_RESPONSE_WINDOW_DURATION + 1, this);
await repCycle.submitRootHash(rootHash, 0, "0x00", 10, { from: MINER });
await repCycle.confirmNewHash(0, { from: MINER });
});
Expand Down
6 changes: 3 additions & 3 deletions test/extensions/voting-rep.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import shortid from "shortid";
import { ethers } from "ethers";
import { soliditySha3 } from "web3-utils";

import { UINT256_MAX, WAD, MINING_CYCLE_DURATION, SECONDS_PER_DAY, DISPUTE_DEFENCE_WINDOW } from "../../helpers/constants";
import { UINT256_MAX, WAD, MINING_CYCLE_DURATION, SECONDS_PER_DAY, CHALLENGE_RESPONSE_WINDOW_DURATION } from "../../helpers/constants";

import {
checkErrorRevert,
Expand Down Expand Up @@ -229,7 +229,7 @@ contract("Voting Reputation", (accounts) => {
const repCycle = await getActiveRepCycle(colonyNetwork);
await forwardTime(MINING_CYCLE_DURATION, this);
await repCycle.submitRootHash(rootHash, 0, "0x00", 10, { from: MINER });
await forwardTime(DISPUTE_DEFENCE_WINDOW + 1, this);
await forwardTime(CHALLENGE_RESPONSE_WINDOW_DURATION + 1, this);
await repCycle.confirmNewHash(0, { from: MINER });
});

Expand Down Expand Up @@ -1059,7 +1059,7 @@ contract("Voting Reputation", (accounts) => {

const repCycle = await getActiveRepCycle(colonyNetwork);
await repCycle.submitRootHash(rootHash, 0, "0x00", 10, { from: MINER });
await forwardTime(DISPUTE_DEFENCE_WINDOW + 1, this);
await forwardTime(CHALLENGE_RESPONSE_WINDOW_DURATION + 1, this);
await repCycle.confirmNewHash(0, { from: MINER });

// Create new motion with new reputation state
Expand Down
Loading

0 comments on commit 4679dbe

Please sign in to comment.