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

Cleanup unused member functions in secure library and various other cleanups #1764

Merged
merged 3 commits into from Feb 22, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion nano/lib/blocks.cpp
Expand Up @@ -1588,7 +1588,7 @@ std::shared_ptr<nano::block> nano::block_uniquer::unique (std::shared_ptr<nano::
existing = block_a;
}
release_assert (std::numeric_limits<CryptoPP::word32>::max () > blocks.size ());
for (auto i (0); i < cleanup_count && blocks.size () > 0; ++i)
for (auto i (0); i < cleanup_count && !blocks.empty (); ++i)
{
auto random_offset (nano::random_pool::generate_word32 (0, static_cast<CryptoPP::word32> (blocks.size () - 1)));
auto existing (std::next (blocks.begin (), random_offset));
Expand Down
4 changes: 2 additions & 2 deletions nano/lib/numbers.cpp
Expand Up @@ -270,7 +270,7 @@ void nano::uint256_union::encode_dec (std::string & text) const

bool nano::uint256_union::decode_dec (std::string const & text)
{
auto error (text.size () > 78 || (text.size () > 1 && text[0] == '0') || (text.size () > 0 && text[0] == '-'));
auto error (text.size () > 78 || (text.size () > 1 && text.front () == '0') || (!text.empty () && text.front () == '-'));
if (!error)
{
std::stringstream stream (text);
Expand Down Expand Up @@ -540,7 +540,7 @@ void nano::uint128_union::encode_dec (std::string & text) const

bool nano::uint128_union::decode_dec (std::string const & text)
{
auto error (text.size () > 39 || (text.size () > 1 && text[0] == '0') || (text.size () > 0 && text[0] == '-'));
auto error (text.size () > 39 || (text.size () > 1 && text.front () == '0') || (!text.empty () && text.front () == '-'));
if (!error)
{
std::stringstream stream (text);
Expand Down
2 changes: 1 addition & 1 deletion nano/node/node.cpp
Expand Up @@ -3121,7 +3121,7 @@ nano::tally_t nano::election::tally (nano::transaction const & transaction_a)
void nano::election::confirm_if_quorum (nano::transaction const & transaction_a)
{
auto tally_l (tally (transaction_a));
assert (tally_l.size () > 0);
assert (!tally_l.empty ());
auto winner (tally_l.begin ());
auto block_l (winner->second);
status.tally = winner->first;
Expand Down
2 changes: 1 addition & 1 deletion nano/node/nodeconfig.cpp
Expand Up @@ -392,7 +392,7 @@ nano::error nano::node_config::deserialize_json (bool & upgraded_a, nano::jsonco

nano::account nano::node_config::random_representative ()
{
assert (preconfigured_representatives.size () > 0);
assert (!preconfigured_representatives.empty ());
size_t index (nano::random_pool::generate_word32 (0, static_cast<CryptoPP::word32> (preconfigured_representatives.size () - 1)));
auto result (preconfigured_representatives[index]);
return result;
Expand Down
2 changes: 0 additions & 2 deletions nano/node/rpc.hpp
Expand Up @@ -75,7 +75,6 @@ class payment_observer : public std::enable_shared_from_this<nano::payment_obser
~payment_observer ();
void start (uint64_t);
void observe ();
void timeout ();
void complete (nano::payment_status);
std::mutex mutex;
std::condition_variable condition;
Expand Down Expand Up @@ -131,7 +130,6 @@ class rpc_handler : public std::enable_shared_from_this<nano::rpc_handler>
void delegators_count ();
void deterministic_key ();
void frontiers ();
void history ();
void keepalive ();
void key_create ();
void key_expand ();
Expand Down
2 changes: 1 addition & 1 deletion nano/node/stats.cpp
Expand Up @@ -293,7 +293,7 @@ void nano::stat::update (uint32_t key_a, uint64_t value)
entry->samples.push_back (entry->sample_current);
entry->sample_current.set_value (0);

if (entry->sample_observers.observers.size () > 0)
if (!entry->sample_observers.observers.empty ())
{
auto snapshot (entry->samples);
entry->sample_observers.notify (snapshot);
Expand Down
4 changes: 2 additions & 2 deletions nano/secure/blockstore.cpp
Expand Up @@ -223,7 +223,7 @@ nano::uint128_t nano::summation_visitor::compute_internal (nano::summation_visit
compiler optimizing that into a loop, though a future alternative is to do a
CPS-style implementation to enforce tail calls.)
*/
while (frames.size () > 0)
while (!frames.empty ())
{
current = &frames.top ();
assert (current->type != summation_type::invalid && current != nullptr);
Expand Down Expand Up @@ -308,7 +308,7 @@ void nano::summation_visitor::epilogue ()
if (!current->awaiting_result)
{
frames.pop ();
if (frames.size () > 0)
if (!frames.empty ())
{
frames.top ().incoming_result = current->sum;
}
Expand Down
135 changes: 15 additions & 120 deletions nano/secure/common.cpp
Expand Up @@ -150,17 +150,6 @@ void nano::serialize_block (nano::stream & stream_a, nano::block const & block_a
block_a.serialize (stream_a);
}

nano::account_info::account_info () :
head (0),
rep_block (0),
open_block (0),
balance (0),
modified (0),
block_count (0),
epoch (nano::epoch::epoch_0)
{
}

nano::account_info::account_info (nano::block_hash const & head_a, nano::block_hash const & rep_block_a, nano::block_hash const & open_block_a, nano::amount const & balance_a, uint64_t modified_a, uint64_t block_count_a, nano::epoch epoch_a) :
head (head_a),
rep_block (rep_block_a),
Expand All @@ -172,16 +161,6 @@ epoch (epoch_a)
{
}

void nano::account_info::serialize (nano::stream & stream_a) const
{
write (stream_a, head.bytes);
write (stream_a, rep_block.bytes);
write (stream_a, open_block.bytes);
write (stream_a, balance.bytes);
write (stream_a, modified);
write (stream_a, block_count);
}

bool nano::account_info::deserialize (nano::stream & stream_a)
{
auto error (false);
Expand Down Expand Up @@ -223,41 +202,18 @@ size_t nano::account_info::db_size () const
return sizeof (head) + sizeof (rep_block) + sizeof (open_block) + sizeof (balance) + sizeof (modified) + sizeof (block_count);
}

nano::block_counts::block_counts () :
send (0),
receive (0),
open (0),
change (0),
state_v0 (0),
state_v1 (0)
{
}

size_t nano::block_counts::sum ()
size_t nano::block_counts::sum () const
{
return send + receive + open + change + state_v0 + state_v1;
}

nano::pending_info::pending_info () :
source (0),
amount (0),
epoch (nano::epoch::epoch_0)
{
}

nano::pending_info::pending_info (nano::account const & source_a, nano::amount const & amount_a, nano::epoch epoch_a) :
source (source_a),
amount (amount_a),
epoch (epoch_a)
{
}

void nano::pending_info::serialize (nano::stream & stream_a) const
{
nano::write (stream_a, source.bytes);
nano::write (stream_a, amount.bytes);
}

bool nano::pending_info::deserialize (nano::stream & stream_a)
{
auto error (false);
Expand All @@ -279,24 +235,12 @@ bool nano::pending_info::operator== (nano::pending_info const & other_a) const
return source == other_a.source && amount == other_a.amount && epoch == other_a.epoch;
}

nano::pending_key::pending_key () :
account (0),
hash (0)
{
}

nano::pending_key::pending_key (nano::account const & account_a, nano::block_hash const & hash_a) :
account (account_a),
hash (hash_a)
{
}

void nano::pending_key::serialize (nano::stream & stream_a) const
{
nano::write (stream_a, account.bytes);
nano::write (stream_a, hash.bytes);
}

bool nano::pending_key::deserialize (nano::stream & stream_a)
{
auto error (false);
Expand All @@ -323,14 +267,6 @@ nano::block_hash nano::pending_key::key () const
return account;
}

nano::unchecked_info::unchecked_info () :
block (nullptr),
account (0),
modified (0),
verified (nano::signature_verification::unknown)
{
}

nano::unchecked_info::unchecked_info (std::shared_ptr<nano::block> block_a, nano::account const & account_a, uint64_t modified_a, nano::signature_verification verified_a) :
block (block_a),
account (account_a),
Expand Down Expand Up @@ -368,11 +304,6 @@ bool nano::unchecked_info::deserialize (nano::stream & stream_a)
return error;
}

bool nano::unchecked_info::operator== (nano::unchecked_info const & other_a) const
{
return block->hash () == other_a.block->hash () && account == other_a.account && modified == other_a.modified && verified == other_a.verified;
}

nano::endpoint_key::endpoint_key (const std::array<uint8_t, 16> & address_a, uint16_t port_a) :
address (address_a), network_port (boost::endian::native_to_big (port_a))
{
Expand All @@ -388,45 +319,12 @@ uint16_t nano::endpoint_key::port () const
return boost::endian::big_to_native (network_port);
}

nano::block_info::block_info () :
account (0),
balance (0)
{
}

nano::block_info::block_info (nano::account const & account_a, nano::amount const & balance_a) :
account (account_a),
balance (balance_a)
{
}

void nano::block_info::serialize (nano::stream & stream_a) const
{
nano::write (stream_a, account.bytes);
nano::write (stream_a, balance.bytes);
}

bool nano::block_info::deserialize (nano::stream & stream_a)
{
auto error (false);
try
{
nano::read (stream_a, account.bytes);
nano::read (stream_a, balance.bytes);
}
catch (std::runtime_error const &)
{
error = true;
}

return error;
}

bool nano::block_info::operator== (nano::block_info const & other_a) const
{
return account == other_a.account && balance == other_a.balance;
}

bool nano::vote::operator== (nano::vote const & other_a) const
{
auto blocks_equal (true);
Expand Down Expand Up @@ -551,16 +449,14 @@ signature (nano::sign_message (prv_a, account_a, hash ()))
{
}

nano::vote::vote (nano::account const & account_a, nano::raw_key const & prv_a, uint64_t sequence_a, std::vector<nano::block_hash> blocks_a) :
nano::vote::vote (nano::account const & account_a, nano::raw_key const & prv_a, uint64_t sequence_a, std::vector<nano::block_hash> const & blocks_a) :
sequence (sequence_a),
account (account_a)
{
assert (blocks_a.size () > 0);
assert (!blocks_a.empty ());
assert (blocks_a.size () <= 12);
for (auto hash : blocks_a)
{
blocks.push_back (hash);
}
blocks.reserve (blocks_a.size ());
std::copy (blocks_a.cbegin (), blocks_a.cend (), std::back_inserter (blocks));
signature = nano::sign_message (prv_a, account_a, hash ());
}

Expand All @@ -582,7 +478,7 @@ nano::uint256_union nano::vote::hash () const
nano::uint256_union result;
blake2b_state hash;
blake2b_init (&hash, sizeof (result.bytes));
if (blocks.size () > 1 || (blocks.size () > 0 && blocks[0].which ()))
if (blocks.size () > 1 || (!blocks.empty () && blocks.front ().which ()))
{
blake2b_update (&hash, hash_prefix.data (), hash_prefix.size ());
}
Expand Down Expand Up @@ -613,12 +509,12 @@ nano::uint256_union nano::vote::full_hash () const
return result;
}

void nano::vote::serialize (nano::stream & stream_a, nano::block_type type)
void nano::vote::serialize (nano::stream & stream_a, nano::block_type type) const
{
write (stream_a, account);
write (stream_a, signature);
write (stream_a, sequence);
for (auto block : blocks)
for (auto const & block : blocks)
{
if (block.which ())
{
Expand All @@ -639,12 +535,12 @@ void nano::vote::serialize (nano::stream & stream_a, nano::block_type type)
}
}

void nano::vote::serialize (nano::stream & stream_a)
void nano::vote::serialize (nano::stream & stream_a) const
{
write (stream_a, account);
write (stream_a, signature);
write (stream_a, sequence);
for (auto block : blocks)
for (auto const & block : blocks)
{
if (block.which ())
{
Expand Down Expand Up @@ -708,10 +604,9 @@ bool nano::vote::deserialize (nano::stream & stream_a, nano::block_uniquer * uni
return error;
}

bool nano::vote::validate ()
bool nano::vote::validate () const
{
auto result (nano::validate_message (account, hash (), signature));
return result;
return nano::validate_message (account, hash (), signature);
}

nano::block_hash nano::iterate_vote_blocks_as_hash::operator() (boost::variant<std::shared_ptr<nano::block>, nano::block_hash> const & item) const
Expand Down Expand Up @@ -748,9 +643,9 @@ std::shared_ptr<nano::vote> nano::vote_uniquer::unique (std::shared_ptr<nano::vo
auto result (vote_a);
if (result != nullptr && !result->blocks.empty ())
{
if (!result->blocks[0].which ())
if (!result->blocks.front ().which ())
{
result->blocks[0] = uniquer.unique (boost::get<std::shared_ptr<nano::block>> (result->blocks[0]));
result->blocks.front () = uniquer.unique (boost::get<std::shared_ptr<nano::block>> (result->blocks.front ()));
}
nano::uint256_union key (vote_a->full_hash ());
std::lock_guard<std::mutex> lock (mutex);
Expand All @@ -765,7 +660,7 @@ std::shared_ptr<nano::vote> nano::vote_uniquer::unique (std::shared_ptr<nano::vo
}

release_assert (std::numeric_limits<CryptoPP::word32>::max () > votes.size ());
for (auto i (0); i < cleanup_count && votes.size () > 0; ++i)
for (auto i (0); i < cleanup_count && !votes.empty (); ++i)
{
auto random_offset = nano::random_pool::generate_word32 (0, static_cast<CryptoPP::word32> (votes.size () - 1));

Expand Down