Documentation
¶
Index ¶
Constants ¶
View Source
const ( DefaultRequestKeyLimit = MaxKeyValuesLimit DefaultRequestByteSizeLimit = maxByteSizeLimit )
View Source
const ( // Maximum number of key-value pairs to return in a proof. // This overrides any other Limit specified in a RangeProofRequest // or ChangeProofRequest if the given Limit is greater. MaxKeyValuesLimit = 2048 )
Variables ¶
View Source
var ( ErrInsufficientHistory = errors.New("insufficient history to generate proof") ErrNoEndRoot = fmt.Errorf("%w: end root not found", ErrInsufficientHistory) )
View Source
var ( ErrAlreadyStarted = errors.New("cannot start a Manager that has already been started") ErrAlreadyClosed = errors.New("Manager is closed") ErrNoRangeProofMarshalerProvided = errors.New("range proof marshaler is a required field of the sync config") ErrNoChangeProofMarshalerProvided = errors.New("change proof marshaler is a required field of the sync config") ErrNoRangeProofClientProvided = errors.New("range proof client is a required field of the sync config") ErrNoChangeProofClientProvided = errors.New("change proof client is a required field of the sync config") ErrNoDatabaseProvided = errors.New("sync database is a required field of the sync config") ErrNoLogProvided = errors.New("log is a required field of the sync config") ErrZeroWorkLimit = errors.New("simultaneous work limit must be greater than 0") ErrFinishedWithUnexpectedRoot = errors.New("finished syncing with an unexpected root") )
View Source
var (
ErrMinProofSizeIsTooLarge = errors.New("cannot generate any proof within the requested limit")
)
Functions ¶
This section is empty.
Types ¶
type DB ¶ added in v1.10.4
type DB[R any, C any] interface { // GetMerkleRoot returns the current root of the trie. // If the trie is empty, returns ids.Empty. GetMerkleRoot(context.Context) (ids.ID, error) // Clear removes all key/value pairs from the trie. Clear() error // GetChangeProof returns a proof for a subset of the key/value changes in key range // [start, end] that occurred between [startRootID] and [endRootID]. // Returns at most [maxLength] key/value pairs. // Returns [sync.ErrStartRootNotFound] if this node has insufficient // history to generate the proof. // Returns ErrEmptyProof if [endRootID] is ids.Empty. // Note that [endRootID] == ids.Empty means the trie is empty // (i.e. we don't need a change proof.) // Returns [ErrNoEndRoot], if the history doesn't contain the [endRootID]. GetChangeProof( ctx context.Context, startRootID ids.ID, endRootID ids.ID, start maybe.Maybe[[]byte], end maybe.Maybe[[]byte], maxLength int, ) (C, error) // Returns nil iff all the following hold: // - [start] <= [end]. // - [proof] is non-empty. // - [proof] is well-formed. // - The keys in [proof] is not longer than [maxLength]. // - All keys in [proof] and [proof] are in [start, end]. // If [start] is nothing, all keys are considered > [start]. // If [end] is nothing, all keys are considered < [end]. // - When the changes in [proof] are applied, // the root ID of the database is [expectedEndRootID]. VerifyChangeProof( ctx context.Context, proof C, start maybe.Maybe[[]byte], end maybe.Maybe[[]byte], expectedEndRootID ids.ID, maxLength int, ) error // CommitChangeProof commits the key/value pairs within the [proof] to the db. // [end] is the largest possible key in the range this [proof] covers. // Returns the next key that should be requested, or Nothing if all keys // have been are correct prior to [end]. CommitChangeProof(ctx context.Context, end maybe.Maybe[[]byte], proof C) (maybe.Maybe[[]byte], error) // GetRangeProofAtRoot returns a proof for the key/value pairs in this trie within the range // [start, end] when the root of the trie was [rootID]. // If [start] is Nothing, there's no lower bound on the range. // If [end] is Nothing, there's no upper bound on the range. // Returns an error if [rootID] is ids.Empty. // Returns [ErrInsufficientHistory] if the root is not found. // Note that [rootID] == ids.Empty means the trie is empty // (i.e. we don't need a range proof.) GetRangeProofAtRoot( ctx context.Context, rootID ids.ID, start maybe.Maybe[[]byte], end maybe.Maybe[[]byte], maxLength int, ) (R, error) // Returns nil iff all the following hold: // - [start] <= [end]. // - [proof] is non-empty. // - [proof] is well-formed. // - The keys in [proof] is not longer than [maxLength]. // - All keys in [proof] and [proof] are in [start, end]. // If [start] is nothing, all keys are considered > [start]. // If [end] is nothing, all keys are considered < [end]. // - When the changes in [proof] are applied, // the root ID of the database is [expectedEndRootID]. VerifyRangeProof( ctx context.Context, proof R, start maybe.Maybe[[]byte], end maybe.Maybe[[]byte], expectedEndRootID ids.ID, maxLength int, ) error // CommitRangeProof commits the key/value pairs within the [proof] to the db. // [start] is the smallest possible key in the range this [proof] covers. // [end] is the largest possible key in the range this [proof] covers. // Returns the next key that should be requested, or Nothing if all keys // have been are correct prior to [end]. CommitRangeProof(ctx context.Context, start, end maybe.Maybe[[]byte], proof R) (maybe.Maybe[[]byte], error) }
type GetChangeProofHandler ¶ added in v1.11.12
func NewGetChangeProofHandler ¶ added in v1.11.12
type GetRangeProofHandler ¶ added in v1.11.12
func NewGetRangeProofHandler ¶ added in v1.11.12
func NewGetRangeProofHandler[R any, C any](db DB[R, C], rangeProofMarshaler Marshaler[R]) *GetRangeProofHandler[R, C]
type Manager ¶ added in v1.10.4
func NewManager ¶ added in v1.10.4
func NewManager[R any, C any]( db DB[R, C], config ManagerConfig[R, C], registerer prometheus.Registerer, ) (*Manager[R, C], error)
func (*Manager[_, _]) Close ¶ added in v1.10.4
func (m *Manager[_, _]) Close()
Close will stop the syncing process
func (*Manager[_, _]) UpdateSyncTarget ¶ added in v1.10.4
type ManagerConfig ¶ added in v1.10.4
type ManagerConfig[R any, C any] struct { RangeProofMarshaler Marshaler[R] ChangeProofMarshaler Marshaler[C] RangeProofClient *p2p.Client ChangeProofClient *p2p.Client SimultaneousWorkLimit int Log logging.Logger TargetRoot ids.ID StateSyncNodes []ids.NodeID }
TODO remove non-config values out of this struct
type SyncMetrics ¶
type SyncMetrics interface {
RequestFailed()
RequestMade()
RequestSucceeded()
}
func NewMetrics ¶
func NewMetrics(namespace string, reg prometheus.Registerer) (SyncMetrics, error)
Click to show internal directories.
Click to hide internal directories.