don't drop from bounded stack and other tweaks

This commit is contained in:
Jethro Grassie 2019-05-11 14:51:56 -04:00
parent 3052e3e20d
commit 98d6fc474f
No known key found for this signature in database
GPG key ID: DE8ED755616565BB

View file

@ -709,13 +709,13 @@ process_blocks(block_t *blocks, size_t count)
{ {
continue; continue;
} }
block_t nb;
memcpy(&nb, sb, sizeof(block_t));
if (ib->status & BLOCK_ORPHANED) if (ib->status & BLOCK_ORPHANED)
{ {
log_debug("Orphaned block at height %"PRIu64, ib->height); log_debug("Orphaned block at height %"PRIu64, ib->height);
block_t bp; nb.status |= BLOCK_ORPHANED;
memcpy(&bp, sb, sizeof(block_t)); MDB_val new_val = {sizeof(block_t), (void*)&nb};
bp.status |= BLOCK_ORPHANED;
MDB_val new_val = {sizeof(block_t), (void*)&bp};
mdb_cursor_put(cursor, &key, &new_val, MDB_CURRENT); mdb_cursor_put(cursor, &key, &new_val, MDB_CURRENT);
continue; continue;
} }
@ -724,22 +724,18 @@ process_blocks(block_t *blocks, size_t count)
{ {
log_warn("Block with matching heights but differing parents! " log_warn("Block with matching heights but differing parents! "
"Setting orphaned.\n"); "Setting orphaned.\n");
block_t bp; nb.status |= BLOCK_ORPHANED;
memcpy(&bp, sb, sizeof(block_t)); MDB_val new_val = {sizeof(block_t), (void*)&nb};
bp.status |= BLOCK_ORPHANED;
MDB_val new_val = {sizeof(block_t), (void*)&bp};
mdb_cursor_put(cursor, &key, &new_val, MDB_CURRENT); mdb_cursor_put(cursor, &key, &new_val, MDB_CURRENT);
continue; continue;
} }
block_t bp; nb.status |= BLOCK_UNLOCKED;
memcpy(&bp, sb, sizeof(block_t)); nb.reward = ib->reward;
bp.status |= BLOCK_UNLOCKED; rc = payout_block(&nb, txn);
bp.reward = ib->reward;
rc = payout_block(&bp, txn);
if (rc == 0) if (rc == 0)
{ {
log_debug("Paided out block %"PRIu64, bp.height); log_debug("Paided out block %"PRIu64, nb.height);
MDB_val new_val = {sizeof(block_t), (void*)&bp}; MDB_val new_val = {sizeof(block_t), (void*)&nb};
mdb_cursor_put(cursor, &key, &new_val, MDB_CURRENT); mdb_cursor_put(cursor, &key, &new_val, MDB_CURRENT);
} }
else else
@ -1402,7 +1398,7 @@ startup_pauout(uint64_t height)
if (block->height > height - 60) if (block->height > height - 60)
continue; continue;
if (block->status & BLOCK_UNLOCKED || block->status & BLOCK_ORPHANED) if (block->status != BLOCK_LOCKED)
continue; continue;
char body[RPC_BODY_MAX]; char body[RPC_BODY_MAX];
@ -1444,22 +1440,25 @@ rpc_on_last_block_header(const char* data, rpc_callback_t *callback)
json_object_put(root); json_object_put(root);
return; return;
} }
block_t *front = bstack_peek(bsh);
block_t *block = bstack_push(bsh, NULL);
JSON_GET_OR_WARN(block_header, result, json_type_object); JSON_GET_OR_WARN(block_header, result, json_type_object);
response_to_block(block_header, block); JSON_GET_OR_WARN(height, block_header, json_type_int);
uint64_t bh = json_object_get_int64(height);
bool need_new_template = false; bool need_new_template = false;
if (front != NULL && block->height > front->height) block_t *front = bstack_peek(bsh);
if (front != NULL && bh > front->height)
{ {
need_new_template = true; need_new_template = true;
block_t *block = bstack_push(bsh, NULL);
response_to_block(block_header, block);
} }
else if (front == NULL) else if (front == NULL)
{ {
block_t *block = bstack_push(bsh, NULL);
response_to_block(block_header, block);
startup_pauout(block->height); startup_pauout(block->height);
need_new_template = true; need_new_template = true;
} }
else
bstack_drop(bsh);
front = bstack_peek(bsh); front = bstack_peek(bsh);
pool_stats.network_difficulty = front->difficulty; pool_stats.network_difficulty = front->difficulty;
@ -1477,7 +1476,7 @@ rpc_on_last_block_header(const char* data, rpc_callback_t *callback)
rpc_callback_t *cb1 = rpc_callback_new(rpc_on_block_template, NULL); rpc_callback_t *cb1 = rpc_callback_new(rpc_on_block_template, NULL);
rpc_request(base, body, cb1); rpc_request(base, body, cb1);
uint64_t end = block->height - 60; uint64_t end = front->height - 60;
uint64_t start = end - BLOCK_HEADERS_RANGE + 1; uint64_t start = end - BLOCK_HEADERS_RANGE + 1;
rpc_get_request_body(body, "get_block_headers_range", "sdsd", rpc_get_request_body(body, "get_block_headers_range", "sdsd",
"start_height", start, "end_height", end); "start_height", start, "end_height", end);
@ -2027,14 +2026,13 @@ client_on_submit(json_object *message, client_t *client)
/* Process share */ /* Process share */
client->hashes += job->target; client->hashes += job->target;
time_t now = time(NULL); time_t now = time(NULL);
bool can_store = true;
log_trace("Checking hash against blobk difficulty: " log_trace("Checking hash against blobk difficulty: "
"%lu, job difficulty: %lu", "%lu, job difficulty: %lu",
BN_get_word(bd), BN_get_word(jd)); BN_get_word(bd), BN_get_word(jd));
bool can_store = false;
if (BN_cmp(hd, bd) >= 0) if (BN_cmp(hd, bd) >= 0)
{ {
can_store = true;
/* Yay! Mined a block so submit to network */ /* Yay! Mined a block so submit to network */
log_info("+++ MINED A BLOCK +++"); log_info("+++ MINED A BLOCK +++");
char *block_hex = calloc((bin_size << 1)+1, sizeof(char)); char *block_hex = calloc((bin_size << 1)+1, sizeof(char));
@ -2047,7 +2045,6 @@ client_on_submit(json_object *message, client_t *client)
rpc_callback_t *cb = rpc_callback_new(rpc_on_block_submitted, NULL); rpc_callback_t *cb = rpc_callback_new(rpc_on_block_submitted, NULL);
cb->data = calloc(1, sizeof(block_t)); cb->data = calloc(1, sizeof(block_t));
block_t* b = (block_t*) cb->data; block_t* b = (block_t*) cb->data;
b->height = bt->height; b->height = bt->height;
bin_to_hex(submitted_hash, 32, b->hash, 64); bin_to_hex(submitted_hash, 32, b->hash, 64);
@ -2067,8 +2064,6 @@ client_on_submit(json_object *message, client_t *client)
log_debug("Low difficulty (%lu) share", BN_get_word(jd)); log_debug("Low difficulty (%lu) share", BN_get_word(jd));
evbuffer_add(output, body, strlen(body)); evbuffer_add(output, body, strlen(body));
} }
else
can_store = true;
BN_free(hd); BN_free(hd);
BN_free(jd); BN_free(jd);