From 8bcf179c2f51f4f555b629420622751f38328b15 Mon Sep 17 00:00:00 2001 From: Alex Rea Date: Wed, 30 Nov 2022 22:01:47 +0000 Subject: [PATCH] Second attempt at fix for issue --- .../IReputationMiningCycle.sol | 7 ------ .../ReputationMiningCycle.sol | 14 ++++------- .../ReputationMiningCycleBinarySearch.sol | 4 ++-- .../ReputationMiningCycleCommon.sol | 4 ++-- .../ReputationMiningCycleRespond.sol | 2 +- docs/interfaces/ireputationminingcycle.md | 18 --------------- .../reputation-miner/ReputationMinerClient.js | 23 ++++++------------- test-smoke/colony-storage-consistent.js | 10 ++++---- 8 files changed, 22 insertions(+), 60 deletions(-) diff --git a/contracts/reputationMiningCycle/IReputationMiningCycle.sol b/contracts/reputationMiningCycle/IReputationMiningCycle.sol index 047a772333..1153377f72 100644 --- a/contracts/reputationMiningCycle/IReputationMiningCycle.sol +++ b/contracts/reputationMiningCycle/IReputationMiningCycle.sol @@ -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); - } diff --git a/contracts/reputationMiningCycle/ReputationMiningCycle.sol b/contracts/reputationMiningCycle/ReputationMiningCycle.sol index 87cf092b1e..1a6741c1b5 100644 --- a/contracts/reputationMiningCycle/ReputationMiningCycle.sol +++ b/contracts/reputationMiningCycle/ReputationMiningCycle.sol @@ -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" ); @@ -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" ); @@ -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" ); @@ -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" ); @@ -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); } ///////////////////////// diff --git a/contracts/reputationMiningCycle/ReputationMiningCycleBinarySearch.sol b/contracts/reputationMiningCycle/ReputationMiningCycleBinarySearch.sol index eac32713e4..50b52c078a 100644 --- a/contracts/reputationMiningCycle/ReputationMiningCycleBinarySearch.sol +++ b/contracts/reputationMiningCycle/ReputationMiningCycleBinarySearch.sol @@ -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" ); @@ -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" ); diff --git a/contracts/reputationMiningCycle/ReputationMiningCycleCommon.sol b/contracts/reputationMiningCycle/ReputationMiningCycleCommon.sol index 9b1bdf07f3..ab324f33fb 100644 --- a/contracts/reputationMiningCycle/ReputationMiningCycleCommon.sol +++ b/contracts/reputationMiningCycle/ReputationMiningCycleCommon.sol @@ -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; @@ -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; } } diff --git a/contracts/reputationMiningCycle/ReputationMiningCycleRespond.sol b/contracts/reputationMiningCycle/ReputationMiningCycleRespond.sol index a4a43f910d..e83e7efd49 100644 --- a/contracts/reputationMiningCycle/ReputationMiningCycleRespond.sol +++ b/contracts/reputationMiningCycle/ReputationMiningCycleRespond.sol @@ -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" ); diff --git a/docs/interfaces/ireputationminingcycle.md b/docs/interfaces/ireputationminingcycle.md index f3f92417b2..4133892364 100644 --- a/docs/interfaces/ireputationminingcycle.md +++ b/docs/interfaces/ireputationminingcycle.md @@ -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** @@ -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. diff --git a/packages/reputation-miner/ReputationMinerClient.js b/packages/reputation-miner/ReputationMinerClient.js index 41b14b8465..c8c44a9063 100644 --- a/packages/reputation-miner/ReputationMinerClient.js +++ b/packages/reputation-miner/ReputationMinerClient.js @@ -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; @@ -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); @@ -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); @@ -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); @@ -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); @@ -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) ); @@ -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(); } diff --git a/test-smoke/colony-storage-consistent.js b/test-smoke/colony-storage-consistent.js index b7f1ce8276..c72d16b4d9 100644 --- a/test-smoke/colony-storage-consistent.js +++ b/test-smoke/colony-storage-consistent.js @@ -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"); }); }); });