known_outputs_keys added to TxSearch

pull/2/head
moneroexamples 7 years ago
parent cce96d24ae
commit 52276bef91

@ -69,7 +69,7 @@ xmreg::MySqlConnector::dbname = "openmonero";
// setup blockchain status monitoring thread
xmreg::CurrentBlockchainStatus::set_blockchain_path(blockchain_path.string());
xmreg::CurrentBlockchainStatus::set_testnet(testnet);
xmreg::CurrentBlockchainStatus::refresh_block_status_every_seconds = 60;
xmreg::CurrentBlockchainStatus::refresh_block_status_every_seconds = 30;
xmreg::CurrentBlockchainStatus::import_payment_address = address_str;
xmreg::CurrentBlockchainStatus::import_payment_viewkey = viewkey_str;
xmreg::CurrentBlockchainStatus::import_fee = static_cast<uint64_t>(0.01e12);

@ -35,6 +35,8 @@ TxSearch::TxSearch(XmrAccount& _acc)
throw TxSearchException("Cant parse private key: " + acc->viewkey);
}
populate_known_outputs();
// start searching from last block that we searched for
// this accont
searched_blk_no = acc->scanned_block_height;
@ -352,6 +354,10 @@ TxSearch::search()
//cerr << "out_mysql_id is zero!" << endl;
//throw TxSearchException("out_mysql_id is zero!");
}
// add the new output to our cash of known outputs
known_outputs_keys.push_back(std::get<0>(out_k_idx));
} // for (auto &out_k_idx: found_mine_outputs)
@ -405,6 +411,21 @@ TxSearch::search()
{
string output_public_key_str = pod_to_hex(output_data.pubkey);
// before going to the mysql, check our known outputs cash
// if the key exists. Its much faster than going to mysql
// for this.
if (std::find(
known_outputs_keys.begin(),
known_outputs_keys.end(),
output_public_key_str)
== known_outputs_keys.end())
{
// this mixins's output is unknown.
continue;
}
XmrOutput out;
if (xmr_accounts->output_exists(output_public_key_str, out))
@ -562,6 +583,20 @@ TxSearch::still_searching()
return continue_search;
}
void
TxSearch::populate_known_outputs()
{
vector<XmrOutput> outs;
if (xmr_accounts->select_outputs(acc->id, outs))
{
for (const XmrOutput& out: outs)
{
known_outputs_keys.push_back(out.out_pub_key);
}
}
}
}

@ -48,6 +48,12 @@ class TxSearch
// represents a row in mysql's Accounts table
shared_ptr<XmrAccount> acc;
// stores known output public keys.
// used as a cash to fast look up of
// our public keys in key images. Saves a lot of
// mysql queries to Outputs table.
vector<string> known_outputs_keys;
// this manages all mysql queries
// its better to when each thread has its own mysql connection object.
// this way if one thread crashes, it want take down
@ -79,6 +85,9 @@ public:
bool
still_searching();
void
populate_known_outputs();
};

Loading…
Cancel
Save