Skip to content

Commit

Permalink
Initial logging updates to Reputation Miner
Browse files Browse the repository at this point in the history
  • Loading branch information
kronosapiens committed Jan 31, 2022
1 parent 42decd1 commit 46e269b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 10 deletions.
28 changes: 22 additions & 6 deletions packages/reputation-miner/ReputationMiner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions packages/reputation-miner/ReputationMinerClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
14 changes: 10 additions & 4 deletions truffle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: () => {
Expand Down

0 comments on commit 46e269b

Please sign in to comment.