mirror of
https://github.com/monero-project/monero.git
synced 2024-12-28 07:59:27 -05:00
wallet: detect and handle failed outgoing transfers
When a transaction is not found in the pool anymore, it is marked as failed, and displayed as such in show_transfers.
This commit is contained in:
parent
4b23714658
commit
b11539fda7
@ -2298,7 +2298,8 @@ bool simple_wallet::show_transfers(const std::vector<std::string> &args_)
|
|||||||
std::string payment_id = string_tools::pod_to_hex(i->second.m_payment_id);
|
std::string payment_id = string_tools::pod_to_hex(i->second.m_payment_id);
|
||||||
if (payment_id.substr(16).find_first_not_of('0') == std::string::npos)
|
if (payment_id.substr(16).find_first_not_of('0') == std::string::npos)
|
||||||
payment_id = payment_id.substr(0,16);
|
payment_id = payment_id.substr(0,16);
|
||||||
message_writer() << (boost::format("%8.8s %6.6s %20.20s %s %s %14.14s") % tr("pending") % tr("out") % print_money(amount - pd.m_change) % string_tools::pod_to_hex(i->first) % payment_id % print_money(fee)).str();
|
bool failed = pd.m_state == tools::wallet2::unconfirmed_transfer_details::failed;
|
||||||
|
message_writer() << (boost::format("%8.8s %6.6s %20.20s %s %s %14.14s") % (failed ? tr("failed") : tr("pending")) % tr("out") % print_money(amount - pd.m_change) % string_tools::pod_to_hex(i->first) % payment_id % print_money(fee)).str();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -674,6 +674,58 @@ void wallet2::pull_next_blocks(uint64_t start_height, uint64_t &blocks_start_hei
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
void wallet2::check_pending_txes()
|
||||||
|
{
|
||||||
|
// if we don't have any pending txes, we don't need to check anything
|
||||||
|
if (m_unconfirmed_txs.empty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
// we have at least one pending tx, so get the pool state
|
||||||
|
cryptonote::COMMAND_RPC_GET_TRANSACTION_POOL::request req;
|
||||||
|
cryptonote::COMMAND_RPC_GET_TRANSACTION_POOL::response res;
|
||||||
|
m_daemon_rpc_mutex.lock();
|
||||||
|
bool r = epee::net_utils::invoke_http_json_remote_command2(m_daemon_address + "/get_transaction_pool", req, res, m_http_client, 200000);
|
||||||
|
m_daemon_rpc_mutex.unlock();
|
||||||
|
THROW_WALLET_EXCEPTION_IF(!r, error::no_connection_to_daemon, "check_pending_txes");
|
||||||
|
THROW_WALLET_EXCEPTION_IF(res.status == CORE_RPC_STATUS_BUSY, error::daemon_busy, "is_key_image_spent");
|
||||||
|
THROW_WALLET_EXCEPTION_IF(res.status != CORE_RPC_STATUS_OK, error::get_tx_pool_error);
|
||||||
|
|
||||||
|
// remove any pending tx that's not in the pool
|
||||||
|
std::unordered_map<crypto::hash, wallet2::unconfirmed_transfer_details>::iterator it = m_unconfirmed_txs.begin();
|
||||||
|
while (it != m_unconfirmed_txs.end())
|
||||||
|
{
|
||||||
|
const std::string txid = epee::string_tools::pod_to_hex(cryptonote::get_transaction_hash(it->second.m_tx));
|
||||||
|
bool found = false;
|
||||||
|
for (auto it2: res.transactions)
|
||||||
|
{
|
||||||
|
if (it2.id_hash == txid)
|
||||||
|
{
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
auto pit = it++;
|
||||||
|
if (!found)
|
||||||
|
{
|
||||||
|
// we want to avoid a false positive when we ask for the pool just after
|
||||||
|
// a tx is removed from the pool due to being found in a new block, but
|
||||||
|
// just before the block is visible by refresh. So we keep a boolean, so
|
||||||
|
// that the first time we don't see the tx, we set that boolean, and only
|
||||||
|
// delete it the second time it is checked
|
||||||
|
if (pit->second.m_state == wallet2::unconfirmed_transfer_details::pending)
|
||||||
|
{
|
||||||
|
LOG_PRINT_L1("Pending txid " << txid << " not in pool, marking as not in pool");
|
||||||
|
pit->second.m_state = wallet2::unconfirmed_transfer_details::pending_not_in_pool;
|
||||||
|
}
|
||||||
|
else if (pit->second.m_state == wallet2::unconfirmed_transfer_details::pending_not_in_pool)
|
||||||
|
{
|
||||||
|
LOG_PRINT_L1("Pending txid " << txid << " not in pool, marking as failed");
|
||||||
|
pit->second.m_state = wallet2::unconfirmed_transfer_details::failed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
void wallet2::refresh(uint64_t start_height, uint64_t & blocks_fetched, bool& received_money)
|
void wallet2::refresh(uint64_t start_height, uint64_t & blocks_fetched, bool& received_money)
|
||||||
{
|
{
|
||||||
received_money = false;
|
received_money = false;
|
||||||
@ -735,6 +787,15 @@ void wallet2::refresh(uint64_t start_height, uint64_t & blocks_fetched, bool& re
|
|||||||
if(last_tx_hash_id != (m_transfers.size() ? get_transaction_hash(m_transfers.back().m_tx) : null_hash))
|
if(last_tx_hash_id != (m_transfers.size() ? get_transaction_hash(m_transfers.back().m_tx) : null_hash))
|
||||||
received_money = true;
|
received_money = true;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
check_pending_txes();
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
LOG_PRINT_L1("Failed to check pending transactions");
|
||||||
|
}
|
||||||
|
|
||||||
LOG_PRINT_L1("Refresh done, blocks received: " << blocks_fetched << ", balance: " << print_money(balance()) << ", unlocked: " << print_money(unlocked_balance()));
|
LOG_PRINT_L1("Refresh done, blocks received: " << blocks_fetched << ", balance: " << print_money(balance()) << ", unlocked: " << print_money(unlocked_balance()));
|
||||||
}
|
}
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
@ -1342,6 +1403,7 @@ uint64_t wallet2::balance() const
|
|||||||
|
|
||||||
|
|
||||||
BOOST_FOREACH(auto& utx, m_unconfirmed_txs)
|
BOOST_FOREACH(auto& utx, m_unconfirmed_txs)
|
||||||
|
if (utx.second.m_state != wallet2::unconfirmed_transfer_details::failed)
|
||||||
amount+= utx.second.m_change;
|
amount+= utx.second.m_change;
|
||||||
|
|
||||||
return amount;
|
return amount;
|
||||||
@ -1565,6 +1627,7 @@ void wallet2::add_unconfirmed_tx(const cryptonote::transaction& tx, const std::v
|
|||||||
utd.m_tx = tx;
|
utd.m_tx = tx;
|
||||||
utd.m_dests = dests;
|
utd.m_dests = dests;
|
||||||
utd.m_payment_id = payment_id;
|
utd.m_payment_id = payment_id;
|
||||||
|
utd.m_state = wallet2::unconfirmed_transfer_details::pending;
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
@ -119,6 +119,7 @@ namespace tools
|
|||||||
time_t m_sent_time;
|
time_t m_sent_time;
|
||||||
std::vector<cryptonote::tx_destination_entry> m_dests;
|
std::vector<cryptonote::tx_destination_entry> m_dests;
|
||||||
crypto::hash m_payment_id;
|
crypto::hash m_payment_id;
|
||||||
|
enum { pending, pending_not_in_pool, failed } m_state;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct confirmed_transfer_details
|
struct confirmed_transfer_details
|
||||||
@ -375,6 +376,7 @@ namespace tools
|
|||||||
void parse_block_round(const cryptonote::blobdata &blob, cryptonote::block &bl, crypto::hash &bl_id, bool &error) const;
|
void parse_block_round(const cryptonote::blobdata &blob, cryptonote::block &bl, crypto::hash &bl_id, bool &error) const;
|
||||||
bool use_fork_rules(uint8_t version);
|
bool use_fork_rules(uint8_t version);
|
||||||
uint64_t get_upper_tranaction_size_limit();
|
uint64_t get_upper_tranaction_size_limit();
|
||||||
|
void check_pending_txes();
|
||||||
|
|
||||||
cryptonote::account_base m_account;
|
cryptonote::account_base m_account;
|
||||||
std::string m_daemon_address;
|
std::string m_daemon_address;
|
||||||
@ -412,7 +414,7 @@ namespace tools
|
|||||||
}
|
}
|
||||||
BOOST_CLASS_VERSION(tools::wallet2, 10)
|
BOOST_CLASS_VERSION(tools::wallet2, 10)
|
||||||
BOOST_CLASS_VERSION(tools::wallet2::payment_details, 0)
|
BOOST_CLASS_VERSION(tools::wallet2::payment_details, 0)
|
||||||
BOOST_CLASS_VERSION(tools::wallet2::unconfirmed_transfer_details, 1)
|
BOOST_CLASS_VERSION(tools::wallet2::unconfirmed_transfer_details, 2)
|
||||||
BOOST_CLASS_VERSION(tools::wallet2::confirmed_transfer_details, 1)
|
BOOST_CLASS_VERSION(tools::wallet2::confirmed_transfer_details, 1)
|
||||||
|
|
||||||
namespace boost
|
namespace boost
|
||||||
@ -440,6 +442,9 @@ namespace boost
|
|||||||
return;
|
return;
|
||||||
a & x.m_dests;
|
a & x.m_dests;
|
||||||
a & x.m_payment_id;
|
a & x.m_payment_id;
|
||||||
|
if (ver < 2)
|
||||||
|
return;
|
||||||
|
a & x.m_state;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class Archive>
|
template <class Archive>
|
||||||
|
@ -61,6 +61,7 @@ namespace tools
|
|||||||
// get_blocks_error
|
// get_blocks_error
|
||||||
// get_out_indexes_error
|
// get_out_indexes_error
|
||||||
// tx_parse_error
|
// tx_parse_error
|
||||||
|
// get_tx_pool_error
|
||||||
// transfer_error *
|
// transfer_error *
|
||||||
// get_random_outs_general_error
|
// get_random_outs_general_error
|
||||||
// not_enough_money
|
// not_enough_money
|
||||||
@ -307,6 +308,16 @@ namespace tools
|
|||||||
cryptonote::blobdata m_tx_blob;
|
cryptonote::blobdata m_tx_blob;
|
||||||
};
|
};
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
struct get_tx_pool_error : public refresh_error
|
||||||
|
{
|
||||||
|
explicit get_tx_pool_error(std::string&& loc)
|
||||||
|
: refresh_error(std::move(loc), "error getting tranaction pool")
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string to_string() const { return refresh_error::to_string(); }
|
||||||
|
};
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
struct transfer_error : public wallet_logic_error
|
struct transfer_error : public wallet_logic_error
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
|
Loading…
Reference in New Issue
Block a user