Compare commits

...

14 Commits

Author SHA1 Message Date
tobtoht 3599e8ee6e epee: string_tools: keep full path in cut_off_extension 2025-03-07 14:16:42 +00:00
tobtoht c089f781e1 epee: string_tools: remove dot from get_extension
Fixes a regression introduced in #9254. Previously it did not
include the dot.
2025-03-07 14:16:14 +00:00
tobtoht dd7c49d7e2 device: add ledger flex support
See: https://github.com/LedgerHQ/ledger-live/blob/bd1b09970f2f5a27eb08352a67a73dfa2fce29f6/libs/ledgerjs/packages/devices/src/index.ts#L111
2025-03-07 14:15:33 +00:00
Lee Clagett ea5fec8618 Make wallet2::estimate_fee static 2025-03-07 14:14:20 +00:00
0xFFFC0000 7b73184c68 epee: fix mlog filename compare bug.
When using a relative path for the log filename,
since the iteration on files adds "./" to the beginning of the filename
monero-wallet-rpc and monero-wallet-cli	cannot find already written
log files and therefore rotate indefinitely.
2025-03-07 14:11:16 +00:00
Lee *!* Clagett fe180ad116 Fix ZMQ DaemonInfo:
* top_block_hash was never set in handler
  * wide_difficulty was never sent in JSON
  * wide_cumulative_difficulty was never sent in JSON
2025-03-07 14:10:38 +00:00
Lee Clagett 8e57973c08 Fix ZMQ Tx Pruning 2025-03-07 12:47:30 +00:00
jeffro256 15f280c6b0 wallet: fetch pool txs in pruned form [RELEASE] 2025-03-07 12:46:29 +00:00
0xFFFC0000 230890aab0 cryptonote_protocol: prevent duplicate txs in fluff queue
1. Fix duplicate transaction #9335
2. Add test for cases where there are duplicate transaction in fluff

Co-authored-by: Boog900 <boog900@tutanota.com>
2025-03-07 12:44:35 +00:00
0xFFFC0000 308277c886 contrib: fix compilation error for boost 1.85 2025-03-07 12:43:34 +00:00
0xFFFC0000 957c79512f Add drop_and_recreate in privatefile class.
When creating a private file we need to delete the file if exist.
2025-03-07 12:30:26 +00:00
Lee *!* Clagett 9e7d100750 Skip privacy networks (on tx sends) that don't have outgoing connections 2025-03-07 12:28:35 +00:00
j-berman cdff63628e wallet2: ensure transfers and sweeps use same fee calc logic rnd2
Looks like the logic from #8882 was accidentally removed in #8861
(regressing to the behavior noted in the #8882 description).
This commit brings that logic back.
2025-03-07 12:27:13 +00:00
0xFFFC0000 a43423f53a Cleanup string_tools.
1. Use boost::filesystem for already available operations.
2. Use boost::string for already available operations.
2025-03-07 12:26:51 +00:00
19 changed files with 271 additions and 81 deletions
@@ -38,6 +38,7 @@
#include <boost/numeric/conversion/bounds.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/numeric/conversion/bounds.hpp>
#include <typeinfo>
#include <iomanip>
+7 -10
View File
@@ -31,6 +31,7 @@
#include "mlocker.h"
#include <boost/utility/string_ref.hpp>
#include <boost/algorithm/string.hpp>
#include <sstream>
#include <string>
#include <cstdint>
@@ -69,23 +70,19 @@ namespace string_tools
#ifdef _WIN32
std::string get_current_module_path();
#endif
bool set_module_name_and_folder(const std::string& path_to_process_);
bool trim_left(std::string& str);
bool trim_right(std::string& str);
void set_module_name_and_folder(const std::string& path_to_process_);
void trim_left(std::string& str);
void trim_right(std::string& str);
//----------------------------------------------------------------------------
inline std::string& trim(std::string& str)
{
trim_left(str);
trim_right(str);
boost::trim(str);
return str;
}
//----------------------------------------------------------------------------
inline std::string trim(const std::string& str_)
inline std::string trim(const std::string& str)
{
std::string str = str_;
trim_left(str);
trim_right(str);
return str;
return boost::trim_copy(str);
}
std::string pad_string(std::string s, size_t n, char c = ' ', bool prepend = false);
+3 -2
View File
@@ -176,11 +176,12 @@ void mlog_configure(const std::string &filename_base, bool console, const std::s
std::vector<boost::filesystem::path> found_files;
const boost::filesystem::directory_iterator end_itr;
const boost::filesystem::path filename_base_path(filename_base);
const std::string filename_base_name = filename_base_path.filename().string();
const boost::filesystem::path parent_path = filename_base_path.has_parent_path() ? filename_base_path.parent_path() : ".";
for (boost::filesystem::directory_iterator iter(parent_path); iter != end_itr; ++iter)
{
const std::string filename = iter->path().string();
if (filename.size() >= filename_base.size() && std::memcmp(filename.data(), filename_base.data(), filename_base.size()) == 0)
const std::string filename = iter->path().filename().string();
if (filename.size() >= filename_base_name.size() && std::memcmp(filename.data(), filename_base_name.data(), filename_base_name.size()) == 0)
{
found_files.push_back(iter->path());
}
+2 -1
View File
@@ -1,4 +1,5 @@
#include "readline_buffer.h"
#include "string_tools.h"
#include <readline/readline.h>
#include <readline/history.h>
#include <iostream>
@@ -173,7 +174,7 @@ static void handle_line(char* line)
line_stat = rdln::full;
the_line = line;
std::string test_line = line;
boost::trim_right(test_line);
epee::string_tools::trim_right(test_line);
if(!test_line.empty())
{
if (!same_as_last_line(test_line))
+37 -53
View File
@@ -38,9 +38,12 @@
#include <cstdlib>
#include <string>
#include <type_traits>
#include <system_error>
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/utility/string_ref.hpp>
#include <boost/filesystem.hpp>
#include "misc_log_ex.h"
#include "storages/parserse_base_utils.h"
#include "hex.h"
@@ -157,46 +160,33 @@ namespace string_tools
return pname;
}
#endif
bool set_module_name_and_folder(const std::string& path_to_process_)
{
std::string path_to_process = path_to_process_;
void set_module_name_and_folder(const std::string& path_to_process_)
{
boost::filesystem::path path_to_process = path_to_process_;
#ifdef _WIN32
path_to_process = get_current_module_path();
#endif
std::string::size_type a = path_to_process.rfind( '\\' );
if(a == std::string::npos )
{
a = path_to_process.rfind( '/' );
}
if ( a != std::string::npos )
{
get_current_module_name() = path_to_process.substr(a+1, path_to_process.size());
get_current_module_folder() = path_to_process.substr(0, a);
return true;
}else
return false;
}
get_current_module_name() = path_to_process.filename().string();
get_current_module_folder() = path_to_process.parent_path().string();
}
//----------------------------------------------------------------------------
bool trim_left(std::string& str)
{
for(std::string::iterator it = str.begin(); it!= str.end() && isspace(static_cast<unsigned char>(*it));)
str.erase(str.begin());
return true;
}
void trim_left(std::string& str)
{
boost::trim_left(str);
return;
}
//----------------------------------------------------------------------------
bool trim_right(std::string& str)
{
void trim_right(std::string& str)
{
boost::trim_right(str);
return;
}
for(std::string::reverse_iterator it = str.rbegin(); it!= str.rend() && isspace(static_cast<unsigned char>(*it));)
str.erase( --((it++).base()));
return true;
}
//----------------------------------------------------------------------------
std::string pad_string(std::string s, size_t n, char c, bool prepend)
{
if (s.size() < n)
@@ -209,28 +199,22 @@ namespace string_tools
return s;
}
std::string get_extension(const std::string& str)
{
std::string res;
std::string::size_type pos = str.rfind('.');
if(std::string::npos == pos)
return res;
res = str.substr(pos+1, str.size()-pos);
return res;
}
//----------------------------------------------------------------------------
std::string cut_off_extension(const std::string& str)
{
std::string res;
std::string::size_type pos = str.rfind('.');
if(std::string::npos == pos)
return str;
std::string get_extension(const std::string& str)
{
std::string ext_with_dot = boost::filesystem::path(str).extension().string();
if (ext_with_dot.empty())
return {};
return ext_with_dot.erase(0, 1);
}
//----------------------------------------------------------------------------
std::string cut_off_extension(const std::string& str)
{
return boost::filesystem::path(str).replace_extension("").string();
}
res = str.substr(0, pos);
return res;
}
//----------------------------------------------------------------------------
#ifdef _WIN32
std::wstring utf8_to_utf16(const std::string& str)
{
+9 -2
View File
@@ -396,6 +396,8 @@ namespace levin
for (auto& connection : connections)
{
std::sort(connection.first.begin(), connection.first.end()); // don't leak receive order
connection.first.erase(std::unique(connection.first.begin(), connection.first.end()),
connection.first.end());
make_payload_send_txs(*zone_->p2p, std::move(connection.first), connection.second, zone_->pad_txs, true);
}
@@ -741,9 +743,14 @@ namespace levin
notify::status notify::get_status() const noexcept
{
if (!zone_)
return {false, false};
return {false, false, false};
return {!zone_->noise.empty(), CRYPTONOTE_NOISE_CHANNELS <= zone_->connection_count};
// `connection_count` is only set when `!noise.empty()`.
const std::size_t connection_count = zone_->connection_count;
bool has_outgoing = connection_count;
if (zone_->noise.empty())
has_outgoing = zone_->p2p->get_out_connections_count();
return {!zone_->noise.empty(), CRYPTONOTE_NOISE_CHANNELS <= connection_count, has_outgoing};
}
void notify::new_out_connection()
+2 -1
View File
@@ -75,7 +75,8 @@ namespace levin
struct status
{
bool has_noise;
bool connections_filled;
bool connections_filled; //!< True when has zone has `CRYPTONOTE_NOISE_CHANNELS` outgoing noise channels
bool has_outgoing; //!< True when zone has outgoing connections
};
//! Construct an instance that cannot notify.
+1
View File
@@ -528,6 +528,7 @@ namespace hw {
{0x2c97, 0x0004, 0, 0xffa0},
{0x2c97, 0x0005, 0, 0xffa0},
{0x2c97, 0x0006, 0, 0xffa0},
{0x2c97, 0x0007, 0, 0xffa0},
};
bool device_ledger::connect(void) {
+3 -2
View File
@@ -2292,11 +2292,12 @@ namespace nodetool
if (enet::zone::tor < network->first)
break; // unknown network
if (network->second.m_connect)
const auto status = network->second.m_notifier.get_status();
if (network->second.m_connect && status.has_outgoing)
return send(*network);
}
// configuration should not allow this scenario
MWARNING("Unable to send " << txs.size() << " transaction(s): anonymity networks had no outgoing connections");
return enet::zone::invalid;
}
//-----------------------------------------------------------------------------------
+2
View File
@@ -536,6 +536,8 @@ namespace rpc
res.info.target_height = res.info.height;
}
m_core.get_blockchain_top(res.info.top_block_height, res.info.top_block_hash);
auto& chain = m_core.get_blockchain_storage();
res.info.wide_difficulty = chain.get_difficulty_for_next_block();
+1
View File
@@ -180,6 +180,7 @@ namespace rpc
{
uint64_t height;
uint64_t target_height;
uint64_t top_block_height;
cryptonote::difficulty_type wide_difficulty;
uint64_t difficulty;
uint64_t target;
+28 -3
View File
@@ -289,7 +289,10 @@ void toJsonValue(rapidjson::Writer<epee::byte_stream>& dest, const cryptonote::t
{
INSERT_INTO_JSON_OBJECT(dest, signatures, tx.signatures);
}
INSERT_INTO_JSON_OBJECT(dest, ringct, tx.rct_signatures);
{
dest.Key("ringct");
toJsonValue(dest, tx.rct_signatures, tx.pruned);
}
dest.EndObject();
}
@@ -1155,7 +1158,7 @@ void fromJsonValue(const rapidjson::Value& val, cryptonote::rpc::BlockHeaderResp
GET_FROM_JSON_OBJECT(val, response.reward, reward);
}
void toJsonValue(rapidjson::Writer<epee::byte_stream>& dest, const rct::rctSig& sig)
void toJsonValue(rapidjson::Writer<epee::byte_stream>& dest, const rct::rctSig& sig, const bool prune)
{
using boost::adaptors::transform;
@@ -1182,7 +1185,7 @@ void toJsonValue(rapidjson::Writer<epee::byte_stream>& dest, const rct::rctSig&
}
// prunable
if (!sig.p.bulletproofs.empty() || !sig.p.bulletproofs_plus.empty() || !sig.p.rangeSigs.empty() || !sig.p.MGs.empty() || !sig.get_pseudo_outs().empty())
if (!prune && (!sig.p.bulletproofs.empty() || !sig.p.bulletproofs_plus.empty() || !sig.p.rangeSigs.empty() || !sig.p.MGs.empty() || !sig.get_pseudo_outs().empty()))
{
dest.Key("prunable");
dest.StartObject();
@@ -1571,9 +1574,14 @@ void toJsonValue(rapidjson::Writer<epee::byte_stream>& dest, const cryptonote::r
{
dest.StartObject();
const uint64_t difficulty_top64 = (info.wide_difficulty >> 64).convert_to<std::uint64_t>();
const uint64_t cumulative_difficulty_top64 = (info.wide_cumulative_difficulty >> 64).convert_to<std::uint64_t>();
INSERT_INTO_JSON_OBJECT(dest, height, info.height);
INSERT_INTO_JSON_OBJECT(dest, target_height, info.target_height);
INSERT_INTO_JSON_OBJECT(dest, top_block_height, info.top_block_height);
INSERT_INTO_JSON_OBJECT(dest, difficulty, info.difficulty);
INSERT_INTO_JSON_OBJECT(dest, difficulty_top64, difficulty_top64);
INSERT_INTO_JSON_OBJECT(dest, target, info.target);
INSERT_INTO_JSON_OBJECT(dest, tx_count, info.tx_count);
INSERT_INTO_JSON_OBJECT(dest, tx_pool_size, info.tx_pool_size);
@@ -1588,12 +1596,14 @@ void toJsonValue(rapidjson::Writer<epee::byte_stream>& dest, const cryptonote::r
INSERT_INTO_JSON_OBJECT(dest, nettype, info.nettype);
INSERT_INTO_JSON_OBJECT(dest, top_block_hash, info.top_block_hash);
INSERT_INTO_JSON_OBJECT(dest, cumulative_difficulty, info.cumulative_difficulty);
INSERT_INTO_JSON_OBJECT(dest, cumulative_difficulty_top64, cumulative_difficulty_top64);
INSERT_INTO_JSON_OBJECT(dest, block_size_limit, info.block_size_limit);
INSERT_INTO_JSON_OBJECT(dest, block_weight_limit, info.block_weight_limit);
INSERT_INTO_JSON_OBJECT(dest, block_size_median, info.block_size_median);
INSERT_INTO_JSON_OBJECT(dest, block_weight_median, info.block_weight_median);
INSERT_INTO_JSON_OBJECT(dest, adjusted_time, info.adjusted_time);
INSERT_INTO_JSON_OBJECT(dest, start_time, info.start_time);
INSERT_INTO_JSON_OBJECT(dest, version, info.version);
dest.EndObject();
}
@@ -1605,9 +1615,14 @@ void fromJsonValue(const rapidjson::Value& val, cryptonote::rpc::DaemonInfo& inf
throw WRONG_TYPE("json object");
}
uint64_t difficulty_top64 = 0;
uint64_t cumulative_difficulty_top64 = 0;
GET_FROM_JSON_OBJECT(val, info.height, height);
GET_FROM_JSON_OBJECT(val, info.target_height, target_height);
GET_FROM_JSON_OBJECT(val, info.top_block_height, top_block_height);
GET_FROM_JSON_OBJECT(val, info.difficulty, difficulty);
GET_FROM_JSON_OBJECT(val, difficulty_top64, difficulty_top64);
GET_FROM_JSON_OBJECT(val, info.target, target);
GET_FROM_JSON_OBJECT(val, info.tx_count, tx_count);
GET_FROM_JSON_OBJECT(val, info.tx_pool_size, tx_pool_size);
@@ -1622,12 +1637,22 @@ void fromJsonValue(const rapidjson::Value& val, cryptonote::rpc::DaemonInfo& inf
GET_FROM_JSON_OBJECT(val, info.nettype, nettype);
GET_FROM_JSON_OBJECT(val, info.top_block_hash, top_block_hash);
GET_FROM_JSON_OBJECT(val, info.cumulative_difficulty, cumulative_difficulty);
GET_FROM_JSON_OBJECT(val, cumulative_difficulty_top64, cumulative_difficulty_top64);
GET_FROM_JSON_OBJECT(val, info.block_size_limit, block_size_limit);
GET_FROM_JSON_OBJECT(val, info.block_weight_limit, block_weight_limit);
GET_FROM_JSON_OBJECT(val, info.block_size_median, block_size_median);
GET_FROM_JSON_OBJECT(val, info.block_weight_median, block_weight_median);
GET_FROM_JSON_OBJECT(val, info.adjusted_time, adjusted_time);
GET_FROM_JSON_OBJECT(val, info.start_time, start_time);
GET_FROM_JSON_OBJECT(val, info.version, version);
info.wide_difficulty = difficulty_top64;
info.wide_difficulty <<= 64;
info.wide_difficulty += info.difficulty;
info.wide_cumulative_difficulty = cumulative_difficulty_top64;
info.wide_cumulative_difficulty <<= 64;
info.wide_cumulative_difficulty += info.cumulative_difficulty;
}
void toJsonValue(rapidjson::Writer<epee::byte_stream>& dest, const cryptonote::rpc::output_distribution& dist)
+1 -1
View File
@@ -281,7 +281,7 @@ void fromJsonValue(const rapidjson::Value& val, cryptonote::rpc::error& error);
void toJsonValue(rapidjson::Writer<epee::byte_stream>& dest, const cryptonote::rpc::BlockHeaderResponse& response);
void fromJsonValue(const rapidjson::Value& val, cryptonote::rpc::BlockHeaderResponse& response);
void toJsonValue(rapidjson::Writer<epee::byte_stream>& dest, const rct::rctSig& i);
void toJsonValue(rapidjson::Writer<epee::byte_stream>& dest, const rct::rctSig& sig, bool prune);
void fromJsonValue(const rapidjson::Value& val, rct::rctSig& sig);
void fromJsonValue(const rapidjson::Value& val, rct::ctkey& key);
+5 -4
View File
@@ -4141,6 +4141,7 @@ void wallet2::update_pool_state(std::vector<std::tuple<cryptonote::transaction,
req.requested_info = COMMAND_RPC_GET_BLOCKS_FAST::POOL_ONLY;
req.pool_info_since = m_pool_info_query_time;
req.prune = true;
{
const boost::lock_guard<boost::recursive_mutex> lock{m_daemon_rpc_mutex};
@@ -8567,7 +8568,7 @@ bool wallet2::sign_multisig_tx_from_file(const std::string &filename, std::vecto
return sign_multisig_tx_to_file(exported_txs, filename, txids);
}
//----------------------------------------------------------------------------------------------------
uint64_t wallet2::estimate_fee(bool use_per_byte_fee, bool use_rct, int n_inputs, int mixin, int n_outputs, size_t extra_size, bool bulletproof, bool clsag, bool bulletproof_plus, bool use_view_tags, uint64_t base_fee, uint64_t fee_quantization_mask) const
uint64_t wallet2::estimate_fee(bool use_per_byte_fee, bool use_rct, int n_inputs, int mixin, int n_outputs, size_t extra_size, bool bulletproof, bool clsag, bool bulletproof_plus, bool use_view_tags, uint64_t base_fee, uint64_t fee_quantization_mask)
{
if (use_per_byte_fee)
{
@@ -11218,8 +11219,8 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions_2(std::vector<cryp
else
{
LOG_PRINT_L2("We made a tx, adjusting fee and saving it, we need " << print_money(needed_fee) << " and we have " << print_money(test_ptx.fee));
size_t fee_tries;
for (fee_tries = 0; fee_tries < 10 && needed_fee > test_ptx.fee; ++fee_tries) {
size_t fee_tries = 0;
do {
tx_dsts = tx.get_adjusted_dsts(needed_fee);
if (use_rct)
@@ -11232,7 +11233,7 @@ std::vector<wallet2::pending_tx> wallet2::create_transactions_2(std::vector<cryp
needed_fee = calculate_fee(use_per_byte_fee, test_ptx.tx, txBlob.size(), base_fee, fee_quantization_mask);
LOG_PRINT_L2("Made an attempt at a final " << get_weight_string(test_ptx.tx, txBlob.size()) << " tx, with " << print_money(test_ptx.fee) <<
" fee and " << print_money(test_ptx.change_dts.amount) << " change");
};
} while (needed_fee > test_ptx.fee && ++fee_tries < 10);
THROW_WALLET_EXCEPTION_IF(fee_tries == 10, error::wallet_internal_error,
"Too many attempts to raise pending tx fee to level of needed fee");
+1 -1
View File
@@ -1618,7 +1618,7 @@ private:
std::vector<std::pair<uint64_t, uint64_t>> estimate_backlog(const std::vector<std::pair<double, double>> &fee_levels);
std::vector<std::pair<uint64_t, uint64_t>> estimate_backlog(uint64_t min_tx_weight, uint64_t max_tx_weight, const std::vector<uint64_t> &fees);
uint64_t estimate_fee(bool use_per_byte_fee, bool use_rct, int n_inputs, int mixin, int n_outputs, size_t extra_size, bool bulletproof, bool clsag, bool bulletproof_plus, bool use_view_tags, uint64_t base_fee, uint64_t fee_quantization_mask) const;
static uint64_t estimate_fee(bool use_per_byte_fee, bool use_rct, int n_inputs, int mixin, int n_outputs, size_t extra_size, bool bulletproof, bool clsag, bool bulletproof_plus, bool use_view_tags, uint64_t base_fee, uint64_t fee_quantization_mask);
uint64_t get_fee_multiplier(uint32_t priority, int fee_algorithm = -1);
uint64_t get_base_fee(uint32_t priority);
uint64_t get_base_fee();
+1 -1
View File
@@ -245,7 +245,7 @@ namespace tools
);
std::string temp = "salvium-wallet-rpc." + bind_port + ".login";
rpc_login_file = tools::private_file::create(temp);
rpc_login_file = tools::private_file::drop_and_recreate(temp);
if (!rpc_login_file.handle())
{
LOG_ERROR(tr("Failed to create file ") << temp << tr(". Check permissions or remove file"));
+15
View File
@@ -1427,6 +1427,21 @@ TEST(StringTools, GetIpInt32)
EXPECT_EQ(htonl(0xff0aff00), ip);
}
TEST(StringTools, GetExtension)
{
EXPECT_EQ(std::string{}, epee::string_tools::get_extension(""));
EXPECT_EQ(std::string{}, epee::string_tools::get_extension("."));
EXPECT_EQ(std::string{"keys"}, epee::string_tools::get_extension("wallet.keys"));
EXPECT_EQ(std::string{"3"}, epee::string_tools::get_extension("1.2.3"));
}
TEST(StringTools, CutOffExtension)
{
EXPECT_EQ(std::string{}, epee::string_tools::cut_off_extension(""));
EXPECT_EQ(std::string{"/home/user/Monero/wallets/wallet"}, epee::string_tools::cut_off_extension("/home/user/Monero/wallets/wallet"));
EXPECT_EQ(std::string{"/home/user/Monero/wallets/wallet"}, epee::string_tools::cut_off_extension("/home/user/Monero/wallets/wallet.keys"));
}
TEST(NetUtils, IPv4NetworkAddress)
{
static_assert(epee::net_utils::ipv4_network_address::get_type_id() == epee::net_utils::address_type::ipv4, "bad ipv4 type id");
+62
View File
@@ -125,6 +125,68 @@ TEST(JsonSerialization, InvalidVectorBytes)
EXPECT_THROW(cryptonote::json::fromJsonValue(doc, out), cryptonote::json::BAD_INPUT);
}
TEST(JsonSerialization, DaemonInfo)
{
cryptonote::rpc::DaemonInfo info{};
info.height = 154544;
info.target_height = 15345435;
info.top_block_height = 2344;
info.wide_difficulty = cryptonote::difficulty_type{"100000000000000000005443"};
info.difficulty = 200376420520695107;
info.target = 7657567;
info.tx_count = 355;
info.tx_pool_size = 45435;
info.alt_blocks_count = 43535;
info.outgoing_connections_count = 1444;
info.incoming_connections_count = 1444;
info.white_peerlist_size = 14550;
info.grey_peerlist_size = 34324;
info.mainnet = true;
info.testnet = true;
info.stagenet = true;
info.nettype = "main";
info.top_block_hash = crypto::hash{1};
info.wide_cumulative_difficulty = cryptonote::difficulty_type{"200000000000000000005543"};
info.cumulative_difficulty = 400752841041384871;
info.block_size_limit = 4324234;
info.block_weight_limit = 3434;
info.block_size_median = 3434;
info.adjusted_time = 4535;
info.block_weight_median = 43535;
info.start_time = 34535;
info.version = "1.0";
const auto info_copy = test_json(info);
EXPECT_EQ(info.height, info_copy.height);
EXPECT_EQ(info.target_height, info_copy.target_height);
EXPECT_EQ(info.top_block_height, info_copy.top_block_height);
EXPECT_EQ(info.wide_difficulty, info_copy.wide_difficulty);
EXPECT_EQ(info.difficulty, info_copy.difficulty);
EXPECT_EQ(info.target, info_copy.target);
EXPECT_EQ(info.tx_count, info_copy.tx_count);
EXPECT_EQ(info.tx_pool_size, info_copy.tx_pool_size);
EXPECT_EQ(info.alt_blocks_count, info_copy.alt_blocks_count);
EXPECT_EQ(info.outgoing_connections_count, info_copy.outgoing_connections_count);
EXPECT_EQ(info.incoming_connections_count, info_copy.incoming_connections_count);
EXPECT_EQ(info.white_peerlist_size, info_copy.white_peerlist_size);
EXPECT_EQ(info.grey_peerlist_size, info_copy.grey_peerlist_size);
EXPECT_EQ(info.mainnet, info_copy.mainnet);
EXPECT_EQ(info.testnet, info_copy.testnet);
EXPECT_EQ(info.stagenet, info_copy.stagenet);
EXPECT_EQ(info.nettype, info_copy.nettype);
EXPECT_EQ(info.top_block_hash, info_copy.top_block_hash);
EXPECT_EQ(info.wide_cumulative_difficulty, info_copy.wide_cumulative_difficulty);
EXPECT_EQ(info.cumulative_difficulty, info_copy.cumulative_difficulty);
EXPECT_EQ(info.block_size_limit, info_copy.block_size_limit);
EXPECT_EQ(info.block_weight_limit, info_copy.block_weight_limit);
EXPECT_EQ(info.block_size_median, info_copy.block_size_median);
EXPECT_EQ(info.adjusted_time, info_copy.adjusted_time);
EXPECT_EQ(info.block_weight_median, info_copy.block_weight_median);
EXPECT_EQ(info.start_time, info_copy.start_time);
EXPECT_EQ(info.version, info_copy.version);
}
TEST(JsonSerialization, MinerTransaction)
{
cryptonote::account_base acct;
+90
View File
@@ -591,6 +591,7 @@ TEST_F(levin_notify, defaulted)
const auto status = notifier.get_status();
EXPECT_FALSE(status.has_noise);
EXPECT_FALSE(status.connections_filled);
EXPECT_FALSE(status.has_outgoing);
}
EXPECT_TRUE(notifier.send_txs({}, random_generator_(), cryptonote::relay_method::local));
@@ -611,6 +612,7 @@ TEST_F(levin_notify, fluff_without_padding)
const auto status = notifier.get_status();
EXPECT_FALSE(status.has_noise);
EXPECT_FALSE(status.connections_filled);
EXPECT_TRUE(status.has_outgoing);
}
notifier.new_out_connection();
io_service_.poll();
@@ -658,6 +660,7 @@ TEST_F(levin_notify, stem_without_padding)
const auto status = notifier.get_status();
EXPECT_FALSE(status.has_noise);
EXPECT_FALSE(status.connections_filled);
EXPECT_TRUE(status.has_outgoing);
}
notifier.new_out_connection();
io_service_.poll();
@@ -731,6 +734,7 @@ TEST_F(levin_notify, stem_no_outs_without_padding)
const auto status = notifier.get_status();
EXPECT_FALSE(status.has_noise);
EXPECT_FALSE(status.connections_filled);
EXPECT_FALSE(status.has_outgoing);
}
notifier.new_out_connection();
io_service_.poll();
@@ -788,6 +792,7 @@ TEST_F(levin_notify, local_without_padding)
const auto status = notifier.get_status();
EXPECT_FALSE(status.has_noise);
EXPECT_FALSE(status.connections_filled);
EXPECT_TRUE(status.has_outgoing);
}
notifier.new_out_connection();
io_service_.poll();
@@ -897,6 +902,7 @@ TEST_F(levin_notify, forward_without_padding)
const auto status = notifier.get_status();
EXPECT_FALSE(status.has_noise);
EXPECT_FALSE(status.connections_filled);
EXPECT_TRUE(status.has_outgoing);
}
notifier.new_out_connection();
io_service_.poll();
@@ -970,6 +976,7 @@ TEST_F(levin_notify, block_without_padding)
const auto status = notifier.get_status();
EXPECT_FALSE(status.has_noise);
EXPECT_FALSE(status.connections_filled);
EXPECT_TRUE(status.has_outgoing);
}
notifier.new_out_connection();
io_service_.poll();
@@ -1000,6 +1007,7 @@ TEST_F(levin_notify, none_without_padding)
const auto status = notifier.get_status();
EXPECT_FALSE(status.has_noise);
EXPECT_FALSE(status.connections_filled);
EXPECT_TRUE(status.has_outgoing);
}
notifier.new_out_connection();
io_service_.poll();
@@ -1030,6 +1038,7 @@ TEST_F(levin_notify, fluff_with_padding)
const auto status = notifier.get_status();
EXPECT_FALSE(status.has_noise);
EXPECT_FALSE(status.connections_filled);
EXPECT_TRUE(status.has_outgoing);
}
notifier.new_out_connection();
io_service_.poll();
@@ -1077,6 +1086,7 @@ TEST_F(levin_notify, stem_with_padding)
const auto status = notifier.get_status();
EXPECT_FALSE(status.has_noise);
EXPECT_FALSE(status.connections_filled);
EXPECT_TRUE(status.has_outgoing);
}
notifier.new_out_connection();
io_service_.poll();
@@ -1145,6 +1155,7 @@ TEST_F(levin_notify, stem_no_outs_with_padding)
const auto status = notifier.get_status();
EXPECT_FALSE(status.has_noise);
EXPECT_FALSE(status.connections_filled);
EXPECT_FALSE(status.has_outgoing);
}
notifier.new_out_connection();
io_service_.poll();
@@ -1202,6 +1213,7 @@ TEST_F(levin_notify, local_with_padding)
const auto status = notifier.get_status();
EXPECT_FALSE(status.has_noise);
EXPECT_FALSE(status.connections_filled);
EXPECT_TRUE(status.has_outgoing);
}
notifier.new_out_connection();
io_service_.poll();
@@ -1303,6 +1315,7 @@ TEST_F(levin_notify, forward_with_padding)
const auto status = notifier.get_status();
EXPECT_FALSE(status.has_noise);
EXPECT_FALSE(status.connections_filled);
EXPECT_TRUE(status.has_outgoing);
}
notifier.new_out_connection();
io_service_.poll();
@@ -1371,6 +1384,7 @@ TEST_F(levin_notify, block_with_padding)
const auto status = notifier.get_status();
EXPECT_FALSE(status.has_noise);
EXPECT_FALSE(status.connections_filled);
EXPECT_TRUE(status.has_outgoing);
}
notifier.new_out_connection();
io_service_.poll();
@@ -1401,6 +1415,7 @@ TEST_F(levin_notify, none_with_padding)
const auto status = notifier.get_status();
EXPECT_FALSE(status.has_noise);
EXPECT_FALSE(status.connections_filled);
EXPECT_TRUE(status.has_outgoing);
}
notifier.new_out_connection();
io_service_.poll();
@@ -1431,6 +1446,7 @@ TEST_F(levin_notify, private_fluff_without_padding)
const auto status = notifier.get_status();
EXPECT_FALSE(status.has_noise);
EXPECT_FALSE(status.connections_filled);
EXPECT_TRUE(status.has_outgoing);
}
notifier.new_out_connection();
io_service_.poll();
@@ -1483,6 +1499,7 @@ TEST_F(levin_notify, private_stem_without_padding)
const auto status = notifier.get_status();
EXPECT_FALSE(status.has_noise);
EXPECT_FALSE(status.connections_filled);
EXPECT_TRUE(status.has_outgoing);
}
notifier.new_out_connection();
io_service_.poll();
@@ -1535,6 +1552,7 @@ TEST_F(levin_notify, private_local_without_padding)
const auto status = notifier.get_status();
EXPECT_FALSE(status.has_noise);
EXPECT_FALSE(status.connections_filled);
EXPECT_TRUE(status.has_outgoing);
}
notifier.new_out_connection();
io_service_.poll();
@@ -1587,6 +1605,7 @@ TEST_F(levin_notify, private_forward_without_padding)
const auto status = notifier.get_status();
EXPECT_FALSE(status.has_noise);
EXPECT_FALSE(status.connections_filled);
EXPECT_TRUE(status.has_outgoing);
}
notifier.new_out_connection();
io_service_.poll();
@@ -1639,6 +1658,7 @@ TEST_F(levin_notify, private_block_without_padding)
const auto status = notifier.get_status();
EXPECT_FALSE(status.has_noise);
EXPECT_FALSE(status.connections_filled);
EXPECT_TRUE(status.has_outgoing);
}
notifier.new_out_connection();
io_service_.poll();
@@ -1670,6 +1690,7 @@ TEST_F(levin_notify, private_none_without_padding)
const auto status = notifier.get_status();
EXPECT_FALSE(status.has_noise);
EXPECT_FALSE(status.connections_filled);
EXPECT_TRUE(status.has_outgoing);
}
notifier.new_out_connection();
io_service_.poll();
@@ -1700,6 +1721,7 @@ TEST_F(levin_notify, private_fluff_with_padding)
const auto status = notifier.get_status();
EXPECT_FALSE(status.has_noise);
EXPECT_FALSE(status.connections_filled);
EXPECT_TRUE(status.has_outgoing);
}
notifier.new_out_connection();
io_service_.poll();
@@ -1751,6 +1773,7 @@ TEST_F(levin_notify, private_stem_with_padding)
const auto status = notifier.get_status();
EXPECT_FALSE(status.has_noise);
EXPECT_FALSE(status.connections_filled);
EXPECT_TRUE(status.has_outgoing);
}
notifier.new_out_connection();
io_service_.poll();
@@ -1802,6 +1825,7 @@ TEST_F(levin_notify, private_local_with_padding)
const auto status = notifier.get_status();
EXPECT_FALSE(status.has_noise);
EXPECT_FALSE(status.connections_filled);
EXPECT_TRUE(status.has_outgoing);
}
notifier.new_out_connection();
io_service_.poll();
@@ -1853,6 +1877,7 @@ TEST_F(levin_notify, private_forward_with_padding)
const auto status = notifier.get_status();
EXPECT_FALSE(status.has_noise);
EXPECT_FALSE(status.connections_filled);
EXPECT_TRUE(status.has_outgoing);
}
notifier.new_out_connection();
io_service_.poll();
@@ -1904,6 +1929,7 @@ TEST_F(levin_notify, private_block_with_padding)
const auto status = notifier.get_status();
EXPECT_FALSE(status.has_noise);
EXPECT_FALSE(status.connections_filled);
EXPECT_TRUE(status.has_outgoing);
}
notifier.new_out_connection();
io_service_.poll();
@@ -1934,6 +1960,7 @@ TEST_F(levin_notify, private_none_with_padding)
const auto status = notifier.get_status();
EXPECT_FALSE(status.has_noise);
EXPECT_FALSE(status.connections_filled);
EXPECT_TRUE(status.has_outgoing);
}
notifier.new_out_connection();
io_service_.poll();
@@ -1966,6 +1993,7 @@ TEST_F(levin_notify, stem_mappings)
const auto status = notifier.get_status();
EXPECT_FALSE(status.has_noise);
EXPECT_FALSE(status.connections_filled);
EXPECT_TRUE(status.has_outgoing);
}
notifier.new_out_connection();
io_service_.poll();
@@ -2090,6 +2118,7 @@ TEST_F(levin_notify, fluff_multiple)
const auto status = notifier.get_status();
EXPECT_FALSE(status.has_noise);
EXPECT_FALSE(status.connections_filled);
EXPECT_TRUE(status.has_outgoing);
}
notifier.new_out_connection();
io_service_.poll();
@@ -2190,6 +2219,63 @@ TEST_F(levin_notify, fluff_multiple)
}
}
TEST_F(levin_notify, fluff_with_duplicate)
{
std::shared_ptr<cryptonote::levin::notify> notifier_ptr = make_notifier(0, true, false);
auto &notifier = *notifier_ptr;
for (unsigned count = 0; count < 10; ++count)
add_connection(count % 2 == 0);
{
const auto status = notifier.get_status();
EXPECT_FALSE(status.has_noise);
EXPECT_FALSE(status.connections_filled);
EXPECT_TRUE(status.has_outgoing);
}
notifier.new_out_connection();
io_service_.poll();
std::vector<cryptonote::blobdata> txs(9);
txs[0].resize(100, 'e');
txs[1].resize(100, 'e');
txs[2].resize(100, 'e');
txs[3].resize(100, 'e');
txs[4].resize(200, 'f');
txs[5].resize(200, 'f');
txs[6].resize(200, 'f');
txs[7].resize(200, 'f');
txs[8].resize(200, 'f');
ASSERT_EQ(10u, contexts_.size());
{
auto context = contexts_.begin();
EXPECT_TRUE(notifier.send_txs(txs, context->get_id(), cryptonote::relay_method::fluff));
io_service_.reset();
ASSERT_LT(0u, io_service_.poll());
notifier.run_fluff();
ASSERT_LT(0u, io_service_.poll());
EXPECT_EQ(0u, context->process_send_queue());
for (++context; context != contexts_.end(); ++context)
EXPECT_EQ(1u, context->process_send_queue());
EXPECT_EQ(txs, events_.take_relayed(cryptonote::relay_method::fluff));
std::sort(txs.begin(), txs.end());
ASSERT_EQ(9u, receiver_.notified_size());
for (unsigned count = 0; count < 9; ++count)
{
auto notification = receiver_.get_notification<cryptonote::NOTIFY_NEW_TRANSACTIONS>().second;
EXPECT_NE(txs, notification.txs);
EXPECT_EQ(notification.txs.size(), 2);
EXPECT_TRUE(notification._.empty());
EXPECT_TRUE(notification.dandelionpp_fluff);
}
}
}
TEST_F(levin_notify, noise)
{
for (unsigned count = 0; count < 10; ++count)
@@ -2206,12 +2292,14 @@ TEST_F(levin_notify, noise)
const auto status = notifier.get_status();
EXPECT_TRUE(status.has_noise);
EXPECT_FALSE(status.connections_filled);
EXPECT_FALSE(status.has_outgoing);
}
ASSERT_LT(0u, io_service_.poll());
{
const auto status = notifier.get_status();
EXPECT_TRUE(status.has_noise);
EXPECT_TRUE(status.connections_filled);
EXPECT_TRUE(status.has_outgoing);
}
notifier.run_stems();
@@ -2298,12 +2386,14 @@ TEST_F(levin_notify, noise_stem)
const auto status = notifier.get_status();
EXPECT_TRUE(status.has_noise);
EXPECT_FALSE(status.connections_filled);
EXPECT_FALSE(status.has_outgoing);
}
ASSERT_LT(0u, io_service_.poll());
{
const auto status = notifier.get_status();
EXPECT_TRUE(status.has_noise);
EXPECT_TRUE(status.connections_filled);
EXPECT_TRUE(status.has_outgoing);
}
notifier.run_stems();