forked from lthn/blockchain
fixed misprint in the fork choise rule
This commit is contained in:
parent
c6583f56c4
commit
0383fb78d4
3 changed files with 78 additions and 2 deletions
|
|
@ -2715,7 +2715,7 @@ namespace currency
|
|||
|
||||
boost::multiprecision::uint1024_t basic_sum = boost::multiprecision::uint1024_t(a_pow_cumulative_difficulty) + (boost::multiprecision::uint1024_t(a_pos_cumulative_difficulty)*difficulty_pow_at_split_point) / difficulty_pos_at_split_point;
|
||||
boost::multiprecision::uint1024_t res =
|
||||
(basic_sum * a_pow_cumulative_difficulty * a_pos_cumulative_difficulty) / (boost::multiprecision::uint1024_t(a_pow_cumulative_difficulty)*a_pos_cumulative_difficulty);
|
||||
(basic_sum * a_pow_cumulative_difficulty * a_pos_cumulative_difficulty) / (boost::multiprecision::uint1024_t(b_pow_cumulative_difficulty)*b_pos_cumulative_difficulty);
|
||||
|
||||
if (res > boost::math::tools::max_value<wide_difficulty_type>())
|
||||
{
|
||||
|
|
|
|||
76
tests/unit_tests/fork_choice_rule.cpp
Normal file
76
tests/unit_tests/fork_choice_rule.cpp
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
// Copyright (c) 2012-2013 The Cryptonote developers
|
||||
// Distributed under the MIT/X11 software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "include_base_utils.h"
|
||||
#include "currency_core/currency_format_utils.h"
|
||||
|
||||
bool if_alt_chain_stronger(const currency::wide_difficulty_type& pos, const currency::wide_difficulty_type& pow)
|
||||
{
|
||||
currency::difficulties main_cumul_diff;
|
||||
main_cumul_diff.pos_diff = 400000;
|
||||
main_cumul_diff.pow_diff = 4000;
|
||||
currency::difficulties alt_cumul_diff;
|
||||
alt_cumul_diff.pow_diff = pow;
|
||||
alt_cumul_diff.pos_diff = pos;
|
||||
static currency::wide_difficulty_type difficulty_pos_at_split_point = 400000;
|
||||
static currency::wide_difficulty_type difficulty_pow_at_split_point = 4000;
|
||||
currency::wide_difficulty_type main = currency::get_a_to_b_relative_cumulative_difficulty(difficulty_pos_at_split_point, difficulty_pow_at_split_point, main_cumul_diff, alt_cumul_diff);
|
||||
currency::wide_difficulty_type alt = currency::get_a_to_b_relative_cumulative_difficulty(difficulty_pos_at_split_point, difficulty_pow_at_split_point, alt_cumul_diff, main_cumul_diff);
|
||||
if (alt > main)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
TEST(fork_choice_rule_test, fork_choice_rule_test_1)
|
||||
{
|
||||
// std::stringstream ss;
|
||||
// for (uint64_t pos = 100000; pos < 1000001; pos += 10000)
|
||||
// {
|
||||
// for (uint64_t pow = 100; pow < 18000; pow += 100)
|
||||
// {
|
||||
// bool r = if_alt_chain_stronger(pos, pow);
|
||||
// if(r)
|
||||
// ss << pos << "\t" << pow << std::endl;
|
||||
// //ss << pos << "\t" << pow << "\t" << (r ? "1" : "0") << std::endl;
|
||||
//
|
||||
//
|
||||
// }
|
||||
// }
|
||||
// bool r = epee::file_io_utils::save_string_to_file("stat.txt", ss.str());
|
||||
bool res = false;
|
||||
res = if_alt_chain_stronger(1000000, 1000);
|
||||
ASSERT_FALSE(res);
|
||||
res = if_alt_chain_stronger(1000000, 1500);
|
||||
ASSERT_TRUE(res);
|
||||
res = if_alt_chain_stronger(800000, 1700);
|
||||
ASSERT_FALSE(res);
|
||||
res = if_alt_chain_stronger(800000, 2000);
|
||||
ASSERT_TRUE(res);
|
||||
res = if_alt_chain_stronger(600000, 2200);
|
||||
ASSERT_FALSE(res);
|
||||
res = if_alt_chain_stronger(600000, 2800);
|
||||
ASSERT_TRUE(res);
|
||||
res = if_alt_chain_stronger(400000, 3999);
|
||||
ASSERT_FALSE(res);
|
||||
res = if_alt_chain_stronger(400000, 4001);
|
||||
ASSERT_TRUE(res);
|
||||
res = if_alt_chain_stronger(200000, 7000);
|
||||
ASSERT_FALSE(res);
|
||||
res = if_alt_chain_stronger(200000, 7700);
|
||||
ASSERT_TRUE(res);
|
||||
res = if_alt_chain_stronger(200000, 7000);
|
||||
ASSERT_FALSE(res);
|
||||
res = if_alt_chain_stronger(200000, 7700);
|
||||
ASSERT_TRUE(res);
|
||||
res = if_alt_chain_stronger(100000, 10000);
|
||||
ASSERT_FALSE(res);
|
||||
res = if_alt_chain_stronger(200000, 14000);
|
||||
ASSERT_TRUE(res);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -54,7 +54,7 @@ namespace lmdb_test
|
|||
if (key % 1024 == 0)
|
||||
{
|
||||
ASSERT_TRUE(lmdb_ptr->commit_transaction());
|
||||
ASSERT_TRUE(lmdb_ptr->resize_if_needed());
|
||||
//ASSERT_TRUE(lmdb_ptr->resize_if_needed());
|
||||
ASSERT_TRUE(lmdb_ptr->begin_transaction());
|
||||
std::cout << total_data / 1024 / 1024 << " MB written to DB" << ENDL;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue