aboutsummaryrefslogtreecommitdiff
path: root/src/cryptonote_core/blockchain.cpp
diff options
context:
space:
mode:
authorvictorsintnicolaas <vicsn@users.noreply.github.com>2018-06-14 21:11:49 +0200
committervictorsintnicolaas <vicsn@users.noreply.github.com>2018-06-29 10:06:11 +0200
commit34cb6b4b703f30be89388f4cdcc5d7b6780ee988 (patch)
tree32563cb9c0fad0a9597bd80b0e0392f708dc1da8 /src/cryptonote_core/blockchain.cpp
parentdb_lmdb: enable batch transactions by default (diff)
downloadmonero-34cb6b4b703f30be89388f4cdcc5d7b6780ee988.tar.xz
add --regtest and --fixed-difficulty for regression testing
on_generateblocks RPC call combines functionality from the on_getblocktemplate and on_submitblock RPC calls to allow rapid block creation. Difficulty is set permanently to 1 for regtest. Makes use of FAKECHAIN network type, but takes hard fork heights from mainchain Default reserve_size in generate_blocks RPC call is now 1. If it is 0, the following error occurs 'Failed to calculate offset for'. Queries hard fork heights info of other network types
Diffstat (limited to 'src/cryptonote_core/blockchain.cpp')
-rw-r--r--src/cryptonote_core/blockchain.cpp46
1 files changed, 45 insertions, 1 deletions
diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp
index 54d8fac31..191130953 100644
--- a/src/cryptonote_core/blockchain.cpp
+++ b/src/cryptonote_core/blockchain.cpp
@@ -329,7 +329,7 @@ uint64_t Blockchain::get_current_blockchain_height() const
//------------------------------------------------------------------
//FIXME: possibly move this into the constructor, to avoid accidentally
// dereferencing a null BlockchainDB pointer
-bool Blockchain::init(BlockchainDB* db, const network_type nettype, bool offline, const cryptonote::test_options *test_options)
+bool Blockchain::init(BlockchainDB* db, const network_type nettype, bool offline, const cryptonote::test_options *test_options, difficulty_type fixed_difficulty)
{
LOG_PRINT_L3("Blockchain::" << __func__);
CRITICAL_REGION_LOCAL(m_tx_pool);
@@ -351,6 +351,7 @@ bool Blockchain::init(BlockchainDB* db, const network_type nettype, bool offline
m_nettype = test_options != NULL ? FAKECHAIN : nettype;
m_offline = offline;
+ m_fixed_difficulty = fixed_difficulty;
if (m_hardfork == nullptr)
{
if (m_nettype == FAKECHAIN || m_nettype == STAGENET)
@@ -805,6 +806,11 @@ bool Blockchain::get_block_by_hash(const crypto::hash &h, block &blk, bool *orph
// less blocks than desired if there aren't enough.
difficulty_type Blockchain::get_difficulty_for_next_block()
{
+ if (m_fixed_difficulty)
+ {
+ return m_db->height() ? m_fixed_difficulty : 1;
+ }
+
LOG_PRINT_L3("Blockchain::" << __func__);
CRITICAL_REGION_LOCAL(m_difficulty_lock);
@@ -1007,6 +1013,11 @@ bool Blockchain::switch_to_alternative_blockchain(std::list<blocks_ext_by_hash::
// an alternate chain.
difficulty_type Blockchain::get_next_difficulty_for_alternative_chain(const std::list<blocks_ext_by_hash::iterator>& alt_chain, block_extended_info& bei) const
{
+ if (m_fixed_difficulty)
+ {
+ return m_db->height() ? m_fixed_difficulty : 1;
+ }
+
LOG_PRINT_L3("Blockchain::" << __func__);
std::vector<uint64_t> timestamps;
std::vector<difficulty_type> cumulative_difficulties;
@@ -4374,6 +4385,39 @@ HardFork::State Blockchain::get_hard_fork_state() const
return m_hardfork->get_state();
}
+const std::vector<HardFork::Params>& Blockchain::get_hard_fork_heights(network_type nettype)
+{
+ static const std::vector<HardFork::Params> mainnet_heights = []()
+ {
+ std::vector<HardFork::Params> heights;
+ for (const auto& i : mainnet_hard_forks)
+ heights.emplace_back(i.version, i.height, i.threshold, i.time);
+ return heights;
+ }();
+ static const std::vector<HardFork::Params> testnet_heights = []()
+ {
+ std::vector<HardFork::Params> heights;
+ for (const auto& i : testnet_hard_forks)
+ heights.emplace_back(i.version, i.height, i.threshold, i.time);
+ return heights;
+ }();
+ static const std::vector<HardFork::Params> stagenet_heights = []()
+ {
+ std::vector<HardFork::Params> heights;
+ for (const auto& i : stagenet_hard_forks)
+ heights.emplace_back(i.version, i.height, i.threshold, i.time);
+ return heights;
+ }();
+ static const std::vector<HardFork::Params> dummy;
+ switch (nettype)
+ {
+ case MAINNET: return mainnet_heights;
+ case TESTNET: return testnet_heights;
+ case STAGENET: return stagenet_heights;
+ default: return dummy;
+ }
+}
+
bool Blockchain::get_hard_fork_voting_info(uint8_t version, uint32_t &window, uint32_t &votes, uint32_t &threshold, uint64_t &earliest_height, uint8_t &voting) const
{
return m_hardfork->get_voting_info(version, window, votes, threshold, earliest_height, voting);