use correct block hash for matching

This commit is contained in:
Jethro Grassie 2019-08-23 20:33:23 -04:00
parent 6471c6a20a
commit c24a3ba3c8
No known key found for this signature in database
GPG key ID: DE8ED755616565BB
4 changed files with 24 additions and 2 deletions

View file

@ -745,6 +745,8 @@ process_blocks(block_t *blocks, size_t count)
memcpy(&nb, sb, sizeof(block_t)); memcpy(&nb, sb, sizeof(block_t));
if (memcmp(ib->hash, sb->hash, 64) != 0) if (memcmp(ib->hash, sb->hash, 64) != 0)
{ {
log_trace("Orphaning because hashes differ: %.64s, %.64s",
ib->hash, sb->hash);
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;
MDB_val new_val = {sizeof(block_t), (void*)&nb}; MDB_val new_val = {sizeof(block_t), (void*)&nb};
@ -2403,7 +2405,10 @@ client_on_submit(json_object *message, client_t *client)
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); unsigned char block_hash[32] = {0};
if (get_block_hash(block, bin_size, block_hash) != 0)
log_error("Error getting block hash!");
bin_to_hex(block_hash, 32, b->hash, 64);
memcpy(b->prev_hash, bt->prev_hash, 64); memcpy(b->prev_hash, bt->prev_hash, 64);
b->difficulty = bt->difficulty; b->difficulty = bt->difficulty;
b->status = BLOCK_LOCKED; b->status = BLOCK_LOCKED;

View file

@ -94,6 +94,16 @@ int parse_address(const char *input, uint64_t *prefix,
return rv ? XMR_NO_ERROR : XMR_PARSE_ERROR; return rv ? XMR_NO_ERROR : XMR_PARSE_ERROR;
} }
int get_block_hash(const unsigned char *input, const size_t in_size,
unsigned char *output)
{
block b = AUTO_VAL_INIT(b);
blobdata bd = std::string((const char*)input, in_size);
bool rv = parse_and_validate_block_from_blob(bd, b,
reinterpret_cast<hash&>(*output));
return rv ? XMR_NO_ERROR : XMR_PARSE_ERROR;
}
void get_hash(const unsigned char *input, const size_t in_size, void get_hash(const unsigned char *input, const size_t in_size,
unsigned char *output, int variant, uint64_t height) unsigned char *output, int variant, uint64_t height)
{ {

View file

@ -54,6 +54,8 @@ int get_hashing_blob(const unsigned char *input, const size_t in_size,
unsigned char **output, size_t *out_size); unsigned char **output, size_t *out_size);
int parse_address(const char *input, uint64_t *prefix, int parse_address(const char *input, uint64_t *prefix,
unsigned char *pub_spend); unsigned char *pub_spend);
int get_block_hash(const unsigned char *input, const size_t in_size,
unsigned char *output);
void get_hash(const unsigned char *input, const size_t in_size, void get_hash(const unsigned char *input, const size_t in_size,
unsigned char *output, int variant, uint64_t height); unsigned char *output, int variant, uint64_t height);
void get_rx_hash(const unsigned char *input, const size_t in_size, void get_rx_hash(const unsigned char *input, const size_t in_size,

7
tools/inspect-data vendored
View file

@ -59,6 +59,9 @@ class block_t(Structure):
('reward', c_longlong), ('reward', c_longlong),
('timestamp', c_longlong)] ('timestamp', c_longlong)]
def format_block_hash(block_hash):
return '{}...{}'.format(block_hash[:4], block_hash[-4:])
def format_block_status(status): def format_block_status(status):
s = ["LOCKED", "UNLOCKED", "ORPHANED"] s = ["LOCKED", "UNLOCKED", "ORPHANED"]
return s[status] return s[status]
@ -109,10 +112,12 @@ def print_mined(path):
for key, value in curs: for key, value in curs:
height = c_longlong.from_buffer_copy(key).value height = c_longlong.from_buffer_copy(key).value
b = block_t.from_buffer_copy(value) b = block_t.from_buffer_copy(value)
bh = format_block_hash(b.hash.decode('utf-8'))
dt = format_timestamp(b.timestamp) dt = format_timestamp(b.timestamp)
reward = format_amount(b.reward) reward = format_amount(b.reward)
status = format_block_status(b.status) status = format_block_status(b.status)
print('{}\t{}\t{}\t{}'.format(height, status, reward, dt)) print('{}\t{}\t{}\t{}\t{}'.format(height, bh, status,
reward, dt))
env.close() env.close()
def print_shares(path): def print_shares(path):