wallet: speedup refresh from daemon
Assume the whole of a coinbase goes to the same address (so that if the first output isn't for us, none of it is), and only look for payment id when we received something in the transaction.
This commit is contained in:
parent
ea707c779c
commit
d2c031332e
@ -174,8 +174,9 @@ void wallet2::check_acc_out(const account_keys &acc, const tx_out &o, const cryp
|
|||||||
error = false;
|
error = false;
|
||||||
}
|
}
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
void wallet2::process_new_transaction(const cryptonote::transaction& tx, uint64_t height)
|
void wallet2::process_new_transaction(const cryptonote::transaction& tx, uint64_t height, bool miner_tx)
|
||||||
{
|
{
|
||||||
|
if (!miner_tx)
|
||||||
process_unconfirmed(tx, height);
|
process_unconfirmed(tx, height);
|
||||||
std::vector<size_t> outs;
|
std::vector<size_t> outs;
|
||||||
uint64_t tx_money_got_in_outs = 0;
|
uint64_t tx_money_got_in_outs = 0;
|
||||||
@ -202,8 +203,27 @@ void wallet2::process_new_transaction(const cryptonote::transaction& tx, uint64_
|
|||||||
|
|
||||||
tx_pub_key = pub_key_field.pub_key;
|
tx_pub_key = pub_key_field.pub_key;
|
||||||
bool r = true;
|
bool r = true;
|
||||||
int threads = std::thread::hardware_concurrency();
|
int threads;
|
||||||
if (threads > 1)
|
if (miner_tx)
|
||||||
|
{
|
||||||
|
for (size_t i = 0; i < tx.vout.size(); ++i)
|
||||||
|
{
|
||||||
|
uint64_t money_transfered = 0;
|
||||||
|
bool error = false;
|
||||||
|
check_acc_out(m_account.get_keys(), tx.vout[i], tx_pub_key, i, money_transfered, error);
|
||||||
|
if (error)
|
||||||
|
{
|
||||||
|
r = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// this assumes that the miner tx pays a single address
|
||||||
|
if (money_transfered == 0)
|
||||||
|
break;
|
||||||
|
outs.push_back(i);
|
||||||
|
tx_money_got_in_outs += money_transfered;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (tx.vout.size() > 1 && (threads = std::thread::hardware_concurrency()) > 1)
|
||||||
{
|
{
|
||||||
boost::asio::io_service ioservice;
|
boost::asio::io_service ioservice;
|
||||||
boost::thread_group threadpool;
|
boost::thread_group threadpool;
|
||||||
@ -214,8 +234,8 @@ void wallet2::process_new_transaction(const cryptonote::transaction& tx, uint64_
|
|||||||
}
|
}
|
||||||
|
|
||||||
const account_keys &keys = m_account.get_keys();
|
const account_keys &keys = m_account.get_keys();
|
||||||
uint64_t *money_transfered = new uint64_t[tx.vout.size()];
|
std::vector<uint64_t> money_transfered(tx.vout.size());
|
||||||
bool *error = new bool[tx.vout.size()];
|
std::deque<bool> error(tx.vout.size());
|
||||||
for (size_t i = 0; i < tx.vout.size(); ++i)
|
for (size_t i = 0; i < tx.vout.size(); ++i)
|
||||||
{
|
{
|
||||||
ioservice.dispatch(boost::bind(&wallet2::check_acc_out, this, std::cref(keys), std::cref(tx.vout[i]), std::cref(tx_pub_key), i,
|
ioservice.dispatch(boost::bind(&wallet2::check_acc_out, this, std::cref(keys), std::cref(tx.vout[i]), std::cref(tx_pub_key), i,
|
||||||
@ -236,8 +256,6 @@ void wallet2::process_new_transaction(const cryptonote::transaction& tx, uint64_
|
|||||||
tx_money_got_in_outs += money_transfered[i];
|
tx_money_got_in_outs += money_transfered[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delete[] error;
|
|
||||||
delete[] money_transfered;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -303,6 +321,14 @@ void wallet2::process_new_transaction(const cryptonote::transaction& tx, uint64_
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (tx_money_spent_in_ins > 0)
|
||||||
|
{
|
||||||
|
process_outgoing(tx, height, tx_money_spent_in_ins, tx_money_got_in_outs);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t received = (tx_money_spent_in_ins < tx_money_got_in_outs) ? tx_money_got_in_outs - tx_money_spent_in_ins : 0;
|
||||||
|
if (0 < received)
|
||||||
|
{
|
||||||
tx_extra_nonce extra_nonce;
|
tx_extra_nonce extra_nonce;
|
||||||
crypto::hash payment_id = null_hash;
|
crypto::hash payment_id = null_hash;
|
||||||
if (find_tx_extra_field_by_type(tx_extra_fields, extra_nonce))
|
if (find_tx_extra_field_by_type(tx_extra_fields, extra_nonce))
|
||||||
@ -337,16 +363,11 @@ void wallet2::process_new_transaction(const cryptonote::transaction& tx, uint64_
|
|||||||
LOG_PRINT_L2("Found unencrypted payment ID: " << payment_id);
|
LOG_PRINT_L2("Found unencrypted payment ID: " << payment_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (get_payment_id_from_tx_extra_nonce(extra_nonce.nonce, payment_id))
|
||||||
uint64_t received = (tx_money_spent_in_ins < tx_money_got_in_outs) ? tx_money_got_in_outs - tx_money_spent_in_ins : 0;
|
|
||||||
|
|
||||||
if (tx_money_spent_in_ins > 0)
|
|
||||||
{
|
{
|
||||||
process_outgoing(tx, height, tx_money_spent_in_ins, tx_money_got_in_outs);
|
LOG_PRINT_L2("Found unencrypted payment ID: " << payment_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (0 < received)
|
|
||||||
{
|
|
||||||
payment_details payment;
|
payment_details payment;
|
||||||
payment.m_tx_hash = cryptonote::get_transaction_hash(tx);
|
payment.m_tx_hash = cryptonote::get_transaction_hash(tx);
|
||||||
payment.m_amount = received;
|
payment.m_amount = received;
|
||||||
@ -395,7 +416,7 @@ void wallet2::process_new_blockchain_entry(const cryptonote::block& b, const cry
|
|||||||
if(b.timestamp + 60*60*24 > m_account.get_createtime())
|
if(b.timestamp + 60*60*24 > m_account.get_createtime())
|
||||||
{
|
{
|
||||||
TIME_MEASURE_START(miner_tx_handle_time);
|
TIME_MEASURE_START(miner_tx_handle_time);
|
||||||
process_new_transaction(b.miner_tx, height);
|
process_new_transaction(b.miner_tx, height, true);
|
||||||
TIME_MEASURE_FINISH(miner_tx_handle_time);
|
TIME_MEASURE_FINISH(miner_tx_handle_time);
|
||||||
|
|
||||||
TIME_MEASURE_START(txs_handle_time);
|
TIME_MEASURE_START(txs_handle_time);
|
||||||
@ -404,7 +425,7 @@ void wallet2::process_new_blockchain_entry(const cryptonote::block& b, const cry
|
|||||||
cryptonote::transaction tx;
|
cryptonote::transaction tx;
|
||||||
bool r = parse_and_validate_tx_from_blob(txblob, tx);
|
bool r = parse_and_validate_tx_from_blob(txblob, tx);
|
||||||
THROW_WALLET_EXCEPTION_IF(!r, error::tx_parse_error, txblob);
|
THROW_WALLET_EXCEPTION_IF(!r, error::tx_parse_error, txblob);
|
||||||
process_new_transaction(tx, height);
|
process_new_transaction(tx, height, false);
|
||||||
}
|
}
|
||||||
TIME_MEASURE_FINISH(txs_handle_time);
|
TIME_MEASURE_FINISH(txs_handle_time);
|
||||||
LOG_PRINT_L2("Processed block: " << bl_id << ", height " << height << ", " << miner_tx_handle_time + txs_handle_time << "(" << miner_tx_handle_time << "/" << txs_handle_time <<")ms");
|
LOG_PRINT_L2("Processed block: " << bl_id << ", height " << height << ", " << miner_tx_handle_time + txs_handle_time << "(" << miner_tx_handle_time << "/" << txs_handle_time <<")ms");
|
||||||
|
@ -336,7 +336,7 @@ namespace tools
|
|||||||
* \param password Password of wallet file
|
* \param password Password of wallet file
|
||||||
*/
|
*/
|
||||||
void load_keys(const std::string& keys_file_name, const std::string& password);
|
void load_keys(const std::string& keys_file_name, const std::string& password);
|
||||||
void process_new_transaction(const cryptonote::transaction& tx, uint64_t height);
|
void process_new_transaction(const cryptonote::transaction& tx, uint64_t height, bool miner_tx);
|
||||||
void process_new_blockchain_entry(const cryptonote::block& b, const cryptonote::block_complete_entry& bche, const crypto::hash& bl_id, uint64_t height);
|
void process_new_blockchain_entry(const cryptonote::block& b, const cryptonote::block_complete_entry& bche, const crypto::hash& bl_id, uint64_t height);
|
||||||
void detach_blockchain(uint64_t height);
|
void detach_blockchain(uint64_t height);
|
||||||
void get_short_chain_history(std::list<crypto::hash>& ids) const;
|
void get_short_chain_history(std::list<crypto::hash>& ids) const;
|
||||||
|
Loading…
Reference in New Issue
Block a user