Documentation
¶
Index ¶
- Variables
- type Store
- func (cs *Store) Get(ctx context.Context, instance uint64) (*certs.FinalityCertificate, error)
- func (cs *Store) GetPowerTable(ctx context.Context, instance uint64) (gpbft.PowerEntries, error)
- func (cs *Store) GetRange(ctx context.Context, start uint64, end uint64) ([]certs.FinalityCertificate, error)
- func (cs *Store) Latest() *certs.FinalityCertificate
- func (cs *Store) Put(ctx context.Context, cert *certs.FinalityCertificate) error
- func (cs *Store) SubscribeForNewCerts(ch chan<- *certs.FinalityCertificate) (last *certs.FinalityCertificate, closer func())
Constants ¶
This section is empty.
Variables ¶
var ErrCertNotFound = errors.New("certificate not found")
var ErrNotInitialized = errors.New("CertStore is not initilaized")
Functions ¶
This section is empty.
Types ¶
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 ¶
OpenStore opens an existing certificate store. The passed Datastore has to be thread safe. Returns ErrCertstoreNotInitialized if the CertStore does not exist
func (*Store) Get ¶
Get returns the FinalityCertificate at the specified instance, or an error derived from ErrCertNotFound.
func (*Store) GetPowerTable ¶
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 ¶
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) SubscribeForNewCerts ¶
func (cs *Store) SubscribeForNewCerts(ch chan<- *certs.FinalityCertificate) (last *certs.FinalityCertificate, closer func())
SubscribeForNewCerts is used to subscribe to the broadcast channel. If the passed channel is full at any point, it will be dropped from subscription and closed. To stop subscribing, either the closer function can be used or the channel can be abandoned. Passing a channel multiple times to the Subscribe function will result in a panic. The channel will receive new certificates sequentially.