Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove timestamp count in votes #3064

Merged
merged 1 commit into from
Dec 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion nano/core_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ add_executable(
telemetry.cpp
toml.cpp
timer.cpp
timestamp.cpp
uint256_union.cpp
utility.cpp
vote_processor.cpp
Expand Down
75 changes: 0 additions & 75 deletions nano/core_test/timestamp.cpp

This file was deleted.

6 changes: 3 additions & 3 deletions nano/core_test/vote_processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ TEST (vote_processor, no_broadcast_local)
ASSERT_TRUE (node.wallets.reps ().exists (nano::dev_genesis_key.pub));
ASSERT_FALSE (node.wallets.reps ().have_half_rep ());
// Process a vote
auto vote = std::make_shared<nano::vote> (nano::dev_genesis_key.pub, nano::dev_genesis_key.prv, node.timestamps.now (), std::vector<nano::block_hash>{ send->hash () });
auto vote = std::make_shared<nano::vote> (nano::dev_genesis_key.pub, nano::dev_genesis_key.prv, nano::milliseconds_since_epoch (), std::vector<nano::block_hash>{ send->hash () });
ASSERT_EQ (nano::vote_code::vote, node.active.vote (vote));
// Make sure the vote was processed
auto election (node.active.election (send->qualified_root ()));
Expand Down Expand Up @@ -241,7 +241,7 @@ TEST (vote_processor, no_broadcast_local)
ASSERT_EQ (node.config.vote_minimum, node.weight (nano::dev_genesis_key.pub));
node.block_confirm (send2);
// Process a vote
auto vote2 = std::make_shared<nano::vote> (nano::dev_genesis_key.pub, nano::dev_genesis_key.prv, node.timestamps.now (), std::vector<nano::block_hash>{ send2->hash () });
auto vote2 = std::make_shared<nano::vote> (nano::dev_genesis_key.pub, nano::dev_genesis_key.prv, nano::milliseconds_since_epoch (), std::vector<nano::block_hash>{ send2->hash () });
ASSERT_EQ (nano::vote_code::vote, node.active.vote (vote2));
// Make sure the vote was processed
auto election2 (node.active.election (send2->qualified_root ()));
Expand Down Expand Up @@ -275,7 +275,7 @@ TEST (vote_processor, no_broadcast_local)
ASSERT_TRUE (node.wallets.reps ().exists (nano::dev_genesis_key.pub));
ASSERT_TRUE (node.wallets.reps ().have_half_rep ());
// Process a vote
auto vote3 = std::make_shared<nano::vote> (nano::dev_genesis_key.pub, nano::dev_genesis_key.prv, node.timestamps.now (), std::vector<nano::block_hash>{ open->hash () });
auto vote3 = std::make_shared<nano::vote> (nano::dev_genesis_key.pub, nano::dev_genesis_key.prv, nano::milliseconds_since_epoch (), std::vector<nano::block_hash>{ open->hash () });
ASSERT_EQ (nano::vote_code::vote, node.active.vote (vote3));
// Make sure the vote was processed
auto election3 (node.active.election (open->qualified_root ()));
Expand Down
3 changes: 0 additions & 3 deletions nano/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,6 @@ add_library(
threading.cpp
timer.hpp
timer.cpp
timestamp_fwd.hpp
timestamp.hpp
timestamp.cpp
tomlconfig.hpp
tomlconfig.cpp
utility.hpp
Expand Down
10 changes: 10 additions & 0 deletions nano/lib/timer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,14 @@ class timer
unsigned measurements{ 0 };
void update_ticks ();
};

inline uint64_t milliseconds_since_epoch ()
{
return std::chrono::duration_cast<std::chrono::milliseconds> (std::chrono::system_clock::now ().time_since_epoch ()).count ();
}

inline uint64_t seconds_since_epoch ()
{
return std::chrono::duration_cast<std::chrono::seconds> (std::chrono::system_clock::now ().time_since_epoch ()).count ();
}
}
Empty file removed nano/lib/timestamp.cpp
Empty file.
76 changes: 0 additions & 76 deletions nano/lib/timestamp.hpp

This file was deleted.

10 changes: 0 additions & 10 deletions nano/lib/timestamp_fwd.hpp

This file was deleted.

2 changes: 1 addition & 1 deletion nano/node/active_transactions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ confirmation_height_processor (confirmation_height_processor_a),
node (node_a),
multipliers_cb (20, 1.),
trended_active_multiplier (1.0),
generator (node_a.timestamps, node_a.config, node_a.ledger, node_a.wallets, node_a.vote_processor, node_a.history, node_a.network, node_a.stats),
generator (node_a.config, node_a.ledger, node_a.wallets, node_a.vote_processor, node_a.history, node_a.network, node_a.stats),
check_all_elections_period (node_a.network_params.network.is_dev_network () ? 10ms : 5s),
election_time_to_live (node_a.network_params.network.is_dev_network () ? 0s : 2s),
prioritized_cutoff (std::max<size_t> (1, node_a.config.active_elections_size / 10)),
Expand Down
2 changes: 0 additions & 2 deletions nano/node/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <nano/lib/alarm.hpp>
#include <nano/lib/config.hpp>
#include <nano/lib/stats.hpp>
#include <nano/lib/timestamp.hpp>
#include <nano/lib/work.hpp>
#include <nano/lib/worker.hpp>
#include <nano/node/active_transactions.hpp>
Expand Down Expand Up @@ -158,7 +157,6 @@ class node final : public std::enable_shared_from_this<nano::node>
bool init_error () const;
bool epoch_upgrader (nano::private_key const &, nano::epoch, uint64_t, uint64_t);
std::pair<uint64_t, decltype (nano::ledger::bootstrap_weights)> get_bootstrap_weights () const;
nano::timestamp_generator timestamps;
nano::worker worker;
nano::write_database_queue write_database_queue;
boost::asio::io_context & io_ctx;
Expand Down
1 change: 0 additions & 1 deletion nano/node/request_aggregator.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include <nano/lib/stats.hpp>
#include <nano/lib/threading.hpp>
#include <nano/lib/timestamp.hpp>
#include <nano/node/active_transactions.hpp>
#include <nano/node/common.hpp>
#include <nano/node/network.hpp>
Expand Down
1 change: 0 additions & 1 deletion nano/node/request_aggregator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include <nano/lib/locks.hpp>
#include <nano/lib/numbers.hpp>
#include <nano/lib/timestamp_fwd.hpp>
#include <nano/node/transport/transport.hpp>

#include <boost/multi_index/hashed_index.hpp>
Expand Down
5 changes: 2 additions & 3 deletions nano/node/voting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,8 @@ std::unique_ptr<nano::container_info_component> nano::collect_container_info (na
return composite;
}

nano::vote_generator::vote_generator (nano::timestamp_generator & timestamps_a, nano::node_config const & config_a, nano::ledger & ledger_a, nano::wallets & wallets_a, nano::vote_processor & vote_processor_a, nano::local_vote_history & history_a, nano::network & network_a, nano::stat & stats_a) :
nano::vote_generator::vote_generator (nano::node_config const & config_a, nano::ledger & ledger_a, nano::wallets & wallets_a, nano::vote_processor & vote_processor_a, nano::local_vote_history & history_a, nano::network & network_a, nano::stat & stats_a) :
config (config_a),
timestamps{ timestamps_a },
ledger (ledger_a),
wallets (wallets_a),
vote_processor (vote_processor_a),
Expand Down Expand Up @@ -282,7 +281,7 @@ void nano::vote_generator::vote (std::vector<nano::block_hash> const & hashes_a,
debug_assert (hashes_a.size () == roots_a.size ());
std::vector<std::shared_ptr<nano::vote>> votes_l;
wallets.foreach_representative ([this, &hashes_a, &votes_l](nano::public_key const & pub_a, nano::raw_key const & prv_a) {
votes_l.emplace_back (std::make_shared<nano::vote> (pub_a, prv_a, timestamps.now (), hashes_a));
votes_l.emplace_back (std::make_shared<nano::vote> (pub_a, prv_a, nano::milliseconds_since_epoch (), hashes_a));
});
for (auto const & vote_l : votes_l)
{
Expand Down
4 changes: 1 addition & 3 deletions nano/node/voting.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

#include <nano/lib/locks.hpp>
#include <nano/lib/numbers.hpp>
#include <nano/lib/timestamp_fwd.hpp>
#include <nano/lib/utility.hpp>
#include <nano/node/wallet.hpp>
#include <nano/secure/common.hpp>
Expand Down Expand Up @@ -87,7 +86,7 @@ class vote_generator final
using request_t = std::pair<std::vector<candidate_t>, std::shared_ptr<nano::transport::channel>>;

public:
vote_generator (nano::timestamp_generator & timestamps_a, nano::node_config const & config_a, nano::ledger & ledger_a, nano::wallets & wallets_a, nano::vote_processor & vote_processor_a, nano::local_vote_history & history_a, nano::network & network_a, nano::stat & stats_a);
vote_generator (nano::node_config const & config_a, nano::ledger & ledger_a, nano::wallets & wallets_a, nano::vote_processor & vote_processor_a, nano::local_vote_history & history_a, nano::network & network_a, nano::stat & stats_a);
/** Queue items for vote generation, or broadcast votes already in cache */
void add (nano::root const &, nano::block_hash const &);
/** Queue blocks for vote generation, returning the number of successful candidates.*/
Expand All @@ -103,7 +102,6 @@ class vote_generator final
void broadcast_action (std::shared_ptr<nano::vote> const &) const;
std::function<void(std::shared_ptr<nano::vote> const &, std::shared_ptr<nano::transport::channel> &)> reply_action; // must be set only during initialization by using set_reply_action
nano::node_config const & config;
nano::timestamp_generator & timestamps;
nano::ledger & ledger;
nano::wallets & wallets;
nano::vote_processor & vote_processor;
Expand Down
8 changes: 2 additions & 6 deletions nano/node/websocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,11 +447,10 @@ std::string from_topic (nano::websocket::topic topic_a)

void nano::websocket::session::send_ack (std::string action_a, std::string id_a)
{
auto milli_since_epoch = std::chrono::duration_cast<std::chrono::milliseconds> (std::chrono::system_clock::now ().time_since_epoch ()).count ();
nano::websocket::message msg (nano::websocket::topic::ack);
boost::property_tree::ptree & message_l = msg.contents;
message_l.add ("ack", action_a);
message_l.add ("time", std::to_string (milli_since_epoch));
message_l.add ("time", std::to_string (nano::milliseconds_since_epoch ()));
if (!id_a.empty ())
{
message_l.add ("id", id_a);
Expand Down Expand Up @@ -915,12 +914,9 @@ nano::websocket::message nano::websocket::message_builder::new_block_arrived (na

void nano::websocket::message_builder::set_common_fields (nano::websocket::message & message_a)
{
using namespace std::chrono;
auto milli_since_epoch = std::chrono::duration_cast<std::chrono::milliseconds> (std::chrono::system_clock::now ().time_since_epoch ()).count ();

// Common message information
message_a.contents.add ("topic", from_topic (message_a.topic));
message_a.contents.add ("time", std::to_string (milli_since_epoch));
message_a.contents.add ("time", std::to_string (nano::milliseconds_since_epoch ()));
}

std::string nano::websocket::message::to_string () const
Expand Down
2 changes: 1 addition & 1 deletion nano/secure/blockstore_partial.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <nano/lib/config.hpp>
#include <nano/lib/rep_weights.hpp>
#include <nano/lib/threading.hpp>
#include <nano/lib/timestamp.hpp>
#include <nano/lib/timer.hpp>
#include <nano/secure/blockstore.hpp>
#include <nano/secure/buffer.hpp>

Expand Down
1 change: 0 additions & 1 deletion nano/secure/ledger.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include <nano/lib/rep_weights.hpp>
#include <nano/lib/stats.hpp>
#include <nano/lib/timestamp.hpp>
#include <nano/lib/utility.hpp>
#include <nano/lib/work.hpp>
#include <nano/secure/blockstore.hpp>
Expand Down
1 change: 1 addition & 0 deletions nano/secure/ledger.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <nano/lib/rep_weights.hpp>
#include <nano/lib/timer.hpp>
#include <nano/secure/common.hpp>

#include <map>
Expand Down