some performance i,provements

pull/88/head
moneroexamples 6 years ago
parent 81c9974b92
commit 77e00ccba1

@ -82,7 +82,7 @@ Open Monero is not as fast as MyMonero.
in back, because viewkey is unknown. in back, because viewkey is unknown.
## Example compilation on Ubuntu 16.04 ## Example compilation on Ubuntu 18.04
Below are example and basic instructions on how to setup up and run Open Monero on Ubuntu 16.04. Below are example and basic instructions on how to setup up and run Open Monero on Ubuntu 16.04.
For other Linux operating systems, the instructions are analogical. For other Linux operating systems, the instructions are analogical.
@ -96,18 +96,18 @@ Download and compile recent Monero into your home folder:
# first install monero dependecines # first install monero dependecines
sudo apt update sudo apt update
sudo apt install git build-essential cmake libboost-all-dev miniupnpc libunbound-dev graphviz doxygen libunwind8-dev pkg-config libssl-dev libcurl4-openssl-dev libgtest-dev libreadline-dev libzmq3-dev sudo apt install git build-essential cmake libboost-all-dev miniupnpc libunbound-dev graphviz doxygen libunwind-dev pkg-config libssl-dev libcurl4-openssl-dev libgtest-dev libreadline-dev libzmq3-dev libsodium-dev
sudo wget -O /usr/local/include/zmq.hpp https://raw.githubusercontent.com/zeromq/cppzmq/master/zmq.hpp
# go to home folder # go to home folder
cd ~ cd ~
# get latest development version of monero. Monero changes so fast git clone --recursive https://github.com/monero-project/monero
# that if something breaks during compilation of open monero, please make an issue
git clone https://github.com/monero-project/monero
cd monero/ cd monero/
# checkout last monero version
git checkout -b last_release v0.12.0.0
make make
``` ```

@ -19,13 +19,8 @@ OutputInputIdentification::OutputInputIdentification(
tx = _tx; tx = _tx;
tx_hash = get_transaction_hash(*tx); tx_hash = get_transaction_hash(*tx);
tx_prefix_hash = get_transaction_prefix_hash(*tx);
tx_pub_key = xmreg::get_tx_pub_key_from_received_outs(*tx); tx_pub_key = xmreg::get_tx_pub_key_from_received_outs(*tx);
tx_hash_str = pod_to_hex(tx_hash);
tx_prefix_hash_str = pod_to_hex(tx_prefix_hash);
tx_pub_key_str = pod_to_hex(tx_pub_key);
tx_is_coinbase = is_coinbase(*tx); tx_is_coinbase = is_coinbase(*tx);
is_rct = (tx->version == 2); is_rct = (tx->version == 2);
@ -39,7 +34,7 @@ OutputInputIdentification::OutputInputIdentification(
if (!generate_key_derivation(tx_pub_key, *viewkey, derivation)) if (!generate_key_derivation(tx_pub_key, *viewkey, derivation))
{ {
cerr << "Cant get derived key for: " << "\n" cerr << "Cant get derived key for: " << "\n"
<< "pub_tx_key: " << tx_pub_key << " and " << "pub_tx_key: " << get_tx_pub_key_str() << " and "
<< "prv_view_key" << viewkey << endl; << "prv_view_key" << viewkey << endl;
throw OutputInputIdentificationException("Cant get derived key for a tx"); throw OutputInputIdentificationException("Cant get derived key for a tx");
@ -47,11 +42,20 @@ OutputInputIdentification::OutputInputIdentification(
if (!tx_is_coinbase) if (!tx_is_coinbase)
{ {
mixin_no = get_mixin_no(*tx);
} }
} }
uint64_t
OutputInputIdentification::get_mixin_no()
{
if (mixin_no == 0 && !tx_is_coinbase)
mixin_no = xmreg::get_mixin_no(*tx);
return mixin_no;
}
void void
OutputInputIdentification::identify_outputs() OutputInputIdentification::identify_outputs()
{ {
@ -141,7 +145,7 @@ OutputInputIdentification::identify_outputs()
// found an output associated with the given address and viewkey // found an output associated with the given address and viewkey
string msg = fmt::format("tx_hash: {:s}, output_pub_key: {:s}\n", string msg = fmt::format("tx_hash: {:s}, output_pub_key: {:s}\n",
tx_hash_str, get_tx_hash_str(),
out_key_str); out_key_str);
cout << msg << endl; cout << msg << endl;
@ -254,4 +258,39 @@ OutputInputIdentification::identify_inputs(
} }
string const&
OutputInputIdentification::get_tx_hash_str()
{
if (tx_hash_str.empty())
{
tx_hash_str = pod_to_hex(tx_hash);
}
return tx_hash_str;
}
string const&
OutputInputIdentification::get_tx_prefix_hash_str()
{
if (tx_prefix_hash_str.empty())
{
tx_prefix_hash = get_transaction_prefix_hash(*tx);
tx_prefix_hash_str = pod_to_hex(tx_prefix_hash);
}
return tx_prefix_hash_str;
}
string const&
OutputInputIdentification::get_tx_pub_key_str()
{
if (tx_pub_key_str.empty())
tx_pub_key_str = pod_to_hex(tx_pub_key);
return tx_pub_key_str;
}
} }

@ -82,7 +82,7 @@ public:
bool is_rct; bool is_rct;
uint8_t rct_type; uint8_t rct_type;
uint64_t mixin_no; uint64_t mixin_no {};
// for each output, in a tx, check if it belongs // for each output, in a tx, check if it belongs
// to the given account of specific address and viewkey // to the given account of specific address and viewkey
@ -128,6 +128,18 @@ public:
void identify_inputs( void identify_inputs(
const vector<pair<string, uint64_t>>& known_outputs_keys); const vector<pair<string, uint64_t>>& known_outputs_keys);
string const&
get_tx_hash_str();
string const&
get_tx_prefix_hash_str();
string const&
get_tx_pub_key_str();
uint64_t
get_mixin_no();
private: private:
// address and viewkey for this search thread. // address and viewkey for this search thread.

@ -72,7 +72,7 @@ TxSearch::search()
uint64_t loop_timestamp {current_timestamp}; uint64_t loop_timestamp {current_timestamp};
if (loop_idx % 5 == 0) if (loop_idx % 10 == 0)
{ {
// get loop time every fith iteration. no need to call it // get loop time every fith iteration. no need to call it
// all the time. // all the time.
@ -135,12 +135,14 @@ TxSearch::search()
{ {
// print status every 100th block // print status every 100th block
fmt::print(" - searching block {:d} of hash {:s} \n", cout << " - searching block " << searched_blk_no
searched_blk_no, pod_to_hex(get_block_hash(blk))); << " of hash: "
<< searched_blk_no << get_block_hash(blk) << '\n';
} }
DateTime blk_timestamp_mysql_format // we will only create mysql DateTime object once, anything is found
= XmrTransaction::timestamp_to_DateTime(blk.timestamp); // in a given block;
unique_ptr<DateTime> blk_timestamp_mysql_format;
// searching for our incoming and outgoing xmr has two components. // searching for our incoming and outgoing xmr has two components.
// //
@ -177,7 +179,7 @@ TxSearch::search()
if (!CurrentBlockchainStatus::tx_exist(oi_identification.tx_hash, blockchain_tx_id)) if (!CurrentBlockchainStatus::tx_exist(oi_identification.tx_hash, blockchain_tx_id))
{ {
cerr << "Tx " << oi_identification.tx_hash_str cerr << "Tx " << oi_identification.get_tx_hash_str()
<< "not found in blockchain !" << '\n'; << "not found in blockchain !" << '\n';
continue; continue;
} }
@ -189,8 +191,9 @@ TxSearch::search()
uint64_t tx_mysql_id {0}; uint64_t tx_mysql_id {0};
// start mysql transaction // create pointer to mysql transaction object
mysqlpp::Transaction trans(xmr_accounts->get_connection()->get_connection()); // that we will initilize if we find something.
unique_ptr<mysqlpp::Transaction> mysql_transaction;
// if we identified some outputs as ours, // if we identified some outputs as ours,
// save them into mysql. // save them into mysql.
@ -230,11 +233,29 @@ TxSearch::search()
// } // }
// } // }
if (!blk_timestamp_mysql_format)
{
blk_timestamp_mysql_format
= unique_ptr<DateTime>(
new DateTime(static_cast<time_t>(blk.timestamp)));
}
if (!mysql_transaction)
{
// start mysql transaction here
mysql_transaction
= unique_ptr<mysqlpp::Transaction>(
new mysqlpp::Transaction(
xmr_accounts->get_connection()
->get_connection()));
}
XmrTransaction tx_data; XmrTransaction tx_data;
tx_data.hash = oi_identification.tx_hash_str; tx_data.hash = oi_identification.get_tx_hash_str();
tx_data.prefix_hash = oi_identification.tx_prefix_hash_str; tx_data.prefix_hash = oi_identification.get_tx_prefix_hash_str();
tx_data.tx_pub_key = oi_identification.tx_pub_key_str; tx_data.tx_pub_key = oi_identification.get_tx_pub_key_str();
tx_data.account_id = acc->id; tx_data.account_id = acc->id;
tx_data.blockchain_tx_id = blockchain_tx_id; tx_data.blockchain_tx_id = blockchain_tx_id;
tx_data.total_received = oi_identification.total_received; tx_data.total_received = oi_identification.total_received;
@ -253,8 +274,8 @@ TxSearch::search()
tx_data.rct_type = oi_identification.rct_type; tx_data.rct_type = oi_identification.rct_type;
tx_data.spendable = is_spendable; tx_data.spendable = is_spendable;
tx_data.payment_id = CurrentBlockchainStatus::get_payment_id_as_string(tx); tx_data.payment_id = CurrentBlockchainStatus::get_payment_id_as_string(tx);
tx_data.mixin = oi_identification.mixin_no; tx_data.mixin = oi_identification.get_mixin_no();
tx_data.timestamp = blk_timestamp_mysql_format; tx_data.timestamp = *blk_timestamp_mysql_format;
// insert tx_data into mysql's Transactions table // insert tx_data into mysql's Transactions table
@ -283,7 +304,7 @@ TxSearch::search()
out_data.account_id = acc->id; out_data.account_id = acc->id;
out_data.tx_id = tx_mysql_id; out_data.tx_id = tx_mysql_id;
out_data.out_pub_key = out_info.pub_key; out_data.out_pub_key = out_info.pub_key;
out_data.tx_pub_key = oi_identification.tx_pub_key_str; out_data.tx_pub_key = oi_identification.get_tx_pub_key_str();
out_data.amount = out_info.amount; out_data.amount = out_info.amount;
out_data.out_index = out_info.idx_in_tx; out_data.out_index = out_info.idx_in_tx;
out_data.rct_outpk = out_info.rtc_outpk; out_data.rct_outpk = out_info.rtc_outpk;
@ -325,6 +346,26 @@ TxSearch::search()
// so now, go over those inputs, and check // so now, go over those inputs, and check
// get detail info for each found mixin output from database // get detail info for each found mixin output from database
if (!blk_timestamp_mysql_format)
{
blk_timestamp_mysql_format
= unique_ptr<DateTime>(
new DateTime(static_cast<time_t>(blk.timestamp)));
}
if (!mysql_transaction)
{
// start mysql transaction here if not already present
mysql_transaction
= unique_ptr<mysqlpp::Transaction>(
new mysqlpp::Transaction(
xmr_accounts->get_connection()
->get_connection()));
}
vector<XmrInput> inputs_found; vector<XmrInput> inputs_found;
for (auto& in_info: oi_identification.identified_inputs) for (auto& in_info: oi_identification.identified_inputs)
@ -348,7 +389,7 @@ TxSearch::search()
in_data.output_id = out.id; in_data.output_id = out.id;
in_data.key_image = in_info.key_img; in_data.key_image = in_info.key_img;
in_data.amount = out.amount; // must match corresponding output's amount in_data.amount = out.amount; // must match corresponding output's amount
in_data.timestamp = blk_timestamp_mysql_format; in_data.timestamp = *blk_timestamp_mysql_format;
inputs_found.push_back(in_data); inputs_found.push_back(in_data);
@ -367,9 +408,7 @@ TxSearch::search()
uint64_t total_sent {0}; uint64_t total_sent {0};
for (const XmrInput& in_data: inputs_found) for (const XmrInput& in_data: inputs_found)
{
total_sent += in_data.amount; total_sent += in_data.amount;
}
if (tx_mysql_id == 0) if (tx_mysql_id == 0)
{ {
@ -381,9 +420,9 @@ TxSearch::search()
XmrTransaction tx_data; XmrTransaction tx_data;
tx_data.hash = oi_identification.tx_hash_str; tx_data.hash = oi_identification.get_tx_hash_str();
tx_data.prefix_hash = oi_identification.tx_prefix_hash_str; tx_data.prefix_hash = oi_identification.get_tx_prefix_hash_str();
tx_data.tx_pub_key = oi_identification.tx_pub_key_str; tx_data.tx_pub_key = oi_identification.get_tx_pub_key_str();
tx_data.account_id = acc->id; tx_data.account_id = acc->id;
tx_data.blockchain_tx_id = blockchain_tx_id; tx_data.blockchain_tx_id = blockchain_tx_id;
tx_data.total_received = 0; // because this is spending, total_recieved is 0 tx_data.total_received = 0; // because this is spending, total_recieved is 0
@ -395,8 +434,8 @@ TxSearch::search()
tx_data.rct_type = oi_identification.rct_type; tx_data.rct_type = oi_identification.rct_type;
tx_data.spendable = is_spendable; tx_data.spendable = is_spendable;
tx_data.payment_id = CurrentBlockchainStatus::get_payment_id_as_string(tx); tx_data.payment_id = CurrentBlockchainStatus::get_payment_id_as_string(tx);
tx_data.mixin = get_mixin_no(tx) - 1; tx_data.mixin = oi_identification.get_mixin_no();
tx_data.timestamp = blk_timestamp_mysql_format; tx_data.timestamp = *blk_timestamp_mysql_format;
// insert tx_data into mysql's Transactions table // insert tx_data into mysql's Transactions table
tx_mysql_id = xmr_accounts->insert_tx(tx_data); tx_mysql_id = xmr_accounts->insert_tx(tx_data);
@ -431,7 +470,8 @@ TxSearch::search()
// to be written, i.e., Transactions, Outputs and Inputs. If so, write // to be written, i.e., Transactions, Outputs and Inputs. If so, write
// all this into database. // all this into database.
trans.commit(); if (mysql_transaction)
mysql_transaction->commit();
} // for (const transaction& tx: blk_txs) } // for (const transaction& tx: blk_txs)
@ -444,8 +484,15 @@ TxSearch::search()
XmrAccount updated_acc = *acc; XmrAccount updated_acc = *acc;
if (!blk_timestamp_mysql_format)
{
blk_timestamp_mysql_format
= unique_ptr<DateTime>(
new DateTime(static_cast<time_t>(blk.timestamp)));
}
updated_acc.scanned_block_height = searched_blk_no; updated_acc.scanned_block_height = searched_blk_no;
updated_acc.scanned_block_timestamp = blk_timestamp_mysql_format; updated_acc.scanned_block_timestamp = *blk_timestamp_mysql_format;
if (xmr_accounts->update(*acc, updated_acc)) if (xmr_accounts->update(*acc, updated_acc))
{ {
@ -585,8 +632,8 @@ TxSearch::find_txs_in_mempool(
j_tx["id"] = 0; // dont have any database id for tx in mempool j_tx["id"] = 0; // dont have any database id for tx in mempool
// this id is used for sorting txs in the frontend. // this id is used for sorting txs in the frontend.
j_tx["hash"] = oi_identification.tx_hash_str; j_tx["hash"] = oi_identification.get_tx_hash_str();
j_tx["tx_pub_key"] = oi_identification.tx_pub_key_str; j_tx["tx_pub_key"] = oi_identification.get_tx_pub_key_str();
j_tx["timestamp"] = recieve_time; // when it got into mempool j_tx["timestamp"] = recieve_time; // when it got into mempool
j_tx["total_received"] = oi_identification.total_received; j_tx["total_received"] = oi_identification.total_received;
j_tx["total_sent"] = 0; // to be set later when looking for key images j_tx["total_sent"] = 0; // to be set later when looking for key images
@ -600,7 +647,7 @@ TxSearch::find_txs_in_mempool(
j_tx["coinbase"] = false; // mempool tx are not coinbase, so always false j_tx["coinbase"] = false; // mempool tx are not coinbase, so always false
j_tx["is_rct"] = oi_identification.is_rct; j_tx["is_rct"] = oi_identification.is_rct;
j_tx["rct_type"] = oi_identification.rct_type; j_tx["rct_type"] = oi_identification.rct_type;
j_tx["mixin"] = get_mixin_no(tx); j_tx["mixin"] = oi_identification.get_mixin_no();
j_tx["mempool"] = true; j_tx["mempool"] = true;
j_transactions.push_back(j_tx); j_transactions.push_back(j_tx);
@ -673,8 +720,8 @@ TxSearch::find_txs_in_mempool(
j_tx["id"] = 0; // dont have any database id for tx in mempool j_tx["id"] = 0; // dont have any database id for tx in mempool
// this id is used for sorting txs in the frontend. // this id is used for sorting txs in the frontend.
j_tx["hash"] = oi_identification.tx_hash_str; j_tx["hash"] = oi_identification.get_tx_hash_str();
j_tx["tx_pub_key"] = oi_identification.tx_pub_key_str; j_tx["tx_pub_key"] = oi_identification.get_tx_pub_key_str();
j_tx["timestamp"] = recieve_time; // when it got into mempool j_tx["timestamp"] = recieve_time; // when it got into mempool
j_tx["total_received"] = 0; // we did not recive any outputs/xmr j_tx["total_received"] = 0; // we did not recive any outputs/xmr
j_tx["total_sent"] = total_sent; // to be set later when looking for key images j_tx["total_sent"] = total_sent; // to be set later when looking for key images

Loading…
Cancel
Save