Skip to content

feat: certstore snapshot export #1032

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

hanabi1224
Copy link
Contributor

This is a draft implementation of F3 snapshot export functionality in the format proposed in filecoin-project/FIPs#1169 to collect feedbacks

Copy link

codecov bot commented Jun 26, 2025

Codecov Report

Attention: Patch coverage is 0% with 44 lines in your changes missing coverage. Please review.

Project coverage is 65.17%. Comparing base (20d68df) to head (740fe1a).

Files with missing lines Patch % Lines
certstore/snapshot.go 0.00% 44 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1032      +/-   ##
==========================================
- Coverage   65.58%   65.17%   -0.41%     
==========================================
  Files          80       81       +1     
  Lines        9703     9747      +44     
==========================================
- Hits         6364     6353      -11     
- Misses       2847     2900      +53     
- Partials      492      494       +2     
Files with missing lines Coverage Δ
certstore/snapshot.go 0.00% <0.00%> (ø)

... and 5 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@BigLep BigLep moved this from Todo to In progress in F3 Jun 26, 2025
@BigLep BigLep requested a review from Kubuxu June 26, 2025 15:23
Copy link
Member

@masih masih left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to pin down high level abstractions more concretely. Left a bunch of suggestions and thank you for pushing this work forward 🍻


"github.com/filecoin-project/go-f3/gpbft"
"github.com/ipfs/go-datastore"
xerrors "golang.org/x/xerrors"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This repo avoids using xerrors in favour of standard Go SDK packages.

xerrors "golang.org/x/xerrors"
)

var ErrlatestCertificateNil = errors.New("latest certificate is not available")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use consistent CamelCasing (i.e. ErrLatestCertificateNil), or better yet follow the existing naming convention based on which I would name this error ErrUnknownLatestCertificate

Suggested change
var ErrlatestCertificateNil = errors.New("latest certificate is not available")
var ErrUnknownLatestCertificate = errors.New("latest certificate is not known")


var ErrlatestCertificateNil = errors.New("latest certificate is not available")

// Exports an F3 snapshot that includes the finality certificate chain until the current `latestCertificate`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By convention start godoc with the function name. Ditto in other places.

return cs.ExportSnapshot(ctx, cs.latestCertificate.GPBFTInstance, writer)
}

// Exports an F3 snapshot that includes the finality certificate chain until the specified `lastInstance`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clarify what the from instance is.

}

// Exports an F3 snapshot that includes the finality certificate chain until the specified `lastInstance`.
func (cs *Store) ExportSnapshot(ctx context.Context, lastInstance uint64, writer io.Writer) error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simply call latestInstance, to? There is nothing in the logic that mandates "latest instance".

InitialPowerTable gpbft.PowerEntries
}

func (h *SnapshotHeader) WriteToSnapshot(writer io.Writer) error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend adhering to the existing SDK interfaces like io.WriterTo.

}

// Writes CBOR-encoded header or data block with a varint-encoded length prefix
func writeSnapshotCborEncodedBlock(writer io.Writer, block MarshalCBOR) error {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems over refactored, i.e. called only from one place.

return nil
}

type MarshalCBOR interface {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this type defined? Consider using existing types from cborgen?

}

// Exports an F3 snapshot that includes the finality certificate chain until the specified `lastInstance`.
func (cs *Store) ExportSnapshot(ctx context.Context, lastInstance uint64, writer io.Writer) error {
Copy link
Member

@masih masih Jun 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe makes sense to define an Exporter type that implements io.WriterTo instead, which takes Store and any other to-from instance params? also see other comment.

var ErrlatestCertificateNil = errors.New("latest certificate is not available")

// Exports an F3 snapshot that includes the finality certificate chain until the current `latestCertificate`.
func (cs *Store) ExportLatestSnapshot(ctx context.Context, writer io.Writer) error {
Copy link
Member

@masih masih Jun 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The term Snapshot doesn't carry enough of a weight within the context of go-f3. What we really mean by it at this stage is simply: export certificates.

You could make it mean something: define a type Snapshot that is either produced by the Store, or takes the Store, and implements io.WriterTo, io.ReaderFrom etc.

Or avoid the term entirely and instead make the store simply an Iterator of certs and separate IO ops elsewhere.

I would probably go with the first approach but there is not enough implementation in this PR for me to fully wrap my head around how you are thinking of approaching the problem.

So please feel free to ignore the recommendations if they happen to not make sense as the work progresses forward.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In progress
Development

Successfully merging this pull request may close these issues.

2 participants