Setting the new sizes, holders, and test states to see if this thing works.

This commit is contained in:
Alexander Blair
2017-07-03 06:43:52 -07:00
parent fb9971c11a
commit 916019f418
2 changed files with 96 additions and 24 deletions
+36 -2
View File
@@ -69,7 +69,7 @@ function Coin(data){
this.getBlockTemplate = function(walletAddress, callback){ this.getBlockTemplate = function(walletAddress, callback){
global.support.rpcDaemon('getblocktemplate', { global.support.rpcDaemon('getblocktemplate', {
reserve_size: 8, reserve_size: 16,
wallet_address: walletAddress wallet_address: walletAddress
}, function(body){ }, function(body){
return callback(body); return callback(body);
@@ -102,22 +102,56 @@ function Coin(data){
}; };
this.BlockTemplate = function(template) { this.BlockTemplate = function(template) {
/*
Generating a block template is a simple thing. Ask for a boatload of information, and go from there.
Important things to consider.
The reserved space is 13 bytes long now in the following format:
|minerNonce/extraNonce - 4 bytes|instanceId - 4 bytes|clientNonce - 4 bytes|clientPoolNonce - 4 bytes|
This is designed to allow a single block template to be used on up to 4 billion poolSlaves (clientPoolNonce)
Each with 4 billion clients. (clientNonce)
While being unique to this particular pool thread (instanceId)
With up to 4 billion clients (minerNonce/extraNonce)
Overkill? Sure. But that's what we do here. Overkill.
*/
// Set this.blob equal to the BT blob that we get from upstream.
this.blob = template.blocktemplate_blob; this.blob = template.blocktemplate_blob;
// Set this.diff equal to the known diff for this block.
this.difficulty = template.difficulty; this.difficulty = template.difficulty;
// Set this.height equal to the known height for this block.
this.height = template.height; this.height = template.height;
// Set this.reserveOffset to the byte location of the reserved offset.
this.reserveOffset = template.reserved_offset; this.reserveOffset = template.reserved_offset;
// Set this.buffer to the binary decoded version of the BT blob.
this.buffer = new Buffer(this.blob, 'hex'); this.buffer = new Buffer(this.blob, 'hex');
// Copy the Instance ID to the reserve offset + 4 bytes deeper. Copy in 4 bytes.
instanceId.copy(this.buffer, this.reserveOffset + 4, 0, 3); instanceId.copy(this.buffer, this.reserveOffset + 4, 0, 3);
// Generate a clean, shiny new buffer.
this.previous_hash = new Buffer(32); this.previous_hash = new Buffer(32);
// Copy in bytes 7 through 39 to this.previous_hash from the current BT.
this.buffer.copy(this.previous_hash, 0, 7, 39); this.buffer.copy(this.previous_hash, 0, 7, 39);
// Reset the Nonce. - This is the per-miner/pool nonce
this.extraNonce = 0; this.extraNonce = 0;
// The clientNonceLocation is the location at which the client pools should set the nonces for each of their clients.
this.clientNonceLocation = this.reserveOffset + 8;
// The clientPoolLocation is for multi-thread/multi-server pools to handle the nonce for each of their tiers.
this.clientPoolLocation = this.reserveOffset + 12;
this.nextBlob = function () { this.nextBlob = function () {
// Write a 32 bit integer, big-endian style to the 0 byte of the reserve offset.
this.buffer.writeUInt32BE(++this.extraNonce, this.reserveOffset); this.buffer.writeUInt32BE(++this.extraNonce, this.reserveOffset);
// Convert the blob into something hashable.
return global.coinFuncs.convertBlob(this.buffer).toString('hex'); return global.coinFuncs.convertBlob(this.buffer).toString('hex');
}; };
// Make it so you can get the raw block blob out.
this.nextBlobWithChildNonce = function () {
// Write a 32 bit integer, big-endian style to the 0 byte of the reserve offset.
this.buffer.writeUInt32BE(++this.extraNonce, this.reserveOffset);
// Don't convert the blob to something hashable. You bad.
return this.buffer.toString('hex');
};
}; };
this.cryptoNight = multiHashing['cryptonight']; this.cryptoNight = multiHashing.cryptoNight;
} }
+60 -22
View File
@@ -215,9 +215,13 @@ function Miner(id, login, pass, ipAddress, startingDiff, messageSender, protoVer
let pass_split = pass.split(":"); let pass_split = pass.split(":");
this.error = ""; this.error = "";
this.identifier = pass_split[0]; this.identifier = pass_split[0];
this.proxy = false;
if (agent && agent.includes('MinerGate')){ if (agent && agent.includes('MinerGate')){
this.identifier = "MinerGate"; this.identifier = "MinerGate";
} }
if (agent && agent.includes('xmr-node-proxy')){
this.proxy = true;
}
this.paymentID = null; this.paymentID = null;
this.valid_miner = true; this.valid_miner = true;
this.port = port; this.port = port;
@@ -463,27 +467,52 @@ function Miner(id, login, pass, ipAddress, startingDiff, messageSender, protoVer
return this.cachedJob; return this.cachedJob;
} }
let blob = activeBlockTemplate.nextBlob(); if (!this.proxy){
let target = this.getTargetHex(); let blob = activeBlockTemplate.nextBlob();
this.lastBlockHeight = activeBlockTemplate.height; let target = this.getTargetHex();
this.lastBlockHeight = activeBlockTemplate.height;
let newJob = { let newJob = {
id: crypto.pseudoRandomBytes(21).toString('base64'), id: crypto.pseudoRandomBytes(21).toString('base64'),
extraNonce: activeBlockTemplate.extraNonce, extraNonce: activeBlockTemplate.extraNonce,
height: activeBlockTemplate.height, height: activeBlockTemplate.height,
difficulty: this.difficulty, difficulty: this.difficulty,
diffHex: this.diffHex, diffHex: this.diffHex,
submissions: [] submissions: []
}; };
this.validJobs.enq(newJob); this.validJobs.enq(newJob);
this.cachedJob = { this.cachedJob = {
blob: blob, blob: blob,
job_id: newJob.id, job_id: newJob.id,
target: target, target: target,
id: this.id id: this.id
}; };
} else {
let blob = activeBlockTemplate.nextBlobWithChildNonce();
this.lastBlockHeight = activeBlockTemplate.height;
let newJob = {
id: crypto.pseudoRandomBytes(21).toString('base64'),
extraNonce: activeBlockTemplate.extraNonce,
height: activeBlockTemplate.height,
difficulty: this.difficulty,
diffHex: this.diffHex,
submissions: []
};
this.validJobs.enq(newJob);
this.cachedJob = {
blocktemplate_blob: blob,
difficulty: activeBlockTemplate.difficulty,
height: activeBlockTemplate.height,
reserved_offset: activeBlockTemplate.reserveOffset,
client_nonce_offset: activeBlockTemplate.clientNonceLocation,
client_pool_offset: activeBlockTemplate.clientPoolLocation,
job_id: newJob.id,
id: this.id
};
}
return this.cachedJob; return this.cachedJob;
}; };
} }
@@ -526,10 +555,19 @@ function recordShareData(miner, job, shareDiff, blockCandidate, hashHex, shareTy
} }
function processShare(miner, job, blockTemplate, nonce, resultHash) { function processShare(miner, job, blockTemplate, params) {
let nonce = params.nonce;
let resultHash = params.result;
let template = new Buffer(blockTemplate.buffer.length); let template = new Buffer(blockTemplate.buffer.length);
blockTemplate.buffer.copy(template); if (!miner.proxy){
template.writeUInt32BE(job.extraNonce, blockTemplate.reserveOffset); blockTemplate.buffer.copy(template);
template.writeUInt32BE(job.extraNonce, blockTemplate.reserveOffset);
} else {
blockTemplate.buffer.copy(template);
template.writeUInt32BE(job.extraNonce, blockTemplate.reserveOffset);
template.writeUInt32BE(params.workerNonce, blockTemplate.clientNonceLocation);
template.writeUInt32BE(params.poolNonce, blockTemplate.clientPoolLocation);
}
let shareBuffer = global.coinFuncs.constructNewBlob(template, new Buffer(nonce, 'hex')); let shareBuffer = global.coinFuncs.constructNewBlob(template, new Buffer(nonce, 'hex'));
let convertedBlob; let convertedBlob;
@@ -691,7 +729,7 @@ function handleMinerData(method, params, ip, portData, sendReply, pushMessage) {
return; return;
} }
let shareAccepted = processShare(miner, job, blockTemplate, params.nonce, params.result); let shareAccepted = processShare(miner, job, blockTemplate, params);
miner.checkBan(shareAccepted); miner.checkBan(shareAccepted);
if (global.config.pool.trustedMiners) { if (global.config.pool.trustedMiners) {