@@ -23,47 +23,47 @@ var ErrUnknownLatestCertificate = errors.New("latest certificate is not known")
23
23
// ExportLatestSnapshot exports an F3 snapshot that includes the finality certificate chain until the current `latestCertificate`.
24
24
//
25
25
// Checkout the snapshot format specification at <https://github.com/filecoin-project/FIPs/blob/master/FRCs/frc-0108.md>
26
- func (cs * Store ) ExportLatestSnapshot (ctx context.Context , writer io.Writer ) (cid.Cid , error ) {
26
+ func (cs * Store ) ExportLatestSnapshot (ctx context.Context , writer io.Writer ) (cid.Cid , * SnapshotHeader , error ) {
27
27
if cs .latestCertificate == nil {
28
- return cid .Undef , ErrUnknownLatestCertificate
28
+ return cid .Undef , nil , ErrUnknownLatestCertificate
29
29
}
30
30
return cs .ExportSnapshot (ctx , cs .latestCertificate .GPBFTInstance , writer )
31
31
}
32
32
33
33
// ExportSnapshot exports an F3 snapshot that includes the finality certificate chain from the `Store.firstInstance` to the specified `lastInstance`.
34
34
//
35
35
// Checkout the snapshot format specification at <https://github.com/filecoin-project/FIPs/blob/master/FRCs/frc-0108.md>
36
- func (cs * Store ) ExportSnapshot (ctx context.Context , latestInstance uint64 , writer io.Writer ) (cid.Cid , error ) {
36
+ func (cs * Store ) ExportSnapshot (ctx context.Context , latestInstance uint64 , writer io.Writer ) (cid.Cid , * SnapshotHeader , error ) {
37
37
hasher , err := blake2b .New256 (nil )
38
38
if err != nil {
39
- return cid .Undef , err
39
+ return cid .Undef , nil , err
40
40
}
41
41
hashWriter := hashWriter {hasher , writer }
42
42
initialPowerTable , err := cs .GetPowerTable (ctx , cs .firstInstance )
43
43
if err != nil {
44
- return cid .Undef , fmt .Errorf ("failed to get initial power table at instance %d: %w" , cs .firstInstance , err )
44
+ return cid .Undef , nil , fmt .Errorf ("failed to get initial power table at instance %d: %w" , cs .firstInstance , err )
45
45
}
46
46
header := SnapshotHeader {1 , cs .firstInstance , latestInstance , initialPowerTable }
47
47
if _ , err := header .WriteTo (hashWriter ); err != nil {
48
- return cid .Undef , fmt .Errorf ("failed to write snapshot header: %w" , err )
48
+ return cid .Undef , nil , fmt .Errorf ("failed to write snapshot header: %w" , err )
49
49
}
50
50
for i := cs .firstInstance ; i <= latestInstance ; i ++ {
51
51
cert , err := cs .ds .Get (ctx , cs .keyForCert (i ))
52
52
if err != nil {
53
- return cid .Undef , fmt .Errorf ("failed to get certificate at instance %d:: %w" , i , err )
53
+ return cid .Undef , nil , fmt .Errorf ("failed to get certificate at instance %d:: %w" , i , err )
54
54
}
55
55
buffer := bytes .NewBuffer (cert )
56
56
if _ , err := writeSnapshotBlockBytes (hashWriter , buffer ); err != nil {
57
- return cid .Undef , err
57
+ return cid .Undef , nil , err
58
58
}
59
59
}
60
60
hash := hashWriter .hasher .Sum (nil )
61
61
mh , err := multihash .Encode (hash , multihash .BLAKE2B_MIN + 31 )
62
62
if err != nil {
63
- return cid .Undef , err
63
+ return cid .Undef , nil , err
64
64
}
65
65
66
- return cid .NewCidV1 (cid .Raw , mh ), nil
66
+ return cid .NewCidV1 (cid .Raw , mh ), & header , nil
67
67
}
68
68
69
69
type hashWriter struct {
0 commit comments