mirror of
https://github.com/LBRYFoundation/pool.git
synced 2025-08-23 17:37:25 +00:00
stratum: reduce defines, prepare the autoexchange variable
also improve the user wallet addresses checks and allow to mine aux coins in normal (gbt) + aux at the same time
This commit is contained in:
parent
edd36ad5f9
commit
9d4c4d41c7
9 changed files with 67 additions and 20 deletions
|
@ -122,6 +122,7 @@ bool client_validate_user_address(YAAMP_CLIENT *client)
|
||||||
// debuglog("user %s testing on coin %s ...\n", client->username, coind->symbol);
|
// debuglog("user %s testing on coin %s ...\n", client->username, coind->symbol);
|
||||||
if(!coind_can_mine(coind)) continue;
|
if(!coind_can_mine(coind)) continue;
|
||||||
if(coind->pos) continue;
|
if(coind->pos) continue;
|
||||||
|
if(strlen(g_current_algo->name) && strcmp(g_current_algo->name, coind->algo)) continue;
|
||||||
if(coind_validate_user_address(coind, client->username)) {
|
if(coind_validate_user_address(coind, client->username)) {
|
||||||
debuglog("new user %s for coin %s\n", client->username, coind->symbol);
|
debuglog("new user %s for coin %s\n", client->username, coind->symbol);
|
||||||
client->coinid = coind->id;
|
client->coinid = coind->id;
|
||||||
|
@ -139,14 +140,25 @@ bool client_validate_user_address(YAAMP_CLIENT *client)
|
||||||
}
|
}
|
||||||
|
|
||||||
YAAMP_COIND *coind = (YAAMP_COIND *)object_find(&g_list_coind, client->coinid);
|
YAAMP_COIND *coind = (YAAMP_COIND *)object_find(&g_list_coind, client->coinid);
|
||||||
if(!coind) {
|
if (!coind) {
|
||||||
clientlog(client, "unable to find wallet for coinid %d...", client->coinid);
|
clientlog(client, "unable to find the wallet for coinid %d...", client->coinid);
|
||||||
return false;
|
return false;
|
||||||
|
} else {
|
||||||
|
if(g_current_algo && strlen(g_current_algo->name) && strcmp(g_current_algo->name, coind->algo)) {
|
||||||
|
clientlog(client, "%s address is on the wrong coin %s, reset to auto...", client->username, coind->symbol);
|
||||||
|
client->coinid = 0;
|
||||||
|
CommonLock(&g_db_mutex);
|
||||||
|
db_init_user_coinid(g_db, client);
|
||||||
|
CommonUnlock(&g_db_mutex);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isvalid = coind_validate_user_address(coind, client->username);
|
bool isvalid = coind_validate_user_address(coind, client->username);
|
||||||
if (isvalid) {
|
if (isvalid) {
|
||||||
client->coinid = coind->id;
|
client->coinid = coind->id;
|
||||||
|
} else {
|
||||||
|
clientlog(client, "unable to verify %s address for user coinid %d...", coind->symbol, client->coinid);
|
||||||
}
|
}
|
||||||
return isvalid;
|
return isvalid;
|
||||||
}
|
}
|
||||||
|
@ -196,9 +208,8 @@ bool client_authorize(YAAMP_CLIENT *client, json_value *json_params)
|
||||||
debuglog("new client %s, %s, %s\n", client->username, client->password, client->version);
|
debuglog("new client %s, %s, %s\n", client->username, client->password, client->version);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef NO_EXCHANGE
|
|
||||||
// when auto exchange is disabled, only authorize good wallet address...
|
// when auto exchange is disabled, only authorize good wallet address...
|
||||||
if (!client_validate_user_address(client)) {
|
if (!g_autoexchange && !client_validate_user_address(client)) {
|
||||||
|
|
||||||
clientlog(client, "bad mining address %s", client->username);
|
clientlog(client, "bad mining address %s", client->username);
|
||||||
client_send_result(client, "false");
|
client_send_result(client, "false");
|
||||||
|
@ -209,7 +220,6 @@ bool client_authorize(YAAMP_CLIENT *client, json_value *json_params)
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
client_send_result(client, "true");
|
client_send_result(client, "true");
|
||||||
client_send_difficulty(client, client->difficulty_actual);
|
client_send_difficulty(client, client->difficulty_actual);
|
||||||
|
|
|
@ -63,6 +63,9 @@ void client_do_submit(YAAMP_CLIENT *client, YAAMP_JOB *job, YAAMP_JOB_VALUES *su
|
||||||
if(!templ->auxs[i]) continue;
|
if(!templ->auxs[i]) continue;
|
||||||
YAAMP_COIND *coind_aux = templ->auxs[i]->coind;
|
YAAMP_COIND *coind_aux = templ->auxs[i]->coind;
|
||||||
|
|
||||||
|
if(!coind_aux || !strcmp(coind->symbol, coind_aux->symbol2))
|
||||||
|
continue;
|
||||||
|
|
||||||
unsigned char target_aux[1024];
|
unsigned char target_aux[1024];
|
||||||
binlify(target_aux, coind_aux->aux.target);
|
binlify(target_aux, coind_aux->aux.target);
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,9 @@ public:
|
||||||
// bool closing;
|
// bool closing;
|
||||||
|
|
||||||
char name[1024];
|
char name[1024];
|
||||||
char symbol[1024];
|
char symbol[256];
|
||||||
|
char symbol2[256];
|
||||||
|
char algo[256];
|
||||||
char wallet[1024];
|
char wallet[1024];
|
||||||
|
|
||||||
char pubkey[1024];
|
char pubkey[1024];
|
||||||
|
|
|
@ -151,6 +151,16 @@ YAAMP_JOB_TEMPLATE *coind_create_template(YAAMP_COIND *coind)
|
||||||
if (strcmp(coind->symbol, "DRP")) // not in Dropcoin
|
if (strcmp(coind->symbol, "DRP")) // not in Dropcoin
|
||||||
strcpy(templ->flags, json_get_string(json_coinbaseaux, "flags"));
|
strcpy(templ->flags, json_get_string(json_coinbaseaux, "flags"));
|
||||||
|
|
||||||
|
// temporary hack, until wallet is fixed...
|
||||||
|
if (!strcmp(coind->symbol, "MBL")) { // MBL: chainid in version
|
||||||
|
unsigned int nVersion = (unsigned int)json_get_int(json_result, "version");
|
||||||
|
if (nVersion & 0xFFFF0000UL == 0) {
|
||||||
|
nVersion |= (0x16UL << 16);
|
||||||
|
debuglog("%s version %s >> %08x\n", coind->symbol, templ->version, nVersion);
|
||||||
|
}
|
||||||
|
sprintf(templ->version, "%08x", nVersion);
|
||||||
|
}
|
||||||
|
|
||||||
// debuglog("%s ntime %s\n", coind->symbol, templ->ntime);
|
// debuglog("%s ntime %s\n", coind->symbol, templ->ntime);
|
||||||
// uint64_t target = decode_compact(json_get_string(json_result, "bits"));
|
// uint64_t target = decode_compact(json_get_string(json_result, "bits"));
|
||||||
// coind->difficulty = target_to_diff(target);
|
// coind->difficulty = target_to_diff(target);
|
||||||
|
|
|
@ -141,7 +141,7 @@ void db_update_coinds(YAAMP_DB *db)
|
||||||
|
|
||||||
db_query(db, "select id, name, rpchost, rpcport, rpcuser, rpcpasswd, rpcencoding, master_wallet, reward, price, "\
|
db_query(db, "select id, name, rpchost, rpcport, rpcuser, rpcpasswd, rpcencoding, master_wallet, reward, price, "\
|
||||||
"hassubmitblock, txmessage, enable, auto_ready, algo, pool_ttf, charity_address, charity_amount, charity_percent, "\
|
"hassubmitblock, txmessage, enable, auto_ready, algo, pool_ttf, charity_address, charity_amount, charity_percent, "\
|
||||||
"reward_mul, symbol, auxpow, actual_ttf, network_ttf, usememorypool, hasmasternodes "\
|
"reward_mul, symbol, auxpow, actual_ttf, network_ttf, usememorypool, hasmasternodes, algo, symbol2 "\
|
||||||
"from coins where enable and auto_ready and algo='%s' order by index_avg", g_stratum_algo);
|
"from coins where enable and auto_ready and algo='%s' order by index_avg", g_stratum_algo);
|
||||||
|
|
||||||
MYSQL_RES *result = mysql_store_result(&db->mysql);
|
MYSQL_RES *result = mysql_store_result(&db->mysql);
|
||||||
|
@ -207,6 +207,9 @@ void db_update_coinds(YAAMP_DB *db)
|
||||||
if(row[24]) coind->usememorypool = atoi(row[24]);
|
if(row[24]) coind->usememorypool = atoi(row[24]);
|
||||||
if(row[25]) coind->hasmasternodes = atoi(row[25]);
|
if(row[25]) coind->hasmasternodes = atoi(row[25]);
|
||||||
|
|
||||||
|
if(row[26]) strcpy(coind->algo, row[26]);
|
||||||
|
if(row[27]) strcpy(coind->symbol2, row[27]); // if pool + aux, prevent double submit
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
coind->touch = true;
|
coind->touch = true;
|
||||||
|
|
|
@ -18,13 +18,11 @@ static bool job_assign_client(YAAMP_JOB *job, YAAMP_CLIENT *client, double maxha
|
||||||
RETURN_ON_CONDITION(client_find_job_history(client, job->id), true);
|
RETURN_ON_CONDITION(client_find_job_history(client, job->id), true);
|
||||||
RETURN_ON_CONDITION(maxhash > 0 && job->speed + client->speed > maxhash, true);
|
RETURN_ON_CONDITION(maxhash > 0 && job->speed + client->speed > maxhash, true);
|
||||||
|
|
||||||
#ifdef NO_EXCHANGE
|
if(!g_autoexchange && maxhash >= 0. && client->coinid != job->coind->id) {
|
||||||
if(maxhash >= 0. && client->coinid != job->coind->id) {
|
|
||||||
//debuglog("prevent client %c on %s, not the right coin\n",
|
//debuglog("prevent client %c on %s, not the right coin\n",
|
||||||
// client->username[0], job->coind->symbol);
|
// client->username[0], job->coind->symbol);
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
if(job->remote)
|
if(job->remote)
|
||||||
{
|
{
|
||||||
|
@ -184,6 +182,7 @@ void job_assign_clients(YAAMP_JOB *job, double maxhash)
|
||||||
|
|
||||||
void job_assign_clients_left(double factor)
|
void job_assign_clients_left(double factor)
|
||||||
{
|
{
|
||||||
|
bool b;
|
||||||
for(CLI li = g_list_coind.first; li; li = li->next)
|
for(CLI li = g_list_coind.first; li; li = li->next)
|
||||||
{
|
{
|
||||||
if(!job_has_free_client()) return;
|
if(!job_has_free_client()) return;
|
||||||
|
@ -198,13 +197,19 @@ void job_assign_clients_left(double factor)
|
||||||
for(CLI li = g_list_client.first; li; li = li->next)
|
for(CLI li = g_list_client.first; li; li = li->next)
|
||||||
{
|
{
|
||||||
YAAMP_CLIENT *client = (YAAMP_CLIENT *)li->data;
|
YAAMP_CLIENT *client = (YAAMP_CLIENT *)li->data;
|
||||||
#ifdef NO_EXCHANGE
|
if (!g_autoexchange) {
|
||||||
debuglog("%s factor %f=>100 nethash %f\n", coind->symbol, factor, nethash);
|
if (client->coinid == coind->id)
|
||||||
if (client->coinid == coind->id)
|
factor = 100.;
|
||||||
factor = 100;
|
else
|
||||||
#endif
|
factor = 0.;
|
||||||
bool b = job_assign_client(coind->job, client, nethash*factor);
|
}
|
||||||
if(!b) break;
|
|
||||||
|
//debuglog("%s %s factor %f nethash %.3f\n", coind->symbol, client->username, factor, nethash);
|
||||||
|
|
||||||
|
if (factor > 0.) {
|
||||||
|
b = job_assign_client(coind->job, client, nethash*factor);
|
||||||
|
if(!b) break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
g_list_client.Leave();
|
g_list_client.Leave();
|
||||||
|
|
|
@ -30,6 +30,7 @@ double g_stratum_difficulty;
|
||||||
int g_stratum_max_ttf;
|
int g_stratum_max_ttf;
|
||||||
bool g_stratum_reconnect;
|
bool g_stratum_reconnect;
|
||||||
bool g_stratum_renting;
|
bool g_stratum_renting;
|
||||||
|
bool g_autoexchange = true;
|
||||||
|
|
||||||
time_t g_last_broadcasted = 0;
|
time_t g_last_broadcasted = 0;
|
||||||
YAAMP_DB *g_db = NULL;
|
YAAMP_DB *g_db = NULL;
|
||||||
|
@ -146,6 +147,11 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
initlog(argv[1]);
|
initlog(argv[1]);
|
||||||
|
|
||||||
|
#ifdef NO_EXCHANGE
|
||||||
|
// todo: init with a db setting or a yiimp shell command
|
||||||
|
g_autoexchange = false;
|
||||||
|
#endif
|
||||||
|
|
||||||
char configfile[1024];
|
char configfile[1024];
|
||||||
sprintf(configfile, "%s.conf", argv[1]);
|
sprintf(configfile, "%s.conf", argv[1]);
|
||||||
|
|
||||||
|
|
|
@ -106,6 +106,8 @@ extern YAAMP_DB *g_db;
|
||||||
extern YAAMP_ALGO g_algos[];
|
extern YAAMP_ALGO g_algos[];
|
||||||
extern YAAMP_ALGO *g_current_algo;
|
extern YAAMP_ALGO *g_current_algo;
|
||||||
|
|
||||||
|
extern bool g_autoexchange;
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
YAAMP_ALGO *stratum_find_algo(const char *name);
|
YAAMP_ALGO *stratum_find_algo(const char *name);
|
||||||
|
|
|
@ -122,7 +122,13 @@ void db_update_workers(YAAMP_DB *db)
|
||||||
|
|
||||||
void db_init_user_coinid(YAAMP_DB *db, YAAMP_CLIENT *client)
|
void db_init_user_coinid(YAAMP_DB *db, YAAMP_CLIENT *client)
|
||||||
{
|
{
|
||||||
db_query(db, "UPDATE accounts SET coinid=%d WHERE id=%d AND IFNULL(coinid,0) = 0",
|
if (!client->userid)
|
||||||
client->coinid, client->userid);
|
return;
|
||||||
|
|
||||||
|
if (!client->coinid)
|
||||||
|
db_query(db, "UPDATE accounts SET coinid=NULL WHERE id=%d", client->userid);
|
||||||
|
else
|
||||||
|
db_query(db, "UPDATE accounts SET coinid=%d WHERE id=%d AND IFNULL(coinid,0) = 0",
|
||||||
|
client->coinid, client->userid);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue