From 46e269b6ed6f1353d158b8aa3fed53014a3989c8 Mon Sep 17 00:00:00 2001 From: Daniel Kronovet Date: Tue, 18 Jan 2022 10:31:52 -0500 Subject: [PATCH] Initial logging updates to Reputation Miner --- packages/reputation-miner/ReputationMiner.js | 28 +++++++++++++++---- .../reputation-miner/ReputationMinerClient.js | 4 +++ truffle.js | 14 +++++++--- 3 files changed, 36 insertions(+), 10 deletions(-) diff --git a/packages/reputation-miner/ReputationMiner.js b/packages/reputation-miner/ReputationMiner.js index 6ad35682ac..1acc3938d7 100644 --- a/packages/reputation-miner/ReputationMiner.js +++ b/packages/reputation-miner/ReputationMiner.js @@ -734,9 +734,9 @@ class ReputationMiner { async getEntryIndex(startIndex = 1) { // Get how much we've staked, and thefore how many entries we have - const [stakeAmount] = await this.colonyNetwork.getMiningStake(this.minerAddress); + const minerStake = await this.getMiningStake(); - for (let i = ethers.BigNumber.from(startIndex); i.lte(stakeAmount.div(minStake)); i = i.add(1)) { + for (let i = ethers.BigNumber.from(startIndex); i.lte(minerStake.amount.div(minStake)); i = i.add(1)) { const submissionPossible = await this.submissionPossible(i); if (submissionPossible) { return i; @@ -769,13 +769,13 @@ class ReputationMiner { } // Check the proposed entry is eligible (emulates entryQualifies modifier behaviour) - const [stakeAmount, stakeTimestamp] = await this.colonyNetwork.getMiningStake(this.minerAddress); + const minerStake = await this.getMiningStake(); - if (ethers.BigNumber.from(entryIndex).gt(stakeAmount.div(minStake))) { + if (ethers.BigNumber.from(entryIndex).gt(minerStake.amount.div(minStake))) { return false; } - if(reputationMiningWindowOpenTimestamp.lt(stakeTimestamp)) { + if(reputationMiningWindowOpenTimestamp.lt(minerStake.timestamp)) { return false; } @@ -799,6 +799,22 @@ class ReputationMiner { return true; } + /** + * Get the stake for the miner + * @return {Promise} Resolves to the mining stake, {amount, timestamp} + */ + getMiningStake() { + return this.colonyNetwork.getMiningStake(this.minerAddress); + } + + /** + * Get the minimum stake for reputation mining + * @return {integer} The minimum stake + */ + getMinStake() { + return minStake; + } + /** * Get the mining cycle duration. * @return {integer} Mining cycle duration @@ -1270,7 +1286,7 @@ class ReputationMiner { } for (let i = syncFromIndex; i < events.length; i += 1) { - console.log(`Syncing mining cycle ${i + 1} of ${events.length}...`) + console.log(`${new Date().toLocaleTimeString()}: Syncing mining cycle ${i + 1} of ${events.length}...`) const event = events[i]; if (i === 0) { // If we are syncing from the very start of the reputation history, the block diff --git a/packages/reputation-miner/ReputationMinerClient.js b/packages/reputation-miner/ReputationMinerClient.js index bd7b23d3d4..efe7a454d3 100644 --- a/packages/reputation-miner/ReputationMinerClient.js +++ b/packages/reputation-miner/ReputationMinerClient.js @@ -224,6 +224,10 @@ class ReputationMinerClient { this.resolveBlockChecksFinished = undefined; await this._miner.initialise(colonyNetworkAddress); + const minerStake = await this._miner.getMiningStake(); + const numEntries = minerStake.amount.div(this._miner.getMinStake()); + this._adapter.log(`Miner has staked ${minerStake.amount} CLNY, allowing up to ${numEntries} entries per cycle`); + // Get latest state from database if available, otherwise sync to current state on-chain const latestReputationHash = await this._miner.colonyNetwork.getReputationRootHash(); await this._miner.createDB(); diff --git a/truffle.js b/truffle.js index 2b4ecf53f1..7285f0c095 100644 --- a/truffle.js +++ b/truffle.js @@ -41,17 +41,23 @@ module.exports = { gasPrice: 0, network_id: "1", }, + mainnet: { + provider: () => { + return new HDWalletProvider("private-key", "https://mainnet.infura.io/v3/infura-key"); + }, + network_id: "1", + }, goerli: { provider: () => { - return new HDWalletProvider("replace-with-private-key-when-using", "https://goerli.infura.io/v3/e21146aa267845a2b7b4da025178196d"); + return new HDWalletProvider("private-key", "https://goerli.infura.io/v3/infura-key"); }, network_id: "5", }, - mainnet: { + xdai: { provider: () => { - return new HDWalletProvider("replace-with-private-key-when-using", "https://mainnet.infura.io/v3/e21146aa267845a2b7b4da025178196d"); + return new HDWalletProvider("private-key", "https://xdai-archive.blockscout.com/"); }, - network_id: "1", + network_id: "100", }, storageSmoke: { provider: () => {