mirror of
https://github.com/monero-project/monero.git
synced 2024-12-13 20:06:32 +02:00
core: avoid unnecessary tx/blob conversions
This commit is contained in:
parent
00cc1a1657
commit
6ecc99ad1f
@ -1349,7 +1349,7 @@ public:
|
||||
*
|
||||
* @param details the details of the transaction to add
|
||||
*/
|
||||
virtual void add_txpool_tx(const transaction &tx, const txpool_tx_meta_t& details) = 0;
|
||||
virtual void add_txpool_tx(const crypto::hash &txid, const cryptonote::blobdata &blob, const txpool_tx_meta_t& details) = 0;
|
||||
|
||||
/**
|
||||
* @brief update a txpool transaction's metadata
|
||||
|
@ -1591,7 +1591,7 @@ void BlockchainLMDB::unlock()
|
||||
auto_txn.commit(); \
|
||||
} while(0)
|
||||
|
||||
void BlockchainLMDB::add_txpool_tx(const transaction &tx, const txpool_tx_meta_t &meta)
|
||||
void BlockchainLMDB::add_txpool_tx(const crypto::hash &txid, const cryptonote::blobdata &blob, const txpool_tx_meta_t &meta)
|
||||
{
|
||||
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
|
||||
check_open();
|
||||
@ -1600,8 +1600,6 @@ void BlockchainLMDB::add_txpool_tx(const transaction &tx, const txpool_tx_meta_t
|
||||
CURSOR(txpool_meta)
|
||||
CURSOR(txpool_blob)
|
||||
|
||||
const crypto::hash txid = get_transaction_hash(tx);
|
||||
|
||||
MDB_val k = {sizeof(txid), (void *)&txid};
|
||||
MDB_val v = {sizeof(meta), (void *)&meta};
|
||||
if (auto result = mdb_cursor_put(m_cur_txpool_meta, &k, &v, MDB_NODUPDATA)) {
|
||||
@ -1610,7 +1608,7 @@ void BlockchainLMDB::add_txpool_tx(const transaction &tx, const txpool_tx_meta_t
|
||||
else
|
||||
throw1(DB_ERROR(lmdb_error("Error adding txpool tx metadata to db transaction: ", result).c_str()));
|
||||
}
|
||||
MDB_val_copy<cryptonote::blobdata> blob_val(tx_to_blob(tx));
|
||||
MDB_val_copy<cryptonote::blobdata> blob_val(blob);
|
||||
if (auto result = mdb_cursor_put(m_cur_txpool_blob, &k, &blob_val, MDB_NODUPDATA)) {
|
||||
if (result == MDB_KEYEXIST)
|
||||
throw1(DB_ERROR("Attempting to add txpool tx blob that's already in the db"));
|
||||
|
@ -256,7 +256,7 @@ public:
|
||||
|
||||
virtual bool has_key_image(const crypto::key_image& img) const;
|
||||
|
||||
virtual void add_txpool_tx(const transaction &tx, const txpool_tx_meta_t& meta);
|
||||
virtual void add_txpool_tx(const crypto::hash &txid, const cryptonote::blobdata &blob, const txpool_tx_meta_t& meta);
|
||||
virtual void update_txpool_tx(const crypto::hash &txid, const txpool_tx_meta_t& meta);
|
||||
virtual uint64_t get_txpool_tx_count(bool include_unrelayed_txes = true) const;
|
||||
virtual bool txpool_has_tx(const crypto::hash &txid) const;
|
||||
|
@ -4254,9 +4254,9 @@ bool Blockchain::prepare_handle_incoming_blocks(const std::vector<block_complete
|
||||
return true;
|
||||
}
|
||||
|
||||
void Blockchain::add_txpool_tx(transaction &tx, const txpool_tx_meta_t &meta)
|
||||
void Blockchain::add_txpool_tx(const crypto::hash &txid, const cryptonote::blobdata &blob, const txpool_tx_meta_t &meta)
|
||||
{
|
||||
m_db->add_txpool_tx(tx, meta);
|
||||
m_db->add_txpool_tx(txid, blob, meta);
|
||||
}
|
||||
|
||||
void Blockchain::update_txpool_tx(const crypto::hash &txid, const txpool_tx_meta_t &meta)
|
||||
|
@ -939,7 +939,7 @@ namespace cryptonote
|
||||
*/
|
||||
std::list<std::pair<block_extended_info,std::vector<crypto::hash>>> get_alternative_chains() const;
|
||||
|
||||
void add_txpool_tx(transaction &tx, const txpool_tx_meta_t &meta);
|
||||
void add_txpool_tx(const crypto::hash &txid, const cryptonote::blobdata &blob, 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);
|
||||
uint64_t get_txpool_tx_count(bool include_unrelayed_txes = true) const;
|
||||
|
@ -909,7 +909,7 @@ namespace cryptonote
|
||||
}
|
||||
|
||||
const size_t weight = get_transaction_weight(results[i].tx, it->size());
|
||||
ok &= add_new_tx(results[i].tx, results[i].hash, results[i].prefix_hash, weight, tvc[i], keeped_by_block, relayed, do_not_relay);
|
||||
ok &= add_new_tx(results[i].tx, results[i].hash, tx_blobs[i], results[i].prefix_hash, weight, tvc[i], keeped_by_block, relayed, do_not_relay);
|
||||
if(tvc[i].m_verifivation_failed)
|
||||
{MERROR_VER("Transaction verification failed: " << results[i].hash);}
|
||||
else if(tvc[i].m_verifivation_impossible)
|
||||
@ -1127,7 +1127,7 @@ namespace cryptonote
|
||||
blobdata bl;
|
||||
t_serializable_object_to_blob(tx, bl);
|
||||
size_t tx_weight = get_transaction_weight(tx, bl.size());
|
||||
return add_new_tx(tx, tx_hash, tx_prefix_hash, tx_weight, tvc, keeped_by_block, relayed, do_not_relay);
|
||||
return add_new_tx(tx, tx_hash, bl, tx_prefix_hash, tx_weight, tvc, keeped_by_block, relayed, do_not_relay);
|
||||
}
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
size_t core::get_blockchain_total_transactions() const
|
||||
@ -1135,7 +1135,7 @@ namespace cryptonote
|
||||
return m_blockchain_storage.get_total_transactions();
|
||||
}
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
bool core::add_new_tx(transaction& tx, const crypto::hash& tx_hash, const crypto::hash& tx_prefix_hash, size_t tx_weight, tx_verification_context& tvc, bool keeped_by_block, bool relayed, bool do_not_relay)
|
||||
bool core::add_new_tx(transaction& tx, const crypto::hash& tx_hash, const cryptonote::blobdata &blob, const crypto::hash& tx_prefix_hash, size_t tx_weight, tx_verification_context& tvc, bool keeped_by_block, bool relayed, bool do_not_relay)
|
||||
{
|
||||
if (keeped_by_block)
|
||||
get_blockchain_storage().on_new_tx_from_block(tx);
|
||||
@ -1153,7 +1153,7 @@ namespace cryptonote
|
||||
}
|
||||
|
||||
uint8_t version = m_blockchain_storage.get_current_hard_fork_version();
|
||||
return m_mempool.add_tx(tx, tx_hash, tx_weight, tvc, keeped_by_block, relayed, do_not_relay, version);
|
||||
return m_mempool.add_tx(tx, tx_hash, blob, tx_weight, tvc, keeped_by_block, relayed, do_not_relay, version);
|
||||
}
|
||||
//-----------------------------------------------------------------------------------------------
|
||||
bool core::relay_txpool_transactions()
|
||||
|
@ -783,13 +783,14 @@ namespace cryptonote
|
||||
* @copydoc add_new_tx(transaction&, tx_verification_context&, bool)
|
||||
*
|
||||
* @param tx_hash the transaction's hash
|
||||
* @param blob the transaction as a blob
|
||||
* @param tx_prefix_hash the transaction prefix' hash
|
||||
* @param tx_weight the weight of the transaction
|
||||
* @param relayed whether or not the transaction was relayed to us
|
||||
* @param do_not_relay whether to prevent the transaction from being relayed
|
||||
*
|
||||
*/
|
||||
bool add_new_tx(transaction& tx, const crypto::hash& tx_hash, const crypto::hash& tx_prefix_hash, size_t tx_weight, tx_verification_context& tvc, bool keeped_by_block, bool relayed, bool do_not_relay);
|
||||
bool add_new_tx(transaction& tx, const crypto::hash& tx_hash, const cryptonote::blobdata &blob, const crypto::hash& tx_prefix_hash, size_t tx_weight, tx_verification_context& tvc, bool keeped_by_block, bool relayed, bool do_not_relay);
|
||||
|
||||
/**
|
||||
* @brief add a new transaction to the transaction pool
|
||||
|
@ -111,7 +111,7 @@ namespace cryptonote
|
||||
|
||||
}
|
||||
//---------------------------------------------------------------------------------
|
||||
bool tx_memory_pool::add_tx(transaction &tx, /*const crypto::hash& tx_prefix_hash,*/ const crypto::hash &id, size_t tx_weight, tx_verification_context& tvc, bool kept_by_block, bool relayed, bool do_not_relay, uint8_t version)
|
||||
bool tx_memory_pool::add_tx(transaction &tx, /*const crypto::hash& tx_prefix_hash,*/ const crypto::hash &id, const cryptonote::blobdata &blob, size_t tx_weight, tx_verification_context& tvc, bool kept_by_block, bool relayed, bool do_not_relay, uint8_t version)
|
||||
{
|
||||
// this should already be called with that lock, but let's make it explicit for clarity
|
||||
CRITICAL_REGION_LOCAL(m_transactions_lock);
|
||||
@ -249,7 +249,7 @@ namespace cryptonote
|
||||
{
|
||||
CRITICAL_REGION_LOCAL1(m_blockchain);
|
||||
LockedTXN lock(m_blockchain);
|
||||
m_blockchain.add_txpool_tx(tx, meta);
|
||||
m_blockchain.add_txpool_tx(id, blob, meta);
|
||||
if (!insert_key_images(tx, id, kept_by_block))
|
||||
return false;
|
||||
m_txs_by_fee_and_receive_time.emplace(std::pair<double, std::time_t>(fee / (double)tx_weight, receive_time), id);
|
||||
@ -292,7 +292,7 @@ namespace cryptonote
|
||||
LockedTXN lock(m_blockchain);
|
||||
const crypto::hash txid = get_transaction_hash(tx);
|
||||
m_blockchain.remove_txpool_tx(txid);
|
||||
m_blockchain.add_txpool_tx(tx, meta);
|
||||
m_blockchain.add_txpool_tx(txid, blob, meta);
|
||||
if (!insert_key_images(tx, txid, kept_by_block))
|
||||
return false;
|
||||
m_txs_by_fee_and_receive_time.emplace(std::pair<double, std::time_t>(fee / (double)tx_weight, receive_time), id);
|
||||
@ -324,9 +324,11 @@ namespace cryptonote
|
||||
{
|
||||
crypto::hash h = null_hash;
|
||||
size_t blob_size = 0;
|
||||
if (!get_transaction_hash(tx, h, blob_size) || blob_size == 0)
|
||||
cryptonote::blobdata bl;
|
||||
t_serializable_object_to_blob(tx, bl);
|
||||
if (bl.size() == 0 || !get_transaction_hash(tx, h))
|
||||
return false;
|
||||
return add_tx(tx, h, get_transaction_weight(tx, blob_size), tvc, keeped_by_block, relayed, do_not_relay, version);
|
||||
return add_tx(tx, h, bl, get_transaction_weight(tx, bl.size()), tvc, keeped_by_block, relayed, do_not_relay, version);
|
||||
}
|
||||
//---------------------------------------------------------------------------------
|
||||
size_t tx_memory_pool::get_txpool_weight() const
|
||||
|
@ -107,7 +107,7 @@ namespace cryptonote
|
||||
* @param id the transaction's hash
|
||||
* @param tx_weight the transaction's weight
|
||||
*/
|
||||
bool add_tx(transaction &tx, const crypto::hash &id, size_t tx_weight, tx_verification_context& tvc, bool kept_by_block, bool relayed, bool do_not_relay, uint8_t version);
|
||||
bool add_tx(transaction &tx, const crypto::hash &id, const cryptonote::blobdata &blob, size_t tx_weight, tx_verification_context& tvc, bool kept_by_block, bool relayed, bool do_not_relay, uint8_t version);
|
||||
|
||||
/**
|
||||
* @brief add a transaction to the transaction pool
|
||||
|
@ -118,7 +118,7 @@ public:
|
||||
virtual std::map<uint64_t, std::tuple<uint64_t, uint64_t, uint64_t>> get_output_histogram(const std::vector<uint64_t> &amounts, bool unlocked, uint64_t recent_cutoff, uint64_t min_count) const { return std::map<uint64_t, std::tuple<uint64_t, uint64_t, uint64_t>>(); }
|
||||
virtual bool get_output_distribution(uint64_t amount, uint64_t from_height, uint64_t to_height, std::vector<uint64_t> &distribution, uint64_t &base) const { return false; }
|
||||
|
||||
virtual void add_txpool_tx(const transaction &tx, const txpool_tx_meta_t& details) {}
|
||||
virtual void add_txpool_tx(const crypto::hash &txid, const cryptonote::blobdata &blob, const txpool_tx_meta_t& details) {}
|
||||
virtual void update_txpool_tx(const crypto::hash &txid, const txpool_tx_meta_t& details) {}
|
||||
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; }
|
||||
|
Loading…
Reference in New Issue
Block a user