Passing work_thresholds in to ledger_constants and removing static references to nano::network_constants from within the ledger processor.

This commit is contained in:
clemahieu 2021-08-09 08:57:40 +01:00
commit 0096d2086b
No known key found for this signature in database
GPG key ID: 43708520C8DFB938
4 changed files with 17 additions and 29 deletions

View file

@ -8,7 +8,6 @@
TEST (network_filter, unit)
{
nano::ledger_constants constants{ nano::networks::nano_dev_network };
nano::network_filter filter (1);
auto one_block = [&filter] (std::shared_ptr<nano::block> const & block_a, bool expect_duplicate_a) {
nano::publish message{ nano::dev::network_params.network, block_a };
@ -32,15 +31,15 @@ TEST (network_filter, unit)
ASSERT_NE (nullptr, block);
ASSERT_EQ (*block, *block_a);
};
one_block (constants.genesis, false);
one_block (nano::dev::genesis, false);
for (int i = 0; i < 10; ++i)
{
one_block (constants.genesis, true);
one_block (nano::dev::genesis, true);
}
nano::state_block_builder builder;
auto new_block = builder
.account (nano::dev::genesis_key.pub)
.previous (constants.genesis->hash ())
.previous (nano::dev::genesis->hash ())
.representative (nano::dev::genesis_key.pub)
.balance (nano::dev::constants.genesis_amount - 10 * nano::xrb_ratio)
.link (nano::public_key ())
@ -55,14 +54,13 @@ TEST (network_filter, unit)
}
for (int i = 0; i < 100; ++i)
{
one_block (constants.genesis, false);
one_block (nano::dev::genesis, false);
one_block (new_block, false);
}
}
TEST (network_filter, many)
{
nano::ledger_constants constants{ nano::networks::nano_dev_network };
nano::network_filter filter (4);
nano::keypair key1;
for (int i = 0; i < 100; ++i)
@ -70,7 +68,7 @@ TEST (network_filter, many)
nano::state_block_builder builder;
auto block = builder
.account (nano::dev::genesis_key.pub)
.previous (constants.genesis->hash ())
.previous (nano::dev::genesis->hash ())
.representative (nano::dev::genesis_key.pub)
.balance (nano::dev::constants.genesis_amount - i * 10 * nano::xrb_ratio)
.link (key1.pub)

View file

@ -86,19 +86,15 @@ nano::ledger_constants & nano::dev::constants{ nano::dev::network_params.ledger
std::shared_ptr<nano::block> & nano::dev::genesis = nano::dev::constants.genesis;
nano::network_params::network_params (nano::networks network_a) :
network (network_a), ledger (network), voting (network), node (network), portmapping (network), bootstrap (network)
network (network_a), ledger (network.publish_thresholds, network.network ()), voting (network), node (network), portmapping (network), bootstrap (network)
{
unsigned constexpr kdf_full_work = 64 * 1024;
unsigned constexpr kdf_dev_work = 8;
kdf_work = network.is_dev_network () ? kdf_dev_work : kdf_full_work;
}
nano::ledger_constants::ledger_constants (nano::network_constants & network_constants) :
ledger_constants (network_constants.network ())
{
}
nano::ledger_constants::ledger_constants (nano::networks network_a) :
nano::ledger_constants::ledger_constants (nano::work_thresholds & work, nano::networks network_a) :
work{ work },
zero_key ("0"),
nano_beta_account (beta_public_key_data),
nano_live_account (live_public_key_data),

View file

@ -340,8 +340,8 @@ class network_params;
class ledger_constants
{
public:
ledger_constants (nano::network_constants & network_constants);
ledger_constants (nano::networks network_a);
ledger_constants (nano::work_thresholds & work, nano::networks network_a);
nano::work_thresholds & work;
nano::keypair zero_key;
nano::account nano_beta_account;
nano::account nano_live_account;

View file

@ -346,8 +346,7 @@ void ledger_processor::state_block_impl (nano::state_block & block_a)
if (result.code == nano::process_result::progress)
{
nano::block_details block_details (epoch, is_send, is_receive, false);
nano::network_constants constants;
result.code = block_a.difficulty () >= constants.publish_thresholds.threshold (block_a.work_version (), block_details) ? nano::process_result::progress : nano::process_result::insufficient_work; // Does this block have sufficient work? (Malformed)
result.code = block_a.difficulty () >= ledger.constants.work.threshold (block_a.work_version (), block_details) ? nano::process_result::progress : nano::process_result::insufficient_work; // Does this block have sufficient work? (Malformed)
if (result.code == nano::process_result::progress)
{
ledger.stats.inc (nano::stat::type::ledger, nano::stat::detail::state_block);
@ -447,8 +446,7 @@ void ledger_processor::epoch_block_impl (nano::state_block & block_a)
if (result.code == nano::process_result::progress)
{
nano::block_details block_details (epoch, false, false, true);
nano::network_constants constants;
result.code = block_a.difficulty () >= constants.publish_thresholds.threshold (block_a.work_version (), block_details) ? nano::process_result::progress : nano::process_result::insufficient_work; // Does this block have sufficient work? (Malformed)
result.code = block_a.difficulty () >= ledger.constants.work.threshold (block_a.work_version (), block_details) ? nano::process_result::progress : nano::process_result::insufficient_work; // Does this block have sufficient work? (Malformed)
if (result.code == nano::process_result::progress)
{
ledger.stats.inc (nano::stat::type::ledger, nano::stat::detail::epoch_block);
@ -500,8 +498,7 @@ void ledger_processor::change_block (nano::change_block & block_a)
if (result.code == nano::process_result::progress)
{
nano::block_details block_details (nano::epoch::epoch_0, false /* unused */, false /* unused */, false /* unused */);
nano::network_constants constants;
result.code = block_a.difficulty () >= constants.publish_thresholds.threshold (block_a.work_version (), block_details) ? nano::process_result::progress : nano::process_result::insufficient_work; // Does this block have sufficient work? (Malformed)
result.code = block_a.difficulty () >= ledger.constants.work.threshold (block_a.work_version (), block_details) ? nano::process_result::progress : nano::process_result::insufficient_work; // Does this block have sufficient work? (Malformed)
if (result.code == nano::process_result::progress)
{
debug_assert (!validate_message (account, hash, block_a.signature));
@ -550,8 +547,7 @@ void ledger_processor::send_block (nano::send_block & block_a)
if (result.code == nano::process_result::progress)
{
nano::block_details block_details (nano::epoch::epoch_0, false /* unused */, false /* unused */, false /* unused */);
nano::network_constants constants;
result.code = block_a.difficulty () >= constants.publish_thresholds.threshold (block_a.work_version (), block_details) ? nano::process_result::progress : nano::process_result::insufficient_work; // Does this block have sufficient work? (Malformed)
result.code = block_a.difficulty () >= ledger.constants.work.threshold (block_a.work_version (), block_details) ? nano::process_result::progress : nano::process_result::insufficient_work; // Does this block have sufficient work? (Malformed)
if (result.code == nano::process_result::progress)
{
debug_assert (!validate_message (account, hash, block_a.signature));
@ -628,8 +624,7 @@ void ledger_processor::receive_block (nano::receive_block & block_a)
if (result.code == nano::process_result::progress)
{
nano::block_details block_details (nano::epoch::epoch_0, false /* unused */, false /* unused */, false /* unused */);
nano::network_constants constants;
result.code = block_a.difficulty () >= constants.publish_thresholds.threshold (block_a.work_version (), block_details) ? nano::process_result::progress : nano::process_result::insufficient_work; // Does this block have sufficient work? (Malformed)
result.code = block_a.difficulty () >= ledger.constants.work.threshold (block_a.work_version (), block_details) ? nano::process_result::progress : nano::process_result::insufficient_work; // Does this block have sufficient work? (Malformed)
if (result.code == nano::process_result::progress)
{
auto new_balance (info.balance.number () + pending.amount.number ());
@ -702,8 +697,7 @@ void ledger_processor::open_block (nano::open_block & block_a)
if (result.code == nano::process_result::progress)
{
nano::block_details block_details (nano::epoch::epoch_0, false /* unused */, false /* unused */, false /* unused */);
nano::network_constants constants;
result.code = block_a.difficulty () >= constants.publish_thresholds.threshold (block_a.work_version (), block_details) ? nano::process_result::progress : nano::process_result::insufficient_work; // Does this block have sufficient work? (Malformed)
result.code = block_a.difficulty () >= ledger.constants.work.threshold (block_a.work_version (), block_details) ? nano::process_result::progress : nano::process_result::insufficient_work; // Does this block have sufficient work? (Malformed)
if (result.code == nano::process_result::progress)
{
#ifdef NDEBUG
@ -870,7 +864,7 @@ 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)
{
static nano::network_constants network_constants;
debug_assert (!network_constants.publish_thresholds.validate_entry (block_a) || constants.genesis == nano::dev::genesis);
debug_assert (!constants.work.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)