Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MPOS SSO DB Compatibility #612

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions libs/mposCompatibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,22 @@ module.exports = function(logger, poolConfig){
var mposConfig = poolConfig.mposMode;
var coin = poolConfig.coin.name;

var connection = mysql.createPool({
var mainDBConnection = mysql.createPool({
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per Coin DB Connection details to be specified in config to be used here

host: mposConfig.host,
port: mposConfig.port,
user: mposConfig.user,
password: mposConfig.password,
database: mposConfig.database
});

var sharedDBConnection = mysql.createPool({
host: mposConfig.host,
port: mposConfig.port,
user: mposConfig.user,
password: mposConfig.password,
database: mposConfig.shared_database
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shared SSO DB to be specified here

});


var logIdentify = 'MySQL';
var logComponent = coin;
Expand All @@ -26,7 +34,7 @@ module.exports = function(logger, poolConfig){
return;
}

connection.query(
sharedDBConnection.query(
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look for Workers in SSO DB rather than per coin db

'SELECT password FROM pool_worker WHERE username = LOWER(?)',
[workerName.toLowerCase()],
function(err, result){
Expand All @@ -38,7 +46,7 @@ module.exports = function(logger, poolConfig){
else if (!result[0]){
if(mposConfig.autoCreateWorker){
var account = workerName.split('.')[0];
connection.query(
sharedDBConnection.query(
'SELECT id,username FROM accounts WHERE username = LOWER(?)',
[account.toLowerCase()],
function(err, result){
Expand All @@ -49,7 +57,7 @@ module.exports = function(logger, poolConfig){
}else if(!result[0]){
authCallback(false);
}else{
connection.query(
sharedDBConnection.query(
"INSERT INTO `pool_worker` (`account_id`, `username`, `password`) VALUES (?, ?, ?);",
[result[0].id,workerName.toLowerCase(),password],
function(err, result){
Expand Down Expand Up @@ -89,7 +97,7 @@ module.exports = function(logger, poolConfig){
typeof(shareData.error) === 'undefined' ? null : shareData.error,
shareData.blockHash ? shareData.blockHash : (shareData.blockHashInvalid ? shareData.blockHashInvalid : '')
];
connection.query(
mainDBConnection.query(
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Insert Shares into Coin DB

'INSERT INTO `shares` SET time = NOW(), rem_host = ?, username = ?, our_result = ?, upstream_result = ?, difficulty = ?, reason = ?, solution = ?',
dbData,
function(err, result) {
Expand All @@ -103,14 +111,14 @@ module.exports = function(logger, poolConfig){

this.handleDifficultyUpdate = function(workerName, diff){

connection.query(
'UPDATE `pool_worker` SET `difficulty` = ' + diff + ' WHERE `username` = ' + connection.escape(workerName),
sharedDBConnection.query(
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update difficulty in Share DB not worker DB.

(This is what we need to get rid of soon but until we come up with a way to handle the issues caused by this, let's not remove it yet)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now here's the issue I was referring to. For payouts, MPOS is using the share DB but for stats it's looking into the worker DB

'UPDATE `pool_worker` SET `difficulty` = ' + diff + ' WHERE `username` = ' + sharedDBConnection.escape(workerName),
function(err, result){
if (err)
logger.error(logIdentify, logComponent, 'Error when updating worker diff: ' +
JSON.stringify(err));
else if (result.affectedRows === 0){
connection.query('INSERT INTO `pool_worker` SET ?', {username: workerName, difficulty: diff});
sharedDBConnection.query('INSERT INTO `pool_worker` SET ?', {username: workerName, difficulty: diff});
}
else
console.log('Updated difficulty successfully', result);
Expand Down