aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md2
-rwxr-xr-xcontrib/gitian/gitian-build.py7
-rw-r--r--src/blockchain_db/locked_txn.h (renamed from src/cryptonote_basic/cryptonote_stat_info.h)51
-rw-r--r--src/cryptonote_basic/CMakeLists.txt1
-rw-r--r--src/cryptonote_config.h3
-rw-r--r--src/cryptonote_core/blockchain.cpp4
-rw-r--r--src/cryptonote_core/cryptonote_core.cpp11
-rw-r--r--src/cryptonote_core/cryptonote_core.h10
-rw-r--r--src/cryptonote_core/tx_pool.cpp42
-rw-r--r--src/cryptonote_core/tx_sanity_check.cpp16
-rw-r--r--src/cryptonote_core/tx_sanity_check.h6
-rw-r--r--src/cryptonote_protocol/cryptonote_protocol_handler.h3
-rw-r--r--src/cryptonote_protocol/cryptonote_protocol_handler.inl8
-rw-r--r--src/net/i2p_address.cpp3
-rw-r--r--src/net/tor_address.cpp3
-rw-r--r--src/p2p/net_node.h19
-rw-r--r--src/p2p/net_node.inl125
-rw-r--r--src/p2p/net_peerlist.h9
-rw-r--r--src/p2p/p2p_protocol_defs.h126
-rw-r--r--src/rpc/core_rpc_server.cpp2
-rw-r--r--src/simplewallet/simplewallet.cpp2
-rw-r--r--src/wallet/ringdb.cpp55
-rw-r--r--src/wallet/wallet2.cpp74
-rw-r--r--src/wallet/wallet2.h6
-rw-r--r--tests/core_proxy/core_proxy.h1
-rw-r--r--tests/unit_tests/epee_utils.cpp1
-rw-r--r--tests/unit_tests/net.cpp427
-rw-r--r--tests/unit_tests/node_server.cpp1
28 files changed, 611 insertions, 407 deletions
diff --git a/README.md b/README.md
index c46097358..0c2488068 100644
--- a/README.md
+++ b/README.md
@@ -134,7 +134,7 @@ Dates are provided in the format YYYY-MM-DD.
| 1686275 | 2018-10-19 | v9 | v0.13.0.0 | v0.13.0.4 | bulletproofs required
| 1788000 | 2019-03-09 | v10 | v0.14.0.0 | v0.14.1.2 | New PoW based on Cryptonight-R, new block weight algorithm, slightly more efficient RingCT format
| 1788720 | 2019-03-10 | v11 | v0.14.0.0 | v0.14.1.2 | forbid old RingCT transaction format
-| 1978433 | 2019-11-30* | v12 | v0.15.0.0 | v0.15.0.0 | New PoW based on RandomX, only allow >= 2 outputs, change to the block median used to calculate penalty, v1 coinbases are forbidden, rct sigs in coinbase forbidden, 10 block lock time for incoming transactions
+| 1978433 | 2019-11-30* | v12 | v0.15.0.0 | v0.15.0.0 | New PoW based on RandomX, only allow >= 2 outputs, change to the block median used to calculate penalty, v1 coinbases are forbidden, rct sigs in coinbase forbidden, 10 block lock time for incoming outputs
| XXXXXXX | XXX-XX-XX | XXX | vX.XX.X.X | vX.XX.X.X | XXX |
X's indicate that these details have not been determined as of commit date.
diff --git a/contrib/gitian/gitian-build.py b/contrib/gitian/gitian-build.py
index 491488efa..a8140a8a6 100755
--- a/contrib/gitian/gitian-build.py
+++ b/contrib/gitian/gitian-build.py
@@ -36,8 +36,11 @@ def setup():
os.chdir('..')
make_image_prog = ['bin/make-base-vm', '--suite', 'bionic', '--arch', 'amd64']
if args.docker:
- if not subprocess.call(['docker', '--help'], shell=False, stdout=subprocess.DEVNULL):
- print("Please install docker first manually")
+ try:
+ subprocess.check_output(['docker', '--help'])
+ except:
+ print("ERROR: Could not find 'docker' command. Ensure this is in your PATH.")
+ sys.exit(1)
make_image_prog += ['--docker']
elif not args.kvm:
make_image_prog += ['--lxc']
diff --git a/src/cryptonote_basic/cryptonote_stat_info.h b/src/blockchain_db/locked_txn.h
index 4cc1bc764..d14631ddb 100644
--- a/src/cryptonote_basic/cryptonote_stat_info.h
+++ b/src/blockchain_db/locked_txn.h
@@ -1,21 +1,21 @@
// Copyright (c) 2014-2019, The Monero Project
-//
+//
// All rights reserved.
-//
+//
// Redistribution and use in source and binary forms, with or without modification, are
// permitted provided that the following conditions are met:
-//
+//
// 1. Redistributions of source code must retain the above copyright notice, this list of
// conditions and the following disclaimer.
-//
+//
// 2. Redistributions in binary form must reproduce the above copyright notice, this list
// of conditions and the following disclaimer in the documentation and/or other
// materials provided with the distribution.
-//
+//
// 3. Neither the name of the copyright holder nor the names of its contributors may be
// used to endorse or promote products derived from this software without specific
// prior written permission.
-//
+//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
@@ -25,30 +25,29 @@
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-//
+//
// Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers
#pragma once
-#include "serialization/keyvalue_serialization.h"
-
namespace cryptonote
{
- struct core_stat_info_t
- {
- uint64_t tx_pool_size;
- uint64_t blockchain_height;
- uint64_t mining_speed;
- uint64_t alternative_blocks;
- std::string top_block_id_str;
-
- BEGIN_KV_SERIALIZE_MAP()
- KV_SERIALIZE(tx_pool_size)
- KV_SERIALIZE(blockchain_height)
- KV_SERIALIZE(mining_speed)
- KV_SERIALIZE(alternative_blocks)
- KV_SERIALIZE(top_block_id_str)
- END_KV_SERIALIZE_MAP()
- };
- typedef epee::misc_utils::struct_init<core_stat_info_t> core_stat_info;
+ // This class is meant to create a batch when none currently exists.
+ // If a batch exists, it can't be from another thread, since we can
+ // only be called with the txpool lock taken, and it is held during
+ // the whole prepare/handle/cleanup incoming block sequence.
+ class LockedTXN {
+ public:
+ LockedTXN(BlockchainDB &db): m_db(db), m_batch(false), m_active(false) {
+ m_batch = m_db.batch_start();
+ m_active = true;
+ }
+ void commit() { try { if (m_batch && m_active) { m_db.batch_stop(); m_active = false; } } catch (const std::exception &e) { MWARNING("LockedTXN::commit filtering exception: " << e.what()); } }
+ void abort() { try { if (m_batch && m_active) { m_db.batch_abort(); m_active = false; } } catch (const std::exception &e) { MWARNING("LockedTXN::abort filtering exception: " << e.what()); } }
+ ~LockedTXN() { abort(); }
+ private:
+ BlockchainDB &m_db;
+ bool m_batch;
+ bool m_active;
+ };
}
diff --git a/src/cryptonote_basic/CMakeLists.txt b/src/cryptonote_basic/CMakeLists.txt
index 5bb56e083..59040d8a2 100644
--- a/src/cryptonote_basic/CMakeLists.txt
+++ b/src/cryptonote_basic/CMakeLists.txt
@@ -54,7 +54,6 @@ set(cryptonote_basic_private_headers
cryptonote_basic_impl.h
cryptonote_boost_serialization.h
cryptonote_format_utils.h
- cryptonote_stat_info.h
difficulty.h
hardfork.h
miner.h
diff --git a/src/cryptonote_config.h b/src/cryptonote_config.h
index 134b630f7..4598baad7 100644
--- a/src/cryptonote_config.h
+++ b/src/cryptonote_config.h
@@ -144,8 +144,6 @@
#define RPC_IP_FAILS_BEFORE_BLOCK 3
-#define ALLOW_DEBUG_COMMANDS
-
#define CRYPTONOTE_NAME "bitmonero"
#define CRYPTONOTE_POOLDATA_FILENAME "poolstate.bin"
#define CRYPTONOTE_BLOCKCHAINDATA_FILENAME "data.mdb"
@@ -193,7 +191,6 @@ namespace config
uint8_t const FEE_CALCULATION_MAX_RETRIES = 10;
uint64_t const DEFAULT_DUST_THRESHOLD = ((uint64_t)2000000000); // 2 * pow(10, 9)
uint64_t const BASE_REWARD_CLAMP_THRESHOLD = ((uint64_t)100000000); // pow(10, 8)
- std::string const P2P_REMOTE_DEBUG_TRUSTED_PUB_KEY = "0000000000000000000000000000000000000000000000000000000000000000";
uint64_t const CRYPTONOTE_PUBLIC_ADDRESS_BASE58_PREFIX = 18;
uint64_t const CRYPTONOTE_PUBLIC_INTEGRATED_ADDRESS_BASE58_PREFIX = 19;
diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp
index a8683a531..5578f519e 100644
--- a/src/cryptonote_core/blockchain.cpp
+++ b/src/cryptonote_core/blockchain.cpp
@@ -3423,7 +3423,7 @@ bool Blockchain::check_fee(size_t tx_weight, uint64_t fee) const
if (version >= HF_VERSION_PER_BYTE_FEE)
{
const bool use_long_term_median_in_fee = version >= HF_VERSION_LONG_TERM_BLOCK_WEIGHT;
- uint64_t fee_per_byte = get_dynamic_base_fee(base_reward, use_long_term_median_in_fee ? m_long_term_effective_median_block_weight : median, version);
+ uint64_t fee_per_byte = get_dynamic_base_fee(base_reward, use_long_term_median_in_fee ? std::min<uint64_t>(median, m_long_term_effective_median_block_weight) : median, version);
MDEBUG("Using " << print_money(fee_per_byte) << "/byte fee");
needed_fee = tx_weight * fee_per_byte;
// quantize fee up to 8 decimals
@@ -3481,7 +3481,7 @@ uint64_t Blockchain::get_dynamic_base_fee_estimate(uint64_t grace_blocks) const
uint64_t already_generated_coins = db_height ? m_db->get_block_already_generated_coins(db_height - 1) : 0;
uint64_t base_reward;
- if (!get_block_reward(median, 1, already_generated_coins, base_reward, version))
+ if (!get_block_reward(m_current_block_cumul_weight_limit / 2, 1, already_generated_coins, base_reward, version))
{
MERROR("Failed to determine block reward, using placeholder " << print_money(BLOCK_REWARD_OVERESTIMATE) << " as a high bound");
base_reward = BLOCK_REWARD_OVERESTIMATE;
diff --git a/src/cryptonote_core/cryptonote_core.cpp b/src/cryptonote_core/cryptonote_core.cpp
index de60367e6..212616af8 100644
--- a/src/cryptonote_core/cryptonote_core.cpp
+++ b/src/cryptonote_core/cryptonote_core.cpp
@@ -1056,17 +1056,6 @@ namespace cryptonote
return handle_incoming_txs({std::addressof(tx_blob), 1}, {std::addressof(tvc), 1}, tx_relay, relayed);
}
//-----------------------------------------------------------------------------------------------
- bool core::get_stat_info(core_stat_info& st_inf) const
- {
- st_inf.mining_speed = m_miner.get_speed();
- st_inf.alternative_blocks = m_blockchain_storage.get_alternative_blocks_count();
- st_inf.blockchain_height = m_blockchain_storage.get_current_blockchain_height();
- st_inf.tx_pool_size = m_mempool.get_transactions_count();
- st_inf.top_block_id_str = epee::string_tools::pod_to_hex(m_blockchain_storage.get_tail_id());
- return true;
- }
-
- //-----------------------------------------------------------------------------------------------
bool core::check_tx_semantic(const transaction& tx, bool keeped_by_block) const
{
if(!tx.vin.size())
diff --git a/src/cryptonote_core/cryptonote_core.h b/src/cryptonote_core/cryptonote_core.h
index 6fb2f68ab..79a846de1 100644
--- a/src/cryptonote_core/cryptonote_core.h
+++ b/src/cryptonote_core/cryptonote_core.h
@@ -45,7 +45,6 @@
#include "blockchain.h"
#include "cryptonote_basic/miner.h"
#include "cryptonote_basic/connection_context.h"
-#include "cryptonote_basic/cryptonote_stat_info.h"
#include "warnings.h"
#include "crypto/hash.h"
#include "span.h"
@@ -556,15 +555,6 @@ namespace cryptonote
bool find_blockchain_supplement(const uint64_t req_start_block, const std::list<crypto::hash>& qblock_ids, std::vector<std::pair<std::pair<cryptonote::blobdata, crypto::hash>, std::vector<std::pair<crypto::hash, cryptonote::blobdata> > > >& blocks, uint64_t& total_height, uint64_t& start_height, bool pruned, bool get_miner_tx_hash, size_t max_count) const;
/**
- * @brief gets some stats about the daemon
- *
- * @param st_inf return-by-reference container for the stats requested
- *
- * @return true
- */
- bool get_stat_info(core_stat_info& st_inf) const;
-
- /**
* @copydoc Blockchain::get_tx_outputs_gindexs
*
* @note see Blockchain::get_tx_outputs_gindexs
diff --git a/src/cryptonote_core/tx_pool.cpp b/src/cryptonote_core/tx_pool.cpp
index 8c8e43c90..05cbf14a8 100644
--- a/src/cryptonote_core/tx_pool.cpp
+++ b/src/cryptonote_core/tx_pool.cpp
@@ -38,6 +38,7 @@
#include "cryptonote_basic/cryptonote_boost_serialization.h"
#include "cryptonote_config.h"
#include "blockchain.h"
+#include "blockchain_db/locked_txn.h"
#include "blockchain_db/blockchain_db.h"
#include "common/boost_serialization_helper.h"
#include "int-util.h"
@@ -88,25 +89,6 @@ namespace cryptonote
else
return get_min_block_weight(version) - CRYPTONOTE_COINBASE_BLOB_RESERVED_SIZE;
}
-
- // This class is meant to create a batch when none currently exists.
- // If a batch exists, it can't be from another thread, since we can
- // only be called with the txpool lock taken, and it is held during
- // the whole prepare/handle/cleanup incoming block sequence.
- class LockedTXN {
- public:
- LockedTXN(Blockchain &b): m_blockchain(b), m_batch(false), m_active(false) {
- m_batch = m_blockchain.get_db().batch_start();
- m_active = true;
- }
- void commit() { try { if (m_batch && m_active) { m_blockchain.get_db().batch_stop(); m_active = false; } } catch (const std::exception &e) { MWARNING("LockedTXN::commit filtering exception: " << e.what()); } }
- void abort() { try { if (m_batch && m_active) { m_blockchain.get_db().batch_abort(); m_active = false; } } catch (const std::exception &e) { MWARNING("LockedTXN::abort filtering exception: " << e.what()); } }
- ~LockedTXN() { abort(); }
- private:
- Blockchain &m_blockchain;
- bool m_batch;
- bool m_active;
- };
}
//---------------------------------------------------------------------------------
//---------------------------------------------------------------------------------
@@ -256,7 +238,7 @@ namespace cryptonote
if (kept_by_block)
m_parsed_tx_cache.insert(std::make_pair(id, tx));
CRITICAL_REGION_LOCAL1(m_blockchain);
- LockedTXN lock(m_blockchain);
+ LockedTXN lock(m_blockchain.get_db());
if (!insert_key_images(tx, id, tx_relay))
return false;
@@ -301,7 +283,7 @@ namespace cryptonote
if (kept_by_block)
m_parsed_tx_cache.insert(std::make_pair(id, tx));
CRITICAL_REGION_LOCAL1(m_blockchain);
- LockedTXN lock(m_blockchain);
+ LockedTXN lock(m_blockchain.get_db());
m_blockchain.remove_txpool_tx(id);
if (!insert_key_images(tx, id, tx_relay))
return false;
@@ -362,7 +344,7 @@ namespace cryptonote
if (bytes == 0)
bytes = m_txpool_max_weight;
CRITICAL_REGION_LOCAL1(m_blockchain);
- LockedTXN lock(m_blockchain);
+ LockedTXN lock(m_blockchain.get_db());
bool changed = false;
// this will never remove the first one, but we don't care
@@ -494,7 +476,7 @@ namespace cryptonote
try
{
- LockedTXN lock(m_blockchain);
+ LockedTXN lock(m_blockchain.get_db());
txpool_tx_meta_t meta;
if (!m_blockchain.get_txpool_tx_meta(id, meta))
{
@@ -549,7 +531,7 @@ namespace cryptonote
try
{
- LockedTXN lock(m_blockchain);
+ LockedTXN lock(m_blockchain.get_db());
txpool_tx_meta_t meta;
if (!m_blockchain.get_txpool_tx_meta(txid, meta))
{
@@ -671,7 +653,7 @@ namespace cryptonote
if (!remove.empty())
{
- LockedTXN lock(m_blockchain);
+ LockedTXN lock(m_blockchain.get_db());
for (const std::pair<crypto::hash, uint64_t> &entry: remove)
{
const crypto::hash &txid = entry.first;
@@ -742,7 +724,7 @@ namespace cryptonote
CRITICAL_REGION_LOCAL(m_transactions_lock);
CRITICAL_REGION_LOCAL1(m_blockchain);
const time_t now = time(NULL);
- LockedTXN lock(m_blockchain);
+ LockedTXN lock(m_blockchain.get_db());
for (const auto& hash : hashes)
{
try
@@ -1219,7 +1201,7 @@ namespace cryptonote
CRITICAL_REGION_LOCAL(m_transactions_lock);
CRITICAL_REGION_LOCAL1(m_blockchain);
bool changed = false;
- LockedTXN lock(m_blockchain);
+ LockedTXN lock(m_blockchain.get_db());
for(size_t i = 0; i!= tx.vin.size(); i++)
{
CHECKED_GET_SPECIFIC_VARIANT(tx.vin[i], const txin_to_key, itk, void());
@@ -1311,7 +1293,7 @@ namespace cryptonote
LOG_PRINT_L2("Filling block template, median weight " << median_weight << ", " << m_txs_by_fee_and_receive_time.size() << " txes in the pool");
- LockedTXN lock(m_blockchain);
+ LockedTXN lock(m_blockchain.get_db());
auto sorted_it = m_txs_by_fee_and_receive_time.begin();
for (; sorted_it != m_txs_by_fee_and_receive_time.end(); ++sorted_it)
@@ -1448,7 +1430,7 @@ namespace cryptonote
size_t n_removed = 0;
if (!remove.empty())
{
- LockedTXN lock(m_blockchain);
+ LockedTXN lock(m_blockchain.get_db());
for (const crypto::hash &txid: remove)
{
try
@@ -1528,7 +1510,7 @@ namespace cryptonote
}
if (!remove.empty())
{
- LockedTXN lock(m_blockchain);
+ LockedTXN lock(m_blockchain.get_db());
for (const auto &txid: remove)
{
try
diff --git a/src/cryptonote_core/tx_sanity_check.cpp b/src/cryptonote_core/tx_sanity_check.cpp
index 03cbb5c26..e99982def 100644
--- a/src/cryptonote_core/tx_sanity_check.cpp
+++ b/src/cryptonote_core/tx_sanity_check.cpp
@@ -28,7 +28,7 @@
#include <stdint.h>
#include <vector>
-#include "cryptonote_basic/cryptonote_basic_impl.h"
+#include "cryptonote_basic/cryptonote_basic.h"
#include "cryptonote_basic/cryptonote_format_utils.h"
#include "blockchain.h"
#include "tx_sanity_check.h"
@@ -39,7 +39,7 @@
namespace cryptonote
{
-bool tx_sanity_check(Blockchain &blockchain, const cryptonote::blobdata &tx_blob)
+bool tx_sanity_check(const cryptonote::blobdata &tx_blob, uint64_t rct_outs_available)
{
cryptonote::transaction tx;
@@ -70,14 +70,18 @@ bool tx_sanity_check(Blockchain &blockchain, const cryptonote::blobdata &tx_blob
n_indices += in_to_key.key_offsets.size();
}
+ return tx_sanity_check(rct_indices, n_indices, rct_outs_available);
+}
+
+bool tx_sanity_check(const std::set<uint64_t> &rct_indices, size_t n_indices, uint64_t rct_outs_available)
+{
if (n_indices <= 10)
{
MDEBUG("n_indices is only " << n_indices << ", not checking");
return true;
}
- uint64_t n_available = blockchain.get_num_mature_outputs(0);
- if (n_available < 10000)
+ if (rct_outs_available < 10000)
return true;
if (rct_indices.size() < n_indices * 8 / 10)
@@ -88,9 +92,9 @@ bool tx_sanity_check(Blockchain &blockchain, const cryptonote::blobdata &tx_blob
std::vector<uint64_t> offsets(rct_indices.begin(), rct_indices.end());
uint64_t median = epee::misc_utils::median(offsets);
- if (median < n_available * 6 / 10)
+ if (median < rct_outs_available * 6 / 10)
{
- MERROR("median offset index is too low (median is " << median << " out of total " << n_available << "offsets). Transactions should contain a higher fraction of recent outputs.");
+ MERROR("median offset index is too low (median is " << median << " out of total " << rct_outs_available << "offsets). Transactions should contain a higher fraction of recent outputs.");
return false;
}
diff --git a/src/cryptonote_core/tx_sanity_check.h b/src/cryptonote_core/tx_sanity_check.h
index c12d1b0b1..4a469462f 100644
--- a/src/cryptonote_core/tx_sanity_check.h
+++ b/src/cryptonote_core/tx_sanity_check.h
@@ -26,11 +26,11 @@
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#include <set>
#include "cryptonote_basic/blobdatatype.h"
namespace cryptonote
{
- class Blockchain;
-
- bool tx_sanity_check(Blockchain &blockchain, const cryptonote::blobdata &tx_blob);
+ bool tx_sanity_check(const cryptonote::blobdata &tx_blob, uint64_t rct_outs_available);
+ bool tx_sanity_check(const std::set<uint64_t> &rct_indices, size_t n_indices, uint64_t rct_outs_available);
}
diff --git a/src/cryptonote_protocol/cryptonote_protocol_handler.h b/src/cryptonote_protocol/cryptonote_protocol_handler.h
index c6aa2b71b..2664716a8 100644
--- a/src/cryptonote_protocol/cryptonote_protocol_handler.h
+++ b/src/cryptonote_protocol/cryptonote_protocol_handler.h
@@ -45,7 +45,6 @@
#include "block_queue.h"
#include "common/perf_timer.h"
#include "cryptonote_basic/connection_context.h"
-#include "cryptonote_basic/cryptonote_stat_info.h"
#include <boost/circular_buffer.hpp>
PUSH_WARNINGS
@@ -77,7 +76,6 @@ namespace cryptonote
{
public:
typedef cryptonote_connection_context connection_context;
- typedef core_stat_info stat_info;
typedef t_cryptonote_protocol_handler<t_core> cryptonote_protocol_handler;
typedef CORE_SYNC_DATA payload_type;
@@ -103,7 +101,6 @@ namespace cryptonote
bool process_payload_sync_data(const CORE_SYNC_DATA& hshd, cryptonote_connection_context& context, bool is_inital);
bool get_payload_sync_data(blobdata& data);
bool get_payload_sync_data(CORE_SYNC_DATA& hshd);
- bool get_stat_info(core_stat_info& stat_inf);
bool on_callback(cryptonote_connection_context& context);
t_core& get_core(){return m_core;}
bool is_synchronized(){return m_synchronized;}
diff --git a/src/cryptonote_protocol/cryptonote_protocol_handler.inl b/src/cryptonote_protocol/cryptonote_protocol_handler.inl
index aad43c586..3aacce421 100644
--- a/src/cryptonote_protocol/cryptonote_protocol_handler.inl
+++ b/src/cryptonote_protocol/cryptonote_protocol_handler.inl
@@ -155,12 +155,6 @@ namespace cryptonote
}
//------------------------------------------------------------------------------------------------------------------------
template<class t_core>
- bool t_cryptonote_protocol_handler<t_core>::get_stat_info(core_stat_info& stat_inf)
- {
- return m_core.get_stat_info(stat_inf);
- }
- //------------------------------------------------------------------------------------------------------------------------
- template<class t_core>
void t_cryptonote_protocol_handler<t_core>::log_connections()
{
std::stringstream ss;
@@ -345,7 +339,7 @@ namespace cryptonote
if(m_core.have_block(hshd.top_id))
{
context.m_state = cryptonote_connection_context::state_normal;
- if(is_inital && target == m_core.get_current_blockchain_height())
+ if(is_inital && hshd.current_height >= target && target == m_core.get_current_blockchain_height())
on_connection_synchronized();
return true;
}
diff --git a/src/net/i2p_address.cpp b/src/net/i2p_address.cpp
index cba829d3f..f4cc75fee 100644
--- a/src/net/i2p_address.cpp
+++ b/src/net/i2p_address.cpp
@@ -171,7 +171,8 @@ namespace net
bool i2p_address::less(const i2p_address& rhs) const noexcept
{
- return std::strcmp(host_str(), rhs.host_str()) < 0 || port() < rhs.port();
+ int res = std::strcmp(host_str(), rhs.host_str());
+ return res < 0 || (res == 0 && port() < rhs.port());
}
bool i2p_address::is_same_host(const i2p_address& rhs) const noexcept
diff --git a/src/net/tor_address.cpp b/src/net/tor_address.cpp
index 904a9a0fc..4414861e7 100644
--- a/src/net/tor_address.cpp
+++ b/src/net/tor_address.cpp
@@ -173,7 +173,8 @@ namespace net
bool tor_address::less(const tor_address& rhs) const noexcept
{
- return std::strcmp(host_str(), rhs.host_str()) < 0 || port() < rhs.port();
+ int res = std::strcmp(host_str(), rhs.host_str());
+ return res < 0 || (res == 0 && port() < rhs.port());
}
bool tor_address::is_same_host(const tor_address& rhs) const noexcept
diff --git a/src/p2p/net_node.h b/src/p2p/net_node.h
index 9b9ffbe2a..31d8aad3f 100644
--- a/src/p2p/net_node.h
+++ b/src/p2p/net_node.h
@@ -301,8 +301,6 @@ namespace nodetool
bool islimitup=false;
bool islimitdown=false;
- typedef COMMAND_REQUEST_STAT_INFO_T<typename t_payload_net_handler::stat_info> COMMAND_REQUEST_STAT_INFO;
-
CHAIN_LEVIN_INVOKE_MAP2(p2p_connection_context); //move levin_commands_handler interface invoke(...) callbacks into invoke map
CHAIN_LEVIN_NOTIFY_MAP2(p2p_connection_context); //move levin_commands_handler interface notify(...) callbacks into nothing
@@ -313,11 +311,6 @@ namespace nodetool
HANDLE_INVOKE_T2(COMMAND_HANDSHAKE, &node_server::handle_handshake)
HANDLE_INVOKE_T2(COMMAND_TIMED_SYNC, &node_server::handle_timed_sync)
HANDLE_INVOKE_T2(COMMAND_PING, &node_server::handle_ping)
-#ifdef ALLOW_DEBUG_COMMANDS
- HANDLE_INVOKE_T2(COMMAND_REQUEST_STAT_INFO, &node_server::handle_get_stat_info)
- HANDLE_INVOKE_T2(COMMAND_REQUEST_NETWORK_STATE, &node_server::handle_get_network_state)
- HANDLE_INVOKE_T2(COMMAND_REQUEST_PEER_ID, &node_server::handle_get_peer_id)
-#endif
HANDLE_INVOKE_T2(COMMAND_REQUEST_SUPPORT_FLAGS, &node_server::handle_get_support_flags)
CHAIN_INVOKE_MAP_TO_OBJ_FORCE_CONTEXT(m_payload_handler, typename t_payload_net_handler::connection_context&)
END_INVOKE_MAP2()
@@ -328,17 +321,11 @@ namespace nodetool
int handle_handshake(int command, typename COMMAND_HANDSHAKE::request& arg, typename COMMAND_HANDSHAKE::response& rsp, p2p_connection_context& context);
int handle_timed_sync(int command, typename COMMAND_TIMED_SYNC::request& arg, typename COMMAND_TIMED_SYNC::response& rsp, p2p_connection_context& context);
int handle_ping(int command, COMMAND_PING::request& arg, COMMAND_PING::response& rsp, p2p_connection_context& context);
-#ifdef ALLOW_DEBUG_COMMANDS
- int handle_get_stat_info(int command, typename COMMAND_REQUEST_STAT_INFO::request& arg, typename COMMAND_REQUEST_STAT_INFO::response& rsp, p2p_connection_context& context);
- int handle_get_network_state(int command, COMMAND_REQUEST_NETWORK_STATE::request& arg, COMMAND_REQUEST_NETWORK_STATE::response& rsp, p2p_connection_context& context);
- int handle_get_peer_id(int command, COMMAND_REQUEST_PEER_ID::request& arg, COMMAND_REQUEST_PEER_ID::response& rsp, p2p_connection_context& context);
-#endif
int handle_get_support_flags(int command, COMMAND_REQUEST_SUPPORT_FLAGS::request& arg, COMMAND_REQUEST_SUPPORT_FLAGS::response& rsp, p2p_connection_context& context);
bool init_config();
bool make_default_peer_id();
bool make_default_config();
bool store_config();
- bool check_trust(const proof_of_trust& tr, epee::net_utils::zone zone_type);
//----------------- levin_commands_handler -------------------------------------------------------------
@@ -393,7 +380,7 @@ namespace nodetool
bool try_ping(basic_node_data& node_data, p2p_connection_context& context, const t_callback &cb);
bool try_get_support_flags(const p2p_connection_context& context, std::function<void(p2p_connection_context&, const uint32_t&)> f);
bool make_expected_connections_count(network_zone& zone, PeerType peer_type, size_t expected_connections);
- void cache_connect_fail_info(const epee::net_utils::network_address& addr);
+ void record_addr_failed(const epee::net_utils::network_address& addr);
bool is_addr_recently_failed(const epee::net_utils::network_address& addr);
bool is_priority_node(const epee::net_utils::network_address& na);
std::set<std::string> get_seed_nodes(cryptonote::network_type nettype) const;
@@ -414,7 +401,6 @@ namespace nodetool
bool set_rate_limit(const boost::program_options::variables_map& vm, int64_t limit);
bool has_too_many_connections(const epee::net_utils::network_address &address);
- uint64_t get_connections_count();
size_t get_incoming_connections_count();
size_t get_incoming_connections_count(network_zone&);
size_t get_outgoing_connections_count();
@@ -478,9 +464,6 @@ namespace nodetool
epee::math_helper::once_a_time_seconds<60> m_gray_peerlist_housekeeping_interval;
epee::math_helper::once_a_time_seconds<3600, false> m_incoming_connections_interval;
-#ifdef ALLOW_DEBUG_COMMANDS
- uint64_t m_last_stat_request_time;
-#endif
std::list<epee::net_utils::network_address> m_priority_peers;
std::vector<epee::net_utils::network_address> m_exclusive_peers;
std::vector<epee::net_utils::network_address> m_seed_nodes;
diff --git a/src/p2p/net_node.inl b/src/p2p/net_node.inl
index 6a02d31b5..9b6358dee 100644
--- a/src/p2p/net_node.inl
+++ b/src/p2p/net_node.inl
@@ -813,7 +813,6 @@ namespace nodetool
//only in case if we really sure that we have external visible ip
m_have_address = true;
- m_last_stat_request_time = 0;
//configure self
@@ -940,15 +939,6 @@ namespace nodetool
}
//-----------------------------------------------------------------------------------
template<class t_payload_net_handler>
- uint64_t node_server<t_payload_net_handler>::get_connections_count()
- {
- std::uint64_t count = 0;
- for (auto& zone : m_network_zones)
- count += zone.second.m_net_server.get_config_object().get_connections_count();
- return count;
- }
- //-----------------------------------------------------------------------------------
- template<class t_payload_net_handler>
bool node_server<t_payload_net_handler>::deinit()
{
kill();
@@ -1262,7 +1252,7 @@ namespace nodetool
bool is_priority = is_priority_node(na);
LOG_PRINT_CC_PRIORITY_NODE(is_priority, bool(con), "Connect failed to " << na.str()
/*<< ", try " << try_count*/);
- //m_peerlist.set_peer_unreachable(pe);
+ record_addr_failed(na);
return false;
}
@@ -1277,6 +1267,7 @@ namespace nodetool
<< na.str()
/*<< ", try " << try_count*/);
zone.m_net_server.get_config_object().close(con->m_connection_id);
+ record_addr_failed(na);
return false;
}
@@ -1327,6 +1318,7 @@ namespace nodetool
bool is_priority = is_priority_node(na);
LOG_PRINT_CC_PRIORITY_NODE(is_priority, p2p_connection_context{}, "Connect failed to " << na.str());
+ record_addr_failed(na);
return false;
}
@@ -1339,6 +1331,7 @@ namespace nodetool
LOG_PRINT_CC_PRIORITY_NODE(is_priority, *con, "Failed to HANDSHAKE with peer " << na.str());
zone.m_net_server.get_config_object().close(con->m_connection_id);
+ record_addr_failed(na);
return false;
}
@@ -1353,6 +1346,13 @@ namespace nodetool
//-----------------------------------------------------------------------------------
template<class t_payload_net_handler>
+ void node_server<t_payload_net_handler>::record_addr_failed(const epee::net_utils::network_address& addr)
+ {
+ CRITICAL_REGION_LOCAL(m_conn_fails_cache_lock);
+ m_conn_fails_cache[addr.host_str()] = time(NULL);
+ }
+ //-----------------------------------------------------------------------------------
+ template<class t_payload_net_handler>
bool node_server<t_payload_net_handler>::is_addr_recently_failed(const epee::net_utils::network_address& addr)
{
CRITICAL_REGION_LOCAL(m_conn_fails_cache_lock);
@@ -1434,10 +1434,10 @@ namespace nodetool
std::deque<size_t> filtered;
const size_t limit = use_white_list ? 20 : std::numeric_limits<size_t>::max();
- size_t idx = 0, skipped = 0;
for (int step = 0; step < 2; ++step)
{
bool skip_duplicate_class_B = step == 0;
+ size_t idx = 0, skipped = 0;
zone.m_peerlist.foreach (use_white_list, [&classB, &filtered, &idx, &skipped, skip_duplicate_class_B, limit, next_needed_pruning_stripe](const peerlist_entry &pe){
if (filtered.size() >= limit)
return false;
@@ -1543,6 +1543,7 @@ namespace nodetool
return true;
size_t try_count = 0;
+ bool is_connected_to_at_least_one_seed_node = false;
size_t current_index = crypto::rand_idx(m_seed_nodes.size());
const net_server& server = m_network_zones.at(epee::net_utils::zone::public_).m_net_server;
while(true)
@@ -1550,21 +1551,25 @@ namespace nodetool
if(server.is_stop_signal_sent())
return false;
- if(try_to_connect_and_handshake_with_new_peer(m_seed_nodes[current_index], true))
+ peerlist_entry pe_seed{};
+ pe_seed.adr = m_seed_nodes[current_index];
+ if (is_peer_used(pe_seed))
+ is_connected_to_at_least_one_seed_node = true;
+ else if (try_to_connect_and_handshake_with_new_peer(m_seed_nodes[current_index], true))
break;
if(++try_count > m_seed_nodes.size())
{
if (!m_fallback_seed_nodes_added)
{
MWARNING("Failed to connect to any of seed peers, trying fallback seeds");
- current_index = m_seed_nodes.size();
+ current_index = m_seed_nodes.size() - 1;
for (const auto &peer: get_seed_nodes(m_nettype))
{
MDEBUG("Fallback seed node: " << peer);
append_net_address(m_seed_nodes, peer, cryptonote::get_config(m_nettype).P2P_DEFAULT_PORT);
}
m_fallback_seed_nodes_added = true;
- if (current_index == m_seed_nodes.size())
+ if (current_index == m_seed_nodes.size() - 1)
{
MWARNING("No fallback seeds, continuing without seeds");
break;
@@ -1573,7 +1578,8 @@ namespace nodetool
}
else
{
- MWARNING("Failed to connect to any of seed peers, continuing without seeds");
+ if (!is_connected_to_at_least_one_seed_node)
+ MWARNING("Failed to connect to any of seed peers, continuing without seeds");
break;
}
}
@@ -1912,7 +1918,7 @@ namespace nodetool
LOG_DEBUG_CC(context, "REMOTE PEERLIST: remote peerlist size=" << peerlist_.size());
LOG_TRACE_CC(context, "REMOTE PEERLIST: " << ENDL << print_peerlist_to_string(peerlist_));
- return m_network_zones.at(context.m_remote_address.get_zone()).m_peerlist.merge_peerlist(peerlist_);
+ return m_network_zones.at(context.m_remote_address.get_zone()).m_peerlist.merge_peerlist(peerlist_, [this](const peerlist_entry &pe) { return !is_addr_recently_failed(pe.adr); });
}
//-----------------------------------------------------------------------------------
template<class t_payload_net_handler>
@@ -1929,91 +1935,6 @@ namespace nodetool
return true;
}
//-----------------------------------------------------------------------------------
-#ifdef ALLOW_DEBUG_COMMANDS
- template<class t_payload_net_handler>
- bool node_server<t_payload_net_handler>::check_trust(const proof_of_trust& tr, const epee::net_utils::zone zone_type)
- {
- uint64_t local_time = time(NULL);
- uint64_t time_delata = local_time > tr.time ? local_time - tr.time: tr.time - local_time;
- if(time_delata > 24*60*60 )
- {
- MWARNING("check_trust failed to check time conditions, local_time=" << local_time << ", proof_time=" << tr.time);
- return false;
- }
- if(m_last_stat_request_time >= tr.time )
- {
- MWARNING("check_trust failed to check time conditions, last_stat_request_time=" << m_last_stat_request_time << ", proof_time=" << tr.time);
- return false;
- }
-
- const network_zone& zone = m_network_zones.at(zone_type);
- if(zone.m_config.m_peer_id != tr.peer_id)
- {
- MWARNING("check_trust failed: peer_id mismatch (passed " << tr.peer_id << ", expected " << peerid_to_string(zone.m_config.m_peer_id) << ")");
- return false;
- }
- crypto::public_key pk = AUTO_VAL_INIT(pk);
- epee::string_tools::hex_to_pod(::config::P2P_REMOTE_DEBUG_TRUSTED_PUB_KEY, pk);
- crypto::hash h = get_proof_of_trust_hash(tr);
- if(!crypto::check_signature(h, pk, tr.sign))
- {
- MWARNING("check_trust failed: sign check failed");
- return false;
- }
- //update last request time
- m_last_stat_request_time = tr.time;
- return true;
- }
- //-----------------------------------------------------------------------------------
- template<class t_payload_net_handler>
- int node_server<t_payload_net_handler>::handle_get_stat_info(int command, typename COMMAND_REQUEST_STAT_INFO::request& arg, typename COMMAND_REQUEST_STAT_INFO::response& rsp, p2p_connection_context& context)
- {
- if(!check_trust(arg.tr, context.m_remote_address.get_zone()))
- {
- drop_connection(context);
- return 1;
- }
- rsp.connections_count = get_connections_count();
- rsp.incoming_connections_count = rsp.connections_count - get_outgoing_connections_count();
- rsp.version = MONERO_VERSION_FULL;
- rsp.os_version = tools::get_os_version_string();
- m_payload_handler.get_stat_info(rsp.payload_info);
- return 1;
- }
- //-----------------------------------------------------------------------------------
- template<class t_payload_net_handler>
- int node_server<t_payload_net_handler>::handle_get_network_state(int command, COMMAND_REQUEST_NETWORK_STATE::request& arg, COMMAND_REQUEST_NETWORK_STATE::response& rsp, p2p_connection_context& context)
- {
- if(!check_trust(arg.tr, context.m_remote_address.get_zone()))
- {
- drop_connection(context);
- return 1;
- }
- m_network_zones.at(epee::net_utils::zone::public_).m_net_server.get_config_object().foreach_connection([&](const p2p_connection_context& cntxt)
- {
- connection_entry ce;
- ce.adr = cntxt.m_remote_address;
- ce.id = cntxt.peer_id;
- ce.is_income = cntxt.m_is_income;
- rsp.connections_list.push_back(ce);
- return true;
- });
-
- network_zone& zone = m_network_zones.at(context.m_remote_address.get_zone());
- zone.m_peerlist.get_peerlist(rsp.local_peerlist_gray, rsp.local_peerlist_white);
- rsp.my_id = zone.m_config.m_peer_id;
- rsp.local_time = time(NULL);
- return 1;
- }
- //-----------------------------------------------------------------------------------
- template<class t_payload_net_handler>
- int node_server<t_payload_net_handler>::handle_get_peer_id(int command, COMMAND_REQUEST_PEER_ID::request& arg, COMMAND_REQUEST_PEER_ID::response& rsp, p2p_connection_context& context)
- {
- rsp.my_id = m_network_zones.at(context.m_remote_address.get_zone()).m_config.m_peer_id;
- return 1;
- }
-#endif
- //-----------------------------------------------------------------------------------
template<class t_payload_net_handler>
int node_server<t_payload_net_handler>::handle_get_support_flags(int command, COMMAND_REQUEST_SUPPORT_FLAGS::request& arg, COMMAND_REQUEST_SUPPORT_FLAGS::response& rsp, p2p_connection_context& context)
{
diff --git a/src/p2p/net_peerlist.h b/src/p2p/net_peerlist.h
index 8225ad2fa..300181bbb 100644
--- a/src/p2p/net_peerlist.h
+++ b/src/p2p/net_peerlist.h
@@ -43,6 +43,7 @@
#include <boost/range/adaptor/reversed.hpp>
+#include "crypto/crypto.h"
#include "cryptonote_config.h"
#include "net/enums.h"
#include "net/local_ip.h"
@@ -101,7 +102,7 @@ namespace nodetool
bool init(peerlist_types&& peers, bool allow_local_ip);
size_t get_white_peers_count(){CRITICAL_REGION_LOCAL(m_peerlist_lock); return m_peers_white.size();}
size_t get_gray_peers_count(){CRITICAL_REGION_LOCAL(m_peerlist_lock); return m_peers_gray.size();}
- bool merge_peerlist(const std::vector<peerlist_entry>& outer_bs);
+ bool merge_peerlist(const std::vector<peerlist_entry>& outer_bs, const std::function<bool(const peerlist_entry&)> &f = NULL);
bool get_peerlist_head(std::vector<peerlist_entry>& bs_head, bool anonymize, uint32_t depth = P2P_DEFAULT_PEERS_IN_HANDSHAKE);
void get_peerlist(std::vector<peerlist_entry>& pl_gray, std::vector<peerlist_entry>& pl_white);
void get_peerlist(peerlist_types& peers);
@@ -112,7 +113,6 @@ namespace nodetool
bool append_with_peer_gray(const peerlist_entry& pr);
bool append_with_peer_anchor(const anchor_peerlist_entry& ple);
bool set_peer_just_seen(peerid_type peer, const epee::net_utils::network_address& addr, uint32_t pruning_seed, uint16_t rpc_port, uint32_t rpc_credits_per_hash);
- bool set_peer_unreachable(const peerlist_entry& pr);
bool is_host_allowed(const epee::net_utils::network_address &address);
bool get_random_gray_peer(peerlist_entry& pe);
bool remove_from_peer_gray(const peerlist_entry& pe);
@@ -213,12 +213,13 @@ namespace nodetool
}
//--------------------------------------------------------------------------------------------------
inline
- bool peerlist_manager::merge_peerlist(const std::vector<peerlist_entry>& outer_bs)
+ bool peerlist_manager::merge_peerlist(const std::vector<peerlist_entry>& outer_bs, const std::function<bool(const peerlist_entry&)> &f)
{
CRITICAL_REGION_LOCAL(m_peerlist_lock);
for(const peerlist_entry& be: outer_bs)
{
- append_with_peer_gray(be);
+ if (!f || f(be))
+ append_with_peer_gray(be);
}
// delete extra elements
trim_gray_peerlist();
diff --git a/src/p2p/p2p_protocol_defs.h b/src/p2p/p2p_protocol_defs.h
index efc8e52fd..609661871 100644
--- a/src/p2p/p2p_protocol_defs.h
+++ b/src/p2p/p2p_protocol_defs.h
@@ -40,9 +40,6 @@
#include "string_tools.h"
#include "time_helper.h"
#include "cryptonote_config.h"
-#ifdef ALLOW_DEBUG_COMMANDS
-#include "crypto/crypto.h"
-#endif
namespace nodetool
{
@@ -286,117 +283,6 @@ namespace nodetool
};
-#ifdef ALLOW_DEBUG_COMMANDS
- //These commands are considered as insecure, and made in debug purposes for a limited lifetime.
- //Anyone who feel unsafe with this commands can disable the ALLOW_GET_STAT_COMMAND macro.
-
- struct proof_of_trust
- {
- peerid_type peer_id;
- uint64_t time;
- crypto::signature sign;
-
- BEGIN_KV_SERIALIZE_MAP()
- KV_SERIALIZE(peer_id)
- KV_SERIALIZE(time)
- KV_SERIALIZE_VAL_POD_AS_BLOB(sign)
- END_KV_SERIALIZE_MAP()
- };
-
-
- template<class payload_stat_info>
- struct COMMAND_REQUEST_STAT_INFO_T
- {
- const static int ID = P2P_COMMANDS_POOL_BASE + 4;
-
- struct request_t
- {
- proof_of_trust tr;
- BEGIN_KV_SERIALIZE_MAP()
- KV_SERIALIZE(tr)
- END_KV_SERIALIZE_MAP()
- };
- typedef epee::misc_utils::struct_init<request_t> request;
-
- struct response_t
- {
- std::string version;
- std::string os_version;
- uint64_t connections_count;
- uint64_t incoming_connections_count;
- payload_stat_info payload_info;
-
- BEGIN_KV_SERIALIZE_MAP()
- KV_SERIALIZE(version)
- KV_SERIALIZE(os_version)
- KV_SERIALIZE(connections_count)
- KV_SERIALIZE(incoming_connections_count)
- KV_SERIALIZE(payload_info)
- END_KV_SERIALIZE_MAP()
- };
- typedef epee::misc_utils::struct_init<response_t> response;
- };
-
-
- /************************************************************************/
- /* */
- /************************************************************************/
- struct COMMAND_REQUEST_NETWORK_STATE
- {
- const static int ID = P2P_COMMANDS_POOL_BASE + 5;
-
- struct request_t
- {
- proof_of_trust tr;
- BEGIN_KV_SERIALIZE_MAP()
- KV_SERIALIZE(tr)
- END_KV_SERIALIZE_MAP()
- };
- typedef epee::misc_utils::struct_init<request_t> request;
-
- struct response_t
- {
- std::vector<peerlist_entry> local_peerlist_white;
- std::vector<peerlist_entry> local_peerlist_gray;
- std::vector<connection_entry> connections_list;
- peerid_type my_id;
- uint64_t local_time;
- BEGIN_KV_SERIALIZE_MAP()
- KV_SERIALIZE_CONTAINER_POD_AS_BLOB(local_peerlist_white)
- KV_SERIALIZE_CONTAINER_POD_AS_BLOB(local_peerlist_gray)
- KV_SERIALIZE_CONTAINER_POD_AS_BLOB(connections_list)
- KV_SERIALIZE(my_id)
- KV_SERIALIZE(local_time)
- END_KV_SERIALIZE_MAP()
- };
- typedef epee::misc_utils::struct_init<response_t> response;
- };
-
- /************************************************************************/
- /* */
- /************************************************************************/
- struct COMMAND_REQUEST_PEER_ID
- {
- const static int ID = P2P_COMMANDS_POOL_BASE + 6;
-
- struct request_t
- {
- BEGIN_KV_SERIALIZE_MAP()
- END_KV_SERIALIZE_MAP()
- };
- typedef epee::misc_utils::struct_init<request_t> request;
-
- struct response_t
- {
- peerid_type my_id;
-
- BEGIN_KV_SERIALIZE_MAP()
- KV_SERIALIZE(my_id)
- END_KV_SERIALIZE_MAP()
- };
- typedef epee::misc_utils::struct_init<response_t> response;
- };
-
/************************************************************************/
/* */
/************************************************************************/
@@ -421,16 +307,4 @@ namespace nodetool
};
typedef epee::misc_utils::struct_init<response_t> response;
};
-
-#endif
-
-
- inline crypto::hash get_proof_of_trust_hash(const nodetool::proof_of_trust& pot)
- {
- std::string s;
- s.append(reinterpret_cast<const char*>(&pot.peer_id), sizeof(pot.peer_id));
- s.append(reinterpret_cast<const char*>(&pot.time), sizeof(pot.time));
- return crypto::cn_fast_hash(s.data(), s.size());
- }
-
}
diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp
index 5b79310c6..afe9d3897 100644
--- a/src/rpc/core_rpc_server.cpp
+++ b/src/rpc/core_rpc_server.cpp
@@ -1100,7 +1100,7 @@ namespace cryptonote
return true;
}
- if (req.do_sanity_checks && !cryptonote::tx_sanity_check(m_core.get_blockchain_storage(), tx_blob))
+ if (req.do_sanity_checks && !cryptonote::tx_sanity_check(tx_blob, m_core.get_blockchain_storage().get_num_mature_outputs(0)))
{
res.status = "Failed";
res.reason = "Sanity check failed";
diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp
index 19e3656c2..d981a48b8 100644
--- a/src/simplewallet/simplewallet.cpp
+++ b/src/simplewallet/simplewallet.cpp
@@ -1691,7 +1691,7 @@ bool simple_wallet::print_ring(const std::vector<std::string> &args)
rings.push_back({key_image, ring});
else if (!m_wallet->get_rings(txid, rings))
{
- fail_msg_writer() << tr("Key image either not spent, or spent with mixin 0");
+ fail_msg_writer() << tr("Key image either not spent, or spent with ring size 1");
return true;
}
diff --git a/src/wallet/ringdb.cpp b/src/wallet/ringdb.cpp
index b7efdd75c..5e88ea788 100644
--- a/src/wallet/ringdb.cpp
+++ b/src/wallet/ringdb.cpp
@@ -39,6 +39,8 @@
#undef MONERO_DEFAULT_LOG_CATEGORY
#define MONERO_DEFAULT_LOG_CATEGORY "wallet.ringdb"
+#define V1TAG ((uint64_t)798237759845202)
+
static const char zerokey[8] = {0};
static const MDB_val zerokeyval = { sizeof(zerokey), (void *)zerokey };
@@ -63,15 +65,16 @@ static int compare_uint64(const MDB_val *a, const MDB_val *b)
return va < vb ? -1 : va > vb;
}
-static std::string compress_ring(const std::vector<uint64_t> &ring)
+static std::string compress_ring(const std::vector<uint64_t> &ring, uint64_t tag)
{
std::string s;
+ s += tools::get_varint_data(tag);
for (uint64_t out: ring)
s += tools::get_varint_data(out);
return s;
}
-static std::vector<uint64_t> decompress_ring(const std::string &s)
+static std::vector<uint64_t> decompress_ring(const std::string &s, uint64_t tag)
{
std::vector<uint64_t> ring;
int read = 0;
@@ -81,6 +84,13 @@ static std::vector<uint64_t> decompress_ring(const std::string &s)
std::string tmp(i, s.cend());
read = tools::read_varint(tmp.begin(), tmp.end(), out);
THROW_WALLET_EXCEPTION_IF(read <= 0 || read > 256, tools::error::wallet_internal_error, "Internal error decompressing ring");
+ if (tag)
+ {
+ if (tag != out)
+ return {};
+ tag = 0;
+ continue;
+ }
ring.push_back(out);
}
return ring;
@@ -93,25 +103,27 @@ std::string get_rings_filename(boost::filesystem::path filename)
return filename.string();
}
-static crypto::chacha_iv make_iv(const crypto::key_image &key_image, const crypto::chacha_key &key)
+static crypto::chacha_iv make_iv(const crypto::key_image &key_image, const crypto::chacha_key &key, uint8_t field)
{
static const char salt[] = "ringdsb";
- uint8_t buffer[sizeof(key_image) + sizeof(key) + sizeof(salt)];
+ uint8_t buffer[sizeof(key_image) + sizeof(key) + sizeof(salt) + sizeof(field)];
memcpy(buffer, &key_image, sizeof(key_image));
memcpy(buffer + sizeof(key_image), &key, sizeof(key));
memcpy(buffer + sizeof(key_image) + sizeof(key), salt, sizeof(salt));
+ memcpy(buffer + sizeof(key_image) + sizeof(key) + sizeof(salt), &field, sizeof(field));
crypto::hash hash;
- crypto::cn_fast_hash(buffer, sizeof(buffer), hash.data);
+ // if field is 0, backward compat mode: hash without the field
+ crypto::cn_fast_hash(buffer, sizeof(buffer) - !field, hash.data);
static_assert(sizeof(hash) >= CHACHA_IV_SIZE, "Incompatible hash and chacha IV sizes");
crypto::chacha_iv iv;
memcpy(&iv, &hash, CHACHA_IV_SIZE);
return iv;
}
-static std::string encrypt(const std::string &plaintext, const crypto::key_image &key_image, const crypto::chacha_key &key)
+static std::string encrypt(const std::string &plaintext, const crypto::key_image &key_image, const crypto::chacha_key &key, uint8_t field)
{
- const crypto::chacha_iv iv = make_iv(key_image, key);
+ const crypto::chacha_iv iv = make_iv(key_image, key, field);
std::string ciphertext;
ciphertext.resize(plaintext.size() + sizeof(iv));
crypto::chacha20(plaintext.data(), plaintext.size(), key, iv, &ciphertext[sizeof(iv)]);
@@ -119,14 +131,14 @@ static std::string encrypt(const std::string &plaintext, const crypto::key_image
return ciphertext;
}
-static std::string encrypt(const crypto::key_image &key_image, const crypto::chacha_key &key)
+static std::string encrypt(const crypto::key_image &key_image, const crypto::chacha_key &key, uint8_t field)
{
- return encrypt(std::string((const char*)&key_image, sizeof(key_image)), key_image, key);
+ return encrypt(std::string((const char*)&key_image, sizeof(key_image)), key_image, key, field);
}
-static std::string decrypt(const std::string &ciphertext, const crypto::key_image &key_image, const crypto::chacha_key &key)
+static std::string decrypt(const std::string &ciphertext, const crypto::key_image &key_image, const crypto::chacha_key &key, uint8_t field)
{
- const crypto::chacha_iv iv = make_iv(key_image, key);
+ const crypto::chacha_iv iv = make_iv(key_image, key, field);
std::string plaintext;
THROW_WALLET_EXCEPTION_IF(ciphertext.size() < sizeof(iv), tools::error::wallet_internal_error, "Bad ciphertext text");
plaintext.resize(ciphertext.size() - sizeof(iv));
@@ -137,11 +149,11 @@ static std::string decrypt(const std::string &ciphertext, const crypto::key_imag
static void store_relative_ring(MDB_txn *txn, MDB_dbi &dbi, const crypto::key_image &key_image, const std::vector<uint64_t> &relative_ring, const crypto::chacha_key &chacha_key)
{
MDB_val key, data;
- std::string key_ciphertext = encrypt(key_image, chacha_key);
+ std::string key_ciphertext = encrypt(key_image, chacha_key, 0);
key.mv_data = (void*)key_ciphertext.data();
key.mv_size = key_ciphertext.size();
- std::string compressed_ring = compress_ring(relative_ring);
- std::string data_ciphertext = encrypt(compressed_ring, key_image, chacha_key);
+ std::string compressed_ring = compress_ring(relative_ring, V1TAG);
+ std::string data_ciphertext = encrypt(compressed_ring, key_image, chacha_key, 1);
data.mv_size = data_ciphertext.size();
data.mv_data = (void*)data_ciphertext.c_str();
int dbr = mdb_put(txn, dbi, &key, &data, 0);
@@ -297,7 +309,7 @@ bool ringdb::remove_rings(const crypto::chacha_key &chacha_key, const std::vecto
for (const crypto::key_image &key_image: key_images)
{
MDB_val key, data;
- std::string key_ciphertext = encrypt(key_image, chacha_key);
+ std::string key_ciphertext = encrypt(key_image, chacha_key, 0);
key.mv_data = (void*)key_ciphertext.data();
key.mv_size = key_ciphertext.size();
@@ -349,7 +361,7 @@ bool ringdb::get_ring(const crypto::chacha_key &chacha_key, const crypto::key_im
tx_active = true;
MDB_val key, data;
- std::string key_ciphertext = encrypt(key_image, chacha_key);
+ std::string key_ciphertext = encrypt(key_image, chacha_key, 0);
key.mv_data = (void*)key_ciphertext.data();
key.mv_size = key_ciphertext.size();
dbr = mdb_get(txn, dbi_rings, &key, &data);
@@ -358,8 +370,15 @@ bool ringdb::get_ring(const crypto::chacha_key &chacha_key, const crypto::key_im
return false;
THROW_WALLET_EXCEPTION_IF(data.mv_size <= 0, tools::error::wallet_internal_error, "Invalid ring data size");
- std::string data_plaintext = decrypt(std::string((const char*)data.mv_data, data.mv_size), key_image, chacha_key);
- outs = decompress_ring(data_plaintext);
+ bool try_v0 = false;
+ std::string data_plaintext = decrypt(std::string((const char*)data.mv_data, data.mv_size), key_image, chacha_key, 1);
+ try { outs = decompress_ring(data_plaintext, V1TAG); if (outs.empty()) try_v0 = true; }
+ catch(...) { try_v0 = true; }
+ if (try_v0)
+ {
+ data_plaintext = decrypt(std::string((const char*)data.mv_data, data.mv_size), key_image, chacha_key, 0);
+ outs = decompress_ring(data_plaintext, 0);
+ }
MDEBUG("Found ring for key image " << key_image << ":");
MDEBUG("Relative: " << boost::join(outs | boost::adaptors::transformed([](uint64_t out){return std::to_string(out);}), " "));
outs = cryptonote::relative_output_offsets_to_absolute(outs);
diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp
index 7ee32a436..eaf185c63 100644
--- a/src/wallet/wallet2.cpp
+++ b/src/wallet/wallet2.cpp
@@ -44,6 +44,7 @@
using namespace epee;
#include "cryptonote_config.h"
+#include "cryptonote_core/tx_sanity_check.h"
#include "wallet_rpc_helpers.h"
#include "wallet2.h"
#include "cryptonote_basic/cryptonote_format_utils.h"
@@ -149,6 +150,9 @@ static const std::string MULTISIG_EXTRA_INFO_MAGIC = "MultisigxV1";
static const std::string ASCII_OUTPUT_MAGIC = "MoneroAsciiDataV1";
+boost::mutex tools::wallet2::default_daemon_address_lock;
+std::string tools::wallet2::default_daemon_address = "";
+
namespace
{
std::string get_default_ringdb_path()
@@ -412,6 +416,15 @@ std::unique_ptr<tools::wallet2> make_basic(const boost::program_options::variabl
daemon_port = get_config(nettype).RPC_DEFAULT_PORT;
}
+ // if no daemon settings are given and we have a previous one, reuse that one
+ if (command_line::is_arg_defaulted(vm, opts.daemon_host) && command_line::is_arg_defaulted(vm, opts.daemon_port) && command_line::is_arg_defaulted(vm, opts.daemon_address))
+ {
+ // not a bug: taking a const ref to a temporary in this way is actually ok in a recent C++ standard
+ const std::string &def = tools::wallet2::get_default_daemon_address();
+ if (!def.empty())
+ daemon_address = def;
+ }
+
if (daemon_address.empty())
daemon_address = std::string("http://") + daemon_host + ":" + std::to_string(daemon_port);
@@ -591,6 +604,8 @@ std::pair<std::unique_ptr<tools::wallet2>, tools::password_container> generate_f
}
viewkey = *reinterpret_cast<const crypto::secret_key*>(viewkey_data.data());
crypto::public_key pkey;
+ if (viewkey == crypto::null_skey)
+ THROW_WALLET_EXCEPTION(tools::error::wallet_internal_error, tools::wallet2::tr("view secret key may not be all zeroes"));
if (!crypto::secret_key_to_public_key(viewkey, pkey)) {
THROW_WALLET_EXCEPTION(tools::error::wallet_internal_error, tools::wallet2::tr("failed to verify view key secret key"));
}
@@ -607,6 +622,8 @@ std::pair<std::unique_ptr<tools::wallet2>, tools::password_container> generate_f
}
spendkey = *reinterpret_cast<const crypto::secret_key*>(spendkey_data.data());
crypto::public_key pkey;
+ if (spendkey == crypto::null_skey)
+ THROW_WALLET_EXCEPTION(tools::error::wallet_internal_error, tools::wallet2::tr("spend secret key may not be all zeroes"));
if (!crypto::secret_key_to_public_key(spendkey, pkey)) {
THROW_WALLET_EXCEPTION(tools::error::wallet_internal_error, tools::wallet2::tr("failed to verify spend key secret key"));
}
@@ -1313,8 +1330,15 @@ bool wallet2::set_daemon(std::string daemon_address, boost::optional<epee::net_u
m_node_rpc_proxy.invalidate();
}
- MINFO("setting daemon to " << get_daemon_address());
- return m_http_client.set_server(get_daemon_address(), get_daemon_login(), std::move(ssl_options));
+ const std::string address = get_daemon_address();
+ MINFO("setting daemon to " << address);
+ bool ret = m_http_client.set_server(address, get_daemon_login(), std::move(ssl_options));
+ if (ret)
+ {
+ CRITICAL_REGION_LOCAL(default_daemon_address_lock);
+ default_daemon_address = address;
+ }
+ return ret;
}
//----------------------------------------------------------------------------------------------------
bool wallet2::init(std::string daemon_address, boost::optional<epee::net_utils::http::login> daemon_login, boost::asio::ip::tcp::endpoint proxy, uint64_t upper_transaction_weight_limit, bool trusted_daemon, epee::net_utils::ssl_options_t ssl_options)
@@ -2934,7 +2958,6 @@ void wallet2::update_pool_state(std::vector<std::tuple<cryptonote::transaction,
pit->second.m_state = wallet2::unconfirmed_transfer_details::failed;
// the inputs aren't spent anymore, since the tx failed
- remove_rings(pit->second.m_tx);
for (size_t vini = 0; vini < pit->second.m_tx.vin.size(); ++vini)
{
if (pit->second.m_tx.vin[vini].type() == typeid(txin_to_key))
@@ -7775,8 +7798,50 @@ void wallet2::light_wallet_get_outs(std::vector<std::vector<tools::wallet2::get_
}
}
+std::pair<std::set<uint64_t>, size_t> outs_unique(const std::vector<std::vector<tools::wallet2::get_outs_entry>> &outs)
+{
+ std::set<uint64_t> unique;
+ size_t total = 0;
+
+ for (const auto &it : outs)
+ {
+ for (const auto &out : it)
+ {
+ const uint64_t global_index = std::get<0>(out);
+ unique.insert(global_index);
+ }
+ total += it.size();
+ }
+
+ return std::make_pair(std::move(unique), total);
+}
+
void wallet2::get_outs(std::vector<std::vector<tools::wallet2::get_outs_entry>> &outs, const std::vector<size_t> &selected_transfers, size_t fake_outputs_count)
{
+ std::vector<uint64_t> rct_offsets;
+ for (size_t attempts = 3; attempts > 0; --attempts)
+ {
+ get_outs(outs, selected_transfers, fake_outputs_count, rct_offsets);
+
+ const auto unique = outs_unique(outs);
+ if (tx_sanity_check(unique.first, unique.second, rct_offsets.empty() ? 0 : rct_offsets.back()))
+ {
+ return;
+ }
+
+ std::vector<crypto::key_image> key_images;
+ key_images.reserve(selected_transfers.size());
+ std::for_each(selected_transfers.begin(), selected_transfers.end(), [this, &key_images](size_t index) {
+ key_images.push_back(m_transfers[index].m_key_image);
+ });
+ unset_ring(key_images);
+ }
+
+ THROW_WALLET_EXCEPTION(error::wallet_internal_error, tr("Transaction sanity check failed"));
+}
+
+void wallet2::get_outs(std::vector<std::vector<tools::wallet2::get_outs_entry>> &outs, const std::vector<size_t> &selected_transfers, size_t fake_outputs_count, std::vector<uint64_t> &rct_offsets)
+{
LOG_PRINT_L2("fake_outputs_count: " << fake_outputs_count);
outs.clear();
@@ -7797,7 +7862,6 @@ void wallet2::get_outs(std::vector<std::vector<tools::wallet2::get_outs_entry>>
// if we have at least one rct out, get the distribution, or fall back to the previous system
uint64_t rct_start_height;
- std::vector<uint64_t> rct_offsets;
bool has_rct = false;
uint64_t max_rct_index = 0;
for (size_t idx: selected_transfers)
@@ -7806,7 +7870,7 @@ void wallet2::get_outs(std::vector<std::vector<tools::wallet2::get_outs_entry>>
has_rct = true;
max_rct_index = std::max(max_rct_index, m_transfers[idx].m_global_output_index);
}
- const bool has_rct_distribution = has_rct && get_rct_distribution(rct_start_height, rct_offsets);
+ const bool has_rct_distribution = has_rct && (!rct_offsets.empty() || get_rct_distribution(rct_start_height, rct_offsets));
if (has_rct_distribution)
{
// check we're clear enough of rct start, to avoid corner cases below
diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h
index 8ecc4d8fa..4b69cae40 100644
--- a/src/wallet/wallet2.h
+++ b/src/wallet/wallet2.h
@@ -1389,6 +1389,8 @@ private:
uint64_t credits() const { return m_rpc_payment_state.credits; }
void credit_report(uint64_t &expected_spent, uint64_t &discrepancy) const { expected_spent = m_rpc_payment_state.expected_spent; discrepancy = m_rpc_payment_state.discrepancy; }
+ static std::string get_default_daemon_address() { CRITICAL_REGION_LOCAL(default_daemon_address_lock); return default_daemon_address; }
+
private:
/*!
* \brief Stores wallet information to wallet file.
@@ -1440,6 +1442,7 @@ private:
bool is_spent(const transfer_details &td, bool strict = true) const;
bool is_spent(size_t idx, bool strict = true) const;
void get_outs(std::vector<std::vector<get_outs_entry>> &outs, const std::vector<size_t> &selected_transfers, size_t fake_outputs_count);
+ void get_outs(std::vector<std::vector<get_outs_entry>> &outs, const std::vector<size_t> &selected_transfers, size_t fake_outputs_count, std::vector<uint64_t> &rct_offsets);
bool tx_add_fake_output(std::vector<std::vector<tools::wallet2::get_outs_entry>> &outs, uint64_t global_index, const crypto::public_key& tx_public_key, const rct::key& mask, uint64_t real_index, bool unlocked) const;
bool should_pick_a_second_output(bool use_rct, size_t n_transfers, const std::vector<size_t> &unused_transfers_indices, const std::vector<size_t> &unused_dust_indices) const;
std::vector<size_t> get_only_rct(const std::vector<size_t> &unused_dust_indices, const std::vector<size_t> &unused_transfers_indices) const;
@@ -1628,6 +1631,9 @@ private:
std::unique_ptr<wallet_device_callback> m_device_callback;
ExportFormat m_export_format;
+
+ static boost::mutex default_daemon_address_lock;
+ static std::string default_daemon_address;
};
}
BOOST_CLASS_VERSION(tools::wallet2, 29)
diff --git a/tests/core_proxy/core_proxy.h b/tests/core_proxy/core_proxy.h
index d09eb31c9..aad1bc962 100644
--- a/tests/core_proxy/core_proxy.h
+++ b/tests/core_proxy/core_proxy.h
@@ -73,7 +73,6 @@ namespace tests
bool init(const boost::program_options::variables_map& vm);
bool deinit(){return true;}
bool get_short_chain_history(std::list<crypto::hash>& ids);
- bool get_stat_info(cryptonote::core_stat_info& st_inf){return true;}
bool have_block(const crypto::hash& id);
void get_blockchain_top(uint64_t& height, crypto::hash& top_id);
bool handle_incoming_tx(const cryptonote::tx_blob_entry& tx_blob, cryptonote::tx_verification_context& tvc, cryptonote::relay_method tx_relay, bool relayed);
diff --git a/tests/unit_tests/epee_utils.cpp b/tests/unit_tests/epee_utils.cpp
index ee44ea2d5..513c2227c 100644
--- a/tests/unit_tests/epee_utils.cpp
+++ b/tests/unit_tests/epee_utils.cpp
@@ -45,6 +45,7 @@
#include "boost/archive/portable_binary_iarchive.hpp"
#include "boost/archive/portable_binary_oarchive.hpp"
#include "byte_slice.h"
+#include "crypto/crypto.h"
#include "hex.h"
#include "net/net_utils_base.h"
#include "net/local_ip.h"
diff --git a/tests/unit_tests/net.cpp b/tests/unit_tests/net.cpp
index 221dc631d..36cb28ae0 100644
--- a/tests/unit_tests/net.cpp
+++ b/tests/unit_tests/net.cpp
@@ -53,8 +53,10 @@
#include <memory>
#include <type_traits>
+#include "crypto/crypto.h"
#include "net/dandelionpp.h"
#include "net/error.h"
+#include "net/i2p_address.h"
#include "net/net_utils_base.h"
#include "net/socks.h"
#include "net/socks_connect.h"
@@ -177,22 +179,33 @@ TEST(tor_address, valid)
EXPECT_FALSE(address2.less(*address1));
EXPECT_TRUE(address1->less(address2));
- address2 = MONERO_UNWRAP(net::tor_address::make(std::string{v3_onion} + ":", 65535));
-
- EXPECT_EQ(65535, address2.port());
- EXPECT_STREQ(v3_onion, address2.host_str());
- EXPECT_EQ(std::string{v3_onion} + ":65535", address2.str().c_str());
- EXPECT_TRUE(address2.is_blockable());
- EXPECT_FALSE(address2.equal(*address1));
- EXPECT_FALSE(address1->equal(address2));
- EXPECT_FALSE(address2 == *address1);
- EXPECT_FALSE(*address1 == address2);
- EXPECT_TRUE(address2 != *address1);
- EXPECT_TRUE(*address1 != address2);
- EXPECT_TRUE(address2.is_same_host(*address1));
- EXPECT_TRUE(address1->is_same_host(address2));
- EXPECT_FALSE(address2.less(*address1));
- EXPECT_TRUE(address1->less(address2));
+ net::tor_address address3 = MONERO_UNWRAP(net::tor_address::make(std::string{v3_onion} + ":", 65535));
+
+ EXPECT_EQ(65535, address3.port());
+ EXPECT_STREQ(v3_onion, address3.host_str());
+ EXPECT_EQ(std::string{v3_onion} + ":65535", address3.str().c_str());
+ EXPECT_TRUE(address3.is_blockable());
+ EXPECT_FALSE(address3.equal(*address1));
+ EXPECT_FALSE(address1->equal(address3));
+ EXPECT_FALSE(address3 == *address1);
+ EXPECT_FALSE(*address1 == address3);
+ EXPECT_TRUE(address3 != *address1);
+ EXPECT_TRUE(*address1 != address3);
+ EXPECT_TRUE(address3.is_same_host(*address1));
+ EXPECT_TRUE(address1->is_same_host(address3));
+ EXPECT_FALSE(address3.less(*address1));
+ EXPECT_TRUE(address1->less(address3));
+
+ EXPECT_FALSE(address3.equal(address2));
+ EXPECT_FALSE(address2.equal(address3));
+ EXPECT_FALSE(address3 == address2);
+ EXPECT_FALSE(address2 == address3);
+ EXPECT_TRUE(address3 != address2);
+ EXPECT_TRUE(address2 != address3);
+ EXPECT_FALSE(address3.is_same_host(address2));
+ EXPECT_FALSE(address2.is_same_host(address3));
+ EXPECT_TRUE(address3.less(address2));
+ EXPECT_FALSE(address2.less(address3));
}
TEST(tor_address, generic_network_address)
@@ -220,7 +233,7 @@ TEST(tor_address, generic_network_address)
namespace
{
- struct test_command
+ struct test_command_tor
{
net::tor_address tor;
@@ -234,7 +247,7 @@ TEST(tor_address, epee_serializev_v2)
{
std::string buffer{};
{
- test_command command{MONERO_UNWRAP(net::tor_address::make(v2_onion, 10))};
+ test_command_tor command{MONERO_UNWRAP(net::tor_address::make(v2_onion, 10))};
EXPECT_FALSE(command.tor.is_unknown());
EXPECT_NE(net::tor_address{}, command.tor);
EXPECT_STREQ(v2_onion, command.tor.host_str());
@@ -245,7 +258,7 @@ TEST(tor_address, epee_serializev_v2)
EXPECT_TRUE(stg.store_to_binary(buffer));
}
- test_command command{};
+ test_command_tor command{};
{
EXPECT_TRUE(command.tor.is_unknown());
EXPECT_EQ(net::tor_address{}, command.tor);
@@ -285,7 +298,7 @@ TEST(tor_address, epee_serializev_v3)
{
std::string buffer{};
{
- test_command command{MONERO_UNWRAP(net::tor_address::make(v3_onion, 10))};
+ test_command_tor command{MONERO_UNWRAP(net::tor_address::make(v3_onion, 10))};
EXPECT_FALSE(command.tor.is_unknown());
EXPECT_NE(net::tor_address{}, command.tor);
EXPECT_STREQ(v3_onion, command.tor.host_str());
@@ -296,7 +309,7 @@ TEST(tor_address, epee_serializev_v3)
EXPECT_TRUE(stg.store_to_binary(buffer));
}
- test_command command{};
+ test_command_tor command{};
{
EXPECT_TRUE(command.tor.is_unknown());
EXPECT_EQ(net::tor_address{}, command.tor);
@@ -336,7 +349,7 @@ TEST(tor_address, epee_serialize_unknown)
{
std::string buffer{};
{
- test_command command{net::tor_address::unknown()};
+ test_command_tor command{net::tor_address::unknown()};
EXPECT_TRUE(command.tor.is_unknown());
EXPECT_EQ(net::tor_address{}, command.tor);
EXPECT_STREQ(net::tor_address::unknown_str(), command.tor.host_str());
@@ -347,7 +360,7 @@ TEST(tor_address, epee_serialize_unknown)
EXPECT_TRUE(stg.store_to_binary(buffer));
}
- test_command command{};
+ test_command_tor command{};
{
EXPECT_TRUE(command.tor.is_unknown());
EXPECT_EQ(net::tor_address{}, command.tor);
@@ -513,6 +526,374 @@ TEST(get_network_address, onion)
EXPECT_EQ(net::error::invalid_port, address);
}
+namespace
+{
+ static constexpr const char b32_i2p[] =
+ "vww6ybal4bd7szmgncyruucpgfkqahzddi37ktceo3ah7ngmcopn.b32.i2p";
+ static constexpr const char b32_i2p_2[] =
+ "xmrto2bturnore26xmrto2bturnore26xmrto2bturnore26xmr2.b32.i2p";
+}
+
+TEST(i2p_address, constants)
+{
+ static_assert(!net::i2p_address::is_local(), "bad is_local() response");
+ static_assert(!net::i2p_address::is_loopback(), "bad is_loopback() response");
+ static_assert(net::i2p_address::get_type_id() == epee::net_utils::address_type::i2p, "bad get_type_id() response");
+
+ EXPECT_FALSE(net::i2p_address::is_local());
+ EXPECT_FALSE(net::i2p_address::is_loopback());
+ EXPECT_EQ(epee::net_utils::address_type::i2p, net::i2p_address::get_type_id());
+ EXPECT_EQ(epee::net_utils::address_type::i2p, net::i2p_address::get_type_id());
+}
+
+TEST(i2p_address, invalid)
+{
+ EXPECT_TRUE(net::i2p_address::make("").has_error());
+ EXPECT_TRUE(net::i2p_address::make(":").has_error());
+ EXPECT_TRUE(net::i2p_address::make(".b32.i2p").has_error());
+ EXPECT_TRUE(net::i2p_address::make(".b32.i2p:").has_error());
+ EXPECT_TRUE(net::i2p_address::make(b32_i2p + 1).has_error());
+ EXPECT_TRUE(net::i2p_address::make(boost::string_ref{b32_i2p, sizeof(b32_i2p) - 2}).has_error());
+ EXPECT_TRUE(net::i2p_address::make(std::string{b32_i2p} + ":65536").has_error());
+ EXPECT_TRUE(net::i2p_address::make(std::string{b32_i2p} + ":-1").has_error());
+
+ std::string i2p{b32_i2p};
+ i2p.at(10) = 1;
+ EXPECT_TRUE(net::i2p_address::make(i2p).has_error());
+}
+
+TEST(i2p_address, unblockable_types)
+{
+ net::i2p_address i2p{};
+
+ ASSERT_NE(nullptr, i2p.host_str());
+ EXPECT_STREQ("<unknown i2p host>", i2p.host_str());
+ EXPECT_STREQ("<unknown i2p host>", i2p.str().c_str());
+ EXPECT_EQ(0u, i2p.port());
+ EXPECT_TRUE(i2p.is_unknown());
+ EXPECT_FALSE(i2p.is_local());
+ EXPECT_FALSE(i2p.is_loopback());
+ EXPECT_EQ(epee::net_utils::address_type::i2p, i2p.get_type_id());
+ EXPECT_EQ(epee::net_utils::zone::i2p, i2p.get_zone());
+
+ i2p = net::i2p_address::unknown();
+ ASSERT_NE(nullptr, i2p.host_str());
+ EXPECT_STREQ("<unknown i2p host>", i2p.host_str());
+ EXPECT_STREQ("<unknown i2p host>", i2p.str().c_str());
+ EXPECT_EQ(0u, i2p.port());
+ EXPECT_TRUE(i2p.is_unknown());
+ EXPECT_FALSE(i2p.is_local());
+ EXPECT_FALSE(i2p.is_loopback());
+ EXPECT_EQ(epee::net_utils::address_type::i2p, i2p.get_type_id());
+ EXPECT_EQ(epee::net_utils::zone::i2p, i2p.get_zone());
+
+ EXPECT_EQ(net::i2p_address{}, net::i2p_address::unknown());
+}
+
+TEST(i2p_address, valid)
+{
+ const auto address1 = net::i2p_address::make(b32_i2p);
+
+ ASSERT_TRUE(address1.has_value());
+ EXPECT_EQ(0u, address1->port());
+ EXPECT_STREQ(b32_i2p, address1->host_str());
+ EXPECT_STREQ(b32_i2p, address1->str().c_str());
+ EXPECT_TRUE(address1->is_blockable());
+
+ net::i2p_address address2{*address1};
+
+ EXPECT_EQ(0u, address2.port());
+ EXPECT_STREQ(b32_i2p, address2.host_str());
+ EXPECT_STREQ(b32_i2p, address2.str().c_str());
+ EXPECT_TRUE(address2.is_blockable());
+ EXPECT_TRUE(address2.equal(*address1));
+ EXPECT_TRUE(address1->equal(address2));
+ EXPECT_TRUE(address2 == *address1);
+ EXPECT_TRUE(*address1 == address2);
+ EXPECT_FALSE(address2 != *address1);
+ EXPECT_FALSE(*address1 != address2);
+ EXPECT_TRUE(address2.is_same_host(*address1));
+ EXPECT_TRUE(address1->is_same_host(address2));
+ EXPECT_FALSE(address2.less(*address1));
+ EXPECT_FALSE(address1->less(address2));
+
+ address2 = MONERO_UNWRAP(net::i2p_address::make(std::string{b32_i2p_2} + ":6545"));
+
+ EXPECT_EQ(6545, address2.port());
+ EXPECT_STREQ(b32_i2p_2, address2.host_str());
+ EXPECT_EQ(std::string{b32_i2p_2} + ":6545", address2.str().c_str());
+ EXPECT_TRUE(address2.is_blockable());
+ EXPECT_FALSE(address2.equal(*address1));
+ EXPECT_FALSE(address1->equal(address2));
+ EXPECT_FALSE(address2 == *address1);
+ EXPECT_FALSE(*address1 == address2);
+ EXPECT_TRUE(address2 != *address1);
+ EXPECT_TRUE(*address1 != address2);
+ EXPECT_FALSE(address2.is_same_host(*address1));
+ EXPECT_FALSE(address1->is_same_host(address2));
+ EXPECT_FALSE(address2.less(*address1));
+ EXPECT_TRUE(address1->less(address2));
+
+ net::i2p_address address3 = MONERO_UNWRAP(net::i2p_address::make(std::string{b32_i2p} + ":", 65535));
+
+ EXPECT_EQ(65535, address3.port());
+ EXPECT_STREQ(b32_i2p, address3.host_str());
+ EXPECT_EQ(std::string{b32_i2p} + ":65535", address3.str().c_str());
+ EXPECT_TRUE(address3.is_blockable());
+ EXPECT_FALSE(address3.equal(*address1));
+ EXPECT_FALSE(address1->equal(address3));
+ EXPECT_FALSE(address3 == *address1);
+ EXPECT_FALSE(*address1 == address3);
+ EXPECT_TRUE(address3 != *address1);
+ EXPECT_TRUE(*address1 != address3);
+ EXPECT_TRUE(address3.is_same_host(*address1));
+ EXPECT_TRUE(address1->is_same_host(address3));
+ EXPECT_FALSE(address3.less(*address1));
+ EXPECT_TRUE(address1->less(address3));
+
+ EXPECT_FALSE(address3.equal(address2));
+ EXPECT_FALSE(address2.equal(address3));
+ EXPECT_FALSE(address3 == address2);
+ EXPECT_FALSE(address2 == address3);
+ EXPECT_TRUE(address3 != address2);
+ EXPECT_TRUE(address2 != address3);
+ EXPECT_FALSE(address3.is_same_host(address2));
+ EXPECT_FALSE(address2.is_same_host(address3));
+ EXPECT_TRUE(address3.less(address2));
+ EXPECT_FALSE(address2.less(address3));
+}
+
+TEST(i2p_address, generic_network_address)
+{
+ const epee::net_utils::network_address i2p1{MONERO_UNWRAP(net::i2p_address::make(b32_i2p, 8080))};
+ const epee::net_utils::network_address i2p2{MONERO_UNWRAP(net::i2p_address::make(b32_i2p, 8080))};
+ const epee::net_utils::network_address ip{epee::net_utils::ipv4_network_address{100, 200}};
+
+ EXPECT_EQ(i2p1, i2p2);
+ EXPECT_NE(ip, i2p1);
+ EXPECT_LT(ip, i2p1);
+
+ EXPECT_STREQ(b32_i2p, i2p1.host_str().c_str());
+ EXPECT_EQ(std::string{b32_i2p} + ":8080", i2p1.str());
+ EXPECT_EQ(epee::net_utils::address_type::i2p, i2p1.get_type_id());
+ EXPECT_EQ(epee::net_utils::address_type::i2p, i2p2.get_type_id());
+ EXPECT_EQ(epee::net_utils::address_type::ipv4, ip.get_type_id());
+ EXPECT_EQ(epee::net_utils::zone::i2p, i2p1.get_zone());
+ EXPECT_EQ(epee::net_utils::zone::i2p, i2p2.get_zone());
+ EXPECT_EQ(epee::net_utils::zone::public_, ip.get_zone());
+ EXPECT_TRUE(i2p1.is_blockable());
+ EXPECT_TRUE(i2p2.is_blockable());
+ EXPECT_TRUE(ip.is_blockable());
+}
+
+namespace
+{
+ struct test_command_i2p
+ {
+ net::i2p_address i2p;
+
+ BEGIN_KV_SERIALIZE_MAP()
+ KV_SERIALIZE(i2p);
+ END_KV_SERIALIZE_MAP()
+ };
+}
+
+TEST(i2p_address, epee_serializev_b32)
+{
+ std::string buffer{};
+ {
+ test_command_i2p command{MONERO_UNWRAP(net::i2p_address::make(b32_i2p, 10))};
+ EXPECT_FALSE(command.i2p.is_unknown());
+ EXPECT_NE(net::i2p_address{}, command.i2p);
+ EXPECT_STREQ(b32_i2p, command.i2p.host_str());
+ EXPECT_EQ(10u, command.i2p.port());
+
+ epee::serialization::portable_storage stg{};
+ EXPECT_TRUE(command.store(stg));
+ EXPECT_TRUE(stg.store_to_binary(buffer));
+ }
+
+ test_command_i2p command{};
+ {
+ EXPECT_TRUE(command.i2p.is_unknown());
+ EXPECT_EQ(net::i2p_address{}, command.i2p);
+ EXPECT_STREQ(net::i2p_address::unknown_str(), command.i2p.host_str());
+ EXPECT_EQ(0u, command.i2p.port());
+
+ epee::serialization::portable_storage stg{};
+ EXPECT_TRUE(stg.load_from_binary(buffer));
+ EXPECT_TRUE(command.load(stg));
+ }
+ EXPECT_FALSE(command.i2p.is_unknown());
+ EXPECT_NE(net::i2p_address{}, command.i2p);
+ EXPECT_STREQ(b32_i2p, command.i2p.host_str());
+ EXPECT_EQ(10u, command.i2p.port());
+
+ // make sure that exceeding max buffer doesn't destroy i2p_address::_load
+ {
+ epee::serialization::portable_storage stg{};
+ stg.load_from_binary(buffer);
+
+ std::string host{};
+ ASSERT_TRUE(stg.get_value("host", host, stg.open_section("i2p", nullptr, false)));
+ EXPECT_EQ(std::strlen(b32_i2p), host.size());
+
+ host.push_back('k');
+ EXPECT_TRUE(stg.set_value("host", std::string{host}, stg.open_section("i2p", nullptr, false)));
+ EXPECT_TRUE(command.load(stg)); // poor error reporting from `KV_SERIALIZE`
+ }
+
+ EXPECT_TRUE(command.i2p.is_unknown());
+ EXPECT_EQ(net::i2p_address{}, command.i2p);
+ EXPECT_STRNE(b32_i2p, command.i2p.host_str());
+ EXPECT_EQ(0u, command.i2p.port());
+}
+
+TEST(i2p_address, epee_serialize_unknown)
+{
+ std::string buffer{};
+ {
+ test_command_i2p command{net::i2p_address::unknown()};
+ EXPECT_TRUE(command.i2p.is_unknown());
+ EXPECT_EQ(net::i2p_address{}, command.i2p);
+ EXPECT_STREQ(net::i2p_address::unknown_str(), command.i2p.host_str());
+ EXPECT_EQ(0u, command.i2p.port());
+
+ epee::serialization::portable_storage stg{};
+ EXPECT_TRUE(command.store(stg));
+ EXPECT_TRUE(stg.store_to_binary(buffer));
+ }
+
+ test_command_i2p command{};
+ {
+ EXPECT_TRUE(command.i2p.is_unknown());
+ EXPECT_EQ(net::i2p_address{}, command.i2p);
+ EXPECT_STRNE(b32_i2p, command.i2p.host_str());
+ EXPECT_EQ(0u, command.i2p.port());
+
+ epee::serialization::portable_storage stg{};
+ EXPECT_TRUE(stg.load_from_binary(buffer));
+ EXPECT_TRUE(command.load(stg));
+ }
+ EXPECT_TRUE(command.i2p.is_unknown());
+ EXPECT_EQ(net::i2p_address{}, command.i2p);
+ EXPECT_STREQ(net::i2p_address::unknown_str(), command.i2p.host_str());
+ EXPECT_EQ(0u, command.i2p.port());
+
+ // make sure that exceeding max buffer doesn't destroy i2p_address::_load
+ {
+ epee::serialization::portable_storage stg{};
+ stg.load_from_binary(buffer);
+
+ std::string host{};
+ ASSERT_TRUE(stg.get_value("host", host, stg.open_section("i2p", nullptr, false)));
+ EXPECT_EQ(std::strlen(net::i2p_address::unknown_str()), host.size());
+
+ host.push_back('k');
+ EXPECT_TRUE(stg.set_value("host", std::string{host}, stg.open_section("i2p", nullptr, false)));
+ EXPECT_TRUE(command.load(stg)); // poor error reporting from `KV_SERIALIZE`
+ }
+
+ EXPECT_TRUE(command.i2p.is_unknown());
+ EXPECT_EQ(net::i2p_address{}, command.i2p);
+ EXPECT_STRNE(b32_i2p, command.i2p.host_str());
+ EXPECT_EQ(0u, command.i2p.port());
+}
+
+TEST(i2p_address, boost_serialize_b32)
+{
+ std::string buffer{};
+ {
+ const net::i2p_address i2p = MONERO_UNWRAP(net::i2p_address::make(b32_i2p, 10));
+ EXPECT_FALSE(i2p.is_unknown());
+ EXPECT_NE(net::i2p_address{}, i2p);
+ EXPECT_STREQ(b32_i2p, i2p.host_str());
+ EXPECT_EQ(10u, i2p.port());
+
+ std::ostringstream stream{};
+ {
+ boost::archive::portable_binary_oarchive archive{stream};
+ archive << i2p;
+ }
+ buffer = stream.str();
+ }
+
+ net::i2p_address i2p{};
+ {
+ EXPECT_TRUE(i2p.is_unknown());
+ EXPECT_EQ(net::i2p_address{}, i2p);
+ EXPECT_STREQ(net::i2p_address::unknown_str(), i2p.host_str());
+ EXPECT_EQ(0u, i2p.port());
+
+ std::istringstream stream{buffer};
+ boost::archive::portable_binary_iarchive archive{stream};
+ archive >> i2p;
+ }
+ EXPECT_FALSE(i2p.is_unknown());
+ EXPECT_NE(net::i2p_address{}, i2p);
+ EXPECT_STREQ(b32_i2p, i2p.host_str());
+ EXPECT_EQ(10u, i2p.port());
+}
+
+TEST(i2p_address, boost_serialize_unknown)
+{
+ std::string buffer{};
+ {
+ const net::i2p_address i2p{};
+ EXPECT_TRUE(i2p.is_unknown());
+ EXPECT_EQ(net::i2p_address::unknown(), i2p);
+ EXPECT_STREQ(net::i2p_address::unknown_str(), i2p.host_str());
+ EXPECT_EQ(0u, i2p.port());
+
+ std::ostringstream stream{};
+ {
+ boost::archive::portable_binary_oarchive archive{stream};
+ archive << i2p;
+ }
+ buffer = stream.str();
+ }
+
+ net::i2p_address i2p{};
+ {
+ EXPECT_TRUE(i2p.is_unknown());
+ EXPECT_EQ(net::i2p_address{}, i2p);
+ EXPECT_STREQ(net::i2p_address::unknown_str(), i2p.host_str());
+ EXPECT_EQ(0u, i2p.port());
+
+ std::istringstream stream{buffer};
+ boost::archive::portable_binary_iarchive archive{stream};
+ archive >> i2p;
+ }
+ EXPECT_TRUE(i2p.is_unknown());
+ EXPECT_EQ(net::i2p_address::unknown(), i2p);
+ EXPECT_STREQ(net::i2p_address::unknown_str(), i2p.host_str());
+ EXPECT_EQ(0u, i2p.port());
+}
+
+TEST(get_network_address, i2p)
+{
+ expect<epee::net_utils::network_address> address =
+ net::get_network_address("i2p", 0);
+ EXPECT_EQ(net::error::unsupported_address, address);
+
+ address = net::get_network_address(".b32.i2p", 0);
+ EXPECT_EQ(net::error::invalid_i2p_address, address);
+
+ address = net::get_network_address(b32_i2p, 1000);
+ ASSERT_TRUE(bool(address));
+ EXPECT_EQ(epee::net_utils::address_type::i2p, address->get_type_id());
+ EXPECT_STREQ(b32_i2p, address->host_str().c_str());
+ EXPECT_EQ(std::string{b32_i2p} + ":1000", address->str());
+
+ address = net::get_network_address(std::string{b32_i2p} + ":2000", 1000);
+ ASSERT_TRUE(bool(address));
+ EXPECT_EQ(epee::net_utils::address_type::i2p, address->get_type_id());
+ EXPECT_STREQ(b32_i2p, address->host_str().c_str());
+ EXPECT_EQ(std::string{b32_i2p} + ":2000", address->str());
+
+ address = net::get_network_address(std::string{b32_i2p} + ":65536", 1000);
+ EXPECT_EQ(net::error::invalid_port, address);
+}
TEST(get_network_address, ipv4)
{
diff --git a/tests/unit_tests/node_server.cpp b/tests/unit_tests/node_server.cpp
index dff223ed3..b656c4858 100644
--- a/tests/unit_tests/node_server.cpp
+++ b/tests/unit_tests/node_server.cpp
@@ -54,7 +54,6 @@ public:
bool init(const boost::program_options::variables_map& vm) {return true ;}
bool deinit(){return true;}
bool get_short_chain_history(std::list<crypto::hash>& ids) const { return true; }
- bool get_stat_info(cryptonote::core_stat_info& st_inf) const {return true;}
bool have_block(const crypto::hash& id) const {return true;}
void get_blockchain_top(uint64_t& height, crypto::hash& top_id)const{height=0;top_id=crypto::null_hash;}
bool handle_incoming_tx(const cryptonote::tx_blob_entry& tx_blob, cryptonote::tx_verification_context& tvc, cryptonote::relay_method tx_relay, bool relayed) { return true; }