Add node sequence for tests (#2712)

This commit is contained in:
Sergey Kroshnin 2020-04-09 11:25:01 +03:00 committed by GitHub
commit 5279d9531b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 23 additions and 10 deletions

View file

@ -3778,6 +3778,15 @@ TEST (active_difficulty, recalculate_work)
lock.unlock ();
}
TEST (node, node_sequence)
{
nano::system system (3);
ASSERT_EQ (0, system.nodes[0]->node_seq);
ASSERT_EQ (0, system.nodes[0]->node_seq);
ASSERT_EQ (1, system.nodes[1]->node_seq);
ASSERT_EQ (2, system.nodes[2]->node_seq);
}
namespace
{
void add_required_children_node_config_tree (nano::jsonconfig & tree)

View file

@ -83,12 +83,12 @@ std::unique_ptr<nano::container_info_component> nano::collect_container_info (re
return composite;
}
nano::node::node (boost::asio::io_context & io_ctx_a, uint16_t peering_port_a, boost::filesystem::path const & application_path_a, nano::alarm & alarm_a, nano::logging const & logging_a, nano::work_pool & work_a, nano::node_flags flags_a) :
node (io_ctx_a, application_path_a, alarm_a, nano::node_config (peering_port_a, logging_a), work_a, flags_a)
nano::node::node (boost::asio::io_context & io_ctx_a, uint16_t peering_port_a, boost::filesystem::path const & application_path_a, nano::alarm & alarm_a, nano::logging const & logging_a, nano::work_pool & work_a, nano::node_flags flags_a, unsigned seq) :
node (io_ctx_a, application_path_a, alarm_a, nano::node_config (peering_port_a, logging_a), work_a, flags_a, seq)
{
}
nano::node::node (boost::asio::io_context & io_ctx_a, boost::filesystem::path const & application_path_a, nano::alarm & alarm_a, nano::node_config const & config_a, nano::work_pool & work_a, nano::node_flags flags_a) :
nano::node::node (boost::asio::io_context & io_ctx_a, boost::filesystem::path const & application_path_a, nano::alarm & alarm_a, nano::node_config const & config_a, nano::work_pool & work_a, nano::node_flags flags_a, unsigned seq) :
io_ctx (io_ctx_a),
node_initialized_latch (1),
config (config_a),
@ -129,7 +129,8 @@ active (*this, confirmation_height_processor),
aggregator (network_params.network, config, stats, votes_cache, store, wallets),
payment_observer_processor (observers.blocks),
wallets (wallets_store.init_error (), *this),
startup_time (std::chrono::steady_clock::now ())
startup_time (std::chrono::steady_clock::now ()),
node_seq (seq)
{
if (!init_error ())
{

View file

@ -87,8 +87,8 @@ std::unique_ptr<container_info_component> collect_container_info (rep_crawler &
class node final : public std::enable_shared_from_this<nano::node>
{
public:
node (boost::asio::io_context &, uint16_t, boost::filesystem::path const &, nano::alarm &, nano::logging const &, nano::work_pool &, nano::node_flags = nano::node_flags ());
node (boost::asio::io_context &, boost::filesystem::path const &, nano::alarm &, nano::node_config const &, nano::work_pool &, nano::node_flags = nano::node_flags ());
node (boost::asio::io_context &, uint16_t, boost::filesystem::path const &, nano::alarm &, nano::logging const &, nano::work_pool &, nano::node_flags = nano::node_flags (), unsigned seq = 0);
node (boost::asio::io_context &, boost::filesystem::path const &, nano::alarm &, nano::node_config const &, nano::work_pool &, nano::node_flags = nano::node_flags (), unsigned seq = 0);
~node ();
template <typename T>
void background (T action_a)
@ -195,6 +195,8 @@ public:
static double constexpr price_max = 16.0;
static double constexpr free_cutoff = 1024.0;
// For tests only
unsigned node_seq;
// For tests only
boost::optional<uint64_t> work_generate_blocking (nano::block &);
// For tests only
boost::optional<uint64_t> work_generate_blocking (nano::root const &, uint64_t);

View file

@ -30,7 +30,7 @@ std::shared_ptr<nano::node> nano::system::add_node (nano::node_flags node_flags_
/** Returns the node added. */
std::shared_ptr<nano::node> nano::system::add_node (nano::node_config const & node_config_a, nano::node_flags node_flags_a, nano::transport::transport_type type_a)
{
auto node (std::make_shared<nano::node> (io_ctx, nano::unique_path (), alarm, node_config_a, work, node_flags_a));
auto node (std::make_shared<nano::node> (io_ctx, nano::unique_path (), alarm, node_config_a, work, node_flags_a, node_sequence++));
debug_assert (!node->init_error ());
node->start ();
node->wallets.create (nano::random_wallet_id ());

View file

@ -53,6 +53,7 @@ public:
nano::work_pool work{ 1 };
std::chrono::time_point<std::chrono::steady_clock, std::chrono::duration<double>> deadline{ std::chrono::steady_clock::time_point::max () };
double deadline_scaling_factor{ 1.0 };
unsigned node_sequence{ 0 };
};
}
REGISTER_ERROR_CODES (nano, error_system);

View file

@ -1010,7 +1010,7 @@ nano::root nano::ledger::latest_root (nano::transaction const & transaction_a, n
}
}
void nano::ledger::dump_account_chain (nano::account const & account_a)
void nano::ledger::dump_account_chain (nano::account const & account_a, std::ostream & stream)
{
auto transaction (store.tx_begin_read ());
auto hash (latest (transaction, account_a));
@ -1018,7 +1018,7 @@ void nano::ledger::dump_account_chain (nano::account const & account_a)
{
auto block (store.block_get (transaction, hash));
debug_assert (block != nullptr);
std::cerr << hash.to_string () << std::endl;
stream << hash.to_string () << std::endl;
hash = block->previous ();
}
}

View file

@ -42,7 +42,7 @@ public:
bool rollback (nano::write_transaction const &, nano::block_hash const &, std::vector<std::shared_ptr<nano::block>> &);
bool rollback (nano::write_transaction const &, nano::block_hash const &);
void change_latest (nano::write_transaction const &, nano::account const &, nano::account_info const &, nano::account_info const &);
void dump_account_chain (nano::account const &);
void dump_account_chain (nano::account const &, std::ostream & = std::cout);
bool could_fit (nano::transaction const &, nano::block const &);
bool is_epoch_link (nano::link const &);
nano::account const & epoch_signer (nano::link const &) const;