-
Notifications
You must be signed in to change notification settings - Fork 1k
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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({ | ||
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
@@ -26,7 +34,7 @@ module.exports = function(logger, poolConfig){ | |
return; | ||
} | ||
|
||
connection.query( | ||
sharedDBConnection.query( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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){ | ||
|
@@ -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){ | ||
|
@@ -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){ | ||
|
@@ -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( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
|
@@ -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( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
|
There was a problem hiding this comment.
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