certstore

package
v0.8.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 1, 2025 License: Apache-2.0, MIT Imports: 25 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnknownLatestCertificate = errors.New("latest certificate is not known")
	ErrNoCertificateExtracted   = errors.New("no certificate is found in the snapshot")
)
View Source
var ErrCertNotFound = errors.New("certificate not found")
View Source
var ErrNotInitialized = errors.New("certstore is not initialized")

Functions

func ImportSnapshotToDatastore added in v0.8.9

func ImportSnapshotToDatastore(ctx context.Context, snapshot SnapshotReader, ds datastore.Batching) error

ImportSnapshotToDatastore imports an F3 snapshot into the specified Datastore

Checkout the snapshot format specification at <https://github.com/filecoin-project/FIPs/blob/master/FRCs/frc-0108.md>

Types

type SnapshotHeader added in v0.8.9

type SnapshotHeader struct {
	Version           uint64
	FirstInstance     uint64
	LatestInstance    uint64
	InitialPowerTable gpbft.PowerEntries
}

func (*SnapshotHeader) MarshalCBOR added in v0.8.9

func (t *SnapshotHeader) MarshalCBOR(w io.Writer) error

func (*SnapshotHeader) UnmarshalCBOR added in v0.8.9

func (t *SnapshotHeader) UnmarshalCBOR(r io.Reader) (err error)

func (*SnapshotHeader) WriteTo added in v0.8.9

func (h *SnapshotHeader) WriteTo(w io.Writer) (int64, error)

type SnapshotReader added in v0.8.9

type SnapshotReader interface {
	io.Reader
	io.ByteReader
}

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store is responsible for storing and relaying information about new finality certificates

func CreateStore

func CreateStore(ctx context.Context, ds datastore.Datastore, firstInstance uint64, initialPowerTable gpbft.PowerEntries) (*Store, error)

CreateStore initializes a new certificate store. It will fail if the store already exists. The passed Datastore has to be thread safe.

func OpenOrCreateStore

func OpenOrCreateStore(ctx context.Context, ds datastore.Datastore, firstInstance uint64, initialPowerTable gpbft.PowerEntries) (*Store, error)

OpenOrCreateStore opens the certificate store if it doesn't exist, or creates it. If the certificate store already exists but uses a different initial instance and/or power table, this function will return an error.

The passed Datastore has to be thread safe.

func OpenStore

func OpenStore(ctx context.Context, ds datastore.Datastore) (*Store, error)

OpenStore opens an existing certificate store. The passed Datastore has to be thread safe. Returns ErrNotInitialized if the CertStore does not exist

func (*Store) Delete added in v0.0.3

func (cs *Store) Delete(ctx context.Context, instance uint64) error

Delete removes all asset belonging to an instance.

func (*Store) DeleteAll added in v0.0.3

func (cs *Store) DeleteAll(ctx context.Context) error

DeleteAll is used to remove all certificates from the store and clean it for a new instance to be able to use it from scratch.

func (*Store) ExportLatestSnapshot added in v0.8.9

func (cs *Store) ExportLatestSnapshot(ctx context.Context, writer io.Writer) (cid.Cid, *SnapshotHeader, error)

ExportLatestSnapshot exports an F3 snapshot that includes the finality certificate chain until the current `latestCertificate`.

Checkout the snapshot format specification at <https://github.com/filecoin-project/FIPs/blob/master/FRCs/frc-0108.md>

func (*Store) ExportSnapshot added in v0.8.9

func (cs *Store) ExportSnapshot(ctx context.Context, latestInstance uint64, writer io.Writer) (cid.Cid, *SnapshotHeader, error)

ExportSnapshot exports an F3 snapshot that includes the finality certificate chain from the `Store.firstInstance` to the specified `lastInstance`.

Checkout the snapshot format specification at <https://github.com/filecoin-project/FIPs/blob/master/FRCs/frc-0108.md>

func (*Store) Get

func (cs *Store) Get(ctx context.Context, instance uint64) (*certs.FinalityCertificate, error)

Get returns the FinalityCertificate at the specified instance, or an error derived from ErrCertNotFound.

func (*Store) GetPowerTable

func (cs *Store) GetPowerTable(ctx context.Context, instance uint64) (gpbft.PowerEntries, error)

GetPowerTable returns the power table (committee) used to validate the specified instance.

func (*Store) GetRange

func (cs *Store) GetRange(ctx context.Context, start uint64, end uint64) ([]certs.FinalityCertificate, error)

GetRange returns a range of certs from start to end inclusive by instance numbers in the increasing order. Only this order of traversal is supported.

If it encounters missing cert, it returns a wrapped ErrCertNotFound and the available certs.

func (*Store) Latest

func (cs *Store) Latest() *certs.FinalityCertificate

Latest returns the newest available certificate

func (*Store) Put

func (cs *Store) Put(ctx context.Context, cert *certs.FinalityCertificate) error

Put saves a certificate in a store and notifies listeners. It returns an error if the certificate is either:

1. Before the initial instance that the certificate store was initialized with. 2. More than one instance after the last certificate stored.

func (*Store) Subscribe added in v0.3.0

func (cs *Store) Subscribe() (out <-chan *certs.FinalityCertificate, closer func())

Subscribe subscribes to new certificate notifications. When read, it will always return the latest not-yet-seen certificate (including the latest certificate when Subscribe is first called, if we have any) but it will drop intermediate certificates. If you need all the certificates, you should keep track of the last certificate you received and call GetRange to get the ones between.

The caller must call the closer to unsubscribe and release resources.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL