src: reduce unnecessary copies/allocations
What changed, and why it matters
This commit is a routine performance cleanup. It reserves memory ahead of time for a list of output keys, avoids one unnecessary move of a block object, and reuses a boolean tracking vector instead of recreating it inside a loop. None of these changes alter security behavior or fix a vulnerability.
No security action required; treat as normal code-quality/performance improvement.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch makes three micro-optimizations: (1) output_keys.reserve(txin.key_offsets.size()) in check_tx_input to preallocate vector capacity; (2) changing std::make_pair(std::move(bl), std::move(bd)) to std::make_pair(bl, std::move(bd)) in Blockchain::add_new_block so bl is not left in a moved-from state before a later use; (3) hoisting std::vector<bool> slot_seen out of the nonce loop in the RPC aux-PoW handler and resetting it with assign() to avoid repeated allocations. These are correctness-preserving refactorings with no security implications.
Changed components
src/cryptonote_core/blockchain.cppsrc/rpc/core_rpc_server.cppInspect captured patch +4 / −2
diff --git a/src/cryptonote_core/blockchain.cpp b/src/cryptonote_core/blockchain.cpp
index f2cce54..9c7518e 100644
--- a/src/cryptonote_core/blockchain.cpp
+++ b/src/cryptonote_core/blockchain.cpp
@@ -3736,6 +3736,7 @@ bool Blockchain::check_tx_input(size_t tx_version, const txin_to_key& txin, cons
};
output_keys.clear();
+ output_keys.reserve(txin.key_offsets.size());
// collect output keys
outputs_visitor vi(output_keys, *this, hf_version);
@@ -4291,7 +4292,7 @@ leave:
{
uint64_t long_term_block_weight = get_next_long_term_block_weight(block_weight);
cryptonote::blobdata bd = cryptonote::block_to_blob(bl);
- new_height = m_db->add_block(std::make_pair(std::move(bl), std::move(bd)), block_weight, long_term_block_weight, cumulative_difficulty, already_generated_coins, txs);
+ new_height = m_db->add_block(std::make_pair(bl, std::move(bd)), block_weight, long_term_block_weight, cumulative_difficulty, already_generated_coins, txs);
}
catch (const KEY_IMAGE_EXISTS& e)
{
diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp
index 104be85..236d869 100644
--- a/src/rpc/core_rpc_server.cpp
+++ b/src/rpc/core_rpc_server.cpp
@@ -1777,9 +1777,10 @@ namespace cryptonote
const uint32_t max_nonce = restricted ? 16384 : 65535;
bool collision = true;
std::vector<uint32_t> slots(aux_pow.size());
+ std::vector<bool> slot_seen(aux_pow.size(), false);
for (nonce = 0; nonce <= max_nonce; ++nonce)
{
- std::vector<bool> slot_seen(aux_pow.size(), false);
+ slot_seen.assign(aux_pow.size(), false);
collision = false;
for (size_t idx = 0; idx < aux_pow.size(); ++idx)
slots[idx] = 0xffffffff;
Why this scored 14/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.