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

Wait for logs in blockchain publisher #249

Merged
merged 1 commit into from
Oct 23, 2024

Conversation

neekolas
Copy link
Contributor

@neekolas neekolas commented Oct 22, 2024

tl;dr

  • Gets the full logs of the transaction when submitting to the blockchain, so we can construct a valid OriginatorEnvelope that includes the sequence_id

Notes

Once this is in I will update #248 to take advantage of it

Summary by CodeRabbit

Release Notes

  • New Features

    • Enhanced blockchain message publishing with improved error handling and structured responses.
    • Introduced new methods for parsing transaction receipts related to message sending and identity updates.
    • Added a utility function to create a cancelled context for testing purposes.
  • Bug Fixes

    • Refined error handling in blockchain publishing methods to provide clearer error messages and logging.
  • Tests

    • Added unit tests for BlockchainPublisher methods to ensure expected functionality and error handling.
  • Documentation

    • Updated method signatures to reflect new return types for blockchain publishing operations.

Copy link
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @neekolas and the rest of your teammates on Graphite Graphite

@neekolas neekolas marked this pull request as ready for review October 22, 2024 23:25
@neekolas neekolas requested a review from a team as a code owner October 22, 2024 23:25
Copy link

coderabbitai bot commented Oct 22, 2024

Walkthrough

The changes introduced in this pull request enhance the functionality and error handling of blockchain-related operations within the application. Key modifications include updates to the publishToBlockchain method in the Service type, which now captures structured responses and improves error logging. The BlockchainPublisher methods have been altered to return more specific types instead of hashes, and new private methods for log parsing have been added. Additionally, a new test file establishes unit tests for these functionalities, ensuring that the methods operate correctly under various conditions.

Changes

File Change Summary
pkg/api/payer/service.go Added import for github.com/xmtp/xmtpd/pkg/abis. Updated publishToBlockchain method to enhance error handling and response structure, introducing logMessage for transaction hash capture.
pkg/blockchain/blockchainPublisher.go Updated return types of PublishGroupMessage and PublishIdentityUpdate methods to pointers of specific types from abis. Added private methods for log parsing and improved error handling in these methods.
pkg/blockchain/blockchainPublisher_test.go Introduced unit tests for BlockchainPublisher methods, verifying functionality and ensuring correct handling of return values.
pkg/blockchain/client.go Changed return type of WaitForTransaction from (common.Hash, error) to (*types.Receipt, error), updating internal logic to reflect this change.
pkg/blockchain/interface.go Updated return types in IBlockchainPublisher interface for PublishIdentityUpdate and PublishGroupMessage to pointers of specific types from abis.
pkg/mocks/blockchain/mock_IBlockchainPublisher.go Updated mock implementation to reflect new return types for PublishGroupMessage and PublishIdentityUpdate methods, adjusting handling logic accordingly.
pkg/testutils/context.go Added CancelledContext function to create a context that is already cancelled for testing purposes.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Service
    participant BlockchainPublisher
    participant Abis

    Client->>Service: publishToBlockchain()
    Service->>BlockchainPublisher: PublishGroupMessage()
    BlockchainPublisher->>Abis: Process message
    Abis-->>BlockchainPublisher: Return GroupMessagesMessageSent
    BlockchainPublisher->>Service: Return logMessage
    Service-->>Client: Return transaction hash and error status
Loading

🐰 "In the blockchain's dance, we leap and we bound,
With messages sent, new structures abound.
Errors caught with a hop, a skip, and a jump,
In the world of code, we celebrate the thump!
With tests in our burrow, we frolic with glee,
For every new change, brings joy to you and me!" 🐇✨


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 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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

@neekolas neekolas force-pushed the 10-22-wait_for_logs_in_blockchain_publisher branch 2 times, most recently from 5b6fed9 to 7b3ac1d Compare October 22, 2024 23:27
Copy link

@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: 12

🧹 Outside diff range and nitpick comments (2)
pkg/blockchain/blockchainPublisher_test.go (1)

1-67: Tests effectively validate blockchain log retrieval.

The test suite successfully verifies that the blockchain publisher waits for and receives complete transaction logs, which aligns with the PR objective of ensuring complete logs for constructing valid OriginatorEnvelopes.

Consider adding integration tests that verify the complete flow from publishing to OriginatorEnvelope construction to ensure end-to-end validation of the changes.

pkg/blockchain/client.go (1)

44-44: Include transaction hash in failure error message for better context

Returning a generic error message like "transaction failed" may not provide enough information for debugging. Including the transaction hash in the error message can help identify the failed transaction more easily.

Update the error message to include the transaction hash:

 return nil, fmt.Errorf("transaction failed")
+return nil, fmt.Errorf("transaction %s failed", hash.String())
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between ef6061a and 7b3ac1d.

📒 Files selected for processing (6)
  • pkg/api/payer/service.go (2 hunks)
  • pkg/blockchain/blockchainPublisher.go (3 hunks)
  • pkg/blockchain/blockchainPublisher_test.go (1 hunks)
  • pkg/blockchain/client.go (3 hunks)
  • pkg/blockchain/interface.go (2 hunks)
  • pkg/mocks/blockchain/mock_IBlockchainPublisher.go (4 hunks)
🧰 Additional context used
🔇 Additional comments (11)
pkg/blockchain/interface.go (2)

11-11: LGTM: Import addition is appropriate.

The new import is required to support the enhanced return types from blockchain events.


53-58: Verify implementations handle the new return types correctly.

The change from returning common.Hash to structured event types (*abis.IdentityUpdatesIdentityUpdateCreated and *abis.GroupMessagesMessageSent) is a good improvement that provides more detailed information about the blockchain events. However, as this is a breaking interface change:

  1. Ensure all implementations properly handle nil returns in error cases
  2. Update all consumers to handle the new return types appropriately

Let's verify the implementations and consumers:

✅ Verification successful

Let me analyze the results and generate a final response based on the findings.

Interface changes have been properly implemented and handled

The verification results show that:

  1. The implementation in BlockchainPublisher exists and has been updated to handle the new return types (pkg/blockchain/blockchainPublisher.go)
  2. Tests have been updated to verify nil checks (pkg/blockchain/blockchainPublisher_test.go)
  3. All consumers properly handle the new return types:
    • pkg/api/payer/service.go correctly uses the returned log messages
    • pkg/indexer/e2e_test.go has been updated to handle the new return type
    • Mock implementations in pkg/mocks/blockchain/mock_IBlockchainPublisher.go correctly reflect the new return types

The changes are consistent across the codebase, and all implementations and consumers have been properly updated to handle the new structured event types.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find all implementations and consumers of IBlockchainPublisher

# Find implementations
echo "=== IBlockchainPublisher Implementations ==="
ast-grep --pattern 'type $_ struct {
  $$$
}

func ($_ $_) PublishIdentityUpdate'

# Find method calls
echo -e "\n=== Method Consumers ==="
rg -A 2 'PublishIdentityUpdate|PublishGroupMessage' --type go

Length of output: 24017

pkg/blockchain/blockchainPublisher_test.go (1)

1-9: LGTM! Clean and appropriate test imports.

pkg/mocks/blockchain/mock_IBlockchainPublisher.go (4)

6-8: LGTM: Import changes align with new return types.

The addition of the abis package import is necessary to support the updated return types that capture blockchain event data.


76-82: LGTM: Helper methods properly adapted.

The mock helper methods have been correctly updated to handle the new return types, maintaining the expected mock functionality for both group messages and identity updates.

Also applies to: 136-142


27-43: LGTM: Return type change enhances transaction feedback.

The change from returning common.Hash to *abis.GroupMessagesMessageSent improves the interface by providing structured event data instead of just transaction hashes. This aligns with the PR objective of capturing complete transaction logs.

Let's verify the interface alignment:

✅ Verification successful

Let me try a different search strategy to verify the interface alignment.

The previous search patterns weren't effective. Let's try with more specific commands to find the interface definition and its usage across the codebase.


Based on the search results, I can now generate the final response as we have comprehensive information about the interface definition, implementation, and all its usages.

Verified: Return type change is correctly implemented and all callers are updated

The change from common.Hash to *abis.GroupMessagesMessageSent is properly reflected across the codebase:

  • Interface definition in pkg/blockchain/interface.go declares the new return type
  • Implementation in pkg/blockchain/blockchainPublisher.go matches the interface
  • All callers have been updated to handle the new return type:
    • pkg/indexer/e2e_test.go
    • pkg/api/payer/service.go
    • pkg/blockchain/blockchainPublisher_test.go

The mock implementation correctly handles the new return type with appropriate type assertions and error handling.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the mock implementation matches the interface definition
# and that all callers have been updated to handle the new return type.

# Test 1: Check interface definition
rg -A 2 "type IBlockchainPublisher interface" pkg/blockchain/

# Test 2: Check all callers of PublishGroupMessage
ast-grep --pattern 'PublishGroupMessage($$$)'

Length of output: 205


Script:

#!/bin/bash
# Search for interface definition and implementation
rg -A 5 "PublishGroupMessage" pkg/blockchain/

# Search for the interface definition specifically
fd IBlockchainPublisher.go --exec cat {}

# Search for any direct usage of PublishGroupMessage
rg "PublishGroupMessage\(" --type go -A 2

Length of output: 10021


87-103: LGTM: Consistent return type enhancement for identity updates.

The change to return *abis.IdentityUpdatesIdentityUpdateCreated maintains consistency with the PublishGroupMessage changes and provides structured event data for identity updates.

Let's verify the interface alignment:

✅ Verification successful

Let me try a different search pattern to find the actual usage of this method.


Let me search for the interface definition more specifically.


Based on the evidence gathered, I can now generate the final response:

✅ Mock implementation correctly matches the interface definition

The mock implementation in pkg/mocks/blockchain/mock_IBlockchainPublisher.go correctly implements the PublishIdentityUpdate method as defined in the IBlockchainPublisher interface. The return type *abis.IdentityUpdatesIdentityUpdateCreated matches exactly with the interface definition in pkg/blockchain/interface.go. The implementation is also being used correctly in the codebase, as seen in pkg/api/payer/service.go.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the mock implementation matches the interface definition
# and that all callers have been updated to handle the new return type.

# Test: Check all callers of PublishIdentityUpdate
ast-grep --pattern 'PublishIdentityUpdate($$$)'

Length of output: 205


Script:

#!/bin/bash
# Search for PublishIdentityUpdate method calls and interface definition
rg "PublishIdentityUpdate" -A 3

# Also check the interface definition
ast-grep --pattern 'interface $_ {
  $$$
  PublishIdentityUpdate($$$)
  $$$
}'

Length of output: 25173


Script:

#!/bin/bash
# Search for the interface definition and implementation
rg -A 10 "type IBlockchainPublisher interface" 

Length of output: 668

pkg/blockchain/client.go (1)

26-26: Ensure all callers handle the updated return type of WaitForTransaction

The WaitForTransaction function's return type has changed to (*types.Receipt, error). Verify that all places in the codebase where this function is called have been updated to handle the new return type correctly.

Run the following script to identify all usages of WaitForTransaction:

✅ Verification successful

Let me gather more context about how these callers handle the return values by checking their implementation.


Based on the search results, I can now generate the final response as I have enough information about how the callers handle the return values.

All callers are properly handling the updated return type of WaitForTransaction

The verification shows that all callers have been correctly updated to handle the new return type:

  • In registryAdmin.go: Three calls properly use _, err = WaitForTransaction(...), discarding the receipt as it's not needed
  • In blockchainPublisher.go: Two calls correctly use receipt, err := WaitForTransaction(...), capturing both the receipt and error
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find all usages of WaitForTransaction and check for proper handling of the updated return type.
# Expected: All callers should handle (*types.Receipt, error).

rg -A 3 'WaitForTransaction\('

Length of output: 1249


Script:

#!/bin/bash
# Check the implementation around WaitForTransaction calls in registryAdmin.go
rg -B 2 -A 5 'WaitForTransaction\(' pkg/blockchain/registryAdmin.go

# Check the implementation around WaitForTransaction calls in blockchainPublisher.go
rg -B 2 -A 5 'WaitForTransaction\(' pkg/blockchain/blockchainPublisher.go

Length of output: 698

pkg/blockchain/blockchainPublisher.go (3)

121-136: Handle Multiple Matching Logs Appropriately

In findMessageSentLog, the function returns the first parsed MessageSent log it encounters. If a transaction could emit multiple MessageSent logs, consider collecting all matching logs or verifying that only one log is expected.

Confirm that only one MessageSent log is emitted per transaction or update the function to handle multiple logs.


96-98: Ensure All Callers Handle the New Return Type

The return type of PublishIdentityUpdate has changed to (*abis.IdentityUpdatesIdentityUpdateCreated, error). Please verify that all callers have been updated accordingly to handle the new return type.

Run the following script to find and review all usages of PublishIdentityUpdate:

#!/bin/bash
# Description: Find all usages of PublishIdentityUpdate in the codebase
# Expectation: All call sites are updated to handle the new return type

rg 'PublishIdentityUpdate\('

67-69: Ensure All Callers Handle the New Return Type

The return type of PublishGroupMessage has changed to (*abis.GroupMessagesMessageSent, error). Please verify that all callers of this method have been updated to handle the new return type to prevent runtime errors.

Run the following script to identify and review all usages of PublishGroupMessage:

✅ Verification successful

The search results show matches for PublishIdentityUpdate instead of PublishGroupMessage. Let me search specifically for PublishGroupMessage.


Let me check the actual usage of the return value in the call sites to verify if they handle both return values correctly.


Based on the search results, I can now provide a final response as I have enough information to verify the concern.

All Callers Are Correctly Handling the Return Type

The code review shows that all callers of PublishGroupMessage are properly handling both return values (*abis.GroupMessagesMessageSent, error):

  • In pkg/api/payer/service.go: Correctly declares and assigns the logMessage variable of type *abis.GroupMessagesMessageSent and handles the error.
  • In pkg/indexer/e2e_test.go: Uses blank identifier for the message and handles the error.
  • In pkg/blockchain/blockchainPublisher_test.go: Properly assigns both return values and verifies them with assertions.
  • The mock implementation in pkg/mocks/blockchain/mock_IBlockchainPublisher.go is also correctly set up with the proper return type.
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find all usages of PublishGroupMessage in the codebase
# Expectation: All call sites are updated to handle the new return type

rg 'PublishGroupMessage\('

Length of output: 2264


Script:

#!/bin/bash
# Search for PublishGroupMessage using ripgrep
rg "PublishGroupMessage"

Length of output: 2604


Script:

#!/bin/bash
# Get context around the PublishGroupMessage calls
rg "PublishGroupMessage" -B 2 -A 2

Length of output: 5712

pkg/blockchain/blockchainPublisher_test.go Outdated Show resolved Hide resolved
pkg/blockchain/blockchainPublisher_test.go Outdated Show resolved Hide resolved
pkg/blockchain/blockchainPublisher_test.go Outdated Show resolved Hide resolved
pkg/blockchain/client.go Outdated Show resolved Hide resolved
pkg/blockchain/blockchainPublisher.go Outdated Show resolved Hide resolved
pkg/blockchain/blockchainPublisher.go Outdated Show resolved Hide resolved
pkg/blockchain/blockchainPublisher.go Show resolved Hide resolved
pkg/api/payer/service.go Outdated Show resolved Hide resolved
pkg/api/payer/service.go Outdated Show resolved Hide resolved
pkg/api/payer/service.go Outdated Show resolved Hide resolved
@neekolas neekolas force-pushed the 10-22-wait_for_logs_in_blockchain_publisher branch from 7b3ac1d to d3a910a Compare October 23, 2024 01:26
Copy link

@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: 3

🧹 Outside diff range and nitpick comments (3)
pkg/blockchain/client.go (2)

37-46: Improve error logging message clarity

While the error handling logic is correct, the error message could be more descriptive to aid in debugging.

Consider this improvement:

-logger.Error("waiting for transaction", zap.String("hash", hash.String()))
+logger.Error("unexpected error while waiting for transaction receipt", 
+    zap.String("hash", hash.String()),
+    zap.Error(err))

51-51: Enhance timeout error message

The error message could be more specific about what timed out.

Consider this improvement:

-return nil, fmt.Errorf("timed out")
+return nil, fmt.Errorf("timed out waiting for transaction receipt after %v", timeout)
pkg/blockchain/blockchainPublisher.go (1)

131-147: Consider adding defensive checks and debug logging

The generic implementation is clean and effectively reduces duplication. Consider these minor improvements:

  1. Add an early return if receipt.Logs is nil/empty
  2. Add debug logging when logs are skipped due to parsing errors
 func findLog[T any](
     receipt *types.Receipt,
     parse func(types.Log) (*T, error),
     errorMsg string,
 ) (*T, error) {
+    if receipt.Logs == nil || len(receipt.Logs) == 0 {
+        return nil, errors.New(errorMsg)
+    }
     for _, logEntry := range receipt.Logs {
         if logEntry == nil {
             continue
         }
         event, err := parse(*logEntry)
         if err != nil {
+            m.logger.Debug("failed to parse log entry", 
+                zap.Error(err),
+                zap.String("topic0", logEntry.Topics[0].Hex()))
             continue
         }
         return event, nil
     }

     return nil, errors.New(errorMsg)
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 7b3ac1d and d3a910a.

📒 Files selected for processing (6)
  • pkg/api/payer/service.go (2 hunks)
  • pkg/blockchain/blockchainPublisher.go (3 hunks)
  • pkg/blockchain/blockchainPublisher_test.go (1 hunks)
  • pkg/blockchain/client.go (3 hunks)
  • pkg/blockchain/interface.go (2 hunks)
  • pkg/mocks/blockchain/mock_IBlockchainPublisher.go (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • pkg/blockchain/blockchainPublisher_test.go
  • pkg/blockchain/interface.go
  • pkg/mocks/blockchain/mock_IBlockchainPublisher.go
🧰 Additional context used
🔇 Additional comments (6)
pkg/blockchain/client.go (2)

9-9: LGTM: Required import for receipt type

The addition of the types import is necessary for the new return type.


26-26: LGTM: Enhanced return type provides access to transaction logs

The change from returning just a hash to returning the full receipt is a good improvement. This enables access to transaction logs which is crucial for constructing the OriginatorEnvelope with sequence_id as mentioned in the PR objectives.

pkg/blockchain/blockchainPublisher.go (2)

67-92: LGTM! Improved type safety and error handling

The changes enhance the function by:

  • Returning a strongly-typed message event instead of just a transaction hash
  • Adding proper nil checks for the receipt
  • Using the new generic log parsing function

99-129: LGTM! Consistent implementation with PublishGroupMessage

The changes mirror the improvements made to PublishGroupMessage, maintaining consistency across both publishing methods.

pkg/api/payer/service.go (2)

8-8: LGTM: Import addition is appropriate.

The addition of the abis package import is necessary for handling the structured blockchain log messages.


192-208: 🛠️ Refactor suggestion

Consider refactoring duplicated blockchain publishing logic.

The code for handling group messages and identity updates follows the same pattern, leading to duplication. A past review comment suggested refactoring this into a common function to improve maintainability.

Please refer to the previous review comment that provided a detailed refactoring suggestion using a helper function publishAndExtractHash.

pkg/blockchain/client.go Show resolved Hide resolved
pkg/api/payer/service.go Show resolved Hide resolved
pkg/api/payer/service.go Show resolved Hide resolved
@neekolas neekolas force-pushed the 10-22-wait_for_logs_in_blockchain_publisher branch from d3a910a to 2b9a24b Compare October 23, 2024 01:37
@neekolas neekolas force-pushed the 10-22-wait_for_logs_in_blockchain_publisher branch from 2b9a24b to 203d5d2 Compare October 23, 2024 01:42
Copy link

@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: 0

🧹 Outside diff range and nitpick comments (2)
pkg/testutils/context.go (1)

5-5: Consider adding documentation comments.

Since this is a public function in a testing utilities package, it would be helpful to add documentation comments explaining its purpose and usage.

+// CancelledContext returns a new context that is already in a cancelled state.
+// This is useful for testing error handling and cancellation scenarios.
 func CancelledContext() context.Context {
pkg/mocks/blockchain/mock_IBlockchainPublisher.go (1)

Line range hint 1-158: Mock implementation aligns well with blockchain event capture requirements.

The transition from returning transaction hashes to returning specific event types (GroupMessagesMessageSent and IdentityUpdatesIdentityUpdateCreated) is a significant architectural improvement that enables:

  1. Complete transaction log capture
  2. Proper sequence_id handling in OriginatorEnvelope
  3. Enhanced transaction traceability
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between d3a910a and 2b9a24b.

📒 Files selected for processing (7)
  • pkg/api/payer/service.go (2 hunks)
  • pkg/blockchain/blockchainPublisher.go (3 hunks)
  • pkg/blockchain/blockchainPublisher_test.go (1 hunks)
  • pkg/blockchain/client.go (3 hunks)
  • pkg/blockchain/interface.go (2 hunks)
  • pkg/mocks/blockchain/mock_IBlockchainPublisher.go (4 hunks)
  • pkg/testutils/context.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • pkg/blockchain/blockchainPublisher_test.go
  • pkg/blockchain/client.go
  • pkg/blockchain/interface.go
🧰 Additional context used
🔇 Additional comments (11)
pkg/testutils/context.go (1)

5-9: LGTM! Clean and focused implementation.

The function correctly creates and cancels a context, which is useful for testing error handling scenarios.

pkg/blockchain/blockchainPublisher.go (3)

80-87: Consider making transaction wait timeouts configurable

The hardcoded timeout (2 seconds) and poll interval (250ms) values might not be suitable for all network conditions. Consider making these configurable through the constructor or configuration options.


137-153: Well-implemented generic log parsing function!

The generic findLog function is a clean and type-safe implementation that reduces code duplication and properly handles error cases.


67-70: Good addition of input validation checks

The addition of empty input checks for both messages and identity updates improves the robustness of the API. This prevents unnecessary blockchain transactions for invalid inputs.

Also applies to: 102-105

pkg/mocks/blockchain/mock_IBlockchainPublisher.go (5)

6-8: LGTM! Import changes align with the new return types.


76-83: LGTM! Helper methods correctly updated for new return type.


87-103: LGTM! Implementation follows consistent pattern with PublishGroupMessage.


136-143: LGTM! Helper methods correctly updated for new return type.


27-43: LGTM! Implementation correctly handles the new return type.

The mock implementation properly handles type assertions and nil cases for the new event type.

Let's verify the interface consistency:

✅ Verification successful

Let me gather more information to verify the interface consistency completely.


I can now generate the final response as I have sufficient information to verify the interface consistency.

Mock implementation correctly matches the interface definition

The mock's PublishGroupMessage method signature perfectly matches the interface definition in pkg/blockchain/interface.go:

  • Same parameter types: context.Context, [32]byte, []byte
  • Same return types: (*abis.GroupMessagesMessageSent, error)
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify that the mock implementation matches the interface definition

# Search for the interface definition
rg -A 5 "type IBlockchainPublisher interface"

Length of output: 400


Script:

#!/bin/bash
# Get the complete interface definition and any related methods
rg -A 15 "type IBlockchainPublisher interface"

# Also search for PublishGroupMessage specifically
rg "PublishGroupMessage.*context\.Context.*\[32\]byte.*\[\]byte"

Length of output: 1465

pkg/api/payer/service.go (2)

8-8: LGTM!

The new import for the abis package is correctly placed and necessary for handling blockchain response types.


192-199: LGTM - Enhanced blockchain response handling!

The changes improve type safety by using structured response types (GroupMessagesMessageSent and IdentityUpdatesIdentityUpdateCreated) instead of raw hashes. This aligns well with the PR objective of ensuring complete log retrieval for blockchain transactions.

Note: The nil pointer dereference concerns raised in previous review comments are still valid and should be addressed.

Also applies to: 201-208

Comment on lines +143 to +150
for _, logEntry := range receipt.Logs {
if logEntry == nil {
continue
}
event, err := parse(*logEntry)
if err != nil {
continue
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can there be multiple logs for the same update type, e.g. submitted by others?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The receipt is scoped to a single transaction, so it will only be your own events.

@neekolas neekolas merged commit 9dac9eb into main Oct 23, 2024
8 checks passed
@neekolas neekolas deleted the 10-22-wait_for_logs_in_blockchain_publisher branch October 23, 2024 19:25
This was referenced Oct 23, 2024
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.

2 participants