fix: use Option<CryptoHash> for Transaction block_hash#135
Open
fix: use Option<CryptoHash> for Transaction block_hash#135
Conversation
The RPC `SignedTransactionView` response contains the transaction hash but not the block hash that was used when signing. Previously, the `TryFrom<SignedTransactionView>` conversion incorrectly placed the transaction hash into the `block_hash` field, causing `get_hash()` to return wrong values. This changes `block_hash` to `Option<CryptoHash>` on `TransactionV0` and `TransactionV1`, so consumers are forced to handle the missing case. Custom borsh serialize/deserialize helpers preserve the on-chain wire format. The `SignedTransaction` hash is now pre-populated from the RPC response so `get_hash()` returns the correct value. Closes #134
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #135 +/- ##
=======================================
Coverage 50.90% 50.90%
=======================================
Files 40 40
Lines 5265 5298 +33
=======================================
+ Hits 2680 2697 +17
- Misses 2585 2601 +16 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes #134 — the
TryFrom<SignedTransactionView>conversion was placing the transaction hash into theblock_hashfield, since the RPC response doesn't include the block hash used at signing time. This causedSignedTransaction::get_hash()to return incorrect values.block_hashfromCryptoHashtoOption<CryptoHash>onTransactionV0andTransactionV1, forcing consumers to handle the missing caseserialize_with/deserialize_withto preserve the on-chain wire format (panics with a clear message if you try to serialize aNoneblock hash)SignedTransactionhash cache with the correct tx hash from the RPC responseTransaction::block_hash()accessor returningOption<CryptoHash>Breaking change:
block_hashfield type changed fromCryptoHashtoOption<CryptoHash>onTransactionV0/TransactionV1.Test plan
cargo checkpassescargo test --libpasses (all 40 tests)Optiontype