Moving valide_entry from a free function to a method of work_thresholds.
This commit is contained in:
parent
868ec8679a
commit
4dead4c384
12 changed files with 23 additions and 23 deletions
|
@ -49,7 +49,7 @@ get_env_threshold_or_default ("NANO_TEST_EPOCH_2", 0xfffffff800000000), // 8x hi
|
|||
get_env_threshold_or_default ("NANO_TEST_EPOCH_2_RECV", 0xfffffe0000000000) // 8x lower than epoch_1
|
||||
);
|
||||
|
||||
uint64_t nano::work_thresholds::threshold_entry (nano::work_version const version_a, nano::block_type const type_a)
|
||||
uint64_t nano::work_thresholds::threshold_entry (nano::work_version const version_a, nano::block_type const type_a) const
|
||||
{
|
||||
uint64_t result{ std::numeric_limits<uint64_t>::max () };
|
||||
if (type_a == nano::block_type::state)
|
||||
|
@ -110,12 +110,11 @@ uint64_t nano::work_thresholds::threshold (nano::block_details const & details_a
|
|||
|
||||
uint64_t nano::work_thresholds::threshold (nano::work_version const version_a, nano::block_details const details_a)
|
||||
{
|
||||
static nano::network_constants network_constants;
|
||||
uint64_t result{ std::numeric_limits<uint64_t>::max () };
|
||||
switch (version_a)
|
||||
{
|
||||
case nano::work_version::work_1:
|
||||
result = network_constants.publish_thresholds.threshold (details_a);
|
||||
result = threshold (details_a);
|
||||
break;
|
||||
default:
|
||||
debug_assert (false && "Invalid version specified to ledger work_threshold");
|
||||
|
@ -199,6 +198,11 @@ bool nano::work_thresholds::validate_entry (nano::work_version const version_a,
|
|||
return difficulty (version_a, root_a, work_a) < threshold_entry (version_a, nano::block_type::state);
|
||||
}
|
||||
|
||||
bool nano::work_thresholds::validate_entry (nano::block const & block_a) const
|
||||
{
|
||||
return block_a.difficulty () < threshold_entry (block_a.work_version (), block_a.type ());
|
||||
}
|
||||
|
||||
namespace nano
|
||||
{
|
||||
const char * network_constants::active_network_err_msg = "Invalid network. Valid values are live, test, beta and dev.";
|
||||
|
|
|
@ -83,6 +83,7 @@ enum class work_version
|
|||
};
|
||||
enum class block_type : uint8_t;
|
||||
class root;
|
||||
class block;
|
||||
class block_details;
|
||||
|
||||
class work_thresholds
|
||||
|
@ -110,7 +111,7 @@ public:
|
|||
return other_a;
|
||||
}
|
||||
|
||||
uint64_t threshold_entry (nano::work_version const, nano::block_type const);
|
||||
uint64_t threshold_entry (nano::work_version const, nano::block_type const) const;
|
||||
uint64_t threshold (nano::block_details const &);
|
||||
// Ledger threshold
|
||||
uint64_t threshold (nano::work_version const, nano::block_details const);
|
||||
|
@ -120,6 +121,7 @@ public:
|
|||
double denormalized_multiplier (double const, uint64_t const);
|
||||
uint64_t difficulty (nano::work_version const, nano::root const &, uint64_t const);
|
||||
bool validate_entry (nano::work_version const, nano::root const &, uint64_t const);
|
||||
bool validate_entry (nano::block const &) const;
|
||||
|
||||
/** Network work thresholds. Define these inline as constexpr when moving to cpp17. */
|
||||
static const nano::work_thresholds publish_full;
|
||||
|
|
|
@ -22,12 +22,6 @@ std::string nano::to_string (nano::work_version const version_a)
|
|||
return result;
|
||||
}
|
||||
|
||||
bool nano::work_validate_entry (nano::block const & block_a)
|
||||
{
|
||||
static nano::network_constants network_constants;
|
||||
return block_a.difficulty () < network_constants.publish_thresholds.threshold_entry (block_a.work_version (), block_a.type ());
|
||||
}
|
||||
|
||||
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),
|
||||
|
|
|
@ -18,7 +18,6 @@ std::string to_string (nano::work_version const version_a);
|
|||
class block;
|
||||
class block_details;
|
||||
enum class block_type : uint8_t;
|
||||
bool work_validate_entry (nano::block const &);
|
||||
|
||||
class opencl_work;
|
||||
class work_item final
|
||||
|
|
|
@ -105,7 +105,7 @@ void nano::block_processor::add (std::shared_ptr<nano::block> const & block_a, u
|
|||
|
||||
void nano::block_processor::add (nano::unchecked_info const & info_a)
|
||||
{
|
||||
debug_assert (!nano::work_validate_entry (*info_a.block));
|
||||
debug_assert (!node.network_params.network.publish_thresholds.validate_entry (*info_a.block));
|
||||
bool quarter_full (size () > node.flags.block_processor_full_size / 4);
|
||||
if (info_a.verified == nano::signature_verification::unknown && (info_a.block->type () == nano::block_type::state || info_a.block->type () == nano::block_type::open || !info_a.account.is_zero ()))
|
||||
{
|
||||
|
@ -124,7 +124,7 @@ void nano::block_processor::add (nano::unchecked_info const & info_a)
|
|||
void nano::block_processor::add_local (nano::unchecked_info const & info_a)
|
||||
{
|
||||
release_assert (info_a.verified == nano::signature_verification::unknown && (info_a.block->type () == nano::block_type::state || !info_a.account.is_zero ()));
|
||||
debug_assert (!nano::work_validate_entry (*info_a.block));
|
||||
debug_assert (!node.network_params.network.publish_thresholds.validate_entry (*info_a.block));
|
||||
state_block_signature_verification.add (info_a);
|
||||
}
|
||||
|
||||
|
|
|
@ -208,7 +208,7 @@ void nano::bulk_pull_client::received_block (boost::system::error_code const & e
|
|||
{
|
||||
nano::bufferstream stream (connection->receive_buffer->data (), size_a);
|
||||
auto block (nano::deserialize_block (stream, type_a));
|
||||
if (block != nullptr && !nano::work_validate_entry (*block))
|
||||
if (block != nullptr && !connection->node->network_params.network.publish_thresholds.validate_entry (*block))
|
||||
{
|
||||
auto hash (block->hash ());
|
||||
if (connection->node->config.logging.bulk_pull_logging ())
|
||||
|
|
|
@ -232,7 +232,7 @@ void nano::bulk_push_server::received_block (boost::system::error_code const & e
|
|||
{
|
||||
nano::bufferstream stream (receive_buffer->data (), size_a);
|
||||
auto block (nano::deserialize_block (stream, type_a));
|
||||
if (block != nullptr && !nano::work_validate_entry (*block))
|
||||
if (block != nullptr && !connection->node->network_params.network.publish_thresholds.validate_entry (*block))
|
||||
{
|
||||
connection->node->process_active (std::move (block));
|
||||
throttled_receive ();
|
||||
|
|
|
@ -426,7 +426,7 @@ void nano::bootstrap_server::receive_publish_action (boost::system::error_code c
|
|||
{
|
||||
if (is_realtime_connection ())
|
||||
{
|
||||
if (!nano::work_validate_entry (*request->block))
|
||||
if (!node->network_params.network.publish_thresholds.validate_entry (*request->block))
|
||||
{
|
||||
add_request (std::unique_ptr<nano::message> (request.release ()));
|
||||
}
|
||||
|
@ -494,7 +494,7 @@ void nano::bootstrap_server::receive_confirm_ack_action (boost::system::error_co
|
|||
if (!vote_block.which ())
|
||||
{
|
||||
auto const & block (boost::get<std::shared_ptr<nano::block>> (vote_block));
|
||||
if (nano::work_validate_entry (*block))
|
||||
if (node->network_params.network.publish_thresholds.validate_entry (*block))
|
||||
{
|
||||
process_vote = false;
|
||||
node->stats.inc_detail_only (nano::stat::type::error, nano::stat::detail::insufficient_work);
|
||||
|
|
|
@ -424,7 +424,7 @@ void nano::message_parser::deserialize_publish (nano::stream & stream_a, nano::m
|
|||
nano::publish incoming (error, stream_a, header_a, digest_a, &block_uniquer);
|
||||
if (!error && at_end (stream_a))
|
||||
{
|
||||
if (!nano::work_validate_entry (*incoming.block))
|
||||
if (!network.publish_thresholds.validate_entry (*incoming.block))
|
||||
{
|
||||
visitor.publish (incoming);
|
||||
}
|
||||
|
@ -445,7 +445,7 @@ void nano::message_parser::deserialize_confirm_req (nano::stream & stream_a, nan
|
|||
nano::confirm_req incoming (error, stream_a, header_a, &block_uniquer);
|
||||
if (!error && at_end (stream_a))
|
||||
{
|
||||
if (incoming.block == nullptr || !nano::work_validate_entry (*incoming.block))
|
||||
if (incoming.block == nullptr || !network.publish_thresholds.validate_entry (*incoming.block))
|
||||
{
|
||||
visitor.confirm_req (incoming);
|
||||
}
|
||||
|
@ -471,7 +471,7 @@ void nano::message_parser::deserialize_confirm_ack (nano::stream & stream_a, nan
|
|||
if (!vote_block.which ())
|
||||
{
|
||||
auto const & block (boost::get<std::shared_ptr<nano::block>> (vote_block));
|
||||
if (nano::work_validate_entry (*block))
|
||||
if (network.publish_thresholds.validate_entry (*block))
|
||||
{
|
||||
status = parse_status::insufficient_work;
|
||||
break;
|
||||
|
|
|
@ -3123,7 +3123,7 @@ void nano::json_handler::process ()
|
|||
}
|
||||
if (!rpc_l->ec)
|
||||
{
|
||||
if (!nano::work_validate_entry (*block))
|
||||
if (!rpc_l->node.network_params.network.publish_thresholds.validate_entry (*block))
|
||||
{
|
||||
if (!is_async)
|
||||
{
|
||||
|
|
|
@ -2003,7 +2003,7 @@ nano_qt::block_entry::block_entry (nano_qt::wallet & wallet_a) :
|
|||
{
|
||||
show_label_ok (*status);
|
||||
this->status->setText ("");
|
||||
if (!nano::work_validate_entry (*block_l))
|
||||
if (!this->wallet.node.network_params.network.publish_thresholds.validate_entry (*block_l))
|
||||
{
|
||||
this->wallet.node.process_active (std::move (block_l));
|
||||
}
|
||||
|
|
|
@ -869,7 +869,8 @@ nano::uint128_t nano::ledger::account_pending (nano::transaction const & transac
|
|||
|
||||
nano::process_return nano::ledger::process (nano::write_transaction const & transaction_a, nano::block & block_a, nano::signature_verification verification)
|
||||
{
|
||||
debug_assert (!nano::work_validate_entry (block_a) || constants.genesis == nano::dev::genesis);
|
||||
static nano::network_constants network_constants;
|
||||
debug_assert (!network_constants.publish_thresholds.validate_entry (block_a) || constants.genesis == nano::dev::genesis);
|
||||
ledger_processor processor (*this, transaction_a, verification);
|
||||
block_a.visit (processor);
|
||||
if (processor.result.code == nano::process_result::progress)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue