Fix our own compiler warnings (#1677)
* Fix our own warnings * Mac warnings * Fix for frontier out of bounds check * Formatting and adding compiler guard around ASAN test * Clang version differences and create futures before threads start * Fix rebase * Move vote_minimum to correct location in constructor init-list * Used wrong clang-format order * Convert spaces to tabs
This commit is contained in:
parent
fc77ae7b0d
commit
885522b276
26 changed files with 107 additions and 62 deletions
|
@ -38,7 +38,8 @@ if (WIN32)
|
|||
add_definitions(-D_WIN32_WINNT=0x0600
|
||||
-DWINVER=0x0600
|
||||
-DWIN32_LEAN_AND_MEAN
|
||||
-DMINIUPNP_STATICLIB)
|
||||
-DMINIUPNP_STATICLIB
|
||||
-D_CRT_SECURE_NO_WARNINGS)
|
||||
else ()
|
||||
add_compile_options(-Werror=switch)
|
||||
if (NANO_ASAN OR RAIBLOCKS_ASAN)
|
||||
|
|
|
@ -7,6 +7,15 @@ TEST (basic, basic)
|
|||
|
||||
TEST (asan, DISABLED_memory)
|
||||
{
|
||||
// Ignore warning with gcc/clang compilers
|
||||
#ifndef MSVC
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Warray-bounds"
|
||||
#endif
|
||||
uint8_t array[1];
|
||||
auto value (array[-0x800000]);
|
||||
}
|
||||
(void)value;
|
||||
#ifndef MSVC
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ TEST (interface, xrb_uint256_to_string)
|
|||
TEST (interface, xrb_uint256_to_address)
|
||||
{
|
||||
nano::uint256_union zero (0);
|
||||
char text[66] = { 0 };
|
||||
char text[65] = { 0 };
|
||||
xrb_uint256_to_address (zero.bytes.data (), text);
|
||||
ASSERT_STREQ ("xrb_1111111111111111111111111111111111111111111111111111hifc8npp", text);
|
||||
}
|
||||
|
|
|
@ -2598,7 +2598,6 @@ TEST (rpc, accounts_pending)
|
|||
nano::keypair key1;
|
||||
system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv);
|
||||
auto block1 (system.wallet (0)->send_action (nano::test_genesis_key.pub, key1.pub, 100));
|
||||
auto iterations (0);
|
||||
system.deadline_set (5s);
|
||||
while (system.nodes[0]->active.active (*block1))
|
||||
{
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include <nano/lib/blocks.hpp>
|
||||
#include <nano/lib/numbers.hpp>
|
||||
#include <nano/lib/utility.hpp>
|
||||
|
||||
#include <boost/endian/conversion.hpp>
|
||||
|
||||
|
@ -1578,9 +1579,10 @@ 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)
|
||||
{
|
||||
auto random_offset (nano::random_pool.GenerateWord32 (0, blocks.size () - 1));
|
||||
auto random_offset (nano::random_pool.GenerateWord32 (0, static_cast<CryptoPP::word32> (blocks.size () - 1)));
|
||||
auto existing (std::next (blocks.begin (), random_offset));
|
||||
if (existing == blocks.end ())
|
||||
{
|
||||
|
|
|
@ -107,7 +107,7 @@ char * xrb_sign_transaction (const char * transaction, const xrb_uint256 private
|
|||
strncpy (result, json.c_str (), json.size () + 1);
|
||||
}
|
||||
}
|
||||
catch (std::runtime_error const & err)
|
||||
catch (std::runtime_error const &)
|
||||
{
|
||||
}
|
||||
return result;
|
||||
|
@ -133,7 +133,7 @@ char * xrb_work_transaction (const char * transaction)
|
|||
strncpy (result, json.c_str (), json.size () + 1);
|
||||
}
|
||||
}
|
||||
catch (std::runtime_error const & err)
|
||||
catch (std::runtime_error const &)
|
||||
{
|
||||
}
|
||||
return result;
|
||||
|
|
|
@ -17,8 +17,7 @@ uint8_t base58_decode (char value)
|
|||
{
|
||||
assert (value >= '0');
|
||||
assert (value <= '~');
|
||||
auto result (base58_reverse[value - 0x30] - 0x30);
|
||||
return result;
|
||||
return static_cast<uint8_t> (base58_reverse[value - 0x30] - 0x30);
|
||||
}
|
||||
char const * account_lookup ("13456789abcdefghijkmnopqrstuwxyz");
|
||||
char const * account_reverse ("~0~1234567~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~89:;<=>?@AB~CDEFGHIJK~LMNO~~~~~");
|
||||
|
|
|
@ -37,7 +37,8 @@ public:
|
|||
}
|
||||
|
||||
timer (std::string description_a, timer * parent_a) :
|
||||
desc (description_a), parent (parent_a)
|
||||
parent (parent_a),
|
||||
desc (description_a)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -186,11 +186,14 @@ void nano::work_pool::generate (nano::uint256_union const & root_a, std::functio
|
|||
uint64_t nano::work_pool::generate (nano::uint256_union const & hash_a, uint64_t difficulty_a)
|
||||
{
|
||||
std::promise<boost::optional<uint64_t>> work;
|
||||
std::future<boost::optional<uint64_t>> future = work.get_future ();
|
||||
// clang-format off
|
||||
generate (hash_a, [&work](boost::optional<uint64_t> work_a) {
|
||||
work.set_value (work_a);
|
||||
},
|
||||
difficulty_a);
|
||||
auto result (work.get_future ().get ());
|
||||
// clang-format on
|
||||
auto result (future.get ());
|
||||
return result.value ();
|
||||
}
|
||||
|
||||
|
|
|
@ -97,7 +97,7 @@ void nano::socket::checkup ()
|
|||
node->alarm.add (std::chrono::steady_clock::now () + std::chrono::seconds (10), [this_w]() {
|
||||
if (auto this_l = this_w.lock ())
|
||||
{
|
||||
if (this_l->cutoff != std::numeric_limits<uint64_t>::max () && this_l->cutoff < std::chrono::steady_clock::now ().time_since_epoch ().count ())
|
||||
if (this_l->cutoff != std::numeric_limits<uint64_t>::max () && this_l->cutoff < static_cast<uint64_t> (std::chrono::steady_clock::now ().time_since_epoch ().count ()))
|
||||
{
|
||||
if (this_l->node->config.logging.bulk_pull_logging ())
|
||||
{
|
||||
|
@ -420,8 +420,8 @@ void nano::frontier_req_client::next (nano::transaction const & transaction_a)
|
|||
|
||||
nano::bulk_pull_client::bulk_pull_client (std::shared_ptr<nano::bootstrap_client> connection_a, nano::pull_info const & pull_a) :
|
||||
connection (connection_a),
|
||||
pull (pull_a),
|
||||
known_account (0),
|
||||
pull (pull_a),
|
||||
total_blocks (0),
|
||||
unexpected_count (0)
|
||||
{
|
||||
|
@ -1053,10 +1053,14 @@ void nano::bootstrap_attempt::run ()
|
|||
frontier_failure = request_frontier (lock);
|
||||
}
|
||||
// Shuffle pulls.
|
||||
for (int i = pulls.size () - 1; i > 0; i--)
|
||||
release_assert (std::numeric_limits<CryptoPP::word32>::max () > pulls.size ());
|
||||
if (!pulls.empty ())
|
||||
{
|
||||
auto k = nano::random_pool.GenerateWord32 (0, i);
|
||||
std::swap (pulls[i], pulls[k]);
|
||||
for (auto i = static_cast<CryptoPP::word32> (pulls.size () - 1); i > 0; --i)
|
||||
{
|
||||
auto k = nano::random_pool.GenerateWord32 (0, i);
|
||||
std::swap (pulls[i], pulls[k]);
|
||||
}
|
||||
}
|
||||
while (still_pulling ())
|
||||
{
|
||||
|
@ -1241,7 +1245,7 @@ void nano::bootstrap_attempt::populate_connections ()
|
|||
auto delta = std::min ((target - connections) * 2, bootstrap_max_new_connections);
|
||||
// TODO - tune this better
|
||||
// Not many peers respond, need to try to make more connections than we need.
|
||||
for (int i = 0; i < delta; i++)
|
||||
for (auto i = 0u; i < delta; i++)
|
||||
{
|
||||
auto peer (node->peers.bootstrap_peer ());
|
||||
auto endpoint (nano::tcp_endpoint (peer.address (), peer.port ()));
|
||||
|
@ -1923,10 +1927,10 @@ std::unique_ptr<seq_con_info_component> collect_seq_con_info (bootstrap_initiato
|
|||
|
||||
nano::bootstrap_listener::bootstrap_listener (boost::asio::io_context & io_ctx_a, uint16_t port_a, nano::node & node_a) :
|
||||
acceptor (io_ctx_a),
|
||||
defer_acceptor (io_ctx_a),
|
||||
local (boost::asio::ip::tcp::endpoint (boost::asio::ip::address_v6::any (), port_a)),
|
||||
io_ctx (io_ctx_a),
|
||||
node (node_a)
|
||||
node (node_a),
|
||||
defer_acceptor (io_ctx_a)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -549,7 +549,7 @@ void nano::confirm_req::serialize (nano::stream & stream_a) const
|
|||
assert (!roots_hashes.empty ());
|
||||
// Calculate size
|
||||
assert (roots_hashes.size () <= 32);
|
||||
uint8_t count (roots_hashes.size ());
|
||||
auto count = static_cast<uint8_t> (roots_hashes.size ());
|
||||
write (stream_a, count);
|
||||
// Write hashes & roots
|
||||
for (auto & root_hash : roots_hashes)
|
||||
|
@ -963,12 +963,10 @@ nano::message_visitor::~message_visitor ()
|
|||
|
||||
bool nano::parse_port (std::string const & string_a, uint16_t & port_a)
|
||||
{
|
||||
bool result;
|
||||
size_t converted;
|
||||
bool result = false;
|
||||
try
|
||||
{
|
||||
port_a = std::stoul (string_a, &converted);
|
||||
result = converted != string_a.size () || converted > std::numeric_limits<uint16_t>::max ();
|
||||
port_a = boost::lexical_cast<uint16_t> (string_a);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
|
|
|
@ -107,7 +107,7 @@ public:
|
|||
{
|
||||
if (timeout_a < std::chrono::seconds::max ())
|
||||
{
|
||||
io_timer.expires_from_now (boost::posix_time::seconds (timeout_a.count ()));
|
||||
io_timer.expires_from_now (boost::posix_time::seconds (static_cast<long> (timeout_a.count ())));
|
||||
io_timer.async_wait ([this](const boost::system::error_code & ec) {
|
||||
if (!ec)
|
||||
{
|
||||
|
@ -645,7 +645,7 @@ std::shared_ptr<std::vector<uint8_t>> nano::ipc::ipc_client::prepare_request (na
|
|||
buffer_l->push_back (0);
|
||||
buffer_l->push_back (0);
|
||||
|
||||
uint32_t payload_length = payload_a.size ();
|
||||
auto payload_length = static_cast<uint32_t> (payload_a.size ());
|
||||
uint32_t be = boost::endian::native_to_big (payload_length);
|
||||
char * chars = reinterpret_cast<char *> (&be);
|
||||
buffer_l->insert (buffer_l->end (), chars, chars + sizeof (uint32_t));
|
||||
|
|
|
@ -1483,7 +1483,8 @@ std::shared_ptr<nano::block> nano::mdb_store::block_random (nano::transaction co
|
|||
std::shared_ptr<nano::block> nano::mdb_store::block_random (nano::transaction const & transaction_a)
|
||||
{
|
||||
auto count (block_count (transaction_a));
|
||||
auto region (nano::random_pool.GenerateWord32 (0, count.sum () - 1));
|
||||
release_assert (std::numeric_limits<CryptoPP::word32>::max () > count.sum ());
|
||||
auto region = static_cast<size_t> (nano::random_pool.GenerateWord32 (0, static_cast<CryptoPP::word32> (count.sum () - 1)));
|
||||
std::shared_ptr<nano::block> result;
|
||||
if (region < count.send)
|
||||
{
|
||||
|
|
|
@ -273,14 +273,14 @@ public:
|
|||
/** Deletes the node ID from the store */
|
||||
void delete_node_id (nano::transaction const &) override;
|
||||
|
||||
void peer_put (nano::transaction const & transaction_a, nano::endpoint_key const & endpoint_a);
|
||||
bool peer_exists (nano::transaction const & transaction_a, nano::endpoint_key const & endpoint_a) const;
|
||||
void peer_del (nano::transaction const & transaction_a, nano::endpoint_key const & endpoint_a);
|
||||
size_t peer_count (nano::transaction const & transaction_a) const;
|
||||
void peer_clear (nano::transaction const & transaction_a);
|
||||
void peer_put (nano::transaction const & transaction_a, nano::endpoint_key const & endpoint_a) override;
|
||||
bool peer_exists (nano::transaction const & transaction_a, nano::endpoint_key const & endpoint_a) const override;
|
||||
void peer_del (nano::transaction const & transaction_a, nano::endpoint_key const & endpoint_a) override;
|
||||
size_t peer_count (nano::transaction const & transaction_a) const override;
|
||||
void peer_clear (nano::transaction const & transaction_a) override;
|
||||
|
||||
nano::store_iterator<nano::endpoint_key, nano::no_value> peers_begin (nano::transaction const & transaction_a);
|
||||
nano::store_iterator<nano::endpoint_key, nano::no_value> peers_end ();
|
||||
nano::store_iterator<nano::endpoint_key, nano::no_value> peers_begin (nano::transaction const & transaction_a) override;
|
||||
nano::store_iterator<nano::endpoint_key, nano::no_value> peers_end () override;
|
||||
|
||||
void stop ();
|
||||
|
||||
|
|
|
@ -268,7 +268,7 @@ bool confirm_block (nano::transaction const & transaction_a, nano::node & node_a
|
|||
if (votes.empty ())
|
||||
{
|
||||
// Generate new vote
|
||||
node_a.wallets.foreach_representative (transaction_a, [&result, &block_a, &list_a, &node_a, &transaction_a, &hash](nano::public_key const & pub_a, nano::raw_key const & prv_a) {
|
||||
node_a.wallets.foreach_representative (transaction_a, [&result, &list_a, &node_a, &transaction_a, &hash](nano::public_key const & pub_a, nano::raw_key const & prv_a) {
|
||||
result = true;
|
||||
auto vote (node_a.store.vote_generate (transaction_a, pub_a, prv_a, std::vector<nano::block_hash> (1, hash)));
|
||||
nano::confirm_ack confirm (vote);
|
||||
|
@ -1515,11 +1515,11 @@ void nano::signature_checker::set_thread_names (unsigned num_threads)
|
|||
}
|
||||
|
||||
nano::block_processor::block_processor (nano::node & node_a) :
|
||||
generator (node_a, nano::is_test_network ? std::chrono::milliseconds (10) : std::chrono::milliseconds (500)),
|
||||
stopped (false),
|
||||
active (false),
|
||||
next_log (std::chrono::steady_clock::now ()),
|
||||
node (node_a),
|
||||
generator (node_a, nano::is_test_network ? std::chrono::milliseconds (10) : std::chrono::milliseconds (500))
|
||||
node (node_a)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -3110,10 +3110,12 @@ public:
|
|||
if (node->config.work_threads != 0 || node->work.opencl)
|
||||
{
|
||||
auto callback_l (callback);
|
||||
// clang-format off
|
||||
node->work.generate (root, [callback_l](boost::optional<uint64_t> const & work_a) {
|
||||
callback_l (work_a.value ());
|
||||
},
|
||||
difficulty);
|
||||
// clang-format on
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -3171,11 +3173,14 @@ void nano::node::work_generate (nano::uint256_union const & hash_a, std::functio
|
|||
uint64_t nano::node::work_generate_blocking (nano::uint256_union const & hash_a, uint64_t difficulty_a)
|
||||
{
|
||||
std::promise<uint64_t> promise;
|
||||
std::future<uint64_t> future = promise.get_future ();
|
||||
// clang-format off
|
||||
work_generate (hash_a, [&promise](uint64_t work_a) {
|
||||
promise.set_value (work_a);
|
||||
},
|
||||
difficulty_a);
|
||||
return promise.get_future ().get ();
|
||||
// clang-format on
|
||||
return future.get ();
|
||||
}
|
||||
|
||||
void nano::node::add_initial_peers ()
|
||||
|
|
|
@ -104,7 +104,9 @@ public:
|
|||
~active_transactions ();
|
||||
// Start an election for a block
|
||||
// Call action with confirmed block, may be different than what we started with
|
||||
// clang-format off
|
||||
bool start (std::shared_ptr<nano::block>, std::function<void(std::shared_ptr<nano::block>)> const & = [](std::shared_ptr<nano::block>) {});
|
||||
// clang-format on
|
||||
// If this returns true, the vote is a replay
|
||||
// If this returns false, the vote may or may not be a replay
|
||||
bool vote (std::shared_ptr<nano::vote>, bool = false);
|
||||
|
@ -140,7 +142,9 @@ public:
|
|||
|
||||
private:
|
||||
// Call action with confirmed block, may be different than what we started with
|
||||
// clang-format off
|
||||
bool add (std::shared_ptr<nano::block>, std::function<void(std::shared_ptr<nano::block>)> const & = [](std::shared_ptr<nano::block>) {});
|
||||
// clang-format on
|
||||
void request_loop ();
|
||||
void request_confirm (std::unique_lock<std::mutex> &);
|
||||
std::condition_variable condition;
|
||||
|
|
|
@ -22,6 +22,7 @@ peering_port (peering_port_a),
|
|||
logging (logging_a),
|
||||
bootstrap_fraction_numerator (1),
|
||||
receive_minimum (nano::xrb_ratio),
|
||||
vote_minimum (nano::Gxrb_ratio),
|
||||
online_weight_minimum (60000 * nano::Gxrb_ratio),
|
||||
online_weight_quorum (50),
|
||||
password_fanout (1024),
|
||||
|
@ -35,8 +36,7 @@ bootstrap_connections_max (64),
|
|||
callback_port (0),
|
||||
lmdb_max_dbs (128),
|
||||
allow_local_peers (false),
|
||||
block_processor_batch_max_time (std::chrono::milliseconds (5000)),
|
||||
vote_minimum (nano::Gxrb_ratio)
|
||||
block_processor_batch_max_time (std::chrono::milliseconds (5000))
|
||||
{
|
||||
const char * epoch_message ("epoch v1 block");
|
||||
strncpy ((char *)epoch_block_link.bytes.data (), epoch_message, epoch_block_link.bytes.size ());
|
||||
|
@ -387,7 +387,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);
|
||||
size_t index (nano::random_pool.GenerateWord32 (0, preconfigured_representatives.size () - 1));
|
||||
size_t index (nano::random_pool.GenerateWord32 (0, static_cast<CryptoPP::word32> (preconfigured_representatives.size () - 1)));
|
||||
auto result (preconfigured_representatives[index]);
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -426,7 +426,7 @@ nano::opencl_environment::opencl_environment (bool & error_a)
|
|||
void nano::opencl_environment::dump (std::ostream & stream)
|
||||
{
|
||||
auto index (0);
|
||||
auto device_count (0);
|
||||
size_t device_count (0);
|
||||
for (auto & i : platforms)
|
||||
{
|
||||
device_count += i.devices.size ();
|
||||
|
@ -555,7 +555,7 @@ logging (logging_a)
|
|||
0, 0
|
||||
};
|
||||
cl_int createContextError (0);
|
||||
context = clCreateContext (contextProperties, selected_devices.size (), selected_devices.data (), nullptr, nullptr, &createContextError);
|
||||
context = clCreateContext (contextProperties, static_cast<cl_uint> (selected_devices.size ()), selected_devices.data (), nullptr, nullptr, &createContextError);
|
||||
error_a |= createContextError != CL_SUCCESS;
|
||||
if (!error_a)
|
||||
{
|
||||
|
@ -587,7 +587,7 @@ logging (logging_a)
|
|||
error_a |= program_error != CL_SUCCESS;
|
||||
if (!error_a)
|
||||
{
|
||||
auto clBuildProgramError (clBuildProgram (program, selected_devices.size (), selected_devices.data (), "-D __APPLE__", nullptr, nullptr));
|
||||
auto clBuildProgramError (clBuildProgram (program, static_cast<cl_uint> (selected_devices.size ()), selected_devices.data (), "-D __APPLE__", nullptr, nullptr));
|
||||
error_a |= clBuildProgramError != CL_SUCCESS;
|
||||
if (!error_a)
|
||||
{
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include <vector>
|
||||
|
||||
#ifdef __APPLE__
|
||||
#define CL_SILENCE_DEPRECATION
|
||||
#include <OpenCL/opencl.h>
|
||||
#else
|
||||
#define CL_USE_DEPRECATED_OPENCL_1_2_APIS
|
||||
|
|
|
@ -202,7 +202,7 @@ std::unordered_set<nano::endpoint> nano::peer_container::random_set (size_t coun
|
|||
{
|
||||
for (auto i (0); i < random_cutoff && result.size () < count_a; ++i)
|
||||
{
|
||||
auto index (random_pool.GenerateWord32 (0, peers_size - 1));
|
||||
auto index (random_pool.GenerateWord32 (0, static_cast<CryptoPP::word32> (peers_size - 1)));
|
||||
result.insert (peers.get<3> ()[index].endpoint);
|
||||
}
|
||||
}
|
||||
|
@ -321,8 +321,7 @@ size_t nano::peer_container::size ()
|
|||
|
||||
size_t nano::peer_container::size_sqrt ()
|
||||
{
|
||||
auto result (std::ceil (std::sqrt (size ())));
|
||||
return result;
|
||||
return (static_cast<size_t> (std::ceil (std::sqrt (size ()))));
|
||||
}
|
||||
|
||||
std::vector<nano::peer_information> nano::peer_container::list_probable_rep_weights ()
|
||||
|
|
|
@ -708,6 +708,7 @@ void nano::rpc_handler::account_representative_set ()
|
|||
{
|
||||
bool generate_work (work == 0); // Disable work generation if "work" option is provided
|
||||
auto response_a (response);
|
||||
// clang-format off
|
||||
wallet->change_async (account, representative, [response_a](std::shared_ptr<nano::block> block) {
|
||||
nano::block_hash hash (0);
|
||||
if (block != nullptr)
|
||||
|
@ -719,6 +720,7 @@ void nano::rpc_handler::account_representative_set ()
|
|||
response_a (response_l);
|
||||
},
|
||||
work, generate_work);
|
||||
// clang-format on
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -2614,6 +2616,7 @@ void nano::rpc_handler::receive ()
|
|||
{
|
||||
bool generate_work (work == 0); // Disable work generation if "work" option is provided
|
||||
auto response_a (response);
|
||||
// clang-format off
|
||||
wallet->receive_async (std::move (block), account, nano::genesis_amount, [response_a](std::shared_ptr<nano::block> block_a) {
|
||||
nano::uint256_union hash_a (0);
|
||||
if (block_a != nullptr)
|
||||
|
@ -2625,6 +2628,7 @@ void nano::rpc_handler::receive ()
|
|||
response_a (response_l);
|
||||
},
|
||||
work, generate_work);
|
||||
// clang-format on
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -2962,6 +2966,7 @@ void nano::rpc_handler::send ()
|
|||
boost::optional<std::string> send_id (request.get_optional<std::string> ("id"));
|
||||
auto rpc_l (shared_from_this ());
|
||||
auto response_a (response);
|
||||
// clang-format off
|
||||
wallet->send_async (source, destination, amount.number (), [balance, amount, response_a](std::shared_ptr<nano::block> block_a) {
|
||||
if (block_a != nullptr)
|
||||
{
|
||||
|
@ -2984,6 +2989,7 @@ void nano::rpc_handler::send ()
|
|||
}
|
||||
},
|
||||
work, generate_work, send_id);
|
||||
// clang-format on
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -3404,7 +3410,7 @@ void nano::rpc_handler::wallet_change_seed ()
|
|||
nano::raw_key seed;
|
||||
if (!seed.data.decode_hex (seed_text))
|
||||
{
|
||||
auto count (count_optional_impl (0));
|
||||
auto count (static_cast<uint32_t> (count_optional_impl (0)));
|
||||
auto transaction (node.wallets.tx_begin_write ());
|
||||
if (wallet->store.valid_password (transaction))
|
||||
{
|
||||
|
@ -3806,7 +3812,9 @@ void nano::rpc_handler::wallet_representative_set ()
|
|||
}
|
||||
for (auto & account : accounts)
|
||||
{
|
||||
// clang-format off
|
||||
wallet->change_async (account, representative, [](std::shared_ptr<nano::block>) {}, 0, false);
|
||||
// clang-format on
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ std::string nano::error_system_messages::message (int ev) const
|
|||
return "Invalid error code";
|
||||
}
|
||||
|
||||
nano::system::system (uint16_t port_a, size_t count_a) :
|
||||
nano::system::system (uint16_t port_a, uint16_t count_a) :
|
||||
alarm (io_ctx),
|
||||
work (1, nullptr)
|
||||
{
|
||||
|
@ -28,7 +28,7 @@ work (1, nullptr)
|
|||
}
|
||||
logging.init (nano::unique_path ());
|
||||
nodes.reserve (count_a);
|
||||
for (size_t i (0); i < count_a; ++i)
|
||||
for (uint16_t i (0); i < count_a; ++i)
|
||||
{
|
||||
nano::node_init init;
|
||||
nano::node_config config (port_a + i, logging);
|
||||
|
@ -165,7 +165,8 @@ void nano::system::generate_usage_traffic (uint32_t count_a, uint32_t wait_a, si
|
|||
void nano::system::generate_rollback (nano::node & node_a, std::vector<nano::account> & accounts_a)
|
||||
{
|
||||
auto transaction (node_a.store.tx_begin_write ());
|
||||
auto index (random_pool.GenerateWord32 (0, accounts_a.size () - 1));
|
||||
assert (std::numeric_limits<CryptoPP::word32>::max () > accounts_a.size ());
|
||||
auto index (random_pool.GenerateWord32 (0, static_cast<CryptoPP::word32> (accounts_a.size () - 1)));
|
||||
auto account (accounts_a[index]);
|
||||
nano::account_info info;
|
||||
auto error (node_a.store.account_get (transaction, account, info));
|
||||
|
@ -234,7 +235,8 @@ void nano::system::generate_activity (nano::node & node_a, std::vector<nano::acc
|
|||
|
||||
nano::account nano::system::get_random_account (std::vector<nano::account> & accounts_a)
|
||||
{
|
||||
auto index (random_pool.GenerateWord32 (0, accounts_a.size () - 1));
|
||||
assert (std::numeric_limits<CryptoPP::word32>::max () > accounts_a.size ());
|
||||
auto index (random_pool.GenerateWord32 (0, static_cast<CryptoPP::word32> (accounts_a.size () - 1)));
|
||||
auto result (accounts_a[index]);
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ enum class error_system
|
|||
class system
|
||||
{
|
||||
public:
|
||||
system (uint16_t, size_t);
|
||||
system (uint16_t, uint16_t);
|
||||
~system ();
|
||||
void generate_activity (nano::node &, std::vector<nano::account> &);
|
||||
void generate_mass_activity (uint32_t, nano::node &);
|
||||
|
|
|
@ -1112,11 +1112,14 @@ std::shared_ptr<nano::block> nano::wallet::send_action (nano::account const & so
|
|||
bool nano::wallet::change_sync (nano::account const & source_a, nano::account const & representative_a)
|
||||
{
|
||||
std::promise<bool> result;
|
||||
std::future<bool> future = result.get_future ();
|
||||
// clang-format off
|
||||
change_async (source_a, representative_a, [&result](std::shared_ptr<nano::block> block_a) {
|
||||
result.set_value (block_a == nullptr);
|
||||
},
|
||||
true);
|
||||
return result.get_future ().get ();
|
||||
// clang-format on
|
||||
return future.get ();
|
||||
}
|
||||
|
||||
void nano::wallet::change_async (nano::account const & source_a, nano::account const & representative_a, std::function<void(std::shared_ptr<nano::block>)> const & action_a, uint64_t work_a, bool generate_work_a)
|
||||
|
@ -1130,11 +1133,14 @@ void nano::wallet::change_async (nano::account const & source_a, nano::account c
|
|||
bool nano::wallet::receive_sync (std::shared_ptr<nano::block> block_a, nano::account const & representative_a, nano::uint128_t const & amount_a)
|
||||
{
|
||||
std::promise<bool> result;
|
||||
std::future<bool> future = result.get_future ();
|
||||
// clang-format off
|
||||
receive_async (block_a, representative_a, amount_a, [&result](std::shared_ptr<nano::block> block_a) {
|
||||
result.set_value (block_a == nullptr);
|
||||
},
|
||||
true);
|
||||
return result.get_future ().get ();
|
||||
// clang-format on
|
||||
return future.get ();
|
||||
}
|
||||
|
||||
void nano::wallet::receive_async (std::shared_ptr<nano::block> block_a, nano::account const & representative_a, nano::uint128_t const & amount_a, std::function<void(std::shared_ptr<nano::block>)> const & action_a, uint64_t work_a, bool generate_work_a)
|
||||
|
@ -1149,11 +1155,14 @@ void nano::wallet::receive_async (std::shared_ptr<nano::block> block_a, nano::ac
|
|||
nano::block_hash nano::wallet::send_sync (nano::account const & source_a, nano::account const & account_a, nano::uint128_t const & amount_a)
|
||||
{
|
||||
std::promise<nano::block_hash> result;
|
||||
std::future<nano::block_hash> future = result.get_future ();
|
||||
// clang-format off
|
||||
send_async (source_a, account_a, amount_a, [&result](std::shared_ptr<nano::block> block_a) {
|
||||
result.set_value (block_a->hash ());
|
||||
},
|
||||
true);
|
||||
return result.get_future ().get ();
|
||||
// clang-format on
|
||||
return future.get ();
|
||||
}
|
||||
|
||||
void nano::wallet::send_async (nano::account const & source_a, nano::account const & account_a, nano::uint128_t const & amount_a, std::function<void(std::shared_ptr<nano::block>)> const & action_a, uint64_t work_a, bool generate_work_a, boost::optional<std::string> id_a)
|
||||
|
|
|
@ -744,9 +744,11 @@ std::shared_ptr<nano::vote> nano::vote_uniquer::unique (std::shared_ptr<nano::vo
|
|||
{
|
||||
existing = vote_a;
|
||||
}
|
||||
|
||||
release_assert (std::numeric_limits<CryptoPP::word32>::max () > votes.size ());
|
||||
for (auto i (0); i < cleanup_count && votes.size () > 0; ++i)
|
||||
{
|
||||
auto random_offset (nano::random_pool.GenerateWord32 (0, votes.size () - 1));
|
||||
auto random_offset (nano::random_pool.GenerateWord32 (0, static_cast<CryptoPP::word32> (votes.size () - 1)));
|
||||
auto existing (std::next (votes.begin (), random_offset));
|
||||
if (existing == votes.end ())
|
||||
{
|
||||
|
|
|
@ -7,7 +7,7 @@ TEST (system, generate_mass_activity)
|
|||
{
|
||||
nano::system system (24000, 1);
|
||||
system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv);
|
||||
size_t count (20);
|
||||
uint32_t count (20);
|
||||
system.generate_mass_activity (count, *system.nodes[0]);
|
||||
size_t accounts (0);
|
||||
auto transaction (system.nodes[0]->store.tx_begin ());
|
||||
|
@ -22,7 +22,7 @@ TEST (system, generate_mass_activity_long)
|
|||
nano::system system (24000, 1);
|
||||
nano::thread_runner runner (system.io_ctx, system.nodes[0]->config.io_threads);
|
||||
system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv);
|
||||
size_t count (1000000000);
|
||||
uint32_t count (1000000000);
|
||||
system.generate_mass_activity (count, *system.nodes[0]);
|
||||
size_t accounts (0);
|
||||
auto transaction (system.nodes[0]->store.tx_begin ());
|
||||
|
@ -41,7 +41,7 @@ TEST (system, receive_while_synchronizing)
|
|||
nano::system system (24000, 1);
|
||||
nano::thread_runner runner (system.io_ctx, system.nodes[0]->config.io_threads);
|
||||
system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv);
|
||||
size_t count (1000);
|
||||
uint32_t count (1000);
|
||||
system.generate_mass_activity (count, *system.nodes[0]);
|
||||
nano::keypair key;
|
||||
nano::node_init init1;
|
||||
|
@ -296,7 +296,6 @@ TEST (broadcast, world_broadcast_simulate)
|
|||
}
|
||||
auto count (heard_count (nodes));
|
||||
(void)count;
|
||||
printf ("");
|
||||
}
|
||||
|
||||
TEST (broadcast, sqrt_broadcast_simulate)
|
||||
|
@ -350,7 +349,6 @@ TEST (broadcast, sqrt_broadcast_simulate)
|
|||
}
|
||||
auto count (heard_count (nodes));
|
||||
(void)count;
|
||||
printf ("");
|
||||
}
|
||||
|
||||
TEST (peer_container, random_set)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue