Detect kicked blocks and deal with them appropriately
This commit is contained in:
parent
c3a15ad200
commit
baadebd97d
@ -213,8 +213,13 @@ function SetupForPool(logger, poolOptions, setupFinished){
|
|||||||
var round = rounds[i];
|
var round = rounds[i];
|
||||||
|
|
||||||
if (tx.error && tx.error.code === -5){
|
if (tx.error && tx.error.code === -5){
|
||||||
logger.error(logSystem, logComponent, 'Daemon reports invalid transaction ' + round.txHash + ' '
|
logger.warning(logSystem, logComponent, 'Daemon reports invalid transaction: ' + round.txHash);
|
||||||
+ JSON.stringify(tx.error));
|
round.category = 'kicked';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (!tx.result.details || (tx.result.details && tx.result.details.length === 0)){
|
||||||
|
logger.warning(logSystem, logComponent, 'Daemon reports no details for transaction: ' + round.txHash);
|
||||||
|
round.category = 'kicked';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (tx.error || !tx.result){
|
else if (tx.error || !tx.result){
|
||||||
@ -222,16 +227,6 @@ function SetupForPool(logger, poolOptions, setupFinished){
|
|||||||
+ JSON.stringify(tx));
|
+ JSON.stringify(tx));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (round.blockHash !== tx.result.blockhash){
|
|
||||||
logger.error(logSystem, logComponent, 'Daemon reports blockhash ' + tx.result.blockhash
|
|
||||||
+ ' for tx ' + round.txHash + ' is not the one we have stored: ' + round.blockHash);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else if (!(tx.result.details instanceof Array)){
|
|
||||||
logger.error(logSystem, logComponent, 'Details array missing from transaction '
|
|
||||||
+ round.txHash);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
var generationTx = tx.result.details.filter(function(tx){
|
var generationTx = tx.result.details.filter(function(tx){
|
||||||
return tx.address === poolOptions.address;
|
return tx.address === poolOptions.address;
|
||||||
@ -253,16 +248,29 @@ function SetupForPool(logger, poolOptions, setupFinished){
|
|||||||
round.reward = generationTx.amount || generationTx.value;
|
round.reward = generationTx.amount || generationTx.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var canDeleteShares = function(r){
|
||||||
|
for (var i = 0; i < rounds.length; i++){
|
||||||
|
var compareR = rounds[i];
|
||||||
|
if ((compareR.height === r.height)
|
||||||
|
&& (compareR.category !== 'kicked')
|
||||||
|
&& (compareR.category !== 'orphan')
|
||||||
|
&& (compareR.serialized !== r.serialized)){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
//Filter out all rounds that are immature (not confirmed or orphaned yet)
|
//Filter out all rounds that are immature (not confirmed or orphaned yet)
|
||||||
rounds = rounds.filter(function(r){
|
rounds = rounds.filter(function(r){
|
||||||
switch (r.category) {
|
switch (r.category) {
|
||||||
case 'generate':
|
|
||||||
return true;
|
|
||||||
case 'orphan':
|
case 'orphan':
|
||||||
|
case 'kicked':
|
||||||
|
r.canDeleteShares = canDeleteShares(r);
|
||||||
|
case 'generate':
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
@ -305,11 +313,8 @@ function SetupForPool(logger, poolOptions, setupFinished){
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch (round.category){
|
switch (round.category){
|
||||||
|
case 'kicked':
|
||||||
case 'orphan':
|
case 'orphan':
|
||||||
/* Each block that gets orphaned, all the shares go into the current round so that
|
|
||||||
miners still get a reward for their work. This seems unfair to those that just
|
|
||||||
started mining during this current round, but over time it balances out and rewards
|
|
||||||
loyal miners. */
|
|
||||||
round.workerShares = workerShares;
|
round.workerShares = workerShares;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -373,7 +378,6 @@ function SetupForPool(logger, poolOptions, setupFinished){
|
|||||||
daemon.cmd('sendmany', [addressAccount || '', addressAmounts], function (result) {
|
daemon.cmd('sendmany', [addressAccount || '', addressAmounts], function (result) {
|
||||||
if (result.error && result.error.code === -6) {
|
if (result.error && result.error.code === -6) {
|
||||||
var higherPercent = withholdPercent + 0.01;
|
var higherPercent = withholdPercent + 0.01;
|
||||||
console.log('asdfasdfsadfasdf');
|
|
||||||
logger.warning(logSystem, logComponent, 'Not enough funds to send out payments, decreasing rewards by '
|
logger.warning(logSystem, logComponent, 'Not enough funds to send out payments, decreasing rewards by '
|
||||||
+ (higherPercent * 100) + '% and retrying');
|
+ (higherPercent * 100) + '% and retrying');
|
||||||
trySend(higherPercent);
|
trySend(higherPercent);
|
||||||
@ -427,21 +431,30 @@ function SetupForPool(logger, poolOptions, setupFinished){
|
|||||||
var roundsToDelete = [];
|
var roundsToDelete = [];
|
||||||
var orphanMergeCommands = [];
|
var orphanMergeCommands = [];
|
||||||
|
|
||||||
|
var moveSharesToCurrent = function(r){
|
||||||
|
var workerShares = r.workerShares;
|
||||||
|
Object.keys(workerShares).forEach(function(worker){
|
||||||
|
orphanMergeCommands.push(['hincrby', coin + '_shares:roundCurrent',
|
||||||
|
worker, workerShares[worker]]);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
rounds.forEach(function(r){
|
rounds.forEach(function(r){
|
||||||
|
|
||||||
switch(r.category){
|
switch(r.category){
|
||||||
|
case 'kicked':
|
||||||
|
movePendingCommands.push(['smove', coin + '_blocksPending', coin + '_blocksKicked', r.serialized]);
|
||||||
case 'orphan':
|
case 'orphan':
|
||||||
movePendingCommands.push(['smove', coin + '_blocksPending', coin + '_blocksOrphaned', r.serialized]);
|
movePendingCommands.push(['smove', coin + '_blocksPending', coin + '_blocksOrphaned', r.serialized]);
|
||||||
var workerShares = r.workerShares;
|
if (r.canDeleteShares){
|
||||||
Object.keys(workerShares).forEach(function(worker){
|
moveSharesToCurrent(r);
|
||||||
orphanMergeCommands.push(['hincrby', coin + '_shares:roundCurrent',
|
roundsToDelete.push(coin + '_shares:round' + r.height);
|
||||||
worker, workerShares[worker]]);
|
}
|
||||||
});
|
return;
|
||||||
break;
|
|
||||||
case 'generate':
|
case 'generate':
|
||||||
movePendingCommands.push(['smove', coin + '_blocksPending', coin + '_blocksConfirmed', r.serialized]);
|
movePendingCommands.push(['smove', coin + '_blocksPending', coin + '_blocksConfirmed', r.serialized]);
|
||||||
roundsToDelete.push(coin + '_shares:round' + r.height);
|
roundsToDelete.push(coin + '_shares:round' + r.height);
|
||||||
break;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user