-
Notifications
You must be signed in to change notification settings - Fork 176
frc-0108: f3-augmented-snapshot #1169
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
Changes from 6 commits
ab861a1
02335e9
b537bb0
d730636
78614ae
7dac2e2
11a7291
412adf0
8db56b3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,245 @@ | ||||||||||||||||||||||
| --- | ||||||||||||||||||||||
| fip: "0108" | ||||||||||||||||||||||
| title: "Filecoin Snapshot Format" | ||||||||||||||||||||||
| author: "Hailong Mu (@hanabi1224)" | ||||||||||||||||||||||
| discussions-to: https://github.com/filecoin-project/go-f3/issues/480 | ||||||||||||||||||||||
| status: Draft | ||||||||||||||||||||||
| type: "FRC" | ||||||||||||||||||||||
| created: 2025-06-25 | ||||||||||||||||||||||
| --- | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # FRC-0108: Filecoin Snapshot Format | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ## Simple Summary | ||||||||||||||||||||||
| <!--"If you can't explain it simply, you don't understand it well enough." Provide a simplified and layman-accessible explanation of the FIP.--> | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| Downloading F3 finality certificates from scratch takes a long time and increases the p2p network bandwidth usage. | ||||||||||||||||||||||
| An F3 snapshot is proposed to be included in the Filecoin CAR snapshot to reduce F3 catchup time and p2p network bandwidth usage on bootstrapping | ||||||||||||||||||||||
| a Filecoin node with a Filecoin snapshot. | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ## Abstract | ||||||||||||||||||||||
| <!--A short (~200 words) description of the technical issue being addressed.--> | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| The Filecoin ecosystem existed for years without specifying the snapshot format. That was fine until the advent of F3 and the resulting need to update the format in a coordinated way. | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| This document outlines: | ||||||||||||||||||||||
| - "v1": the original accepted format found implementations through 2025 and | ||||||||||||||||||||||
| - "v2": the extension to v1 with an F3 snapshot as a raw data block, and changing CAR roots to be a CID that points to a CBOR-encoded Filecoin snapshot header struct. | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ## Motivation | ||||||||||||||||||||||
| <!--The motivation is critical for FIPs that want to change the Filecoin protocol. It should clearly explain why the existing protocol specification is inadequate to address the problem that the FIP solves. FIP submissions without sufficient motivation may be rejected outright.--> | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| The time cost and the network bandwidth usage for a new Filecoin node to catch up with all F3 finality certificates grow over time, which delays the readiness of the F3-aware V2 RPC APIs. By embedding an F3 snapshot into the current Filecoin CAR snapshot, both can be vastly reduced at the cost of a slightly increased Filecoin CAR snapshot size. | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ## V1 Specification | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| We define the existing Filecoin snapshot format as v1 here for future reference. | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| Filecoin snapshot v1 is in [CARv1](https://ipld.io/specs/transport/car/carv1/) format. | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| The roots array in the `CarHeader` stores the tipset keys of the chain head in the snapshot. | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| The data blocks are chain IPLD blocks generated in a deterministic depth-first traversal order during chain export. Thus a snapshot is deterministic for a given chain head and the number of state trees to include. (The details of the chain traversal algorithm can be found in Filecoin node implementations.) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ```go | ||||||||||||||||||||||
| type CarHeader struct { | ||||||||||||||||||||||
| version Int | ||||||||||||||||||||||
| roots [&Any] | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| ``` | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ## V2 Specification | ||||||||||||||||||||||
| <!--The technical specification should describe the syntax and semantics of any new feature. The specification should be detailed enough to allow competing, interoperable implementations for any current Filecoin implementations. --> | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| We propose the below changes to the [V1 Filecoin CAR snapshot format](#v1-specification). | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| - Change CAR root to be a CID that points to a CBOR-encoded [`SnapshotMetadata`](#snapshotmetadata) struct that is stored as the first data block in the CAR. | ||||||||||||||||||||||
| - Store the raw [`F3Data`](#f3data) bytes as the second data block in the CAR when `F3Data != nil` in the metadata. | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ### SnapshotMetadata | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ```go | ||||||||||||||||||||||
| type SnapshotMetadata { | ||||||||||||||||||||||
| Version uint64 // required, format version for SnapshotMetadata. Only "2" is supported since "v1" was implied in the original format that predates `SnapshotMetadata`. | ||||||||||||||||||||||
| HeadTipsetKey []Cid // required | ||||||||||||||||||||||
| F3Data *Cid // optional, points to F3Data structure. The only supported codec is "RAW" (0x55). | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| ``` | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ### F3Data | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| An F3 snapshot contains one header block and N data blocks (where N>0) in the below [CARv1](https://ipld.io/specs/transport/car/carv1)-like format: | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| `[Header block] [Data block] [Data block] [Data block] ...` | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| A header block is a CBOR-encoded [`F3SnapshotHeader`](#f3snapshotheader) with a length prefix in the below format: | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| `[varint-encoded byte length of "CBOR-encoded F3SnapshotHeader"] [CBOR-encoded F3SnapshotHeader]` | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| A data block is a CBOR-encoded [`FinalityCertificate`](#finalitycertificate) with a length prefix in the below format: | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| `[varint-encoded byte length of "CBOR-encoded FinalityCertificate"] [CBOR-encoded FinalityCertificate]` | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| Notes: | ||||||||||||||||||||||
| - `FinalityCertificate`s should be ordered by `GPBFTInstance` in ascending order for sequential validation and intermediate power table calculation. This also ensures deterministic generation of F3 snapshot from a given F3 finality certificate chain. | ||||||||||||||||||||||
| - The first and last `FinalityCertificate` instances should match those in the [F3SnapshotHeader](#f3snapshotheader), respectively. | ||||||||||||||||||||||
| - This [CARv1](https://ipld.io/specs/transport/car/carv1)-like format is ideal for dumping blocks via streaming reads as the [F3SnapshotHeader](#f3snapshotheader) can be loaded first and minimal state is required for ongoing parsing. | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ### F3SnapshotHeader | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ```go | ||||||||||||||||||||||
| type F3SnapshotHeader struct { | ||||||||||||||||||||||
| Version uint64 | ||||||||||||||||||||||
| FirstInstance uint64 | ||||||||||||||||||||||
| LatestInstance uint64 | ||||||||||||||||||||||
| InitialPowerTable gpbft.PowerEntries | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| ``` | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ### FinalityCertificate | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ```go | ||||||||||||||||||||||
| // Defined at <https://github.com/filecoin-project/go-f3/blob/v0.8.7/certs/certs.go#L34> | ||||||||||||||||||||||
| // | ||||||||||||||||||||||
| // FinalityCertificate represents a single finalized GPBFT instance. | ||||||||||||||||||||||
| type FinalityCertificate struct { | ||||||||||||||||||||||
| // The GPBFT instance to which this finality certificate corresponds. | ||||||||||||||||||||||
| GPBFTInstance uint64 | ||||||||||||||||||||||
| // The ECChain finalized during this instance, starting with the last tipset finalized in | ||||||||||||||||||||||
| // the previous instance. | ||||||||||||||||||||||
| ECChain *gpbft.ECChain | ||||||||||||||||||||||
| // Additional data signed by the participants in this instance. Currently used to certify | ||||||||||||||||||||||
| // the power table used in the next instance. | ||||||||||||||||||||||
| SupplementalData gpbft.SupplementalData | ||||||||||||||||||||||
| // Indexes in the base power table of the certifiers (bitset) | ||||||||||||||||||||||
| Signers bitfield.BitField | ||||||||||||||||||||||
| // Aggregated signature of the certifiers | ||||||||||||||||||||||
| Signature []byte | ||||||||||||||||||||||
| // Changes between the power table used to validate this finality certificate and the power | ||||||||||||||||||||||
| // used to validate the next finality certificate. Sorted by ParticipantID, ascending. | ||||||||||||||||||||||
| PowerTableDelta PowerTableDiff `json:"PowerTableDelta,omitempty"` | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // Defined at <https://github.com/filecoin-project/go-f3/blob/v0.8.7/gpbft/chain.go#L194> | ||||||||||||||||||||||
| // | ||||||||||||||||||||||
| // A chain of tipsets comprising a base (the last finalised tipset from which the chain extends). | ||||||||||||||||||||||
| // and (possibly empty) suffix. | ||||||||||||||||||||||
| // Tipsets are assumed to be built contiguously on each other, | ||||||||||||||||||||||
| // though epochs may be missing due to null rounds. | ||||||||||||||||||||||
| // The zero value is not a valid chain, and represents a "bottom" value | ||||||||||||||||||||||
| // when used in a Granite message. | ||||||||||||||||||||||
| type ECChain struct { | ||||||||||||||||||||||
| TipSets []*TipSet | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| key ECChainKey `cborgen:"ignore"` | ||||||||||||||||||||||
| keyLazyLoader sync.Once `cborgen:"ignore"` | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // Defined at <https://github.com/filecoin-project/go-f3/blob/v0.8.7/gpbft/types.go#L123> | ||||||||||||||||||||||
| type SupplementalData struct { | ||||||||||||||||||||||
| // Commitments is the Merkle-tree of instance-specific commitments. Currently | ||||||||||||||||||||||
| // empty but this will eventually include things like snark-friendly power-table | ||||||||||||||||||||||
| // commitments. | ||||||||||||||||||||||
| Commitments [32]byte `cborgen:"maxlen=32"` | ||||||||||||||||||||||
| // PowerTable is the DagCBOR-blake2b256 CID of the power table used to validate | ||||||||||||||||||||||
| // the next instance, taking lookback into account. | ||||||||||||||||||||||
| PowerTable cid.Cid // []PowerEntry | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // Defined at <https://github.com/filecoin-project/go-f3/blob/v0.8.7/certs/certs.go#L31> | ||||||||||||||||||||||
| type PowerTableDiff []PowerTableDelta | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // Defined at <https://github.com/filecoin-project/go-f3/blob/v0.8.7/certs/certs.go#L16> | ||||||||||||||||||||||
| // | ||||||||||||||||||||||
| // PowerTableDelta represents a single power table change between GPBFT instances. If the resulting | ||||||||||||||||||||||
| // power is 0 after applying the delta, the participant is removed from the power table. | ||||||||||||||||||||||
| type PowerTableDelta struct { | ||||||||||||||||||||||
| // Participant with changed power | ||||||||||||||||||||||
| ParticipantID gpbft.ActorID | ||||||||||||||||||||||
| // Change in power from base (signed). | ||||||||||||||||||||||
| PowerDelta gpbft.StoragePower | ||||||||||||||||||||||
| // New signing key if relevant (else empty) | ||||||||||||||||||||||
| SigningKey gpbft.PubKey `cborgen:"maxlen=48"` | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // Defined at <https://github.com/filecoin-project/go-f3/blob/v0.8.7/gpbft/types.go#L15> | ||||||||||||||||||||||
| type ActorID uint64 | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // Defined at <https://github.com/filecoin-project/go-f3/blob/v0.8.7/gpbft/types.go#L17> | ||||||||||||||||||||||
| type StoragePower = big.Int | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // Defined at <https://github.com/filecoin-project/go-f3/blob/v0.8.7/gpbft/types.go#L19> | ||||||||||||||||||||||
| type PubKey []byte | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // Defined at <https://github.com/filecoin-project/go-f3/blob/v0.8.7/gpbft/chain.go#L52> | ||||||||||||||||||||||
| // | ||||||||||||||||||||||
| // TipSet represents a single EC tipset. | ||||||||||||||||||||||
| type TipSet struct { | ||||||||||||||||||||||
| // The EC epoch (strictly increasing). | ||||||||||||||||||||||
| Epoch int64 | ||||||||||||||||||||||
| // The tipset's key (canonically ordered concatenated block-header CIDs). | ||||||||||||||||||||||
| Key TipSetKey `cborgen:"maxlen=760"` // 20 * 38B | ||||||||||||||||||||||
| // Blake2b256-32 CID of the CBOR-encoded power table. | ||||||||||||||||||||||
| PowerTable cid.Cid | ||||||||||||||||||||||
| // Keccak256 root hash of the commitments merkle tree. | ||||||||||||||||||||||
| Commitments [32]byte `cborgen:"maxlen=32"` | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // Defined at <https://github.com/filecoin-project/go-f3/blob/v0.8.7/gpbft/chain.go#L20> | ||||||||||||||||||||||
| // | ||||||||||||||||||||||
| // TipSetKey is the canonically ordered concatenation of the block CIDs in a tipset. | ||||||||||||||||||||||
| type TipSetKey = []byte | ||||||||||||||||||||||
| ``` | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ## Backwards Compatibility | ||||||||||||||||||||||
| <!--All FIPs that introduce backwards incompatibilities must include a section describing these incompatibilities and their severity. The FIP must explain how the author proposes to deal with these incompatibilities. FIP submissions without a sufficient backwards compatibility treatise may be rejected outright.--> | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| - A Filecoin node should try to read a snapshot CAR in the [v2 format](#v2-specification). If there is a failure to successfully decode the block referenced as the CAR's single root using the schema presented above, a snapshot reader may fallback to the [v1 format](#v1-specification) and maintain backward compatibility. Additional failures to decode original snapshot format would indicate a fatal error. | ||||||||||||||||||||||
| - CLI options for implementations like Forest, Lotus and Venus should remain unchanged to make it transparent to the node users. | ||||||||||||||||||||||
| - The code change in all Filecoin nodes should be shipped with a network upgrade, and the Filecoin snapshot providers should only start publishing with the new format after the mainnet upgrade finishes to avoid potential errors during snapshot import for node users. That is to say: | ||||||||||||||||||||||
| - Before NV27, | ||||||||||||||||||||||
| - node implementations can read v1 snapshots for sure and v2 snapshot reading is being rolled out before the upgrade. | ||||||||||||||||||||||
| - node implementations generate v1 snapshots by default | ||||||||||||||||||||||
| - node implementation providers publish and host v1 snapshots | ||||||||||||||||||||||
| - After NV27, | ||||||||||||||||||||||
| - node implementations can read both v1 and v2 snapshots | ||||||||||||||||||||||
| - node implementations generate v2 snapshots by default | ||||||||||||||||||||||
| - node implementation providers publish and host v2 snapshots | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ## Test Cases | ||||||||||||||||||||||
| <!--Test cases for an implementation are mandatory for FIPs affecting consensus changes. Other FIPs can choose to include links to test cases if applicable.--> | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ## Security Considerations | ||||||||||||||||||||||
| <!--All FIPs must contain a section that discusses the security implications/considerations relevant to the proposed change. Include information that might be important for security discussions, surfaces risks and can be used throughout the life cycle of the proposal. E.g. include security-relevant design decisions, concerns, important discussions, implementation-specific guidance and pitfalls, an outline of threats and risks and how they are being addressed. FIP submissions missing the "Security Considerations" section will be rejected. A FIP cannot proceed to status "Final" without a Security Considerations discussion deemed sufficient by the reviewers.--> | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| This change has minimal security implications as the additional F3 data are also stored in the node database, unencrypted. Key considerations: | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| - **Integrity**: The F3 snapshot can be validated. | ||||||||||||||||||||||
| - **Performance** The F3 snapshot data blocks can be read, validated and imported in a stream, without requiring to hold the entire finality certificate chain in the RAM. To facilitate this, it might require some new API(s) in the CAR reader package. | ||||||||||||||||||||||
| - **Cyclic structure** Not applicable. The F3 snapshot does not build any cyclic graph during import and export, only a single block(certificate) is required to be held in the RAM. | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| The change does not introduce new attack vectors or modify existing security properties of the protocol. | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ## Incentive Considerations | ||||||||||||||||||||||
| <!--All FIPs must contain a section that discusses the incentive implications/considerations relative to the proposed change. Include information that might be important for incentive discussion. A discussion on how the proposed change will incentivize reliable and useful storage is required. FIP submissions missing the "Incentive Considerations" section will be rejected. An FIP cannot proceed to status "Final" without a Incentive Considerations discussion deemed sufficient by the reviewers.--> | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| Node users should experience faster F3 bootstrapping time and less network bandwidth usage. | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ## Product Considerations | ||||||||||||||||||||||
| <!--All FIPs must contain a section that discusses the product implications/considerations relative to the proposed change. Include information that might be important for product discussion. A discussion on how the proposed change will enable better storage-related goods and services to be developed on Filecoin. FIP submissions missing the "Product Considerations" section will be rejected. An FIP cannot proceed to status "Final" without a Product Considerations discussion deemed sufficient by the reviewers.--> | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| Nodes starting from a snapshot should not rely on the certificate exchange protocol to catch up with the F3 data because we expect this will get slower over time. A slow F3 catchup time leads to, e.g. | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| - delay in the readiness of F3-aware RPC APIs | ||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
See TODO in there, I don't know what size we're talking about here, do you have a rough guestimate to get us started? If it's too hard we could remove the specific reference but I wanted to provide a ballpark to point out how it's different to the max ~1MiB expectation that a lot of tools expect today. But also be clear that this isn't necessarily a bad thing, just bad expectations in existing software.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rvagg filled TODO with 100MiB. The current F3 db size on mainnet is ~100MiB in ~2 month. We do plan to extend the current CAR package with API that returns |
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ## Implementation | ||||||||||||||||||||||
| <!--The implementations must be completed before any core FIP is given status "Final", but it need not be completed before the FIP is accepted. While there is merit to the approach of reaching consensus on the specification and rationale before writing code, the principle of "rough consensus and running code" is still useful when it comes to resolving many discussions of API details.--> | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| - Lotus: https://github.com/filecoin-project/lotus/issues/13129 | ||||||||||||||||||||||
| - Forest: | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ## Future Work | ||||||||||||||||||||||
| <!--A section that lists any unresolved issues or tasks that are part of the FIP proposal. Examples of these include performing benchmarking to know gas fees, validate claims made in the FIP once the final implementation is ready, etc. A FIP can only move to a "Last Call" status once all these items have been resolved.--> | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| ## Copyright | ||||||||||||||||||||||
| Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/). | ||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.