Skip to content

Commit 389ac96

Browse files
committed
Data structure and versioning cleanup
This is an attempt to build upon #1169 with the key differences being: 1. SnapshotMetadata contains a version rather than F3SnapshotHeader. 2. F3Data is a cbor-encoded structure.
1 parent ab861a1 commit 389ac96

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

FRCs/frc-f3-augmented-snapshot.md

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,42 +33,45 @@ The time cost and the network bandwidth usage for a new Filecoin node to catch u
3333
We propose the blow changes to the Filecoin CAR snapshot format.
3434

3535
- Change CAR roots to be a CID that points to a CBOR-encoded [`SnapshotMetadata`](#snapshotmetadata) struct that is stored as the first data block in the CAR.
36-
- Store the raw [`F3Snapshot`](#f3snapshot) bytes as the second data block in the CAR when `F3Data != nil` in the metadata.
36+
- Store the [`F3Data`](#f3data) structure as the second data block in the CAR when `F3Data != nil` in the metadata.
3737

3838
### SnapshotMetadata
3939

4040
```go
4141
type SnapshotMetadata {
42-
HeadTipsetKey []Cid // required
43-
F3Data *Cid // optional
42+
Version uint64 // required, format version for SnapshotMetadata
43+
// Only "2" is supported since "v1" was implied in the original format that predates `SnapshotMetadata`.
44+
HeadTipsetKey []Cid // required
45+
F3Data *Cid // optional, points to F3Data structure.
46+
// The only supported codec is "CBOR" (0x51).
4447
}
4548
```
4649

47-
### F3Snapshot
50+
### F3Data
4851

49-
An F3 snapshot contains one header block and N(N>0) data blocks in the below format:
52+
F3Data is a CBOR-encoded structure that contains the complete F3 snapshot data:
5053

51-
`[Header block] [Data block] [Data block] [Data block] ...`
52-
53-
A header block is a CBOR-encoded [`F3SnapshotHeader`](#f3snapshotheader) with a length prefix in the below format:
54+
```go
55+
type F3Data struct {
56+
Header F3SnapshotHeader
57+
Certificates []FinalityCertificate
58+
}
59+
```
5460

55-
`[varint-encoded length] [CBOR-encoded F3SnapshotHeader]`
61+
Notes:
62+
- `FinalityCertificate`s should be ordered by `GPBFTInstance` in ascending order for sequential validation
63+
- The first and last `FinalityCertificate` instances should match those in the header, respectively
5664

5765
### F3SnapshotHeader
5866

5967
```go
60-
type SnapshotHeader struct {
61-
Version uint64
68+
type F3SnapshotHeader struct {
6269
FirstInstance uint64
6370
LatestInstance uint64
6471
InitialPowerTable gpbft.PowerEntries
6572
}
6673
```
6774

68-
A data block is a CBOR-encoded [`FinalityCertificate`](#finalitycertificate) with a length prefix in the below format:
69-
70-
`[varint-encoded length] [CBOR-encoded FinalityCertificate]`
71-
7275
### FinalityCertificate
7376

7477
```go
@@ -92,9 +95,11 @@ type FinalityCertificate struct {
9295
}
9396
```
9497

95-
Notes:
96-
- `FinalityCertificate`s should be ordered by `GPBFTInstance` in ascending order, thus they can be validated and intermediate power tables can be generated while data blocks are being read in a stream.
97-
- The first and last `FinalityCertificate` instances should match those in the header, respectively.
98+
### Ability to upgrade
99+
100+
1. **SnapshotMetadata.Version**: Controls the overall snapshot format and structure. Any changes/additions to the underlying structures (e.g., F3Data) (including encoding changes) should include an accompanying version bump.
101+
2. **CID codec**: This will also change in encoding changes.
102+
98103

99104
## Backwards Compatibility
100105
<!--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.-->
@@ -112,7 +117,7 @@ Notes:
112117
This change has minimal security implications as the additional F3 data are also stored in the node database, unencrypted. Key considerations:
113118

114119
- **Integrity**: The F3 snapshot can be validated.
115-
- **Performance** The F3 snapshot data blocks can be read, validated and imported in a stream.
120+
- **Performance**: The F3Data structure can be validated efficiently as a single CBOR block.
116121

117122
The change does not introduce new attack vectors or modify existing security properties of the protocol.
118123

0 commit comments

Comments
 (0)