-
-
Notifications
You must be signed in to change notification settings - Fork 16
[OPTIMIZE] Implement lazy hashing cache for Transaction IDs #75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sanaica
wants to merge
16
commits into
StabilityNexus:main
Choose a base branch
from
sanaica:optimize-tx-hashing
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
6faa9de
optimize: implement lazy hashing cache for Transaction IDs
sanaica 8912e16
test: refactor diagnostic prints to assertions and fix linting
sanaica 43507e7
refactor: implement guarded __setattr__ for robust cache invalidation
sanaica 7c7d51c
refactor: use guarded __setattr__ for automated cache invalidation
sanaica 07f11c6
fix: frozenset for _TX_FIELDS and is not None timestamp check
sanaica 76e691c
chore: trigger CodeRabbit re-review
sanaica 655d49d
fix: use try/except/else in verify() for TRY300
sanaica cf4a0ba
chore: trigger CodeRabbit re-review
sanaica 7d3dc7f
fix: normalize timestamps and seal tx fields after signing
sanaica b18d6af
feat: add state sealing and robust cache invalidation
sanaica 8988a33
feat: add mock-based verification for hashing efficiency
sanaica 19fd40a
test: implement mock-based call counting to verify hashing efficiency
sanaica 9b20f49
test: implement mock-based call counting to verify hashing efficiency
sanaica 5a5d751
chore: trigger CodeRabbit re-review
sanaica 3e93e01
test: add parameterized loop to verify comprehensive cache invalidation
sanaica 445fcf5
chore: trigger CodeRabbit re-review
sanaica File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| from minichain.transaction import Transaction | ||
| from nacl.signing import SigningKey | ||
| from nacl.encoding import HexEncoder | ||
|
|
||
|
|
||
| def test_tx_caching(): | ||
| sk = SigningKey.generate() | ||
| sender_hex = sk.verify_key.encode(encoder=HexEncoder).decode() | ||
| tx = Transaction(sender=sender_hex, receiver="addr", amount=100, nonce=1) | ||
|
|
||
| assert tx._cached_tx_id is None | ||
| first_id = tx.tx_id | ||
| assert tx._cached_tx_id == first_id | ||
| assert tx.tx_id == first_id # second access, same result | ||
|
|
||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
| tx.sign(sk) | ||
| assert tx._cached_tx_id is None | ||
|
|
||
| signed_id = tx.tx_id | ||
| assert signed_id != first_id | ||
| assert tx._cached_tx_id == signed_id | ||
|
|
||
|
|
||
| def test_tx_mutation_clears_cache(): | ||
| tx = Transaction(sender="alice", receiver="bob", amount=100, nonce=1) | ||
| original_id = tx.tx_id | ||
| assert tx._cached_tx_id is not None | ||
|
|
||
| tx.amount = 500 | ||
| assert tx._cached_tx_id is None | ||
| assert tx.tx_id != original_id | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.