Skip to content

Commit 7cc7b77

Browse files
committed
return snap header in export func
1 parent 3cde113 commit 7cc7b77

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

certstore/snapshot.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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

6969
type hashWriter struct {

certstore/snapshot_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func Test_SnapshotExportImportRoundTrip(t *testing.T) {
9191
}
9292

9393
snapshot := buffer.Buffer{}
94-
c, err := cs.ExportLatestSnapshot(ctx, &snapshot)
94+
c, _, err := cs.ExportLatestSnapshot(ctx, &snapshot)
9595
require.NoError(t, err)
9696
require.NotEqual(t, c, cid.Undef)
9797
require.Equal(t, int(c.Prefix().Version), 1)

0 commit comments

Comments
 (0)