mirror of
https://github.com/monero-project/monero.git
synced 2024-12-23 03:59:33 +00:00
wallet2: fix duplicate output making it to the RPC
This commit is contained in:
parent
58ee1f2bde
commit
3caa403893
1 changed files with 32 additions and 7 deletions
|
@ -1121,6 +1121,7 @@ void wallet2::process_new_transaction(const crypto::hash &txid, const cryptonote
|
||||||
size_t pk_index = 0;
|
size_t pk_index = 0;
|
||||||
std::vector<tx_scan_info_t> tx_scan_info(tx.vout.size());
|
std::vector<tx_scan_info_t> tx_scan_info(tx.vout.size());
|
||||||
std::deque<bool> output_found(tx.vout.size(), false);
|
std::deque<bool> output_found(tx.vout.size(), false);
|
||||||
|
uint64_t total_received_1 = 0;
|
||||||
while (!tx.vout.empty())
|
while (!tx.vout.empty())
|
||||||
{
|
{
|
||||||
// if tx.vout is not empty, we loop through all tx pubkeys
|
// if tx.vout is not empty, we loop through all tx pubkeys
|
||||||
|
@ -1266,6 +1267,7 @@ void wallet2::process_new_transaction(const crypto::hash &txid, const cryptonote
|
||||||
+ ", m_transfers.size() is " + boost::lexical_cast<std::string>(m_transfers.size()));
|
+ ", m_transfers.size() is " + boost::lexical_cast<std::string>(m_transfers.size()));
|
||||||
if (kit == m_pub_keys.end())
|
if (kit == m_pub_keys.end())
|
||||||
{
|
{
|
||||||
|
uint64_t amount = tx.vout[o].amount ? tx.vout[o].amount : tx_scan_info[o].amount;
|
||||||
if (!pool)
|
if (!pool)
|
||||||
{
|
{
|
||||||
m_transfers.push_back(boost::value_initialized<transfer_details>());
|
m_transfers.push_back(boost::value_initialized<transfer_details>());
|
||||||
|
@ -1278,14 +1280,13 @@ void wallet2::process_new_transaction(const crypto::hash &txid, const cryptonote
|
||||||
td.m_key_image = tx_scan_info[o].ki;
|
td.m_key_image = tx_scan_info[o].ki;
|
||||||
td.m_key_image_known = !m_watch_only && !m_multisig;
|
td.m_key_image_known = !m_watch_only && !m_multisig;
|
||||||
td.m_key_image_partial = m_multisig;
|
td.m_key_image_partial = m_multisig;
|
||||||
td.m_amount = tx.vout[o].amount;
|
td.m_amount = amount;
|
||||||
td.m_pk_index = pk_index - 1;
|
td.m_pk_index = pk_index - 1;
|
||||||
td.m_subaddr_index = tx_scan_info[o].received->index;
|
td.m_subaddr_index = tx_scan_info[o].received->index;
|
||||||
expand_subaddresses(tx_scan_info[o].received->index);
|
expand_subaddresses(tx_scan_info[o].received->index);
|
||||||
if (td.m_amount == 0)
|
if (tx.vout[o].amount == 0)
|
||||||
{
|
{
|
||||||
td.m_mask = tx_scan_info[o].mask;
|
td.m_mask = tx_scan_info[o].mask;
|
||||||
td.m_amount = tx_scan_info[o].amount;
|
|
||||||
td.m_rct = true;
|
td.m_rct = true;
|
||||||
}
|
}
|
||||||
else if (miner_tx && tx.version == 2)
|
else if (miner_tx && tx.version == 2)
|
||||||
|
@ -1313,6 +1314,7 @@ void wallet2::process_new_transaction(const crypto::hash &txid, const cryptonote
|
||||||
if (0 != m_callback)
|
if (0 != m_callback)
|
||||||
m_callback->on_money_received(height, txid, tx, td.m_amount, td.m_subaddr_index);
|
m_callback->on_money_received(height, txid, tx, td.m_amount, td.m_subaddr_index);
|
||||||
}
|
}
|
||||||
|
total_received_1 += amount;
|
||||||
}
|
}
|
||||||
else if (m_transfers[kit->second].m_spent || m_transfers[kit->second].amount() >= tx_scan_info[o].amount)
|
else if (m_transfers[kit->second].m_spent || m_transfers[kit->second].amount() >= tx_scan_info[o].amount)
|
||||||
{
|
{
|
||||||
|
@ -1320,6 +1322,9 @@ void wallet2::process_new_transaction(const crypto::hash &txid, const cryptonote
|
||||||
<< " from received " << print_money(tx_scan_info[o].amount) << " output already exists with "
|
<< " from received " << print_money(tx_scan_info[o].amount) << " output already exists with "
|
||||||
<< (m_transfers[kit->second].m_spent ? "spent" : "unspent") << " "
|
<< (m_transfers[kit->second].m_spent ? "spent" : "unspent") << " "
|
||||||
<< print_money(m_transfers[kit->second].amount()) << " in tx " << m_transfers[kit->second].m_txid << ", received output ignored");
|
<< print_money(m_transfers[kit->second].amount()) << " in tx " << m_transfers[kit->second].m_txid << ", received output ignored");
|
||||||
|
THROW_WALLET_EXCEPTION_IF(tx_money_got_in_outs[tx_scan_info[o].received->index] < tx_scan_info[o].amount,
|
||||||
|
error::wallet_internal_error, "Unexpected values of new and old outputs");
|
||||||
|
tx_money_got_in_outs[tx_scan_info[o].received->index] -= tx_scan_info[o].amount;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1327,8 +1332,14 @@ void wallet2::process_new_transaction(const crypto::hash &txid, const cryptonote
|
||||||
<< " from received " << print_money(tx_scan_info[o].amount) << " output already exists with "
|
<< " from received " << print_money(tx_scan_info[o].amount) << " output already exists with "
|
||||||
<< print_money(m_transfers[kit->second].amount()) << ", replacing with new output");
|
<< print_money(m_transfers[kit->second].amount()) << ", replacing with new output");
|
||||||
// The new larger output replaced a previous smaller one
|
// The new larger output replaced a previous smaller one
|
||||||
tx_money_got_in_outs[tx_scan_info[o].received->index] -= tx_scan_info[o].amount;
|
THROW_WALLET_EXCEPTION_IF(tx_money_got_in_outs[tx_scan_info[o].received->index] < tx_scan_info[o].amount,
|
||||||
|
error::wallet_internal_error, "Unexpected values of new and old outputs");
|
||||||
|
THROW_WALLET_EXCEPTION_IF(m_transfers[kit->second].amount() > tx_scan_info[o].amount,
|
||||||
|
error::wallet_internal_error, "Unexpected values of new and old outputs");
|
||||||
|
tx_money_got_in_outs[tx_scan_info[o].received->index] -= m_transfers[kit->second].amount();
|
||||||
|
|
||||||
|
uint64_t amount = tx.vout[o].amount ? tx.vout[o].amount : tx_scan_info[o].amount;
|
||||||
|
uint64_t extra_amount = amount - m_transfers[kit->second].amount();
|
||||||
if (!pool)
|
if (!pool)
|
||||||
{
|
{
|
||||||
transfer_details &td = m_transfers[kit->second];
|
transfer_details &td = m_transfers[kit->second];
|
||||||
|
@ -1337,14 +1348,13 @@ void wallet2::process_new_transaction(const crypto::hash &txid, const cryptonote
|
||||||
td.m_global_output_index = o_indices[o];
|
td.m_global_output_index = o_indices[o];
|
||||||
td.m_tx = (const cryptonote::transaction_prefix&)tx;
|
td.m_tx = (const cryptonote::transaction_prefix&)tx;
|
||||||
td.m_txid = txid;
|
td.m_txid = txid;
|
||||||
td.m_amount = tx.vout[o].amount;
|
td.m_amount = amount;
|
||||||
td.m_pk_index = pk_index - 1;
|
td.m_pk_index = pk_index - 1;
|
||||||
td.m_subaddr_index = tx_scan_info[o].received->index;
|
td.m_subaddr_index = tx_scan_info[o].received->index;
|
||||||
expand_subaddresses(tx_scan_info[o].received->index);
|
expand_subaddresses(tx_scan_info[o].received->index);
|
||||||
if (td.m_amount == 0)
|
if (tx.vout[o].amount == 0)
|
||||||
{
|
{
|
||||||
td.m_mask = tx_scan_info[o].mask;
|
td.m_mask = tx_scan_info[o].mask;
|
||||||
td.m_amount = tx_scan_info[o].amount;
|
|
||||||
td.m_rct = true;
|
td.m_rct = true;
|
||||||
}
|
}
|
||||||
else if (miner_tx && tx.version == 2)
|
else if (miner_tx && tx.version == 2)
|
||||||
|
@ -1371,6 +1381,7 @@ void wallet2::process_new_transaction(const crypto::hash &txid, const cryptonote
|
||||||
if (0 != m_callback)
|
if (0 != m_callback)
|
||||||
m_callback->on_money_received(height, txid, tx, td.m_amount, td.m_subaddr_index);
|
m_callback->on_money_received(height, txid, tx, td.m_amount, td.m_subaddr_index);
|
||||||
}
|
}
|
||||||
|
total_received_1 += extra_amount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1494,6 +1505,20 @@ void wallet2::process_new_transaction(const crypto::hash &txid, const cryptonote
|
||||||
LOG_PRINT_L2("Found unencrypted payment ID: " << payment_id);
|
LOG_PRINT_L2("Found unencrypted payment ID: " << payment_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint64_t total_received_2 = 0;
|
||||||
|
for (const auto& i : tx_money_got_in_outs)
|
||||||
|
total_received_2 += i.second;
|
||||||
|
if (total_received_1 != total_received_2)
|
||||||
|
{
|
||||||
|
const el::Level level = el::Level::Warning;
|
||||||
|
MCLOG_RED(level, "global", "**********************************************************************");
|
||||||
|
MCLOG_RED(level, "global", "Consistency failure in amounts received");
|
||||||
|
MCLOG_RED(level, "global", "Check transaction " << txid);
|
||||||
|
MCLOG_RED(level, "global", "**********************************************************************");
|
||||||
|
exit(1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for (const auto& i : tx_money_got_in_outs)
|
for (const auto& i : tx_money_got_in_outs)
|
||||||
{
|
{
|
||||||
payment_details payment;
|
payment_details payment;
|
||||||
|
|
Loading…
Reference in a new issue