Skip to content

Commit 2c05959

Browse files
committed
report errors to the miner on pool connection problems
1 parent db3dcbd commit 2c05959

File tree

3 files changed

+41
-11
lines changed

3 files changed

+41
-11
lines changed

index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22

3-
global.VERSION = '1.0.6';
3+
global.VERSION = '1.0.7';
44

55
global.logger = logger = require('./lib/log');
66
logger.init(process.cwd(), 'log.txt');
@@ -80,6 +80,9 @@ async function init() {
8080
}).on('workPackage', (params) => {
8181
// listen for work packages from the stratum pool and make them available to the rpc server
8282
rpcServer.setWork(params);
83+
84+
}).on('login', (error) => {
85+
rpcServer.poolLoginNotify(error);
8386
});
8487

8588
}

lib/rpc.js

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,26 @@ module.exports = class RPCServer extends EventEmitter {
2424
this.lastRPCRequest = Date.now();
2525
this.activeMiner = true;
2626
this.poolConnection = false;
27+
this.poolError = null;
2728

2829
// create an rpc server
2930
var server = jayson.server({
3031

3132
getPoolEthAddress: (args, callback) => {
3233
this.serviceRPCRequest('getPoolEthAddress', () => {
33-
callback(null, this.mintingAccount);
34+
if (this.poolError) {
35+
callback(this.poolError);
36+
} else {
37+
callback(null, this.mintingAccount);
38+
}
3439
});
3540
},
3641

3742
getMinimumShareDifficulty: async (args, callback) => {
3843
this.serviceRPCRequest('getMinimumShareDifficulty', () => {
39-
if (args[0].toLowerCase() != this.minerEthAddress) {
44+
if (this.poolError) {
45+
callback(this.poolError);
46+
} else if (args[0].toLowerCase() != this.minerEthAddress) {
4047
callback({code: -1, message: 'Invalid minerEthAddresss ' + args[0] + '. Expecting ' + this.minerEthAddress});
4148
} else {
4249
callback(null, this.minerVarDiff);
@@ -46,7 +53,9 @@ module.exports = class RPCServer extends EventEmitter {
4653

4754
getMinimumShareTarget: async (args, callback) => {
4855
this.serviceRPCRequest('getMinimumShareTarget', () => {
49-
if (args[0].toLowerCase() != this.minerEthAddress) {
56+
if (this.poolError) {
57+
callback(this.poolError);
58+
} else if (args[0].toLowerCase() != this.minerEthAddress) {
5059
callback({code: -1, message: 'Invalid minerEthAddresss ' + args[0] + '. Expecting ' + this.minerEthAddress});
5160
} else {
5261
callback(null, this.minimumShareTarget);
@@ -56,17 +65,25 @@ module.exports = class RPCServer extends EventEmitter {
5665

5766
getChallengeNumber: async (args, callback) => {
5867
this.serviceRPCRequest('getChallengeNumber', () => {
59-
callback(null, this.challengeNumber);
68+
if (this.poolError) {
69+
callback(this.poolError);
70+
} else {
71+
callback(null, this.challengeNumber);
72+
}
6073
});
6174
},
6275

6376
submitShare: async (args, callback) => {
6477
this.serviceRPCRequest('submitShare', () => {
65-
// notify interested listeners of a share submit. provide a callback so we can be
66-
// notified if share was accepted (true/false).
67-
this.emit('submitShare', args, (res) => {
68-
callback(null, res);
69-
})
78+
if (this.poolError) {
79+
callback(this.poolError);
80+
} else {
81+
// notify interested listeners of a share submit. provide a callback so we can be
82+
// notified if share was accepted (true/false).
83+
this.emit('submitShare', args, (res) => {
84+
callback(null, res);
85+
})
86+
}
7087
});
7188
},
7289

@@ -131,5 +148,14 @@ module.exports = class RPCServer extends EventEmitter {
131148
}
132149
}
133150

151+
152+
poolLoginNotify(error) {
153+
if (error) {
154+
this.poolError = {code: error[0], message: error[1]};
155+
} else {
156+
this.poolError = null;
157+
}
158+
}
159+
134160
}
135161

lib/stratum.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,9 @@ module.exports = class StratumClient extends EventEmitter {
8282
// miner.subscribe response
8383
this.subscribed = jsonData.result;
8484
if (jsonData.error) {
85-
LogB('Pool login rejected. Reason given:', jsonData.error);
85+
LogB('Pool login rejected. Reason given: ', jsonData.error[1]);
8686
}
87+
this.emit('login', jsonData.error);
8788
break;
8889
case 4:
8990
// miner.submit response

0 commit comments

Comments
 (0)