Skip to content
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

fix(x/tx): add unordered and timeout timestamp fields in textual signing #23324

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

julienrbrt
Copy link
Member

@julienrbrt julienrbrt commented Jan 10, 2025

Description

Found during #22723


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title, you can find examples of the prefixes below:
  • confirmed ! in the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • reviewed "Files changed" and left comments if necessary
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • updated the relevant documentation or specification, including comments for documenting Go code
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

Please see Pull Request Reviewer section in the contributing guide for more information on how to review a pull request.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic, API design and naming, documentation is accurate, tests and test coverage

Summary by CodeRabbit

  • New Features

    • Added ability to sign over unordered and timeout timestamp fields in transactions
    • Enhanced transaction metadata with new timestamp and ordering options
  • Improvements

    • Updated dependencies for better protocol buffer handling
    • Refined transaction signing and parsing mechanisms
  • Chores

    • Updated changelog for version v1.0.1
    • Synchronized version information across project components

@julienrbrt julienrbrt requested a review from a team as a code owner January 10, 2025 15:38
Copy link
Contributor

coderabbitai bot commented Jan 10, 2025

📝 Walkthrough

Walkthrough

This pull request introduces changes to the x/tx module, focusing on enhancing transaction signing capabilities. The modifications include updating the changelog to version v1.0.1, adding new dependencies in the buf.yaml configuration, and extending the Envelope message structure in textual.proto. The changes primarily involve introducing support for signing over unordered and timeout timestamp fields, with updates to various files to accommodate these new transaction-related features.

Changes

File Change Summary
x/tx/CHANGELOG.md - Added new version entry v1.0.1
- Updated v1.0.0 entry to note equivalence to v1.0.0-alpha.3
x/tx/signing/textual/internal/textualpb/buf.yaml - Added dependencies:
- buf.build/cosmos/cosmos-sdk
- buf.build/protocolbuffers/wellknowntypes:v23.4
x/tx/signing/textual/internal/textualpb/textual.proto - Added fields to Envelope message:
- bool unordered = 19
- google.protobuf.Timestamp timeout_timestamp = 20
x/tx/signing/textual/internal/textualpb/textual.pulsar.go - Removed fields: Tip, Tipper
- Added fields: Unordered, TimeoutTimestamp
- Updated init, ProtoMethods, and related methods
x/tx/signing/textual/tx.go - Added TimeoutTimestamp and Unordered fields to transaction handling

Sequence Diagram

sequenceDiagram
    participant Client
    participant TxSigning
    participant Envelope
    
    Client->>TxSigning: Create Transaction
    TxSigning->>Envelope: Set Unordered Flag
    TxSigning->>Envelope: Set Timeout Timestamp
    Envelope-->>TxSigning: Validate Transaction
    TxSigning-->>Client: Signed Transaction
Loading

Possibly Related PRs

Suggested Reviewers

  • julienrbrt
  • aaronc
  • tac0turtle
  • kocubinski
  • sontrinh16

Finishing Touches

  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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. (Beta)
  • @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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (7)
x/tx/signing/textual/internal/textualpb/textual.pulsar.go (4)

14-14: Missing Import Comment

The new import of timestamppb "google.golang.org/protobuf/types/known/timestamppb" should be accompanied by a comment explaining why it's needed, to enhance code readability.


Line range hint 3104-3168: Update Comment for TextualData and SignerData

The comments for TextualData and SignerData mention their roles and usage. Consider updating these comments to reflect any changes in their interactions with the newly added fields in the Envelope message.

For example:

// TextualData represents all the information needed to generate
// the textual SignDoc (which is []Screen encoded to CBOR). It is meant to be
// used as an internal type in Textual's implementations.
+ // It now includes support for unordered transactions and timeout timestamps.

3283-3284: Document New Fields in the Envelope Message

The fields Unordered and TimeoutTimestamp have been added to the Envelope message. It's important to update the documentation comments for the Envelope struct to explain the purpose and usage of these new fields.

For example:

// Envelope is an internal data structure used to generate the tx envelope
// screens. It is derived from the TextualData struct (also internal) which
// contains the three following fields:
// - body_bytes (from the original tx),
// - auth_info_bytes (from the original tx),
// - signer_data (passed in by the sign mode handler)
//
// If any of the three structs above is modified, then this Envelope message
// also needs to be updated.
+//
//+// unordered indicates whether the transaction should be processed in an unordered fashion.
//+// timeout_timestamp specifies the timestamp after which the transaction should be considered invalid.

Also applies to: 3419-3431


3444-3453: Maintain Import Order

In the imports section, ensure that standard library imports, external imports, and project-specific imports are properly grouped and ordered for better readability.

Consider grouping google.protobuf imports together.

x/tx/signing/textual/tx.go (1)

Line range hint 3169-3170: Update getSigners Function Documentation

The getSigners function relies on the protobuf annotation cosmos.msg.v1.signer. Ensure that this function's documentation is up to date, especially if the new fields affect signer determination.

Consider adding:

// getSigners gets the ordered signers of a transaction, taking into account
// the new `Unordered` field, which may impact the signing order.
x/tx/signing/textual/internal/textualpb/textual.proto (2)

7-7: Group New Import with Similar Dependencies

The new import google/protobuf/timestamp.proto should be grouped with other google.protobuf imports for better organization.

Consider reordering imports:

import "google/protobuf/any.proto";
import "google/protobuf/timestamp.proto";

87-88: Add Comments for New Fields in Envelope

The new field bool unordered = 19; lacks a descriptive comment. Adding a comment will enhance the understanding of its purpose in the message.

For example:

// unordered indicates if the transaction should be processed without order constraints.
bool unordered = 19;
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a6b0924 and 1b8c4b9.

⛔ Files ignored due to path filters (1)
  • x/tx/signing/textual/internal/textualpb/buf.lock is excluded by !**/*.lock
📒 Files selected for processing (5)
  • x/tx/CHANGELOG.md (1 hunks)
  • x/tx/signing/textual/internal/textualpb/buf.yaml (1 hunks)
  • x/tx/signing/textual/internal/textualpb/textual.proto (2 hunks)
  • x/tx/signing/textual/internal/textualpb/textual.pulsar.go (20 hunks)
  • x/tx/signing/textual/tx.go (2 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
x/tx/signing/textual/tx.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

x/tx/CHANGELOG.md (1)

Pattern **/*.md: "Assess the documentation for misspellings, grammatical errors, missing documentation and correctness"

x/tx/signing/textual/internal/textualpb/textual.pulsar.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

⏰ Context from checks skipped due to timeout of 90000ms (12)
  • GitHub Check: tests (03)
  • GitHub Check: tests (02)
  • GitHub Check: tests (01)
  • GitHub Check: tests (00)
  • GitHub Check: test-simapp-v2
  • GitHub Check: test-integration
  • GitHub Check: test-system-v2
  • GitHub Check: build (arm64)
  • GitHub Check: build (amd64)
  • GitHub Check: Analyze
  • GitHub Check: golangci-lint
  • GitHub Check: Summary
🔇 Additional comments (14)
x/tx/signing/textual/internal/textualpb/buf.yaml (2)

3-3: Verify potential circular dependency

Adding buf.build/cosmos/cosmos-sdk as a dependency within the cosmos-sdk repository itself might create a circular dependency. Please verify if this is intentional and necessary.

✅ Verification successful

Dependency pattern is correct and consistent with codebase

The buf.build/cosmos/cosmos-sdk dependency is a standard pattern used across the repository's protobuf configurations, appearing in 28+ other buf.yaml files. This is normal for protobuf type definitions and doesn't create problematic circular dependencies.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if this creates a circular dependency by examining other buf.yaml files
echo "Searching for other buf.yaml files that might be affected..."
fd buf.yaml --type f --exec grep -l "buf.build/cosmos/cosmos-sdk" {}

Length of output: 1108


6-6: Verify wellknowntypes version compatibility

The addition of buf.build/protocolbuffers/wellknowntypes:v23.4 seems appropriate for the new timestamp field. However, let's verify if this is the latest stable version and if it's compatible with other dependencies.

✅ Verification successful

✓ Wellknowntypes version is consistent

The version v23.4 is consistently used across both buf.yaml files in the codebase, confirming proper version alignment.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check other buf.yaml files for wellknowntypes versions to ensure consistency
echo "Checking for other wellknowntypes versions in the codebase..."
fd buf.yaml --type f --exec grep -l "buf.build/protocolbuffers/wellknowntypes" {}

Length of output: 284


Script:

#!/bin/bash
echo "=== Content of ./x/tx/signing/textual/internal/textualpb/buf.yaml ==="
grep -A 1 -B 1 "wellknowntypes" ./x/tx/signing/textual/internal/textualpb/buf.yaml

echo -e "\n=== Content of ./proto/buf.yaml ==="
grep -A 1 -B 1 "wellknowntypes" ./proto/buf.yaml

Length of output: 553

x/tx/signing/textual/internal/textualpb/textual.pulsar.go (7)

1519-1520: Ensure Consistency in Field Descriptors

The addition of fd_Envelope_unordered and fd_Envelope_timeout_timestamp should be consistently integrated with proper initialization in the init() function. Verify that all field descriptors are correctly set up to avoid runtime issues.

Also applies to: 1542-1543


1707-1718: Handle New Fields in Range Method

The Range method for fastReflection_Envelope now includes handling for Unordered and TimeoutTimestamp. Ensure that these fields are correctly reflected and that their inclusion does not affect the iteration logic over populated fields.


1818-1821: Clear Method Should Reset New Fields

The Clear method now resets Unordered and TimeoutTimestamp. Confirm that clearing these fields aligns with expected behavior and does not introduce unintended side effects.


1901-1906: Get Method Correctly Retrieves New Fields

The Get method now includes cases for Unordered and TimeoutTimestamp. Ensure that the retrieval logic accurately returns the values of these new fields.


Line range hint 2028-2054: Mutable and NewField Methods Should Correctly Handle New Fields

In the Mutable and NewField methods, handling of TimeoutTimestamp is added. Ensure that attempting to mutate or create these fields behaves as intended and that immutability constraints are respected where applicable.


2250-2256: Update Size and Marshal Methods for New Fields

The Size and Marshal methods are updated to include Unordered and TimeoutTimestamp. Verify that the size calculations and marshaling logic correctly account for these fields to prevent serialization errors.

Also applies to: 2286-2313


2999-3054: Update Unmarshal Method to Handle New Fields

The Unmarshal method now includes cases for Unordered and TimeoutTimestamp. Confirm that it can correctly parse incoming data for these fields without causing errors, ensuring robustness in deserialization.

x/tx/signing/textual/tx.go (1)

234-235: Ensure New Fields Are Properly Marshaled Back

When reconstructing txBody in the Parse method, TimeoutTimestamp and Unordered are included. Verify that these fields are correctly populated from the parsed envelope to maintain data integrity during the serialization and deserialization processes.

x/tx/signing/textual/internal/textualpb/textual.proto (1)

87-88: Confirm Field Numbers Do Not Conflict

Ensure that the field numbers assigned to unordered (19) and timeout_timestamp (20) do not conflict with any existing or reserved field numbers in the Envelope message.

Run the following script to verify field numbers:

If the script outputs any numbers, there is a conflict that needs to be resolved.

✅ Verification successful

No Field Number Conflicts Found

The field numbers 19 and 20 assigned to unordered and timeout_timestamp respectively do not conflict with any existing fields in the Envelope message.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for duplicate field numbers in Envelope message.

# Extract field numbers
grep -E '=[[:space:]]*[0-9]+;' textual.proto | grep -o '=[[:space:]]*[0-9]\+' | sort | uniq -d

Length of output: 143


Script:

#!/bin/bash
# First, let's verify the file exists and see its content
cat x/tx/signing/textual/internal/textualpb/textual.proto

# Then use ast-grep to find the Envelope message structure
ast-grep --pattern 'message Envelope {
  $$$
}'

Length of output: 3984

x/tx/CHANGELOG.md (3)

36-38: LGTM! Version and release date are properly formatted.

The new version entry follows the changelog format guidelines with proper linking and release date.


38-38: LGTM! Changelog message is clear and follows the format.

The message correctly references PR #23324 and clearly describes the changes related to signing over unordered and timeout timestamp fields.


40-42: LGTM! Version note is clear and accurate.

The note about v1.0.0 being identical to v1.0.0-alpha.3 provides helpful context about version equivalence.

Comment on lines +1969 to +1972
case "Envelope.unordered":
x.Unordered = value.Bool()
case "Envelope.timeout_timestamp":
x.TimeoutTimestamp = value.Message().Interface().(*timestamppb.Timestamp)
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Set Method Should Handle New Fields Safely

The Set method now allows setting values for Unordered and TimeoutTimestamp. Validate that input values are correctly assigned and that type assertions are safe to prevent potential panics.

Apply this diff to ensure type safety when setting the TimeoutTimestamp field:

- x.TimeoutTimestamp = value.Message().Interface().(*timestamppb.Timestamp)
+ if ts, ok := value.Message().Interface().(*timestamppb.Timestamp); ok {
+     x.TimeoutTimestamp = ts
+ } else {
+     panic(fmt.Errorf("invalid type for TimeoutTimestamp field"))
+ }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
case "Envelope.unordered":
x.Unordered = value.Bool()
case "Envelope.timeout_timestamp":
x.TimeoutTimestamp = value.Message().Interface().(*timestamppb.Timestamp)
case "Envelope.unordered":
x.Unordered = value.Bool()
case "Envelope.timeout_timestamp":
if ts, ok := value.Message().Interface().(*timestamppb.Timestamp); ok {
x.TimeoutTimestamp = ts
} else {
panic(fmt.Errorf("invalid type for TimeoutTimestamp field"))
}

Comment on lines +82 to +83
TimeoutTimestamp: txBody.TimeoutTimestamp,
Unordered: txBody.Unordered,
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Handle Potential Nil Pointers for New Fields

When assigning TimeoutTimestamp and Unordered from txBody, ensure that txBody is not nil and that these fields are properly initialized to avoid potential nil pointer dereferences.

Apply this diff to add nil checks:

+ if txBody != nil {
      envelope.TimeoutTimestamp = txBody.TimeoutTimestamp
      envelope.Unordered = txBody.Unordered
+ }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
TimeoutTimestamp: txBody.TimeoutTimestamp,
Unordered: txBody.Unordered,
if txBody != nil {
TimeoutTimestamp: txBody.TimeoutTimestamp,
Unordered: txBody.Unordered,
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant