Skip to content

Commit

Permalink
Second attempt at fix for issue
Browse files Browse the repository at this point in the history
  • Loading branch information
area authored and kronosapiens committed Dec 15, 2022
1 parent fecec7e commit 8bcf179
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 60 deletions.
7 changes: 0 additions & 7 deletions contracts/reputationMiningCycle/IReputationMiningCycle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -271,12 +271,5 @@ interface IReputationMiningCycle is ReputationMiningCycleDataTypes {
/// enum in ReputationMiningCycleDataTypes
/// @param _since The timestamp the last response for the submission in the dispute in question was made at.
/// @return possible bool Whether the user can respond at the current time.
/// @dev Deprecated
function getResponsePossible(DisputeStages _stage, uint256 _since) external view returns (bool possible);

/// @notice Returns whether the caller is able to currently respond to a dispute stage.
/// @param _since The timestamp the last response for the submission in the dispute in question was made at.
/// @return possible bool Whether the user can respond at the current time.
function getResponsePossible(uint256 _since) external view returns (bool possible);

}
14 changes: 5 additions & 9 deletions contracts/reputationMiningCycle/ReputationMiningCycle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ contract ReputationMiningCycle is ReputationMiningCycleCommon {
require(submissionWindowClosed(), "colony-reputation-mining-submission-window-still-open");

require(
responsePossible(disputeRounds[_roundNumber][0].lastResponseTimestamp),
responsePossible(DisputeStages.ConfirmNewHash, disputeRounds[_roundNumber][0].lastResponseTimestamp),
"colony-reputation-mining-user-ineligible-to-respond"
);

Expand Down Expand Up @@ -256,7 +256,7 @@ contract ReputationMiningCycle is ReputationMiningCycleCommon {

// Is the person making this call eligible to?
require(
responsePossible(disputeRounds[_round][opponentIdx].lastResponseTimestamp),
responsePossible(DisputeStages.InvalidateHash, disputeRounds[_round][opponentIdx].lastResponseTimestamp),
"colony-reputation-mining-user-ineligible-to-respond"
);

Expand Down Expand Up @@ -292,7 +292,7 @@ contract ReputationMiningCycle is ReputationMiningCycleCommon {

// The submission can be invalidated - now check the person invalidating is allowed to
require(
responsePossible(add(disputeRounds[_round][_idx].lastResponseTimestamp, CHALLENGE_RESPONSE_WINDOW_DURATION)),
responsePossible(DisputeStages.InvalidateHash, add(disputeRounds[_round][_idx].lastResponseTimestamp, CHALLENGE_RESPONSE_WINDOW_DURATION)),
"colony-reputation-mining-user-ineligible-to-respond"
);

Expand Down Expand Up @@ -350,7 +350,7 @@ contract ReputationMiningCycle is ReputationMiningCycleCommon {
require(submissionWindowClosed(), "colony-reputation-mining-cycle-submissions-not-closed");
require(_index < disputeRounds[_round].length, "colony-reputation-mining-index-beyond-round-length");
require(
responsePossible(disputeRounds[_round][_index].lastResponseTimestamp),
responsePossible(DisputeStages.ConfirmNewHash, disputeRounds[_round][_index].lastResponseTimestamp),
"colony-reputation-mining-user-ineligible-to-respond"
);

Expand Down Expand Up @@ -500,11 +500,7 @@ contract ReputationMiningCycle is ReputationMiningCycleCommon {
}

function getResponsePossible(DisputeStages _stage, uint256 _since) external view returns (bool) {
return responsePossible(_since);
}

function getResponsePossible(uint256 _since) external view returns (bool) {
return responsePossible(_since);
return responsePossible(_stage, _since);
}

/////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ contract ReputationMiningCycleBinarySearch is ReputationMiningCycleCommon {
require(_idx < disputeRounds[_round].length, "colony-reputation-mining-index-beyond-round-length");
require(disputeRounds[_round][_idx].lowerBound != disputeRounds[_round][_idx].upperBound, "colony-reputation-mining-challenge-not-active");
require(
responsePossible(disputeRounds[_round][_idx].lastResponseTimestamp),
responsePossible(DisputeStages.BinarySearchResponse, disputeRounds[_round][_idx].lastResponseTimestamp),
"colony-reputation-mining-user-ineligible-to-respond"
);

Expand Down Expand Up @@ -87,7 +87,7 @@ contract ReputationMiningCycleBinarySearch is ReputationMiningCycleCommon {
"colony-reputation-binary-search-result-already-confirmed"
);
require(
responsePossible(disputeRounds[_round][_idx].lastResponseTimestamp),
responsePossible(DisputeStages.BinarySearchConfirm, disputeRounds[_round][_idx].lastResponseTimestamp),
"colony-reputation-mining-user-ineligible-to-respond"
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ contract ReputationMiningCycleCommon is ReputationMiningCycleStorage, PatriciaTr
uint256 constant CHALLENGE_RESPONSE_WINDOW_DURATION = 60 * 20;
uint256 constant Y = UINT256_MAX / (CHALLENGE_RESPONSE_WINDOW_DURATION - ALL_ENTRIES_ALLOWED_END_OF_WINDOW);

function responsePossible(uint256 _responseWindowOpened) internal view returns (bool) {
function responsePossible(DisputeStages _stage, uint256 _responseWindowOpened) internal view returns (bool) {
if (_responseWindowOpened > block.timestamp) {
// I don't think this is currently possible, but belt and braces!
return false;
Expand All @@ -162,7 +162,7 @@ contract ReputationMiningCycleCommon is ReputationMiningCycleStorage, PatriciaTr
return false;
}
uint256 target = windowOpenFor * Y;
if (uint256(keccak256(abi.encodePacked(minerAddress, _responseWindowOpened))) > target) {
if (uint256(keccak256(abi.encodePacked(minerAddress, address(this), _stage))) > target) {
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ contract ReputationMiningCycleRespond is ReputationMiningCycleCommon {
challengeOpen(_u[U_ROUND], _u[U_IDX])
{
require(
responsePossible(disputeRounds[_u[U_ROUND]][_u[U_IDX]].lastResponseTimestamp),
responsePossible(DisputeStages.RespondToChallenge, disputeRounds[_u[U_ROUND]][_u[U_IDX]].lastResponseTimestamp),
"colony-reputation-mining-user-ineligible-to-respond"
);

Expand Down
18 changes: 0 additions & 18 deletions docs/interfaces/ireputationminingcycle.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@ Get the length of the ReputationUpdateLog stored on this instance of the Reputat

Returns whether the caller is able to currently respond to a dispute stage.

*Note: Deprecated*

**Parameters**

Expand All @@ -292,23 +291,6 @@ Returns whether the caller is able to currently respond to a dispute stage.
|---|---|---|
|possible|bool|bool Whether the user can respond at the current time.

### `getResponsePossible(uint256 _since):bool possible`

Returns whether the caller is able to currently respond to a dispute stage.


**Parameters**

|Name|Type|Description|
|---|---|---|
|_since|uint256|The timestamp the last response for the submission in the dispute in question was made at.

**Return Parameters**

|Name|Type|Description|
|---|---|---|
|possible|bool|bool Whether the user can respond at the current time.

### `getSubmissionUser(bytes32 _hash, uint256 _nLeaves, bytes32 _jrh, uint256 _index):address user`

Get the address that made a particular submission.
Expand Down
23 changes: 7 additions & 16 deletions packages/reputation-miner/ReputationMinerClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ class ReputationMinerClient {
const oppSubmission = await repCycle.getReputationHashSubmission(oppEntry.firstSubmitter);

if (oppSubmission.proposedNewRootHash === ethers.constants.AddressZero){
const responsePossible = await repCycle["getResponsePossible(uint8,uint256)"](disputeStages.INVALIDATE_HASH, entry.lastResponseTimestamp);
const responsePossible = await repCycle.getResponsePossible(disputeStages.INVALIDATE_HASH, entry.lastResponseTimestamp);
if (!responsePossible) {
this.endDoBlockChecks();
return;
Expand Down Expand Up @@ -507,7 +507,7 @@ class ReputationMinerClient {
// Before checking if our opponent has timed out yet, check if we can respond to something
// 1. Do we still need to confirm JRH?
if (submission.jrhNLeaves.eq(0)) {
const responsePossible = await repCycle["getResponsePossible(uint8,uint256)"](disputeStages.CONFIRM_JRH, entry.lastResponseTimestamp);
const responsePossible = await repCycle.getResponsePossible(disputeStages.CONFIRM_JRH, entry.lastResponseTimestamp);
if (responsePossible){
const gasPrice = await updateGasEstimate("fast", this.chainId, this._adapter);
await this._miner.setGasPrice(gasPrice);
Expand All @@ -522,10 +522,7 @@ class ReputationMinerClient {
// We can respond if neither of us have responded to this stage yet or
// if they have responded already
if (oppEntry.challengeStepCompleted.gte(entry.challengeStepCompleted)) {
const responsePossible = await repCycle["getResponsePossible(uint8,uint256)"](
disputeStages.BINARY_SEARCH_RESPONSE,
entry.lastResponseTimestamp
);
const responsePossible = await repCycle.getResponsePossible(disputeStages.BINARY_SEARCH_RESPONSE, entry.lastResponseTimestamp);
if (responsePossible){
const gasPrice = await updateGasEstimate("fast", this.chainId, this._adapter);
await this._miner.setGasPrice(gasPrice);
Expand All @@ -543,10 +540,7 @@ class ReputationMinerClient {
ethers.BigNumber.from(2).pow(entry.challengeStepCompleted.sub(2)).lte(submission.jrhNLeaves)
)
{
const responsePossible = await repCycle["getResponsePossible(uint8,uint256)"](
disputeStages.BINARY_SEARCH_CONFIRM,
entry.lastResponseTimestamp
);
const responsePossible = await repCycle.getResponsePossible(disputeStages.BINARY_SEARCH_CONFIRM, entry.lastResponseTimestamp);
if (responsePossible){
const gasPrice = await updateGasEstimate("fast", this.chainId, this._adapter);
await this._miner.setGasPrice(gasPrice);
Expand All @@ -564,10 +558,7 @@ class ReputationMinerClient {
ethers.BigNumber.from(2).pow(entry.challengeStepCompleted.sub(3)).lte(submission.jrhNLeaves)
)
{
const responsePossible = await repCycle["getResponsePossible(uint8,uint256)"](
disputeStages.RESPOND_TO_CHALLENGE,
entry.lastResponseTimestamp
);
const responsePossible = await repCycle.getResponsePossible(disputeStages.RESPOND_TO_CHALLENGE, entry.lastResponseTimestamp);
if (responsePossible){
const gasPrice = await updateGasEstimate("fast", this.chainId, this._adapter);
await this._miner.setGasPrice(gasPrice);
Expand All @@ -581,7 +572,7 @@ class ReputationMinerClient {

const opponentTimeout = ethers.BigNumber.from(block.timestamp).sub(oppEntry.lastResponseTimestamp).gte(CHALLENGE_RESPONSE_WINDOW_DURATION);
if (opponentTimeout){
const responsePossible = await repCycle["getResponsePossible(uint8,uint256)"](
const responsePossible = await repCycle.getResponsePossible(
disputeStages.INVALIDATE_HASH,
ethers.BigNumber.from(oppEntry.lastResponseTimestamp).add(CHALLENGE_RESPONSE_WINDOW_DURATION)
);
Expand All @@ -604,7 +595,7 @@ class ReputationMinerClient {
const disputeRound = await repCycle.getDisputeRound(round);
const entry = disputeRound[index];

const responsePossible = await repCycle["getResponsePossible(uint8,uint256)"](disputeStages.CONFIRM_NEW_HASH, entry.lastResponseTimestamp);
const responsePossible = await repCycle.getResponsePossible(disputeStages.CONFIRM_NEW_HASH, entry.lastResponseTimestamp);
if (responsePossible){
await this.confirmEntry();
}
Expand Down
10 changes: 5 additions & 5 deletions test-smoke/colony-storage-consistent.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,11 @@ contract("Contract Storage", (accounts) => {
console.log("miningCycleStateHash:", miningCycleStateHash);
console.log("tokenLockingStateHash:", tokenLockingStateHash);

expect(colonyNetworkStateHash).to.equal("0x77e04702d554bbcff2c36be7ccce767adce92a13c135a9cd279dd3f7415b093b");
expect(colonyStateHash).to.equal("0x4e90fcbe58b79118b2a2c09dd96c2cefe46f732b18b1d6230a361c0332133dec");
expect(metaColonyStateHash).to.equal("0x6be6cb630afd143ac7db391fb52150d3b817443b59206497e36aa4ffbeca5c1a");
expect(miningCycleStateHash).to.equal("0x20b0a911563ceab3018f750b12c1dda75608436d3f67abb061a1201434931028");
expect(tokenLockingStateHash).to.equal("0xc9fa6f26cac13030e857f1c4aeb6057d65a0d196a11e69c152483aa382270a2a");
expect(colonyNetworkStateHash).to.equal("0xa9289d3025a1f5e108b7b68f335327c1c5748015db91c78978679ba9832984e1");
expect(colonyStateHash).to.equal("0x54a0edcb2097270bd95d610dc827869cc827241d131461f58788f7c3257ca151");
expect(metaColonyStateHash).to.equal("0x15fab25907cfb6baedeaf1fdabd68678d37584a1817a08dfe77db60db378a508");
expect(miningCycleStateHash).to.equal("0x632d459a2197708bd2dbde87e8275c47dddcdf16d59e3efd21dcef9acb2a7366");
expect(tokenLockingStateHash).to.equal("0x30fbcbfbe589329fe20288101faabe1f60a4610ae0c0effb15526c6b390a8e07");
});
});
});

0 comments on commit 8bcf179

Please sign in to comment.