Skip to content

Commit

Permalink
Move tx for confirmNewHash in to Miner
Browse files Browse the repository at this point in the history
  • Loading branch information
area committed Jan 17, 2022
1 parent 9f82fbf commit 2ddf7db
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 9 deletions.
2 changes: 1 addition & 1 deletion helpers/test-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ export async function advanceMiningCycleNoContest({ colonyNetwork, client, miner
if (client !== undefined) {
await client.addLogContentsToReputationTree();
await client.submitRootHash();
await client.confirmEntry();
await client.confirmNewHash();
} else {
const accounts = await web3GetAccounts();
minerAddress = minerAddress || accounts[5]; // eslint-disable-line no-param-reassign
Expand Down
18 changes: 18 additions & 0 deletions packages/reputation-miner/ReputationMiner.js
Original file line number Diff line number Diff line change
Expand Up @@ -1070,6 +1070,24 @@ class ReputationMiner {
);
}

/**
* Confirm the new reputation hash after all dispute resolution (if any) has occurred.
* @return {Promise} Resolves to tx hash of the response
*/
async confirmNewHash() {
const repCycle = await this.getActiveRepCycle();
const [round] = await this.getMySubmissionRoundAndIndex();

let gasEstimate = ethers.BigNumber.from(4000000);
try {
gasEstimate = await repCycle.estimateGas.confirmNewHash(round);
} catch (err){ // eslint-disable-line no-empty

}
return repCycle.confirmNewHash(round, { gasLimit: gasEstimate, gasPrice: this.gasPrice });
}


async updatePeriodLength(repCycle) {
const { numerator, denominator } = await repCycle.getDecayConstant();

Expand Down
9 changes: 2 additions & 7 deletions packages/reputation-miner/ReputationMinerClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -612,16 +612,11 @@ class ReputationMinerClient {
}

async confirmEntry() {
const addr = await this._miner.colonyNetwork.getReputationMiningCycle(true);
const repCycle = new ethers.Contract(addr, this._miner.repCycleContractDef.abi, this._miner.realWallet);

this._adapter.log("⏰ Looks like it's time to confirm the new hash");
// Confirm hash
// Confirm hash if possible
const [round] = await this._miner.getMySubmissionRoundAndIndex();
if (round && round.gte(0)) {
const gasEstimate = await repCycle.estimateGas.confirmNewHash(round);

const confirmNewHashTx = await repCycle.confirmNewHash(round, { gasLimit: gasEstimate, gasPrice: this._miner.gasPrice });
const confirmNewHashTx = await this._miner.confirmNewHash();
this._adapter.log(`⛏️ Transaction waiting to be mined ${confirmNewHashTx.hash}`);
await confirmNewHashTx.wait();
this._adapter.log("✅ New reputation hash confirmed");
Expand Down
5 changes: 5 additions & 0 deletions packages/reputation-miner/test/ReputationMinerTestWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ class ReputationMinerTestWrapper extends ReputationMiner {
const tx = await super.respondToChallenge();
return tx.wait();
}

async confirmNewHash() {
const tx = await super.confirmNewHash();
return tx.wait();
}
}

export default ReputationMinerTestWrapper;
17 changes: 16 additions & 1 deletion test/contracts-network/reputation-basic-functionality.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,22 @@ contract("Reputation mining - basic functionality", (accounts) => {
const repCycle = await getActiveRepCycle(colonyNetwork);
await forwardTime(MINING_CYCLE_DURATION, this);

await checkErrorRevert(repCycle.submitRootHash("0x12345678", 10, "0x00", 0), "colony-reputation-mining-zero-entry-index-passed");
await checkErrorRevert(repCycle.submitRootHash("0x12345678", 10, "0x00", 0), "colony-reputation-mining-no-stake-or-delegator");

const nUniqueSubmittedHashes = await repCycle.getNUniqueSubmittedHashes();
expect(nUniqueSubmittedHashes).to.be.zero;
});

it("should not allow someone to submit a new reputation hash with an entry index of 0, even if they're mining", async () => {
await giveUserCLNYTokensAndStake(colonyNetwork, MINER2, 9000);

const repCycle = await getActiveRepCycle(colonyNetwork);
await forwardTime(MINING_CYCLE_DURATION, this);

await checkErrorRevert(
repCycle.submitRootHash("0x12345678", 10, "0x00", 0, { from: MINER2 }),
"colony-reputation-mining-zero-entry-index-passed"
);

const nUniqueSubmittedHashes = await repCycle.getNUniqueSubmittedHashes();
expect(nUniqueSubmittedHashes).to.be.zero;
Expand Down

0 comments on commit 2ddf7db

Please sign in to comment.