diff --git a/libs/poolWorker.js b/libs/poolWorker.js index 5e2e8dc..18f6623 100644 --- a/libs/poolWorker.js +++ b/libs/poolWorker.js @@ -184,7 +184,7 @@ module.exports = function(logger){ logger.debug(logSystem, logComponent, logSubCat, 'We thought a block was found but it was rejected by the daemon, share data: ' + shareData); else if (isValidBlock) - logger.debug(logSystem, logComponent, logSubCat, 'Block found: ' + data.blockHash + ' by ' + data.worker); + logger.special(logSystem, logComponent, logSubCat, 'Block found: ' + data.blockHash + ' by ' + data.worker); if (isValidShare) { if(data.shareDiff > 1000000000) diff --git a/libs/rewardProcessor.js b/libs/rewardProcessor.js index b0da2ad..dc8a537 100644 --- a/libs/rewardProcessor.js +++ b/libs/rewardProcessor.js @@ -104,9 +104,7 @@ function SetupForPool(logger, poolOptions, setupFinished) { }, ], function (err) { - console.log("cb: err: ", err); if (err) { - console.log("setup finished", false); setupFinished(false); return; } @@ -134,7 +132,6 @@ function SetupForPool(logger, poolOptions, setupFinished) { } }, processingConfig.rewardInterval * 1000); setTimeout(processRewards, 100); - console.log("setup finished", true); setupFinished(true); } ); @@ -194,7 +191,7 @@ function SetupForPool(logger, poolOptions, setupFinished) { } // calculate worker balances - console.log("workers: ", results[0]); + // console.log("balances: ", results[0]); var workers = {}; for (var w in results[0]) { workers[w] = { @@ -238,11 +235,6 @@ function SetupForPool(logger, poolOptions, setupFinished) { let pendingShares = {}; // worker name -> shares sum for this worker let totalShares = 0; // total share of pending rounds - logger.debug( - logSystem, - logComponent, - "Start calculate totalShares & pendingShares" - ); startRedisTimer(); redisClient .multi(shareLookups) @@ -263,10 +255,7 @@ function SetupForPool(logger, poolOptions, setupFinished) { logger.error( logSystem, logComponent, - "No worker shares for round: " + - round.height + - " blockHash: " + - round.blockHash + `No worker shares for round: ${round.height}, blockHash: ${round.blockHash}` ); return; } @@ -287,11 +276,11 @@ function SetupForPool(logger, poolOptions, setupFinished) { ); totalShares += totalSharesInRound; - logger.debug( - logSystem, - logComponent, - `Total shares in round ${round.height}: ${totalSharesInRound}` - ); + // logger.debug( + // logSystem, + // logComponent, + // `Total shares in round ${round.height}: ${totalSharesInRound}` + // ); for (var workerAddress in workerShares) { if (!(workerAddress in pendingShares)) { @@ -308,6 +297,9 @@ function SetupForPool(logger, poolOptions, setupFinished) { } }); + if ("time" in pendingShares) { + delete pendingShares["time"]; + } logger.debug( logSystem, logComponent, @@ -315,9 +307,6 @@ function SetupForPool(logger, poolOptions, setupFinished) { Object.keys(pendingShares).length }` ); - if ("time" in pendingShares) { - delete pendingShares["time"]; - } callback(null, workers, rounds, totalShares, pendingShares); }); @@ -328,11 +317,6 @@ function SetupForPool(logger, poolOptions, setupFinished) { * according to their shares */ function (workers, rounds, totalShares, pendingShares, callback) { - logger.debug( - logSystem, - logComponent, - `Read balance/reserve and calculate the actual reward for each worker` - ); startRPCTimer(); web3.eth.getEnergy(beneficiary, function (err, bal) { endRPCTimer(); @@ -372,7 +356,6 @@ function SetupForPool(logger, poolOptions, setupFinished) { // if actual total reward is not enough for distribute, skip if (actualTotalReward.isLessThanOrEqualTo(0)) { - logger.debug(logSystem, logComponent, "No reward this interval"); return callback(new Error("no reward this interval")); } @@ -410,6 +393,20 @@ function SetupForPool(logger, poolOptions, setupFinished) { }; } + console.log(`Beneficiary: ${beneficiary}`); + console.log(`PoolTaxReceiver: ${poolTaxReceiver}`); + console.log(`Balances: `); + for (w in workers) { + console.log(` ${w}: ${workers[w].balance.toFixed(0)}`); + } + console.log(`Shares:`); + for (w in pendingShares) { + console.log( + ` ${w}: ${new BigNumber(pendingShares[w]).toFixed(0)}` + ); + } + console.log(`Total Shares: `, totalShares); + // calculate rewards for each miner // and accumulated pool tax to poolTaxReceiver for (let w in pendingShares) { @@ -418,7 +415,6 @@ function SetupForPool(logger, poolOptions, setupFinished) { if (w == "time") { continue; } - console.log("VISITED: WORKER ", w); if (!(w in workers)) { workers[w] = { reward: new BigNumber(0), @@ -438,36 +434,28 @@ function SetupForPool(logger, poolOptions, setupFinished) { logger.debug( logSystem, logComponent, - `worker ${w} reward: ${share}/${totalShares} * ${actualTotalReward.toFixed( + `reward for ${w}: ${share}/${totalShares} * ${actualTotalReward.toFixed( 0 )} * ${ 100 - processingConfig.poolTax - }% = ${workerReward.toFixed(0)}` + }% = ${workerReward.toFixed(0)}, tax: ${tax.toFixed(0)}` ); - console.log("beofre tax.plus"); workers[poolTaxReceiver].reward = tax.plus( workers[poolTaxReceiver].reward ); if (w.match(ADDR_PATTERN)) { - console.log("before workerReward.plus"); workers[w].reward = workerReward.plus(workers[w].reward); } else { - console.log("before workerReward.plus"); workers[w].balance = workerReward.plus(workers[w].balance); workers[w].issue = false; } - console.log( - `calced worker ${w}, balance: ${workers[w].balance}, reward: ${workers[w].reward}` - ); } // filter out actual payees with amount over minimum threshold // if amount < minimum threshold, add them to balance and payout next round - console.log("loop through workers"); + logger.debug("Issue Plan"); for (w in workers) { - console.log("visit: ", w); - console.log(workers[w]); if (workers[w].issue !== false) { const amount = workers[w].reward.plus(workers[w].balance); if (amount.isGreaterThan(minimumPayment)) { @@ -483,19 +471,33 @@ function SetupForPool(logger, poolOptions, setupFinished) { workers[w].issue = false; } } + if (workers[w].issue === false) { + logger.debug( + logSystem, + logComponent, + `Reserve for ${w}: ${workers[w].balance.toFixed(0)}` + ); + } else if (workers[w].issue === true) { + amount = workers[w].balance.plus(workers[w].reward); + logger.debug( + logSystem, + logComponent, + `Issue to ${w}: ${amount.toFixed(0)}` + ); + } } - console.log("add leftovers"); // ideally there should be no leftovers, but if it does, add it to reserve if (leftover.isGreaterThan(0)) { - console.log(`add leftover to reserve: `, leftover.toFixed(0)); workers[beneficiary].balance = new BigNumber( leftover.plus(workers[beneficiary].balance.toFixed(0)) ); logger.debug( logSystem, logComponent, - `Add reserve ${leftover.toFixed(0)}, totalReserve: ${workers[ + `Add leftover ${leftover.toFixed( + 0 + )} to reserve, afterwards totalReserve: ${workers[ beneficiary ].balance.toFixed(0)}` ); @@ -529,14 +531,14 @@ function SetupForPool(logger, poolOptions, setupFinished) { web3.eth.getBlockNumber(function (err, blockNum) { endRPCTimer(); if (err) { - console.log("getBlockNumber erro: ", err); + console.log("getBlockNumber error: ", err); return callback(err); } startRPCTimer(); web3.eth.getBlock(blockNum, function (err, best) { endRPCTimer(); if (err) { - console.log("getBlock erro: ", err); + console.log("getBlock error: ", err); return callback(err); } const blockRef = best.id.substr(0, 18); @@ -546,7 +548,9 @@ function SetupForPool(logger, poolOptions, setupFinished) { let clauses = []; for (const addr in addressAmounts) { const amount = addressAmounts[addr]; - console.log(`pay to ${addr} with ${amount.toFixed(0)}`); + console.log( + `pay to ${addr} with ${amount.div(1e18).toFixed()} MTR` + ); clauses.push({ to: addr, value: amount.toFixed(0), diff --git a/package-lock.json b/package-lock.json index ada7b2d..4524d8d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,7 +21,7 @@ "ethers": "^5.4.4", "express": "*", "extend": "*", - "meter-stratum-pool": "^0.2.7", + "meter-stratum-pool": "^0.2.12", "meterify": "^1.4.7", "mysql": "*", "node-json-minify": "*", @@ -2671,9 +2671,9 @@ "integrity": "sha512-cCi6g3/Zr1iqQi6ySbseM1Xvooa98N0w31jzUYrXPX2xqObmFGHJ0tQ5u74H3mVh7wLouTseZyYIq39g8cNp1w==" }, "node_modules/meter-stratum-pool": { - "version": "0.2.7", - "resolved": "https://registry.npmjs.org/meter-stratum-pool/-/meter-stratum-pool-0.2.7.tgz", - "integrity": "sha512-K2NPO1sWxdQ8kNpkiSGjgUVf8e5e/AU74PAjX9U0P1pl96n7dYtCXgeKqxVlRQl40s5g/uTvfC8iRlcYh23Sjw==", + "version": "0.2.12", + "resolved": "https://registry.npmjs.org/meter-stratum-pool/-/meter-stratum-pool-0.2.12.tgz", + "integrity": "sha512-CM/Z7sq7bc1ayaF+9AsxY2hBPjnr5sUU0yFb0pw/l26Y9aV0kNqD/FHZXScJjo7L9MT4T5g7Q6TAxVOHUmc+/Q==", "dependencies": { "async": "^3.2.4", "bignumber.js": "^9.1.1", diff --git a/package.json b/package.json index 4c9d18e..8e4f390 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "ethers": "^5.4.4", "express": "*", "extend": "*", - "meter-stratum-pool": "^0.2.10", + "meter-stratum-pool": "^0.2.12", "meterify": "^1.4.7", "mysql": "*", "node-json-minify": "*",