@@ -23,47 +23,47 @@ var ErrUnknownLatestCertificate = errors.New("latest certificate is not known")
2323// ExportLatestSnapshot exports an F3 snapshot that includes the finality certificate chain until the current `latestCertificate`.
2424//
2525// 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 ) {
2727 if cs .latestCertificate == nil {
28- return cid .Undef , ErrUnknownLatestCertificate
28+ return cid .Undef , nil , ErrUnknownLatestCertificate
2929 }
3030 return cs .ExportSnapshot (ctx , cs .latestCertificate .GPBFTInstance , writer )
3131}
3232
3333// ExportSnapshot exports an F3 snapshot that includes the finality certificate chain from the `Store.firstInstance` to the specified `lastInstance`.
3434//
3535// 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 ) {
3737 hasher , err := blake2b .New256 (nil )
3838 if err != nil {
39- return cid .Undef , err
39+ return cid .Undef , nil , err
4040 }
4141 hashWriter := hashWriter {hasher , writer }
4242 initialPowerTable , err := cs .GetPowerTable (ctx , cs .firstInstance )
4343 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 )
4545 }
4646 header := SnapshotHeader {1 , cs .firstInstance , latestInstance , initialPowerTable }
4747 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 )
4949 }
5050 for i := cs .firstInstance ; i <= latestInstance ; i ++ {
5151 cert , err := cs .ds .Get (ctx , cs .keyForCert (i ))
5252 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 )
5454 }
5555 buffer := bytes .NewBuffer (cert )
5656 if _ , err := writeSnapshotBlockBytes (hashWriter , buffer ); err != nil {
57- return cid .Undef , err
57+ return cid .Undef , nil , err
5858 }
5959 }
6060 hash := hashWriter .hasher .Sum (nil )
6161 mh , err := multihash .Encode (hash , multihash .BLAKE2B_MIN + 31 )
6262 if err != nil {
63- return cid .Undef , err
63+ return cid .Undef , nil , err
6464 }
6565
66- return cid .NewCidV1 (cid .Raw , mh ), nil
66+ return cid .NewCidV1 (cid .Raw , mh ), & header , nil
6767}
6868
6969type hashWriter struct {
0 commit comments