flowchart LR
    subgraph Filecoin Snapshot Service
        subgraph Snapshot Generation
            A[Trigger Cron Job] --> B[Download Latest Filecoin Snapshot with aria2c]
            B --> C[Import Snapshot into Forest Node]
            C --> D[Start Forest Node & Install Utilities curl, aria2]
            D --> E[Sync Forest Node with Network Head]
            E --> F[Export Snapshot Including Last 2000 Blocks]
            F --> G[Run Initial Validation with forest-tool]
            G --> H[Stop Forest Node & Store Snapshot]
            H --> I[Destroy Forest DB to Save Space]
        end
        subgraph Snapshot Validation
            I --> J[Import Snapshot into Lotus Node]
            J --> K[Start Lotus Node & Install Utilities curl, jq]
            K --> L[Sync Lotus Node with Network Head]
            L --> M[Verify Lotus Node Sync Status]
            M --> N[Retrieve Head Epoch from Lotus Node using ChainHead RPC Method]
            N --> O[Calculate Adjusted Epoch: Head Epoch - 1950]
            O --> P[GET Block Hash from a remote Full Node using Adjusted Epoch with ChainGetTipSetByHeight]
            P --> Q[Verify Block Hash in Local Node using ChainGetBlock RPC Meethod]
        end
        Q --> T[Upload Validated Snapshot to Regular S3 Bucket]
        %% Failure Handling
        Q -- Validation Failure --> V[Move Snapshot to Forbidden Bucket]
        G -- Generation/Validation Failure --> V
        %% Notifications
        V --> W1[Send Alert to Team for Investigation]
        W1 --> W2[On-Call Team Investigates and Escalates]
    end

This document outlines the step-by-step process for generating and validating a Filecoin snapshot. The diagram above provides a quick overview of the snapshot service architecture.


Snapshot Service Process Overview

The snapshot process is initiated by a cron job that triggers the service container to execute hourly. Below is a detailed step-by-step outline of how snapshots are generated and validated:

  1. Download the Snapshot:
  2. Import Snapshot into Forest Node:
  3. Start the Forest Node:
  4. Export Snapshot:
  5. Forest Tool Validate the Exported Snapshot:
  6. Stop the Forest Node and Store the Snapshot:
  7. Import Snapshot into Lotus Node:
  8. Start the Lotus Node:
  9. Check Node Sync Status and Health:

Begin Main Validation

Important Note:

If any step in this process fails, an alert is sent to the team. The snapshot is then moved to a forbidden bucket for further investigation by the on-call team. If necessary, the issue is escalated for resolution.