What changed, and why it matters
This change is a performance optimization for the Monero transaction pool. It caches a 'prunable hash' when a transaction first enters the pool, so that later RPC lookups can reuse the cached value instead of recalculating it every time. There is no direct security vulnerability in the patch; it is intended to make the node faster and the RPC behavior more consistent. The commit message and diff do not describe any security bug or exploit.
No security action required. Review as normal code-quality/performance change.
Security signals we found
No security-relevant signals present in commit message or diff
Change is a performance/caching optimization
Functional test added to verify cache correctness
Evidence from the diff
The commit adds a prunable_hash field to txpool_tx_meta_t and computes it once at transaction insertion time via a new cache_prunable_hash() helper. The RPC server then uses the cached value when available, falling back to on-the-fly calculation only when the cache is absent or invalid. A functional test verifies that the cached prunable hash matches the independently calculated value after the transaction is mined. The change reduces repeated hash computation but does not alter transaction validation rules or consensus logic.
Changed components
src/blockchain_db/blockchain_db.hsrc/cryptonote_core/tx_pool.cppsrc/cryptonote_core/tx_pool.hsrc/rpc/core_rpc_server.cpptests/functional_tests/txpool.pyInspect captured patch +73 / −3
### src/blockchain_db/blockchain_db.h
@@ -170,9 +170,12 @@ struct txpool_tx_meta_t
uint8_t is_local: 1;
uint8_t dandelionpp_stem : 1;
uint8_t is_forwarding: 1;
- uint8_t bf_padding: 3;
+ uint8_t prunable_hash_valid: 1;
+ uint8_t bf_padding: 2;
- uint8_t padding[44]; // til 160 bytes
+ crypto::hash prunable_hash;
+
+ uint8_t padding[12]; // til 160 bytes
// If non-null, this verification ID is set for this tx only when some mixring passed ver_input_proofs_rings()
crypto::hash valid_input_verification_id;
### src/cryptonote_core/tx_pool.cpp
@@ -118,6 +118,37 @@ namespace cryptonote
if (candidate < next_check.load(std::memory_order_relaxed))
next_check = candidate;
}
+
+ // Computes the transaction's prunable hash once at insertion time, so RPC
+ // lookups don't need to recompute it on every call. Version 1 transactions
+ // don't have a prunable part, so `null_hash` is correct for them as well.
+ void cache_prunable_hash(const transaction& tx, const cryptonote::blobdata& blob, txpool_tx_meta_t& meta)
+ {
+ if (tx.pruned)
+ {
+ if (tx.is_prunable_hash_valid())
+ {
+ meta.prunable_hash = tx.prunable_hash;
+ meta.prunable_hash_valid = true;
+ }
+ else
+ {
+ meta.prunable_hash = crypto::null_hash;
+ meta.prunable_hash_valid = false;
+ }
+ return;
+ }
+ if (tx.version == 1)
+ {
+ meta.prunable_hash = crypto::null_hash;
+ meta.prunable_hash_valid = true;
+ return;
+ }
+ const cryptonote::blobdata_ref blob_ref{blob};
+ meta.prunable_hash_valid = calculate_transaction_prunable_hash(tx, &blob_ref, meta.prunable_hash);
+ if (!meta.prunable_hash_valid)
+ meta.prunable_hash = crypto::null_hash;
+ }
}
//---------------------------------------------------------------------------------
//---------------------------------------------------------------------------------
@@ -246,6 +277,7 @@ namespace cryptonote
meta.pruned = tx.pruned;
meta.bf_padding = 0;
memset(meta.padding, 0, sizeof(meta.padding));
+ cache_prunable_hash(tx, blob, meta);
try
{
if (kept_by_block)
@@ -322,6 +354,8 @@ namespace cryptonote
meta.pruned = tx.pruned;
meta.bf_padding = 0;
memset(meta.padding, 0, sizeof(meta.padding));
+ if (!meta.prunable_hash_valid)
+ cache_prunable_hash(tx, blob, meta);
if (!insert_key_images(tx, id, tx_relay))
return false;
@@ -629,6 +663,8 @@ namespace cryptonote
td.relayed = meta.relayed;
td.do_not_relay = meta.do_not_relay;
td.double_spend_seen = meta.double_spend_seen;
+ td.prunable_hash = meta.prunable_hash;
+ td.prunable_hash_valid = meta.prunable_hash_valid;
}
catch (const std::exception &e)
{
@@ -1790,6 +1826,13 @@ namespace cryptonote
MINFO("Failed to re-validate tx " << e.txid << " for v" << (unsigned)version << ", dropped");
continue;
}
+ // keep the prunable hash add_tx just computed, rather than overwriting it below
+ txpool_tx_meta_t new_meta;
+ if (m_blockchain.get_txpool_tx_meta(e.txid, new_meta) && new_meta.prunable_hash_valid)
+ {
+ e.meta.prunable_hash = new_meta.prunable_hash;
+ e.meta.prunable_hash_valid = true;
+ }
m_blockchain.update_txpool_tx(e.txid, e.meta);
++added;
}
### src/cryptonote_core/tx_pool.h
@@ -460,6 +460,9 @@ namespace cryptonote
bool do_not_relay; //!< to avoid relay this transaction to the network
bool double_spend_seen; //!< true iff another tx was seen double spending this one
+
+ crypto::hash prunable_hash; //!< cached prunable hash, valid iff `prunable_hash_valid`
+ bool prunable_hash_valid; //!< whether `prunable_hash` was cached at pool-insertion time
};
/**
### src/rpc/core_rpc_server.cpp
@@ -763,8 +763,13 @@ namespace cryptonote
assert(pruned_tx_blob.size() <= prunable_tx_blob.size());
prunable_tx_blob.erase(prunable_tx_blob.cbegin(), prunable_tx_blob.cbegin() + pruned_tx_blob.size());
- // calculate unprunable hash if applicable
+ // Use the cached prunable hash if available, otherwise, fall back to calculating it here
crypto::hash prunable_hash = crypto::null_hash;
+ if (td.prunable_hash_valid)
+ {
+ prunable_hash = td.prunable_hash;
+ }
+ else
{
const std::size_t tx_version = get_tx_version(pruned_tx_blob);
if (1 != tx_version && !calculate_transaction_prunable_hash(tx_version, prunable_tx_blob, prunable_hash))
### tests/functional_tests/txpool.py
@@ -270,6 +270,22 @@ def check_txpool(self):
assert res.txs[0].in_pool
assert res.txs[0].relayed
+ print('Checking cached prunable hash against independently calculated value')
+ # while unconfirmed, prunable_hash comes from the pool's cache (populated
+ # when the tx was inserted/re-inserted into the pool)
+ pool_prunable_hash = res.txs[0].prunable_hash
+ assert len(pool_prunable_hash) == 64
+ assert pool_prunable_hash != '0' * 64
+
+ # once mined, prunable_hash is calculated independently from the
+ # confirmed blockchain data, not the pool's cache
+ daemon.generateblocks('42ey1afDFnn4886T7196doS9GPMzexD9gXpsZJDwVjeRVdFCSoHnv7KPbBeGpzJBzHRCAs9UxqeoyFQMYbqSWYTfJJQAWDm', 1)
+ res = daemon.get_transactions([txid])
+ assert len(res.txs) == 1
+ assert res.txs[0].tx_hash == txid
+ assert not res.txs[0].in_pool
+ assert res.txs[0].prunable_hash == pool_prunable_hash
+
daemon.flush_txpool()
self.check_empty_pool()
Why this scored 19/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.