Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@neekolas
Copy link
Contributor

@neekolas neekolas commented Sep 2, 2025

TL;DR

Refactored payer report status management and added functionality to clear unsettled usage when reports are settled.

What changed?

  • Added a new ClearUnsettledUsage SQL query to delete unsettled usage records for an originator up to a specific time
  • Added a FetchPayerReport query to retrieve a single payer report by ID
  • Replaced string manipulation in SQL queries with proper PostgreSQL array parameters using pq.Array
  • Simplified the report status management API by replacing generic status transition methods with specific, purpose-named methods:
    • SetReportSubmitted
    • SetReportSettled
    • SetReportAttestationApproved
    • SetReportAttestationRejected
  • Implemented the PayerReportSubsetSettled event handler to properly mark reports as settled and clear associated unsettled usage
  • Added comprehensive tests for the new settlement functionality

How to test?

  1. Create a payer report with unsettled usage
  2. Call SetReportSettled on the report
  3. Verify that:
    • The report status changes to SubmissionSettled
    • Unsettled usage records for that originator up to the report's end minute are cleared
    • Unsettled usage records after the end minute remain intact
    • Unsettled usage for other originators is not affected

Why make this change?

This change improves the settlement process by automatically clearing unsettled usage records once a report is settled on-chain. This prevents double-counting of usage in future reports and maintains data integrity. The refactored API also makes the code more maintainable by providing clear, purpose-specific methods for state transitions rather than generic methods that could be misused.

@neekolas neekolas mentioned this pull request Sep 2, 2025
Copy link
Contributor Author

neekolas commented Sep 2, 2025

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more


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.

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

@macroscopeapp
Copy link

macroscopeapp bot commented Sep 2, 2025

Implement settlement processing to update settlement flows by handling PayerReportSubsetSettled in contracts.PayerReportManagerStorer.StoreLog and deleting originator unsettled_usage rows in (prev_report_end_minute_since_epoch, end_minute_since_epoch] via queries.ClearUnsettledUsage

📍Where to Start

Start with the StoreLog handler in payer_report_manager_storer.go, then follow the call into payerreport.Store.SetReportSettled in store.go and the database deletion in queries.ClearUnsettledUsage in payerReports.sql and payerReports.sql.go.


Macroscope summarized e2bc145.

@neekolas neekolas force-pushed the 08-28-update_settlement_flows branch 2 times, most recently from adfa4a7 to 5a6cb7a Compare September 2, 2025 13:14
@neekolas neekolas changed the base branch from 08-06-settled_usage_ledger to graphite-base/1081 September 2, 2025 13:18
@neekolas neekolas force-pushed the 08-28-update_settlement_flows branch from 5a6cb7a to 6c57b83 Compare September 2, 2025 13:18
@neekolas neekolas changed the base branch from graphite-base/1081 to 09-02-upgrade_tools_dependencies September 2, 2025 13:19
@neekolas neekolas changed the base branch from 09-02-upgrade_tools_dependencies to graphite-base/1081 September 2, 2025 13:24
@neekolas neekolas force-pushed the 08-28-update_settlement_flows branch from 6c57b83 to a8812eb Compare September 2, 2025 13:24
@neekolas neekolas changed the base branch from graphite-base/1081 to 08-06-settled_usage_ledger September 2, 2025 13:24
@neekolas neekolas force-pushed the 08-28-update_settlement_flows branch from a8812eb to 435894f Compare September 2, 2025 13:28
@neekolas neekolas force-pushed the 08-06-settled_usage_ledger branch from 89d2900 to 70dbe40 Compare September 2, 2025 13:28
@neekolas neekolas force-pushed the 08-28-update_settlement_flows branch from 435894f to b28fced Compare September 2, 2025 13:37
@neekolas neekolas force-pushed the 08-06-settled_usage_ledger branch from 70dbe40 to 8e325f2 Compare September 2, 2025 13:37
@neekolas neekolas force-pushed the 08-28-update_settlement_flows branch from b28fced to 92de60f Compare September 2, 2025 14:05
@neekolas neekolas force-pushed the 08-06-settled_usage_ledger branch from 8e325f2 to 85d4ef5 Compare September 2, 2025 14:05
@neekolas neekolas force-pushed the 08-28-update_settlement_flows branch from 92de60f to e2bc145 Compare September 2, 2025 14:23
@neekolas neekolas marked this pull request as ready for review September 2, 2025 14:24
@neekolas neekolas requested a review from a team as a code owner September 2, 2025 14:24
@graphite-app
Copy link

graphite-app bot commented Sep 2, 2025

Merge activity

  • Sep 2, 7:14 PM UTC: neekolas added this pull request to the Graphite merge queue.
  • Sep 2, 7:14 PM UTC: CI is running for this pull request on a draft pull request (#1085) due to your merge queue CI optimization settings.
  • Sep 2, 7:22 PM UTC: Merged by the Graphite merge queue via draft PR: #1085.

graphite-app bot pushed a commit that referenced this pull request Sep 2, 2025
### TL;DR

Refactored payer report status management and added functionality to clear unsettled usage when reports are settled.

### What changed?

- Added a new `ClearUnsettledUsage` SQL query to delete unsettled usage records for an originator up to a specific time
- Added a `FetchPayerReport` query to retrieve a single payer report by ID
- Replaced string manipulation in SQL queries with proper PostgreSQL array parameters using `pq.Array`
- Simplified the report status management API by replacing generic status transition methods with specific, purpose-named methods:
    - `SetReportSubmitted`
    - `SetReportSettled`
    - `SetReportAttestationApproved`
    - `SetReportAttestationRejected`
- Implemented the `PayerReportSubsetSettled` event handler to properly mark reports as settled and clear associated unsettled usage
- Added comprehensive tests for the new settlement functionality

### How to test?

1. Create a payer report with unsettled usage
2. Call `SetReportSettled` on the report
3. Verify that:
    - The report status changes to `SubmissionSettled`
    - Unsettled usage records for that originator up to the report's end minute are cleared
    - Unsettled usage records after the end minute remain intact
    - Unsettled usage for other originators is not affected

### Why make this change?

This change improves the settlement process by automatically clearing unsettled usage records once a report is settled on-chain. This prevents double-counting of usage in future reports and maintains data integrity. The refactored API also makes the code more maintainable by providing clear, purpose-specific methods for state transitions rather than generic methods that could be misused.
@graphite-app graphite-app bot closed this Sep 2, 2025
@graphite-app graphite-app bot deleted the 08-28-update_settlement_flows branch September 2, 2025 19:22
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