fix orphaning

This commit is contained in:
Jethro Grassie 2019-08-23 16:24:03 -04:00
parent af3bf72f08
commit af9b9c8953
No known key found for this signature in database
GPG key ID: DE8ED755616565BB

View file

@ -743,7 +743,7 @@ process_blocks(block_t *blocks, size_t count)
} }
block_t nb; block_t nb;
memcpy(&nb, sb, sizeof(block_t)); memcpy(&nb, sb, sizeof(block_t));
if (ib->status & BLOCK_ORPHANED) if (memcmp(ib->hash, sb->hash, 64) != 0)
{ {
log_debug("Orphaned block at height %"PRIu64, ib->height); log_debug("Orphaned block at height %"PRIu64, ib->height);
nb.status |= BLOCK_ORPHANED; nb.status |= BLOCK_ORPHANED;
@ -751,16 +751,24 @@ process_blocks(block_t *blocks, size_t count)
mdb_cursor_put(cursor, &key, &new_val, MDB_CURRENT); mdb_cursor_put(cursor, &key, &new_val, MDB_CURRENT);
continue; continue;
} }
if (memcmp(ib->hash, sb->hash, 64) == 0 if (memcmp(ib->prev_hash, sb->prev_hash, 64) != 0)
&& memcmp(ib->prev_hash, sb->prev_hash, 64) != 0)
{ {
log_warn("Block with matching heights but differing parents! " log_warn("Block with matching height and hash "
"but differing parent! "
"Setting orphaned.\n"); "Setting orphaned.\n");
nb.status |= BLOCK_ORPHANED; nb.status |= BLOCK_ORPHANED;
MDB_val new_val = {sizeof(block_t), (void*)&nb}; 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);
continue; continue;
} }
if (ib->status & BLOCK_ORPHANED)
{
log_debug("Orphaned block at height %"PRIu64, ib->height);
nb.status |= BLOCK_ORPHANED;
MDB_val new_val = {sizeof(block_t), (void*)&nb};
mdb_cursor_put(cursor, &key, &new_val, MDB_CURRENT);
continue;
}
nb.status |= BLOCK_UNLOCKED; nb.status |= BLOCK_UNLOCKED;
nb.reward = ib->reward; nb.reward = ib->reward;
rc = payout_block(&nb, txn); rc = payout_block(&nb, txn);