aboutsummaryrefslogtreecommitdiff
path: root/src/cryptonote_basic
diff options
context:
space:
mode:
Diffstat (limited to 'src/cryptonote_basic')
-rw-r--r--src/cryptonote_basic/difficulty.cpp15
-rw-r--r--src/cryptonote_basic/difficulty.h3
-rw-r--r--src/cryptonote_basic/hardfork.cpp30
3 files changed, 22 insertions, 26 deletions
diff --git a/src/cryptonote_basic/difficulty.cpp b/src/cryptonote_basic/difficulty.cpp
index 5162e53e6..859173aa5 100644
--- a/src/cryptonote_basic/difficulty.cpp
+++ b/src/cryptonote_basic/difficulty.cpp
@@ -239,4 +239,19 @@ namespace cryptonote {
return res.convert_to<difficulty_type>();
}
+ std::string hex(difficulty_type v)
+ {
+ static const char chars[] = "0123456789abcdef";
+ std::string s;
+ while (v > 0)
+ {
+ s.push_back(chars[(v & 0xf).convert_to<unsigned>()]);
+ v >>= 4;
+ }
+ if (s.empty())
+ s += "0";
+ std::reverse(s.begin(), s.end());
+ return "0x" + s;
+ }
+
}
diff --git a/src/cryptonote_basic/difficulty.h b/src/cryptonote_basic/difficulty.h
index f7a9376fb..02ed89e5a 100644
--- a/src/cryptonote_basic/difficulty.h
+++ b/src/cryptonote_basic/difficulty.h
@@ -32,6 +32,7 @@
#include <cstdint>
#include <vector>
+#include <string>
#include <boost/multiprecision/cpp_int.hpp>
#include "crypto/hash.h"
@@ -58,4 +59,6 @@ namespace cryptonote
bool check_hash_128(const crypto::hash &hash, difficulty_type difficulty);
bool check_hash(const crypto::hash &hash, difficulty_type difficulty);
difficulty_type next_difficulty(std::vector<std::uint64_t> timestamps, std::vector<difficulty_type> cumulative_difficulties, size_t target_seconds);
+
+ std::string hex(difficulty_type v);
}
diff --git a/src/cryptonote_basic/hardfork.cpp b/src/cryptonote_basic/hardfork.cpp
index 89bca2f09..d5710f727 100644
--- a/src/cryptonote_basic/hardfork.cpp
+++ b/src/cryptonote_basic/hardfork.cpp
@@ -185,26 +185,8 @@ void HardFork::init()
else
height = 1;
- bool populate = false;
- try
- {
- db.get_hard_fork_version(0);
- }
- catch (...) { populate = true; }
- if (populate) {
- MINFO("The DB has no hard fork info, reparsing from start");
- height = 1;
- }
- MDEBUG("reorganizing from " << height);
- if (populate) {
- reorganize_from_chain_height(height);
- // reorg will not touch the genesis block, use this as a flag for populating done
- db.set_hard_fork_version(0, original_version);
- }
- else {
- rescan_from_chain_height(height);
- }
- MDEBUG("reorganization done");
+ rescan_from_chain_height(height);
+ MDEBUG("init done");
}
uint8_t HardFork::get_block_version(uint64_t height) const
@@ -266,11 +248,9 @@ bool HardFork::reorganize_from_chain_height(uint64_t height)
bool HardFork::rescan_from_block_height(uint64_t height)
{
CRITICAL_REGION_LOCAL(lock);
- db.block_txn_start(true);
- if (height >= db.height()) {
- db.block_txn_stop();
+ db_rtxn_guard rtxn_guard(&db);
+ if (height >= db.height())
return false;
- }
versions.clear();
@@ -293,8 +273,6 @@ bool HardFork::rescan_from_block_height(uint64_t height)
current_fork_index = voted;
}
- db.block_txn_stop();
-
return true;
}