Skip to content

Commit

Permalink
Merge commit '89645ec' into LokiMergeUpstream20180821
Browse files Browse the repository at this point in the history
  • Loading branch information
Doy-lee committed Sep 25, 2018
2 parents cd59815 + 89645ec commit 3f85a1b
Show file tree
Hide file tree
Showing 21 changed files with 477 additions and 285 deletions.
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ RUN set -ex && \
WORKDIR /usr/local

#Cmake
ARG CMAKE_VERSION=3.11.4
ARG CMAKE_VERSION_DOT=v3.11
ARG CMAKE_HASH=8f864e9f78917de3e1483e256270daabc4a321741592c5b36af028e72bff87f5
ARG CMAKE_VERSION=3.12.0
ARG CMAKE_VERSION_DOT=v3.12
ARG CMAKE_HASH=d0781a90f6cdb9049d104ac16a150f9350b693498b9dea8a0331e799db6b9d69
RUN set -ex \
&& curl -s -O https://cmake.org/files/${CMAKE_VERSION_DOT}/cmake-${CMAKE_VERSION}.tar.gz \
&& echo "${CMAKE_HASH} cmake-${CMAKE_VERSION}.tar.gz" | sha256sum -c \
Expand Down
4 changes: 3 additions & 1 deletion contrib/epee/src/mlog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ 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;
for (boost::filesystem::directory_iterator iter(boost::filesystem::path(filename_base).parent_path()); iter != end_itr; ++iter)
const boost::filesystem::path filename_base_path(filename_base);
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)
Expand Down
2 changes: 1 addition & 1 deletion src/blockchain_db/berkeleydb/db_bdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,6 @@ class BlockchainBDB : public BlockchainDB
virtual uint64_t get_indexing_base() const { return 1; }

virtual output_data_t get_output_key(const uint64_t& amount, const uint64_t& index) const;
virtual output_data_t get_output_key(const uint64_t& global_index) const;
virtual void get_output_key(const uint64_t &amount, const std::vector<uint64_t> &offsets, std::vector<output_data_t> &outputs) const;

virtual tx_out_index get_output_tx_and_index_from_global(const uint64_t& index) const;
Expand Down Expand Up @@ -419,6 +418,7 @@ class BlockchainBDB : public BlockchainDB
* @return the global index of the desired output
*/
uint64_t get_output_global_index(const uint64_t& amount, const uint64_t& index);
output_data_t get_output_key(const uint64_t& global_index) const;
void checkpoint_worker() const;
void check_open() const;

Expand Down
4 changes: 2 additions & 2 deletions src/blockchain_db/blockchain_db.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ const command_line::arg_descriptor<std::string> arg_db_type = {
};
const command_line::arg_descriptor<std::string> arg_db_sync_mode = {
"db-sync-mode"
, "Specify sync option, using format [safe|fast|fastest]:[sync|async]:[nblocks_per_sync]."
, "fast:async:1000"
, "Specify sync option, using format [safe|fast|fastest]:[sync|async]:[<nblocks_per_sync>[blocks]|<nbytes_per_sync>[bytes]]."
, "fast:async:250000000bytes"
};
const command_line::arg_descriptor<bool> arg_db_salvage = {
"db-salvage"
Expand Down
17 changes: 0 additions & 17 deletions src/blockchain_db/blockchain_db.h
Original file line number Diff line number Diff line change
Expand Up @@ -1277,23 +1277,6 @@ class BlockchainDB
*/
virtual output_data_t get_output_key(const uint64_t& amount, const uint64_t& index) const = 0;

/**
* @brief get some of an output's data
*
* The subclass should return the public key, unlock time, and block height
* for the output with the given global index, collected in a struct.
*
* If the output cannot be found, the subclass should throw OUTPUT_DNE.
*
* If any of these parts cannot be found, but some are, the subclass
* should throw DB_ERROR with a message stating as much.
*
* @param global_index the output's index (global)
*
* @return the requested output data
*/
virtual output_data_t get_output_key(const uint64_t& global_index) const = 0;

/**
* @brief gets an output's tx hash and index
*
Expand Down
49 changes: 0 additions & 49 deletions src/blockchain_db/lmdb/db_lmdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2460,55 +2460,6 @@ uint64_t BlockchainLMDB::get_num_outputs(const uint64_t& amount) const
return num_elems;
}

// This is a lot harder now that we've removed the output_keys index
output_data_t BlockchainLMDB::get_output_key(const uint64_t &global_index) const
{
LOG_PRINT_L3("BlockchainLMDB::" << __func__ << " (unused version - does nothing)");
check_open();
TXN_PREFIX_RDONLY();
RCURSOR(output_txs);
RCURSOR(tx_indices);

output_data_t od;
MDB_val_set(v, global_index);
auto get_result = mdb_cursor_get(m_cur_output_txs, (MDB_val *)&zerokval, &v, MDB_GET_BOTH);
if (get_result == MDB_NOTFOUND)
throw1(OUTPUT_DNE("output with given index not in db"));
else if (get_result)
throw0(DB_ERROR("DB error attempting to fetch output tx hash"));

outtx *ot = (outtx *)v.mv_data;

MDB_val_set(val_h, ot->tx_hash);
get_result = mdb_cursor_get(m_cur_tx_indices, (MDB_val *)&zerokval, &val_h, MDB_GET_BOTH);
if (get_result)
throw0(DB_ERROR(lmdb_error(std::string("DB error attempting to fetch transaction index from hash ") + epee::string_tools::pod_to_hex(ot->tx_hash) + ": ", get_result).c_str()));

txindex *tip = (txindex *)val_h.mv_data;
MDB_val_set(val_tx_id, tip->data.tx_id);
MDB_val result;
get_result = mdb_cursor_get(m_cur_txs_pruned, &val_tx_id, &result, MDB_SET);
if (get_result == MDB_NOTFOUND)
throw1(TX_DNE(std::string("tx with hash ").append(epee::string_tools::pod_to_hex(ot->tx_hash)).append(" not found in db").c_str()));
else if (get_result)
throw0(DB_ERROR(lmdb_error("DB error attempting to fetch tx from hash", get_result).c_str()));

blobdata bd;
bd.assign(reinterpret_cast<char*>(result.mv_data), result.mv_size);

transaction tx;
if (!parse_and_validate_tx_base_from_blob(bd, tx))
throw0(DB_ERROR("Failed to parse tx from blob retrieved from the db"));

const tx_out tx_output = tx.vout[ot->local_index];
od.unlock_time = tip->data.unlock_time;
od.height = tip->data.block_id;
od.pubkey = boost::get<txout_to_key>(tx_output.target).key;

TXN_POSTFIX_RDONLY();
return od;
}

output_data_t BlockchainLMDB::get_output_key(const uint64_t& amount, const uint64_t& index) const
{
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
Expand Down
1 change: 0 additions & 1 deletion src/blockchain_db/lmdb/db_lmdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,6 @@ class BlockchainLMDB : public BlockchainDB
virtual uint64_t get_num_outputs(const uint64_t& amount) const;

virtual output_data_t get_output_key(const uint64_t& amount, const uint64_t& index) const;
virtual output_data_t get_output_key(const uint64_t& global_index) const;
virtual void get_output_key(const uint64_t &amount, const std::vector<uint64_t> &offsets, std::vector<output_data_t> &outputs, bool allow_partial = false) const;

virtual tx_out_index get_output_tx_and_index_from_global(const uint64_t& index) const;
Expand Down
12 changes: 8 additions & 4 deletions src/cryptonote_core/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ static const struct {
//------------------------------------------------------------------
Blockchain::Blockchain(tx_memory_pool& tx_pool, service_nodes::service_node_list& service_node_list, loki::deregister_vote_pool& deregister_vote_pool):
m_db(), m_tx_pool(tx_pool), m_hardfork(NULL), m_timestamps_and_difficulties_height(0), m_current_block_cumul_sz_limit(0), m_current_block_cumul_sz_median(0),
m_enforce_dns_checkpoints(false), m_max_prepare_blocks_threads(4), m_db_blocks_per_sync(1), m_db_sync_mode(db_async), m_db_default_sync(false), m_fast_sync(true), m_show_time_stats(false), m_sync_counter(0), m_cancel(false),
m_enforce_dns_checkpoints(false), m_max_prepare_blocks_threads(4), m_db_sync_on_blocks(true), m_db_sync_threshold(1), m_db_sync_mode(db_async), m_db_default_sync(false), m_fast_sync(true), m_show_time_stats(false), m_sync_counter(0), m_bytes_to_sync(0), m_cancel(false),
m_difficulty_for_next_block_top_hash(crypto::null_hash),
m_difficulty_for_next_block(1),
m_service_node_list(service_node_list),
Expand Down Expand Up @@ -4045,11 +4045,13 @@ bool Blockchain::cleanup_handle_incoming_blocks(bool force_sync)
store_blockchain();
m_sync_counter = 0;
}
else if (m_db_blocks_per_sync && m_sync_counter >= m_db_blocks_per_sync)
else if (m_db_sync_threshold && ((m_db_sync_on_blocks && m_sync_counter >= m_db_sync_threshold) || (!m_db_sync_on_blocks && m_bytes_to_sync >= m_db_sync_threshold)))
{
MDEBUG("Sync threshold met, syncing");
if(m_db_sync_mode == db_async)
{
m_sync_counter = 0;
m_bytes_to_sync = 0;
m_async_service.dispatch(boost::bind(&Blockchain::store_blockchain, this));
}
else if(m_db_sync_mode == db_sync)
Expand Down Expand Up @@ -4241,6 +4243,7 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::vector<block_complete
}
total_txs += entry.txs.size();
}
m_bytes_to_sync += bytes;
while (!(stop_batch = m_db->batch_start(blocks_entry.size(), bytes))) {
m_blockchain_lock.unlock();
m_tx_pool.unlock();
Expand Down Expand Up @@ -4591,7 +4594,7 @@ bool Blockchain::for_all_txpool_txes(std::function<bool(const crypto::hash&, con
return m_db->for_all_txpool_txes(f, include_blob, include_unrelayed_txes);
}

void Blockchain::set_user_options(uint64_t maxthreads, uint64_t blocks_per_sync, blockchain_db_sync_mode sync_mode, bool fast_sync)
void Blockchain::set_user_options(uint64_t maxthreads, bool sync_on_blocks, uint64_t sync_threshold, blockchain_db_sync_mode sync_mode, bool fast_sync)
{
if (sync_mode == db_defaultsync)
{
Expand All @@ -4600,7 +4603,8 @@ void Blockchain::set_user_options(uint64_t maxthreads, uint64_t blocks_per_sync,
}
m_db_sync_mode = sync_mode;
m_fast_sync = fast_sync;
m_db_blocks_per_sync = blocks_per_sync;
m_db_sync_on_blocks = sync_on_blocks;
m_db_sync_threshold = sync_threshold;
m_max_prepare_blocks_threads = maxthreads;
}

Expand Down
9 changes: 6 additions & 3 deletions src/cryptonote_core/blockchain.h
Original file line number Diff line number Diff line change
Expand Up @@ -763,11 +763,12 @@ namespace cryptonote
* @brief sets various performance options
*
* @param maxthreads max number of threads when preparing blocks for addition
* @param blocks_per_sync number of blocks to cache before syncing to database
* @param sync_on_blocks whether to sync based on blocks or bytes
* @param sync_threshold number of blocks/bytes to cache before syncing to database
* @param sync_mode the ::blockchain_db_sync_mode to use
* @param fast_sync sync using built-in block hashes as trusted
*/
void set_user_options(uint64_t maxthreads, uint64_t blocks_per_sync,
void set_user_options(uint64_t maxthreads, bool sync_on_blocks, uint64_t sync_threshold,
blockchain_db_sync_mode sync_mode, bool fast_sync);

/**
Expand Down Expand Up @@ -1068,11 +1069,13 @@ namespace cryptonote
bool m_fast_sync;
bool m_show_time_stats;
bool m_db_default_sync;
uint64_t m_db_blocks_per_sync;
bool m_db_sync_on_blocks;
uint64_t m_db_sync_threshold;
uint64_t m_max_prepare_blocks_threads;
uint64_t m_fake_pow_calc_time;
uint64_t m_fake_scan_time;
uint64_t m_sync_counter;
uint64_t m_bytes_to_sync;
std::vector<uint64_t> m_timestamps;
std::vector<difficulty_type> m_difficulties;
uint64_t m_timestamps_and_difficulties_height;
Expand Down
28 changes: 21 additions & 7 deletions src/cryptonote_core/cryptonote_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -460,9 +460,10 @@ namespace cryptonote
MGINFO("Loading blockchain from folder " << folder.string() << " ...");

const std::string filename = folder.string();
// default to fast:async:1
// default to fast:async:1 if overridden
blockchain_db_sync_mode sync_mode = db_defaultsync;
uint64_t blocks_per_sync = 1;
bool sync_on_blocks = true;
uint64_t sync_threshold = 1;

if (m_nettype == FAKECHAIN)
{
Expand Down Expand Up @@ -512,7 +513,7 @@ namespace cryptonote
else if(options[0] == "fastest")
{
db_flags = DBF_FASTEST;
blocks_per_sync = 1000; // default to fastest:async:1000
sync_threshold = 1000; // default to fastest:async:1000
sync_mode = db_sync_mode_is_default ? db_defaultsync : db_async;
}
else
Expand All @@ -530,9 +531,22 @@ namespace cryptonote
if(options.size() >= 3 && !safemode)
{
char *endptr;
uint64_t bps = strtoull(options[2].c_str(), &endptr, 0);
if (*endptr == '\0')
blocks_per_sync = bps;
uint64_t threshold = strtoull(options[2].c_str(), &endptr, 0);
if (*endptr == '\0' || !strcmp(endptr, "blocks"))
{
sync_on_blocks = true;
sync_threshold = threshold;
}
else if (!strcmp(endptr, "bytes"))
{
sync_on_blocks = false;
sync_threshold = threshold;
}
else
{
LOG_ERROR("Invalid db sync mode: " << options[2]);
return false;
}
}

if (db_salvage)
Expand All @@ -549,7 +563,7 @@ namespace cryptonote
}

m_blockchain_storage.set_user_options(blocks_threads,
blocks_per_sync, sync_mode, fast_sync);
sync_on_blocks, sync_threshold, sync_mode, fast_sync);

const std::pair<uint8_t, uint64_t> regtest_hard_forks[3] = {std::make_pair(1, 0), std::make_pair(Blockchain::get_hard_fork_heights(MAINNET).back().version, 1), std::make_pair(0, 0)};
const cryptonote::test_options regtest_test_options = {
Expand Down
2 changes: 1 addition & 1 deletion src/cryptonote_core/tx_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ namespace cryptonote
m_txpool_size -= txblob.size();
remove_transaction_keyimages(tx);
MINFO("Pruned tx " << txid << " from txpool: size: " << txblob.size() << ", fee/byte: " << std::get<1>(it->first));
it = --m_txs_by_fee_and_receive_time.erase(it);
it = m_txs_by_fee_and_receive_time.erase(it);
changed = true;
}
catch (const std::exception &e)
Expand Down
19 changes: 12 additions & 7 deletions src/cryptonote_protocol/cryptonote_protocol_handler.inl
Original file line number Diff line number Diff line change
Expand Up @@ -1737,11 +1737,6 @@ skip:
fluffy_arg.b = arg.b;
fluffy_arg.b.txs = fluffy_txs;

// pre-serialize them
std::string fullBlob, fluffyBlob;
epee::serialization::store_t_to_binary(arg, fullBlob);
epee::serialization::store_t_to_binary(fluffy_arg, fluffyBlob);

// sort peers between fluffy ones and others
std::list<boost::uuids::uuid> fullConnections, fluffyConnections;
m_p2p->for_each_connection([this, &exclude_context, &fullConnections, &fluffyConnections](connection_context& context, nodetool::peerid_type peer_id, uint32_t support_flags)
Expand All @@ -1763,8 +1758,18 @@ skip:
});

// send fluffy ones first, we want to encourage people to run that
m_p2p->relay_notify_to_list(NOTIFY_NEW_FLUFFY_BLOCK::ID, fluffyBlob, fluffyConnections);
m_p2p->relay_notify_to_list(NOTIFY_NEW_BLOCK::ID, fullBlob, fullConnections);
if (!fluffyConnections.empty())
{
std::string fluffyBlob;
epee::serialization::store_t_to_binary(fluffy_arg, fluffyBlob);
m_p2p->relay_notify_to_list(NOTIFY_NEW_FLUFFY_BLOCK::ID, fluffyBlob, fluffyConnections);
}
if (!fullConnections.empty())
{
std::string fullBlob;
epee::serialization::store_t_to_binary(arg, fullBlob);
m_p2p->relay_notify_to_list(NOTIFY_NEW_BLOCK::ID, fullBlob, fullConnections);
}

return true;
}
Expand Down
10 changes: 10 additions & 0 deletions src/ringct/rctTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,16 @@ namespace rct {
};
struct rctSig: public rctSigBase {
rctSigPrunable p;

keyV& get_pseudo_outs()
{
return type == RCTTypeSimpleBulletproof ? p.pseudoOuts : pseudoOuts;
}

keyV const& get_pseudo_outs() const
{
return type == RCTTypeSimpleBulletproof ? p.pseudoOuts : pseudoOuts;
}
};

//other basepoint H = toPoint(cn_fast_hash(G)), G the basepoint
Expand Down
Loading

0 comments on commit 3f85a1b

Please sign in to comment.