generated from StabilityNexus/Template-Repo
-
-
Notifications
You must be signed in to change notification settings - Fork 14
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Description
Currently, the Transaction.tx_id calculation logic re-computes the SHA-256 hash every time the identifier is requested. During high-load operations like block validation or full-node syncing, the CPU performs these expensive cryptographic operations thousands of times for the same static data.
By implementing a caching pattern, we store the result of the first hash calculation and reuse it for all subsequent calls, significantly reducing redundant CPU cycles.
Proposed Optimization
- Lazy Initialization: Add a
_cached_tx_idattribute to theTransactionclass (initialized asNonein__init__). - Memoization: Update the
@property tx_idto check if_cached_tx_idexists. If not, it calculates the hash once viacanonical_json_hashand stores it. - Cache Invalidation: The
sign()method modifies the transaction payload by adding a signature, will reset_cached_tx_idtoNoneto ensure the ID always reflects a signed state.
Expected Impact
- Performance: Dramatically reduces SHA-256 overhead during validation loops.
- Minimality: Implemented with a code footprint, maintaining the project's "strictly minimal" philosophy.
-
Scalability: Complements the ongoing
$O(1)$ mempool work by ensuring ID retrieval is as fast as the dictionary lookup.
Roadmap Alignment
This supports the "Core Perfection" phase to make it minimal, clean, and performant.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request