From 7729b5c2efbe8eba017312cbe93af80d0c14cac1 Mon Sep 17 00:00:00 2001 From: AltMinerNet Date: Sat, 6 Jan 2018 13:04:55 +0100 Subject: [PATCH 001/195] stratum: possibility to change sql port --- stratum/db.cpp | 2 +- stratum/stratum.cpp | 2 ++ stratum/stratum.h | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/stratum/db.cpp b/stratum/db.cpp index 765a7dc..7006d61 100644 --- a/stratum/db.cpp +++ b/stratum/db.cpp @@ -12,7 +12,7 @@ void db_reconnect(YAAMP_DB *db) mysql_init(&db->mysql); for(int i=0; i<6; i++) { - MYSQL *p = mysql_real_connect(&db->mysql, g_sql_host, g_sql_username, g_sql_password, g_sql_database, 0, 0, 0); + MYSQL *p = mysql_real_connect(&db->mysql, g_sql_host, g_sql_username, g_sql_password, g_sql_database, g_sql_port, 0, 0); if(p) break; stratumlog("%d, %s\n", i, mysql_error(&db->mysql)); diff --git a/stratum/stratum.cpp b/stratum/stratum.cpp index 6758eea..8c86f75 100644 --- a/stratum/stratum.cpp +++ b/stratum/stratum.cpp @@ -23,6 +23,7 @@ char g_sql_host[1024]; char g_sql_database[1024]; char g_sql_username[1024]; char g_sql_password[1024]; +int g_sql_port = 3306; char g_stratum_coin_include[256]; char g_stratum_coin_exclude[256]; @@ -218,6 +219,7 @@ int main(int argc, char **argv) strcpy(g_sql_database, iniparser_getstring(ini, "SQL:database", NULL)); strcpy(g_sql_username, iniparser_getstring(ini, "SQL:username", NULL)); strcpy(g_sql_password, iniparser_getstring(ini, "SQL:password", NULL)); + g_sql_port = iniparser_getint(ini, "SQL:port", 3306); // optional coin filters (to mine only one on a special port or a test instance) char *coin_filter = iniparser_getstring(ini, "WALLETS:include", NULL); diff --git a/stratum/stratum.h b/stratum/stratum.h index e338e6b..21b6dc1 100644 --- a/stratum/stratum.h +++ b/stratum/stratum.h @@ -74,6 +74,7 @@ extern char g_sql_host[1024]; extern char g_sql_database[1024]; extern char g_sql_username[1024]; extern char g_sql_password[1024]; +extern int g_sql_port; extern char g_stratum_coin_include[256]; extern char g_stratum_coin_exclude[256]; From ab5e4115296a8e3582aedc65b96a3fc5b7c8c248 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Sun, 7 Jan 2018 16:57:11 +0100 Subject: [PATCH 002/195] kucoin exchange api + balances and icons Signed-off-by: Tanguy Pruvot --- web/keys.sample.php | 1 + web/serverconfig.sample.php | 3 + web/yaamp/commands/CoindbCommand.php | 42 +++++- web/yaamp/commands/ExchangeCommand.php | 5 + web/yaamp/core/backend/markets.php | 59 +++++++- web/yaamp/core/backend/rawcoins.php | 14 ++ web/yaamp/core/exchange/exchange.php | 3 + web/yaamp/core/exchange/kucoin.php | 133 ++++++++++++++++++ web/yaamp/core/trading/kucoin_trading.php | 56 ++++++++ web/yaamp/core/trading/trading.php | 9 ++ web/yaamp/defaultconfig.php | 1 + .../modules/thread/CronjobController.php | 1 + 12 files changed, 322 insertions(+), 5 deletions(-) create mode 100644 web/yaamp/core/exchange/kucoin.php create mode 100644 web/yaamp/core/trading/kucoin_trading.php diff --git a/web/keys.sample.php b/web/keys.sample.php index da2034f..a0fd40b 100644 --- a/web/keys.sample.php +++ b/web/keys.sample.php @@ -16,6 +16,7 @@ define('EXCH_CRYPTOPIA_SECRET', ''); define('EXCH_EMPOEX_SECKEY', ''); define('EXCH_HITBTC_SECRET', ''); define('EXCH_KRAKEN_SECRET',''); +define('EXCH_KUCOIN_SECRET', ''); define('EXCH_LIVECOIN_SECRET', ''); define('EXCH_NOVA_SECRET',''); define('EXCH_POLONIEX_SECRET', ''); diff --git a/web/serverconfig.sample.php b/web/serverconfig.sample.php index 742d166..40c083e 100644 --- a/web/serverconfig.sample.php +++ b/web/serverconfig.sample.php @@ -49,12 +49,15 @@ define('EXCH_BLEUTRADE_KEY', ''); define('EXCH_BTER_KEY', ''); define('EXCH_YOBIT_KEY', ''); define('EXCH_CCEX_KEY', ''); +define('EXCH_CEXIO_ID', ''); +define('EXCH_CEXIO_KEY', ''); define('EXCH_COINMARKETS_USER', ''); define('EXCH_COINMARKETS_PIN', ''); define('EXCH_BITSTAMP_ID',''); define('EXCH_BITSTAMP_KEY',''); define('EXCH_HITBTC_KEY',''); define('EXCH_KRAKEN_KEY', ''); +define('EXCH_KUCOIN_KEY', ''); define('EXCH_LIVECOIN_KEY', ''); define('EXCH_NOVA_KEY', ''); define('EXCH_STOCKSEXCHANGE_KEY', ''); diff --git a/web/yaamp/commands/CoindbCommand.php b/web/yaamp/commands/CoindbCommand.php index 41892a4..7d6913b 100644 --- a/web/yaamp/commands/CoindbCommand.php +++ b/web/yaamp/commands/CoindbCommand.php @@ -56,6 +56,7 @@ class CoindbCommand extends CConsoleCommand $nbUpdated += $this->grabBittrexIcons(); // can be huge ones $nbUpdated += $this->grabCoinExchangeIcons(); $nbUpdated += $this->grabAlcurexIcons(); + $nbUpdated += $this->grabKuCoinIcons(); $nbUpdated += $this->grabNovaIcons(); echo "total updated: $nbUpdated\n"; @@ -504,8 +505,7 @@ class CoindbCommand extends CConsoleCommand echo "alcurex: try to download new icons...\n"; foreach ($coins as $coin) { $coin = getdbo('db_coins', $coin["id"]); - $symbol = $coin->symbol; - if (!empty($coin->symbol2)) $symbol = $coin->symbol2; + $symbol = $coin->getOfficialSymbol(); $local = $this->basePath."/images/coin-{$symbol}.png"; try { $data = @ file_get_contents($url.strtoupper($symbol).'.png'); @@ -525,6 +525,41 @@ class CoindbCommand extends CConsoleCommand return $nbUpdated; } + /** + * Icon grabber - KuCoin + */ + public function grabKuCoinIcons() + { + $url = 'https://assets.kucoin.com/www/1.2.0/assets/coins/';//QLC.png + $nbUpdated = 0; + $sql = "SELECT DISTINCT coins.id FROM coins INNER JOIN markets M ON M.coinid = coins.id ". + "WHERE M.name='kucoin' AND IFNULL(coins.image,'') = ''"; + $coins = dbolist($sql); + if (empty($coins)) + return 0; + echo "kucoin: try to download new icons...\n"; + foreach ($coins as $coin) { + $coin = getdbo('db_coins', $coin["id"]); + $symbol = $coin->getOfficialSymbol(); + $local = $this->basePath."/images/coin-{$symbol}.png"; + try { + $data = @ file_get_contents($url.$symbol.'.png'); + } catch (Exception $e) { + continue; + } + if (strlen($data) < 2048) continue; + echo $symbol." icon found\n"; + file_put_contents($local, $data); + if (filesize($local) > 0) { + $coin->image = "/images/coin-{$symbol}.png"; + $nbUpdated += $coin->save(); + } + } + if ($nbUpdated) + echo "$nbUpdated icons downloaded from kucoin\n"; + return $nbUpdated; + } + /** * Icon grabber - NovaExchange */ @@ -540,8 +575,7 @@ class CoindbCommand extends CConsoleCommand echo "nova: try to download new icons...\n"; foreach ($coins as $coin) { $coin = getdbo('db_coins', $coin["id"]); - $symbol = $coin->symbol; - if (!empty($coin->symbol2)) $symbol = $coin->symbol2; + $symbol = $coin->getOfficialSymbol(); $local = $this->basePath."/images/coin-{$symbol}.png"; try { $data = @ file_get_contents($url.strtolower($symbol).'.png'); diff --git a/web/yaamp/commands/ExchangeCommand.php b/web/yaamp/commands/ExchangeCommand.php index 15f143f..44bc860 100644 --- a/web/yaamp/commands/ExchangeCommand.php +++ b/web/yaamp/commands/ExchangeCommand.php @@ -181,6 +181,11 @@ class ExchangeCommand extends CConsoleCommand $balance = kraken_api_user('Balance'); echo("kraken btc: ".json_encode($balance)."\n"); } + if (!empty(EXCH_KUCOIN_KEY)) { + $balance = kucoin_api_user('account/BTC/balance'); + if (!is_object($balance) || !isset($balance->data)) echo "kucoin error ".json_encode($balance)."\n"; + else echo("kucoin: ".json_encode($balance->data)."\n"); + } if (!empty(EXCH_LIVECOIN_KEY)) { $livecoin = new LiveCoinApi; $balance = $livecoin->getBalances('BTC'); diff --git a/web/yaamp/core/backend/markets.php b/web/yaamp/core/backend/markets.php index 83c5b27..14aed56 100644 --- a/web/yaamp/core/backend/markets.php +++ b/web/yaamp/core/backend/markets.php @@ -14,6 +14,7 @@ function BackendPricesUpdate() updatePoloniexMarkets(); updateBleutradeMarkets(); updateKrakenMarkets(); + updateKuCoinMarkets(); updateCCexMarkets(); updateCryptopiaMarkets(); updateHitBTCMarkets(); @@ -1167,6 +1168,62 @@ function updateEmpoexMarkets() } } +function updateKuCoinMarkets() +{ + $exchange = 'kucoin'; + if (exchange_get($exchange, 'disabled')) return; + + $markets = kucoin_api_query('open/symbols','market=BTC'); + if(!is_object($markets) || !isset($markets->data) || empty($markets->data)) return; + + $coininfo = NULL; //kucoin_api_query('market/open/coins'); + if(!is_object($coininfo) || !isset($coininfo->data) || empty($coininfo->data)) { + $coininfo = NULL; + } + + $list = getdbolist('db_markets', "name='$exchange'"); + foreach($list as $market) + { + $coin = getdbo('db_coins', $market->coinid); + if(!$coin) continue; + + $symbol = $coin->getOfficialSymbol(); + if (market_get($exchange, $symbol, "disabled")) { + $market->disabled = 1; + $market->message = 'disabled from settings'; + $market->save(); + continue; + } + + $pair = strtoupper($symbol).'-BTC'; + + foreach ($markets->data as $ticker) { + if ($ticker->symbol != $pair) continue; + + $market->price = AverageIncrement($market->price, $ticker->buy); + $market->price2 = AverageIncrement($market->price2, $ticker->sell); + if (!empty($coininfo)) foreach ($coininfo->data as $info) { + if ($info->coin == $symbol) { + //todo: $market->withdrawfee = $info->withdrawMinFee; + break; + } + } + $market->txfee = $ticker->feeRate * 100; // is 0.1% for trades (0.001) + $market->priority = -1; + $market->pricetime = time(); + + if (floatval($ticker->vol) > 0.01) + $market->save(); + + if (empty($coin->price2)) { + $coin->price = $market->price; + $coin->price2 = $market->price2; + $coin->save(); + } + } + } +} + function updateLiveCoinMarkets() { $exchange = 'livecoin'; @@ -1489,7 +1546,7 @@ function updateShapeShiftMarkets() $market->price = AverageIncrement($market->price, $ticker['rate']); $market->price2 = AverageIncrement($market->price2, $ticker['rate']); - $market->txfee = $ticker['minerFee']; + $market->txfee = $ticker['minerFee'] * 100; $market->pricetime = time(); $market->priority = -1; // not ready for trading $market->save(); diff --git a/web/yaamp/core/backend/rawcoins.php b/web/yaamp/core/backend/rawcoins.php index 8e7bdf9..670af51 100644 --- a/web/yaamp/core/backend/rawcoins.php +++ b/web/yaamp/core/backend/rawcoins.php @@ -259,6 +259,20 @@ function updateRawcoins() } } + if (!exchange_get('kucoin', 'disabled')) { + $list = kucoin_api_query('market/open/coins'); + if(is_object($list) && isset($list->data) && !empty($list->data)) + { + dborun("UPDATE markets SET deleted=true WHERE name='kucoin'"); + foreach($list->data as $item) { + $symbol = $item->coin; + $name = $item->name; + if (strpos($item->withdrawRemark,'Ethereum')) continue; + updateRawCoin('kucoin', $symbol, $name); + } + } + } + if (!exchange_get('livecoin', 'disabled')) { $list = livecoin_api_query('exchange/ticker'); if(is_array($list)) diff --git a/web/yaamp/core/exchange/exchange.php b/web/yaamp/core/exchange/exchange.php index b690f83..6a8b851 100644 --- a/web/yaamp/core/exchange/exchange.php +++ b/web/yaamp/core/exchange/exchange.php @@ -29,6 +29,7 @@ require_once("alcurex.php"); require_once("binance.php"); require_once("cryptopia.php"); require_once("hitbtc.php"); +require_once("kucoin.php"); require_once("livecoin.php"); require_once("nova.php"); require_once("coinexchange.php"); @@ -101,6 +102,8 @@ function getMarketUrl($coin, $marketName) $url = "http://jubi.com/coin/{$lowsymbol}"; else if($market == 'hitbtc') $url = "https://hitbtc.com/exchange/{$symbol}-to-{$base}"; + else if($market == 'kucoin') + $url = "https://www.kucoin.com/#/trade.pro/{$symbol}-{$base}"; else if($market == 'livecoin') $url = "https://www.livecoin.net/trade/?currencyPair={$symbol}%2F{$base}"; else if($market == 'nova') diff --git a/web/yaamp/core/exchange/kucoin.php b/web/yaamp/core/exchange/kucoin.php new file mode 100644 index 0000000..ac71b67 --- /dev/null +++ b/web/yaamp/core/exchange/kucoin.php @@ -0,0 +1,133 @@ +/wallet/address + +function kucoin_api_user($method, $params=NULL, $isPostMethod=false) +{ + require_once('/etc/yiimp/keys.php'); + if (!defined('EXCH_KUCOIN_SECRET')) define('EXCH_KUCOIN_SECRET', ''); + + if (empty(EXCH_KUCOIN_KEY) || empty(EXCH_KUCOIN_SECRET)) return false; + + $api_host = 'https://api.kucoin.com'; + $mt = explode(' ', microtime()); + $nonce = $mt[1].substr($mt[0], 2, 3); + $url = $endpoint = "/v1/$method"; + $tosign = "$endpoint/$nonce/"; + + if (empty($params)) $params = array(); + $query = http_build_query($params); + if (strlen($query) && !$isPostMethod) { + $url .= '&'.$query; $query = ''; + } + if ($isPostMethod) $post_data = $params; + $hmac = strtolower(hash_hmac('sha256', base64_encode($tosign.$query), EXCH_KUCOIN_SECRET)); + + $headers = array( + 'Content-Type: application/json;charset=UTF-8', + 'KC-API-KEY: '.EXCH_KUCOIN_KEY, + 'KC-API-NONCE: '.$nonce, + 'KC-API-SIGNATURE: '.$hmac, + ); + + $ch = curl_init(); + + curl_setopt($ch, CURLOPT_URL, $api_host.$url); + curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + if ($isPostMethod) { + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); + } + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); + curl_setopt($ch, CURLOPT_TIMEOUT, 30); + curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; KuCoin API PHP client; '.php_uname('s').'; PHP/'.phpversion().')'); + curl_setopt($ch, CURLOPT_ENCODING , ''); + //curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + //curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); + //curl_setopt($ch, CURLOPT_VERBOSE, 1); + + $res = curl_exec($ch); + if($res === false) { + $e = curl_error($ch); + debuglog("kucoin: $e"); + curl_close($ch); + return false; + } + + $result = json_decode($res); + if(!is_object($result) && !is_array($result)) { + $status = curl_getinfo($ch, CURLINFO_HTTP_CODE); + debuglog("kucoin: $method failed ($status) ".strip_data($res)); + } + + curl_close($ch); + + return $result; +} + +////////////////////////////////////////////////////////////////////////////////////////////////////////////// + +// manual update of one market +function kucoin_update_market($market) +{ + $exchange = 'kucoin'; + if (is_string($market)) + { + $symbol = $market; + $coin = getdbosql('db_coins', "symbol=:sym", array(':sym'=>$symbol)); + if(!$coin) return false; + $pair = $symbol.'-BTC'; + $market = getdbosql('db_markets', "coinid={$coin->id} AND name='$exchange'"); + if(!$market) return false; + + } else if (is_object($market)) { + + $coin = getdbo('db_coins', $market->coinid); + if(!$coin) return false; + $symbol = $coin->getOfficialSymbol(); + $pair = $symbol.'-BTC'; + if (!empty($market->base_coin)) $pair = $symbol.'-'.$market->base_coin; + } + + $t1 = microtime(true); + $query = kucoin_api_query("$pair/open/tick"); + if(!is_object($query) || !isset($query->data)) return false; + $ticker = $ticker->data; + + $price2 = ((double) $ticker->buy + (double)$ticker->sell)/2; + $market->price2 = AverageIncrement($market->price2, $price2); + $market->price = AverageIncrement($market->price, $ticker->buy); + $market->pricetime = time(); + $market->save(); + + $apims = round((microtime(true) - $t1)*1000,3); + user()->setFlash('message', "$exchange $symbol price updated in $apims ms"); + + return true; +} diff --git a/web/yaamp/core/trading/kucoin_trading.php b/web/yaamp/core/trading/kucoin_trading.php new file mode 100644 index 0000000..33fe34d --- /dev/null +++ b/web/yaamp/core/trading/kucoin_trading.php @@ -0,0 +1,56 @@ +data)) return; + + $savebalance = getdbosql('db_balances', "name='$exchange'"); + + if (is_array($data->data)) + foreach($data->data as $balance) + { + if ($balance->coinType == 'BTC') { + if (is_object($savebalance)) { + $savebalance->balance = $balance->balance; + $savebalance->save(); + } + continue; + } + + if ($updatebalances) { + // store available balance in market table + $coins = getdbolist('db_coins', "symbol=:symbol OR symbol2=:symbol", + array(':symbol'=>$balance->coinType) + ); + if (empty($coins)) continue; + foreach ($coins as $coin) { + $market = getdbosql('db_markets', + "coinid=:coinid AND name='$exchange' ORDER BY balance" + , array(':coinid'=>$coin->id) + ); + if (!$market) continue; + $market->balance = $balance->balance; + $market->ontrade = $balance->freezeBalance; + $market->balancetime = time(); + $market->save(); + } + } + } + + if (!YAAMP_ALLOW_EXCHANGE) return; + + // real trading, todo.. +} diff --git a/web/yaamp/core/trading/trading.php b/web/yaamp/core/trading/trading.php index 525fa25..1ce4773 100644 --- a/web/yaamp/core/trading/trading.php +++ b/web/yaamp/core/trading/trading.php @@ -10,6 +10,7 @@ require_once('alcurex_trading.php'); require_once('coinsmarkets_trading.php'); require_once('cryptopia_trading.php'); require_once('hitbtc_trading.php'); +require_once('kucoin_trading.php'); require_once('livecoin_trading.php'); require_once('nova_trading.php'); @@ -37,6 +38,9 @@ function cancelExchangeOrder($order=false) case 'hitbtc': doHitBTCCancelOrder($order->uuid); break; + case 'kucoin': + doKuCoinCancelOrder($order->uuid); + break; case 'livecoin': doLiveCoinCancelOrder($order->uuid); break; @@ -113,6 +117,11 @@ function runExchange($exchangeName=false) updateKrakenMarkets(); break; + case 'kucoin': + doKuCoinTrading(true); + updateKucoinMarkets(); + break; + case 'livecoin': doLiveCoinTrading(true); updateLiveCoinMarkets(); diff --git a/web/yaamp/defaultconfig.php b/web/yaamp/defaultconfig.php index c260f44..26ff494 100644 --- a/web/yaamp/defaultconfig.php +++ b/web/yaamp/defaultconfig.php @@ -39,6 +39,7 @@ if (!defined('EXCH_HITBTC_KEY')) define('EXCH_HITBTC_KEY', ''); if (!defined('EXCH_POLONIEX_KEY')) define('EXCH_POLONIEX_KEY', ''); if (!defined('EXCH_YOBIT_KEY')) define('EXCH_YOBIT_KEY', ''); if (!defined('EXCH_KRAKEN_KEY')) define('EXCH_KRAKEN_KEY', ''); +if (!defined('EXCH_KUCOIN_KEY')) define('EXCH_KUCOIN_KEY', ''); if (!defined('EXCH_LIVECOIN_KEY')) define('EXCH_LIVECOIN_KEY', ''); if (!defined('EXCH_NOVA_KEY')) define('EXCH_NOVA_KEY', ''); if (!defined('EXCH_STOCKSEXCHANGE_KEY')) define('EXCH_STOCKSEXCHANGE_KEY', ''); diff --git a/web/yaamp/modules/thread/CronjobController.php b/web/yaamp/modules/thread/CronjobController.php index b6bd7db..9d00dfd 100644 --- a/web/yaamp/modules/thread/CronjobController.php +++ b/web/yaamp/modules/thread/CronjobController.php @@ -147,6 +147,7 @@ class CronjobController extends CommonController doCCexTrading(); doBterTrading(); doBleutradeTrading(); + doKuCoinTrading(); doNovaTrading(); doCoinsMarketsTrading(); break; From 1d523798be48acfaabb6be0cacd9818325244e6c Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Tue, 9 Jan 2018 17:52:34 +0100 Subject: [PATCH 003/195] stratum: use new dash masternodes as default remember to do a make clean... coind struct was changed --- stratum/coinbase.cpp | 13 +++---------- stratum/coind.h | 1 + stratum/db.cpp | 9 +++++++++ 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/stratum/coinbase.cpp b/stratum/coinbase.cpp index b37bca8..bbe7df2 100644 --- a/stratum/coinbase.cpp +++ b/stratum/coinbase.cpp @@ -213,15 +213,8 @@ void coinbase_create(YAAMP_COIND *coind, YAAMP_JOB_TEMPLATE *templ, json_value * } } - if(strcmp(coind->symbol, "SIB") == 0 || - strcmp(coind->symbol, "MUE") == 0 || // MUEcore-x11 - strcmp(coind->symbol, "VIVO") == 0 || // VIVO coin - strcmp(coind->symbol, "INN") == 0 || // Innova coin - strcmp(coind->symbol, "DSR") == 0 || // Desire coin - strcmp(coind->symbol, "ONEX") == 0 || // ONEX Cash - strcmp(coind->symbol, "GBX") == 0 || // GoByte - strcmp(coind->symbol, "KZC") == 0 || // KZ Cash - strcmp(coind->symbol, "DASH") == 0 || strcmp(coind->symbol, "DASH-TESTNET") == 0) // Dash 12.1 + // most recent masternodes rpc (DASH, SIB, MUE, DSR, GBX...) + if(coind->hasmasternodes && !coind->oldmasternodes) { char script_dests[2048] = { 0 }; char script_payee[128] = { 0 }; @@ -351,7 +344,7 @@ void coinbase_create(YAAMP_COIND *coind, YAAMP_JOB_TEMPLATE *templ, json_value * } - else if(coind->hasmasternodes) /* OLD DASH style */ + else if(coind->hasmasternodes && coind->oldmasternodes) /* OLD DASH style */ { char charity_payee[256] = { 0 }; const char *payee = json_get_string(json_result, "payee"); diff --git a/stratum/coind.h b/stratum/coind.h index aae8eb3..5ea7fff 100644 --- a/stratum/coind.h +++ b/stratum/coind.h @@ -65,6 +65,7 @@ public: bool usegetwork; bool usememorypool; bool hasmasternodes; + bool oldmasternodes; bool noblocknotify; bool multialgos; // pow_hash field (or mined_hash) diff --git a/stratum/db.cpp b/stratum/db.cpp index 7006d61..71a8600 100644 --- a/stratum/db.cpp +++ b/stratum/db.cpp @@ -282,6 +282,15 @@ void db_update_coinds(YAAMP_DB *db) if(!strcmp(coind->symbol, "DCR") && strcmp(coind->rpcencoding, "DCR")) strcpy(coind->rpcencoding, "DCR"); + // old dash masternodes coins.. + if(coind->hasmasternodes) { + if (strcmp(coind->symbol, "BSD") == 0) coind->oldmasternodes = true; + if (strcmp(coind->symbol, "CHC") == 0) coind->oldmasternodes = true; + if (strcmp(coind->symbol, "CRW") == 0) coind->oldmasternodes = true; + if (strcmp(coind->symbol, "FLAX") == 0) coind->oldmasternodes = true; + if (strcmp(coind->symbol, "J") == 0 || strcmp(coind->symbol2, "J") == 0) coind->oldmasternodes = true; + } + //////////////////////////////////////////////////////////////////////////////////////////////////// //coind->touch = true; From 383682190bdccd776b351ebb85780a446a2884ba Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Tue, 9 Jan 2018 21:27:09 +0100 Subject: [PATCH 004/195] stratum: prevent double auth & ignore invalid sockets seems to works well, but not a normal case/behavior --- stratum/client.cpp | 7 +++++++ stratum/job_send.cpp | 1 + 2 files changed, 8 insertions(+) diff --git a/stratum/client.cpp b/stratum/client.cpp index e0bf1fb..e50f03c 100644 --- a/stratum/client.cpp +++ b/stratum/client.cpp @@ -197,6 +197,13 @@ bool client_validate_user_address(YAAMP_CLIENT *client) bool client_authorize(YAAMP_CLIENT *client, json_value *json_params) { + + if(g_list_client.Find(client)) { + clientlog(client, "Already logged"); + client_send_error(client, 21, "Already logged"); + return false; + } + if(json_params->u.array.length>1) strncpy(client->password, json_params->u.array.values[1]->u.string.ptr, 1023); diff --git a/stratum/job_send.cpp b/stratum/job_send.cpp index d1d8567..8ed6a23 100644 --- a/stratum/job_send.cpp +++ b/stratum/job_send.cpp @@ -107,6 +107,7 @@ void job_broadcast(YAAMP_JOB *job) { YAAMP_CLIENT *client = (YAAMP_CLIENT *)li->data; if(client->deleted) continue; + if(!client->sock) continue; // if(client->reconnecting && client->locked) continue; if(client->jobid_next != job->id) continue; From 9a0aedfacd3fd3d3e80417b78d0efd19037deb12 Mon Sep 17 00:00:00 2001 From: crackfoo Date: Tue, 9 Jan 2018 20:01:21 -0400 Subject: [PATCH 005/195] bittrex: update min trade (#203) --- web/yaamp/core/trading/bittrex_trading.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/yaamp/core/trading/bittrex_trading.php b/web/yaamp/core/trading/bittrex_trading.php index a3bbe64..9240eac 100644 --- a/web/yaamp/core/trading/bittrex_trading.php +++ b/web/yaamp/core/trading/bittrex_trading.php @@ -66,7 +66,7 @@ function doBittrexTrading($quick=false) if($quick) $flushall = false; // minimum order allowed by the exchange - $min_btc_trade = exchange_get($exchange, 'trade_min_btc', 0.00050000); + $min_btc_trade = exchange_get($exchange, 'trade_min_btc', 0.00100000); // sell on ask price + 5% $sell_ask_pct = exchange_get($exchange, 'trade_sell_ask_pct', 1.05); // cancel order if our price is more than ask price + 20% From d20093519879b3069e22959774d1b7ed08db4815 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Wed, 10 Jan 2018 15:54:09 +0100 Subject: [PATCH 006/195] stratum: null ptr check on json arrays --- stratum/json.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stratum/json.cpp b/stratum/json.cpp index ca70ef7..3ceba40 100644 --- a/stratum/json.cpp +++ b/stratum/json.cpp @@ -503,7 +503,7 @@ json_value * json_parse_ex (json_settings * settings, case ']': - if (top->type == json_array) + if (top && top->type == json_array) flags = (flags & ~ (flag_need_comma | flag_seek_value)) | flag_next; else { sprintf (error, "%d:%d: Unexpected ]", cur_line, e_off); From bc68c041638654518ea64488d4dadfaee10b501a Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Wed, 10 Jan 2018 16:10:24 +0100 Subject: [PATCH 007/195] stratum: handle more old masternodes (#204) --- stratum/db.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/stratum/db.cpp b/stratum/db.cpp index 71a8600..30124d5 100644 --- a/stratum/db.cpp +++ b/stratum/db.cpp @@ -288,7 +288,11 @@ void db_update_coinds(YAAMP_DB *db) if (strcmp(coind->symbol, "CHC") == 0) coind->oldmasternodes = true; if (strcmp(coind->symbol, "CRW") == 0) coind->oldmasternodes = true; if (strcmp(coind->symbol, "FLAX") == 0) coind->oldmasternodes = true; + if (strcmp(coind->symbol, "ITZ") == 0) coind->oldmasternodes = true; if (strcmp(coind->symbol, "J") == 0 || strcmp(coind->symbol2, "J") == 0) coind->oldmasternodes = true; + if (strcmp(coind->symbol, "URALS") == 0) coind->oldmasternodes = true; + if (strcmp(coind->symbol, "VSX") == 0) coind->oldmasternodes = true; + if (strcmp(coind->symbol, "XLR") == 0) coind->oldmasternodes = true; } //////////////////////////////////////////////////////////////////////////////////////////////////// From d7b980b2199abf4a638a4c36dc5ffeae7481d7fb Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Thu, 11 Jan 2018 14:24:30 +0100 Subject: [PATCH 008/195] home: update project description --- web/yaamp/modules/site/index.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/web/yaamp/modules/site/index.php b/web/yaamp/modules/site/index.php index 60697cf..a1888b8 100644 --- a/web/yaamp/modules/site/index.php +++ b/web/yaamp/modules/site/index.php @@ -28,13 +28,13 @@ $payout_freq = (YAAMP_PAYMENTS_FREQ / 3600)." hours";
-
YII MINING POOL
+
YII MINING POOLS
    -
  • YIIMP is a pool management solution based on the Yii Framework.
  • -
  • This fork based on the Yaamp published source code will be soon another open source project.
  • +
  • YiiMP is a pool management solution based on the Yii Framework.
  • +
  • This fork was based on the yaamp source code and is now an open source project.
  • No registration is required, we do payouts in the currency you mine. Use your wallet address as the username.
  •  
  • Payouts are made automatically every for all balances above , or on Sunday.
  • From accb3b4bd3b6f13edba818520e236d10960ec7ba Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Fri, 12 Jan 2018 13:08:02 +0100 Subject: [PATCH 009/195] kucoin: daily check deposit addresses + typo on manual ticker update --- web/yaamp/core/backend/markets.php | 5 +-- web/yaamp/core/exchange/kucoin.php | 40 ++++++++++++++++++----- web/yaamp/core/trading/kucoin_trading.php | 16 ++++++++- 3 files changed, 49 insertions(+), 12 deletions(-) diff --git a/web/yaamp/core/backend/markets.php b/web/yaamp/core/backend/markets.php index 14aed56..f69fe10 100644 --- a/web/yaamp/core/backend/markets.php +++ b/web/yaamp/core/backend/markets.php @@ -1174,10 +1174,10 @@ function updateKuCoinMarkets() if (exchange_get($exchange, 'disabled')) return; $markets = kucoin_api_query('open/symbols','market=BTC'); - if(!is_object($markets) || !isset($markets->data) || empty($markets->data)) return; + if(!kucoin_result_valid($markets) || empty($markets->data)) return; $coininfo = NULL; //kucoin_api_query('market/open/coins'); - if(!is_object($coininfo) || !isset($coininfo->data) || empty($coininfo->data)) { + if(!kucoin_result_valid($coininfo) || empty($coininfo->data)) { $coininfo = NULL; } @@ -1199,6 +1199,7 @@ function updateKuCoinMarkets() foreach ($markets->data as $ticker) { if ($ticker->symbol != $pair) continue; + if (objSafeVal($ticker,'buy',-1) == -1) continue; $market->price = AverageIncrement($market->price, $ticker->buy); $market->price2 = AverageIncrement($market->price2, $ticker->sell); diff --git a/web/yaamp/core/exchange/kucoin.php b/web/yaamp/core/exchange/kucoin.php index ac71b67..743c86e 100644 --- a/web/yaamp/core/exchange/kucoin.php +++ b/web/yaamp/core/exchange/kucoin.php @@ -1,9 +1,18 @@ data)) return false; + return true; +} + // https://api.kucoin.com/v1/open/symbols/?market=BTC function kucoin_api_query($method, $params='', $returnType='object') { + $exchange = 'kucoin'; $url = "https://api.kucoin.com/v1/$method/"; if (!empty($params)) $url .= "?$params"; @@ -16,12 +25,24 @@ function kucoin_api_query($method, $params='', $returnType='object') curl_setopt($ch, CURLOPT_ENCODING , ''); //curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); - $execResult = curl_exec($ch); - if ($returnType == 'object') - $ret = json_decode($execResult); - else - $ret = json_decode($execResult,true); + $res = curl_exec($ch); + if($res === false) { + $e = curl_error($ch); + debuglog("$exchange: $method $e"); + curl_close($ch); + return false; + } + if ($returnType == 'object') + $ret = json_decode($res); + else + $ret = json_decode($res,true); + + if(!is_object($ret) && !is_array($ret)) { + $status = curl_getinfo($ch, CURLINFO_HTTP_CODE); + debuglog("$exchange: $method failed ($status) ".strip_data($res)); + } + curl_close($ch); return $ret; } @@ -29,6 +50,7 @@ function kucoin_api_query($method, $params='', $returnType='object') function kucoin_api_user($method, $params=NULL, $isPostMethod=false) { + $exchange = 'kucoin'; require_once('/etc/yiimp/keys.php'); if (!defined('EXCH_KUCOIN_SECRET')) define('EXCH_KUCOIN_SECRET', ''); @@ -75,7 +97,7 @@ function kucoin_api_user($method, $params=NULL, $isPostMethod=false) $res = curl_exec($ch); if($res === false) { $e = curl_error($ch); - debuglog("kucoin: $e"); + debuglog("$exchange: $method $e"); curl_close($ch); return false; } @@ -83,7 +105,7 @@ function kucoin_api_user($method, $params=NULL, $isPostMethod=false) $result = json_decode($res); if(!is_object($result) && !is_array($result)) { $status = curl_getinfo($ch, CURLINFO_HTTP_CODE); - debuglog("kucoin: $method failed ($status) ".strip_data($res)); + debuglog("$exchange: $method failed ($status) ".strip_data($res)); } curl_close($ch); @@ -117,8 +139,8 @@ function kucoin_update_market($market) $t1 = microtime(true); $query = kucoin_api_query("$pair/open/tick"); - if(!is_object($query) || !isset($query->data)) return false; - $ticker = $ticker->data; + if(!kucoin_result_valid($query)) return false; + $ticker = $query->data; $price2 = ((double) $ticker->buy + (double)$ticker->sell)/2; $market->price2 = AverageIncrement($market->price2, $price2); diff --git a/web/yaamp/core/trading/kucoin_trading.php b/web/yaamp/core/trading/kucoin_trading.php index 33fe34d..394a614 100644 --- a/web/yaamp/core/trading/kucoin_trading.php +++ b/web/yaamp/core/trading/kucoin_trading.php @@ -15,7 +15,7 @@ function doKuCoinTrading($quick=false) if (exchange_get($exchange, 'disabled')) return; $data = kucoin_api_user('account/balance'); - if (!is_object($data) || !isset($data->data)) return; + if (!kucoin_result_valid($data)) return; $savebalance = getdbosql('db_balances', "name='$exchange'"); @@ -46,6 +46,20 @@ function doKuCoinTrading($quick=false) $market->ontrade = $balance->freezeBalance; $market->balancetime = time(); $market->save(); + + $checked_today = cache()->get($exchange.'-deposit_address-check-'.$coin->symbol); + if ($coin->installed && !$checked_today) { + sleep(1); + $obj = kucoin_api_user("account/{$coin->symbol}/wallet/address"); + if (!kucoin_result_valid($obj)) continue; + $result = $obj->data; + $deposit_address = objSafeVal($result,'address'); + if (!empty($deposit_address) && $deposit_address != $market->deposit_address) { + debuglog("$exchange: updated {$coin->symbol} deposit address $deposit_address"); + $market->save(); + } + cache()->set($exchange.'-deposit_address-check-'.$coin->symbol, time(), 24*3600); + } } } } From 5ae0afb43d847cc0655d9ea07a57bd86779270fe Mon Sep 17 00:00:00 2001 From: Jia Wu Date: Sat, 13 Jan 2018 14:36:59 -0500 Subject: [PATCH 010/195] ui: remove css width % from footer (#206) Was bothering me a lot. --- web/yaamp/ui/css/main.css | 1 - 1 file changed, 1 deletion(-) diff --git a/web/yaamp/ui/css/main.css b/web/yaamp/ui/css/main.css index b759a8e..747860e 100644 --- a/web/yaamp/ui/css/main.css +++ b/web/yaamp/ui/css/main.css @@ -149,7 +149,6 @@ hr font-weight: bold; text-align: center; padding: 10px; - width: 98%; background-color: #ccc; color: #333; } From fda559bca48e9e6660b2359240eccb28c5e4363d Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Sun, 14 Jan 2018 00:43:15 +0100 Subject: [PATCH 011/195] stratum: hsr sm3 cleanup + rotl32 issue --- stratum/algos/sm3.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/stratum/algos/sm3.c b/stratum/algos/sm3.c index 295ba15..b627cb8 100644 --- a/stratum/algos/sm3.c +++ b/stratum/algos/sm3.c @@ -153,17 +153,17 @@ void sm3_compress(uint32_t digest[8], const unsigned char block[64]) uint32_t H = digest[7]; uint32_t SS1,SS2,TT1,TT2,T[64]; - for (j = 0; j < 16; j++) { + for(j = 0; j < 16; j++) { W[j] = cpu_to_be32(pblock[j]); } - for (j = 16; j < 68; j++) { + for(j = 16; j < 68; j++) { W[j] = P1( W[j-16] ^ W[j-9] ^ ROTATELEFT(W[j-3],15)) ^ ROTATELEFT(W[j - 13],7 ) ^ W[j-6];; } - for( j = 0; j < 64; j++) { + for(j = 0; j < 64; j++) { W1[j] = W[j] ^ W[j+4]; } - for(j =0; j < 16; j++) { + for(j = 0; j < 16; j++) { T[j] = 0x79CC4519; SS1 = ROTATELEFT((ROTATELEFT(A,12) + E + ROTATELEFT(T[j],j)), 7); @@ -180,10 +180,10 @@ void sm3_compress(uint32_t digest[8], const unsigned char block[64]) E = P0(TT2); } - for(j =16; j < 64; j++) { + for(j = 16; j < 64; j++) { T[j] = 0x7A879D8A; - SS1 = ROTATELEFT((ROTATELEFT(A,12) + E + ROTATELEFT(T[j],j)), 7); + SS1 = ROTATELEFT((ROTATELEFT(A,12) + E + ROTATELEFT(T[j],j&31)), 7); SS2 = SS1 ^ ROTATELEFT(A,12); TT1 = FF1(A,B,C) + D + SS2 + W1[j]; TT2 = GG1(E,F,G) + H + SS1 + W[j]; From e569b5774903b6eaaeb36ac28b0a4d3b1716b794 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Sun, 14 Jan 2018 20:10:34 +0100 Subject: [PATCH 012/195] binance: auth rest api function --- web/keys.sample.php | 1 + web/serverconfig.sample.php | 1 + web/yaamp/commands/ExchangeCommand.php | 10 ++++ web/yaamp/core/exchange/binance.php | 72 ++++++++++++++++++++++++++ web/yaamp/defaultconfig.php | 1 + 5 files changed, 85 insertions(+) diff --git a/web/keys.sample.php b/web/keys.sample.php index a0fd40b..63509ca 100644 --- a/web/keys.sample.php +++ b/web/keys.sample.php @@ -7,6 +7,7 @@ define('YIIMP_MYSQLDUMP_PASS', ''); /* Keys required to create/cancel orders and access your balances/deposit addresses */ define('EXCH_BITTREX_SECRET', ''); define('EXCH_BITSTAMP_SECRET',''); +define('EXCH_BINANCE_SECRET', ''); define('EXCH_BLEUTRADE_SECRET', ''); define('EXCH_BTER_SECRET', ''); define('EXCH_CCEX_SECRET', ''); diff --git a/web/serverconfig.sample.php b/web/serverconfig.sample.php index 40c083e..59b4a7f 100644 --- a/web/serverconfig.sample.php +++ b/web/serverconfig.sample.php @@ -53,6 +53,7 @@ define('EXCH_CEXIO_ID', ''); define('EXCH_CEXIO_KEY', ''); define('EXCH_COINMARKETS_USER', ''); define('EXCH_COINMARKETS_PIN', ''); +define('EXCH_BINANCE_KEY', ''); define('EXCH_BITSTAMP_ID',''); define('EXCH_BITSTAMP_KEY',''); define('EXCH_HITBTC_KEY',''); diff --git a/web/yaamp/commands/ExchangeCommand.php b/web/yaamp/commands/ExchangeCommand.php index 44bc860..73f538f 100644 --- a/web/yaamp/commands/ExchangeCommand.php +++ b/web/yaamp/commands/ExchangeCommand.php @@ -122,6 +122,16 @@ class ExchangeCommand extends CConsoleCommand public function testApiKeys() { + if (!empty(EXCH_BINANCE_KEY)) { + $balance = binance_api_user('account'); + if (!is_object($balance)) echo "binance error ".json_encode($balance)."\n"; + else { + $assets = $balance->balances; + foreach ($assets as $asset) { + if ($asset->asset == 'BTC') echo("binance: ".json_encode($asset)."\n"); + } + } + } if (!empty(EXCH_BITSTAMP_KEY)) { $balance = bitstamp_api_user('balance'); if (!is_array($balance)) echo "bitstamp error ".json_encode($balance)."\n"; diff --git a/web/yaamp/core/exchange/binance.php b/web/yaamp/core/exchange/binance.php index a83b44c..456d09d 100644 --- a/web/yaamp/core/exchange/binance.php +++ b/web/yaamp/core/exchange/binance.php @@ -4,19 +4,91 @@ function binance_api_query($method) { + $exchange = 'binance'; $uri = "https://www.binance.com/api/v1/$method"; $ch = curl_init($uri); + curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; Binance API PHP client; '.php_uname('s').'; PHP/'.PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION.')'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); curl_setopt($ch, CURLOPT_TIMEOUT, 30); $res = curl_exec($ch); $obj = json_decode($res); + if(!is_object($obj) && !is_array($obj)) { + $status = curl_getinfo($ch, CURLINFO_HTTP_CODE); + debuglog("$exchange: $method failed ($status) ".strip_data($res)); + } return $obj; } +// https://api.binance.com/api/v3/account + +function binance_api_user($method, $params=NULL) +{ + $exchange = 'binance'; + require_once('/etc/yiimp/keys.php'); + if (!defined('EXCH_BINANCE_SECRET')) define('EXCH_BINANCE_SECRET', ''); + + if (empty(EXCH_BINANCE_KEY) || empty(EXCH_BINANCE_SECRET)) return false; + + $mt = explode(' ', microtime()); + $nonce = $mt[1].substr($mt[0], 2, 3); + $url = "https://api.binance.com/api/v3/$method"; + + if (empty($params)) $params = array(); + $params['timestamp'] = $nonce; + $query = http_build_query($params, '', '&'); + + $hmac = strtolower(hash_hmac('sha256', $query, EXCH_BINANCE_SECRET)); + $isPostMethod = ($method == 'order'); + if ($isPostMethod) + $query .= '&signature='.$hmac; + else + $url .= '?'.$query.'&signature='.$hmac; + + $headers = array( + 'Content-Type: application/json;charset=UTF-8', + 'X-MBX-APIKEY: '.EXCH_BINANCE_KEY, + ); + + $ch = curl_init(); + + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + if ($isPostMethod) { + curl_setopt($ch, CURLOPT_POST, true); + curl_setopt($ch, CURLOPT_POSTFIELDS, $query); + } + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10); + curl_setopt($ch, CURLOPT_TIMEOUT, 30); + curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; Binance API PHP client; '.php_uname('s').'; PHP/'.PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION.')'); + curl_setopt($ch, CURLOPT_ENCODING , ''); + //curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + //curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); + //curl_setopt($ch, CURLOPT_VERBOSE, 1); + + $res = curl_exec($ch); + if($res === false) { + $e = curl_error($ch); + debuglog("$exchange: $method $e"); + curl_close($ch); + return false; + } + + $result = json_decode($res); + if(!is_object($result) && !is_array($result)) { + $status = curl_getinfo($ch, CURLINFO_HTTP_CODE); + debuglog("$exchange: $method failed ($status) ".strip_data($res)); + } + + curl_close($ch); + + return $result; +} + ////////////////////////////////////////////////////////////////////////////////////////////////////////////// // manual update of one market diff --git a/web/yaamp/defaultconfig.php b/web/yaamp/defaultconfig.php index 26ff494..195eb21 100644 --- a/web/yaamp/defaultconfig.php +++ b/web/yaamp/defaultconfig.php @@ -26,6 +26,7 @@ if (!defined('YAAMP_PAYMENTS_MINI')) define('YAAMP_PAYMENTS_MINI', 0.001); if (!defined('YAAMP_ALLOW_EXCHANGE')) define('YAAMP_ALLOW_EXCHANGE', false); if (!defined('EXCH_AUTO_WITHDRAW')) define('EXCH_AUTO_WITHDRAW', 9999.9999); +if (!defined('EXCH_BINANCE_KEY')) define('EXCH_BINANCE_KEY', ''); if (!defined('EXCH_BITTREX_KEY')) define('EXCH_BITTREX_KEY', ''); if (!defined('EXCH_BITSTAMP_ID')) define('EXCH_BITSTAMP_ID', ''); if (!defined('EXCH_BITSTAMP_KEY')) define('EXCH_BITSTAMP_KEY',''); From b760beaad3d13ca9b2a0431032f9b3a6becc7209 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Sun, 14 Jan 2018 20:57:07 +0100 Subject: [PATCH 013/195] binance: update balances deposit addresses seems missing in their api --- web/yaamp/core/trading/binance_trading.php | 56 +++++++++++++++++++ web/yaamp/core/trading/trading.php | 9 +++ .../modules/thread/CronjobController.php | 3 +- 3 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 web/yaamp/core/trading/binance_trading.php diff --git a/web/yaamp/core/trading/binance_trading.php b/web/yaamp/core/trading/binance_trading.php new file mode 100644 index 0000000..467eb35 --- /dev/null +++ b/web/yaamp/core/trading/binance_trading.php @@ -0,0 +1,56 @@ +balances)) return; + + $savebalance = getdbosql('db_balances', "name='$exchange'"); + + if (is_array($data->balances)) + foreach($data->balances as $balance) + { + if ($balance->asset == 'BTC') { + if (is_object($savebalance)) { + $savebalance->balance = $balance->free; + $savebalance->save(); + } + continue; + } + + if ($updatebalances) { + // store available balance in market table + $coins = getdbolist('db_coins', "symbol=:symbol OR symbol2=:symbol", + array(':symbol'=>$balance->asset) + ); + if (empty($coins)) continue; + foreach ($coins as $coin) { + $market = getdbosql('db_markets', + "coinid=:coinid AND name='$exchange' ORDER BY balance" + , array(':coinid'=>$coin->id) + ); + if (!$market) continue; + $market->balance = $balance->free; + $market->ontrade = $balance->locked; + $market->balancetime = time(); + $market->save(); + } + } + } + + if (!YAAMP_ALLOW_EXCHANGE) return; + + // real trading, todo.. +} diff --git a/web/yaamp/core/trading/trading.php b/web/yaamp/core/trading/trading.php index 1ce4773..6f1d28c 100644 --- a/web/yaamp/core/trading/trading.php +++ b/web/yaamp/core/trading/trading.php @@ -1,5 +1,6 @@ uuid); break; + case 'binance': + doBinanceCancelOrder($order->uuid); + break; case 'c-cex': doCCexCancelOrder($order->uuid); break; @@ -59,6 +63,11 @@ function runExchange($exchangeName=false) updateAlcurexMarkets(); break; + case 'binance': + doBinanceTrading(true); + updateBinanceMarkets(); + break; + case 'bter': doBterTrading(true); updateBterMarkets(); diff --git a/web/yaamp/modules/thread/CronjobController.php b/web/yaamp/modules/thread/CronjobController.php index 9d00dfd..4af3982 100644 --- a/web/yaamp/modules/thread/CronjobController.php +++ b/web/yaamp/modules/thread/CronjobController.php @@ -143,12 +143,13 @@ class CronjobController extends CommonController case 2: if(!YAAMP_PRODUCTION) break; - doYobitTrading(); + doBinanceTrading(); doCCexTrading(); doBterTrading(); doBleutradeTrading(); doKuCoinTrading(); doNovaTrading(); + doYobitTrading(); doCoinsMarketsTrading(); break; From 758e591348b1e411b22d59c8cdbcb2b00d2f63d5 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Fri, 19 Jan 2018 00:52:28 +0100 Subject: [PATCH 014/195] stratum: initialize segwit flag --- stratum/stratum.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stratum/stratum.cpp b/stratum/stratum.cpp index 8c86f75..21dddd1 100644 --- a/stratum/stratum.cpp +++ b/stratum/stratum.cpp @@ -35,7 +35,7 @@ int g_stratum_max_ttf; int g_stratum_max_cons = 5000; bool g_stratum_reconnect; bool g_stratum_renting; -bool g_stratum_segwit; +bool g_stratum_segwit = false; bool g_autoexchange = true; uint64_t g_max_shares = 0; From 3737f97a60f0740348e613124b6f72cec62f2282 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Fri, 19 Jan 2018 19:53:18 +0100 Subject: [PATCH 015/195] lbry: change estimates in mBTC/GH like other sha algos if needed (already mining) you can do that to update the pool estimate graph values: UPDATE hashrate SET price=price*1000.0, rent=rent*1000 WHERE algo='lbry' AND price < 0.01; --- web/yaamp/core/functions/yaamp.php | 1 + web/yaamp/modules/renting/all_orders_results.php | 2 +- web/yaamp/modules/renting/orders_results.php | 2 +- web/yaamp/modules/renting/status_results.php | 2 +- web/yaamp/modules/site/results/current_results.php | 6 +----- web/yaamp/modules/site/results/mining_results.php | 10 +++++----- 6 files changed, 10 insertions(+), 13 deletions(-) diff --git a/web/yaamp/core/functions/yaamp.php b/web/yaamp/core/functions/yaamp.php index 335962c..0d8a4fc 100755 --- a/web/yaamp/core/functions/yaamp.php +++ b/web/yaamp/core/functions/yaamp.php @@ -72,6 +72,7 @@ function yaamp_algo_mBTC_factor($algo) case 'decred': case 'keccak': case 'keccakc': + case 'lbry': case 'vanilla': return 1000; default: diff --git a/web/yaamp/modules/renting/all_orders_results.php b/web/yaamp/modules/renting/all_orders_results.php index b587dee..249be8f 100644 --- a/web/yaamp/modules/renting/all_orders_results.php +++ b/web/yaamp/modules/renting/all_orders_results.php @@ -80,7 +80,7 @@ echo ""; echo "

     * approximate from the last 5 minutes submitted shares
    -  ** price in mBTC/Mh/day (mBTC/Gh/day for sha256 and blake algos)
    +  ** price in mBTC/MH/day (GH/day for sha and blake algos)

    "; echo "
    "; diff --git a/web/yaamp/modules/renting/orders_results.php b/web/yaamp/modules/renting/orders_results.php index 58b3180..fe7c4d4 100644 --- a/web/yaamp/modules/renting/orders_results.php +++ b/web/yaamp/modules/renting/orders_results.php @@ -121,7 +121,7 @@ echo "

    echo "

     * approximate from the last 5 minutes submitted shares
    -  ** price in mBTC/Mh/day (mBTC/Gh/day for sha256 and blake algos)
    +  ** price in mBTC/MH/day (GH/day for sha and blake algos)

    "; echo "
    "; diff --git a/web/yaamp/modules/renting/status_results.php b/web/yaamp/modules/renting/status_results.php index 8e80e1a..d9fa8cc 100644 --- a/web/yaamp/modules/renting/status_results.php +++ b/web/yaamp/modules/renting/status_results.php @@ -90,7 +90,7 @@ foreach($algos as $item) echo ""; echo "

    -  * values in mBTC/Mh/day (mBTC/Gh/day for sha256 and blake algos)
    +  * values in mBTC/MH/day (GH/day for sha and blake algos)
     ** only hashpower with extranonce.subscribe or reconnect support can be rented

    "; diff --git a/web/yaamp/modules/site/results/current_results.php b/web/yaamp/modules/site/results/current_results.php index 5fc8e1c..c24a925 100644 --- a/web/yaamp/modules/site/results/current_results.php +++ b/web/yaamp/modules/site/results/current_results.php @@ -169,11 +169,7 @@ echo ""; echo ""; -echo "

    -  * best normalized multi algo
    -  ** fees are now fixed manually.
    -  *** values in mBTC/Mh/day (mBTC/Gh/day for sha256 and blake algos)
    -

    "; +echo '

     * values in mBTC/MH/day, per GH for sha & blake algos

    '; echo "

"; ?> diff --git a/web/yaamp/modules/site/results/mining_results.php b/web/yaamp/modules/site/results/mining_results.php index 9ea04e8..d6fb39c 100644 --- a/web/yaamp/modules/site/results/mining_results.php +++ b/web/yaamp/modules/site/results/mining_results.php @@ -222,11 +222,11 @@ if(isset($price_rent) && $showrental) echo ""; -echo "

-  *** estimated average time to find a block at full pool speed
-  ** approximate from the last 5 minutes submitted shares
-  * 24h estimation from network difficulty in mBTC/Mh/day (mBTC/Gh/day for sha256 and blake algos)
-

"; +echo '

+  *** estimated average time to find a block at full pool speed
+  ** approximate from the last 5 minutes submitted shares
+  * 24h estimation from net difficulty in mBTC/MH/day (GH/day for sha & blake algos)
+

'; echo "
"; From bc7c183114eeccf39f6ff0a218850afa7aaff006 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Fri, 19 Jan 2018 21:28:35 +0100 Subject: [PATCH 016/195] backend: drop old blocks from the db after 60 days --- web/yaamp/core/backend/system.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/yaamp/core/backend/system.php b/web/yaamp/core/backend/system.php index 99c9117..9d5478a 100644 --- a/web/yaamp/core/backend/system.php +++ b/web/yaamp/core/backend/system.php @@ -135,7 +135,7 @@ function BackendCleanDatabase() marketHistoryPrune(); $delay = time() - 60*24*60*60; -// dborun("delete from blocks where time<$delay"); + dborun("DELETE from blocks where time<$delay"); dborun("delete from hashstats where time<$delay"); dborun("delete from payouts where time<$delay"); dborun("delete from rentertxs where time<$delay"); From 117c7b3c9ce11b49a925c6c8b3f663f933a3cf25 Mon Sep 17 00:00:00 2001 From: AltMinerNet <31431085+AltMinerNet@users.noreply.github.com> Date: Fri, 19 Jan 2018 23:12:24 +0100 Subject: [PATCH 017/195] stratum: pushing more old masternodes (#210) --- stratum/db.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/stratum/db.cpp b/stratum/db.cpp index 30124d5..b9f17c5 100644 --- a/stratum/db.cpp +++ b/stratum/db.cpp @@ -284,7 +284,9 @@ void db_update_coinds(YAAMP_DB *db) // old dash masternodes coins.. if(coind->hasmasternodes) { + if (strcmp(coind->symbol, "ALQO") == 0) coind->oldmasternodes = true; if (strcmp(coind->symbol, "BSD") == 0) coind->oldmasternodes = true; + if (strcmp(coind->symbol, "BWK") == 0) coind->oldmasternodes = true; if (strcmp(coind->symbol, "CHC") == 0) coind->oldmasternodes = true; if (strcmp(coind->symbol, "CRW") == 0) coind->oldmasternodes = true; if (strcmp(coind->symbol, "FLAX") == 0) coind->oldmasternodes = true; From 1f9bfd006a78eeebc3a05fd54a41efb85b748f60 Mon Sep 17 00:00:00 2001 From: AltMinerNet <31431085+AltMinerNet@users.noreply.github.com> Date: Mon, 22 Jan 2018 01:18:57 +0100 Subject: [PATCH 018/195] stratum: handle proxy protocol (#196) Implemented PROXY v2 protocol (https://www.haproxy.org/download/1.8/doc/proxy-protocol.txt) so that stratum can be run behind an haproxy instance. iptables/ipset still work if haproxy is run on local machine. if run on remote machine switch to using client_block_ipset() and periodically sync the ipset to the machine running haproxy. haproxy must be configured with send-proxy-v2, version 1 does not work --- stratum/socket.cpp | 52 ++++++++++++++++++++++++++++++++++++++-------- stratum/socket.h | 31 +++++++++++++++++++++++++++ 2 files changed, 74 insertions(+), 9 deletions(-) diff --git a/stratum/socket.cpp b/stratum/socket.cpp index b708f96..c829c6a 100644 --- a/stratum/socket.cpp +++ b/stratum/socket.cpp @@ -8,6 +8,48 @@ bool socket_connected(YAAMP_SOCKET *s) return s->sock > 0; } +void socket_real_ip(YAAMP_SOCKET *s) +{ + // get real ip if we are using haproxy or similar that use PROXY protocol + // https://www.haproxy.org/download/1.8/doc/proxy-protocol.txt + int size, ret; + const char v2sig[] = "\x0D\x0A\x0D\x0A\x00\x0D\x0A\x51\x55\x49\x54\x0A"; + + do { + ret = recv(s->sock, &hdr, sizeof(hdr), MSG_PEEK); + } while (ret == -1 && errno == EINTR); + + if (ret >= (16 + ntohs(hdr.v2.len)) && + memcmp(&hdr.v2, v2sig, 12) == 0 && + ((hdr.v2.ver_cmd & 0xF0) == 0x20) && + hdr.v2.fam == 0x11) { + // we received a proxy v2 header + inet_ntop(AF_INET, &hdr.v2.addr.ip4.src_addr, s->ip, 64); + s->port = ntohs(hdr.v2.addr.ip4.src_port); + + // we need to consume the appropriate amount of data from the socket + // read the buffer without PEEK'ing so that we begin at the real data later in socket_nextjson + size = 16 + ntohs(hdr.v2.len); + do { + ret = recv(s->sock, &hdr, size, 0); + } while (ret == -1 && errno == EINTR); + return; + } + else { + // not received any proxy header + struct sockaddr_in name; + socklen_t len = sizeof(name); + memset(&name, 0, len); + + int res = getpeername(s->sock, (struct sockaddr *)&name, &len); + inet_ntop(AF_INET, &name.sin_addr, s->ip, 64); + + res = getsockname(s->sock, (struct sockaddr *)&name, &len); + s->port = ntohs(name.sin_port); + return; + } +} + YAAMP_SOCKET *socket_initialize(int sock) { YAAMP_SOCKET *s = new YAAMP_SOCKET; @@ -19,15 +61,7 @@ YAAMP_SOCKET *socket_initialize(int sock) // yaamp_create_mutex(&s->mutex); // pthread_mutex_lock(&s->mutex); - struct sockaddr_in name; - socklen_t len = sizeof(name); - memset(&name, 0, len); - - int res = getpeername(s->sock, (struct sockaddr *)&name, &len); - inet_ntop(AF_INET, &name.sin_addr, s->ip, 64); - - res = getsockname(s->sock, (struct sockaddr *)&name, &len); - s->port = ntohs(name.sin_port); + socket_real_ip(s); return s; } diff --git a/stratum/socket.h b/stratum/socket.h index c169e33..f992fa5 100644 --- a/stratum/socket.h +++ b/stratum/socket.h @@ -18,6 +18,8 @@ struct YAAMP_SOCKET bool socket_connected(YAAMP_SOCKET *s); +void socket_real_ip(YAAMP_SOCKET *s); + YAAMP_SOCKET *socket_initialize(int sock); void socket_close(YAAMP_SOCKET *s); @@ -26,3 +28,32 @@ int socket_send(YAAMP_SOCKET *s, const char *format, ...); int socket_send_raw(YAAMP_SOCKET *s, const char *buffer, int size); +static union { + struct { + char line[108]; + } v1; + struct { + uint8_t sig[12]; + uint8_t ver_cmd; + uint8_t fam; + uint16_t len; + union { + struct { /* for TCP/UDP over IPv4, len = 12 */ + uint32_t src_addr; + uint32_t dst_addr; + uint16_t src_port; + uint16_t dst_port; + } ip4; + struct { /* for TCP/UDP over IPv6, len = 36 */ + uint8_t src_addr[16]; + uint8_t dst_addr[16]; + uint16_t src_port; + uint16_t dst_port; + } ip6; + struct { /* for AF_UNIX sockets, len = 216 */ + uint8_t src_addr[108]; + uint8_t dst_addr[108]; + } unx; + } addr; + } v2; +} hdr; From 7aa93d684a3d238133d61c0941f66cbfa4d358a7 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Tue, 23 Jan 2018 23:54:06 +0100 Subject: [PATCH 019/195] decred: listtransactions order is finally like others --- web/yaamp/modules/site/coin_results.php | 3 ++- web/yaamp/modules/site/coin_tickets.php | 6 ++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/web/yaamp/modules/site/coin_results.php b/web/yaamp/modules/site/coin_results.php index eb01ea7..f1667a9 100644 --- a/web/yaamp/modules/site/coin_results.php +++ b/web/yaamp/modules/site/coin_results.php @@ -395,7 +395,8 @@ if ($DCR) { if ($lastday == '' && count($txs) == $maxrows) $lastday = strftime('%F', $tx['time']); } - ksort($txs_array); // reversed order + if ($info['version'] < 1010200) + ksort($txs_array); // was in reversed order } $rows = 0; diff --git a/web/yaamp/modules/site/coin_tickets.php b/web/yaamp/modules/site/coin_tickets.php index 3abed60..9b36934 100644 --- a/web/yaamp/modules/site/coin_tickets.php +++ b/web/yaamp/modules/site/coin_tickets.php @@ -179,7 +179,8 @@ if (!empty($txs_array)) { if ($lastday == '' && count($txs) == $maxrows) $lastday = strftime('%F', arraySafeVal($tx,'blocktime', $tx['time'])); } - ksort($txs_array); + if ($info['version'] < 1010200) + ksort($txs_array); } if (!empty($tickets)) foreach ($tickets['hashes'] as $n => $txid) { @@ -200,7 +201,8 @@ if (!empty($tickets)) foreach ($tickets['hashes'] as $n => $txid) { $stx['stx'] = $stx; $txs_array[$k] = $stx; } - ksort($txs_array); + if ($info['version'] < 1010200) + ksort($txs_array); } $rows = 0; From e4914a6b097430d3230a011f906132159224fc4c Mon Sep 17 00:00:00 2001 From: AltMinerNet <31431085+AltMinerNet@users.noreply.github.com> Date: Wed, 24 Jan 2018 20:35:41 +0100 Subject: [PATCH 020/195] stratum: check coin filters early (#211) Avoid the override of global variables g_stratum_max_cons, g_max_shares, g_stratum_segwit by excluded coinds by checking the include/exclude filters earlier. --- stratum/db.cpp | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/stratum/db.cpp b/stratum/db.cpp index b9f17c5..680483d 100644 --- a/stratum/db.cpp +++ b/stratum/db.cpp @@ -200,6 +200,17 @@ void db_update_coinds(YAAMP_DB *db) coind->newcoind = false; strcpy(coind->name, row[1]); + strcpy(coind->symbol, row[20]; + // optional coin filters + if(coind->newcoind) { + bool ignore = false; + if (strlen(g_stratum_coin_include) && !strstr(g_stratum_coin_include, coind->symbol)) ignore = true; + if (strlen(g_stratum_coin_exclude) && strstr(g_stratum_coin_exclude, coind->symbol)) ignore = true; + if (ignore) { + object_delete(coind); + continue; + } + } if(row[7]) strcpy(coind->wallet, row[7]); if(row[6]) strcpy(coind->rpcencoding, row[6]); @@ -252,7 +263,6 @@ void db_update_coinds(YAAMP_DB *db) if(row[18]) coind->charity_percent = atof(row[18]); if(row[19]) coind->reward_mul = atof(row[19]); - strcpy(coind->symbol, row[20]); if(row[21]) coind->isaux = atoi(row[21]); if(row[22] && row[23]) coind->actual_ttf = min(atoi(row[22]), atoi(row[23])); @@ -302,15 +312,6 @@ void db_update_coinds(YAAMP_DB *db) //coind->touch = true; if(coind->newcoind) { - // optional coin filter - bool ignore = false; - if (strlen(g_stratum_coin_include) && !strstr(g_stratum_coin_include, coind->symbol)) ignore = true; - if (strlen(g_stratum_coin_exclude) && strstr(g_stratum_coin_exclude, coind->symbol)) ignore = true; - if (ignore) { - object_delete(coind); - continue; - } - debuglog("connecting to coind %s\n", coind->symbol); bool b = rpc_connect(&coind->rpc); From 0019ca611d073d319b3856d9810898cc2e9c4b46 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Fri, 12 Jan 2018 18:35:06 +0100 Subject: [PATCH 021/195] new x16r algo, with stratum factor 256, like timetravel algos beware: this algo may have a variable hashrate, unlike timetravel its ignored from benchs for this reason --- stratum/algos/makefile | 2 +- stratum/algos/x16r.c | 178 +++++++++++++++++++++++++++++ stratum/algos/x16r.h | 16 +++ stratum/config.sample/x16r.conf | 16 +++ stratum/stratum.cpp | 7 +- stratum/stratum.h | 1 + web/yaamp/core/functions/yaamp.php | 3 + 7 files changed, 219 insertions(+), 4 deletions(-) create mode 100644 stratum/algos/x16r.c create mode 100644 stratum/algos/x16r.h create mode 100644 stratum/config.sample/x16r.conf diff --git a/stratum/algos/makefile b/stratum/algos/makefile index 950ec2b..9c92a9f 100644 --- a/stratum/algos/makefile +++ b/stratum/algos/makefile @@ -12,7 +12,7 @@ SOURCES=lyra2re.c lyra2v2.c Lyra2.c lyra2z.c Lyra2z.c Sponge.c \ blake.c scrypt.c c11.c x11.c x13.c sha256.c sha256t.c jha.c keccak.c deep.c tribus.c \ hsr14.c sm3.c \ x14.c x15.c x17.c nist5.c fresh.c quark.c neoscrypt.c scryptn.c qubit.c skein.c groestl.c \ - bitcore.c timetravel.c xevan.c bastion.c hmq17.c \ + bitcore.c timetravel.c x16r.c xevan.c bastion.c hmq17.c \ skein2.c zr5.c bmw.c luffa.c pentablake.c whirlpool.c whirlpoolx.c blakecoin.c \ blake2.c \ yescrypt.c yescrypt-opt.c sha256_Y.c lbry.c \ diff --git a/stratum/algos/x16r.c b/stratum/algos/x16r.c new file mode 100644 index 0000000..2b7a44f --- /dev/null +++ b/stratum/algos/x16r.c @@ -0,0 +1,178 @@ +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "common.h" + +enum Algo { + BLAKE = 0, + BMW, + GROESTL, + JH, + KECCAK, + SKEIN, + LUFFA, + CUBEHASH, + SHAVITE, + SIMD, + ECHO, + HAMSI, + FUGUE, + SHABAL, + WHIRLPOOL, + SHA512, + HASH_FUNC_COUNT +}; + +static void getAlgoString(const uint8_t* prevblock, char *output) +{ + char *sptr = output; + + for (int j = 0; j < HASH_FUNC_COUNT; j++) { + char b = (15 - j) >> 1; // 16 ascii hex chars, reversed + uint8_t algoDigit = (j & 1) ? prevblock[b] & 0xF : prevblock[b] >> 4; + if (algoDigit >= 10) + sprintf(sptr, "%c", 'A' + (algoDigit - 10)); + else + sprintf(sptr, "%u", (uint32_t) algoDigit); + sptr++; + } + *sptr = '\0'; +} + +void x16r_hash(const char* input, char* output, uint32_t len) +{ + uint32_t hash[64/4]; + char hashOrder[HASH_FUNC_COUNT + 1] = { 0 }; + + sph_blake512_context ctx_blake; + sph_bmw512_context ctx_bmw; + sph_groestl512_context ctx_groestl; + sph_skein512_context ctx_skein; + sph_jh512_context ctx_jh; + sph_keccak512_context ctx_keccak; + sph_luffa512_context ctx_luffa; + sph_cubehash512_context ctx_cubehash; + sph_shavite512_context ctx_shavite; + sph_simd512_context ctx_simd; + sph_echo512_context ctx_echo; + sph_hamsi512_context ctx_hamsi; + sph_fugue512_context ctx_fugue; + sph_shabal512_context ctx_shabal; + sph_whirlpool_context ctx_whirlpool; + sph_sha512_context ctx_sha512; + + void *in = (void*) input; + int size = len; + + getAlgoString(&input[4], hashOrder); + + for (int i = 0; i < 16; i++) + { + const char elem = hashOrder[i]; + const uint8_t algo = elem >= 'A' ? elem - 'A' + 10 : elem - '0'; + + switch (algo) { + case BLAKE: + sph_blake512_init(&ctx_blake); + sph_blake512(&ctx_blake, in, size); + sph_blake512_close(&ctx_blake, hash); + break; + case BMW: + sph_bmw512_init(&ctx_bmw); + sph_bmw512(&ctx_bmw, in, size); + sph_bmw512_close(&ctx_bmw, hash); + break; + case GROESTL: + sph_groestl512_init(&ctx_groestl); + sph_groestl512(&ctx_groestl, in, size); + sph_groestl512_close(&ctx_groestl, hash); + break; + case SKEIN: + sph_skein512_init(&ctx_skein); + sph_skein512(&ctx_skein, in, size); + sph_skein512_close(&ctx_skein, hash); + break; + case JH: + sph_jh512_init(&ctx_jh); + sph_jh512(&ctx_jh, in, size); + sph_jh512_close(&ctx_jh, hash); + break; + case KECCAK: + sph_keccak512_init(&ctx_keccak); + sph_keccak512(&ctx_keccak, in, size); + sph_keccak512_close(&ctx_keccak, hash); + break; + case LUFFA: + sph_luffa512_init(&ctx_luffa); + sph_luffa512(&ctx_luffa, in, size); + sph_luffa512_close(&ctx_luffa, hash); + break; + case CUBEHASH: + sph_cubehash512_init(&ctx_cubehash); + sph_cubehash512(&ctx_cubehash, in, size); + sph_cubehash512_close(&ctx_cubehash, hash); + break; + case SHAVITE: + sph_shavite512_init(&ctx_shavite); + sph_shavite512(&ctx_shavite, in, size); + sph_shavite512_close(&ctx_shavite, hash); + break; + case SIMD: + sph_simd512_init(&ctx_simd); + sph_simd512(&ctx_simd, in, size); + sph_simd512_close(&ctx_simd, hash); + break; + case ECHO: + sph_echo512_init(&ctx_echo); + sph_echo512(&ctx_echo, in, size); + sph_echo512_close(&ctx_echo, hash); + break; + case HAMSI: + sph_hamsi512_init(&ctx_hamsi); + sph_hamsi512(&ctx_hamsi, in, size); + sph_hamsi512_close(&ctx_hamsi, hash); + break; + case FUGUE: + sph_fugue512_init(&ctx_fugue); + sph_fugue512(&ctx_fugue, in, size); + sph_fugue512_close(&ctx_fugue, hash); + break; + case SHABAL: + sph_shabal512_init(&ctx_shabal); + sph_shabal512(&ctx_shabal, in, size); + sph_shabal512_close(&ctx_shabal, hash); + break; + case WHIRLPOOL: + sph_whirlpool_init(&ctx_whirlpool); + sph_whirlpool(&ctx_whirlpool, in, size); + sph_whirlpool_close(&ctx_whirlpool, hash); + break; + case SHA512: + sph_sha512_init(&ctx_sha512); + sph_sha512(&ctx_sha512,(const void*) in, size); + sph_sha512_close(&ctx_sha512,(void*) hash); + break; + } + in = (void*) hash; + size = 64; + } + memcpy(output, hash, 32); +} diff --git a/stratum/algos/x16r.h b/stratum/algos/x16r.h new file mode 100644 index 0000000..4a41ec8 --- /dev/null +++ b/stratum/algos/x16r.h @@ -0,0 +1,16 @@ +#ifndef X16R_H +#define X16R_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +void x16r_hash(const char* input, char* output, uint32_t len); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/stratum/config.sample/x16r.conf b/stratum/config.sample/x16r.conf new file mode 100644 index 0000000..5407f03 --- /dev/null +++ b/stratum/config.sample/x16r.conf @@ -0,0 +1,16 @@ +[TCP] +server = yaamp.com +port = 3737 +password = tu8tu5 + +[SQL] +host = yaampdb +database = yaamp +username = root +password = patofpaq + +[STRATUM] +algo = x16r +difficulty = 0.25 +max_ttf = 50000 + diff --git a/stratum/stratum.cpp b/stratum/stratum.cpp index 21dddd1..fe74772 100644 --- a/stratum/stratum.cpp +++ b/stratum/stratum.cpp @@ -110,6 +110,7 @@ YAAMP_ALGO g_algos[] = {"x11evo", x11evo_hash, 1, 0, 0}, {"xevan", xevan_hash, 0x100, 0, 0}, + {"x16r", x16r_hash, 0x100, 0, 0}, {"timetravel", timetravel_hash, 0x100, 0, 0}, {"bitcore", timetravel10_hash, 0x100, 0, 0}, {"hsr", hsr_hash, 1, 0, 0}, @@ -251,9 +252,9 @@ int main(int argc, char **argv) g_current_algo->name, g_tcp_server, g_tcp_port); // ntime should not be changed by miners for these algos - g_allow_rolltime = strcmp(g_current_algo->name,"x11evo"); - g_allow_rolltime = g_allow_rolltime && strcmp(g_current_algo->name,"timetravel"); - g_allow_rolltime = g_allow_rolltime && strcmp(g_current_algo->name,"bitcore"); + g_allow_rolltime = strcmp(g_stratum_algo,"x11evo"); + g_allow_rolltime = g_allow_rolltime && strcmp(g_stratum_algo,"timetravel"); + g_allow_rolltime = g_allow_rolltime && strcmp(g_stratum_algo,"bitcore"); if (!g_allow_rolltime) stratumlog("note: time roll disallowed for %s algo\n", g_current_algo->name); diff --git a/stratum/stratum.h b/stratum/stratum.h index 21b6dc1..9ea87d7 100644 --- a/stratum/stratum.h +++ b/stratum/stratum.h @@ -140,6 +140,7 @@ void sha256_double_hash_hex(const char *input, char *output, unsigned int len); #include "algos/x13.h" #include "algos/x14.h" #include "algos/x15.h" +#include "algos/x16r.h" #include "algos/x17.h" #include "algos/xevan.h" #include "algos/hmq17.h" diff --git a/web/yaamp/core/functions/yaamp.php b/web/yaamp/core/functions/yaamp.php index 0d8a4fc..c19af3f 100755 --- a/web/yaamp/core/functions/yaamp.php +++ b/web/yaamp/core/functions/yaamp.php @@ -37,6 +37,7 @@ function yaamp_get_algos() 'x13', 'x14', 'x15', + 'x16r', 'x17', 'xevan', 'groestl', // dmd-gr -m 256 (deprecated) @@ -133,6 +134,7 @@ function getAlgoColors($algo) 'x13' => '#ffd880', 'x14' => '#f0c080', 'x15' => '#f0b080', + 'x16r' => '#f0b080', 'x17' => '#f0b0a0', 'xevan' => '#f0b0a0', 'argon2' => '#e0d0e0', @@ -196,6 +198,7 @@ function getAlgoPort($algo) 'x11evo' => 3553, 'x13' => 3633, 'x15' => 3733, + 'x16r' => 3636, 'x17' => 3737, 'xevan' => 3739, 'hmq1725' => 3747, From 88cfe6faf7b003d290d0d831e13cdc2e94d9a42a Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Wed, 24 Jan 2018 20:40:26 +0100 Subject: [PATCH 022/195] benchs: ignore some weird device names and x16r algo --- web/yaamp/core/backend/bench.php | 9 +++++++++ web/yaamp/modules/bench/functions.php | 8 ++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/web/yaamp/core/backend/bench.php b/web/yaamp/core/backend/bench.php index 110d808..dce1e7c 100644 --- a/web/yaamp/core/backend/bench.php +++ b/web/yaamp/core/backend/bench.php @@ -22,6 +22,11 @@ function BenchUpdateChips() foreach ($benchs as $bench) { if (empty($bench->vendorid) || empty($bench->device)) continue; + if ($bench->algo == 'x16r') { // not constant, inaccurate + $bench->delete(); + continue; + } + $dups = getdbocount('db_benchmarks', "vendorid=:vid AND client=:client AND os=:os AND driver=:drv AND throughput=:thr AND userid=:uid", array(':vid'=>$bench->vendorid, ':client'=>$bench->client, ':os'=>$bench->os, ':drv'=>$bench->driver,':thr'=>$bench->throughput,':uid'=>$bench->userid) ); @@ -48,6 +53,10 @@ function BenchUpdateChips() $bench->delete(); continue; } + if ($bench->chip == 'GPU' || $bench->chip == 'Graphics Device') { + $bench->delete(); + continue; + } debuglog("bench: {$bench->device} ($chip)..."); $bench->save(); } diff --git a/web/yaamp/modules/bench/functions.php b/web/yaamp/modules/bench/functions.php index 2681997..9e67a95 100644 --- a/web/yaamp/modules/bench/functions.php +++ b/web/yaamp/modules/bench/functions.php @@ -163,8 +163,11 @@ function getChipName($row) } else { - // nNidia - $words = explode(' ', $row['device']); + // nVidia + $device = str_replace(' with Max-Q Design', '', $row['device']); + $device = str_replace(' COLLECTORS EDITION', '', $device); + + $words = explode(' ', $device); $chip = array_pop($words); $vendorid = $row['vendorid']; if (!is_numeric($chip)) { @@ -177,6 +180,7 @@ function getChipName($row) $chip = str_replace('760 Ti OEM','760 Ti', $chip); $chip = str_replace(' (Pascal)',' Pascal', $chip); $chip = str_replace('Tesla P100-SXM2-16GB','Tesla P100', $chip); + $chip = str_replace('Tesla P100-PCIE-16GB','Tesla P100', $chip); $chip = str_replace('Tesla V100-SXM2-16GB','Tesla V100', $chip); $chip = preg_replace('/ASUS ([6-9]\d\dM)/','\1', $chip); // ASUS 940M $chip = preg_replace('/MSI ([6-9]\d\dM)/','\1', $chip); // MSI 840M From a89a0ef4cf1be441429b0a276c9726a32739a01c Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Wed, 24 Jan 2018 20:47:06 +0100 Subject: [PATCH 023/195] stratum: fix altminer commit --- stratum/db.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stratum/db.cpp b/stratum/db.cpp index 680483d..a221fe6 100644 --- a/stratum/db.cpp +++ b/stratum/db.cpp @@ -200,7 +200,7 @@ void db_update_coinds(YAAMP_DB *db) coind->newcoind = false; strcpy(coind->name, row[1]); - strcpy(coind->symbol, row[20]; + strcpy(coind->symbol, row[20]); // optional coin filters if(coind->newcoind) { bool ignore = false; From 4e5fbb49396d323b11a02e98a86476e424d40720 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Thu, 25 Jan 2018 00:32:38 +0100 Subject: [PATCH 024/195] cexio: include btc in orders for the balance to do like bitstamp... --- web/yaamp/core/exchange/cexio.php | 2 +- web/yaamp/core/trading/trading.php | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/web/yaamp/core/exchange/cexio.php b/web/yaamp/core/exchange/cexio.php index 243a4b6..e095f66 100644 --- a/web/yaamp/core/exchange/cexio.php +++ b/web/yaamp/core/exchange/cexio.php @@ -100,7 +100,7 @@ function getCexIoBalances() $balances = cexio_api_user('balance'); if (is_array($balances)) { $b = arraySafeVal($balances, 'BTC'); - $savebalance->balance = arraySafeVal($b, 'available'); + $savebalance->balance = arraySafeVal($b, 'available',0.) + arraySafeVal($b, 'orders',0.); $savebalance->save(); } } diff --git a/web/yaamp/core/trading/trading.php b/web/yaamp/core/trading/trading.php index 6f1d28c..3027d39 100644 --- a/web/yaamp/core/trading/trading.php +++ b/web/yaamp/core/trading/trading.php @@ -87,6 +87,10 @@ function runExchange($exchangeName=false) updateBittrexMarkets(); break; + case 'cexio': + getCexIoBalances(); + break; + case 'c-cex': doCCexTrading(true); updateCCexMarkets(); From 88106d8be26fbd09363f55aaa331706e3ad9051e Mon Sep 17 00:00:00 2001 From: Frederic Rezeau Date: Sat, 27 Jan 2018 06:46:36 +0900 Subject: [PATCH 025/195] Add MAG (Magnet) masternode to oldmasternodes (#213) Greetings, I am head dev for Magnet masternode and noticed the change made in coinbase.cpp for recent masternode RPC as default. This change has disabled masternode payments on pools using MAG client. So, we would like to add it to oldmasternodes list with this pull request. --- stratum/db.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/stratum/db.cpp b/stratum/db.cpp index a221fe6..53c56e5 100644 --- a/stratum/db.cpp +++ b/stratum/db.cpp @@ -302,6 +302,7 @@ void db_update_coinds(YAAMP_DB *db) if (strcmp(coind->symbol, "FLAX") == 0) coind->oldmasternodes = true; if (strcmp(coind->symbol, "ITZ") == 0) coind->oldmasternodes = true; if (strcmp(coind->symbol, "J") == 0 || strcmp(coind->symbol2, "J") == 0) coind->oldmasternodes = true; + if (strcmp(coind->symbol, "MAG") == 0) coind->oldmasternodes = true; if (strcmp(coind->symbol, "URALS") == 0) coind->oldmasternodes = true; if (strcmp(coind->symbol, "VSX") == 0) coind->oldmasternodes = true; if (strcmp(coind->symbol, "XLR") == 0) coind->oldmasternodes = true; From 0f04d6d82466a27df8a30af5234d98f8cc2b6d25 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Sat, 27 Jan 2018 06:16:19 +0100 Subject: [PATCH 026/195] balances: fill the btc 'onsell' field too (locked) and restore bitstamp & cexio behavior to act like other trading exchanges todo: kraken if possible... real pain, need to parse open orders.. --- web/yaamp/core/exchange/bitstamp.php | 3 +- web/yaamp/core/exchange/cexio.php | 3 +- web/yaamp/core/trading/binance_trading.php | 1 + web/yaamp/core/trading/bittrex_trading.php | 4 +- web/yaamp/core/trading/bleutrade_trading.php | 2 + web/yaamp/core/trading/bter_trading.php | 1 + web/yaamp/core/trading/c-cex_trading.php | 1 + web/yaamp/core/trading/cryptopia_trading.php | 2 + web/yaamp/core/trading/hitbtc_trading.php | 1 + web/yaamp/core/trading/kraken_trading.php | 4 ++ web/yaamp/core/trading/kucoin_trading.php | 1 + web/yaamp/core/trading/livecoin_trading.php | 10 ++- web/yaamp/core/trading/nova_trading.php | 2 + web/yaamp/core/trading/poloniex_trading.php | 3 +- web/yaamp/core/trading/yobit_trading.php | 2 + web/yaamp/modules/site/common_results.php | 67 ++++++++++++-------- 16 files changed, 72 insertions(+), 35 deletions(-) diff --git a/web/yaamp/core/exchange/bitstamp.php b/web/yaamp/core/exchange/bitstamp.php index 2b86158..0431129 100644 --- a/web/yaamp/core/exchange/bitstamp.php +++ b/web/yaamp/core/exchange/bitstamp.php @@ -86,7 +86,8 @@ function getBitstampBalances() if (is_object($savebalance)) { $balances = bitstamp_api_user('balance'); if (is_array($balances)) { - $savebalance->balance = arraySafeVal($balances, 'btc_balance'); + $savebalance->balance = arraySafeVal($balances, 'btc_balance',0.) - arraySafeVal($balances, 'btc_reserved'); + $savebalance->onsell = arraySafeVal($balances, 'btc_reserved'); $savebalance->save(); } } diff --git a/web/yaamp/core/exchange/cexio.php b/web/yaamp/core/exchange/cexio.php index e095f66..51e5b0d 100644 --- a/web/yaamp/core/exchange/cexio.php +++ b/web/yaamp/core/exchange/cexio.php @@ -100,7 +100,8 @@ function getCexIoBalances() $balances = cexio_api_user('balance'); if (is_array($balances)) { $b = arraySafeVal($balances, 'BTC'); - $savebalance->balance = arraySafeVal($b, 'available',0.) + arraySafeVal($b, 'orders',0.); + $savebalance->balance = arraySafeVal($b, 'available',0.); + $savebalance->onsell = arraySafeVal($b, 'orders',0.); $savebalance->save(); } } diff --git a/web/yaamp/core/trading/binance_trading.php b/web/yaamp/core/trading/binance_trading.php index 467eb35..3cad356 100644 --- a/web/yaamp/core/trading/binance_trading.php +++ b/web/yaamp/core/trading/binance_trading.php @@ -25,6 +25,7 @@ function doBinanceTrading($quick=false) if ($balance->asset == 'BTC') { if (is_object($savebalance)) { $savebalance->balance = $balance->free; + $savebalance->onsell = $balance->locked; $savebalance->save(); } continue; diff --git a/web/yaamp/core/trading/bittrex_trading.php b/web/yaamp/core/trading/bittrex_trading.php index 9240eac..8f67cec 100644 --- a/web/yaamp/core/trading/bittrex_trading.php +++ b/web/yaamp/core/trading/bittrex_trading.php @@ -27,7 +27,8 @@ function doBittrexTrading($quick=false) $savebalance = getdbosql('db_balances', "name='$exchange'"); if (is_object($savebalance)) { - $savebalance->balance = 0; + $savebalance->balance = 0.; + $savebalance->onsell = 0.; $savebalance->save(); } @@ -36,6 +37,7 @@ function doBittrexTrading($quick=false) if ($balance->Currency == 'BTC') { if (is_object($savebalance)) { $savebalance->balance = $balance->Available; + $savebalance->onsell = (double) $balance->Balance - (double) $balance->Available; $savebalance->save(); } continue; diff --git a/web/yaamp/core/trading/bleutrade_trading.php b/web/yaamp/core/trading/bleutrade_trading.php index b5a31f5..6d800e3 100644 --- a/web/yaamp/core/trading/bleutrade_trading.php +++ b/web/yaamp/core/trading/bleutrade_trading.php @@ -28,6 +28,7 @@ function doBleutradeTrading($quick=false) $savebalance = getdbosql('db_balances', "name='$exchange'"); if (is_object($savebalance)) { $savebalance->balance = 0; + $savebalance->onsell = 0; $savebalance->save(); } @@ -36,6 +37,7 @@ function doBleutradeTrading($quick=false) if ($balance->Currency == 'BTC') { if (is_object($savebalance)) { $savebalance->balance = $balance->Available; + $savebalance->onsell = (double) $balance->Balance - (double) $balance->Available; $savebalance->save(); } continue; diff --git a/web/yaamp/core/trading/bter_trading.php b/web/yaamp/core/trading/bter_trading.php index 7736905..5d38a1f 100644 --- a/web/yaamp/core/trading/bter_trading.php +++ b/web/yaamp/core/trading/bter_trading.php @@ -27,6 +27,7 @@ function doBterTrading($quick=false) if ($symbol == 'BTC') { if (is_object($savebalance)) { $savebalance->balance = $balance->available; + $savebalance->onsell = arraySafeVal($balances['locked_funds'],$symbol,0); $savebalance->save(); } continue; diff --git a/web/yaamp/core/trading/c-cex_trading.php b/web/yaamp/core/trading/c-cex_trading.php index f91c8ce..a9d4351 100644 --- a/web/yaamp/core/trading/c-cex_trading.php +++ b/web/yaamp/core/trading/c-cex_trading.php @@ -39,6 +39,7 @@ function doCCexTrading($quick=false) if ($symbol == 'BTC') { if (!is_object($savebalance)) continue; $savebalance->balance = arraySafeVal($balance,'Available'); + $savebalance->onsell = arraySafeVal($balance,'Balance',0.) - arraySafeVal($balance,'Available'); $savebalance->save(); continue; } diff --git a/web/yaamp/core/trading/cryptopia_trading.php b/web/yaamp/core/trading/cryptopia_trading.php index 7956c6f..4a026b9 100644 --- a/web/yaamp/core/trading/cryptopia_trading.php +++ b/web/yaamp/core/trading/cryptopia_trading.php @@ -27,6 +27,7 @@ function doCryptopiaTrading($quick=false) $savebalance = getdbosql('db_balances', "name='$exchange'"); if (is_object($savebalance)) { $savebalance->balance = 0; + $savebalance->onsell = 0; $savebalance->save(); } @@ -36,6 +37,7 @@ function doCryptopiaTrading($quick=false) if ($balance->Symbol == 'BTC') { if (is_object($savebalance)) { $savebalance->balance = $balance->Available; + $savebalance->onsell = $balance->HeldForTrades; $savebalance->save(); } continue; diff --git a/web/yaamp/core/trading/hitbtc_trading.php b/web/yaamp/core/trading/hitbtc_trading.php index ba6a38d..db380ea 100644 --- a/web/yaamp/core/trading/hitbtc_trading.php +++ b/web/yaamp/core/trading/hitbtc_trading.php @@ -25,6 +25,7 @@ function doHitBTCTrading($quick=false) if ($balance->currency_code == 'BTC') { if (is_object($savebalance)) { $savebalance->balance = $balance->cash; + $savebalance->onsell = $balance->reserved; $savebalance->save(); } continue; diff --git a/web/yaamp/core/trading/kraken_trading.php b/web/yaamp/core/trading/kraken_trading.php index d8a7c0f..580bcff 100644 --- a/web/yaamp/core/trading/kraken_trading.php +++ b/web/yaamp/core/trading/kraken_trading.php @@ -10,12 +10,16 @@ function doKrakenTrading($quick=false) $balances = kraken_api_user('Balance'); if(!$balances || !is_array($balances)) return; + //$total = kraken_api_user('TradeBalance', array('asset'=>'XXBT')); + //if(!$total || !is_array($total)) return; + foreach($balances as $symbol => $balance) { if ($symbol == 'BTC') { $db_balance = getdbosql('db_balances', "name='$exchange'"); if ($db_balance) { $db_balance->balance = $balance; + //$db_balance->onsell = (double) $total['result']['tb'] - $balance; $db_balance->save(); } continue; diff --git a/web/yaamp/core/trading/kucoin_trading.php b/web/yaamp/core/trading/kucoin_trading.php index 394a614..dd33182 100644 --- a/web/yaamp/core/trading/kucoin_trading.php +++ b/web/yaamp/core/trading/kucoin_trading.php @@ -25,6 +25,7 @@ function doKuCoinTrading($quick=false) if ($balance->coinType == 'BTC') { if (is_object($savebalance)) { $savebalance->balance = $balance->balance; + $savebalance->onsell = $balance->freezeBalance; $savebalance->save(); } continue; diff --git a/web/yaamp/core/trading/livecoin_trading.php b/web/yaamp/core/trading/livecoin_trading.php index a014fdd..40676d2 100644 --- a/web/yaamp/core/trading/livecoin_trading.php +++ b/web/yaamp/core/trading/livecoin_trading.php @@ -52,13 +52,17 @@ function doLiveCoinTrading($quick = false) foreach ($balances as $balance) { if ($balance->currency == 'BTC' && $balance->type == "available") { - if (!is_object($savebalance)) { - continue; - } + if (!is_object($savebalance)) continue; $savebalance->balance = $balance->value; $savebalance->save(); continue; } + if ($balance->currency == 'BTC' && $balance->type == "trade") { + if (!is_object($savebalance)) continue; + $savebalance->onsell = $balance->value; + $savebalance->save(); + continue; + } if ($updatebalances) { // store available balance in market table diff --git a/web/yaamp/core/trading/nova_trading.php b/web/yaamp/core/trading/nova_trading.php index ca32216..4e7b268 100644 --- a/web/yaamp/core/trading/nova_trading.php +++ b/web/yaamp/core/trading/nova_trading.php @@ -38,6 +38,7 @@ function doNovaTrading($quick=false) $savebalance = getdbosql('db_balances', "name='{$exchange}'"); if (is_object($savebalance)) { $savebalance->balance = 0; + $savebalance->onsell = 0; $savebalance->save(); } else { dborun("INSERT INTO balances (name,balance) VALUES ('$exchange',0)"); @@ -49,6 +50,7 @@ function doNovaTrading($quick=false) if ($balance->currency == 'BTC') { if (is_object($savebalance)) { $savebalance->balance = $balance->amount; + $savebalance->onsell = $balance->amount_trades; $savebalance->save(); } continue; diff --git a/web/yaamp/core/trading/poloniex_trading.php b/web/yaamp/core/trading/poloniex_trading.php index e817bdf..1aef2b2 100644 --- a/web/yaamp/core/trading/poloniex_trading.php +++ b/web/yaamp/core/trading/poloniex_trading.php @@ -33,7 +33,8 @@ function doPoloniexTrading() { if ($symbol == 'BTC') { if (is_object($savebalance)) { - $savebalance->balance = $balance['available']; + $savebalance->balance = arraySafeVal($balance,'available'); + $savebalance->onsell = arraySafeVal($balance,'onOrders'); $savebalance->save(); } continue; diff --git a/web/yaamp/core/trading/yobit_trading.php b/web/yaamp/core/trading/yobit_trading.php index ddc483a..f794a6f 100644 --- a/web/yaamp/core/trading/yobit_trading.php +++ b/web/yaamp/core/trading/yobit_trading.php @@ -37,6 +37,7 @@ function doYobitTrading($quick=false) if ($symbol == 'btc') { if (is_object($savebalance)) { $savebalance->balance = $amount; + $savebalance->onsell = arraySafeVal($balances['return']['funds_incl_orders'],$symbol,0.) - $amount; $savebalance->save(); } continue; @@ -51,6 +52,7 @@ function doYobitTrading($quick=false) $market = getdbosql('db_markets', "coinid=:coinid AND name='$exchange'", array(':coinid'=>$coin->id)); if (!$market) continue; $market->balance = $amount; + $market->ontrade = arraySafeVal($balances['return']['funds_incl_orders'],$symbol,0.) - $amount; $market->balancetime = time(); $market->save(); } diff --git a/web/yaamp/modules/site/common_results.php b/web/yaamp/modules/site/common_results.php index 3c25577..a5b93b0 100644 --- a/web/yaamp/modules/site/common_results.php +++ b/web/yaamp/modules/site/common_results.php @@ -222,34 +222,6 @@ echo ''; // ---------------------------------------------------------------------------------------------------- -if (YAAMP_ALLOW_EXCHANGE) { -echo 'sell orders'; -foreach($markets as $market) -{ - $exchange = $market->name; - $onsell = bitcoinvaluetoa(dboscalar("select sum(amount*bid) from orders where market='$exchange'")); - $salebalances[$exchange] = $onsell; - - if($onsell > 0.2) - echo ''.$onsell.''; - else if($onsell > 0.1) - echo ''.$onsell.''; - else if($onsell == 0.0) - echo '-'; - else - echo ''.$onsell.''; - - $total_onsell += $onsell; -} - -$total_onsell = bitcoinvaluetoa($total_onsell); - -echo ''.$total_onsell.''; -echo ''; -} // YAAMP_ALLOW_EXCHANGE - -// ---------------------------------------------------------------------------------------------------- - echo 'BTC'; foreach($markets as $market) { @@ -274,6 +246,45 @@ echo ''; // ---------------------------------------------------------------------------------------------------- +echo 'orders'; +if (YAAMP_ALLOW_EXCHANGE) { + // yaamp mode + foreach($markets as $market) { + $exchange = $market->name; + $onsell = bitcoinvaluetoa(dboscalar("SELECT sum(amount*bid) FROM orders WHERE market='$exchange'")); + $salebalances[$exchange] = $onsell; + + if($onsell > 0.2) + echo ''.$onsell.''; + else if($onsell > 0.1) + echo ''.$onsell.''; + else if($onsell == 0.0) + echo '-'; + else + echo ''.$onsell.''; + + $total_onsell += $onsell; + } +} else { + // yiimp mode + $ontrade = dbolist("SELECT name, onsell FROM balances B ORDER by name"); + foreach($ontrade as $row) { + $exchange = $row['name']; + $onsell = bitcoinvaluetoa($row['onsell']); + $salebalances[$exchange] = $onsell; + + echo ''.($onsell == 0 ? '-' : $onsell).''; + + $total_onsell += (double) $onsell; + } + +} +$total_onsell = bitcoinvaluetoa($total_onsell); +echo ''.$total_onsell.''; +echo ''; + +// ---------------------------------------------------------------------------------------------------- + $t = time() - 48*60*60; $altmarkets = dbolist(" SELECT B.name, SUM((M.balance+M.ontrade)*M.price) AS balance From a79e21491a614656bd137414c4ce6c08e0614626 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Tue, 30 Jan 2018 02:16:06 +0100 Subject: [PATCH 027/195] stratum: avoid the use of getinfo --- stratum/coind.cpp | 4 +--- stratum/coind_template.cpp | 6 +++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/stratum/coind.cpp b/stratum/coind.cpp index 8e33540..bfebc8f 100644 --- a/stratum/coind.cpp +++ b/stratum/coind.cpp @@ -98,7 +98,7 @@ bool coind_validate_user_address(YAAMP_COIND *coind, char* const address) } bool isvalid = json_get_bool(json_result, "isvalid"); - if(!isvalid) stratumlog("%s user address %s is not valid.\n", coind->name, address); + if(!isvalid) stratumlog("%s: %s user address %s is not valid.\n", g_stratum_algo, coind->symbol, address); json_value_free(json); @@ -247,8 +247,6 @@ void coind_terminate(YAAMP_COIND *coind) // CommonLock(&coind->mutex); // while(!coind->deleted) // { -// debuglog("calling coind_getinfo %s\n", coind->symbol); - // job_create_last(coind, true); // pthread_cond_wait(&coind->cond, &coind->mutex); // } diff --git a/stratum/coind_template.cpp b/stratum/coind_template.cpp index 82bd4f6..6aa8b6f 100644 --- a/stratum/coind_template.cpp +++ b/stratum/coind_template.cpp @@ -68,17 +68,17 @@ YAAMP_JOB_TEMPLATE *coind_create_template_memorypool(YAAMP_COIND *coind) json_value_free(json); - json = rpc_call(&coind->rpc, "getinfo", "[]"); + json = rpc_call(&coind->rpc, "getmininginfo", "[]"); if(!json || json->type == json_null) { - coind_error(coind, "coind_getinfo"); + coind_error(coind, "coind getmininginfo"); return NULL; } json_result = json_get_object(json, "result"); if(!json_result || json_result->type == json_null) { - coind_error(coind, "coind_getinfo"); + coind_error(coind, "coind getmininginfo"); json_value_free(json); return NULL; From d69d3ce3fc49f6146e15b01fd76749e2a1a42a2a Mon Sep 17 00:00:00 2001 From: "UniMining.net" <35696127+UniMiningNet@users.noreply.github.com> Date: Wed, 31 Jan 2018 08:23:27 +0100 Subject: [PATCH 028/195] yescryptR16 algo (#217) Algo yescryptR16 for Yenten [YTN] https://bitcointalk.org/?topic=2329470.0 stratum changes from https://github.com/bubasik/yiimp --- stratum/algos/yescrypt-opt.c | 7 ++++++- stratum/algos/yescrypt.c | 4 ++++ stratum/algos/yescrypt.h | 1 + stratum/config.sample/yescryptR16.conf | 15 +++++++++++++++ stratum/stratum.cpp | 1 + web/yaamp/core/functions/yaamp.php | 4 ++++ 6 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 stratum/config.sample/yescryptR16.conf diff --git a/stratum/algos/yescrypt-opt.c b/stratum/algos/yescrypt-opt.c index 4b42e85..b65cdd2 100644 --- a/stratum/algos/yescrypt-opt.c +++ b/stratum/algos/yescrypt-opt.c @@ -942,7 +942,12 @@ yescrypt_kdf(const yescrypt_shared_t * shared, yescrypt_local_t * local, { HMAC_SHA256_CTX_Y ctx; HMAC_SHA256_Init_Y(&ctx, buf, buflen); - HMAC_SHA256_Update_Y(&ctx, salt, saltlen); + if (r == 16) { // yescryptR16 + HMAC_SHA256_Update_Y(&ctx, "Client Key", 10); + } + else { // yescrypt + HMAC_SHA256_Update_Y(&ctx, salt, saltlen); + } HMAC_SHA256_Final_Y((uint8_t *)sha256, &ctx); } /* Compute StoredKey */ diff --git a/stratum/algos/yescrypt.c b/stratum/algos/yescrypt.c index da070d6..9fac019 100644 --- a/stratum/algos/yescrypt.c +++ b/stratum/algos/yescrypt.c @@ -364,3 +364,7 @@ void yescrypt_hash(const char *input, char *output, uint32_t len) { yescrypt_bsty((uint8_t*)input, len, (uint8_t*)input, len, 2048, 8, 1, (uint8_t*)output, 32); } +void yescryptR16_hash(const char *input, char *output, uint32_t len) +{ + yescrypt_bsty((uint8_t*)input, len, (uint8_t*)input, len, 4096, 16, 1, (uint8_t*)output, 32); +} diff --git a/stratum/algos/yescrypt.h b/stratum/algos/yescrypt.h index db72217..f7dac48 100644 --- a/stratum/algos/yescrypt.h +++ b/stratum/algos/yescrypt.h @@ -39,6 +39,7 @@ extern "C" { #include /* for size_t */ void yescrypt_hash(const char* input, char* output, uint32_t len); +void yescryptR16_hash(const char* input, char* output, uint32_t len); /** * crypto_scrypt(passwd, passwdlen, salt, saltlen, N, r, p, buf, buflen): diff --git a/stratum/config.sample/yescryptR16.conf b/stratum/config.sample/yescryptR16.conf new file mode 100644 index 0000000..7c24aed --- /dev/null +++ b/stratum/config.sample/yescryptR16.conf @@ -0,0 +1,15 @@ +[TCP] +server = yaamp.com +port = 6333 +password = tu8tu5 + +[SQL] +host = yaampdb +database = yaamp +username = root +password = patofpaq + +[STRATUM] +algo = yescryptR16 +difficulty = 2 +max_ttf = 400000000 diff --git a/stratum/stratum.cpp b/stratum/stratum.cpp index fe74772..c2177a4 100644 --- a/stratum/stratum.cpp +++ b/stratum/stratum.cpp @@ -150,6 +150,7 @@ YAAMP_ALGO g_algos[] = {"penta", penta_hash, 1, 0, 0}, {"skein2", skein2_hash, 1, 0, 0}, {"yescrypt", yescrypt_hash, 0x10000, 0, 0}, + {"yescryptR16", yescryptR16_hash, 0x10000, 0, 0 }, {"zr5", zr5_hash, 1, 0, 0}, {"hive", hive_hash, 0x10000, 0, 0}, diff --git a/web/yaamp/core/functions/yaamp.php b/web/yaamp/core/functions/yaamp.php index c19af3f..0a05a19 100755 --- a/web/yaamp/core/functions/yaamp.php +++ b/web/yaamp/core/functions/yaamp.php @@ -55,6 +55,7 @@ function yaamp_get_algos() 'veltor', 'velvet', 'yescrypt', + 'yescryptR16', 'whirlpool', 'zr5', ); @@ -109,6 +110,7 @@ function yaamp_get_algo_norm($algo) 'velvet' => 1.0, 'whirlpool' => 1.0, 'yescrypt' => 1.0, + 'yescryptR16' => 1.0, 'zr5' => 1.0, ); @@ -171,6 +173,7 @@ function getAlgoColors($algo) 'velvet' => '#aac0cc', 'whirlpool' => '#d0e0e0', 'yescrypt' => '#e0d0e0', + 'yescryptR16' => '#e2d0e2', 'zr5' => '#d0b0d0', 'MN' => '#ffffff', // MasterNode Earnings @@ -235,6 +238,7 @@ function getAlgoPort($algo) 'veltor' => 5034, 'velvet' => 6133, 'yescrypt' => 6233, + 'yescryptR16' => 6333, 'bastion' => 6433, 'hsr' => 7433, 'phi' => 8333, From 0bf982da9581e96906d9684295ea62331302043a Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Fri, 2 Feb 2018 06:02:53 +0100 Subject: [PATCH 029/195] sql: add hasgetinfo and no_explorer fields to coins table wallets without getinfo will be handled in a later commit... ps: remember to restart memcached service after the db change.. --- sql/2018-02-coins_getinfo.sql | 13 +++++++++++++ web/yaamp/models/db_coinsModel.php | 1 + web/yaamp/modules/explorer/ExplorerController.php | 8 ++++++++ web/yaamp/modules/site/coin_form.php | 14 +++++++++++++- 4 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 sql/2018-02-coins_getinfo.sql diff --git a/sql/2018-02-coins_getinfo.sql b/sql/2018-02-coins_getinfo.sql new file mode 100644 index 0000000..b3ea822 --- /dev/null +++ b/sql/2018-02-coins_getinfo.sql @@ -0,0 +1,13 @@ +-- Recent additions to add after db init (.gz) +-- mysql yaamp -p < file.sql + +-- filled by the stratum instance, to allow to handle/watch multiple instances + +ALTER TABLE `coins` ADD `hasgetinfo` tinyint(1) UNSIGNED NOT NULL DEFAULT '1' AFTER `account`; + +UPDATE coins SET hassubmitblock=0 WHERE hassubmitblock IS NULL; +UPDATE coins SET hassubmitblock=1 WHERE hassubmitblock > 0; +ALTER TABLE `coins` CHANGE `hassubmitblock` `hassubmitblock` tinyint(1) UNSIGNED NOT NULL DEFAULT '1'; + +ALTER TABLE `coins` ADD `no_explorer` tinyint(1) UNSIGNED NOT NULL DEFAULT '0' AFTER `visible`; + diff --git a/web/yaamp/models/db_coinsModel.php b/web/yaamp/models/db_coinsModel.php index 3446eb1..5ce150d 100644 --- a/web/yaamp/models/db_coinsModel.php +++ b/web/yaamp/models/db_coinsModel.php @@ -47,6 +47,7 @@ class db_coins extends CActiveRecord 'rpcssl' => 'RPC SSL', 'rpccert' => 'RPC Certificate', 'serveruser' => 'Server user', + 'hasgetinfo' => 'Has getinfo', 'hassubmitblock'=> 'Has submitblock', 'hasmasternodes'=> 'Masternodes', 'usesegwit' => 'Use segwit', diff --git a/web/yaamp/modules/explorer/ExplorerController.php b/web/yaamp/modules/explorer/ExplorerController.php index b122bf5..c165007 100644 --- a/web/yaamp/modules/explorer/ExplorerController.php +++ b/web/yaamp/modules/explorer/ExplorerController.php @@ -57,6 +57,14 @@ class ExplorerController extends CommonController $id = getiparam('id'); $coin = getdbo('db_coins', $id); + if($coin && $coin->no_explorer) { + $link = $coin->link_explorer; + //$txid = getparam('txid'); + //$hash = getparam('hash'); + //if (!empty($txid)) $link .= 'tx/'.$txid; + //elseif (!empty($hash)) $link .= 'block/'.$hash; + die("Block explorer disabled, please use $link"); + } $height = getiparam('height'); if($coin && intval($height)>0) { diff --git a/web/yaamp/modules/site/coin_form.php b/web/yaamp/modules/site/coin_form.php index af67481..3507ca4 100644 --- a/web/yaamp/modules/site/coin_form.php +++ b/web/yaamp/modules/site/coin_form.php @@ -147,6 +147,12 @@ echo CUFHtml::activeCheckBox($coin, 'installed'); echo '

Required to be visible in the Wallets board

'; echo CUFHtml::closeCtrlHolder(); +echo CUFHtml::openActiveCtrlHolder($coin, 'no_explorer'); +echo CUFHtml::activeLabelEx($coin, 'no_explorer'); +echo CUFHtml::activeCheckBox($coin, 'no_explorer'); +echo '

Disable block explorer for the public

'; +echo CUFHtml::closeCtrlHolder(); + echo CUFHtml::openActiveCtrlHolder($coin, 'watch'); echo CUFHtml::activeLabelEx($coin, 'watch'); echo CUFHtml::activeCheckBox($coin, 'watch'); @@ -201,6 +207,12 @@ echo CUFHtml::activeTextField($coin, 'charity_address', array('maxlength'=>200)) echo '

Foundation address if "dev fees" are required

'; echo CUFHtml::closeCtrlHolder(); +echo CUFHtml::openActiveCtrlHolder($coin, 'hasgetinfo'); +echo CUFHtml::activeLabelEx($coin, 'hasgetinfo'); +echo CUFHtml::activeCheckBox($coin, 'hasgetinfo'); +echo '

Enable if getinfo rpc method is present

'; +echo CUFHtml::closeCtrlHolder(); + echo CUFHtml::openActiveCtrlHolder($coin, 'hassubmitblock'); echo CUFHtml::activeLabelEx($coin, 'hassubmitblock'); echo CUFHtml::activeCheckBox($coin, 'hassubmitblock'); @@ -216,7 +228,7 @@ echo CUFHtml::closeCtrlHolder(); echo CUFHtml::openActiveCtrlHolder($coin, 'hasmasternodes'); echo CUFHtml::activeLabelEx($coin, 'hasmasternodes'); echo CUFHtml::activeCheckBox($coin, 'hasmasternodes'); -echo '

Require "payee" and "payee_amount" fields in getblocktemplate (DASH)

'; +echo '

Require "payee" and "payee_amount", or masternode object in getblocktemplate

'; echo CUFHtml::closeCtrlHolder(); echo CUFHtml::openActiveCtrlHolder($coin, 'usesegwit'); From 4d74f062047436457187e84716857b5a85a541ac Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Wed, 7 Feb 2018 11:55:09 +0100 Subject: [PATCH 030/195] stratum: extra check for the haters --- stratum/client.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/stratum/client.cpp b/stratum/client.cpp index e50f03c..e3f679b 100644 --- a/stratum/client.cpp +++ b/stratum/client.cpp @@ -548,6 +548,10 @@ void *client_thread(void *p) client->id_int = json_get_int(json, "id"); client->id_str = json_get_string(json, "id"); + if (client->id_str && strlen(client->id_str) > 32) { + clientlog(client, "bad id"); + break; + } const char *method = json_get_string(json, "method"); From 30413db5486291be6b5aab67f4276042e06cc89c Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Fri, 9 Feb 2018 16:48:59 +0100 Subject: [PATCH 031/195] update sample stratum rc.local #225 --- rc.local | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/rc.local b/rc.local index 7ea3e67..9da2b84 100644 --- a/rc.local +++ b/rc.local @@ -25,8 +25,9 @@ screen -dmS deep $STRATUM_DIR/run.sh deep screen -dmS x11 $STRATUM_DIR/run.sh x11 screen -dmS x11evo $STRATUM_DIR/run.sh x11evo screen -dmS x13 $STRATUM_DIR/run.sh x13 -screen -dmS x14 $STRATUM_DIR/run.sh x14 -screen -dmS x15 $STRATUM_DIR/run.sh x15 +#screen -dmS x14 $STRATUM_DIR/run.sh x14 +#screen -dmS x15 $STRATUM_DIR/run.sh x15 +#screen -dmS x16r $STRATUM_DIR/run.sh x16r screen -dmS x17 $STRATUM_DIR/run.sh x17 screen -dmS xevan $STRATUM_DIR/run.sh xevan screen -dmS timetravel $STRATUM_DIR/run.sh timetravel @@ -59,11 +60,15 @@ screen -dmS vanilla $STRATUM_DIR/run.sh vanilla # blake 8 screen -dmS decred $STRATUM_DIR/run.sh decred # blake 14 #screen -dmS keccak $STRATUM_DIR/run.sh keccak +#screen -dmS keccakc $STRATUM_DIR/run.sh keccakc +#screen -dmS phi $STRATUM_DIR/run.sh phi +#screen -dmS polytimos $STRATUM_DIR/run.sh polytimos screen -dmS whirlpool $STRATUM_DIR/run.sh whirlpool screen -dmS skein $STRATUM_DIR/run.sh skein screen -dmS skein2 $STRATUM_DIR/run.sh skein2 screen -dmS yescrypt $STRATUM_DIR/run.sh yescrypt +#screen -dmS yescryptR16 $STRATUM_DIR/run.sh yescryptR16 screen -dmS zr5 $STRATUM_DIR/run.sh zr5 screen -dmS sib $STRATUM_DIR/run.sh sib screen -dmS m7m $STRATUM_DIR/run.sh m7m From 1e57015a65cf47b1a00173fdee9e8313108abe8c Mon Sep 17 00:00:00 2001 From: phm87 <31578435+phm87@users.noreply.github.com> Date: Thu, 8 Feb 2018 00:53:18 +0100 Subject: [PATCH 032/195] admin: fill servers dropdown with the db #222 with proper html quotes... --- web/yaamp/modules/site/admin.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/web/yaamp/modules/site/admin.php b/web/yaamp/modules/site/admin.php index e10542c..92620c6 100644 --- a/web/yaamp/modules/site/admin.php +++ b/web/yaamp/modules/site/admin.php @@ -12,14 +12,16 @@ $server = getparam('server'); echo << Select Server: - + +end; + +$serverlist = dbolist("SELECT DISTINCT rpchost FROM coins WHERE installed=1 ORDER BY rpchost"); +foreach ($serverlist as $srv) { + echo ''; +} + +echo <<  From 5468b84da746416bfae771fc82a82fa8e2bdcc31 Mon Sep 17 00:00:00 2001 From: oddhome Date: Sun, 4 Feb 2018 21:07:19 +0700 Subject: [PATCH 033/195] stratum: set PBS as old masternode #220 --- stratum/db.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/stratum/db.cpp b/stratum/db.cpp index 53c56e5..a46a62a 100644 --- a/stratum/db.cpp +++ b/stratum/db.cpp @@ -303,6 +303,7 @@ void db_update_coinds(YAAMP_DB *db) if (strcmp(coind->symbol, "ITZ") == 0) coind->oldmasternodes = true; if (strcmp(coind->symbol, "J") == 0 || strcmp(coind->symbol2, "J") == 0) coind->oldmasternodes = true; if (strcmp(coind->symbol, "MAG") == 0) coind->oldmasternodes = true; + if (strcmp(coind->symbol, "PBS") == 0) coind->oldmasternodes = true; if (strcmp(coind->symbol, "URALS") == 0) coind->oldmasternodes = true; if (strcmp(coind->symbol, "VSX") == 0) coind->oldmasternodes = true; if (strcmp(coind->symbol, "XLR") == 0) coind->oldmasternodes = true; From 90e78f772f7309828916be2070d41db69af66877 Mon Sep 17 00:00:00 2001 From: phm87 <31578435+phm87@users.noreply.github.com> Date: Wed, 14 Feb 2018 10:24:24 +0100 Subject: [PATCH 034/195] NH: new algos (#229) --- web/yaamp/core/backend/services.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/web/yaamp/core/backend/services.php b/web/yaamp/core/backend/services.php index e398698..60dfbd3 100644 --- a/web/yaamp/core/backend/services.php +++ b/web/yaamp/core/backend/services.php @@ -22,6 +22,23 @@ function BackendUpdateServices() 10=>'whirlx', 11=>'qubit', 12=>'quark', + // 13=>'Axiom', + 14=>'lyra2v2', // 14 = Lyra2REv2 + // 15=>'ScryptJaneNf16', // 15 = ScryptJaneNf16 + 16=>'blakecoin', // 16 = Blake256r8 + // 17=>'Blake256r14', + // 18=>'Blake256r8vnl', + // 19=>'Hodl', + // 20=>'DaggerHashimoto', + // 21=>'Decred', + // 22=>'CryptoNight', + 23=>'lbry', + 24=>'equihash', + // 25=>'Pascal', + 26=>'sib', // X11Gost + // 27=>'Sia', + 28=>'blake2s', + 29=>'skunk', ); $res = fetch_url('https://api.nicehash.com/api?method=stats.global.current'); From c99770a5ae9fb46b8092b6cbe6fc88dd2510448b Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Fri, 16 Feb 2018 13:33:25 +0100 Subject: [PATCH 035/195] stratum: allow to reopen wiped global logs can be useful after a logrotate, to avoid restarting the stratums --- stratum/util.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/stratum/util.cpp b/stratum/util.cpp index ef928c4..a8b7237 100644 --- a/stratum/util.cpp +++ b/stratum/util.cpp @@ -149,7 +149,11 @@ void clientlog(YAAMP_CLIENT *client, const char *format, ...) if(g_clientlog) { fprintf(g_clientlog, "%s", buffer3); - fflush(g_clientlog); + if (fflush(g_clientlog) == EOF) { + // reopen if wiped + fclose(g_clientlog); + g_clientlog = fopen("client.log", "a"); + } } } @@ -219,7 +223,10 @@ void stratumlog(const char *format, ...) if(g_stratumlog) { fprintf(g_stratumlog, "%s: %s", buffer2, buffer); - fflush(g_stratumlog); + if (fflush(g_stratumlog) == EOF) { + fclose(g_stratumlog); + g_stratumlog = fopen("stratum.log", "a"); + } } } @@ -264,7 +271,10 @@ void rejectlog(const char *format, ...) if(g_rejectlog) { fprintf(g_rejectlog, "%s: %s", buffer2, buffer); - fflush(g_rejectlog); + if (fflush(g_rejectlog) == EOF) { + fclose(g_rejectlog); + g_rejectlog = fopen("reject.log", "a"); + } } } From e37c636deb6f6a48c82367fefd05e1dc4877f652 Mon Sep 17 00:00:00 2001 From: Tatar Xavatar Date: Sun, 18 Feb 2018 14:04:32 +0100 Subject: [PATCH 036/195] Update x16r.conf : error with port (#232) --- stratum/config.sample/x16r.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stratum/config.sample/x16r.conf b/stratum/config.sample/x16r.conf index 5407f03..a2329a8 100644 --- a/stratum/config.sample/x16r.conf +++ b/stratum/config.sample/x16r.conf @@ -1,6 +1,6 @@ [TCP] server = yaamp.com -port = 3737 +port = 3636 password = tu8tu5 [SQL] From 033d50c9ba81632fdfb07a485a17b85bace57565 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Fri, 16 Feb 2018 18:56:57 +0100 Subject: [PATCH 037/195] stratum: allow more than 254 transactions in blocks --- stratum/client_submit.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/stratum/client_submit.cpp b/stratum/client_submit.cpp index 993b726..41cbf5b 100644 --- a/stratum/client_submit.cpp +++ b/stratum/client_submit.cpp @@ -215,12 +215,18 @@ static void client_do_submit(YAAMP_CLIENT *client, YAAMP_JOB *job, YAAMP_JOB_VAL if(hash_int <= coin_target) { + char count_hex[8] = { 0 }; + if (templ->txcount <= 255) + sprintf(count_hex, "%02x", templ->txcount & 0xFF); + else + sprintf(count_hex, "fd%02x%02x", templ->txcount & 0xFF, templ->txcount >> 8); + memset(block_hex, 0, block_size); - sprintf(block_hex, "%s%02x%s", submitvalues->header_be, (unsigned char)templ->txcount, submitvalues->coinbase); + sprintf(block_hex, "%s%s%s", submitvalues->header_be, count_hex, submitvalues->coinbase); if (g_current_algo->name && !strcmp("jha", g_current_algo->name)) { // block header of 88 bytes - sprintf(block_hex, "%s8400000008000000%02x%s", submitvalues->header_be, (unsigned char)templ->txcount, submitvalues->coinbase); + sprintf(block_hex, "%s8400000008000000%s%s", submitvalues->header_be, count_hex, submitvalues->coinbase); } vector::const_iterator i; From 236650dc57b6ae2a1cb122a0bdbb93af073c7450 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Sun, 18 Feb 2018 15:50:48 +0100 Subject: [PATCH 038/195] stratum: allow to limit txs per block --- stratum/coind_template.cpp | 24 +++++++++++++++++++++--- stratum/job.h | 3 +++ stratum/stratum.cpp | 5 +++++ stratum/stratum.h | 1 + 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/stratum/coind_template.cpp b/stratum/coind_template.cpp index 6aa8b6f..cca3ebf 100644 --- a/stratum/coind_template.cpp +++ b/stratum/coind_template.cpp @@ -381,12 +381,20 @@ YAAMP_JOB_TEMPLATE *coind_create_template(YAAMP_COIND *coind) txids.push_back(""); templ->has_segwit_txs = false; - // to force/test - // templ->has_segwit_txs = coind->usesegwit = (coind->usesegwit || g_stratum_segwit); + + templ->has_filtered_txs = false; + templ->filtered_txs_fee = 0; + for(int i = 0; i < json_tx->u.array.length; i++) { const char *p = json_get_string(json_tx->u.array.values[i], "hash"); char hash_be[256] = { 0 }; + + if (templ->has_filtered_txs) { + templ->filtered_txs_fee += json_get_int(json_tx->u.array.values[i], "fee"); + continue; + } + string_be(p, hash_be); txhashes.push_back(hash_be); @@ -396,7 +404,6 @@ YAAMP_JOB_TEMPLATE *coind_create_template(YAAMP_COIND *coind) string_be(txid, txid_be); txids.push_back(txid_be); if (strcmp(hash_be, txid_be)) { - //debuglog("%s segwit tx found, height %d\n", coind->symbol, templ->height); templ->has_segwit_txs = true; // if not, its useless to generate a segwit block, bigger } } else { @@ -405,6 +412,17 @@ YAAMP_JOB_TEMPLATE *coind_create_template(YAAMP_COIND *coind) const char *d = json_get_string(json_tx->u.array.values[i], "data"); templ->txdata.push_back(d); + + // if wanted, we can limit the count of txs to include + if (g_limit_txs_per_block && i >= g_limit_txs_per_block-2) { + debuglog("limiting block to %d first txs (of %d)\n", g_limit_txs_per_block, json_tx->u.array.length); + templ->has_filtered_txs = true; + } + } + + if (templ->has_filtered_txs) { + // coinbasevalue is a total with all tx fees, need to reduce it if some are skipped + templ->value -= templ->filtered_txs_fee; } templ->txmerkles[0] = '\0'; diff --git a/stratum/job.h b/stratum/job.h index f876fd7..59657fc 100644 --- a/stratum/job.h +++ b/stratum/job.h @@ -52,6 +52,9 @@ struct YAAMP_JOB_TEMPLATE bool has_segwit_txs; + bool has_filtered_txs; + int filtered_txs_fee; + int auxs_size; YAAMP_COIND_AUX *auxs[MAX_AUXS]; }; diff --git a/stratum/stratum.cpp b/stratum/stratum.cpp index c2177a4..b5c16af 100644 --- a/stratum/stratum.cpp +++ b/stratum/stratum.cpp @@ -36,6 +36,9 @@ int g_stratum_max_cons = 5000; bool g_stratum_reconnect; bool g_stratum_renting; bool g_stratum_segwit = false; + +int g_limit_txs_per_block = 0; + bool g_autoexchange = true; uint64_t g_max_shares = 0; @@ -236,6 +239,8 @@ int main(int argc, char **argv) g_stratum_reconnect = iniparser_getint(ini, "STRATUM:reconnect", true); g_stratum_renting = iniparser_getint(ini, "STRATUM:renting", true); + g_limit_txs_per_block = iniparser_getint(ini, "STRATUM:max_txs_per_block", 0); + iniparser_freedict(ini); g_current_algo = stratum_find_algo(g_stratum_algo); diff --git a/stratum/stratum.h b/stratum/stratum.h index 9ea87d7..773da2e 100644 --- a/stratum/stratum.h +++ b/stratum/stratum.h @@ -87,6 +87,7 @@ extern int g_stratum_max_ttf; extern bool g_stratum_reconnect; extern bool g_stratum_renting; extern bool g_stratum_segwit; +extern int g_limit_txs_per_block; extern uint64_t g_max_shares; extern uint64_t g_shares_counter; From 03f25a73ef17fe107d9552de6050d0d6231fcd93 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Sat, 24 Feb 2018 18:00:36 +0100 Subject: [PATCH 039/195] stratum: DNR v2 masternodes --- stratum/db.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/stratum/db.cpp b/stratum/db.cpp index a46a62a..e838267 100644 --- a/stratum/db.cpp +++ b/stratum/db.cpp @@ -299,6 +299,7 @@ void db_update_coinds(YAAMP_DB *db) if (strcmp(coind->symbol, "BWK") == 0) coind->oldmasternodes = true; if (strcmp(coind->symbol, "CHC") == 0) coind->oldmasternodes = true; if (strcmp(coind->symbol, "CRW") == 0) coind->oldmasternodes = true; + if (strcmp(coind->symbol, "DNR") == 0) coind->oldmasternodes = true; if (strcmp(coind->symbol, "FLAX") == 0) coind->oldmasternodes = true; if (strcmp(coind->symbol, "ITZ") == 0) coind->oldmasternodes = true; if (strcmp(coind->symbol, "J") == 0 || strcmp(coind->symbol2, "J") == 0) coind->oldmasternodes = true; From 02c0191e5ee7383dcdf00fbc9882949c05ddaf18 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Sat, 24 Feb 2018 19:29:06 +0100 Subject: [PATCH 040/195] stats: rewrite pool graphes data with json_encode --- .../site/results/graph_hashrate_results.php | 48 ++++------------- .../site/results/graph_price_results.php | 54 ++++++------------- 2 files changed, 25 insertions(+), 77 deletions(-) diff --git a/web/yaamp/modules/site/results/graph_hashrate_results.php b/web/yaamp/modules/site/results/graph_hashrate_results.php index 1741dd9..b585fb0 100644 --- a/web/yaamp/modules/site/results/graph_hashrate_results.php +++ b/web/yaamp/modules/site/results/graph_hashrate_results.php @@ -8,19 +8,16 @@ $factor = yaamp_algo_mBTC_factor($algo); // 1000 sha (GH/s), 1 for normal MH/s $step = 15*60; $t = time() - 24*60*60; - -$stats = getdbolist('db_hashrate', "time > $t AND algo=:algo ORDER BY time", array(':algo'=>$algo)); +$t = intval($t / $step) * $step; +$stats = getdbolist('db_hashrate', "time >= $t AND algo=:algo ORDER BY time", array(':algo'=>$algo)); +$tfirst = empty($stats) ? $t : $stats[0]->time; $averages = array(); -$json = ''; - -for($i = 0; $i < 95-count($stats); $i++) -{ +for($i = 0; $i < 95-count($stats); $i++) { $d = date('Y-m-d H:i:s', $t); - $json .= "[\"$d\",0],"; - $averages[] = array($d, 0); $t += $step; + if ($t >= $tfirst) break; } foreach($stats as $n) @@ -29,43 +26,18 @@ foreach($stats as $n) $m = round($r / $factor, 3); $d = date('Y-m-d H:i:s', $n->time); - $json .= "[\"$d\",$m],"; $averages[] = array($d, $m); } -echo '[['.rtrim($json,',').'],'; -echo '['; +if ($averages[0][1] == 0) $averages[0][1] = $averages[1][1]; -$json = ''; +$avg2 = array(); $average = $averages[0][1]; -foreach($averages as $n) -{ +foreach($averages as $n) { $average = ($average*(100-$percent) + $n[1]*$percent) / 100; $m = round($average, 3); - - $json .= "[\"{$n[0]}\",$m],"; + $avg2[] = array($n[0], $m); } -// $a = 10; -// foreach($averages as $i=>$n) -// { -// if($i < $a) continue; - -// $average = 0; -// for($j = $i-$a+1; $j<=$i; $j++) -// $average += $averages[$j][1]/$a; - -// $m = round($average, 3); - -// $json .= "[\"{$n[0]}\",$m]"; -// } - -echo rtrim($json,','); -echo ']]'; - - - - - - +echo '['.json_encode($averages).",\n".json_encode($avg2).']'; diff --git a/web/yaamp/modules/site/results/graph_price_results.php b/web/yaamp/modules/site/results/graph_price_results.php index 50536c5..77873cb 100644 --- a/web/yaamp/modules/site/results/graph_price_results.php +++ b/web/yaamp/modules/site/results/graph_price_results.php @@ -1,62 +1,38 @@ getState('yaamp-algo'); $step = 15*60; $t = time() - 24*60*60; - -$stats = getdbolist('db_hashrate', "time > $t AND algo=:algo ORDER BY time", array(':algo'=>$algo)); +$t = intval($t / $step) * $step; +$stats = getdbolist('db_hashrate', "time >= $t AND algo=:algo ORDER BY time", array(':algo'=>$algo)); +$tfirst = empty($stats) ? $t : $stats[0]->time; +$pfirst = empty($stats) ? 0.0 : (double) altcoinvaluetoa($stats[0]->price); $averages = array(); -$json = ''; -for($i = 0; $i < 95-count($stats); $i++) -{ +for($i = 0; $i < 95-count($stats); $i++) { $d = date('Y-m-d H:i:s', $t); - $json .= "[\"$d\",0],"; - + $averages[] = array($d, $pfirst); $t += $step; - $averages[] = array($d, 0); + if ($t >= $tfirst) break; } -foreach($stats as $n) -{ - $m = $n->price; - +foreach($stats as $n) { + $m = (double) altcoinvaluetoa($n->price); $d = date('Y-m-d H:i:s', $n->time); - $json .= "[\"$d\",$m],"; - $averages[] = array($d, $m); } -echo '[['; -echo rtrim($json, ','); -echo '],['; - -$json = ''; +$avg2 = array(); $average = $averages[0][1]; -foreach($averages as $n) -{ +foreach($averages as $n) { $average = ($average*(100-$percent) + $n[1]*$percent) / 100; $m = round($average, 5); - $json .= "[\"{$n[0]}\",$m],"; + $avg2[] = array($n[0], $m); } -// $a = 10; -// foreach($averages as $i=>$n) -// { -// if($i < $a) continue; - -// $average = 0; -// for($j = $i-$a+1; $j<=$i; $j++) -// $average += $averages[$j][1]/$a; - -// $m = round($average, 3); - -// echo "[\"{$n[0]}\",$m]"; -// } - -echo rtrim($json, ','); -echo ']]'; - +echo '['.json_encode($averages).",\n".json_encode($avg2).']'; From de4592cc1a212608f6cdbf7a8fc4c1d6f646d8f6 Mon Sep 17 00:00:00 2001 From: exmac Date: Sun, 25 Feb 2018 16:51:01 +0000 Subject: [PATCH 041/195] Add a5a algo for Andcoin --- stratum/algos/a5a.c | 260 +++++++++++++++++++++++++++++ stratum/algos/a5a.h | 14 ++ stratum/algos/a5amath.c | 116 +++++++++++++ stratum/algos/a5amath.h | 16 ++ stratum/algos/makefile | 1 + stratum/config.sample/a5a.conf | 15 ++ stratum/stratum.cpp | 1 + stratum/stratum.h | 1 + web/yaamp/core/functions/yaamp.php | 3 + 9 files changed, 427 insertions(+) create mode 100644 stratum/algos/a5a.c create mode 100644 stratum/algos/a5a.h create mode 100644 stratum/algos/a5amath.c create mode 100644 stratum/algos/a5amath.h create mode 100644 stratum/config.sample/a5a.conf diff --git a/stratum/algos/a5a.c b/stratum/algos/a5a.c new file mode 100644 index 0000000..fbf608b --- /dev/null +++ b/stratum/algos/a5a.c @@ -0,0 +1,260 @@ +#include +#include +#include +#include +#include +#include +#include +#include "a5amath.h" + +#include "../sha3/sph_sha2.h" +#include "../sha3/sph_keccak.h" +#include "../sha3/sph_whirlpool.h" +#include "../sha3/sph_ripemd.h" + +static void mpz_set_uint256(mpz_t r, uint8_t *u) +{ + mpz_import(r, 32 / sizeof(unsigned long), -1, sizeof(unsigned long), -1, 0, u); +} + +static void mpz_get_uint256(mpz_t r, uint8_t *u) +{ + u=0; + mpz_export(u, 0, -1, sizeof(unsigned long), -1, 0, r); +} + +static void mpz_set_uint512(mpz_t r, uint8_t *u) +{ + mpz_import(r, 64 / sizeof(unsigned long), -1, sizeof(unsigned long), -1, 0, u); +} + +static void set_one_if_zero(uint8_t *hash512) { + int i; + for (i = 0; i < 32; i++) { + if (hash512[i] != 0) { + return; + } + } + hash512[0] = 1; +} + +#define BITS_PER_DIGIT 3.32192809488736234787 +//#define EPS (std::numeric_limits::epsilon()) +#define EPS (DBL_EPSILON) + +#define Na5a 5 +#define SW_DIVS 5 +//#define SW_MAX 1000 + +void a5a_hash(const char* input, char* output, uint32_t len) +{ + unsigned int nnNonce; + uint32_t pdata[32]; + memcpy(pdata, input, 80); +// memcpy(&nnNonce, input+76, 4); + + int i, j, bytes, nnNonce2; + nnNonce2 = (int)(pdata[19]/2); + size_t sz = 80; + uint8_t bhash[5][64]; + uint32_t hash[6]; + memset(bhash, 0, 5 * 64); + + sph_sha256_context ctx_final_sha256; + + sph_sha256_context ctx_sha256; + sph_sha512_context ctx_sha512; + sph_keccak512_context ctx_keccak; + sph_whirlpool_context ctx_whirlpool; + sph_ripemd160_context ctx_ripemd; + + sph_sha256_init(&ctx_sha256); + // ZSHA256; + sph_sha256 (&ctx_sha256, input, sz); + sph_sha256_close(&ctx_sha256, (void*)(bhash[0])); + + sph_sha512_init(&ctx_sha512); + // ZSHA512; + sph_sha512 (&ctx_sha512, input, sz); + sph_sha512_close(&ctx_sha512, (void*)(bhash[1])); + + sph_keccak512_init(&ctx_keccak); + // ZKECCAK; + sph_keccak512 (&ctx_keccak, input, sz); + sph_keccak512_close(&ctx_keccak, (void*)(bhash[2])); + + sph_whirlpool_init(&ctx_whirlpool); + // ZWHIRLPOOL; + sph_whirlpool (&ctx_whirlpool, input, sz); + sph_whirlpool_close(&ctx_whirlpool, (void*)(bhash[3])); + + sph_ripemd160_init(&ctx_ripemd); + // ZRIPEMD; + sph_ripemd160 (&ctx_ripemd, input, sz); + sph_ripemd160_close(&ctx_ripemd, (void*)(bhash[4])); + +// printf("%s\n", hash[4].GetHex().c_str()); + + mpz_t bns[6]; + for(i=0; i < 6; i++){ + mpz_init(bns[i]); + } + //Take care of zeros and load gmp + for(i=0; i < 5; i++){ + set_one_if_zero(bhash[i]); + mpz_set_uint512(bns[i],bhash[i]); + } + + mpz_set_ui(bns[5],0); + for(i=0; i < 5; i++) + mpz_add(bns[5], bns[5], bns[i]); + + mpz_t product; + mpz_init(product); + mpz_set_ui(product,1); +// mpz_pow_ui(bns[5], bns[5], 2); + for(i=0; i < 6; i++){ + mpz_mul(product,product,bns[i]); + } + mpz_pow_ui(product, product, 2); + + bytes = mpz_sizeinbase(product, 256); +// printf("a5a data space: %iB\n", bytes); + char *data = (char*)malloc(bytes); + mpz_export(data, NULL, -1, 1, 0, 0, product); + + sph_sha256_init(&ctx_final_sha256); + // ZSHA256; + sph_sha256 (&ctx_final_sha256, data, bytes); + sph_sha256_close(&ctx_final_sha256, (void*)(hash)); + free(data); + + int digits=(int)((sqrt((double)(nnNonce2))*(1.+EPS))/9000+75); +// int iterations=(int)((sqrt((double)(nnNonce2))+EPS)/500+350); // <= 500 +// int digits=100; + int iterations=20; // <= 500 + mpf_set_default_prec((long int)(digits*BITS_PER_DIGIT+16)); + + mpz_t a5api; + mpz_t a5asw; + mpf_t a5afpi; + mpf_t mpa1, mpb1, mpt1, mpp1; + mpf_t mpa2, mpb2, mpt2, mpp2; + mpf_t mpsft; + + mpz_init(a5api); + mpz_init(a5asw); + mpf_init(a5afpi); + mpf_init(mpsft); + mpf_init(mpa1); + mpf_init(mpb1); + mpf_init(mpt1); + mpf_init(mpp1); + + mpf_init(mpa2); + mpf_init(mpb2); + mpf_init(mpt2); + mpf_init(mpp2); + + uint32_t usw_; + usw_ = sw_(nnNonce2, SW_DIVS); + if (usw_ < 1) usw_ = 1; +// if(fDebuga5a) printf("usw_: %d\n", usw_); + mpz_set_ui(a5asw, usw_); + uint32_t mpzscale=mpz_size(a5asw); +for(i=0; i < Na5a; i++) +{ + if (mpzscale > 1000) { + mpzscale = 1000; + } + else if (mpzscale < 1) { + mpzscale = 1; + } +// if(fDebuga5a) printf("mpzscale: %d\n", mpzscale); + + mpf_set_ui(mpa1, 1); + mpf_set_ui(mpb1, 2); + mpf_set_d(mpt1, 0.25*mpzscale); + mpf_set_ui(mpp1, 1); + mpf_sqrt(mpb1, mpb1); + mpf_ui_div(mpb1, 1, mpb1); + mpf_set_ui(mpsft, 10); + + for(j=0; j <= iterations; j++) + { + mpf_add(mpa2, mpa1, mpb1); + mpf_div_ui(mpa2, mpa2, 2); + mpf_mul(mpb2, mpa1, mpb1); + mpf_abs(mpb2, mpb2); + mpf_sqrt(mpb2, mpb2); + mpf_sub(mpt2, mpa1, mpa2); + mpf_abs(mpt2, mpt2); + mpf_sqrt(mpt2, mpt2); + mpf_mul(mpt2, mpt2, mpp1); + mpf_sub(mpt2, mpt1, mpt2); + mpf_mul_ui(mpp2, mpp1, 2); + mpf_swap(mpa1, mpa2); + mpf_swap(mpb1, mpb2); + mpf_swap(mpt1, mpt2); + mpf_swap(mpp1, mpp2); + } + mpf_add(a5afpi, mpa1, mpb1); + mpf_pow_ui(a5afpi, a5afpi, 2); + mpf_div_ui(a5afpi, a5afpi, 4); + mpf_abs(mpt1, mpt1); + mpf_div(a5afpi, a5afpi, mpt1); + +// mpf_out_str(stdout, 10, digits+2, a5afpi); + + mpf_pow_ui(mpsft, mpsft, digits/2); + mpf_mul(a5afpi, a5afpi, mpsft); + + mpz_set_f(a5api, a5afpi); + +//mpz_set_ui(a5api,1); + + mpz_add(product,product,a5api); + mpz_add(product,product,a5asw); + + mpz_set_uint256(bns[0], (void*)(hash)); + mpz_add(bns[5], bns[5], bns[0]); + + mpz_mul(product,product,bns[5]); + mpz_cdiv_q (product, product, bns[0]); + if (mpz_sgn(product) <= 0) mpz_set_ui(product,1); + + bytes = mpz_sizeinbase(product, 256); + mpzscale=bytes; +// printf("a5a data space: %iB\n", bytes); + char *bdata = (char*)malloc(bytes); + mpz_export(bdata, NULL, -1, 1, 0, 0, product); + + sph_sha256_init(&ctx_final_sha256); + // ZSHA256; + sph_sha256 (&ctx_final_sha256, bdata, bytes); + sph_sha256_close(&ctx_final_sha256, (void*)(hash)); + free(bdata); +} + //Free the memory + for(i=0; i < 6; i++){ + mpz_clear(bns[i]); + } +// mpz_clear(dSpectralWeight); + mpz_clear(product); + + mpz_clear(a5api); + mpz_clear(a5asw); + mpf_clear(a5afpi); + mpf_clear(mpsft); + mpf_clear(mpa1); + mpf_clear(mpb1); + mpf_clear(mpt1); + mpf_clear(mpp1); + + mpf_clear(mpa2); + mpf_clear(mpb2); + mpf_clear(mpt2); + mpf_clear(mpp2); + + memcpy(output, hash, 32); +} \ No newline at end of file diff --git a/stratum/algos/a5a.h b/stratum/algos/a5a.h new file mode 100644 index 0000000..3470d8f --- /dev/null +++ b/stratum/algos/a5a.h @@ -0,0 +1,14 @@ +#ifndef SCRYPT_H +#define SCRYPT_H +#include +#ifdef __cplusplus +extern "C" { +#endif + +void a5a_hash(const char* input, char* output, uint32_t len); + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/stratum/algos/a5amath.c b/stratum/algos/a5amath.c new file mode 100644 index 0000000..1c61c5f --- /dev/null +++ b/stratum/algos/a5amath.c @@ -0,0 +1,116 @@ +// Copyright (c) 2014 The a5a developers +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include +#include +#include +#include +#include +#include +#include +//#include +#include "a5amath.h" + +//#define EPS1 (std::numeric_limits::epsilon()) +#define EPS1 (DBL_EPSILON) +#define EPS2 3.0e-11 + +double exp_n(double xt) +{ + double p1 = -700.0, p3 = -0.8e-8, p4 = 0.8e-8, p6 = 700.0; + if(xt < p1) + return 0; + else if(xt > p6) + return 1e200; + else if(xt > p3 && xt < p4) + return (1.0 + xt); + else + return exp(xt); +} + +// 1 / (1 + exp(x1-x2)) +double exp_n2(double x1, double x2) +{ + double p1 = -700., p2 = -37., p3 = -0.8e-8, p4 = 0.8e-8, p5 = 37., p6 = 700.; + double xt = x1 - x2; + if (xt < p1+1.e-200) + return 1.; + else if (xt > p1 && xt < p2 + 1.e-200) + return ( 1. - exp(xt) ); + else if (xt > p2 && xt < p3 + 1.e-200) + return ( 1. / (1. + exp(xt)) ); + else if (xt > p3 && xt < p4) + return ( 1. / (2. + xt) ); + else if (xt > p4 - 1.e-200 && xt < p5) + return ( exp(-xt) / (1. + exp(-xt)) ); + else if (xt > p5 - 1.e-200 && xt < p6) + return ( exp(-xt) ); + else if (xt > p6 - 1.e-200) + return 0.; +} + +void gauleg(double x1, double x2, double x[], double w[], int n) +{ + int m,j,i; + double z1, z, xm, xl, pp, p3, p2, p1; + m=(n+1)/2; + xm=0.5*(x2+x1); + xl=0.5*(x2-x1); + for (i=1;i<=m;i++) { + z=cos(3.141592654*(i-0.25)/(n+0.5)); + do { + p1=1.0; + p2=0.0; + for (j=1;j<=n;j++) { + p3=p2; + p2=p1; + p1=((2.0*j-1.0)*z*p2-(j-1.0)*p3)/j; + } + pp=n*(z*p1-p2)/(z*z-1.0); + z1=z; + z=z1-p1/pp; + } while (fabs(z-z1) > EPS2); + x[i]=xm-xl*z; + x[n+1-i]=xm+xl*z; + w[i]=2.0*xl/((1.0-z*z)*pp*pp); + w[n+1-i]=w[i]; + } +} + +double GaussianQuad_N(double func(const double), const double a2, const double b2, int NptGQ) +{ + double s=0.0; + double x[NptGQ], w[NptGQ]; + int j; +// double dh=(b2-a2)/double(divs); + gauleg(a2, b2, x, w, NptGQ); + for (j=1; j<=NptGQ; j++) { + s += w[j]*func(x[j]); + } +/* + for (i=1; i<=divs; i++) + { + a0 = a2 + (i-1)*dh; + b0 = a0 + dh; + gauleg(a0, b0, x, w, NptGQ); + for (j=1; j<=NptGQ; j++) + { + s += w[j]*func(x[j]); + } + } +*/ + return s; +} + +double swit_(double wvnmb) +{ + return pow( (5.55243*(exp_n(-0.3*wvnmb/15.762) - exp_n(-0.6*wvnmb/15.762)))*wvnmb, 0.5) + / 1034.66 * pow(sin(wvnmb/65.), 2.); +} + +uint32_t sw_(int nnounce, int divs) +{ + double wmax = ((sqrt((double)(nnounce))*(1.+EPS1))/450+100); + return ((uint32_t)(GaussianQuad_N(swit_, 0., wmax, divs)*(1.+EPS1)*1.e6)); +} \ No newline at end of file diff --git a/stratum/algos/a5amath.h b/stratum/algos/a5amath.h new file mode 100644 index 0000000..d2f4ca8 --- /dev/null +++ b/stratum/algos/a5amath.h @@ -0,0 +1,16 @@ +// Copyright (c) 2014 The a5a developers +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. +#ifndef a5a_MATH_H +#define a5a_MATH_H + +double exp_n(double xt); +double exp_n2(double x1, double x2); +void gauleg(double x1, double x2, double x[], double w[], int n); +double GaussianQuad_N(double func(const double), const double a2, const double b2, int NptGQ); +double swit_(double wvnmb); +uint32_t sw_(int nnounce, int divs); + + + +#endif \ No newline at end of file diff --git a/stratum/algos/makefile b/stratum/algos/makefile index 9c92a9f..b684b87 100644 --- a/stratum/algos/makefile +++ b/stratum/algos/makefile @@ -18,6 +18,7 @@ SOURCES=lyra2re.c lyra2v2.c Lyra2.c lyra2z.c Lyra2z.c Sponge.c \ yescrypt.c yescrypt-opt.c sha256_Y.c lbry.c \ m7m.c magimath.cpp velvet.c \ argon2a.c ar2/blake2b.c ar2/argon2.c ar2/ref.c ar2/cores.c ar2/ar2-scrypt-jane.c \ + a5a.c a5amath.c \ hive.c pomelo.c \ phi.c polytimos.c skunk.c sib.c veltor.c gost.c x11evo.c diff --git a/stratum/config.sample/a5a.conf b/stratum/config.sample/a5a.conf new file mode 100644 index 0000000..25bdc96 --- /dev/null +++ b/stratum/config.sample/a5a.conf @@ -0,0 +1,15 @@ +[TCP] +server = yaamp.com +port = 8633 +password = tu8tu5 + +[SQL] +host = yaampdb +database = yaamp +username = root +password = patofpaq + +[STRATUM] +algo = a5a +difficulty = 8 +max_ttf = 4000000 diff --git a/stratum/stratum.cpp b/stratum/stratum.cpp index b5c16af..b120021 100644 --- a/stratum/stratum.cpp +++ b/stratum/stratum.cpp @@ -142,6 +142,7 @@ YAAMP_ALGO g_algos[] = {"myr-gr", groestlmyriad_hash, 1, 0, 0}, /* groestl + sha 64 */ {"skein", skein_hash, 1, 0, 0}, {"tribus", tribus_hash, 1, 0, 0}, + {"a5a", a5a_hash, 0x10000, 0, 0}, {"keccak", keccak256_hash, 0x80, 0, sha256_hash_hex }, {"phi", phi_hash, 1, 0, 0}, {"polytimos", polytimos_hash, 1, 0, 0}, diff --git a/stratum/stratum.h b/stratum/stratum.h index 773da2e..1323ab6 100644 --- a/stratum/stratum.h +++ b/stratum/stratum.h @@ -135,6 +135,7 @@ void scrypt_N_R_1_256(const char* input, char* output, uint32_t N, uint32_t R, u void sha256_hash_hex(const char *input, char *output, unsigned int len); void sha256_double_hash_hex(const char *input, char *output, unsigned int len); +#include "algos/a5a.h" #include "algos/c11.h" #include "algos/x11.h" #include "algos/x11evo.h" diff --git a/web/yaamp/core/functions/yaamp.php b/web/yaamp/core/functions/yaamp.php index 0a05a19..0e8b90a 100755 --- a/web/yaamp/core/functions/yaamp.php +++ b/web/yaamp/core/functions/yaamp.php @@ -51,6 +51,7 @@ function yaamp_get_algos() 'skunk', 'timetravel', 'tribus', + 'a5a', 'vanilla', 'veltor', 'velvet', @@ -169,6 +170,7 @@ function getAlgoColors($algo) 'bitcore' => '#f790c0', 'skunk' => '#dedefe', 'tribus' => '#c0d0d0', + 'a5a' => '#f0f0f0', 'vanilla' => '#f0f0f0', 'velvet' => '#aac0cc', 'whirlpool' => '#d0e0e0', @@ -245,6 +247,7 @@ function getAlgoPort($algo) 'polytimos' => 8463, 'skunk' => 8433, 'tribus' => 8533, + 'a5a' => 8633, ); global $configCustomPorts; From 4120ee7d62c0214ed455c821738bec243118a7d5 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Mon, 26 Feb 2018 11:46:44 +0100 Subject: [PATCH 042/195] stratum: auto detect 'old' masternodes rpc (#236) --- stratum/coinbase.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/stratum/coinbase.cpp b/stratum/coinbase.cpp index bbe7df2..a604f15 100644 --- a/stratum/coinbase.cpp +++ b/stratum/coinbase.cpp @@ -224,6 +224,11 @@ void coinbase_create(YAAMP_COIND *coind, YAAMP_JOB_TEMPLATE *templ, json_value * bool superblocks_enabled = json_get_bool(json_result, "superblocks_enabled"); json_value* superblock = json_get_array(json_result, "superblock"); json_value* masternode = json_get_object(json_result, "masternode"); + if(!masternode && json_get_bool(json_result, "masternode_payments")) { + coind->oldmasternodes = true; + debuglog("%s is using old masternodes rpc keys\n", coind->symbol); + return; + } if(superblocks_enabled && superblock) { for(int i = 0; i < superblock->u.array.length; i++) { const char *payee = json_get_string(superblock->u.array.values[i], "payee"); From 0287896b0afe22a479d56a29fc16ba2fc590b748 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Wed, 28 Feb 2018 11:08:23 +0100 Subject: [PATCH 043/195] stratum: add missing keccakc variant --- stratum/config.sample/keccakc.conf | 16 ++++++++++++++++ stratum/stratum.cpp | 7 ++++--- web/yaamp/core/functions/yaamp.php | 3 +++ 3 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 stratum/config.sample/keccakc.conf diff --git a/stratum/config.sample/keccakc.conf b/stratum/config.sample/keccakc.conf new file mode 100644 index 0000000..0be446a --- /dev/null +++ b/stratum/config.sample/keccakc.conf @@ -0,0 +1,16 @@ +[TCP] +server = yaamp.com +port = 5134 +password = tu8tu5 + +[SQL] +host = yaampdb +database = yaamp +username = root +password = patofpaq + +[STRATUM] +algo = keccakc +difficulty = 2 +max_ttf = 4000000 + diff --git a/stratum/stratum.cpp b/stratum/stratum.cpp index b120021..37f9bb4 100644 --- a/stratum/stratum.cpp +++ b/stratum/stratum.cpp @@ -142,8 +142,8 @@ YAAMP_ALGO g_algos[] = {"myr-gr", groestlmyriad_hash, 1, 0, 0}, /* groestl + sha 64 */ {"skein", skein_hash, 1, 0, 0}, {"tribus", tribus_hash, 1, 0, 0}, - {"a5a", a5a_hash, 0x10000, 0, 0}, {"keccak", keccak256_hash, 0x80, 0, sha256_hash_hex }, + {"keccakc", keccak256_hash, 0x100, 0, 0}, {"phi", phi_hash, 1, 0, 0}, {"polytimos", polytimos_hash, 1, 0, 0}, {"skunk", skunk_hash, 1, 0, 0}, @@ -157,6 +157,7 @@ YAAMP_ALGO g_algos[] = {"yescryptR16", yescryptR16_hash, 0x10000, 0, 0 }, {"zr5", zr5_hash, 1, 0, 0}, + {"a5a", a5a_hash, 0x10000, 0, 0}, {"hive", hive_hash, 0x10000, 0, 0}, {"m7m", m7m_hash, 0x10000, 0, 0}, {"veltor", veltor_hash, 1, 0, 0}, @@ -410,8 +411,8 @@ void *stratum_thread(void *p) stratumlog("%s socket accept() error %d\n", g_stratum_algo, error); failcount++; usleep(50000); - if (error == 24 && failcount > 16) { - g_exiting = true; + if (error == 24 && failcount > 5) { + g_exiting = true; // happen when max open files is reached (see ulimit) stratumlogdate("%s too much socket failure, exiting...\n", g_stratum_algo); exit(error); } diff --git a/web/yaamp/core/functions/yaamp.php b/web/yaamp/core/functions/yaamp.php index 0e8b90a..98e63cd 100755 --- a/web/yaamp/core/functions/yaamp.php +++ b/web/yaamp/core/functions/yaamp.php @@ -18,6 +18,7 @@ function yaamp_get_algos() 'deep', 'hmq1725', 'keccak', + 'keccakc', 'jha', 'hsr', 'lbry', @@ -151,6 +152,7 @@ function getAlgoColors($algo) 'hmq1725' => '#ffa0a0', 'hsr' => '#aa70ff', 'keccak' => '#c0f0c0', + 'keccakc' => '#c0f0c0', 'lbry' => '#b0d0e0', 'luffa' => '#a0c0c0', 'm7m' => '#d0a0a0', @@ -223,6 +225,7 @@ function getAlgoPort($algo) 'skein' => 4933, 'sib' => 5033, 'keccak' => 5133, + 'keccakc' => 5134, 'skein2' => 5233, //'groestl' => 5333, 'dmd-gr' => 5333, From 72b738da0d9fb025f6ebb675a9c126a68a469e9b Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Wed, 28 Feb 2018 15:25:06 +0100 Subject: [PATCH 044/195] explorer: truncate huge txs json for site reliability + display x16r hashorder field --- web/yaamp/modules/explorer/block.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/web/yaamp/modules/explorer/block.php b/web/yaamp/modules/explorer/block.php index 4738b4d..e1521b1 100644 --- a/web/yaamp/modules/explorer/block.php +++ b/web/yaamp/modules/explorer/block.php @@ -144,6 +144,12 @@ echo 'Size:'.$block['size'].' bytes'; if(isset($block['flags'])) echo 'Flags:'.$block['flags'].''; +if(isset($block['previousblockhash']) && $coin->algo == 'x16r') { + echo 'Hash order:'. + substr($block['previousblockhash'], -16). + ''; +} + if(isset($block['previousblockhash'])) echo 'Previous Hash:'. $coin->createExplorerLink($block['previousblockhash'], array('hash'=>$block['previousblockhash'])). @@ -219,6 +225,9 @@ foreach($block['tx'] as $txhash) echo ""; echo ""; + $nvout = count($tx['vout']);; + if ($nvout > 500) echo "Too much addresses to display ($nvout)"; + else foreach($tx['vout'] as $vout) { $value = $vout['value']; @@ -235,7 +244,7 @@ foreach($block['tx'] as $txhash) echo '
'; unset($tx['hex']); - echo colorizeJson(json_encode($tx, 128)); + echo ($nvout > 500) ? 'truncated' : colorizeJson(json_encode($tx, 128)); echo '
'; echo ""; From 2dccc579cff33db4033ba1b67cd106c56a8f10eb Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Wed, 28 Feb 2018 20:42:03 +0100 Subject: [PATCH 045/195] markets: handle cryptobridge ticker --- web/yaamp/core/backend/markets.php | 41 ++++++++++++++++++++++++ web/yaamp/core/backend/rawcoins.php | 17 +++++++++- web/yaamp/core/exchange/cryptobridge.php | 20 ++++++++++++ web/yaamp/core/exchange/exchange.php | 9 ++++-- web/yaamp/core/trading/trading.php | 4 +++ 5 files changed, 87 insertions(+), 4 deletions(-) create mode 100644 web/yaamp/core/exchange/cryptobridge.php diff --git a/web/yaamp/core/backend/markets.php b/web/yaamp/core/backend/markets.php index f69fe10..2db5e05 100644 --- a/web/yaamp/core/backend/markets.php +++ b/web/yaamp/core/backend/markets.php @@ -13,6 +13,7 @@ function BackendPricesUpdate() updateBittrexMarkets(); updatePoloniexMarkets(); updateBleutradeMarkets(); + updateCryptoBridgeMarkets(); updateKrakenMarkets(); updateKuCoinMarkets(); updateCCexMarkets(); @@ -283,6 +284,46 @@ function updateBleutradeMarkets() ///////////////////////////////////////////////////////////////////////////////////////////// +function updateCryptoBridgeMarkets($force = false) +{ + $exchange = 'cryptobridge'; + + $result = cryptobridge_api_query('ticker'); + if(!is_array($result)) return; + + foreach($result as $ticker) + { + if (is_null(objSafeVal($ticker,'id'))) continue; + $pairs = explode('_', $ticker->id); + $symbol = reset($pairs); $base = end($pairs); + if($symbol == 'BTC' || $base != 'BTC') continue; + + if (market_get($exchange, $symbol, "disabled")) { + $market->disabled = 1; + $market->message = 'disabled from settings'; + } + + $coin = getdbosql('db_coins', "symbol='{$symbol}'"); + if(!$coin) continue; + if(!$coin->installed && !$coin->watch) continue; + + $market = getdbosql('db_markets', "coinid={$coin->id} and name='{$exchange}'"); + if(!$market) continue; + + $price2 = ($ticker->bid + $ticker->ask)/2; + $market->price2 = AverageIncrement($market->price2, $price2); + $market->price = AverageIncrement($market->price, $ticker->bid); + $market->pricetime = time(); + $market->priority = -1; + $market->txfee = 0.2; // trade pct + $market->save(); + + //debuglog("$exchange: update $symbol: {$market->price} {$market->price2}"); + } +} + +///////////////////////////////////////////////////////////////////////////////////////////// + function updateKrakenMarkets($force = false) { $exchange = 'kraken'; diff --git a/web/yaamp/core/backend/rawcoins.php b/web/yaamp/core/backend/rawcoins.php index 670af51..067d0de 100644 --- a/web/yaamp/core/backend/rawcoins.php +++ b/web/yaamp/core/backend/rawcoins.php @@ -152,6 +152,21 @@ function updateRawcoins() } } + if (!exchange_get('cryptobridge', 'disabled')) { + $list = cryptobridge_api_query('ticker'); + if(is_array($list) && !empty($list)) + { + dborun("UPDATE markets SET deleted=true WHERE name='cryptobridge'"); + foreach($list as $ticker) { + $e = explode('_', $ticker->id); + if (strtoupper($e[1]) !== 'BTC') + continue; + $symbol = strtoupper($e[0]); + updateRawCoin('cryptobridge', $symbol); + } + } + } + if (!exchange_get('hitbtc', 'disabled')) { $list = hitbtc_api_query('symbols'); if(is_object($list) && isset($list->symbols) && is_array($list->symbols)) @@ -375,7 +390,7 @@ function updateRawCoin($marketname, $symbol, $name='unknown') } } - if (in_array($marketname, array('nova','askcoin','binance','coinexchange','coinsmarkets','hitbtc'))) { + if (in_array($marketname, array('nova','askcoin','binance','coinexchange','coinsmarkets','cryptobridge','hitbtc'))) { // don't polute too much the db with new coins, its better from exchanges with labels return; } diff --git a/web/yaamp/core/exchange/cryptobridge.php b/web/yaamp/core/exchange/cryptobridge.php new file mode 100644 index 0000000..3251768 --- /dev/null +++ b/web/yaamp/core/exchange/cryptobridge.php @@ -0,0 +1,20 @@ + Date: Thu, 1 Mar 2018 15:22:45 +0100 Subject: [PATCH 046/195] cli: allow to search users by ip --- web/yaamp/commands/UserCommand.php | 40 ++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/web/yaamp/commands/UserCommand.php b/web/yaamp/commands/UserCommand.php index 4d3e9d5..eb11139 100644 --- a/web/yaamp/commands/UserCommand.php +++ b/web/yaamp/commands/UserCommand.php @@ -26,6 +26,7 @@ class UserCommand extends CConsoleCommand echo "YiiMP user command(s)\n"; echo "Usage: yiimp user delete \n"; echo " yiimp user swap
- assign symbol\n"; + echo " yiimp user search \n"; echo " yiimp user purge [days] (default 180)\n"; return 1; @@ -48,12 +49,19 @@ class UserCommand extends CConsoleCommand echo "$nb user(s) deleted\n"; return 0; + } else if ($args[0] == 'search') { + if (!isset($args[1])) + die("usage: yiimp user search \n"); + $addr = $args[1]; + $this->searchUserByIP($addr); + } else if ($args[0] == 'swap') { if (!isset($args[2])) - die("usage: yiimp user swap
- assign symbol"); + die("usage: yiimp user swap
[force] - assign symbol\n"); $addr = $args[1]; $symbol = $args[2]; - $this->swapUserCoin($addr, $symbol); + $force = arraySafeVal($args, 3, false); + $this->swapUserCoin($addr, $symbol, $force); return 0; } } @@ -124,6 +132,34 @@ class UserCommand extends CConsoleCommand return $nbDeleted; } + /** + * Search users by worker ip + */ + public function searchUserByIP($ip) + { + $workers = new db_workers; + $rows = $workers->findAll(array( + 'condition'=>'ip LIKE :ip', + 'params'=>array(':ip'=>"%$ip%"), + 'limit'=>25, + 'order'=>'id DESC', + )); + + if (empty($rows)) { + echo "no user(s) found with this ip\n"; + return 0; + } + + foreach ($rows as $worker) { + $user = getdbo('db_accounts', $worker->userid); + if (!$user) continue; + $time = strftime("%Y-%m-%d %H:%M:%S", $worker->time); + echo "$time\t{$user->username}\t{$worker->ip}\t{$worker->algo}\n"; + } + + return 0; + } + /** * Manually assign the right currency symbol to an user (for yiimp mode without exchange) */ From befb105e5dc9034ab666b6cc6b6118d83c3e87c4 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Thu, 1 Mar 2018 23:28:06 +0100 Subject: [PATCH 047/195] stratum: fill fds and server name/url in stratums table meant to detect socket leaks before its too late... --- stratum/db.cpp | 13 +++++++------ stratum/stratum.cpp | 2 -- stratum/stratum.h | 1 + stratum/util.cpp | 12 ++++++++++++ stratum/util.h | 2 ++ 5 files changed, 22 insertions(+), 8 deletions(-) diff --git a/stratum/db.cpp b/stratum/db.cpp index e838267..1cdb34e 100644 --- a/stratum/db.cpp +++ b/stratum/db.cpp @@ -87,17 +87,17 @@ void db_register_stratum(YAAMP_DB *db) int t = time(NULL); if(!db) return; - db_query(db, "INSERT INTO stratums (pid, time, started, algo, port) VALUES (%d, %d, %d, '%s', %d) " - " ON DUPLICATE KEY UPDATE time=%d, algo='%s', port=%d", - pid, t, t, g_stratum_algo, g_tcp_port, - t, g_stratum_algo, g_tcp_port + db_query(db, "INSERT INTO stratums (pid, time, started, algo, url, port) VALUES (%d,%d,%d,'%s','%s',%d) " + " ON DUPLICATE KEY UPDATE time=%d, algo='%s', url='%s', port=%d", + pid, t, t, g_stratum_algo, g_tcp_server, g_tcp_port, + t, g_stratum_algo, g_tcp_server, g_tcp_port ); } void db_update_algos(YAAMP_DB *db) { int pid = getpid(); - //int fds = 0; // todo, sample: ls -l /proc/$PID/fd | grep socket | grep -c . + int fds = opened_files(); if(!db) return; if(g_current_algo->overflow) @@ -117,7 +117,8 @@ void db_update_algos(YAAMP_DB *db) } } - db_query(db, "UPDATE stratums SET workers=%d, symbol=%s WHERE pid=%d", g_list_client.count, symbol, pid); + db_query(db, "UPDATE stratums SET workers=%d, fds=%d, symbol=%s WHERE pid=%d", + g_list_client.count, fds, symbol, pid); /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/stratum/stratum.cpp b/stratum/stratum.cpp index 37f9bb4..2be15b2 100644 --- a/stratum/stratum.cpp +++ b/stratum/stratum.cpp @@ -188,8 +188,6 @@ YAAMP_ALGO *stratum_find_algo(const char *name) //////////////////////////////////////////////////////////////////////////////////////// -#include - int main(int argc, char **argv) { if(argc < 2) diff --git a/stratum/stratum.h b/stratum/stratum.h index 1323ab6..81c3d52 100644 --- a/stratum/stratum.h +++ b/stratum/stratum.h @@ -19,6 +19,7 @@ #include #include #include +#include #include #include diff --git a/stratum/util.cpp b/stratum/util.cpp index a8b7237..0dda75f 100644 --- a/stratum/util.cpp +++ b/stratum/util.cpp @@ -674,6 +674,18 @@ long long current_timestamp_dms() // allow 0.1 ms time return dms; } +int opened_files() +{ + int fds = 0; + DIR *d = opendir("/proc/self/fd"); + if (d) { + struct dirent *ent; + while (readdir(d)) fds++; + closedir(d); + } + return fds; +} + void string_lower(char *s) { for(int i = 0; s[i]; i++) diff --git a/stratum/util.h b/stratum/util.h index 1a39be2..a10d20a 100644 --- a/stratum/util.h +++ b/stratum/util.h @@ -102,6 +102,8 @@ uint64_t get_hash_difficulty(unsigned char *input); long long current_timestamp(); long long current_timestamp_dms(); +int opened_files(); + void string_lower(char *s); void string_upper(char *s); From c49c8b30f2b123bc7c4346ab9628d1b649c52a70 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Fri, 2 Mar 2018 13:16:06 +0100 Subject: [PATCH 048/195] stratum: fix the major socket leak on bad auth --- stratum/client.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/stratum/client.cpp b/stratum/client.cpp index e3f679b..f51f9d0 100644 --- a/stratum/client.cpp +++ b/stratum/client.cpp @@ -619,9 +619,7 @@ void *client_thread(void *p) else if(!strcmp(method, "getwork")) { clientlog(client, "using getwork"); // client using http:// url - break; } - else { b = client_send_error(client, 20, "Not supported"); @@ -657,6 +655,9 @@ void *client_thread(void *p) db_clear_worker(g_db, client); CommonUnlock(&g_db_mutex); } + } else { + // only clients sockets in g_list_client are purged (if marked deleted) + socket_close(client->sock); } object_delete(client); From 343ec492c8700e04a76bca4f6d39c2ef3593d6ab Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Fri, 2 Mar 2018 13:34:24 +0100 Subject: [PATCH 049/195] stratum: min diff and anti-flood adjustments --- stratum/client_difficulty.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/stratum/client_difficulty.cpp b/stratum/client_difficulty.cpp index 59ee751..2ef8948 100644 --- a/stratum/client_difficulty.cpp +++ b/stratum/client_difficulty.cpp @@ -3,7 +3,9 @@ double client_normalize_difficulty(double difficulty) { - if(difficulty <= 0.001) difficulty = 0.001; + double min_stratum_diff = g_stratum_difficulty * 0.5; + if(difficulty < min_stratum_diff) + difficulty = min_stratum_diff; else if(difficulty < 1) difficulty = floor(difficulty*1000/2)/1000*2; else if(difficulty > 1) difficulty = floor(difficulty/2)*2; @@ -48,13 +50,12 @@ void client_change_difficulty(YAAMP_CLIENT *client, double difficulty) void client_adjust_difficulty(YAAMP_CLIENT *client) { - if(client->difficulty_remote) - { + if(client->difficulty_remote) { client_change_difficulty(client, client->difficulty_remote); return; } - if(client->shares_per_minute > 600) + if(client->shares_per_minute > 100) client_change_difficulty(client, client->difficulty_actual*4); else if(client->difficulty_fixed) @@ -79,6 +80,7 @@ int client_send_difficulty(YAAMP_CLIENT *client, double difficulty) client_call(client, "mining.set_difficulty", "[%.0f]", difficulty); else client_call(client, "mining.set_difficulty", "[%.3f]", difficulty); + return 0; } void client_initialize_difficulty(YAAMP_CLIENT *client) From 010fd144935f1a2e04c95329a89bca272942fb7f Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Fri, 2 Mar 2018 15:08:55 +0100 Subject: [PATCH 050/195] stratum: ignore possible dup on new user This race case was causing a stratum exit and should not --- stratum/db.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/stratum/db.cpp b/stratum/db.cpp index 1cdb34e..fbbc2b2 100644 --- a/stratum/db.cpp +++ b/stratum/db.cpp @@ -1,5 +1,6 @@ #include "stratum.h" +#include #include void db_reconnect(YAAMP_DB *db) @@ -70,6 +71,7 @@ void db_query(YAAMP_DB *db, const char *format, ...) res = mysql_errno(&db->mysql); stratumlog("SQL ERROR: %d, %s\n", res, mysql_error(&db->mysql)); + if(res == ER_DUP_ENTRY) break; // rarely seen on new user creation if(res != CR_SERVER_GONE_ERROR && res != CR_SERVER_LOST) exit(1); usleep(100*YAAMP_MS); From 8c85b95220b50eab9b56fded3ab5ca48febd66a6 Mon Sep 17 00:00:00 2001 From: "protopool.net" Date: Tue, 6 Mar 2018 14:58:37 +0600 Subject: [PATCH 051/195] stratum: debuglog on/off without code recompile + drop log CFLAGS comments in Makefile and old defines comments --- stratum/Makefile | 6 --- stratum/client.cpp | 44 +++++++++++----------- stratum/client_submit.cpp | 63 ++++++++++++++++---------------- stratum/config.sample/skein.conf | 8 ++++ stratum/list.cpp | 52 +++++++++++++------------- stratum/remote.cpp | 22 +++++------ stratum/rpc.cpp | 24 ++++++------ stratum/socket.cpp | 14 +++---- stratum/stratum.cpp | 14 +++++++ stratum/stratum.h | 7 ++++ 10 files changed, 135 insertions(+), 119 deletions(-) diff --git a/stratum/Makefile b/stratum/Makefile index 8bf6a9f..3bf978b 100755 --- a/stratum/Makefile +++ b/stratum/Makefile @@ -8,12 +8,6 @@ SQLFLAGS= `mysql_config --cflags --libs` # if you use the auto exchange feature... CFLAGS += -DNO_EXCHANGE -#CFLAGS += -DHASH_DEBUGLOG_ -#CFLAGS += -DRPC_DEBUGLOG_ -#CFLAGS += -DREMOTE_DEBUGLOG_ -#CFLAGS += -DSOCKET_DEBUGLOG_ -#CFLAGS += -DCLIENT_DEBUGLOG_ - #CFLAGS=-c -O2 -I /usr/include/mysql LDFLAGS=-O2 `mysql_config --libs` diff --git a/stratum/client.cpp b/stratum/client.cpp index f51f9d0..844d23d 100644 --- a/stratum/client.cpp +++ b/stratum/client.cpp @@ -1,8 +1,6 @@ #include "stratum.h" -//#define CLIENT_DEBUGLOG_ - bool client_suggest_difficulty(YAAMP_CLIENT *client, json_value *json_params) { if(json_params->u.array.length>0) @@ -88,9 +86,9 @@ bool client_subscribe(YAAMP_CLIENT *client, json_value *json_params) memcpy(client->job_history, client1->job_history, sizeof(client->job_history)); client1->lock_count = 0; -#ifdef CLIENT_DEBUGLOG_ - debuglog("reconnecting client locked to %x\n", client->jobid_next); -#endif + if (g_debuglog_client) { + debuglog("reconnecting client locked to %x\n", client->jobid_next); + } } else @@ -106,9 +104,9 @@ bool client_subscribe(YAAMP_CLIENT *client, json_value *json_params) memcpy(client->job_history, client1->job_history, sizeof(client->job_history)); client1->lock_count = 0; -#ifdef CLIENT_DEBUGLOG_ - debuglog("reconnecting2 client\n"); -#endif + if (g_debuglog_client) { + debuglog("reconnecting2 client\n"); + } } } } @@ -116,9 +114,9 @@ bool client_subscribe(YAAMP_CLIENT *client, json_value *json_params) strcpy(client->extranonce1_last, client->extranonce1); client->extranonce2size_last = client->extranonce2size; -#ifdef CLIENT_DEBUGLOG_ - debuglog("new client with nonce %s\n", client->extranonce1); -#endif + if (g_debuglog_client) { + debuglog("new client with nonce %s\n", client->extranonce1); + } client_send_result(client, "[[[\"mining.set_difficulty\",\"%.3g\"],[\"mining.notify\",\"%s\"]],\"%s\",%d]", client->difficulty_actual, client->notify_id, client->extranonce1, client->extranonce2size); @@ -236,9 +234,9 @@ bool client_authorize(YAAMP_CLIENT *client, json_value *json_params) client_initialize_difficulty(client); -#ifdef CLIENT_DEBUGLOG_ - debuglog("new client %s, %s, %s\n", client->username, client->password, client->version); -#endif + if (g_debuglog_client) { + debuglog("new client %s, %s, %s\n", client->username, client->password, client->version); + } if(!client->userid || !client->workerid) { @@ -305,9 +303,9 @@ bool client_update_block(YAAMP_CLIENT *client, json_value *json_params) const char* hash = json_params->u.array.values[2]->u.string.ptr; -#ifdef CLIENT_DEBUGLOG_ - debuglog("notify: new %s block %s\n", coind->symbol, hash); -#endif + if (g_debuglog_client) { + debuglog("notify: new %s block %s\n", coind->symbol, hash); + } coind->newblock = true; coind->notreportingcounter = 0; @@ -578,9 +576,9 @@ void *client_thread(void *p) break; } -#ifdef CLIENT_DEBUGLOG_ - debuglog("client %s %d %s\n", method, client->id_int, client->id_str? client->id_str: "null"); -#endif + if (g_debuglog_client) { + debuglog("client %s %d %s\n", method, client->id_int, client->id_str? client->id_str: "null"); + } bool b = false; if(!strcmp(method, "mining.subscribe")) @@ -634,9 +632,9 @@ void *client_thread(void *p) // source_close(client->source); -#ifdef CLIENT_DEBUGLOG_ - debuglog("client terminate\n"); -#endif + if (g_debuglog_client) { + debuglog("client terminate\n"); + } if(!client || client->deleted) { pthread_exit(NULL); } diff --git a/stratum/client_submit.cpp b/stratum/client_submit.cpp index 41cbf5b..e1021f9 100644 --- a/stratum/client_submit.cpp +++ b/stratum/client_submit.cpp @@ -4,7 +4,6 @@ uint64_t lyra2z_height = 0; //#define MERKLE_DEBUGLOG -//#define HASH_DEBUGLOG_ //#define DONTSUBMIT void build_submit_values(YAAMP_JOB_VALUES *submitvalues, YAAMP_JOB_TEMPLATE *templ, @@ -285,20 +284,20 @@ static void client_do_submit(YAAMP_CLIENT *client, YAAMP_JOB *job, YAAMP_JOB_VAL block_confirm(coind->id, submitvalues->hash_be); } -#ifdef HASH_DEBUGLOG_ - debuglog("--------------------------------------------------------------\n"); - debuglog("hash1 %s\n", hash1); - debuglog("hash2 %s\n", submitvalues->hash_be); -#endif + if (g_debuglog_hash) { + debuglog("--------------------------------------------------------------\n"); + debuglog("hash1 %s\n", hash1); + debuglog("hash2 %s\n", submitvalues->hash_be); + } } else { debuglog("*** REJECTED :( %s block %d %d txs\n", coind->name, templ->height, templ->txcount); rejectlog("REJECTED %s block %d\n", coind->symbol, templ->height); -#ifdef HASH_DEBUGLOG_ - //debuglog("block %s\n", block_hex); - debuglog("--------------------------------------------------------------\n"); -#endif + if (g_debuglog_hash) { + //debuglog("block %s\n", block_hex); + debuglog("--------------------------------------------------------------\n"); + } } } @@ -324,9 +323,9 @@ void client_submit_error(YAAMP_CLIENT *client, YAAMP_JOB *job, int id, const cha share_add(client, job, false, extranonce2, ntime, nonce, 0, id); client->submit_bad++; -#ifdef HASH_DEBUGLOG_ - dump_submit_debug(message, client, job, extranonce2, ntime, nonce); -#endif + if (g_debuglog_hash) { + dump_submit_debug(message, client, job, extranonce2, ntime, nonce); + } } object_unlock(job); @@ -377,9 +376,9 @@ bool client_submit(YAAMP_CLIENT *client, json_value *json_params) if (json_params->u.array.length == 6) strncpy(vote, json_params->u.array.values[5]->u.string.ptr, 7); -#ifdef HASH_DEBUGLOG_ - debuglog("submit %s (uid %d) %d, %s, %s, %s\n", client->sock->ip, client->userid, jobid, extranonce2, ntime, nonce); -#endif + if (g_debuglog_hash) { + debuglog("submit %s (uid %d) %d, %s, %s, %s\n", client->sock->ip, client->userid, jobid, extranonce2, ntime, nonce); + } string_lower(extranonce2); string_lower(ntime); @@ -480,11 +479,11 @@ bool client_submit(YAAMP_CLIENT *client, json_value *json_params) // minimum hash diff begins with 0000, for all... uint8_t pfx = submitvalues.hash_bin[30] | submitvalues.hash_bin[31]; if(pfx) { -#ifdef HASH_DEBUGLOG_ - debuglog("Possible %s error, hash starts with %02x%02x%02x%02x\n", g_current_algo->name, - (int) submitvalues.hash_bin[31], (int) submitvalues.hash_bin[30], - (int) submitvalues.hash_bin[29], (int) submitvalues.hash_bin[28]); -#endif + if (g_debuglog_hash) { + debuglog("Possible %s error, hash starts with %02x%02x%02x%02x\n", g_current_algo->name, + (int) submitvalues.hash_bin[31], (int) submitvalues.hash_bin[30], + (int) submitvalues.hash_bin[29], (int) submitvalues.hash_bin[28]); + } client_submit_error(client, job, 25, "Invalid share", extranonce2, ntime, nonce); return true; } @@ -494,11 +493,11 @@ bool client_submit(YAAMP_CLIENT *client, json_value *json_params) uint64_t coin_target = decode_compact(templ->nbits); if (templ->nbits && !coin_target) coin_target = 0xFFFF000000000000ULL; -#ifdef HASH_DEBUGLOG_ - debuglog("%016llx actual\n", hash_int); - debuglog("%016llx target\n", user_target); - debuglog("%016llx coin\n", coin_target); -#endif + if (g_debuglog_hash) { + debuglog("%016llx actual\n", hash_int); + debuglog("%016llx target\n", user_target); + debuglog("%016llx coin\n", coin_target); + } if(hash_int > user_target && hash_int > coin_target) { client_submit_error(client, job, 26, "Low difficulty share", extranonce2, ntime, nonce); @@ -524,12 +523,12 @@ bool client_submit(YAAMP_CLIENT *client, json_value *json_params) // share_diff = share_diff / g_current_algo->diff_multiplier; // } -#ifndef HASH_DEBUGLOG_ - // only log a few... - if (share_diff > (client->difficulty_actual * 16)) - debuglog("submit %s (uid %d) %d, %s, %s, %s, %.3f/%.3f\n", client->sock->ip, client->userid, - jobid, extranonce2, ntime, nonce, share_diff, client->difficulty_actual); -#endif + if (g_debuglog_hash) { + // only log a few... + if (share_diff > (client->difficulty_actual * 16)) + debuglog("submit %s (uid %d) %d, %s, %s, %s, %.3f/%.3f\n", client->sock->ip, client->userid, + jobid, extranonce2, ntime, nonce, share_diff, client->difficulty_actual); + } share_add(client, job, true, extranonce2, ntime, nonce, share_diff, 0); object_unlock(job); diff --git a/stratum/config.sample/skein.conf b/stratum/config.sample/skein.conf index f4957e5..b6d7536 100644 --- a/stratum/config.sample/skein.conf +++ b/stratum/config.sample/skein.conf @@ -14,3 +14,11 @@ algo = skein difficulty = 0.1 max_ttf = 200000000000000 +[DEBUGLOG] +client = 0 +hash = 0 +socket = 0 +rpc = 0 +list = 0 +remote = 0 + diff --git a/stratum/list.cpp b/stratum/list.cpp index 2942f43..ea18d7f 100644 --- a/stratum/list.cpp +++ b/stratum/list.cpp @@ -5,21 +5,21 @@ void CommonLock(pthread_mutex_t *mutex) { -#ifdef _LIST_DEBUG_ - int i=0; - for(; i<10; i++) - { - int res = pthread_mutex_trylock(mutex); - if(res == 0) break; + if (g_debuglog_list) { + int i=0; + for(; i<10; i++) + { + int res = pthread_mutex_trylock(mutex); + if(res == 0) break; - usleep(100*YAAMP_MS); + usleep(100*YAAMP_MS); + } + + if(i == 10) + debuglog("failed mutex2 %x <<----------------\n", mutex); + } else { + pthread_mutex_lock(mutex); } - - if(i == 10) - debuglog("failed mutex2 %x <<----------------\n", mutex); -#else - pthread_mutex_lock(mutex); -#endif } void CommonUnlock(pthread_mutex_t *mutex) @@ -43,21 +43,21 @@ CommonList::~CommonList() void CommonList::Enter() { -#ifdef _LIST_DEBUG_ - int i=0; - for(; i<10; i++) - { - int res = pthread_mutex_trylock(&mutex); - if(res == 0) break; + if (g_debuglog_list) { + int i=0; + for(; i<10; i++) + { + int res = pthread_mutex_trylock(&mutex); + if(res == 0) break; - usleep(100*YAAMP_MS); + usleep(100*YAAMP_MS); + } + + if(i == 10) + debuglog("failed mutex1 %x <<----------------\n", &mutex); + } else { + pthread_mutex_lock(&mutex); } - - if(i == 10) - debuglog("failed mutex1 %x <<----------------\n", &mutex); -#else - pthread_mutex_lock(&mutex); -#endif } void CommonList::Leave() diff --git a/stratum/remote.cpp b/stratum/remote.cpp index 70e8793..b3e4ef1 100644 --- a/stratum/remote.cpp +++ b/stratum/remote.cpp @@ -1,8 +1,6 @@ #include "stratum.h" -//#define REMOTE_DEBUGLOG_ - bool remote_can_mine(YAAMP_REMOTE *remote) { if(!remote) return false; @@ -40,9 +38,9 @@ bool remote_connected(YAAMP_REMOTE *remote) void remote_close(YAAMP_REMOTE *remote) { -#ifdef REMOTE_DEBUGLOG_ - debuglog("remote_close JOB%d\n", remote->id); -#endif + if (g_debuglog_remote) { + debuglog("remote_close JOB%d\n", remote->id); + } remote->difficulty_actual = 0; @@ -65,11 +63,11 @@ bool remote_connect(YAAMP_REMOTE *remote) if(remote_connected(remote)) remote_close(remote); -#ifdef REMOTE_DEBUGLOG_ - debuglog("connecting to %s:%d JOB%d\n", remote->host, remote->port, remote->id); -#endif + if (g_debuglog_remote) { + debuglog("connecting to %s:%d JOB%d\n", remote->host, remote->port, remote->id); + } - int sock = socket(AF_INET, SOCK_STREAM, 0); + int sock = socket(AF_INET, SOCK_STREAM, 0); if(sock <= 0) return false; struct hostent *ent = gethostbyname(remote->host); @@ -85,9 +83,9 @@ bool remote_connect(YAAMP_REMOTE *remote) int res = connect(sock, (struct sockaddr*)&serv, sizeof(serv)); if(res < 0) { -#ifdef REMOTE_DEBUGLOG_ - debuglog("cant connect to %s:%d JOB%d\n", remote->host, remote->port, remote->id); -#endif + if (g_debuglog_remote) { + debuglog("cant connect to %s:%d JOB%d\n", remote->host, remote->port, remote->id); + } return false; } diff --git a/stratum/rpc.cpp b/stratum/rpc.cpp index 66f857d..219b619 100644 --- a/stratum/rpc.cpp +++ b/stratum/rpc.cpp @@ -37,9 +37,9 @@ bool rpc_connect(YAAMP_RPC *rpc) rpc->id = 0; rpc->bufpos = 0; -#ifdef RPC_DEBUGLOG_ - debuglog("connected to %s:%d\n", rpc->host, rpc->port); -#endif + if (g_debuglog_rpc) { + debuglog("connected to %s:%d\n", rpc->host, rpc->port); + } return true; } @@ -52,9 +52,9 @@ void rpc_close(YAAMP_RPC *rpc) close(rpc->sock); rpc->sock = 0; -#ifdef RPC_DEBUGLOG_ - debuglog("disconnected from %s:%d\n", rpc->host, rpc->port); -#endif + if (g_debuglog_rpc) { + debuglog("disconnected from %s:%d\n", rpc->host, rpc->port); + } } /////////////////////////////////////////////////////////////////// @@ -66,9 +66,9 @@ int rpc_send_raw(YAAMP_RPC *rpc, const char *buffer, int bytes) int res = send(rpc->sock, buffer, bytes, MSG_NOSIGNAL); if(res <= 0) return res; -#ifdef RPC_DEBUGLOG_ - debuglog("sending >%s<\n", buffer); -#endif + if (g_debuglog_rpc) { + debuglog("sending >%s<\n", buffer); + } return res; } @@ -148,9 +148,9 @@ char *rpc_do_call(YAAMP_RPC *rpc, char const *data) while(!g_exiting) { int bytes = recv(rpc->sock, buffer+bufpos, YAAMP_SMALLBUFSIZE-bufpos-1, 0); -#ifdef RPC_DEBUGLOG_ - debuglog("got %s\n", buffer+bufpos); -#endif + if (g_debuglog_rpc) { + debuglog("got %s\n", buffer+bufpos); + } if(bytes <= 0) { debuglog("ERROR: recv1, %d, %d, %s, %s\n", bytes, errno, data, buffer); diff --git a/stratum/socket.cpp b/stratum/socket.cpp index c829c6a..00710db 100644 --- a/stratum/socket.cpp +++ b/stratum/socket.cpp @@ -1,8 +1,6 @@ #include "stratum.h" -//#define SOCKET_DEBUGLOG_ - bool socket_connected(YAAMP_SOCKET *s) { return s->sock > 0; @@ -68,9 +66,9 @@ YAAMP_SOCKET *socket_initialize(int sock) void socket_close(YAAMP_SOCKET *s) { -#ifdef SOCKET_DEBUGLOG_ - debuglog("socket_close\n"); -#endif + if (g_debuglog_socket) { + debuglog("socket_close\n"); + } if(!s) return; if(s->sock) close(s->sock); @@ -174,9 +172,9 @@ json_value *socket_nextjson(YAAMP_SOCKET *s, YAAMP_CLIENT *client) int socket_send_raw(YAAMP_SOCKET *s, const char *buffer, int size) { -#ifdef SOCKET_DEBUGLOG_ - debuglog("socket send: %s", buffer); -#endif + if (g_debuglog_socket) { + debuglog("socket send: %s", buffer); + } int res = send(s->sock, buffer, size, MSG_NOSIGNAL); return res; diff --git a/stratum/stratum.cpp b/stratum/stratum.cpp index 2be15b2..7d75587 100644 --- a/stratum/stratum.cpp +++ b/stratum/stratum.cpp @@ -39,6 +39,13 @@ bool g_stratum_segwit = false; int g_limit_txs_per_block = 0; +bool g_debuglog_client; +bool g_debuglog_hash; +bool g_debuglog_socket; +bool g_debuglog_rpc; +bool g_debuglog_list; +bool g_debuglog_remote; + bool g_autoexchange = true; uint64_t g_max_shares = 0; @@ -241,6 +248,13 @@ int main(int argc, char **argv) g_limit_txs_per_block = iniparser_getint(ini, "STRATUM:max_txs_per_block", 0); + g_debuglog_client = iniparser_getint(ini, "DEBUGLOG:client", false); + g_debuglog_hash = iniparser_getint(ini, "DEBUGLOG:hash", false); + g_debuglog_socket = iniparser_getint(ini, "DEBUGLOG:socket", false); + g_debuglog_rpc = iniparser_getint(ini, "DEBUGLOG:rpc", false); + g_debuglog_list = iniparser_getint(ini, "DEBUGLOG:list", false); + g_debuglog_remote = iniparser_getint(ini, "DEBUGLOG:remote", false); + iniparser_freedict(ini); g_current_algo = stratum_find_algo(g_stratum_algo); diff --git a/stratum/stratum.h b/stratum/stratum.h index 81c3d52..43356e0 100644 --- a/stratum/stratum.h +++ b/stratum/stratum.h @@ -90,6 +90,13 @@ extern bool g_stratum_renting; extern bool g_stratum_segwit; extern int g_limit_txs_per_block; +extern bool g_debuglog_client; +extern bool g_debuglog_hash; +extern bool g_debuglog_socket; +extern bool g_debuglog_rpc; +extern bool g_debuglog_list; +extern bool g_debuglog_remote; + extern uint64_t g_max_shares; extern uint64_t g_shares_counter; From 1e06755a743142508e1be88893368e1871d05871 Mon Sep 17 00:00:00 2001 From: Johan Dufour Date: Tue, 6 Mar 2018 13:26:03 +0100 Subject: [PATCH 052/195] use memcache object method instead of low level method (#234) --- web/yaamp/core/common/system.php | 4 +- web/yaamp/modules/api/ApiController.php | 11 ++---- web/yaamp/modules/site/SiteController.php | 4 +- web/yaamp/modules/site/common_results.php | 16 ++++---- web/yaamp/modules/site/memcached.php | 5 +-- .../modules/thread/CronjobController.php | 38 +++++++++---------- 6 files changed, 37 insertions(+), 41 deletions(-) diff --git a/web/yaamp/core/common/system.php b/web/yaamp/core/common/system.php index b8eff20..a666673 100644 --- a/web/yaamp/core/common/system.php +++ b/web/yaamp/core/common/system.php @@ -4,7 +4,7 @@ function send_email_alert($name, $title, $message, $t=10) { // debuglog(__FUNCTION__); - $last = memcache_get(controller()->memcache->memcache, "last_email_sent_$name"); + $last = controller()->memcache->get("last_email_sent_$name"); if($last + $t*60 > time()) return; debuglog("mail('".YAAMP_ADMIN_EMAIL."', $title, ...)"); @@ -12,7 +12,7 @@ function send_email_alert($name, $title, $message, $t=10) $b = mail(YAAMP_ADMIN_EMAIL, $title, $message); if(!$b) debuglog('error sending email'); - memcache_set(controller()->memcache->memcache, "last_email_sent_$name", time()); + controller()->memcache->set("last_email_sent_$name", time()); } function dos_filesize($fn) diff --git a/web/yaamp/modules/api/ApiController.php b/web/yaamp/modules/api/ApiController.php index 80074fc..1ff641a 100644 --- a/web/yaamp/modules/api/ApiController.php +++ b/web/yaamp/modules/api/ApiController.php @@ -20,8 +20,7 @@ class ApiController extends CommonController return; } - $memcache = controller()->memcache->memcache; - $json = memcache_get($memcache, "api_status"); + $json = controller()->memcache->get("api_status"); if (!empty($json)) { echo $json; @@ -97,7 +96,7 @@ class ApiController extends CommonController $json = json_encode($stats); echo $json; - memcache_set($memcache, "api_status", $json, MEMCACHE_COMPRESSED, 30); + controller()->memcache->set("api_status", $json, MEMCACHE_COMPRESSED, 30); } public function actionCurrencies() @@ -112,9 +111,7 @@ class ApiController extends CommonController return; } - $memcache = controller()->memcache->memcache; - - $json = memcache_get($memcache, "api_currencies"); + $json = controller()->memcache->get("api_currencies"); if (empty($json)) { $data = array(); @@ -186,7 +183,7 @@ class ApiController extends CommonController $data[$symbol]['symbol'] = $coin->symbol2; } $json = json_encode($data); - memcache_set($memcache, "api_currencies", $json, MEMCACHE_COMPRESSED, 15); + controller()->memcache->set("api_currencies", $json, MEMCACHE_COMPRESSED, 15); } echo str_replace("},","},\n", $json); diff --git a/web/yaamp/modules/site/SiteController.php b/web/yaamp/modules/site/SiteController.php index df0a719..a96e5b1 100644 --- a/web/yaamp/modules/site/SiteController.php +++ b/web/yaamp/modules/site/SiteController.php @@ -415,7 +415,7 @@ class SiteController extends CommonController $algo = user()->getState('yaamp-algo'); $memcache = controller()->memcache->memcache; $memkey = $algo.'_'.str_replace('/','_',$partial); - $html = memcache_get($memcache, $memkey); + $html = controller()->memcache->get($memkey); if (!empty($html)) { echo $html; @@ -428,7 +428,7 @@ class SiteController extends CommonController $html = ob_get_clean(); echo $html; - memcache_set($memcache, $memkey, $html, MEMCACHE_COMPRESSED, $cachetime); + controller()->memcache->set($memkey, $html, MEMCACHE_COMPRESSED, $cachetime); } // Pool Status : public right panel with all algos and live stats diff --git a/web/yaamp/modules/site/common_results.php b/web/yaamp/modules/site/common_results.php index a5b93b0..fb88841 100644 --- a/web/yaamp/modules/site/common_results.php +++ b/web/yaamp/modules/site/common_results.php @@ -507,8 +507,8 @@ function cronstate2text($state) } } -//$state_block = memcache_get($this->memcache->memcache, 'cronjob_block_state'); -$state_main = memcache_get($this->memcache->memcache, 'cronjob_main_state'); +//$state_block = $this->memcache->get('cronjob_block_state'); +$state_main = $this->memcache->get('cronjob_main_state'); $btc = getdbosql('db_coins', "symbol='BTC'"); if (!$btc) $btc = json_decode('{"id": 6, "balance": 0}'); @@ -517,24 +517,24 @@ for($i=0; $i<10; $i++) { // if($i != $state_block-1 && $state_block>0) // { -// $state = memcache_get($this->memcache->memcache, "cronjob_block_state_$i"); +// $state = $this->memcache->get("cronjob_block_state_$i"); // if($state) echo "block $i "; // } if($i != $state_main-1 && $state_main>0) { - $state = memcache_get($this->memcache->memcache, "cronjob_main_state_$i"); + $state = $this->memcache->get("cronjob_main_state_$i"); if($state) echo "main $i "; } } echo ''; -$block_time = sectoa(time()-memcache_get($this->memcache->memcache, "cronjob_block_time_start")); -$loop2_time = sectoa(time()-memcache_get($this->memcache->memcache, "cronjob_loop2_time_start")); -$main_time2 = sectoa(time()-memcache_get($this->memcache->memcache, "cronjob_main_time_start")); +$block_time = sectoa(time()-$this->memcache->get("cronjob_block_time_start")); +$loop2_time = sectoa(time()-$this->memcache->get("cronjob_loop2_time_start")); +$main_time2 = sectoa(time()-$this->memcache->get("cronjob_main_time_start")); -$main_time = sectoa(memcache_get($this->memcache->memcache, "cronjob_main_time")); +$main_time = sectoa($this->memcache->get("cronjob_main_time")); $main_text = cronstate2text($state_main); echo "*** main ($main_time) $state_main $main_text ($main_time2), loop2 ($loop2_time), block ($block_time)
"; diff --git a/web/yaamp/modules/site/memcached.php b/web/yaamp/modules/site/memcached.php index bed417b..a1252a6 100644 --- a/web/yaamp/modules/site/memcached.php +++ b/web/yaamp/modules/site/memcached.php @@ -2,8 +2,7 @@ echo "refresh
"; -$memcache = controller()->memcache->memcache; -$a = memcache_get($this->memcache->memcache, 'url-map'); +$a = controller()->memcache->memcache->get( 'url-map'); function printStats($stat) { @@ -51,7 +50,7 @@ function cmp($a, $b) if (!empty($a)) foreach($a as $url=>$n) { - $d = memcache_get($this->memcache->memcache, "$url-time"); + $d = $this->memcache->get("$url-time"); $avg = $d/$n; $res[] = array($url, $n, $d, $avg); diff --git a/web/yaamp/modules/thread/CronjobController.php b/web/yaamp/modules/thread/CronjobController.php index 4af3982..723c7ad 100644 --- a/web/yaamp/modules/thread/CronjobController.php +++ b/web/yaamp/modules/thread/CronjobController.php @@ -18,7 +18,7 @@ class CronjobController extends CommonController $uptime = exec('uptime'); - $apache_locked = memcache_get($this->memcache->memcache, 'apache_locked'); + $apache_locked = $this->memcache->get('apache_locked'); if($apache_locked) return; $b = preg_match('/load average: (.*)$/', $uptime, $m); @@ -52,7 +52,7 @@ class CronjobController extends CommonController $this->monitorApache(); - $last_complete = memcache_get($this->memcache->memcache, "cronjob_block_time_start"); + $last_complete = $this->memcache->get("cronjob_block_time_start"); if($last_complete+(5*60) < time()) dborun("update jobs set active=false"); @@ -62,7 +62,7 @@ class CronjobController extends CommonController BackendProcessList(); BackendBlocksUpdate(); - memcache_set($this->memcache->memcache, "cronjob_block_time_start", time()); + $this->memcache->set("cronjob_block_time_start", time()); // debuglog(__METHOD__); } @@ -82,21 +82,21 @@ class CronjobController extends CommonController MonitorBTC(); - $last = memcache_get($this->memcache->memcache, 'last_renting_payout2'); + $last = $this->memcache->get('last_renting_payout2'); if($last + 5*60 < time()) { - memcache_set($this->memcache->memcache, 'last_renting_payout2', time()); + $this->memcache->set('last_renting_payout2', time()); BackendRentingPayout(); } - $last = memcache_get($this->memcache->memcache, 'last_stats2'); + $last = $this->memcache->get('last_stats2'); if($last + 5*60 < time()) { - memcache_set($this->memcache->memcache, 'last_stats2', time()); + $this->memcache->set('last_stats2', time()); BackendStatsUpdate2(); } - memcache_set($this->memcache->memcache, "cronjob_loop2_time_start", time()); + $this->memcache->set("cronjob_loop2_time_start", time()); // debuglog(__METHOD__); } @@ -107,11 +107,11 @@ class CronjobController extends CommonController // BackendRunCoinActions(); - $state = memcache_get($this->memcache->memcache, 'cronjob_main_state'); + $state = $this->memcache->get('cronjob_main_state'); if(!$state) $state = 0; - memcache_set($this->memcache->memcache, 'cronjob_main_state', $state+1); - memcache_set($this->memcache->memcache, "cronjob_main_state_$state", 1); + $this->memcache->set('cronjob_main_state', $state+1); + $this->memcache->set("cronjob_main_state_$state", 1); switch($state) { @@ -177,20 +177,20 @@ class CronjobController extends CommonController break; default: - memcache_set($this->memcache->memcache, 'cronjob_main_state', 0); + $this->memcache->set('cronjob_main_state', 0); BackendQuickClean(); - $t = memcache_get($this->memcache->memcache, "cronjob_main_start_time"); + $t = $this->memcache->get("cronjob_main_start_time"); $n = time(); - memcache_set($this->memcache->memcache, "cronjob_main_time", $n-$t); - memcache_set($this->memcache->memcache, "cronjob_main_start_time", $n); + $this->memcache->set("cronjob_main_time", $n-$t); + $this->memcache->set("cronjob_main_start_time", $n); } debuglog(__METHOD__." $state"); - memcache_set($this->memcache->memcache, "cronjob_main_state_$state", 0); + $this->memcache->set("cronjob_main_state_$state", 0); - memcache_set($this->memcache->memcache, "cronjob_main_time_start", time()); + $this->memcache->set("cronjob_main_time_start", time()); if(!YAAMP_PRODUCTION) return; /////////////////////////////////////////////////////////////////// @@ -203,14 +203,14 @@ class CronjobController extends CommonController $mining->last_payout = time(); $mining->save(); - memcache_set($this->memcache->memcache, 'apache_locked', true); + $this->memcache->set('apache_locked', true); if(YAAMP_USE_NGINX) system("service nginx stop"); sleep(10); BackendDoBackup(); - memcache_set($this->memcache->memcache, 'apache_locked', false); + $this->memcache->set('apache_locked', false); BackendPayments(); BackendCleanDatabase(); From 6a7bc6de1ded25b9566dd81faa9fd7987a194802 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Tue, 6 Mar 2018 13:48:57 +0100 Subject: [PATCH 053/195] memcache: fix param order in last commit --- web/yaamp/modules/api/ApiController.php | 4 ++-- web/yaamp/modules/site/SiteController.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/web/yaamp/modules/api/ApiController.php b/web/yaamp/modules/api/ApiController.php index 1ff641a..9a5a156 100644 --- a/web/yaamp/modules/api/ApiController.php +++ b/web/yaamp/modules/api/ApiController.php @@ -96,7 +96,7 @@ class ApiController extends CommonController $json = json_encode($stats); echo $json; - controller()->memcache->set("api_status", $json, MEMCACHE_COMPRESSED, 30); + controller()->memcache->set("api_status", $json, 30, MEMCACHE_COMPRESSED); } public function actionCurrencies() @@ -183,7 +183,7 @@ class ApiController extends CommonController $data[$symbol]['symbol'] = $coin->symbol2; } $json = json_encode($data); - controller()->memcache->set("api_currencies", $json, MEMCACHE_COMPRESSED, 15); + controller()->memcache->set("api_currencies", $json, 15, MEMCACHE_COMPRESSED); } echo str_replace("},","},\n", $json); diff --git a/web/yaamp/modules/site/SiteController.php b/web/yaamp/modules/site/SiteController.php index a96e5b1..e4c265d 100644 --- a/web/yaamp/modules/site/SiteController.php +++ b/web/yaamp/modules/site/SiteController.php @@ -428,7 +428,7 @@ class SiteController extends CommonController $html = ob_get_clean(); echo $html; - controller()->memcache->set($memkey, $html, MEMCACHE_COMPRESSED, $cachetime); + controller()->memcache->set($memkey, $html, $cachetime, MEMCACHE_COMPRESSED); } // Pool Status : public right panel with all algos and live stats From 569661a25c41fc520adc52f8c21d4139bd49c8c8 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Tue, 6 Mar 2018 14:26:42 +0100 Subject: [PATCH 054/195] memcache: revert commit for the backend job --- .../modules/thread/CronjobController.php | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/web/yaamp/modules/thread/CronjobController.php b/web/yaamp/modules/thread/CronjobController.php index 723c7ad..4af3982 100644 --- a/web/yaamp/modules/thread/CronjobController.php +++ b/web/yaamp/modules/thread/CronjobController.php @@ -18,7 +18,7 @@ class CronjobController extends CommonController $uptime = exec('uptime'); - $apache_locked = $this->memcache->get('apache_locked'); + $apache_locked = memcache_get($this->memcache->memcache, 'apache_locked'); if($apache_locked) return; $b = preg_match('/load average: (.*)$/', $uptime, $m); @@ -52,7 +52,7 @@ class CronjobController extends CommonController $this->monitorApache(); - $last_complete = $this->memcache->get("cronjob_block_time_start"); + $last_complete = memcache_get($this->memcache->memcache, "cronjob_block_time_start"); if($last_complete+(5*60) < time()) dborun("update jobs set active=false"); @@ -62,7 +62,7 @@ class CronjobController extends CommonController BackendProcessList(); BackendBlocksUpdate(); - $this->memcache->set("cronjob_block_time_start", time()); + memcache_set($this->memcache->memcache, "cronjob_block_time_start", time()); // debuglog(__METHOD__); } @@ -82,21 +82,21 @@ class CronjobController extends CommonController MonitorBTC(); - $last = $this->memcache->get('last_renting_payout2'); + $last = memcache_get($this->memcache->memcache, 'last_renting_payout2'); if($last + 5*60 < time()) { - $this->memcache->set('last_renting_payout2', time()); + memcache_set($this->memcache->memcache, 'last_renting_payout2', time()); BackendRentingPayout(); } - $last = $this->memcache->get('last_stats2'); + $last = memcache_get($this->memcache->memcache, 'last_stats2'); if($last + 5*60 < time()) { - $this->memcache->set('last_stats2', time()); + memcache_set($this->memcache->memcache, 'last_stats2', time()); BackendStatsUpdate2(); } - $this->memcache->set("cronjob_loop2_time_start", time()); + memcache_set($this->memcache->memcache, "cronjob_loop2_time_start", time()); // debuglog(__METHOD__); } @@ -107,11 +107,11 @@ class CronjobController extends CommonController // BackendRunCoinActions(); - $state = $this->memcache->get('cronjob_main_state'); + $state = memcache_get($this->memcache->memcache, 'cronjob_main_state'); if(!$state) $state = 0; - $this->memcache->set('cronjob_main_state', $state+1); - $this->memcache->set("cronjob_main_state_$state", 1); + memcache_set($this->memcache->memcache, 'cronjob_main_state', $state+1); + memcache_set($this->memcache->memcache, "cronjob_main_state_$state", 1); switch($state) { @@ -177,20 +177,20 @@ class CronjobController extends CommonController break; default: - $this->memcache->set('cronjob_main_state', 0); + memcache_set($this->memcache->memcache, 'cronjob_main_state', 0); BackendQuickClean(); - $t = $this->memcache->get("cronjob_main_start_time"); + $t = memcache_get($this->memcache->memcache, "cronjob_main_start_time"); $n = time(); - $this->memcache->set("cronjob_main_time", $n-$t); - $this->memcache->set("cronjob_main_start_time", $n); + memcache_set($this->memcache->memcache, "cronjob_main_time", $n-$t); + memcache_set($this->memcache->memcache, "cronjob_main_start_time", $n); } debuglog(__METHOD__." $state"); - $this->memcache->set("cronjob_main_state_$state", 0); + memcache_set($this->memcache->memcache, "cronjob_main_state_$state", 0); - $this->memcache->set("cronjob_main_time_start", time()); + memcache_set($this->memcache->memcache, "cronjob_main_time_start", time()); if(!YAAMP_PRODUCTION) return; /////////////////////////////////////////////////////////////////// @@ -203,14 +203,14 @@ class CronjobController extends CommonController $mining->last_payout = time(); $mining->save(); - $this->memcache->set('apache_locked', true); + memcache_set($this->memcache->memcache, 'apache_locked', true); if(YAAMP_USE_NGINX) system("service nginx stop"); sleep(10); BackendDoBackup(); - $this->memcache->set('apache_locked', false); + memcache_set($this->memcache->memcache, 'apache_locked', false); BackendPayments(); BackendCleanDatabase(); From 46996e3269d18b7d909a165c07e420604bf26c8e Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Thu, 8 Mar 2018 17:05:44 +0100 Subject: [PATCH 055/195] stratum: disable haproxy ip translation code by default toggle it via the .conf or edit code to change overall defaults --- stratum/socket.cpp | 21 ++++++++++++++++----- stratum/stratum.cpp | 4 ++++ stratum/stratum.h | 2 ++ 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/stratum/socket.cpp b/stratum/socket.cpp index 00710db..300e4d5 100644 --- a/stratum/socket.cpp +++ b/stratum/socket.cpp @@ -17,9 +17,9 @@ void socket_real_ip(YAAMP_SOCKET *s) ret = recv(s->sock, &hdr, sizeof(hdr), MSG_PEEK); } while (ret == -1 && errno == EINTR); - if (ret >= (16 + ntohs(hdr.v2.len)) && - memcmp(&hdr.v2, v2sig, 12) == 0 && - ((hdr.v2.ver_cmd & 0xF0) == 0x20) && + if (ret >= (16 + ntohs(hdr.v2.len)) && + memcmp(&hdr.v2, v2sig, 12) == 0 && + ((hdr.v2.ver_cmd & 0xF0) == 0x20) && hdr.v2.fam == 0x11) { // we received a proxy v2 header inet_ntop(AF_INET, &hdr.v2.addr.ip4.src_addr, s->ip, 64); @@ -58,8 +58,20 @@ YAAMP_SOCKET *socket_initialize(int sock) // yaamp_create_mutex(&s->mutex); // pthread_mutex_lock(&s->mutex); + int res = 0; + if (!g_handle_haproxy_ips) { + struct sockaddr_in name; + socklen_t len = sizeof(name); + memset(&name, 0, len); - socket_real_ip(s); + res = getpeername(s->sock, (struct sockaddr *)&name, &len); + inet_ntop(AF_INET, &name.sin_addr, s->ip, 64); + + res = getsockname(s->sock, (struct sockaddr *)&name, &len); + s->port = ntohs(name.sin_port); + } else { + socket_real_ip(s); + } return s; } @@ -202,7 +214,6 @@ int socket_send(YAAMP_SOCKET *s, const char *format, ...) // pthread_mutex_lock(&s->mutex); int res = socket_send_raw(s, buffer, strlen(buffer)); - // pthread_mutex_unlock(&s->mutex); return res; } diff --git a/stratum/stratum.cpp b/stratum/stratum.cpp index 7d75587..b1f032d 100644 --- a/stratum/stratum.cpp +++ b/stratum/stratum.cpp @@ -39,6 +39,8 @@ bool g_stratum_segwit = false; int g_limit_txs_per_block = 0; +bool g_handle_haproxy_ips = false; + bool g_debuglog_client; bool g_debuglog_hash; bool g_debuglog_socket; @@ -245,7 +247,9 @@ int main(int argc, char **argv) g_stratum_max_ttf = iniparser_getint(ini, "STRATUM:max_ttf", 0x70000000); g_stratum_reconnect = iniparser_getint(ini, "STRATUM:reconnect", true); g_stratum_renting = iniparser_getint(ini, "STRATUM:renting", true); + g_handle_haproxy_ips = iniparser_getint(ini, "STRATUM:haproxy_ips", g_handle_haproxy_ips); + g_max_shares = iniparser_getint(ini, "STRATUM:max_shares", g_max_shares); g_limit_txs_per_block = iniparser_getint(ini, "STRATUM:max_txs_per_block", 0); g_debuglog_client = iniparser_getint(ini, "DEBUGLOG:client", false); diff --git a/stratum/stratum.h b/stratum/stratum.h index 43356e0..efd9204 100644 --- a/stratum/stratum.h +++ b/stratum/stratum.h @@ -90,6 +90,8 @@ extern bool g_stratum_renting; extern bool g_stratum_segwit; extern int g_limit_txs_per_block; +extern bool g_handle_haproxy_ips; + extern bool g_debuglog_client; extern bool g_debuglog_hash; extern bool g_debuglog_socket; From 669ab6bb0faf2cb271cd804e144141c00ba029b0 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Mon, 12 Mar 2018 15:38:19 +0100 Subject: [PATCH 056/195] stratum: ensure all blocks are put in db (#241) may be important for pool op noobs who dunno what they do, doesn't setup blocknotify or have server efficiency issues.. squashed commit of today's commits, sorry for the mess ;) prevent job delays if no blocks were submitted double check coin id on blocknotify remove noblocknotify boolean prevent notify debuglog on normal blocks --- stratum/client.cpp | 6 +++++- stratum/client_submit.cpp | 8 +++++--- stratum/coind.cpp | 1 - stratum/coind.h | 2 +- stratum/share.cpp | 19 ++++++++++--------- stratum/share.h | 2 +- 6 files changed, 22 insertions(+), 16 deletions(-) diff --git a/stratum/client.cpp b/stratum/client.cpp index 844d23d..c3787ca 100644 --- a/stratum/client.cpp +++ b/stratum/client.cpp @@ -298,7 +298,9 @@ bool client_update_block(YAAMP_CLIENT *client, json_value *json_params) return false; } - YAAMP_COIND *coind = (YAAMP_COIND *)object_find(&g_list_coind, json_params->u.array.values[1]->u.integer, true); + int coinid = json_params->u.array.values[1]->u.integer; + if(!coinid) return false; + YAAMP_COIND *coind = (YAAMP_COIND *)object_find(&g_list_coind, coinid, true); if(!coind) return false; const char* hash = json_params->u.array.values[2]->u.string.ptr; @@ -307,6 +309,8 @@ bool client_update_block(YAAMP_CLIENT *client, json_value *json_params) debuglog("notify: new %s block %s\n", coind->symbol, hash); } + snprintf(coind->lastnotifyhash, 161, "%s", hash); + coind->newblock = true; coind->notreportingcounter = 0; diff --git a/stratum/client_submit.cpp b/stratum/client_submit.cpp index e1021f9..02227ec 100644 --- a/stratum/client_submit.cpp +++ b/stratum/client_submit.cpp @@ -277,10 +277,12 @@ static void client_do_submit(YAAMP_CLIENT *client, YAAMP_JOB *job, YAAMP_JOB_VAL target_to_diff(coin_target), target_to_diff(hash_int), hash1, submitvalues->hash_be, templ->has_segwit_txs); - if(coind->noblocknotify) { - // DCR go wallet doesnt handle blocknotify= config (yet) - // required to store the user id and the user diff + if(!strcmp("DCR", coind->rpcencoding)) { + // delay between dcrd and dcrwallet sleep(1); + } + + if(!strcmp(coind->lastnotifyhash,submitvalues->hash_be)) { block_confirm(coind->id, submitvalues->hash_be); } diff --git a/stratum/coind.cpp b/stratum/coind.cpp index bfebc8f..4ba9ab8 100644 --- a/stratum/coind.cpp +++ b/stratum/coind.cpp @@ -165,7 +165,6 @@ void coind_init(YAAMP_COIND *coind) strcpy(account, coind->account); if(!strcmp(coind->rpcencoding, "DCR")) { coind->usegetwork = true; - //coind->noblocknotify = true; //sprintf(account, "default"); } diff --git a/stratum/coind.h b/stratum/coind.h index 5ea7fff..d008a24 100644 --- a/stratum/coind.h +++ b/stratum/coind.h @@ -47,6 +47,7 @@ public: bool enable; bool auto_ready; bool newblock; + char lastnotifyhash[192]; int height; double difficulty; @@ -66,7 +67,6 @@ public: bool usememorypool; bool hasmasternodes; bool oldmasternodes; - bool noblocknotify; bool multialgos; // pow_hash field (or mined_hash) bool usesegwit; diff --git a/stratum/share.cpp b/stratum/share.cpp index c7106da..a8a4f82 100644 --- a/stratum/share.cpp +++ b/stratum/share.cpp @@ -232,10 +232,10 @@ void block_add(int userid, int workerid, int coinid, int height, double diff, do } // called from blocknotify tool -void block_confirm(int coinid, const char *blockhash) +bool block_confirm(int coinid, const char *blockhash) { char hash[192]; - if(strlen(blockhash) < 64) return; + if(strlen(blockhash) < 64) return false; snprintf(hash, 161, "%s", blockhash); @@ -290,17 +290,18 @@ void block_confirm(int coinid, const char *blockhash) for(CLI li = g_list_block.first; li; li = li->next) { YAAMP_BLOCK *block = (YAAMP_BLOCK *)li->data; - if(block->coinid == coinid && !block->confirmed && !block->deleted) + if(block->coinid == coinid && !block->deleted) { if(strcmp(block->hash1, hash) && strcmp(block->hash2, hash)) continue; - debuglog("*** CONFIRMED %d : %s\n", block->height, block->hash2); - - strncpy(block->hash, blockhash, 65); - block->confirmed = true; - - return; + if (!block->confirmed) { + debuglog("*** CONFIRMED %d : %s\n", block->height, block->hash2); + strncpy(block->hash, blockhash, 65); + block->confirmed = true; + } + return true; } } + return false; } ////////////////////////////////////////////////////////////////////////////////////////// diff --git a/stratum/share.h b/stratum/share.h index 1decef9..dd90eca 100644 --- a/stratum/share.h +++ b/stratum/share.h @@ -100,7 +100,7 @@ inline void submit_delete(YAAMP_OBJECT *object) void block_prune(YAAMP_DB *db); void block_add(int userid, int workerid, int coinid, int height, double diff, double diff_user, const char *hash1, const char *h2, int segwit); -void block_confirm(int coinid, const char *hash); +bool block_confirm(int coinid, const char *hash); YAAMP_SUBMIT *submit_add(int remoteid, double difficulty); void submit_prune(YAAMP_DB *db); From 3624f2c44d88e6836fee1cf340ac3239a557d0b8 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Tue, 13 Mar 2018 17:44:33 +0100 Subject: [PATCH 057/195] stratum: be more strict with user string fields --- stratum/db.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/stratum/db.cpp b/stratum/db.cpp index fbbc2b2..2e90eac 100644 --- a/stratum/db.cpp +++ b/stratum/db.cpp @@ -43,11 +43,19 @@ void db_close(YAAMP_DB *db) char *db_clean_string(YAAMP_DB *db, char *string) { - string[1000] = 0; - char tmp[1024]; + char escaped[512] = { 0 }; + char *c = string; - unsigned long ret = mysql_real_escape_string(&db->mysql, tmp, string, strlen(string)); - strcpy(string, tmp); + size_t i, len = strlen(string); + for (i = 0; i < len && i < sizeof(escaped); i++) { + bool isdigit = (c[i] >= '0' && c[i] <= '9'); + bool isalpha = (c[i] >= 'a' && c[i] <= 'z') || (c[i] >= 'A' && c[i] <= 'Z'); + bool issepch = (c[i] == '=' || c[i] == ',' || c[i] == ';' || c[i] == '.'); + bool isextra = (c[i] == '/' || c[i] == '-' || c[i] == '_'); + if (!isdigit && !isalpha && !issepch && !isextra) { c[i] = '\0'; break; } + } + mysql_real_escape_string(&db->mysql, escaped, string, strlen(string)); + strcpy(string, escaped); return string; } From 8c27bed4383dd5c0c7b96ea678d420cb68248ad2 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Tue, 13 Mar 2018 19:08:11 +0100 Subject: [PATCH 058/195] stratum: remove useless mysql escape + fix for stats the custom check is already more secure than "unknown" mysql code --- stratum/db.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/stratum/db.cpp b/stratum/db.cpp index 2e90eac..3b34415 100644 --- a/stratum/db.cpp +++ b/stratum/db.cpp @@ -43,20 +43,15 @@ void db_close(YAAMP_DB *db) char *db_clean_string(YAAMP_DB *db, char *string) { - char escaped[512] = { 0 }; char *c = string; - - size_t i, len = strlen(string); - for (i = 0; i < len && i < sizeof(escaped); i++) { + size_t i, len = strlen(string) & 0x1FF; + for (i = 0; i < len; i++) { bool isdigit = (c[i] >= '0' && c[i] <= '9'); bool isalpha = (c[i] >= 'a' && c[i] <= 'z') || (c[i] >= 'A' && c[i] <= 'Z'); bool issepch = (c[i] == '=' || c[i] == ',' || c[i] == ';' || c[i] == '.'); bool isextra = (c[i] == '/' || c[i] == '-' || c[i] == '_'); if (!isdigit && !isalpha && !issepch && !isextra) { c[i] = '\0'; break; } } - mysql_real_escape_string(&db->mysql, escaped, string, strlen(string)); - strcpy(string, escaped); - return string; } @@ -537,9 +532,14 @@ static void _json_str_safe(YAAMP_DB *db, json_value *json, const char *key, size json_value *val = json_get_val(json, key); out[0] = '\0'; if (db && val && json_is_string(val)) { - strncpy(out, json_string_value(val), maxlen); + char str[128] = { 0 }; + char escaped[256] = { 0 }; + snprintf(str, sizeof(str)-1, "%s", json_string_value(val)); + str[maxlen-1] = '\0'; // truncate to dest len + //db_clean_string(db, str); + mysql_real_escape_string(&db->mysql, escaped, str, strlen(str)); + snprintf(out, maxlen, "%s", escaped); out[maxlen-1] = '\0'; - db_clean_string(db, out); } } #define json_str_safe(stats, k, out) _json_str_safe(db, stats, k, sizeof(out), out) From bd888ff4e2d43e784517af1f23d18bd6b7f6f89a Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Tue, 13 Mar 2018 21:22:17 +0100 Subject: [PATCH 059/195] stratum: function to track mem usage + bad client possible leak... but it is not the main one --- stratum/client.cpp | 6 +++--- stratum/util.cpp | 13 ++++++++++++- stratum/util.h | 1 + 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/stratum/client.cpp b/stratum/client.cpp index c3787ca..bdc6bb2 100644 --- a/stratum/client.cpp +++ b/stratum/client.cpp @@ -639,7 +639,7 @@ void *client_thread(void *p) if (g_debuglog_client) { debuglog("client terminate\n"); } - if(!client || client->deleted) { + if(!client) { pthread_exit(NULL); } @@ -657,13 +657,13 @@ void *client_thread(void *p) db_clear_worker(g_db, client); CommonUnlock(&g_db_mutex); } + object_delete(client); } else { // only clients sockets in g_list_client are purged (if marked deleted) socket_close(client->sock); + delete client; } - object_delete(client); - pthread_exit(NULL); } diff --git a/stratum/util.cpp b/stratum/util.cpp index 0dda75f..9329944 100644 --- a/stratum/util.cpp +++ b/stratum/util.cpp @@ -679,13 +679,24 @@ int opened_files() int fds = 0; DIR *d = opendir("/proc/self/fd"); if (d) { - struct dirent *ent; while (readdir(d)) fds++; closedir(d); } return fds; } +int resident_size() +{ + int sz, res = 0; + FILE *fp = fopen("/proc/self/statm", "r"); + if (fp) { + fscanf(fp,"%d", &sz); + fscanf(fp,"%d", &res); + fclose(fp); + } + return res; +} + void string_lower(char *s) { for(int i = 0; s[i]; i++) diff --git a/stratum/util.h b/stratum/util.h index a10d20a..685e1e3 100644 --- a/stratum/util.h +++ b/stratum/util.h @@ -103,6 +103,7 @@ long long current_timestamp(); long long current_timestamp_dms(); int opened_files(); +int resident_size(); void string_lower(char *s); void string_upper(char *s); From 165e93bf29769b38a4cf3297c8a5215cecaf5c3a Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Wed, 14 Mar 2018 18:12:55 +0100 Subject: [PATCH 060/195] stratum: function to check hex strings validity --- stratum/client_submit.cpp | 5 +++++ stratum/util.cpp | 8 ++++++++ stratum/util.h | 2 ++ 3 files changed, 15 insertions(+) diff --git a/stratum/client_submit.cpp b/stratum/client_submit.cpp index 02227ec..11efebf 100644 --- a/stratum/client_submit.cpp +++ b/stratum/client_submit.cpp @@ -463,6 +463,11 @@ bool client_submit(YAAMP_CLIENT *client, json_value *json_params) return true; } } + else if(!ishexa(extranonce2, client->extranonce2size*2)) { + client_submit_error(client, job, 27, "Invalid nonce2", extranonce2, ntime, nonce); + client->submit_bad++; + return true; + } /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/stratum/util.cpp b/stratum/util.cpp index 9329944..e18d211 100644 --- a/stratum/util.cpp +++ b/stratum/util.cpp @@ -417,6 +417,14 @@ void hexlify(char *hex, const unsigned char *bin, int len) sprintf(hex+strlen(hex), "%02x", bin[i]); } +bool ishexa(char *hex, int len) +{ + for(int i=0; i= '0' && v <= '9') diff --git a/stratum/util.h b/stratum/util.h index 685e1e3..7afdd1b 100644 --- a/stratum/util.h +++ b/stratum/util.h @@ -86,6 +86,8 @@ void ser_string_be2(const char *input, char *output, int len); void string_be(const char *input, char *output); void string_be1(char *s); +bool ishexa(char *hex, int len); + void hexlify(char *hex, const unsigned char *bin, int len); void binlify(unsigned char *bin, const char *hex); From f342017d3118f3b3282079d73af0a11b5f7e1e75 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Wed, 14 Mar 2018 20:20:41 +0100 Subject: [PATCH 061/195] stratum: also check early nonce is hexa and remove double submit_bad++ --- stratum/client_submit.cpp | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/stratum/client_submit.cpp b/stratum/client_submit.cpp index 11efebf..47dfd0f 100644 --- a/stratum/client_submit.cpp +++ b/stratum/client_submit.cpp @@ -406,8 +406,7 @@ bool client_submit(YAAMP_CLIENT *client, json_value *json_params) YAAMP_JOB_TEMPLATE *templ = job->templ; - if(strlen(nonce) != YAAMP_NONCE_SIZE*2) - { + if(strlen(nonce) != YAAMP_NONCE_SIZE*2 || !ishexa(nonce, YAAMP_NONCE_SIZE*2)) { client_submit_error(client, job, 20, "Invalid nonce size", extranonce2, ntime, nonce); return true; } @@ -451,13 +450,11 @@ bool client_submit(YAAMP_CLIENT *client, json_value *json_params) if (extranull) { debuglog("extranonce %s is empty!, should be %s - %s\n", extranonce2, extra1_id, client->sock->ip); client_submit_error(client, job, 27, "Invalid extranonce2 suffix", extranonce2, ntime, nonce); - client->submit_bad++; return true; } if (extradiff) { // some ccminer pre-release doesn't fill correctly the extranonce client_submit_error(client, job, 27, "Invalid extranonce2 suffix", extranonce2, ntime, nonce); - client->submit_bad++; socket_send(client->sock, "{\"id\":null,\"method\":\"mining.set_extranonce\",\"params\":[\"%s\",%d]}\n", client->extranonce1, client->extranonce2size); return true; @@ -465,7 +462,6 @@ bool client_submit(YAAMP_CLIENT *client, json_value *json_params) } else if(!ishexa(extranonce2, client->extranonce2size*2)) { client_submit_error(client, job, 27, "Invalid nonce2", extranonce2, ntime, nonce); - client->submit_bad++; return true; } From 67d3e6aeed5b5bd2c4913b9bb04d9a53b28e5066 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Wed, 14 Mar 2018 22:43:00 +0100 Subject: [PATCH 062/195] stratum: warning fix for recent gcc was -Wunused-result, useless but... --- stratum/util.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stratum/util.cpp b/stratum/util.cpp index e18d211..92f284a 100644 --- a/stratum/util.cpp +++ b/stratum/util.cpp @@ -698,8 +698,8 @@ int resident_size() int sz, res = 0; FILE *fp = fopen("/proc/self/statm", "r"); if (fp) { - fscanf(fp,"%d", &sz); - fscanf(fp,"%d", &res); + int p = fscanf(fp, "%d", &sz); + if (p) p += fscanf(fp, "%d", &res); fclose(fp); } return res; From c56969c51c472fbed5f3fcabeb55735c601f2513 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Thu, 15 Mar 2018 15:44:23 +0100 Subject: [PATCH 063/195] stratum: socket recv timeout config With a default value set to 10mn, better than unlimited (0) --- stratum/socket.cpp | 7 ++++++- stratum/stratum.cpp | 2 ++ stratum/stratum.h | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/stratum/socket.cpp b/stratum/socket.cpp index 300e4d5..a9796fc 100644 --- a/stratum/socket.cpp +++ b/stratum/socket.cpp @@ -50,16 +50,21 @@ void socket_real_ip(YAAMP_SOCKET *s) YAAMP_SOCKET *socket_initialize(int sock) { + struct timeval timeout; + timeout.tv_sec = g_socket_recv_timeout; + timeout.tv_usec = 0; YAAMP_SOCKET *s = new YAAMP_SOCKET; memset(s, 0, sizeof(YAAMP_SOCKET)); s->buflen = 0; s->sock = sock; + setsockopt(s->sock, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout)); + // yaamp_create_mutex(&s->mutex); // pthread_mutex_lock(&s->mutex); - int res = 0; if (!g_handle_haproxy_ips) { + int res = 0; struct sockaddr_in name; socklen_t len = sizeof(name); memset(&name, 0, len); diff --git a/stratum/stratum.cpp b/stratum/stratum.cpp index b1f032d..382a165 100644 --- a/stratum/stratum.cpp +++ b/stratum/stratum.cpp @@ -40,6 +40,7 @@ bool g_stratum_segwit = false; int g_limit_txs_per_block = 0; bool g_handle_haproxy_ips = false; +int g_socket_recv_timeout = 600; bool g_debuglog_client; bool g_debuglog_hash; @@ -248,6 +249,7 @@ int main(int argc, char **argv) g_stratum_reconnect = iniparser_getint(ini, "STRATUM:reconnect", true); g_stratum_renting = iniparser_getint(ini, "STRATUM:renting", true); g_handle_haproxy_ips = iniparser_getint(ini, "STRATUM:haproxy_ips", g_handle_haproxy_ips); + g_socket_recv_timeout = iniparser_getint(ini, "STRATUM:recv_timeout", 600); g_max_shares = iniparser_getint(ini, "STRATUM:max_shares", g_max_shares); g_limit_txs_per_block = iniparser_getint(ini, "STRATUM:max_txs_per_block", 0); diff --git a/stratum/stratum.h b/stratum/stratum.h index efd9204..cb9f9dd 100644 --- a/stratum/stratum.h +++ b/stratum/stratum.h @@ -91,6 +91,7 @@ extern bool g_stratum_segwit; extern int g_limit_txs_per_block; extern bool g_handle_haproxy_ips; +extern int g_socket_recv_timeout; extern bool g_debuglog_client; extern bool g_debuglog_hash; From 333acc0d2518ca8cf3a26211359426ec024ab0a7 Mon Sep 17 00:00:00 2001 From: Daniel Mackie Date: Fri, 16 Mar 2018 15:03:01 +1100 Subject: [PATCH 064/195] stratum: STAK special coinbase, with SegWit support untested, but compiled fine --- stratum/coinbase.cpp | 62 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) mode change 100644 => 100755 stratum/coinbase.cpp diff --git a/stratum/coinbase.cpp b/stratum/coinbase.cpp old mode 100644 new mode 100755 index a604f15..c417430 --- a/stratum/coinbase.cpp +++ b/stratum/coinbase.cpp @@ -145,6 +145,68 @@ void coinbase_create(YAAMP_COIND *coind, YAAMP_JOB_TEMPLATE *templ, json_value * if (strlen(coind->charity_address) == 0 && !strcmp(coind->symbol, "DCR")) sprintf(coind->charity_address, "Dcur2mcGjmENx4DhNqDctW5wJCVyT3Qeqkx"); } + else if(strcmp(coind->symbol, "STAK") == 0) { + char script_dests[1024] = { 0 }; + char script_payee[1024]; + char payee_address[1024]; + char payees[4]; + int npayees = (templ->has_segwit_txs) ? 2 : 1; + bool masternode_payments = json_get_bool(json_result, "masternode_payments"); + bool masternodes_enabled = json_get_bool(json_result, "enforce_masternode_payments"); + + if (masternodes_enabled && masternode_payments) { + const char *payee = json_get_string(json_result, "payee"); + json_int_t amount = json_get_int(json_result, "payee_amount"); + if (payee && amount) + ++npayees; + } + + //treasury 5% @ 10 STAK per block + json_int_t charity_amount = 50000000; + //testnet + //sprintf(coind->charity_address, "93ASJtDuVYVdKXemH9BrtSMscznvsp9stD"); + switch (templ->height % 4) { + case 0: sprintf(coind->charity_address, "3K3bPrW5h7DYEMp2RcXawTCXajcm4ZU9Zh"); + break; + case 1: sprintf(coind->charity_address, "33Ssxmn3ehVMgyxgegXhpLGSBpubPjLZQ6"); + break; + case 2: sprintf(coind->charity_address, "3HFPNAjesiBY5sSVUmuBFnMEGut69R49ca"); + break; + case 3: sprintf(coind->charity_address, "37jLjjfUXQU4bdqVzvpUXyzAqPQSmxyByi"); + break; + } + ++npayees; + available -= charity_amount; + strcpy(payee_address, coind->charity_address); + base58_decode(payee_address, script_payee); + sprintf(payees, "%02x", npayees); + strcat(templ->coinb2, payees); + if (templ->has_segwit_txs) strcat(templ->coinb2, commitment); + char echarity_amount[32]; + encode_tx_value(echarity_amount, charity_amount); + strcat(templ->coinb2, echarity_amount); + char coinb2_part[1024] = { 0 }; + char coinb2_len[3] = { 0 }; + sprintf(coinb2_part, "a9%02x%s87", (unsigned int)(strlen(script_payee) >> 1) & 0xFF, script_payee); + sprintf(coinb2_len, "%02x", (unsigned int)(strlen(coinb2_part) >> 1) & 0xFF); + strcat(templ->coinb2, coinb2_len); + strcat(templ->coinb2, coinb2_part); + if (masternodes_enabled && masternode_payments) { + //duplicated: revisit ++todo + const char *payee = json_get_string(json_result, "payee"); + json_int_t amount = json_get_int(json_result, "payee_amount"); + if (payee && amount) { + available -= amount; + base58_decode(payee, script_payee); + job_pack_tx(coind, templ->coinb2, amount, script_payee); + } + } + job_pack_tx(coind, templ->coinb2, available, NULL); + strcat(templ->coinb2, "00000000"); // locktime + + coind->reward = (double)available / 100000000 * coind->reward_mul; + return; + } // 2 txs are required on these coins, one for foundation (dev fees) if(coind->charity_percent) From 77e2624db13c941a237affe9e881cc648bb80173 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Fri, 16 Mar 2018 11:03:54 +0100 Subject: [PATCH 065/195] stratum: drop STAK unused vars + git file mode fix --- stratum/coinbase.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) mode change 100755 => 100644 stratum/coinbase.cpp diff --git a/stratum/coinbase.cpp b/stratum/coinbase.cpp old mode 100755 new mode 100644 index c417430..4b99ef2 --- a/stratum/coinbase.cpp +++ b/stratum/coinbase.cpp @@ -146,9 +146,7 @@ void coinbase_create(YAAMP_COIND *coind, YAAMP_JOB_TEMPLATE *templ, json_value * sprintf(coind->charity_address, "Dcur2mcGjmENx4DhNqDctW5wJCVyT3Qeqkx"); } else if(strcmp(coind->symbol, "STAK") == 0) { - char script_dests[1024] = { 0 }; - char script_payee[1024]; - char payee_address[1024]; + char script_payee[512] = { 0 }; char payees[4]; int npayees = (templ->has_segwit_txs) ? 2 : 1; bool masternode_payments = json_get_bool(json_result, "masternode_payments"); @@ -177,8 +175,7 @@ void coinbase_create(YAAMP_COIND *coind, YAAMP_JOB_TEMPLATE *templ, json_value * } ++npayees; available -= charity_amount; - strcpy(payee_address, coind->charity_address); - base58_decode(payee_address, script_payee); + base58_decode(coind->charity_address, script_payee); sprintf(payees, "%02x", npayees); strcat(templ->coinb2, payees); if (templ->has_segwit_txs) strcat(templ->coinb2, commitment); From 1b3f15fef3c42379cd3955d1ea1216167cc5e38d Mon Sep 17 00:00:00 2001 From: exmac Date: Mon, 19 Mar 2018 19:27:31 +0100 Subject: [PATCH 066/195] Add yescryptR32 (#247) YescryptR32 for coin WAVI https://bitcointalk.org/index.php?topic=3146751.0 Tested on : https://lpool.name/pool/WAVI --- stratum/algos/yescrypt-opt.c | 3 +++ stratum/algos/yescrypt.c | 5 +++++ stratum/algos/yescrypt.h | 1 + stratum/config.sample/yescryptR32.conf | 15 +++++++++++++++ stratum/stratum.cpp | 1 + web/yaamp/core/functions/yaamp.php | 4 ++++ 6 files changed, 29 insertions(+) create mode 100644 stratum/config.sample/yescryptR32.conf diff --git a/stratum/algos/yescrypt-opt.c b/stratum/algos/yescrypt-opt.c index b65cdd2..c96190b 100644 --- a/stratum/algos/yescrypt-opt.c +++ b/stratum/algos/yescrypt-opt.c @@ -942,6 +942,9 @@ yescrypt_kdf(const yescrypt_shared_t * shared, yescrypt_local_t * local, { HMAC_SHA256_CTX_Y ctx; HMAC_SHA256_Init_Y(&ctx, buf, buflen); + if (r == 32) { // yescryptR32 + HMAC_SHA256_Update_Y(&ctx, "WaviBanana", 10); + } else if (r == 16) { // yescryptR16 HMAC_SHA256_Update_Y(&ctx, "Client Key", 10); } diff --git a/stratum/algos/yescrypt.c b/stratum/algos/yescrypt.c index 9fac019..1501745 100644 --- a/stratum/algos/yescrypt.c +++ b/stratum/algos/yescrypt.c @@ -368,3 +368,8 @@ void yescryptR16_hash(const char *input, char *output, uint32_t len) { yescrypt_bsty((uint8_t*)input, len, (uint8_t*)input, len, 4096, 16, 1, (uint8_t*)output, 32); } + +void yescryptR32_hash(const char *input, char *output, uint32_t len) +{ + yescrypt_bsty((uint8_t*)input, len, (uint8_t*)input, len, 4096, 32, 1, (uint8_t*)output, 32); +} diff --git a/stratum/algos/yescrypt.h b/stratum/algos/yescrypt.h index f7dac48..8e87c7b 100644 --- a/stratum/algos/yescrypt.h +++ b/stratum/algos/yescrypt.h @@ -40,6 +40,7 @@ extern "C" { void yescrypt_hash(const char* input, char* output, uint32_t len); void yescryptR16_hash(const char* input, char* output, uint32_t len); +void yescryptR32_hash(const char* input, char* output, uint32_t len); /** * crypto_scrypt(passwd, passwdlen, salt, saltlen, N, r, p, buf, buflen): diff --git a/stratum/config.sample/yescryptR32.conf b/stratum/config.sample/yescryptR32.conf new file mode 100644 index 0000000..7494625 --- /dev/null +++ b/stratum/config.sample/yescryptR32.conf @@ -0,0 +1,15 @@ +[TCP] +server = yaamp.com +port = 6343 +password = tu8tu5 + +[SQL] +host = yaampdb +database = yaamp +username = root +password = patofpaq + +[STRATUM] +algo = yescryptR32 +difficulty = 1 +max_ttf = 400000000 diff --git a/stratum/stratum.cpp b/stratum/stratum.cpp index 382a165..0e8e5ba 100644 --- a/stratum/stratum.cpp +++ b/stratum/stratum.cpp @@ -165,6 +165,7 @@ YAAMP_ALGO g_algos[] = {"skein2", skein2_hash, 1, 0, 0}, {"yescrypt", yescrypt_hash, 0x10000, 0, 0}, {"yescryptR16", yescryptR16_hash, 0x10000, 0, 0 }, + {"yescryptR32", yescryptR32_hash, 0x10000, 0, 0 }, {"zr5", zr5_hash, 1, 0, 0}, {"a5a", a5a_hash, 0x10000, 0, 0}, diff --git a/web/yaamp/core/functions/yaamp.php b/web/yaamp/core/functions/yaamp.php index 98e63cd..95d3e32 100755 --- a/web/yaamp/core/functions/yaamp.php +++ b/web/yaamp/core/functions/yaamp.php @@ -58,6 +58,7 @@ function yaamp_get_algos() 'velvet', 'yescrypt', 'yescryptR16', + 'yescryptR32', 'whirlpool', 'zr5', ); @@ -113,6 +114,7 @@ function yaamp_get_algo_norm($algo) 'whirlpool' => 1.0, 'yescrypt' => 1.0, 'yescryptR16' => 1.0, + 'yescryptR32' => 1.0, 'zr5' => 1.0, ); @@ -178,6 +180,7 @@ function getAlgoColors($algo) 'whirlpool' => '#d0e0e0', 'yescrypt' => '#e0d0e0', 'yescryptR16' => '#e2d0e2', + 'yescryptR32' => '#e2d0d2', 'zr5' => '#d0b0d0', 'MN' => '#ffffff', // MasterNode Earnings @@ -244,6 +247,7 @@ function getAlgoPort($algo) 'velvet' => 6133, 'yescrypt' => 6233, 'yescryptR16' => 6333, + 'yescryptR32' => 6343, 'bastion' => 6433, 'hsr' => 7433, 'phi' => 8333, From e5dd766dd5de57044f1db11e6f1b8d334b235600 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Sat, 24 Mar 2018 07:59:52 +0100 Subject: [PATCH 067/195] backend: avoid to clear earnings during payouts (#249) + simplify payment code based on RavenMinerPool commit --- web/yaamp/core/backend/payment.php | 6 ++++-- web/yaamp/modules/thread/CronjobController.php | 11 ++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/web/yaamp/core/backend/payment.php b/web/yaamp/core/backend/payment.php index 7a5eaa5..b3704ea 100644 --- a/web/yaamp/core/backend/payment.php +++ b/web/yaamp/core/backend/payment.php @@ -171,17 +171,19 @@ function BackendCoinPayments($coin) if(!$user) continue; if(!isset($addresses[$user->username])) continue; + $payment_amount = bitcoinvaluetoa($addresses[$user->username]); + $payout = new db_payouts; $payout->account_id = $user->id; $payout->time = time(); - $payout->amount = bitcoinvaluetoa($user->balance*$coef); + $payout->amount = $payment_amount; $payout->fee = 0; $payout->idcoin = $coin->id; if ($payout->save()) { $payouts[$payout->id] = $user->id; - $user->balance = bitcoinvaluetoa(floatval($user->balance) - (floatval($user->balance)*$coef)); + $user->balance = bitcoinvaluetoa(floatval($user->balance) - $payment_amount); $user->save(); } } diff --git a/web/yaamp/modules/thread/CronjobController.php b/web/yaamp/modules/thread/CronjobController.php index 4af3982..fc8a2a3 100644 --- a/web/yaamp/modules/thread/CronjobController.php +++ b/web/yaamp/modules/thread/CronjobController.php @@ -57,8 +57,10 @@ class CronjobController extends CommonController dborun("update jobs set active=false"); BackendBlockFind1(); - BackendClearEarnings(); - BackendRentingUpdate(); + if(!memcache_get($this->memcache->memcache, 'balances_locked')) { + BackendClearEarnings(); + BackendRentingUpdate(); + } BackendProcessList(); BackendBlocksUpdate(); @@ -209,10 +211,13 @@ class CronjobController extends CommonController sleep(10); BackendDoBackup(); - memcache_set($this->memcache->memcache, 'apache_locked', false); + // prevent user balances changes during payments (blocks thread) + memcache_set($this->memcache->memcache, 'balances_locked', true); BackendPayments(); + memcache_set($this->memcache->memcache, 'balances_locked', false); + BackendCleanDatabase(); // BackendOptimizeTables(); From 9c438eeb946dc5a3f5ac60490458e76337d9be2f Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Sat, 24 Mar 2018 22:01:10 +0100 Subject: [PATCH 068/195] backend: protect also balances from renting clear + set an expiration to memcache lock, payment unlikely fails, but... --- web/yaamp/modules/thread/CronjobController.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/web/yaamp/modules/thread/CronjobController.php b/web/yaamp/modules/thread/CronjobController.php index fc8a2a3..a05ebcd 100644 --- a/web/yaamp/modules/thread/CronjobController.php +++ b/web/yaamp/modules/thread/CronjobController.php @@ -59,8 +59,8 @@ class CronjobController extends CommonController BackendBlockFind1(); if(!memcache_get($this->memcache->memcache, 'balances_locked')) { BackendClearEarnings(); - BackendRentingUpdate(); } + BackendRentingUpdate(); BackendProcessList(); BackendBlocksUpdate(); @@ -85,7 +85,7 @@ class CronjobController extends CommonController MonitorBTC(); $last = memcache_get($this->memcache->memcache, 'last_renting_payout2'); - if($last + 5*60 < time()) + if($last + 5*60 < time() && !memcache_get($this->memcache->memcache, 'balances_locked')) { memcache_set($this->memcache->memcache, 'last_renting_payout2', time()); BackendRentingPayout(); @@ -214,7 +214,7 @@ class CronjobController extends CommonController memcache_set($this->memcache->memcache, 'apache_locked', false); // prevent user balances changes during payments (blocks thread) - memcache_set($this->memcache->memcache, 'balances_locked', true); + memcache_set($this->memcache->memcache, 'balances_locked', true, 0, 300); BackendPayments(); memcache_set($this->memcache->memcache, 'balances_locked', false); From 2d0a2df4807bef32d42fcf45841a43941f98396e Mon Sep 17 00:00:00 2001 From: Tanariel Date: Sun, 25 Mar 2018 13:09:26 +0300 Subject: [PATCH 069/195] emulate getinfo for wallets who copy bitcoin mistakes (#250) like vertcoin 0.12... for sure its more efficient sigh --- .gitignore | 2 ++ web/yaamp/core/rpc/wallet-rpc.php | 31 ++++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 29a8aeb..ee8ea02 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,5 @@ web/serverconfig.php web/assets/ *.rej *.orig +.idea/* +web/yaamp/.idea/ \ No newline at end of file diff --git a/web/yaamp/core/rpc/wallet-rpc.php b/web/yaamp/core/rpc/wallet-rpc.php index f5b77c4..70104fb 100644 --- a/web/yaamp/core/rpc/wallet-rpc.php +++ b/web/yaamp/core/rpc/wallet-rpc.php @@ -7,6 +7,7 @@ class WalletRPC { public $type = 'Bitcoin'; protected $rpc; protected $rpc_wallet; + protected $hasGetInfo = false; // cache protected $account; @@ -42,6 +43,7 @@ class WalletRPC { default: $this->type = 'Bitcoin'; $this->rpc = new Bitcoin($coin->rpcuser, $coin->rpcpasswd, $coin->rpchost, $coin->rpcport, $url); + $this->hasGetInfo = $coin->hasgetinfo; } } else { @@ -377,7 +379,34 @@ class WalletRPC { } // Bitcoin RPC - $res = $this->rpc->__call($method,$params); + switch ($method) { + case 'getinfo': + if ($this->hasGetInfo) { + $res = $this->rpc->__call($method,$params); + } else { + $miningInfo = $this->rpc->getmininginfo(); + $res["blocks"] = arraySafeVal($miningInfo,"blocks"); + $res["difficulty"] = arraySafeVal($miningInfo,"difficulty"); + $res["testnet"] = "main" != arraySafeVal($miningInfo,"chain"); + $walletInfo = $this->rpc->getwalletinfo(); + $res["walletversion"] = arraySafeVal($walletInfo,"walletversion"); + $res["balance"] = arraySafeVal($walletInfo,"balance"); + $res["keypoololdest"] = arraySafeVal($walletInfo,"keypoololdest"); + $res["keypoolsize"] = arraySafeVal($walletInfo,"keypoolsize"); + $res["paytxfee"] = arraySafeVal($walletInfo,"paytxfee"); + $networkInfo = $this->rpc->getnetworkinfo(); + $res["version"] = arraySafeVal($networkInfo,"version"); + $res["protocolversion"] = arraySafeVal($networkInfo,"protocolversion"); + $res["timeoffset"] = arraySafeVal($networkInfo,"timeoffset"); + $res["connections"] = arraySafeVal($networkInfo,"connections"); +// $res["proxy"] = arraySafeVal($networkInfo,"networks")[0]["proxy"]; + $res["relayfee"] = arraySafeVal($networkInfo,"relayfee"); + } + break; + default: + $res = $this->rpc->__call($method,$params); + } + $this->error = $this->rpc->error; return $res; } From 2ad138591e12e5ea8d95bd325e5b4af1afd7e3bf Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Mon, 26 Mar 2018 05:55:06 +0200 Subject: [PATCH 070/195] x12 algo + GCH multi-algos definition --- stratum/algos/makefile | 2 +- stratum/algos/x12.c | 85 +++++++++++++++++++++++++++++ stratum/algos/x12.h | 16 ++++++ stratum/config.sample/x12.conf | 16 ++++++ stratum/stratum.cpp | 1 + stratum/stratum.h | 1 + web/yaamp/core/functions/yaamp.php | 3 + web/yaamp/modules/explorer/util.php | 5 ++ 8 files changed, 128 insertions(+), 1 deletion(-) create mode 100644 stratum/algos/x12.c create mode 100644 stratum/algos/x12.h create mode 100644 stratum/config.sample/x12.conf diff --git a/stratum/algos/makefile b/stratum/algos/makefile index b684b87..e61b7da 100644 --- a/stratum/algos/makefile +++ b/stratum/algos/makefile @@ -9,7 +9,7 @@ CFLAGS= $(CXXFLAGS) -std=gnu99 LDFLAGS=-O2 -lgmp SOURCES=lyra2re.c lyra2v2.c Lyra2.c lyra2z.c Lyra2z.c Sponge.c \ - blake.c scrypt.c c11.c x11.c x13.c sha256.c sha256t.c jha.c keccak.c deep.c tribus.c \ + blake.c scrypt.c c11.c x11.c x12.c x13.c sha256.c sha256t.c jha.c keccak.c deep.c tribus.c \ hsr14.c sm3.c \ x14.c x15.c x17.c nist5.c fresh.c quark.c neoscrypt.c scryptn.c qubit.c skein.c groestl.c \ bitcore.c timetravel.c x16r.c xevan.c bastion.c hmq17.c \ diff --git a/stratum/algos/x12.c b/stratum/algos/x12.c new file mode 100644 index 0000000..07346a1 --- /dev/null +++ b/stratum/algos/x12.c @@ -0,0 +1,85 @@ +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +void x12_hash(const char* input, char* output, uint32_t len) +{ + sph_blake512_context ctx_blake; + sph_bmw512_context ctx_bmw; + sph_luffa512_context ctx_luffa; + sph_cubehash512_context ctx_cubehash; + sph_shavite512_context ctx_shavite; + sph_simd512_context ctx_simd; + sph_echo512_context ctx_echo; + sph_groestl512_context ctx_groestl; + sph_skein512_context ctx_skein; + sph_jh512_context ctx_jh; + sph_keccak512_context ctx_keccak; + sph_hamsi512_context ctx_hamsi; + + uint32_t hash[16]; + + sph_blake512_init(&ctx_blake); + sph_blake512(&ctx_blake, input, len); + sph_blake512_close(&ctx_blake, hash); + + sph_bmw512_init(&ctx_bmw); + sph_bmw512(&ctx_bmw, hash, 64); + sph_bmw512_close(&ctx_bmw, hash); + + sph_luffa512_init(&ctx_luffa); + sph_luffa512(&ctx_luffa, hash, 64); + sph_luffa512_close(&ctx_luffa, hash); + + sph_cubehash512_init(&ctx_cubehash); + sph_cubehash512(&ctx_cubehash, hash, 64); + sph_cubehash512_close(&ctx_cubehash, hash); + + sph_shavite512_init(&ctx_shavite); + sph_shavite512(&ctx_shavite, hash, 64); + sph_shavite512_close(&ctx_shavite, hash); + + sph_simd512_init(&ctx_simd); + sph_simd512(&ctx_simd, hash, 64); + sph_simd512_close(&ctx_simd, hash); + + sph_echo512_init(&ctx_echo); + sph_echo512(&ctx_echo, hash, 64); + sph_echo512_close(&ctx_echo, hash); + + sph_groestl512_init(&ctx_groestl); + sph_groestl512(&ctx_groestl, hash, 64); + sph_groestl512_close(&ctx_groestl, hash); + + sph_skein512_init(&ctx_skein); + sph_skein512(&ctx_skein, hash, 64); + sph_skein512_close(&ctx_skein, hash); + + sph_jh512_init(&ctx_jh); + sph_jh512(&ctx_jh, hash, 64); + sph_jh512_close(&ctx_jh, hash); + + sph_keccak512_init(&ctx_keccak); + sph_keccak512(&ctx_keccak, hash, 64); + sph_keccak512_close(&ctx_keccak, hash); + + sph_hamsi512_init(&ctx_hamsi); + sph_hamsi512(&ctx_hamsi, hash, 64); + sph_hamsi512_close(&ctx_hamsi, hash); + + memcpy(output, hash, 32); +} diff --git a/stratum/algos/x12.h b/stratum/algos/x12.h new file mode 100644 index 0000000..1b7ee98 --- /dev/null +++ b/stratum/algos/x12.h @@ -0,0 +1,16 @@ +#ifndef X12_H +#define X12_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +void x12_hash(const char* input, char* output, uint32_t len); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/stratum/config.sample/x12.conf b/stratum/config.sample/x12.conf new file mode 100644 index 0000000..6bce44a --- /dev/null +++ b/stratum/config.sample/x12.conf @@ -0,0 +1,16 @@ +[TCP] +server = yaamp.com +port = 3233 +password = tu8tu5 + +[SQL] +host = yaampdb +database = yaamp +username = root +password = patofpaq + +[STRATUM] +algo = x12 +difficulty = 0.008 +max_ttf = 50000 + diff --git a/stratum/stratum.cpp b/stratum/stratum.cpp index 0e8e5ba..f9757c0 100644 --- a/stratum/stratum.cpp +++ b/stratum/stratum.cpp @@ -115,6 +115,7 @@ YAAMP_ALGO g_algos[] = {"c11", c11_hash, 1, 0, 0}, {"x11", x11_hash, 1, 0, 0}, + {"x12", x12_hash, 1, 0, 0}, {"x13", x13_hash, 1, 0, 0}, {"x14", x14_hash, 1, 0, 0}, {"x15", x15_hash, 1, 0, 0}, diff --git a/stratum/stratum.h b/stratum/stratum.h index cb9f9dd..d244948 100644 --- a/stratum/stratum.h +++ b/stratum/stratum.h @@ -150,6 +150,7 @@ void sha256_double_hash_hex(const char *input, char *output, unsigned int len); #include "algos/c11.h" #include "algos/x11.h" #include "algos/x11evo.h" +#include "algos/x12.h" #include "algos/x13.h" #include "algos/x14.h" #include "algos/x15.h" diff --git a/web/yaamp/core/functions/yaamp.php b/web/yaamp/core/functions/yaamp.php index 95d3e32..b1f23f9 100755 --- a/web/yaamp/core/functions/yaamp.php +++ b/web/yaamp/core/functions/yaamp.php @@ -35,6 +35,7 @@ function yaamp_get_algos() 'c11', 'x11', 'x11evo', + 'x12', 'x13', 'x14', 'x15', @@ -137,6 +138,7 @@ function getAlgoColors($algo) 'deep' => '#e0ffff', 'x11' => '#f0f0a0', 'x11evo' => '#c0f0c0', + 'x12' => '#ffe090', 'x13' => '#ffd880', 'x14' => '#f0c080', 'x15' => '#f0b080', @@ -206,6 +208,7 @@ function getAlgoPort($algo) 'deep' => 3535, 'x11' => 3533, 'x11evo' => 3553, + 'x12' => 3233, 'x13' => 3633, 'x15' => 3733, 'x16r' => 3636, diff --git a/web/yaamp/modules/explorer/util.php b/web/yaamp/modules/explorer/util.php index fb66eaf..172a7e4 100644 --- a/web/yaamp/modules/explorer/util.php +++ b/web/yaamp/modules/explorer/util.php @@ -165,6 +165,9 @@ function versionToAlgo($coin, $version) 7 =>'nist5', 8 =>'myr-gr', 9=>'penta', 10=>'whirlpool', 11=>'luffa', 12=>'keccak', 13=>'quark', 15=>'bastion' ); + $algos['GCH'] = array( + 0=>'x12', 1=>'x11', 2=>'x13', 3=>'sha256', 4=>'blake2s' + ); $algos['RICHX'] = array( 0=>'sha256', 1=>'scrypt', 2=>'myr-gr', 3=>'skein', 4=>'qubit' ); @@ -182,6 +185,8 @@ function versionToAlgo($coin, $version) if ($symbol == 'J') return arraySafeVal($algos[$symbol], $version, ''); + else if($symbol == 'GCH') + return arraySafeVal($algos[$symbol], ($version - 9), ''); else if($symbol == 'XVG') return arraySafeVal($algos[$symbol], ($version >> 11), 'scrypt'); else if (isset($algos[$symbol])) From 20de9ab7747a89d2ff0f258990829cb3b918296f Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Mon, 26 Mar 2018 10:27:07 +0200 Subject: [PATCH 071/195] markets: handle cryptohub api, but only manually their api is not complete enough to auto create the markets... --- web/yaamp/core/backend/markets.php | 43 +++++++++++++++++ web/yaamp/core/exchange/cryptohub.php | 68 +++++++++++++++++++++++++++ web/yaamp/core/exchange/exchange.php | 3 ++ 3 files changed, 114 insertions(+) create mode 100644 web/yaamp/core/exchange/cryptohub.php diff --git a/web/yaamp/core/backend/markets.php b/web/yaamp/core/backend/markets.php index 2db5e05..e044c76 100644 --- a/web/yaamp/core/backend/markets.php +++ b/web/yaamp/core/backend/markets.php @@ -23,6 +23,7 @@ function BackendPricesUpdate() updateAlcurexMarkets(); updateBinanceMarkets(); updateBterMarkets(); + updateCryptohubMarkets(); //updateEmpoexMarkets(); updateJubiMarkets(); updateLiveCoinMarkets(); @@ -1165,6 +1166,48 @@ function updateBterMarkets() } } +function updateCryptohubMarkets() +{ + $exchange = 'cryptohub'; + if (exchange_get($exchange, 'disabled')) return; + + $markets = cryptohub_api_query('market/ticker'); + if(!is_array($markets)) return; + + $list = getdbolist('db_markets', "name='$exchange'"); + foreach($list as $market) + { + $coin = getdbo('db_coins', $market->coinid); + if(!$coin) continue; + + $symbol = $coin->getOfficialSymbol(); + if (market_get($exchange, $symbol, "disabled")) { + $market->disabled = 1; + $market->message = 'disabled from settings'; + $market->save(); + continue; + } + + $dbpair = 'BTC'.'_'.$symbol; + foreach ($markets as $pair => $ticker) { + if ($pair != $dbpair) continue; + $price2 = ($ticker['highestBid']+$ticker['lowestAsk'])/2; + $market->price = AverageIncrement($market->price, $ticker['highestBid']); + $market->price2 = AverageIncrement($market->price2, $price2); + $market->pricetime = time(); + //if ($market->disabled < 9) $market->disabled = (floatval($ticker['baseVolume']) < 0.01); + $market->save(); + + if (empty($coin->price2)) { + $coin->price = $market->price; + $coin->price2 = $market->price2; + $coin->market = $exchange; + $coin->save(); + } + } + } +} + function updateEmpoexMarkets() { $exchange = 'empoex'; diff --git a/web/yaamp/core/exchange/cryptohub.php b/web/yaamp/core/exchange/cryptohub.php new file mode 100644 index 0000000..6111724 --- /dev/null +++ b/web/yaamp/core/exchange/cryptohub.php @@ -0,0 +1,68 @@ +$symbol)); + if(!$coin) return false; + $pair = $symbol; + $market = getdbosql('db_markets', "coinid={$coin->id} AND name='$exchange'"); + if(!$market) return false; + + } else if (is_object($market)) { + + $coin = getdbo('db_coins', $market->coinid); + if(!$coin) return false; + $symbol = $coin->getOfficialSymbol(); + $pair = $symbol; + if (!empty($market->base_coin)) $pair = $market->base_coin.'_'.$symbol; + } + + $t1 = microtime(true); + $ticker = cryptohub_api_query("market/ticker",$pair); + if(!$ticker || empty($ticker)) return false; + $ticker = array_pop($ticker); + if(arraySafeVal($ticker,'highestBid') === NULL) { + debuglog("$exchange: invalid data received for $pair ticker"); + return false; + } + + $price2 = ((double) $ticker['highestBid'] + $ticker['lowestAsk']) / 2; + $market->price2 = AverageIncrement($market->price2, $price2); + $market->price = AverageIncrement($market->price, (double) $ticker['highestBid']); + if ($ticker['lowestAsk'] < $market->price) $market->price = $ticker['lowestAsk']; + $market->pricetime = time(); + $market->save(); + + $apims = round((microtime(true) - $t1)*1000,3); + user()->setFlash('message', "$exchange $symbol price updated in $apims ms"); + + return true; +} diff --git a/web/yaamp/core/exchange/exchange.php b/web/yaamp/core/exchange/exchange.php index fc2a983..d9b67dc 100644 --- a/web/yaamp/core/exchange/exchange.php +++ b/web/yaamp/core/exchange/exchange.php @@ -19,6 +19,7 @@ require_once("bleutrade.php"); require_once("ccexapi.php"); require_once("cexio.php"); require_once("cryptobridge.php"); +require_once("cryptohub.php"); require_once("kraken.php"); require_once("poloniex.php"); require_once("yobit.php"); @@ -93,6 +94,8 @@ function getMarketUrl($coin, $marketName) $url = "https://coinsmarkets.com/trade-{$base}-{$symbol}.htm"; else if($market == 'cryptobridge') $url = "https://wallet.crypto-bridge.org/market/BRIDGE.{$symbol}_BRIDGE.{$base}"; + else if($market == 'cryptohub') + $url = "https://cryptohub.online/market/{$symbol}/{$base}"; else if($market == 'cryptopia') $url = "https://www.cryptopia.co.nz/Exchange?market={$symbol}_{$base}"; else if($market == 'cryptowatch') From afa2e929a2e6bd59047131717a177babed128416 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Tue, 27 Mar 2018 01:46:57 +0200 Subject: [PATCH 072/195] markets: avoid useless api queries if exchange is not used --- web/yaamp/core/backend/markets.php | 74 ++++++++++++++++++++++++++---- 1 file changed, 64 insertions(+), 10 deletions(-) diff --git a/web/yaamp/core/backend/markets.php b/web/yaamp/core/backend/markets.php index e044c76..64adb5d 100644 --- a/web/yaamp/core/backend/markets.php +++ b/web/yaamp/core/backend/markets.php @@ -221,6 +221,9 @@ function updateBleutradeMarkets() $exchange = 'bleutrade'; if (exchange_get($exchange, 'disabled')) return; + $count = (int) dboscalar("SELECT count(id) FROM markets WHERE name LIKE '$exchange%'"); + if ($count == 0) return; + $list = bleutrade_api_query('public/getcurrencies'); if(!is_object($list)) return; @@ -288,6 +291,10 @@ function updateBleutradeMarkets() function updateCryptoBridgeMarkets($force = false) { $exchange = 'cryptobridge'; + if (exchange_get($exchange, 'disabled')) return; + + $count = (int) dboscalar("SELECT count(id) FROM markets WHERE name LIKE '$exchange%'"); + if ($count == 0) return; $result = cryptobridge_api_query('ticker'); if(!is_array($result)) return; @@ -330,6 +337,9 @@ function updateKrakenMarkets($force = false) $exchange = 'kraken'; if (exchange_get($exchange, 'disabled')) return; + $count = (int) dboscalar("SELECT count(id) FROM markets WHERE name LIKE '$exchange%'"); + if ($count == 0) return; + $result = kraken_api_query('AssetPairs'); if(!is_array($result)) return; @@ -394,6 +404,9 @@ function updateBittrexMarkets($force = false) $exchange = 'bittrex'; if (exchange_get($exchange, 'disabled')) return; + $count = (int) dboscalar("SELECT count(id) FROM markets WHERE name LIKE '$exchange%'"); + if ($count == 0) return; + $list = bittrex_api_query('public/getcurrencies'); if(!is_object($list)) return; foreach($list->result as $currency) @@ -474,6 +487,9 @@ function updateCCexMarkets() $exchange = 'c-cex'; if (exchange_get($exchange, 'disabled')) return; + $count = (int) dboscalar("SELECT count(id) FROM markets WHERE name LIKE '$exchange%'"); + if ($count == 0) return; + $ccex = new CcexAPI; $list = $ccex->getMarketSummaries(); if (!is_array($list)) return; @@ -561,6 +577,9 @@ function updatePoloniexMarkets() $exchange = 'poloniex'; if (exchange_get($exchange, 'disabled')) return; + $count = (int) dboscalar("SELECT count(id) FROM markets WHERE name LIKE '$exchange%'"); + if ($count == 0) return; + $poloniex = new poloniex; $tickers = $poloniex->get_ticker(); @@ -646,6 +665,9 @@ function updateYobitMarkets() $exchange = 'yobit'; if (exchange_get($exchange, 'disabled')) return; + $count = (int) dboscalar("SELECT count(id) FROM markets WHERE name LIKE '$exchange%'"); + if ($count == 0) return; + $res = yobit_api_query('info'); if(!is_object($res)) return; @@ -731,10 +753,12 @@ function updateJubiMarkets() $exchange = 'jubi'; if (exchange_get($exchange, 'disabled')) return; + $list = getdbolist('db_markets', "name LIKE '$exchange%'"); + if (empty($list)) return; + $btc = jubi_api_query('ticker', "?coin=btc"); if(!is_object($btc)) return; - $list = getdbolist('db_markets', "name='jubi'"); foreach($list as $market) { $coin = getdbo('db_coins', $market->coinid); @@ -776,10 +800,12 @@ function updateAlcurexMarkets() $exchange = 'alcurex'; if (exchange_get($exchange, 'disabled')) return; + $list = getdbolist('db_markets', "name LIKE '$exchange%'"); + if (empty($list)) return; + $data = alcurex_api_query('market', "?info=on"); if(!is_object($data)) return; - $list = getdbolist('db_markets', "name='$exchange'"); foreach($list as $market) { $coin = getdbo('db_coins', $market->coinid); @@ -828,10 +854,12 @@ function updateCryptopiaMarkets() $exchange = 'cryptopia'; if (exchange_get($exchange, 'disabled')) return; + $list = getdbolist('db_markets', "name LIKE '$exchange%'"); + if (empty($list)) return; + $data = cryptopia_api_query('GetMarkets', 24); if(!is_object($data)) return; - $list = getdbolist('db_markets', "name LIKE('$exchange%')"); foreach($list as $market) { $coin = getdbo('db_coins', $market->coinid); @@ -1088,10 +1116,12 @@ function updateBinanceMarkets() $exchange = 'binance'; if (exchange_get($exchange, 'disabled')) return; + $list = getdbolist('db_markets', "name LIKE '$exchange%'"); + if (empty($list)) return; + $tickers = binance_api_query('ticker/allBookTickers'); if(!is_array($tickers)) return; - $list = getdbolist('db_markets', "name='$exchange'"); foreach($list as $market) { $coin = getdbo('db_coins', $market->coinid); @@ -1130,10 +1160,12 @@ function updateBterMarkets() $exchange = 'bter'; if (exchange_get($exchange, 'disabled')) return; + $list = getdbolist('db_markets', "name LIKE '$exchange%'"); + if (empty($list)) return; + $markets = bter_api_query('tickers'); if(!is_array($markets)) return; - $list = getdbolist('db_markets', "name='$exchange'"); foreach($list as $market) { $coin = getdbo('db_coins', $market->coinid); @@ -1171,10 +1203,12 @@ function updateCryptohubMarkets() $exchange = 'cryptohub'; if (exchange_get($exchange, 'disabled')) return; + $list = getdbolist('db_markets', "name LIKE '$exchange%'"); + if (empty($list)) return; + $markets = cryptohub_api_query('market/ticker'); if(!is_array($markets)) return; - $list = getdbolist('db_markets', "name='$exchange'"); foreach($list as $market) { $coin = getdbo('db_coins', $market->coinid); @@ -1213,10 +1247,12 @@ function updateEmpoexMarkets() $exchange = 'empoex'; if (exchange_get($exchange, 'disabled')) return; + $list = getdbolist('db_markets', "name LIKE '$exchange%'"); + if (empty($list)) return; + $markets = empoex_api_query('marketinfo'); if(!is_array($markets)) return; - $list = getdbolist('db_markets', "name='$exchange'"); foreach($list as $market) { $coin = getdbo('db_coins', $market->coinid); @@ -1257,6 +1293,9 @@ function updateKuCoinMarkets() $exchange = 'kucoin'; if (exchange_get($exchange, 'disabled')) return; + $list = getdbolist('db_markets', "name LIKE '$exchange%'"); + if (empty($list)) return; + $markets = kucoin_api_query('open/symbols','market=BTC'); if(!kucoin_result_valid($markets) || empty($markets->data)) return; @@ -1265,7 +1304,6 @@ function updateKuCoinMarkets() $coininfo = NULL; } - $list = getdbolist('db_markets', "name='$exchange'"); foreach($list as $market) { $coin = getdbo('db_coins', $market->coinid); @@ -1314,10 +1352,12 @@ function updateLiveCoinMarkets() $exchange = 'livecoin'; if (exchange_get($exchange, 'disabled')) return; + $list = getdbolist('db_markets', "name LIKE '$exchange%'"); + if (empty($list)) return; + $markets = livecoin_api_query('exchange/ticker'); if(!is_array($markets)) return; - $list = getdbolist('db_markets', "name='$exchange'"); foreach($list as $market) { $coin = getdbo('db_coins', $market->coinid); @@ -1383,6 +1423,9 @@ function updateCoinExchangeMarkets() $exchange = 'coinexchange'; if (exchange_get($exchange, 'disabled')) return; + $count = (int) dboscalar("SELECT count(id) FROM markets WHERE name LIKE '$exchange%'"); + if ($count == 0) return; + $list = coinexchange_api_query('getmarkets'); if(!is_object($list)) return; $markets = coinexchange_api_query('getmarketsummaries'); @@ -1454,6 +1497,9 @@ function updateCoinsMarketsMarkets() $exchange = 'coinsmarkets'; if (exchange_get($exchange, 'disabled')) return; + $count = (int) dboscalar("SELECT count(id) FROM markets WHERE name LIKE '$exchange%'"); + if ($count == 0) return; + $list = coinsmarkets_api_query('apicoin'); if(empty($list) || !is_array($list)) return; foreach($list as $pair=>$data) @@ -1511,6 +1557,9 @@ function updateStocksExchangeMarkets() $exchange = 'stocksexchange'; if (exchange_get($exchange, 'disabled')) return; + $count = (int) dboscalar("SELECT count(id) FROM markets WHERE name LIKE '$exchange%'"); + if ($count == 0) return; + $list = stocksexchange_api_query('ticker'); if(empty($list) || !is_array($list)) return; foreach($list as $m) @@ -1558,6 +1607,9 @@ function updateTradeSatoshiMarkets() $exchange = 'tradesatoshi'; if (exchange_get($exchange, 'disabled')) return; + $count = (int) dboscalar("SELECT count(id) FROM markets WHERE name LIKE '$exchange%'"); + if ($count == 0) return; + $data = tradesatoshi_api_query('getmarketsummaries'); if(!is_object($data) || !$data->success || !is_array($data->result)) return; foreach($data->result as $m) @@ -1605,10 +1657,12 @@ function updateShapeShiftMarkets() $exchange = 'shapeshift'; if (exchange_get($exchange, 'disabled')) return; + $list = getdbolist('db_markets', "name LIKE '$exchange%'"); + if (empty($list)) return; + $markets = shapeshift_api_query('marketinfo'); if(!is_array($markets) || empty($markets)) return; - $list = getdbolist('db_markets', "name='$exchange'"); foreach($list as $market) { $coin = getdbo('db_coins', $market->coinid); From a954c13b36a85b642274e7de62e020cea884ebb6 Mon Sep 17 00:00:00 2001 From: opensourcerulez Date: Thu, 29 Mar 2018 03:49:37 +0300 Subject: [PATCH 073/195] x16s algo, shuffle variant (#251) see https://bitcointalk.org/?topic=3208091.0 for more explanations --- stratum/algos/makefile | 2 +- stratum/algos/x16s.c | 180 +++++++++++++++++++++++++++++ stratum/algos/x16s.h | 16 +++ stratum/stratum.h | 1 + web/yaamp/core/functions/yaamp.php | 3 + 5 files changed, 201 insertions(+), 1 deletion(-) create mode 100644 stratum/algos/x16s.c create mode 100644 stratum/algos/x16s.h diff --git a/stratum/algos/makefile b/stratum/algos/makefile index e61b7da..815c7eb 100644 --- a/stratum/algos/makefile +++ b/stratum/algos/makefile @@ -12,7 +12,7 @@ SOURCES=lyra2re.c lyra2v2.c Lyra2.c lyra2z.c Lyra2z.c Sponge.c \ blake.c scrypt.c c11.c x11.c x12.c x13.c sha256.c sha256t.c jha.c keccak.c deep.c tribus.c \ hsr14.c sm3.c \ x14.c x15.c x17.c nist5.c fresh.c quark.c neoscrypt.c scryptn.c qubit.c skein.c groestl.c \ - bitcore.c timetravel.c x16r.c xevan.c bastion.c hmq17.c \ + bitcore.c timetravel.c x16r.c x16s.c xevan.c bastion.c hmq17.c \ skein2.c zr5.c bmw.c luffa.c pentablake.c whirlpool.c whirlpoolx.c blakecoin.c \ blake2.c \ yescrypt.c yescrypt-opt.c sha256_Y.c lbry.c \ diff --git a/stratum/algos/x16s.c b/stratum/algos/x16s.c new file mode 100644 index 0000000..6247b69 --- /dev/null +++ b/stratum/algos/x16s.c @@ -0,0 +1,180 @@ +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "common.h" + +enum Algo { + BLAKE = 0, + BMW, + GROESTL, + JH, + KECCAK, + SKEIN, + LUFFA, + CUBEHASH, + SHAVITE, + SIMD, + ECHO, + HAMSI, + FUGUE, + SHABAL, + WHIRLPOOL, + SHA512, + HASH_FUNC_COUNT +}; + +static void getAlgoString(const uint8_t* prevblock, char *output) +{ + strcpy(output, "0123456789ABCDEF"); + + for(int i = 0; i < 16; i++){ + uint8_t b = (15 - i) >> 1; // 16 ascii hex chars, reversed + uint8_t algoDigit = (i & 1) ? prevblock[b] & 0xF : prevblock[b] >> 4; + + int offset = algoDigit; + // insert the nth character at the front + char oldVal = output[offset]; + for(int j=offset; j-->0;) { + output[j+1] = output[j]; + } + output[0] = oldVal; + } +} + +void x16s_hash(const char* input, char* output, uint32_t len) +{ + uint32_t hash[64/4]; + char hashOrder[HASH_FUNC_COUNT + 1] = { 0 }; + + sph_blake512_context ctx_blake; + sph_bmw512_context ctx_bmw; + sph_groestl512_context ctx_groestl; + sph_skein512_context ctx_skein; + sph_jh512_context ctx_jh; + sph_keccak512_context ctx_keccak; + sph_luffa512_context ctx_luffa; + sph_cubehash512_context ctx_cubehash; + sph_shavite512_context ctx_shavite; + sph_simd512_context ctx_simd; + sph_echo512_context ctx_echo; + sph_hamsi512_context ctx_hamsi; + sph_fugue512_context ctx_fugue; + sph_shabal512_context ctx_shabal; + sph_whirlpool_context ctx_whirlpool; + sph_sha512_context ctx_sha512; + + void *in = (void*) input; + int size = len; + + getAlgoString(&input[4], hashOrder); + + for (int i = 0; i < 16; i++) + { + const char elem = hashOrder[i]; + const uint8_t algo = elem >= 'A' ? elem - 'A' + 10 : elem - '0'; + + switch (algo) { + case BLAKE: + sph_blake512_init(&ctx_blake); + sph_blake512(&ctx_blake, in, size); + sph_blake512_close(&ctx_blake, hash); + break; + case BMW: + sph_bmw512_init(&ctx_bmw); + sph_bmw512(&ctx_bmw, in, size); + sph_bmw512_close(&ctx_bmw, hash); + break; + case GROESTL: + sph_groestl512_init(&ctx_groestl); + sph_groestl512(&ctx_groestl, in, size); + sph_groestl512_close(&ctx_groestl, hash); + break; + case SKEIN: + sph_skein512_init(&ctx_skein); + sph_skein512(&ctx_skein, in, size); + sph_skein512_close(&ctx_skein, hash); + break; + case JH: + sph_jh512_init(&ctx_jh); + sph_jh512(&ctx_jh, in, size); + sph_jh512_close(&ctx_jh, hash); + break; + case KECCAK: + sph_keccak512_init(&ctx_keccak); + sph_keccak512(&ctx_keccak, in, size); + sph_keccak512_close(&ctx_keccak, hash); + break; + case LUFFA: + sph_luffa512_init(&ctx_luffa); + sph_luffa512(&ctx_luffa, in, size); + sph_luffa512_close(&ctx_luffa, hash); + break; + case CUBEHASH: + sph_cubehash512_init(&ctx_cubehash); + sph_cubehash512(&ctx_cubehash, in, size); + sph_cubehash512_close(&ctx_cubehash, hash); + break; + case SHAVITE: + sph_shavite512_init(&ctx_shavite); + sph_shavite512(&ctx_shavite, in, size); + sph_shavite512_close(&ctx_shavite, hash); + break; + case SIMD: + sph_simd512_init(&ctx_simd); + sph_simd512(&ctx_simd, in, size); + sph_simd512_close(&ctx_simd, hash); + break; + case ECHO: + sph_echo512_init(&ctx_echo); + sph_echo512(&ctx_echo, in, size); + sph_echo512_close(&ctx_echo, hash); + break; + case HAMSI: + sph_hamsi512_init(&ctx_hamsi); + sph_hamsi512(&ctx_hamsi, in, size); + sph_hamsi512_close(&ctx_hamsi, hash); + break; + case FUGUE: + sph_fugue512_init(&ctx_fugue); + sph_fugue512(&ctx_fugue, in, size); + sph_fugue512_close(&ctx_fugue, hash); + break; + case SHABAL: + sph_shabal512_init(&ctx_shabal); + sph_shabal512(&ctx_shabal, in, size); + sph_shabal512_close(&ctx_shabal, hash); + break; + case WHIRLPOOL: + sph_whirlpool_init(&ctx_whirlpool); + sph_whirlpool(&ctx_whirlpool, in, size); + sph_whirlpool_close(&ctx_whirlpool, hash); + break; + case SHA512: + sph_sha512_init(&ctx_sha512); + sph_sha512(&ctx_sha512,(const void*) in, size); + sph_sha512_close(&ctx_sha512,(void*) hash); + break; + } + in = (void*) hash; + size = 64; + } + memcpy(output, hash, 32); +} diff --git a/stratum/algos/x16s.h b/stratum/algos/x16s.h new file mode 100644 index 0000000..ec9201c --- /dev/null +++ b/stratum/algos/x16s.h @@ -0,0 +1,16 @@ +#ifndef X16S_H +#define X16S_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +void x16s_hash(const char* input, char* output, uint32_t len); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/stratum/stratum.h b/stratum/stratum.h index d244948..d8638fb 100644 --- a/stratum/stratum.h +++ b/stratum/stratum.h @@ -155,6 +155,7 @@ void sha256_double_hash_hex(const char *input, char *output, unsigned int len); #include "algos/x14.h" #include "algos/x15.h" #include "algos/x16r.h" +#include "algos/x16s.h" #include "algos/x17.h" #include "algos/xevan.h" #include "algos/hmq17.h" diff --git a/web/yaamp/core/functions/yaamp.php b/web/yaamp/core/functions/yaamp.php index b1f23f9..f2e855f 100755 --- a/web/yaamp/core/functions/yaamp.php +++ b/web/yaamp/core/functions/yaamp.php @@ -40,6 +40,7 @@ function yaamp_get_algos() 'x14', 'x15', 'x16r', + 'x16s', 'x17', 'xevan', 'groestl', // dmd-gr -m 256 (deprecated) @@ -143,6 +144,7 @@ function getAlgoColors($algo) 'x14' => '#f0c080', 'x15' => '#f0b080', 'x16r' => '#f0b080', + 'x16s' => '#f0b080', 'x17' => '#f0b0a0', 'xevan' => '#f0b0a0', 'argon2' => '#e0d0e0', @@ -212,6 +214,7 @@ function getAlgoPort($algo) 'x13' => 3633, 'x15' => 3733, 'x16r' => 3636, + 'x16s' => 3666, 'x17' => 3737, 'xevan' => 3739, 'hmq1725' => 3747, From 5bb898f651939a6c8a4fff8fc589ef7ca2f8846e Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Thu, 29 Mar 2018 02:53:55 +0200 Subject: [PATCH 074/195] small x16s fixes, and stratum sample --- stratum/algos/x16s.c | 2 +- stratum/config.sample/x16s.conf | 16 ++++++++++++++++ stratum/stratum.cpp | 1 + web/yaamp/core/functions/yaamp.php | 2 +- 4 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 stratum/config.sample/x16s.conf diff --git a/stratum/algos/x16s.c b/stratum/algos/x16s.c index 6247b69..d3f3291 100644 --- a/stratum/algos/x16s.c +++ b/stratum/algos/x16s.c @@ -43,7 +43,7 @@ enum Algo { static void getAlgoString(const uint8_t* prevblock, char *output) { - strcpy(output, "0123456789ABCDEF"); + strcpy(output, "0123456789ABCDEF"); for(int i = 0; i < 16; i++){ uint8_t b = (15 - i) >> 1; // 16 ascii hex chars, reversed diff --git a/stratum/config.sample/x16s.conf b/stratum/config.sample/x16s.conf new file mode 100644 index 0000000..d71d25e --- /dev/null +++ b/stratum/config.sample/x16s.conf @@ -0,0 +1,16 @@ +[TCP] +server = yaamp.com +port = 3663 +password = tu8tu5 + +[SQL] +host = yaampdb +database = yaamp +username = root +password = patofpaq + +[STRATUM] +algo = x16s +difficulty = 0.25 +max_ttf = 50000 + diff --git a/stratum/stratum.cpp b/stratum/stratum.cpp index f9757c0..65a14de 100644 --- a/stratum/stratum.cpp +++ b/stratum/stratum.cpp @@ -125,6 +125,7 @@ YAAMP_ALGO g_algos[] = {"xevan", xevan_hash, 0x100, 0, 0}, {"x16r", x16r_hash, 0x100, 0, 0}, + {"x16s", x16s_hash, 0x100, 0, 0}, {"timetravel", timetravel_hash, 0x100, 0, 0}, {"bitcore", timetravel10_hash, 0x100, 0, 0}, {"hsr", hsr_hash, 1, 0, 0}, diff --git a/web/yaamp/core/functions/yaamp.php b/web/yaamp/core/functions/yaamp.php index f2e855f..896ea76 100755 --- a/web/yaamp/core/functions/yaamp.php +++ b/web/yaamp/core/functions/yaamp.php @@ -214,7 +214,7 @@ function getAlgoPort($algo) 'x13' => 3633, 'x15' => 3733, 'x16r' => 3636, - 'x16s' => 3666, + 'x16s' => 3663, 'x17' => 3737, 'xevan' => 3739, 'hmq1725' => 3747, From 31441a6c98889574bbb6260909c18af22f9d6100 Mon Sep 17 00:00:00 2001 From: Jia Wu Date: Sat, 31 Mar 2018 23:01:17 -0400 Subject: [PATCH 075/195] markets: handle graviex ticker (#252) manual only, so market row need to be created manually if really required. --- web/yaamp/core/backend/markets.php | 47 ++++++++++++++++++++++++++++ web/yaamp/core/exchange/exchange.php | 3 ++ web/yaamp/core/exchange/graviex.php | 23 ++++++++++++++ 3 files changed, 73 insertions(+) create mode 100644 web/yaamp/core/exchange/graviex.php diff --git a/web/yaamp/core/backend/markets.php b/web/yaamp/core/backend/markets.php index 64adb5d..b882272 100644 --- a/web/yaamp/core/backend/markets.php +++ b/web/yaamp/core/backend/markets.php @@ -14,6 +14,7 @@ function BackendPricesUpdate() updatePoloniexMarkets(); updateBleutradeMarkets(); updateCryptoBridgeMarkets(); + updateGraviexMarkets(); updateKrakenMarkets(); updateKuCoinMarkets(); updateCCexMarkets(); @@ -332,6 +333,52 @@ function updateCryptoBridgeMarkets($force = false) ///////////////////////////////////////////////////////////////////////////////////////////// +function updateGraviexMarkets($force = false) +{ + $exchange = 'graviex'; + if (exchange_get($exchange, 'disabled')) return; + + $list = getdbolist('db_markets', "name LIKE '$exchange%'"); + if (empty($list)) return; + + $markets = graviex_api_query('tickers'); + if(!is_array($markets)) return; + + foreach($list as $market) + { + $coin = getdbo('db_coins', $market->coinid); + if(!$coin) continue; + + $symbol = $coin->getOfficialSymbol(); + if (market_get($exchange, $symbol, "disabled")) { + $market->disabled = 1; + $market->message = 'disabled from settings'; + $market->save(); + continue; + } + + $symbol = strtolower($symbol); + $dbpair = $symbol.'btc'; + foreach ($markets as $pair => $ticker) { + if ($pair != $dbpair) continue; + $price2 = ($ticker['ticker']['high']+$ticker['ticker']['low'])/2; + $market->price = AverageIncrement($market->price, $ticker['ticker']['high']); + $market->price2 = AverageIncrement($market->price2, $price2); + $market->pricetime = time(); + $market->save(); + + if (empty($coin->price2)) { + $coin->price = $market->price; + $coin->price2 = $market->price2; + $coin->market = $exchange; + $coin->save(); + } + } + } +} + +///////////////////////////////////////////////////////////////////////////////////////////// + function updateKrakenMarkets($force = false) { $exchange = 'kraken'; diff --git a/web/yaamp/core/exchange/exchange.php b/web/yaamp/core/exchange/exchange.php index d9b67dc..1684cfc 100644 --- a/web/yaamp/core/exchange/exchange.php +++ b/web/yaamp/core/exchange/exchange.php @@ -19,6 +19,7 @@ require_once("bleutrade.php"); require_once("ccexapi.php"); require_once("cexio.php"); require_once("cryptobridge.php"); +require_once("graviex.php"); require_once("cryptohub.php"); require_once("kraken.php"); require_once("poloniex.php"); @@ -104,6 +105,8 @@ function getMarketUrl($coin, $marketName) $url = "https://c-cex.com/?p={$lowsymbol}-{$lowbase}"; else if($market == 'empoex') $url = "http://www.empoex.com/trade/{$symbol}-{$base}"; + else if($market == 'graviex') + $url = "https://graviex.net/api/v2/tickers/{$symbol}{$base}"; else if($market == 'jubi') $url = "http://jubi.com/coin/{$lowsymbol}"; else if($market == 'hitbtc') diff --git a/web/yaamp/core/exchange/graviex.php b/web/yaamp/core/exchange/graviex.php new file mode 100644 index 0000000..befffda --- /dev/null +++ b/web/yaamp/core/exchange/graviex.php @@ -0,0 +1,23 @@ + Date: Tue, 3 Apr 2018 11:49:30 +0200 Subject: [PATCH 076/195] trading: auto set bittrex and bleutrade withdraw tx fee --- web/yaamp/core/backend/rawcoins.php | 18 ++++++++++++++---- web/yaamp/core/trading/bittrex_trading.php | 2 +- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/web/yaamp/core/backend/rawcoins.php b/web/yaamp/core/backend/rawcoins.php index 067d0de..1f6c5fa 100644 --- a/web/yaamp/core/backend/rawcoins.php +++ b/web/yaamp/core/backend/rawcoins.php @@ -22,21 +22,31 @@ function updateRawcoins() if (!exchange_get('bittrex', 'disabled')) { $list = bittrex_api_query('public/getcurrencies'); - if(isset($list->result)) + if(isset($list->result) && !empty($list->result)) { dborun("UPDATE markets SET deleted=true WHERE name='bittrex'"); - foreach($list->result as $currency) + foreach($list->result as $currency) { + if ($currency->Currency == 'BTC') { + exchange_set('bittrex', 'withdraw_fee_btc', $currency->TxFee); + continue; + } updateRawCoin('bittrex', $currency->Currency, $currency->CurrencyLong); + } } } if (!exchange_get('bleutrade', 'disabled')) { $list = bleutrade_api_query('public/getcurrencies'); - if(isset($list->result)) + if(isset($list->result) && !empty($list->result)) { dborun("UPDATE markets SET deleted=true WHERE name='bleutrade'"); - foreach($list->result as $currency) + foreach($list->result as $currency) { + if ($currency->Currency == 'BTC') { + exchange_set('bleutrade', 'withdraw_fee_btc', $currency->TxFee); + continue; + } updateRawCoin('bleutrade', $currency->Currency, $currency->CurrencyLong); + } } } diff --git a/web/yaamp/core/trading/bittrex_trading.php b/web/yaamp/core/trading/bittrex_trading.php index 8f67cec..2ce73f2 100644 --- a/web/yaamp/core/trading/bittrex_trading.php +++ b/web/yaamp/core/trading/bittrex_trading.php @@ -236,7 +236,7 @@ function doBittrexTrading($quick=false) } $withdraw_min = exchange_get($exchange, 'withdraw_min_btc', EXCH_AUTO_WITHDRAW); - $withdraw_fee = exchange_get($exchange, 'withdraw_fee_btc', 0.001); + $withdraw_fee = exchange_get($exchange, 'withdraw_fee_btc', 0.0005); if($withdraw_min > 0 && $savebalance->balance >= ($withdraw_min + $withdraw_fee)) { // $btcaddr = exchange_get($exchange, 'withdraw_btc_address', YAAMP_BTCADDRESS); From 580801f3991b35fd533d988bb73ec34e29e434f7 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Tue, 10 Apr 2018 10:05:53 +0200 Subject: [PATCH 077/195] benchs: unique function to format devices labels + some new devices chips rules --- web/yaamp/core/backend/bench.php | 9 +++++++++ web/yaamp/modules/bench/devices.php | 6 +----- web/yaamp/modules/bench/functions.php | 16 ++++++++++++++++ web/yaamp/modules/bench/index.php | 12 +++++------- 4 files changed, 31 insertions(+), 12 deletions(-) diff --git a/web/yaamp/core/backend/bench.php b/web/yaamp/core/backend/bench.php index dce1e7c..54e4627 100644 --- a/web/yaamp/core/backend/bench.php +++ b/web/yaamp/core/backend/bench.php @@ -17,6 +17,8 @@ function BenchUpdateChips() // bug in nvml 378.x and 381.x (linux + win) fixed in 382.05 dborun("UPDATE benchmarks SET realfreq=NULL WHERE realfreq<=200 AND driver LIKE '% 378.%'"); dborun("UPDATE benchmarks SET realfreq=NULL WHERE realfreq<=200 AND driver LIKE '% 381.%'"); + // sanity check on long fields (no html wanted) + dborun("DELETE FROM benchmarks WHERE device LIKE '%<%' OR client LIKE '%<%'"); $benchs = getdbolist('db_benchmarks', "IFNULL(chip,'')=''"); foreach ($benchs as $bench) { @@ -27,6 +29,13 @@ function BenchUpdateChips() continue; } + $rawdata = json_encode($bench->attributes); + if (strpos($rawdata,"script")) { + debuglog("bench record deleted : $rawdata"); + $bench->delete(); + continue; + } + $dups = getdbocount('db_benchmarks', "vendorid=:vid AND client=:client AND os=:os AND driver=:drv AND throughput=:thr AND userid=:uid", array(':vid'=>$bench->vendorid, ':client'=>$bench->client, ':os'=>$bench->os, ':drv'=>$bench->driver,':thr'=>$bench->throughput,':uid'=>$bench->userid) ); diff --git a/web/yaamp/modules/bench/devices.php b/web/yaamp/modules/bench/devices.php index 5bc76d3..68174ee 100644 --- a/web/yaamp/modules/bench/devices.php +++ b/web/yaamp/modules/bench/devices.php @@ -105,11 +105,7 @@ foreach ($in_db as $row) { $chip = CHtml::link($chip, '/bench?chip='.$row['idchip'].'&algo=all'); } echo ''.$chip.''; - - if ($row['type'] == 'gpu') - echo ''.$row['device'].getProductIdSuffix($row).''; - else - echo ''.formatCPU($row).''; + echo ''.formatDevice($row).''; if (substr($vendorid,0,4) == '10de') echo ''.$vendorid.''; diff --git a/web/yaamp/modules/bench/functions.php b/web/yaamp/modules/bench/functions.php index 9e67a95..84b3e45 100644 --- a/web/yaamp/modules/bench/functions.php +++ b/web/yaamp/modules/bench/functions.php @@ -140,6 +140,20 @@ function formatCPU($row) return trim($device); } +function formatGPU($row) +{ + $label = $row['device'].getProductIdSuffix($row); + return strip_tags($label); +} + +function formatDevice($row) +{ + if ($row['type'] == 'gpu') + return formatGPU($row); + else + return formatCPU($row); +} + function getChipName($row) { if ($row['type'] == 'cpu') { @@ -179,6 +193,8 @@ function getChipName($row) $chip = str_replace('650 Ti BOOST','650 Ti', $chip); $chip = str_replace('760 Ti OEM','760 Ti', $chip); $chip = str_replace(' (Pascal)',' Pascal', $chip); + $chip = str_replace('Quadro M6000 24GB','Quadro M6000', $chip); + $chip = str_replace('Tesla P100 (PCIe)','Tesla P100', $chip); $chip = str_replace('Tesla P100-SXM2-16GB','Tesla P100', $chip); $chip = str_replace('Tesla P100-PCIE-16GB','Tesla P100', $chip); $chip = str_replace('Tesla V100-SXM2-16GB','Tesla V100', $chip); diff --git a/web/yaamp/modules/bench/index.php b/web/yaamp/modules/bench/index.php index f45cd6e..1546dfc 100644 --- a/web/yaamp/modules/bench/index.php +++ b/web/yaamp/modules/bench/index.php @@ -144,14 +144,12 @@ foreach ($db_rows as $row) { echo ''.CHtml::link($row['algo'],'/bench?algo='.$row['algo']).''; echo ''.$age.''; echo ''.($row['idchip'] ? CHtml::link($row['chip'],'/bench?chip='.$row['idchip']) : $row['chip']).''; - if ($row['type'] == 'cpu') { - echo ''.formatCPU($row).''; - echo ''.CHtml::link($row['vendorid'],'/bench?vid='.$row['vendorid']).''; - echo ''.$row['arch'].''; - } else { - echo ''.$row['device'].getProductIdSuffix($row).''; - echo ''.CHtml::link($row['vendorid'],'/bench?vid='.$row['vendorid']).''; + echo ''.formatDevice($row).''; + echo ''.CHtml::link($row['vendorid'],'/bench?vid='.$row['vendorid']).''; + if ($row['type'] == 'gpu') { echo ''.formatCudaArch($row['arch']).''; + } else { + echo ''.$row['arch'].''; } echo ''.$hashrate.''; From 60fb627ad909fbef7ede75613567099c622108b3 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Tue, 10 Apr 2018 11:03:01 +0200 Subject: [PATCH 078/195] security: be more strict with algo param --- web/yaamp/core/common/util.php | 6 ++++++ web/yaamp/modules/site/SiteController.php | 6 +++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/web/yaamp/core/common/util.php b/web/yaamp/core/common/util.php index d494035..6bc6462 100644 --- a/web/yaamp/core/common/util.php +++ b/web/yaamp/core/common/util.php @@ -54,6 +54,12 @@ function getiparam($p,$default=0) return isset($_REQUEST[$p]) ? intval($_REQUEST[$p]) : $default; } +function getalgoparam() +{ + $algo = strip_tags(substr(getparam('algo'), 0, 32)); + return $algo; +} + ////////////////////////////////////////////////////// function downloadFile($url, &$size) diff --git a/web/yaamp/modules/site/SiteController.php b/web/yaamp/modules/site/SiteController.php index e4c265d..80cf6a5 100644 --- a/web/yaamp/modules/site/SiteController.php +++ b/web/yaamp/modules/site/SiteController.php @@ -1077,7 +1077,7 @@ class SiteController extends CommonController $this->goback(); } - public function actionCancelorder() + public function actionCancelorder() { if(!$this->admin) return; $order = getdbo('db_orders', getiparam('id')); @@ -1091,7 +1091,7 @@ class SiteController extends CommonController public function actionAlgo() { - $algo = substr(getparam('algo'), 0, 32); + $algo = getalgoparam(); $a = getdbosql('db_algos', "name=:name", array(':name'=>$algo)); if($a) @@ -1108,7 +1108,7 @@ class SiteController extends CommonController public function actionGomining() { - $algo = substr(getparam('algo'), 0, 32); + $algo = getalgoparam(); if ($algo == 'all') { return; } From e97ea63c61755d0823d80f8ca6802d81f0577a6e Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Tue, 10 Apr 2018 11:22:14 +0200 Subject: [PATCH 079/195] security: protect XSS seekers from their own hacks --- web/yaamp/modules/renting/login.php | 3 +++ web/yaamp/modules/site/wallet.php | 4 ++++ web/yaamp/modules/trading/index.php | 3 +++ 3 files changed, 10 insertions(+) diff --git a/web/yaamp/modules/renting/login.php b/web/yaamp/modules/renting/login.php index 5f4cc6d..e7ad453 100644 --- a/web/yaamp/modules/renting/login.php +++ b/web/yaamp/modules/renting/login.php @@ -13,6 +13,9 @@ $this->widget('UniForm'); $address = getparam('address'); if($address == 0) $address = ''; +if (!empty($address) && preg_match('/[^A-Za-z0-9]/', $address)) { + die; +} echo <<getState('yaamp-wallet'); +if (!empty($wallet) && preg_match('/[^A-Za-z0-9]/', $wallet)) { + die; +} $user = getuserparam($wallet); $algo_unit = 'Mh'; From 5b91a559f9d14e2e7218a7a1121f2c90442dac30 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Tue, 10 Apr 2018 15:47:48 +0200 Subject: [PATCH 080/195] stratum: do more checks on stats device names --- stratum/db.cpp | 15 ++++++++++++++- web/yaamp/core/functions/yaamp.php | 2 +- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/stratum/db.cpp b/stratum/db.cpp index 3b34415..f8c513c 100644 --- a/stratum/db.cpp +++ b/stratum/db.cpp @@ -55,6 +55,19 @@ char *db_clean_string(YAAMP_DB *db, char *string) return string; } +// allow more chars without the most hurting ones (bench device names) +static void clean_html(char* string) +{ + char *c = string; + size_t i, len = strlen(string) & 0x1FF; + for (i = 0; i < len; i++) { + if (c[i] == '<' || c[i] == '>' || c[i] == '%' || c[i] == '\\' || c[i] == '"' || c[i] == '\'') { + c[i] = '\0'; break; + } + } + if (strstr(string, "script")) strcpy(string, ""); +} + void db_query(YAAMP_DB *db, const char *format, ...) { va_list arglist; @@ -536,7 +549,7 @@ static void _json_str_safe(YAAMP_DB *db, json_value *json, const char *key, size char escaped[256] = { 0 }; snprintf(str, sizeof(str)-1, "%s", json_string_value(val)); str[maxlen-1] = '\0'; // truncate to dest len - //db_clean_string(db, str); + clean_html(str); mysql_real_escape_string(&db->mysql, escaped, str, strlen(str)); snprintf(out, maxlen, "%s", escaped); out[maxlen-1] = '\0'; diff --git a/web/yaamp/core/functions/yaamp.php b/web/yaamp/core/functions/yaamp.php index 896ea76..0a9d691 100755 --- a/web/yaamp/core/functions/yaamp.php +++ b/web/yaamp/core/functions/yaamp.php @@ -278,7 +278,7 @@ function getAlgoPort($algo) function yaamp_fee($algo) { $fee = controller()->memcache->get("yaamp_fee-$algo"); - if($fee) return $fee; + if($fee && is_numeric($fee)) return (float) $fee; /* $norm = yaamp_get_algo_norm($algo); if($norm == 0) $norm = 1; From e6a731cf19fd74fef76f9f44577eb7e161f003e2 Mon Sep 17 00:00:00 2001 From: crackfoo Date: Wed, 11 Apr 2018 10:52:57 -0300 Subject: [PATCH 081/195] explorer: add multi-algo support for ARG explorer (#254) --- web/yaamp/modules/explorer/util.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/web/yaamp/modules/explorer/util.php b/web/yaamp/modules/explorer/util.php index 172a7e4..39ce81f 100644 --- a/web/yaamp/modules/explorer/util.php +++ b/web/yaamp/modules/explorer/util.php @@ -180,6 +180,9 @@ function versionToAlgo($coin, $version) $algos['XVG'] = array( 0=>'scrypt', 1=>'scrypt', 2=>'myr-gr', 3=>'x17', 4=>'blake2s', 10=>'lyra2v2', ); + $algos['ARG'] = array( + 0=>'sha256', 1=>'scrypt', 2=>'lyra2v2', 3=>'myr-gr', 4=>'argon2d', 5=>'yescrypt', + ); $symbol = $coin->symbol; if (!empty($coin->symbol2)) $symbol = $coin->symbol2; From ea59f8a53b926f234b7c0f78d9dcb4b8a89d4fcc Mon Sep 17 00:00:00 2001 From: Jia Wu Date: Thu, 19 Apr 2018 04:20:20 -0400 Subject: [PATCH 082/195] Fix graviex market url (#257) --- web/yaamp/core/exchange/exchange.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/yaamp/core/exchange/exchange.php b/web/yaamp/core/exchange/exchange.php index 1684cfc..6dd88c5 100644 --- a/web/yaamp/core/exchange/exchange.php +++ b/web/yaamp/core/exchange/exchange.php @@ -106,7 +106,7 @@ function getMarketUrl($coin, $marketName) else if($market == 'empoex') $url = "http://www.empoex.com/trade/{$symbol}-{$base}"; else if($market == 'graviex') - $url = "https://graviex.net/api/v2/tickers/{$symbol}{$base}"; + $url = "https://graviex.net/markets/{$lowsymbol}{$lowbase}"; else if($market == 'jubi') $url = "http://jubi.com/coin/{$lowsymbol}"; else if($market == 'hitbtc') From 99f1fa9ac05e37bc5139a8f4ac47943c87489d3c Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Fri, 20 Apr 2018 08:48:02 +0200 Subject: [PATCH 083/195] graviex: use the right ticker bid/ask fields --- web/yaamp/core/backend/markets.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/web/yaamp/core/backend/markets.php b/web/yaamp/core/backend/markets.php index b882272..7541bce 100644 --- a/web/yaamp/core/backend/markets.php +++ b/web/yaamp/core/backend/markets.php @@ -361,8 +361,8 @@ function updateGraviexMarkets($force = false) $dbpair = $symbol.'btc'; foreach ($markets as $pair => $ticker) { if ($pair != $dbpair) continue; - $price2 = ($ticker['ticker']['high']+$ticker['ticker']['low'])/2; - $market->price = AverageIncrement($market->price, $ticker['ticker']['high']); + $price2 = ($ticker['ticker']['buy']+$ticker['ticker']['sell'])/2; + $market->price = AverageIncrement($market->price, $ticker['ticker']['buy']); $market->price2 = AverageIncrement($market->price2, $price2); $market->pricetime = time(); $market->save(); From dd9b467ecb91d6c98280140b4eeeeef495c3b6d7 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Fri, 20 Apr 2018 17:34:55 +0200 Subject: [PATCH 084/195] config: new server var to disable autocreation of coins --- web/serverconfig.sample.php | 3 ++- web/yaamp/core/backend/rawcoins.php | 6 +++++- web/yaamp/defaultconfig.php | 3 ++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/web/serverconfig.sample.php b/web/serverconfig.sample.php index 59b4a7f..0a8d2e0 100644 --- a/web/serverconfig.sample.php +++ b/web/serverconfig.sample.php @@ -36,7 +36,8 @@ define('YAAMP_SITE_NAME', 'YiiMP'); define('YAAMP_ADMIN_EMAIL', 'yiimp@spam.la'); define('YAAMP_ADMIN_IP', ''); // samples: "80.236.118.26,90.234.221.11" or "10.0.0.1/8" define('YAAMP_ADMIN_WEBCONSOLE', true); -define('YAAMP_NOTIFY_NEW_COINS', true); +define('YAAMP_CREATE_NEW_COINS', true); +define('YAAMP_NOTIFY_NEW_COINS', false); define('YAAMP_DEFAULT_ALGO', 'x11'); define('YAAMP_USE_NGINX', false); diff --git a/web/yaamp/core/backend/rawcoins.php b/web/yaamp/core/backend/rawcoins.php index 1f6c5fa..fbd96a6 100644 --- a/web/yaamp/core/backend/rawcoins.php +++ b/web/yaamp/core/backend/rawcoins.php @@ -382,7 +382,7 @@ function updateRawCoin($marketname, $symbol, $name='unknown') if($symbol == 'BTC') return; $coin = getdbosql('db_coins', "symbol=:symbol", array(':symbol'=>$symbol)); - if(!$coin && $marketname != 'yobit') + if(!$coin && YAAMP_CREATE_NEW_COINS) { $algo = ''; if ($marketname == 'cryptopia') { @@ -405,6 +405,10 @@ function updateRawCoin($marketname, $symbol, $name='unknown') return; } + // some other to ignore... + if (in_array($marketname, array('yobit','kucoin'))) + return; + if (market_get($marketname, $symbol, "disabled")) { return; } diff --git a/web/yaamp/defaultconfig.php b/web/yaamp/defaultconfig.php index 195eb21..589c11e 100644 --- a/web/yaamp/defaultconfig.php +++ b/web/yaamp/defaultconfig.php @@ -55,7 +55,8 @@ if (!defined('YAAMP_ADMIN_EMAIL')) define('YAAMP_ADMIN_EMAIL', 'yiimp@spam.la'); if (!defined('YAAMP_ADMIN_IP')) define('YAAMP_ADMIN_IP', '127.0.0.1'); if (!defined('YAAMP_ADMIN_WEBCONSOLE')) define('YAAMP_ADMIN_WEBCONSOLE', true); -if (!defined('YAAMP_NOTIFY_NEW_COINS')) define('YAAMP_NOTIFY_NEW_COINS', true); +if (!defined('YAAMP_CREATE_NEW_COINS')) define('YAAMP_CREATE_NEW_COINS', true); +if (!defined('YAAMP_NOTIFY_NEW_COINS')) define('YAAMP_NOTIFY_NEW_COINS', false); if (!defined('YAAMP_LIMIT_ESTIMATE')) define('YAAMP_LIMIT_ESTIMATE', false); if (!defined('YAAMP_RENTAL')) define('YAAMP_RENTAL', false); From 10be25ee8287eea02f5f0ff9ccdb308235bd143d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Nov=C3=BD?= Date: Sun, 22 Apr 2018 04:25:40 +0200 Subject: [PATCH 085/195] stratum: correctly create blocks with 253-255 transactions (#260) According to [1], varints of 0xfd to 0xff are prefixed with 0xfd too. [1]: http://learnmeabitcoin.com/glossary/varint --- stratum/client_submit.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stratum/client_submit.cpp b/stratum/client_submit.cpp index 47dfd0f..78fc94c 100644 --- a/stratum/client_submit.cpp +++ b/stratum/client_submit.cpp @@ -215,7 +215,7 @@ static void client_do_submit(YAAMP_CLIENT *client, YAAMP_JOB *job, YAAMP_JOB_VAL if(hash_int <= coin_target) { char count_hex[8] = { 0 }; - if (templ->txcount <= 255) + if (templ->txcount <= 252) sprintf(count_hex, "%02x", templ->txcount & 0xFF); else sprintf(count_hex, "fd%02x%02x", templ->txcount & 0xFF, templ->txcount >> 8); From b22b599b3e826e30299cf4170897bd963a893cad Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Mon, 23 Apr 2018 15:52:24 +0200 Subject: [PATCH 086/195] explorer: only allow hexa chars in query params --- web/yaamp/core/common/util.php | 7 +++++++ .../modules/explorer/ExplorerController.php | 20 +++++++++---------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/web/yaamp/core/common/util.php b/web/yaamp/core/common/util.php index 6bc6462..999d897 100644 --- a/web/yaamp/core/common/util.php +++ b/web/yaamp/core/common/util.php @@ -40,6 +40,13 @@ function getparam($p,$default='') return isset($_REQUEST[$p]) ? $_REQUEST[$p] : $default; } +function gethexparam($p,$default='') +{ + $str = getparam($p, NULL); + $hex = (is_string($str) && ctype_xdigit($str)) ? $str : $default; + return $hex; +} + function getiparam($p,$default=0) { // workaround for yii default /route/ .... diff --git a/web/yaamp/modules/explorer/ExplorerController.php b/web/yaamp/modules/explorer/ExplorerController.php index c165007..cfa1925 100644 --- a/web/yaamp/modules/explorer/ExplorerController.php +++ b/web/yaamp/modules/explorer/ExplorerController.php @@ -59,8 +59,8 @@ class ExplorerController extends CommonController $coin = getdbo('db_coins', $id); if($coin && $coin->no_explorer) { $link = $coin->link_explorer; - //$txid = getparam('txid'); - //$hash = getparam('hash'); + //$txid = gethexparam('txid'); + //$hash = gethexparam('hash'); //if (!empty($txid)) $link .= 'tx/'.$txid; //elseif (!empty($hash)) $link .= 'block/'.$hash; die("Block explorer disabled, please use $link"); @@ -71,11 +71,11 @@ class ExplorerController extends CommonController $remote = new WalletRPC($coin); $hash = $remote->getblockhash(intval($height)); } else { - $hash = getparam('hash'); + $hash = gethexparam('hash'); } - $txid = getparam('txid'); - $q = getparam('q'); + $txid = gethexparam('txid'); + $q = gethexparam('q'); if (strlen($q) >= 32 && ctype_xdigit($q)) { $remote = new WalletRPC($coin); $block = $remote->getblock($q); @@ -87,7 +87,7 @@ class ExplorerController extends CommonController } } - if($coin && !empty($txid) && ctype_xdigit($txid)) + if($coin && !empty($txid)) { $remote = new WalletRPC($coin); $tx = $remote->getrawtransaction($txid, 1); @@ -96,7 +96,7 @@ class ExplorerController extends CommonController $hash = arraySafeVal($tx,'blockhash'); } - if($coin && !empty($hash) && ctype_xdigit($hash)) + if($coin && !empty($hash)) $this->render('block', array('coin'=>$coin, 'hash'=>$hash)); else if($coin) @@ -116,9 +116,9 @@ class ExplorerController extends CommonController public function actionSearch() { $height = getiparam('height'); - $txid = arraySafeVal($_REQUEST,'txid'); - $hash = arraySafeVal($_REQUEST,'hash'); - $q = arraySafeVal($_REQUEST,'q'); + $txid = gethexparam('txid'); + $hash = gethexparam('hash'); + $q = gethexparam('q'); if (isset($_GET['SYM'])) { // only for visible coins $url = "/explorer/".$_GET['SYM']."?"; From b517afb571033c7c912901ff5aa4785a222abbab Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Sun, 29 Apr 2018 18:41:12 +0200 Subject: [PATCH 087/195] dashboard: some cleanup, remove unused state --- web/yaamp/modules/site/common_results.php | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/web/yaamp/modules/site/common_results.php b/web/yaamp/modules/site/common_results.php index fb88841..88abe8b 100644 --- a/web/yaamp/modules/site/common_results.php +++ b/web/yaamp/modules/site/common_results.php @@ -507,20 +507,13 @@ function cronstate2text($state) } } -//$state_block = $this->memcache->get('cronjob_block_state'); -$state_main = $this->memcache->get('cronjob_main_state'); +$state_main = (int) $this->memcache->get('cronjob_main_state'); $btc = getdbosql('db_coins', "symbol='BTC'"); if (!$btc) $btc = json_decode('{"id": 6, "balance": 0}'); echo ''; for($i=0; $i<10; $i++) { -// if($i != $state_block-1 && $state_block>0) -// { -// $state = $this->memcache->get("cronjob_block_state_$i"); -// if($state) echo "block $i "; -// } - if($i != $state_main-1 && $state_main>0) { $state = $this->memcache->get("cronjob_main_state_$i"); From 1bfec2be32acdeb5119875d59f8ad8d88570e782 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Tue, 1 May 2018 15:03:59 +0200 Subject: [PATCH 088/195] stratum: precheck addresses are valid base58 --- stratum/base58.cpp | 16 ++++++++++++++++ stratum/client.cpp | 6 +++++- stratum/util.h | 1 + 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/stratum/base58.cpp b/stratum/base58.cpp index 856683e..631fde0 100644 --- a/stratum/base58.cpp +++ b/stratum/base58.cpp @@ -96,3 +96,19 @@ bool base58_decode(const char *input, char *output) return true; } + +bool is_base58(char *input) +{ + // All alphanumeric characters except "0", "O", "I" and "l" + size_t i=0, len = strlen(input); + char *c = input; + while (i < len) { + bool isdigit = (c[i] >= '1' && c[i] <= '9'); + bool isalpha = (c[i] >= 'a' && c[i] <= 'z') || (c[i] >= 'A' && c[i] <= 'Z'); + if (!isdigit && !isalpha) return false; + if (c[i] == 'I' || c[i] == 'O' || c[i] == 'l') return false; + i++; + } + return true; +} + diff --git a/stratum/client.cpp b/stratum/client.cpp index bdc6bb2..60a0d9b 100644 --- a/stratum/client.cpp +++ b/stratum/client.cpp @@ -256,8 +256,12 @@ bool client_authorize(YAAMP_CLIENT *client, json_value *json_params) CommonUnlock(&g_db_mutex); } + bool is_bad_address = !is_base58(client->username); // when auto exchange is disabled, only authorize good wallet address... - if (!g_autoexchange && !client_validate_user_address(client)) { + if (!g_autoexchange && !client_validate_user_address(client)) + is_bad_address = true; + + if (is_bad_address) { clientlog(client, "bad mining address %s", client->username); client_send_result(client, "false"); diff --git a/stratum/util.h b/stratum/util.h index 7afdd1b..bf57bfd 100644 --- a/stratum/util.h +++ b/stratum/util.h @@ -74,6 +74,7 @@ string merkle_with_first(vector steps, string f); ////////////////////////////////////////////////////////////////////////// bool base58_decode(const char *input, char *output); +bool is_base58(char *input); void base64_encode(char *base64, const char *normal); void base64_decode(char *normal, const char *base64); From 138b0079bb2c78930aad106ce691d3a733dca6f3 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Tue, 1 May 2018 15:34:01 +0200 Subject: [PATCH 089/195] stratum: pre-check bad usernames before db add --- stratum/client.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/stratum/client.cpp b/stratum/client.cpp index 60a0d9b..6f0c9d5 100644 --- a/stratum/client.cpp +++ b/stratum/client.cpp @@ -229,6 +229,11 @@ bool client_authorize(YAAMP_CLIENT *client, json_value *json_params) } } + if (!is_base58(client->username)) { + clientlog(client, "bad mining address %s", client->username); + return false; + } + bool reset = client_initialize_multialgo(client); if(reset) return false; @@ -256,12 +261,8 @@ bool client_authorize(YAAMP_CLIENT *client, json_value *json_params) CommonUnlock(&g_db_mutex); } - bool is_bad_address = !is_base58(client->username); // when auto exchange is disabled, only authorize good wallet address... - if (!g_autoexchange && !client_validate_user_address(client)) - is_bad_address = true; - - if (is_bad_address) { + if (!g_autoexchange && !client_validate_user_address(client)) { clientlog(client, "bad mining address %s", client->username); client_send_result(client, "false"); From 078ace3a6503cd80d638492dcb0922363476c4fa Mon Sep 17 00:00:00 2001 From: crackfoo Date: Wed, 2 May 2018 09:10:39 -0300 Subject: [PATCH 090/195] stratum: log ip of new clients (#262) --- stratum/user.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stratum/user.cpp b/stratum/user.cpp index 29bf045..1e2ec6c 100644 --- a/stratum/user.cpp +++ b/stratum/user.cpp @@ -108,8 +108,8 @@ void db_add_user(YAAMP_DB *db, YAAMP_CLIENT *client) else if(client->userid == 0 && strlen(client->username) >= MIN_ADDRESS_LEN) { - db_query(db, "INSERT INTO accounts (username, coinsymbol, balance, donation) values ('%s', '%s', 0, %d)", - client->username, symbol, gift); + db_query(db, "INSERT INTO accounts (username, coinsymbol, balance, donation, hostaddr) values ('%s', '%s', 0, %d, '%s')", + client->username, symbol, gift, client->sock->ip); client->userid = (int)mysql_insert_id(&db->mysql); } From 6fe2208e2ea69392863f45590767fa691065f253 Mon Sep 17 00:00:00 2001 From: crackfoo Date: Wed, 2 May 2018 09:11:02 -0300 Subject: [PATCH 091/195] yiimp: log ip in debug message for unknown address (#263) --- web/yaamp/core/backend/users.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/yaamp/core/backend/users.php b/web/yaamp/core/backend/users.php index 35bc8bb..443443d 100644 --- a/web/yaamp/core/backend/users.php +++ b/web/yaamp/core/backend/users.php @@ -70,7 +70,7 @@ function BackendUsersUpdate() } if (empty($user->coinid)) { - debuglog("{$user->username} is an unknown address!"); + debuglog("{$user->hostaddr} - {$user->username} is an unknown address!"); } $user->save(); From 8fb9a74164ca2f706af4e8712fe2360f563f48f0 Mon Sep 17 00:00:00 2001 From: Jia Wu Date: Wed, 2 May 2018 08:27:39 -0400 Subject: [PATCH 092/195] stratum: add vitalium algo (#261) note: beware of the masterscams --- stratum/algos/makefile | 2 +- stratum/algos/vitalium.c | 87 +++++++++++++++++++++++++++++ stratum/algos/vitalium.h | 16 ++++++ stratum/config.sample/vitalium.conf | 16 ++++++ stratum/stratum.cpp | 1 + stratum/stratum.h | 1 + web/yaamp/core/functions/yaamp.php | 5 +- 7 files changed, 126 insertions(+), 2 deletions(-) create mode 100644 stratum/algos/vitalium.c create mode 100644 stratum/algos/vitalium.h create mode 100644 stratum/config.sample/vitalium.conf diff --git a/stratum/algos/makefile b/stratum/algos/makefile index 815c7eb..c6e5200 100644 --- a/stratum/algos/makefile +++ b/stratum/algos/makefile @@ -20,7 +20,7 @@ SOURCES=lyra2re.c lyra2v2.c Lyra2.c lyra2z.c Lyra2z.c Sponge.c \ argon2a.c ar2/blake2b.c ar2/argon2.c ar2/ref.c ar2/cores.c ar2/ar2-scrypt-jane.c \ a5a.c a5amath.c \ hive.c pomelo.c \ - phi.c polytimos.c skunk.c sib.c veltor.c gost.c x11evo.c + phi.c polytimos.c skunk.c sib.c veltor.c gost.c x11evo.c vitalium.c OBJECTS=$(SOURCES:%.c=%.o) $(SOURCES:%.cpp=%.o) OUTPUT=libalgos.a diff --git a/stratum/algos/vitalium.c b/stratum/algos/vitalium.c new file mode 100644 index 0000000..2a3b27c --- /dev/null +++ b/stratum/algos/vitalium.c @@ -0,0 +1,87 @@ +#include "vitalium.h" +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include "gost.h" + +#include "common.h" + +void vitalium_hash(const char* input, char* output, uint32_t len) +{ + sph_skein512_context ctx_skein; + sph_cubehash512_context ctx_cubehash; + sph_fugue512_context ctx_fugue; + sph_gost512_context ctx_gost; + sph_echo512_context ctx_echo; + sph_shavite512_context ctx_shavite; + sph_luffa512_context ctx_luffa; + + //these uint512 in the c++ source of the client are backed by an array of uint32 + uint32_t hashA[16], hashB[16]; + + sph_skein512_init(&ctx_skein); + sph_skein512 (&ctx_skein, input, len); + sph_skein512_close (&ctx_skein, hashA); + + sph_cubehash512_init(&ctx_cubehash); + sph_cubehash512 (&ctx_cubehash, hashA, 64); + sph_cubehash512_close(&ctx_cubehash, hashB); + + sph_fugue512_init(&ctx_fugue); + sph_fugue512 (&ctx_fugue, hashB, 64); + sph_fugue512_close(&ctx_fugue, hashA); + + sph_gost512_init(&ctx_gost); + sph_gost512 (&ctx_gost, hashA, 64); + sph_gost512_close (&ctx_gost, hashB); + + sph_echo512_init(&ctx_echo); + sph_echo512 (&ctx_echo, hashB, 64); + sph_echo512_close(&ctx_echo, hashA); + + sph_shavite512_init(&ctx_shavite); + sph_shavite512 (&ctx_shavite, hashA, 64); + sph_shavite512_close(&ctx_shavite, hashB); + + sph_luffa512_init (&ctx_luffa); + sph_luffa512 (&ctx_luffa, hashB, 64); + sph_luffa512_close (&ctx_luffa, hashA); + + sph_gost512_init(&ctx_gost); + sph_gost512 (&ctx_gost, hashA, 64); + sph_gost512_close (&ctx_gost, hashB); + + sph_cubehash512_init(&ctx_cubehash); + sph_cubehash512 (&ctx_cubehash, hashB, 64); + sph_cubehash512_close(&ctx_cubehash, hashA); + + sph_fugue512_init(&ctx_fugue); + sph_fugue512 (&ctx_fugue, hashA, 64); + sph_fugue512_close(&ctx_fugue, hashB); + + sph_gost512_init(&ctx_gost); + sph_gost512 (&ctx_gost, hashB, 64); + sph_gost512_close (&ctx_gost, hashA); + + sph_echo512_init(&ctx_echo); + sph_echo512 (&ctx_echo, hashA, 64); + sph_echo512_close(&ctx_echo, hashB); + + sph_shavite512_init(&ctx_shavite); + sph_shavite512 (&ctx_shavite, hashB, 64); + sph_shavite512_close(&ctx_shavite, hashA); + + sph_luffa512_init (&ctx_luffa); + sph_luffa512 (&ctx_luffa, hashA, 64); + sph_luffa512_close (&ctx_luffa, hashB); + + memcpy(output, hashB, 32); +} diff --git a/stratum/algos/vitalium.h b/stratum/algos/vitalium.h new file mode 100644 index 0000000..e29b3bc --- /dev/null +++ b/stratum/algos/vitalium.h @@ -0,0 +1,16 @@ +#ifndef VITALITY_H +#define VITALITY_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +void vitalium_hash(const char* input, char* output, uint32_t len); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/stratum/config.sample/vitalium.conf b/stratum/config.sample/vitalium.conf new file mode 100644 index 0000000..ff522cb --- /dev/null +++ b/stratum/config.sample/vitalium.conf @@ -0,0 +1,16 @@ +[TCP] +server = yaamp.com +port = 3233 +password = tu8tu5 + +[SQL] +host = yaampdb +database = yaamp +username = root +password = patofpaq + +[STRATUM] +algo = vitalium +difficulty = 0.001 +max_ttf = 400000000 + diff --git a/stratum/stratum.cpp b/stratum/stratum.cpp index 65a14de..8f6f09e 100644 --- a/stratum/stratum.cpp +++ b/stratum/stratum.cpp @@ -176,6 +176,7 @@ YAAMP_ALGO g_algos[] = {"veltor", veltor_hash, 1, 0, 0}, {"velvet", velvet_hash, 0x10000, 0, 0}, {"argon2", argon2_hash, 0x10000, 0, sha256_hash_hex }, + {"vitalium", vitalium_hash, 1, 0, 0}, {"sha256t", sha256t_hash, 1, 0, 0}, // sha256 3x diff --git a/stratum/stratum.h b/stratum/stratum.h index d8638fb..6604d1a 100644 --- a/stratum/stratum.h +++ b/stratum/stratum.h @@ -200,4 +200,5 @@ void sha256_double_hash_hex(const char *input, char *output, unsigned int len); #include "algos/veltor.h" #include "algos/velvet.h" #include "algos/argon2a.h" +#include "algos/vitalium.h" diff --git a/web/yaamp/core/functions/yaamp.php b/web/yaamp/core/functions/yaamp.php index 0a9d691..0167c94 100755 --- a/web/yaamp/core/functions/yaamp.php +++ b/web/yaamp/core/functions/yaamp.php @@ -58,6 +58,7 @@ function yaamp_get_algos() 'vanilla', 'veltor', 'velvet', + 'vitalium', 'yescrypt', 'yescryptR16', 'yescryptR32', @@ -178,9 +179,10 @@ function getAlgoColors($algo) 'bitcore' => '#f790c0', 'skunk' => '#dedefe', 'tribus' => '#c0d0d0', - 'a5a' => '#f0f0f0', + 'a5a' => '#f0f0f0', 'vanilla' => '#f0f0f0', 'velvet' => '#aac0cc', + 'vitalium' => '#f0b0a0', 'whirlpool' => '#d0e0e0', 'yescrypt' => '#e0d0e0', 'yescryptR16' => '#e2d0e2', @@ -251,6 +253,7 @@ function getAlgoPort($algo) 'm7m' => 6033, 'veltor' => 5034, 'velvet' => 6133, + 'vitalium' => 3233, 'yescrypt' => 6233, 'yescryptR16' => 6333, 'yescryptR32' => 6343, From adbdad424e795dad9433f8d2ee2b9a573902ee50 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Wed, 2 May 2018 16:32:44 +0200 Subject: [PATCH 093/195] backend: prevent php bug on empty masternode payee field (LUX) --- web/yaamp/core/backend/coins.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/yaamp/core/backend/coins.php b/web/yaamp/core/backend/coins.php index 51c0e80..34a1c32 100644 --- a/web/yaamp/core/backend/coins.php +++ b/web/yaamp/core/backend/coins.php @@ -140,7 +140,7 @@ function BackendCoinsUpdate() $coin->charity_amount = $template['_V2']/100000000; if(isset($template['payee_amount']) && $coin->symbol != 'LIMX') { - $coin->charity_amount = $template['payee_amount']/100000000; + $coin->charity_amount = doubleval($template['payee_amount'])/100000000; $coin->reward -= $coin->charity_amount; } From a78ec34d37545a21a33aaa41f427ed9f2d90da66 Mon Sep 17 00:00:00 2001 From: Nico Date: Fri, 4 May 2018 19:52:44 +0200 Subject: [PATCH 094/195] stratum: support for Machinecoin 0.16 mn+segwit (#265) --- stratum/coinbase.cpp | 65 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/stratum/coinbase.cpp b/stratum/coinbase.cpp index 4b99ef2..280008c 100644 --- a/stratum/coinbase.cpp +++ b/stratum/coinbase.cpp @@ -204,6 +204,71 @@ void coinbase_create(YAAMP_COIND *coind, YAAMP_JOB_TEMPLATE *templ, json_value * coind->reward = (double)available / 100000000 * coind->reward_mul; return; } + else if(strcmp(coind->symbol, "MAC") == 0) { + char script_payee[1024] = { 0 }; + char payees[4]; + int npayees = (templ->has_segwit_txs) ? 2 : 1; + bool masternode_enabled = json_get_bool(json_result, "masternode_payments_enforced"); + bool superblocks_enabled = json_get_bool(json_result, "superblocks_enabled"); + json_value* superblock = json_get_array(json_result, "superblock"); + json_value* masternode = json_get_object(json_result, "masternode"); + + if (masternode_enabled && masternode) { + const char *payee = json_get_string(masternode, "payee"); + json_int_t amount = json_get_int(masternode, "amount"); + if (payee && amount) + ++npayees; + } + if(superblocks_enabled && superblock) { + for(int i = 0; i < superblock->u.array.length; i++) { + const char *payee = json_get_string(superblock->u.array.values[i], "payee"); + json_int_t amount = json_get_int(superblock->u.array.values[i], "amount"); + if (payee && amount) { + ++npayees; + } + } + } + sprintf(payees, "%02x", npayees); + strcat(templ->coinb2, payees); + if (templ->has_segwit_txs) strcat(templ->coinb2, commitment); + if(superblocks_enabled && superblock) { + for(int i = 0; i < superblock->u.array.length; i++) { + const char *payee = json_get_string(superblock->u.array.values[i], "payee"); + json_int_t amount = json_get_int(superblock->u.array.values[i], "amount"); + if (payee && amount) { + npayees++; + available -= amount; + // superblock payments are going to use P2SH addresses / segwit transactions + base58_decode(payee, script_payee); + char eamount[32]; + encode_tx_value(eamount, amount); + strcat(templ->coinb2, eamount); + char coinb2_part[1024] = { 0 }; + char coinb2_len[3] = { 0 }; + sprintf(coinb2_part, "a9%02x%s87", (unsigned int)(strlen(script_payee) >> 1) & 0xFF, script_payee); + sprintf(coinb2_len, "%02x", (unsigned int)(strlen(coinb2_part) >> 1) & 0xFF); + strcat(templ->coinb2, coinb2_len); + strcat(templ->coinb2, coinb2_part); + debuglog("%s superblock %s %u\n", coind->symbol, payee, amount); + } + } + } + if (masternode_enabled && masternode) { + const char *payee = json_get_string(masternode, "payee"); + json_int_t amount = json_get_int(masternode, "amount"); + if (payee && amount) { + npayees++; + available -= amount; + base58_decode(payee, script_payee); + job_pack_tx(coind, templ->coinb2, amount, script_payee); + } + } + job_pack_tx(coind, templ->coinb2, available, NULL); + strcat(templ->coinb2, "00000000"); // locktime + + coind->reward = (double)available / 100000000 * coind->reward_mul; + return; + } // 2 txs are required on these coins, one for foundation (dev fees) if(coind->charity_percent) From fe47cca831555c60edfd70a32ad756b08dcdf08a Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Fri, 4 May 2018 19:53:31 +0200 Subject: [PATCH 095/195] stratum: also prepare normal optional mn+segwit --- stratum/coinbase.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/stratum/coinbase.cpp b/stratum/coinbase.cpp index 280008c..49afbf6 100644 --- a/stratum/coinbase.cpp +++ b/stratum/coinbase.cpp @@ -343,7 +343,7 @@ void coinbase_create(YAAMP_COIND *coind, YAAMP_JOB_TEMPLATE *templ, json_value * char script_dests[2048] = { 0 }; char script_payee[128] = { 0 }; char payees[4]; // addresses count - int npayees = 1; + int npayees = (templ->has_segwit_txs) ? 2 : 1; bool masternode_enabled = json_get_bool(json_result, "masternode_payments_enforced"); bool superblocks_enabled = json_get_bool(json_result, "superblocks_enabled"); json_value* superblock = json_get_array(json_result, "superblock"); @@ -378,6 +378,7 @@ void coinbase_create(YAAMP_COIND *coind, YAAMP_JOB_TEMPLATE *templ, json_value * } sprintf(payees, "%02x", npayees); strcat(templ->coinb2, payees); + if (templ->has_segwit_txs) strcat(templ->coinb2, commitment); strcat(templ->coinb2, script_dests); job_pack_tx(coind, templ->coinb2, available, NULL); strcat(templ->coinb2, "00000000"); // locktime From d4b00a8b0b850cab606501b1d5c401563cc9f0f4 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Fri, 4 May 2018 21:41:06 +0200 Subject: [PATCH 096/195] Revert "stratum: support for Machinecoin 0.16 mn+segwit (#265)" This reverts commit a78ec34d37545a21a33aaa41f427ed9f2d90da66. --- stratum/coinbase.cpp | 65 -------------------------------------------- 1 file changed, 65 deletions(-) diff --git a/stratum/coinbase.cpp b/stratum/coinbase.cpp index 49afbf6..be21ad1 100644 --- a/stratum/coinbase.cpp +++ b/stratum/coinbase.cpp @@ -204,71 +204,6 @@ void coinbase_create(YAAMP_COIND *coind, YAAMP_JOB_TEMPLATE *templ, json_value * coind->reward = (double)available / 100000000 * coind->reward_mul; return; } - else if(strcmp(coind->symbol, "MAC") == 0) { - char script_payee[1024] = { 0 }; - char payees[4]; - int npayees = (templ->has_segwit_txs) ? 2 : 1; - bool masternode_enabled = json_get_bool(json_result, "masternode_payments_enforced"); - bool superblocks_enabled = json_get_bool(json_result, "superblocks_enabled"); - json_value* superblock = json_get_array(json_result, "superblock"); - json_value* masternode = json_get_object(json_result, "masternode"); - - if (masternode_enabled && masternode) { - const char *payee = json_get_string(masternode, "payee"); - json_int_t amount = json_get_int(masternode, "amount"); - if (payee && amount) - ++npayees; - } - if(superblocks_enabled && superblock) { - for(int i = 0; i < superblock->u.array.length; i++) { - const char *payee = json_get_string(superblock->u.array.values[i], "payee"); - json_int_t amount = json_get_int(superblock->u.array.values[i], "amount"); - if (payee && amount) { - ++npayees; - } - } - } - sprintf(payees, "%02x", npayees); - strcat(templ->coinb2, payees); - if (templ->has_segwit_txs) strcat(templ->coinb2, commitment); - if(superblocks_enabled && superblock) { - for(int i = 0; i < superblock->u.array.length; i++) { - const char *payee = json_get_string(superblock->u.array.values[i], "payee"); - json_int_t amount = json_get_int(superblock->u.array.values[i], "amount"); - if (payee && amount) { - npayees++; - available -= amount; - // superblock payments are going to use P2SH addresses / segwit transactions - base58_decode(payee, script_payee); - char eamount[32]; - encode_tx_value(eamount, amount); - strcat(templ->coinb2, eamount); - char coinb2_part[1024] = { 0 }; - char coinb2_len[3] = { 0 }; - sprintf(coinb2_part, "a9%02x%s87", (unsigned int)(strlen(script_payee) >> 1) & 0xFF, script_payee); - sprintf(coinb2_len, "%02x", (unsigned int)(strlen(coinb2_part) >> 1) & 0xFF); - strcat(templ->coinb2, coinb2_len); - strcat(templ->coinb2, coinb2_part); - debuglog("%s superblock %s %u\n", coind->symbol, payee, amount); - } - } - } - if (masternode_enabled && masternode) { - const char *payee = json_get_string(masternode, "payee"); - json_int_t amount = json_get_int(masternode, "amount"); - if (payee && amount) { - npayees++; - available -= amount; - base58_decode(payee, script_payee); - job_pack_tx(coind, templ->coinb2, amount, script_payee); - } - } - job_pack_tx(coind, templ->coinb2, available, NULL); - strcat(templ->coinb2, "00000000"); // locktime - - coind->reward = (double)available / 100000000 * coind->reward_mul; - return; - } // 2 txs are required on these coins, one for foundation (dev fees) if(coind->charity_percent) From daac1a10c6ad6b13436a4835a56100a1fbf9cb5e Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Fri, 4 May 2018 21:39:30 +0200 Subject: [PATCH 097/195] stratum: merge P2SH superblock code to prevent duplicated code --- stratum/coinbase.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/stratum/coinbase.cpp b/stratum/coinbase.cpp index be21ad1..4db9df8 100644 --- a/stratum/coinbase.cpp +++ b/stratum/coinbase.cpp @@ -296,7 +296,20 @@ void coinbase_create(YAAMP_COIND *coind, YAAMP_JOB_TEMPLATE *templ, json_value * npayees++; available -= amount; base58_decode(payee, script_payee); - job_pack_tx(coind, script_dests, amount, script_payee); + bool superblock_use_p2sh = (strcmp(coind->symbol, "MAC") == 0); + if(superblock_use_p2sh) { + char eamount[32]; + char coinb2_part[512] = { 0 }; + char coinb2_len[4] = { 0 }; + sprintf(coinb2_part, "a9%02x%s87", (unsigned int)(strlen(script_payee) >> 1) & 0xFF, script_payee); + sprintf(coinb2_len, "%02x", (unsigned int)(strlen(coinb2_part) >> 1) & 0xFF); + encode_tx_value(eamount, amount); + strcat(templ->coinb2, eamount); + strcat(templ->coinb2, coinb2_len); + strcat(templ->coinb2, coinb2_part); + } else { + job_pack_tx(coind, script_dests, amount, script_payee); + } //debuglog("%s superblock %s %u\n", coind->symbol, payee, amount); } } From b43d6465486572b3451c34bf373eada3a5262145 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Sun, 6 May 2018 16:50:23 +0200 Subject: [PATCH 098/195] handle allium algo, kind of double lyra2 --- rc.local | 3 +- stratum/algos/allium.c | 46 ++++++++++++++++++++++++++++++ stratum/algos/allium.h | 16 +++++++++++ stratum/algos/makefile | 2 +- stratum/config.sample/allium.conf | 15 ++++++++++ stratum/stratum.cpp | 1 + stratum/stratum.h | 1 + web/yaamp/core/functions/yaamp.php | 3 ++ 8 files changed, 85 insertions(+), 2 deletions(-) create mode 100644 stratum/algos/allium.c create mode 100644 stratum/algos/allium.h create mode 100644 stratum/config.sample/allium.conf diff --git a/rc.local b/rc.local index 9da2b84..dec3336 100644 --- a/rc.local +++ b/rc.local @@ -49,7 +49,8 @@ screen -dmS jha $STRATUM_DIR/run.sh jha #screen -dmS dmd-gr $STRATUM_DIR/run.sh dmd-gr screen -dmS myr-gr $STRATUM_DIR/run.sh myr-gr screen -dmS lbry $STRATUM_DIR/run.sh lbry -screen -dmS lyra2 $STRATUM_DIR/run.sh lyra2 +screen -dmS allium $STRATUM_DIR/run.sh allium +#screen -dmS lyra2 $STRATUM_DIR/run.sh lyra2 screen -dmS lyra2v2 $STRATUM_DIR/run.sh lyra2v2 screen -dmS zero $STRATUM_DIR/run.sh lyra2z diff --git a/stratum/algos/allium.c b/stratum/algos/allium.c new file mode 100644 index 0000000..4c3569d --- /dev/null +++ b/stratum/algos/allium.c @@ -0,0 +1,46 @@ +#include + +#include "sha3/sph_blake.h" +#include "sha3/sph_groestl.h" +#include "sha3/sph_skein.h" +#include "sha3/sph_keccak.h" +#include "sha3/sph_cubehash.h" + +#include "Lyra2.h" + +void allium_hash(const char* input, char* output, uint32_t len) +{ + uint32_t hashA[8], hashB[8]; + + sph_blake256_context ctx_blake; + sph_keccak256_context ctx_keccak; + sph_cubehash512_context ctx_cubehash; + sph_skein256_context ctx_skein; + sph_groestl256_context ctx_groestl; + + sph_blake256_init(&ctx_blake); + sph_blake256(&ctx_blake, input, 80); + sph_blake256_close(&ctx_blake, hashA); + + sph_keccak256_init(&ctx_keccak); + sph_keccak256(&ctx_keccak, hashA, 32); + sph_keccak256_close(&ctx_keccak, hashB); + + LYRA2(hashA, 32, hashB, 32, hashB, 32, 1, 8, 8); + + sph_cubehash256_init(&ctx_cubehash); + sph_cubehash256(&ctx_cubehash, hashA, 32); + sph_cubehash256_close(&ctx_cubehash, hashB); + + LYRA2(hashA, 32, hashB, 32, hashB, 32, 1, 8, 8); + + sph_skein256_init(&ctx_skein); + sph_skein256(&ctx_skein, hashA, 32); + sph_skein256_close(&ctx_skein, hashB); + + sph_groestl256_init(&ctx_groestl); + sph_groestl256(&ctx_groestl, hashB, 32); + sph_groestl256_close(&ctx_groestl, hashA); + + memcpy(output, hashA, 32); +} diff --git a/stratum/algos/allium.h b/stratum/algos/allium.h new file mode 100644 index 0000000..3705161 --- /dev/null +++ b/stratum/algos/allium.h @@ -0,0 +1,16 @@ +#ifndef ALLIUM_H +#define ALLIUM_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +void allium_hash(const char* input, char* output, uint32_t len); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/stratum/algos/makefile b/stratum/algos/makefile index c6e5200..e2a7141 100644 --- a/stratum/algos/makefile +++ b/stratum/algos/makefile @@ -8,7 +8,7 @@ CXXFLAGS = -O2 -I.. -march=native CFLAGS= $(CXXFLAGS) -std=gnu99 LDFLAGS=-O2 -lgmp -SOURCES=lyra2re.c lyra2v2.c Lyra2.c lyra2z.c Lyra2z.c Sponge.c \ +SOURCES=lyra2re.c lyra2v2.c Lyra2.c lyra2z.c Lyra2z.c Sponge.c allium.c \ blake.c scrypt.c c11.c x11.c x12.c x13.c sha256.c sha256t.c jha.c keccak.c deep.c tribus.c \ hsr14.c sm3.c \ x14.c x15.c x17.c nist5.c fresh.c quark.c neoscrypt.c scryptn.c qubit.c skein.c groestl.c \ diff --git a/stratum/config.sample/allium.conf b/stratum/config.sample/allium.conf new file mode 100644 index 0000000..ec9d41f --- /dev/null +++ b/stratum/config.sample/allium.conf @@ -0,0 +1,15 @@ +[TCP] +server = yaamp.com +port = 4443 +password = tu8tu5 + +[SQL] +host = yaampdb +database = yaamp +username = root +password = patofpaq + +[STRATUM] +algo = allium +difficulty = 0.01 +max_ttf = 4000000 diff --git a/stratum/stratum.cpp b/stratum/stratum.cpp index 8f6f09e..73717ae 100644 --- a/stratum/stratum.cpp +++ b/stratum/stratum.cpp @@ -133,6 +133,7 @@ YAAMP_ALGO g_algos[] = {"jha", jha_hash, 0x10000, 0}, + {"allium", allium_hash, 1, 0, 0}, {"lyra2", lyra2re_hash, 0x80, 0, 0}, {"lyra2v2", lyra2v2_hash, 0x100, 0, 0}, {"lyra2z", lyra2z_hash, 0x100, 0, 0}, diff --git a/stratum/stratum.h b/stratum/stratum.h index 6604d1a..fdbf124 100644 --- a/stratum/stratum.h +++ b/stratum/stratum.h @@ -164,6 +164,7 @@ void sha256_double_hash_hex(const char *input, char *output, unsigned int len); #include "algos/hsr14.h" #include "algos/quark.h" #include "algos/neoscrypt.h" +#include "algos/allium.h" #include "algos/lyra2re.h" #include "algos/lyra2v2.h" #include "algos/lyra2z.h" diff --git a/web/yaamp/core/functions/yaamp.php b/web/yaamp/core/functions/yaamp.php index 0167c94..e7adae2 100755 --- a/web/yaamp/core/functions/yaamp.php +++ b/web/yaamp/core/functions/yaamp.php @@ -8,6 +8,7 @@ function yaamp_get_algos() 'sha256t', 'scrypt', 'scryptn', + 'allium', 'argon2', 'bastion', 'bitcore', @@ -148,6 +149,7 @@ function getAlgoColors($algo) 'x16s' => '#f0b080', 'x17' => '#f0b0a0', 'xevan' => '#f0b0a0', + 'allium' => '#80a0d0', 'argon2' => '#e0d0e0', 'bastion' => '#e0b0b0', 'blake' => '#f0f0f0', @@ -227,6 +229,7 @@ function getAlgoPort($algo) 'neoscrypt' => 4233, 'argon2' => 4234, 'scryptn' => 4333, + 'allium' => 4443, 'lyra2' => 4433, 'lyra2v2' => 4533, 'lyra2z' => 4553, From d428130df324255b2b6e145c786661b6fa5e19b7 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Sun, 6 May 2018 17:09:11 +0200 Subject: [PATCH 099/195] allium: fix pool diff ratio, same as lyra2v2, cf cpuminer-opt --- stratum/config.sample/allium.conf | 2 +- stratum/stratum.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/stratum/config.sample/allium.conf b/stratum/config.sample/allium.conf index ec9d41f..1f8f192 100644 --- a/stratum/config.sample/allium.conf +++ b/stratum/config.sample/allium.conf @@ -11,5 +11,5 @@ password = patofpaq [STRATUM] algo = allium -difficulty = 0.01 +difficulty = 1 max_ttf = 4000000 diff --git a/stratum/stratum.cpp b/stratum/stratum.cpp index 73717ae..4fcba40 100644 --- a/stratum/stratum.cpp +++ b/stratum/stratum.cpp @@ -133,7 +133,7 @@ YAAMP_ALGO g_algos[] = {"jha", jha_hash, 0x10000, 0}, - {"allium", allium_hash, 1, 0, 0}, + {"allium", allium_hash, 0x100, 0, 0}, {"lyra2", lyra2re_hash, 0x80, 0, 0}, {"lyra2v2", lyra2v2_hash, 0x100, 0, 0}, {"lyra2z", lyra2z_hash, 0x100, 0, 0}, From db7a145c0b30df61407420235eca064a43c4c5be Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Mon, 7 May 2018 15:00:41 +0200 Subject: [PATCH 100/195] stratum: fix superblock script order was not easy to code without the future wallet code to test it ;) --- stratum/coinbase.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/stratum/coinbase.cpp b/stratum/coinbase.cpp index 4db9df8..ee23e63 100644 --- a/stratum/coinbase.cpp +++ b/stratum/coinbase.cpp @@ -298,15 +298,15 @@ void coinbase_create(YAAMP_COIND *coind, YAAMP_JOB_TEMPLATE *templ, json_value * base58_decode(payee, script_payee); bool superblock_use_p2sh = (strcmp(coind->symbol, "MAC") == 0); if(superblock_use_p2sh) { - char eamount[32]; - char coinb2_part[512] = { 0 }; - char coinb2_len[4] = { 0 }; + char eamount[32] = { 0 }; + char coinb2_part[256]; + char coinb2_len[4]; sprintf(coinb2_part, "a9%02x%s87", (unsigned int)(strlen(script_payee) >> 1) & 0xFF, script_payee); sprintf(coinb2_len, "%02x", (unsigned int)(strlen(coinb2_part) >> 1) & 0xFF); encode_tx_value(eamount, amount); - strcat(templ->coinb2, eamount); - strcat(templ->coinb2, coinb2_len); - strcat(templ->coinb2, coinb2_part); + strcat(script_dests, eamount); + strcat(script_dests, coinb2_len); + strcat(script_dests, coinb2_part); } else { job_pack_tx(coind, script_dests, amount, script_payee); } From ed97818e612c3b0eb6017bf75b5eefe5db8f9998 Mon Sep 17 00:00:00 2001 From: Nico Date: Mon, 7 May 2018 15:41:20 +0200 Subject: [PATCH 101/195] stratum: support for MAC P2SH masternodes too (#266) note: a field "isscript" should be added to getblocktemplate masternode/superblock objects if the type of address can vary over time... Code may be refactored later (common func and p2sh fields in coind object) --- stratum/coinbase.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/stratum/coinbase.cpp b/stratum/coinbase.cpp index ee23e63..06bb4c6 100644 --- a/stratum/coinbase.cpp +++ b/stratum/coinbase.cpp @@ -321,7 +321,20 @@ void coinbase_create(YAAMP_COIND *coind, YAAMP_JOB_TEMPLATE *templ, json_value * npayees++; available -= amount; base58_decode(payee, script_payee); - job_pack_tx(coind, script_dests, amount, script_payee); + bool masternode_use_p2sh = (strcmp(coind->symbol, "MAC") == 0); + if(masternode_use_p2sh) { + char eamount[32] = { 0 }; + char coinb2_part[256]; + char coinb2_len[4]; + sprintf(coinb2_part, "a9%02x%s87", (unsigned int)(strlen(script_payee) >> 1) & 0xFF, script_payee); + sprintf(coinb2_len, "%02x", (unsigned int)(strlen(coinb2_part) >> 1) & 0xFF); + encode_tx_value(eamount, amount); + strcat(script_dests, eamount); + strcat(script_dests, coinb2_len); + strcat(script_dests, coinb2_part); + } else { + job_pack_tx(coind, script_dests, amount, script_payee); + } } } sprintf(payees, "%02x", npayees); From b114a1c66f0a6a08f0dc7abf60766afc63579209 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Mon, 7 May 2018 16:15:56 +0200 Subject: [PATCH 102/195] stratum: common p2sh_pack_tx func for p2sh masternodes --- stratum/coinbase.cpp | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/stratum/coinbase.cpp b/stratum/coinbase.cpp index 06bb4c6..15db7a2 100644 --- a/stratum/coinbase.cpp +++ b/stratum/coinbase.cpp @@ -32,6 +32,19 @@ static void job_pack_tx(YAAMP_COIND *coind, char *data, json_int_t amount, char // debuglog("pack tx %lld\n", amount); } +static void p2sh_pack_tx(YAAMP_COIND *coind, char *data, json_int_t amount, char *payee) +{ + char evalue[32]; + char coinb2_part[256]; + char coinb2_len[4]; + sprintf(coinb2_part, "a9%02x%s87", (unsigned int)(strlen(payee) >> 1) & 0xFF, payee); + sprintf(coinb2_len, "%02x", (unsigned int)(strlen(coinb2_part) >> 1) & 0xFF); + encode_tx_value(evalue, amount); + strcat(data, evalue); + strcat(data, coinb2_len); + strcat(data, coinb2_part); +} + void coinbase_aux(YAAMP_JOB_TEMPLATE *templ, char *aux_script) { vector hashlist = coind_aux_hashlist(templ->auxs, templ->auxs_size); @@ -298,15 +311,7 @@ void coinbase_create(YAAMP_COIND *coind, YAAMP_JOB_TEMPLATE *templ, json_value * base58_decode(payee, script_payee); bool superblock_use_p2sh = (strcmp(coind->symbol, "MAC") == 0); if(superblock_use_p2sh) { - char eamount[32] = { 0 }; - char coinb2_part[256]; - char coinb2_len[4]; - sprintf(coinb2_part, "a9%02x%s87", (unsigned int)(strlen(script_payee) >> 1) & 0xFF, script_payee); - sprintf(coinb2_len, "%02x", (unsigned int)(strlen(coinb2_part) >> 1) & 0xFF); - encode_tx_value(eamount, amount); - strcat(script_dests, eamount); - strcat(script_dests, coinb2_len); - strcat(script_dests, coinb2_part); + p2sh_pack_tx(coind, script_dests, amount, script_payee); } else { job_pack_tx(coind, script_dests, amount, script_payee); } @@ -323,15 +328,7 @@ void coinbase_create(YAAMP_COIND *coind, YAAMP_JOB_TEMPLATE *templ, json_value * base58_decode(payee, script_payee); bool masternode_use_p2sh = (strcmp(coind->symbol, "MAC") == 0); if(masternode_use_p2sh) { - char eamount[32] = { 0 }; - char coinb2_part[256]; - char coinb2_len[4]; - sprintf(coinb2_part, "a9%02x%s87", (unsigned int)(strlen(script_payee) >> 1) & 0xFF, script_payee); - sprintf(coinb2_len, "%02x", (unsigned int)(strlen(coinb2_part) >> 1) & 0xFF); - encode_tx_value(eamount, amount); - strcat(script_dests, eamount); - strcat(script_dests, coinb2_len); - strcat(script_dests, coinb2_part); + p2sh_pack_tx(coind, script_dests, amount, script_payee); } else { job_pack_tx(coind, script_dests, amount, script_payee); } From ca974e661f468a3770617716c44056c048c76006 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Tue, 8 May 2018 23:49:53 +0200 Subject: [PATCH 103/195] backend: keep blocks history at least 7 days --- web/yaamp/core/backend/system.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/web/yaamp/core/backend/system.php b/web/yaamp/core/backend/system.php index 9d5478a..b70da2c 100644 --- a/web/yaamp/core/backend/system.php +++ b/web/yaamp/core/backend/system.php @@ -35,8 +35,7 @@ function BackendQuickClean() foreach($coins as $coin) { - $delay = time() - 24*60*60; - if ($coin->symbol=='DCR') $delay = time() - 7*24*60*60; + $delay = time() - 7*24*60*60; $id = dboscalar("select id from blocks where coin_id=$coin->id and time<$delay and id not in (select blockid from earnings where coinid=$coin->id) From f358e723c83fe7b26c969cdddea403348064ef25 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Wed, 9 May 2018 00:12:44 +0200 Subject: [PATCH 104/195] exchanges: ignore coins 'created' by tradesatoshi they have a very huge amount of scams... --- web/yaamp/core/backend/rawcoins.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/yaamp/core/backend/rawcoins.php b/web/yaamp/core/backend/rawcoins.php index fbd96a6..c4539af 100644 --- a/web/yaamp/core/backend/rawcoins.php +++ b/web/yaamp/core/backend/rawcoins.php @@ -406,7 +406,7 @@ function updateRawCoin($marketname, $symbol, $name='unknown') } // some other to ignore... - if (in_array($marketname, array('yobit','kucoin'))) + if (in_array($marketname, array('yobit','kucoin','tradesatoshi'))) return; if (market_get($marketname, $symbol, "disabled")) { From a98b631a87f946b5bf5f4462c2e3a6b6750c8e14 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Wed, 9 May 2018 00:24:50 +0200 Subject: [PATCH 105/195] coindb: avoid incapsuda html on cryptopia icons --- web/yaamp/commands/CoindbCommand.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/yaamp/commands/CoindbCommand.php b/web/yaamp/commands/CoindbCommand.php index 7d6913b..a209850 100644 --- a/web/yaamp/commands/CoindbCommand.php +++ b/web/yaamp/commands/CoindbCommand.php @@ -441,7 +441,7 @@ class CoindbCommand extends CConsoleCommand } catch (Exception $e) { continue; } - if (strlen($data) < 2048) continue; + if (strlen($data) < 3000 || strstr($data, 'script src')) continue; echo $symbol." icon found\n"; file_put_contents($local, $data); if (filesize($local) > 0) { From 495dcbba00761d4b266b9453e0d31a78f599e7ed Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Fri, 11 May 2018 10:12:30 +0200 Subject: [PATCH 106/195] stratum: detect if master wallet is p2sh + mn started field --- stratum/coinbase.cpp | 9 +++++++-- stratum/coind.cpp | 2 ++ stratum/coind.h | 1 + web/yaamp/core/backend/coins.php | 3 ++- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/stratum/coinbase.cpp b/stratum/coinbase.cpp index 15db7a2..2d20a87 100644 --- a/stratum/coinbase.cpp +++ b/stratum/coinbase.cpp @@ -320,9 +320,10 @@ void coinbase_create(YAAMP_COIND *coind, YAAMP_JOB_TEMPLATE *templ, json_value * } } if (masternode_enabled && masternode) { + bool started = json_get_bool(json_result, "masternode_payments_started"); const char *payee = json_get_string(masternode, "payee"); json_int_t amount = json_get_int(masternode, "amount"); - if (payee && amount) { + if (payee && amount && started) { npayees++; available -= amount; base58_decode(payee, script_payee); @@ -338,7 +339,11 @@ void coinbase_create(YAAMP_COIND *coind, YAAMP_JOB_TEMPLATE *templ, json_value * strcat(templ->coinb2, payees); if (templ->has_segwit_txs) strcat(templ->coinb2, commitment); strcat(templ->coinb2, script_dests); - job_pack_tx(coind, templ->coinb2, available, NULL); + if (coind->p2sh_address) { // "MAC 0.16" + p2sh_pack_tx(coind, templ->coinb2, available, coind->script_pubkey); + } else { + job_pack_tx(coind, templ->coinb2, available, NULL); + } strcat(templ->coinb2, "00000000"); // locktime coind->reward = (double)available/100000000*coind->reward_mul; //debuglog("%s %d dests %s\n", coind->symbol, npayees, script_dests); diff --git a/stratum/coind.cpp b/stratum/coind.cpp index 4ba9ab8..1544803 100644 --- a/stratum/coind.cpp +++ b/stratum/coind.cpp @@ -139,6 +139,8 @@ bool coind_validate_address(YAAMP_COIND *coind) if (!base58_decode(coind->wallet, coind->script_pubkey)) stratumlog("Warning: unable to decode %s %s script pubkey\n", coind->symbol, coind->wallet); + coind->p2sh_address = json_get_bool(json_result, "isscript"); + // if base58 decode fails if (!strlen(coind->script_pubkey)) { const char *pk = json_get_string(json_result, "scriptPubKey"); diff --git a/stratum/coind.h b/stratum/coind.h index d008a24..f58f091 100644 --- a/stratum/coind.h +++ b/stratum/coind.h @@ -35,6 +35,7 @@ public: char pubkey[1024]; char script_pubkey[1024]; + bool p2sh_address; bool pos; bool hassubmitblock; diff --git a/web/yaamp/core/backend/coins.php b/web/yaamp/core/backend/coins.php index 34a1c32..1112671 100644 --- a/web/yaamp/core/backend/coins.php +++ b/web/yaamp/core/backend/coins.php @@ -145,7 +145,8 @@ function BackendCoinsUpdate() } else if(isset($template['masternode']) && arraySafeVal($template,'masternode_payments_enforced')) { - $coin->reward -= arraySafeVal($template['masternode'],'amount',0)/100000000; + if (arraySafeVal($template,'masternode_payments_started')) + $coin->reward -= arraySafeVal($template['masternode'],'amount',0)/100000000; $coin->hasmasternodes = true; } From a3103af7ba4c098a668e652f90a342a6f3ab6dc8 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Mon, 14 May 2018 17:35:09 +0200 Subject: [PATCH 107/195] stratum: fix client memory leak in yescrypt --- stratum/algos/yescrypt.c | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/stratum/algos/yescrypt.c b/stratum/algos/yescrypt.c index 1501745..2959dfa 100644 --- a/stratum/algos/yescrypt.c +++ b/stratum/algos/yescrypt.c @@ -327,35 +327,25 @@ static int yescrypt_bsty(const uint8_t * passwd, size_t passwdlen, const uint8_t * salt, size_t saltlen, uint64_t N, uint32_t r, uint32_t p, uint8_t * buf, size_t buflen) { - static __thread int initialized = 0; - static __thread yescrypt_shared_t shared; - static __thread yescrypt_local_t local; + yescrypt_shared_t shared; + yescrypt_local_t local; int retval; - if (!initialized) { -/* "shared" could in fact be shared, but it's simpler to keep it private - * along with "local". It's dummy and tiny anyway. */ - if (yescrypt_init_shared(&shared, NULL, 0, + if (yescrypt_init_shared(&shared, NULL, 0, 0, 0, 0, YESCRYPT_SHARED_DEFAULTS, 0, NULL, 0)) return -1; - if (yescrypt_init_local(&local)) { + if (yescrypt_init_local(&local)) { yescrypt_free_shared(&shared); return -1; - } - initialized = 1; } + retval = yescrypt_kdf(&shared, &local, passwd, passwdlen, salt, saltlen, N, r, p, 0, YESCRYPT_FLAGS, buf, buflen); -#if 0 - if (yescrypt_free_local(&local)) { - yescrypt_free_shared(&shared); - return -1; - } - if (yescrypt_free_shared(&shared)) - return -1; - initialized = 0; -#endif + + yescrypt_free_local(&local); + yescrypt_free_shared(&shared); + return retval; } @@ -364,6 +354,7 @@ void yescrypt_hash(const char *input, char *output, uint32_t len) { yescrypt_bsty((uint8_t*)input, len, (uint8_t*)input, len, 2048, 8, 1, (uint8_t*)output, 32); } + void yescryptR16_hash(const char *input, char *output, uint32_t len) { yescrypt_bsty((uint8_t*)input, len, (uint8_t*)input, len, 4096, 16, 1, (uint8_t*)output, 32); From a9dc8c5dfdff2e3cc458f4b9c319b168028c55d9 Mon Sep 17 00:00:00 2001 From: crackfoo Date: Wed, 16 May 2018 09:53:44 -0300 Subject: [PATCH 108/195] trading: don't send coins to exchange which have late tx already --- web/yaamp/core/backend/sell.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/web/yaamp/core/backend/sell.php b/web/yaamp/core/backend/sell.php index 5b25a2c..7fba09b 100644 --- a/web/yaamp/core/backend/sell.php +++ b/web/yaamp/core/backend/sell.php @@ -38,7 +38,7 @@ function sellCoinToExchange($coin) $market = getBestMarket($coin); if(!$market) return; - if(!$coin->sellonbid && $market->lastsent != null && $market->lastsent > $market->lasttraded) + if($market->lastsent != null && $market->lastsent > $market->lasttraded) { // debuglog("*** not sending $coin->name to $market->name. last tx is late ***"); return; @@ -77,9 +77,6 @@ function sellCoinToExchange($coin) $amount = round($amount, 8); // debuglog("sending $amount $coin->symbol to $marketname, $deposit_address"); - $market->lastsent = time(); - $market->save(); - // sleep(1); $tx = $remote->sendtoaddress($deposit_address, $amount); @@ -107,6 +104,12 @@ function sellCoinToExchange($coin) return; } } + + if($tx) + { + $market->lastsent = time(); + $market->save(); + } $exchange = new db_exchange; $exchange->market = $marketname; From 8c1964d0d960380a11958a6adf42e5513b5521be Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Fri, 18 May 2018 12:52:10 +0200 Subject: [PATCH 109/195] lyra2z: prevent filenames with different cases + rename blake2 to blake2s and reorder algo makefile --- stratum/algos/{Lyra2z.c => Lyra2-z.c} | 0 stratum/algos/{Lyra2z.h => Lyra2-z.h} | 0 stratum/algos/{blake2.c => blake2s.c} | 0 stratum/algos/{blake2.h => blake2s.h} | 0 stratum/algos/lyra2z.c | 2 +- stratum/algos/makefile | 21 ++++++++++----------- stratum/stratum.h | 2 +- 7 files changed, 12 insertions(+), 13 deletions(-) rename stratum/algos/{Lyra2z.c => Lyra2-z.c} (100%) rename stratum/algos/{Lyra2z.h => Lyra2-z.h} (100%) rename stratum/algos/{blake2.c => blake2s.c} (100%) rename stratum/algos/{blake2.h => blake2s.h} (100%) diff --git a/stratum/algos/Lyra2z.c b/stratum/algos/Lyra2-z.c similarity index 100% rename from stratum/algos/Lyra2z.c rename to stratum/algos/Lyra2-z.c diff --git a/stratum/algos/Lyra2z.h b/stratum/algos/Lyra2-z.h similarity index 100% rename from stratum/algos/Lyra2z.h rename to stratum/algos/Lyra2-z.h diff --git a/stratum/algos/blake2.c b/stratum/algos/blake2s.c similarity index 100% rename from stratum/algos/blake2.c rename to stratum/algos/blake2s.c diff --git a/stratum/algos/blake2.h b/stratum/algos/blake2s.h similarity index 100% rename from stratum/algos/blake2.h rename to stratum/algos/blake2s.h diff --git a/stratum/algos/lyra2z.c b/stratum/algos/lyra2z.c index b83b838..0d946de 100644 --- a/stratum/algos/lyra2z.c +++ b/stratum/algos/lyra2z.c @@ -3,7 +3,7 @@ #include #include -#include "Lyra2z.h" +#include "Lyra2-z.h" #include diff --git a/stratum/algos/makefile b/stratum/algos/makefile index e2a7141..d7c296f 100644 --- a/stratum/algos/makefile +++ b/stratum/algos/makefile @@ -8,19 +8,18 @@ CXXFLAGS = -O2 -I.. -march=native CFLAGS= $(CXXFLAGS) -std=gnu99 LDFLAGS=-O2 -lgmp -SOURCES=lyra2re.c lyra2v2.c Lyra2.c lyra2z.c Lyra2z.c Sponge.c allium.c \ - blake.c scrypt.c c11.c x11.c x12.c x13.c sha256.c sha256t.c jha.c keccak.c deep.c tribus.c \ - hsr14.c sm3.c \ - x14.c x15.c x17.c nist5.c fresh.c quark.c neoscrypt.c scryptn.c qubit.c skein.c groestl.c \ - bitcore.c timetravel.c x16r.c x16s.c xevan.c bastion.c hmq17.c \ - skein2.c zr5.c bmw.c luffa.c pentablake.c whirlpool.c whirlpoolx.c blakecoin.c \ - blake2.c \ - yescrypt.c yescrypt-opt.c sha256_Y.c lbry.c \ - m7m.c magimath.cpp velvet.c \ +SOURCES=lyra2re.c lyra2v2.c Lyra2.c lyra2z.c Lyra2-z.c Sponge.c allium.c \ + c11.c x11.c x12.c x13.c hsr14.c sm3.c x14.c x15.c x17.c \ + blake.c blakecoin.c blake2s.c jha.c keccak.c lbry.c tribus.c \ + deep.c fresh.c groestl.c neoscrypt.c nist5.c quark.c qubit.c skein.c skein2.c \ + bitcore.c timetravel.c x11evo.c x16r.c x16s.c xevan.c bastion.c hmq17.c \ + bmw.c luffa.c pentablake.c vitalium.c whirlpool.c whirlpoolx.c zr5.c \ + scrypt.c scryptn.c sha256.c sha256t.c \ + yescrypt.c yescrypt-opt.c sha256_Y.c \ + a5a.c a5amath.c m7m.c magimath.cpp velvet.c \ argon2a.c ar2/blake2b.c ar2/argon2.c ar2/ref.c ar2/cores.c ar2/ar2-scrypt-jane.c \ - a5a.c a5amath.c \ hive.c pomelo.c \ - phi.c polytimos.c skunk.c sib.c veltor.c gost.c x11evo.c vitalium.c + phi.c polytimos.c skunk.c sib.c veltor.c gost.c OBJECTS=$(SOURCES:%.c=%.o) $(SOURCES:%.cpp=%.o) OUTPUT=libalgos.a diff --git a/stratum/stratum.h b/stratum/stratum.h index fdbf124..b4b6fe7 100644 --- a/stratum/stratum.h +++ b/stratum/stratum.h @@ -170,7 +170,7 @@ void sha256_double_hash_hex(const char *input, char *output, unsigned int len); #include "algos/lyra2z.h" #include "algos/blake.h" #include "algos/blakecoin.h" -#include "algos/blake2.h" +#include "algos/blake2s.h" #include "algos/qubit.h" #include "algos/groestl.h" #include "algos/jha.h" From f3d9f253b35613a02fb4f4aabbbb8563aa56c579 Mon Sep 17 00:00:00 2001 From: Jakub Jelen Date: Fri, 18 May 2018 13:35:17 +0200 Subject: [PATCH 110/195] ci: add travis config (#212) --- .travis.yml | 5 +++++ README.md | 2 ++ 2 files changed, 7 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..f954618 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,5 @@ +language: cpp +script: + - (cd blocknotify && make) + - (cd stratum/iniparser && make) + - (cd stratum && make) diff --git a/README.md b/README.md index 3472e55..99c19e8 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,5 @@ +[![Build Status](https://travis-ci.org/tpruvot/yiimp.svg?branch=next)](https://travis-ci.org/tpruvot/yiimp) + #yiimp - yaamp fork Required: From 2b932a8a9694e2ace76c464e409c84581af36885 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Mon, 21 May 2018 15:52:57 +0200 Subject: [PATCH 111/195] stratum: check json version string ptr validity --- stratum/client.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stratum/client.cpp b/stratum/client.cpp index 6f0c9d5..37232e4 100644 --- a/stratum/client.cpp +++ b/stratum/client.cpp @@ -45,8 +45,8 @@ bool client_subscribe(YAAMP_CLIENT *client, json_value *json_params) if(json_params->u.array.length>0) { - strncpy(client->version, json_params->u.array.values[0]->u.string.ptr, 1023); - // if(!strcmp(client->version, "stratum-proxy/0.0.1")) return false; + if (json_params->u.array.values[0]->u.string.ptr) + strncpy(client->version, json_params->u.array.values[0]->u.string.ptr, 1023); if(strstr(client->version, "NiceHash") || strstr(client->version, "proxy") || strstr(client->version, "/3.")) client->reconnectable = false; From afc80e2a68dde51f836e4a37cac7d6f6a23c3373 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Fri, 25 May 2018 15:11:37 +0200 Subject: [PATCH 112/195] stratum: handle ismine check moved in getaddressinfo --- stratum/coind.cpp | 3 ++- stratum/coind.h | 2 +- stratum/db.cpp | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/stratum/coind.cpp b/stratum/coind.cpp index 1544803..fe1c955 100644 --- a/stratum/coind.cpp +++ b/stratum/coind.cpp @@ -114,7 +114,8 @@ bool coind_validate_address(YAAMP_COIND *coind) char params[YAAMP_SMALLBUFSIZE]; sprintf(params, "[\"%s\"]", coind->wallet); - json_value *json = rpc_call(&coind->rpc, "validateaddress", params); + // assume, if the wallet has dropped getinfo, that it use the new getaddressinfo rpc for ismine and account + json_value *json = rpc_call(&coind->rpc, coind->hasgetinfo ? "validateaddress" : "getaddressinfo", params); if(!json) return false; json_value *json_result = json_get_object(json, "result"); diff --git a/stratum/coind.h b/stratum/coind.h index f58f091..611020b 100644 --- a/stratum/coind.h +++ b/stratum/coind.h @@ -69,7 +69,7 @@ public: bool hasmasternodes; bool oldmasternodes; bool multialgos; // pow_hash field (or mined_hash) - + bool hasgetinfo; bool usesegwit; char commitment[128]; char witness_magic[16]; diff --git a/stratum/db.cpp b/stratum/db.cpp index f8c513c..fb0ca4e 100644 --- a/stratum/db.cpp +++ b/stratum/db.cpp @@ -193,7 +193,7 @@ void db_update_coinds(YAAMP_DB *db) 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, " "reward_mul, symbol, auxpow, actual_ttf, network_ttf, usememorypool, hasmasternodes, algo, symbol2, " - "rpccurl, rpcssl, rpccert, account, multialgos, max_miners, max_shares, usesegwit " + "rpccurl, rpcssl, rpccert, account, multialgos, max_miners, max_shares, usesegwit, hasgetinfo " "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); @@ -304,6 +304,7 @@ void db_update_coinds(YAAMP_DB *db) if(row[33] && atoi(row[33]) > 0) g_stratum_max_cons = atoi(row[33]); if(row[34] && atol(row[34]) > 0) g_max_shares = atol(row[34]); if(row[35]) coind->usesegwit = atoi(row[35]) > 0; + if(row[36]) coind->hasgetinfo = atoi(row[36]) > 0; if(coind->usesegwit) g_stratum_segwit = true; From c72dd9151106b9e85a5ec989d5a9cfb412071d96 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Fri, 25 May 2018 15:48:33 +0200 Subject: [PATCH 113/195] Revert "stratum: handle ismine check moved in getaddressinfo" most wallets are not ready for that... This reverts commit afc80e2a68dde51f836e4a37cac7d6f6a23c3373. --- stratum/coind.cpp | 3 +-- stratum/coind.h | 2 +- stratum/db.cpp | 3 +-- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/stratum/coind.cpp b/stratum/coind.cpp index fe1c955..1544803 100644 --- a/stratum/coind.cpp +++ b/stratum/coind.cpp @@ -114,8 +114,7 @@ bool coind_validate_address(YAAMP_COIND *coind) char params[YAAMP_SMALLBUFSIZE]; sprintf(params, "[\"%s\"]", coind->wallet); - // assume, if the wallet has dropped getinfo, that it use the new getaddressinfo rpc for ismine and account - json_value *json = rpc_call(&coind->rpc, coind->hasgetinfo ? "validateaddress" : "getaddressinfo", params); + json_value *json = rpc_call(&coind->rpc, "validateaddress", params); if(!json) return false; json_value *json_result = json_get_object(json, "result"); diff --git a/stratum/coind.h b/stratum/coind.h index 611020b..f58f091 100644 --- a/stratum/coind.h +++ b/stratum/coind.h @@ -69,7 +69,7 @@ public: bool hasmasternodes; bool oldmasternodes; bool multialgos; // pow_hash field (or mined_hash) - bool hasgetinfo; + bool usesegwit; char commitment[128]; char witness_magic[16]; diff --git a/stratum/db.cpp b/stratum/db.cpp index fb0ca4e..f8c513c 100644 --- a/stratum/db.cpp +++ b/stratum/db.cpp @@ -193,7 +193,7 @@ void db_update_coinds(YAAMP_DB *db) 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, " "reward_mul, symbol, auxpow, actual_ttf, network_ttf, usememorypool, hasmasternodes, algo, symbol2, " - "rpccurl, rpcssl, rpccert, account, multialgos, max_miners, max_shares, usesegwit, hasgetinfo " + "rpccurl, rpcssl, rpccert, account, multialgos, max_miners, max_shares, usesegwit " "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); @@ -304,7 +304,6 @@ void db_update_coinds(YAAMP_DB *db) if(row[33] && atoi(row[33]) > 0) g_stratum_max_cons = atoi(row[33]); if(row[34] && atol(row[34]) > 0) g_max_shares = atol(row[34]); if(row[35]) coind->usesegwit = atoi(row[35]) > 0; - if(row[36]) coind->hasgetinfo = atoi(row[36]) > 0; if(coind->usesegwit) g_stratum_segwit = true; From b5e22c5a002064b8b7630f9c5b2a58d4baf95294 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Fri, 25 May 2018 15:58:42 +0200 Subject: [PATCH 114/195] stratum: DGB getaddressinfo to check master wallet --- stratum/coind.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/stratum/coind.cpp b/stratum/coind.cpp index 1544803..08073c6 100644 --- a/stratum/coind.cpp +++ b/stratum/coind.cpp @@ -114,7 +114,11 @@ bool coind_validate_address(YAAMP_COIND *coind) char params[YAAMP_SMALLBUFSIZE]; sprintf(params, "[\"%s\"]", coind->wallet); - json_value *json = rpc_call(&coind->rpc, "validateaddress", params); + json_value *json; + if(strcmp(coind->symbol,"DGB") == 0) + json = rpc_call(&coind->rpc, "getaddressinfo", params); + else + json = rpc_call(&coind->rpc, "validateaddress", params); if(!json) return false; json_value *json_result = json_get_object(json, "result"); From ab24ba8145b432d7f4c2b32ad763f908e2d6eb9d Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Fri, 25 May 2018 19:22:00 +0200 Subject: [PATCH 115/195] stratum: getaddressinfo doesnt return isvalid --- stratum/coind.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/stratum/coind.cpp b/stratum/coind.cpp index 08073c6..cfda91c 100644 --- a/stratum/coind.cpp +++ b/stratum/coind.cpp @@ -115,7 +115,8 @@ bool coind_validate_address(YAAMP_COIND *coind) sprintf(params, "[\"%s\"]", coind->wallet); json_value *json; - if(strcmp(coind->symbol,"DGB") == 0) + bool getaddressinfo = (strcmp(coind->symbol,"DGB") == 0); + if(getaddressinfo) json = rpc_call(&coind->rpc, "getaddressinfo", params); else json = rpc_call(&coind->rpc, "validateaddress", params); @@ -128,11 +129,12 @@ bool coind_validate_address(YAAMP_COIND *coind) return false; } - bool isvalid = json_get_bool(json_result, "isvalid"); + bool isvalid = getaddressinfo || json_get_bool(json_result, "isvalid"); if(!isvalid) stratumlog("%s wallet %s is not valid.\n", coind->name, coind->wallet); bool ismine = json_get_bool(json_result, "ismine"); if(!ismine) stratumlog("%s wallet %s is not mine.\n", coind->name, coind->wallet); + else isvalid = ismine; const char *p = json_get_string(json_result, "pubkey"); strcpy(coind->pubkey, p ? p : ""); From 5fcb58e9c9ce49889d5408946b20088503ce5f34 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Mon, 28 May 2018 11:32:17 +0200 Subject: [PATCH 116/195] api: add mbtc_mh_factor (mBTC/MH) to status api 1000 means mBTC/GH 0.001 for mBTC/kH --- web/yaamp/modules/api/ApiController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/web/yaamp/modules/api/ApiController.php b/web/yaamp/modules/api/ApiController.php index 9a5a156..bb4ba80 100644 --- a/web/yaamp/modules/api/ApiController.php +++ b/web/yaamp/modules/api/ApiController.php @@ -82,6 +82,7 @@ class ApiController extends CommonController "estimate_current" => $price, "estimate_last24h" => $avgprice, "actual_last24h" => $btcmhday1, + "mbtc_mh_factor" => $algo_unit_factor, "hashrate_last24h" => (double) $hashrate1, ); if(YAAMP_RENTAL) { From c1f2ad7cf02b5f9a6d34b7dd8cb4ba73e5fbae88 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Wed, 30 May 2018 15:22:24 +0200 Subject: [PATCH 117/195] api: disable rental apis if not enabled --- web/yaamp/modules/api/ApiController.php | 41 +++++++------------------ 1 file changed, 11 insertions(+), 30 deletions(-) diff --git a/web/yaamp/modules/api/ApiController.php b/web/yaamp/modules/api/ApiController.php index bb4ba80..d1217c5 100644 --- a/web/yaamp/modules/api/ApiController.php +++ b/web/yaamp/modules/api/ApiController.php @@ -6,8 +6,6 @@ class ApiController extends CommonController ///////////////////////////////////////////////// -// debuglog("saving renter {$_SERVER['REMOTE_ADDR']} $renter->address"); - public function actionStatus() { $client_ip = arraySafeVal($_SERVER,'REMOTE_ADDR'); @@ -289,9 +287,12 @@ class ApiController extends CommonController echo "}"; } + ///////////////////////////////////////////////// + public function actionRental() { if(!LimitRequest('api-rental', 10)) return; + if(!YAAMP_RENTAL) return; $key = getparam('key'); $renter = getdbosql('db_renters', "apikey=:apikey", array(':apikey'=>$key)); @@ -336,6 +337,8 @@ class ApiController extends CommonController public function actionRental_price() { + if(!YAAMP_RENTAL) return; + $key = getparam('key'); $renter = getdbosql('db_renters', "apikey=:apikey", array(':apikey'=>$key)); if(!$renter) return; @@ -353,6 +356,8 @@ class ApiController extends CommonController public function actionRental_hashrate() { + if(!YAAMP_RENTAL) return; + $key = getparam('key'); $renter = getdbosql('db_renters', "apikey=:apikey", array(':apikey'=>$key)); if(!$renter) return; @@ -370,6 +375,8 @@ class ApiController extends CommonController public function actionRental_start() { + if(!YAAMP_RENTAL) return; + $key = getparam('key'); $renter = getdbosql('db_renters', "apikey=:apikey", array(':apikey'=>$key)); if(!$renter || $renter->balance<=0) return; @@ -386,6 +393,8 @@ class ApiController extends CommonController public function actionRental_stop() { + if(!YAAMP_RENTAL) return; + $key = getparam('key'); $renter = getdbosql('db_renters', "apikey=:apikey", array(':apikey'=>$key)); if(!$renter) return; @@ -400,33 +409,5 @@ class ApiController extends CommonController $job->save(); } -// public function actionNodeReport() -// { -// $name = getparam('name'); -// $uptime = getparam('uptime'); - -// $server = getdbosql('db_servers', "name='$name'"); -// if(!$server) -// { -// $server = new db_servers; -// $server->name = $name; -// } - -// $server->uptime = $uptime; -// $server->save(); -// } - } -// function dummy() -// { -// $uptime = system('uptime'); -// $name = system('hostname'); - -// fetch_url("http://".YAAMP_SITE_URL."/api/nodereport?name=$name&uptime=$uptime"); -// } - - - - - From 3343328da56226d2b9fb52c53d721ac50be6da7a Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Thu, 31 May 2018 00:56:32 +0200 Subject: [PATCH 118/195] rpc: prevent any dump command --- web/yaamp/core/rpc/wallet-rpc.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/web/yaamp/core/rpc/wallet-rpc.php b/web/yaamp/core/rpc/wallet-rpc.php index 70104fb..533bb13 100644 --- a/web/yaamp/core/rpc/wallet-rpc.php +++ b/web/yaamp/core/rpc/wallet-rpc.php @@ -55,6 +55,12 @@ class WalletRPC { function __call($method, $params) { + if (stripos($method, "dump") !== false) { + $this->error = "$method not authorized!"; + debuglog("$method rpc method is not authorized!"); + return false; + } + if ($this->type == 'Ethereum') { if (!isset($this->accounts)) { $this->accounts = $this->rpc->eth_accounts(); @@ -64,11 +70,6 @@ class WalletRPC { // if wallet is stopped return false; } - if (stripos($method, "key") !== false) { - $this->error = "$method not authorized!"; - debuglog("$method not authorized (key)!"); - return false; - } // convert common methods used by yiimp switch ($method) { case 'getaccountaddress': From b0a0e53293d81cd3a2f86df64aa8b1749fd5dd87 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Thu, 31 May 2018 15:11:01 +0200 Subject: [PATCH 119/195] rpc: also prevent dangerous methods in core btc class --- web/yaamp/core/rpc/easybitcoin.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/web/yaamp/core/rpc/easybitcoin.php b/web/yaamp/core/rpc/easybitcoin.php index 59d8342..5021887 100644 --- a/web/yaamp/core/rpc/easybitcoin.php +++ b/web/yaamp/core/rpc/easybitcoin.php @@ -135,6 +135,11 @@ class Bitcoin { // The ID should be unique for each call $this->id++; + if (stripos($method, 'dump') !== false) { + $this->error = "$method method is not authorized!"; + return FALSE; + } + // If no parameters are passed, this will be an empty array if($method == 'getblocktemplate') { From ba20dc3ffaaa7a705bae3c7adc91e756afcb4219 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Fri, 1 Jun 2018 18:11:28 +0200 Subject: [PATCH 120/195] stratum: check if blocknotify string param is set --- stratum/client.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stratum/client.cpp b/stratum/client.cpp index 37232e4..3308b9f 100644 --- a/stratum/client.cpp +++ b/stratum/client.cpp @@ -291,7 +291,7 @@ bool client_authorize(YAAMP_CLIENT *client, json_value *json_params) bool client_update_block(YAAMP_CLIENT *client, json_value *json_params) { // password, id, block hash - if(json_params->u.array.length < 3) + if(json_params->u.array.length < 3 || !json_params->u.array.values[0]->u.string.ptr) { clientlog(client, "update block, bad params"); return false; From 411a6c734301edb430d5a4d2983d004646c8f50a Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Sun, 3 Jun 2018 18:41:33 +0200 Subject: [PATCH 121/195] stratum: more string params checks --- stratum/client.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stratum/client.cpp b/stratum/client.cpp index 3308b9f..3c2bd94 100644 --- a/stratum/client.cpp +++ b/stratum/client.cpp @@ -202,7 +202,7 @@ bool client_authorize(YAAMP_CLIENT *client, json_value *json_params) return false; } - if(json_params->u.array.length>1) + if(json_params->u.array.length>1 && json_params->u.array.values[1]->u.string.ptr) strncpy(client->password, json_params->u.array.values[1]->u.string.ptr, 1023); if (g_list_client.count >= g_stratum_max_cons) { @@ -210,7 +210,7 @@ bool client_authorize(YAAMP_CLIENT *client, json_value *json_params) return false; } - if(json_params->u.array.length>0) + if(json_params->u.array.length>0 && json_params->u.array.values[0]->u.string.ptr) { strncpy(client->username, json_params->u.array.values[0]->u.string.ptr, 1023); From 5e0f1e1d1c3e78871caab853edfc08137ae66ef1 Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Wed, 6 Jun 2018 18:28:17 +0200 Subject: [PATCH 122/195] handle phi2 algo --- stratum/algos/makefile | 2 +- stratum/algos/phi2.c | 62 ++++++++++++++++++++++++++++++ stratum/algos/phi2.h | 16 ++++++++ stratum/config.sample/phi2.conf | 16 ++++++++ stratum/stratum.cpp | 1 + stratum/stratum.h | 1 + web/yaamp/core/functions/yaamp.php | 3 ++ 7 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 stratum/algos/phi2.c create mode 100644 stratum/algos/phi2.h create mode 100644 stratum/config.sample/phi2.conf diff --git a/stratum/algos/makefile b/stratum/algos/makefile index d7c296f..90b2614 100644 --- a/stratum/algos/makefile +++ b/stratum/algos/makefile @@ -19,7 +19,7 @@ SOURCES=lyra2re.c lyra2v2.c Lyra2.c lyra2z.c Lyra2-z.c Sponge.c allium.c \ a5a.c a5amath.c m7m.c magimath.cpp velvet.c \ argon2a.c ar2/blake2b.c ar2/argon2.c ar2/ref.c ar2/cores.c ar2/ar2-scrypt-jane.c \ hive.c pomelo.c \ - phi.c polytimos.c skunk.c sib.c veltor.c gost.c + phi.c phi2.c polytimos.c skunk.c sib.c veltor.c gost.c OBJECTS=$(SOURCES:%.c=%.o) $(SOURCES:%.cpp=%.o) OUTPUT=libalgos.a diff --git a/stratum/algos/phi2.c b/stratum/algos/phi2.c new file mode 100644 index 0000000..59d34bb --- /dev/null +++ b/stratum/algos/phi2.c @@ -0,0 +1,62 @@ +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "gost.h" + +#include "Lyra2.h" + +#include "common.h" + +void phi2_hash(const char* input, char* output, uint32_t len) +{ + unsigned char _ALIGN(128) hash[128] = { 0 }; + unsigned char _ALIGN(128) hashA[64] = { 0 }; + unsigned char _ALIGN(128) hashB[64] = { 0 }; + + sph_cubehash512_context ctx_cubehash; + sph_jh512_context ctx_jh; + sph_gost512_context ctx_gost; + sph_echo512_context ctx_echo; + sph_skein512_context ctx_skein; + + sph_cubehash512_init(&ctx_cubehash); + sph_cubehash512(&ctx_cubehash, input, 80); + sph_cubehash512_close(&ctx_cubehash, (void*)hashB); + + LYRA2(&hashA[ 0], 32, &hashB[ 0], 32, &hashB[ 0], 32, 1, 8, 8); + LYRA2(&hashA[32], 32, &hashB[32], 32, &hashB[32], 32, 1, 8, 8); + + sph_jh512_init(&ctx_jh); + sph_jh512(&ctx_jh, (const void*)hashA, 64); + sph_jh512_close(&ctx_jh, (void*)hash); + + if (hash[0] & 1) { + sph_gost512_init(&ctx_gost); + sph_gost512(&ctx_gost, (const void*)hash, 64); + sph_gost512_close(&ctx_gost, (void*)hash); + } else { + sph_echo512_init(&ctx_echo); + sph_echo512(&ctx_echo, (const void*)hash, 64); + sph_echo512_close(&ctx_echo, (void*)hash); + + sph_echo512_init(&ctx_echo); + sph_echo512(&ctx_echo, (const void*)hash, 64); + sph_echo512_close(&ctx_echo, (void*)hash); + } + + sph_skein512_init(&ctx_skein); + sph_skein512(&ctx_skein, (const void*)hash, 64); + sph_skein512_close(&ctx_skein, (void*)hash); + + for (int i=0; i<32; i++) + hash[i] ^= hash[i+32]; + + memcpy(output, hash, 32); +} diff --git a/stratum/algos/phi2.h b/stratum/algos/phi2.h new file mode 100644 index 0000000..d551d28 --- /dev/null +++ b/stratum/algos/phi2.h @@ -0,0 +1,16 @@ +#ifndef PHI2_H +#define PHI2_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +void phi2_hash(const char* input, char* output, uint32_t len); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/stratum/config.sample/phi2.conf b/stratum/config.sample/phi2.conf new file mode 100644 index 0000000..f961112 --- /dev/null +++ b/stratum/config.sample/phi2.conf @@ -0,0 +1,16 @@ +[TCP] +server = yaamp.com +port = 8332 +password = tu8tu5 + +[SQL] +host = yaampdb +database = yaamp +username = root +password = patofpaq + +[STRATUM] +algo = phi2 +difficulty = 1 +max_ttf = 40000 + diff --git a/stratum/stratum.cpp b/stratum/stratum.cpp index 4fcba40..f1f0c61 100644 --- a/stratum/stratum.cpp +++ b/stratum/stratum.cpp @@ -158,6 +158,7 @@ YAAMP_ALGO g_algos[] = {"keccak", keccak256_hash, 0x80, 0, sha256_hash_hex }, {"keccakc", keccak256_hash, 0x100, 0, 0}, {"phi", phi_hash, 1, 0, 0}, + {"phi2", phi2_hash, 0x100, 0, 0}, {"polytimos", polytimos_hash, 1, 0, 0}, {"skunk", skunk_hash, 1, 0, 0}, diff --git a/stratum/stratum.h b/stratum/stratum.h index b4b6fe7..0cdf9c3 100644 --- a/stratum/stratum.h +++ b/stratum/stratum.h @@ -196,6 +196,7 @@ void sha256_double_hash_hex(const char *input, char *output, unsigned int len); #include "algos/sib.h" #include "algos/m7m.h" #include "algos/phi.h" +#include "algos/phi2.h" #include "algos/polytimos.h" #include "algos/tribus.h" #include "algos/veltor.h" diff --git a/web/yaamp/core/functions/yaamp.php b/web/yaamp/core/functions/yaamp.php index e7adae2..c9a96e0 100755 --- a/web/yaamp/core/functions/yaamp.php +++ b/web/yaamp/core/functions/yaamp.php @@ -49,6 +49,7 @@ function yaamp_get_algos() 'myr-gr', 'm7m', 'phi', + 'phi2', 'sib', 'skein', 'skein2', @@ -173,6 +174,7 @@ function getAlgoColors($algo) 'lyra2v2' => '#80c0f0', 'lyra2z' => '#80b0f0', 'phi' => '#a0a0e0', + 'phi2' => '#a0a0e0', 'polytimos' => '#dedefe', 'sib' => '#a0a0c0', 'skein' => '#80a0a0', @@ -263,6 +265,7 @@ function getAlgoPort($algo) 'bastion' => 6433, 'hsr' => 7433, 'phi' => 8333, + 'phi2' => 8332, 'polytimos' => 8463, 'skunk' => 8433, 'tribus' => 8533, From 8841bf4201387fcfb046f6ca6ec950c494cbed93 Mon Sep 17 00:00:00 2001 From: crackfoo Date: Wed, 6 Jun 2018 13:38:20 -0300 Subject: [PATCH 123/195] explorer: support for DUO multialgo (#272) --- web/yaamp/modules/explorer/util.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/web/yaamp/modules/explorer/util.php b/web/yaamp/modules/explorer/util.php index 39ce81f..ed7db07 100644 --- a/web/yaamp/modules/explorer/util.php +++ b/web/yaamp/modules/explorer/util.php @@ -160,6 +160,9 @@ function versionToAlgo($coin, $version) $algos['DGC'] = array( 0=>'scrypt', 1=>'sha256', 2=>'x11' ); + $algos['DUO'] = array( + 0=>'sha256', 1=>'scrypt' + ); $algos['J'] = array( 2 =>'sha256', 3=>'x11', 4=>'x13', 5=>'x15', 6=>'scrypt', 7 =>'nist5', 8 =>'myr-gr', 9=>'penta', 10=>'whirlpool', From 6e874602165511d2b83d6c1c55bcfe669105349e Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Thu, 7 Jun 2018 11:07:16 +0200 Subject: [PATCH 124/195] stratum: reduce valid ntime range --- stratum/client_submit.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stratum/client_submit.cpp b/stratum/client_submit.cpp index 78fc94c..c3f19d6 100644 --- a/stratum/client_submit.cpp +++ b/stratum/client_submit.cpp @@ -339,10 +339,10 @@ static bool ntime_valid_range(const char ntimehex[]) uint32_t ntime = 0; if (strlen(ntimehex) != 8) return false; sscanf(ntimehex, "%8x", &ntime); - if (ntime < 0x57000000 || ntime > 0x60000000) // 14 Jan 2021 - ntime = bswap32(ntime); // just in case... + if (ntime < 0x5b000000 || ntime > 0x60000000) // 14 Jan 2021 + return false; time(&rawtime); - return ((rawtime - ntime) < (23 * 60 * 60)); + return (abs(rawtime - ntime) < (30 * 60)); } bool client_submit(YAAMP_CLIENT *client, json_value *json_params) From eee06c920b1ca70b66fb78c1b2f3bf35a8de674d Mon Sep 17 00:00:00 2001 From: itamarcps <32653934+itamarcps@users.noreply.github.com> Date: Fri, 8 Jun 2018 14:49:48 -0300 Subject: [PATCH 125/195] stratum: add aergo algo (#274) + spaces fixes --- stratum/algos/aergo.c | 162 +++++++++++++++++++++++++++++ stratum/algos/aergo.h | 17 +++ stratum/algos/makefile | 2 +- stratum/config.sample/aergo.conf | 15 +++ stratum/stratum.cpp | 1 + stratum/stratum.h | 1 + web/yaamp/core/functions/yaamp.php | 3 + 7 files changed, 200 insertions(+), 1 deletion(-) create mode 100644 stratum/algos/aergo.c create mode 100644 stratum/algos/aergo.h create mode 100644 stratum/config.sample/aergo.conf diff --git a/stratum/algos/aergo.c b/stratum/algos/aergo.c new file mode 100644 index 0000000..7a79184 --- /dev/null +++ b/stratum/algos/aergo.c @@ -0,0 +1,162 @@ +#include "aergo.h" +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "gost.h" + +#include "common.h" + +void aergo_hash(const char* input, char* output, uint32_t len) +{ + uint32_t hash[16]; + + sph_blake512_context ctx_blake; + sph_bmw512_context ctx_bmw; + sph_groestl512_context ctx_groestl; + sph_jh512_context ctx_jh; + sph_keccak512_context ctx_keccak; + sph_skein512_context ctx_skein; + sph_luffa512_context ctx_luffa; + sph_cubehash512_context ctx_cubehash; + sph_shavite512_context ctx_shavite; + sph_simd512_context ctx_simd; + sph_echo512_context ctx_echo; + sph_hamsi512_context ctx_hamsi; + sph_fugue512_context ctx_fugue; + sph_shabal512_context ctx_shabal; + sph_gost512_context ctx_gost; + sph_whirlpool_context ctx_whirlpool; + sph_haval256_5_context ctx_haval; + + sph_echo512_init(&ctx_echo); + sph_echo512(&ctx_echo, input, len); + sph_echo512_close(&ctx_echo, hash); + + sph_simd512_init(&ctx_simd); + sph_simd512(&ctx_simd, hash, 64); + sph_simd512_close(&ctx_simd, hash); + + sph_blake512_init(&ctx_blake); + sph_blake512(&ctx_blake, hash, 64); + sph_blake512_close(&ctx_blake, hash); + + sph_bmw512_init(&ctx_bmw); + sph_bmw512(&ctx_bmw, hash, 64); + sph_bmw512_close(&ctx_bmw, hash); + + sph_whirlpool_init(&ctx_whirlpool); + sph_whirlpool(&ctx_whirlpool, hash, 64); + sph_whirlpool_close(&ctx_whirlpool, hash); + + sph_groestl512_init(&ctx_groestl); + sph_groestl512(&ctx_groestl, hash, 64); + sph_groestl512_close(&ctx_groestl, hash); + + sph_gost512_init(&ctx_gost); + sph_gost512(&ctx_gost, hash, 64); + sph_gost512_close(&ctx_gost, hash); + + sph_skein512_init(&ctx_skein); + sph_skein512(&ctx_skein, hash, 64); + sph_skein512_close(&ctx_skein, hash); + + sph_bmw512_init(&ctx_bmw); + sph_bmw512(&ctx_bmw, hash, 64); + sph_bmw512_close(&ctx_bmw, hash); + + sph_jh512_init(&ctx_jh); + sph_jh512(&ctx_jh, hash, 64); + sph_jh512_close(&ctx_jh, hash); + + sph_luffa512_init(&ctx_luffa); + sph_luffa512(&ctx_luffa, hash, 64); + sph_luffa512_close(&ctx_luffa, hash); + + sph_keccak512_init(&ctx_keccak); + sph_keccak512(&ctx_keccak, hash, 64); + sph_keccak512_close(&ctx_keccak, hash); + + sph_gost512_init(&ctx_gost); + sph_gost512(&ctx_gost, hash, 64); + sph_gost512_close(&ctx_gost, hash); + + sph_cubehash512_init(&ctx_cubehash); + sph_cubehash512(&ctx_cubehash, hash, 64); + sph_cubehash512_close(&ctx_cubehash, hash); + + sph_echo512_init(&ctx_echo); + sph_echo512(&ctx_echo, hash, 64); + sph_echo512_close(&ctx_echo, hash); + + sph_simd512_init(&ctx_simd); + sph_simd512(&ctx_simd, hash, 64); + sph_simd512_close(&ctx_simd, hash); + + sph_hamsi512_init(&ctx_hamsi); + sph_hamsi512(&ctx_hamsi, hash, 64); + sph_hamsi512_close(&ctx_hamsi, hash); + + sph_fugue512_init(&ctx_fugue); + sph_fugue512(&ctx_fugue, hash, 64); + sph_fugue512_close(&ctx_fugue, hash); + + sph_shavite512_init(&ctx_shavite); + sph_shavite512(&ctx_shavite, hash, 64); + sph_shavite512_close(&ctx_shavite, hash); + + sph_shabal512_init(&ctx_shabal); + sph_shabal512(&ctx_shabal, hash, 64); + sph_shabal512_close(&ctx_shabal, hash); + + sph_haval256_5_init(&ctx_haval); + sph_haval256_5(&ctx_haval,(const void*) hash, 64); + sph_haval256_5_close(&ctx_haval, hash); + + sph_shavite512_init(&ctx_shavite); + sph_shavite512(&ctx_shavite, hash, 64); + sph_shavite512_close(&ctx_shavite, hash); + + sph_gost512_init(&ctx_gost); + sph_gost512(&ctx_gost, hash, 64); + sph_gost512_close(&ctx_gost, hash); + + sph_echo512_init(&ctx_echo); + sph_echo512(&ctx_echo, hash, 64); + sph_echo512_close(&ctx_echo, hash); + + sph_blake512_init(&ctx_blake); + sph_blake512(&ctx_blake, hash, 64); + sph_blake512_close(&ctx_blake, hash); + + sph_jh512_init(&ctx_jh); + sph_jh512(&ctx_jh, hash, 64); + sph_jh512_close(&ctx_jh, hash); + + sph_cubehash512_init(&ctx_cubehash); + sph_cubehash512(&ctx_cubehash, hash, 64); + sph_cubehash512_close(&ctx_cubehash, hash); + + sph_simd512_init(&ctx_simd); + sph_simd512(&ctx_simd, hash, 64); + sph_simd512_close(&ctx_simd, hash); + + memcpy(output, hash, 32); +} diff --git a/stratum/algos/aergo.h b/stratum/algos/aergo.h new file mode 100644 index 0000000..ad129b3 --- /dev/null +++ b/stratum/algos/aergo.h @@ -0,0 +1,17 @@ + +#ifndef AERGO_H +#define AERGO_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +void aergo_hash(const char* input, char* output, uint32_t len); + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/stratum/algos/makefile b/stratum/algos/makefile index 90b2614..612d508 100644 --- a/stratum/algos/makefile +++ b/stratum/algos/makefile @@ -19,7 +19,7 @@ SOURCES=lyra2re.c lyra2v2.c Lyra2.c lyra2z.c Lyra2-z.c Sponge.c allium.c \ a5a.c a5amath.c m7m.c magimath.cpp velvet.c \ argon2a.c ar2/blake2b.c ar2/argon2.c ar2/ref.c ar2/cores.c ar2/ar2-scrypt-jane.c \ hive.c pomelo.c \ - phi.c phi2.c polytimos.c skunk.c sib.c veltor.c gost.c + phi.c phi2.c polytimos.c skunk.c sib.c veltor.c gost.c aergo.c OBJECTS=$(SOURCES:%.c=%.o) $(SOURCES:%.cpp=%.o) OUTPUT=libalgos.a diff --git a/stratum/config.sample/aergo.conf b/stratum/config.sample/aergo.conf new file mode 100644 index 0000000..c7488e3 --- /dev/null +++ b/stratum/config.sample/aergo.conf @@ -0,0 +1,15 @@ +[TCP] +server = yaamp.com +port = 3691 +password = tu8tu5 + +[SQL] +host = yaampdb +database = yaamp +username = root +password = patofpaq + +[STRATUM] +algo = aergo +difficulty = 0.001 +max_ttf = 400000000 \ No newline at end of file diff --git a/stratum/stratum.cpp b/stratum/stratum.cpp index f1f0c61..26fd175 100644 --- a/stratum/stratum.cpp +++ b/stratum/stratum.cpp @@ -179,6 +179,7 @@ YAAMP_ALGO g_algos[] = {"velvet", velvet_hash, 0x10000, 0, 0}, {"argon2", argon2_hash, 0x10000, 0, sha256_hash_hex }, {"vitalium", vitalium_hash, 1, 0, 0}, + {"aergo", aergo_hash, 1, 0, 0}, {"sha256t", sha256t_hash, 1, 0, 0}, // sha256 3x diff --git a/stratum/stratum.h b/stratum/stratum.h index 0cdf9c3..549084f 100644 --- a/stratum/stratum.h +++ b/stratum/stratum.h @@ -203,4 +203,5 @@ void sha256_double_hash_hex(const char *input, char *output, unsigned int len); #include "algos/velvet.h" #include "algos/argon2a.h" #include "algos/vitalium.h" +#include "algos/aergo.h" diff --git a/web/yaamp/core/functions/yaamp.php b/web/yaamp/core/functions/yaamp.php index c9a96e0..4307f8a 100755 --- a/web/yaamp/core/functions/yaamp.php +++ b/web/yaamp/core/functions/yaamp.php @@ -10,6 +10,7 @@ function yaamp_get_algos() 'scryptn', 'allium', 'argon2', + 'aergo', 'bastion', 'bitcore', 'blake', @@ -152,6 +153,7 @@ function getAlgoColors($algo) 'xevan' => '#f0b0a0', 'allium' => '#80a0d0', 'argon2' => '#e0d0e0', + 'aergo' => '#e0d0e0', 'bastion' => '#e0b0b0', 'blake' => '#f0f0f0', 'blakecoin' => '#f0f0f0', @@ -222,6 +224,7 @@ function getAlgoPort($algo) 'x16r' => 3636, 'x16s' => 3663, 'x17' => 3737, + 'aergo' => 3691, 'xevan' => 3739, 'hmq1725' => 3747, 'nist5' => 3833, From 035d304150073ca05826148074f66a05b60d58db Mon Sep 17 00:00:00 2001 From: Tanguy Pruvot Date: Sat, 9 Jun 2018 08:20:17 +0200 Subject: [PATCH 126/195] checkup: delete images containing cloudcrap scripts