Skip to content

Commit 30ad12a

Browse files
committed
cryptonote_basic: add overload for get_block_longhash()
1 parent 06b74ae commit 30ad12a

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
@@ -679,29 +679,13 @@ namespace cryptonote
679679

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

0 commit comments

Comments
 (0)