Skip to content

Conversation

anjor
Copy link
Collaborator

@anjor anjor commented Jul 24, 2025

Summary

  • Adds comprehensive CLI commands for state management: singularity state list/get/stats/repair
  • Implements CSV/JSON export functionality with automatic timestamps
  • Provides manual recovery/repair operations with dry-run mode and audit logging
  • Supports advanced filtering by deal ID, state, provider, client, and time range

Changes

  • New CLI Commands: Complete state management suite under singularity state
  • Export System: Pluggable CSV/JSON export with custom output paths
  • Recovery Operations: Manual state repair with safety features
  • Comprehensive Testing: Unit tests and integration validation
  • Documentation: Complete user guide with examples and use cases

Test Plan

  • All new CLI commands build and execute successfully
  • Export functionality tested with both CSV and JSON formats
  • Recovery operations validated with dry-run mode
  • Integration with existing state tracking services verified

Resolves #573

anjor added 14 commits July 24, 2025 09:55
…ion-programs#572

Enhanced DealTracker and StateTracker integration with comprehensive on-chain event handling:

**StateTracker Enhancements:**
- Added enhanced metadata tracking with error categorization
- Improved error handling with specific error categories (network, provider, client, chain, etc.)
- Extended metadata fields for comprehensive deal tracking
- Added helper functions for error categorization and metadata creation
- Implemented TrackStateChangeWithError for better error tracking

**DealTracker Enhancements:**
- Enhanced state change tracking with detailed metadata for all deal transitions
- Added special handling for critical deal events (slashed, expired, activated)
- Improved logging for deal state transitions with contextual information
- Enhanced expiration handling for both active deals and proposals
- Better tracking of external deal discovery with comprehensive metadata

**Special Handling for Critical Events:**
- Deal slashing: Enhanced logging and metadata with slashing epoch details
- Deal expiration: Detailed tracking of natural expiration with epoch information
- Proposal expiration: Comprehensive handling of unactivated proposals
- Deal activation: Proper tracking with sector start epoch information

**Comprehensive Testing:**
- Added 296+ lines of new unit and integration tests
- Enhanced test coverage for error categorization and metadata creation
- Integration tests for slashed deal detection and handling
- Tests for external deal discovery with enhanced metadata
- Comprehensive expiration testing for deals and proposals

**Key Features:**
- Error categorization system for better analytics and debugging
- Enhanced metadata collection including piece size, verified status, pricing
- Improved recovery mechanisms for missing state changes
- Better performance monitoring and error tracking
- Comprehensive logging for all deal lifecycle events

All tests pass and the implementation maintains backward compatibility while significantly enhancing the deal tracking capabilities.
- Add comprehensive CLI commands: singularity state list/get/stats/repair
- Implement CSV/JSON export functionality with timestamps
- Add manual recovery/repair operations with dry-run mode
- Support filtering by deal ID, state, provider, client, and time range
- Add comprehensive unit and integration tests
- Include complete documentation and user guide
- Implement safety features with audit logging for all operations

Addresses data-preservation-programs#573
- Resolved conflict in service/statetracker/statetracker.go by keeping the cleaned up struct definition with basic fields properly organized under their respective comment sections
- Removed the PieceCID mapping logic to match develop branch
- Maintained the proper struct organization without duplicate fields
The mapping logic from PieceCID to ProposalID was lost during the recent merge
with origin/develop. This fixes the TestCreateErrorMetadata test failure by
restoring the compatibility mapping that was implemented in commit b640cb2.

- Add mapping from PieceCID to ProposalID when ProposalID is empty
- Add mapping from PieceCID to PublishCID for test compatibility
- Fixes TestCreateErrorMetadata test failure
Copy link
Contributor

@lanzafame lanzafame left a comment

Choose a reason for hiding this comment

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

@anjor this a draft pr... Can we get this to a level worth reviewing please? Documentation written and in the correct place, and unit and integration tests written. Also make sure remove any ai slop.

@anjor anjor requested a review from Sankara-Jefferson July 30, 2025 11:39
@Sankara-Jefferson
Copy link
Collaborator

@anjor — I'll review it first thing in the morning. I got sidetracked with some UI deployment work.

Copy link
Collaborator

@Sankara-Jefferson Sankara-Jefferson left a comment

Choose a reason for hiding this comment

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

Can we consider moving the state command (and its subcommands) under the existing deal command group?

singularity deal state list
singularity deal state get <deal-id>
singularity deal state repair ...

@anjor
Copy link
Collaborator Author

anjor commented Jul 31, 2025

@Sankara-Jefferson is this what you had in mind?

@Sankara-Jefferson
Copy link
Collaborator

I can no longer see it:

jeffersonsankara@Jeffersons-MacBook-Pro singularity % ./singularity -h     
2025-07-31T12:41:03.700-0700	INFO	auto-deal	dataprep/autodeal.go:44	Auto-deal service initialized
NAME:
   singularity - A tool for large-scale clients with PB-scale data onboarding to Filecoin network

USAGE:
   singularity [global options] command [command options]

DESCRIPTION:
   Database Backend Support:
     Singularity supports multiple database backend: sqlite3, postgres, mysql5.7+
     Use '--database-connection-string' or $DATABASE_CONNECTION_STRING to specify the database connection string.
       Example for postgres  - postgres://user:[email protected]:5432/dbname
       Example for mysql     - mysql://user:pass@tcp(localhost:3306)/dbname?parseTime=true
       Example for sqlite3   - sqlite:/absolute/path/to/database.db
                   or        - sqlite:relative/path/to/database.db

   Network Support:
     Default settings in Singularity are for Mainnet. You may set below environment values for other network:
       For Calibration network:
         * Set LOTUS_API to https://api.calibration.node.glif.io/rpc/v1
         * Set MARKET_DEAL_URL to https://marketdeals-calibration.s3.amazonaws.com/StateMarketDeals.json.zst
         * Set LOTUS_TEST to 1
       For all other networks:
         * Set LOTUS_API to your network's Lotus API endpoint
         * Set MARKET_DEAL_URL to empty string
         * Set LOTUS_TEST to 0 or 1 based on whether the network address starts with 'f' or 't'
       Switching between different networks with the same database instance is not recommended.

   Logging:
     Singularity uses go-log for logging and can be controlled by below environment variables:
       * GOLOG_LOG_LEVEL  - example values: debug, info, warn, error, dpanic, panic, fatal
       * GOLOG_LOG_FMT    - example values: color, nocolor, json
       * More details can be found at https://github.com/ipfs/go-log

   Upgrading:
     Within each minor version upgrade, use "singularity admin init" to upgrade the database schema.
     For major version upgrade, please refer to the release notes for upgrade instructions.


COMMANDS:
   onboard     Complete data onboarding workflow (storage → preparation → scanning → deal creation)
   version, v  Print version information
   help, h     Shows a list of commands or help for one command
   Daemons:
     run  run different singularity components
   Operations:
     admin                        Admin commands
     deal                         Replication / Deal making management
     deal-schedule-template, dst  Deal schedule template management
     wallet                       Wallet management
     storage                      Create and manage storage system connections
     prep                         Create and manage dataset preparations
     error                        Error log management
   Utility:
     ez-prep      Prepare a dataset from a local path
     download     Download a CAR file from the metadata API
     extract-car  Extract folders or files from a folder of CAR files to a local directory

GLOBAL OPTIONS:
   --database-connection-string value  Connection string to the database (default: sqlite:./singularity.db) [$DATABASE_CONNECTION_STRING]
   --help, -h                          show help
   --json                              Enable JSON output (default: false)
   --verbose                           Enable verbose output. This will print more columns for the result as well as full error trace (default: false)

   Lotus

   --lotus-api value    Lotus RPC API endpoint (default: "https://api.node.glif.io/rpc/v1") [$LOTUS_API]
   --lotus-test         Whether the runtime environment is using Testnet. (default: false) [$LOTUS_TEST]
   --lotus-token value  Lotus RPC API token [$LOTUS_TOKEN]

jeffersonsankara@Jeffersons-MacBook-Pro singularity % 

jeffersonsankara@Jeffersons-MacBook-Pro singularity % ./singularity deal -h
2025-07-31T12:42:30.115-0700	INFO	auto-deal	dataprep/autodeal.go:44	Auto-deal service initialized
NAME:
   singularity deal - Replication / Deal making management

USAGE:
   singularity deal command [command options] [arguments...]

COMMANDS:
   schedule     Schedule deals
   send-manual  Send a manual deal proposal to boost or legacy market
   list         List all deals
   help, h      Shows a list of commands or help for one command

OPTIONS:
   --help, -h  show help
jeffersonsankara@Jeffersons-MacBook-Pro singularity % 

@anjor
Copy link
Collaborator Author

anjor commented Jul 31, 2025

@Sankara-Jefferson it's under deal now as you suggested.

./singularity deal state -h
NAME:
   singularity deal state - Deal state management and monitoring

USAGE:
   singularity deal state command [command options] [arguments...]

DESCRIPTION:
   Comprehensive deal state management tools including:
   - View and filter deal state changes
   - Export state history to CSV/JSON
   - Manual recovery and repair operations
   - State change statistics and analytics

COMMANDS:
   list, ls  List deal state changes with optional filtering and pagination
   get       Get state changes for a specific deal
   stats     Get statistics about deal state changes
   repair    Manual recovery and repair commands for deal state management
   help, h   Shows a list of commands or help for one command

OPTIONS:
   --help, -h  show help

@Sankara-Jefferson
Copy link
Collaborator

@anjor yes, that works for me. It looks better. Thei is ready for merging, @ianconsolata.

Copy link
Collaborator

@ianconsolata ianconsolata left a comment

Choose a reason for hiding this comment

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

LGTM, only one minor change, and some questions. @lanzafame Can you do another review and let us know if @anjor has addressed all your concerns?

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.

CLI Commands for State Management
4 participants