Merge pull request #4509 from clemahieu/election_header_reduction
Header reduction for election, vote_generator, vote_spacing, and active_transactions
This commit is contained in:
commit
e8beaa8f89
59 changed files with 523 additions and 341 deletions
|
@ -1,5 +1,6 @@
|
|||
#include <nano/lib/blocks.hpp>
|
||||
#include <nano/lib/jsonconfig.hpp>
|
||||
#include <nano/node/active_transactions.hpp>
|
||||
#include <nano/node/election.hpp>
|
||||
#include <nano/node/scheduler/component.hpp>
|
||||
#include <nano/node/scheduler/manual.hpp>
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include <nano/lib/blocks.hpp>
|
||||
#include <nano/node/active_transactions.hpp>
|
||||
#include <nano/node/bootstrap/block_deserializer.hpp>
|
||||
#include <nano/node/bootstrap/bootstrap_frontier.hpp>
|
||||
#include <nano/node/bootstrap/bootstrap_lazy.hpp>
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include <nano/lib/blocks.hpp>
|
||||
#include <nano/lib/logging.hpp>
|
||||
#include <nano/node/active_transactions.hpp>
|
||||
#include <nano/node/election.hpp>
|
||||
#include <nano/node/make_store.hpp>
|
||||
#include <nano/secure/ledger.hpp>
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <nano/lib/blocks.hpp>
|
||||
#include <nano/lib/jsonconfig.hpp>
|
||||
#include <nano/node/active_transactions.hpp>
|
||||
#include <nano/node/confirmation_solicitor.hpp>
|
||||
#include <nano/node/election.hpp>
|
||||
#include <nano/node/transport/inproc.hpp>
|
||||
#include <nano/test_common/network.hpp>
|
||||
#include <nano/test_common/system.hpp>
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include <nano/lib/blocks.hpp>
|
||||
#include <nano/node/active_transactions.hpp>
|
||||
#include <nano/node/election.hpp>
|
||||
#include <nano/node/scheduler/component.hpp>
|
||||
#include <nano/node/scheduler/priority.hpp>
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include <nano/lib/blocks.hpp>
|
||||
#include <nano/node/active_transactions.hpp>
|
||||
#include <nano/node/election.hpp>
|
||||
#include <nano/node/scheduler/component.hpp>
|
||||
#include <nano/node/scheduler/priority.hpp>
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
#include <nano/lib/blocks.hpp>
|
||||
#include <nano/node/active_transactions.hpp>
|
||||
#include <nano/node/election.hpp>
|
||||
#include <nano/node/scheduler/component.hpp>
|
||||
#include <nano/node/scheduler/priority.hpp>
|
||||
#include <nano/secure/ledger.hpp>
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include <nano/lib/logging.hpp>
|
||||
#include <nano/lib/stats.hpp>
|
||||
#include <nano/lib/threading.hpp>
|
||||
#include <nano/node/active_transactions.hpp>
|
||||
#include <nano/node/election.hpp>
|
||||
#include <nano/node/make_store.hpp>
|
||||
#include <nano/node/scheduler/component.hpp>
|
||||
|
|
|
@ -1,13 +1,16 @@
|
|||
#include <nano/lib/blocks.hpp>
|
||||
#include <nano/lib/config.hpp>
|
||||
#include <nano/lib/logging.hpp>
|
||||
#include <nano/node/active_transactions.hpp>
|
||||
#include <nano/node/election.hpp>
|
||||
#include <nano/node/local_vote_history.hpp>
|
||||
#include <nano/node/make_store.hpp>
|
||||
#include <nano/node/scheduler/component.hpp>
|
||||
#include <nano/node/scheduler/manual.hpp>
|
||||
#include <nano/node/scheduler/priority.hpp>
|
||||
#include <nano/node/transport/fake.hpp>
|
||||
#include <nano/node/transport/inproc.hpp>
|
||||
#include <nano/node/vote_generator.hpp>
|
||||
#include <nano/secure/ledger.hpp>
|
||||
#include <nano/test_common/network.hpp>
|
||||
#include <nano/test_common/system.hpp>
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include <nano/lib/blocks.hpp>
|
||||
#include <nano/node/active_transactions.hpp>
|
||||
#include <nano/node/election.hpp>
|
||||
#include <nano/test_common/chains.hpp>
|
||||
#include <nano/test_common/system.hpp>
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include <nano/lib/blocks.hpp>
|
||||
#include <nano/lib/config.hpp>
|
||||
#include <nano/lib/logging.hpp>
|
||||
#include <nano/node/active_transactions.hpp>
|
||||
#include <nano/node/repcrawler.hpp>
|
||||
#include <nano/node/transport/fake.hpp>
|
||||
#include <nano/node/transport/inproc.hpp>
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
#include <nano/lib/blocks.hpp>
|
||||
#include <nano/lib/jsonconfig.hpp>
|
||||
#include <nano/node/active_transactions.hpp>
|
||||
#include <nano/node/election.hpp>
|
||||
#include <nano/node/local_vote_history.hpp>
|
||||
#include <nano/node/request_aggregator.hpp>
|
||||
#include <nano/node/transport/inproc.hpp>
|
||||
#include <nano/secure/ledger.hpp>
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#include <nano/lib/blocks.hpp>
|
||||
#include <nano/lib/jsonconfig.hpp>
|
||||
#include <nano/node/active_transactions.hpp>
|
||||
#include <nano/node/election.hpp>
|
||||
#include <nano/node/transport/inproc.hpp>
|
||||
#include <nano/node/vote_processor.hpp>
|
||||
#include <nano/secure/ledger.hpp>
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <nano/lib/blocks.hpp>
|
||||
#include <nano/node/common.hpp>
|
||||
#include <nano/node/voting.hpp>
|
||||
#include <nano/node/local_vote_history.hpp>
|
||||
#include <nano/node/vote_generator.hpp>
|
||||
#include <nano/node/vote_spacing.hpp>
|
||||
#include <nano/secure/ledger.hpp>
|
||||
#include <nano/test_common/system.hpp>
|
||||
#include <nano/test_common/testutil.hpp>
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <nano/crypto_lib/random_pool.hpp>
|
||||
#include <nano/lib/blocks.hpp>
|
||||
#include <nano/lib/thread_runner.hpp>
|
||||
#include <nano/node/active_transactions.hpp>
|
||||
#include <nano/node/election.hpp>
|
||||
#include <nano/secure/ledger.hpp>
|
||||
#include <nano/store/lmdb/wallet_value.hpp>
|
||||
#include <nano/test_common/system.hpp>
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
#include <nano/lib/blocks.hpp>
|
||||
#include <nano/node/active_transactions.hpp>
|
||||
#include <nano/node/election.hpp>
|
||||
#include <nano/secure/ledger.hpp>
|
||||
#include <nano/store/versioning.hpp>
|
||||
#include <nano/test_common/system.hpp>
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include <nano/core_test/fakes/websocket_client.hpp>
|
||||
#include <nano/lib/blocks.hpp>
|
||||
#include <nano/node/active_transactions.hpp>
|
||||
#include <nano/node/transport/fake.hpp>
|
||||
#include <nano/node/websocket.hpp>
|
||||
#include <nano/test_common/network.hpp>
|
||||
|
|
|
@ -389,4 +389,12 @@ struct hash<std::reference_wrapper<::nano::block_hash const>>
|
|||
return hash (hash_a);
|
||||
}
|
||||
};
|
||||
template <>
|
||||
struct hash<::nano::root>
|
||||
{
|
||||
size_t operator() (::nano::root const & value_a) const
|
||||
{
|
||||
return std::hash<::nano::root> () (value_a);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -108,7 +108,7 @@ public:
|
|||
}
|
||||
|
||||
public: // Container info
|
||||
std::unique_ptr<container_info_component> collect_container_info (std::string const & name)
|
||||
std::unique_ptr<container_info_component> collect_container_info (std::string const & name) const
|
||||
{
|
||||
nano::lock_guard<nano::mutex> guard{ mutex };
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include <nano/lib/thread_runner.hpp>
|
||||
#include <nano/lib/utility.hpp>
|
||||
#include <nano/nano_node/daemon.hpp>
|
||||
#include <nano/node/active_transactions.hpp>
|
||||
#include <nano/node/cli.hpp>
|
||||
#include <nano/node/daemonconfig.hpp>
|
||||
#include <nano/node/ipc/ipc_server.hpp>
|
||||
|
|
|
@ -75,7 +75,9 @@ add_library(
|
|||
distributed_work_factory.cpp
|
||||
election.hpp
|
||||
election.cpp
|
||||
election_behavior.hpp
|
||||
election_insertion_result.hpp
|
||||
election_status.hpp
|
||||
epoch_upgrader.hpp
|
||||
epoch_upgrader.cpp
|
||||
ipc/action_handler.hpp
|
||||
|
@ -96,6 +98,8 @@ add_library(
|
|||
json_handler.cpp
|
||||
local_block_broadcaster.cpp
|
||||
local_block_broadcaster.hpp
|
||||
local_vote_history.cpp
|
||||
local_vote_history.hpp
|
||||
make_store.hpp
|
||||
make_store.cpp
|
||||
network.hpp
|
||||
|
@ -162,10 +166,13 @@ add_library(
|
|||
unchecked_map.hpp
|
||||
vote_cache.hpp
|
||||
vote_cache.cpp
|
||||
vote_generator.hpp
|
||||
vote_generator.cpp
|
||||
vote_processor.hpp
|
||||
vote_processor.cpp
|
||||
voting.hpp
|
||||
voting.cpp
|
||||
vote_spacing.hpp
|
||||
vote_spacing.cpp
|
||||
vote_with_weight_info.hpp
|
||||
wallet.hpp
|
||||
wallet.cpp
|
||||
websocket.hpp
|
||||
|
|
|
@ -1,9 +1,10 @@
|
|||
#pragma once
|
||||
|
||||
#include <nano/lib/numbers.hpp>
|
||||
#include <nano/node/election.hpp>
|
||||
#include <nano/node/election_behavior.hpp>
|
||||
#include <nano/node/election_insertion_result.hpp>
|
||||
#include <nano/node/voting.hpp>
|
||||
#include <nano/node/election_status.hpp>
|
||||
#include <nano/node/vote_with_weight_info.hpp>
|
||||
#include <nano/secure/common.hpp>
|
||||
|
||||
#include <boost/multi_index/hashed_index.hpp>
|
||||
|
@ -15,6 +16,7 @@
|
|||
#include <condition_variable>
|
||||
#include <deque>
|
||||
#include <memory>
|
||||
#include <thread>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace mi = boost::multi_index;
|
||||
|
@ -30,7 +32,14 @@ class election;
|
|||
class vote;
|
||||
class confirmation_height_processor;
|
||||
class stats;
|
||||
}
|
||||
namespace nano::store
|
||||
{
|
||||
class read_transaction;
|
||||
}
|
||||
|
||||
namespace nano
|
||||
{
|
||||
class recently_confirmed_cache final
|
||||
{
|
||||
public:
|
||||
|
@ -51,8 +60,9 @@ public: // Tests
|
|||
|
||||
private:
|
||||
// clang-format off
|
||||
class tag_root {};
|
||||
class tag_hash {};
|
||||
class tag_root {};
|
||||
class tag_sequence {};
|
||||
|
||||
using ordered_recent_confirmations = boost::multi_index_container<entry_t,
|
||||
mi::indexed_by<
|
||||
|
|
|
@ -2,7 +2,9 @@
|
|||
#include <nano/node/backlog_population.hpp>
|
||||
#include <nano/node/nodeconfig.hpp>
|
||||
#include <nano/node/scheduler/priority.hpp>
|
||||
#include <nano/store/account.hpp>
|
||||
#include <nano/store/component.hpp>
|
||||
#include <nano/store/confirmation_height.hpp>
|
||||
|
||||
nano::backlog_population::backlog_population (const config & config_a, nano::store::component & store_a, nano::stats & stats_a) :
|
||||
config_m{ config_a },
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
#include <nano/lib/blocks.hpp>
|
||||
#include <nano/lib/threading.hpp>
|
||||
#include <nano/lib/timer.hpp>
|
||||
#include <nano/node/active_transactions.hpp>
|
||||
#include <nano/node/blockprocessor.hpp>
|
||||
#include <nano/node/local_vote_history.hpp>
|
||||
#include <nano/node/node.hpp>
|
||||
#include <nano/secure/ledger.hpp>
|
||||
#include <nano/store/component.hpp>
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
#include <nano/lib/blocks.hpp>
|
||||
#include <nano/node/active_transactions.hpp>
|
||||
#include <nano/node/confirmation_solicitor.hpp>
|
||||
#include <nano/node/election.hpp>
|
||||
#include <nano/node/local_vote_history.hpp>
|
||||
#include <nano/node/network.hpp>
|
||||
#include <nano/node/node.hpp>
|
||||
#include <nano/node/vote_generator.hpp>
|
||||
#include <nano/secure/ledger.hpp>
|
||||
|
||||
#include <boost/format.hpp>
|
||||
|
|
|
@ -2,8 +2,10 @@
|
|||
|
||||
#include <nano/lib/id_dispenser.hpp>
|
||||
#include <nano/lib/logging.hpp>
|
||||
#include <nano/secure/common.hpp>
|
||||
#include <nano/store/component.hpp>
|
||||
#include <nano/lib/stats_enums.hpp>
|
||||
#include <nano/node/election_behavior.hpp>
|
||||
#include <nano/node/election_status.hpp>
|
||||
#include <nano/node/vote_with_weight_info.hpp>
|
||||
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
|
@ -11,6 +13,7 @@
|
|||
|
||||
namespace nano
|
||||
{
|
||||
class block;
|
||||
class channel;
|
||||
class confirmation_solicitor;
|
||||
class inactive_cache_information;
|
||||
|
@ -24,34 +27,6 @@ public:
|
|||
nano::block_hash hash;
|
||||
};
|
||||
|
||||
class vote_with_weight_info final
|
||||
{
|
||||
public:
|
||||
nano::account representative;
|
||||
std::chrono::steady_clock::time_point time;
|
||||
uint64_t timestamp;
|
||||
nano::block_hash hash;
|
||||
nano::uint128_t weight;
|
||||
};
|
||||
|
||||
enum class election_behavior
|
||||
{
|
||||
normal,
|
||||
/**
|
||||
* Hinted elections:
|
||||
* - shorter timespan
|
||||
* - limited space inside AEC
|
||||
*/
|
||||
hinted,
|
||||
/**
|
||||
* Optimistic elections:
|
||||
* - shorter timespan
|
||||
* - limited space inside AEC
|
||||
* - more frequent confirmation requests
|
||||
*/
|
||||
optimistic,
|
||||
};
|
||||
|
||||
nano::stat::detail to_stat_detail (nano::election_behavior);
|
||||
|
||||
// map of vote weight per block, ordered greater first
|
||||
|
|
22
nano/node/election_behavior.hpp
Normal file
22
nano/node/election_behavior.hpp
Normal file
|
@ -0,0 +1,22 @@
|
|||
#pragma once
|
||||
|
||||
namespace nano
|
||||
{
|
||||
enum class election_behavior
|
||||
{
|
||||
normal,
|
||||
/**
|
||||
* Hinted elections:
|
||||
* - shorter timespan
|
||||
* - limited space inside AEC
|
||||
*/
|
||||
hinted,
|
||||
/**
|
||||
* Optimistic elections:
|
||||
* - shorter timespan
|
||||
* - limited space inside AEC
|
||||
* - more frequent confirmation requests
|
||||
*/
|
||||
optimistic,
|
||||
};
|
||||
}
|
39
nano/node/election_status.hpp
Normal file
39
nano/node/election_status.hpp
Normal file
|
@ -0,0 +1,39 @@
|
|||
#pragma once
|
||||
|
||||
#include <nano/lib/numbers.hpp>
|
||||
|
||||
#include <chrono>
|
||||
#include <memory>
|
||||
|
||||
namespace nano
|
||||
{
|
||||
class block;
|
||||
}
|
||||
|
||||
namespace nano
|
||||
{
|
||||
/* Defines the possible states for an election to stop in */
|
||||
enum class election_status_type : uint8_t
|
||||
{
|
||||
ongoing = 0,
|
||||
active_confirmed_quorum = 1,
|
||||
active_confirmation_height = 2,
|
||||
inactive_confirmation_height = 3,
|
||||
stopped = 5
|
||||
};
|
||||
|
||||
/* Holds a summary of an election */
|
||||
class election_status final
|
||||
{
|
||||
public:
|
||||
std::shared_ptr<nano::block> winner;
|
||||
nano::amount tally{ 0 };
|
||||
nano::amount final_tally{ 0 };
|
||||
std::chrono::milliseconds election_end{ std::chrono::duration_cast<std::chrono::milliseconds> (std::chrono::system_clock::now ().time_since_epoch ()) };
|
||||
std::chrono::milliseconds election_duration{ std::chrono::duration_values<std::chrono::milliseconds>::zero () };
|
||||
unsigned confirmation_request_count{ 0 };
|
||||
unsigned block_count{ 0 };
|
||||
unsigned voter_count{ 0 };
|
||||
election_status_type type{ nano::election_status_type::inactive_confirmation_height };
|
||||
};
|
||||
}
|
|
@ -2,6 +2,7 @@
|
|||
#include <nano/lib/config.hpp>
|
||||
#include <nano/lib/json_error_response.hpp>
|
||||
#include <nano/lib/timer.hpp>
|
||||
#include <nano/node/active_transactions.hpp>
|
||||
#include <nano/node/bootstrap/bootstrap_lazy.hpp>
|
||||
#include <nano/node/bootstrap_ascending/service.hpp>
|
||||
#include <nano/node/common.hpp>
|
||||
|
|
115
nano/node/local_vote_history.cpp
Normal file
115
nano/node/local_vote_history.cpp
Normal file
|
@ -0,0 +1,115 @@
|
|||
#include <nano/node/local_vote_history.hpp>
|
||||
#include <nano/secure/common.hpp>
|
||||
#include <nano/secure/vote.hpp>
|
||||
|
||||
bool nano::local_vote_history::consistency_check (nano::root const & root_a) const
|
||||
{
|
||||
auto & history_by_root (history.get<tag_root> ());
|
||||
auto const range (history_by_root.equal_range (root_a));
|
||||
// All cached votes for a root must be for the same hash, this is actively enforced in local_vote_history::add
|
||||
auto consistent_same = std::all_of (range.first, range.second, [hash = range.first->hash] (auto const & info_a) { return info_a.hash == hash; });
|
||||
std::vector<nano::account> accounts;
|
||||
std::transform (range.first, range.second, std::back_inserter (accounts), [] (auto const & info_a) { return info_a.vote->account; });
|
||||
std::sort (accounts.begin (), accounts.end ());
|
||||
// All cached votes must be unique by account, this is actively enforced in local_vote_history::add
|
||||
auto consistent_unique = accounts.size () == std::unique (accounts.begin (), accounts.end ()) - accounts.begin ();
|
||||
auto result = consistent_same && consistent_unique;
|
||||
debug_assert (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
void nano::local_vote_history::add (nano::root const & root_a, nano::block_hash const & hash_a, std::shared_ptr<nano::vote> const & vote_a)
|
||||
{
|
||||
nano::lock_guard<nano::mutex> guard{ mutex };
|
||||
clean ();
|
||||
auto add_vote (true);
|
||||
auto & history_by_root (history.get<tag_root> ());
|
||||
// Erase any vote that is not for this hash, or duplicate by account, and if new timestamp is higher
|
||||
auto range (history_by_root.equal_range (root_a));
|
||||
for (auto i (range.first); i != range.second;)
|
||||
{
|
||||
if (i->hash != hash_a || (vote_a->account == i->vote->account && i->vote->timestamp () <= vote_a->timestamp ()))
|
||||
{
|
||||
i = history_by_root.erase (i);
|
||||
}
|
||||
else if (vote_a->account == i->vote->account && i->vote->timestamp () > vote_a->timestamp ())
|
||||
{
|
||||
add_vote = false;
|
||||
++i;
|
||||
}
|
||||
else
|
||||
{
|
||||
++i;
|
||||
}
|
||||
}
|
||||
// Do not add new vote to cache if representative account is same and timestamp is lower
|
||||
if (add_vote)
|
||||
{
|
||||
auto result (history_by_root.emplace (root_a, hash_a, vote_a));
|
||||
(void)result;
|
||||
debug_assert (result.second);
|
||||
}
|
||||
debug_assert (consistency_check (root_a));
|
||||
}
|
||||
|
||||
void nano::local_vote_history::erase (nano::root const & root_a)
|
||||
{
|
||||
nano::lock_guard<nano::mutex> guard{ mutex };
|
||||
auto & history_by_root (history.get<tag_root> ());
|
||||
auto range (history_by_root.equal_range (root_a));
|
||||
history_by_root.erase (range.first, range.second);
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<nano::vote>> nano::local_vote_history::votes (nano::root const & root_a) const
|
||||
{
|
||||
nano::lock_guard<nano::mutex> guard{ mutex };
|
||||
std::vector<std::shared_ptr<nano::vote>> result;
|
||||
auto range (history.get<tag_root> ().equal_range (root_a));
|
||||
std::transform (range.first, range.second, std::back_inserter (result), [] (auto const & entry) { return entry.vote; });
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<nano::vote>> nano::local_vote_history::votes (nano::root const & root_a, nano::block_hash const & hash_a, bool const is_final_a) const
|
||||
{
|
||||
nano::lock_guard<nano::mutex> guard{ mutex };
|
||||
std::vector<std::shared_ptr<nano::vote>> result;
|
||||
auto range (history.get<tag_root> ().equal_range (root_a));
|
||||
// clang-format off
|
||||
nano::transform_if (range.first, range.second, std::back_inserter (result),
|
||||
[&hash_a, is_final_a](auto const & entry) { return entry.hash == hash_a && (!is_final_a || entry.vote->timestamp () == std::numeric_limits<uint64_t>::max ()); },
|
||||
[](auto const & entry) { return entry.vote; });
|
||||
// clang-format on
|
||||
return result;
|
||||
}
|
||||
|
||||
bool nano::local_vote_history::exists (nano::root const & root_a) const
|
||||
{
|
||||
nano::lock_guard<nano::mutex> guard{ mutex };
|
||||
return history.get<tag_root> ().find (root_a) != history.get<tag_root> ().end ();
|
||||
}
|
||||
|
||||
void nano::local_vote_history::clean ()
|
||||
{
|
||||
debug_assert (constants.max_cache > 0);
|
||||
auto & history_by_sequence (history.get<tag_sequence> ());
|
||||
while (history_by_sequence.size () > constants.max_cache)
|
||||
{
|
||||
history_by_sequence.erase (history_by_sequence.begin ());
|
||||
}
|
||||
}
|
||||
|
||||
std::size_t nano::local_vote_history::size () const
|
||||
{
|
||||
nano::lock_guard<nano::mutex> guard{ mutex };
|
||||
return history.size ();
|
||||
}
|
||||
|
||||
std::unique_ptr<nano::container_info_component> nano::local_vote_history::collect_container_info (std::string const & name) const
|
||||
{
|
||||
std::size_t history_count = size ();
|
||||
auto sizeof_element = sizeof (decltype (history)::value_type);
|
||||
auto composite = std::make_unique<container_info_composite> (name);
|
||||
/* This does not currently loop over each element inside the cache to get the sizes of the votes inside history*/
|
||||
composite->add_component (std::make_unique<container_info_leaf> (container_info{ "history", history_count, sizeof_element }));
|
||||
return composite;
|
||||
}
|
74
nano/node/local_vote_history.hpp
Normal file
74
nano/node/local_vote_history.hpp
Normal file
|
@ -0,0 +1,74 @@
|
|||
#pragma once
|
||||
|
||||
#include <nano/lib/locks.hpp>
|
||||
#include <nano/lib/numbers.hpp>
|
||||
|
||||
#include <boost/multi_index/hashed_index.hpp>
|
||||
#include <boost/multi_index/member.hpp>
|
||||
#include <boost/multi_index/sequenced_index.hpp>
|
||||
#include <boost/multi_index_container.hpp>
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
namespace mi = boost::multi_index;
|
||||
|
||||
namespace nano
|
||||
{
|
||||
class container_info_component;
|
||||
class vote;
|
||||
class voting_constants;
|
||||
}
|
||||
|
||||
namespace nano
|
||||
{
|
||||
class local_vote_history final
|
||||
{
|
||||
class local_vote final
|
||||
{
|
||||
public:
|
||||
local_vote (nano::root const & root_a, nano::block_hash const & hash_a, std::shared_ptr<nano::vote> const & vote_a) :
|
||||
root (root_a),
|
||||
hash (hash_a),
|
||||
vote (vote_a)
|
||||
{
|
||||
}
|
||||
nano::root root;
|
||||
nano::block_hash hash;
|
||||
std::shared_ptr<nano::vote> vote;
|
||||
};
|
||||
|
||||
public:
|
||||
local_vote_history (nano::voting_constants const & constants) :
|
||||
constants{ constants }
|
||||
{
|
||||
}
|
||||
void add (nano::root const & root_a, nano::block_hash const & hash_a, std::shared_ptr<nano::vote> const & vote_a);
|
||||
void erase (nano::root const & root_a);
|
||||
|
||||
std::vector<std::shared_ptr<nano::vote>> votes (nano::root const & root_a, nano::block_hash const & hash_a, bool const is_final_a = false) const;
|
||||
bool exists (nano::root const &) const;
|
||||
std::size_t size () const;
|
||||
|
||||
std::unique_ptr<container_info_component> collect_container_info (std::string const & name) const;
|
||||
|
||||
private:
|
||||
// clang-format off
|
||||
boost::multi_index_container<local_vote,
|
||||
mi::indexed_by<
|
||||
mi::hashed_non_unique<mi::tag<class tag_root>,
|
||||
mi::member<local_vote, nano::root, &local_vote::root>>,
|
||||
mi::sequenced<mi::tag<class tag_sequence>>>>
|
||||
history;
|
||||
// clang-format on
|
||||
|
||||
nano::voting_constants const & constants;
|
||||
void clean ();
|
||||
std::vector<std::shared_ptr<nano::vote>> votes (nano::root const & root_a) const;
|
||||
// Only used in Debug
|
||||
bool consistency_check (nano::root const &) const;
|
||||
mutable nano::mutex mutex;
|
||||
|
||||
friend class local_vote_history_basic_Test;
|
||||
};
|
||||
}
|
|
@ -2,8 +2,11 @@
|
|||
#include <nano/lib/stream.hpp>
|
||||
#include <nano/lib/tomlconfig.hpp>
|
||||
#include <nano/lib/utility.hpp>
|
||||
#include <nano/node/active_transactions.hpp>
|
||||
#include <nano/node/common.hpp>
|
||||
#include <nano/node/daemonconfig.hpp>
|
||||
#include <nano/node/election_status.hpp>
|
||||
#include <nano/node/local_vote_history.hpp>
|
||||
#include <nano/node/make_store.hpp>
|
||||
#include <nano/node/node.hpp>
|
||||
#include <nano/node/scheduler/component.hpp>
|
||||
|
@ -12,6 +15,7 @@
|
|||
#include <nano/node/scheduler/optimistic.hpp>
|
||||
#include <nano/node/scheduler/priority.hpp>
|
||||
#include <nano/node/telemetry.hpp>
|
||||
#include <nano/node/vote_generator.hpp>
|
||||
#include <nano/node/websocket.hpp>
|
||||
#include <nano/secure/ledger.hpp>
|
||||
#include <nano/store/component.hpp>
|
||||
|
@ -165,19 +169,23 @@ nano::node::node (std::shared_ptr<boost::asio::io_context> io_ctx_a, std::filesy
|
|||
tcp_listener{ std::make_shared<nano::transport::tcp_listener> (network.port, *this, config.tcp_incoming_connections_max) },
|
||||
application_path (application_path_a),
|
||||
port_mapping (*this),
|
||||
block_processor (*this, write_database_queue),
|
||||
confirmation_height_processor (ledger, write_database_queue, config.conf_height_processor_batch_min_time, logger, node_initialized_latch, flags.confirmation_height_processor_mode),
|
||||
active_impl{ std::make_unique<nano::active_transactions> (*this, confirmation_height_processor, block_processor) },
|
||||
active{ *active_impl },
|
||||
rep_crawler (config.rep_crawler, *this),
|
||||
rep_tiers{ ledger, network_params, online_reps, stats, logger },
|
||||
vote_processor{ active, observers, stats, config, flags, logger, online_reps, rep_crawler, ledger, network_params, rep_tiers },
|
||||
warmed_up (0),
|
||||
block_processor (*this, write_database_queue),
|
||||
online_reps (ledger, config),
|
||||
history{ config.network_params.voting },
|
||||
history_impl{ std::make_unique<nano::local_vote_history> (config.network_params.voting) },
|
||||
history{ *history_impl },
|
||||
vote_uniquer{},
|
||||
confirmation_height_processor (ledger, write_database_queue, config.conf_height_processor_batch_min_time, logger, node_initialized_latch, flags.confirmation_height_processor_mode),
|
||||
vote_cache{ config.vote_cache, stats },
|
||||
generator{ config, *this, ledger, wallets, vote_processor, history, network, stats, logger, /* non-final */ false },
|
||||
final_generator{ config, *this, ledger, wallets, vote_processor, history, network, stats, logger, /* final */ true },
|
||||
active{ *this, confirmation_height_processor, block_processor },
|
||||
generator_impl{ std::make_unique<nano::vote_generator> (config, *this, ledger, wallets, vote_processor, history, network, stats, logger, /* non-final */ false) },
|
||||
generator{ *generator_impl },
|
||||
final_generator_impl{ std::make_unique<nano::vote_generator> (config, *this, ledger, wallets, vote_processor, history, network, stats, logger, /* final */ true) },
|
||||
final_generator{ *final_generator_impl },
|
||||
scheduler_impl{ std::make_unique<nano::scheduler::component> (*this) },
|
||||
scheduler{ *scheduler_impl },
|
||||
aggregator (config, stats, generator, final_generator, history, ledger, wallets, active),
|
||||
|
@ -537,7 +545,7 @@ std::unique_ptr<nano::container_info_component> nano::collect_container_info (no
|
|||
composite->add_component (node.rep_crawler.collect_container_info ("rep_crawler"));
|
||||
composite->add_component (node.block_processor.collect_container_info ("block_processor"));
|
||||
composite->add_component (collect_container_info (node.online_reps, "online_reps"));
|
||||
composite->add_component (collect_container_info (node.history, "history"));
|
||||
composite->add_component (node.history.collect_container_info ("history"));
|
||||
composite->add_component (node.block_uniquer.collect_container_info ("block_uniquer"));
|
||||
composite->add_component (node.vote_uniquer.collect_container_info ("vote_uniquer"));
|
||||
composite->add_component (collect_container_info (node.confirmation_height_processor, "confirmation_height_processor"));
|
||||
|
@ -545,8 +553,8 @@ std::unique_ptr<nano::container_info_component> nano::collect_container_info (no
|
|||
composite->add_component (collect_container_info (node.aggregator, "request_aggregator"));
|
||||
composite->add_component (node.scheduler.collect_container_info ("election_scheduler"));
|
||||
composite->add_component (node.vote_cache.collect_container_info ("vote_cache"));
|
||||
composite->add_component (collect_container_info (node.generator, "vote_generator"));
|
||||
composite->add_component (collect_container_info (node.final_generator, "vote_generator_final"));
|
||||
composite->add_component (node.generator.collect_container_info ("vote_generator"));
|
||||
composite->add_component (node.final_generator.collect_container_info ("vote_generator_final"));
|
||||
composite->add_component (node.ascendboot.collect_container_info ("bootstrap_ascending"));
|
||||
composite->add_component (node.unchecked.collect_container_info ("unchecked"));
|
||||
composite->add_component (node.local_block_broadcaster.collect_container_info ("local_block_broadcaster"));
|
||||
|
|
|
@ -6,7 +6,6 @@
|
|||
#include <nano/lib/stats.hpp>
|
||||
#include <nano/lib/thread_pool.hpp>
|
||||
#include <nano/lib/work.hpp>
|
||||
#include <nano/node/active_transactions.hpp>
|
||||
#include <nano/node/backlog_population.hpp>
|
||||
#include <nano/node/bandwidth_limiter.hpp>
|
||||
#include <nano/node/blockprocessor.hpp>
|
||||
|
@ -16,7 +15,6 @@
|
|||
#include <nano/node/bootstrap_ascending/service.hpp>
|
||||
#include <nano/node/confirmation_height_processor.hpp>
|
||||
#include <nano/node/distributed_work_factory.hpp>
|
||||
#include <nano/node/election.hpp>
|
||||
#include <nano/node/epoch_upgrader.hpp>
|
||||
#include <nano/node/local_block_broadcaster.hpp>
|
||||
#include <nano/node/network.hpp>
|
||||
|
@ -48,6 +46,7 @@
|
|||
|
||||
namespace nano
|
||||
{
|
||||
class active_transactions;
|
||||
namespace rocksdb
|
||||
{
|
||||
} // Declare a namespace rocksdb inside nano so all references to the rocksdb library need to be globally scoped e.g. ::rocksdb::Slice
|
||||
|
@ -161,20 +160,24 @@ public:
|
|||
std::filesystem::path application_path;
|
||||
nano::node_observers observers;
|
||||
nano::port_mapping port_mapping;
|
||||
nano::block_processor block_processor;
|
||||
nano::confirmation_height_processor confirmation_height_processor;
|
||||
std::unique_ptr<nano::active_transactions> active_impl;
|
||||
nano::active_transactions & active;
|
||||
nano::online_reps online_reps;
|
||||
nano::rep_crawler rep_crawler;
|
||||
nano::rep_tiers rep_tiers;
|
||||
nano::vote_processor vote_processor;
|
||||
unsigned warmed_up;
|
||||
nano::block_processor block_processor;
|
||||
nano::local_vote_history history;
|
||||
std::unique_ptr<nano::local_vote_history> history_impl;
|
||||
nano::local_vote_history & history;
|
||||
nano::block_uniquer block_uniquer;
|
||||
nano::vote_uniquer vote_uniquer;
|
||||
nano::confirmation_height_processor confirmation_height_processor;
|
||||
nano::vote_cache vote_cache;
|
||||
nano::vote_generator generator;
|
||||
nano::vote_generator final_generator;
|
||||
nano::active_transactions active;
|
||||
std::unique_ptr<nano::vote_generator> generator_impl;
|
||||
nano::vote_generator & generator;
|
||||
std::unique_ptr<nano::vote_generator> final_generator_impl;
|
||||
nano::vote_generator & final_generator;
|
||||
|
||||
private: // Placed here to maintain initialization order
|
||||
std::unique_ptr<nano::scheduler::component> scheduler_impl;
|
||||
|
|
|
@ -2,12 +2,21 @@
|
|||
|
||||
#include <nano/lib/numbers.hpp>
|
||||
#include <nano/lib/utility.hpp>
|
||||
#include <nano/node/active_transactions.hpp>
|
||||
#include <nano/node/transport/transport.hpp>
|
||||
#include <nano/node/vote_with_weight_info.hpp>
|
||||
|
||||
namespace nano
|
||||
{
|
||||
class election_status;
|
||||
class telemetry;
|
||||
}
|
||||
namespace nano::transport
|
||||
{
|
||||
class channel;
|
||||
}
|
||||
|
||||
namespace nano
|
||||
{
|
||||
class node_observers final
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#include <nano/node/active_transactions.hpp>
|
||||
#include <nano/node/node.hpp>
|
||||
#include <nano/node/repcrawler.hpp>
|
||||
#include <nano/secure/ledger.hpp>
|
||||
|
|
|
@ -2,10 +2,11 @@
|
|||
#include <nano/lib/stats.hpp>
|
||||
#include <nano/node/active_transactions.hpp>
|
||||
#include <nano/node/common.hpp>
|
||||
#include <nano/node/local_vote_history.hpp>
|
||||
#include <nano/node/network.hpp>
|
||||
#include <nano/node/nodeconfig.hpp>
|
||||
#include <nano/node/request_aggregator.hpp>
|
||||
#include <nano/node/voting.hpp>
|
||||
#include <nano/node/vote_generator.hpp>
|
||||
#include <nano/node/wallet.hpp>
|
||||
#include <nano/secure/ledger.hpp>
|
||||
#include <nano/store/component.hpp>
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#include <nano/lib/stats.hpp>
|
||||
#include <nano/lib/tomlconfig.hpp>
|
||||
#include <nano/node/active_transactions.hpp>
|
||||
#include <nano/node/election_behavior.hpp>
|
||||
#include <nano/node/node.hpp>
|
||||
#include <nano/node/scheduler/hinted.hpp>
|
||||
#include <nano/secure/ledger.hpp>
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
#include <nano/node/active_transactions.hpp>
|
||||
#include <nano/node/election.hpp>
|
||||
#include <nano/node/node.hpp>
|
||||
#include <nano/node/scheduler/manual.hpp>
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
#pragma once
|
||||
#include <nano/lib/locks.hpp>
|
||||
#include <nano/lib/numbers.hpp>
|
||||
#include <nano/node/active_transactions.hpp>
|
||||
#include <nano/node/election_behavior.hpp>
|
||||
|
||||
#include <boost/optional.hpp>
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include <nano/lib/blocks.hpp>
|
||||
#include <nano/lib/stats.hpp>
|
||||
#include <nano/lib/tomlconfig.hpp>
|
||||
#include <nano/node/active_transactions.hpp>
|
||||
#include <nano/node/election_behavior.hpp>
|
||||
#include <nano/node/node.hpp>
|
||||
#include <nano/node/scheduler/optimistic.hpp>
|
||||
#include <nano/secure/ledger.hpp>
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
#include <nano/lib/blocks.hpp>
|
||||
#include <nano/node/active_transactions.hpp>
|
||||
#include <nano/node/election.hpp>
|
||||
#include <nano/node/node.hpp>
|
||||
#include <nano/node/scheduler/buckets.hpp>
|
||||
#include <nano/node/scheduler/priority.hpp>
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <nano/lib/numbers.hpp>
|
||||
#include <nano/node/active_transactions.hpp>
|
||||
|
||||
#include <boost/optional.hpp>
|
||||
|
||||
|
@ -16,6 +15,11 @@ namespace nano
|
|||
class block;
|
||||
class container_info_component;
|
||||
class node;
|
||||
class stats;
|
||||
}
|
||||
namespace nano::store
|
||||
{
|
||||
class transaction;
|
||||
}
|
||||
|
||||
namespace nano::scheduler
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include <nano/lib/tomlconfig.hpp>
|
||||
#include <nano/node/election.hpp>
|
||||
#include <nano/node/node.hpp>
|
||||
#include <nano/node/vote_cache.hpp>
|
||||
|
||||
|
@ -280,4 +281,4 @@ nano::error nano::vote_cache_config::deserialize (nano::tomlconfig & toml)
|
|||
age_cutoff = std::chrono::seconds{ age_cutoff_l };
|
||||
|
||||
return toml.get_error ();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,167 +1,19 @@
|
|||
#include <nano/lib/blocks.hpp>
|
||||
#include <nano/lib/stats.hpp>
|
||||
#include <nano/lib/utility.hpp>
|
||||
#include <nano/node/local_vote_history.hpp>
|
||||
#include <nano/node/network.hpp>
|
||||
#include <nano/node/nodeconfig.hpp>
|
||||
#include <nano/node/transport/inproc.hpp>
|
||||
#include <nano/node/vote_generator.hpp>
|
||||
#include <nano/node/vote_processor.hpp>
|
||||
#include <nano/node/voting.hpp>
|
||||
#include <nano/node/vote_spacing.hpp>
|
||||
#include <nano/node/wallet.hpp>
|
||||
#include <nano/secure/ledger.hpp>
|
||||
#include <nano/store/component.hpp>
|
||||
|
||||
#include <chrono>
|
||||
|
||||
void nano::vote_spacing::trim ()
|
||||
{
|
||||
recent.get<tag_time> ().erase (recent.get<tag_time> ().begin (), recent.get<tag_time> ().upper_bound (std::chrono::steady_clock::now () - delay));
|
||||
}
|
||||
|
||||
bool nano::vote_spacing::votable (nano::root const & root_a, nano::block_hash const & hash_a) const
|
||||
{
|
||||
bool result = true;
|
||||
for (auto range = recent.get<tag_root> ().equal_range (root_a); result && range.first != range.second; ++range.first)
|
||||
{
|
||||
auto & item = *range.first;
|
||||
result = hash_a == item.hash || item.time < std::chrono::steady_clock::now () - delay;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void nano::vote_spacing::flag (nano::root const & root_a, nano::block_hash const & hash_a)
|
||||
{
|
||||
trim ();
|
||||
auto now = std::chrono::steady_clock::now ();
|
||||
auto existing = recent.get<tag_root> ().find (root_a);
|
||||
if (existing != recent.end ())
|
||||
{
|
||||
recent.get<tag_root> ().modify (existing, [now] (entry & entry) {
|
||||
entry.time = now;
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
recent.insert ({ root_a, now, hash_a });
|
||||
}
|
||||
}
|
||||
|
||||
std::size_t nano::vote_spacing::size () const
|
||||
{
|
||||
return recent.size ();
|
||||
}
|
||||
|
||||
bool nano::local_vote_history::consistency_check (nano::root const & root_a) const
|
||||
{
|
||||
auto & history_by_root (history.get<tag_root> ());
|
||||
auto const range (history_by_root.equal_range (root_a));
|
||||
// All cached votes for a root must be for the same hash, this is actively enforced in local_vote_history::add
|
||||
auto consistent_same = std::all_of (range.first, range.second, [hash = range.first->hash] (auto const & info_a) { return info_a.hash == hash; });
|
||||
std::vector<nano::account> accounts;
|
||||
std::transform (range.first, range.second, std::back_inserter (accounts), [] (auto const & info_a) { return info_a.vote->account; });
|
||||
std::sort (accounts.begin (), accounts.end ());
|
||||
// All cached votes must be unique by account, this is actively enforced in local_vote_history::add
|
||||
auto consistent_unique = accounts.size () == std::unique (accounts.begin (), accounts.end ()) - accounts.begin ();
|
||||
auto result = consistent_same && consistent_unique;
|
||||
debug_assert (result);
|
||||
return result;
|
||||
}
|
||||
|
||||
void nano::local_vote_history::add (nano::root const & root_a, nano::block_hash const & hash_a, std::shared_ptr<nano::vote> const & vote_a)
|
||||
{
|
||||
nano::lock_guard<nano::mutex> guard{ mutex };
|
||||
clean ();
|
||||
auto add_vote (true);
|
||||
auto & history_by_root (history.get<tag_root> ());
|
||||
// Erase any vote that is not for this hash, or duplicate by account, and if new timestamp is higher
|
||||
auto range (history_by_root.equal_range (root_a));
|
||||
for (auto i (range.first); i != range.second;)
|
||||
{
|
||||
if (i->hash != hash_a || (vote_a->account == i->vote->account && i->vote->timestamp () <= vote_a->timestamp ()))
|
||||
{
|
||||
i = history_by_root.erase (i);
|
||||
}
|
||||
else if (vote_a->account == i->vote->account && i->vote->timestamp () > vote_a->timestamp ())
|
||||
{
|
||||
add_vote = false;
|
||||
++i;
|
||||
}
|
||||
else
|
||||
{
|
||||
++i;
|
||||
}
|
||||
}
|
||||
// Do not add new vote to cache if representative account is same and timestamp is lower
|
||||
if (add_vote)
|
||||
{
|
||||
auto result (history_by_root.emplace (root_a, hash_a, vote_a));
|
||||
(void)result;
|
||||
debug_assert (result.second);
|
||||
}
|
||||
debug_assert (consistency_check (root_a));
|
||||
}
|
||||
|
||||
void nano::local_vote_history::erase (nano::root const & root_a)
|
||||
{
|
||||
nano::lock_guard<nano::mutex> guard{ mutex };
|
||||
auto & history_by_root (history.get<tag_root> ());
|
||||
auto range (history_by_root.equal_range (root_a));
|
||||
history_by_root.erase (range.first, range.second);
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<nano::vote>> nano::local_vote_history::votes (nano::root const & root_a) const
|
||||
{
|
||||
nano::lock_guard<nano::mutex> guard{ mutex };
|
||||
std::vector<std::shared_ptr<nano::vote>> result;
|
||||
auto range (history.get<tag_root> ().equal_range (root_a));
|
||||
std::transform (range.first, range.second, std::back_inserter (result), [] (auto const & entry) { return entry.vote; });
|
||||
return result;
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<nano::vote>> nano::local_vote_history::votes (nano::root const & root_a, nano::block_hash const & hash_a, bool const is_final_a) const
|
||||
{
|
||||
nano::lock_guard<nano::mutex> guard{ mutex };
|
||||
std::vector<std::shared_ptr<nano::vote>> result;
|
||||
auto range (history.get<tag_root> ().equal_range (root_a));
|
||||
// clang-format off
|
||||
nano::transform_if (range.first, range.second, std::back_inserter (result),
|
||||
[&hash_a, is_final_a](auto const & entry) { return entry.hash == hash_a && (!is_final_a || entry.vote->timestamp () == std::numeric_limits<uint64_t>::max ()); },
|
||||
[](auto const & entry) { return entry.vote; });
|
||||
// clang-format on
|
||||
return result;
|
||||
}
|
||||
|
||||
bool nano::local_vote_history::exists (nano::root const & root_a) const
|
||||
{
|
||||
nano::lock_guard<nano::mutex> guard{ mutex };
|
||||
return history.get<tag_root> ().find (root_a) != history.get<tag_root> ().end ();
|
||||
}
|
||||
|
||||
void nano::local_vote_history::clean ()
|
||||
{
|
||||
debug_assert (constants.max_cache > 0);
|
||||
auto & history_by_sequence (history.get<tag_sequence> ());
|
||||
while (history_by_sequence.size () > constants.max_cache)
|
||||
{
|
||||
history_by_sequence.erase (history_by_sequence.begin ());
|
||||
}
|
||||
}
|
||||
|
||||
std::size_t nano::local_vote_history::size () const
|
||||
{
|
||||
nano::lock_guard<nano::mutex> guard{ mutex };
|
||||
return history.size ();
|
||||
}
|
||||
|
||||
std::unique_ptr<nano::container_info_component> nano::collect_container_info (nano::local_vote_history & history, std::string const & name)
|
||||
{
|
||||
std::size_t history_count = history.size ();
|
||||
auto sizeof_element = sizeof (decltype (history.history)::value_type);
|
||||
auto composite = std::make_unique<container_info_composite> (name);
|
||||
/* This does not currently loop over each element inside the cache to get the sizes of the votes inside history*/
|
||||
composite->add_component (std::make_unique<container_info_leaf> (container_info{ "history", history_count, sizeof_element }));
|
||||
return composite;
|
||||
}
|
||||
|
||||
nano::vote_generator::vote_generator (nano::node_config const & config_a, nano::node & node_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::stats & stats_a, nano::logger & logger_a, bool is_final_a) :
|
||||
config (config_a),
|
||||
node (node_a),
|
||||
|
@ -169,7 +21,8 @@ nano::vote_generator::vote_generator (nano::node_config const & config_a, nano::
|
|||
wallets (wallets_a),
|
||||
vote_processor (vote_processor_a),
|
||||
history (history_a),
|
||||
spacing{ config_a.network_params.voting.delay },
|
||||
spacing_impl{ std::make_unique<nano::vote_spacing> (config_a.network_params.voting.delay) },
|
||||
spacing{ *spacing_impl },
|
||||
network (network_a),
|
||||
stats (stats_a),
|
||||
logger (logger_a),
|
||||
|
@ -429,20 +282,20 @@ void nano::vote_generator::run ()
|
|||
}
|
||||
}
|
||||
|
||||
std::unique_ptr<nano::container_info_component> nano::collect_container_info (nano::vote_generator & vote_generator, std::string const & name)
|
||||
std::unique_ptr<nano::container_info_component> nano::vote_generator::collect_container_info (std::string const & name) const
|
||||
{
|
||||
std::size_t candidates_count = 0;
|
||||
std::size_t requests_count = 0;
|
||||
{
|
||||
nano::lock_guard<nano::mutex> guard{ vote_generator.mutex };
|
||||
candidates_count = vote_generator.candidates.size ();
|
||||
requests_count = vote_generator.requests.size ();
|
||||
nano::lock_guard<nano::mutex> guard{ mutex };
|
||||
candidates_count = candidates.size ();
|
||||
requests_count = requests.size ();
|
||||
}
|
||||
auto sizeof_candidate_element = sizeof (decltype (vote_generator.candidates)::value_type);
|
||||
auto sizeof_request_element = sizeof (decltype (vote_generator.requests)::value_type);
|
||||
auto sizeof_candidate_element = sizeof (decltype (candidates)::value_type);
|
||||
auto sizeof_request_element = sizeof (decltype (requests)::value_type);
|
||||
auto composite = std::make_unique<container_info_composite> (name);
|
||||
composite->add_component (std::make_unique<container_info_leaf> (container_info{ "candidates", candidates_count, sizeof_candidate_element }));
|
||||
composite->add_component (std::make_unique<container_info_leaf> (container_info{ "requests", requests_count, sizeof_request_element }));
|
||||
composite->add_component (vote_generator.vote_generation_queue.collect_container_info ("vote_generation_queue"));
|
||||
composite->add_component (vote_generation_queue.collect_container_info ("vote_generation_queue"));
|
||||
return composite;
|
||||
}
|
|
@ -22,99 +22,23 @@ namespace mi = boost::multi_index;
|
|||
|
||||
namespace nano
|
||||
{
|
||||
class node;
|
||||
class ledger;
|
||||
class local_vote_history;
|
||||
class network;
|
||||
class node;
|
||||
class node_config;
|
||||
class stats;
|
||||
class vote_processor;
|
||||
class vote_spacing;
|
||||
class wallets;
|
||||
namespace transport
|
||||
}
|
||||
namespace nano::transport
|
||||
{
|
||||
class channel;
|
||||
class channel;
|
||||
}
|
||||
|
||||
class vote_spacing final
|
||||
namespace nano
|
||||
{
|
||||
class entry
|
||||
{
|
||||
public:
|
||||
nano::root root;
|
||||
std::chrono::steady_clock::time_point time;
|
||||
nano::block_hash hash;
|
||||
};
|
||||
|
||||
boost::multi_index_container<entry,
|
||||
mi::indexed_by<
|
||||
mi::hashed_non_unique<mi::tag<class tag_root>,
|
||||
mi::member<entry, nano::root, &entry::root>>,
|
||||
mi::ordered_non_unique<mi::tag<class tag_time>,
|
||||
mi::member<entry, std::chrono::steady_clock::time_point, &entry::time>>>>
|
||||
recent;
|
||||
std::chrono::milliseconds const delay;
|
||||
void trim ();
|
||||
|
||||
public:
|
||||
vote_spacing (std::chrono::milliseconds const & delay) :
|
||||
delay{ delay }
|
||||
{
|
||||
}
|
||||
bool votable (nano::root const & root_a, nano::block_hash const & hash_a) const;
|
||||
void flag (nano::root const & root_a, nano::block_hash const & hash_a);
|
||||
std::size_t size () const;
|
||||
};
|
||||
|
||||
class local_vote_history final
|
||||
{
|
||||
class local_vote final
|
||||
{
|
||||
public:
|
||||
local_vote (nano::root const & root_a, nano::block_hash const & hash_a, std::shared_ptr<nano::vote> const & vote_a) :
|
||||
root (root_a),
|
||||
hash (hash_a),
|
||||
vote (vote_a)
|
||||
{
|
||||
}
|
||||
nano::root root;
|
||||
nano::block_hash hash;
|
||||
std::shared_ptr<nano::vote> vote;
|
||||
};
|
||||
|
||||
public:
|
||||
local_vote_history (nano::voting_constants const & constants) :
|
||||
constants{ constants }
|
||||
{
|
||||
}
|
||||
void add (nano::root const & root_a, nano::block_hash const & hash_a, std::shared_ptr<nano::vote> const & vote_a);
|
||||
void erase (nano::root const & root_a);
|
||||
|
||||
std::vector<std::shared_ptr<nano::vote>> votes (nano::root const & root_a, nano::block_hash const & hash_a, bool const is_final_a = false) const;
|
||||
bool exists (nano::root const &) const;
|
||||
std::size_t size () const;
|
||||
|
||||
private:
|
||||
// clang-format off
|
||||
boost::multi_index_container<local_vote,
|
||||
mi::indexed_by<
|
||||
mi::hashed_non_unique<mi::tag<class tag_root>,
|
||||
mi::member<local_vote, nano::root, &local_vote::root>>,
|
||||
mi::sequenced<mi::tag<class tag_sequence>>>>
|
||||
history;
|
||||
// clang-format on
|
||||
|
||||
nano::voting_constants const & constants;
|
||||
void clean ();
|
||||
std::vector<std::shared_ptr<nano::vote>> votes (nano::root const & root_a) const;
|
||||
// Only used in Debug
|
||||
bool consistency_check (nano::root const &) const;
|
||||
mutable nano::mutex mutex;
|
||||
|
||||
friend std::unique_ptr<container_info_component> collect_container_info (local_vote_history & history, std::string const & name);
|
||||
friend class local_vote_history_basic_Test;
|
||||
};
|
||||
|
||||
std::unique_ptr<container_info_component> collect_container_info (local_vote_history & history, std::string const & name);
|
||||
|
||||
class vote_generator final
|
||||
{
|
||||
private:
|
||||
|
@ -135,6 +59,8 @@ public:
|
|||
void start ();
|
||||
void stop ();
|
||||
|
||||
std::unique_ptr<container_info_component> collect_container_info (std::string const & name) const;
|
||||
|
||||
private:
|
||||
void run ();
|
||||
void broadcast (nano::unique_lock<nano::mutex> &);
|
||||
|
@ -159,7 +85,8 @@ private: // Dependencies
|
|||
nano::wallets & wallets;
|
||||
nano::vote_processor & vote_processor;
|
||||
nano::local_vote_history & history;
|
||||
nano::vote_spacing spacing;
|
||||
std::unique_ptr<nano::vote_spacing> spacing_impl;
|
||||
nano::vote_spacing & spacing;
|
||||
nano::network & network;
|
||||
nano::stats & stats;
|
||||
nano::logger & logger;
|
||||
|
@ -176,9 +103,5 @@ private:
|
|||
std::deque<candidate_t> candidates;
|
||||
std::atomic<bool> stopped{ false };
|
||||
std::thread thread;
|
||||
|
||||
friend std::unique_ptr<container_info_component> collect_container_info (vote_generator & vote_generator, std::string const & name);
|
||||
};
|
||||
|
||||
std::unique_ptr<container_info_component> collect_container_info (vote_generator & generator, std::string const & name);
|
||||
}
|
39
nano/node/vote_spacing.cpp
Normal file
39
nano/node/vote_spacing.cpp
Normal file
|
@ -0,0 +1,39 @@
|
|||
#include <nano/node/vote_spacing.hpp>
|
||||
|
||||
void nano::vote_spacing::trim ()
|
||||
{
|
||||
recent.get<tag_time> ().erase (recent.get<tag_time> ().begin (), recent.get<tag_time> ().upper_bound (std::chrono::steady_clock::now () - delay));
|
||||
}
|
||||
|
||||
bool nano::vote_spacing::votable (nano::root const & root_a, nano::block_hash const & hash_a) const
|
||||
{
|
||||
bool result = true;
|
||||
for (auto range = recent.get<tag_root> ().equal_range (root_a); result && range.first != range.second; ++range.first)
|
||||
{
|
||||
auto & item = *range.first;
|
||||
result = hash_a == item.hash || item.time < std::chrono::steady_clock::now () - delay;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void nano::vote_spacing::flag (nano::root const & root_a, nano::block_hash const & hash_a)
|
||||
{
|
||||
trim ();
|
||||
auto now = std::chrono::steady_clock::now ();
|
||||
auto existing = recent.get<tag_root> ().find (root_a);
|
||||
if (existing != recent.end ())
|
||||
{
|
||||
recent.get<tag_root> ().modify (existing, [now] (entry & entry) {
|
||||
entry.time = now;
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
recent.insert ({ root_a, now, hash_a });
|
||||
}
|
||||
}
|
||||
|
||||
std::size_t nano::vote_spacing::size () const
|
||||
{
|
||||
return recent.size ();
|
||||
}
|
45
nano/node/vote_spacing.hpp
Normal file
45
nano/node/vote_spacing.hpp
Normal file
|
@ -0,0 +1,45 @@
|
|||
#pragma once
|
||||
|
||||
#include <nano/lib/numbers.hpp>
|
||||
|
||||
#include <boost/multi_index/hashed_index.hpp>
|
||||
#include <boost/multi_index/member.hpp>
|
||||
#include <boost/multi_index/ordered_index.hpp>
|
||||
#include <boost/multi_index_container.hpp>
|
||||
|
||||
#include <chrono>
|
||||
|
||||
namespace mi = boost::multi_index;
|
||||
|
||||
namespace nano
|
||||
{
|
||||
class vote_spacing final
|
||||
{
|
||||
class entry
|
||||
{
|
||||
public:
|
||||
nano::root root;
|
||||
std::chrono::steady_clock::time_point time;
|
||||
nano::block_hash hash;
|
||||
};
|
||||
|
||||
boost::multi_index_container<entry,
|
||||
mi::indexed_by<
|
||||
mi::hashed_non_unique<mi::tag<class tag_root>,
|
||||
mi::member<entry, nano::root, &entry::root>>,
|
||||
mi::ordered_non_unique<mi::tag<class tag_time>,
|
||||
mi::member<entry, std::chrono::steady_clock::time_point, &entry::time>>>>
|
||||
recent;
|
||||
std::chrono::milliseconds const delay;
|
||||
void trim ();
|
||||
|
||||
public:
|
||||
vote_spacing (std::chrono::milliseconds const & delay) :
|
||||
delay{ delay }
|
||||
{
|
||||
}
|
||||
bool votable (nano::root const & root_a, nano::block_hash const & hash_a) const;
|
||||
void flag (nano::root const & root_a, nano::block_hash const & hash_a);
|
||||
std::size_t size () const;
|
||||
};
|
||||
}
|
18
nano/node/vote_with_weight_info.hpp
Normal file
18
nano/node/vote_with_weight_info.hpp
Normal file
|
@ -0,0 +1,18 @@
|
|||
#pragma once
|
||||
|
||||
#include <nano/lib/numbers.hpp>
|
||||
|
||||
#include <chrono>
|
||||
|
||||
namespace nano
|
||||
{
|
||||
class vote_with_weight_info final
|
||||
{
|
||||
public:
|
||||
nano::account representative;
|
||||
std::chrono::steady_clock::time_point time;
|
||||
uint64_t timestamp;
|
||||
nano::block_hash hash;
|
||||
nano::uint128_t weight;
|
||||
};
|
||||
}
|
|
@ -5,6 +5,7 @@
|
|||
#include <nano/lib/logging.hpp>
|
||||
#include <nano/lib/tlsconfig.hpp>
|
||||
#include <nano/lib/work.hpp>
|
||||
#include <nano/node/election_status.hpp>
|
||||
#include <nano/node/node_observers.hpp>
|
||||
#include <nano/node/transport/channel.hpp>
|
||||
#include <nano/node/wallet.hpp>
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#include <nano/lib/numbers.hpp>
|
||||
#include <nano/lib/work.hpp>
|
||||
#include <nano/node/common.hpp>
|
||||
#include <nano/node/election.hpp>
|
||||
#include <nano/node/vote_with_weight_info.hpp>
|
||||
#include <nano/node/websocket_stream.hpp>
|
||||
#include <nano/node/websocketconfig.hpp>
|
||||
#include <nano/secure/common.hpp>
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#include <nano/lib/blocks.hpp>
|
||||
#include <nano/lib/config.hpp>
|
||||
#include <nano/node/election_status.hpp>
|
||||
#include <nano/node/vote_with_weight_info.hpp>
|
||||
#include <nano/qt/qt.hpp>
|
||||
#include <nano/secure/ledger.hpp>
|
||||
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
#include <nano/lib/rpcconfig.hpp>
|
||||
#include <nano/lib/thread_runner.hpp>
|
||||
#include <nano/lib/threading.hpp>
|
||||
#include <nano/node/active_transactions.hpp>
|
||||
#include <nano/node/election.hpp>
|
||||
#include <nano/node/ipc/ipc_server.hpp>
|
||||
#include <nano/node/json_handler.hpp>
|
||||
#include <nano/node/node_rpc_config.hpp>
|
||||
|
|
|
@ -73,14 +73,6 @@ struct hash<::nano::qualified_root>
|
|||
return std::hash<::nano::qualified_root> () (value_a);
|
||||
}
|
||||
};
|
||||
template <>
|
||||
struct hash<::nano::root>
|
||||
{
|
||||
size_t operator() (::nano::root const & value_a) const
|
||||
{
|
||||
return std::hash<::nano::root> () (value_a);
|
||||
}
|
||||
};
|
||||
}
|
||||
namespace nano
|
||||
{
|
||||
|
@ -345,30 +337,5 @@ enum class confirmation_height_mode
|
|||
bounded
|
||||
};
|
||||
|
||||
/* Defines the possible states for an election to stop in */
|
||||
enum class election_status_type : uint8_t
|
||||
{
|
||||
ongoing = 0,
|
||||
active_confirmed_quorum = 1,
|
||||
active_confirmation_height = 2,
|
||||
inactive_confirmation_height = 3,
|
||||
stopped = 5
|
||||
};
|
||||
|
||||
/* Holds a summary of an election */
|
||||
class election_status final
|
||||
{
|
||||
public:
|
||||
std::shared_ptr<nano::block> winner;
|
||||
nano::amount tally{ 0 };
|
||||
nano::amount final_tally{ 0 };
|
||||
std::chrono::milliseconds election_end{ std::chrono::duration_cast<std::chrono::milliseconds> (std::chrono::system_clock::now ().time_since_epoch ()) };
|
||||
std::chrono::milliseconds election_duration{ std::chrono::duration_values<std::chrono::milliseconds>::zero () };
|
||||
unsigned confirmation_request_count{ 0 };
|
||||
unsigned block_count{ 0 };
|
||||
unsigned voter_count{ 0 };
|
||||
election_status_type type{ nano::election_status_type::inactive_confirmation_height };
|
||||
};
|
||||
|
||||
nano::wallet_id random_wallet_id ();
|
||||
}
|
||||
|
|
|
@ -10,6 +10,11 @@
|
|||
|
||||
#include <vector>
|
||||
|
||||
namespace nano
|
||||
{
|
||||
class object_stream;
|
||||
}
|
||||
|
||||
namespace nano
|
||||
{
|
||||
class vote final
|
||||
|
@ -77,4 +82,4 @@ public: // Logging
|
|||
};
|
||||
|
||||
using vote_uniquer = nano::uniquer<nano::block_hash, nano::vote>;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include <nano/lib/blocks.hpp>
|
||||
#include <nano/lib/logging.hpp>
|
||||
#include <nano/lib/thread_runner.hpp>
|
||||
#include <nano/node/active_transactions.hpp>
|
||||
#include <nano/node/election.hpp>
|
||||
#include <nano/node/make_store.hpp>
|
||||
#include <nano/node/scheduler/component.hpp>
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include <nano/lib/blocks.hpp>
|
||||
#include <nano/node/active_transactions.hpp>
|
||||
#include <nano/test_common/rate_observer.hpp>
|
||||
#include <nano/test_common/system.hpp>
|
||||
#include <nano/test_common/testutil.hpp>
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <nano/lib/stats.hpp>
|
||||
#include <nano/lib/work.hpp>
|
||||
#include <nano/secure/ledger.hpp>
|
||||
|
||||
namespace nano
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include <nano/crypto_lib/random_pool.hpp>
|
||||
#include <nano/lib/blocks.hpp>
|
||||
#include <nano/node/active_transactions.hpp>
|
||||
#include <nano/node/common.hpp>
|
||||
#include <nano/secure/ledger.hpp>
|
||||
#include <nano/test_common/system.hpp>
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#include <nano/crypto_lib/random_pool.hpp>
|
||||
#include <nano/lib/blocks.hpp>
|
||||
#include <nano/node/active_transactions.hpp>
|
||||
#include <nano/node/election.hpp>
|
||||
#include <nano/node/scheduler/component.hpp>
|
||||
#include <nano/node/scheduler/manual.hpp>
|
||||
#include <nano/node/scheduler/priority.hpp>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue