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 committed Dec 8, 2022
1 parent 2b45f6b commit 6f841ed
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("0xe569866a96f732ca1330414c3fd405f8a78577fb0d2841c01d8bdef3a8acd13f");
expect(colonyStateHash).to.equal("0x9f135d0fa07f45af99aac3199e37272783875fd506be6060c665d42f582dcbe9");
expect(metaColonyStateHash).to.equal("0x6be6cb630afd143ac7db391fb52150d3b817443b59206497e36aa4ffbeca5c1a");
expect(miningCycleStateHash).to.equal("0x20b0a911563ceab3018f750b12c1dda75608436d3f67abb061a1201434931028");
expect(tokenLockingStateHash).to.equal("0xc9fa6f26cac13030e857f1c4aeb6057d65a0d196a11e69c152483aa382270a2a");
expect(colonyNetworkStateHash).to.equal("0xa59c636e6dc71c79ac297dc2419e21f94e3bab0d47ada0723821b1c6fabebaf5");
expect(colonyStateHash).to.equal("0x7bb6c8a0c01bf0eda1b51e28739f3e7c43bc6bca8bb62331465b62dc6c5f7983");
expect(metaColonyStateHash).to.equal("0x15fab25907cfb6baedeaf1fdabd68678d37584a1817a08dfe77db60db378a508");
expect(miningCycleStateHash).to.equal("0x632d459a2197708bd2dbde87e8275c47dddcdf16d59e3efd21dcef9acb2a7366");
expect(tokenLockingStateHash).to.equal("0x30fbcbfbe589329fe20288101faabe1f60a4610ae0c0effb15526c6b390a8e07");
});
});
});

0 comments on commit 6f841ed

Please sign in to comment.