Skip to content

Commit

Permalink
Fix exceptions not finding txpool txes when relaying
Browse files Browse the repository at this point in the history
  • Loading branch information
andrepatta committed Nov 9, 2018
1 parent ae101d8 commit bfda2cb
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 16 deletions.
5 changes: 3 additions & 2 deletions src/blockchain_db/blockchain_db.h
Original file line number Diff line number Diff line change
Expand Up @@ -1322,10 +1322,11 @@ class BlockchainDB
* @brief get a txpool transaction's metadata
*
* @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
Expand Down
8 changes: 5 additions & 3 deletions src/blockchain_db/lmdb/db_lmdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1574,7 +1574,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__);
check_open();
Expand All @@ -1585,12 +1585,14 @@ txpool_tx_meta_t BlockchainLMDB::get_txpool_tx_meta(const crypto::hash& txid) co
MDB_val k = {sizeof(txid), (void *)&txid};
MDB_val v;
auto result = mdb_cursor_get(m_cur_txpool_meta, &k, &v, MDB_SET);
if (result == MDB_NOTFOUND)
return false;
if (result != 0)
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();
return meta;
return true;
}

bool BlockchainLMDB::get_txpool_tx_blob(const crypto::hash& txid, cryptonote::blobdata &bd) const
Expand Down
2 changes: 1 addition & 1 deletion src/blockchain_db/lmdb/db_lmdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ class BlockchainLMDB : public BlockchainDB
virtual uint64_t get_txpool_tx_count() const;
virtual bool txpool_has_tx(const crypto::hash &txid) const;
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 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) const;
Expand Down
4 changes: 2 additions & 2 deletions src/cryptonote_core/blockchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4058,9 +4058,9 @@ uint64_t Blockchain::get_txpool_tx_count() const
return m_db->get_txpool_tx_count();
}

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
Expand Down
2 changes: 1 addition & 1 deletion src/cryptonote_core/blockchain.h
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,7 @@ namespace cryptonote
void update_txpool_tx(const crypto::hash &txid, const txpool_tx_meta_t &meta);
void remove_txpool_tx(const crypto::hash &txid);
uint64_t get_txpool_tx_count() 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;
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) const;
Expand Down
25 changes: 19 additions & 6 deletions src/cryptonote_core/tx_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,12 @@ namespace cryptonote
try
{
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);
if (!parse_and_validate_tx_from_blob(txblob, tx))
{
Expand Down Expand Up @@ -508,10 +513,13 @@ namespace cryptonote
{
try
{
txpool_tx_meta_t meta = m_blockchain.get_txpool_tx_meta(it->first);
meta.relayed = true;
meta.last_relayed_time = now;
m_blockchain.update_txpool_tx(it->first, meta);
txpool_tx_meta_t meta;
if (m_blockchain.get_txpool_tx_meta(it->first, meta))
{
meta.relayed = true;
meta.last_relayed_time = now;
m_blockchain.update_txpool_tx(it->first, meta);
}
}
catch (const std::exception &e)
{
Expand Down Expand Up @@ -867,7 +875,12 @@ namespace cryptonote
auto sorted_it = m_txs_by_fee_and_receive_time.begin();
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));

// Can not exceed maximum block size
Expand Down
2 changes: 1 addition & 1 deletion tests/unit_tests/hardfork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class TestDB: public BlockchainDB {
virtual uint64_t get_txpool_tx_count() const { return 0; }
virtual bool txpool_has_tx(const crypto::hash &txid) const { return false; }
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 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) const { return false; }
Expand Down

0 comments on commit bfda2cb

Please sign in to comment.