Moving work_threshold_base from a free function to a member of work_thresholds.
This commit is contained in:
		
					parent
					
						
							
								8e53b142d6
							
						
					
				
			
			
				commit
				
					
						3d71605cfd
					
				
			
		
					 9 changed files with 28 additions and 27 deletions
				
			
		| 
						 | 
				
			
			@ -129,7 +129,7 @@ TEST (difficulty, network_constants)
 | 
			
		|||
 | 
			
		||||
	nano::work_version version{ nano::work_version::work_1 };
 | 
			
		||||
	ASSERT_EQ (nano::dev::network_params.network.publish_thresholds.base, nano::dev::network_params.network.publish_thresholds.epoch_2);
 | 
			
		||||
	ASSERT_EQ (nano::dev::network_params.network.publish_thresholds.base, nano::work_threshold_base (version));
 | 
			
		||||
	ASSERT_EQ (nano::dev::network_params.network.publish_thresholds.base, nano::dev::network_params.network.publish_thresholds.threshold_base (version));
 | 
			
		||||
	ASSERT_EQ (nano::dev::network_params.network.publish_thresholds.entry, nano::dev::network_params.network.publish_thresholds.threshold_entry (version, nano::block_type::state));
 | 
			
		||||
	ASSERT_EQ (nano::dev::network_params.network.publish_thresholds.epoch_1, nano::dev::network_params.network.publish_thresholds.threshold_entry (version, nano::block_type::send));
 | 
			
		||||
	ASSERT_EQ (nano::dev::network_params.network.publish_thresholds.epoch_1, nano::dev::network_params.network.publish_thresholds.threshold_entry (version, nano::block_type::receive));
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -138,10 +138,11 @@ private:
 | 
			
		|||
 | 
			
		||||
	void handle_generate (nano::block_hash const & hash_a)
 | 
			
		||||
	{
 | 
			
		||||
		static nano::network_constants constants;
 | 
			
		||||
		if (type == work_peer_type::good)
 | 
			
		||||
		{
 | 
			
		||||
			auto hash = hash_a;
 | 
			
		||||
			auto request_difficulty = nano::work_threshold_base (version);
 | 
			
		||||
			auto request_difficulty = constants.publish_thresholds.threshold_base (version);
 | 
			
		||||
			auto this_l (shared_from_this ());
 | 
			
		||||
			work_pool.generate (version, hash, request_difficulty, [this_l, hash] (boost::optional<uint64_t> work_a) {
 | 
			
		||||
				auto result = work_a.value_or (0);
 | 
			
		||||
| 
						 | 
				
			
			@ -149,7 +150,7 @@ private:
 | 
			
		|||
				ptree::ptree message_l;
 | 
			
		||||
				message_l.put ("work", nano::to_string_hex (result));
 | 
			
		||||
				message_l.put ("difficulty", nano::to_string_hex (result_difficulty));
 | 
			
		||||
				message_l.put ("multiplier", nano::to_string (nano::difficulty::to_multiplier (result_difficulty, nano::work_threshold_base (this_l->version))));
 | 
			
		||||
				message_l.put ("multiplier", nano::to_string (nano::difficulty::to_multiplier (result_difficulty, constants.publish_thresholds.threshold_base (this_l->version))));
 | 
			
		||||
				message_l.put ("hash", hash.to_string ());
 | 
			
		||||
				std::stringstream ostream;
 | 
			
		||||
				ptree::write_json (ostream, message_l);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -19,7 +19,7 @@ TEST (work, one)
 | 
			
		|||
	nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits<unsigned>::max () };
 | 
			
		||||
	nano::change_block block (1, 1, nano::keypair ().prv, 3, 4);
 | 
			
		||||
	block.block_work_set (*pool.generate (block.root ()));
 | 
			
		||||
	ASSERT_LT (nano::work_threshold_base (block.work_version ()), block.difficulty ());
 | 
			
		||||
	ASSERT_LT (nano::dev::network_params.network.publish_thresholds.threshold_base (block.work_version ()), block.difficulty ());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TEST (work, disabled)
 | 
			
		||||
| 
						 | 
				
			
			@ -33,9 +33,9 @@ TEST (work, validate)
 | 
			
		|||
{
 | 
			
		||||
	nano::work_pool pool{ nano::dev::network_params.network, std::numeric_limits<unsigned>::max () };
 | 
			
		||||
	nano::send_block send_block (1, 1, 2, nano::keypair ().prv, 4, 6);
 | 
			
		||||
	ASSERT_LT (send_block.difficulty (), nano::work_threshold_base (send_block.work_version ()));
 | 
			
		||||
	ASSERT_LT (send_block.difficulty (), nano::dev::network_params.network.publish_thresholds.threshold_base (send_block.work_version ()));
 | 
			
		||||
	send_block.block_work_set (*pool.generate (send_block.root ()));
 | 
			
		||||
	ASSERT_LT (nano::work_threshold_base (send_block.work_version ()), send_block.difficulty ());
 | 
			
		||||
	ASSERT_LT (nano::dev::network_params.network.publish_thresholds.threshold_base (send_block.work_version ()), send_block.difficulty ());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TEST (work, cancel)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -166,6 +166,20 @@ double nano::work_thresholds::denormalized_multiplier (double const multiplier_a
 | 
			
		|||
	return multiplier;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint64_t nano::work_thresholds::threshold_base (nano::work_version const version_a)
 | 
			
		||||
{
 | 
			
		||||
	uint64_t result{ std::numeric_limits<uint64_t>::max () };
 | 
			
		||||
	switch (version_a)
 | 
			
		||||
	{
 | 
			
		||||
		case nano::work_version::work_1:
 | 
			
		||||
			result = base;
 | 
			
		||||
			break;
 | 
			
		||||
		default:
 | 
			
		||||
			debug_assert (false && "Invalid version specified to work_threshold_base");
 | 
			
		||||
	}
 | 
			
		||||
	return result;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
namespace nano
 | 
			
		||||
{
 | 
			
		||||
const char * network_constants::active_network_err_msg = "Invalid network. Valid values are live, test, beta and dev.";
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -111,10 +111,11 @@ public:
 | 
			
		|||
	}
 | 
			
		||||
 | 
			
		||||
	uint64_t threshold_entry (nano::work_version const, nano::block_type const);
 | 
			
		||||
	uint64_t value (nano::root const & root_a, uint64_t work_a);
 | 
			
		||||
	uint64_t threshold (nano::block_details const &);
 | 
			
		||||
	// Ledger threshold
 | 
			
		||||
	uint64_t threshold (nano::work_version const, nano::block_details const);
 | 
			
		||||
	uint64_t threshold_base (nano::work_version const);
 | 
			
		||||
	uint64_t value (nano::root const & root_a, uint64_t work_a);
 | 
			
		||||
	double normalized_multiplier (double const, uint64_t const);
 | 
			
		||||
	double denormalized_multiplier (double const, uint64_t const);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -49,21 +49,6 @@ uint64_t nano::work_difficulty (nano::work_version const version_a, nano::root c
 | 
			
		|||
	return result;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
uint64_t nano::work_threshold_base (nano::work_version const version_a)
 | 
			
		||||
{
 | 
			
		||||
	uint64_t result{ std::numeric_limits<uint64_t>::max () };
 | 
			
		||||
	switch (version_a)
 | 
			
		||||
	{
 | 
			
		||||
		case nano::work_version::work_1:
 | 
			
		||||
			static nano::network_constants network_constants;
 | 
			
		||||
			result = network_constants.publish_thresholds.base;
 | 
			
		||||
			break;
 | 
			
		||||
		default:
 | 
			
		||||
			debug_assert (false && "Invalid version specified to work_threshold_base");
 | 
			
		||||
	}
 | 
			
		||||
	return result;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
nano::work_pool::work_pool (nano::network_constants & network_constants, unsigned max_threads_a, std::chrono::nanoseconds pow_rate_limiter_a, std::function<boost::optional<uint64_t> (nano::work_version const, nano::root const &, uint64_t, std::atomic<int> &)> opencl_a) :
 | 
			
		||||
	network_constants{ network_constants },
 | 
			
		||||
	ticket (0),
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -23,7 +23,6 @@ bool work_validate_entry (nano::work_version const, nano::root const &, uint64_t
 | 
			
		|||
 | 
			
		||||
uint64_t work_difficulty (nano::work_version const, nano::root const &, uint64_t const);
 | 
			
		||||
 | 
			
		||||
uint64_t work_threshold_base (nano::work_version const);
 | 
			
		||||
class opencl_work;
 | 
			
		||||
class work_item final
 | 
			
		||||
{
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1110,11 +1110,12 @@ int nano::node::price (nano::uint128_t const & balance_a, int amount_a)
 | 
			
		|||
 | 
			
		||||
uint64_t nano::node::default_difficulty (nano::work_version const version_a) const
 | 
			
		||||
{
 | 
			
		||||
	nano::network_constants constants;
 | 
			
		||||
	uint64_t result{ std::numeric_limits<uint64_t>::max () };
 | 
			
		||||
	switch (version_a)
 | 
			
		||||
	{
 | 
			
		||||
		case nano::work_version::work_1:
 | 
			
		||||
			result = nano::work_threshold_base (version_a);
 | 
			
		||||
			result = constants.publish_thresholds.threshold_base (version_a);
 | 
			
		||||
			break;
 | 
			
		||||
		default:
 | 
			
		||||
			debug_assert (false && "Invalid version specified to default_difficulty");
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -2215,7 +2215,7 @@ TEST (rpc, work_peer_bad)
 | 
			
		|||
		ASSERT_TRUE (work_a.is_initialized ());
 | 
			
		||||
		work = *work_a;
 | 
			
		||||
	});
 | 
			
		||||
	ASSERT_TIMELY (5s, nano::work_difficulty (nano::work_version::work_1, hash1, work) >= nano::work_threshold_base (nano::work_version::work_1));
 | 
			
		||||
	ASSERT_TIMELY (5s, nano::work_difficulty (nano::work_version::work_1, hash1, work) >= nano::dev::network_params.network.publish_thresholds.threshold_base (nano::work_version::work_1));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TEST (rpc, work_peer_one)
 | 
			
		||||
| 
						 | 
				
			
			@ -2231,7 +2231,7 @@ TEST (rpc, work_peer_one)
 | 
			
		|||
		ASSERT_TRUE (work_a.is_initialized ());
 | 
			
		||||
		work = *work_a;
 | 
			
		||||
	});
 | 
			
		||||
	ASSERT_TIMELY (5s, nano::work_difficulty (nano::work_version::work_1, key1.pub, work) >= nano::work_threshold_base (nano::work_version::work_1));
 | 
			
		||||
	ASSERT_TIMELY (5s, nano::work_difficulty (nano::work_version::work_1, key1.pub, work) >= nano::dev::network_params.network.publish_thresholds.threshold_base (nano::work_version::work_1));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
TEST (rpc, work_peer_many)
 | 
			
		||||
| 
						 | 
				
			
			@ -2258,7 +2258,7 @@ TEST (rpc, work_peer_many)
 | 
			
		|||
		node1.work_generate (nano::work_version::work_1, key1.pub, node1.network_params.network.publish_thresholds.base, [&work = works[i]] (boost::optional<uint64_t> work_a) {
 | 
			
		||||
			work = *work_a;
 | 
			
		||||
		});
 | 
			
		||||
		while (nano::work_difficulty (nano::work_version::work_1, key1.pub, works[i]) < nano::work_threshold_base (nano::work_version::work_1))
 | 
			
		||||
		while (nano::work_difficulty (nano::work_version::work_1, key1.pub, works[i]) < nano::dev::network_params.network.publish_thresholds.threshold_base (nano::work_version::work_1))
 | 
			
		||||
		{
 | 
			
		||||
			system1.poll ();
 | 
			
		||||
			system2.poll ();
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue