aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormoneromooo-monero <moneromooo-monero@users.noreply.github.com>2019-05-01 19:57:34 +0000
committermoneromooo-monero <moneromooo-monero@users.noreply.github.com>2019-05-01 19:58:09 +0000
commite9809382109765ce53fcbd95e1fc593d9b19e184 (patch)
treef79bcb4fd4f14e9b262f67c70b4181f6df86b5eb
parentMerge pull request #5486 (diff)
downloadmonero-e9809382109765ce53fcbd95e1fc593d9b19e184.tar.xz
fix wide difficulty conversion with some versions of boost
-rw-r--r--src/blockchain_db/lmdb/db_lmdb.cpp4
-rw-r--r--src/cryptonote_basic/cryptonote_boost_serialization.h4
-rw-r--r--src/cryptonote_core/blockchain.cpp4
-rw-r--r--src/cryptonote_protocol/cryptonote_protocol_handler.inl4
-rw-r--r--src/rpc/core_rpc_server.cpp4
-rw-r--r--src/rpc/daemon_handler.cpp6
-rw-r--r--src/serialization/difficulty_type.h4
-rw-r--r--tests/difficulty/difficulty.cpp2
-rw-r--r--tests/hash-target.cpp2
-rw-r--r--tests/performance_tests/check_hash.h8
-rw-r--r--tests/unit_tests/difficulty.cpp8
11 files changed, 25 insertions, 25 deletions
diff --git a/src/blockchain_db/lmdb/db_lmdb.cpp b/src/blockchain_db/lmdb/db_lmdb.cpp
index 340434888..a03a0989b 100644
--- a/src/blockchain_db/lmdb/db_lmdb.cpp
+++ b/src/blockchain_db/lmdb/db_lmdb.cpp
@@ -770,8 +770,8 @@ void BlockchainLMDB::add_block(const block& blk, size_t block_weight, uint64_t l
bi.bi_timestamp = blk.timestamp;
bi.bi_coins = coins_generated;
bi.bi_weight = block_weight;
- bi.bi_diff_hi = (cumulative_difficulty >> 64).convert_to<uint64_t>();
- bi.bi_diff_lo = (cumulative_difficulty << 64 >> 64).convert_to<uint64_t>();
+ bi.bi_diff_hi = ((cumulative_difficulty >> 64) & 0xffffffffffffffff).convert_to<uint64_t>();
+ bi.bi_diff_lo = (cumulative_difficulty & 0xffffffffffffffff).convert_to<uint64_t>();
bi.bi_hash = blk_hash;
bi.bi_cum_rct = num_rct_outs;
if (blk.major_version >= 4)
diff --git a/src/cryptonote_basic/cryptonote_boost_serialization.h b/src/cryptonote_basic/cryptonote_boost_serialization.h
index 3dd98f0c6..79ce610a9 100644
--- a/src/cryptonote_basic/cryptonote_boost_serialization.h
+++ b/src/cryptonote_basic/cryptonote_boost_serialization.h
@@ -365,11 +365,11 @@ namespace boost
else
{
// store high part
- cryptonote::difficulty_type x_ = x >> 64;
+ cryptonote::difficulty_type x_ = (x >> 64) & 0xffffffffffffffff;
uint64_t v = x_.convert_to<uint64_t>();
a & v;
// store low part
- x_ = x << 64 >> 64;
+ x_ = x & 0xffffffffffffffff;
v = x_.convert_to<uint64_t>();
a & v;
}
diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp
index f733efb2f..3ef20fd0b 100644
--- a/src/cryptonote_core/blockchain.cpp
+++ b/src/cryptonote_core/blockchain.cpp
@@ -2324,8 +2324,8 @@ bool Blockchain::find_blockchain_supplement(const std::list<crypto::hash>& qbloc
if (result)
{
cryptonote::difficulty_type wide_cumulative_difficulty = m_db->get_block_cumulative_difficulty(resp.total_height - 1);
- resp.cumulative_difficulty = (wide_cumulative_difficulty << 64 >> 64).convert_to<uint64_t>();
- resp.cumulative_difficulty_top64 = (wide_cumulative_difficulty >> 64).convert_to<uint64_t>();
+ resp.cumulative_difficulty = (wide_cumulative_difficulty & 0xffffffffffffffff).convert_to<uint64_t>();
+ resp.cumulative_difficulty_top64 = ((wide_cumulative_difficulty >> 64) & 0xffffffffffffffff).convert_to<uint64_t>();
}
return result;
diff --git a/src/cryptonote_protocol/cryptonote_protocol_handler.inl b/src/cryptonote_protocol/cryptonote_protocol_handler.inl
index 7adca3158..8958af7c7 100644
--- a/src/cryptonote_protocol/cryptonote_protocol_handler.inl
+++ b/src/cryptonote_protocol/cryptonote_protocol_handler.inl
@@ -410,8 +410,8 @@ namespace cryptonote
m_core.get_blockchain_top(hshd.current_height, hshd.top_id);
hshd.top_version = m_core.get_ideal_hard_fork_version(hshd.current_height);
difficulty_type wide_cumulative_difficulty = m_core.get_block_cumulative_difficulty(hshd.current_height);
- hshd.cumulative_difficulty = (wide_cumulative_difficulty << 64 >> 64).convert_to<uint64_t>();
- hshd.cumulative_difficulty_top64 = (wide_cumulative_difficulty >> 64).convert_to<uint64_t>();
+ hshd.cumulative_difficulty = (wide_cumulative_difficulty & 0xffffffffffffffff).convert_to<uint64_t>();
+ hshd.cumulative_difficulty_top64 = ((wide_cumulative_difficulty >> 64) & 0xffffffffffffffff).convert_to<uint64_t>();
hshd.current_height +=1;
hshd.pruning_seed = m_core.get_blockchain_pruning_seed();
return true;
diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp
index c41fb37d8..0ad7e59e9 100644
--- a/src/rpc/core_rpc_server.cpp
+++ b/src/rpc/core_rpc_server.cpp
@@ -74,9 +74,9 @@ namespace
void store_difficulty(cryptonote::difficulty_type difficulty, uint64_t &sdiff, std::string &swdiff, uint64_t &stop64)
{
- sdiff = (difficulty << 64 >> 64).convert_to<uint64_t>();
+ sdiff = (difficulty & 0xffffffffffffffff).convert_to<uint64_t>();
swdiff = cryptonote::hex(difficulty);
- stop64 = (difficulty >> 64).convert_to<uint64_t>();
+ stop64 = ((difficulty >> 64) & 0xffffffffffffffff).convert_to<uint64_t>();
}
}
diff --git a/src/rpc/daemon_handler.cpp b/src/rpc/daemon_handler.cpp
index 7c8953930..c997f6f47 100644
--- a/src/rpc/daemon_handler.cpp
+++ b/src/rpc/daemon_handler.cpp
@@ -437,7 +437,7 @@ namespace rpc
auto& chain = m_core.get_blockchain_storage();
res.info.wide_difficulty = chain.get_difficulty_for_next_block();
- res.info.difficulty = (res.info.wide_difficulty << 64 >> 64).convert_to<uint64_t>();
+ res.info.difficulty = (res.info.wide_difficulty & 0xffffffffffffffff).convert_to<uint64_t>();
res.info.target = chain.get_difficulty_target();
@@ -459,7 +459,7 @@ namespace rpc
res.info.testnet = m_core.get_nettype() == TESTNET;
res.info.stagenet = m_core.get_nettype() == STAGENET;
res.info.wide_cumulative_difficulty = m_core.get_blockchain_storage().get_db().get_block_cumulative_difficulty(res.info.height - 1);
- res.info.cumulative_difficulty = (res.info.wide_cumulative_difficulty << 64 >> 64).convert_to<uint64_t>();
+ res.info.cumulative_difficulty = (res.info.wide_cumulative_difficulty & 0xffffffffffffffff).convert_to<uint64_t>();
res.info.block_size_limit = res.info.block_weight_limit = m_core.get_blockchain_storage().get_current_cumulative_block_weight_limit();
res.info.block_size_median = res.info.block_weight_median = m_core.get_blockchain_storage().get_current_cumulative_block_weight_median();
res.info.start_time = (uint64_t)m_core.get_start_time();
@@ -829,7 +829,7 @@ namespace rpc
}
header.wide_difficulty = m_core.get_blockchain_storage().block_difficulty(header.height);
- header.difficulty = (header.wide_difficulty << 64 >> 64).convert_to<uint64_t>();
+ header.difficulty = (header.wide_difficulty & 0xffffffffffffffff).convert_to<uint64_t>();
return true;
}
diff --git a/src/serialization/difficulty_type.h b/src/serialization/difficulty_type.h
index e32e24b78..c551095f9 100644
--- a/src/serialization/difficulty_type.h
+++ b/src/serialization/difficulty_type.h
@@ -54,8 +54,8 @@ inline bool do_serialize(Archive<true>& ar, cryptonote::difficulty_type &diff)
{
if (!ar.stream().good())
return false;
- const uint64_t hi = (diff >> 64).convert_to<uint64_t>();
- const uint64_t lo = (diff << 64 >> 64).convert_to<uint64_t>();
+ const uint64_t hi = ((diff >> 64) & 0xffffffffffffffff).convert_to<uint64_t>();
+ const uint64_t lo = (diff & 0xffffffffffffffff).convert_to<uint64_t>();
ar.serialize_varint(hi);
ar.serialize_varint(lo);
if (!ar.stream().good())
diff --git a/tests/difficulty/difficulty.cpp b/tests/difficulty/difficulty.cpp
index 11ce0bd73..18f1d0030 100644
--- a/tests/difficulty/difficulty.cpp
+++ b/tests/difficulty/difficulty.cpp
@@ -124,7 +124,7 @@ int main(int argc, char *argv[]) {
cryptonote::difficulty_type wide_res = cryptonote::next_difficulty(
std::vector<uint64_t>(timestamps.begin() + begin, timestamps.begin() + end),
std::vector<cryptonote::difficulty_type>(wide_cumulative_difficulties.begin() + begin, wide_cumulative_difficulties.begin() + end), DEFAULT_TEST_DIFFICULTY_TARGET);
- if (wide_res.convert_to<uint64_t>() != res) {
+ if ((wide_res & 0xffffffffffffffff).convert_to<uint64_t>() != res) {
cerr << "Wrong wide difficulty for block " << n << endl
<< "Expected: " << res << endl
<< "Found: " << wide_res << endl;
diff --git a/tests/hash-target.cpp b/tests/hash-target.cpp
index 1e988c302..e95475cac 100644
--- a/tests/hash-target.cpp
+++ b/tests/hash-target.cpp
@@ -61,7 +61,7 @@ int main(int argc, char *argv[]) {
for (int i = 31; i >= 0; i--) {
val = val * 256 + 255;
((char *) &h)[i] = static_cast<char>(static_cast<uint64_t>(val / diff));
- val %= diff.convert_to<uint64_t>();
+ val %= (diff & 0xffffffffffffffff).convert_to<uint64_t>();
}
if (check_hash(h, diff) != true) {
return 3;
diff --git a/tests/performance_tests/check_hash.h b/tests/performance_tests/check_hash.h
index d24001903..53746fec4 100644
--- a/tests/performance_tests/check_hash.h
+++ b/tests/performance_tests/check_hash.h
@@ -44,13 +44,13 @@ public:
difficulty = difficulty_high;
difficulty = (difficulty << 64) | difficulty_low;
boost::multiprecision::uint256_t hash_value = std::numeric_limits<boost::multiprecision::uint256_t>::max() / hash_target;
- ((uint64_t*)&hash)[0] = (hash_value << 64 >> 64).convert_to<uint64_t>();
+ ((uint64_t*)&hash)[0] = (hash_value & 0xffffffffffffffff).convert_to<uint64_t>();
hash_value >>= 64;
- ((uint64_t*)&hash)[1] = (hash_value << 64 >> 64).convert_to<uint64_t>();
+ ((uint64_t*)&hash)[1] = (hash_value & 0xffffffffffffffff).convert_to<uint64_t>();
hash_value >>= 64;
- ((uint64_t*)&hash)[2] = (hash_value << 64 >> 64).convert_to<uint64_t>();
+ ((uint64_t*)&hash)[2] = (hash_value & 0xffffffffffffffff).convert_to<uint64_t>();
hash_value >>= 64;
- ((uint64_t*)&hash)[3] = (hash_value << 64 >> 64).convert_to<uint64_t>();
+ ((uint64_t*)&hash)[3] = (hash_value & 0xffffffffffffffff).convert_to<uint64_t>();
return true;
}
diff --git a/tests/unit_tests/difficulty.cpp b/tests/unit_tests/difficulty.cpp
index 090fecc84..a732e6969 100644
--- a/tests/unit_tests/difficulty.cpp
+++ b/tests/unit_tests/difficulty.cpp
@@ -42,13 +42,13 @@ static crypto::hash MKHASH(uint64_t high, uint64_t low)
hash_target = (hash_target << 64) | low;
boost::multiprecision::uint256_t hash_value = std::numeric_limits<boost::multiprecision::uint256_t>::max() / hash_target;
crypto::hash h;
- ((uint64_t*)&h)[0] = hash_value.convert_to<uint64_t>();
+ ((uint64_t*)&h)[0] = (hash_value & 0xffffffffffffffff).convert_to<uint64_t>();
hash_value >>= 64;
- ((uint64_t*)&h)[1] = hash_value.convert_to<uint64_t>();
+ ((uint64_t*)&h)[1] = (hash_value & 0xffffffffffffffff).convert_to<uint64_t>();
hash_value >>= 64;
- ((uint64_t*)&h)[2] = hash_value.convert_to<uint64_t>();
+ ((uint64_t*)&h)[2] = (hash_value & 0xffffffffffffffff).convert_to<uint64_t>();
hash_value >>= 64;
- ((uint64_t*)&h)[3] = hash_value.convert_to<uint64_t>();
+ ((uint64_t*)&h)[3] = (hash_value & 0xffffffffffffffff).convert_to<uint64_t>();
return h;
}