Fix exceptions not finding txpool txes when relaying

This commit is contained in:
moneromooo-monero 2017-12-14 17:09:30 +00:00
parent 1cc7451130
commit ae8602303a
No known key found for this signature in database
GPG Key ID: 686F07454D6CEFC3
7 changed files with 44 additions and 18 deletions

View File

@ -1333,10 +1333,11 @@ public:
* @brief get a txpool transaction's metadata * @brief get a txpool transaction's metadata
* *
* @param txid the transaction id of the transation to lookup * @param txid the transaction id of the transation to lookup
* @param meta the metadata to return
* *
* @return the metadata associated with that transaction * @return true if the tx meta was found, false otherwise
*/ */
virtual txpool_tx_meta_t get_txpool_tx_meta(const crypto::hash& txid) const = 0; virtual bool get_txpool_tx_meta(const crypto::hash& txid, txpool_tx_meta_t &meta) const = 0;
/** /**
* @brief get a txpool transaction's blob * @brief get a txpool transaction's blob

View File

@ -1621,7 +1621,7 @@ void BlockchainLMDB::remove_txpool_tx(const crypto::hash& txid)
} }
} }
txpool_tx_meta_t BlockchainLMDB::get_txpool_tx_meta(const crypto::hash& txid) const bool BlockchainLMDB::get_txpool_tx_meta(const crypto::hash& txid, txpool_tx_meta_t &meta) const
{ {
LOG_PRINT_L3("BlockchainLMDB::" << __func__); LOG_PRINT_L3("BlockchainLMDB::" << __func__);
check_open(); check_open();
@ -1632,12 +1632,14 @@ txpool_tx_meta_t BlockchainLMDB::get_txpool_tx_meta(const crypto::hash& txid) co
MDB_val k = {sizeof(txid), (void *)&txid}; MDB_val k = {sizeof(txid), (void *)&txid};
MDB_val v; MDB_val v;
auto result = mdb_cursor_get(m_cur_txpool_meta, &k, &v, MDB_SET); auto result = mdb_cursor_get(m_cur_txpool_meta, &k, &v, MDB_SET);
if (result == MDB_NOTFOUND)
return false;
if (result != 0) if (result != 0)
throw1(DB_ERROR(lmdb_error("Error finding txpool tx meta: ", result).c_str())); throw1(DB_ERROR(lmdb_error("Error finding txpool tx meta: ", result).c_str()));
const txpool_tx_meta_t meta = *(const txpool_tx_meta_t*)v.mv_data; meta = *(const txpool_tx_meta_t*)v.mv_data;
TXN_POSTFIX_RDONLY(); TXN_POSTFIX_RDONLY();
return meta; return true;
} }
bool BlockchainLMDB::get_txpool_tx_blob(const crypto::hash& txid, cryptonote::blobdata &bd) const bool BlockchainLMDB::get_txpool_tx_blob(const crypto::hash& txid, cryptonote::blobdata &bd) const

View File

@ -246,7 +246,7 @@ public:
virtual uint64_t get_txpool_tx_count(bool include_unrelayed_txes = true) const; virtual uint64_t get_txpool_tx_count(bool include_unrelayed_txes = true) const;
virtual bool txpool_has_tx(const crypto::hash &txid) const; virtual bool txpool_has_tx(const crypto::hash &txid) const;
virtual void remove_txpool_tx(const crypto::hash& txid); virtual void remove_txpool_tx(const crypto::hash& txid);
virtual txpool_tx_meta_t get_txpool_tx_meta(const crypto::hash& txid) const; virtual bool get_txpool_tx_meta(const crypto::hash& txid, txpool_tx_meta_t &meta) const;
virtual bool get_txpool_tx_blob(const crypto::hash& txid, cryptonote::blobdata &bd) const; virtual bool get_txpool_tx_blob(const crypto::hash& txid, cryptonote::blobdata &bd) const;
virtual cryptonote::blobdata get_txpool_tx_blob(const crypto::hash& txid) const; virtual cryptonote::blobdata get_txpool_tx_blob(const crypto::hash& txid) const;
virtual bool for_all_txpool_txes(std::function<bool(const crypto::hash&, const txpool_tx_meta_t&, const cryptonote::blobdata*)> f, bool include_blob = false, bool include_unrelayed_txes = true) const; virtual bool for_all_txpool_txes(std::function<bool(const crypto::hash&, const txpool_tx_meta_t&, const cryptonote::blobdata*)> f, bool include_blob = false, bool include_unrelayed_txes = true) const;

View File

@ -4236,9 +4236,9 @@ uint64_t Blockchain::get_txpool_tx_count(bool include_unrelayed_txes) const
return m_db->get_txpool_tx_count(include_unrelayed_txes); return m_db->get_txpool_tx_count(include_unrelayed_txes);
} }
txpool_tx_meta_t Blockchain::get_txpool_tx_meta(const crypto::hash& txid) const bool Blockchain::get_txpool_tx_meta(const crypto::hash& txid, txpool_tx_meta_t &meta) const
{ {
return m_db->get_txpool_tx_meta(txid); return m_db->get_txpool_tx_meta(txid, meta);
} }
bool Blockchain::get_txpool_tx_blob(const crypto::hash& txid, cryptonote::blobdata &bd) const bool Blockchain::get_txpool_tx_blob(const crypto::hash& txid, cryptonote::blobdata &bd) const

View File

@ -940,7 +940,7 @@ namespace cryptonote
void update_txpool_tx(const crypto::hash &txid, const txpool_tx_meta_t &meta); void update_txpool_tx(const crypto::hash &txid, const txpool_tx_meta_t &meta);
void remove_txpool_tx(const crypto::hash &txid); void remove_txpool_tx(const crypto::hash &txid);
uint64_t get_txpool_tx_count(bool include_unrelayed_txes = true) const; uint64_t get_txpool_tx_count(bool include_unrelayed_txes = true) const;
txpool_tx_meta_t get_txpool_tx_meta(const crypto::hash& txid) const; bool get_txpool_tx_meta(const crypto::hash& txid, txpool_tx_meta_t &meta) const;
bool get_txpool_tx_blob(const crypto::hash& txid, cryptonote::blobdata &bd) const; bool get_txpool_tx_blob(const crypto::hash& txid, cryptonote::blobdata &bd) const;
cryptonote::blobdata get_txpool_tx_blob(const crypto::hash& txid) const; cryptonote::blobdata get_txpool_tx_blob(const crypto::hash& txid) const;
bool for_all_txpool_txes(std::function<bool(const crypto::hash&, const txpool_tx_meta_t&, const cryptonote::blobdata*)>, bool include_blob = false, bool include_unrelayed_txes = true) const; bool for_all_txpool_txes(std::function<bool(const crypto::hash&, const txpool_tx_meta_t&, const cryptonote::blobdata*)>, bool include_blob = false, bool include_unrelayed_txes = true) const;

View File

@ -371,7 +371,12 @@ namespace cryptonote
try try
{ {
LockedTXN lock(m_blockchain); LockedTXN lock(m_blockchain);
txpool_tx_meta_t meta = m_blockchain.get_txpool_tx_meta(id); txpool_tx_meta_t meta;
if (!m_blockchain.get_txpool_tx_meta(id, meta))
{
MERROR("Failed to find tx in txpool");
return false;
}
cryptonote::blobdata txblob = m_blockchain.get_txpool_tx_blob(id); cryptonote::blobdata txblob = m_blockchain.get_txpool_tx_blob(id);
if (!parse_and_validate_tx_from_blob(txblob, tx)) if (!parse_and_validate_tx_from_blob(txblob, tx))
{ {
@ -514,11 +519,14 @@ namespace cryptonote
{ {
try try
{ {
txpool_tx_meta_t meta = m_blockchain.get_txpool_tx_meta(it->first); txpool_tx_meta_t meta;
if (m_blockchain.get_txpool_tx_meta(it->first, meta))
{
meta.relayed = true; meta.relayed = true;
meta.last_relayed_time = now; meta.last_relayed_time = now;
m_blockchain.update_txpool_tx(it->first, meta); m_blockchain.update_txpool_tx(it->first, meta);
} }
}
catch (const std::exception &e) catch (const std::exception &e)
{ {
MERROR("Failed to update txpool transaction metadata: " << e.what()); MERROR("Failed to update txpool transaction metadata: " << e.what());
@ -696,7 +704,11 @@ namespace cryptonote
{ {
try try
{ {
meta = m_blockchain.get_txpool_tx_meta(tx_id_hash); if (!m_blockchain.get_txpool_tx_meta(tx_id_hash, meta))
{
MERROR("Failed to get tx meta from txpool");
return false;
}
if (!meta.relayed) if (!meta.relayed)
// Do not include that transaction if in restricted mode and it's not relayed // Do not include that transaction if in restricted mode and it's not relayed
continue; continue;
@ -918,7 +930,13 @@ namespace cryptonote
{ {
for (const crypto::hash &txid: it->second) for (const crypto::hash &txid: it->second)
{ {
txpool_tx_meta_t meta = m_blockchain.get_txpool_tx_meta(txid); txpool_tx_meta_t meta;
if (!m_blockchain.get_txpool_tx_meta(txid, meta))
{
MERROR("Failed to find tx meta in txpool");
// continue, not fatal
continue;
}
if (!meta.double_spend_seen) if (!meta.double_spend_seen)
{ {
MDEBUG("Marking " << txid << " as double spending " << itk.k_image); MDEBUG("Marking " << txid << " as double spending " << itk.k_image);
@ -998,7 +1016,12 @@ namespace cryptonote
auto sorted_it = m_txs_by_fee_and_receive_time.begin(); auto sorted_it = m_txs_by_fee_and_receive_time.begin();
while (sorted_it != m_txs_by_fee_and_receive_time.end()) while (sorted_it != m_txs_by_fee_and_receive_time.end())
{ {
txpool_tx_meta_t meta = m_blockchain.get_txpool_tx_meta(sorted_it->second); txpool_tx_meta_t meta;
if (!m_blockchain.get_txpool_tx_meta(sorted_it->second, meta))
{
MERROR(" failed to find tx meta");
continue;
}
LOG_PRINT_L2("Considering " << sorted_it->second << ", size " << meta.blob_size << ", current block size " << total_size << "/" << max_total_size << ", current coinbase " << print_money(best_coinbase)); LOG_PRINT_L2("Considering " << sorted_it->second << ", size " << meta.blob_size << ", current block size " << total_size << "/" << max_total_size << ", current coinbase " << print_money(best_coinbase));
// Can not exceed maximum block size // Can not exceed maximum block size

View File

@ -118,7 +118,7 @@ public:
virtual uint64_t get_txpool_tx_count(bool include_unrelayed_txes = true) const { return 0; } virtual uint64_t get_txpool_tx_count(bool include_unrelayed_txes = true) const { return 0; }
virtual bool txpool_has_tx(const crypto::hash &txid) const { return false; } virtual bool txpool_has_tx(const crypto::hash &txid) const { return false; }
virtual void remove_txpool_tx(const crypto::hash& txid) {} virtual void remove_txpool_tx(const crypto::hash& txid) {}
virtual txpool_tx_meta_t get_txpool_tx_meta(const crypto::hash& txid) const { return txpool_tx_meta_t(); } virtual bool get_txpool_tx_meta(const crypto::hash& txid, txpool_tx_meta_t &meta) const { return false; }
virtual bool get_txpool_tx_blob(const crypto::hash& txid, cryptonote::blobdata &bd) const { return false; } virtual bool get_txpool_tx_blob(const crypto::hash& txid, cryptonote::blobdata &bd) const { return false; }
virtual cryptonote::blobdata get_txpool_tx_blob(const crypto::hash& txid) const { return ""; } virtual cryptonote::blobdata get_txpool_tx_blob(const crypto::hash& txid) const { return ""; }
virtual bool for_all_txpool_txes(std::function<bool(const crypto::hash&, const txpool_tx_meta_t&, const cryptonote::blobdata*)>, bool include_blob = false, bool include_unrelayed_txes = false) const { return false; } virtual bool for_all_txpool_txes(std::function<bool(const crypto::hash&, const txpool_tx_meta_t&, const cryptonote::blobdata*)>, bool include_blob = false, bool include_unrelayed_txes = false) const { return false; }