Skip to content

Conversation

@fbac
Copy link
Collaborator

@fbac fbac commented May 27, 2025

Closes #851

Summary by CodeRabbit

  • New Features
    • Added support for tracking and handling events from the "PayerReportManager" contract on the settlement chain.
    • Introduced new configuration options for specifying payer registry and payer report manager contract addresses, as well as a maximum allowed disconnect time.
  • Bug Fixes
    • Improved validation for new configuration fields to ensure correct contract addresses and disconnect time settings.
  • Tests
    • Added comprehensive tests for event handling and error scenarios related to the PayerReportManager contract.
  • Chores
    • Updated test utilities to include new contract addresses and configuration options.

@fbac fbac requested a review from a team as a code owner May 27, 2025 08:45
@coderabbitai
Copy link
Contributor

coderabbitai bot commented May 27, 2025

## Walkthrough

This change introduces support for indexing the "PayerReportManager" Ethereum contract. It adds configuration fields, contract wrappers, log storer logic, and validation for the new contract. The SettlementChain indexer is updated to initialize, track, and process events from the PayerReportManager, with associated tests and configuration updates.

## Changes

| File(s)                                                                                   | Change Summary                                                                                           |
|------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------|
| pkg/config/options.go, pkg/testutils/config.go                                            | Added new config fields for PayerRegistryAddress, PayerReportManagerAddress, MaxChainDisconnectTime.     |
| pkg/config/validation.go                                                                  | Added validation logic for new SettlementChain config fields.                                            |
| pkg/indexer/settlement_chain/contracts/payer_report_manager.go                            | Added contract wrapper for PayerReportManager, including initialization and accessor methods.            |
| pkg/indexer/settlement_chain/contracts/payer_report_manager_storer.go                     | Added log storer for PayerReportManager events, with event parsing and error handling.                   |
| pkg/indexer/settlement_chain/contracts/payer_report_manager_storer_test.go                | Added tests for PayerReportManagerStorer covering error and event handling.                              |
| pkg/indexer/settlement_chain/settlement_chain.go                                         | Updated SettlementChain to manage, initialize, and start indexing for PayerReportManager.                |
| pkg/indexer/app_chain/app_chain.go, pkg/blockchain/rpcLogStreamer.go                      | Updated logger usage and RpcLogStreamer signature (removed chainID parameter, logger context change).    |

## Sequence Diagram(s)

```mermaid
sequenceDiagram
    participant Config as Config
    participant SC as SettlementChain
    participant PRM as PayerReportManager
    participant RLS as RpcLogStreamer
    participant DB as Database

    Config->>SC: Provide PayerReportManagerAddress, MaxChainDisconnectTime
    SC->>PRM: Initialize contract wrapper with address
    SC->>RLS: Register PRM contract address, topics, disconnect time
    SC->>PRM: Retrieve latest block number
    SC->>RLS: Start log streaming for PRM
    RLS->>PRM: Emit event logs
    PRM->>DB: Store processed event logs

Assessment against linked issues

Objective Addressed Explanation
Add PayerReportManager contract indexing support (#851)
Add configuration and validation for PayerReportManager contract (#851)
Implement event log storer and tests for PayerReportManager (#851)
Update SettlementChain to manage and index PayerReportManager (#851)

Possibly related PRs

Suggested reviewers

  • mkysel

<!-- walkthrough_end -->
<!-- This is an auto-generated comment: all tool run failures by coderabbit.ai -->

> [!WARNING]
> There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.
> 
> <details>
> <summary>🔧 golangci-lint (1.64.8)</summary>
> 
> Error: you are using a configuration file for golangci-lint v2 with golangci-lint v1: please use golangci-lint v2
> Failed executing command with error: you are using a configuration file for golangci-lint v2 with golangci-lint v1: please use golangci-lint v2
> 
> 
> 
> </details>

<!-- end of auto-generated comment: all tool run failures by coderabbit.ai -->


---

<details>
<summary>📜 Recent review details</summary>

**Configuration used: CodeRabbit UI**
**Review profile: CHILL**
**Plan: Pro**


<details>
<summary>📥 Commits</summary>

Reviewing files that changed from the base of the PR and between 8162d957ba8e15063653bb7b5183b6c498599c62 and a51441d5e64235a53c91d3eab0f466cdfc9980fb.

</details>

<details>
<summary>📒 Files selected for processing (4)</summary>

* `pkg/blockchain/rpcLogStreamer.go` (1 hunks)
* `pkg/blockchain/rpcLogStreamer_test.go` (0 hunks)
* `pkg/indexer/app_chain/app_chain.go` (1 hunks)
* `pkg/indexer/settlement_chain/settlement_chain.go` (6 hunks)

</details>

<details>
<summary>💤 Files with no reviewable changes (1)</summary>

* pkg/blockchain/rpcLogStreamer_test.go

</details>

<details>
<summary>🚧 Files skipped from review as they are similar to previous changes (3)</summary>

* pkg/indexer/app_chain/app_chain.go
* pkg/blockchain/rpcLogStreamer.go
* pkg/indexer/settlement_chain/settlement_chain.go

</details>

<details>
<summary>⏰ Context from checks skipped due to timeout of 90000ms (5)</summary>

* GitHub Check: Push Docker Images to GitHub Packages (xmtpd-cli)
* GitHub Check: Push Docker Images to GitHub Packages (xmtpd)
* GitHub Check: Test (Node)
* GitHub Check: Upgrade Tests
* GitHub Check: Code Review

</details>

</details>
<!-- internal state start -->


<!-- DwQgtGAEAqAWCWBnSTIEMB26CuAXA9mAOYCmGJATmriQCaQDG+Ats2bgFyQAOFk+AIwBWJBrngA3EsgEBPRvlqU0AgfFwA6NPEgQAfACgjoCEYDEZyAAUASpETZWaCrKNwSPbABsvkCiQBHbGlcSHFcLzpIACIrNFlKSBsSbnwKUIBZTDRSPngMJQAPfKJoyAB3NGQHAWZ1Gno5MNgPbEREgDMBNAZ0ApRkeCUMcQ74KKrIDEcBRIAOAFYAJhQsXBa/FPxEdTTZDRgN2wHIL3yAayiCZo8kBw8zRYBGPvptZmRrhi9t29DsVJYNgUIglA4AOXw6FotHU8HwGDQviUiAYFHg3HECP4fCUuG0XmQKnweBujFgmFIyGYaCUqzJ3G8vn8QRC6H8PAo+AkQyis1kCPo6w8/g6lDIDA8Xx+OwwRDJ/i81Cid2CB3c1jsDEwkFmmx5JHKE1CwsgAFUbAAZLiwXC4biIDgAeidoPW2AEGiYzCdhWY9t9/u4tCdjJ8TsWSw0Rn0xnAUDI9HwHRwBGIZGUDQUrHYXF4/GEonEUhk8iYSioqnUWh0sZMUDgqFQOrQeEIpHIVCz3rYIy4VHK9kcNJcurLimUVc02l0YEMcdMBm45yITqYGDGq/wmPhGEQGiI+A4Bmip4MFkgAEEAJLpzvK+gOJyj5PkynSNwbAAGAGUSHbIl7XAAGEKXyAB5HcEUQL97FwChsDECpJhIQoaAKKJynUWBmn8DxyEHMYSC8WhHUgL84gSChklBRB4NkS8YX8RAYMgAAKOj0TlABKAAacjKMoZJUnSLJEVyRjaGY1iOPgko+Neci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HU4rBfREAdAPGM06acngtAE0VpyWCmiFgHo80SqMLGmiNkAgYnh0E07qdkxtADoAwDVFzB6x0nWMKKOVHijEiUomUeMDlGJhFRQAA== -->

<!-- internal state end -->
<!-- finishing_touch_checkbox_start -->

<details open="true">
<summary>✨ Finishing Touches</summary>

- [ ] <!-- {"checkboxId": "7962f53c-55bc-4827-bfbf-6a18da830691"} --> 📝 Generate Docstrings

</details>

<!-- finishing_touch_checkbox_end -->
<!-- tips_start -->

---

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

<details>
<summary>❤️ Share</summary>

- [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai)
- [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai)
- [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai)
- [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)

</details>

<details>
<summary>🪧 Tips</summary>

### Chat

There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=xmtp/xmtpd&utm_content=852):

- 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](https://www.coderabbit.ai/contact-us/support) 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](https://docs.coderabbit.ai/finishing-touches/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.

### 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](https://docs.coderabbit.ai/guides/configure-coderabbit) 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](https://docs.coderabbit.ai) for detailed information on how to use CodeRabbit.
- Join our [Discord Community](http://discord.gg/coderabbit) to get help, request features, and share feedback.
- Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.

</details>

<!-- tips_end -->

@graphite-app
Copy link

graphite-app bot commented May 27, 2025

How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • Queue - adds this PR to the back of the merge queue
  • Hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

@fbac fbac changed the base branch from main to 05-25-settlement_chain May 27, 2025 08:45
@macroscopeapp
Copy link

macroscopeapp bot commented May 27, 2025

Add settlement chain indexing for Payer Registry and Payer Report Manager contracts with 300s maximum chain disconnect time

Adds settlement chain monitoring capabilities to the indexer by creating new contract interfaces for PayerRegistry and PayerReportManager smart contracts. The changes include:

• New settlement chain configuration fields in options.go for contract addresses and a 300s maximum disconnect time
SettlementChain component in settlement_chain.go that coordinates blockchain monitoring
• Contract implementations for PayerRegistry in payer_registry.go and PayerReportManager in payer_report_manager.go
• Event storage handlers for processing contract events like Deposit, WithdrawalRequested, PayerReportSubmitted, and PayerReportSubsetSettled
• Integration of settlement chain monitoring into the main Indexer component in indexer.go

📍Where to Start

Start with the NewIndexer function in indexer.go to see how the settlement chain component is integrated into the main indexer.


Macroscope summarized 99549bb.

@macroscopeapp
Copy link

macroscopeapp bot commented May 27, 2025

Add PayerReportManager contract indexing to SettlementChain with configuration support and remove chainID parameter from RpcLogStreamer

This PR adds support for indexing the PayerReportManager contract within the SettlementChain implementation. The changes include:

• Add new PayerReportManager contract implementation in payer_report_manager.go that tracks PayerReportSubmitted and PayerReportSubsetSettled events
• Add PayerReportManagerStorer in payer_report_manager_storer.go that processes contract events (currently only logs without database storage)
• Update settlement_chain.go to initialize PayerReportManager contract and start a dedicated goroutine for log indexing
• Add PayerReportManagerAddress configuration field to SettlementChainOptions in options.go with validation in validation.go
• Remove chainID parameter from NewRpcLogStreamer function signature in rpcLogStreamer.go and update all callers

📍Where to Start

Start with the NewSettlementChain function in settlement_chain.go to see how the PayerReportManager contract is initialized and integrated into the settlement chain indexing process.


Macroscope summarized a51441d.

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.

Caution

Inline review comments failed to post. This is likely due to GitHub's limits when posting large numbers of comments. If you are seeing this consistently it is likely a permissions issue. Please check "Moderation" -> "Code review limits" under your organization settings.

Actionable comments posted: 2

🧹 Nitpick comments (4)
pkg/indexer/settlement_chain/settlement_chain.go (1)

20-23: Track the TODO for rpc log streamer changes.

The TODO comment indicates this is temporary code. Consider tracking this in an issue to ensure it's addressed when the rpc log streamer changes are introduced.

Do you want me to open a new issue to track this TODO?

pkg/indexer/settlement_chain/contracts/payer_report_manager.go (1)

18-21: Use plural form for slice variable name.

The variable contains multiple topics, so it should use the plural form for clarity.

Apply this diff:

-var payerReportManagerTopic = []string{
+var payerReportManagerTopics = []string{
 	"PayerReportSubmitted",
 	"PayerReportSubsetSettled",
 }

Also update the usage at line 113:

-	topics := make([]common.Hash, len(payerReportManagerTopic))
-	for i, topic := range payerReportManagerTopic {
+	topics := make([]common.Hash, len(payerReportManagerTopics))
+	for i, topic := range payerReportManagerTopics {
pkg/indexer/settlement_chain/contracts/payer_registry.go (2)

18-23: Fix variable naming for consistency.

The variable name should be plural since it contains multiple topic names.

-var payerRegistryTopic = []string{
+var payerRegistryTopics = []string{

Don't forget to update the reference in line 116:

-	for i, topic := range payerRegistryTopic {
+	for i, topic := range payerRegistryTopics {

83-93: Fix receiver naming to avoid confusion.

The receiver name pr conflicts with the imported package alias pr from line 9, which can cause confusion.

-func (pr *PayerRegistry) Address() common.Address {
-	return pr.address
+func (p *PayerRegistry) Address() common.Address {
+	return p.address
 }

-func (pr *PayerRegistry) Topics() []common.Hash {
-	return pr.topics
+func (p *PayerRegistry) Topics() []common.Hash {
+	return p.topics
 }

-func (pr *PayerRegistry) Logger() *zap.Logger {
-	return pr.logger
+func (p *PayerRegistry) Logger() *zap.Logger {
+	return p.logger
 }
🛑 Comments failed to post (2)
pkg/indexer/settlement_chain/settlement_chain.go (2)

65-85: ⚠️ Potential issue

Incomplete resource cleanup on initialization failure.

When NewPayerReportManager fails, the payerRegistry resource is not cleaned up. This could lead to resource leaks.

Apply this diff to ensure proper cleanup:

 	payerReportManager, err := contracts.NewPayerReportManager(
 		ctxwc,
 		client,
 		querier,
 		chainLogger,
 		common.HexToAddress(cfg.PayerReportManagerAddress),
 		cfg.ChainID,
 	)
 	if err != nil {
 		cancel()
 		client.Close()
+		// Add any necessary cleanup for payerRegistry if it has resources
 		return nil, err
 	}
📝 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.

    payerReportManager, err := contracts.NewPayerReportManager(
        ctxwc,
        client,
        querier,
        chainLogger,
        common.HexToAddress(cfg.PayerReportManagerAddress),
        cfg.ChainID,
    )
    if err != nil {
        cancel()
        client.Close()
        // Add any necessary cleanup for payerRegistry if it has resources
        return nil, err
    }
🤖 Prompt for AI Agents
In pkg/indexer/settlement_chain/settlement_chain.go between lines 65 and 85,
when NewPayerReportManager returns an error, the payerRegistry resource is not
being closed, causing a potential resource leak. To fix this, add a call to
payerRegistry.Close() before cancel() and client.Close() in the error handling
block after NewPayerReportManager fails, ensuring all allocated resources are
properly cleaned up on initialization failure.

120-129: ⚠️ Potential issue

Missing payerReportManager field assignment.

The payerReportManager field is not assigned in the struct initialization, which will cause nil pointer issues when accessed.

Apply this diff to fix the missing assignment:

 	return &SettlementChain{
-		ctx:           ctxwc,
-		cancel:        cancel,
-		client:        client,
-		log:           chainLogger,
-		streamer:      streamer,
-		chainID:       cfg.ChainID,
-		payerRegistry: payerRegistry,
+		ctx:                ctxwc,
+		cancel:             cancel,
+		client:             client,
+		log:                chainLogger,
+		streamer:           streamer,
+		chainID:            cfg.ChainID,
+		payerRegistry:      payerRegistry,
+		payerReportManager: payerReportManager,
 	}, nil
🤖 Prompt for AI Agents
In pkg/indexer/settlement_chain/settlement_chain.go around lines 120 to 129, the
SettlementChain struct initialization is missing the assignment for the
payerReportManager field. To fix this, add the payerReportManager field with the
appropriate variable or value during the struct initialization to prevent nil
pointer dereference errors when this field is accessed later.

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: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 99549bb and 8162d95.

📒 Files selected for processing (3)
  • pkg/blockchain/rpcLogStreamer.go (1 hunks)
  • pkg/indexer/app_chain/app_chain.go (1 hunks)
  • pkg/indexer/settlement_chain/settlement_chain.go (6 hunks)
✅ Files skipped from review due to trivial changes (1)
  • pkg/indexer/app_chain/app_chain.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/indexer/settlement_chain/settlement_chain.go
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Test (Node)
  • GitHub Check: Upgrade Tests

@fbac fbac force-pushed the 05-27-payer_report_manager_indexing branch from 8162d95 to a51441d Compare May 27, 2025 14:30
IDENTITY_UPDATE_BROADCAST_ADDRESS = "0xDCbC334a97c6a8DBe7d673bd52fA56718708BC9C"
PARAMETER_REGISTRY_ADDRESS = "0x7FFc148AF5f00C56D78Bce732fC79a08007eC8be"
PAYER_REGISTRY_ADDRESS = "0x6ADCc064469C3b69ED6Fa4DbeFA21490FD200D7c"
PAYER_REPORT_MANAGER_ADDRESS = "0x2aA7BC557FF0b9B55FFD82274706DD2aD37E687B"
Copy link
Collaborator

Choose a reason for hiding this comment

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

do we already have this in local.env?

@fbac fbac merged commit 4a5ec24 into 05-25-settlement_chain May 28, 2025
10 checks passed
@fbac fbac deleted the 05-27-payer_report_manager_indexing branch May 28, 2025 10:30
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.

feat(indexer): PayerReportManager indexing

3 participants