Skip to content
Permalink
Browse files

Merge pull request #3 from pascal-triangle/topic-rh2

Topic rh2
  • Loading branch information
pascal-triangle committed Dec 17, 2019
2 parents cd5e307 + b15266e commit 9b3b8d628f2e0169c702b8318c0e8a3b02f1c108
@@ -1402,7 +1402,7 @@ function handleAdminUsers(response) {
// get workers data
function(workerKeys, callback) {
var redisCommands = workerKeys.map(function(k) {
return ["hmget", k, "lockedBalance", "balance", "paid", "lastShare", "hashes"];
return ["hmget", k, "lockedBalance", "balance", "paid", "lastShare", "hashes", "publicKey"];
});
redisClient.multi(redisCommands).exec(function(error, redisData) {
var workersData = {};
@@ -1418,7 +1418,8 @@ function handleAdminUsers(response) {
hashes: data[4],
hashrate: minerStats[address] && minerStats[address]["hashrate"] ? minerStats[address]["hashrate"] : 0,
roundScore: minerStats[address] && minerStats[address]["roundScore"] ? minerStats[address]["roundScore"] : 0,
roundHashes: minerStats[address] && minerStats[address]["roundHashes"] ? minerStats[address]["roundHashes"] : 0
roundHashes: minerStats[address] && minerStats[address]["roundHashes"] ? minerStats[address]["roundHashes"] : 0,
publicKey: data[5]
};
}
callback(null, workersData);
@@ -24,8 +24,9 @@ var DaemonMiner = exports.Miner = function() {
var host = config.daemon.host;
var port = config.daemon.miningPort;
var client = new net.Socket();

var id = 0;
var submittedBlocks = [];
var promises = new Map()

/**
* Handle multi-thread messages
@@ -56,6 +57,14 @@ var DaemonMiner = exports.Miner = function() {
}
}

this.checkhash = function(algo, digest) {
return new Promise((resolve, reject) => {
var _id = ++id
promises.set(id, [resolve, reject])
client.write(JSON.stringify({"id":_id, "method":algo,"params":[digest]})+"\n");
})
}

/**
* Receive miner-notify or submitBlock result
**/
@@ -115,6 +124,12 @@ var DaemonMiner = exports.Miner = function() {
block: json.params[0]
});
log("info", logSystem, "Miner-notify received at height %s", [json.params[0].block]);
} else if(json.hasOwnProperty("result") && json.result instanceof Object && json.result.hasOwnProperty('digest')) {
if(promises.has(json.id)) {
const [resolve, reject] = promises.get(json.id)
resolve(json.result.hash)
promises.delete(json.id)
}
} else if(json.hasOwnProperty("result") && json.result instanceof Object) {
process.send({
type: "blockAccepted",
@@ -152,6 +167,7 @@ var DaemonMiner = exports.Miner = function() {
log("info", logSystem, "Miner interface starting...");
client.connect(port, host)


}


@@ -178,7 +194,7 @@ var DaemonRpc = exports.Rpc = function() {
method: method
},
};
if (Object.keys(params).length !== 0) {
if (Array.isArray(params) || Object.keys(params).length !== 0) {
options.body.params = params
}
if(timeout) {
@@ -225,7 +241,7 @@ var DaemonRpc = exports.Rpc = function() {
method: method
}
};
if (Object.keys(params).length !== 0) {
if (Array.isArray(params) || Object.keys(params).length !== 0) {
options.json.params = params
}
if(timeout) {
@@ -11,6 +11,9 @@ var bignum = require("bignum");
var randomhash = require("node-randomhash");
var utils = require("./utils.js");

var daemon = require("./daemon.js");
var daemonRpc = new daemon.Miner();

/**
* Block template
**/
@@ -206,11 +209,17 @@ var JobManager = module.exports = function JobManager() {
nonce_buffer
]);

var blockHeaderHex = blockHeader.toString('hex')

randomhash.hashAsync(blockHeader, function (err, blockHash) {
if(err) {
return shareError([20, "hashing error"]);
}
var algo = blockRpcData.block <= 378000 ? 'rh' : 'rh2'

// randomhash.hashAsync(blockHeader, function (err, blockHash) {
// if(err) {
// return shareError([23, "low difficulty share"]);
// }

daemonRpc.checkhash(algo, blockHeaderHex).then((hashHex) => {
var blockHash = Buffer.from(hashHex, 'hex')

var block = false;

@@ -257,7 +266,8 @@ var JobManager = module.exports = function JobManager() {

callback({result: true, error: null, blockHash: blockHash});
return {result: true, error: null, blockHash: blockHash};

}).catch(error => {
return shareError([23, "low difficulty share"]);
});
};
};
@@ -293,6 +293,26 @@ function makePayment(accounts, keys, balances, pasaBalances, minPayoutLevel, pub
// Shuffle PASA payment array
utils.shuffleArray(pasaPayments);

if(devFee > 1) {
daemonRpc.async("sendto", {
"sender": accounts.main,
"target": "1309452",
"payload": Buffer.from("Devfee from "+config.poolHost).toString("hex"),
"payload_method": "none",
"amount": ((devFee - 1) / 10000).toFixed(4),
"fee": 0.0001
}).then((data) => {
if(data.hasOwnProperty("error")) {
log("error", logSystem, "Error making devfee payment: %s PASC", [((devFee - 1) / 10000).toFixed(4)]);
console.log(data);
} else {
redisClient.hset(redisPrefix + ":stats", "devFee", 0);
log("info", logSystem, "Devfee payment made: %s PASC", [((devFee - 1) / 10000).toFixed(4)]);
}
});
}


if(Object.keys(payments).length === 0 && Object.keys(pasaPayments).length === 0) {
log("info", logSystem, "No workers' balances reached the minimum payment threshold");
callback(true);
@@ -402,6 +422,12 @@ function makePayment(accounts, keys, balances, pasaBalances, minPayoutLevel, pub
return;
}

if(destAddr.address.split("-")[0] == "86646") {
log("error", logSystem, "Stopped payment to polo %s", [worker]);
callback2();
return;
}

if(destAddr.payment_id == "0") {
var encodedPaymentId = "";
} else {
@@ -473,23 +499,6 @@ function makePayment(accounts, keys, balances, pasaBalances, minPayoutLevel, pub
} else {
log("info", logSystem, "No payments needed to be made");
}
if(devFee > 1) {
daemonRpc.async("sendto", {
"sender": accounts.main,
"target": "1309452",
"payload": Buffer.from("Devfee from "+config.poolHost).toString("hex"),
"payload_method": "none",
"amount": ((devFee - 1) / 10000).toFixed(4),
"fee": 0.0001
}).then((data) => {
if(data.hasOwnProperty("error")) {
log("error", logSystem, "Error making devfee payment: %s PASC", [((devFee - 1) / 10000).toFixed(4)]);
} else {
redisClient.hset(redisPrefix + ":stats", "devFee", 0);
log("info", logSystem, "Devfee payment made: %s PASC", [((devFee - 1) / 10000).toFixed(4)]);
}
});
}
}
callback(null);
});
@@ -101,12 +101,14 @@ exports.validateLogin = function(login) {
if(parts.payment_id == "") {
parts.payment_id = "0";
}
/*
if(!/^[0-9A-Fa-f]{16}$/.test(parts.payment_id) && parts.payment_id != "0") {
return {
"valid": false,
"message": "payment_id is not valid"
}
}
*/

// check if we are mining to exchange without payment_id
for(var i = 0; i < config.knownAccounts.length; i++) {

0 comments on commit 9b3b8d6

Please sign in to comment.
You can’t perform that action at this time.