Skip to content

[KLC-1601] Fix relayer transaction creation#13

Merged
nickgs1337 merged 3 commits intomainfrom
KLC-1601-fix-relayer-transaction-hash-calculation
Jun 12, 2025
Merged

[KLC-1601] Fix relayer transaction creation#13
nickgs1337 merged 3 commits intomainfrom
KLC-1601-fix-relayer-transaction-hash-calculation

Conversation

@RomuloSiebra
Copy link
Copy Markdown

@RomuloSiebra RomuloSiebra commented Jun 5, 2025

Changes

  • Add smart contract call to transaction
  • Fix transaction signature generation
  • Update tests to validate changes

Summary by CodeRabbit

  • Bug Fixes

    • Corrected the JSON response key for transaction fee estimation to use "data" instead of "fees", ensuring proper compatibility with expected API responses.
  • Refactor

    • Updated internal terminology and log messages to consistently reference Klever instead of MultiversX.
    • Improved transaction signing to use a more secure hashing method, enhancing reliability and maintainability.
  • Tests

    • Updated test cases to reflect changes in transaction signature generation and address formatting.
  • Chores

    • Removed an unused workspace configuration file.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Jun 5, 2025

Walkthrough

The changes update the Klever blockchain client by renaming constants and logging identifiers to Klever-specific terms, integrating new marshaling and hashing utilities, and adjusting transaction signing to use a computed hash. Struct field tags and test assertions are updated for consistency. An unused workspace JSON file is removed.

Changes

File(s) Change Summary
clients/klever/client.go Updated constant names, logger identifiers, and comments to Klever-specific terms; initialized marshalizer and hasher for transaction handler.
clients/klever/transactionHandler.go Refactored transaction signing to hash raw data using new marshalizer and hasher; added computeTxHash method; updated imports.
clients/klever/transactionHandler_test.go Injected marshalizer and hasher into test setup; updated address comparison and expected signature in tests.
clients/klever/proxy/models/transactions.go Changed JSON field tag for Data in EstimateTransactionFeesResponse from "fees" to "data".
kleverchain.workspace.json Deleted empty workspace JSON file.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant TransactionHandler
    participant Marshalizer
    participant Hasher
    participant Signer

    Client->>TransactionHandler: Create and send transaction
    TransactionHandler->>Marshalizer: Marshal transaction data
    Marshalizer-->>TransactionHandler: Marshaled bytes
    TransactionHandler->>Hasher: Hash marshaled bytes ("blake2b")
    Hasher-->>TransactionHandler: Transaction hash
    TransactionHandler->>Signer: Sign transaction hash
    Signer-->>TransactionHandler: Signature
    TransactionHandler-->>Client: Return transaction hash and signature
Loading

Poem

In Klever fields where code does grow,
Marshals and hashes now in tow,
Transactions sign with blake2b’s might,
JSON tags aligned just right.
The workspace file has hopped away—
A lighter chain for us today!
🐇✨

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • JIRA integration encountered authorization issues. Please disconnect and reconnect the integration in the CodeRabbit UI.

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 65b0425 and a0d862c.

📒 Files selected for processing (5)
  • clients/klever/client.go (8 hunks)
  • clients/klever/proxy/models/transactions.go (1 hunks)
  • clients/klever/transactionHandler.go (5 hunks)
  • clients/klever/transactionHandler_test.go (4 hunks)
  • kleverchain.workspace.json (0 hunks)
💤 Files with no reviewable changes (1)
  • kleverchain.workspace.json
🧰 Additional context used
🧬 Code Graph Analysis (1)
clients/klever/client.go (2)
integrationTests/testscommon.go (1)
  • Log (21-21)
core/loggerWithIdentifier.go (1)
  • NewLoggerWithIdentifier (14-25)
🔇 Additional comments (16)
clients/klever/proxy/models/transactions.go (1)

35-35: LGTM! JSON field tag corrected to match the field purpose.

The change from "fees" to "data" aligns the JSON key with the field name and makes the API response structure more consistent. This ensures proper marshaling/unmarshaling of the EstimateTransactionFeesResponse.

clients/klever/transactionHandler_test.go (4)

10-12: Imports updated to support new transaction signing dependencies.

The added imports for hasher and marshalizer factories align with the new transaction signing logic that computes hashes instead of using JSON marshaling.


39-51: Test setup enhanced with proper dependency injection.

The test setup correctly initializes and injects the marshalizer and hasher dependencies, mirroring the production code initialization pattern in client.go. This ensures the tests validate the actual runtime behavior.


170-170: Address comparison improved using Bech32 format.

Comparing the Bech32 string representation is more appropriate than comparing raw address bytes, as it validates the human-readable address format that would be used in practice.


177-177: Signature expectation updated for new signing process.

The expected signature value reflects the new hash-based signing process instead of JSON marshaling. This change is consistent with the transaction signing refactor in the main code.

clients/klever/transactionHandler.go (5)

6-9: Imports updated to support improved transaction signing.

The new imports for hashing and marshaling utilities replace JSON-based serialization with more efficient internal marshaling, which is appropriate for cryptographic operations.


24-25: Transaction handler enhanced with cryptographic dependencies.

Adding marshalizer and hasher fields enables proper hash computation for transaction signing, moving away from JSON marshaling to more efficient and secure internal serialization.


60-70: Smart contract creation made explicit and robust.

The explicit creation of the SmartContract struct with proper type (SCInvoke) and address ensures the transaction structure is correctly formed. This is more reliable than implicit contract handling.


89-94: Transaction signing improved with hash-based approach.

Using the computed hash instead of JSON marshaling for signing is more efficient and follows cryptographic best practices. The computeTxHash method provides proper abstraction for this operation.


104-111: Hash computation method properly implemented.

The computeTxHash method correctly uses the injected marshalizer and hasher to compute the transaction hash. This provides a clean separation of concerns and follows the Klever SDK patterns.

clients/klever/client.go (6)

12-13: Dependencies added for enhanced transaction signing.

The imports for marshalizer and hasher factories support the new hash-based transaction signing approach, replacing JSON marshaling with more efficient internal serialization.


29-30: Constants updated to reflect Klever terminology.

The renaming from MultiversX-specific terms to Klever-specific terms improves code clarity and aligns with the current blockchain implementation.

Also applies to: 35-35


53-53: Comment updated for accuracy.

The comment correctly reflects that this is a Klever Blockchain Client implementation.


121-129: Cryptographic components properly initialized.

The factory-based initialization of ProtoMarshalizer and Blake2b hasher is well-implemented with proper error handling. These components support the improved transaction signing process.


140-141: Dependencies correctly injected into transaction handler.

The marshalizer and hasher are properly injected into the transaction handler, enabling the new hash-based signing functionality.


157-157: Log message updated for consistency.

The log message now correctly identifies this as a Klever blockchain client, maintaining consistency with the overall rebranding.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@@ -1 +0,0 @@
{} No newline at end of file
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this file is a problem, you should consider adding it to gitignore

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can add, however I don't think is needed since this project doesn't uses Klever IDE.

@nickgs1337 nickgs1337 merged commit 88eba0c into main Jun 12, 2025
1 of 6 checks passed
@nickgs1337 nickgs1337 deleted the KLC-1601-fix-relayer-transaction-hash-calculation branch June 12, 2025 13:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants