Skip to content

Commit 488bf71

Browse files
committed
cryptonote_basic: add overload for get_block_longhash()
1 parent 7fe199f commit 488bf71

File tree

3 files changed

+34
-21
lines changed

3 files changed

+34
-21
lines changed

src/cryptonote_basic/cryptonote_format_utils.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1605,6 +1605,31 @@ namespace cryptonote
16051605
return get_tx_tree_hash(txs_ids);
16061606
}
16071607
//---------------------------------------------------------------
1608+
crypto::hash get_block_longhash(const blobdata_ref block_hashing_blob,
1609+
const uint64_t height,
1610+
const uint8_t major_version,
1611+
const crypto::hash &seed_hash)
1612+
{
1613+
crypto::hash res;
1614+
1615+
if (height == 202612) // block 202612 bug workaround
1616+
{
1617+
static const std::string longhash_202612 = "84f64766475d51837ac9efbef1926486e58563c95a19fef4aec3254f03000000";
1618+
epee::string_tools::hex_to_pod(longhash_202612, res);
1619+
}
1620+
else if (major_version >= RX_BLOCK_VERSION) // RandomX
1621+
{
1622+
crypto::rx_slow_hash(seed_hash.data, block_hashing_blob.data(), block_hashing_blob.size(), res.data);
1623+
}
1624+
else // CryptoNight
1625+
{
1626+
const int pow_variant = major_version >= 7 ? major_version - 6 : 0;
1627+
crypto::cn_slow_hash(block_hashing_blob.data(), block_hashing_blob.size(), res, pow_variant, height);
1628+
}
1629+
1630+
return res;
1631+
}
1632+
//---------------------------------------------------------------
16081633
bool is_valid_decomposed_amount(uint64_t amount)
16091634
{
16101635
if (0 == amount)

src/cryptonote_basic/cryptonote_format_utils.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,10 @@ namespace cryptonote
261261
void get_tx_tree_hash(const std::vector<crypto::hash>& tx_hashes, crypto::hash& h);
262262
crypto::hash get_tx_tree_hash(const std::vector<crypto::hash>& tx_hashes);
263263
crypto::hash get_tx_tree_hash(const block& b);
264+
crypto::hash get_block_longhash(const blobdata_ref block_hashing_blob,
265+
const uint64_t height,
266+
const uint8_t major_version,
267+
const crypto::hash &seed_hash);
264268
bool is_valid_decomposed_amount(uint64_t amount);
265269
void get_hash_stats(uint64_t &tx_hashes_calculated, uint64_t &tx_hashes_cached, uint64_t &block_hashes_calculated, uint64_t & block_hashes_cached);
266270

src/cryptonote_core/cryptonote_tx_utils.cpp

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -678,29 +678,13 @@ namespace cryptonote
678678

679679
bool get_block_longhash(const Blockchain *pbc, const blobdata& bd, crypto::hash& res, const uint64_t height, const int major_version, const crypto::hash *seed_hash, const int miners)
680680
{
681-
// block 202612 bug workaround
682-
if (height == 202612)
681+
crypto::hash seed_hash_ = crypto::null_hash;
682+
if (pbc != NULL && major_version >= RX_BLOCK_VERSION)
683683
{
684-
static const std::string longhash_202612 = "84f64766475d51837ac9efbef1926486e58563c95a19fef4aec3254f03000000";
685-
epee::string_tools::hex_to_pod(longhash_202612, res);
686-
return true;
687-
}
688-
if (major_version >= RX_BLOCK_VERSION)
689-
{
690-
crypto::hash hash;
691-
if (pbc != NULL)
692-
{
693-
const uint64_t seed_height = rx_seedheight(height);
694-
hash = seed_hash ? *seed_hash : pbc->get_pending_block_id_by_height(seed_height);
695-
} else
696-
{
697-
memset(&hash, 0, sizeof(hash)); // only happens when generating genesis block
698-
}
699-
rx_slow_hash(hash.data, bd.data(), bd.size(), res.data);
700-
} else {
701-
const int pow_variant = major_version >= 7 ? major_version - 6 : 0;
702-
crypto::cn_slow_hash(bd.data(), bd.size(), res, pow_variant, height);
684+
const uint64_t seed_height = rx_seedheight(height);
685+
seed_hash_ = seed_hash ? *seed_hash : pbc->get_pending_block_id_by_height(seed_height);
703686
}
687+
res = get_block_longhash(bd, height, major_version, seed_hash_);
704688
return true;
705689
}
706690

0 commit comments

Comments
 (0)