decred: handle reggression in orphaned getblock + cleanup

removed confusing/dead code in stratum code (failed attempt to use gbt)
This commit is contained in:
Tanguy Pruvot 2017-01-17 16:47:25 +01:00
parent 83b9858d24
commit 09336533c0
2 changed files with 24 additions and 56 deletions

View file

@ -14,29 +14,6 @@ static void encode_tx_value(char *encoded, json_int_t value)
TX_VALUE(value, 32), TX_VALUE(value, 40), TX_VALUE(value, 48), TX_VALUE(value, 56));
}
static void job_pack_devfees(YAAMP_COIND *coind, char *data, json_int_t amount, char *addr)
{
char evalue[32];
encode_tx_value(evalue, amount);
sprintf(data+strlen(data), "%s", evalue);
// "asm": "OP_HASH160 f5916158e3e2c4551c1796708db8367207ed13bb OP_EQUAL",
// "hex": "a914f5916158e3e2c4551c1796708db8367207ed13bb87",
sprintf(data+strlen(data), "a914%s87", addr);
}
static void job_pack_vote(YAAMP_COIND *coind, char *data, char *blockhash)
{
// OP_RETURN validSSGenReferenceOutPrefix
// 32 byte block header hash for the block + uint32 for the height of the block
char evalue[32];
char eheight[8];
char hash[65] = "000000000000000000000000000000000000000000000000df910622e44ef4b2";
uint32_t height = coind->height;
sprintf(eheight, "%02x%02x%02x%02x", TX_VALUE(height, 0), TX_VALUE(height, 8), TX_VALUE(height, 16), TX_VALUE(height, 24));
encode_tx_value(evalue, 0);
sprintf(data+strlen(data), "6a24%s%sdea1906f%s", eheight, blockhash ? blockhash : hash, evalue);
}
static void job_pack_tx(YAAMP_COIND *coind, char *data, json_int_t amount, char *key)
{
int ol = strlen(data);
@ -101,25 +78,17 @@ void coinbase_create(YAAMP_COIND *coind, YAAMP_JOB_TEMPLATE *templ, json_value *
char script1[4*1024];
sprintf(script1, "%s%s%s08", eheight, templ->flags, etime);
if (strcmp(coind->symbol, "DCR") == 0) {
sprintf(templ->coinb1, "%s01"
"0000000000000000000000000000000000000000000000000000000000000000"
"ffffffff00ffffffff", eversion1);
strcpy(templ->coinb2, "");
} else {
char script2[32] = "7969696d7000"; // "yiimp\0" in hex ascii
char script2[32] = "7969696d7000"; // "yiimp\0" in hex ascii
if(!coind->pos && !coind->isaux && templ->auxs_size)
coinbase_aux(templ, script2);
if(!coind->pos && !coind->isaux && templ->auxs_size)
coinbase_aux(templ, script2);
int script_len = strlen(script1)/2 + strlen(script2)/2 + 8;
sprintf(templ->coinb1, "%s%s01"
"0000000000000000000000000000000000000000000000000000000000000000"
"ffffffff%02x%s", eversion1, entime, script_len, script1);
int script_len = strlen(script1)/2 + strlen(script2)/2 + 8;
sprintf(templ->coinb1, "%s%s01"
"0000000000000000000000000000000000000000000000000000000000000000"
"ffffffff%02x%s", eversion1, entime, script_len, script1);
sprintf(templ->coinb2, "%s00000000", script2);
}
sprintf(templ->coinb2, "%s00000000", script2);
json_int_t available = templ->value;
@ -173,22 +142,7 @@ void coinbase_create(YAAMP_COIND *coind, YAAMP_JOB_TEMPLATE *templ, json_value *
else if(coind->charity_amount && !strcmp("DCR", coind->rpcencoding))
{
char script_payee[1024];
char charity_payee[256] = { 0 };
const char *payee = json_get_string(json_result, "payee");
if (payee) snprintf(charity_payee, 255, "%s", payee);
else sprintf(charity_payee, "%s", coind->charity_address);
if (strlen(charity_payee) == 0)
stratumlog("ERROR %s has no charity_address set!\n", coind->name);
base58_decode(charity_payee, script_payee);
strcat(templ->coinb2, "03");
job_pack_devfees(coind, templ->coinb2, coind->charity_amount, script_payee);
job_pack_vote(coind, templ->coinb2, templ->prevhash_hex);
job_pack_tx(coind, templ->coinb2, available, NULL);
strcat(templ->coinb2, "00000000"); // locktime
stratumlog("ERROR %s should not use coinbase (getwork only)!\n", coind->symbol);
coind->reward = (double)available/100000000;
return;
}

View file

@ -183,8 +183,22 @@ function BackendBlocksUpdate($coinid = NULL)
$tx = $remote->gettransaction($block->txhash);
if(!$tx) {
if ($coin->enable)
if ($coin->enable) {
debuglog("{$coin->name} unable to find block {$block->height} tx {$block->txhash}!");
// DCR orphaned confirmations are not(no more) -1!
if($coin->rpcencoding == 'DCR' && $block->category == 'immature') {
$blockext = $remote->getblock($block->blockhash);
$conf = arraySafeVal($blockext,'confirmations',-1);
if ($conf == -1 || ($conf > 2 && arraySafeVal($blockext,'nextblockhash','') == '')) {
debuglog("{$coin->name} orphan block {$block->height} detected! (after $conf confirmations)");
$block->confirmations = -1;
$block->amount = 0;
$block->category = 'orphan';
$block->save();
continue;
}
}
}
else if ((time() - $block->time) > (7 * 24 * 3600)) {
debuglog("{$coin->name} outdated immature block {$block->height} detected!");
$block->category = 'orphan';