mirror of
https://codeberg.org/anoncontributorxmr/monero.git
synced 2024-11-30 03:03:17 +00:00
Merge pull request #4946
6644b9b
blockchain_db: remove a couple unused functions (moneromooo-monero)ce594f5
blockchain_db: allocate known size vector only once (moneromooo-monero)8332698
db_lmdb: inline check_open, it's trivial and called everywhere (moneromooo-monero)5511563
db_lmdb: avoid pointless division (moneromooo-monero)d1efe3d
cryptonote: set tx hash on newly parsed txes when known (moneromooo-monero)9cc68a2
tx_pool: add a few std::move where it can make a difference (moneromooo-monero)
This commit is contained in:
commit
69e8567c0e
8 changed files with 31 additions and 104 deletions
|
@ -714,29 +714,6 @@ bool BlockchainBDB::for_all_outputs(std::function<bool(uint64_t amount, const cr
|
|||
return ret;
|
||||
}
|
||||
|
||||
blobdata BlockchainBDB::output_to_blob(const tx_out& output) const
|
||||
{
|
||||
LOG_PRINT_L3("BlockchainBDB::" << __func__);
|
||||
blobdata b;
|
||||
if (!t_serializable_object_to_blob(output, b))
|
||||
throw1(DB_ERROR("Error serializing output to blob"));
|
||||
return b;
|
||||
}
|
||||
|
||||
tx_out BlockchainBDB::output_from_blob(const blobdata& blob) const
|
||||
{
|
||||
LOG_PRINT_L3("BlockchainBDB::" << __func__);
|
||||
std::stringstream ss;
|
||||
ss << blob;
|
||||
binary_archive<false> ba(ss);
|
||||
tx_out o;
|
||||
|
||||
if (!(::serialization::serialize(ba, o)))
|
||||
throw1(DB_ERROR("Error deserializing tx output blob"));
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
uint64_t BlockchainBDB::get_output_global_index(const uint64_t& amount, const uint64_t& index)
|
||||
{
|
||||
LOG_PRINT_L3("BlockchainBDB::" << __func__);
|
||||
|
|
|
@ -391,24 +391,6 @@ private:
|
|||
virtual void check_hard_fork_info();
|
||||
virtual void drop_hard_fork_info();
|
||||
|
||||
/**
|
||||
* @brief convert a tx output to a blob for storage
|
||||
*
|
||||
* @param output the output to convert
|
||||
*
|
||||
* @return the resultant blob
|
||||
*/
|
||||
blobdata output_to_blob(const tx_out& output) const;
|
||||
|
||||
/**
|
||||
* @brief convert a tx output blob to a tx output
|
||||
*
|
||||
* @param blob the blob to convert
|
||||
*
|
||||
* @return the resultant tx output
|
||||
*/
|
||||
tx_out output_from_blob(const blobdata& blob) const;
|
||||
|
||||
/**
|
||||
* @brief get the global index of the index-th output of the given amount
|
||||
*
|
||||
|
|
|
@ -170,7 +170,7 @@ void BlockchainDB::add_transaction(const crypto::hash& blk_hash, const transacti
|
|||
|
||||
uint64_t tx_id = add_transaction_data(blk_hash, tx, tx_hash, tx_prunable_hash);
|
||||
|
||||
std::vector<uint64_t> amount_output_indices;
|
||||
std::vector<uint64_t> amount_output_indices(tx.vout.size());
|
||||
|
||||
// iterate tx.vout using indices instead of C++11 foreach syntax because
|
||||
// we need the index
|
||||
|
@ -183,13 +183,13 @@ void BlockchainDB::add_transaction(const crypto::hash& blk_hash, const transacti
|
|||
cryptonote::tx_out vout = tx.vout[i];
|
||||
rct::key commitment = rct::zeroCommit(vout.amount);
|
||||
vout.amount = 0;
|
||||
amount_output_indices.push_back(add_output(tx_hash, vout, i, tx.unlock_time,
|
||||
&commitment));
|
||||
amount_output_indices[i] = add_output(tx_hash, vout, i, tx.unlock_time,
|
||||
&commitment);
|
||||
}
|
||||
else
|
||||
{
|
||||
amount_output_indices.push_back(add_output(tx_hash, tx.vout[i], i, tx.unlock_time,
|
||||
tx.version > 1 ? &tx.rct_signatures.outPk[i].mask : NULL));
|
||||
amount_output_indices[i] = add_output(tx_hash, tx.vout[i], i, tx.unlock_time,
|
||||
tx.version > 1 ? &tx.rct_signatures.outPk[i].mask : NULL);
|
||||
}
|
||||
}
|
||||
add_tx_amount_output_indices(tx_id, amount_output_indices);
|
||||
|
|
|
@ -456,6 +456,12 @@ inline int lmdb_txn_renew(MDB_txn *txn)
|
|||
return res;
|
||||
}
|
||||
|
||||
inline void BlockchainLMDB::check_open() const
|
||||
{
|
||||
if (!m_open)
|
||||
throw0(DB_ERROR("DB operation attempted on a not-open DB instance"));
|
||||
}
|
||||
|
||||
void BlockchainLMDB::do_resize(uint64_t increase_size)
|
||||
{
|
||||
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
|
||||
|
@ -1166,36 +1172,6 @@ void BlockchainLMDB::remove_spent_key(const crypto::key_image& k_image)
|
|||
}
|
||||
}
|
||||
|
||||
blobdata BlockchainLMDB::output_to_blob(const tx_out& output) const
|
||||
{
|
||||
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
|
||||
blobdata b;
|
||||
if (!t_serializable_object_to_blob(output, b))
|
||||
throw1(DB_ERROR("Error serializing output to blob"));
|
||||
return b;
|
||||
}
|
||||
|
||||
tx_out BlockchainLMDB::output_from_blob(const blobdata& blob) const
|
||||
{
|
||||
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
|
||||
std::stringstream ss;
|
||||
ss << blob;
|
||||
binary_archive<false> ba(ss);
|
||||
tx_out o;
|
||||
|
||||
if (!(::serialization::serialize(ba, o)))
|
||||
throw1(DB_ERROR("Error deserializing tx output blob"));
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
void BlockchainLMDB::check_open() const
|
||||
{
|
||||
// LOG_PRINT_L3("BlockchainLMDB::" << __func__);
|
||||
if (!m_open)
|
||||
throw0(DB_ERROR("DB operation attempted on a not-open DB instance"));
|
||||
}
|
||||
|
||||
BlockchainLMDB::~BlockchainLMDB()
|
||||
{
|
||||
LOG_PRINT_L3("BlockchainLMDB::" << __func__);
|
||||
|
@ -3192,7 +3168,7 @@ uint64_t BlockchainLMDB::add_block(const block& blk, size_t block_weight, const
|
|||
check_open();
|
||||
uint64_t m_height = height();
|
||||
|
||||
if (m_height % 1000 == 0)
|
||||
if (m_height % 1024 == 0)
|
||||
{
|
||||
// for batch mode, DB resize check is done at start of batch transaction
|
||||
if (! m_batch_active && need_resize())
|
||||
|
|
|
@ -359,25 +359,7 @@ private:
|
|||
virtual void check_hard_fork_info();
|
||||
virtual void drop_hard_fork_info();
|
||||
|
||||
/**
|
||||
* @brief convert a tx output to a blob for storage
|
||||
*
|
||||
* @param output the output to convert
|
||||
*
|
||||
* @return the resultant blob
|
||||
*/
|
||||
blobdata output_to_blob(const tx_out& output) const;
|
||||
|
||||
/**
|
||||
* @brief convert a tx output blob to a tx output
|
||||
*
|
||||
* @param blob the blob to convert
|
||||
*
|
||||
* @return the resultant tx output
|
||||
*/
|
||||
tx_out output_from_blob(const blobdata& blob) const;
|
||||
|
||||
void check_open() const;
|
||||
inline void check_open() const;
|
||||
|
||||
virtual bool is_read_only() const;
|
||||
|
||||
|
|
|
@ -211,6 +211,8 @@ namespace cryptonote
|
|||
void set_hash_valid(bool v) const { hash_valid.store(v,std::memory_order_release); }
|
||||
bool is_blob_size_valid() const { return blob_size_valid.load(std::memory_order_acquire); }
|
||||
void set_blob_size_valid(bool v) const { blob_size_valid.store(v,std::memory_order_release); }
|
||||
void set_hash(const crypto::hash &h) { hash = h; set_hash_valid(true); }
|
||||
void set_blob_size(size_t sz) { blob_size = sz; set_blob_size_valid(true); }
|
||||
|
||||
BEGIN_SERIALIZE_OBJECT()
|
||||
if (!typename Archive<W>::is_saving())
|
||||
|
|
|
@ -184,6 +184,7 @@ namespace cryptonote
|
|||
CHECK_AND_ASSERT_MES(r, false, "Failed to parse transaction from blob");
|
||||
CHECK_AND_ASSERT_MES(expand_transaction_1(tx, false), false, "Failed to expand transaction data");
|
||||
tx.invalidate_hashes();
|
||||
tx.set_blob_size(tx_blob.size());
|
||||
return true;
|
||||
}
|
||||
//---------------------------------------------------------------
|
||||
|
|
|
@ -480,6 +480,10 @@ namespace cryptonote
|
|||
MERROR("Failed to parse tx from txpool");
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
tx.set_hash(id);
|
||||
}
|
||||
tx_weight = meta.weight;
|
||||
fee = meta.fee;
|
||||
relayed = meta.relayed;
|
||||
|
@ -659,7 +663,8 @@ namespace cryptonote
|
|||
// continue
|
||||
return true;
|
||||
}
|
||||
txs.push_back(tx);
|
||||
tx.set_hash(txid);
|
||||
txs.push_back(std::move(tx));
|
||||
return true;
|
||||
}, true, include_unrelayed_txes);
|
||||
}
|
||||
|
@ -782,6 +787,7 @@ namespace cryptonote
|
|||
// continue
|
||||
return true;
|
||||
}
|
||||
tx.set_hash(txid);
|
||||
txi.tx_json = obj_to_json_str(tx);
|
||||
txi.blob_size = bd->size();
|
||||
txi.weight = meta.weight;
|
||||
|
@ -798,7 +804,7 @@ namespace cryptonote
|
|||
txi.last_relayed_time = include_sensitive_data ? meta.last_relayed_time : 0;
|
||||
txi.do_not_relay = meta.do_not_relay;
|
||||
txi.double_spend_seen = meta.double_spend_seen;
|
||||
tx_infos.push_back(txi);
|
||||
tx_infos.push_back(std::move(txi));
|
||||
return true;
|
||||
}, true, include_sensitive_data);
|
||||
|
||||
|
@ -847,14 +853,13 @@ namespace cryptonote
|
|||
m_blockchain.for_all_txpool_txes([&tx_infos, key_image_infos](const crypto::hash &txid, const txpool_tx_meta_t &meta, const cryptonote::blobdata *bd){
|
||||
cryptonote::rpc::tx_in_pool txi;
|
||||
txi.tx_hash = txid;
|
||||
transaction tx;
|
||||
if (!parse_and_validate_tx_from_blob(*bd, tx))
|
||||
if (!parse_and_validate_tx_from_blob(*bd, txi.tx))
|
||||
{
|
||||
MERROR("Failed to parse tx from txpool");
|
||||
// continue
|
||||
return true;
|
||||
}
|
||||
txi.tx = tx;
|
||||
txi.tx.set_hash(txid);
|
||||
txi.blob_size = bd->size();
|
||||
txi.weight = meta.weight;
|
||||
txi.fee = meta.fee;
|
||||
|
@ -881,7 +886,7 @@ namespace cryptonote
|
|||
}
|
||||
|
||||
const crypto::key_image& k_image = kee.first;
|
||||
key_image_infos[k_image] = tx_hashes;
|
||||
key_image_infos[k_image] = std::move(tx_hashes);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -990,21 +995,23 @@ namespace cryptonote
|
|||
{
|
||||
struct transction_parser
|
||||
{
|
||||
transction_parser(const cryptonote::blobdata &txblob, transaction &tx): txblob(txblob), tx(tx), parsed(false) {}
|
||||
transction_parser(const cryptonote::blobdata &txblob, const crypto::hash &txid, transaction &tx): txblob(txblob), txid(txid), tx(tx), parsed(false) {}
|
||||
cryptonote::transaction &operator()()
|
||||
{
|
||||
if (!parsed)
|
||||
{
|
||||
if (!parse_and_validate_tx_from_blob(txblob, tx))
|
||||
throw std::runtime_error("failed to parse transaction blob");
|
||||
tx.set_hash(txid);
|
||||
parsed = true;
|
||||
}
|
||||
return tx;
|
||||
}
|
||||
const cryptonote::blobdata &txblob;
|
||||
const crypto::hash &txid;
|
||||
transaction &tx;
|
||||
bool parsed;
|
||||
} lazy_tx(txblob, tx);
|
||||
} lazy_tx(txblob, txid, tx);
|
||||
|
||||
//not the best implementation at this time, sorry :(
|
||||
//check is ring_signature already checked ?
|
||||
|
|
Loading…
Reference in a new issue